123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900 |
- /*
- * Copyright (C) 2004-2015 L2J DataPack
- *
- * This file is part of L2J DataPack.
- *
- * L2J DataPack is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * L2J DataPack is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package conquerablehalls.flagwar;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Map.Entry;
- import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
- import com.l2jserver.gameserver.ThreadPoolManager;
- import com.l2jserver.gameserver.ai.CtrlIntention;
- import com.l2jserver.gameserver.ai.L2SpecialSiegeGuardAI;
- import com.l2jserver.gameserver.data.sql.impl.ClanTable;
- import com.l2jserver.gameserver.model.L2Clan;
- import com.l2jserver.gameserver.model.L2ClanMember;
- import com.l2jserver.gameserver.model.L2SiegeClan;
- import com.l2jserver.gameserver.model.L2SiegeClan.SiegeClanType;
- import com.l2jserver.gameserver.model.L2Spawn;
- import com.l2jserver.gameserver.model.L2World;
- import com.l2jserver.gameserver.model.Location;
- import com.l2jserver.gameserver.model.TeleportWhereType;
- import com.l2jserver.gameserver.model.actor.L2Npc;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.entity.Siegable;
- import com.l2jserver.gameserver.model.entity.clanhall.ClanHallSiegeEngine;
- import com.l2jserver.gameserver.model.entity.clanhall.SiegeStatus;
- import com.l2jserver.gameserver.model.zone.type.L2ResidenceHallTeleportZone;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
- import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
- import com.l2jserver.gameserver.util.Broadcast;
- /**
- * @author BiggBoss
- */
- public abstract class FlagWar extends ClanHallSiegeEngine
- {
- private static final String SQL_LOAD_ATTACKERS = "SELECT * FROM siegable_hall_flagwar_attackers WHERE hall_id = ?";
- private static final String SQL_SAVE_ATTACKER = "INSERT INTO siegable_hall_flagwar_attackers_members VALUES (?,?,?)";
- private static final String SQL_LOAD_MEMEBERS = "SELECT object_id FROM siegable_hall_flagwar_attackers_members WHERE clan_id = ?";
- private static final String SQL_SAVE_CLAN = "INSERT INTO siegable_hall_flagwar_attackers VALUES(?,?,?,?)";
- private static final String SQL_SAVE_NPC = "UPDATE siegable_hall_flagwar_attackers SET npc = ? WHERE clan_id = ?";
- private static final String SQL_CLEAR_CLAN = "DELETE FROM siegable_hall_flagwar_attackers WHERE hall_id = ?";
- private static final String SQL_CLEAR_CLAN_ATTACKERS = "DELETE FROM siegable_hall_flagwar_attackers_members WHERE hall_id = ?";
-
- protected static int ROYAL_FLAG;
- protected static int FLAG_RED;
- protected static int FLAG_YELLOW;
- protected static int FLAG_GREEN;
- protected static int FLAG_BLUE;
- protected static int FLAG_PURPLE;
-
- protected static int ALLY_1;
- protected static int ALLY_2;
- protected static int ALLY_3;
- protected static int ALLY_4;
- protected static int ALLY_5;
-
- protected static int TELEPORT_1;
-
- protected static int MESSENGER;
-
- protected static int[] OUTTER_DOORS_TO_OPEN = new int[2];
- protected static int[] INNER_DOORS_TO_OPEN = new int[2];
- protected static Location[] FLAG_COORDS = new Location[7];
-
- protected static L2ResidenceHallTeleportZone[] TELE_ZONES = new L2ResidenceHallTeleportZone[6];
-
- protected static int QUEST_REWARD;
-
- protected static Location CENTER;
-
- protected Map<Integer, ClanData> _data = new HashMap<>(6);
- protected L2Clan _winner;
- private boolean _firstPhase;
-
- public FlagWar(String name, int hallId)
- {
- super(name, "conquerablehalls/flagwar", hallId);
- addStartNpc(MESSENGER);
- addFirstTalkId(MESSENGER);
- addTalkId(MESSENGER);
-
- for (int i = 0; i < 6; i++)
- {
- addFirstTalkId(TELEPORT_1 + i);
- }
-
- addKillId(ALLY_1);
- addKillId(ALLY_2);
- addKillId(ALLY_3);
- addKillId(ALLY_4);
- addKillId(ALLY_5);
-
- addSpawnId(ALLY_1);
- addSpawnId(ALLY_2);
- addSpawnId(ALLY_3);
- addSpawnId(ALLY_4);
- addSpawnId(ALLY_5);
-
- // If siege ends w/ more than 1 flag alive, winner is old owner
- _winner = ClanTable.getInstance().getClan(_hall.getOwnerId());
- }
-
- @Override
- public String onFirstTalk(L2Npc npc, L2PcInstance player)
- {
- String html = null;
- if (npc.getId() == MESSENGER)
- {
- if (!checkIsAttacker(player.getClan()))
- {
- L2Clan clan = ClanTable.getInstance().getClan(_hall.getOwnerId());
- String content = getHtm(player.getHtmlPrefix(), "messenger_initial.htm");
- content = content.replaceAll("%clanName%", (clan == null) ? "no owner" : clan.getName());
- content = content.replaceAll("%objectId%", String.valueOf(npc.getObjectId()));
- html = content;
- }
- else
- {
- html = "messenger_initial.htm";
- }
- }
- else
- {
- int index = npc.getId() - TELEPORT_1;
- if ((index == 0) && _firstPhase)
- {
- html = "teleporter_notyet.htm";
- }
- else
- {
- TELE_ZONES[index].checkTeleporTask();
- html = "teleporter.htm";
- }
- }
- return html;
- }
-
- @Override
- public synchronized String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
- {
- String html = event;
- L2Clan clan = player.getClan();
-
- if (event.startsWith("register_clan")) // Register the clan for the siege
- {
- if (!_hall.isRegistering())
- {
- if (_hall.isInSiege())
- {
- html = "messenger_registrationpassed.htm";
- }
- else
- {
- sendRegistrationPageDate(player);
- return null;
- }
- }
- else if ((clan == null) || !player.isClanLeader())
- {
- html = "messenger_notclannotleader.htm";
- }
- else if (getAttackers().size() >= 5)
- {
- html = "messenger_attackersqueuefull.htm";
- }
- else if (checkIsAttacker(clan))
- {
- html = "messenger_clanalreadyregistered.htm";
- }
- else if (_hall.getOwnerId() == clan.getId())
- {
- html = "messenger_curownermessage.htm";
- }
- else
- {
- String[] arg = event.split(" ");
- if (arg.length >= 2)
- {
- // Register passing the quest
- if (arg[1].equals("wQuest"))
- {
- if (player.destroyItemByItemId(_hall.getName() + " Siege", QUEST_REWARD, 1, npc, false)) // Quest passed
- {
- registerClan(clan);
- html = getFlagHtml(_data.get(clan.getId()).flag);
- }
- else
- {
- html = "messenger_noquest.htm";
- }
- }
- // Register paying the fee
- else if (arg[1].equals("wFee") && canPayRegistration())
- {
- if (player.reduceAdena(getName() + " Siege", 200000, npc, false)) // Fee payed
- {
- registerClan(clan);
- html = getFlagHtml(_data.get(clan.getId()).flag);
- }
- else
- {
- html = "messenger_nomoney.htm";
- }
- }
- }
- }
- }
- // Select the flag to defend
- else if (event.startsWith("select_clan_npc"))
- {
- if (!player.isClanLeader())
- {
- html = "messenger_onlyleaderselectally.htm";
- }
- else if (!_data.containsKey(clan.getId()))
- {
- html = "messenger_clannotregistered.htm";
- }
- else
- {
- String[] var = event.split(" ");
- if (var.length >= 2)
- {
- int id = 0;
- try
- {
- id = Integer.parseInt(var[1]);
- }
- catch (Exception e)
- {
- _log.warning(getName() + "->select_clan_npc->Wrong mahum warrior id: " + var[1]);
- }
- if ((id > 0) && ((html = getAllyHtml(id)) != null))
- {
- _data.get(clan.getId()).npc = id;
- saveNpc(id, clan.getId());
- }
- }
- else
- {
- _log.warning(getName() + " Siege: Not enough parameters to save clan npc for clan: " + clan.getName());
- }
- }
- }
- // View (and change ? ) the current selected mahum warrior
- else if (event.startsWith("view_clan_npc"))
- {
- ClanData cd = null;
- if (clan == null)
- {
- html = "messenger_clannotregistered.htm";
- }
- else if ((cd = _data.get(clan.getId())) == null)
- {
- html = "messenger_notclannotleader.htm";
- }
- else if (cd.npc == 0)
- {
- html = "messenger_leaderdidnotchooseyet.htm";
- }
- else
- {
- html = getAllyHtml(cd.npc);
- }
- }
- // Register a clan member for the fight
- else if (event.equals("register_member"))
- {
- if (clan == null)
- {
- html = "messenger_clannotregistered.htm";
- }
- else if (!_hall.isRegistering())
- {
- html = "messenger_registrationpassed.htm";
- }
- else if (!_data.containsKey(clan.getId()))
- {
- html = "messenger_notclannotleader.htm";
- }
- else if (_data.get(clan.getId()).players.size() >= 18)
- {
- html = "messenger_clanqueuefull.htm";
- }
- else
- {
- ClanData data = _data.get(clan.getId());
- data.players.add(player.getObjectId());
- saveMember(clan.getId(), player.getObjectId());
- if (data.npc == 0)
- {
- html = "messenger_leaderdidnotchooseyet.htm";
- }
- else
- {
- html = "messenger_clanregistered.htm";
- }
- }
- }
- // Show cur attacker list
- else if (event.equals("view_attacker_list"))
- {
- if (_hall.isRegistering())
- {
- sendRegistrationPageDate(player);
- }
- else
- {
- html = getHtm(player.getHtmlPrefix(), "messenger_registeredclans.htm");
- int i = 0;
- for (Entry<Integer, ClanData> clanData : _data.entrySet())
- {
- L2Clan attacker = ClanTable.getInstance().getClan(clanData.getKey());
- if (attacker == null)
- {
- continue;
- }
- html = html.replaceAll("%clan" + i + "%", clan.getName());
- html = html.replaceAll("%clanMem" + i + "%", String.valueOf(clanData.getValue().players.size()));
- i++;
- }
- if (_data.size() < 5)
- {
- for (int c = _data.size(); c < 5; c++)
- {
- html = html.replaceAll("%clan" + c + "%", "Empty pos. ");
- html = html.replaceAll("%clanMem" + c + "%", "Empty pos. ");
- }
- }
- }
- }
-
- return html;
- }
-
- @Override
- public synchronized String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
- {
- if (_hall.isInSiege())
- {
- final int npcId = npc.getId();
- for (int keys : _data.keySet())
- {
- if (_data.get(keys).npc == npcId)
- {
- removeParticipant(keys, true);
- }
- }
-
- synchronized (this)
- {
- // TODO: Zoey76: previous bad implementation.
- // Converting map.keySet() to List and map.values() to List doesn't ensure that
- // first element in the key's List correspond to the first element in the values' List
- // That's the reason that values aren't copied to a List, instead using _data.get(clanIds.get(0))
- final List<Integer> clanIds = new ArrayList<>(_data.keySet());
- if (_firstPhase)
- {
- // Siege ends if just 1 flag is alive
- // Hall was free before battle or owner didn't set the ally npc
- if (((clanIds.size() == 1) && (_hall.getOwnerId() <= 0)) || (_data.get(clanIds.get(0)).npc == 0))
- {
- _missionAccomplished = true;
- // _winner = ClanTable.getInstance().getClan(_data.keySet()[0]);
- // removeParticipant(_data.keySet()[0], false);
- cancelSiegeTask();
- endSiege();
- }
- else if ((_data.size() == 2) && (_hall.getOwnerId() > 0)) // Hall has defender (owner)
- {
- cancelSiegeTask(); // No time limit now
- _firstPhase = false;
- _hall.getSiegeZone().setIsActive(false);
- for (int doorId : INNER_DOORS_TO_OPEN)
- {
- _hall.openCloseDoor(doorId, true);
- }
-
- for (ClanData data : _data.values())
- {
- doUnSpawns(data);
- }
-
- ThreadPoolManager.getInstance().scheduleGeneral(() ->
- {
- for (int doorId : INNER_DOORS_TO_OPEN)
- {
- _hall.openCloseDoor(doorId, false);
- }
-
- for (Entry<Integer, ClanData> e : _data.entrySet())
- {
- doSpawns(e.getKey(), e.getValue());
- }
-
- _hall.getSiegeZone().setIsActive(true);
- }, 300000);
- }
- }
- else
- {
- _missionAccomplished = true;
- _winner = ClanTable.getInstance().getClan(clanIds.get(0));
- removeParticipant(clanIds.get(0), false);
- endSiege();
- }
- }
- }
- return null;
- }
-
- @Override
- public String onSpawn(L2Npc npc)
- {
- npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, CENTER);
- return null;
- }
-
- @Override
- public L2Clan getWinner()
- {
- return _winner;
- }
-
- @Override
- public void prepareOwner()
- {
- if (_hall.getOwnerId() > 0)
- {
- registerClan(ClanTable.getInstance().getClan(_hall.getOwnerId()));
- }
-
- _hall.banishForeigners();
- SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.REGISTRATION_TERM_FOR_S1_ENDED);
- msg.addString(getName());
- Broadcast.toAllOnlinePlayers(msg);
- _hall.updateSiegeStatus(SiegeStatus.WAITING_BATTLE);
-
- _siegeTask = ThreadPoolManager.getInstance().scheduleGeneral(new SiegeStarts(), 3600000);
- }
-
- @Override
- public void startSiege()
- {
- if (getAttackers().size() < 2)
- {
- onSiegeEnds();
- getAttackers().clear();
- _hall.updateNextSiege();
- SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.SIEGE_OF_S1_HAS_BEEN_CANCELED_DUE_TO_LACK_OF_INTEREST);
- sm.addString(_hall.getName());
- Broadcast.toAllOnlinePlayers(sm);
- return;
- }
-
- // Open doors for challengers
- for (int door : OUTTER_DOORS_TO_OPEN)
- {
- _hall.openCloseDoor(door, true);
- }
-
- // Teleport owner inside
- if (_hall.getOwnerId() > 0)
- {
- L2Clan owner = ClanTable.getInstance().getClan(_hall.getOwnerId());
- final Location loc = _hall.getZone().getSpawns().get(0); // Owner restart point
- for (L2ClanMember pc : owner.getMembers())
- {
- if (pc != null)
- {
- final L2PcInstance player = pc.getPlayerInstance();
- if ((player != null) && player.isOnline())
- {
- player.teleToLocation(loc, false);
- }
- }
- }
- }
-
- // Schedule open doors closement and siege start in 2 minutes
- ThreadPoolManager.getInstance().scheduleGeneral(new CloseOutterDoorsTask(FlagWar.super), 300000);
- }
-
- /**
- * Runnable class to schedule doors closing and siege start.
- * @author Zoey76
- */
- protected class CloseOutterDoorsTask implements Runnable
- {
- private final Siegable _siegable;
-
- protected CloseOutterDoorsTask(Siegable clanHallSiege)
- {
- _siegable = clanHallSiege;
- }
-
- @Override
- public void run()
- {
- for (int door : OUTTER_DOORS_TO_OPEN)
- {
- _hall.openCloseDoor(door, false);
- }
-
- _hall.getZone().banishNonSiegeParticipants();
-
- _siegable.startSiege();
- }
- }
-
- @Override
- public void onSiegeStarts()
- {
- for (Entry<Integer, ClanData> clan : _data.entrySet())
- {
- // Spawns challengers flags and npcs
- try
- {
- ClanData data = clan.getValue();
- doSpawns(clan.getKey(), data);
- fillPlayerList(data);
- }
- catch (Exception e)
- {
- endSiege();
- _log.warning(getName() + ": Problems in siege initialization!");
- e.printStackTrace();
- }
- }
- }
-
- @Override
- public void endSiege()
- {
- if (_hall.getOwnerId() > 0)
- {
- L2Clan clan = ClanTable.getInstance().getClan(_hall.getOwnerId());
- clan.setHideoutId(0);
- _hall.free();
- }
- super.endSiege();
- }
-
- @Override
- public void onSiegeEnds()
- {
- if (_data.size() > 0)
- {
- for (int clanId : _data.keySet())
- {
- if (_hall.getOwnerId() == clanId)
- {
- removeParticipant(clanId, false);
- }
- else
- {
- removeParticipant(clanId, true);
- }
- }
- }
- clearTables();
- }
-
- @Override
- public final Location getInnerSpawnLoc(final L2PcInstance player)
- {
- Location loc = null;
- if (player.getClanId() == _hall.getOwnerId())
- {
- loc = _hall.getZone().getSpawns().get(0);
- }
- else
- {
- ClanData cd = _data.get(player.getClanId());
- if (cd != null)
- {
- int index = cd.flag - FLAG_RED;
- if ((index >= 0) && (index <= 4))
- {
- loc = _hall.getZone().getChallengerSpawns().get(index);
- }
- else
- {
- throw new ArrayIndexOutOfBoundsException();
- }
- }
- }
- return loc;
- }
-
- @Override
- public final boolean canPlantFlag()
- {
- return false;
- }
-
- @Override
- public final boolean doorIsAutoAttackable()
- {
- return false;
- }
-
- void doSpawns(int clanId, ClanData data)
- {
- try
- {
- int index = 0;
- if (_firstPhase)
- {
- index = data.flag - FLAG_RED;
- }
- else
- {
- index = clanId == _hall.getOwnerId() ? 5 : 6;
- }
- Location loc = FLAG_COORDS[index];
-
- data.flagInstance = new L2Spawn(data.flag);
- data.flagInstance.setLocation(loc);
- data.flagInstance.setRespawnDelay(10000);
- data.flagInstance.setAmount(1);
- data.flagInstance.init();
-
- data.warrior = new L2Spawn(data.npc);
- data.warrior.setLocation(loc);
- data.warrior.setRespawnDelay(10000);
- data.warrior.setAmount(1);
- data.warrior.init();
- ((L2SpecialSiegeGuardAI) data.warrior.getLastSpawn().getAI()).getAlly().addAll(data.players);
- }
- catch (Exception e)
- {
- _log.warning(getName() + ": Couldnt make clan spawns: " + e.getMessage());
- e.printStackTrace();
- }
- }
-
- private void fillPlayerList(ClanData data)
- {
- for (int objId : data.players)
- {
- L2PcInstance plr = L2World.getInstance().getPlayer(objId);
- if (plr != null)
- {
- data.playersInstance.add(plr);
- }
- }
- }
-
- private void registerClan(L2Clan clan)
- {
- final int clanId = clan.getId();
-
- L2SiegeClan sc = new L2SiegeClan(clanId, SiegeClanType.ATTACKER);
- getAttackers().put(clanId, sc);
-
- ClanData data = new ClanData();
- data.flag = ROYAL_FLAG + _data.size();
- data.players.add(clan.getLeaderId());
- _data.put(clanId, data);
-
- saveClan(clanId, data.flag);
- saveMember(clanId, clan.getLeaderId());
- }
-
- private final void doUnSpawns(ClanData data)
- {
- if (data.flagInstance != null)
- {
- data.flagInstance.stopRespawn();
- data.flagInstance.getLastSpawn().deleteMe();
- }
- if (data.warrior != null)
- {
- data.warrior.stopRespawn();
- data.warrior.getLastSpawn().deleteMe();
- }
- }
-
- private final void removeParticipant(int clanId, boolean teleport)
- {
- ClanData dat = _data.remove(clanId);
-
- if (dat != null)
- {
- // Destroy clan flag
- if (dat.flagInstance != null)
- {
- dat.flagInstance.stopRespawn();
- if (dat.flagInstance.getLastSpawn() != null)
- {
- dat.flagInstance.getLastSpawn().deleteMe();
- }
- }
-
- if (dat.warrior != null)
- {
- // Destroy clan warrior
- dat.warrior.stopRespawn();
- if (dat.warrior.getLastSpawn() != null)
- {
- dat.warrior.getLastSpawn().deleteMe();
- }
- }
-
- dat.players.clear();
-
- if (teleport)
- {
- // Teleport players outside
- for (L2PcInstance pc : dat.playersInstance)
- {
- if (pc != null)
- {
- pc.teleToLocation(TeleportWhereType.TOWN);
- }
- }
- }
-
- dat.playersInstance.clear();
- }
- }
-
- public boolean canPayRegistration()
- {
- return true;
- }
-
- private void sendRegistrationPageDate(L2PcInstance player)
- {
- final NpcHtmlMessage msg = new NpcHtmlMessage();
- msg.setHtml(getHtm(player.getHtmlPrefix(), "siege_date.htm"));
- msg.replace("%nextSiege%", _hall.getSiegeDate().getTime().toString());
- player.sendPacket(msg);
- }
-
- public abstract String getFlagHtml(int flag);
-
- public abstract String getAllyHtml(int ally);
-
- @Override
- public final void loadAttackers()
- {
- try (Connection con = ConnectionFactory.getInstance().getConnection();
- PreparedStatement ps = con.prepareStatement(SQL_LOAD_ATTACKERS))
- {
- ps.setInt(1, _hall.getId());
- try (ResultSet rset = ps.executeQuery())
- {
- while (rset.next())
- {
- final int clanId = rset.getInt("clan_id");
-
- if (ClanTable.getInstance().getClan(clanId) == null)
- {
- _log.warning(getName() + ": Loaded an unexistent clan as attacker! Clan ID: " + clanId);
- continue;
- }
-
- ClanData data = new ClanData();
- data.flag = rset.getInt("flag");
- data.npc = rset.getInt("npc");
-
- _data.put(clanId, data);
- loadAttackerMembers(clanId);
- }
- }
- }
- catch (Exception e)
- {
- _log.warning(getName() + ".loadAttackers()->" + e.getMessage());
- }
- }
-
- private final void loadAttackerMembers(int clanId)
- {
- final List<Integer> listInstance = _data.get(clanId).players;
- if (listInstance == null)
- {
- _log.warning(getName() + ": Tried to load unregistered clan with ID " + clanId);
- return;
- }
-
- try (Connection con = ConnectionFactory.getInstance().getConnection();
- PreparedStatement ps = con.prepareStatement(SQL_LOAD_MEMEBERS))
- {
- ps.setInt(1, clanId);
- try (ResultSet rset = ps.executeQuery())
- {
- while (rset.next())
- {
- listInstance.add(rset.getInt("object_id"));
- }
- }
- }
- catch (Exception e)
- {
- _log.warning(getName() + ".loadAttackerMembers()->" + e.getMessage());
- }
- }
-
- private final void saveClan(int clanId, int flag)
- {
- try (Connection con = ConnectionFactory.getInstance().getConnection();
- PreparedStatement ps = con.prepareStatement(SQL_SAVE_CLAN))
- {
- ps.setInt(1, _hall.getId());
- ps.setInt(2, flag);
- ps.setInt(3, 0);
- ps.setInt(4, clanId);
- ps.execute();
- }
- catch (Exception e)
- {
- _log.warning(getName() + ".saveClan()->" + e.getMessage());
- }
- }
-
- private final void saveNpc(int npc, int clanId)
- {
- try (Connection con = ConnectionFactory.getInstance().getConnection();
- PreparedStatement ps = con.prepareStatement(SQL_SAVE_NPC))
- {
- ps.setInt(1, npc);
- ps.setInt(2, clanId);
- ps.execute();
- }
- catch (Exception e)
- {
- _log.warning(getName() + ".saveNpc()->" + e.getMessage());
- }
- }
-
- private final void saveMember(int clanId, int objectId)
- {
- try (Connection con = ConnectionFactory.getInstance().getConnection();
- PreparedStatement ps = con.prepareStatement(SQL_SAVE_ATTACKER))
- {
- ps.setInt(1, _hall.getId());
- ps.setInt(2, clanId);
- ps.setInt(3, objectId);
- ps.execute();
- }
- catch (Exception e)
- {
- _log.warning(getName() + ".saveMember()->" + e.getMessage());
- }
- }
-
- private void clearTables()
- {
- try (Connection con = ConnectionFactory.getInstance().getConnection();
- PreparedStatement ps1 = con.prepareStatement(SQL_CLEAR_CLAN);
- PreparedStatement ps2 = con.prepareStatement(SQL_CLEAR_CLAN_ATTACKERS))
- {
- ps1.setInt(1, _hall.getId());
- ps1.execute();
-
- ps2.setInt(1, _hall.getId());
- ps2.execute();
- }
- catch (Exception e)
- {
- _log.warning(getName() + ".clearTables()->" + e.getMessage());
- }
- }
-
- class ClanData
- {
- int flag = 0;
- int npc = 0;
- List<Integer> players = new ArrayList<>(18);
- List<L2PcInstance> playersInstance = new ArrayList<>(18);
- L2Spawn warrior = null;
- L2Spawn flagInstance = null;
- }
- }
|