package ai;
import java.util.*;
import l2.commons.util.Rnd;
import l2.gameserver.Announcements;
import l2.gameserver.ThreadPoolManager;
import l2.gameserver.ai.DefaultAI;
import l2.gameserver.model.instances.NpcInstance;
import l2.gameserver.network.l2.s2c.L2GameServerPacket;
import l2.gameserver.network.l2.s2c.MagicSkillUse;
import l2.gameserver.scripts.Functions;
import l2.gameserver.templates.StatsSet;
import l2.gameserver.utils.Location;
public class BlacksmithMammon extends DefaultAI {
private final int teleportPeriod;
private final List<Location> teleportLocations = new ArrayList<>();
private final Map<Integer, String> locationNames = new HashMap<>();
private long lastTeleportTime = System.currentTimeMillis();
private static final String DEFAULT_TELEPORTS =
"12655,-248700,-9576;" + //Catacomb forbiten path
"-20515,-251010,-8160;" + //Catacomb of Apostate
"-53145,-250500,-7904;" + //Catacomb of Heretic
"46288,170096,-4979;" + //Catacomb of Branded
"-19378,13264,-4899;" + //Catacomb dark omen
"140480,79472,-5427"; //Catacomb the wich
private static final String[] ANNOUNCE_MESSAGES = new String[]{
"1000431",
"1000432",
"1000433"
};
public BlacksmithMammon(NpcInstance actor) {
super(actor);
StatsSet params = actor.getTemplate().getAIParams();
String teleportData = params.getString("tele_loc", DEFAULT_TELEPORTS);
StringTokenizer tokenizer = new StringTokenizer(teleportData, ";");
while (tokenizer.hasMoreTokens()) {
teleportLocations.add(Location.parseLoc(tokenizer.nextToken()));
}
teleportPeriod = params.getInteger("teleport_period", 1800000);
locationNames.put(0, "Mammon blacksmith spawned on Catacomb forbiten path \n Мамон кузнец появился в Катакомбах Запретного пути");
locationNames.put(1, "Mammon blacksmith spawned on Catacomb of Apostate \n Мамон кузнец появился в Катакомбах отступников");
locationNames.put(2, "Mammon blacksmith spawned on Catacomb of Heretic \n Мамон кузнец появился в Катакомбах Еритиков");
locationNames.put(3, "Mammon blacksmith spawned on Catacomb of Branded \n Мамон кузнец появился в Катакомбах Отлученных");
locationNames.put(4, "Mammon blacksmith spawned on Catacomb of Dark Omen \n Мамон кузнец появился в Катакомбах Тёмного пророчества");
locationNames.put(5, "Mammon blacksmith spawned on Catacomb of the Wich \n Мамон кузнец появился в Катакомбах Ведьм");
}
@Override
protected boolean thinkActive() {
NpcInstance npc = getActor();
if (npc.isDead()) {
return true;
}
if (System.currentTimeMillis() - lastTeleportTime >= teleportPeriod) {
Location newLoc = teleportLocations.get(Rnd.get(teleportLocations.size()));
int index = teleportLocations.indexOf(newLoc);
if (!npc.getLoc().equals(newLoc)) {
ThreadPoolManager.getInstance().schedule(new DefaultAI.Teleport(newLoc, true), 1000L);
npc.broadcastPacketToOthers(new L2GameServerPacket[]{
new MagicSkillUse(npc, npc, 4671, 1, 1000, 0L)
});
lastTeleportTime = System.currentTimeMillis();
ThreadPoolManager.getInstance().schedule(() ->
Functions.npcShoutCustomMessage(npc, Rnd.get(ANNOUNCE_MESSAGES)), 5000L);
Announcements.getInstance().announceToAll(locationNames.get(index));
}
}
return false;
}
@Override
public boolean isGlobalAI() {
return true;
}
}