private static void ProcessBattleScript(Type type, Result result, Object attribute) { BattleScriptAttribute bsa = (BattleScriptAttribute)attribute; ConstructorInfo constructor = type.GetConstructor(new[] { TypeCache <BattleCalculator> .Type }); DynamicMethod dm = Expressions.MakeConstructor <BattleCalculator>(type, constructor); BattleScriptFactory factory = (BattleScriptFactory)dm.CreateDelegate(TypeCache <BattleScriptFactory> .Type); if (bsa.Id < result.BattleBaseScripts.Length && bsa.Id >= 0) { result.BattleBaseScripts[bsa.Id] = factory; } else { result.BattleExtendedScripts[bsa.Id] = factory; } }
internal static void CalcMain(BTL_DATA caster, BTL_DATA target, BattleCommand command, Byte scriptId) { BattleCalculator v = new BattleCalculator(caster, target, command); BattleScriptFactory factory = FindScriptFactory(scriptId); if (factory != null) { IBattleScript script = factory(v); script.Perform(); } else { Log.Warning($"Unknown script id: {scriptId}"); } if (caster != null && target != null) { CalcResult(v); } }
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); } } }