using System;
using XGame.Database;
using XGame.Framework;
namespace FL.Battle
{
public class EntityAttributes : IDisposable
{
public int TableId { get; private set; }
public long UID { get; private set; }
public string Name { get; set; }
///
/// 基础生命
///
public long BasicHp => GetValue(EAttributeType.Hp);
public long HpLimit => GetValue(EAttributeType.HpTotal);
///
/// 当前生命值
///
public long CurrentHp { get; set; }
public long Mp { get; set; }
public long MpLimit { get; set; }
public float Radius { get; set; }
///
/// 移动速度,不带缩放
///
public float MoveSpeed => GetValue(EAttributeType.Speed);
///
/// 移动速度缩放值
/// EAttributeType.SpeedAdd 最低值必须大于 -10000
///
public float MoveSpeedScale
{
get
{
var scale = 1 + (float)GetValue(EAttributeType.SpeedAdd).ToRealDouble();
return scale < 0 ? 0 : scale;
}
}
///
/// 移动时间缩放值
/// EAttributeType.SpeedAdd 最低值必须大于 -10000
///
public float MoveTimeScale => 1 / MoveSpeedScale;
///
/// 真实的移动速度
/// 慎用
///
public float MoveSpeedReal => MoveSpeed * MoveSpeedScale;
public int Attack { get => (int)GetValue(EAttributeType.Atk); }
public int AttackCD { get; set; }
private Attributes _staticAttr;
///
/// 静态属性,战斗外基础数值
/// 战斗内不会变
///
public Attributes Static => _staticAttr ??= ObjectPool.Acquire();
private Attributes _dynamicAttr;
///
/// 动态属性,战斗内属性加成
///
public Attributes Dynamic => _dynamicAttr ??= ObjectPool.Acquire();
public EntityAttributes(int tableId, long uid)
{
TableId = tableId;
UID = uid;
}
public long GetValue(EAttributeType type)
{
return Static.GetValue(type) + (_dynamicAttr?.GetValue(type) ?? 0);
}
void IDisposable.Dispose()
{
if (_staticAttr != null)
{
ObjectPool.Recycle(_staticAttr);
_staticAttr = null;
}
if (_dynamicAttr != null)
{
ObjectPool.Recycle(_dynamicAttr);
_dynamicAttr = null;
}
}
public void CopyFrom(Attributes attribute)
{
attribute.CopyTo(Static);
CurrentHp = HpLimit;
}
public void ResetHp()
{
CurrentHp = HpLimit;
}
}
}