123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using XGame.Database;
- using XGame.Framework;
- namespace FL.Battle.Buffs
- {
- /// <summary>
- /// 元素易伤debuff
- /// </summary>
- public class ElementAddDebuff : Buff
- {
- private int _autoTickLayer = 3;
- private int _elementTickLayer = 5;
- //private EElementType _elementType;
- protected override void OnInited()
- {
- //_elementType = (EElementType)(Table.BuffType / 10 % 10); // BuffType的十位数为元素类型
- Assert.IsTrue((Table.BuffType / 10 % 10) == (int)ElementType, $"元素易伤配置错误. BuffType:{Table.BuffType} ElementType:{ElementType}");
- _autoTickLayer = Table.BuffTypeNum[2];
- _elementTickLayer = Table.BuffTypeNum[4];
- }
- protected override void OnDispose()
- {
- }
- public bool IsReachLayer3()
- {
- return Layers >= _autoTickLayer;
- }
- /// <summary>
- /// 是否达到3层元素易伤条件
- /// AddBuff时判定
- /// </summary>
- /// <param name="attacker"></param>
- /// <returns></returns>
- public bool TryTickLayer3(ICombatCalculation attacker)
- {
- if (Layers < _autoTickLayer) return false;
- if (Layers == _autoTickLayer)
- {
- var buffOrSkillId = Table.BuffTypeNum[3];
- if (Table.BuffType == (int)EBuffType.ElementAddPoison)
- {
- var calculation = Context.Calculation.GetSkillTrigger(buffOrSkillId, attacker);
- calculation?.TickSkill(buffOrSkillId, Context.Entity.EntityId);
- }
- else
- {
- var calculation = Context.Calculation.GetBuffTrigger(buffOrSkillId, attacker);
- calculation?.TickBuff(buffOrSkillId);
- }
- }
- return true;
- }
- /// <summary>
- /// 是否达到5层元素易伤条件
- /// 攻击生效时判定
- /// </summary>
- /// <param name="elementType"></param>
- /// <returns></returns>
- public bool IsReachLayer5(EElementType elementType)
- {
- return elementType == ElementType && _elementTickLayer == Layers;
- }
- public bool TryTickBuff(int damage, EElementType elementType, ICombatCalculation attacker)
- {
- if (elementType == EElementType.None)
- return false;
- var isReach = IsReachLayer5(elementType);
- var isSkill = false;
- var buffOrSkillId = isReach ? Table.BuffTypeNum[5] : Table.BuffTypeNum[0];
- var probability = isReach ? TableUtils.Multiple : Table.BuffTypeNum[1];
- var addLayer = 1;
- switch (BuffType)
- {
- case EBuffType.ElementAddFire:
- case EBuffType.ElementAddWind:
- {
- isSkill = isReach;
- }
- break;
- case EBuffType.ElementAddThunder:
- {
- isSkill = true;
- }
- break;
- case EBuffType.ElementAddIce:
- {
- if (!isReach)
- return false;
- // TODO 给主角加冰盾buff,
- //probability = 0;
- }
- break;
- case EBuffType.ElementAddPoison:
- {
- addLayer = isReach ? Table.BuffTypeNum[5] : Layers;
- buffOrSkillId = Table.BuffTypeNum[0];
- }
- break;
- }
- if (isSkill)
- {
- var calculation = Context.Calculation.GetSkillTrigger(buffOrSkillId, attacker);
- calculation?.TickSkill(buffOrSkillId, Context.Entity.EntityId, probability);
- }
- else
- {
- var calculation = Context.Calculation.GetBuffTrigger(buffOrSkillId, attacker);
- calculation?.TickBuff(buffOrSkillId, probability, addLayer, damage);
- }
- if (isReach)
- {
- Listener?.OnCompleted(TableId);
- }
- return true;
- }
- }
- }
|