WutheringWaves/GameServer/Systems/Entity/Component/EntityAttributeComponent.cs

73 lines
1.9 KiB
C#
Raw Normal View History

2024-02-10 16:04:03 +00:00
using Protocol;
namespace GameServer.Systems.Entity.Component;
internal class EntityAttributeComponent : EntityComponentBase
{
public override EntityComponentType Type => EntityComponentType.Attribute;
private readonly Dictionary<EAttributeType, GameplayAttributeData> _gameplayAttributes;
public EntityAttributeComponent()
{
_gameplayAttributes = [];
}
public void SetAttribute(EAttributeType type, int currentValue, int baseValue)
{
if (!_gameplayAttributes.TryGetValue(type, out GameplayAttributeData? attribute))
{
attribute = new GameplayAttributeData
{
AttributeType = (int)type
};
_gameplayAttributes.Add(type, attribute);
}
attribute.CurrentValue = currentValue;
attribute.BaseValue = baseValue;
}
public void SetAttribute(EAttributeType type, int currentValue)
{
if (!_gameplayAttributes.TryGetValue(type, out GameplayAttributeData? attribute))
{
SetAttribute(type, currentValue, currentValue);
return;
}
attribute.CurrentValue = currentValue;
}
public int GetAttribute(EAttributeType type)
{
if (_gameplayAttributes.TryGetValue(type, out GameplayAttributeData? attribute))
return attribute.CurrentValue;
return 0;
}
public int GetAttributeBase(EAttributeType type)
{
if (_gameplayAttributes.TryGetValue(type, out GameplayAttributeData? attribute))
return attribute.BaseValue;
return 0;
}
public override EntityComponentPb Pb
{
get
{
EntityComponentPb pb = new()
{
AttributeComponent = new()
};
pb.AttributeComponent.GameAttributes.AddRange(_gameplayAttributes.Values);
return pb;
}
}
}