Exemplo n.º 1
0
        // 是否能够反击
        public static bool CanAttackBack(this Warrior warrior, Warrior attacker)
        {
            // 检查反击技能
            var s = warrior.GetActiveSkillByName("CounterAttack");

            if (s == null)
            {
                return(false);
            }

            // 检查攻击范围
            attacker.GetPosInMap(out int x, out int y);
            if (!warrior.InAttackRange(x, y))
            {
                return(false);
            }

            //// 检查它限制行动的被动技能
            //if (warrior.GetBuffSkill<Faint>() != null)
            //    return false;

            return(true);
        }
Exemplo n.º 2
0
        // 模拟攻击行为的伤害数值,但并不执行攻击行为
        public void SimulateAttackingDamage(Warrior attacker, Warrior target, Warrior[] addtionalTargets, Skill skill, Action <int> onDamage, params string[] flags)
        {
            target.GetPosInMap(out int tx, out int ty); // 检查攻击范围限制
            if (!attacker.InAttackRange(tx, ty))
            {
                return;
            }

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

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

            var addTars = new List <Warrior>();

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

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

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

            if (attackFlags.Contains("CancelAttack")) // 取消攻击
            {
                return;
            }

            // 计算实际伤害
            var damage = CalculateDamage(attacker, target, skill, attackFlags, multi);

            onDamage(damage);
        }
Exemplo 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;
        }