package l2n.game.scripts;
import gnu.trove.map.hash.THashMap;
import java.io.File;
import java.lang.reflect.Constructor;
import l2n.commons.compiler.Compiler;
import l2n.commons.compiler.MemoryClassLoader;
import l2n.commons.list.GArray;
import l2n.extensions.scripts.ScriptFileLoader;
import l2n.game.ai.Fighter;
import l2n.game.ai.Guard;
import l2n.game.ai.L2CharacterAI;
import l2n.game.ai.Mystic;
import l2n.game.ai.Priest;
import l2n.game.ai.RaceManager;
import l2n.game.ai.Ranger;
import l2n.game.ai.SiegeGuard;
import l2n.game.ai.SiegeGuardFighter;
import l2n.game.ai.SiegeGuardMystic;
import l2n.game.ai.SiegeGuardPriest;
import l2n.game.ai.SiegeGuardRanger;
import l2n.game.ai.Trap;
import l2n.game.model.actor.L2Character;
import l2n.game.scripts.ai.AncientEgg;
import l2n.game.scripts.ai.AttackMobNotPlayerFighter;
import l2n.game.scripts.ai.BehemothDragon;
import l2n.game.scripts.ai.CaughtFighter;
import l2n.game.scripts.ai.CaughtMystic;
import l2n.game.scripts.ai.CrystallineGolem;
import l2n.game.scripts.ai.DarkWaterDragon;
import l2n.game.scripts.ai.DeluLizardmanSpecialAgent;
import l2n.game.scripts.ai.DeluLizardmanSpecialCommander;
import l2n.game.scripts.ai.Elpy;
import l2n.game.scripts.ai.EvasGiftBox;
import l2n.game.scripts.ai.FafurionKindred;
import l2n.game.scripts.ai.FieldMachine;
import l2n.game.scripts.ai.ForgeOfGods;
import l2n.game.scripts.ai.FrightenedRagnaOrc;
import l2n.game.scripts.ai.FrostBuffalo;
import l2n.game.scripts.ai.GatekeeperZombie;
import l2n.game.scripts.ai.GhostOfVonHellmannsPage;
import l2n.game.scripts.ai.GraveRobberSummoner;
import l2n.game.scripts.ai.GuardRndWalkAndAnim;
import l2n.game.scripts.ai.GuardianAngel;
import l2n.game.scripts.ai.HotSpringsMob;
import l2n.game.scripts.ai.IsleOfPrayerFighter;
import l2n.game.scripts.ai.IsleOfPrayerMystic;
import l2n.game.scripts.ai.KarulBugbear;
import l2n.game.scripts.ai.KashasEye;
import l2n.game.scripts.ai.Keltirs;
import l2n.game.scripts.ai.Lavasaurus;
import l2n.game.scripts.ai.Leogul;
import l2n.game.scripts.ai.MoSMonk;
import l2n.game.scripts.ai.NightAgressionMystic;
import l2n.game.scripts.ai.NoRndWalkFighter;
import l2n.game.scripts.ai.NoRndWalkMystic;
import l2n.game.scripts.ai.OlMahumGeneral;
import l2n.game.scripts.ai.PaganGuard;
import l2n.game.scripts.ai.PrisonGuard;
import l2n.game.scripts.ai.Pronghorn;
import l2n.game.scripts.ai.Pterosaur;
import l2n.game.scripts.ai.RagnaHealer;
import l2n.game.scripts.ai.RndTeleportFighter;
import l2n.game.scripts.ai.RndWalkAndAnim;
import l2n.game.scripts.ai.Shade;
import l2n.game.scripts.ai.TarBeetle;
import l2n.game.scripts.ai.TimakOrcTroopLeader;
import l2n.game.scripts.ai.WatchmanMonster;
import l2n.game.scripts.ai.WitchWarder;
import l2n.game.scripts.ai.ZoneSwither;
import l2n.game.scripts.ai.event.HandysBlock;
import l2n.game.scripts.ai.event.Thomas;
import l2n.game.scripts.ai.grandboss.Antharas;
import l2n.game.scripts.ai.grandboss.Baium;
import l2n.game.scripts.ai.grandboss.BaiumNpc;
import l2n.game.scripts.ai.grandboss.Core;
import l2n.game.scripts.ai.grandboss.Orfen;
import l2n.game.scripts.ai.grandboss.Orfen_RibaIren;
import l2n.game.scripts.ai.grandboss.QueenAntNurse;
import l2n.game.scripts.ai.grandboss.Scarlet;
import l2n.game.scripts.ai.grandboss.Valakas;
import l2n.game.scripts.ai.grandboss.Zaken;
import l2n.game.scripts.ai.hellbound.BelethMinion;
import l2n.game.scripts.ai.hellbound.BelethSlave;
import l2n.game.scripts.ai.hellbound.BodyDestroyer;
import l2n.game.scripts.ai.hellbound.Challenger;
import l2n.game.scripts.ai.hellbound.Chimeras;
import l2n.game.scripts.ai.hellbound.ExperimentalGolem;
import l2n.game.scripts.ai.hellbound.FloatingGhost;
import l2n.game.scripts.ai.hellbound.InfinitumFighter;
import l2n.game.scripts.ai.hellbound.InfinitumMystic;
import l2n.game.scripts.ai.hellbound.MasterFestina;
import l2n.game.scripts.ai.hellbound.MasterZelos;
import l2n.game.scripts.ai.hellbound.MutatedElpy;
import l2n.game.scripts.ai.hellbound.NaiaSpore;
import l2n.game.scripts.ai.hellbound.Sandstorm;
import l2n.game.scripts.ai.hellbound.SoulCrystalPillar;
import l2n.game.scripts.ai.hellbound.SteelCitadelKeymaster;
import l2n.game.scripts.ai.hellbound.TorturedNative;
import l2n.game.scripts.ai.hellbound.TownGuard;
import l2n.game.scripts.ai.hellbound.TullyServant;
import l2n.game.scripts.ai.hellbound.TullyWarden;
import l2n.game.scripts.ai.kamaloka.Kama56Boss;
import l2n.game.scripts.ai.kamaloka.Kama56Minion;
import l2n.game.scripts.ai.kamaloka.Kama63Minion;
import l2n.game.scripts.ai.npc.AirshipGuard1;
import l2n.game.scripts.ai.npc.AirshipGuard2;
import l2n.game.scripts.ai.npc.Alhena;
import l2n.game.scripts.ai.npc.DaimonTheWhiteEyed;
import l2n.game.scripts.ai.npc.Edwin;
import l2n.game.scripts.ai.npc.EdwinFollower;
import l2n.game.scripts.ai.npc.EvilNpc;
import l2n.game.scripts.ai.npc.Jaradine;
import l2n.game.scripts.ai.npc.Kasiel;
import l2n.game.scripts.ai.npc.Kreed;
import l2n.game.scripts.ai.npc.Leandro;
import l2n.game.scripts.ai.npc.MercenaryCaptain;
import l2n.game.scripts.ai.npc.Remy;
import l2n.game.scripts.ai.npc.Rogin;
import l2n.game.scripts.ai.npc.Rokar;
import l2n.game.scripts.ai.npc.Rooney;
import l2n.game.scripts.ai.npc.SuspiciousMerchantAaru;
import l2n.game.scripts.ai.npc.SuspiciousMerchantAntharas;
import l2n.game.scripts.ai.npc.SuspiciousMerchantArchaic;
import l2n.game.scripts.ai.npc.SuspiciousMerchantBayou;
import l2n.game.scripts.ai.npc.SuspiciousMerchantBorderland;
import l2n.game.scripts.ai.npc.SuspiciousMerchantCloud;
import l2n.game.scripts.ai.npc.SuspiciousMerchantDemon;
import l2n.game.scripts.ai.npc.SuspiciousMerchantDragonspine;
import l2n.game.scripts.ai.npc.SuspiciousMerchantFloran;
import l2n.game.scripts.ai.npc.SuspiciousMerchantHive;
import l2n.game.scripts.ai.npc.SuspiciousMerchantHunters;
import l2n.game.scripts.ai.npc.SuspiciousMerchantIvoryTower;
import l2n.game.scripts.ai.npc.SuspiciousMerchantMarshland;
import l2n.game.scripts.ai.npc.SuspiciousMerchantMonastic;
import l2n.game.scripts.ai.npc.SuspiciousMerchantShanty;
import l2n.game.scripts.ai.npc.SuspiciousMerchantSouthernGludio;
import l2n.game.scripts.ai.npc.SuspiciousMerchantTanor;
import l2n.game.scripts.ai.npc.SuspiciousMerchantValley;
import l2n.game.scripts.ai.npc.SuspiciousMerchantWestern;
import l2n.game.scripts.ai.npc.SuspiciousMerchantWhiteSands;
import l2n.game.scripts.ai.npc.Tate;
import l2n.game.scripts.ai.npc.Taurin;
import l2n.game.scripts.ai.npc.Turnir;
import l2n.game.scripts.ai.npc.Yakand;
import l2n.game.scripts.ai.quests.EpicQuestAnakim;
import l2n.game.scripts.ai.quests.EpicQuestFighter;
import l2n.game.scripts.ai.quests.EpicQuestLilith;
import l2n.game.scripts.ai.quests.EpicQuestMage;
import l2n.game.scripts.ai.quests.Lematan;
import l2n.game.scripts.ai.quests.PailakaBoss;
import l2n.game.scripts.ai.quests.PailakaHelperFighter;
import l2n.game.scripts.ai.quests.PailakaHelperMystic;
import l2n.game.scripts.ai.quests.PailakaHelperRanger;
import l2n.game.scripts.ai.quests.PailakaInvader;
import l2n.game.scripts.ai.quests.Quest024Fighter;
import l2n.game.scripts.ai.quests.Quest024Mystic;
import l2n.game.scripts.ai.quests.Quest421FairyTree;
import l2n.game.scripts.ai.quests.SealDevice;
import l2n.game.scripts.ai.raidboss.Aenkinel;
import l2n.game.scripts.ai.raidboss.Baylor;
import l2n.game.scripts.ai.raidboss.Beleth;
import l2n.game.scripts.ai.raidboss.Darion;
import l2n.game.scripts.ai.raidboss.Darnel;
import l2n.game.scripts.ai.raidboss.DemonPrince;
import l2n.game.scripts.ai.raidboss.Epidos;
import l2n.game.scripts.ai.raidboss.Gordon;
import l2n.game.scripts.ai.raidboss.Kechi;
import l2n.game.scripts.ai.raidboss.QueenShyeed;
import l2n.game.scripts.ai.raidboss.Ranku;
import l2n.game.scripts.ai.raidboss.RankuScapegoat;
import l2n.game.scripts.ai.raidboss.Tears;
import l2n.game.scripts.ai.raidboss.Tully;
import l2n.game.scripts.ai.raidboss.Tyrannosaurus;
import l2n.game.scripts.ai.sod.DimensionMovingDevice;
import l2n.game.scripts.ai.sod.NoRndWalkMonster;
import l2n.game.scripts.ai.sod.Tiat;
import l2n.game.scripts.ai.soi.AbstractSOIMonster;
import l2n.game.scripts.ai.soi.Cohemenes;
import l2n.game.scripts.ai.soi.FeralHound;
import l2n.game.scripts.ai.soi.HallOfSufferingBoss;
import l2n.game.scripts.ai.soi.UnstableSeed;
import l2n.game.scripts.ai.stakato.BizarreCocoon;
import l2n.game.scripts.ai.stakato.FemaleSpikedStakato;
import l2n.game.scripts.ai.stakato.SpikedStakatoNurse;
import l2n.game.scripts.ai.stakato.StakatoCheif;
import l2n.game.scripts.ai.stakato.StakatoFollower;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author bloodshed (L2NextGen)
* @date 29.08.2011
* @time 9:58:13
*/
public class CharacterAILoader extends ScriptFileLoader
{
protected static final Logger _log = LoggerFactory.getLogger(CharacterAILoader.class.getName());
public final THashMap<String, Constructor<? extends L2CharacterAI>> ai_constructors;
public static CharacterAILoader getInstance()
{
return SingletonHolder._instance;
}
private CharacterAILoader()
{
ai_constructors = new THashMap<String, Constructor<? extends L2CharacterAI>>();
// загружаем
load(false);
ai_constructors.trimToSize();
}
public void load(final boolean reload)
{
if(reload)
ai_constructors.clear();
loadStaticAI();
final int count = loadCustomAI();
_log.info("CharacterAILoader: loaded " + ai_constructors.size() + " (" + count + " custom) AIs.");
}
/**
* Загружает AI которые в ядре
*/
private void loadStaticAI()
{
// Основные типы ИИ
loadConstructor("Fighter", Fighter.class);
loadConstructor("Guard", Guard.class);
loadConstructor("Mystic", Mystic.class);
loadConstructor("Priest", Priest.class);
loadConstructor("RaceManager", RaceManager.class);
loadConstructor("Ranger", Ranger.class);
loadConstructor("SiegeGuard", SiegeGuard.class);
loadConstructor("SiegeGuardFighter", SiegeGuardFighter.class);
loadConstructor("SiegeGuardMystic", SiegeGuardMystic.class);
loadConstructor("SiegeGuardPriest", SiegeGuardPriest.class);
loadConstructor("SiegeGuardRanger", SiegeGuardRanger.class);
loadConstructor("Trap", Trap.class);
// Дополнительные типы ИИ
loadConstructor("AirshipGuard1", AirshipGuard1.class);
loadConstructor("AirshipGuard2", AirshipGuard2.class);
// RaidBoss
loadConstructor("Aenkinel", Aenkinel.class);
loadConstructor("Antharas", Antharas.class);
loadConstructor("Baium", Baium.class);
loadConstructor("BaiumNpc", BaiumNpc.class);
loadConstructor("Baylor", Baylor.class);
loadConstructor("Darnel", Darnel.class);
loadConstructor("Core", Core.class);
loadConstructor("Gordon", Gordon.class);
loadConstructor("RankuScapegoat", RankuScapegoat.class);
loadConstructor("Orfen", Orfen.class);
loadConstructor("Orfen_RibaIren", Orfen_RibaIren.class);
loadConstructor("Tears", Tears.class);
loadConstructor("Tiat", Tiat.class);
loadConstructor("Tyrannosaurus", Tyrannosaurus.class);
loadConstructor("Valakas", Valakas.class);
loadConstructor("Zaken", Zaken.class);
loadConstructor("Alhena", Alhena.class);
loadConstructor("AncientEgg", AncientEgg.class);
loadConstructor("AttackMobNotPlayerFighter", AttackMobNotPlayerFighter.class);
loadConstructor("BehemothDragon", BehemothDragon.class);
loadConstructor("BodyDestroyer", BodyDestroyer.class);
loadConstructor("CaughtFighter", CaughtFighter.class);
loadConstructor("CaughtMystic", CaughtMystic.class);
loadConstructor("Chimeras", Chimeras.class);
loadConstructor("CrystallineGolem", CrystallineGolem.class);
loadConstructor("DaimonTheWhiteEyed", DaimonTheWhiteEyed.class);
loadConstructor("DarkWaterDragon", DarkWaterDragon.class);
loadConstructor("DeluLizardmanSpecialAgent", DeluLizardmanSpecialAgent.class);
loadConstructor("DeluLizardmanSpecialCommander", DeluLizardmanSpecialCommander.class);
loadConstructor("DimensionMovingDevice", DimensionMovingDevice.class);
loadConstructor("Edwin", Edwin.class);
loadConstructor("EdwinFollower", EdwinFollower.class);
loadConstructor("Elpy", Elpy.class);
loadConstructor("EvasGiftBox", EvasGiftBox.class);
loadConstructor("EvilNpc", EvilNpc.class);
loadConstructor("FafurionKindred", FafurionKindred.class);
loadConstructor("FieldMachine", FieldMachine.class);
loadConstructor("FrightenedRagnaOrc", FrightenedRagnaOrc.class);
loadConstructor("FrostBuffalo", FrostBuffalo.class);
loadConstructor("GatekeeperZombie", GatekeeperZombie.class);
loadConstructor("GhostOfVonHellmannsPage", GhostOfVonHellmannsPage.class);
loadConstructor("GraveRobberSummoner", GraveRobberSummoner.class);
loadConstructor("GuardianAngel", GuardianAngel.class);
loadConstructor("GuardRndWalkAndAnim", GuardRndWalkAndAnim.class);
// AI для Seed Of Infinity
loadConstructor("HallOfSufferingBoss", HallOfSufferingBoss.class);
loadConstructor("Cohemenes", Cohemenes.class);
loadConstructor("UnstableSeed", UnstableSeed.class);
loadConstructor("AbstractSOIMonster", AbstractSOIMonster.class);
loadConstructor("FeralHound", FeralHound.class);
loadConstructor("HotSpringsMob", HotSpringsMob.class);
loadConstructor("InfinitumFighter", InfinitumFighter.class);
loadConstructor("InfinitumMystic", InfinitumMystic.class);
loadConstructor("IsleOfPrayerFighter", IsleOfPrayerFighter.class);
loadConstructor("IsleOfPrayerMystic", IsleOfPrayerMystic.class);
loadConstructor("Jaradine", Jaradine.class);
loadConstructor("Kama56Boss", Kama56Boss.class);
loadConstructor("Kama56Minion", Kama56Minion.class);
loadConstructor("Kama63Minion", Kama63Minion.class);
loadConstructor("KarulBugbear", KarulBugbear.class);
loadConstructor("KashasEye", KashasEye.class);
loadConstructor("Kasiel", Kasiel.class);
loadConstructor("Keltirs", Keltirs.class);
loadConstructor("Kreed", Kreed.class);
loadConstructor("Leandro", Leandro.class);
loadConstructor("Leogul", Leogul.class);
loadConstructor("MercenaryCaptain", MercenaryCaptain.class);
loadConstructor("MoSMonk", MoSMonk.class);
loadConstructor("NightAgressionMystic", NightAgressionMystic.class);
loadConstructor("NoRndWalkFighter", NoRndWalkFighter.class);
loadConstructor("NoRndWalkMystic", NoRndWalkMystic.class);
loadConstructor("NoRndWalkMonster", NoRndWalkMonster.class);
loadConstructor("OlMahumGeneral", OlMahumGeneral.class);
loadConstructor("PaganGuard", PaganGuard.class);
loadConstructor("PrisonGuard", PrisonGuard.class);
loadConstructor("Pronghorn", Pronghorn.class);
loadConstructor("Pterosaur", Pterosaur.class);
loadConstructor("QueenAntNurse", QueenAntNurse.class);
loadConstructor("RagnaHealer", RagnaHealer.class);
loadConstructor("Remy", Remy.class);
loadConstructor("RndTeleportFighter", RndTeleportFighter.class);
loadConstructor("RndWalkAndAnim", RndWalkAndAnim.class);
loadConstructor("Rogin", Rogin.class);
loadConstructor("Rokar", Rokar.class);
loadConstructor("Rooney", Rooney.class);
loadConstructor("Sandstorm", Sandstorm.class);
loadConstructor("Scarlet", Scarlet.class);
loadConstructor("Shade", Shade.class);
loadConstructor("SteelCitadelKeymaster", SteelCitadelKeymaster.class);
loadConstructor("SuspiciousMerchantAaru", SuspiciousMerchantAaru.class);
loadConstructor("SuspiciousMerchantAntharas", SuspiciousMerchantAntharas.class);
loadConstructor("SuspiciousMerchantArchaic", SuspiciousMerchantArchaic.class);
loadConstructor("SuspiciousMerchantBayou", SuspiciousMerchantBayou.class);
loadConstructor("SuspiciousMerchantBorderland", SuspiciousMerchantBorderland.class);
loadConstructor("SuspiciousMerchantCloud", SuspiciousMerchantCloud.class);
loadConstructor("SuspiciousMerchantDemon", SuspiciousMerchantDemon.class);
loadConstructor("SuspiciousMerchantDragonspine", SuspiciousMerchantDragonspine.class);
loadConstructor("SuspiciousMerchantFloran", SuspiciousMerchantFloran.class);
loadConstructor("SuspiciousMerchantHive", SuspiciousMerchantHive.class);
loadConstructor("SuspiciousMerchantHunters", SuspiciousMerchantHunters.class);
loadConstructor("SuspiciousMerchantIvoryTower", SuspiciousMerchantIvoryTower.class);
loadConstructor("SuspiciousMerchantMarshland", SuspiciousMerchantMarshland.class);
loadConstructor("SuspiciousMerchantMonastic", SuspiciousMerchantMonastic.class);
loadConstructor("SuspiciousMerchantShanty", SuspiciousMerchantShanty.class);
loadConstructor("SuspiciousMerchantSouthernGludio", SuspiciousMerchantSouthernGludio.class);
loadConstructor("SuspiciousMerchantTanor", SuspiciousMerchantTanor.class);
loadConstructor("SuspiciousMerchantValley", SuspiciousMerchantValley.class);
loadConstructor("SuspiciousMerchantWestern", SuspiciousMerchantWestern.class);
loadConstructor("SuspiciousMerchantWhiteSands", SuspiciousMerchantWhiteSands.class);
loadConstructor("Tate", Tate.class);
loadConstructor("Taurin", Taurin.class);
loadConstructor("Thomas", Thomas.class);
loadConstructor("TimakOrcTroopLeader", TimakOrcTroopLeader.class);
loadConstructor("TorturedNative", TorturedNative.class);
loadConstructor("TownGuard", TownGuard.class);
loadConstructor("Turnir", Turnir.class);
loadConstructor("WatchmanMonster", WatchmanMonster.class);
loadConstructor("WitchWarder", WitchWarder.class);
loadConstructor("Yakand", Yakand.class);
// AI для монстров в Forge of Gods
loadConstructor("ForgeOfGods", ForgeOfGods.class);
loadConstructor("TarBeetle", TarBeetle.class);
loadConstructor("Lavasaurus", Lavasaurus.class);
// AI для монстров в Stakato
loadConstructor("QueenShyeed", QueenShyeed.class);
loadConstructor("StakatoCheif", StakatoCheif.class);
loadConstructor("BizarreCocoon", BizarreCocoon.class);
loadConstructor("FemaleSpikedStakato", FemaleSpikedStakato.class);
loadConstructor("SpikedStakatoNurse", SpikedStakatoNurse.class);
loadConstructor("StakatoFollower", StakatoFollower.class);
// Различные квесты
loadConstructor("Quest024Fighter", Quest024Fighter.class);
loadConstructor("Quest024Mystic", Quest024Mystic.class);
loadConstructor("Quest421FairyTree", Quest421FairyTree.class);
loadConstructor("EpicQuestLilith", EpicQuestLilith.class);
loadConstructor("EpicQuestAnakim", EpicQuestAnakim.class);
loadConstructor("EpicQuestMage", EpicQuestMage.class);
loadConstructor("EpicQuestFighter", EpicQuestFighter.class);
loadConstructor("SealDevice", SealDevice.class);
// FIXME конструктор тут другой, можно не грузить loadConstructor("GuardsOfDawn", GuardsOfDawn.class);
loadConstructor("Lematan", Lematan.class);
loadConstructor("PailakaBoss", PailakaBoss.class);
loadConstructor("PailakaInvader", PailakaInvader.class);
loadConstructor("PailakaHelperFighter", PailakaHelperFighter.class);
loadConstructor("PailakaHelperMystic", PailakaHelperMystic.class);
loadConstructor("PailakaHelperRanger", PailakaHelperRanger.class);
// Hellbound
loadConstructor("Darion", Darion.class);
loadConstructor("DemonPrince", DemonPrince.class);
loadConstructor("Ranku", Ranku.class);
loadConstructor("Kechi", Kechi.class);
loadConstructor("MasterZelos", MasterZelos.class);
loadConstructor("MasterFestina", MasterFestina.class);
loadConstructor("Tully", Tully.class);
loadConstructor("TullyWarden", TullyWarden.class);
loadConstructor("TullyServant", TullyServant.class);
loadConstructor("ExperimentalGolem", ExperimentalGolem.class);
loadConstructor("FloatingGhost", FloatingGhost.class);
loadConstructor("SoulCrystalPillar", SoulCrystalPillar.class);
loadConstructor("Challenger", Challenger.class);
loadConstructor("MutatedElpy", MutatedElpy.class);
loadConstructor("BelethSlave", BelethSlave.class);
loadConstructor("NaiaSpore", NaiaSpore.class);
loadConstructor("Epidos", Epidos.class);
loadConstructor("Beleth", Beleth.class);
loadConstructor("BelethMinion", BelethMinion.class);
loadConstructor("ZoneSwither", ZoneSwither.class);
// event Handys Block Checker
loadConstructor("HandysBlock", HandysBlock.class);
}
private int loadCustomAI()
{
final GArray<File> ai_files = new GArray<File>();
parseClasses(new File("./data/scripts/ai"), ai_files);
if(Compiler.getInstance().compile(ai_files, System.out))
{
int count = 0;
final MemoryClassLoader classLoader = Compiler.getInstance().getClassLoader();
for(final String name : classLoader.getClasses())
{
if(name.contains("$"))
continue; // пропускаем вложенные классы
try
{
@SuppressWarnings("unchecked")
final Class<? extends L2CharacterAI> c = (Class<? extends L2CharacterAI>) classLoader.loadClass(name);
if(loadConstructor(c))
count++;
}
catch(final Exception e)
{
_log.warn("Can't load custom AI script class[" + name + "]:" + e.getMessage());
}
}
Compiler.getInstance().clearClassLoader();
return count;
}
else
_log.warn("Can't compile custom AI scripts!");
return 0;
}
protected void loadConstructor(final String nameAI, final Class<? extends L2CharacterAI> c)
{
Constructor<? extends L2CharacterAI> constructor = null;
try
{
constructor = c.getConstructor(L2Character.class);
}
catch(final SecurityException e)
{
_log.warn("", e);
}
catch(final NoSuchMethodException e)
{
// _log.warn("", e);
}
if(constructor != null)
ai_constructors.put(nameAI, constructor);
}
protected boolean loadConstructor(final Class<? extends L2CharacterAI> c)
{
Constructor<? extends L2CharacterAI> constructor = null;
try
{
constructor = c.getConstructor(L2Character.class);
}
catch(final SecurityException e)
{
_log.warn("", e);
}
catch(final NoSuchMethodException e)
{
// _log.warn("", e);
}
if(constructor != null)
{
ai_constructors.put(c.getSimpleName(), constructor);
return true;
}
return false;
}
/**
* @param aiType
* - название AI
* @return true если AI с таким названием есть
*/
public boolean isAvailable(final String aiType)
{
return ai_constructors.containsKey(aiType);
}
public L2CharacterAI getAI(final String aiType, final L2Character actor)
{
final Constructor<? extends L2CharacterAI> constructor = ai_constructors.get(aiType);
if(constructor != null)
try
{
return constructor.newInstance(actor);
}
catch(final Exception e)
{
_log.error("CharacterAILoader getAI error: ", e);
return null;
}
return null;
}
@Override
protected boolean checkFileCondition(final File file, final boolean dir)
{
if(dir)
{
if(file.isHidden() || file.getName().equals(".svn"))
return false;
}
else if(file.isHidden() || !file.getName().contains(".java"))
return false;
return true;
}
@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
private static final CharacterAILoader _instance = new CharacterAILoader();
}
}