Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / buff / fragment / Buff_BulletCount.cs
@小李xl 小李xl on 15 Mar 2024 1 KB buff系统重构中

using Godot;

[Buff("BulletCount", "子弹数量 buff, 参数‘1’为子弹数量添加类型, 1: 具体数量, 2:百分比(小数), 参数‘2’为增加子弹的数量")]
public class Buff_BulletCount : BuffFragment
{
    private int _type;
    private float _value;

    public override void InitParam(float arg1, float arg2)
    {
        _type = (int)arg2;
        _value = (int)arg1;
    }
    
    public override void OnPickUpItem()
    {
        if (_type == 1)
        {
            Role.RoleState.CalcBulletCountEvent += CalcBulletCountEvent1;
        }
        else
        {
            Role.RoleState.CalcBulletCountEvent += CalcBulletCountEvent2;
        }
    }

    public override void OnRemoveItem()
    {
        if (_type == 1)
        {
            Role.RoleState.CalcBulletCountEvent -= CalcBulletCountEvent1;
        }
        else
        {
            Role.RoleState.CalcBulletCountEvent -= CalcBulletCountEvent2;
        }
    }

    private void CalcBulletCountEvent1(int originCount, RefValue<int> refValue)
    {
        refValue.Value += Mathf.CeilToInt(_value);
    }
    
    private void CalcBulletCountEvent2(int originCount, RefValue<int> refValue)
    {
        refValue.Value += Mathf.CeilToInt(originCount * _value);
    }
}