Пример #1
0
        protected virtual bool attackable(Game_Unit attacker, Combat_Map_Object target)
        {
            // If target doesn't exist because it's a flare use/etc
            if (target == null)
            {
                return(true);
            }

            // If attacker is dead return
            //@Debug: make sure units who are out of hp but technically aren't
            // dead for whatever reason will stop
            if (attacker.hp <= 0) //@Debug: .is_dead)
            {
                return(false);
            }

            bool is_target_unit = false;

            // If the target is already dead, stop attacking
            if (target.hp <= 0)
            {
                // Don't return if either battler wants the attacks to continue
                if (!attacker.continue_attacking() &&
                    !(target.is_unit() && (target as Game_Unit).continue_attacking()))
                {
                    return(false);
                }
            }
            Game_Unit target_unit = null;

            if (target.is_unit())
            {
                is_target_unit = true;
                target_unit    = (Game_Unit)target;
            }

            var weapon = attacker.id == Battler_1_Id ? this.weapon1 : this.weapon2;

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

            // If target is berserk ally and attacker isn't berserk, don't hurt your friend >:
            if (is_target_unit && attacker.id != Battler_1_Id &&
                !attacker.is_attackable_team(target_unit) && !can_counter_ally(attacker))
            {
                return(false);
            }

            int hit, uses;

            if (attacker.id == Battler_1_Id)
            {
                List <int?> ary = Combat.combat_stats(attacker.id, target.id, Distance);
                hit  = 100;
                uses = Weapon_1_Uses;
                if (ary[0] == null && !weapon.is_staff())
                {
                    return(false); // This is newly added to account for the attacker being put to sleep, did any other cases make hit null?
                }
                if (ary[0] != null)
                {
                    hit = (int)ary[0];
                }
            }
            else
            {
                List <int?> ary = Combat.combat_stats(target.id, attacker.id, Distance);
                if (ary[4] == null)
                {
                    return(false);
                }
                hit  = (int)ary[4];
                uses = Weapon_2_Uses;
            }

            // Breaks if the attacker can't fight/broke their weapon
            if (hit < 0 || attacker.is_weapon_broke(uses))
            {
                return(false);
            }

            return(true);
        }