(client) feat:实现掉落物,UI显示,维度
This commit is contained in:
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using AI;
|
||||
using Base;
|
||||
using Data;
|
||||
using Item;
|
||||
using Prefab;
|
||||
using UnityEngine;
|
||||
|
||||
@ -86,19 +87,19 @@ namespace Entity
|
||||
IsChase = true;
|
||||
currentJob = null;
|
||||
// 逻辑修改:只有当存在一个不同的焦点实体时,才将其PlayerControlled设为false
|
||||
if (Program.Instance.focusedEntity && Program.Instance.focusedEntity != this)
|
||||
if (Program.Instance.FocusedEntity && Program.Instance.FocusedEntity != this)
|
||||
{
|
||||
Program.Instance.focusedEntity.PlayerControlled = false;
|
||||
Program.Instance.FocusedEntity.PlayerControlled = false;
|
||||
}
|
||||
Program.Instance.focusedEntity = this;
|
||||
Program.Instance.SetFocusedEntity(this);
|
||||
}
|
||||
// 逻辑修改:确保只有当自身是焦点实体时才取消焦点,避免不必要的逻辑执行
|
||||
else if (Program.Instance.focusedEntity == this)
|
||||
else if (Program.Instance.FocusedEntity == this)
|
||||
{
|
||||
Program.Instance.focusedEntity = null;
|
||||
Program.Instance.SetFocusedEntity(null);
|
||||
}
|
||||
}
|
||||
get => Program.Instance.focusedEntity == this;
|
||||
get => Program.Instance.FocusedEntity == this;
|
||||
}
|
||||
|
||||
|
||||
@ -115,18 +116,27 @@ namespace Entity
|
||||
public bool IsDead => attributes.health <= 0;
|
||||
public bool IsShowingHealthBarUI=>_hitBarUIShowTimer > 0;
|
||||
public bool IsAttacking => _attackCoroutine != null;
|
||||
|
||||
/// <summary>
|
||||
/// 当实体受到伤害时触发的事件。
|
||||
/// 可以订阅此事件来响应实体的生命值变化,例如更新UI或播放受击特效。
|
||||
/// </summary>
|
||||
public event Action<EntityHitEventArgs> OnEntityHit;
|
||||
/// <summary>
|
||||
/// 当实体死亡时触发的事件。
|
||||
/// 只在实体首次进入死亡状态时触发一次。
|
||||
/// </summary>
|
||||
public event Action<Entity> OnEntityDied;
|
||||
private bool _warning = false;
|
||||
|
||||
/// <summary>
|
||||
/// 存储不同朝向下的动画节点集合。
|
||||
/// </summary>
|
||||
public Dictionary<EntityState, Dictionary<Orientation, List<ITick>>> bodyAnimationNode = new();
|
||||
private List<ITick> _currentAnimatorCache=new ();
|
||||
public Dictionary<EntityState, Dictionary<Orientation, ITick[]>> bodyAnimationNode = new();
|
||||
private ITick[] _currentAnimatorCache;
|
||||
/// <summary>
|
||||
/// 存储不同朝向下的身体节点对象。
|
||||
/// </summary>
|
||||
private Dictionary<EntityState, Dictionary<Orientation,GameObject>> bodyNodes = new();
|
||||
protected Dictionary<EntityState, Dictionary<Orientation,GameObject>> bodyNodes = new();
|
||||
|
||||
/// <summary>
|
||||
/// 当前实体的朝向。
|
||||
@ -186,7 +196,7 @@ namespace Entity
|
||||
foreach (var state in states)
|
||||
{
|
||||
bodyNodes.TryAdd(state, new Dictionary<Orientation, GameObject>());
|
||||
bodyAnimationNode.TryAdd(state, new Dictionary<Orientation, List<ITick>>());
|
||||
bodyAnimationNode.TryAdd(state, new Dictionary<Orientation, ITick[]>());
|
||||
}
|
||||
|
||||
// 主初始化逻辑
|
||||
@ -229,7 +239,7 @@ namespace Entity
|
||||
{
|
||||
animatorsForOrientation.AddRange(animators);
|
||||
}
|
||||
stateAnimNodes[orientation] = animatorsForOrientation;
|
||||
stateAnimNodes[orientation] = animatorsForOrientation.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@ -472,7 +482,7 @@ namespace Entity
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentAnimatorCache = new List<ITick>(); // 如果没有找到动画,则使用空列表
|
||||
_currentAnimatorCache = new ITick[]{}; // 如果没有找到动画,则使用空列表
|
||||
}
|
||||
}
|
||||
|
||||
@ -487,19 +497,38 @@ namespace Entity
|
||||
SetBodyTexture(EntityState.Walking,_currentOrientation);
|
||||
_walkingTimer = 2;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 处理实体受到攻击的逻辑。
|
||||
/// </summary>
|
||||
/// <param name="from">攻击来源实体。</param>
|
||||
public virtual void OnHit(Entity from)
|
||||
{
|
||||
// MODIFIED: 收到攻击时触发回调
|
||||
if (IsDead) // 如果已经死亡,则不再处理伤害 nor 触发事件
|
||||
{
|
||||
return;
|
||||
}
|
||||
var hit = from.attributes.attack - attributes.defense;
|
||||
if (hit < 0)
|
||||
hit = from.attributes.attack / 100;
|
||||
// 确保伤害不为负,最小为0
|
||||
hit = Mathf.Max(0, hit);
|
||||
attributes.health -= hit;
|
||||
var wasFatal = IsDead; // 检查这次攻击是否导致实体死亡
|
||||
// 触发 OnEntityHit 事件
|
||||
OnEntityHit?.Invoke(new EntityHitEventArgs(
|
||||
this, from, hit, attributes.health, entityDef.attributes.health, wasFatal));
|
||||
currentJob?.StopJob();
|
||||
ShowHealthBar();
|
||||
if (wasFatal)
|
||||
{
|
||||
// 如果是首次死亡,则触发 OnEntityDied 事件
|
||||
// MODIFIED: 停止所有活动,包括当前工作
|
||||
currentJob = null; // 清除当前工作
|
||||
OnEntityDied?.Invoke(this);
|
||||
}
|
||||
|
||||
ShowHealthBar(); // 无论是否死亡,都更新血条UI
|
||||
}
|
||||
|
||||
public void ShowHealthBar()
|
||||
@ -523,7 +552,17 @@ namespace Entity
|
||||
/// </summary>
|
||||
public virtual void Kill()
|
||||
{
|
||||
attributes.health = 0;
|
||||
if (IsDead)
|
||||
{
|
||||
return;
|
||||
}
|
||||
attributes.health = 0; // 直接设置生命值为0
|
||||
// MODIFIED: 停止所有活动,包括当前工作
|
||||
currentJob?.StopJob();
|
||||
currentJob = null; // 清除当前工作
|
||||
// 触发 OnEntityDied 事件
|
||||
OnEntityDied?.Invoke(this);
|
||||
ShowHealthBar();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -684,5 +723,10 @@ namespace Entity
|
||||
attackCount--;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual WeaponResource GetCurrentWeapon()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user