Ejemplo n.º 1
0
 private void Attack(Character character, Damage damage)
 {
     BeforeAttack?.Invoke(character, damage);
     character.ReceiveDamage(damage);
     AfterAttack?.Invoke(character, damage);
     if (!character.IsAlive)
     {
         OnKill?.Invoke();
     }
 }
Ejemplo n.º 2
0
 public void Attack(Character character, Damage damage)        //, AttackType attackType, int atkPoints)
 {
     BeforeAttack?.Invoke(character, damage);
     character.ReceiveDamage(damage);
     AfterAttack?.Invoke(character, damage);
     if (!character.IsAlive)
     {
         OnEnemyKill?.Invoke();
     }
 }
Ejemplo n.º 3
0
        public void Attack(Warrior attacker, Warrior target, Warrior[] addtionalTargets, Skill skill = null, params string[] flags)
        {
            // 在连续指令的情况下,可能条件已经不满足
            if (attacker == null || target == null)
            {
                return;
            }

            // 整理攻击标记
            var attackFlags = new HashSet <string>();

            attackFlags.UnionWith(flags);
            attackFlags.Add(attacker.AttackingType);

            // 额外攻击目标
            var addTars = new List <Warrior>();

            if (addtionalTargets != null)
            {
                addTars.AddRange(addtionalTargets);
            }

            PrepareAttack?.Invoke(attacker, target, addTars, skill, attackFlags);

            if (!attackFlags.Contains("IgnoreAttackRange")) // 可能是无视攻击距离限制的
            {
                target.GetPosInMap(out int tx, out int ty); // 检查攻击范围限制
                if (!attacker.InAttackRange(tx, ty))
                {
                    return;
                }
            }

            // 额外伤害系数
            var multi    = new List <int>();
            var addMulti = new List <int>();

            BeforeAttack?.Invoke(attacker, target, addTars, skill, attackFlags, multi, addMulti);

            // 可能需要取消攻击 或者因为 PatternSkill 导致已经行动过了
            if (attacker.ActionDone || attackFlags.Contains("CancelAttack"))
            {
                return;
            }

            var tars = new List <Warrior>();

            tars.Add(target);
            tars.AddRange(addTars);

            // 计算实际伤害
            var damages = new Dictionary <Warrior, int>();

            foreach (var tar in tars)
            {
                damages[tar] = CalculateDamage(attacker, tar, skill, attackFlags, tar == target ? multi : addMulti);
            }

            // ExtraAttack 不影响行动标记
            if (!attackFlags.Contains("ExtraAttack"))
            {
                Debug.Assert(!attacker.ActionDone, "attacker has already attacted in this round");
                SetActionFlag(attacker, true, true, true);
            }

            // 混乱攻击不计算护盾,其它类型攻击需要先消耗护盾
            var dhps = new Dictionary <Warrior, int>();
            var dess = new Dictionary <Warrior, int>();

            foreach (var tar in tars)
            {
                var damage = damages[tar];
                var dhp    = -damage;
                var des    = 0;
                if (!attackFlags.Contains("chaos") && target.ES > 0)
                {
                    dhp = damage > target.ES ? target.ES - damage : 0;
                    des = damage > target.ES ? 0 : -damage;
                }

                dhps[tar] = dhp;
                dess[tar] = des;
            }

            OnWarriorAttack?.Invoke(attacker, target, addTars, dhps, dess, skill, attackFlags);

            foreach (var tar in tars)
            {
                var dhp = dhps[tar];
                var des = dess[tar];

                if (des != 0)
                {
                    AddES(tar, des);
                }
                if (dhp != 0)
                {
                    AddHP(tar, dhp);
                }
            }

            AfterAttack?.Invoke(attacker, target, addTars, skill, attackFlags);

            return;
        }
Ejemplo n.º 4
0
 public static void OnAfterAttack(object sender, AfterAttackEventArgs args)
 {
     AfterAttack?.Invoke(sender, args);
 }