buff系统重构中

This commit is contained in:
小李xl 2024-03-14 01:37:51 +08:00
parent c4f1104f43
commit 76d4c08041
10 changed files with 335 additions and 1 deletions

View File

@ -0,0 +1,50 @@
/// <summary>
/// 子弹射程 buff
/// </summary>
[Buff("BulletDistance", "子弹射程 buff, 参数1为射程增加类型: 1:具体射程, 2:百分比射程(小数), 参数2为子弹增加的射程值")]
public class Buff_BulletDistance : BuffFragment
{
private int _type;
private float _value;
public override void InitParam(float arg1, float arg2)
{
_type = (int)arg1;
_value = arg2;
}
public override void OnPickUpItem()
{
if (_type == 1)
{
Role.RoleState.CalcBulletDistanceEvent += CalcBulletDistanceEvent1;
}
else
{
Role.RoleState.CalcBulletDistanceEvent += CalcBulletDistanceEvent2;
}
}
public override void OnRemoveItem()
{
if (_type == 1)
{
Role.RoleState.CalcBulletDistanceEvent -= CalcBulletDistanceEvent1;
}
else
{
Role.RoleState.CalcBulletDistanceEvent -= CalcBulletDistanceEvent2;
}
}
private void CalcBulletDistanceEvent1(float originDistance, RefValue<float> distance)
{
distance.Value += _value;
}
private void CalcBulletDistanceEvent2(float originDistance, RefValue<float> distance)
{
distance.Value += originDistance * _value;
}
}

View File

@ -0,0 +1,50 @@
/// <summary>
/// 子弹速度 buff
/// </summary>
[Buff("BulletSpeed", "子弹速度 buff, 参数1为射速增加类型: 1:具体射速, 2:百分比射速(小数), 参数2为子弹增加的射速值")]
public class Buff_BulletSpeed : BuffFragment
{
private int _type;
private float _value;
public override void InitParam(float arg1, float arg2)
{
_type = (int)arg1;
_value = arg2;
}
public override void OnPickUpItem()
{
if (_type == 1)
{
Role.RoleState.CalcBulletSpeedEvent += CalcBulletSpeedEvent1;
}
else
{
Role.RoleState.CalcBulletSpeedEvent += CalcBulletSpeedEvent2;
}
}
public override void OnRemoveItem()
{
if (_type == 1)
{
Role.RoleState.CalcBulletSpeedEvent -= CalcBulletSpeedEvent1;
}
else
{
Role.RoleState.CalcBulletSpeedEvent -= CalcBulletSpeedEvent2;
}
}
private void CalcBulletSpeedEvent1(float originSpeed, RefValue<float> speed)
{
speed.Value += _value;
}
private void CalcBulletSpeedEvent2(float originSpeed, RefValue<float> speed)
{
speed.Value += originSpeed * _value;
}
}

View File

@ -0,0 +1,52 @@
using Godot;
/// <summary>
/// 提升伤害buff
/// </summary>
[Buff("Damage", "提升伤害buff, 参数1为伤害增加类型: 1:具体伤害, 2:百分比伤害(小数), 参数2为增益伤害值")]
public class Buff_Damage : BuffFragment
{
private int _type;
private float _value;
public override void InitParam(float arg1, float arg2)
{
_type = (int)arg1;
_value = arg2;
}
public override void OnPickUpItem()
{
if (_type == 1)
{
Role.RoleState.CalcDamageEvent += CalcDamage1;
}
else
{
Role.RoleState.CalcDamageEvent += CalcDamage2;
}
}
public override void OnRemoveItem()
{
if (_type == 1)
{
Role.RoleState.CalcDamageEvent -= CalcDamage1;
}
else
{
Role.RoleState.CalcDamageEvent -= CalcDamage2;
}
}
private void CalcDamage1(int originDamage, RefValue<int> refValue)
{
refValue.Value += Mathf.CeilToInt(_value);
}
private void CalcDamage2(int originDamage, RefValue<int> refValue)
{
refValue.Value += Mathf.CeilToInt(originDamage * _value);
}
}

View File

@ -0,0 +1,33 @@
using System.Collections.Generic;
/// <summary>
/// 血量上限 buff
/// </summary>
[Buff("MaxHp", "血量上限 buff, 参数1为血量上限值")]
public class Buff_MaxHp : BuffFragment
{
private List<ulong> _cacheId = new List<ulong>();
private int _maxHp;
public override void InitParam(float arg1)
{
_maxHp = (int)arg1;
}
public override void OnPickUpItem()
{
Role.MaxHp += _maxHp;
var instanceId = Role.GetInstanceId();
if (!_cacheId.Contains(instanceId))
{
_cacheId.Add(instanceId);
Role.Hp += _maxHp;
}
}
public override void OnRemoveItem()
{
Role.MaxHp -= _maxHp;
}
}

View File

@ -0,0 +1,33 @@
using System.Collections.Generic;
/// <summary>
/// 护盾上限buff
/// </summary>
[Buff("MaxShield", "护盾上限buff, 参数1为护盾上限")]
public class Buff_MaxShield : BuffFragment
{
private List<ulong> _cacheId = new List<ulong>();
private int _maxShield;
public override void InitParam(float arg1)
{
_maxShield = (int)arg1;
}
public override void OnPickUpItem()
{
Role.MaxShield += _maxShield;
var instanceId = Role.GetInstanceId();
if (!_cacheId.Contains(instanceId))
{
_cacheId.Add(instanceId);
Role.Shield += _maxShield;
}
}
public override void OnRemoveItem()
{
Role.MaxShield -= _maxShield;
}
}

View File

@ -2,7 +2,7 @@
/// <summary>
/// 移速 buff
/// </summary>
[Buff("MoveSpeed", "移速 buff, 参数 1 为移动速度值")]
[Buff("MoveSpeed", "移速 buff, 参数1为移动速度值")]
public class Buff_MoveSpeed : BuffFragment
{
private float _moveSpeed;

View File

@ -0,0 +1,32 @@
/// <summary>
/// 受伤时有概率抵消伤害的buff
/// </summary>
[Buff("OffsetInjury", "受伤时有概率抵消伤害的buff, 参数1为抵消伤害概率百分比(小数)")]
public class Buff_OffsetInjury : BuffFragment
{
private float _value;
public override void InitParam(float arg1)
{
_value = arg1;
}
public override void OnPickUpItem()
{
Role.RoleState.CalcHurtDamageEvent += CalcHurtDamageEvent;
}
public override void OnRemoveItem()
{
Role.RoleState.CalcHurtDamageEvent -= CalcHurtDamageEvent;
}
private void CalcHurtDamageEvent(int originDamage, RefValue<int> refValue)
{
if (refValue.Value > 0 && Utils.Random.RandomBoolean(_value))
{
refValue.Value = 0;
}
}
}

View File

@ -0,0 +1,36 @@
/// <summary>
/// 提高武器精准度buff
/// </summary>
[Buff("Scattering", "提高武器精准度buff, 参数1为提升的精准度百分比值(小数)")]
public class Buff_Scattering : BuffFragment
{
private float _value;
public override void InitParam(float arg1)
{
_value = arg1;
}
public override void OnPickUpItem()
{
Role.RoleState.CalcStartScatteringEvent += CalcStartScatteringEvent;
Role.RoleState.CalcFinalScatteringEvent += CalcFinalScatteringEvent;
}
public override void OnRemoveItem()
{
Role.RoleState.CalcStartScatteringEvent -= CalcStartScatteringEvent;
Role.RoleState.CalcFinalScatteringEvent -= CalcFinalScatteringEvent;
}
private void CalcStartScatteringEvent(float originValue, RefValue<float> refValue)
{
refValue.Value -= refValue.Value * _value;
}
private void CalcFinalScatteringEvent(float originValue, RefValue<float> refValue)
{
refValue.Value -= refValue.Value * _value;
}
}

View File

@ -0,0 +1,24 @@
/// <summary>
/// 护盾恢复时间buff
/// </summary>
[Buff("ShieldRecoveryTime", "单格护盾恢复时间, 参数1单位: 秒")]
public class Buff_ShieldRecoveryTime : BuffFragment
{
private float _time;
public override void InitParam(float arg1)
{
_time = arg1;
}
public override void OnPickUpItem()
{
Role.RoleState.ShieldRecoveryTime -= _time;
}
public override void OnRemoveItem()
{
Role.RoleState.ShieldRecoveryTime += _time;
}
}

View File

@ -0,0 +1,24 @@
/// <summary>
/// 延长无敌时间buff
/// </summary>
[Buff("WoundedInvincibleTime", "延长无敌时间buff, 参数1为延长时间, 单位秒")]
public class Buff_WoundedInvincibleTime : BuffFragment
{
private float _time;
public override void InitParam(float arg1)
{
_time = arg1;
}
public override void OnPickUpItem()
{
Role.RoleState.WoundedInvincibleTime += _time;
}
public override void OnRemoveItem()
{
Role.RoleState.WoundedInvincibleTime -= _time;
}
}