Esempio n. 1
0
        public static Boolean CheckCounterAbility(BattleTarget defender, BattleCaster attacker, BattleCommand command)
        {
            if (defender.IsUnderStatus(BattleStatus.NoReaction) || command.Id > BattleCommandId.EnemyAtk)
            {
                return(false);
            }

            if (defender.HasSupportAbility(SupportAbility2.Counter) && (command.Data.aa.Category & 8) != 0) // Physical
            {
                Int32 chance = defender.Will;
                if (defender.HasSupportAbility(SupportAbility2.Eye4Eye))
                {
                    chance *= 2;
                }

                if (chance > Comn.random16() % 100)
                {
                    btl_cmd.SetCounter(defender.Data, BattleCommandId.Counter, 176, attacker.Id);
                    return(true);
                }
            }

            if (defender.HasSupportAbility(SupportAbility2.ReturnMagic) && (command.Data.aa.Category & 128) != 0)     // Magic
            {
                btl_cmd.SetCounter(defender.Data, BattleCommandId.MagicCounter, command.Data.sub_no, attacker.Id);
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        public static void CheckAutoItemAbility(BattleTarget defender, BattleCommand command)
        {
            const Byte potion1Id      = 236;
            const Byte potion2Id      = 237;
            const Byte potionScriptId = 069;

            if (!defender.HasSupportAbility(SupportAbility2.AutoPotion))
            {
                return;
            }

            if (defender.IsUnderStatus(BattleStatus.NoReaction) || command.Id > BattleCommandId.EnemyAtk)
            {
                return;
            }

            Int32 overhealLimit = Configuration.Battle.AutoPotionOverhealLimit;

            // Vanila
            if (overhealLimit < 0)
            {
                foreach (Byte potionId in new[] { potion1Id, potion2Id })
                {
                    if (ff9item.FF9Item_GetCount(potionId) != 0)
                    {
                        UIManager.Battle.ItemRequest(potionId);
                        btl_cmd.SetCounter(defender.Data, BattleCommandId.AutoPotion, potionId, defender.Id);
                        break;
                    }
                }
            }
            // Better auto-potions
            else
            {
                Byte betterPotionId = 0;

                foreach (Byte potionId in new[] { potion1Id, potion2Id })
                {
                    if (ff9item.FF9Item_GetCount(potionId) < 1)
                    {
                        continue;
                    }

                    CMD_DATA testCommand = new CMD_DATA
                    {
                        cmd_no = BattleCommandId.AutoPotion,
                        sub_no = potionId,
                        aa     = FF9StateSystem.Battle.FF9Battle.aa_data[0],
                        tar_id = defender.Id,
                        info   = new CMD_DATA.SELECT_INFO()
                    };

                    BattleCalculator    v       = new BattleCalculator(defender.Data, defender.Data, new BattleCommand(testCommand));
                    BattleScriptFactory factory = SBattleCalculator.FindScriptFactory(potionScriptId);
                    if (factory != null)
                    {
                        IBattleScript script = factory(v);
                        script.Perform();
                    }

                    Int16 heal = v.Target.HpDamage;
                    Int32 harm = v.Target.MaximumHp - v.Target.CurrentHp;

                    if (heal - harm > heal * overhealLimit / 100)
                    {
                        break;
                    }

                    betterPotionId = potionId;
                }

                if (betterPotionId != 0)
                {
                    UIManager.Battle.ItemRequest(betterPotionId);
                    btl_cmd.SetCounter(defender.Data, BattleCommandId.AutoPotion, betterPotionId, defender.Id);
                }
            }
        }