Advertisement
Guest User

Engine L2jKamui

a guest
Aug 30th, 2017
2,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 480.51 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P Gameserver
  3. Index: java/net/sf/l2j/gameserver/model/entity/CursedWeapon.java
  4. ===================================================================
  5. --- java/net/sf/l2j/gameserver/model/entity/CursedWeapon.java   (revision 1)
  6. +++ java/net/sf/l2j/gameserver/model/entity/CursedWeapon.java   (working copy)
  7. @@ -10,7 +10,7 @@
  8.  
  9.  import net.sf.l2j.commons.concurrent.ThreadPool;
  10.  import net.sf.l2j.commons.random.Rnd;
  11. -
  12. +import net.sf.l2j.Config;
  13.  import net.sf.l2j.L2DatabaseFactory;
  14.  import net.sf.l2j.gameserver.datatables.ItemTable;
  15.  import net.sf.l2j.gameserver.datatables.SkillTable;
  16. @@ -20,6 +20,8 @@
  17.  import net.sf.l2j.gameserver.model.actor.Attackable;
  18.  import net.sf.l2j.gameserver.model.actor.Character;
  19.  import net.sf.l2j.gameserver.model.actor.instance.Player;
  20. +import net.sf.l2j.gameserver.model.entity.engine.CTF;
  21. +import net.sf.l2j.gameserver.model.entity.engine.TvT;
  22.  import net.sf.l2j.gameserver.model.group.Party.MessageType;
  23.  import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
  24.  import net.sf.l2j.gameserver.network.SystemMessageId;
  25. @@ -463,7 +465,15 @@
  26.             player.dropItem("InvDrop", item, null, true);
  27.             return;
  28.         }
  29. -      
  30. +
  31. +       if ((player._inEventTvT && !Config.TVT_JOIN_CURSED) || (player._inEventCTF && !Config.CTF_JOIN_CURSED))
  32. +       {
  33. +           if (player._inEventTvT)
  34. +               TvT.removePlayer(player);
  35. +           if (player._inEventCTF)
  36. +               CTF.removePlayer(player);
  37. +       }
  38. +
  39.         _isActivated = true;
  40.        
  41.         // Hold player data.
  42. Index: java/net/sf/l2j/gameserver/model/entity/engine/EventHandlerCtf.java
  43. ===================================================================
  44. --- java/net/sf/l2j/gameserver/model/entity/engine/EventHandlerCtf.java (revision 0)
  45. +++ java/net/sf/l2j/gameserver/model/entity/engine/EventHandlerCtf.java (working copy)
  46. @@ -0,0 +1,92 @@
  47. +/*
  48. + * This program is free software: you can redistribute it and/or modify it under
  49. + * the terms of the GNU General Public License as published by the Free Software
  50. + * Foundation, either version 3 of the License, or (at your option) any later
  51. + * version.
  52. + *
  53. + * This program is distributed in the hope that it will be useful, but WITHOUT
  54. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  55. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  56. + * details.
  57. + *
  58. + * You should have received a copy of the GNU General Public License along with
  59. + * this program. If not, see <http://www.gnu.org/licenses/>.
  60. + */
  61. +package net.sf.l2j.gameserver.model.entity.engine;
  62. +
  63. +import java.util.ArrayList;
  64. +import java.util.Calendar;
  65. +import java.util.List;
  66. +import java.util.logging.Logger;
  67. +
  68. +import net.sf.l2j.Config;
  69. +import net.sf.l2j.commons.concurrent.ThreadPool;
  70. +;
  71. +
  72. +/**
  73. + * @author Boorinio
  74. + */
  75. +public class EventHandlerCtf
  76. +{
  77. +   private static final Logger _log = Logger.getLogger(EventHandlerCtf.class.getName());
  78. +   public List<Long> datesCtf = new ArrayList<>();
  79. +  
  80. +   public void startHandler()
  81. +   {
  82. +       loadConfisCtf(false);
  83. +       getNextTimeStampCTF();
  84. +       _log.info(EventHandlerCtf.class.getSimpleName() + ": Ctf handler initiated");
  85. +   }
  86. +  
  87. +   public void loadConfisCtf(boolean NextDay)
  88. +   {
  89. +       datesCtf.clear();
  90. +       for (String times : Config.CTF_EVENT_TIMES.split(","))
  91. +       {
  92. +           String[] timesSplited = times.split(":");
  93. +           int hour = Integer.parseInt(timesSplited[0]);
  94. +           int minute = Integer.parseInt(timesSplited[1]);
  95. +           Calendar time = Calendar.getInstance();
  96. +           if (!NextDay)
  97. +           {
  98. +               time.set(Calendar.HOUR_OF_DAY, hour);
  99. +               time.set(Calendar.MINUTE, minute);
  100. +           }
  101. +           else
  102. +           {
  103. +               time.set(Calendar.DAY_OF_MONTH, Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + 1);
  104. +               time.set(Calendar.HOUR_OF_DAY, hour);
  105. +               time.set(Calendar.MINUTE, minute);
  106. +           }
  107. +           datesCtf.add(time.getTimeInMillis());
  108. +       }
  109. +   }
  110. +  
  111. +   public void getNextTimeStampCTF()
  112. +   {
  113. +       boolean found = false;
  114. +       for (Long stamp : datesCtf)
  115. +       {
  116. +           if (stamp > System.currentTimeMillis())
  117. +           {
  118. +               ThreadPool.schedule(new Runnable()
  119. +               {
  120. +                   @Override
  121. +                   public void run()
  122. +                   {
  123. +                       CTF.loadData();
  124. +                       CTF.autoEvent();
  125. +                       getNextTimeStampCTF();
  126. +                   }
  127. +               }, stamp - System.currentTimeMillis());
  128. +               found = true;
  129. +               break;
  130. +           }
  131. +       }
  132. +       if (!found)
  133. +       {
  134. +           loadConfisCtf(true);
  135. +           getNextTimeStampCTF();
  136. +       }
  137. +   }
  138. +}
  139. Index: java/net/sf/l2j/gameserver/model/L2Skill.java
  140. ===================================================================
  141. --- java/net/sf/l2j/gameserver/model/L2Skill.java   (revision 3)
  142. +++ java/net/sf/l2j/gameserver/model/L2Skill.java   (working copy)
  143. @@ -6,6 +6,7 @@
  144.  import java.util.StringTokenizer;
  145.  import java.util.logging.Logger;
  146.  
  147. +import net.sf.l2j.Config;
  148.  import net.sf.l2j.commons.util.ArraysUtil;
  149.  import net.sf.l2j.gameserver.datatables.SkillTable;
  150.  import net.sf.l2j.gameserver.datatables.SkillTreeTable;
  151. @@ -23,6 +24,9 @@
  152.  import net.sf.l2j.gameserver.model.actor.instance.Player;
  153.  import net.sf.l2j.gameserver.model.actor.instance.Servitor;
  154.  import net.sf.l2j.gameserver.model.actor.instance.SiegeFlag;
  155. +import net.sf.l2j.gameserver.model.entity.engine.CTF;
  156. +import net.sf.l2j.gameserver.model.entity.engine.DM;
  157. +import net.sf.l2j.gameserver.model.entity.engine.TvT;
  158.  import net.sf.l2j.gameserver.model.group.Party;
  159.  import net.sf.l2j.gameserver.model.holder.IntIntHolder;
  160.  import net.sf.l2j.gameserver.model.item.kind.Armor;
  161. @@ -1659,6 +1663,17 @@
  162.                                 continue;
  163.                         }
  164.                        
  165. +                       //check if allow interference is allowed if player is not on event but target is on event
  166. +                       if (((TvT._started && !Config.TVT_ALLOW_INTERFERENCE) || (CTF._started && !Config.CTF_ALLOW_INTERFERENCE) || (DM._started && !Config.DM_ALLOW_INTERFERENCE)))
  167. +                       {
  168. +                           if ((obj._inEventTvT && !player._inEventTvT) || (!obj._inEventTvT && player._inEventTvT))
  169. +                               continue;
  170. +                           if ((obj._inEventCTF && !player._inEventCTF) || (!obj._inEventCTF && player._inEventCTF))
  171. +                               continue;
  172. +                           else if ((obj._inEventDM && !player._inEventDM) || (!obj._inEventDM && player._inEventDM))
  173. +                               continue;
  174. +                       }
  175. +                      
  176.                         if (!player.checkPvpSkill(obj, this))
  177.                             continue;
  178.                        
  179. @@ -1983,7 +1998,7 @@
  180.                 {
  181.                     final Summon targetSummon = (Summon) target;
  182.                     final Player summonOwner = targetSummon.getActingPlayer();
  183. -                              
  184. +                  
  185.                     if (activeChar instanceof Player && activeChar.getPet() != targetSummon && !targetSummon.isDead() && (summonOwner.getPvpFlag() != 0 || summonOwner.getKarma() > 0) || (summonOwner.isInsideZone(ZoneId.PVP) && activeChar.isInsideZone(ZoneId.PVP)) || (summonOwner.isInDuel() && ((Player) activeChar).isInDuel() && summonOwner.getDuelId() == ((Player) activeChar).getDuelId()))
  186.                         return new Character[]
  187.                             {
  188. Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java
  189. ===================================================================
  190. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java    (revision 1)
  191. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java    (working copy)
  192. @@ -50,7 +50,13 @@
  193.             sendPacket(RestartResponse.valueOf(false));
  194.             return;
  195.         }
  196. -      
  197. +
  198. +       if (player._inEventTvT)
  199. +       {
  200. +           player.sendMessage("You may not use an escape skill in a Event.");
  201. +           return;
  202. +       }
  203. +
  204.         player.removeFromBossZone();
  205.        
  206.         final L2GameClient client = getClient();
  207. Index: java/net/sf/l2j/util/EventData.java
  208. ===================================================================
  209. --- java/net/sf/l2j/util/EventData.java (revision 0)
  210. +++ java/net/sf/l2j/util/EventData.java (working copy)
  211. @@ -0,0 +1,43 @@
  212. +/*
  213. + * This program is free software: you can redistribute it and/or modify it under
  214. + * the terms of the GNU General Public License as published by the Free Software
  215. + * Foundation, either version 3 of the License, or (at your option) any later
  216. + * version.
  217. + *
  218. + * This program is distributed in the hope that it will be useful, but WITHOUT
  219. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  220. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  221. + * details.
  222. + *
  223. + * You should have received a copy of the GNU General Public License along with
  224. + * this program. If not, see <http://www.gnu.org/licenses/>.
  225. + */
  226. +package net.sf.l2j.util;
  227. +
  228. +import java.util.LinkedList;
  229. +
  230. +public class EventData
  231. +{
  232. +   public int eventX;
  233. +   public int eventY;
  234. +   public int eventZ;
  235. +   public int eventKarma;
  236. +   public int eventPvpKills;
  237. +   public int eventPkKills;
  238. +   public String eventTitle;
  239. +   public LinkedList<String> kills = new LinkedList<>();
  240. +   public boolean eventSitForced = false;
  241. +
  242. +   public EventData(int pEventX, int pEventY, int pEventZ, int pEventkarma, int pEventpvpkills, int pEventpkkills, String pEventTitle, LinkedList<String> pKills, boolean pEventSitForced)
  243. +   {
  244. +       eventX = pEventX;
  245. +       eventY = pEventY;
  246. +       eventZ = pEventZ;
  247. +       eventKarma = pEventkarma;
  248. +       eventPvpKills = pEventpvpkills;
  249. +       eventPkKills = pEventpkkills;
  250. +       eventTitle = pEventTitle;
  251. +       kills = pKills;
  252. +       eventSitForced = pEventSitForced;
  253. +   }
  254. +}
  255. \ No newline at end of file
  256. Index: java/net/sf/l2j/gameserver/network/clientpackets/Logout.java
  257. ===================================================================
  258. --- java/net/sf/l2j/gameserver/network/clientpackets/Logout.java    (revision 3)
  259. +++ java/net/sf/l2j/gameserver/network/clientpackets/Logout.java    (working copy)
  260. @@ -5,6 +5,7 @@
  261.  import net.sf.l2j.gameserver.model.zone.ZoneId;
  262.  import net.sf.l2j.gameserver.network.SystemMessageId;
  263.  import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  264. +import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  265.  import net.sf.l2j.gameserver.taskmanager.AttackStanceTaskManager;
  266.  
  267.  public final class Logout extends L2GameClientPacket
  268. @@ -47,7 +48,13 @@
  269.             player.sendPacket(ActionFailed.STATIC_PACKET);
  270.             return;
  271.         }
  272. -      
  273. +
  274. +       if (player.atEvent)
  275. +       {
  276. +           player.sendPacket(SystemMessage.sendString("A superior power doesn't allow you to leave the event."));
  277. +           return;
  278. +       }
  279. +
  280.         player.removeFromBossZone();
  281.         player.logout();
  282.     }
  283. Index: java/net/sf/l2j/gameserver/network/clientpackets/UseItem.java
  284. ===================================================================
  285. --- java/net/sf/l2j/gameserver/network/clientpackets/UseItem.java   (revision 3)
  286. +++ java/net/sf/l2j/gameserver/network/clientpackets/UseItem.java   (working copy)
  287. @@ -183,6 +183,12 @@
  288.                 return;
  289.             }
  290.            
  291. +           else if (activeChar._haveFlagCTF)
  292. +           {
  293. +               activeChar.sendMessage("You can't equip an item while holding the flag");
  294. +               return;
  295. +           }
  296. +          
  297.             switch (item.getItem().getBodyPart())
  298.             {
  299.                 case Item.SLOT_LR_HAND:
  300. Index: java/net/sf/l2j/gameserver/network/L2GameClient.java
  301. ===================================================================
  302. --- java/net/sf/l2j/gameserver/network/L2GameClient.java    (revision 1)
  303. +++ java/net/sf/l2j/gameserver/network/L2GameClient.java    (working copy)
  304. @@ -17,7 +17,6 @@
  305.  import net.sf.l2j.commons.mmocore.MMOClient;
  306.  import net.sf.l2j.commons.mmocore.MMOConnection;
  307.  import net.sf.l2j.commons.mmocore.ReceivablePacket;
  308. -
  309.  import net.sf.l2j.Config;
  310.  import net.sf.l2j.L2DatabaseFactory;
  311.  import net.sf.l2j.gameserver.LoginServerThread;
  312. @@ -28,10 +27,12 @@
  313.  import net.sf.l2j.gameserver.model.L2Clan;
  314.  import net.sf.l2j.gameserver.model.World;
  315.  import net.sf.l2j.gameserver.model.actor.instance.Player;
  316. +import net.sf.l2j.gameserver.model.entity.L2Event;
  317.  import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  318.  import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
  319.  import net.sf.l2j.gameserver.network.serverpackets.ServerClose;
  320.  import net.sf.l2j.gameserver.util.FloodProtectors;
  321. +import net.sf.l2j.util.EventData;
  322.  
  323.  /**
  324.   * Represents a client connected on Game Server
  325. @@ -574,7 +575,16 @@
  326.                 // we are going to manually save the char below thus we can force the cancel
  327.                 if (_autoSaveInDB != null)
  328.                     _autoSaveInDB.cancel(true);
  329. -              
  330. +               Player player = L2GameClient.this.getActiveChar();
  331. +               if (player != null) // this should only happen on connection loss
  332. +               {
  333. +                   // we store all data from players who are disconnected while in an event in order to restore it in the next login
  334. +                   if (player.atEvent)
  335. +                   {
  336. +                       EventData data = new EventData(player.eventX, player.eventY, player.eventZ, player.eventkarma, player.eventpvpkills, player.eventpkkills, player.eventTitle, player.kills, player.eventSitForced);
  337. +                       L2Event.connectionLossData.put(player.getName(), data);
  338. +                   }
  339. +               }
  340.                 if (getActiveChar() != null) // this should only happen on connection loss
  341.                 {
  342.                     if (getActiveChar().isLocked())
  343. Index: java/net/sf/l2j/gameserver/model/actor/stat/PcStat.java
  344. ===================================================================
  345. --- java/net/sf/l2j/gameserver/model/actor/stat/PcStat.java (revision 1)
  346. +++ java/net/sf/l2j/gameserver/model/actor/stat/PcStat.java (working copy)
  347. @@ -11,6 +11,9 @@
  348.  import net.sf.l2j.gameserver.model.actor.instance.Pet;
  349.  import net.sf.l2j.gameserver.model.actor.instance.Player;
  350.  import net.sf.l2j.gameserver.model.base.Experience;
  351. +import net.sf.l2j.gameserver.model.entity.engine.CTF;
  352. +import net.sf.l2j.gameserver.model.entity.engine.DM;
  353. +import net.sf.l2j.gameserver.model.entity.engine.TvT;
  354.  import net.sf.l2j.gameserver.model.group.Party;
  355.  import net.sf.l2j.gameserver.model.zone.ZoneId;
  356.  import net.sf.l2j.gameserver.model.zone.type.L2SwampZone;
  357. @@ -192,6 +195,23 @@
  358.             getActiveChar().setCurrentCp(getMaxCp());
  359.             getActiveChar().broadcastPacket(new SocialAction(getActiveChar(), 15));
  360.             getActiveChar().sendPacket(SystemMessageId.YOU_INCREASED_YOUR_LEVEL);
  361. +
  362. +           if (getActiveChar().isInFunEvent())
  363. +           {
  364. +               if (getActiveChar()._inEventTvT && TvT._maxlvl == getLevel() && !TvT._started)
  365. +               {
  366. +                   TvT.removePlayer(getActiveChar());
  367. +               }
  368. +               if (getActiveChar()._inEventCTF && CTF._maxlvl == getLevel() && !CTF._started)
  369. +               {
  370. +                   TvT.removePlayer(getActiveChar());
  371. +               }
  372. +               if (getActiveChar()._inEventDM && CTF._maxlvl == getLevel() && !DM._started)
  373. +               {
  374. +                   DM.removePlayer(getActiveChar());
  375. +               }
  376. +               getActiveChar().sendMessage("Your event sign up was canceled.");
  377. +           }
  378.         }
  379.        
  380.         // Give Expertise skill of this level
  381. Index: java/net/sf/l2j/gameserver/util/Util.java
  382. ===================================================================
  383. --- java/net/sf/l2j/gameserver/util/Util.java   (revision 1)
  384. +++ java/net/sf/l2j/gameserver/util/Util.java   (working copy)
  385. @@ -171,7 +171,21 @@
  386.         double d = dx * dx + dy * dy;
  387.         return d <= range * range + 2 * range * rad + rad * rad;
  388.     }
  389. -  
  390. +
  391. +   public static String reverseColor(String color)
  392. +   {
  393. +       char[] ch1 = color.toCharArray();
  394. +       char[] ch2 = new char[6];
  395. +       ch2[0] = ch1[4];
  396. +       ch2[1] = ch1[5];
  397. +       ch2[2] = ch1[2];
  398. +       ch2[3] = ch1[3];
  399. +       ch2[4] = ch1[0];
  400. +       ch2[5] = ch1[1];
  401. +
  402. +       return new String(ch2);
  403. +   }
  404. +
  405.     /**
  406.      * Returns the rounded value of val to specified number of digits after the decimal point.<BR>
  407.      * (Based on round() in PHP)
  408. Index: java/net/sf/l2j/gameserver/model/L2Object.java
  409. ===================================================================
  410. --- java/net/sf/l2j/gameserver/model/L2Object.java  (revision 1)
  411. +++ java/net/sf/l2j/gameserver/model/L2Object.java  (working copy)
  412. @@ -43,7 +43,13 @@
  413.     private WorldRegion _region;
  414.    
  415.     private boolean _isVisible;
  416. -  
  417. +
  418. +   /** Engine parameters */
  419. +   public boolean _inEventTvT = false;
  420. +   public boolean _inEventCTF = false;
  421. +   public boolean _inEventVIP = false;
  422. +   public boolean _inEventDM = false;
  423. +
  424.     public L2Object(int objectId)
  425.     {
  426.         _objectId = objectId;
  427. Index: java/net/sf/l2j/gameserver/GameServer.java
  428. ===================================================================
  429. --- java/net/sf/l2j/gameserver/GameServer.java  (revision 3)
  430. +++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
  431. @@ -84,6 +84,8 @@
  432.  import net.sf.l2j.gameserver.instancemanager.games.MonsterRace;
  433.  import net.sf.l2j.gameserver.model.World;
  434.  import net.sf.l2j.gameserver.model.entity.Hero;
  435. +import net.sf.l2j.gameserver.model.entity.engine.EventHandlerCtf;
  436. +import net.sf.l2j.gameserver.model.entity.engine.EventHandlerTvT;
  437.  import net.sf.l2j.gameserver.model.olympiad.Olympiad;
  438.  import net.sf.l2j.gameserver.model.olympiad.OlympiadGameManager;
  439.  import net.sf.l2j.gameserver.model.partymatching.PartyMatchRoomList;
  440. @@ -258,7 +260,16 @@
  441.        
  442.         StringUtil.printSection("Events");
  443.         MonsterRace.getInstance();
  444. -
  445. +       if (Config.ALLOW_CTF_AUTOEVENT)
  446. +       {
  447. +           new EventHandlerCtf().startHandler();
  448. +       }
  449. +      
  450. +       if (Config.TVT_ALLOW_AUTOEVENT)
  451. +       {
  452. +           new EventHandlerTvT().startHandler();
  453. +       }
  454. +      
  455.         if (Config.CKM_ENABLED)
  456.         {
  457.             CharacterKillingManager.getInstance().init();
  458. Index: java/net/sf/l2j/gameserver/model/entity/L2Event.java
  459. ===================================================================
  460. --- java/net/sf/l2j/gameserver/model/entity/L2Event.java    (revision 0)
  461. +++ java/net/sf/l2j/gameserver/model/entity/L2Event.java    (working copy)
  462. @@ -0,0 +1,286 @@
  463. +/*
  464. + * This program is free software: you can redistribute it and/or modify it under
  465. + * the terms of the GNU General Public License as published by the Free Software
  466. + * Foundation, either version 3 of the License, or (at your option) any later
  467. + * version.
  468. + *
  469. + * This program is distributed in the hope that it will be useful, but WITHOUT
  470. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  471. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  472. + * details.
  473. + *
  474. + * You should have received a copy of the GNU General Public License along with
  475. + * this program. If not, see <http://www.gnu.org/licenses/>.
  476. + */
  477. +package net.sf.l2j.gameserver.model.entity;
  478. +
  479. +import java.io.BufferedInputStream;
  480. +import java.io.BufferedReader;
  481. +import java.io.DataInputStream;
  482. +import java.io.FileInputStream;
  483. +import java.io.IOException;
  484. +import java.io.InputStreamReader;
  485. +import java.util.HashMap;
  486. +import java.util.Iterator;
  487. +import java.util.LinkedList;
  488. +import java.util.logging.Logger;
  489. +
  490. +import net.sf.l2j.Config;
  491. +import net.sf.l2j.gameserver.datatables.NpcTable;
  492. +import net.sf.l2j.gameserver.datatables.SpawnTable;
  493. +import net.sf.l2j.gameserver.model.L2Spawn;
  494. +import net.sf.l2j.gameserver.model.World;
  495. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  496. +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  497. +import net.sf.l2j.gameserver.network.clientpackets.Say2;
  498. +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  499. +import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  500. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  501. +import net.sf.l2j.util.EventData;
  502. +
  503. +public class L2Event
  504. +{
  505. +   private static final Logger _log = Logger.getLogger(L2Event.class.getName());
  506. +   public static String eventName = "";
  507. +   public static int teamsNumber = 0;
  508. +   public static final HashMap<Integer, String> names = new HashMap<>();
  509. +   public static final LinkedList<String> participatingPlayers = new LinkedList<>();
  510. +   public static final HashMap<Integer, LinkedList<String>> players = new HashMap<>();
  511. +   public static int id = 12760;
  512. +   public static final LinkedList<String> npcs = new LinkedList<>();
  513. +   public static boolean active = false;
  514. +   public static final HashMap<String, EventData> connectionLossData = new HashMap<>();
  515. +
  516. +   public static int getTeamOfPlayer(String name)
  517. +   {
  518. +       for (int i = 1; i <= players.size(); i++)
  519. +       {
  520. +           LinkedList<?> temp = players.get(i);
  521. +           Iterator<?> it = temp.iterator();
  522. +           while (it.hasNext())
  523. +           {
  524. +               if (it.next().equals(name))
  525. +                   return i;
  526. +           }
  527. +       }
  528. +       return 0;
  529. +   }
  530. +
  531. +   public static String[] getTopNKillers(int N)
  532. +   { // this will return top N players sorted by kills, first element in the array will be the one with more kills
  533. +       String[] killers = new String[N];
  534. +       String playerTemp = "";
  535. +       int kills = 0;
  536. +       LinkedList<String> killersTemp = new LinkedList<>();
  537. +
  538. +       for (int k = 0; k < N; k++)
  539. +       {
  540. +           kills = 0;
  541. +           for (int i = 1; i <= teamsNumber; i++)
  542. +           {
  543. +               LinkedList<?> temp = players.get(i);
  544. +               Iterator<?> it = temp.iterator();
  545. +               while (it.hasNext())
  546. +               {
  547. +                   try
  548. +                   {
  549. +                       Player player = World.getInstance().getPlayer((String) it.next());
  550. +                       if (!killersTemp.contains(player.getName()))
  551. +                       {
  552. +                           if (player.kills.size() > kills)
  553. +                           {
  554. +                               kills = player.kills.size();
  555. +                               playerTemp = player.getName();
  556. +                           }
  557. +                       }
  558. +                   }
  559. +                   catch (Exception e)
  560. +                   {
  561. +                   }
  562. +               }
  563. +           }
  564. +           killersTemp.add(playerTemp);
  565. +       }
  566. +
  567. +       for (int i = 0; i < N; i++)
  568. +       {
  569. +           kills = 0;
  570. +           Iterator<String> it = killersTemp.iterator();
  571. +           while (it.hasNext())
  572. +           {
  573. +               try
  574. +               {
  575. +                   Player player = World.getInstance().getPlayer(it.next());
  576. +                   if (player.kills.size() > kills)
  577. +                   {
  578. +                       kills = player.kills.size();
  579. +                       playerTemp = player.getName();
  580. +                   }
  581. +               }
  582. +               catch (Exception e)
  583. +               {
  584. +               }
  585. +           }
  586. +           killers[i] = playerTemp;
  587. +           killersTemp.remove(playerTemp);
  588. +       }
  589. +       return killers;
  590. +   }
  591. +
  592. +   public static void showEventHtml(Player player, String objectid)
  593. +   {
  594. +       try (BufferedReader inbr = new BufferedReader(new InputStreamReader(new DataInputStream(new BufferedInputStream(new FileInputStream("data/events/" + eventName))))))
  595. +       {
  596. +           NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  597. +           StringBuilder replyMSG = new StringBuilder("<html><body>");
  598. +           replyMSG.append("<center><font color=\"LEVEL\">" + eventName + "</font><font color=\"FF0000\"> bY " + inbr.readLine() + "</font></center><br>");
  599. +
  600. +           replyMSG.append("<br>" + inbr.readLine());
  601. +           if (L2Event.participatingPlayers.contains(player.getName()))
  602. +               replyMSG.append("<br><center>You are already in the event players list !!</center></body></html>");
  603. +           else
  604. +               replyMSG.append("<br><center><button value=\"Participate !! \" action=\"bypass -h npc_" + objectid + "_event_participate\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></center></body></html>");
  605. +
  606. +           adminReply.setHtml(replyMSG.toString());
  607. +           player.sendPacket(adminReply);
  608. +           inbr.close();
  609. +       }
  610. +       catch (IOException e)
  611. +       {
  612. +           _log.warning(L2Event.class.getSimpleName() + ": failed to read line data/events/" + eventName);
  613. +           if (Config.DEVELOPER)
  614. +               e.printStackTrace();
  615. +       }
  616. +   }
  617. +
  618. +   public static void spawn(Player target, int npcid)
  619. +   {
  620. +       NpcTemplate template1 = NpcTable.getInstance().getTemplate(npcid);
  621. +
  622. +       try
  623. +       {
  624. +           // L2MonsterInstance mob = new L2MonsterInstance(template1);
  625. +
  626. +           L2Spawn spawn = new L2Spawn(template1);
  627. +
  628. +           spawn.setLoc(target.getX() + 50, target.getY() + 50, target.getZ(),target.getHeading());
  629. +           spawn.setRespawnDelay(1);
  630. +
  631. +           SpawnTable.getInstance().addNewSpawn(spawn, false);
  632. +
  633. +           spawn.setRespawnState(true);
  634. +           spawn.doSpawn(false);
  635. +           spawn.getNpc().setCurrentHp(999999999);
  636. +           spawn.getNpc().setName("event inscriptor");
  637. +           spawn.getNpc().setTitle(L2Event.eventName);
  638. +           spawn.getNpc().isEventMob = true;
  639. +           spawn.getNpc().isAggressive();
  640. +           spawn.getNpc().decayMe();
  641. +           spawn.getNpc().spawnMe(spawn.getNpc().getX(), spawn.getNpc().getY(), spawn.getNpc().getZ());
  642. +
  643. +           spawn.getNpc().broadcastPacket(new MagicSkillUse(spawn.getNpc(), spawn.getNpc(), 1034, 1, 1, 1));
  644. +
  645. +           npcs.add(String.valueOf(spawn.getNpc().getObjectId()));
  646. +       }
  647. +       catch (Exception e)
  648. +       {
  649. +           _log.warning(L2Event.class.getSimpleName() + ": failed to spawn npcid:" + npcid);
  650. +           if (Config.DEVELOPER)
  651. +               e.printStackTrace();
  652. +       }
  653. +   }
  654. +
  655. +   public static void announceAllPlayers(String text)
  656. +   {
  657. +       CreatureSay cs = new CreatureSay(0, Say2.ANNOUNCEMENT, "", text);
  658. +
  659. +       for (Player player : World.getInstance().getPlayers())
  660. +       {
  661. +           player.sendPacket(cs);
  662. +       }
  663. +   }
  664. +
  665. +   public static boolean isOnEvent(Player player)
  666. +   {
  667. +       for (int k = 0; k < L2Event.teamsNumber; k++)
  668. +       {
  669. +           Iterator<?> it = L2Event.players.get(k + 1).iterator();
  670. +           boolean temp = false;
  671. +           while (it.hasNext())
  672. +           {
  673. +               temp = player.getName().equalsIgnoreCase(it.next().toString());
  674. +               if (temp)
  675. +                   return true;
  676. +           }
  677. +       }
  678. +       return false;
  679. +   }
  680. +
  681. +   public static void inscribePlayer(Player player)
  682. +   {
  683. +       try
  684. +       {
  685. +           L2Event.participatingPlayers.add(player.getName());
  686. +           player.eventkarma = player.getKarma();
  687. +           player.eventX = player.getX();
  688. +           player.eventY = player.getY();
  689. +           player.eventZ = player.getZ();
  690. +           player.eventpkkills = player.getPkKills();
  691. +           player.eventpvpkills = player.getPvpKills();
  692. +           player.eventTitle = player.getTitle();
  693. +           player.kills.clear();
  694. +           player.atEvent = true;
  695. +       }
  696. +       catch (Exception e)
  697. +       {
  698. +           _log.warning(L2Event.class.getSimpleName() + ": error when signing in the event:");
  699. +           if (Config.DEVELOPER)
  700. +               e.printStackTrace();
  701. +       }
  702. +   }
  703. +
  704. +   public static void restoreChar(Player player)
  705. +   {
  706. +       try
  707. +       {
  708. +           player.eventX = connectionLossData.get(player.getName()).eventX;
  709. +           player.eventY = connectionLossData.get(player.getName()).eventY;
  710. +           player.eventZ = connectionLossData.get(player.getName()).eventZ;
  711. +           player.eventkarma = connectionLossData.get(player.getName()).eventKarma;
  712. +           player.eventpvpkills = connectionLossData.get(player.getName()).eventPvpKills;
  713. +           player.eventpkkills = connectionLossData.get(player.getName()).eventPkKills;
  714. +           player.eventTitle = connectionLossData.get(player.getName()).eventTitle;
  715. +           player.kills = connectionLossData.get(player.getName()).kills;
  716. +           player.eventSitForced = connectionLossData.get(player.getName()).eventSitForced;
  717. +           player.atEvent = true;
  718. +       }
  719. +       catch (Exception e)
  720. +       {
  721. +           _log.warning(L2Event.class.getSimpleName() + ": error when signing in the event:");
  722. +           if (Config.DEVELOPER)
  723. +               e.printStackTrace();
  724. +       }
  725. +   }
  726. +
  727. +   public static void restoreAndTeleChar(Player target)
  728. +   {
  729. +       try
  730. +       {
  731. +           restoreChar(target);
  732. +           target.setTitle(target.eventTitle);
  733. +           target.setKarma(target.eventkarma);
  734. +           target.setPvpKills(target.eventpvpkills);
  735. +           target.setPkKills(target.eventpkkills);
  736. +           target.teleToLocation(target.eventX, target.eventY, target.eventZ, 0);
  737. +           target.kills.clear();
  738. +           target.eventSitForced = false;
  739. +           target.atEvent = false;
  740. +       }
  741. +       catch (Exception e)
  742. +       {
  743. +           _log.warning(L2Event.class.getSimpleName() + ": error when restore and teleport character");
  744. +           if (Config.DEVELOPER)
  745. +               e.printStackTrace();
  746. +       }
  747. +   }
  748. +}
  749. \ No newline at end of file
  750. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminCTFEngine.java
  751. ===================================================================
  752. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminCTFEngine.java (revision 0)
  753. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminCTFEngine.java (working copy)
  754. @@ -0,0 +1,465 @@
  755. +/*
  756. + * This program is free software: you can redistribute it and/or modify it under
  757. + * the terms of the GNU General Public License as published by the Free Software
  758. + * Foundation, either version 3 of the License, or (at your option) any later
  759. + * version.
  760. + *
  761. + * This program is distributed in the hope that it will be useful, but WITHOUT
  762. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  763. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  764. + * details.
  765. + *
  766. + * You should have received a copy of the GNU General Public License along with
  767. + * this program. If not, see <http://www.gnu.org/licenses/>.
  768. + */
  769. +package net.sf.l2j.gameserver.handler.admincommandhandlers;
  770. +
  771. +import net.sf.l2j.Config;
  772. +import net.sf.l2j.commons.concurrent.ThreadPool;
  773. +import net.sf.l2j.gameserver.datatables.ItemTable;
  774. +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  775. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  776. +import net.sf.l2j.gameserver.model.entity.engine.CTF;
  777. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  778. +import net.sf.l2j.gameserver.util.Util;
  779. +
  780. +
  781. +/**
  782. + * @author: FBIagent / fixed by SqueezeD
  783. + */
  784. +public class AdminCTFEngine implements IAdminCommandHandler
  785. +{
  786. +   private static final String[] ADMIN_COMMANDS =
  787. +   {/** @formatter:off */
  788. +       "admin_ctf",
  789. +       "admin_ctf_name",
  790. +       "admin_ctf_desc",
  791. +       "admin_ctf_join_loc",
  792. +       "admin_ctf_edit",
  793. +       "admin_ctf_control",
  794. +       "admin_ctf_minlvl",
  795. +       "admin_ctf_maxlvl",
  796. +       "admin_ctf_tele_npc",
  797. +       "admin_ctf_tele_team",
  798. +       "admin_ctf_tele_flag",
  799. +       "admin_ctf_npc",
  800. +       "admin_ctf_npc_pos",
  801. +       "admin_ctf_reward",
  802. +       "admin_ctf_reward_amount",
  803. +       "admin_ctf_team_add",
  804. +       "admin_ctf_team_remove",
  805. +       "admin_ctf_team_pos",
  806. +       "admin_ctf_team_color",
  807. +       "admin_ctf_team_flag",
  808. +       "admin_ctf_join",
  809. +       "admin_ctf_teleport",
  810. +       "admin_ctf_start",
  811. +       "admin_ctf_abort",
  812. +       "admin_ctf_finish",
  813. +       "admin_ctf_sit",
  814. +       "admin_ctf_dump",
  815. +       "admin_ctf_save",
  816. +       "admin_ctf_load",
  817. +       "admin_ctf_jointime",
  818. +       "admin_ctf_eventtime",
  819. +       "admin_ctf_autoevent",
  820. +       "admin_ctf_minplayers",
  821. +       "admin_ctf_maxplayers"
  822. +   };/** @formatter:on */
  823. +
  824. +   @Override
  825. +   public boolean useAdminCommand(String command, Player activeChar)
  826. +   {
  827. +       try
  828. +       {
  829. +           if (command.equals("admin_ctf"))
  830. +               showMainPage(activeChar);
  831. +           else if (command.startsWith("admin_ctf_name "))
  832. +           {
  833. +               CTF._eventName = command.substring(15);
  834. +               showMainPage(activeChar);
  835. +           }
  836. +           else if (command.startsWith("admin_ctf_desc "))
  837. +           {
  838. +               CTF._eventDesc = command.substring(15);
  839. +               showMainPage(activeChar);
  840. +           }
  841. +           else if (command.startsWith("admin_ctf_minlvl "))
  842. +           {
  843. +               if (!CTF.checkMinLevel(Integer.valueOf(command.substring(17))))
  844. +                   return false;
  845. +               CTF._minlvl = Integer.valueOf(command.substring(17));
  846. +               showMainPage(activeChar);
  847. +           }
  848. +           else if (command.startsWith("admin_ctf_team_flag "))
  849. +           {
  850. +               String[] params;
  851. +
  852. +               params = command.split(" ");
  853. +
  854. +               if (params.length != 2)
  855. +               {
  856. +                   activeChar.sendMessage("Wrong usge: //ctf_team_flag <teamName>");
  857. +                   return false;
  858. +               }
  859. +
  860. +               CTF.setTeamFlag(params[1], activeChar);
  861. +               showMainPage(activeChar);
  862. +           }
  863. +           else if (command.equals("admin_ctf_edit"))
  864. +           {
  865. +               showEditPage(activeChar);
  866. +           }
  867. +           else if (command.equals("admin_ctf_control"))
  868. +           {
  869. +               showControlPage(activeChar);
  870. +           }
  871. +           else if (command.equals("admin_ctf_tele_npc"))
  872. +           {
  873. +               activeChar.teleToLocation(CTF._npcX, CTF._npcY, CTF._npcZ, 0);
  874. +               showMainPage(activeChar);
  875. +           }
  876. +           else if (command.startsWith("admin_ctf_tele_team "))
  877. +           {
  878. +               for (String t : CTF._teams)
  879. +                   if (t.equals(command.substring(20)))
  880. +                   {
  881. +                       int index = CTF._teams.indexOf(t);
  882. +                       activeChar.teleToLocation(CTF._teamsX.get(index), CTF._teamsY.get(index), CTF._teamsZ.get(index), 0);
  883. +                   }
  884. +               showMainPage(activeChar);
  885. +           }
  886. +           else if (command.startsWith("admin_ctf_tele_flag "))
  887. +           {
  888. +               for (String t : CTF._teams)
  889. +                   if (t.equals(command.substring(20)))
  890. +                   {
  891. +                       int index = CTF._teams.indexOf(t);
  892. +                       activeChar.teleToLocation(CTF._flagsX.get(index), CTF._flagsY.get(index), CTF._flagsZ.get(index), 0);
  893. +                   }
  894. +               showMainPage(activeChar);
  895. +           }
  896. +           else if (command.startsWith("admin_ctf_maxlvl "))
  897. +           {
  898. +               if (!CTF.checkMaxLevel(Integer.valueOf(command.substring(17))))
  899. +                   return false;
  900. +               CTF._maxlvl = Integer.valueOf(command.substring(17));
  901. +               showMainPage(activeChar);
  902. +           }
  903. +           else if (command.startsWith("admin_ctf_minplayers "))
  904. +           {
  905. +               CTF._minPlayers = Integer.valueOf(command.substring(21));
  906. +               showMainPage(activeChar);
  907. +           }
  908. +           else if (command.startsWith("admin_ctf_maxplayers "))
  909. +           {
  910. +               CTF._maxPlayers = Integer.valueOf(command.substring(21));
  911. +               showMainPage(activeChar);
  912. +           }
  913. +           else if (command.startsWith("admin_ctf_join_loc "))
  914. +           {
  915. +               CTF._joiningLocationName = command.substring(19);
  916. +               showMainPage(activeChar);
  917. +           }
  918. +           else if (command.startsWith("admin_ctf_npc "))
  919. +           {
  920. +               CTF._npcId = Integer.valueOf(command.substring(14));
  921. +               showMainPage(activeChar);
  922. +           }
  923. +           else if (command.equals("admin_ctf_npc_pos"))
  924. +           {
  925. +               CTF.setNpcPos(activeChar);
  926. +               showMainPage(activeChar);
  927. +           }
  928. +           else if (command.startsWith("admin_ctf_reward "))
  929. +           {
  930. +               CTF._rewardId = Integer.valueOf(command.substring(17));
  931. +               showMainPage(activeChar);
  932. +           }
  933. +           else if (command.startsWith("admin_ctf_reward_amount "))
  934. +           {
  935. +               CTF._rewardAmount = Integer.valueOf(command.substring(24));
  936. +               showMainPage(activeChar);
  937. +           }
  938. +           else if (command.startsWith("admin_ctf_jointime "))
  939. +           {
  940. +               CTF._joinTime = Integer.valueOf(command.substring(19));
  941. +               showMainPage(activeChar);
  942. +           }
  943. +           else if (command.startsWith("admin_ctf_eventtime "))
  944. +           {
  945. +               CTF._eventTime = Integer.valueOf(command.substring(20));
  946. +               showMainPage(activeChar);
  947. +           }
  948. +           else if (command.startsWith("admin_ctf_team_add "))
  949. +           {
  950. +               String teamName = command.substring(19);
  951. +
  952. +               CTF.addTeam(teamName);
  953. +               showMainPage(activeChar);
  954. +           }
  955. +           else if (command.startsWith("admin_ctf_team_remove "))
  956. +           {
  957. +               String teamName = command.substring(22);
  958. +
  959. +               CTF.removeTeam(teamName);
  960. +               showMainPage(activeChar);
  961. +           }
  962. +           else if (command.startsWith("admin_ctf_team_pos "))
  963. +           {
  964. +               String teamName = command.substring(19);
  965. +
  966. +               CTF.setTeamPos(teamName, activeChar);
  967. +               showMainPage(activeChar);
  968. +           }
  969. +           else if (command.startsWith("admin_ctf_team_color "))
  970. +           {
  971. +               String[] params;
  972. +
  973. +               params = command.split(" ");
  974. +
  975. +               if (params.length != 3)
  976. +               {
  977. +                   activeChar.sendMessage("Wrong usege: //ctf_team_color <colorHex> <teamName>");
  978. +                   return false;
  979. +               }
  980. +
  981. +               CTF.setTeamColor(command.substring(params[0].length() + params[1].length() + 2), Integer.decode("0x" + Util.reverseColor(params[1])));
  982. +               showMainPage(activeChar);
  983. +           }
  984. +           else if (command.equals("admin_ctf_join"))
  985. +           {
  986. +               CTF.startJoin(activeChar);
  987. +               showMainPage(activeChar);
  988. +           }
  989. +           else if (command.equals("admin_ctf_teleport"))
  990. +           {
  991. +               CTF.teleportStart();
  992. +               showMainPage(activeChar);
  993. +           }
  994. +           else if (command.equals("admin_ctf_start"))
  995. +           {
  996. +               CTF.startEvent(activeChar);
  997. +               showMainPage(activeChar);
  998. +           }
  999. +           else if (command.equals("admin_ctf_abort"))
  1000. +           {
  1001. +               activeChar.sendMessage("Aborting event");
  1002. +               CTF.abortEvent();
  1003. +               showMainPage(activeChar);
  1004. +           }
  1005. +           else if (command.equals("admin_ctf_finish"))
  1006. +           {
  1007. +               CTF.finishEvent();
  1008. +               showMainPage(activeChar);
  1009. +           }
  1010. +           else if (command.equals("admin_ctf_sit"))
  1011. +           {
  1012. +               CTF.sit();
  1013. +               showMainPage(activeChar);
  1014. +           }
  1015. +           else if (command.equals("admin_ctf_load"))
  1016. +           {
  1017. +               CTF.loadData();
  1018. +               showMainPage(activeChar);
  1019. +           }
  1020. +           else if (command.equals("admin_ctf_autoevent"))
  1021. +           {
  1022. +               if (CTF._joinTime > 0 && CTF._eventTime > 0)
  1023. +                   ThreadPool.schedule(new Runnable()
  1024. +                   {
  1025. +                       @Override
  1026. +                       public void run()
  1027. +                       {
  1028. +                           CTF.autoEvent();
  1029. +                       }
  1030. +                   }, 0);
  1031. +               else
  1032. +                   activeChar.sendMessage("Wrong usege: join time or event time invallid.");
  1033. +               showMainPage(activeChar);
  1034. +           }
  1035. +           else if (command.equals("admin_ctf_save"))
  1036. +           {
  1037. +               CTF.saveData();
  1038. +               showMainPage(activeChar);
  1039. +           }
  1040. +           else if (command.equals("admin_ctf_dump"))
  1041. +               CTF.dumpData();
  1042. +
  1043. +           return true;
  1044. +       }
  1045. +       catch (Exception e)
  1046. +       {
  1047. +           activeChar.sendMessage("The command was not used correctly");
  1048. +           return false;
  1049. +       }
  1050. +   }
  1051. +
  1052. +   @Override
  1053. +   public String[] getAdminCommandList()
  1054. +   {
  1055. +       return ADMIN_COMMANDS;
  1056. +   }
  1057. +
  1058. +   public void showEditPage(Player activeChar)
  1059. +   {
  1060. +       NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1061. +       StringBuilder replyMSG = new StringBuilder("<html><body>");
  1062. +
  1063. +       replyMSG.append("<center><font color=\"LEVEL\">[CTF Engine by Darki699]</font></center><br><br><br>");
  1064. +       replyMSG.append("<table><tr><td><edit var=\"input1\" width=\"125\"></td><td><edit var=\"input2\" width=\"125\"></td></tr></table>");
  1065. +       replyMSG.append("<table border=\"0\"><tr>");
  1066. +       replyMSG.append("<td width=\"100\"><button value=\"Name\" action=\"bypass -h admin_ctf_name $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1067. +       replyMSG.append("<td width=\"100\"><button value=\"Description\" action=\"bypass -h admin_ctf_desc $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1068. +       replyMSG.append("<td width=\"100\"><button value=\"Join Location\" action=\"bypass -h admin_ctf_join_loc $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1069. +       replyMSG.append("</tr></table><br><table><tr>");
  1070. +       replyMSG.append("<td width=\"100\"><button value=\"Max lvl\" action=\"bypass -h admin_ctf_maxlvl $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1071. +       replyMSG.append("<td width=\"100\"><button value=\"Min lvl\" action=\"bypass -h admin_ctf_minlvl $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1072. +       replyMSG.append("</tr></table><br><table><tr>");
  1073. +       replyMSG.append("<td width=\"100\"><button value=\"Max players\" action=\"bypass -h admin_ctf_maxplayers $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1074. +       replyMSG.append("<td width=\"100\"><button value=\"Min players\" action=\"bypass -h admin_ctf_minplayers $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1075. +       replyMSG.append("</tr></table><br><table><tr>");
  1076. +       replyMSG.append("<td width=\"100\"><button value=\"NPC\" action=\"bypass -h admin_ctf_npc $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1077. +       replyMSG.append("<td width=\"100\"><button value=\"NPC Pos\" action=\"bypass -h admin_ctf_npc_pos\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1078. +       replyMSG.append("</tr></table><br><table><tr>");
  1079. +       replyMSG.append("<td width=\"100\"><button value=\"Reward\" action=\"bypass -h admin_ctf_reward $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1080. +       replyMSG.append("<td width=\"100\"><button value=\"Reward Amount\" action=\"bypass -h admin_ctf_reward_amount $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1081. +       replyMSG.append("</tr></table><br><table><tr>");
  1082. +       replyMSG.append("<td width=\"100\"><button value=\"Join Time\" action=\"bypass -h admin_ctf_jointime $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1083. +       replyMSG.append("<td width=\"100\"><button value=\"Event Time\" action=\"bypass -h admin_ctf_eventtime $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1084. +       replyMSG.append("</tr></table><br><table><tr>");
  1085. +       replyMSG.append("<td width=\"100\"><button value=\"Team Add\" action=\"bypass -h admin_ctf_team_add $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1086. +       replyMSG.append("<td width=\"100\"><button value=\"Team Color\" action=\"bypass -h admin_ctf_team_color $input1 $input2\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1087. +       replyMSG.append("<td width=\"100\"><button value=\"Team Pos\" action=\"bypass -h admin_ctf_team_pos $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1088. +       replyMSG.append("</tr></table><table><tr>");
  1089. +       replyMSG.append("<td width=\"100\"><button value=\"Team Flag\" action=\"bypass -h admin_ctf_team_flag $input1 $input2\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1090. +       replyMSG.append("<td width=\"100\"><button value=\"Team Remove\" action=\"bypass -h admin_ctf_team_remove $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1091. +       replyMSG.append("</tr></table><br>");
  1092. +       replyMSG.append("<br><center><button value=\"Back\" action=\"bypass -h admin_ctf\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  1093. +       adminReply.setHtml(replyMSG.toString());
  1094. +       activeChar.sendPacket(adminReply);
  1095. +   }
  1096. +
  1097. +   public void showControlPage(Player activeChar)
  1098. +   {
  1099. +       NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1100. +       StringBuilder replyMSG = new StringBuilder("<html><body>");
  1101. +
  1102. +       replyMSG.append("<center><font color=\"LEVEL\">[CTF Engine by Darki699]</font></center><br><br><br>");
  1103. +       replyMSG.append("<table border=\"0\"><tr>");
  1104. +       replyMSG.append("<td width=\"100\"><button value=\"Join\" action=\"bypass -h admin_ctf_join\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1105. +       replyMSG.append("<td width=\"100\"><button value=\"Teleport\" action=\"bypass -h admin_ctf_teleport\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1106. +       replyMSG.append("<td width=\"100\"><button value=\"Start\" action=\"bypass -h admin_ctf_start\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1107. +       replyMSG.append("</tr></table><table><tr>");
  1108. +       replyMSG.append("<td width=\"100\"><button value=\"Abort\" action=\"bypass -h admin_ctf_abort\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1109. +       replyMSG.append("<td width=\"100\"><button value=\"Finish\" action=\"bypass -h admin_ctf_finish\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1110. +       replyMSG.append("</tr></table><br><table><tr>");
  1111. +       replyMSG.append("<td width=\"100\"><button value=\"Sit Force\" action=\"bypass -h admin_ctf_sit\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1112. +       replyMSG.append("<td width=\"100\"><button value=\"Dump\" action=\"bypass -h admin_ctf_dump\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1113. +       replyMSG.append("</tr></table><br><br><table><tr>");
  1114. +       replyMSG.append("<td width=\"100\"><button value=\"Save\" action=\"bypass -h admin_ctf_save\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1115. +       replyMSG.append("<td width=\"100\"><button value=\"Load\" action=\"bypass -h admin_ctf_load\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1116. +       replyMSG.append("<td width=\"100\"><button value=\"Auto Event\" action=\"bypass -h admin_ctf_autoevent\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1117. +       replyMSG.append("</tr></table><br>");
  1118. +       replyMSG.append("<br><center><button value=\"Back\" action=\"bypass -h admin_ctf\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  1119. +       adminReply.setHtml(replyMSG.toString());
  1120. +       activeChar.sendPacket(adminReply);
  1121. +   }
  1122. +
  1123. +   public void showMainPage(Player activeChar)
  1124. +   {
  1125. +       NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1126. +       StringBuilder replyMSG = new StringBuilder("<html><body>");
  1127. +
  1128. +       replyMSG.append("<center><font color=\"LEVEL\">[CTF Engine by Darki699]</font></center><br><br><br>");
  1129. +
  1130. +       replyMSG.append("<table><tr>");
  1131. +       if (!CTF._joining && !CTF._started && !CTF._teleport)
  1132. +           replyMSG.append("<td width=\"100\"><button value=\"Edit\" action=\"bypass -h admin_ctf_edit\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1133. +       replyMSG.append("<td width=\"100\"><button value=\"Control\" action=\"bypass -h admin_ctf_control\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  1134. +       replyMSG.append("</tr></table><br>");
  1135. +
  1136. +       replyMSG.append("<br><font color=\"LEVEL\">Current event...</font><br1>");
  1137. +       replyMSG.append("    ... name:&nbsp;<font color=\"00FF00\">" + CTF._eventName + "</font><br1>");
  1138. +       replyMSG.append("    ... description:&nbsp;<font color=\"00FF00\">" + CTF._eventDesc + "</font><br1>");
  1139. +       replyMSG.append("    ... joining location name:&nbsp;<font color=\"00FF00\">" + CTF._joiningLocationName + "</font><br1>");
  1140. +       replyMSG.append("    ... joining NPC ID:&nbsp;<font color=\"00FF00\">" + CTF._npcId + " on pos " + CTF._npcX + "," + CTF._npcY + "," + CTF._npcZ + "</font><br1>");
  1141. +       replyMSG.append("        <button value=\"Tele->NPC\" action=\"bypass -h admin_ctf_tele_npc\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><br>");
  1142. +       replyMSG.append("    ... reward ID:&nbsp;<font color=\"00FF00\">" + CTF._rewardId + "</font><br1>");
  1143. +       if (ItemTable.getInstance().getTemplate(CTF._rewardId) != null)
  1144. +           replyMSG.append("    ... reward Item:&nbsp;<font color=\"00FF00\">" + ItemTable.getInstance().getTemplate(CTF._rewardId).getName() + "</font><br1>");
  1145. +       else
  1146. +           replyMSG.append("    ... reward Item:&nbsp;<font color=\"00FF00\">(unknown)</font><br1>");
  1147. +       replyMSG.append("    ... reward Amount:&nbsp;<font color=\"00FF00\">" + CTF._rewardAmount + "</font><br>");
  1148. +       replyMSG.append("    ... Min lvl:&nbsp;<font color=\"00FF00\">" + CTF._minlvl + "</font><br1>");
  1149. +       replyMSG.append("    ... Max lvl:&nbsp;<font color=\"00FF00\">" + CTF._maxlvl + "</font><br><br>");
  1150. +       replyMSG.append("    ... Min Players:&nbsp;<font color=\"00FF00\">" + CTF._minPlayers + "</font><br1>");
  1151. +       replyMSG.append("    ... Max Players:&nbsp;<font color=\"00FF00\">" + CTF._maxPlayers + "</font><br>");
  1152. +       replyMSG.append("    ... Joining Time:&nbsp;<font color=\"00FF00\">" + CTF._joinTime + "</font><br1>");
  1153. +       replyMSG.append("    ... Event Time:&nbsp;<font color=\"00FF00\">" + CTF._eventTime + "</font><br>");
  1154. +       if (CTF._teams != null && !CTF._teams.isEmpty())
  1155. +           replyMSG.append("<font color=\"LEVEL\">Current teams:</font><br1>");
  1156. +       replyMSG.append("<center><table border=\"0\">");
  1157. +
  1158. +       for (String team : CTF._teams)
  1159. +       {
  1160. +           replyMSG.append("<tr><td width=\"100\">Name: <font color=\"FF0000\">" + team + "</font>");
  1161. +
  1162. +           if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  1163. +               replyMSG.append("&nbsp;(" + CTF.teamPlayersCount(team) + " joined)");
  1164. +           else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  1165. +           {
  1166. +               if (CTF._teleport || CTF._started)
  1167. +                   replyMSG.append("&nbsp;(" + CTF.teamPlayersCount(team) + " in)");
  1168. +           }
  1169. +           replyMSG.append("</td></tr><tr><td>");
  1170. +
  1171. +           String c = Integer.toHexString(CTF._teamColors.get(CTF._teams.indexOf(team)));
  1172. +           while (c.length() < 6)
  1173. +               c = "0" + c;
  1174. +           replyMSG.append("Color: <font color=\"00FF00\">0x" + c.toUpperCase() + "</font><font color=\"" + c + "\"> =) </font>");
  1175. +
  1176. +           replyMSG.append("</td></tr><tr><td>");
  1177. +           replyMSG.append("<button value=\"Tele->Team\" action=\"bypass -h admin_ctf_tele_team " + team + "\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  1178. +           replyMSG.append("</td></tr><tr><td>");
  1179. +           replyMSG.append(CTF._teamsX.get(CTF._teams.indexOf(team)) + ", " + CTF._teamsY.get(CTF._teams.indexOf(team)) + ", " + CTF._teamsZ.get(CTF._teams.indexOf(team)));
  1180. +           replyMSG.append("</td></tr><tr><td>");
  1181. +           replyMSG.append("Flag Id: <font color=\"00FF00\">" + CTF._flagIds.get(CTF._teams.indexOf(team)) + "</font>");
  1182. +           replyMSG.append("</td></tr><tr><td>");
  1183. +           replyMSG.append("<button value=\"Tele->Flag\" action=\"bypass -h admin_ctf_tele_flag " + team + "\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  1184. +           replyMSG.append("</td></tr><tr><td>");
  1185. +           replyMSG.append(CTF._flagsX.get(CTF._teams.indexOf(team)) + ", " + CTF._flagsY.get(CTF._teams.indexOf(team)) + ", " + CTF._flagsZ.get(CTF._teams.indexOf(team)) + "</td></tr>");
  1186. +           if (!CTF._joining && !CTF._started && !CTF._teleport)
  1187. +               replyMSG.append("<tr><td width=\"60\"><button value=\"Remove\" action=\"bypass -h admin_ctf_team_remove " + team + "\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr><tr></tr>");
  1188. +       }
  1189. +
  1190. +       replyMSG.append("</table></center>");
  1191. +
  1192. +       if (!CTF._joining && !CTF._started && !CTF._teleport)
  1193. +       {
  1194. +           if (CTF.startJoinOk())
  1195. +           {
  1196. +               replyMSG.append("<br1>");
  1197. +               replyMSG.append("Event is now set up. Press JOIN to start the registration.<br1>");
  1198. +               replyMSG.append("                           <button value=\"Join\" action=\"bypass -h admin_ctf_join\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><br1>");
  1199. +               replyMSG.append("<br>");
  1200. +           }
  1201. +           else
  1202. +           {
  1203. +               replyMSG.append("<br1>");
  1204. +               replyMSG.append("Event is NOT set up. Press <font color=\"LEVEL\">EDIT</font> to create a new event, or <font color=\"LEVEL\">CONTROL</font> to load an existing event.<br1>");
  1205. +               replyMSG.append("<br>");
  1206. +           }
  1207. +       }
  1208. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !CTF._started)
  1209. +       {
  1210. +           replyMSG.append("<br1>");
  1211. +           replyMSG.append(CTF._playersShuffle.size() + " players participating. Waiting to shuffle in teams(done on teleport)!");
  1212. +           replyMSG.append("<br><br>");
  1213. +       }
  1214. +
  1215. +       replyMSG.append("</body></html>");
  1216. +       adminReply.setHtml(replyMSG.toString());
  1217. +       activeChar.sendPacket(adminReply);
  1218. +   }
  1219. +}
  1220. \ No newline at end of file
  1221. Index: java/net/sf/l2j/gameserver/model/actor/instance/Player.java
  1222. ===================================================================
  1223. --- java/net/sf/l2j/gameserver/model/actor/instance/Player.java (revision 3)
  1224. +++ java/net/sf/l2j/gameserver/model/actor/instance/Player.java (working copy)
  1225. @@ -9,6 +9,7 @@
  1226.  import java.util.Collection;
  1227.  import java.util.HashMap;
  1228.  import java.util.LinkedHashMap;
  1229. +import java.util.LinkedList;
  1230.  import java.util.List;
  1231.  import java.util.Map;
  1232.  import java.util.Set;
  1233. @@ -107,8 +108,12 @@
  1234.  import net.sf.l2j.gameserver.model.entity.Castle;
  1235.  import net.sf.l2j.gameserver.model.entity.Duel.DuelState;
  1236.  import net.sf.l2j.gameserver.model.entity.Hero;
  1237. +import net.sf.l2j.gameserver.model.entity.L2Event;
  1238.  import net.sf.l2j.gameserver.model.entity.Siege;
  1239.  import net.sf.l2j.gameserver.model.entity.Siege.SiegeSide;
  1240. +import net.sf.l2j.gameserver.model.entity.engine.CTF;
  1241. +import net.sf.l2j.gameserver.model.entity.engine.DM;
  1242. +import net.sf.l2j.gameserver.model.entity.engine.TvT;
  1243.  import net.sf.l2j.gameserver.model.group.CommandChannel;
  1244.  import net.sf.l2j.gameserver.model.group.Party;
  1245.  import net.sf.l2j.gameserver.model.group.Party.LootRule;
  1246. @@ -504,7 +509,7 @@
  1247.     private ScheduledFuture<?> _chargeTask;
  1248.    
  1249.     private Location _currentSkillWorldPosition;
  1250. -  
  1251. +  
  1252.     private int antiAfkTime;
  1253.    
  1254.     private L2AccessLevel _accessLevel;
  1255. @@ -606,6 +611,33 @@
  1256.    
  1257.     private Door _requestedGate;
  1258.    
  1259. +   /** Event parameters */
  1260. +   public int eventX;
  1261. +   public int eventY;
  1262. +   public int eventZ;
  1263. +   public int eventkarma;
  1264. +   public int eventpvpkills;
  1265. +   public int eventpkkills;
  1266. +   public String eventTitle;
  1267. +   public LinkedList<String> kills = new LinkedList<>();
  1268. +   public boolean eventSitForced = false;
  1269. +   public boolean atEvent = false;
  1270. +  
  1271. +   /** TvT Engine parameters */
  1272. +   public String _teamNameTvT, _originalTitleTvT;
  1273. +   public int _originalNameColorTvT, _countTvTkills, _countTvTdies, _originalKarmaTvT;
  1274. +   public boolean _inEventTvT = false;
  1275. +  
  1276. +   /** CTF Engine parameters */
  1277. +   public String _teamNameCTF, _teamNameHaveFlagCTF, _originalTitleCTF;
  1278. +   public int _originalNameColorCTF, _originalKarmaCTF, _countCTFflags;
  1279. +   public boolean _inEventCTF = false, _haveFlagCTF = false;
  1280. +   public Future<?> _posCheckerCTF = null;
  1281. +  
  1282. +   /** DM Engine parameters */
  1283. +   public int _originalNameColorDM, _countDMkills, _originalKarmaDM;
  1284. +   public boolean _inEventDM = false;
  1285. +  
  1286.     /**
  1287.      * Constructor of L2PcInstance (use L2Character constructor).
  1288.      * <ul>
  1289. @@ -2145,8 +2177,16 @@
  1290.      */
  1291.     public void standUp()
  1292.     {
  1293. -       if (_isSitting && !isInStoreMode() && !isAlikeDead() && !isParalyzed())
  1294. +       if (L2Event.active && eventSitForced)
  1295.         {
  1296. +           sendMessage("A dark force beyond your mortal understanding makes your knees to shake when you try to stand up ...");
  1297. +       }
  1298. +       else if (TvT._sitForced && _inEventTvT || CTF._sitForced && _inEventCTF || DM._sitForced && _inEventDM)
  1299. +       {
  1300. +           sendMessage("The Admin/GM handle if you sit or stand in this match!");
  1301. +       }
  1302. +       else if (_isSitting && !isInStoreMode() && !isAlikeDead() && !isParalyzed())
  1303. +       {
  1304.             if (_effects.isAffected(L2EffectFlag.RELAXING))
  1305.                 stopEffects(L2EffectType.RELAXING);
  1306.            
  1307. @@ -3120,7 +3160,7 @@
  1308.                             return false;
  1309.                         }
  1310.                         break;
  1311. -                  
  1312. +                      
  1313.                     case ATTACKER:
  1314.                         if (getClan().getFlag() == null)
  1315.                         {
  1316. @@ -3128,7 +3168,7 @@
  1317.                             return false;
  1318.                         }
  1319.                         break;
  1320. -                  
  1321. +                      
  1322.                     default:
  1323.                         sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CANNOT_BE_RESURRECTED_DURING_SIEGE));
  1324.                         return false;
  1325. @@ -3169,6 +3209,25 @@
  1326.     @Override
  1327.     public void onAction(Player player)
  1328.     {
  1329. +       if (((TvT._started && !Config.TVT_ALLOW_INTERFERENCE) || (CTF._started && !Config.CTF_ALLOW_INTERFERENCE) || (DM._started && !Config.DM_ALLOW_INTERFERENCE) && !player.isGM()))
  1330. +       {
  1331. +           if ((_inEventTvT && !player._inEventTvT) || (!_inEventTvT && player._inEventTvT))
  1332. +           {
  1333. +               player.sendPacket(ActionFailed.STATIC_PACKET);
  1334. +               return;
  1335. +           }
  1336. +          
  1337. +           if ((_inEventCTF && !player._inEventCTF) || (!_inEventCTF && player._inEventCTF))
  1338. +           {
  1339. +               player.sendPacket(ActionFailed.STATIC_PACKET);
  1340. +               return;
  1341. +           }
  1342. +           if ((_inEventDM && !player._inEventDM) || (!_inEventDM && player._inEventDM))
  1343. +           {
  1344. +               player.sendPacket(ActionFailed.STATIC_PACKET);
  1345. +               return;
  1346. +           }
  1347. +       }
  1348.         // Set the target of the player
  1349.         if (player.getTarget() != this)
  1350.             player.setTarget(this);
  1351. @@ -3180,9 +3239,9 @@
  1352.                 player.getAI().setIntention(CtrlIntention.INTERACT, this);
  1353.                 return;
  1354.             }
  1355. -
  1356. +          
  1357.             // Check if this L2PcInstance is autoAttackable
  1358. -           if (isAutoAttackable(player))
  1359. +           if (isAutoAttackable(player) || (player._inEventTvT && TvT._started) || (player._inEventCTF && CTF._started) || (player._inEventDM && DM._started))
  1360.             {
  1361.                 // Player with lvl < 21 can't attack a cursed weapon holder and a cursed weapon holder can't attack players with lvl < 21
  1362.                 if ((isCursedWeaponEquipped() && player.getLevel() < 21) || (player.isCursedWeaponEquipped() && getLevel() < 21))
  1363. @@ -3427,11 +3486,11 @@
  1364.                 case PACKAGE_SELL:
  1365.                     sendPacket(new PrivateStoreListSell(this, temp));
  1366.                     break;
  1367. -              
  1368. +                  
  1369.                 case BUY:
  1370.                     sendPacket(new PrivateStoreListBuy(this, temp));
  1371.                     break;
  1372. -              
  1373. +                  
  1374.                 case MANUFACTURE:
  1375.                     sendPacket(new RecipeShopSellList(this, temp));
  1376.                     break;
  1377. @@ -3743,7 +3802,7 @@
  1378.         {
  1379.             if (oldTarget.equals(newTarget))
  1380.                 return; // no target change
  1381. -              
  1382. +          
  1383.             // Remove the L2PcInstance from the _statusListener of the old target if it was a L2Character
  1384.             if (oldTarget instanceof Character)
  1385.                 ((Character) oldTarget).removeStatusListener(this);
  1386. @@ -3826,7 +3885,7 @@
  1387.         final ItemInstance armor = getInventory().getPaperdollItem((type == ArmorType.SHIELD) ? Inventory.PAPERDOLL_LHAND : Inventory.PAPERDOLL_CHEST);
  1388.         if (armor == null)
  1389.             return type == ArmorType.NONE; // Return true if not equipped and the check was based on NONE ArmorType.
  1390. -          
  1391. +      
  1392.         // Test if the equipped item is an armor, then finally compare both ArmorType.
  1393.         return armor.getItemType() instanceof ArmorType && armor.getItemType() == type;
  1394.     }
  1395. @@ -3936,6 +3995,125 @@
  1396.         {
  1397.             Player pk = killer.getActingPlayer();
  1398.            
  1399. +           if (pk != null && pk._inEventTvT && _inEventTvT)
  1400. +           {
  1401. +               if (TvT._teleport || TvT._started)
  1402. +               {
  1403. +                   if (!(pk._teamNameTvT.equals(_teamNameTvT)))
  1404. +                   {
  1405. +                       QuestState ps = pk.getQuestState(null);
  1406. +                       ps.playSound(QuestState.SOUND_FINISH);
  1407. +                      
  1408. +                       _countTvTdies++;
  1409. +                       pk._countTvTkills++;
  1410. +                       pk.setTitle("Kills: " + pk._countTvTkills);
  1411. +
  1412. +                       TvT.setTeamKillsCount(pk._teamNameTvT, TvT.teamKillsCount(pk._teamNameTvT) + 1);
  1413. +                   }
  1414. +                   else
  1415. +                   {
  1416. +                       pk.sendMessage("You are a teamkiller! Teamkills are not allowed, you will get death penalty and your team will lose one kill!");
  1417. +                      
  1418. +                       // Give Penalty for Team-Kill:
  1419. +                       // 1. Death Penalty + 5
  1420. +                       // 2. Team will lost 1 Kill
  1421. +                       if (pk.getDeathPenaltyBuffLevel() < 10)
  1422. +                       {
  1423. +                           pk.setDeathPenaltyBuffLevel(pk.getDeathPenaltyBuffLevel() + 4);
  1424. +                           pk.getDeathPenaltyBuffLevel();
  1425. +                       }
  1426. +                       TvT.setTeamKillsCount(_teamNameTvT, TvT.teamKillsCount(_teamNameTvT) - 1);
  1427. +                   }
  1428. +                   sendMessage("You will be revived and teleported to team spot in " + Config.TVT_REVIVE_DELAY / 1000 + " seconds!");
  1429. +                   ThreadPool.schedule(new Runnable()
  1430. +                   {
  1431. +                       @Override
  1432. +                       public void run()
  1433. +                       {
  1434. +                           teleToLocation(TvT._teamsX.get(TvT._teams.indexOf(_teamNameTvT)), TvT._teamsY.get(TvT._teams.indexOf(_teamNameTvT)), TvT._teamsZ.get(TvT._teams.indexOf(_teamNameTvT)), 0);
  1435. +                           doRevive();
  1436. +                       }
  1437. +                   }, Config.TVT_REVIVE_DELAY);
  1438. +               }
  1439. +           }
  1440. +           else if (_inEventTvT)
  1441. +           {
  1442. +               if (TvT._teleport || TvT._started)
  1443. +               {
  1444. +                   sendMessage("You will be revived and teleported to team spot in " + Config.TVT_REVIVE_DELAY / 1000 + " seconds!");
  1445. +                   ThreadPool.schedule(new Runnable()
  1446. +                   {
  1447. +                       @Override
  1448. +                       public void run()
  1449. +                       {
  1450. +                           teleToLocation(TvT._teamsX.get(TvT._teams.indexOf(_teamNameTvT)), TvT._teamsY.get(TvT._teams.indexOf(_teamNameTvT)), TvT._teamsZ.get(TvT._teams.indexOf(_teamNameTvT)), 0);
  1451. +                           doRevive();
  1452. +                       }
  1453. +                   }, Config.TVT_REVIVE_DELAY);
  1454. +               }
  1455. +           }
  1456. +           else if (_inEventCTF)
  1457. +           {
  1458. +               if (CTF._teleport || CTF._started)
  1459. +               {
  1460. +                   sendMessage("You will be revived and teleported to team flag in " + Config.CTF_REVIVE_DELAY / 1000 + " seconds!");
  1461. +                  
  1462. +                   if (_haveFlagCTF)
  1463. +                   {
  1464. +                       removeCTFFlagOnDie();
  1465. +                   }
  1466. +                  
  1467. +                   ThreadPool.schedule(new Runnable()
  1468. +                   {
  1469. +                       @Override
  1470. +                       public void run()
  1471. +                       {
  1472. +                           teleToLocation(CTF._teamsX.get(CTF._teams.indexOf(_teamNameCTF)), CTF._teamsY.get(CTF._teams.indexOf(_teamNameCTF)), CTF._teamsZ.get(CTF._teams.indexOf(_teamNameCTF)), 0);
  1473. +                           doRevive();
  1474. +                       }
  1475. +                   }, Config.CTF_REVIVE_DELAY);
  1476. +               }
  1477. +           }
  1478. +           else if ((killer instanceof Player && ((Player) killer)._inEventDM) && _inEventDM)
  1479. +           {
  1480. +               if (DM._teleport || DM._started)
  1481. +               {
  1482. +                   ((Player) killer)._countDMkills++;
  1483. +                  
  1484. +                   sendMessage("You will be revived and teleported to spot in " + Config.DM_REVIVE_DELAY / 1000 + " seconds!");
  1485. +                   ThreadPool.schedule(new Runnable()
  1486. +                   {
  1487. +                       @Override
  1488. +                       public void run()
  1489. +                       {
  1490. +                           teleToLocation(DM._playerX, DM._playerY, DM._playerZ, 0);
  1491. +                           doRevive();
  1492. +                       }
  1493. +                   }, Config.DM_REVIVE_DELAY);
  1494. +               }
  1495. +           }
  1496. +           else if (_inEventDM)
  1497. +           {
  1498. +               if (DM._teleport || DM._started)
  1499. +               {
  1500. +                   sendMessage("You will be revived and teleported to spot in " + Config.DM_REVIVE_DELAY / 1000 + " seconds!");
  1501. +                   ThreadPool.schedule(new Runnable()
  1502. +                   {
  1503. +                       @Override
  1504. +                       public void run()
  1505. +                       {
  1506. +                           teleToLocation(DM._playerX, DM._playerY, DM._playerZ, 0);
  1507. +                           doRevive();
  1508. +                       }
  1509. +                   }, Config.DM_REVIVE_DELAY);
  1510. +               }
  1511. +           }
  1512. +          
  1513. +           if (atEvent && pk != null)
  1514. +           {
  1515. +               pk.kills.add(getName());
  1516. +           }
  1517. +          
  1518.             // Clear resurrect xp calculation
  1519.             setExpBeforeDeath(0);
  1520.            
  1521. @@ -3991,7 +4169,7 @@
  1522.         for (Character character : getKnownType(Character.class))
  1523.             if (character.getFusionSkill() != null && character.getFusionSkill().getTarget() == this)
  1524.                 character.abortCast();
  1525. -          
  1526. +      
  1527.         // calculate death penalty buff
  1528.         calculateDeathPenaltyBuffLevel(killer);
  1529.        
  1530. @@ -4062,7 +4240,7 @@
  1531.                     }
  1532.                     else
  1533.                         itemDropPercent = dropItem; // Item in inventory
  1534. -                      
  1535. +                  
  1536.                     // NOTE: Each time an item is dropped, the chance of another item being dropped gets lesser (dropCount * 2)
  1537.                     if (Rnd.get(100) < itemDropPercent)
  1538.                     {
  1539. @@ -4100,6 +4278,9 @@
  1540.         if (targetPlayer == null || targetPlayer == this)
  1541.             return;
  1542.        
  1543. +       if (_inEventCTF || _inEventTvT || _inEventDM)
  1544. +           return;
  1545. +      
  1546.         // Don't rank up the CW if it was a summon.
  1547.         if (isCursedWeaponEquipped() && target instanceof Player)
  1548.         {
  1549. @@ -4110,7 +4291,7 @@
  1550.         // If in duel and you kill (only can kill l2summon), do nothing
  1551.         if (isInDuel() && targetPlayer.isInDuel())
  1552.             return;
  1553. -
  1554. +      
  1555.         // If in pvp zone, do nothing.
  1556.         if (isInsideZone(ZoneId.PVP) && targetPlayer.isInsideZone(ZoneId.PVP))
  1557.         {
  1558. @@ -4134,6 +4315,9 @@
  1559.         {
  1560.             if (target instanceof Player)
  1561.             {
  1562. +               if ((TvT._started && _inEventTvT) || (DM._started && _inEventDM) || (CTF._started && _inEventCTF))
  1563. +                   return;
  1564. +              
  1565.                 // Add PvP point to attacker.
  1566.                 setPvpKills(getPvpKills() + 1);
  1567.                
  1568. @@ -4148,6 +4332,9 @@
  1569.             if (target instanceof Player)
  1570.                 setPkKills(getPkKills() + 1);
  1571.            
  1572. +           if ((TvT._started && _inEventTvT) || (DM._started && _inEventDM) || (CTF._started && _inEventCTF))
  1573. +               return;
  1574. +          
  1575.             // Calculate new karma.
  1576.             setKarma(getKarma() + Formulas.calculateKarmaGain(getPkKills(), target instanceof Summon));
  1577.            
  1578. @@ -4156,11 +4343,19 @@
  1579.         }
  1580.     }
  1581.    
  1582. +   public boolean isInFunEvent()
  1583. +   {
  1584. +       return (atEvent || (TvT._started && _inEventTvT) || (DM._started && _inEventDM) || (CTF._started && _inEventCTF));
  1585. +   }
  1586. +  
  1587.     public void updatePvPStatus()
  1588.     {
  1589.         if (isInsideZone(ZoneId.PVP))
  1590.             return;
  1591. -
  1592. +      
  1593. +       if ((TvT._started && _inEventTvT) ||(DM._started && _inEventDM) || (CTF._started && _inEventCTF))
  1594. +           return;
  1595. +      
  1596.         PvpFlagTaskManager.getInstance().add(this, Config.PVP_NORMAL_TIME);
  1597.        
  1598.         if (getPvpFlag() == 0)
  1599. @@ -4172,7 +4367,10 @@
  1600.         final Player player = target.getActingPlayer();
  1601.         if (player == null)
  1602.             return;
  1603. -
  1604. +      
  1605. +       if ((TvT._started && _inEventTvT && target._inEventTvT) || (DM._started && _inEventDM && target._inEventDM) || (CTF._started && _inEventCTF && target._inEventCTF))
  1606. +           return;
  1607. +      
  1608.         if (isInDuel() && player.getDuelId() == getDuelId())
  1609.             return;
  1610.        
  1611. @@ -4227,7 +4425,7 @@
  1612.             else if (killedByPlayable)
  1613.                 return;
  1614.         }
  1615. -
  1616. +      
  1617.         // Get the level of the L2PcInstance
  1618.         final int lvl = getLevel();
  1619.        
  1620. @@ -4246,12 +4444,12 @@
  1621.        
  1622.         // Calculate the Experience loss
  1623.         long lostExp = 0;
  1624. +       if (!atEvent && !_inEventTvT && !_inEventDM && !_inEventCTF)
  1625. +           if (lvl < Experience.MAX_LEVEL)
  1626. +               lostExp = Math.round((getStat().getExpForLevel(lvl + 1) - getStat().getExpForLevel(lvl)) * percentLost / 100);
  1627. +           else
  1628. +               lostExp = Math.round((getStat().getExpForLevel(Experience.MAX_LEVEL) - getStat().getExpForLevel(Experience.MAX_LEVEL - 1)) * percentLost / 100);
  1629.        
  1630. -       if (lvl < Experience.MAX_LEVEL)
  1631. -           lostExp = Math.round((getStat().getExpForLevel(lvl + 1) - getStat().getExpForLevel(lvl)) * percentLost / 100);
  1632. -       else
  1633. -           lostExp = Math.round((getStat().getExpForLevel(Experience.MAX_LEVEL) - getStat().getExpForLevel(Experience.MAX_LEVEL - 1)) * percentLost / 100);
  1634. -      
  1635.         // Get the Experience before applying penalty
  1636.         setExpBeforeDeath(getExp());
  1637.        
  1638. @@ -4720,8 +4918,8 @@
  1639.         if (wpn != null)
  1640.         {
  1641.             if (wpn.getItemId() == 9999)
  1642. -                               return false;
  1643. -                          
  1644. +               return false;
  1645. +          
  1646.             ItemInstance[] unequipped = getInventory().unEquipItemInBodySlotAndRecord(wpn);
  1647.             InventoryUpdate iu = new InventoryUpdate();
  1648.             for (ItemInstance itm : unequipped)
  1649. @@ -5545,6 +5743,19 @@
  1650.     }
  1651.    
  1652.     /**
  1653. +    * checks if player is same team member in TvT
  1654. +    * @param attacker
  1655. +    * @param target
  1656. +    * @return
  1657. +    */
  1658. +   public static boolean isMemberOfSameTeam(Character attacker, Character target)
  1659. +   {
  1660. +       if ((attacker instanceof Player && ((Player) attacker)._inEventTvT && ((Player) attacker)._teamNameTvT == ((Player) target)._teamNameTvT && ((Player) target)._inEventTvT))
  1661. +           return true;
  1662. +       return false;
  1663. +   }
  1664. +  
  1665. +   /**
  1666.      * Restores secondary data for the L2PcInstance, based on the current class index.
  1667.      */
  1668.     private void restoreCharData()
  1669. @@ -6062,7 +6273,7 @@
  1670.                
  1671.                 if (id > 9000)
  1672.                     continue; // fake skills for base stats
  1673. -                  
  1674. +              
  1675.                 // Create a L2Skill object for each record
  1676.                 L2Skill skill = SkillTable.getInstance().getInfo(id, level);
  1677.                
  1678. @@ -6465,7 +6676,7 @@
  1679.             // is AutoAttackable if both players are in the same duel and the duel is still going on
  1680.             if (getDuelState() == DuelState.DUELLING && getDuelId() == cha.getDuelId())
  1681.                 return true;
  1682. -
  1683. +          
  1684.             if (getClan() != null)
  1685.             {
  1686.                 final Siege siege = CastleManager.getInstance().getSiege(this);
  1687. @@ -6544,7 +6755,7 @@
  1688.             sendPacket(ActionFailed.STATIC_PACKET);
  1689.             return false;
  1690.         }
  1691. -
  1692. +      
  1693.         // Cancels the use of skills when player uses a cursed weapon or is flying.
  1694.         if ((isCursedWeaponEquipped() && !skill.isDemonicSkill()) // If CW, allow ONLY demonic skills.
  1695.             || (getMountType() == 1 && !skill.isStriderSkill()) // If mounted, allow ONLY Strider skills.
  1696. @@ -6605,7 +6816,7 @@
  1697.             case TARGET_AURA_UNDEAD:
  1698.                 target = this;
  1699.                 break;
  1700. -          
  1701. +              
  1702.             default: // Get the first target of the list
  1703.                 target = skill.getFirstOfTargetList(this);
  1704.                 break;
  1705. @@ -6698,6 +6909,7 @@
  1706.         // ************************************* Check Target *******************************************
  1707.         // Create and set a L2Object containing the target of the skill
  1708.         L2Object target = null;
  1709. +       L2SkillType SkillType = skill.getSkillType();
  1710.         SkillTargetType sklTargetType = skill.getTargetType();
  1711.         Location worldPosition = getCurrentSkillWorldPosition();
  1712.        
  1713. @@ -6767,6 +6979,36 @@
  1714.             }
  1715.         }
  1716.        
  1717. +       if (_inEventTvT && TvT._started && !Config.TVT_ALLOW_ENEMY_HEALING)
  1718. +       {
  1719. +           if (target instanceof Player && skill.getSkillType() == L2SkillType.HEAL)
  1720. +           {
  1721. +               if (!isMemberOfSameTeam((this), (Player) target))
  1722. +               {
  1723. +                   sendPacket(SystemMessageId.INCORRECT_TARGET);
  1724. +                   sendPacket(ActionFailed.STATIC_PACKET);
  1725. +                   return false;
  1726. +               }
  1727. +              
  1728. +               // prevent usage of skills in same team members on TvT if tvt is on figthing period and if config is enabled
  1729. +               if (_inEventTvT && TvT._started && !Config.TVT_ALLOW_TEAM_CASTING)
  1730. +               {
  1731. +                   if (target instanceof Player && skill.getTargetType() != SkillTargetType.TARGET_SELF && skill.getSkillType() != L2SkillType.BUFF)
  1732. +                   {
  1733. +                       if (isMemberOfSameTeam((this), (Player) target))
  1734. +                       {
  1735. +                           if (skill.getSkillType() == L2SkillType.PDAM || skill.getSkillType() == L2SkillType.MDAM || (skill.getSkillType() == L2SkillType.BLOW))
  1736. +                           {
  1737. +                               sendPacket(SystemMessageId.INCORRECT_TARGET);
  1738. +                               sendPacket(ActionFailed.STATIC_PACKET);
  1739. +                               return false;
  1740. +                           }
  1741. +                       }
  1742. +                   }
  1743. +               }
  1744. +           }
  1745. +       }
  1746. +      
  1747.         // ************************************* Check skill availability *******************************************
  1748.        
  1749.         // Siege summon checks. Both checks send a message to the player if it return false.
  1750. @@ -6788,6 +7030,11 @@
  1751.        
  1752.         // ************************************* Check casting conditions *******************************************
  1753.        
  1754. +       if (_inEventCTF && !Config.CTF_ALLOW_SUMMON && CTF._started && SkillType == L2SkillType.SUMMON)
  1755. +       {
  1756. +           sendPacket(SystemMessageId.NOTHING_HAPPENED);
  1757. +       }
  1758. +      
  1759.         // Check if all casting conditions are completed
  1760.         if (!skill.checkCondition(this, target, false))
  1761.         {
  1762. @@ -7154,7 +7401,7 @@
  1763.            
  1764.             final L2Clan aClan = getClan();
  1765.             final L2Clan tClan = targetPlayer.getClan();
  1766. -
  1767. +          
  1768.             if (aClan != null && tClan != null)
  1769.             {
  1770.                 if (aClan.isAtWarWith(tClan.getClanId()) && tClan.isAtWarWith(aClan.getClanId()))
  1771. @@ -7174,7 +7421,7 @@
  1772.                     return false;
  1773.                 }
  1774.             }
  1775. -
  1776. +          
  1777.             // On retail, it is impossible to debuff a "peaceful" player.
  1778.             if (targetPlayer.getPvpFlag() == 0 && targetPlayer.getKarma() == 0)
  1779.             {
  1780. @@ -7226,7 +7473,7 @@
  1781.                 if (isFlying())
  1782.                     removeSkill(FrequentSkill.WYVERN_BREATH.getSkill());
  1783.                 break;
  1784. -          
  1785. +              
  1786.             case 2: // Flying Wyvern
  1787.                 addSkill(FrequentSkill.WYVERN_BREATH.getSkill(), false); // not saved to DB
  1788.                 break;
  1789. @@ -7973,7 +8220,7 @@
  1790.         else
  1791.             for (L2Skill s : SkillTable.getNobleSkills())
  1792.                 super.removeSkill(s); // Just Remove skills without deleting from Sql
  1793. -              
  1794. +      
  1795.         _isNoble = val;
  1796.        
  1797.         sendSkillList();
  1798. @@ -8071,7 +8318,7 @@
  1799.         {
  1800.             if (s.getId() > 9000 && s.getId() < 9007)
  1801.                 continue; // Fake skills to change base stats
  1802. -              
  1803. +          
  1804.             if (getClan() != null)
  1805.                 isDisabled = s.isClanSkill() && getClan().getReputationScore() < 0;
  1806.            
  1807. @@ -8104,7 +8351,7 @@
  1808.     {
  1809.         if (!_subclassLock.tryLock())
  1810.             return false;
  1811. -
  1812. +      
  1813.         try
  1814.         {
  1815.             if (_subClasses.size() == 3 || classIndex == 0 || _subClasses.containsKey(classIndex))
  1816. @@ -8305,7 +8552,7 @@
  1817.             for (Character character : getKnownType(Character.class))
  1818.                 if (character.getFusionSkill() != null && character.getFusionSkill().getTarget() == this)
  1819.                     character.abortCast();
  1820. -              
  1821. +          
  1822.             store();
  1823.             _reuseTimeStamps.clear();
  1824.            
  1825. @@ -8534,6 +8781,13 @@
  1826.         if (isMounted())
  1827.             startFeed(_mountNpcId);
  1828.        
  1829. +       if ((_inEventTvT && TvT._started && Config.TVT_REVIVE_RECOVERY) || (_inEventCTF && CTF._started && Config.CTF_REVIVE_RECOVERY))
  1830. +       {
  1831. +           getStatus().setCurrentHp(getMaxHp());
  1832. +           getStatus().setCurrentMp(getMaxMp());
  1833. +           getStatus().setCurrentCp(getMaxCp());
  1834. +       }
  1835. +      
  1836.         // Schedule a paralyzed task to wait for the animation to finish
  1837.         ThreadPool.schedule(new Runnable()
  1838.         {
  1839. @@ -8545,6 +8799,16 @@
  1840.         }, (int) (2000 / getStat().getMovementSpeedMultiplier()));
  1841.         setIsParalyzed(true);
  1842.     }
  1843. +
  1844. +   public void removeCTFFlagOnDie()
  1845. +   {
  1846. +       CTF._flagsTaken.set(CTF._teams.indexOf(_teamNameHaveFlagCTF), false);
  1847. +       CTF.spawnFlag(_teamNameHaveFlagCTF);
  1848. +       CTF.removeFlagFromPlayer(this);
  1849. +       broadcastUserInfo();
  1850. +       _haveFlagCTF = false;
  1851. +       CTF.AnnounceToPlayers(false, CTF._eventName + "(CTF): " + _teamNameHaveFlagCTF + "'s flag returned.");
  1852. +   }
  1853.    
  1854.     @Override
  1855.     public void doRevive(double revivePower)
  1856. @@ -8675,6 +8939,29 @@
  1857.        
  1858.         if (Config.PLAYER_SPAWN_PROTECTION > 0)
  1859.             setSpawnProtection(true);
  1860. +
  1861. +       if (L2Event.active && L2Event.connectionLossData.containsKey(getName()) && L2Event.isOnEvent(this))
  1862. +       {
  1863. +           L2Event.restoreChar(this);
  1864. +       }
  1865. +       else if (L2Event.connectionLossData.containsKey(getName()))
  1866. +       {
  1867. +           L2Event.restoreAndTeleChar(this);
  1868. +       }
  1869. +       if (TvT._savePlayers.contains(getName()))
  1870. +       {
  1871. +           TvT.addDisconnectedPlayer(this);
  1872. +       }
  1873. +
  1874. +       if (CTF._savePlayers.contains(getName()))
  1875. +       {
  1876. +           CTF.addDisconnectedPlayer(this);
  1877. +       }
  1878. +
  1879. +       if (DM._savePlayers.contains(getName()))
  1880. +       {
  1881. +           DM.addDisconnectedPlayer(this);
  1882. +       }
  1883.        
  1884.         // Stop toggles upon teleport.
  1885.         if (!isGM())
  1886. @@ -8889,7 +9176,7 @@
  1887.             for (Character character : getKnownType(Character.class))
  1888.                 if (character.getFusionSkill() != null && character.getFusionSkill().getTarget() == this)
  1889.                     character.abortCast();
  1890. -              
  1891. +          
  1892.             // Stop signets & toggles effects.
  1893.             for (L2Effect effect : getAllEffects())
  1894.             {
  1895. @@ -9051,13 +9338,13 @@
  1896.             case 7809: // yellow for beginners
  1897.             case 8486: // prize-winning for beginners
  1898.                 return 0;
  1899. -          
  1900. +              
  1901.             case 8485: // prize-winning luminous
  1902.             case 8506: // green luminous
  1903.             case 8509: // purple luminous
  1904.             case 8512: // yellow luminous
  1905.                 return 2;
  1906. -          
  1907. +              
  1908.             default:
  1909.                 return 1;
  1910.         }
  1911. @@ -9080,7 +9367,7 @@
  1912.                         else
  1913.                             type = 6;
  1914.                         break;
  1915. -                  
  1916. +                      
  1917.                     case 7808: // purple lure, preferred by fat fish (type 4)
  1918.                         if (check <= 54)
  1919.                             type = 4;
  1920. @@ -9089,7 +9376,7 @@
  1921.                         else
  1922.                             type = 5;
  1923.                         break;
  1924. -                  
  1925. +                      
  1926.                     case 7809: // yellow lure, preferred by ugly fish (type 6)
  1927.                         if (check <= 54)
  1928.                             type = 6;
  1929. @@ -9098,7 +9385,7 @@
  1930.                         else
  1931.                             type = 4;
  1932.                         break;
  1933. -                  
  1934. +                      
  1935.                     case 8486: // prize-winning fishing lure for beginners
  1936.                         if (check <= 33)
  1937.                             type = 4;
  1938. @@ -9109,7 +9396,7 @@
  1939.                         break;
  1940.                 }
  1941.                 break;
  1942. -          
  1943. +              
  1944.             case 1: // normal fish
  1945.                 switch (_lure.getItemId())
  1946.                 {
  1947. @@ -9119,7 +9406,7 @@
  1948.                     case 7613:
  1949.                         type = 3;
  1950.                         break;
  1951. -                  
  1952. +                      
  1953.                     case 6519: // all theese lures (green) are prefered by fast-moving (nimble) fish (type 1)
  1954.                     case 8505:
  1955.                     case 6520:
  1956. @@ -9134,7 +9421,7 @@
  1957.                         else
  1958.                             type = 3;
  1959.                         break;
  1960. -                  
  1961. +                      
  1962.                     case 6522: // all theese lures (purple) are prefered by fat fish (type 0)
  1963.                     case 8508:
  1964.                     case 6523:
  1965. @@ -9149,7 +9436,7 @@
  1966.                         else
  1967.                             type = 3;
  1968.                         break;
  1969. -                  
  1970. +                      
  1971.                     case 6525: // all theese lures (yellow) are prefered by ugly fish (type 2)
  1972.                     case 8511:
  1973.                     case 6526:
  1974. @@ -9174,7 +9461,7 @@
  1975.                         break;
  1976.                 }
  1977.                 break;
  1978. -          
  1979. +              
  1980.             case 2: // upper grade fish, luminous lure
  1981.                 switch (_lure.getItemId())
  1982.                 {
  1983. @@ -9186,7 +9473,7 @@
  1984.                         else
  1985.                             type = 9;
  1986.                         break;
  1987. -                  
  1988. +                      
  1989.                     case 8509: // purple lure, preferred by fat fish (type 7)
  1990.                         if (check <= 54)
  1991.                             type = 7;
  1992. @@ -9195,7 +9482,7 @@
  1993.                         else
  1994.                             type = 8;
  1995.                         break;
  1996. -                  
  1997. +                      
  1998.                     case 8512: // yellow lure, preferred by ugly fish (type 9)
  1999.                         if (check <= 54)
  2000.                             type = 9;
  2001. @@ -9204,7 +9491,7 @@
  2002.                         else
  2003.                             type = 7;
  2004.                         break;
  2005. -                  
  2006. +                      
  2007.                     case 8485: // prize-winning fishing lure
  2008.                         if (check <= 33)
  2009.                             type = 7;
  2010. @@ -9608,12 +9895,12 @@
  2011.     {
  2012.         return _punishTimer;
  2013.     }
  2014. -
  2015. +  
  2016.     public int getAntiAfk()
  2017.     {      
  2018.         return antiAfkTime;
  2019.     }
  2020. -  
  2021. +  
  2022.     public void setAntiAfk(int antiAfk)
  2023.     {
  2024.         antiAfkTime = antiAfk;
  2025. @@ -9737,7 +10024,7 @@
  2026.     {
  2027.         if (_deathPenaltyBuffLevel >= 15) // maximum level reached
  2028.             return;
  2029. -
  2030. +      
  2031.         if ((getKarma() > 0 || Rnd.get(1, 100) <= Config.DEATH_PENALTY_CHANCE) && !(killer instanceof Player) && !isGM() && !(getCharmOfLuck() && (killer == null || killer.isRaid())) && !isPhoenixBlessed() && !(isInsideZone(ZoneId.PVP) || isInsideZone(ZoneId.SIEGE)))
  2032.         {
  2033.             if (_deathPenaltyBuffLevel != 0)
  2034. @@ -10192,7 +10479,7 @@
  2035.             summonerChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_IN_SUMMON_BLOCKING_AREA).addCharName(targetChar));
  2036.             return false;
  2037.         }
  2038. -
  2039. +      
  2040.         return true;
  2041.     }
  2042.    
  2043. @@ -10445,11 +10732,11 @@
  2044.             case PACKAGE_SELL:
  2045.                 activeChar.sendPacket(new PrivateStoreMsgSell(this));
  2046.                 break;
  2047. -          
  2048. +              
  2049.             case BUY:
  2050.                 activeChar.sendPacket(new PrivateStoreMsgBuy(this));
  2051.                 break;
  2052. -          
  2053. +              
  2054.             case MANUFACTURE:
  2055.                 activeChar.sendPacket(new RecipeShopMsg(this));
  2056.                 break;
  2057. Index: java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
  2058. ===================================================================
  2059. --- java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (revision 1)
  2060. +++ java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (working copy)
  2061. @@ -8,11 +8,13 @@
  2062.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminBan;
  2063.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminBookmark;
  2064.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminBuffs;
  2065. +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminCTFEngine;
  2066.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminCache;
  2067.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminCamera;
  2068.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminChangeAccessLevel;
  2069.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminCreateItem;
  2070.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminCursedWeapons;
  2071. +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminDMEngine;
  2072.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminDelete;
  2073.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminDoorControl;
  2074.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminEditChar;
  2075. @@ -19,6 +21,7 @@
  2076.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminEditNpc;
  2077.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminEffects;
  2078.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminEnchant;
  2079. +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminEventEngine;
  2080.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminExpSp;
  2081.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminGeoEngine;
  2082.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminGm;
  2083. @@ -48,6 +51,7 @@
  2084.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSpawn;
  2085.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminTarget;
  2086.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminTeleport;
  2087. +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminTvTEngine;
  2088.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminZone;
  2089.  
  2090.  public class AdminCommandHandler
  2091. @@ -107,6 +111,10 @@
  2092.         registerAdminCommandHandler(new AdminTarget());
  2093.         registerAdminCommandHandler(new AdminTeleport());
  2094.         registerAdminCommandHandler(new AdminZone());
  2095. +       registerAdminCommandHandler(new AdminCTFEngine());
  2096. +       registerAdminCommandHandler(new AdminDMEngine());
  2097. +       registerAdminCommandHandler(new AdminEventEngine());
  2098. +       registerAdminCommandHandler(new AdminTvTEngine());
  2099.     }
  2100.    
  2101.     public void registerAdminCommandHandler(IAdminCommandHandler handler)
  2102. Index: java/net/sf/l2j/gameserver/model/entity/engine/CTF.java
  2103. ===================================================================
  2104. --- java/net/sf/l2j/gameserver/model/entity/engine/CTF.java (revision 0)
  2105. +++ java/net/sf/l2j/gameserver/model/entity/engine/CTF.java (working copy)
  2106. @@ -0,0 +1,2223 @@
  2107. +/*
  2108. + * This program is free software: you can redistribute it and/or modify it under
  2109. + * the terms of the GNU General Public License as published by the Free Software
  2110. + * Foundation, either version 3 of the License, or (at your option) any later
  2111. + * version.
  2112. + *
  2113. + * This program is distributed in the hope that it will be useful, but WITHOUT
  2114. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  2115. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  2116. + * details.
  2117. + *
  2118. + * You should have received a copy of the GNU General Public License along with
  2119. + * this program. If not, see <http://www.gnu.org/licenses/>.
  2120. + */
  2121. +package net.sf.l2j.gameserver.model.entity.engine;
  2122. +
  2123. +import java.sql.Connection;
  2124. +import java.sql.PreparedStatement;
  2125. +import java.sql.ResultSet;
  2126. +import java.sql.SQLException;
  2127. +import java.util.ArrayList;
  2128. +import java.util.List;
  2129. +import java.util.logging.Logger;
  2130. +
  2131. +import net.sf.l2j.Config;
  2132. +import net.sf.l2j.L2DatabaseFactory;
  2133. +import net.sf.l2j.commons.concurrent.ThreadPool;
  2134. +import net.sf.l2j.commons.random.Rnd;
  2135. +import net.sf.l2j.gameserver.datatables.ItemTable;
  2136. +import net.sf.l2j.gameserver.datatables.NpcTable;
  2137. +import net.sf.l2j.gameserver.datatables.SpawnTable;
  2138. +import net.sf.l2j.gameserver.model.L2Effect;
  2139. +import net.sf.l2j.gameserver.model.L2Radar;
  2140. +import net.sf.l2j.gameserver.model.L2Spawn;
  2141. +import net.sf.l2j.gameserver.model.actor.Summon;
  2142. +import net.sf.l2j.gameserver.model.actor.instance.Pet;
  2143. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  2144. +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  2145. +import net.sf.l2j.gameserver.model.group.Party;
  2146. +import net.sf.l2j.gameserver.model.group.Party.MessageType;
  2147. +import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
  2148. +import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
  2149. +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  2150. +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  2151. +import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
  2152. +import net.sf.l2j.gameserver.network.serverpackets.ItemList;
  2153. +import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  2154. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  2155. +import net.sf.l2j.gameserver.network.serverpackets.RadarControl;
  2156. +import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
  2157. +import net.sf.l2j.gameserver.util.Broadcast;
  2158. +
  2159. +/**
  2160. + * @author SqueezeD & Darki699 (idea by FBIAgent)
  2161. + */
  2162. +public class CTF
  2163. +{
  2164. +   private final static Logger _log = Logger.getLogger(CTF.class.getName());
  2165. +   private static int _FlagNPC = 35062, _FLAG_IN_HAND_ITEM_ID = 6718;
  2166. +   public static String _eventName = new String(), _eventDesc = new String(), _topTeam = new String(),
  2167. +   _joiningLocationName = new String();
  2168. +   public static List<String> _teams = new ArrayList<>(), _savePlayers = new ArrayList<>(),
  2169. +           _savePlayerTeams = new ArrayList<>();
  2170. +   public static List<Player> _players = new ArrayList<>(),
  2171. +           _playersShuffle = new ArrayList<>();
  2172. +   public static List<Integer> _teamPlayersCount = new ArrayList<>(), _teamColors = new ArrayList<>(),
  2173. +           _teamsX = new ArrayList<>(), _teamsY = new ArrayList<>(), _teamsZ = new ArrayList<>();
  2174. +   public static boolean _joining = false, _teleport = false, _started = false, _sitForced = false;
  2175. +   public static L2Spawn _npcSpawn;
  2176. +   public static int _npcId = 0, _npcX = 0, _npcY = 0, _npcZ = 0, _npcHeading = 0, _rewardId = 0, _rewardAmount = 0,
  2177. +           _minlvl = 0, _maxlvl = 0, _joinTime = 0, _eventTime = 0, _minPlayers = 0, _maxPlayers = 0;
  2178. +   public static List<Integer> _teamPointsCount = new ArrayList<>();
  2179. +   public static List<Integer> _flagIds = new ArrayList<>(), _flagsX = new ArrayList<>(),
  2180. +           _flagsY = new ArrayList<>(), _flagsZ = new ArrayList<>();
  2181. +   public static List<L2Spawn> _flagSpawns = new ArrayList<>(), _throneSpawns = new ArrayList<>();
  2182. +   public static List<Boolean> _flagsTaken = new ArrayList<>();
  2183. +   public static int _topScore = 0, eventCenterX = 0, eventCenterY = 0, eventCenterZ = 0, eventOffset = 0;
  2184. +
  2185. +   public static void showFlagHtml(Player eventPlayer, String objectId, String teamName)
  2186. +   {
  2187. +       if (eventPlayer == null)
  2188. +           return;
  2189. +
  2190. +       try
  2191. +       {
  2192. +           NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  2193. +
  2194. +           StringBuilder replyMSG = new StringBuilder();
  2195. +
  2196. +           replyMSG.append("<html><body><center>");
  2197. +           replyMSG.append("CTF Flag<br><br>");
  2198. +           replyMSG.append("<font color=\"00FF00\">" + teamName + "'s Flag</font><br>");
  2199. +           if (eventPlayer._teamNameCTF != null && eventPlayer._teamNameCTF.equals(teamName))
  2200. +               replyMSG.append("<font color=\"LEVEL\">This is your Flag</font><br>");
  2201. +           else
  2202. +               replyMSG.append("<font color=\"LEVEL\">Enemy Flag!</font><br>");
  2203. +           if (_started)
  2204. +               processInFlagRange(eventPlayer);
  2205. +           else
  2206. +               replyMSG.append("CTF match is not in progress yet.<br>Wait for a GM to start the event<br>");
  2207. +           replyMSG.append("</center></body></html>");
  2208. +           adminReply.setHtml(replyMSG.toString());
  2209. +           eventPlayer.sendPacket(adminReply);
  2210. +       }
  2211. +       catch (Exception e)
  2212. +       {
  2213. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception: " + e.getStackTrace());
  2214. +       }
  2215. +   }
  2216. +
  2217. +   public static void CheckRestoreFlags()
  2218. +   {
  2219. +       List<Integer> teamsTakenFlag = new ArrayList<>();
  2220. +       try
  2221. +       {
  2222. +           for (Player player : _players)
  2223. +           { // if there's a player with a flag
  2224. +               // add the index of the team who's FLAG WAS TAKEN to the list
  2225. +               if (player != null)
  2226. +               {
  2227. +                   if (player.isOnline() && player._haveFlagCTF)// logged off with a flag in his hands
  2228. +                   {
  2229. +                       AnnounceToPlayers(false, _eventName + "(CTF): " + player.getName() + " logged off with a CTF flag!");
  2230. +                       player._haveFlagCTF = false;
  2231. +                       if (_teams.indexOf(player._teamNameHaveFlagCTF) >= 0)
  2232. +                       {
  2233. +                           if (_flagsTaken.get(_teams.indexOf(player._teamNameHaveFlagCTF)))
  2234. +                           {
  2235. +                               _flagsTaken.set(_teams.indexOf(player._teamNameHaveFlagCTF), false);
  2236. +                               spawnFlag(player._teamNameHaveFlagCTF);
  2237. +                               AnnounceToPlayers(false, _eventName + "(CTF): " + player._teamNameHaveFlagCTF + " flag now returned to place.");
  2238. +                           }
  2239. +                       }
  2240. +                       removeFlagFromPlayer(player);
  2241. +                       player._teamNameHaveFlagCTF = null;
  2242. +                       return;
  2243. +                   }
  2244. +                   else if (player._haveFlagCTF)
  2245. +                       teamsTakenFlag.add(_teams.indexOf(player._teamNameHaveFlagCTF));
  2246. +               }
  2247. +           }
  2248. +           // Go over the list of ALL teams
  2249. +           for (String team : _teams)
  2250. +           {
  2251. +               if (team == null)
  2252. +                   continue;
  2253. +               int index = _teams.indexOf(team);
  2254. +               if (!teamsTakenFlag.contains(index))
  2255. +               {
  2256. +                   if (_flagsTaken.get(index))
  2257. +                   {
  2258. +                       _flagsTaken.set(index, false);
  2259. +                       spawnFlag(team);
  2260. +                       AnnounceToPlayers(false, _eventName + "(CTF): " + team + " flag returned due to player error.");
  2261. +                   }
  2262. +               }
  2263. +           }
  2264. +           // Check if a player ran away from the event holding a flag:
  2265. +           for (Player player : _players)
  2266. +           {
  2267. +               if ((player != null) && player._haveFlagCTF)
  2268. +               {
  2269. +                   if (isOutsideCTFArea(player))
  2270. +                   {
  2271. +                       AnnounceToPlayers(false, _eventName + "(CTF): " + player.getName() + " escaped from the event holding a flag!");
  2272. +                       player._haveFlagCTF = false;
  2273. +                       if (_teams.indexOf(player._teamNameHaveFlagCTF) >= 0)
  2274. +                       {
  2275. +                           if (_flagsTaken.get(_teams.indexOf(player._teamNameHaveFlagCTF)))
  2276. +                           {
  2277. +                               _flagsTaken.set(_teams.indexOf(player._teamNameHaveFlagCTF), false);
  2278. +                               spawnFlag(player._teamNameHaveFlagCTF);
  2279. +                               AnnounceToPlayers(false, _eventName + "(CTF): " + player._teamNameHaveFlagCTF + " flag now returned to place.");
  2280. +                           }
  2281. +                       }
  2282. +                       removeFlagFromPlayer(player);
  2283. +                       player._teamNameHaveFlagCTF = null;
  2284. +                       player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ.get(_teams.indexOf(player._teamNameCTF)), 0);
  2285. +                       player.sendMessage("You have been returned to your team spawn");
  2286. +                       return;
  2287. +                   }
  2288. +               }
  2289. +           }
  2290. +       }
  2291. +       catch (Exception e)
  2292. +       {
  2293. +           _log.warning(CTF.class.getSimpleName() + ":  CTF.restoreFlags() Error:" + e.toString());
  2294. +       }
  2295. +   }
  2296. +
  2297. +   public static void kickPlayerFromCTf(Player playerToKick)
  2298. +   {
  2299. +       if (playerToKick == null)
  2300. +           return;
  2301. +
  2302. +       if (_joining)
  2303. +       {
  2304. +           _playersShuffle.remove(playerToKick);
  2305. +           _players.remove(playerToKick);
  2306. +           playerToKick._inEventCTF = false;
  2307. +           playerToKick._teamNameCTF = new String();
  2308. +       }
  2309. +       if (_started || _teleport)
  2310. +       {
  2311. +           _playersShuffle.remove(playerToKick);
  2312. +           playerToKick._inEventCTF = false;
  2313. +           removePlayer(playerToKick);
  2314. +           if (playerToKick.isOnline())
  2315. +           {
  2316. +               playerToKick.getAppearance().setNameColor(playerToKick._originalNameColorCTF);
  2317. +               playerToKick.setKarma(playerToKick._originalKarmaCTF);
  2318. +               playerToKick.setTitle(playerToKick._originalTitleCTF);
  2319. +               playerToKick.broadcastUserInfo();
  2320. +               playerToKick.sendMessage("You have been kicked from the CTF.");
  2321. +               playerToKick.teleToLocation(_npcX, _npcY, _npcZ, 0);
  2322. +           }
  2323. +       }
  2324. +   }
  2325. +
  2326. +   public static void AnnounceToPlayers(Boolean toall, String announce)
  2327. +   {
  2328. +       if (toall)
  2329. +           Broadcast.announceToOnlinePlayers(announce);
  2330. +       else
  2331. +       {
  2332. +           CreatureSay cs = new CreatureSay(0, 2, "", "Announcements : " + announce);
  2333. +           if (_players != null && !_players.isEmpty())
  2334. +           {
  2335. +               for (Player player : _players)
  2336. +               {
  2337. +                   if (player != null && player.isOnline())
  2338. +                       player.sendPacket(cs);
  2339. +               }
  2340. +           }
  2341. +       }
  2342. +   }
  2343. +
  2344. +   public static void Started(Player player)
  2345. +   {
  2346. +       player._teamNameHaveFlagCTF = null;
  2347. +       player._haveFlagCTF = false;
  2348. +   }
  2349. +
  2350. +   public static void StartEvent()
  2351. +   {
  2352. +       for (Player player : _players)
  2353. +       {
  2354. +           if (player != null)
  2355. +           {
  2356. +               player._teamNameHaveFlagCTF = null;
  2357. +               player._haveFlagCTF = false;
  2358. +           }
  2359. +       }
  2360. +       AnnounceToPlayers(false, _eventName + "(CTF): Started. Go Capture the Flags!");
  2361. +   }
  2362. +
  2363. +   public static void addFlagToPlayer(Player _player)
  2364. +   {
  2365. +       // remove items from the player hands (right, left, both)
  2366. +       // This is NOT a BUG, I don't want them to see the icon they have 8D
  2367. +       ItemInstance wpn = _player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  2368. +       if (wpn == null)
  2369. +       {
  2370. +           wpn = _player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  2371. +           if (wpn != null)
  2372. +               _player.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_LHAND);
  2373. +       }
  2374. +       else
  2375. +       {
  2376. +           _player.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_RHAND);
  2377. +           wpn = _player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  2378. +           if (wpn != null)
  2379. +               _player.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_LHAND);
  2380. +       }
  2381. +       // add the flag in his hands
  2382. +       _player.getInventory().equipItem(ItemTable.getInstance().createItem("", CTF._FLAG_IN_HAND_ITEM_ID, 1, _player, null));
  2383. +       _player.broadcastPacket(new SocialAction(_player, 16),2000); // amazing glow
  2384. +       _player._haveFlagCTF = true;
  2385. +       _player.broadcastUserInfo();
  2386. +       CreatureSay cs = new CreatureSay(_player.getObjectId(), 15, ":", "You got it! Run back! ::"); // 8D
  2387. +       _player.sendPacket(cs);
  2388. +   }
  2389. +
  2390. +   public static void removeFlagFromPlayer(Player player)
  2391. +   {
  2392. +       ItemInstance wpn = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  2393. +       player._haveFlagCTF = false;
  2394. +       if (wpn != null)
  2395. +       {
  2396. +           ItemInstance[] unequiped = player.getInventory().unEquipItemInBodySlotAndRecord(wpn);
  2397. +           player.getInventory().destroyItemByItemId("", CTF._FLAG_IN_HAND_ITEM_ID, 1, player, null);
  2398. +           InventoryUpdate iu = new InventoryUpdate();
  2399. +           for (ItemInstance element : unequiped)
  2400. +               iu.addModifiedItem(element);
  2401. +           player.sendPacket(iu);
  2402. +           player.sendPacket(new ItemList(player, true)); // get your weapon back now ...
  2403. +           player.abortAttack();
  2404. +           player.broadcastUserInfo();
  2405. +       }
  2406. +       else
  2407. +       {
  2408. +           player.getInventory().destroyItemByItemId("", CTF._FLAG_IN_HAND_ITEM_ID, 1, player, null);
  2409. +           player.sendPacket(new ItemList(player, true)); // get your weapon back now ...
  2410. +           player.abortAttack();
  2411. +           player.broadcastUserInfo();
  2412. +       }
  2413. +   }
  2414. +
  2415. +   public static void setTeamFlag(String teamName, Player activeChar)
  2416. +   {
  2417. +       int index = _teams.indexOf(teamName);
  2418. +
  2419. +       if (index == -1)
  2420. +           return;
  2421. +       addOrSet(_teams.indexOf(teamName), null, false, _FlagNPC, activeChar.getX(), activeChar.getY(), activeChar.getZ());
  2422. +   }
  2423. +
  2424. +   public static void setTeamFlag(String teamName, int x, int y, int z)
  2425. +   {
  2426. +       int index = _teams.indexOf(teamName);
  2427. +
  2428. +       if (index == -1)
  2429. +           return;
  2430. +       addOrSet(_teams.indexOf(teamName), null, false, _FlagNPC, x, y, z);
  2431. +   }
  2432. +
  2433. +   public static void spawnAllFlags()
  2434. +   {
  2435. +       while (_flagSpawns.size() < _teams.size())
  2436. +           _flagSpawns.add(null);
  2437. +       while (_throneSpawns.size() < _teams.size())
  2438. +           _throneSpawns.add(null);
  2439. +       for (String team : _teams)
  2440. +       {
  2441. +           int index = _teams.indexOf(team);
  2442. +           NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_flagIds.get(index));
  2443. +           NpcTemplate throne = NpcTable.getInstance().getTemplate(32027);
  2444. +           try
  2445. +           {
  2446. +               // spawn throne
  2447. +               _throneSpawns.set(index, new L2Spawn(throne));
  2448. +               _throneSpawns.get(index).setLoc(_flagsX.get(index), _flagsY.get(index), _flagsZ.get(index) - 10, 0);
  2449. +               _throneSpawns.get(index).setRespawnDelay(1);
  2450. +              
  2451. +               SpawnTable.getInstance().addNewSpawn(_throneSpawns.get(index), false);
  2452. +              
  2453. +               _throneSpawns.get(index).setRespawnState(true);
  2454. +               _throneSpawns.get(index).doSpawn(false);
  2455. +               _throneSpawns.get(index).getNpc().getStatus().setCurrentHp(999999999);
  2456. +               _throneSpawns.get(index).getNpc().decayMe();
  2457. +               _throneSpawns.get(index).getNpc().spawnMe(_throneSpawns.get(index).getNpc().getX(), _throneSpawns.get(index).getNpc().getY(), _throneSpawns.get(index).getNpc().getZ());
  2458. +               _throneSpawns.get(index).getNpc().setTitle(team + " Throne");
  2459. +               _throneSpawns.get(index).getNpc().broadcastPacket(new MagicSkillUse(_throneSpawns.get(index).getNpc(), _throneSpawns.get(index).getNpc(), 1036, 1, 5500, 1));
  2460. +               _throneSpawns.get(index).getNpc()._isCTF_throneSpawn = true;
  2461. +
  2462. +               // spawn flag
  2463. +               _flagSpawns.set(index, new L2Spawn(tmpl));
  2464. +               _flagSpawns.get(index).setLoc(_flagsX.get(index), _flagsY.get(index), _flagsZ.get(index), 0);
  2465. +               _flagSpawns.get(index).setRespawnDelay(1);
  2466. +              
  2467. +               SpawnTable.getInstance().addNewSpawn(_flagSpawns.get(index), false);
  2468. +              
  2469. +               _flagSpawns.get(index).setRespawnState(true);
  2470. +               _flagSpawns.get(index).doSpawn(false);
  2471. +               _flagSpawns.get(index).getNpc().getStatus().setCurrentHp(999999999);
  2472. +               _flagSpawns.get(index).getNpc().setTitle(team + "'s Flag");
  2473. +               _flagSpawns.get(index).getNpc()._CTF_FlagTeamName = team;
  2474. +               _flagSpawns.get(index).getNpc().decayMe();
  2475. +               _flagSpawns.get(index).getNpc().spawnMe(_flagSpawns.get(index).getNpc().getX(), _flagSpawns.get(index).getNpc().getY(), _flagSpawns.get(index).getNpc().getZ());
  2476. +               _flagSpawns.get(index).getNpc()._isCTF_Flag = true;
  2477. +               if (index == (_teams.size() - 1))
  2478. +                   calculateOutSideOfCTF(); // sets event boundaries so players don't run with the flag.
  2479. +           }
  2480. +           catch (Exception e)
  2481. +           {
  2482. +               _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[spawnAllFlags()]: exception: " + e.getStackTrace());
  2483. +           }
  2484. +       }
  2485. +   }
  2486. +
  2487. +   public static void processTopTeam()
  2488. +   {
  2489. +       _topTeam = null;
  2490. +       for (String team : _teams)
  2491. +       {
  2492. +           if (teamPointsCount(team) == _topScore && _topScore > 0)
  2493. +               _topTeam = null;
  2494. +           if (teamPointsCount(team) > _topScore)
  2495. +           {
  2496. +               _topTeam = team;
  2497. +               _topScore = teamPointsCount(team);
  2498. +           }
  2499. +       }
  2500. +       if (_topScore <= 0)
  2501. +       {
  2502. +           AnnounceToPlayers(true, _eventName + "(CTF): No flags taken.");
  2503. +       }
  2504. +       else
  2505. +       {
  2506. +           if (_topTeam == null)
  2507. +               AnnounceToPlayers(true, _eventName + "(CTF): Maximum flags taken : " + _topScore + " flags! No one won.");
  2508. +           else
  2509. +           {
  2510. +               AnnounceToPlayers(true, _eventName + "(CTF): Team " + _topTeam + " wins the match, with " + _topScore + " flags taken!");
  2511. +               rewardTeam(_topTeam);
  2512. +           }
  2513. +       }
  2514. +       teleportFinish();
  2515. +   }
  2516. +
  2517. +   public static void unspawnAllFlags()
  2518. +   {
  2519. +       try
  2520. +       {
  2521. +           if ((_throneSpawns == null) || (_flagSpawns == null) || (_teams == null))
  2522. +               return;
  2523. +           for (String team : _teams)
  2524. +           {
  2525. +               int index = _teams.indexOf(team);
  2526. +               if (_throneSpawns.get(index) != null)
  2527. +               {
  2528. +                   _throneSpawns.get(index).getNpc().deleteMe();
  2529. +                   _throneSpawns.get(index).setRespawnState(false);
  2530. +                   SpawnTable.getInstance().deleteSpawn(_throneSpawns.get(index), true);
  2531. +               }
  2532. +               if (_flagSpawns.get(index) != null)
  2533. +               {
  2534. +                   _flagSpawns.get(index).getNpc().deleteMe();
  2535. +                   _flagSpawns.get(index).setRespawnState(false);
  2536. +                   SpawnTable.getInstance().deleteSpawn(_flagSpawns.get(index), true);
  2537. +               }
  2538. +           }
  2539. +           _throneSpawns.clear();
  2540. +       }
  2541. +       catch (Throwable t)
  2542. +       {
  2543. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[unspawnAllFlags()]: exception: " + t.getStackTrace());
  2544. +       }
  2545. +   }
  2546. +
  2547. +   private static void unspawnFlag(String teamName)
  2548. +   {
  2549. +       int index = _teams.indexOf(teamName);
  2550. +
  2551. +       _flagSpawns.get(index).getNpc().deleteMe();
  2552. +       _flagSpawns.get(index).setRespawnState(false);
  2553. +       SpawnTable.getInstance().deleteSpawn(_flagSpawns.get(index), true);
  2554. +   }
  2555. +
  2556. +   public static void spawnFlag(String teamName)
  2557. +   {
  2558. +       int index = _teams.indexOf(teamName);
  2559. +       NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_flagIds.get(index));
  2560. +
  2561. +       try
  2562. +       {
  2563. +           _flagSpawns.set(index, new L2Spawn(tmpl));
  2564. +
  2565. +           _flagSpawns.get(index).setLoc(_flagsX.get(index), _flagsY.get(index), _flagsZ.get(index), 0);
  2566. +           _flagSpawns.get(index).setRespawnDelay(1);
  2567. +
  2568. +           SpawnTable.getInstance().addNewSpawn(_flagSpawns.get(index), false);
  2569. +
  2570. +           _flagSpawns.get(index).setRespawnState(true);
  2571. +           _flagSpawns.get(index).doSpawn(false);
  2572. +           _flagSpawns.get(index).getNpc().getStatus().setCurrentHp(999999999);
  2573. +           _flagSpawns.get(index).getNpc().setTitle(teamName + "'s Flag");
  2574. +           _flagSpawns.get(index).getNpc()._CTF_FlagTeamName = teamName;
  2575. +           _flagSpawns.get(index).getNpc()._isCTF_Flag = true;
  2576. +           _flagSpawns.get(index).getNpc().decayMe();
  2577. +           _flagSpawns.get(index).getNpc().spawnMe(_flagSpawns.get(index).getNpc().getX(), _flagSpawns.get(index).getNpc().getY(), _flagSpawns.get(index).getNpc().getZ());
  2578. +       }
  2579. +       catch (Exception e)
  2580. +       {
  2581. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[spawnFlag(" + teamName + ")]: exception: " + e.getStackTrace());
  2582. +       }
  2583. +   }
  2584. +
  2585. +   public static boolean InRangeOfFlag(Player _player, int flagIndex, int offset)
  2586. +   {
  2587. +       if (_player.getX() > CTF._flagsX.get(flagIndex) - offset && _player.getX() < CTF._flagsX.get(flagIndex) + offset && _player.getY() > CTF._flagsY.get(flagIndex) - offset && _player.getY() < CTF._flagsY.get(flagIndex) + offset && _player.getZ() > CTF._flagsZ.get(flagIndex) - offset && _player.getZ() < CTF._flagsZ.get(flagIndex) + offset)
  2588. +           return true;
  2589. +       return false;
  2590. +   }
  2591. +
  2592. +   public static void processInFlagRange(Player _player)
  2593. +   {
  2594. +       try
  2595. +       {
  2596. +           CheckRestoreFlags();
  2597. +           for (String team : _teams)
  2598. +           {
  2599. +               if (team.equals(_player._teamNameCTF))
  2600. +               {
  2601. +                   int indexOwn = _teams.indexOf(_player._teamNameCTF);
  2602. +
  2603. +                   // if player is near his team flag holding the enemy flag
  2604. +                   if (InRangeOfFlag(_player, indexOwn, 100) && !_flagsTaken.get(indexOwn) && _player._haveFlagCTF)
  2605. +                   {
  2606. +                       int indexEnemy = _teams.indexOf(_player._teamNameHaveFlagCTF);
  2607. +                       // return enemy flag to place
  2608. +                       _flagsTaken.set(indexEnemy, false);
  2609. +                       spawnFlag(_player._teamNameHaveFlagCTF);
  2610. +                       // remove the flag from this player
  2611. +                       _player.broadcastPacket(new SocialAction(_player, 16),2000); // amazing glow
  2612. +                       _player.broadcastUserInfo();
  2613. +                       _player.broadcastPacket(new SocialAction(_player, 3),2000); // Victory
  2614. +                       _player.broadcastUserInfo();
  2615. +                       removeFlagFromPlayer(_player);
  2616. +                       _teamPointsCount.set(indexOwn, teamPointsCount(team) + 1);
  2617. +                          
  2618. +                       _player.broadcastUserInfo();
  2619. +                      
  2620. +                       AnnounceToPlayers(false, _eventName + "(CTF): " + _player.getName() + " scores for " + _player._teamNameCTF + ".");
  2621. +                   }
  2622. +               }
  2623. +               else
  2624. +               {
  2625. +                   int indexEnemy = _teams.indexOf(team);
  2626. +                   // if the player is near a enemy flag
  2627. +                   if (InRangeOfFlag(_player, indexEnemy, 100) && !_flagsTaken.get(indexEnemy) && !_player._haveFlagCTF && !_player.isDead())
  2628. +                   {
  2629. +                       if (_player.isRiding() || _player.isFlying())
  2630. +                       {
  2631. +                           _player.sendPacket(ActionFailed.STATIC_PACKET);
  2632. +                           break;
  2633. +                       }
  2634. +
  2635. +                       _flagsTaken.set(indexEnemy, true);
  2636. +                       unspawnFlag(team);
  2637. +                       _player._teamNameHaveFlagCTF = team;
  2638. +                       addFlagToPlayer(_player);
  2639. +                       _player.broadcastUserInfo();
  2640. +                       _player._haveFlagCTF = true;
  2641. +                       AnnounceToPlayers(false, _eventName + "(CTF): " + team + " flag taken by " + _player.getName() + "...");
  2642. +                       pointTeamTo(_player, team);
  2643. +                       break;
  2644. +                   }
  2645. +               }
  2646. +           }
  2647. +       }
  2648. +       catch (Exception e)
  2649. +       {
  2650. +           e.printStackTrace();
  2651. +       }
  2652. +   }
  2653. +
  2654. +   public static void pointTeamTo(Player hasFlag, String ourFlag)
  2655. +   {
  2656. +       try
  2657. +       {
  2658. +           for (Player player : _players)
  2659. +           {
  2660. +               if (player != null && player.isOnline())
  2661. +               {
  2662. +                   if (player._teamNameCTF.equals(ourFlag))
  2663. +                   {
  2664. +                       player.sendMessage(hasFlag.getName() + " took your flag!");
  2665. +                       if (player._haveFlagCTF)
  2666. +                       {
  2667. +                           player.sendMessage("You can not return the flag to headquarters, until your flag is returned to it's place.");
  2668. +                           player.sendPacket(new RadarControl(1, 1, player.getX(), player.getY(), player.getZ()));
  2669. +                       }
  2670. +                       else
  2671. +                       {
  2672. +                           player.sendPacket(new RadarControl(0, 1, hasFlag.getX(), hasFlag.getY(), hasFlag.getZ()));
  2673. +                           L2Radar rdr = new L2Radar(player);
  2674. +                           L2Radar.RadarOnPlayer radar = rdr.new RadarOnPlayer(hasFlag, player);
  2675. +                           ThreadPool.schedule(radar, 10000 + Rnd.get(30000));
  2676. +                       }
  2677. +                   }
  2678. +               }
  2679. +           }
  2680. +       }
  2681. +       catch (Throwable t)
  2682. +       {
  2683. +       }
  2684. +   }
  2685. +
  2686. +   public static int teamPointsCount(String teamName)
  2687. +   {
  2688. +       int index = _teams.indexOf(teamName);
  2689. +
  2690. +       if (index == -1)
  2691. +           return -1;
  2692. +
  2693. +       return _teamPointsCount.get(index);
  2694. +   }
  2695. +
  2696. +   public static void setTeamPointsCount(String teamName, int teamPointCount)
  2697. +   {
  2698. +       int index = _teams.indexOf(teamName);
  2699. +
  2700. +       if (index == -1)
  2701. +           return;
  2702. +
  2703. +       _teamPointsCount.set(index, teamPointCount);
  2704. +   }
  2705. +
  2706. +   public static int teamPlayersCount(String teamName)
  2707. +   {
  2708. +       int index = _teams.indexOf(teamName);
  2709. +
  2710. +       if (index == -1)
  2711. +           return -1;
  2712. +
  2713. +       return _teamPlayersCount.get(index);
  2714. +   }
  2715. +
  2716. +   public static void setTeamPlayersCount(String teamName, int teamPlayersCount)
  2717. +   {
  2718. +       int index = _teams.indexOf(teamName);
  2719. +
  2720. +       if (index == -1)
  2721. +           return;
  2722. +
  2723. +       _teamPlayersCount.set(index, teamPlayersCount);
  2724. +   }
  2725. +
  2726. +   public static void setNpcPos(Player activeChar)
  2727. +   {
  2728. +       _npcX = activeChar.getX();
  2729. +       _npcY = activeChar.getY();
  2730. +       _npcZ = activeChar.getZ();
  2731. +       _npcHeading = activeChar.getHeading();
  2732. +   }
  2733. +
  2734. +   public static void setNpcPos(int x, int y, int z)
  2735. +   {
  2736. +       _npcX = x;
  2737. +       _npcY = y;
  2738. +       _npcZ = z;
  2739. +   }
  2740. +
  2741. +   public static void addTeam(String teamName)
  2742. +   {
  2743. +       if (!checkTeamOk())
  2744. +       {
  2745. +           if (Config.DEBUG)
  2746. +               _log.fine("CTF Engine[addTeam(" + teamName + ")]: checkTeamOk() = false");
  2747. +           return;
  2748. +       }
  2749. +
  2750. +       if (teamName.equals(" "))
  2751. +           return;
  2752. +
  2753. +       _teams.add(teamName);
  2754. +       _teamPlayersCount.add(0);
  2755. +       _teamColors.add(0);
  2756. +       _teamsX.add(0);
  2757. +       _teamsY.add(0);
  2758. +       _teamsZ.add(0);
  2759. +       _teamPointsCount.add(0);
  2760. +       addOrSet(_teams.indexOf(teamName), null, false, _FlagNPC, 0, 0, 0);
  2761. +   }
  2762. +
  2763. +   private static void addOrSet(int listSize, L2Spawn flagSpawn, boolean flagsTaken, int flagId, int flagX, int flagY, int flagZ)
  2764. +   {
  2765. +       while (_flagsX.size() <= listSize)
  2766. +       {
  2767. +           _flagSpawns.add(null);
  2768. +           _flagsTaken.add(false);
  2769. +           _flagIds.add(_FlagNPC);
  2770. +           _flagsX.add(0);
  2771. +           _flagsY.add(0);
  2772. +           _flagsZ.add(0);
  2773. +       }
  2774. +       _flagSpawns.set(listSize, flagSpawn);
  2775. +       _flagsTaken.set(listSize, flagsTaken);
  2776. +       _flagIds.set(listSize, flagId);
  2777. +       _flagsX.set(listSize, flagX);
  2778. +       _flagsY.set(listSize, flagY);
  2779. +       _flagsZ.set(listSize, flagZ);
  2780. +   }
  2781. +
  2782. +   public static boolean checkMaxLevel(int maxlvl)
  2783. +   {
  2784. +       if (_minlvl >= maxlvl)
  2785. +           return false;
  2786. +
  2787. +       return true;
  2788. +   }
  2789. +
  2790. +   public static boolean checkMinLevel(int minlvl)
  2791. +   {
  2792. +       if (_maxlvl <= minlvl)
  2793. +           return false;
  2794. +
  2795. +       return true;
  2796. +   }
  2797. +
  2798. +   /** returns true if participated players is higher or equal then minimum needed players
  2799. +    * @param players
  2800. +    * @return */
  2801. +   public static boolean checkMinPlayers(int players)
  2802. +   {
  2803. +       if (_minPlayers <= players)
  2804. +           return true;
  2805. +
  2806. +       return false;
  2807. +   }
  2808. +
  2809. +   /** returns true if max players is higher or equal then participated players
  2810. +    * @param players
  2811. +    * @return */
  2812. +   public static boolean checkMaxPlayers(int players)
  2813. +   {
  2814. +       if (_maxPlayers > players)
  2815. +           return true;
  2816. +
  2817. +       return false;
  2818. +   }
  2819. +
  2820. +   public static void removeTeam(String teamName)
  2821. +   {
  2822. +       if (!checkTeamOk() || _teams.isEmpty())
  2823. +       {
  2824. +           if (Config.DEBUG)
  2825. +               _log.fine("CTF Engine[removeTeam(" + teamName + ")]: checkTeamOk() = false");
  2826. +           return;
  2827. +       }
  2828. +
  2829. +       if (teamPlayersCount(teamName) > 0)
  2830. +       {
  2831. +           if (Config.DEBUG)
  2832. +               _log.fine("CTF Engine[removeTeam(" + teamName + ")]: teamPlayersCount(teamName) > 0");
  2833. +           return;
  2834. +       }
  2835. +
  2836. +       int index = _teams.indexOf(teamName);
  2837. +
  2838. +       if (index == -1)
  2839. +           return;
  2840. +
  2841. +       _teamsZ.remove(index);
  2842. +       _teamsY.remove(index);
  2843. +       _teamsX.remove(index);
  2844. +       _teamColors.remove(index);
  2845. +       _teamPointsCount.remove(index);
  2846. +       _teamPlayersCount.remove(index);
  2847. +       _teams.remove(index);
  2848. +       _flagSpawns.remove(index);
  2849. +       _flagsTaken.remove(index);
  2850. +       _flagIds.remove(index);
  2851. +       _flagsX.remove(index);
  2852. +       _flagsY.remove(index);
  2853. +       _flagsZ.remove(index);
  2854. +   }
  2855. +
  2856. +   public static void setTeamPos(String teamName, Player activeChar)
  2857. +   {
  2858. +       int index = _teams.indexOf(teamName);
  2859. +
  2860. +       if (index == -1)
  2861. +           return;
  2862. +
  2863. +       _teamsX.set(index, activeChar.getX());
  2864. +       _teamsY.set(index, activeChar.getY());
  2865. +       _teamsZ.set(index, activeChar.getZ());
  2866. +   }
  2867. +
  2868. +   public static void setTeamPos(String teamName, int x, int y, int z)
  2869. +   {
  2870. +       int index = _teams.indexOf(teamName);
  2871. +
  2872. +       if (index == -1)
  2873. +           return;
  2874. +
  2875. +       _teamsX.set(index, x);
  2876. +       _teamsY.set(index, y);
  2877. +       _teamsZ.set(index, z);
  2878. +   }
  2879. +
  2880. +   public static void setTeamColor(String teamName, int color)
  2881. +   {
  2882. +       if (!checkTeamOk())
  2883. +           return;
  2884. +
  2885. +       int index = _teams.indexOf(teamName);
  2886. +
  2887. +       if (index == -1)
  2888. +           return;
  2889. +
  2890. +       _teamColors.set(index, color);
  2891. +   }
  2892. +
  2893. +   public static boolean checkTeamOk()
  2894. +   {
  2895. +       if (_started || _teleport || _joining)
  2896. +           return false;
  2897. +
  2898. +       return true;
  2899. +   }
  2900. +
  2901. +   public static void startJoin(Player activeChar)
  2902. +   {
  2903. +       if (!startJoinOk())
  2904. +       {
  2905. +           activeChar.sendMessage("Event not setted propertly.");
  2906. +           if (Config.DEBUG)
  2907. +               _log.fine("CTF Engine[startJoin(" + activeChar.getName() + ")]: startJoinOk() = false");
  2908. +           return;
  2909. +       }
  2910. +
  2911. +       _joining = true;
  2912. +       spawnEventNpc(activeChar);
  2913. +       AnnounceToPlayers(true, _eventName + " (CTF)!");
  2914. +       if (Config.CTF_ANNOUNCE_REWARD)
  2915. +           AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).getName());
  2916. +       AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
  2917. +       AnnounceToPlayers(true, "Joinable in " + _joiningLocationName + "!");
  2918. +   }
  2919. +
  2920. +   public static void startJoin()
  2921. +   {
  2922. +       if (!startJoinOk())
  2923. +       {
  2924. +           _log.warning(CTF.class.getSimpleName() + ":  Event not setted propertly.");
  2925. +           if (Config.DEBUG)
  2926. +               _log.fine("CTF Engine[startJoin(startJoinOk() = false");
  2927. +           return;
  2928. +       }
  2929. +
  2930. +       _joining = true;
  2931. +       spawnEventNpc();
  2932. +       AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
  2933. +       AnnounceToPlayers(true, "Joinable in " + _joiningLocationName + "!");
  2934. +       if (Config.CTF_ANNOUNCE_REWARD)
  2935. +           AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).getName());
  2936. +   }
  2937. +
  2938. +   public static boolean startAutoJoin()
  2939. +   {
  2940. +       if (!startJoinOk())
  2941. +       {
  2942. +           if (Config.DEBUG)
  2943. +               _log.fine("CTF Engine[startJoin]: startJoinOk() = false");
  2944. +           return false;
  2945. +       }
  2946. +
  2947. +       _joining = true;
  2948. +       spawnEventNpc();
  2949. +       AnnounceToPlayers(true, _eventName + " (CTF)!");
  2950. +       if (Config.CTF_ANNOUNCE_REWARD)
  2951. +           AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).getName());
  2952. +       AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
  2953. +       AnnounceToPlayers(true, "Joinable in " + _joiningLocationName + "!");
  2954. +       return true;
  2955. +   }
  2956. +
  2957. +   public static boolean startJoinOk()
  2958. +   {
  2959. +       if (_started || _teleport || _joining || _teams.size() < 2 || _eventName.equals("") || _joiningLocationName.equals("") || _eventDesc.equals("") || _npcId == 0 || _npcX == 0 || _npcY == 0 || _npcZ == 0 || _rewardId == 0 || _rewardAmount == 0 || _teamsX.contains(0) || _teamsY.contains(0) || _teamsZ.contains(0))
  2960. +           return false;
  2961. +       try
  2962. +       {
  2963. +           if (_flagsX.contains(0) || _flagsY.contains(0) || _flagsZ.contains(0) || _flagIds.contains(0))
  2964. +               return false;
  2965. +           if (_flagsX.size() < _teams.size() || _flagsY.size() < _teams.size() || _flagsZ.size() < _teams.size() || _flagIds.size() < _teams.size())
  2966. +               return false;
  2967. +       }
  2968. +       catch (ArrayIndexOutOfBoundsException e)
  2969. +       {
  2970. +           return false;
  2971. +       }
  2972. +       return true;
  2973. +   }
  2974. +
  2975. +   private static void spawnEventNpc(Player activeChar)
  2976. +   {
  2977. +       NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
  2978. +
  2979. +       try
  2980. +       {
  2981. +           _npcSpawn = new L2Spawn(tmpl);
  2982. +           _npcSpawn.setLoc(_npcX, _npcY, _npcZ, _npcHeading);
  2983. +           _npcSpawn.setRespawnDelay(1);
  2984. +
  2985. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  2986. +
  2987. +           _npcSpawn.setRespawnState(true);
  2988. +           _npcSpawn.doSpawn(false);
  2989. +           _npcSpawn.getNpc().getStatus().setCurrentHp(999999999);
  2990. +           _npcSpawn.getNpc().setTitle(_eventName);
  2991. +           _npcSpawn.getNpc()._isEventMobCTF = true;
  2992. +           _npcSpawn.getNpc().isAggressive();
  2993. +           _npcSpawn.getNpc().decayMe();
  2994. +           _npcSpawn.getNpc().spawnMe(_npcSpawn.getNpc().getX(), _npcSpawn.getNpc().getY(), _npcSpawn.getNpc().getZ());
  2995. +
  2996. +           _npcSpawn.getNpc().broadcastPacket(new MagicSkillUse(_npcSpawn.getNpc(), _npcSpawn.getNpc(), 1034, 1, 1, 1));
  2997. +       }
  2998. +       catch (Exception e)
  2999. +       {
  3000. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[spawnEventNpc(" + activeChar.getName() + ")]: exception: " + e.getMessage());
  3001. +       }
  3002. +   }
  3003. +
  3004. +   private static void spawnEventNpc()
  3005. +   {
  3006. +       NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
  3007. +
  3008. +       try
  3009. +       {
  3010. +           _npcSpawn = new L2Spawn(tmpl);
  3011. +
  3012. +           _npcSpawn.setLoc(_npcX, _npcY, _npcZ, _npcHeading);
  3013. +           _npcSpawn.setRespawnDelay(1);
  3014. +
  3015. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  3016. +
  3017. +           _npcSpawn.setRespawnState(true);
  3018. +           _npcSpawn.doSpawn(false);
  3019. +           _npcSpawn.getNpc().getStatus().setCurrentHp(999999999);
  3020. +           _npcSpawn.getNpc().setTitle(_eventName);
  3021. +           _npcSpawn.getNpc()._isEventMobCTF = true;
  3022. +           _npcSpawn.getNpc().isAggressive();
  3023. +           _npcSpawn.getNpc().decayMe();
  3024. +           _npcSpawn.getNpc().spawnMe(_npcSpawn.getNpc().getX(), _npcSpawn.getNpc().getY(), _npcSpawn.getNpc().getZ());
  3025. +
  3026. +           _npcSpawn.getNpc().broadcastPacket(new MagicSkillUse(_npcSpawn.getNpc(), _npcSpawn.getNpc(), 1034, 1, 1, 1));
  3027. +       }
  3028. +       catch (Exception e)
  3029. +       {
  3030. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[spawnEventNpc(exception: " + e.getMessage());
  3031. +       }
  3032. +   }
  3033. +
  3034. +   public static void teleportStart()
  3035. +   {
  3036. +       if (!_joining || _started || _teleport)
  3037. +           return;
  3038. +
  3039. +       if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && checkMinPlayers(_playersShuffle.size()))
  3040. +       {
  3041. +           removeOfflinePlayers();
  3042. +           shuffleTeams();
  3043. +       }
  3044. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !checkMinPlayers(_playersShuffle.size()))
  3045. +       {
  3046. +           AnnounceToPlayers(true, "Not enough players for event. Min Requested : " + _minPlayers + ", Participating : " + _playersShuffle.size());
  3047. +           return;
  3048. +       }
  3049. +
  3050. +       _joining = false;
  3051. +       AnnounceToPlayers(true, _eventName + "(CTF): Teleport to team spot in 20 seconds!");
  3052. +
  3053. +       setUserData();
  3054. +       ThreadPool.schedule(new Runnable()
  3055. +       {
  3056. +           @Override
  3057. +           public void run()
  3058. +           {
  3059. +               CTF.sit();
  3060. +               CTF.spawnAllFlags();
  3061. +               for (Player player : _players)
  3062. +               {
  3063. +                   if (player != null)
  3064. +                   {
  3065. +                       if (Config.CTF_ON_START_UNSUMMON_PET)
  3066. +                       {
  3067. +                           // Remove Summon's buffs
  3068. +                           if (player.getPet() != null)
  3069. +                           {
  3070. +                               Summon summon = player.getPet();
  3071. +                               for (L2Effect e : summon.getAllEffects())
  3072. +                                   if (e != null)
  3073. +                                       e.exit();
  3074. +
  3075. +                               if (summon instanceof Pet)
  3076. +                                   summon.unSummon(player);
  3077. +                           }
  3078. +                       }
  3079. +
  3080. +                       if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
  3081. +                       {
  3082. +                           for (L2Effect e : player.getAllEffects())
  3083. +                           {
  3084. +                               if (e != null)
  3085. +                                   e.exit();
  3086. +                           }
  3087. +                       }
  3088. +
  3089. +                       // Remove player from his party
  3090. +                       if (player.getParty() != null)
  3091. +                       {
  3092. +                           Party party = player.getParty();
  3093. +                           party.removePartyMember(player, MessageType.EXPELLED);
  3094. +                       }
  3095. +                       player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ.get(_teams.indexOf(player._teamNameCTF)), 0);
  3096. +                   }
  3097. +               }
  3098. +           }
  3099. +       }, 20000);
  3100. +       _teleport = true;
  3101. +   }
  3102. +
  3103. +   public static boolean teleportAutoStart()
  3104. +   {
  3105. +       if (!_joining || _started || _teleport)
  3106. +           return false;
  3107. +
  3108. +       if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && checkMinPlayers(_playersShuffle.size()))
  3109. +       {
  3110. +           removeOfflinePlayers();
  3111. +           shuffleTeams();
  3112. +       }
  3113. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !checkMinPlayers(_playersShuffle.size()))
  3114. +       {
  3115. +           AnnounceToPlayers(true, "Not enough players for event. Min Requested : " + _minPlayers + ", Participating : " + _playersShuffle.size());
  3116. +           return false;
  3117. +       }
  3118. +
  3119. +       _joining = false;
  3120. +       AnnounceToPlayers(false, _eventName + "(CTF): Teleport to team spot in 20 seconds!");
  3121. +
  3122. +       setUserData();
  3123. +       ThreadPool.schedule(new Runnable()
  3124. +       {
  3125. +           @Override
  3126. +           public void run()
  3127. +           {
  3128. +               sit();
  3129. +               spawnAllFlags();
  3130. +
  3131. +               for (Player player : _players)
  3132. +               {
  3133. +                   if (player != null)
  3134. +                   {
  3135. +                       if (Config.CTF_ON_START_UNSUMMON_PET)
  3136. +                       {
  3137. +                           // Remove Summon's buffs
  3138. +                           if (player.getPet() != null)
  3139. +                           {
  3140. +                               Summon summon = player.getPet();
  3141. +                               for (L2Effect e : summon.getAllEffects())
  3142. +                                   if (e != null)
  3143. +                                       e.exit();
  3144. +
  3145. +                               if (summon instanceof Pet)
  3146. +                                   summon.unSummon(player);
  3147. +                           }
  3148. +                       }
  3149. +                       if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
  3150. +                       {
  3151. +                           for (L2Effect e : player.getAllEffects())
  3152. +                           {
  3153. +                               if (e != null)
  3154. +                                   e.exit();
  3155. +                           }
  3156. +                       }
  3157. +
  3158. +                       // Remove player from his party
  3159. +                       if (player.getParty() != null)
  3160. +                       {
  3161. +                           Party party = player.getParty();
  3162. +                           party.removePartyMember(player, MessageType.EXPELLED);
  3163. +                       }
  3164. +
  3165. +                       player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ.get(_teams.indexOf(player._teamNameCTF)), 0);
  3166. +                   }
  3167. +               }
  3168. +           }
  3169. +       }, 20000);
  3170. +       _teleport = true;
  3171. +       return true;
  3172. +   }
  3173. +
  3174. +   public static void startEvent(Player activeChar)
  3175. +   {
  3176. +       if (!startEventOk())
  3177. +       {
  3178. +           if (Config.DEBUG)
  3179. +               _log.fine("CTF Engine[startEvent(" + activeChar.getName() + ")]: startEventOk() = false");
  3180. +           return;
  3181. +       }
  3182. +
  3183. +       _teleport = false;
  3184. +       sit();
  3185. +       _started = true;
  3186. +       StartEvent();
  3187. +   }
  3188. +
  3189. +   public static void setJoinTime(int time)
  3190. +   {
  3191. +       _joinTime = time;
  3192. +   }
  3193. +
  3194. +   public static void setEventTime(int time)
  3195. +   {
  3196. +       _eventTime = time;
  3197. +   }
  3198. +
  3199. +   public static boolean startAutoEvent()
  3200. +   {
  3201. +       if (!startEventOk())
  3202. +       {
  3203. +           if (Config.DEBUG)
  3204. +               _log.fine("CTF Engine[startEvent]: startEventOk() = false");
  3205. +           return false;
  3206. +       }
  3207. +
  3208. +       _teleport = false;
  3209. +       sit();
  3210. +       AnnounceToPlayers(true, _eventName + "(CTF): Started. Go Capture the Flags!");
  3211. +       _started = true;
  3212. +       return true;
  3213. +   }
  3214. +
  3215. +   public static synchronized void autoEvent()
  3216. +   {
  3217. +       if (startAutoJoin())
  3218. +       {
  3219. +           if (_joinTime > 0)
  3220. +               waiter(_joinTime * 60 * 1000); // minutes for join event
  3221. +           else if (_joinTime <= 0)
  3222. +           {
  3223. +               abortEvent();
  3224. +               return;
  3225. +           }
  3226. +           if (teleportAutoStart())
  3227. +           {
  3228. +               waiter(1 * 30 * 1000); // 30 seconds wait time until start fight after teleported
  3229. +               if (startAutoEvent())
  3230. +               {
  3231. +                   waiter(_eventTime * 60 * 1000); // minutes for event time
  3232. +                   finishEvent();
  3233. +               }
  3234. +           }
  3235. +           else if (!teleportAutoStart())
  3236. +           {
  3237. +               abortEvent();
  3238. +           }
  3239. +       }
  3240. +   }
  3241. +
  3242. +   private static synchronized void waiter(long interval)
  3243. +   {
  3244. +       long startWaiterTime = System.currentTimeMillis();
  3245. +       int seconds = (int) (interval / 1000);
  3246. +
  3247. +       while (startWaiterTime + interval > System.currentTimeMillis())
  3248. +       {
  3249. +           seconds--; // here because we don't want to see two time announce at the same time
  3250. +
  3251. +           if (_joining || _started || _teleport)
  3252. +           {
  3253. +               switch (seconds)
  3254. +               {
  3255. +                   case 3600: // 1 hour left
  3256. +                       if (_joining)
  3257. +                       {
  3258. +                           AnnounceToPlayers(true, _eventName + "(CTF): Joinable in " + _joiningLocationName + "!");
  3259. +                           AnnounceToPlayers(true, "CTF Event: " + seconds / 60 / 60 + " hour(s) till registration close!");
  3260. +                       }
  3261. +                       else if (_started)
  3262. +                           AnnounceToPlayers(false, "CTF Event: " + seconds / 60 / 60 + " hour(s) till event finish!");
  3263. +
  3264. +                   break;
  3265. +                   case 1800: // 30 minutes left
  3266. +                   case 600: // 10 minutes left
  3267. +                   case 180: // 3 minutes left
  3268. +                   case 120: // 2 minutes left
  3269. +                   case 60: // 1 minute left
  3270. +                       if (_joining)
  3271. +                       {
  3272. +                           removeOfflinePlayers();
  3273. +                           AnnounceToPlayers(true, _eventName + "(CTF): Joinable in " + _joiningLocationName + "!");
  3274. +                           AnnounceToPlayers(true, "CTF Event: " + seconds / 60 + " minute(s) till registration ends!");
  3275. +                       }
  3276. +                       else if (_started)
  3277. +                           AnnounceToPlayers(false, "CTF Event: " + seconds / 60 + " minute(s) till event ends!");
  3278. +
  3279. +                   break;
  3280. +                   case 30: // 30 seconds left
  3281. +                   case 10: // 10 seconds left
  3282. +                   case 3: // 3 seconds left
  3283. +                   case 2: // 2 seconds left
  3284. +                   case 1: // 1 seconds left
  3285. +                       if (_joining)
  3286. +                           AnnounceToPlayers(true, "CTF Event: " + seconds + " second(s) till registration close!");
  3287. +                       else if (_teleport)
  3288. +                           AnnounceToPlayers(false, "CTF Event: " + seconds + " seconds(s) till fight starts!");
  3289. +                       else if (_started)
  3290. +                           AnnounceToPlayers(false, "CTF Event: " + seconds + " second(s) till event ends!");
  3291. +
  3292. +                   break;
  3293. +               }
  3294. +           }
  3295. +
  3296. +           long startOneSecondWaiterStartTime = System.currentTimeMillis();
  3297. +
  3298. +           // only the try catch with Thread.sleep(1000) give bad countdown on high wait times
  3299. +           while (startOneSecondWaiterStartTime + 1000 > System.currentTimeMillis())
  3300. +           {
  3301. +               try
  3302. +               {
  3303. +                   Thread.sleep(1);
  3304. +               }
  3305. +               catch (InterruptedException ie)
  3306. +               {
  3307. +               }
  3308. +           }
  3309. +       }
  3310. +   }
  3311. +
  3312. +   private static boolean startEventOk()
  3313. +   {
  3314. +       if (_joining || !_teleport || _started)
  3315. +           return false;
  3316. +
  3317. +       if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  3318. +       {
  3319. +           if (_teamPlayersCount.contains(0))
  3320. +               return false;
  3321. +       }
  3322. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  3323. +       {
  3324. +           List<Player> playersShuffleTemp = new ArrayList<>();
  3325. +           int loopCount = 0;
  3326. +
  3327. +           loopCount = _playersShuffle.size();
  3328. +
  3329. +           for (int i = 0; i < loopCount; i++)
  3330. +           {
  3331. +               if (_playersShuffle != null)
  3332. +                   playersShuffleTemp.add(_playersShuffle.get(i));
  3333. +           }
  3334. +
  3335. +           _playersShuffle = playersShuffleTemp;
  3336. +           playersShuffleTemp.clear();
  3337. +
  3338. +           // if (_playersShuffle.size() < (_teams.size()*2)){
  3339. +           // return false;
  3340. +           // }
  3341. +       }
  3342. +
  3343. +       return true;
  3344. +   }
  3345. +
  3346. +   public static void shuffleTeams()
  3347. +   {
  3348. +       int teamCount = 0, playersCount = 0;
  3349. +
  3350. +       for (;;)
  3351. +       {
  3352. +           if (_playersShuffle.isEmpty())
  3353. +               break;
  3354. +
  3355. +           int playerToAddIndex = Rnd.nextInt(_playersShuffle.size());
  3356. +           Player player = null;
  3357. +           player = _playersShuffle.get(playerToAddIndex);
  3358. +           player._originalNameColorCTF = player.getAppearance().getNameColor();
  3359. +           player._originalKarmaCTF = player.getKarma();
  3360. +
  3361. +           _players.add(player);
  3362. +           _players.get(playersCount)._teamNameCTF = _teams.get(teamCount);
  3363. +           _savePlayers.add(_players.get(playersCount).getName());
  3364. +           _savePlayerTeams.add(_teams.get(teamCount));
  3365. +           playersCount++;
  3366. +
  3367. +           if (teamCount == _teams.size() - 1)
  3368. +               teamCount = 0;
  3369. +           else
  3370. +               teamCount++;
  3371. +
  3372. +           _playersShuffle.remove(playerToAddIndex);
  3373. +       }
  3374. +   }
  3375. +
  3376. +   public static void setUserData()
  3377. +   {
  3378. +       for (Player player : _players)
  3379. +       {
  3380. +           player.getAppearance().setNameColor(_teamColors.get(_teams.indexOf(player._teamNameCTF)));
  3381. +           player.setKarma(0);
  3382. +           player.broadcastUserInfo();
  3383. +       }
  3384. +   }
  3385. +
  3386. +   public static void finishEvent()
  3387. +   {
  3388. +       if (!finishEventOk())
  3389. +       {
  3390. +           if (Config.DEBUG)
  3391. +               _log.fine("CTF Engine[finishEvent]: finishEventOk() = false");
  3392. +           return;
  3393. +       }
  3394. +
  3395. +       _started = false;
  3396. +       unspawnEventNpc();
  3397. +       unspawnAllFlags();
  3398. +       processTopTeam();
  3399. +
  3400. +       if (_topScore != 0)
  3401. +           playKneelAnimation(_topTeam);
  3402. +
  3403. +       if (Config.CTF_ANNOUNCE_TEAM_STATS)
  3404. +       {
  3405. +           AnnounceToPlayers(true, _eventName + " Team Statistics:");
  3406. +           for (String team : _teams)
  3407. +           {
  3408. +               int _flags_ = teamFlagCount(team);
  3409. +               AnnounceToPlayers(true, "Team: " + team + " - Flags taken: " + _flags_);
  3410. +           }
  3411. +       }
  3412. +
  3413. +       teleportFinish();
  3414. +   }
  3415. +
  3416. +   // show losers and winners animations
  3417. +   public static void playKneelAnimation(String teamName)
  3418. +   {
  3419. +       for (Player player : _players)
  3420. +       {
  3421. +           if (player != null && player.isOnline() && player._inEventCTF == true)
  3422. +           {
  3423. +               if (!player._teamNameCTF.equals(teamName))
  3424. +               {
  3425. +                   player.broadcastPacket(new SocialAction(player, 7),2000);
  3426. +               }
  3427. +               else if (player._teamNameCTF.equals(teamName))
  3428. +               {
  3429. +                   player.broadcastPacket(new SocialAction(player, 3),2000);
  3430. +               }
  3431. +           }
  3432. +       }
  3433. +   }
  3434. +
  3435. +   private static boolean finishEventOk()
  3436. +   {
  3437. +       if (!_started)
  3438. +           return false;
  3439. +
  3440. +       return true;
  3441. +   }
  3442. +
  3443. +   public static void rewardTeam(String teamName)
  3444. +   {
  3445. +       for (Player player : _players)
  3446. +       {
  3447. +           if (player != null)
  3448. +           {
  3449. +               if (player._teamNameCTF.equals(teamName))
  3450. +               {
  3451. +                   player.addItem("CTF Event: " + _eventName, _rewardId, _rewardAmount, player, true);
  3452. +
  3453. +                   NpcHtmlMessage nhm = new NpcHtmlMessage(5);
  3454. +                   StringBuilder replyMSG = new StringBuilder();
  3455. +
  3456. +                   replyMSG.append("<html><body>Your team wins the event. Look in your inventory for the reward.</body></html>");
  3457. +
  3458. +                   nhm.setHtml(replyMSG.toString());
  3459. +                   player.sendPacket(nhm);
  3460. +
  3461. +                   // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  3462. +                   player.sendPacket(ActionFailed.STATIC_PACKET);
  3463. +               }
  3464. +           }
  3465. +       }
  3466. +   }
  3467. +
  3468. +   public static void abortEvent()
  3469. +   {
  3470. +       if (!_joining && !_teleport && !_started)
  3471. +           return;
  3472. +       if (_joining && !_teleport && !_started)
  3473. +       {
  3474. +           unspawnEventNpc();
  3475. +           cleanCTF();
  3476. +           _joining = false;
  3477. +           AnnounceToPlayers(true, _eventName + "(CTF): Match aborted!");
  3478. +           return;
  3479. +       }
  3480. +       _joining = false;
  3481. +       _teleport = false;
  3482. +       _started = false;
  3483. +       unspawnEventNpc();
  3484. +       unspawnAllFlags();
  3485. +       AnnounceToPlayers(true, _eventName + "(CTF): Match aborted!");
  3486. +       teleportFinish();
  3487. +   }
  3488. +
  3489. +   public static void sit()
  3490. +   {
  3491. +       if (_sitForced)
  3492. +           _sitForced = false;
  3493. +       else
  3494. +           _sitForced = true;
  3495. +
  3496. +       for (Player player : _players)
  3497. +       {
  3498. +           if (player != null)
  3499. +           {
  3500. +               if (_sitForced)
  3501. +               {
  3502. +                   player.stopMove(null);
  3503. +                   player.abortAttack();
  3504. +                   player.abortCast();
  3505. +
  3506. +                   if (!player.isSitting())
  3507. +                       player.sitDown();
  3508. +               }
  3509. +               else
  3510. +               {
  3511. +                   if (player.isSitting())
  3512. +                       player.standUp();
  3513. +               }
  3514. +           }
  3515. +       }
  3516. +   }
  3517. +
  3518. +   public static void dumpData()
  3519. +   {
  3520. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  3521. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  3522. +
  3523. +       if (!_joining && !_teleport && !_started)
  3524. +       {
  3525. +           _log.warning(CTF.class.getSimpleName() + ":  <<---------------------------------->>");
  3526. +           _log.warning(CTF.class.getSimpleName() + ":  >> CTF Engine infos dump (INACTIVE) <<");
  3527. +           _log.warning(CTF.class.getSimpleName() + ":  <<--^----^^-----^----^^------^^----->>");
  3528. +       }
  3529. +       else if (_joining && !_teleport && !_started)
  3530. +       {
  3531. +           _log.warning(CTF.class.getSimpleName() + ":  <<--------------------------------->>");
  3532. +           _log.warning(CTF.class.getSimpleName() + ":  >> CTF Engine infos dump (JOINING) <<");
  3533. +           _log.warning(CTF.class.getSimpleName() + ":  <<--^----^^-----^----^^------^----->>");
  3534. +       }
  3535. +       else if (!_joining && _teleport && !_started)
  3536. +       {
  3537. +           _log.warning(CTF.class.getSimpleName() + ":  <<---------------------------------->>");
  3538. +           _log.warning(CTF.class.getSimpleName() + ":  >> CTF Engine infos dump (TELEPORT) <<");
  3539. +           _log.warning(CTF.class.getSimpleName() + ":  <<--^----^^-----^----^^------^^----->>");
  3540. +       }
  3541. +       else if (!_joining && !_teleport && _started)
  3542. +       {
  3543. +           _log.warning(CTF.class.getSimpleName() + ":  <<--------------------------------->>");
  3544. +           _log.warning(CTF.class.getSimpleName() + ":  >> CTF Engine infos dump (STARTED) <<");
  3545. +           _log.warning(CTF.class.getSimpleName() + ":  <<--^----^^-----^----^^------^----->>");
  3546. +       }
  3547. +
  3548. +       _log.warning(CTF.class.getSimpleName() + ":  Name: " + _eventName);
  3549. +       _log.warning(CTF.class.getSimpleName() + ":  Desc: " + _eventDesc);
  3550. +       _log.warning(CTF.class.getSimpleName() + ":  Join location: " + _joiningLocationName);
  3551. +       _log.warning(CTF.class.getSimpleName() + ":  Min lvl: " + _minlvl);
  3552. +       _log.warning(CTF.class.getSimpleName() + ":  Max lvl: " + _maxlvl);
  3553. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  3554. +       _log.warning(CTF.class.getSimpleName() + ":  ##########################");
  3555. +       _log.warning(CTF.class.getSimpleName() + ":  # _teams(Vector<String>) #");
  3556. +       _log.warning(CTF.class.getSimpleName() + ":  ##########################");
  3557. +
  3558. +       for (String team : _teams)
  3559. +           _log.warning(CTF.class.getSimpleName() + ": " + team + " Flags Taken :" + _teamPointsCount.get(_teams.indexOf(team)));
  3560. +
  3561. +       if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  3562. +       {
  3563. +           _log.warning(CTF.class.getSimpleName() + ":  ");
  3564. +           _log.warning(CTF.class.getSimpleName() + ":  #########################################");
  3565. +           _log.warning(CTF.class.getSimpleName() + ":  # _playersShuffle(Vector<Player>) #");
  3566. +           _log.warning(CTF.class.getSimpleName() + ":  #########################################");
  3567. +
  3568. +           for (Player player : _playersShuffle)
  3569. +           {
  3570. +               if (player != null)
  3571. +                   _log.warning(CTF.class.getSimpleName() + ":  Name: " + player.getName());
  3572. +           }
  3573. +       }
  3574. +
  3575. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  3576. +       _log.warning(CTF.class.getSimpleName() + ":  ##################################");
  3577. +       _log.warning(CTF.class.getSimpleName() + ":  # _players(Vector<Player>) #");
  3578. +       _log.warning(CTF.class.getSimpleName() + ":  ##################################");
  3579. +
  3580. +       for (Player player : _players)
  3581. +       {
  3582. +           if (player != null)
  3583. +               _log.warning(CTF.class.getSimpleName() + ":  Name: " + player.getName() + "   Team: " + player._teamNameCTF + "  Flags :" + player._countCTFflags);
  3584. +       }
  3585. +
  3586. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  3587. +       _log.warning(CTF.class.getSimpleName() + ":  #####################################################################");
  3588. +       _log.warning(CTF.class.getSimpleName() + ":  # _savePlayers(Vector<String>) and _savePlayerTeams(Vector<String>) #");
  3589. +       _log.warning(CTF.class.getSimpleName() + ":  #####################################################################");
  3590. +
  3591. +       for (String player : _savePlayers)
  3592. +           _log.warning(CTF.class.getSimpleName() + ":  Name: " + player + "   Team: " + _savePlayerTeams.get(_savePlayers.indexOf(player)));
  3593. +
  3594. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  3595. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  3596. +       _log.warning(CTF.class.getSimpleName() + ":  **********==CTF==************");
  3597. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._teamPointsCount:" + _teamPointsCount.toString());
  3598. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._flagIds:" + _flagIds.toString());
  3599. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._flagSpawns:" + _flagSpawns.toString());
  3600. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._throneSpawns:" + _throneSpawns.toString());
  3601. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._flagsTaken:" + _flagsTaken.toString());
  3602. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._flagsX:" + _flagsX.toString());
  3603. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._flagsY:" + _flagsY.toString());
  3604. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._flagsZ:" + _flagsZ.toString());
  3605. +       _log.warning(CTF.class.getSimpleName() + ":  ************EOF**************");
  3606. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  3607. +   }
  3608. +
  3609. +   public static void loadData()
  3610. +   {
  3611. +       _eventName = new String();
  3612. +       _eventDesc = new String();
  3613. +       _topTeam = new String();
  3614. +       _joiningLocationName = new String();
  3615. +       _teams = new ArrayList<>();
  3616. +       _savePlayers = new ArrayList<>();
  3617. +       _savePlayerTeams = new ArrayList<>();
  3618. +       _players = new ArrayList<>();
  3619. +       _playersShuffle = new ArrayList<>();
  3620. +       _teamPlayersCount = new ArrayList<>();
  3621. +       _teamPointsCount = new ArrayList<>();
  3622. +       _teamColors = new ArrayList<>();
  3623. +       _teamsX = new ArrayList<>();
  3624. +       _teamsY = new ArrayList<>();
  3625. +       _teamsZ = new ArrayList<>();
  3626. +
  3627. +       _throneSpawns = new ArrayList<>();
  3628. +       _flagSpawns = new ArrayList<>();
  3629. +       _flagsTaken = new ArrayList<>();
  3630. +       _flagIds = new ArrayList<>();
  3631. +       _flagsX = new ArrayList<>();
  3632. +       _flagsY = new ArrayList<>();
  3633. +       _flagsZ = new ArrayList<>();
  3634. +
  3635. +       _joining = false;
  3636. +       _teleport = false;
  3637. +       _started = false;
  3638. +       _sitForced = false;
  3639. +       _npcId = 0;
  3640. +       _npcX = 0;
  3641. +       _npcY = 0;
  3642. +       _npcZ = 0;
  3643. +       _npcHeading = 0;
  3644. +       _rewardId = 0;
  3645. +       _rewardAmount = 0;
  3646. +       _topScore = 0;
  3647. +       _minlvl = 0;
  3648. +       _maxlvl = 0;
  3649. +       _joinTime = 0;
  3650. +       _eventTime = 0;
  3651. +       _minPlayers = 0;
  3652. +       _maxPlayers = 0;
  3653. +
  3654. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  3655. +       {
  3656. +           PreparedStatement statement;
  3657. +           ResultSet rs;
  3658. +
  3659. +           statement = con.prepareStatement("SELECT * FROM ctf");
  3660. +           rs = statement.executeQuery();
  3661. +
  3662. +           int teams = 0;
  3663. +
  3664. +           while (rs.next())
  3665. +           {
  3666. +               _eventName = rs.getString("eventName");
  3667. +               _eventDesc = rs.getString("eventDesc");
  3668. +               _joiningLocationName = rs.getString("joiningLocation");
  3669. +               _minlvl = rs.getInt("minlvl");
  3670. +               _maxlvl = rs.getInt("maxlvl");
  3671. +               _npcId = rs.getInt("npcId");
  3672. +               _npcX = rs.getInt("npcX");
  3673. +               _npcY = rs.getInt("npcY");
  3674. +               _npcZ = rs.getInt("npcZ");
  3675. +               _npcHeading = rs.getInt("npcHeading");
  3676. +               _rewardId = rs.getInt("rewardId");
  3677. +               _rewardAmount = rs.getInt("rewardAmount");
  3678. +               teams = rs.getInt("teamsCount");
  3679. +               _joinTime = rs.getInt("joinTime");
  3680. +               _eventTime = rs.getInt("eventTime");
  3681. +               _minPlayers = rs.getInt("minPlayers");
  3682. +               _maxPlayers = rs.getInt("maxPlayers");
  3683. +           }
  3684. +           rs.close();
  3685. +           statement.close();
  3686. +
  3687. +           int index = -1;
  3688. +           if (teams > 0)
  3689. +               index = 0;
  3690. +           while (index < teams && index > -1)
  3691. +           {
  3692. +               statement = con.prepareStatement("SELECT * FROM ctf_teams WHERE teamId=?");
  3693. +               statement.setInt(1, index);
  3694. +               rs = statement.executeQuery();
  3695. +               while (rs.next())
  3696. +               {
  3697. +                   _teams.add(rs.getString("teamName"));
  3698. +                   _teamPlayersCount.add(0);
  3699. +                   _teamPointsCount.add(0);
  3700. +                   _teamColors.add(0);
  3701. +                   _teamsX.add(0);
  3702. +                   _teamsY.add(0);
  3703. +                   _teamsZ.add(0);
  3704. +                   _teamsX.set(index, rs.getInt("teamX"));
  3705. +                   _teamsY.set(index, rs.getInt("teamY"));
  3706. +                   _teamsZ.set(index, rs.getInt("teamZ"));
  3707. +                   _teamColors.set(index, rs.getInt("teamColor"));
  3708. +                   _flagsX.add(0);
  3709. +                   _flagsY.add(0);
  3710. +                   _flagsZ.add(0);
  3711. +                   _flagsX.set(index, rs.getInt("flagX"));
  3712. +                   _flagsY.set(index, rs.getInt("flagY"));
  3713. +                   _flagsZ.set(index, rs.getInt("flagZ"));
  3714. +                   _flagSpawns.add(null);
  3715. +                   _flagIds.add(_FlagNPC);
  3716. +                   _flagsTaken.add(false);
  3717. +
  3718. +               }
  3719. +               index++;
  3720. +               rs.close();
  3721. +               statement.close();
  3722. +           }
  3723. +       }
  3724. +       catch (Exception e)
  3725. +       {
  3726. +           _log.warning(CTF.class.getSimpleName() + ":  Exception: CTF.loadData(): " + e.getMessage());
  3727. +       }
  3728. +   }
  3729. +
  3730. +   public static void saveData()
  3731. +   {
  3732. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  3733. +       {
  3734. +           PreparedStatement statement;
  3735. +
  3736. +           statement = con.prepareStatement("DELETE FROM ctf");
  3737. +           statement.execute();
  3738. +           statement.close();
  3739. +
  3740. +           statement = con.prepareStatement("INSERT INTO ctf (eventName, eventDesc, joiningLocation, minlvl, maxlvl, npcId, npcX, npcY, npcZ, npcHeading, rewardId, rewardAmount, teamsCount, joinTime, eventTime, minPlayers, maxPlayers) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
  3741. +           statement.setString(1, _eventName);
  3742. +           statement.setString(2, _eventDesc);
  3743. +           statement.setString(3, _joiningLocationName);
  3744. +           statement.setInt(4, _minlvl);
  3745. +           statement.setInt(5, _maxlvl);
  3746. +           statement.setInt(6, _npcId);
  3747. +           statement.setInt(7, _npcX);
  3748. +           statement.setInt(8, _npcY);
  3749. +           statement.setInt(9, _npcZ);
  3750. +           statement.setInt(10, _npcHeading);
  3751. +           statement.setInt(11, _rewardId);
  3752. +           statement.setInt(12, _rewardAmount);
  3753. +           statement.setInt(13, _teams.size());
  3754. +           statement.setInt(14, _joinTime);
  3755. +           statement.setInt(15, _eventTime);
  3756. +           statement.setInt(16, _minPlayers);
  3757. +           statement.setInt(17, _maxPlayers);
  3758. +           statement.execute();
  3759. +           statement.close();
  3760. +
  3761. +           statement = con.prepareStatement("DELETE FROM ctf_teams");
  3762. +           statement.execute();
  3763. +           statement.close();
  3764. +
  3765. +           for (String teamName : _teams)
  3766. +           {
  3767. +               int index = _teams.indexOf(teamName);
  3768. +
  3769. +               if (index == -1)
  3770. +                   return;
  3771. +               statement = con.prepareStatement("INSERT INTO ctf_teams (teamId ,teamName, teamX, teamY, teamZ, teamColor, flagX, flagY, flagZ) VALUES (?,?,?,?,?,?,?,?,?)");
  3772. +               statement.setInt(1, index);
  3773. +               statement.setString(2, teamName);
  3774. +               statement.setInt(3, _teamsX.get(index));
  3775. +               statement.setInt(4, _teamsY.get(index));
  3776. +               statement.setInt(5, _teamsZ.get(index));
  3777. +               statement.setInt(6, _teamColors.get(index));
  3778. +               statement.setInt(7, _flagsX.get(index));
  3779. +               statement.setInt(8, _flagsY.get(index));
  3780. +               statement.setInt(9, _flagsZ.get(index));
  3781. +               statement.execute();
  3782. +               statement.close();
  3783. +           }
  3784. +       }
  3785. +       catch (Exception e)
  3786. +       {
  3787. +           _log.warning(CTF.class.getSimpleName() + ":  Exception: CTF.saveData(): " + e.getMessage());
  3788. +       }
  3789. +   }
  3790. +
  3791. +   public static void showEventHtml(Player eventPlayer, String objectId)
  3792. +   {
  3793. +       try
  3794. +       {
  3795. +           NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  3796. +           StringBuilder replyMSG = new StringBuilder();
  3797. +
  3798. +           replyMSG.append("<html><body>");
  3799. +           replyMSG.append("CTF Match<br><br><br>");
  3800. +           replyMSG.append("Current event...<br>");
  3801. +           replyMSG.append("   ... description:&nbsp;<font color=\"00FF00\">" + _eventDesc + "</font><br>");
  3802. +           if (Config.CTF_ANNOUNCE_REWARD)
  3803. +               replyMSG.append("   ... reward: (" + _rewardAmount + ") " + ItemTable.getInstance().getTemplate(_rewardId).getName() + "<br>");
  3804. +
  3805. +           if (!_started && !_joining)
  3806. +               replyMSG.append("<center>Wait till the admin/gm start the participation.</center>");
  3807. +           else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !checkMaxPlayers(_playersShuffle.size()))
  3808. +           {
  3809. +               if (!CTF._started)
  3810. +               {
  3811. +                   replyMSG.append("<font color=\"FFFF00\">The event has reached its maximum capacity.</font><br>Keep checking, someone may crit and you can steal their spot.");
  3812. +               }
  3813. +           }
  3814. +           else if (eventPlayer.isCursedWeaponEquipped() && !Config.CTF_JOIN_CURSED)
  3815. +           {
  3816. +               replyMSG.append("<font color=\"FFFF00\">You can't participate in this event with a cursed Weapon.</font><br>");
  3817. +           }
  3818. +           else if (!_started && _joining && eventPlayer.getLevel() >= _minlvl && eventPlayer.getLevel() <= _maxlvl)
  3819. +           {
  3820. +               if (_players.contains(eventPlayer) || checkShufflePlayers(eventPlayer))
  3821. +               {
  3822. +                   if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  3823. +                       replyMSG.append("You are already participating in team <font color=\"LEVEL\">" + eventPlayer._teamNameCTF + "</font><br><br>");
  3824. +                   else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  3825. +                       replyMSG.append("You are already participating!<br><br>");
  3826. +
  3827. +                   replyMSG.append("<table border=\"0\"><tr>");
  3828. +                   replyMSG.append("<td width=\"200\">Wait till event start or</td>");
  3829. +                   replyMSG.append("<td width=\"60\"><center><button value=\"remove\" action=\"bypass -h npc_" + objectId + "_ctf_player_leave\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></td>");
  3830. +                   replyMSG.append("<td width=\"100\">your participation!</td>");
  3831. +                   replyMSG.append("</tr></table>");
  3832. +               }
  3833. +               else
  3834. +               {
  3835. +                   replyMSG.append("<td width=\"200\">Your level : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font></td><br>");
  3836. +                   replyMSG.append("<td width=\"200\">Min level : <font color=\"00FF00\">" + _minlvl + "</font></td><br>");
  3837. +                   replyMSG.append("<td width=\"200\">Max level : <font color=\"00FF00\">" + _maxlvl + "</font></td><br><br>");
  3838. +
  3839. +                   if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  3840. +                   {
  3841. +                       replyMSG.append("<center><table border=\"0\">");
  3842. +
  3843. +                       for (String team : _teams)
  3844. +                       {
  3845. +                           replyMSG.append("<tr><td width=\"100\"><font color=\"LEVEL\">" + team + "</font>&nbsp;(" + teamPlayersCount(team) + " joined)</td>");
  3846. +                           replyMSG.append("<td width=\"60\"><button value=\"Join\" action=\"bypass -h npc_" + objectId + "_ctf_player_join " + team + "\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  3847. +                       }
  3848. +
  3849. +                       replyMSG.append("</table></center>");
  3850. +                   }
  3851. +                   else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  3852. +                   {
  3853. +                       replyMSG.append("<center><table border=\"0\">");
  3854. +
  3855. +                       for (String team : _teams)
  3856. +                           replyMSG.append("<tr><td width=\"100\"><font color=\"LEVEL\">" + team + "</font></td>");
  3857. +
  3858. +                       replyMSG.append("</table></center><br>");
  3859. +
  3860. +                       replyMSG.append("<button value=\"Join\" action=\"bypass -h npc_" + objectId + "_ctf_player_join eventShuffle\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  3861. +                       replyMSG.append("Teams will be randomly generated!");
  3862. +                   }
  3863. +               }
  3864. +           }
  3865. +           else if (_started && !_joining)
  3866. +               replyMSG.append("<center>CTF match is in progress.</center>");
  3867. +           else if (eventPlayer.getLevel() < _minlvl || eventPlayer.getLevel() > _maxlvl)
  3868. +           {
  3869. +               replyMSG.append("Your lvl : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font><br>");
  3870. +               replyMSG.append("Min level : <font color=\"00FF00\">" + _minlvl + "</font><br>");
  3871. +               replyMSG.append("Max level : <font color=\"00FF00\">" + _maxlvl + "</font><br><br>");
  3872. +               replyMSG.append("<font color=\"FFFF00\">You can't participatein this event.</font><br>");
  3873. +           }
  3874. +           // Show how many players joined & how many are still needed to join
  3875. +           replyMSG.append("<br>There are " + _playersShuffle.size() + " player(s) participating in this event.<br>");
  3876. +           if (_joining)
  3877. +           {
  3878. +               if (_playersShuffle.size() < _minPlayers)
  3879. +               {
  3880. +                   int playersNeeded = _minPlayers - _playersShuffle.size();
  3881. +                   replyMSG.append("The event will not start unless " + playersNeeded + " more player(s) joins!");
  3882. +               }
  3883. +           }
  3884. +
  3885. +           replyMSG.append("</body></html>");
  3886. +           adminReply.setHtml(replyMSG.toString());
  3887. +           eventPlayer.sendPacket(adminReply);
  3888. +
  3889. +           // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  3890. +           eventPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  3891. +       }
  3892. +       catch (Exception e)
  3893. +       {
  3894. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception" + e.getMessage());
  3895. +       }
  3896. +   }
  3897. +
  3898. +   public static void addPlayer(Player player, String teamName)
  3899. +   {
  3900. +       if (!addPlayerOk(teamName, player))
  3901. +           return;
  3902. +
  3903. +       if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  3904. +       {
  3905. +           player._teamNameCTF = teamName;
  3906. +           _players.add(player);
  3907. +           setTeamPlayersCount(teamName, teamPlayersCount(teamName) + 1);
  3908. +       }
  3909. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  3910. +           _playersShuffle.add(player);
  3911. +
  3912. +       player._inEventCTF = true;
  3913. +       player._countCTFflags = 0;
  3914. +   }
  3915. +
  3916. +   public static synchronized void removeOfflinePlayers()
  3917. +   {
  3918. +       try
  3919. +       {
  3920. +           if (_playersShuffle == null)
  3921. +               return;
  3922. +           else if (_playersShuffle.isEmpty())
  3923. +               return;
  3924. +           else if (_playersShuffle.size() > 0)
  3925. +           {
  3926. +               for (Player player : _playersShuffle)
  3927. +               {
  3928. +                   if (player == null)
  3929. +                       _playersShuffle.remove(player);
  3930. +                   else if (player.isOnline() || player.isInJail())
  3931. +                       removePlayer(player);
  3932. +                   if (_playersShuffle.size() == 0 || _playersShuffle.isEmpty())
  3933. +                       break;
  3934. +               }
  3935. +           }
  3936. +       }
  3937. +       catch (Exception e)
  3938. +       {
  3939. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine exception: " + e.getMessage());
  3940. +           return;
  3941. +       }
  3942. +   }
  3943. +
  3944. +   public static boolean checkShufflePlayers(Player eventPlayer)
  3945. +   {
  3946. +       try
  3947. +       {
  3948. +           for (Player player : _playersShuffle)
  3949. +           {
  3950. +               if (player == null || player.isOnline())
  3951. +               {
  3952. +                   _playersShuffle.remove(player);
  3953. +                   eventPlayer._inEventCTF = false;
  3954. +                   continue;
  3955. +               }
  3956. +               else if (player.getObjectId() == eventPlayer.getObjectId())
  3957. +               {
  3958. +                   eventPlayer._inEventCTF = true;
  3959. +                   eventPlayer._countCTFflags = 0;
  3960. +                   return true;
  3961. +               }
  3962. +               // this 1 is in case player got new object id after DC or reconnect
  3963. +               else if (player.getName().equals(eventPlayer.getName()))
  3964. +               {
  3965. +                   _playersShuffle.remove(player);
  3966. +                   _playersShuffle.add(eventPlayer);
  3967. +                   eventPlayer._inEventCTF = true;
  3968. +                   eventPlayer._countCTFflags = 0;
  3969. +                   return true;
  3970. +               }
  3971. +           }
  3972. +       }
  3973. +       catch (Exception e)
  3974. +       {
  3975. +       }
  3976. +       return false;
  3977. +   }
  3978. +
  3979. +   public static boolean addPlayerOk(String teamName, Player eventPlayer)
  3980. +   {
  3981. +       try
  3982. +       {
  3983. +           if (checkShufflePlayers(eventPlayer) || eventPlayer._inEventCTF)
  3984. +           {
  3985. +               eventPlayer.sendMessage("You are already participating in the event!");
  3986. +               return false;
  3987. +           }
  3988. +
  3989. +           for (Player player : _players)
  3990. +           {
  3991. +               if (player.getObjectId() == eventPlayer.getObjectId())
  3992. +               {
  3993. +                   eventPlayer.sendMessage("You are already participating in the event!");
  3994. +                   return false;
  3995. +               }
  3996. +               else if (player.getName() == eventPlayer.getName())
  3997. +               {
  3998. +                   eventPlayer.sendMessage("You are already participating in the event!");
  3999. +                   return false;
  4000. +               }
  4001. +           }
  4002. +           if (_players.contains(eventPlayer))
  4003. +           {
  4004. +               eventPlayer.sendMessage("You are already participating in the event!");
  4005. +               return false;
  4006. +           }
  4007. +       }
  4008. +       catch (Exception e)
  4009. +       {
  4010. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Siege Engine exception: " + e.getMessage());
  4011. +       }
  4012. +
  4013. +       if (Config.CTF_EVEN_TEAMS.equals("NO"))
  4014. +           return true;
  4015. +       else if (Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  4016. +       {
  4017. +           boolean allTeamsEqual = true;
  4018. +           int countBefore = -1;
  4019. +
  4020. +           for (int playersCount : _teamPlayersCount)
  4021. +           {
  4022. +               if (countBefore == -1)
  4023. +                   countBefore = playersCount;
  4024. +
  4025. +               if (countBefore != playersCount)
  4026. +               {
  4027. +                   allTeamsEqual = false;
  4028. +                   break;
  4029. +               }
  4030. +
  4031. +               countBefore = playersCount;
  4032. +           }
  4033. +
  4034. +           if (allTeamsEqual)
  4035. +               return true;
  4036. +
  4037. +           countBefore = Integer.MAX_VALUE;
  4038. +
  4039. +           for (int teamPlayerCount : _teamPlayersCount)
  4040. +           {
  4041. +               if (teamPlayerCount < countBefore)
  4042. +                   countBefore = teamPlayerCount;
  4043. +           }
  4044. +
  4045. +           List<String> joinableTeams = new ArrayList<>();
  4046. +
  4047. +           for (String team : _teams)
  4048. +           {
  4049. +               if (teamPlayersCount(team) == countBefore)
  4050. +                   joinableTeams.add(team);
  4051. +           }
  4052. +
  4053. +           if (joinableTeams.contains(teamName))
  4054. +               return true;
  4055. +       }
  4056. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  4057. +           return true;
  4058. +
  4059. +       eventPlayer.sendMessage("Too many players in team \"" + teamName + "\"");
  4060. +       return false;
  4061. +   }
  4062. +
  4063. +   public static synchronized void addDisconnectedPlayer(Player player)
  4064. +   {
  4065. +       /*
  4066. +        * !!! CAUTION !!!
  4067. +        * Do NOT fix multiple object Ids on this event or you will ruin the flag reposition check!!!
  4068. +        * All Multiple object Ids will be collected by the Garbage Collector, after the event ends, memory sweep is made!!!
  4069. +        */
  4070. +
  4071. +       if ((Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && (_teleport || _started)) || (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE") && (_teleport || _started)))
  4072. +       {
  4073. +           if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
  4074. +           {
  4075. +               for (L2Effect e : player.getAllEffects())
  4076. +               {
  4077. +                   if (e != null)
  4078. +                       e.exit();
  4079. +               }
  4080. +           }
  4081. +
  4082. +           player._teamNameCTF = _savePlayerTeams.get(_savePlayers.indexOf(player.getName()));
  4083. +           for (Player p : _players)
  4084. +           {
  4085. +               if (p == null)
  4086. +               {
  4087. +                   continue;
  4088. +               }
  4089. +               // check by name in case player got new objectId
  4090. +               else if (p.getName().equals(player.getName()))
  4091. +               {
  4092. +                   player._originalNameColorCTF = player.getAppearance().getNameColor();
  4093. +                   player._originalKarmaCTF = player.getKarma();
  4094. +                   player._inEventCTF = true;
  4095. +                   player._countCTFflags = p._countCTFflags;
  4096. +                   _players.remove(p); // removing old object id from vector
  4097. +                   _players.add(player); // adding new objectId to vector
  4098. +                   break;
  4099. +               }
  4100. +           }
  4101. +           player.getAppearance().setNameColor(_teamColors.get(_teams.indexOf(player._teamNameCTF)));
  4102. +           player.setKarma(0);
  4103. +           player.broadcastUserInfo();
  4104. +           player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ.get(_teams.indexOf(player._teamNameCTF)), 0);
  4105. +           Started(player);
  4106. +           CheckRestoreFlags();
  4107. +       }
  4108. +   }
  4109. +
  4110. +   public static void removePlayer(Player player)
  4111. +   {
  4112. +       if (player._inEventCTF)
  4113. +       {
  4114. +           if (!_joining)
  4115. +           {
  4116. +               player.getAppearance().setNameColor(player._originalNameColorCTF);
  4117. +               player.setKarma(player._originalKarmaCTF);
  4118. +               player.broadcastUserInfo();
  4119. +           }
  4120. +           player._teamNameCTF = new String();
  4121. +           player._countCTFflags = 0;
  4122. +           player._inEventCTF = false;
  4123. +
  4124. +           if ((Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE")) && _players.contains(player))
  4125. +           {
  4126. +               setTeamPlayersCount(player._teamNameCTF, teamPlayersCount(player._teamNameCTF) - 1);
  4127. +               _players.remove(player);
  4128. +           }
  4129. +           else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && (!_playersShuffle.isEmpty() && _playersShuffle.contains(player)))
  4130. +               _playersShuffle.remove(player);
  4131. +       }
  4132. +   }
  4133. +
  4134. +   public static void cleanCTF()
  4135. +   {
  4136. +       _log.warning(CTF.class.getSimpleName() + ":  CTF : Cleaning players.");
  4137. +       for (Player player : _players)
  4138. +       {
  4139. +           if (player != null)
  4140. +           {
  4141. +               if (player._haveFlagCTF)
  4142. +                   removeFlagFromPlayer(player);
  4143. +               else
  4144. +                   player.getInventory().destroyItemByItemId("", CTF._FLAG_IN_HAND_ITEM_ID, 1, player, null);
  4145. +               player._haveFlagCTF = false;
  4146. +               removePlayer(player);
  4147. +               if (_savePlayers.contains(player.getName()))
  4148. +                   _savePlayers.remove(player.getName());
  4149. +               player._inEventCTF = false;
  4150. +           }
  4151. +       }
  4152. +       if (_playersShuffle != null && !_playersShuffle.isEmpty())
  4153. +       {
  4154. +           for (Player player : _playersShuffle)
  4155. +           {
  4156. +               if (player != null)
  4157. +                   player._inEventCTF = false;
  4158. +           }
  4159. +       }
  4160. +       _log.warning(CTF.class.getSimpleName() + ":  CTF : Cleaning teams and flags.");
  4161. +       for (String team : _teams)
  4162. +       {
  4163. +           int index = _teams.indexOf(team);
  4164. +           _teamPointsCount.set(index, 0);
  4165. +           _flagSpawns.set(index, null);
  4166. +           _flagsTaken.set(index, false);
  4167. +           _teamPlayersCount.set(index, 0);
  4168. +           _teamPointsCount.set(index, 0);
  4169. +       }
  4170. +       _topScore = 0;
  4171. +       _topTeam = new String();
  4172. +       _players.clear();
  4173. +       _playersShuffle.clear();
  4174. +       _savePlayers.clear();
  4175. +       _savePlayerTeams.clear();
  4176. +       _teamPointsCount.clear();
  4177. +       _flagSpawns.clear();
  4178. +       _flagsTaken.clear();
  4179. +       _teamPlayersCount.clear();
  4180. +       _log.warning(CTF.class.getSimpleName() + ":  Cleaning CTF done.");
  4181. +       _log.warning(CTF.class.getSimpleName() + ":  Loading new data from MySql");
  4182. +       loadData();
  4183. +   }
  4184. +
  4185. +   public static void unspawnEventNpc()
  4186. +   {
  4187. +       if (_npcSpawn == null)
  4188. +           return;
  4189. +
  4190. +       _npcSpawn.getNpc().deleteMe();
  4191. +       _npcSpawn.setRespawnState(false);
  4192. +       SpawnTable.getInstance().deleteSpawn(_npcSpawn, true);
  4193. +   }
  4194. +
  4195. +   public static void teleportFinish()
  4196. +   {
  4197. +       AnnounceToPlayers(false, _eventName + "(CTF): Teleport back to participation NPC in 20 seconds!");
  4198. +       ThreadPool.schedule(new Runnable()
  4199. +       {
  4200. +           @SuppressWarnings("synthetic-access")
  4201. +           @Override
  4202. +           public void run()
  4203. +           {
  4204. +               for (Player player : _players)
  4205. +               {
  4206. +                   if (player != null)
  4207. +                   {
  4208. +                       if (player.isOnline())
  4209. +                           player.teleToLocation(_npcX, _npcY, _npcZ, 0);
  4210. +                       else
  4211. +                       {
  4212. +                           try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  4213. +                           {
  4214. +                               PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=? WHERE char_name=?");
  4215. +                               statement.setInt(1, _npcX);
  4216. +                               statement.setInt(2, _npcY);
  4217. +                               statement.setInt(3, _npcZ);
  4218. +                               statement.setString(4, player.getName());
  4219. +                               statement.execute();
  4220. +                               statement.close();
  4221. +                           }
  4222. +                           catch (SQLException se)
  4223. +                           {
  4224. +                               _log.warning(CTF.class.getSimpleName() + ":  CTF Engine exception: " + se.getMessage());
  4225. +                           }
  4226. +                       }
  4227. +                   }
  4228. +               }
  4229. +               cleanCTF();
  4230. +           }
  4231. +       }, 20000);
  4232. +   }
  4233. +
  4234. +   public static int teamFlagCount(String teamName)
  4235. +   {
  4236. +       int index = _teams.indexOf(teamName);
  4237. +
  4238. +       if (index == -1)
  4239. +           return -1;
  4240. +
  4241. +       return _teamPointsCount.get(index);
  4242. +   }
  4243. +
  4244. +   public static void setTeamFlagCount(String teamName, int teamFlagCount)
  4245. +   {
  4246. +       int index = _teams.indexOf(teamName);
  4247. +
  4248. +       if (index == -1)
  4249. +           return;
  4250. +
  4251. +       _teamPointsCount.set(index, teamFlagCount);
  4252. +   }
  4253. +
  4254. +   /**
  4255. +    * Used to calculate the event CTF area, so that players don't run off with the flag.
  4256. +    * Essential, since a player may take the flag just so other teams can't score points.
  4257. +    * This function is Only called upon ONE time on BEGINING OF EACH EVENT right after we spawn the flags.
  4258. +    */
  4259. +   private static void calculateOutSideOfCTF()
  4260. +   {
  4261. +       if ((_teams == null) || (_flagSpawns == null) || (_teamsX == null) || (_teamsY == null) || (_teamsZ == null))
  4262. +           return;
  4263. +
  4264. +       int division = _teams.size() * 2, pos = 0;
  4265. +       int[] locX = new int[division], locY = new int[division], locZ = new int[division];
  4266. +       // Get all coordinates in order to create a polygon:
  4267. +       for (L2Spawn flag : _flagSpawns)
  4268. +       {
  4269. +           flag.setLoc(locX[pos], locY[pos], locZ[pos], pos);
  4270. +          
  4271. +           pos++;
  4272. +           if (pos > division / 2)
  4273. +               break;
  4274. +       }
  4275. +
  4276. +       for (int x = 0; x < _teams.size(); x++)
  4277. +       {
  4278. +           locX[pos] = _teamsX.get(x);
  4279. +           locY[pos] = _teamsY.get(x);
  4280. +           locZ[pos] = _teamsZ.get(x);
  4281. +           pos++;
  4282. +           if (pos > division)
  4283. +               break;
  4284. +       }
  4285. +
  4286. +       // find the polygon center, note that it's not the mathematical center of the polygon,
  4287. +       // rather than a point which centers all coordinates:
  4288. +       int centerX = 0, centerY = 0, centerZ = 0;
  4289. +       for (int x = 0; x < pos; x++)
  4290. +       {
  4291. +           centerX += (locX[x] / division);
  4292. +           centerY += (locY[x] / division);
  4293. +           centerZ += (locZ[x] / division);
  4294. +       }
  4295. +
  4296. +       // now let's find the farthest distance from the "center" to the egg shaped sphere
  4297. +       // surrounding the polygon, size x1.5 (for maximum logical area to wander...):
  4298. +       int maxX = 0, maxY = 0, maxZ = 0;
  4299. +       for (int x = 0; x < pos; x++)
  4300. +       {
  4301. +           if (maxX < 2 * Math.abs(centerX - locX[x]))
  4302. +               maxX = (2 * Math.abs(centerX - locX[x]));
  4303. +           if (maxY < 2 * Math.abs(centerY - locY[x]))
  4304. +               maxY = (2 * Math.abs(centerY - locY[x]));
  4305. +           if (maxZ < 2 * Math.abs(centerZ - locZ[x]))
  4306. +               maxZ = (2 * Math.abs(centerZ - locZ[x]));
  4307. +       }
  4308. +
  4309. +       // centerX,centerY,centerZ are the coordinates of the "event center".
  4310. +       // so let's save those coordinates to check on the players:
  4311. +       eventCenterX = centerX;
  4312. +       eventCenterY = centerY;
  4313. +       eventCenterZ = centerZ;
  4314. +       eventOffset = maxX;
  4315. +       if (eventOffset < maxY)
  4316. +           eventOffset = maxY;
  4317. +       if (eventOffset < maxZ)
  4318. +           eventOffset = maxZ;
  4319. +   }
  4320. +
  4321. +   public static boolean isOutsideCTFArea(Player _player)
  4322. +   {
  4323. +       if ((_player == null) || (_player.isOnline()))
  4324. +           return true;
  4325. +       if (!(_player.getX() > eventCenterX - eventOffset && _player.getX() < eventCenterX + eventOffset && _player.getY() > eventCenterY - eventOffset && _player.getY() < eventCenterY + eventOffset && _player.getZ() > eventCenterZ - eventOffset && _player.getZ() < eventCenterZ + eventOffset))
  4326. +           return true;
  4327. +       return false;
  4328. +   }
  4329. +}
  4330. \ No newline at end of file
  4331. Index: java/net/sf/l2j/gameserver/model/entity/engine/DM.java
  4332. ===================================================================
  4333. --- java/net/sf/l2j/gameserver/model/entity/engine/DM.java  (revision 0)
  4334. +++ java/net/sf/l2j/gameserver/model/entity/engine/DM.java  (working copy)
  4335. @@ -0,0 +1,700 @@
  4336. +/*
  4337. + * This program is free software: you can redistribute it and/or modify it under
  4338. + * the terms of the GNU General Public License as published by the Free Software
  4339. + * Foundation, either version 3 of the License, or (at your option) any later
  4340. + * version.
  4341. + *
  4342. + * This program is distributed in the hope that it will be useful, but WITHOUT
  4343. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  4344. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  4345. + * details.
  4346. + *
  4347. + * You should have received a copy of the GNU General Public License along with
  4348. + * this program. If not, see <http://www.gnu.org/licenses/>.
  4349. + */
  4350. +package net.sf.l2j.gameserver.model.entity.engine;
  4351. +
  4352. +import java.sql.Connection;
  4353. +import java.sql.PreparedStatement;
  4354. +import java.sql.ResultSet;
  4355. +import java.util.ArrayList;
  4356. +import java.util.List;
  4357. +import java.util.logging.Logger;
  4358. +
  4359. +import net.sf.l2j.Config;
  4360. +import net.sf.l2j.L2DatabaseFactory;
  4361. +import net.sf.l2j.commons.concurrent.ThreadPool;
  4362. +import net.sf.l2j.gameserver.datatables.NpcTable;
  4363. +import net.sf.l2j.gameserver.datatables.SpawnTable;
  4364. +import net.sf.l2j.gameserver.model.L2Effect;
  4365. +import net.sf.l2j.gameserver.model.L2Spawn;
  4366. +import net.sf.l2j.gameserver.model.actor.Summon;
  4367. +import net.sf.l2j.gameserver.model.actor.instance.Pet;
  4368. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  4369. +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  4370. +import net.sf.l2j.gameserver.model.group.Party;
  4371. +import net.sf.l2j.gameserver.model.group.Party.MessageType;
  4372. +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  4373. +import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  4374. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  4375. +import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  4376. +import net.sf.l2j.gameserver.util.Broadcast;
  4377. +
  4378. +/**
  4379. + * @author SqueezeD Edited By TheEnd
  4380. + */
  4381. +public class DM
  4382. +{
  4383. +   private final static Logger _log = Logger.getLogger(DM.class.getName());
  4384. +   public static String _eventName = new String(), _eventDesc = new String(), _joiningLocationName = new String();
  4385. +   public static List<String> _savePlayers = new ArrayList<>();
  4386. +   public static List<Player> _players = new ArrayList<>();
  4387. +   public static boolean _joining = false, _teleport = false, _started = false, _sitForced = false;
  4388. +   public static L2Spawn _npcSpawn;
  4389. +   public static Player _topPlayer;
  4390. +   public static int _npcId = 0, _npcX = 0, _npcY = 0, _npcZ = 0, _rewardId = 0, _rewardAmount = 0, _topKills = 0,
  4391. +           _minlvl = 0, _maxlvl = 0, _playerColors = 0, _playerX = 0, _playerY = 0, _playerZ = 0;
  4392. +
  4393. +   public static void setNpcPos(Player activeChar)
  4394. +   {
  4395. +       _npcX = activeChar.getX();
  4396. +       _npcY = activeChar.getY();
  4397. +       _npcZ = activeChar.getZ();
  4398. +   }
  4399. +
  4400. +   public static boolean checkMaxLevel(int maxlvl)
  4401. +   {
  4402. +       if (_minlvl >= maxlvl)
  4403. +           return false;
  4404. +
  4405. +       return true;
  4406. +   }
  4407. +
  4408. +   public static boolean checkMinLevel(int minlvl)
  4409. +   {
  4410. +       if (_maxlvl <= minlvl)
  4411. +           return false;
  4412. +
  4413. +       return true;
  4414. +   }
  4415. +
  4416. +   public static void setPlayersPos(Player activeChar)
  4417. +   {
  4418. +       _playerX = activeChar.getX();
  4419. +       _playerY = activeChar.getY();
  4420. +       _playerZ = activeChar.getZ();
  4421. +   }
  4422. +
  4423. +   public static boolean checkPlayerOk()
  4424. +   {
  4425. +       if (_started || _teleport || _joining)
  4426. +           return false;
  4427. +
  4428. +       return true;
  4429. +   }
  4430. +
  4431. +   public static void startJoin(Player activeChar)
  4432. +   {
  4433. +       if (!startJoinOk())
  4434. +       {
  4435. +           if (!Config.DEBUG)
  4436. +               _log.fine("DM Engine[startJoin(" + activeChar.getName() + ")]: startJoinOk() = false");
  4437. +           return;
  4438. +       }
  4439. +
  4440. +       _joining = true;
  4441. +       spawnEventNpc(activeChar);
  4442. +       Broadcast.announceToOnlinePlayers(_eventName + "(DM): Joinable in " + _joiningLocationName + "!");
  4443. +   }
  4444. +
  4445. +   private static boolean startJoinOk()
  4446. +   {
  4447. +       if (_started || _teleport || _joining || _eventName.equals("") || _joiningLocationName.equals("") || _eventDesc.equals("") || _npcId == 0 || _npcX == 0 || _npcY == 0 || _npcZ == 0 || _rewardId == 0 || _rewardAmount == 0 || _playerX == 0 || _playerY == 0 || _playerZ == 0)
  4448. +           return false;
  4449. +
  4450. +       return true;
  4451. +   }
  4452. +
  4453. +   private static void spawnEventNpc(Player activeChar)
  4454. +   {
  4455. +       NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
  4456. +
  4457. +       try
  4458. +       {
  4459. +           _npcSpawn = new L2Spawn(tmpl);
  4460. +           _npcSpawn.setLoc(_npcX, _npcY, _npcZ, activeChar.getHeading());
  4461. +           _npcSpawn.setRespawnDelay(1);
  4462. +
  4463. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  4464. +
  4465. +           _npcSpawn.setRespawnState(true);
  4466. +           _npcSpawn.doSpawn(false);
  4467. +           _npcSpawn.getNpc().getStatus().setCurrentHp(999999999);
  4468. +           _npcSpawn.getNpc().setTitle(_eventName);
  4469. +           _npcSpawn.getNpc()._isEventMobDM = true;
  4470. +           _npcSpawn.getNpc().isAggressive();
  4471. +           _npcSpawn.getNpc().decayMe();
  4472. +           _npcSpawn.getNpc().spawnMe(_npcSpawn.getNpc().getX(), _npcSpawn.getNpc().getY(), _npcSpawn.getNpc().getZ());
  4473. +
  4474. +           _npcSpawn.getNpc().broadcastPacket(new MagicSkillUse(_npcSpawn.getNpc(), _npcSpawn.getNpc(), 1034, 1, 1, 1));
  4475. +       }
  4476. +       catch (Exception e)
  4477. +       {
  4478. +           _log.warning(DM.class.getSimpleName() + ":  DM Engine[spawnEventNpc(" + activeChar.getName() + ")]: exception: " + e.getMessage());
  4479. +       }
  4480. +   }
  4481. +
  4482. +   public static void teleportStart()
  4483. +   {
  4484. +       if (!_joining || _started || _teleport)
  4485. +           return;
  4486. +
  4487. +       _joining = false;
  4488. +       Broadcast.announceToOnlinePlayers(_eventName + "(DM): Teleport to team spot in 20 seconds!");
  4489. +
  4490. +       setUserData();
  4491. +       ThreadPool.schedule(new Runnable()
  4492. +       {
  4493. +           @Override
  4494. +           public void run()
  4495. +           {
  4496. +               DM.sit();
  4497. +
  4498. +               for (Player player : DM._players)
  4499. +               {
  4500. +                   if (player != null)
  4501. +                   {
  4502. +                       if (Config.DM_ON_START_UNSUMMON_PET)
  4503. +                       {
  4504. +                           // Remove Summon's buffs
  4505. +                           if (player.getPet() != null)
  4506. +                           {
  4507. +                               Summon summon = player.getPet();
  4508. +                               for (L2Effect e : summon.getAllEffects())
  4509. +                                   e.exit();
  4510. +
  4511. +                               if (summon instanceof Pet)
  4512. +                                   summon.unSummon(player);
  4513. +                           }
  4514. +                       }
  4515. +
  4516. +                       if (Config.DM_ON_START_REMOVE_ALL_EFFECTS)
  4517. +                       {
  4518. +                           for (L2Effect e : player.getAllEffects())
  4519. +                           {
  4520. +                               if (e != null)
  4521. +                                   e.exit();
  4522. +                           }
  4523. +                       }
  4524. +
  4525. +                       // Remove player from his party
  4526. +                       if (player.getParty() != null)
  4527. +                       {
  4528. +                           Party party = player.getParty();
  4529. +                           party.removePartyMember(player, MessageType.EXPELLED);
  4530. +                       }
  4531. +                       player.teleToLocation(_playerX, _playerY, _playerZ, 0);
  4532. +                   }
  4533. +               }
  4534. +           }
  4535. +       }, 20000);
  4536. +       _teleport = true;
  4537. +   }
  4538. +
  4539. +   public static void startEvent(Player activeChar)
  4540. +   {
  4541. +       if (!startEventOk())
  4542. +       {
  4543. +           if (Config.DEBUG)
  4544. +               _log.fine("DM Engine[startEvent(" + activeChar.getName() + ")]: startEventOk() = false");
  4545. +           return;
  4546. +       }
  4547. +
  4548. +       _teleport = false;
  4549. +       sit();
  4550. +       Broadcast.announceToOnlinePlayers(_eventName + "(DM): Started. Go to kill your enemies!");
  4551. +       _started = true;
  4552. +   }
  4553. +
  4554. +   private static boolean startEventOk()
  4555. +   {
  4556. +       if (_joining || !_teleport || _started)
  4557. +           return false;
  4558. +
  4559. +       return true;
  4560. +   }
  4561. +
  4562. +   public static void setUserData()
  4563. +   {
  4564. +       for (Player player : _players)
  4565. +       {
  4566. +           player._originalNameColorDM = player.getAppearance().getNameColor();
  4567. +           player._originalKarmaDM = player.getKarma();
  4568. +           player._inEventDM = true;
  4569. +           player._countDMkills = 0;
  4570. +           player.getAppearance().setNameColor(_playerColors);
  4571. +           player.setKarma(0);
  4572. +           player.broadcastUserInfo();
  4573. +       }
  4574. +   }
  4575. +
  4576. +   public static void removeUserData()
  4577. +   {
  4578. +       for (Player player : _players)
  4579. +       {
  4580. +           player.getAppearance().setNameColor(player._originalNameColorDM);
  4581. +           player.setKarma(player._originalKarmaDM);
  4582. +           player._inEventDM = false;
  4583. +           player._countDMkills = 0;
  4584. +           player.broadcastUserInfo();
  4585. +       }
  4586. +   }
  4587. +
  4588. +   public static void finishEvent(Player activeChar)
  4589. +   {
  4590. +       if (!finishEventOk())
  4591. +       {
  4592. +           if (Config.DEBUG)
  4593. +               _log.fine("DM Engine[finishEvent(" + activeChar.getName() + ")]: finishEventOk() = false");
  4594. +           return;
  4595. +       }
  4596. +
  4597. +       _started = false;
  4598. +       unspawnEventNpc();
  4599. +       processTopPlayer();
  4600. +
  4601. +       if (_topKills == 0)
  4602. +           Broadcast.announceToOnlinePlayers(_eventName + "(DM): No players win the match(nobody killed).");
  4603. +       else
  4604. +       {
  4605. +           Broadcast.announceToOnlinePlayers(_eventName + "(DM): " + _topPlayer.getName() + " wins the match! " + _topKills + " kills.");
  4606. +           rewardPlayer(activeChar);
  4607. +       }
  4608. +
  4609. +       teleportFinish();
  4610. +   }
  4611. +
  4612. +   private static boolean finishEventOk()
  4613. +   {
  4614. +       if (!_started)
  4615. +           return false;
  4616. +
  4617. +       return true;
  4618. +   }
  4619. +
  4620. +   public static void processTopPlayer()
  4621. +   {
  4622. +       for (Player player : _players)
  4623. +       {
  4624. +           if (player._countDMkills > _topKills)
  4625. +           {
  4626. +               _topPlayer = player;
  4627. +               _topKills = player._countDMkills;
  4628. +           }
  4629. +       }
  4630. +   }
  4631. +
  4632. +   /**
  4633. +    * @param activeChar
  4634. +    */
  4635. +   public static void rewardPlayer(Player activeChar)
  4636. +   {
  4637. +       if (_topPlayer != null)
  4638. +       {
  4639. +           _topPlayer.addItem("DM Event: " + _eventName, _rewardId, _rewardAmount, _topPlayer, true);
  4640. +
  4641. +           StatusUpdate su = new StatusUpdate(_topPlayer);
  4642. +           su.addAttribute(StatusUpdate.CUR_LOAD, _topPlayer.getCurrentLoad());
  4643. +           _topPlayer.sendPacket(su);
  4644. +
  4645. +           NpcHtmlMessage nhm = new NpcHtmlMessage(5);
  4646. +           StringBuilder replyMSG = new StringBuilder("");
  4647. +
  4648. +           replyMSG.append("<html><body>You won the event. Look in your inventory for the reward.</body></html>");
  4649. +
  4650. +           nhm.setHtml(replyMSG.toString());
  4651. +           _topPlayer.sendPacket(nhm);
  4652. +
  4653. +           // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  4654. +           _topPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  4655. +       }
  4656. +   }
  4657. +
  4658. +   public static void abortEvent()
  4659. +   {
  4660. +       if (!_joining && !_teleport && !_started)
  4661. +           return;
  4662. +
  4663. +       _joining = false;
  4664. +       _teleport = false;
  4665. +       _started = false;
  4666. +       unspawnEventNpc();
  4667. +       Broadcast.announceToOnlinePlayers(_eventName + "(DM): Match aborted!");
  4668. +       teleportFinish();
  4669. +   }
  4670. +
  4671. +   public static void sit()
  4672. +   {
  4673. +       if (_sitForced)
  4674. +           _sitForced = false;
  4675. +       else
  4676. +           _sitForced = true;
  4677. +
  4678. +       for (Player player : _players)
  4679. +       {
  4680. +           if (player != null)
  4681. +           {
  4682. +               if (_sitForced)
  4683. +               {
  4684. +                   player.stopMove(null);
  4685. +                   player.abortAttack();
  4686. +                   player.abortCast();
  4687. +
  4688. +                   if (!player.isSitting())
  4689. +                       player.sitDown();
  4690. +               }
  4691. +               else
  4692. +               {
  4693. +                   if (player.isSitting())
  4694. +                       player.standUp();
  4695. +               }
  4696. +           }
  4697. +       }
  4698. +   }
  4699. +
  4700. +   public static void dumpData()
  4701. +   {
  4702. +       _log.info("");
  4703. +       _log.info("");
  4704. +
  4705. +       if (!_joining && !_teleport && !_started)
  4706. +       {
  4707. +           _log.info("<<---------------------------------->>");
  4708. +           _log.info(">> DM Engine infos dump (INACTIVE) <<");
  4709. +           _log.info("<<--^----^^-----^----^^------^^----->>");
  4710. +       }
  4711. +       else if (_joining && !_teleport && !_started)
  4712. +       {
  4713. +           _log.info("<<--------------------------------->>");
  4714. +           _log.info(">> DM Engine infos dump (JOINING) <<");
  4715. +           _log.info("<<--^----^^-----^----^^------^----->>");
  4716. +       }
  4717. +       else if (!_joining && _teleport && !_started)
  4718. +       {
  4719. +           _log.info("<<---------------------------------->>");
  4720. +           _log.info(">> DM Engine infos dump (TELEPORT) <<");
  4721. +           _log.info("<<--^----^^-----^----^^------^^----->>");
  4722. +       }
  4723. +       else if (!_joining && !_teleport && _started)
  4724. +       {
  4725. +           _log.info("<<--------------------------------->>");
  4726. +           _log.info(">> DM Engine infos dump (STARTED) <<");
  4727. +           _log.info("<<--^----^^-----^----^^------^----->>");
  4728. +       }
  4729. +
  4730. +       _log.info("Name: " + _eventName);
  4731. +       _log.info("Desc: " + _eventDesc);
  4732. +       _log.info("Join location: " + _joiningLocationName);
  4733. +       _log.info("Min lvl: " + _minlvl);
  4734. +       _log.info("Max lvl: " + _maxlvl);
  4735. +
  4736. +       _log.info("");
  4737. +       _log.info("##################################");
  4738. +       _log.info("# _players(Vector<Player>) #");
  4739. +       _log.info("##################################");
  4740. +
  4741. +       _log.info("Total Players : " + _players.size());
  4742. +
  4743. +       for (Player player : _players)
  4744. +       {
  4745. +           if (player != null)
  4746. +               _log.info("Name: " + player.getName() + " kills :" + player._countDMkills);
  4747. +       }
  4748. +
  4749. +       _log.info("");
  4750. +       _log.info("################################");
  4751. +       _log.info("# _savePlayers(Vector<String>) #");
  4752. +       _log.info("################################");
  4753. +
  4754. +       for (String player : _savePlayers)
  4755. +           _log.info("Name: " + player);
  4756. +
  4757. +       _log.info("");
  4758. +       _log.info("");
  4759. +   }
  4760. +
  4761. +   public static void loadData()
  4762. +   {
  4763. +       _eventName = new String();
  4764. +       _eventDesc = new String();
  4765. +       _joiningLocationName = new String();
  4766. +       _savePlayers = new ArrayList<>();
  4767. +       _players = new ArrayList<>();
  4768. +       _topPlayer = null;
  4769. +       _npcSpawn = null;
  4770. +       _joining = false;
  4771. +       _teleport = false;
  4772. +       _started = false;
  4773. +       _sitForced = false;
  4774. +       _npcId = 0;
  4775. +       _npcX = 0;
  4776. +       _npcY = 0;
  4777. +       _npcZ = 0;
  4778. +       _rewardId = 0;
  4779. +       _rewardAmount = 0;
  4780. +       _topKills = 0;
  4781. +       _minlvl = 0;
  4782. +       _maxlvl = 0;
  4783. +       _playerColors = 0;
  4784. +       _playerX = 0;
  4785. +       _playerY = 0;
  4786. +       _playerZ = 0;
  4787. +
  4788. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  4789. +       {
  4790. +           PreparedStatement statement;
  4791. +           ResultSet rs;
  4792. +
  4793. +           statement = con.prepareStatement("SELECT * FROM dm");
  4794. +           rs = statement.executeQuery();
  4795. +
  4796. +           while (rs.next())
  4797. +           {
  4798. +               _eventName = rs.getString("eventName");
  4799. +               _eventDesc = rs.getString("eventDesc");
  4800. +               _joiningLocationName = rs.getString("joiningLocation");
  4801. +               _minlvl = rs.getInt("minlvl");
  4802. +               _maxlvl = rs.getInt("maxlvl");
  4803. +               _npcId = rs.getInt("npcId");
  4804. +               _npcX = rs.getInt("npcX");
  4805. +               _npcY = rs.getInt("npcY");
  4806. +               _npcZ = rs.getInt("npcZ");
  4807. +               _rewardId = rs.getInt("rewardId");
  4808. +               _rewardAmount = rs.getInt("rewardAmount");
  4809. +               _playerColors = rs.getInt("color");
  4810. +               _playerX = rs.getInt("playerX");
  4811. +               _playerY = rs.getInt("playerY");
  4812. +               _playerZ = rs.getInt("playerZ");
  4813. +
  4814. +           }
  4815. +           rs.close();
  4816. +           statement.close();
  4817. +       }
  4818. +       catch (Exception e)
  4819. +       {
  4820. +           _log.warning(DM.class.getSimpleName() + ":  Exception: DM.loadData(): " + e.getMessage());
  4821. +       }
  4822. +   }
  4823. +
  4824. +   public static void saveData()
  4825. +   {
  4826. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  4827. +       {
  4828. +           PreparedStatement statement;
  4829. +
  4830. +           statement = con.prepareStatement("DELETE FROM dm");
  4831. +           statement.execute();
  4832. +           statement.close();
  4833. +
  4834. +           statement = con.prepareStatement("INSERT INTO dm (eventName, eventDesc, joiningLocation, minlvl, maxlvl, npcId, npcX, npcY, npcZ, rewardId, rewardAmount, color, playerX, playerY, playerZ ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
  4835. +           statement.setString(1, _eventName);
  4836. +           statement.setString(2, _eventDesc);
  4837. +           statement.setString(3, _joiningLocationName);
  4838. +           statement.setInt(4, _minlvl);
  4839. +           statement.setInt(5, _maxlvl);
  4840. +           statement.setInt(6, _npcId);
  4841. +           statement.setInt(7, _npcX);
  4842. +           statement.setInt(8, _npcY);
  4843. +           statement.setInt(9, _npcZ);
  4844. +           statement.setInt(10, _rewardId);
  4845. +           statement.setInt(11, _rewardAmount);
  4846. +           statement.setInt(12, _playerColors);
  4847. +           statement.setInt(13, _playerX);
  4848. +           statement.setInt(14, _playerY);
  4849. +           statement.setInt(15, _playerZ);
  4850. +           statement.execute();
  4851. +           statement.close();
  4852. +       }
  4853. +       catch (Exception e)
  4854. +       {
  4855. +           _log.warning(DM.class.getSimpleName() + ":  Exception: DM.saveData(): " + e.getMessage());
  4856. +       }
  4857. +   }
  4858. +
  4859. +   public static void showEventHtml(Player eventPlayer, String objectId)
  4860. +   {
  4861. +       try
  4862. +       {
  4863. +           NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  4864. +
  4865. +           StringBuilder replyMSG = new StringBuilder("<html><body>");
  4866. +           replyMSG.append("DM Match<br><br><br>");
  4867. +           replyMSG.append("Current event...<br1>");
  4868. +           replyMSG.append("   ... name:&nbsp;<font color=\"00FF00\">" + _eventName + "</font><br1>");
  4869. +           replyMSG.append("   ... description:&nbsp;<font color=\"00FF00\">" + _eventDesc + "</font><br><br>");
  4870. +
  4871. +           if (!_started && !_joining)
  4872. +               replyMSG.append("<center>Wait till the admin/gm start the participation.</center>");
  4873. +           else if (!_started && _joining && eventPlayer.getLevel() >= _minlvl && eventPlayer.getLevel() < _maxlvl)
  4874. +           {
  4875. +               if (_players.contains(eventPlayer))
  4876. +               {
  4877. +                   replyMSG.append("You are already participating!<br><br>");
  4878. +
  4879. +                   replyMSG.append("<table border=\"0\"><tr>");
  4880. +                   replyMSG.append("<td width=\"200\">Wait till event start or</td>");
  4881. +                   replyMSG.append("<td width=\"60\"><center><button value=\"remove\" action=\"bypass -h npc_" + objectId + "_dmevent_player_leave\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></td>");
  4882. +                   replyMSG.append("<td width=\"100\">your participation!</td>");
  4883. +                   replyMSG.append("</tr></table>");
  4884. +               }
  4885. +               else
  4886. +               {
  4887. +                   replyMSG.append("You want to participate in the event?<br><br>");
  4888. +                   replyMSG.append("<td width=\"200\">Admin set min lvl : <font color=\"00FF00\">" + _minlvl + "</font></td><br>");
  4889. +                   replyMSG.append("<td width=\"200\">Admin set max lvl : <font color=\"00FF00\">" + _maxlvl + "</font></td><br><br>");
  4890. +
  4891. +                   replyMSG.append("<button value=\"Join\" action=\"bypass -h npc_" + objectId + "_dmevent_player_join\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  4892. +
  4893. +               }
  4894. +           }
  4895. +           else if (_started && !_joining)
  4896. +               replyMSG.append("<center>DM match is in progress.</center>");
  4897. +           else if (eventPlayer.getLevel() < _minlvl || eventPlayer.getLevel() > _maxlvl)
  4898. +           {
  4899. +               replyMSG.append("Your lvl : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font><br>");
  4900. +               replyMSG.append("Admin set min lvl : <font color=\"00FF00\">" + _minlvl + "</font><br>");
  4901. +               replyMSG.append("Admin set max lvl : <font color=\"00FF00\">" + _maxlvl + "</font><br><br>");
  4902. +               replyMSG.append("<font color=\"FFFF00\">You can't participate to this event.</font><br>");
  4903. +           }
  4904. +
  4905. +           replyMSG.append("</body></html>");
  4906. +           adminReply.setHtml(replyMSG.toString());
  4907. +           eventPlayer.sendPacket(adminReply);
  4908. +
  4909. +           // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  4910. +           eventPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  4911. +       }
  4912. +       catch (Exception e)
  4913. +       {
  4914. +           _log.warning(DM.class.getSimpleName() + ":  DM Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception" + e.getMessage());
  4915. +       }
  4916. +   }
  4917. +
  4918. +   public static void addPlayer(Player player)
  4919. +   {
  4920. +       if (!addPlayerOk(player))
  4921. +           return;
  4922. +       _players.add(player);
  4923. +       player._originalNameColorDM = player.getAppearance().getNameColor();
  4924. +       player._originalKarmaDM = player.getKarma();
  4925. +       player._inEventDM = true;
  4926. +       player._countDMkills = 0;
  4927. +       _savePlayers.add(player.getName());
  4928. +
  4929. +   }
  4930. +
  4931. +   public static boolean addPlayerOk(Player eventPlayer)
  4932. +   {
  4933. +
  4934. +       if (eventPlayer._inEventDM)
  4935. +       {
  4936. +           eventPlayer.sendMessage("You are already participating in the event!");
  4937. +           return false;
  4938. +       }
  4939. +
  4940. +       return true;
  4941. +   }
  4942. +
  4943. +   public static synchronized void addDisconnectedPlayer(Player player)
  4944. +   {
  4945. +       if ((_teleport || _started) || _savePlayers.contains(player.getName()))
  4946. +       {
  4947. +           if (Config.DM_ON_START_REMOVE_ALL_EFFECTS)
  4948. +           {
  4949. +               for (L2Effect e : player.getAllEffects())
  4950. +               {
  4951. +                   if (e != null)
  4952. +                       e.exit();
  4953. +               }
  4954. +           }
  4955. +           for (Player p : _players)
  4956. +           {
  4957. +               if (p == null)
  4958. +               {
  4959. +                   continue;
  4960. +               }
  4961. +               // check by name incase player got new objectId
  4962. +               else if (p.getName().equals(player.getName()))
  4963. +               {
  4964. +                   player._originalNameColorDM = player.getAppearance().getNameColor();
  4965. +                   player._originalKarmaDM = player.getKarma();
  4966. +                   player._inEventDM = true;
  4967. +                   player._countDMkills = p._countDMkills;
  4968. +                   _players.remove(p); // removing old object id from vector
  4969. +                   _players.add(player); // adding new objectId to vector
  4970. +                   break;
  4971. +               }
  4972. +           }
  4973. +
  4974. +           player.getAppearance().setNameColor(_playerColors);
  4975. +           player.setKarma(0);
  4976. +           player.broadcastUserInfo();
  4977. +           player.teleToLocation(_playerX, _playerY, _playerZ, 0);
  4978. +       }
  4979. +   }
  4980. +
  4981. +   public static void removePlayer(Player player)
  4982. +   {
  4983. +       if (player != null)
  4984. +           _players.remove(player);
  4985. +   }
  4986. +
  4987. +   public static void cleanDM()
  4988. +   {
  4989. +       for (Player player : _players)
  4990. +       {
  4991. +           removePlayer(player);
  4992. +       }
  4993. +
  4994. +       _savePlayers = new ArrayList<>();
  4995. +       _topPlayer = null;
  4996. +       _npcSpawn = null;
  4997. +       _joining = false;
  4998. +       _teleport = false;
  4999. +       _started = false;
  5000. +       _sitForced = false;
  5001. +       _topKills = 0;
  5002. +       _players = new ArrayList<>();
  5003. +
  5004. +   }
  5005. +
  5006. +   public static void unspawnEventNpc()
  5007. +   {
  5008. +       if (_npcSpawn == null)
  5009. +           return;
  5010. +
  5011. +       _npcSpawn.getNpc().deleteMe();
  5012. +       _npcSpawn.setRespawnState(false);
  5013. +       SpawnTable.getInstance().deleteSpawn(_npcSpawn, true);
  5014. +   }
  5015. +
  5016. +   public static void teleportFinish()
  5017. +   {
  5018. +       Broadcast.announceToOnlinePlayers(_eventName + "(DM): Teleport back to participation NPC in 20 seconds!");
  5019. +
  5020. +       removeUserData();
  5021. +       ThreadPool.schedule(new Runnable()
  5022. +       {
  5023. +           @Override
  5024. +           public void run()
  5025. +           {
  5026. +               for (Player player : _players)
  5027. +               {
  5028. +                   if (player != null && player.isOnline())
  5029. +                       player.teleToLocation(_npcX, _npcY, _npcZ, 0);
  5030. +               }
  5031. +               cleanDM();
  5032. +           }
  5033. +       }, 20000);
  5034. +   }
  5035. +}
  5036. \ No newline at end of file
  5037. Index: java/net/sf/l2j/gameserver/model/entity/engine/EventHandlerCtf.java
  5038. ===================================================================
  5039. --- java/net/sf/l2j/gameserver/model/entity/engine/EventHandlerCtf.java (revision 0)
  5040. +++ java/net/sf/l2j/gameserver/model/entity/engine/EventHandlerCtf.java (working copy)
  5041. @@ -0,0 +1,92 @@
  5042. +/*
  5043. + * This program is free software: you can redistribute it and/or modify it under
  5044. + * the terms of the GNU General Public License as published by the Free Software
  5045. + * Foundation, either version 3 of the License, or (at your option) any later
  5046. + * version.
  5047. + *
  5048. + * This program is distributed in the hope that it will be useful, but WITHOUT
  5049. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  5050. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  5051. + * details.
  5052. + *
  5053. + * You should have received a copy of the GNU General Public License along with
  5054. + * this program. If not, see <http://www.gnu.org/licenses/>.
  5055. + */
  5056. +package net.sf.l2j.gameserver.model.entity.engine;
  5057. +
  5058. +import java.util.ArrayList;
  5059. +import java.util.Calendar;
  5060. +import java.util.List;
  5061. +import java.util.logging.Logger;
  5062. +
  5063. +import net.sf.l2j.Config;
  5064. +import net.sf.l2j.commons.concurrent.ThreadPool;
  5065. +;
  5066. +
  5067. +/**
  5068. + * @author Boorinio
  5069. + */
  5070. +public class EventHandlerCtf
  5071. +{
  5072. +   private static final Logger _log = Logger.getLogger(EventHandlerCtf.class.getName());
  5073. +   public List<Long> datesCtf = new ArrayList<>();
  5074. +  
  5075. +   public void startHandler()
  5076. +   {
  5077. +       loadConfisCtf(false);
  5078. +       getNextTimeStampCTF();
  5079. +       _log.info(EventHandlerCtf.class.getSimpleName() + ": Ctf handler initiated");
  5080. +   }
  5081. +  
  5082. +   public void loadConfisCtf(boolean NextDay)
  5083. +   {
  5084. +       datesCtf.clear();
  5085. +       for (String times : Config.CTF_EVENT_TIMES.split(","))
  5086. +       {
  5087. +           String[] timesSplited = times.split(":");
  5088. +           int hour = Integer.parseInt(timesSplited[0]);
  5089. +           int minute = Integer.parseInt(timesSplited[1]);
  5090. +           Calendar time = Calendar.getInstance();
  5091. +           if (!NextDay)
  5092. +           {
  5093. +               time.set(Calendar.HOUR_OF_DAY, hour);
  5094. +               time.set(Calendar.MINUTE, minute);
  5095. +           }
  5096. +           else
  5097. +           {
  5098. +               time.set(Calendar.DAY_OF_MONTH, Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + 1);
  5099. +               time.set(Calendar.HOUR_OF_DAY, hour);
  5100. +               time.set(Calendar.MINUTE, minute);
  5101. +           }
  5102. +           datesCtf.add(time.getTimeInMillis());
  5103. +       }
  5104. +   }
  5105. +  
  5106. +   public void getNextTimeStampCTF()
  5107. +   {
  5108. +       boolean found = false;
  5109. +       for (Long stamp : datesCtf)
  5110. +       {
  5111. +           if (stamp > System.currentTimeMillis())
  5112. +           {
  5113. +               ThreadPool.schedule(new Runnable()
  5114. +               {
  5115. +                   @Override
  5116. +                   public void run()
  5117. +                   {
  5118. +                       CTF.loadData();
  5119. +                       CTF.autoEvent();
  5120. +                       getNextTimeStampCTF();
  5121. +                   }
  5122. +               }, stamp - System.currentTimeMillis());
  5123. +               found = true;
  5124. +               break;
  5125. +           }
  5126. +       }
  5127. +       if (!found)
  5128. +       {
  5129. +           loadConfisCtf(true);
  5130. +           getNextTimeStampCTF();
  5131. +       }
  5132. +   }
  5133. +}
  5134. Index: java/net/sf/l2j/gameserver/model/entity/engine/EventHandlerTvT.java
  5135. ===================================================================
  5136. --- java/net/sf/l2j/gameserver/model/entity/engine/EventHandlerTvT.java (revision 0)
  5137. +++ java/net/sf/l2j/gameserver/model/entity/engine/EventHandlerTvT.java (working copy)
  5138. @@ -0,0 +1,91 @@
  5139. +/*
  5140. + * This program is free software: you can redistribute it and/or modify it under
  5141. + * the terms of the GNU General Public License as published by the Free Software
  5142. + * Foundation, either version 3 of the License, or (at your option) any later
  5143. + * version.
  5144. + *
  5145. + * This program is distributed in the hope that it will be useful, but WITHOUT
  5146. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  5147. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  5148. + * details.
  5149. + *
  5150. + * You should have received a copy of the GNU General Public License along with
  5151. + * this program. If not, see <http://www.gnu.org/licenses/>.
  5152. + */
  5153. +package net.sf.l2j.gameserver.model.entity.engine;
  5154. +
  5155. +import java.util.ArrayList;
  5156. +import java.util.Calendar;
  5157. +import java.util.List;
  5158. +import java.util.logging.Logger;
  5159. +
  5160. +import net.sf.l2j.Config;
  5161. +import net.sf.l2j.commons.concurrent.ThreadPool;
  5162. +
  5163. +/**
  5164. + * @author Boorinio
  5165. + */
  5166. +public class EventHandlerTvT
  5167. +{
  5168. +   private static final Logger _log = Logger.getLogger(EventHandlerTvT.class.getName());
  5169. +   public List<Long> datesTvT = new ArrayList<>();
  5170. +  
  5171. +   public void startHandler()
  5172. +   {
  5173. +       loadConfisTvT(false);
  5174. +       getNextTimeStampTvT();
  5175. +       _log.info(EventHandlerTvT.class.getSimpleName() + ": TvT handler initiated.");
  5176. +   }
  5177. +  
  5178. +   public void loadConfisTvT(boolean NextDay)
  5179. +   {
  5180. +       datesTvT.clear();
  5181. +       for (String times : Config.TVT_EVENT_TIMES.split(","))
  5182. +       {
  5183. +           String[] timesSplited = times.split(":");
  5184. +           int hour = Integer.parseInt(timesSplited[0]);
  5185. +           int minute = Integer.parseInt(timesSplited[1]);
  5186. +           Calendar time = Calendar.getInstance();
  5187. +           if (!NextDay)
  5188. +           {
  5189. +               time.set(Calendar.HOUR_OF_DAY, hour);
  5190. +               time.set(Calendar.MINUTE, minute);
  5191. +           }
  5192. +           else
  5193. +           {
  5194. +               time.set(Calendar.DAY_OF_MONTH, Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + 1);
  5195. +               time.set(Calendar.HOUR_OF_DAY, hour);
  5196. +               time.set(Calendar.MINUTE, minute);
  5197. +           }
  5198. +           datesTvT.add(time.getTimeInMillis());
  5199. +       }
  5200. +   }
  5201. +  
  5202. +   public void getNextTimeStampTvT()
  5203. +   {
  5204. +       boolean found = false;
  5205. +       for (Long stamp : datesTvT)
  5206. +       {
  5207. +           if (stamp > System.currentTimeMillis())
  5208. +           {
  5209. +               ThreadPool.schedule(new Runnable()
  5210. +               {
  5211. +                   @Override
  5212. +                   public void run()
  5213. +                   {
  5214. +                       TvT.loadData();
  5215. +                       TvT.autoEvent();
  5216. +                       getNextTimeStampTvT();
  5217. +                   }
  5218. +               }, stamp - System.currentTimeMillis());
  5219. +               found = true;
  5220. +               break;
  5221. +           }
  5222. +       }
  5223. +       if (!found)
  5224. +       {
  5225. +           loadConfisTvT(true);
  5226. +           getNextTimeStampTvT();
  5227. +       }
  5228. +   }
  5229. +}
  5230. Index: java/net/sf/l2j/gameserver/model/entity/engine/TvT.java
  5231. ===================================================================
  5232. --- java/net/sf/l2j/gameserver/model/entity/engine/TvT.java (revision 0)
  5233. +++ java/net/sf/l2j/gameserver/model/entity/engine/TvT.java (working copy)
  5234. @@ -0,0 +1,1767 @@
  5235. +/*
  5236. + * This program is free software: you can redistribute it and/or modify it under
  5237. + * the terms of the GNU General Public License as published by the Free Software
  5238. + * Foundation, either version 3 of the License, or (at your option) any later
  5239. + * version.
  5240. + *
  5241. + * This program is distributed in the hope that it will be useful, but WITHOUT
  5242. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  5243. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  5244. + * details.
  5245. + *
  5246. + * You should have received a copy of the GNU General Public License along with
  5247. + * this program. If not, see <http://www.gnu.org/licenses/>.
  5248. + */
  5249. +package net.sf.l2j.gameserver.model.entity.engine;
  5250. +
  5251. +/**
  5252. + * @author FBIagent / Fixed By l2jhellas And L2Emu Team
  5253. + */
  5254. +import java.sql.Connection;
  5255. +import java.sql.PreparedStatement;
  5256. +import java.sql.ResultSet;
  5257. +import java.sql.SQLException;
  5258. +import java.util.ArrayList;
  5259. +import java.util.List;
  5260. +import java.util.logging.Level;
  5261. +import java.util.logging.Logger;
  5262. +
  5263. +import net.sf.l2j.Config;
  5264. +import net.sf.l2j.L2DatabaseFactory;
  5265. +import net.sf.l2j.commons.concurrent.ThreadPool;
  5266. +import net.sf.l2j.commons.random.Rnd;
  5267. +import net.sf.l2j.gameserver.datatables.DoorTable;
  5268. +import net.sf.l2j.gameserver.datatables.ItemTable;
  5269. +import net.sf.l2j.gameserver.datatables.NpcTable;
  5270. +import net.sf.l2j.gameserver.datatables.SpawnTable;
  5271. +import net.sf.l2j.gameserver.model.L2Effect;
  5272. +import net.sf.l2j.gameserver.model.L2Spawn;
  5273. +import net.sf.l2j.gameserver.model.actor.Summon;
  5274. +import net.sf.l2j.gameserver.model.actor.instance.Pet;
  5275. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  5276. +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  5277. +import net.sf.l2j.gameserver.model.group.Party;
  5278. +import net.sf.l2j.gameserver.model.group.Party.MessageType;
  5279. +import net.sf.l2j.gameserver.model.olympiad.OlympiadManager;
  5280. +import net.sf.l2j.gameserver.network.clientpackets.Say2;
  5281. +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  5282. +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  5283. +import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  5284. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  5285. +import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
  5286. +import net.sf.l2j.gameserver.util.Broadcast;
  5287. +
  5288. +public class TvT
  5289. +{
  5290. +   protected static final Logger _log = Logger.getLogger(TvT.class.getName());
  5291. +   public static String _eventName = "";
  5292. +   public static String _eventDesc = "";
  5293. +   public static String _topTeam = "";
  5294. +   public static String _joiningLocationName = "";
  5295. +   public static List<String> _teams = new ArrayList<>();
  5296. +   public static List<String> _savePlayers = new ArrayList<>();
  5297. +   public static List<String> _savePlayerTeams = new ArrayList<>();
  5298. +
  5299. +   public static List<Player> _players = new ArrayList<>();
  5300. +   public static List<Player> _playersShuffle = new ArrayList<>();
  5301. +   public static List<Integer> _teamPlayersCount = new ArrayList<>();
  5302. +   public static List<Integer> _teamKillsCount = new ArrayList<>();
  5303. +   public static List<Integer> _teamColors = new ArrayList<>();
  5304. +   public static List<Integer> _teamsX = new ArrayList<>();
  5305. +   public static List<Integer> _teamsY = new ArrayList<>();
  5306. +   public static List<Integer> _teamsZ = new ArrayList<>();
  5307. +   public static boolean _joining = false;
  5308. +   public static boolean _teleport = false;
  5309. +   public static boolean _started = false;
  5310. +   public static boolean _sitForced = false;
  5311. +   public static L2Spawn _npcSpawn;
  5312. +
  5313. +   public static int _npcId = 0;
  5314. +   public static int _npcX = 0;
  5315. +   public static int _npcY = 0;
  5316. +   public static int _npcZ = 0;
  5317. +   public static int _npcHeading = 0;
  5318. +
  5319. +   public static int _rewardId = 0;
  5320. +   public static int _rewardAmount = 0;
  5321. +
  5322. +   public static int _topKills = 0;
  5323. +   public static int _minlvl = 0;
  5324. +   public static int _maxlvl = 0;
  5325. +
  5326. +   public static int _joinTime = 0;
  5327. +   public static int _eventTime = 0;
  5328. +
  5329. +   public static int _minPlayers = 0;
  5330. +   public static int _maxPlayers = 0;
  5331. +
  5332. +   public static int _playerWon = 0;
  5333. +
  5334. +   public static void AnnounceToPlayers(Boolean toall, String announce)
  5335. +   {
  5336. +       if (toall)
  5337. +           Broadcast.announceToOnlinePlayers(announce);
  5338. +       else
  5339. +       {
  5340. +           CreatureSay cs = new CreatureSay(0, Say2.ANNOUNCEMENT, "", announce);
  5341. +           if (_players != null && !_players.isEmpty())
  5342. +           {
  5343. +               for (Player player : _players)
  5344. +               {
  5345. +                   if (player != null && player.isOnline())
  5346. +                       player.sendPacket(cs);
  5347. +               }
  5348. +           }
  5349. +       }
  5350. +   }
  5351. +
  5352. +   public static void kickPlayerFromTvt(Player playerToKick)
  5353. +   {
  5354. +       if (playerToKick == null)
  5355. +           return;
  5356. +
  5357. +       if (_joining)
  5358. +       {
  5359. +           _playersShuffle.remove(playerToKick);
  5360. +           _players.remove(playerToKick);
  5361. +           playerToKick._inEventTvT = false;
  5362. +           playerToKick._teamNameTvT = "";
  5363. +           playerToKick._countTvTkills = 0;
  5364. +       }
  5365. +       if (_started || _teleport)
  5366. +       {
  5367. +           _playersShuffle.remove(playerToKick);
  5368. +           playerToKick._inEventTvT = false;
  5369. +           removePlayer(playerToKick);
  5370. +           if (playerToKick.isOnline())
  5371. +           {
  5372. +               playerToKick.getAppearance().setNameColor(playerToKick._originalNameColorTvT);
  5373. +               playerToKick.setKarma(playerToKick._originalKarmaTvT);
  5374. +               playerToKick.setTitle(playerToKick._originalTitleTvT);
  5375. +               playerToKick.broadcastUserInfo();
  5376. +               playerToKick.sendMessage("You have been kicked from the TvT.");
  5377. +               playerToKick.teleToLocation(_npcX, _npcY, _npcZ, 0);
  5378. +           }
  5379. +       }
  5380. +   }
  5381. +
  5382. +   public static void setNpcPos(Player activeChar)
  5383. +   {
  5384. +       _npcX = activeChar.getX();
  5385. +       _npcY = activeChar.getY();
  5386. +       _npcZ = activeChar.getZ();
  5387. +       _npcHeading = activeChar.getHeading();
  5388. +   }
  5389. +
  5390. +   public static void setNpcPos(int x, int y, int z)
  5391. +   {
  5392. +       _npcX = x;
  5393. +       _npcY = y;
  5394. +       _npcZ = z;
  5395. +   }
  5396. +
  5397. +   public static void addTeam(String teamName)
  5398. +   {
  5399. +       if (!checkTeamOk())
  5400. +       {
  5401. +           if (Config.DEBUG)
  5402. +               _log.log(Level.FINER, "TvT Engine[addTeam(" + teamName + ")]: checkTeamOk() = false");
  5403. +           return;
  5404. +       }
  5405. +
  5406. +       if (teamName.equals(" "))
  5407. +           return;
  5408. +
  5409. +       _teams.add(teamName);
  5410. +       _teamPlayersCount.add(0);
  5411. +       _teamKillsCount.add(0);
  5412. +       _teamColors.add(0);
  5413. +       _teamsX.add(0);
  5414. +       _teamsY.add(0);
  5415. +       _teamsZ.add(0);
  5416. +   }
  5417. +
  5418. +   public static boolean checkMaxLevel(int maxlvl)
  5419. +   {
  5420. +       return _minlvl < maxlvl;
  5421. +   }
  5422. +
  5423. +   public static boolean checkMinLevel(int minlvl)
  5424. +   {
  5425. +       return _maxlvl > minlvl;
  5426. +   }
  5427. +
  5428. +   /** returns true if participated players is higher or equal then minimum needed players
  5429. +    * @param players
  5430. +    * @return */
  5431. +   public static boolean checkMinPlayers(int players)
  5432. +   {
  5433. +       return _minPlayers <= players;
  5434. +   }
  5435. +
  5436. +   /** returns true if max players is higher or equal then participated players
  5437. +    * @param players
  5438. +    * @return */
  5439. +   public static boolean checkMaxPlayers(int players)
  5440. +   {
  5441. +       return _maxPlayers > players;
  5442. +   }
  5443. +
  5444. +   public static void removeTeam(String teamName)
  5445. +   {
  5446. +       if (!checkTeamOk() || _teams.isEmpty())
  5447. +       {
  5448. +           if (Config.DEBUG)
  5449. +               _log.log(Level.FINER, "TvT Engine[removeTeam(" + teamName + ")]: checkTeamOk() = false");
  5450. +           return;
  5451. +       }
  5452. +
  5453. +       if (teamPlayersCount(teamName) > 0)
  5454. +       {
  5455. +           if (Config.DEBUG)
  5456. +               _log.log(Level.FINER, "TvT Engine[removeTeam(" + teamName + ")]: teamPlayersCount(teamName) > 0");
  5457. +           return;
  5458. +       }
  5459. +
  5460. +       int index = _teams.indexOf(teamName);
  5461. +
  5462. +       if (index == -1)
  5463. +           return;
  5464. +
  5465. +       _teamsZ.remove(index);
  5466. +       _teamsY.remove(index);
  5467. +       _teamsX.remove(index);
  5468. +       _teamColors.remove(index);
  5469. +       _teamKillsCount.remove(index);
  5470. +       _teamPlayersCount.remove(index);
  5471. +       _teams.remove(index);
  5472. +   }
  5473. +
  5474. +   public static void setTeamPos(String teamName, Player activeChar)
  5475. +   {
  5476. +       int index = _teams.indexOf(teamName);
  5477. +
  5478. +       if (index == -1)
  5479. +           return;
  5480. +
  5481. +       _teamsX.set(index, activeChar.getX());
  5482. +       _teamsY.set(index, activeChar.getY());
  5483. +       _teamsZ.set(index, activeChar.getZ());
  5484. +   }
  5485. +
  5486. +   public static void setTeamPos(String teamName, int x, int y, int z)
  5487. +   {
  5488. +       int index = _teams.indexOf(teamName);
  5489. +
  5490. +       if (index == -1)
  5491. +           return;
  5492. +
  5493. +       _teamsX.set(index, x);
  5494. +       _teamsY.set(index, y);
  5495. +       _teamsZ.set(index, z);
  5496. +   }
  5497. +
  5498. +   public static void setTeamColor(String teamName, int color)
  5499. +   {
  5500. +       if (!checkTeamOk())
  5501. +           return;
  5502. +
  5503. +       int index = _teams.indexOf(teamName);
  5504. +
  5505. +       if (index == -1)
  5506. +           return;
  5507. +
  5508. +       _teamColors.set(index, color);
  5509. +   }
  5510. +
  5511. +   public static boolean checkTeamOk()
  5512. +   {
  5513. +       return !(_started || _teleport || _joining);
  5514. +   }
  5515. +
  5516. +   public static void startJoin(Player activeChar)
  5517. +   {
  5518. +       if (!startJoinOk())
  5519. +       {
  5520. +           activeChar.sendMessage("Event not setted propertly.");
  5521. +           if (Config.DEBUG)
  5522. +               _log.log(Level.FINER, "TvT Engine[startJoin(" + activeChar.getName() + ")]: startJoinOk() = false");
  5523. +           return;
  5524. +       }
  5525. +       _joining = true;
  5526. +       spawnEventNpc(activeChar);
  5527. +       AnnounceToPlayers(true, _eventName);
  5528. +       if (Config.TVT_ANNOUNCE_REWARD)
  5529. +           AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).getName());
  5530. +       AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
  5531. +       AnnounceToPlayers(true, "Join in " + _joiningLocationName + "!");
  5532. +   }
  5533. +
  5534. +   public static void startJoin()
  5535. +   {
  5536. +       if (!startJoinOk())
  5537. +       {
  5538. +           _log.warning(TvT.class.getSimpleName() + ":  Event not setted propertly.");
  5539. +           if (Config.DEBUG)
  5540. +               _log.log(Level.FINER, "TvT Engine[startJoin(startJoinOk() = false");
  5541. +           return;
  5542. +       }
  5543. +       _joining = true;
  5544. +       spawnEventNpc();
  5545. +       AnnounceToPlayers(true, _eventName);
  5546. +       if (Config.TVT_ANNOUNCE_REWARD)
  5547. +           AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).getName());
  5548. +       AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
  5549. +       AnnounceToPlayers(true, "Join in " + _joiningLocationName + "!");
  5550. +   }
  5551. +
  5552. +   public static boolean startAutoJoin()
  5553. +   {
  5554. +       if (!startJoinOk())
  5555. +       {
  5556. +           if (Config.DEBUG)
  5557. +               _log.log(Level.FINER, "TvT Engine[startJoin]: startJoinOk() = false");
  5558. +           return false;
  5559. +       }
  5560. +
  5561. +       _joining = true;
  5562. +       spawnEventNpc();
  5563. +       AnnounceToPlayers(true, _eventName);
  5564. +       if (Config.TVT_ANNOUNCE_REWARD)
  5565. +           AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).getName());
  5566. +       AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
  5567. +       AnnounceToPlayers(true, "Join in " + _joiningLocationName + "!");
  5568. +       return true;
  5569. +   }
  5570. +
  5571. +   public static boolean startJoinOk()
  5572. +   {
  5573. +       return !(_started || _teleport || _joining || _teams.size() < 2 || _eventName.isEmpty() || _joiningLocationName.isEmpty() || _eventDesc.isEmpty() || _npcId == 0 || _npcX == 0 || _npcY == 0 || _npcZ == 0 || _rewardId == 0 || _rewardAmount == 0 || _teamsX.contains(0) || _teamsY.contains(0) || _teamsZ.contains(0));
  5574. +   }
  5575. +
  5576. +   private static void spawnEventNpc(Player activeChar)
  5577. +   {
  5578. +       NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
  5579. +
  5580. +       try
  5581. +       {
  5582. +           _npcSpawn = new L2Spawn(tmpl);
  5583. +
  5584. +           _npcSpawn.setLoc(_npcX, _npcY, _npcZ, _npcHeading);
  5585. +           _npcSpawn.setRespawnDelay(1);
  5586. +
  5587. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  5588. +
  5589. +           _npcSpawn.setRespawnState(true);
  5590. +           _npcSpawn.doSpawn(false);
  5591. +           _npcSpawn.getNpc().getStatus().setCurrentHp(999999999);
  5592. +           _npcSpawn.getNpc().setTitle(_eventName);
  5593. +           _npcSpawn.getNpc()._isEventMobTvT = true;
  5594. +           _npcSpawn.getNpc().isAggressive();
  5595. +           _npcSpawn.getNpc().decayMe();
  5596. +           _npcSpawn.getNpc().spawnMe(_npcSpawn.getNpc().getX(), _npcSpawn.getNpc().getY(), _npcSpawn.getNpc().getZ());
  5597. +
  5598. +           _npcSpawn.getNpc().broadcastPacket(new MagicSkillUse(_npcSpawn.getNpc(), _npcSpawn.getNpc(), 1034, 1, 1, 1));
  5599. +       }
  5600. +       catch (Exception e)
  5601. +       {
  5602. +           _log.warning(TvT.class.getSimpleName() + ":  TvT Engine[spawnEventNpc(" + activeChar.getName() + ")]: exception: ");
  5603. +           if (Config.DEVELOPER)
  5604. +               e.printStackTrace();
  5605. +       }
  5606. +   }
  5607. +
  5608. +   private static void spawnEventNpc()
  5609. +   {
  5610. +       NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
  5611. +
  5612. +       try
  5613. +       {
  5614. +           _npcSpawn = new L2Spawn(tmpl);
  5615. +           _npcSpawn.setLoc(_npcX, _npcY, _npcZ, _npcHeading);
  5616. +           _npcSpawn.setRespawnDelay(1);
  5617. +
  5618. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  5619. +
  5620. +           _npcSpawn.setRespawnState(true);
  5621. +           _npcSpawn.doSpawn(false);
  5622. +           _npcSpawn.getNpc().getStatus().setCurrentHp(999999999);
  5623. +           _npcSpawn.getNpc().setTitle(_eventName);
  5624. +           _npcSpawn.getNpc()._isEventMobTvT = true;
  5625. +           _npcSpawn.getNpc().isAggressive();
  5626. +           _npcSpawn.getNpc().decayMe();
  5627. +           _npcSpawn.getNpc().spawnMe(_npcSpawn.getNpc().getX(), _npcSpawn.getNpc().getY(), _npcSpawn.getNpc().getZ());
  5628. +
  5629. +           _npcSpawn.getNpc().broadcastPacket(new MagicSkillUse(_npcSpawn.getNpc(), _npcSpawn.getNpc(), 1034, 1, 1, 1));
  5630. +       }
  5631. +       catch (Exception e)
  5632. +       {
  5633. +           _log.warning(TvT.class.getSimpleName() + ":  TvT Engine[spawnEventNpc(exception: ");
  5634. +           if (Config.DEVELOPER)
  5635. +               e.printStackTrace();
  5636. +       }
  5637. +   }
  5638. +
  5639. +   public static void teleportStart()
  5640. +   {
  5641. +       if (!_joining || _started || _teleport)
  5642. +           return;
  5643. +
  5644. +       if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && checkMinPlayers(_playersShuffle.size()))
  5645. +       {
  5646. +           removeOfflinePlayers();
  5647. +           shuffleTeams();
  5648. +       }
  5649. +       else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && !checkMinPlayers(_playersShuffle.size()))
  5650. +       {
  5651. +           AnnounceToPlayers(true, "Not enough players for event. Min Requested : " + _minPlayers + ", Participating : " + _playersShuffle.size());
  5652. +           return;
  5653. +       }
  5654. +
  5655. +       _joining = false;
  5656. +       AnnounceToPlayers(false, _eventName + "Teleport to team spot in 20 seconds!");
  5657. +
  5658. +       setUserData();
  5659. +       ThreadPool.schedule(new Runnable()
  5660. +       {
  5661. +           @Override
  5662. +           public void run()
  5663. +           {
  5664. +               TvT.sit();
  5665. +
  5666. +               for (Player player : _players)
  5667. +               {
  5668. +                   if (player != null)
  5669. +                   {
  5670. +                       if (Config.TVT_ON_START_UNSUMMON_PET)
  5671. +                       {
  5672. +                           // Remove Summon's buffs
  5673. +                           if (player.getPet() != null)
  5674. +                           {
  5675. +                               Summon summon = player.getPet();
  5676. +                               for (L2Effect e : summon.getAllEffects())
  5677. +                               {
  5678. +                                   if (e != null)
  5679. +                                       e.exit();
  5680. +                               }
  5681. +
  5682. +                               if (summon instanceof Pet)
  5683. +                                   summon.unSummon(player);
  5684. +                           }
  5685. +                       }
  5686. +
  5687. +                       if (Config.TVT_ON_START_REMOVE_ALL_EFFECTS)
  5688. +                       {
  5689. +                           for (L2Effect e : player.getAllEffects())
  5690. +                           {
  5691. +                               if (e != null)
  5692. +                                   e.exit();
  5693. +                           }
  5694. +                       }
  5695. +
  5696. +                       // Remove player from his party
  5697. +                       if (player.getParty() != null)
  5698. +                       {
  5699. +                           Party party = player.getParty();
  5700. +                           party.removePartyMember(player, MessageType.EXPELLED);
  5701. +                       }
  5702. +
  5703. +                       player.setTitle("Kills: " + player._countTvTkills);
  5704. +                       player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameTvT)), _teamsY.get(_teams.indexOf(player._teamNameTvT)), _teamsZ.get(_teams.indexOf(player._teamNameTvT)), 0);
  5705. +                   }
  5706. +               }
  5707. +           }
  5708. +       }, 20000);
  5709. +       _teleport = true;
  5710. +   }
  5711. +
  5712. +   public static boolean teleportAutoStart()
  5713. +   {
  5714. +       if (!_joining || _started || _teleport)
  5715. +           return false;
  5716. +
  5717. +       if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && checkMinPlayers(_playersShuffle.size()))
  5718. +       {
  5719. +           removeOfflinePlayers();
  5720. +           shuffleTeams();
  5721. +       }
  5722. +       else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && !checkMinPlayers(_playersShuffle.size()))
  5723. +       {
  5724. +           AnnounceToPlayers(true, "Not enough players for event. Min Requested : " + _minPlayers + ", Participating : " + _playersShuffle.size());
  5725. +           return false;
  5726. +       }
  5727. +
  5728. +       _joining = false;
  5729. +       AnnounceToPlayers(false, _eventName + "Teleport to team spot in 20 seconds!");
  5730. +
  5731. +       setUserData();
  5732. +       ThreadPool.schedule(new Runnable()
  5733. +       {
  5734. +           @Override
  5735. +           public void run()
  5736. +           {
  5737. +               TvT.sit();
  5738. +
  5739. +               for (Player player : _players)
  5740. +               {
  5741. +                   if (player != null)
  5742. +                   {
  5743. +                       if (Config.TVT_ON_START_UNSUMMON_PET)
  5744. +                       {
  5745. +                           // Remove Summon's buffs
  5746. +                           if (player.getPet() != null)
  5747. +                           {
  5748. +                               Summon summon = player.getPet();
  5749. +                               for (L2Effect e : summon.getAllEffects())
  5750. +                               {
  5751. +                                   if (e != null)
  5752. +                                       e.exit();
  5753. +                               }
  5754. +
  5755. +                               if (summon instanceof Pet)
  5756. +                                   summon.unSummon(player);
  5757. +                           }
  5758. +                       }
  5759. +
  5760. +                       if (Config.TVT_ON_START_REMOVE_ALL_EFFECTS)
  5761. +                       {
  5762. +                           for (L2Effect e : player.getAllEffects())
  5763. +                           {
  5764. +                               if (e != null)
  5765. +                                   e.exit();
  5766. +                           }
  5767. +                       }
  5768. +
  5769. +                       // Remove player from his party
  5770. +                       if (player.getParty() != null)
  5771. +                       {
  5772. +                           Party party = player.getParty();
  5773. +                           party.removePartyMember(player, MessageType.EXPELLED);
  5774. +                       }
  5775. +                       player.setTitle("Kills: " + player._countTvTkills);
  5776. +                       player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameTvT)), _teamsY.get(_teams.indexOf(player._teamNameTvT)), _teamsZ.get(_teams.indexOf(player._teamNameTvT)), 0);
  5777. +                   }
  5778. +               }
  5779. +           }
  5780. +       }, 20000);
  5781. +       _teleport = true;
  5782. +       return true;
  5783. +   }
  5784. +
  5785. +   public static void startEvent(Player activeChar)
  5786. +   {
  5787. +       if (_inProgress)
  5788. +       {
  5789. +           activeChar.sendMessage("A TvT event is already in progress, try abort.");
  5790. +           return;
  5791. +       }
  5792. +
  5793. +       if (!startEventOk())
  5794. +       {
  5795. +           if (Config.DEBUG)
  5796. +               _log.log(Level.FINER, "TvT Engine[startEvent(" + activeChar.getName() + ")]: startEventOk() = false");
  5797. +           return;
  5798. +       }
  5799. +
  5800. +       _teleport = false;
  5801. +       sit();
  5802. +
  5803. +       if (Config.TVT_CLOSE_COLISEUM_DOORS)
  5804. +           closeColiseumDoors();
  5805. +
  5806. +       AnnounceToPlayers(false, _eventName + "Started. Go to kill your enemies!");
  5807. +       _started = true;
  5808. +       _inProgress = true;
  5809. +   }
  5810. +
  5811. +   public static void setJoinTime(int time)
  5812. +   {
  5813. +       _joinTime = time;
  5814. +   }
  5815. +
  5816. +   public static void setEventTime(int time)
  5817. +   {
  5818. +       _eventTime = time;
  5819. +   }
  5820. +
  5821. +   public static boolean startAutoEvent()
  5822. +   {
  5823. +       if (!startEventOk())
  5824. +       {
  5825. +           if (Config.DEBUG)
  5826. +               _log.log(Level.FINER, "TvT Engine[startEvent]: startEventOk() = false");
  5827. +           return false;
  5828. +       }
  5829. +
  5830. +       _teleport = false;
  5831. +       sit();
  5832. +
  5833. +       if (Config.TVT_CLOSE_COLISEUM_DOORS)
  5834. +           closeColiseumDoors();
  5835. +
  5836. +       AnnounceToPlayers(false, _eventName + "Started. Go to kill your enemies!");
  5837. +       _started = true;
  5838. +       return true;
  5839. +   }
  5840. +
  5841. +   public static synchronized void autoEvent()
  5842. +   {
  5843. +       _log.info("Starting TvT!");
  5844. +       if (startAutoJoin())
  5845. +       {
  5846. +           _eventType = 2;
  5847. +
  5848. +           if (_joinTime > 0)
  5849. +               waiter(_joinTime * 60 * 1000); // minutes for join event
  5850. +           else if (_joinTime <= 0)
  5851. +           {
  5852. +               _log.info("TvT: join time <=0 aborting event.");
  5853. +               abortEvent();
  5854. +               return;
  5855. +           }
  5856. +           if (teleportAutoStart())
  5857. +           {
  5858. +               waiter(30 * 1000); // 30 sec wait time untill start fight after teleported
  5859. +               if (startAutoEvent())
  5860. +               {
  5861. +                   _log.log(Level.FINER, "TvT: waiting.....minutes for event time " + TvT._eventTime);
  5862. +
  5863. +                   waiter(_eventTime * 60 * 1000); // minutes for event time
  5864. +                   finishEvent();
  5865. +
  5866. +                   _log.info("TvT: waiting... delay for final messages ");
  5867. +                   waiter(60000);// just a give a delay delay for final messages
  5868. +                   sendFinalMessages();
  5869. +               }
  5870. +           }
  5871. +           else if (!teleportAutoStart())
  5872. +           {
  5873. +               abortEvent();
  5874. +           }
  5875. +       }
  5876. +   }
  5877. +
  5878. +   private synchronized static void waiter(long interval)
  5879. +   {
  5880. +       long startWaiterTime = System.currentTimeMillis();
  5881. +       int seconds = (int) (interval / 1000);
  5882. +
  5883. +       String npcManager = NpcTable.getInstance().getTemplate(_npcId).getName();
  5884. +
  5885. +       while (startWaiterTime + interval > System.currentTimeMillis())
  5886. +       {
  5887. +           seconds--; // here because we don't want to see two time announce at the same time
  5888. +
  5889. +           if (_joining || _started || _teleport)
  5890. +           {
  5891. +               switch (seconds)
  5892. +               {
  5893. +                   case 3600: // 1 hour left
  5894. +                       if (_joining)
  5895. +                       {
  5896. +                           AnnounceToPlayers(true, "TvT: Joinable in " + _joiningLocationName + "!");
  5897. +                           AnnounceToPlayers(true, "TvT: " + seconds / 60 / 60 + " hour(s) till registration ends!");
  5898. +                           if (Config.TVT_ANNOUNCE_REGISTRATION_LOC_NPC)
  5899. +                               AnnounceToPlayers(true, "TvT: Registration Period is Active in " + _joiningLocationName + " ! at Npc " + npcManager);
  5900. +                       }
  5901. +                       else if (_started)
  5902. +                           AnnounceToPlayers(false, "TvT: " + seconds / 60 / 60 + " hour(s) till event ends!");
  5903. +
  5904. +                   break;
  5905. +                   case 1800: // 30 minutes left
  5906. +                   case 900: // 15 minutes left
  5907. +                   case 600: // 10 minutes left
  5908. +                   case 300: // 5 minutes left
  5909. +                   case 60: // 1 minute left
  5910. +                       if (_joining)
  5911. +                       {
  5912. +                           removeOfflinePlayers();
  5913. +                           AnnounceToPlayers(true, "TvT: Joinable in " + _joiningLocationName + "!");
  5914. +                           AnnounceToPlayers(true, "TvT: " + seconds / 60 + " minute(s) till registration ends!");
  5915. +                           if (Config.TVT_ANNOUNCE_REGISTRATION_LOC_NPC)
  5916. +                               Broadcast.announceToOnlinePlayers("TvT: Registration Period is Active in " + _joiningLocationName + " ! at Npc " + npcManager);
  5917. +                       }
  5918. +                       else if (_started)
  5919. +                           AnnounceToPlayers(false, "TvT: " + seconds / 60 + " minute(s) till event ends!");
  5920. +
  5921. +                   break;
  5922. +                   case 30: // 30 seconds left
  5923. +                   case 10: // 10 seconds left
  5924. +                   case 3: // 3 seconds left
  5925. +                   case 2: // 2 seconds left
  5926. +                   case 1: // 1 seconds left
  5927. +                       if (_joining)
  5928. +                           AnnounceToPlayers(true, "TvT: " + seconds + " second(s) till registration ends!");
  5929. +                       else if (_teleport)
  5930. +                           AnnounceToPlayers(false, "TvT: " + seconds + " seconds(s) till fight starts!");
  5931. +                       else if (_started)
  5932. +                           AnnounceToPlayers(false, "TvT: " + seconds + " second(s) till event ends!");
  5933. +
  5934. +                   break;
  5935. +               }
  5936. +           }
  5937. +
  5938. +           long startOneSecondWaiterStartTime = System.currentTimeMillis();
  5939. +
  5940. +           // only the try catch with Thread.sleep(1000) give bad countdown on high wait times
  5941. +           while (startOneSecondWaiterStartTime + 1000 > System.currentTimeMillis())
  5942. +           {
  5943. +               try
  5944. +               {
  5945. +                   Thread.sleep(1);
  5946. +               }
  5947. +               catch (InterruptedException ie)
  5948. +               {
  5949. +
  5950. +               }
  5951. +           }
  5952. +       }
  5953. +   }
  5954. +
  5955. +   private static boolean startEventOk()
  5956. +   {
  5957. +       if (_joining || !_teleport || _started)
  5958. +           return false;
  5959. +
  5960. +       if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE"))
  5961. +       {
  5962. +           if (_teamPlayersCount.contains(0))
  5963. +               return false;
  5964. +       }
  5965. +       else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  5966. +       {
  5967. +           List<Player> playersShuffleTemp = new ArrayList<>();
  5968. +           int loopCount = 0;
  5969. +
  5970. +           loopCount = _playersShuffle.size();
  5971. +
  5972. +           for (int i = 0; i < loopCount; i++)
  5973. +           {
  5974. +               if (_playersShuffle != null)
  5975. +                   playersShuffleTemp.add(_playersShuffle.get(i));
  5976. +           }
  5977. +
  5978. +           _playersShuffle = playersShuffleTemp;
  5979. +           playersShuffleTemp.clear();
  5980. +       }
  5981. +
  5982. +       return true;
  5983. +   }
  5984. +
  5985. +   public static void shuffleTeams()
  5986. +   {
  5987. +       int teamCount = 0, playersCount = 0;
  5988. +
  5989. +       for (;;)
  5990. +       {
  5991. +           if (_playersShuffle.isEmpty())
  5992. +               break;
  5993. +
  5994. +           int playerToAddIndex = Rnd.nextInt(_playersShuffle.size());
  5995. +           Player player = null;
  5996. +           player = _playersShuffle.get(playerToAddIndex);
  5997. +           player._originalNameColorTvT = player.getAppearance().getNameColor();
  5998. +           player._originalTitleTvT = player.getTitle();
  5999. +           player._originalKarmaTvT = player.getKarma();
  6000. +
  6001. +           _players.add(player);
  6002. +           _players.get(playersCount)._teamNameTvT = _teams.get(teamCount);
  6003. +           _savePlayers.add(_players.get(playersCount).getName());
  6004. +           _savePlayerTeams.add(_teams.get(teamCount));
  6005. +           playersCount++;
  6006. +
  6007. +           if (teamCount == _teams.size() - 1)
  6008. +               teamCount = 0;
  6009. +           else
  6010. +               teamCount++;
  6011. +
  6012. +           _playersShuffle.remove(playerToAddIndex);
  6013. +       }
  6014. +   }
  6015. +
  6016. +   public static void setUserData()
  6017. +   {
  6018. +       for (Player player : _players)
  6019. +       {
  6020. +           player.getAppearance().setNameColor(_teamColors.get(_teams.indexOf(player._teamNameTvT)));
  6021. +           player.setKarma(0);
  6022. +
  6023. +           if (Config.TVT_AURA)
  6024. +           {
  6025. +               if (_teams.size() >= 2)
  6026. +                   player.setTeam(_teams.indexOf(player._teamNameTvT) + 1);
  6027. +           }
  6028. +           player.broadcastUserInfo();
  6029. +       }
  6030. +   }
  6031. +
  6032. +   public static void finishEvent()
  6033. +   {
  6034. +       if (!finishEventOk())
  6035. +       {
  6036. +           if (Config.DEBUG)
  6037. +               _log.log(Level.FINER, "TvT Engine[finishEvent]: finishEventOk() = false");
  6038. +           return;
  6039. +       }
  6040. +
  6041. +       _started = false;
  6042. +       unspawnEventNpc();
  6043. +       processTopTeam();
  6044. +
  6045. +       if (_topKills == 0)
  6046. +           AnnounceToPlayers(true, _eventName + "No team wins the match(nobody killed).");
  6047. +       else
  6048. +       {
  6049. +           AnnounceToPlayers(true, _eventName + " " + _topTeam + "'s win the match! " + _topKills + " kills.");
  6050. +           rewardTeam(_topTeam);
  6051. +           playKneelAnimation(_topTeam);
  6052. +       }
  6053. +
  6054. +       if (Config.TVT_ANNOUNCE_TEAM_STATS)
  6055. +       {
  6056. +           AnnounceToPlayers(true, _eventName + " Team Statistics:");
  6057. +           for (String team : _teams)
  6058. +           {
  6059. +               int _kills = teamKillsCount(team);
  6060. +               AnnounceToPlayers(true, "Team: " + team + " - Kills: " + _kills);
  6061. +           }
  6062. +       }
  6063. +
  6064. +       teleportFinish();
  6065. +   }
  6066. +
  6067. +   // show losers and winners animations
  6068. +   public static void playKneelAnimation(String teamName)
  6069. +   {
  6070. +       for (Player player : _players)
  6071. +       {
  6072. +           if (player != null)
  6073. +           {
  6074. +               if (!player._teamNameTvT.equals(teamName))
  6075. +                   player.broadcastPacket(new SocialAction(player, 7),2000);
  6076. +               else if (player._teamNameTvT.equals(teamName))
  6077. +                   player.broadcastPacket(new SocialAction(player, 3),2000);
  6078. +           }
  6079. +       }
  6080. +   }
  6081. +
  6082. +   private static boolean finishEventOk()
  6083. +   {
  6084. +       if (!_started)
  6085. +           return false;
  6086. +
  6087. +       _inProgress = false;
  6088. +       if (Config.TVT_CLOSE_COLISEUM_DOORS)
  6089. +           openColiseumDoors();
  6090. +
  6091. +       return true;
  6092. +   }
  6093. +
  6094. +   public static void processTopTeam()
  6095. +   {
  6096. +       for (String team : _teams)
  6097. +       {
  6098. +           if (teamKillsCount(team) > _topKills)
  6099. +           {
  6100. +               _topTeam = team;
  6101. +               _topKills = teamKillsCount(team);
  6102. +           }
  6103. +       }
  6104. +   }
  6105. +
  6106. +   public static void rewardTeam(String teamName)
  6107. +   {
  6108. +       for (Player player : _players)
  6109. +       {
  6110. +           if (player != null && player.isOnline() && player._inEventTvT)
  6111. +           {
  6112. +               if (player._teamNameTvT.equals(teamName) && (player._countTvTkills > 0 || Config.TVT_PRICE_NO_KILLS))
  6113. +               {
  6114. +                   player.addItem("TvT: " + _eventName, _rewardId, _rewardAmount, player, true);
  6115. +
  6116. +                   _playerWon = 1;
  6117. +
  6118. +                   NpcHtmlMessage nhm = new NpcHtmlMessage(5);
  6119. +                   StringBuilder replyMSG = new StringBuilder("");
  6120. +
  6121. +                   replyMSG.append("<html><body>Your team wins the event. Look in your inventory for the reward.</body></html>");
  6122. +
  6123. +                   nhm.setHtml(replyMSG.toString());
  6124. +                   player.sendPacket(nhm);
  6125. +
  6126. +                   // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  6127. +                   player.sendPacket(ActionFailed.STATIC_PACKET);
  6128. +               }
  6129. +           }
  6130. +       }
  6131. +   }
  6132. +
  6133. +   public static void abortEvent()
  6134. +   {
  6135. +       if (!_joining && !_teleport && !_started)
  6136. +           return;
  6137. +       if (_joining && !_teleport && !_started)
  6138. +       {
  6139. +           unspawnEventNpc();
  6140. +           cleanTvT();
  6141. +           _joining = false;
  6142. +           AnnounceToPlayers(true, _eventName + "Match aborted!");
  6143. +           return;
  6144. +       }
  6145. +       _joining = false;
  6146. +       _teleport = false;
  6147. +       _started = false;
  6148. +       _inProgress = false;
  6149. +       unspawnEventNpc();
  6150. +       AnnounceToPlayers(true, _eventName + "Match aborted!");
  6151. +       teleportFinish();
  6152. +   }
  6153. +
  6154. +   public static void sit()
  6155. +   {
  6156. +       _sitForced = !_sitForced;
  6157. +
  6158. +       for (Player player : _players)
  6159. +       {
  6160. +           if (player != null)
  6161. +           {
  6162. +               if (_sitForced)
  6163. +               {
  6164. +                   player.stopMove(null);
  6165. +                   player.abortAttack();
  6166. +                   player.abortCast();
  6167. +
  6168. +                   if (!player.isSitting())
  6169. +                       player.sitDown();
  6170. +               }
  6171. +               else
  6172. +               {
  6173. +                   if (player.isSitting())
  6174. +                       player.standUp();
  6175. +               }
  6176. +           }
  6177. +       }
  6178. +   }
  6179. +
  6180. +   public static void dumpData()
  6181. +   {
  6182. +       _log.info("");
  6183. +       _log.info("");
  6184. +
  6185. +       if (!_joining && !_teleport && !_started)
  6186. +       {
  6187. +           _log.info("<<---------------------------------->>");
  6188. +           _log.info(">> TvT Engine infos dump (INACTIVE) <<");
  6189. +           _log.info("<<--^----^^-----^----^^------^^----->>");
  6190. +       }
  6191. +       else if (_joining && !_teleport && !_started)
  6192. +       {
  6193. +           _log.info("<<--------------------------------->>");
  6194. +           _log.info(">> TvT Engine infos dump (JOINING) <<");
  6195. +           _log.info("<<--^----^^-----^----^^------^----->>");
  6196. +       }
  6197. +       else if (!_joining && _teleport && !_started)
  6198. +       {
  6199. +           _log.info("<<---------------------------------->>");
  6200. +           _log.info(">> TvT Engine infos dump (TELEPORT) <<");
  6201. +           _log.info("<<--^----^^-----^----^^------^^----->>");
  6202. +       }
  6203. +       else if (!_joining && !_teleport && _started)
  6204. +       {
  6205. +           _log.info("<<--------------------------------->>");
  6206. +           _log.info(">> TvT Engine infos dump (STARTED) <<");
  6207. +           _log.info("<<--^----^^-----^----^^------^----->>");
  6208. +       }
  6209. +
  6210. +       _log.info("Name: " + _eventName);
  6211. +       _log.info("Desc: " + _eventDesc);
  6212. +       _log.info("Join location: " + _joiningLocationName);
  6213. +       _log.info("Min lvl: " + _minlvl);
  6214. +       _log.info("Max lvl: " + _maxlvl);
  6215. +       _log.info("");
  6216. +       _log.info("##########################");
  6217. +       _log.info("# _teams(Vector<String>) #");
  6218. +       _log.info("##########################");
  6219. +
  6220. +       for (String team : _teams)
  6221. +           _log.info(team + " Kills Done :" + _teamKillsCount.get(_teams.indexOf(team)));
  6222. +
  6223. +       if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  6224. +       {
  6225. +           _log.info("");
  6226. +           _log.info("#########################################");
  6227. +           _log.info("# _playersShuffle(Vector<Player>) #");
  6228. +           _log.info("#########################################");
  6229. +
  6230. +           for (Player player : _playersShuffle)
  6231. +           {
  6232. +               if (player != null)
  6233. +                   _log.info("Name: " + player.getName());
  6234. +           }
  6235. +       }
  6236. +
  6237. +       _log.info("");
  6238. +       _log.info("##################################");
  6239. +       _log.info("# _players(Vector<Player>) #");
  6240. +       _log.info("##################################");
  6241. +
  6242. +       for (Player player : _players)
  6243. +       {
  6244. +           if (player != null)
  6245. +               _log.info("Name: " + player.getName() + "   Team: " + player._teamNameTvT + "  Kills Done:" + player._countTvTkills);
  6246. +       }
  6247. +
  6248. +       _log.info("");
  6249. +       _log.info("#####################################################################");
  6250. +       _log.info("# _savePlayers(Vector<String>) and _savePlayerTeams(Vector<String>) #");
  6251. +       _log.info("#####################################################################");
  6252. +
  6253. +       for (String player : _savePlayers)
  6254. +           _log.info("Name: " + player + " Team: " + _savePlayerTeams.get(_savePlayers.indexOf(player)));
  6255. +
  6256. +       _log.info("");
  6257. +       _log.info("");
  6258. +   }
  6259. +
  6260. +   public static void loadData()
  6261. +   {
  6262. +       _eventName = "";
  6263. +       _eventDesc = "";
  6264. +       _topTeam = "";
  6265. +       _joiningLocationName = "";
  6266. +       _teams = new ArrayList<>();
  6267. +       _savePlayers = new ArrayList<>();
  6268. +       _savePlayerTeams = new ArrayList<>();
  6269. +       _players = new ArrayList<>();
  6270. +       _playersShuffle = new ArrayList<>();
  6271. +       _teamPlayersCount = new ArrayList<>();
  6272. +       _teamKillsCount = new ArrayList<>();
  6273. +       _teamColors = new ArrayList<>();
  6274. +       _teamsX = new ArrayList<>();
  6275. +       _teamsY = new ArrayList<>();
  6276. +       _teamsZ = new ArrayList<>();
  6277. +       _joining = false;
  6278. +       _teleport = false;
  6279. +       _started = false;
  6280. +       _sitForced = false;
  6281. +       _npcId = 0;
  6282. +       _npcX = 0;
  6283. +       _npcY = 0;
  6284. +       _npcZ = 0;
  6285. +       _npcHeading = 0;
  6286. +       _rewardId = 0;
  6287. +       _rewardAmount = 0;
  6288. +       _topKills = 0;
  6289. +       _minlvl = 0;
  6290. +       _maxlvl = 0;
  6291. +       _joinTime = 0;
  6292. +       _eventTime = 0;
  6293. +       _minPlayers = 0;
  6294. +       _maxPlayers = 0;
  6295. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  6296. +       {
  6297. +           PreparedStatement statement;
  6298. +           ResultSet rs;
  6299. +           statement = con.prepareStatement("SELECT * FROM tvt");
  6300. +           rs = statement.executeQuery();
  6301. +
  6302. +           int teams = 0;
  6303. +
  6304. +           while (rs.next())
  6305. +           {
  6306. +               _eventName = rs.getString("eventName");
  6307. +               _eventDesc = rs.getString("eventDesc");
  6308. +               _joiningLocationName = rs.getString("joiningLocation");
  6309. +               _minlvl = rs.getInt("minlvl");
  6310. +               _maxlvl = rs.getInt("maxlvl");
  6311. +               _npcId = rs.getInt("npcId");
  6312. +               _npcX = rs.getInt("npcX");
  6313. +               _npcY = rs.getInt("npcY");
  6314. +               _npcZ = rs.getInt("npcZ");
  6315. +               _npcHeading = rs.getInt("npcHeading");
  6316. +               _rewardId = rs.getInt("rewardId");
  6317. +               _rewardAmount = rs.getInt("rewardAmount");
  6318. +               teams = rs.getInt("teamsCount");
  6319. +               _joinTime = rs.getInt("joinTime");
  6320. +               _eventTime = rs.getInt("eventTime");
  6321. +               _minPlayers = rs.getInt("minPlayers");
  6322. +               _maxPlayers = rs.getInt("maxPlayers");
  6323. +           }
  6324. +           rs.close();
  6325. +           statement.close();
  6326. +
  6327. +           int index = -1;
  6328. +           if (teams > 0)
  6329. +               index = 0;
  6330. +           while (index < teams && index > -1)
  6331. +           {
  6332. +               statement = con.prepareStatement("SELECT * FROM tvt_teams WHERE teamId=?");
  6333. +               statement.setInt(1, index);
  6334. +               rs = statement.executeQuery();
  6335. +               while (rs.next())
  6336. +               {
  6337. +                   _teams.add(rs.getString("teamName"));
  6338. +                   _teamPlayersCount.add(0);
  6339. +                   _teamKillsCount.add(0);
  6340. +                   _teamColors.add(0);
  6341. +                   _teamsX.add(0);
  6342. +                   _teamsY.add(0);
  6343. +                   _teamsZ.add(0);
  6344. +                   _teamsX.set(index, rs.getInt("teamX"));
  6345. +                   _teamsY.set(index, rs.getInt("teamY"));
  6346. +                   _teamsZ.set(index, rs.getInt("teamZ"));
  6347. +                   _teamColors.set(index, rs.getInt("teamColor"));
  6348. +               }
  6349. +               index++;
  6350. +               rs.close();
  6351. +               statement.close();
  6352. +           }
  6353. +       }
  6354. +       catch (Exception e)
  6355. +       {
  6356. +           _log.warning(TvT.class.getSimpleName() + ":  Exception: TvT.loadData(): ");
  6357. +           if (Config.DEVELOPER)
  6358. +               e.printStackTrace();
  6359. +       }
  6360. +   }
  6361. +
  6362. +   public static void saveData()
  6363. +   {
  6364. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  6365. +       {
  6366. +           PreparedStatement statement;
  6367. +
  6368. +           statement = con.prepareStatement("DELETE FROM tvt");
  6369. +           statement.execute();
  6370. +           statement.close();
  6371. +
  6372. +           statement = con.prepareStatement("INSERT INTO tvt (eventName, eventDesc, joiningLocation, minlvl, maxlvl, npcId, npcX, npcY, npcZ, npcHeading, rewardId, rewardAmount, teamsCount, joinTime, eventTime, minPlayers, maxPlayers) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  6373. +           statement.setString(1, _eventName);
  6374. +           statement.setString(2, _eventDesc);
  6375. +           statement.setString(3, _joiningLocationName);
  6376. +           statement.setInt(4, _minlvl);
  6377. +           statement.setInt(5, _maxlvl);
  6378. +           statement.setInt(6, _npcId);
  6379. +           statement.setInt(7, _npcX);
  6380. +           statement.setInt(8, _npcY);
  6381. +           statement.setInt(9, _npcZ);
  6382. +           statement.setInt(10, _npcHeading);
  6383. +           statement.setInt(11, _rewardId);
  6384. +           statement.setInt(12, _rewardAmount);
  6385. +           statement.setInt(13, _teams.size());
  6386. +           statement.setInt(14, _joinTime);
  6387. +           statement.setInt(15, _eventTime);
  6388. +           statement.setInt(16, _minPlayers);
  6389. +           statement.setInt(17, _maxPlayers);
  6390. +           statement.execute();
  6391. +           statement.close();
  6392. +
  6393. +           statement = con.prepareStatement("DELETE FROM tvt_teams");
  6394. +           statement.execute();
  6395. +           statement.close();
  6396. +
  6397. +           for (String teamName : _teams)
  6398. +           {
  6399. +               int index = _teams.indexOf(teamName);
  6400. +
  6401. +               if (index == -1)
  6402. +                   return;
  6403. +               statement = con.prepareStatement("INSERT INTO tvt_teams (teamId ,teamName, teamX, teamY, teamZ, teamColor) VALUES (?, ?, ?, ?, ?, ?)");
  6404. +               statement.setInt(1, index);
  6405. +               statement.setString(2, teamName);
  6406. +               statement.setInt(3, _teamsX.get(index));
  6407. +               statement.setInt(4, _teamsY.get(index));
  6408. +               statement.setInt(5, _teamsZ.get(index));
  6409. +               statement.setInt(6, _teamColors.get(index));
  6410. +               statement.execute();
  6411. +               statement.close();
  6412. +           }
  6413. +       }
  6414. +       catch (Exception e)
  6415. +       {
  6416. +           _log.warning(TvT.class.getSimpleName() + ":  Exception: TvT.saveData(): ");
  6417. +           if (Config.DEVELOPER)
  6418. +               e.printStackTrace();
  6419. +       }
  6420. +   }
  6421. +
  6422. +   public static void showEventHtml(Player eventPlayer, String objectId)
  6423. +   {
  6424. +       try
  6425. +       {
  6426. +           NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  6427. +
  6428. +           StringBuilder replyMSG = new StringBuilder("<html><body>");
  6429. +           replyMSG.append("TvT Match<br><br><br>");
  6430. +           replyMSG.append("Current event...<br1>");
  6431. +           replyMSG.append("    ... name:&nbsp;<font color=\"00FF00\">" + _eventName + "</font><br1>");
  6432. +           replyMSG.append("    ... description:&nbsp;<font color=\"00FF00\">" + _eventDesc + "</font><br>");
  6433. +           if (Config.TVT_ANNOUNCE_REWARD)
  6434. +               replyMSG.append("    ... reward: (" + _rewardAmount + ") " + ItemTable.getInstance().getTemplate(_rewardId).getName() + "<br>");
  6435. +
  6436. +           if (!_started && !_joining)
  6437. +               replyMSG.append("<center>Wait till the admin/gm start the participation.</center>");
  6438. +           else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && !checkMaxPlayers(_playersShuffle.size()))
  6439. +           {
  6440. +               if (!TvT._started)
  6441. +                   replyMSG.append("<font color=\"FFFF00\">The event has reached its maximum capacity.</font><br>Keep checking, someone may crit and you can steal their spot.");
  6442. +           }
  6443. +           else if (eventPlayer.isCursedWeaponEquipped() && !Config.TVT_JOIN_CURSED)
  6444. +               replyMSG.append("<font color=\"FFFF00\">You can't participate in this event with a cursed Weapon.</font><br>");
  6445. +           else if (!_started && _joining && eventPlayer.getLevel() >= _minlvl && eventPlayer.getLevel() <= _maxlvl)
  6446. +           {
  6447. +               if (_players.contains(eventPlayer) || checkShufflePlayers(eventPlayer))
  6448. +               {
  6449. +                   if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE"))
  6450. +                       replyMSG.append("You are already participating in team <font color=\"LEVEL\">" + eventPlayer._teamNameTvT + "</font><br><br>");
  6451. +                   else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  6452. +                       replyMSG.append("You are already participating!<br><br>");
  6453. +
  6454. +                   replyMSG.append("<table border=\"0\"><tr>");
  6455. +                   replyMSG.append("<td width=\"200\">Wait till event start or</td>");
  6456. +                   replyMSG.append("<td width=\"60\"><center><button value=\"remove\" action=\"bypass -h npc_" + objectId + "_tvt_player_leave\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></td>");
  6457. +                   replyMSG.append("<td width=\"100\">your participation!</td>");
  6458. +                   replyMSG.append("</tr></table>");
  6459. +               }
  6460. +               else
  6461. +               {
  6462. +                   replyMSG.append("You want to participate in the event?<br><br>");
  6463. +                   replyMSG.append("<td width=\"200\">Your level : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font></td><br>");
  6464. +                   replyMSG.append("<td width=\"200\">Min level : <font color=\"00FF00\">" + _minlvl + "</font></td><br>");
  6465. +                   replyMSG.append("<td width=\"200\">Max level : <font color=\"00FF00\">" + _maxlvl + "</font></td><br><br>");
  6466. +
  6467. +                   if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE"))
  6468. +                   {
  6469. +                       replyMSG.append("<center><table border=\"0\">");
  6470. +
  6471. +                       for (String team : _teams)
  6472. +                       {
  6473. +                           replyMSG.append("<tr><td width=\"100\"><font color=\"LEVEL\">" + team + "</font>&nbsp;(" + teamPlayersCount(team) + " joined)</td>");
  6474. +                           replyMSG.append("<td width=\"60\"><button value=\"Join\" action=\"bypass -h npc_" + objectId + "_tvt_player_join " + team + "\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  6475. +                       }
  6476. +
  6477. +                       replyMSG.append("</table></center>");
  6478. +                   }
  6479. +                   else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  6480. +                   {
  6481. +                       replyMSG.append("<center><table border=\"0\">");
  6482. +
  6483. +                       for (String team : _teams)
  6484. +                           replyMSG.append("<tr><td width=\"100\"><font color=\"LEVEL\">" + team + "</font></td>");
  6485. +
  6486. +                       replyMSG.append("</table></center><br>");
  6487. +
  6488. +                       replyMSG.append("<button value=\"Join\" action=\"bypass -h npc_" + objectId + "_tvt_player_join eventShuffle\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  6489. +                       replyMSG.append("Teams will be randomly generated!");
  6490. +                   }
  6491. +               }
  6492. +           }
  6493. +           else if (_started && !_joining)
  6494. +               replyMSG.append("<center>TvT match is in progress.</center>");
  6495. +           else if (eventPlayer.getLevel() < _minlvl || eventPlayer.getLevel() >= _maxlvl)
  6496. +           {
  6497. +               replyMSG.append("Your level : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font><br>");
  6498. +               replyMSG.append("Min level : <font color=\"00FF00\">" + _minlvl + "</font><br>");
  6499. +               replyMSG.append("Max level : <font color=\"00FF00\">" + _maxlvl + "</font><br><br>");
  6500. +               replyMSG.append("<font color=\"FFFF00\">You can't participate in this event.</font><br>");
  6501. +           }
  6502. +           // Show how many players joined & how many are still needed to join
  6503. +           replyMSG.append("<br>There are " + _playersShuffle.size() + " player(s) participating in this event.<br>");
  6504. +           if (_joining)
  6505. +           {
  6506. +               if (_playersShuffle.size() < _minPlayers)
  6507. +               {
  6508. +                   int playersNeeded = _minPlayers - _playersShuffle.size();
  6509. +                   replyMSG.append("The event will not start unless " + playersNeeded + " more player(s) joins!");
  6510. +               }
  6511. +           }
  6512. +           replyMSG.append("</body></html>");
  6513. +           adminReply.setHtml(replyMSG.toString());
  6514. +           eventPlayer.sendPacket(adminReply);
  6515. +
  6516. +           // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  6517. +           eventPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  6518. +       }
  6519. +       catch (Exception e)
  6520. +       {
  6521. +           _log.warning(TvT.class.getSimpleName() + ":  TvT Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception");
  6522. +           if (Config.DEVELOPER)
  6523. +               e.printStackTrace();
  6524. +       }
  6525. +   }
  6526. +
  6527. +   public static void addPlayer(Player player, String teamName)
  6528. +   {
  6529. +       if (!addPlayerOk(teamName, player))
  6530. +           return;
  6531. +
  6532. +       if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE"))
  6533. +       {
  6534. +           player._teamNameTvT = teamName;
  6535. +           _players.add(player);
  6536. +           setTeamPlayersCount(teamName, teamPlayersCount(teamName) + 1);
  6537. +       }
  6538. +       else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  6539. +           _playersShuffle.add(player);
  6540. +
  6541. +       player._inEventTvT = true;
  6542. +       player._countTvTkills = 0;
  6543. +
  6544. +       // notify player that he signed up in event
  6545. +       NpcHtmlMessage html = new NpcHtmlMessage(1);
  6546. +       html.setFile("data/html/mods/Participation.htm");
  6547. +       player.sendPacket(html);
  6548. +
  6549. +       if (Config.TVT_ANNOUNCE_SIGNUPS)
  6550. +           Broadcast.announceToOnlinePlayers("Player " + player.getName() + " has Signed Up in TvT!");
  6551. +   }
  6552. +
  6553. +   public synchronized static void removeOfflinePlayers()
  6554. +   {
  6555. +       try
  6556. +       {
  6557. +           if (_playersShuffle == null || _playersShuffle.isEmpty())
  6558. +               return;
  6559. +           for (Player player : _playersShuffle)
  6560. +           {
  6561. +               if (player == null)
  6562. +                   _playersShuffle.remove(player);
  6563. +               else if (player.isOnline() || player.isInJail())
  6564. +                   removePlayer(player);
  6565. +               if (_playersShuffle.size() == 0 || _playersShuffle.isEmpty())
  6566. +                   break;
  6567. +           }
  6568. +       }
  6569. +       catch (Exception e)
  6570. +       {
  6571. +           _log.warning(TvT.class.getSimpleName() + ": TVT unknown error");
  6572. +           if (Config.DEVELOPER)
  6573. +               e.printStackTrace();
  6574. +       }
  6575. +   }
  6576. +
  6577. +   public static boolean checkShufflePlayers(Player eventPlayer)
  6578. +   {
  6579. +       try
  6580. +       {
  6581. +           for (Player player : _playersShuffle)
  6582. +           {
  6583. +               if (player == null || player.isOnline())
  6584. +               {
  6585. +                   _playersShuffle.remove(player);
  6586. +                   eventPlayer._inEventTvT = false;
  6587. +                   continue;
  6588. +               }
  6589. +               else if (player.getObjectId() == eventPlayer.getObjectId())
  6590. +               {
  6591. +                   eventPlayer._inEventTvT = true;
  6592. +                   eventPlayer._countTvTkills = 0;
  6593. +                   return true;
  6594. +               }
  6595. +               // this 1 is incase player got new objectid after DC or reconnect
  6596. +               else if (player.getName().equals(eventPlayer.getName()))
  6597. +               {
  6598. +                   _playersShuffle.remove(player);
  6599. +                   _playersShuffle.add(eventPlayer);
  6600. +                   eventPlayer._inEventTvT = true;
  6601. +                   eventPlayer._countTvTkills = 0;
  6602. +                   return true;
  6603. +               }
  6604. +           }
  6605. +       }
  6606. +       catch (Exception e)
  6607. +       {
  6608. +       }
  6609. +       return false;
  6610. +   }
  6611. +
  6612. +   public static boolean addPlayerOk(String teamName, Player eventPlayer)
  6613. +   {
  6614. +       try
  6615. +       {
  6616. +           if(OlympiadManager.getInstance().isRegisteredInComp(eventPlayer) || eventPlayer.isInOlympiadMode() || eventPlayer.getOlympiadGameId() >0)
  6617. +           {
  6618. +               eventPlayer.sendMessage("You can't register while you are in olympiad!");
  6619. +               return false;
  6620. +           }
  6621. +           if (checkShufflePlayers(eventPlayer) || eventPlayer._inEventTvT)
  6622. +           {
  6623. +               eventPlayer.sendMessage("You are already participating in the event!");
  6624. +               return false;
  6625. +           }
  6626. +           if (eventPlayer._inEventCTF || eventPlayer._inEventDM || eventPlayer._inEventVIP)
  6627. +           {
  6628. +               eventPlayer.sendMessage("You are already participating in another event!");
  6629. +               return false;
  6630. +           }
  6631. +
  6632. +           for (Player player : _players)
  6633. +           {
  6634. +               if (player.getObjectId() == eventPlayer.getObjectId())
  6635. +               {
  6636. +                   eventPlayer.sendMessage("You are already participating in the event!");
  6637. +                   return false;
  6638. +               }
  6639. +               else if (player.getName() == eventPlayer.getName())
  6640. +               {
  6641. +                   eventPlayer.sendMessage("You are already participating in the event!");
  6642. +                   return false;
  6643. +               }
  6644. +           }
  6645. +           if (_players.contains(eventPlayer))
  6646. +           {
  6647. +               eventPlayer.sendMessage("You are already participating in the event!");
  6648. +               return false;
  6649. +           }
  6650. +           if (CTF._savePlayers.contains(eventPlayer.getName()))
  6651. +           {
  6652. +               eventPlayer.sendMessage("You are already participating in another event!");
  6653. +               return false;
  6654. +           }
  6655. +       }
  6656. +       catch (Exception e)
  6657. +       {
  6658. +           _log.warning(TvT.class.getSimpleName() + ":  TvT Engine exception: ");
  6659. +           if (Config.DEVELOPER)
  6660. +               e.printStackTrace();
  6661. +       }
  6662. +
  6663. +       if (Config.TVT_EVEN_TEAMS.equals("NO"))
  6664. +           return true;
  6665. +       else if (Config.TVT_EVEN_TEAMS.equals("BALANCE"))
  6666. +       {
  6667. +           boolean allTeamsEqual = true;
  6668. +           int countBefore = -1;
  6669. +
  6670. +           for (int playersCount : _teamPlayersCount)
  6671. +           {
  6672. +               if (countBefore == -1)
  6673. +                   countBefore = playersCount;
  6674. +
  6675. +               if (countBefore != playersCount)
  6676. +               {
  6677. +                   allTeamsEqual = false;
  6678. +                   break;
  6679. +               }
  6680. +
  6681. +               countBefore = playersCount;
  6682. +           }
  6683. +
  6684. +           if (allTeamsEqual)
  6685. +               return true;
  6686. +
  6687. +           countBefore = Integer.MAX_VALUE;
  6688. +
  6689. +           for (int teamPlayerCount : _teamPlayersCount)
  6690. +           {
  6691. +               if (teamPlayerCount < countBefore)
  6692. +                   countBefore = teamPlayerCount;
  6693. +           }
  6694. +
  6695. +           List<String> joinableTeams = new ArrayList<>();
  6696. +
  6697. +           for (String team : _teams)
  6698. +           {
  6699. +               if (teamPlayersCount(team) == countBefore)
  6700. +                   joinableTeams.add(team);
  6701. +           }
  6702. +
  6703. +           if (joinableTeams.contains(teamName))
  6704. +               return true;
  6705. +       }
  6706. +       else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  6707. +           return true;
  6708. +
  6709. +       eventPlayer.sendMessage("Too many players in team \"" + teamName + "\"");
  6710. +       return false;
  6711. +   }
  6712. +
  6713. +   public static synchronized void addDisconnectedPlayer(Player player)
  6714. +   {
  6715. +       if ((Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && (_teleport || _started)) || (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE") && (_teleport || _started)))
  6716. +       {
  6717. +           if (Config.TVT_ON_START_REMOVE_ALL_EFFECTS)
  6718. +           {
  6719. +               for (L2Effect e : player.getAllEffects())
  6720. +               {
  6721. +                   if (e != null)
  6722. +                       e.exit();
  6723. +               }
  6724. +           }
  6725. +
  6726. +           player._teamNameTvT = _savePlayerTeams.get(_savePlayers.indexOf(player.getName()));
  6727. +           for (Player p : _players)
  6728. +           {
  6729. +               if (p == null)
  6730. +                   continue;
  6731. +               // check by name incase player got new objectId
  6732. +               else if (p.getName().equals(player.getName()))
  6733. +               {
  6734. +                   player._originalNameColorTvT = player.getAppearance().getNameColor();
  6735. +                   player._originalTitleTvT = player.getTitle();
  6736. +                   player._originalKarmaTvT = player.getKarma();
  6737. +                   player._inEventTvT = true;
  6738. +                   player._countTvTkills = p._countTvTkills;
  6739. +                   _players.remove(p); // removing old object id from vector
  6740. +                   _players.add(player); // adding new objectId to vector
  6741. +                   break;
  6742. +               }
  6743. +           }
  6744. +
  6745. +           player.getAppearance().setNameColor(_teamColors.get(_teams.indexOf(player._teamNameTvT)));
  6746. +           player.setKarma(0);
  6747. +           if (Config.TVT_AURA)
  6748. +           {
  6749. +               if (_teams.size() >= 2)
  6750. +                   player.setTeam(_teams.indexOf(player._teamNameTvT) + 1);
  6751. +           }
  6752. +           player.broadcastUserInfo();
  6753. +           player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameTvT)), _teamsY.get(_teams.indexOf(player._teamNameTvT)), _teamsZ.get(_teams.indexOf(player._teamNameTvT)), 0);
  6754. +       }
  6755. +   }
  6756. +
  6757. +   public static void removePlayer(Player player)
  6758. +   {
  6759. +       if (player._inEventTvT)
  6760. +       {
  6761. +           if (!_joining)
  6762. +           {
  6763. +               player.getAppearance().setNameColor(player._originalNameColorTvT);
  6764. +               player.setTitle(player._originalTitleTvT);
  6765. +               player.setKarma(player._originalKarmaTvT);
  6766. +               if (Config.TVT_AURA)
  6767. +               {
  6768. +                   if (_teams.size() >= 2)
  6769. +                       player.setTeam(0);// clear aura :P
  6770. +               }
  6771. +               player.broadcastUserInfo();
  6772. +           }
  6773. +           player._teamNameTvT = "";
  6774. +           player._countTvTkills = 0;
  6775. +           player._inEventTvT = false;
  6776. +
  6777. +           if ((Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE")) && _players.contains(player))
  6778. +           {
  6779. +               setTeamPlayersCount(player._teamNameTvT, teamPlayersCount(player._teamNameTvT) - 1);
  6780. +               _players.remove(player);
  6781. +           }
  6782. +           else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && (!_playersShuffle.isEmpty() && _playersShuffle.contains(player)))
  6783. +               _playersShuffle.remove(player);
  6784. +       }
  6785. +   }
  6786. +
  6787. +   public static void cleanTvT()
  6788. +   {
  6789. +       _log.info("TvT: Cleaning players.");
  6790. +       for (Player player : _players)
  6791. +       {
  6792. +           if (player != null)
  6793. +           {
  6794. +               removePlayer(player);
  6795. +               if (_savePlayers.contains(player.getName()))
  6796. +                   _savePlayers.remove(player.getName());
  6797. +               player._inEventTvT = false;
  6798. +           }
  6799. +       }
  6800. +       if (_playersShuffle != null && !_playersShuffle.isEmpty())
  6801. +       {
  6802. +           for (Player player : _playersShuffle)
  6803. +           {
  6804. +               if (player != null)
  6805. +                   player._inEventTvT = false;
  6806. +           }
  6807. +       }
  6808. +       _log.info("TvT: Cleaning teams.");
  6809. +       for (String team : _teams)
  6810. +       {
  6811. +           int index = _teams.indexOf(team);
  6812. +
  6813. +           _teamPlayersCount.set(index, 0);
  6814. +           _teamKillsCount.set(index, 0);
  6815. +       }
  6816. +
  6817. +       _topKills = 0;
  6818. +       _topTeam = "";
  6819. +       _players.clear();
  6820. +       _playersShuffle.clear();
  6821. +       _savePlayers.clear();
  6822. +       _savePlayerTeams.clear();
  6823. +       _log.info("Cleaning TvT done.");
  6824. +   }
  6825. +
  6826. +   public static void unspawnEventNpc()
  6827. +   {
  6828. +       if (_npcSpawn == null)
  6829. +           return;
  6830. +
  6831. +       _npcSpawn.getNpc().deleteMe();
  6832. +       _npcSpawn.setRespawnState(false);
  6833. +       SpawnTable.getInstance().deleteSpawn(_npcSpawn, true);
  6834. +   }
  6835. +
  6836. +   public static void teleportFinish()
  6837. +   {
  6838. +       AnnounceToPlayers(false, _eventName + "Teleport back to participation NPC in 20 seconds!");
  6839. +
  6840. +       ThreadPool.schedule(new Runnable()
  6841. +       {
  6842. +           @Override
  6843. +           public void run()
  6844. +           {
  6845. +               for (Player player : _players)
  6846. +               {
  6847. +                   if (player != null)
  6848. +                   {
  6849. +                       if (player.isOnline())
  6850. +                           player.teleToLocation(_npcX, _npcY, _npcZ, 0);
  6851. +                       else
  6852. +                       {
  6853. +                           try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  6854. +                           {
  6855. +                               PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=? WHERE char_name=?");
  6856. +                               statement.setInt(1, _npcX);
  6857. +                               statement.setInt(2, _npcY);
  6858. +                               statement.setInt(3, _npcZ);
  6859. +                               statement.setString(4, player.getName());
  6860. +                               statement.execute();
  6861. +                               statement.close();
  6862. +                           }
  6863. +                           catch (SQLException se)
  6864. +                           {
  6865. +                               _log.warning(TvT.class.getSimpleName() + ": " + se);
  6866. +                           }
  6867. +                       }
  6868. +                   }
  6869. +               }
  6870. +               _log.info("TvT: Teleport done.");
  6871. +               cleanTvT();
  6872. +           }
  6873. +       }, 20000);
  6874. +   }
  6875. +
  6876. +   public static int teamKillsCount(String teamName)
  6877. +   {
  6878. +       int index = _teams.indexOf(teamName);
  6879. +
  6880. +       if (index == -1)
  6881. +           return -1;
  6882. +
  6883. +       return _teamKillsCount.get(index);
  6884. +   }
  6885. +
  6886. +   public static void setTeamKillsCount(String teamName, int teamKillsCount)
  6887. +   {
  6888. +       int index = _teams.indexOf(teamName);
  6889. +
  6890. +       if (index == -1)
  6891. +           return;
  6892. +
  6893. +       _teamKillsCount.set(index, teamKillsCount);
  6894. +   }
  6895. +
  6896. +   public static int teamPlayersCount(String teamName)
  6897. +   {
  6898. +       int index = _teams.indexOf(teamName);
  6899. +
  6900. +       if (index == -1)
  6901. +           return -1;
  6902. +
  6903. +       return _teamPlayersCount.get(index);
  6904. +   }
  6905. +
  6906. +   public static void setTeamPlayersCount(String teamName, int teamPlayersCount)
  6907. +   {
  6908. +       int index = _teams.indexOf(teamName);
  6909. +
  6910. +       if (index == -1)
  6911. +           return;
  6912. +
  6913. +       _teamPlayersCount.set(index, teamPlayersCount);
  6914. +   }
  6915. +
  6916. +   public static long _intervalBetweenMatchs = 0;
  6917. +
  6918. +   /**
  6919. +    * The type of TvT Event
  6920. +    * 1 = Manual
  6921. +    * 2 = Automatic
  6922. +    */
  6923. +   public static int _eventType = 0;
  6924. +
  6925. +   private static boolean _inProgress = false;
  6926. +   private static boolean _finished = false;
  6927. +   private static boolean _aborted = false;
  6928. +
  6929. +   /**
  6930. +    * Opens All Coliseum Doors
  6931. +    */
  6932. +   private static void closeColiseumDoors()
  6933. +   {
  6934. +       Broadcast.announceToOnlinePlayers("Closing Coliseum Doors, TvT event has just started !");
  6935. +       DoorTable.getInstance().getDoor(24190001).closeMe();// west gate out
  6936. +       DoorTable.getInstance().getDoor(24190002).closeMe();// west gate in
  6937. +       DoorTable.getInstance().getDoor(24190003).closeMe();// east gate out
  6938. +       DoorTable.getInstance().getDoor(24190004).closeMe();// east gate in
  6939. +
  6940. +       try
  6941. +       {
  6942. +           // just to give a lil delay :P
  6943. +           Thread.sleep(20);
  6944. +       }
  6945. +       catch (InterruptedException ie)
  6946. +       {
  6947. +           _log.warning(TvT.class.getSimpleName() + ": Error, " + ie.getMessage());
  6948. +           if (Config.DEVELOPER)
  6949. +           {
  6950. +               ie.printStackTrace();
  6951. +           }
  6952. +       }
  6953. +   }
  6954. +
  6955. +   /**
  6956. +    * Open all Coliseum Doors
  6957. +    */
  6958. +   private static void openColiseumDoors()
  6959. +   {
  6960. +       Broadcast.announceToOnlinePlayers("Opening Coliseum Doors, TvT event has finished!");
  6961. +       DoorTable.getInstance().getDoor(24190001).openMe();
  6962. +       DoorTable.getInstance().getDoor(24190002).openMe();
  6963. +       DoorTable.getInstance().getDoor(24190003).openMe();
  6964. +       DoorTable.getInstance().getDoor(24190004).openMe();
  6965. +
  6966. +   }
  6967. +   /**
  6968. +    * Returns the event type by name.
  6969. +    *
  6970. +    * @param value
  6971. +    * @return
  6972. +    */
  6973. +   public static String getEventTypeByName(int value)
  6974. +   {
  6975. +       String type = String.valueOf(value);
  6976. +
  6977. +       switch (value)
  6978. +       {
  6979. +           case 0:
  6980. +               type = ("None");
  6981. +           break;
  6982. +
  6983. +           case 1:
  6984. +               type = ("Manual");
  6985. +           break;
  6986. +
  6987. +           case 2:
  6988. +               type = ("Automatic");
  6989. +           break;
  6990. +       }
  6991. +       return type;
  6992. +   }
  6993. +   /**
  6994. +    * just an announcer to send termination messages
  6995. +    */
  6996. +   public static void sendFinalMessages()
  6997. +   {
  6998. +       if (_finished && !_aborted)
  6999. +           Broadcast.announceToOnlinePlayers("TvT: Thank you For Participating At, " + "TVT Event.");
  7000. +   }
  7001. +}
  7002. \ No newline at end of file
  7003. Index: java/net/sf/l2j/gameserver/model/actor/instance/VillageMaster.java
  7004. ===================================================================
  7005. --- java/net/sf/l2j/gameserver/model/actor/instance/VillageMaster.java  (revision 3)
  7006. +++ java/net/sf/l2j/gameserver/model/actor/instance/VillageMaster.java  (working copy)
  7007. @@ -325,7 +325,13 @@
  7008.                    
  7009.                     if (player.getLevel() < 75)
  7010.                         allowAddition = false;
  7011. -                  
  7012. +
  7013. +                   if (player._inEventCTF || player._inEventDM || player._inEventTvT)
  7014. +                   {
  7015. +                       player.sendMessage("You may not add a new sub class while being registered on event.");
  7016. +                       return;
  7017. +                   }
  7018. +
  7019.                     if (allowAddition)
  7020.                     {
  7021.                         if (!player.getSubClasses().isEmpty())
  7022. @@ -349,7 +355,13 @@
  7023.                      */
  7024.                     if (allowAddition && !Config.ALT_GAME_SUBCLASS_WITHOUT_QUESTS)
  7025.                         allowAddition = checkQuests(player);
  7026. -                  
  7027. +
  7028. +                   if (player._inEventCTF || player._inEventDM || player._inEventTvT)
  7029. +                   {
  7030. +                       player.sendMessage("You may not add a new sub class while being registered on event.");
  7031. +                       return;
  7032. +                   }
  7033. +
  7034.                     if (allowAddition && isValidNewSubClass(player, paramOne))
  7035.                     {
  7036.                         if (!player.addSubClass(paramOne, player.getSubClasses().size() + 1))
  7037. Index: java/net/sf/l2j/gameserver/model/actor/Npc.java
  7038. ===================================================================
  7039. --- java/net/sf/l2j/gameserver/model/actor/Npc.java (revision 3)
  7040. +++ java/net/sf/l2j/gameserver/model/actor/Npc.java (working copy)
  7041. @@ -40,6 +40,10 @@
  7042.  import net.sf.l2j.gameserver.model.actor.template.NpcTemplate.Race;
  7043.  import net.sf.l2j.gameserver.model.actor.template.NpcTemplate.SkillType;
  7044.  import net.sf.l2j.gameserver.model.entity.Castle;
  7045. +import net.sf.l2j.gameserver.model.entity.L2Event;
  7046. +import net.sf.l2j.gameserver.model.entity.engine.CTF;
  7047. +import net.sf.l2j.gameserver.model.entity.engine.DM;
  7048. +import net.sf.l2j.gameserver.model.entity.engine.TvT;
  7049.  import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
  7050.  import net.sf.l2j.gameserver.model.item.kind.Item;
  7051.  import net.sf.l2j.gameserver.model.item.kind.Weapon;
  7052. @@ -103,6 +107,12 @@
  7053.    
  7054.     private Castle _castle;
  7055.    
  7056. +   /** Engine Parameters */
  7057. +   public boolean isEventMob = false, _isEventMobCTF = false, _isCTF_throneSpawn = false, _isCTF_Flag = false;
  7058. +   public boolean _isEventMobTvT = false;
  7059. +   public boolean _isEventMobDM = false;
  7060. +   public String _CTF_FlagTeamName;
  7061. +  
  7062.     /**
  7063.      * Send a packet SocialAction to all L2PcInstance in the _KnownPlayers of the L2Npc and create a new RandomAnimation Task.
  7064.      * @param id the animation id.
  7065. @@ -356,11 +366,26 @@
  7066.                     if (qlsa != null && !qlsa.isEmpty())
  7067.                         player.setLastQuestNpcObject(getObjectId());
  7068.                    
  7069. -                   List<Quest> qlst = getTemplate().getEventQuests(EventType.ON_FIRST_TALK);
  7070. -                   if (qlst != null && qlst.size() == 1)
  7071. -                       qlst.get(0).notifyFirstTalk(this, player);
  7072. +                   if (isEventMob)
  7073. +                       L2Event.showEventHtml(player, String.valueOf(getObjectId()));
  7074. +                   else if (_isEventMobTvT)
  7075. +                       TvT.showEventHtml(player, String.valueOf(getObjectId()));
  7076. +                   else if (_isEventMobDM)
  7077. +                       DM.showEventHtml(player, String.valueOf(getObjectId()));
  7078. +                   else if (_isEventMobCTF)
  7079. +                       CTF.showEventHtml(player, String.valueOf(getObjectId()));
  7080. +                   else if (_isCTF_Flag && player._inEventCTF)
  7081. +                       CTF.showFlagHtml(player, String.valueOf(getObjectId()), _CTF_FlagTeamName);
  7082. +                   else if (_isCTF_throneSpawn)
  7083. +                       CTF.CheckRestoreFlags();
  7084.                     else
  7085. -                       showChatWindow(player);
  7086. +                   {
  7087. +                       List<Quest> qlst = getTemplate().getEventQuests(EventType.ON_FIRST_TALK);
  7088. +                       if (qlst != null && qlst.size() == 1)
  7089. +                           qlst.get(0).notifyFirstTalk(this, player);
  7090. +                       else
  7091. +                           showChatWindow(player);
  7092. +                   }
  7093.                 }
  7094.             }
  7095.         }
  7096. @@ -901,7 +926,7 @@
  7097.                         player.setLoto(i, val);
  7098.                         break;
  7099.                     }
  7100. -              
  7101. +          
  7102.             // setting pusshed buttons
  7103.             count = 0;
  7104.             for (int i = 0; i < 5; i++)
  7105. @@ -1206,7 +1231,7 @@
  7106.             filename = SevenSigns.SEVEN_SIGNS_HTML_PATH + "rift/GuardianOfBorder.htm";
  7107.         else
  7108.             filename = getHtmlPath(npcId, val);
  7109. -
  7110. +      
  7111.         final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  7112.         html.setFile(filename);
  7113.         html.replace("%objectId%", getObjectId());
  7114. @@ -1275,7 +1300,7 @@
  7115.     {
  7116.         if (!super.doDie(killer))
  7117.             return false;
  7118. -          
  7119. +      
  7120.         // normally this wouldn't really be needed, but for those few exceptions,
  7121.         // we do need to reset the weapons back to the initial templated weapon.
  7122.         _currentLHandId = getTemplate().getLeftHand();
  7123. @@ -1324,7 +1349,7 @@
  7124.         if (quests != null)
  7125.             for (Quest quest : quests)
  7126.                 quest.notifyDecay(this);
  7127. -          
  7128. +      
  7129.         // Remove the L2Npc from the world when the decay task is launched.
  7130.         super.onDecay();
  7131.        
  7132. Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestUnEquipItem.java
  7133. ===================================================================
  7134. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestUnEquipItem.java    (revision 1)
  7135. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestUnEquipItem.java    (working copy)
  7136. @@ -26,7 +26,13 @@
  7137.         final Player activeChar = getClient().getActiveChar();
  7138.         if (activeChar == null)
  7139.             return;
  7140. -      
  7141. +
  7142. +       if (activeChar._haveFlagCTF)
  7143. +       {
  7144. +           activeChar.sendMessage("You can't unequip a CTF flag.");
  7145. +           return;
  7146. +       }
  7147. +
  7148.         ItemInstance item = activeChar.getInventory().getPaperdollItemByL2ItemId(_slot);
  7149.         if (item == null)
  7150.             return;
  7151. Index: java/net/sf/l2j/gameserver/model/entity/engine/TvT.java
  7152. ===================================================================
  7153. --- java/net/sf/l2j/gameserver/model/entity/engine/TvT.java (revision 0)
  7154. +++ java/net/sf/l2j/gameserver/model/entity/engine/TvT.java (working copy)
  7155. @@ -0,0 +1,1767 @@
  7156. +/*
  7157. + * This program is free software: you can redistribute it and/or modify it under
  7158. + * the terms of the GNU General Public License as published by the Free Software
  7159. + * Foundation, either version 3 of the License, or (at your option) any later
  7160. + * version.
  7161. + *
  7162. + * This program is distributed in the hope that it will be useful, but WITHOUT
  7163. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  7164. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  7165. + * details.
  7166. + *
  7167. + * You should have received a copy of the GNU General Public License along with
  7168. + * this program. If not, see <http://www.gnu.org/licenses/>.
  7169. + */
  7170. +package net.sf.l2j.gameserver.model.entity.engine;
  7171. +
  7172. +/**
  7173. + * @author FBIagent / Fixed By l2jhellas And L2Emu Team
  7174. + */
  7175. +import java.sql.Connection;
  7176. +import java.sql.PreparedStatement;
  7177. +import java.sql.ResultSet;
  7178. +import java.sql.SQLException;
  7179. +import java.util.ArrayList;
  7180. +import java.util.List;
  7181. +import java.util.logging.Level;
  7182. +import java.util.logging.Logger;
  7183. +
  7184. +import net.sf.l2j.Config;
  7185. +import net.sf.l2j.L2DatabaseFactory;
  7186. +import net.sf.l2j.commons.concurrent.ThreadPool;
  7187. +import net.sf.l2j.commons.random.Rnd;
  7188. +import net.sf.l2j.gameserver.datatables.DoorTable;
  7189. +import net.sf.l2j.gameserver.datatables.ItemTable;
  7190. +import net.sf.l2j.gameserver.datatables.NpcTable;
  7191. +import net.sf.l2j.gameserver.datatables.SpawnTable;
  7192. +import net.sf.l2j.gameserver.model.L2Effect;
  7193. +import net.sf.l2j.gameserver.model.L2Spawn;
  7194. +import net.sf.l2j.gameserver.model.actor.Summon;
  7195. +import net.sf.l2j.gameserver.model.actor.instance.Pet;
  7196. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  7197. +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  7198. +import net.sf.l2j.gameserver.model.group.Party;
  7199. +import net.sf.l2j.gameserver.model.group.Party.MessageType;
  7200. +import net.sf.l2j.gameserver.model.olympiad.OlympiadManager;
  7201. +import net.sf.l2j.gameserver.network.clientpackets.Say2;
  7202. +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  7203. +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  7204. +import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  7205. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  7206. +import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
  7207. +import net.sf.l2j.gameserver.util.Broadcast;
  7208. +
  7209. +public class TvT
  7210. +{
  7211. +   protected static final Logger _log = Logger.getLogger(TvT.class.getName());
  7212. +   public static String _eventName = "";
  7213. +   public static String _eventDesc = "";
  7214. +   public static String _topTeam = "";
  7215. +   public static String _joiningLocationName = "";
  7216. +   public static List<String> _teams = new ArrayList<>();
  7217. +   public static List<String> _savePlayers = new ArrayList<>();
  7218. +   public static List<String> _savePlayerTeams = new ArrayList<>();
  7219. +
  7220. +   public static List<Player> _players = new ArrayList<>();
  7221. +   public static List<Player> _playersShuffle = new ArrayList<>();
  7222. +   public static List<Integer> _teamPlayersCount = new ArrayList<>();
  7223. +   public static List<Integer> _teamKillsCount = new ArrayList<>();
  7224. +   public static List<Integer> _teamColors = new ArrayList<>();
  7225. +   public static List<Integer> _teamsX = new ArrayList<>();
  7226. +   public static List<Integer> _teamsY = new ArrayList<>();
  7227. +   public static List<Integer> _teamsZ = new ArrayList<>();
  7228. +   public static boolean _joining = false;
  7229. +   public static boolean _teleport = false;
  7230. +   public static boolean _started = false;
  7231. +   public static boolean _sitForced = false;
  7232. +   public static L2Spawn _npcSpawn;
  7233. +
  7234. +   public static int _npcId = 0;
  7235. +   public static int _npcX = 0;
  7236. +   public static int _npcY = 0;
  7237. +   public static int _npcZ = 0;
  7238. +   public static int _npcHeading = 0;
  7239. +
  7240. +   public static int _rewardId = 0;
  7241. +   public static int _rewardAmount = 0;
  7242. +
  7243. +   public static int _topKills = 0;
  7244. +   public static int _minlvl = 0;
  7245. +   public static int _maxlvl = 0;
  7246. +
  7247. +   public static int _joinTime = 0;
  7248. +   public static int _eventTime = 0;
  7249. +
  7250. +   public static int _minPlayers = 0;
  7251. +   public static int _maxPlayers = 0;
  7252. +
  7253. +   public static int _playerWon = 0;
  7254. +
  7255. +   public static void AnnounceToPlayers(Boolean toall, String announce)
  7256. +   {
  7257. +       if (toall)
  7258. +           Broadcast.announceToOnlinePlayers(announce);
  7259. +       else
  7260. +       {
  7261. +           CreatureSay cs = new CreatureSay(0, Say2.ANNOUNCEMENT, "", announce);
  7262. +           if (_players != null && !_players.isEmpty())
  7263. +           {
  7264. +               for (Player player : _players)
  7265. +               {
  7266. +                   if (player != null && player.isOnline())
  7267. +                       player.sendPacket(cs);
  7268. +               }
  7269. +           }
  7270. +       }
  7271. +   }
  7272. +
  7273. +   public static void kickPlayerFromTvt(Player playerToKick)
  7274. +   {
  7275. +       if (playerToKick == null)
  7276. +           return;
  7277. +
  7278. +       if (_joining)
  7279. +       {
  7280. +           _playersShuffle.remove(playerToKick);
  7281. +           _players.remove(playerToKick);
  7282. +           playerToKick._inEventTvT = false;
  7283. +           playerToKick._teamNameTvT = "";
  7284. +           playerToKick._countTvTkills = 0;
  7285. +       }
  7286. +       if (_started || _teleport)
  7287. +       {
  7288. +           _playersShuffle.remove(playerToKick);
  7289. +           playerToKick._inEventTvT = false;
  7290. +           removePlayer(playerToKick);
  7291. +           if (playerToKick.isOnline())
  7292. +           {
  7293. +               playerToKick.getAppearance().setNameColor(playerToKick._originalNameColorTvT);
  7294. +               playerToKick.setKarma(playerToKick._originalKarmaTvT);
  7295. +               playerToKick.setTitle(playerToKick._originalTitleTvT);
  7296. +               playerToKick.broadcastUserInfo();
  7297. +               playerToKick.sendMessage("You have been kicked from the TvT.");
  7298. +               playerToKick.teleToLocation(_npcX, _npcY, _npcZ, 0);
  7299. +           }
  7300. +       }
  7301. +   }
  7302. +
  7303. +   public static void setNpcPos(Player activeChar)
  7304. +   {
  7305. +       _npcX = activeChar.getX();
  7306. +       _npcY = activeChar.getY();
  7307. +       _npcZ = activeChar.getZ();
  7308. +       _npcHeading = activeChar.getHeading();
  7309. +   }
  7310. +
  7311. +   public static void setNpcPos(int x, int y, int z)
  7312. +   {
  7313. +       _npcX = x;
  7314. +       _npcY = y;
  7315. +       _npcZ = z;
  7316. +   }
  7317. +
  7318. +   public static void addTeam(String teamName)
  7319. +   {
  7320. +       if (!checkTeamOk())
  7321. +       {
  7322. +           if (Config.DEBUG)
  7323. +               _log.log(Level.FINER, "TvT Engine[addTeam(" + teamName + ")]: checkTeamOk() = false");
  7324. +           return;
  7325. +       }
  7326. +
  7327. +       if (teamName.equals(" "))
  7328. +           return;
  7329. +
  7330. +       _teams.add(teamName);
  7331. +       _teamPlayersCount.add(0);
  7332. +       _teamKillsCount.add(0);
  7333. +       _teamColors.add(0);
  7334. +       _teamsX.add(0);
  7335. +       _teamsY.add(0);
  7336. +       _teamsZ.add(0);
  7337. +   }
  7338. +
  7339. +   public static boolean checkMaxLevel(int maxlvl)
  7340. +   {
  7341. +       return _minlvl < maxlvl;
  7342. +   }
  7343. +
  7344. +   public static boolean checkMinLevel(int minlvl)
  7345. +   {
  7346. +       return _maxlvl > minlvl;
  7347. +   }
  7348. +
  7349. +   /** returns true if participated players is higher or equal then minimum needed players
  7350. +    * @param players
  7351. +    * @return */
  7352. +   public static boolean checkMinPlayers(int players)
  7353. +   {
  7354. +       return _minPlayers <= players;
  7355. +   }
  7356. +
  7357. +   /** returns true if max players is higher or equal then participated players
  7358. +    * @param players
  7359. +    * @return */
  7360. +   public static boolean checkMaxPlayers(int players)
  7361. +   {
  7362. +       return _maxPlayers > players;
  7363. +   }
  7364. +
  7365. +   public static void removeTeam(String teamName)
  7366. +   {
  7367. +       if (!checkTeamOk() || _teams.isEmpty())
  7368. +       {
  7369. +           if (Config.DEBUG)
  7370. +               _log.log(Level.FINER, "TvT Engine[removeTeam(" + teamName + ")]: checkTeamOk() = false");
  7371. +           return;
  7372. +       }
  7373. +
  7374. +       if (teamPlayersCount(teamName) > 0)
  7375. +       {
  7376. +           if (Config.DEBUG)
  7377. +               _log.log(Level.FINER, "TvT Engine[removeTeam(" + teamName + ")]: teamPlayersCount(teamName) > 0");
  7378. +           return;
  7379. +       }
  7380. +
  7381. +       int index = _teams.indexOf(teamName);
  7382. +
  7383. +       if (index == -1)
  7384. +           return;
  7385. +
  7386. +       _teamsZ.remove(index);
  7387. +       _teamsY.remove(index);
  7388. +       _teamsX.remove(index);
  7389. +       _teamColors.remove(index);
  7390. +       _teamKillsCount.remove(index);
  7391. +       _teamPlayersCount.remove(index);
  7392. +       _teams.remove(index);
  7393. +   }
  7394. +
  7395. +   public static void setTeamPos(String teamName, Player activeChar)
  7396. +   {
  7397. +       int index = _teams.indexOf(teamName);
  7398. +
  7399. +       if (index == -1)
  7400. +           return;
  7401. +
  7402. +       _teamsX.set(index, activeChar.getX());
  7403. +       _teamsY.set(index, activeChar.getY());
  7404. +       _teamsZ.set(index, activeChar.getZ());
  7405. +   }
  7406. +
  7407. +   public static void setTeamPos(String teamName, int x, int y, int z)
  7408. +   {
  7409. +       int index = _teams.indexOf(teamName);
  7410. +
  7411. +       if (index == -1)
  7412. +           return;
  7413. +
  7414. +       _teamsX.set(index, x);
  7415. +       _teamsY.set(index, y);
  7416. +       _teamsZ.set(index, z);
  7417. +   }
  7418. +
  7419. +   public static void setTeamColor(String teamName, int color)
  7420. +   {
  7421. +       if (!checkTeamOk())
  7422. +           return;
  7423. +
  7424. +       int index = _teams.indexOf(teamName);
  7425. +
  7426. +       if (index == -1)
  7427. +           return;
  7428. +
  7429. +       _teamColors.set(index, color);
  7430. +   }
  7431. +
  7432. +   public static boolean checkTeamOk()
  7433. +   {
  7434. +       return !(_started || _teleport || _joining);
  7435. +   }
  7436. +
  7437. +   public static void startJoin(Player activeChar)
  7438. +   {
  7439. +       if (!startJoinOk())
  7440. +       {
  7441. +           activeChar.sendMessage("Event not setted propertly.");
  7442. +           if (Config.DEBUG)
  7443. +               _log.log(Level.FINER, "TvT Engine[startJoin(" + activeChar.getName() + ")]: startJoinOk() = false");
  7444. +           return;
  7445. +       }
  7446. +       _joining = true;
  7447. +       spawnEventNpc(activeChar);
  7448. +       AnnounceToPlayers(true, _eventName);
  7449. +       if (Config.TVT_ANNOUNCE_REWARD)
  7450. +           AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).getName());
  7451. +       AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
  7452. +       AnnounceToPlayers(true, "Join in " + _joiningLocationName + "!");
  7453. +   }
  7454. +
  7455. +   public static void startJoin()
  7456. +   {
  7457. +       if (!startJoinOk())
  7458. +       {
  7459. +           _log.warning(TvT.class.getSimpleName() + ":  Event not setted propertly.");
  7460. +           if (Config.DEBUG)
  7461. +               _log.log(Level.FINER, "TvT Engine[startJoin(startJoinOk() = false");
  7462. +           return;
  7463. +       }
  7464. +       _joining = true;
  7465. +       spawnEventNpc();
  7466. +       AnnounceToPlayers(true, _eventName);
  7467. +       if (Config.TVT_ANNOUNCE_REWARD)
  7468. +           AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).getName());
  7469. +       AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
  7470. +       AnnounceToPlayers(true, "Join in " + _joiningLocationName + "!");
  7471. +   }
  7472. +
  7473. +   public static boolean startAutoJoin()
  7474. +   {
  7475. +       if (!startJoinOk())
  7476. +       {
  7477. +           if (Config.DEBUG)
  7478. +               _log.log(Level.FINER, "TvT Engine[startJoin]: startJoinOk() = false");
  7479. +           return false;
  7480. +       }
  7481. +
  7482. +       _joining = true;
  7483. +       spawnEventNpc();
  7484. +       AnnounceToPlayers(true, _eventName);
  7485. +       if (Config.TVT_ANNOUNCE_REWARD)
  7486. +           AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).getName());
  7487. +       AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
  7488. +       AnnounceToPlayers(true, "Join in " + _joiningLocationName + "!");
  7489. +       return true;
  7490. +   }
  7491. +
  7492. +   public static boolean startJoinOk()
  7493. +   {
  7494. +       return !(_started || _teleport || _joining || _teams.size() < 2 || _eventName.isEmpty() || _joiningLocationName.isEmpty() || _eventDesc.isEmpty() || _npcId == 0 || _npcX == 0 || _npcY == 0 || _npcZ == 0 || _rewardId == 0 || _rewardAmount == 0 || _teamsX.contains(0) || _teamsY.contains(0) || _teamsZ.contains(0));
  7495. +   }
  7496. +
  7497. +   private static void spawnEventNpc(Player activeChar)
  7498. +   {
  7499. +       NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
  7500. +
  7501. +       try
  7502. +       {
  7503. +           _npcSpawn = new L2Spawn(tmpl);
  7504. +
  7505. +           _npcSpawn.setLoc(_npcX, _npcY, _npcZ, _npcHeading);
  7506. +           _npcSpawn.setRespawnDelay(1);
  7507. +
  7508. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  7509. +
  7510. +           _npcSpawn.setRespawnState(true);
  7511. +           _npcSpawn.doSpawn(false);
  7512. +           _npcSpawn.getNpc().getStatus().setCurrentHp(999999999);
  7513. +           _npcSpawn.getNpc().setTitle(_eventName);
  7514. +           _npcSpawn.getNpc()._isEventMobTvT = true;
  7515. +           _npcSpawn.getNpc().isAggressive();
  7516. +           _npcSpawn.getNpc().decayMe();
  7517. +           _npcSpawn.getNpc().spawnMe(_npcSpawn.getNpc().getX(), _npcSpawn.getNpc().getY(), _npcSpawn.getNpc().getZ());
  7518. +
  7519. +           _npcSpawn.getNpc().broadcastPacket(new MagicSkillUse(_npcSpawn.getNpc(), _npcSpawn.getNpc(), 1034, 1, 1, 1));
  7520. +       }
  7521. +       catch (Exception e)
  7522. +       {
  7523. +           _log.warning(TvT.class.getSimpleName() + ":  TvT Engine[spawnEventNpc(" + activeChar.getName() + ")]: exception: ");
  7524. +           if (Config.DEVELOPER)
  7525. +               e.printStackTrace();
  7526. +       }
  7527. +   }
  7528. +
  7529. +   private static void spawnEventNpc()
  7530. +   {
  7531. +       NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
  7532. +
  7533. +       try
  7534. +       {
  7535. +           _npcSpawn = new L2Spawn(tmpl);
  7536. +           _npcSpawn.setLoc(_npcX, _npcY, _npcZ, _npcHeading);
  7537. +           _npcSpawn.setRespawnDelay(1);
  7538. +
  7539. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  7540. +
  7541. +           _npcSpawn.setRespawnState(true);
  7542. +           _npcSpawn.doSpawn(false);
  7543. +           _npcSpawn.getNpc().getStatus().setCurrentHp(999999999);
  7544. +           _npcSpawn.getNpc().setTitle(_eventName);
  7545. +           _npcSpawn.getNpc()._isEventMobTvT = true;
  7546. +           _npcSpawn.getNpc().isAggressive();
  7547. +           _npcSpawn.getNpc().decayMe();
  7548. +           _npcSpawn.getNpc().spawnMe(_npcSpawn.getNpc().getX(), _npcSpawn.getNpc().getY(), _npcSpawn.getNpc().getZ());
  7549. +
  7550. +           _npcSpawn.getNpc().broadcastPacket(new MagicSkillUse(_npcSpawn.getNpc(), _npcSpawn.getNpc(), 1034, 1, 1, 1));
  7551. +       }
  7552. +       catch (Exception e)
  7553. +       {
  7554. +           _log.warning(TvT.class.getSimpleName() + ":  TvT Engine[spawnEventNpc(exception: ");
  7555. +           if (Config.DEVELOPER)
  7556. +               e.printStackTrace();
  7557. +       }
  7558. +   }
  7559. +
  7560. +   public static void teleportStart()
  7561. +   {
  7562. +       if (!_joining || _started || _teleport)
  7563. +           return;
  7564. +
  7565. +       if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && checkMinPlayers(_playersShuffle.size()))
  7566. +       {
  7567. +           removeOfflinePlayers();
  7568. +           shuffleTeams();
  7569. +       }
  7570. +       else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && !checkMinPlayers(_playersShuffle.size()))
  7571. +       {
  7572. +           AnnounceToPlayers(true, "Not enough players for event. Min Requested : " + _minPlayers + ", Participating : " + _playersShuffle.size());
  7573. +           return;
  7574. +       }
  7575. +
  7576. +       _joining = false;
  7577. +       AnnounceToPlayers(false, _eventName + "Teleport to team spot in 20 seconds!");
  7578. +
  7579. +       setUserData();
  7580. +       ThreadPool.schedule(new Runnable()
  7581. +       {
  7582. +           @Override
  7583. +           public void run()
  7584. +           {
  7585. +               TvT.sit();
  7586. +
  7587. +               for (Player player : _players)
  7588. +               {
  7589. +                   if (player != null)
  7590. +                   {
  7591. +                       if (Config.TVT_ON_START_UNSUMMON_PET)
  7592. +                       {
  7593. +                           // Remove Summon's buffs
  7594. +                           if (player.getPet() != null)
  7595. +                           {
  7596. +                               Summon summon = player.getPet();
  7597. +                               for (L2Effect e : summon.getAllEffects())
  7598. +                               {
  7599. +                                   if (e != null)
  7600. +                                       e.exit();
  7601. +                               }
  7602. +
  7603. +                               if (summon instanceof Pet)
  7604. +                                   summon.unSummon(player);
  7605. +                           }
  7606. +                       }
  7607. +
  7608. +                       if (Config.TVT_ON_START_REMOVE_ALL_EFFECTS)
  7609. +                       {
  7610. +                           for (L2Effect e : player.getAllEffects())
  7611. +                           {
  7612. +                               if (e != null)
  7613. +                                   e.exit();
  7614. +                           }
  7615. +                       }
  7616. +
  7617. +                       // Remove player from his party
  7618. +                       if (player.getParty() != null)
  7619. +                       {
  7620. +                           Party party = player.getParty();
  7621. +                           party.removePartyMember(player, MessageType.EXPELLED);
  7622. +                       }
  7623. +
  7624. +                       player.setTitle("Kills: " + player._countTvTkills);
  7625. +                       player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameTvT)), _teamsY.get(_teams.indexOf(player._teamNameTvT)), _teamsZ.get(_teams.indexOf(player._teamNameTvT)), 0);
  7626. +                   }
  7627. +               }
  7628. +           }
  7629. +       }, 20000);
  7630. +       _teleport = true;
  7631. +   }
  7632. +
  7633. +   public static boolean teleportAutoStart()
  7634. +   {
  7635. +       if (!_joining || _started || _teleport)
  7636. +           return false;
  7637. +
  7638. +       if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && checkMinPlayers(_playersShuffle.size()))
  7639. +       {
  7640. +           removeOfflinePlayers();
  7641. +           shuffleTeams();
  7642. +       }
  7643. +       else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && !checkMinPlayers(_playersShuffle.size()))
  7644. +       {
  7645. +           AnnounceToPlayers(true, "Not enough players for event. Min Requested : " + _minPlayers + ", Participating : " + _playersShuffle.size());
  7646. +           return false;
  7647. +       }
  7648. +
  7649. +       _joining = false;
  7650. +       AnnounceToPlayers(false, _eventName + "Teleport to team spot in 20 seconds!");
  7651. +
  7652. +       setUserData();
  7653. +       ThreadPool.schedule(new Runnable()
  7654. +       {
  7655. +           @Override
  7656. +           public void run()
  7657. +           {
  7658. +               TvT.sit();
  7659. +
  7660. +               for (Player player : _players)
  7661. +               {
  7662. +                   if (player != null)
  7663. +                   {
  7664. +                       if (Config.TVT_ON_START_UNSUMMON_PET)
  7665. +                       {
  7666. +                           // Remove Summon's buffs
  7667. +                           if (player.getPet() != null)
  7668. +                           {
  7669. +                               Summon summon = player.getPet();
  7670. +                               for (L2Effect e : summon.getAllEffects())
  7671. +                               {
  7672. +                                   if (e != null)
  7673. +                                       e.exit();
  7674. +                               }
  7675. +
  7676. +                               if (summon instanceof Pet)
  7677. +                                   summon.unSummon(player);
  7678. +                           }
  7679. +                       }
  7680. +
  7681. +                       if (Config.TVT_ON_START_REMOVE_ALL_EFFECTS)
  7682. +                       {
  7683. +                           for (L2Effect e : player.getAllEffects())
  7684. +                           {
  7685. +                               if (e != null)
  7686. +                                   e.exit();
  7687. +                           }
  7688. +                       }
  7689. +
  7690. +                       // Remove player from his party
  7691. +                       if (player.getParty() != null)
  7692. +                       {
  7693. +                           Party party = player.getParty();
  7694. +                           party.removePartyMember(player, MessageType.EXPELLED);
  7695. +                       }
  7696. +                       player.setTitle("Kills: " + player._countTvTkills);
  7697. +                       player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameTvT)), _teamsY.get(_teams.indexOf(player._teamNameTvT)), _teamsZ.get(_teams.indexOf(player._teamNameTvT)), 0);
  7698. +                   }
  7699. +               }
  7700. +           }
  7701. +       }, 20000);
  7702. +       _teleport = true;
  7703. +       return true;
  7704. +   }
  7705. +
  7706. +   public static void startEvent(Player activeChar)
  7707. +   {
  7708. +       if (_inProgress)
  7709. +       {
  7710. +           activeChar.sendMessage("A TvT event is already in progress, try abort.");
  7711. +           return;
  7712. +       }
  7713. +
  7714. +       if (!startEventOk())
  7715. +       {
  7716. +           if (Config.DEBUG)
  7717. +               _log.log(Level.FINER, "TvT Engine[startEvent(" + activeChar.getName() + ")]: startEventOk() = false");
  7718. +           return;
  7719. +       }
  7720. +
  7721. +       _teleport = false;
  7722. +       sit();
  7723. +
  7724. +       if (Config.TVT_CLOSE_COLISEUM_DOORS)
  7725. +           closeColiseumDoors();
  7726. +
  7727. +       AnnounceToPlayers(false, _eventName + "Started. Go to kill your enemies!");
  7728. +       _started = true;
  7729. +       _inProgress = true;
  7730. +   }
  7731. +
  7732. +   public static void setJoinTime(int time)
  7733. +   {
  7734. +       _joinTime = time;
  7735. +   }
  7736. +
  7737. +   public static void setEventTime(int time)
  7738. +   {
  7739. +       _eventTime = time;
  7740. +   }
  7741. +
  7742. +   public static boolean startAutoEvent()
  7743. +   {
  7744. +       if (!startEventOk())
  7745. +       {
  7746. +           if (Config.DEBUG)
  7747. +               _log.log(Level.FINER, "TvT Engine[startEvent]: startEventOk() = false");
  7748. +           return false;
  7749. +       }
  7750. +
  7751. +       _teleport = false;
  7752. +       sit();
  7753. +
  7754. +       if (Config.TVT_CLOSE_COLISEUM_DOORS)
  7755. +           closeColiseumDoors();
  7756. +
  7757. +       AnnounceToPlayers(false, _eventName + "Started. Go to kill your enemies!");
  7758. +       _started = true;
  7759. +       return true;
  7760. +   }
  7761. +
  7762. +   public static synchronized void autoEvent()
  7763. +   {
  7764. +       _log.info("Starting TvT!");
  7765. +       if (startAutoJoin())
  7766. +       {
  7767. +           _eventType = 2;
  7768. +
  7769. +           if (_joinTime > 0)
  7770. +               waiter(_joinTime * 60 * 1000); // minutes for join event
  7771. +           else if (_joinTime <= 0)
  7772. +           {
  7773. +               _log.info("TvT: join time <=0 aborting event.");
  7774. +               abortEvent();
  7775. +               return;
  7776. +           }
  7777. +           if (teleportAutoStart())
  7778. +           {
  7779. +               waiter(30 * 1000); // 30 sec wait time untill start fight after teleported
  7780. +               if (startAutoEvent())
  7781. +               {
  7782. +                   _log.log(Level.FINER, "TvT: waiting.....minutes for event time " + TvT._eventTime);
  7783. +
  7784. +                   waiter(_eventTime * 60 * 1000); // minutes for event time
  7785. +                   finishEvent();
  7786. +
  7787. +                   _log.info("TvT: waiting... delay for final messages ");
  7788. +                   waiter(60000);// just a give a delay delay for final messages
  7789. +                   sendFinalMessages();
  7790. +               }
  7791. +           }
  7792. +           else if (!teleportAutoStart())
  7793. +           {
  7794. +               abortEvent();
  7795. +           }
  7796. +       }
  7797. +   }
  7798. +
  7799. +   private synchronized static void waiter(long interval)
  7800. +   {
  7801. +       long startWaiterTime = System.currentTimeMillis();
  7802. +       int seconds = (int) (interval / 1000);
  7803. +
  7804. +       String npcManager = NpcTable.getInstance().getTemplate(_npcId).getName();
  7805. +
  7806. +       while (startWaiterTime + interval > System.currentTimeMillis())
  7807. +       {
  7808. +           seconds--; // here because we don't want to see two time announce at the same time
  7809. +
  7810. +           if (_joining || _started || _teleport)
  7811. +           {
  7812. +               switch (seconds)
  7813. +               {
  7814. +                   case 3600: // 1 hour left
  7815. +                       if (_joining)
  7816. +                       {
  7817. +                           AnnounceToPlayers(true, "TvT: Joinable in " + _joiningLocationName + "!");
  7818. +                           AnnounceToPlayers(true, "TvT: " + seconds / 60 / 60 + " hour(s) till registration ends!");
  7819. +                           if (Config.TVT_ANNOUNCE_REGISTRATION_LOC_NPC)
  7820. +                               AnnounceToPlayers(true, "TvT: Registration Period is Active in " + _joiningLocationName + " ! at Npc " + npcManager);
  7821. +                       }
  7822. +                       else if (_started)
  7823. +                           AnnounceToPlayers(false, "TvT: " + seconds / 60 / 60 + " hour(s) till event ends!");
  7824. +
  7825. +                   break;
  7826. +                   case 1800: // 30 minutes left
  7827. +                   case 900: // 15 minutes left
  7828. +                   case 600: // 10 minutes left
  7829. +                   case 300: // 5 minutes left
  7830. +                   case 60: // 1 minute left
  7831. +                       if (_joining)
  7832. +                       {
  7833. +                           removeOfflinePlayers();
  7834. +                           AnnounceToPlayers(true, "TvT: Joinable in " + _joiningLocationName + "!");
  7835. +                           AnnounceToPlayers(true, "TvT: " + seconds / 60 + " minute(s) till registration ends!");
  7836. +                           if (Config.TVT_ANNOUNCE_REGISTRATION_LOC_NPC)
  7837. +                               Broadcast.announceToOnlinePlayers("TvT: Registration Period is Active in " + _joiningLocationName + " ! at Npc " + npcManager);
  7838. +                       }
  7839. +                       else if (_started)
  7840. +                           AnnounceToPlayers(false, "TvT: " + seconds / 60 + " minute(s) till event ends!");
  7841. +
  7842. +                   break;
  7843. +                   case 30: // 30 seconds left
  7844. +                   case 10: // 10 seconds left
  7845. +                   case 3: // 3 seconds left
  7846. +                   case 2: // 2 seconds left
  7847. +                   case 1: // 1 seconds left
  7848. +                       if (_joining)
  7849. +                           AnnounceToPlayers(true, "TvT: " + seconds + " second(s) till registration ends!");
  7850. +                       else if (_teleport)
  7851. +                           AnnounceToPlayers(false, "TvT: " + seconds + " seconds(s) till fight starts!");
  7852. +                       else if (_started)
  7853. +                           AnnounceToPlayers(false, "TvT: " + seconds + " second(s) till event ends!");
  7854. +
  7855. +                   break;
  7856. +               }
  7857. +           }
  7858. +
  7859. +           long startOneSecondWaiterStartTime = System.currentTimeMillis();
  7860. +
  7861. +           // only the try catch with Thread.sleep(1000) give bad countdown on high wait times
  7862. +           while (startOneSecondWaiterStartTime + 1000 > System.currentTimeMillis())
  7863. +           {
  7864. +               try
  7865. +               {
  7866. +                   Thread.sleep(1);
  7867. +               }
  7868. +               catch (InterruptedException ie)
  7869. +               {
  7870. +
  7871. +               }
  7872. +           }
  7873. +       }
  7874. +   }
  7875. +
  7876. +   private static boolean startEventOk()
  7877. +   {
  7878. +       if (_joining || !_teleport || _started)
  7879. +           return false;
  7880. +
  7881. +       if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE"))
  7882. +       {
  7883. +           if (_teamPlayersCount.contains(0))
  7884. +               return false;
  7885. +       }
  7886. +       else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  7887. +       {
  7888. +           List<Player> playersShuffleTemp = new ArrayList<>();
  7889. +           int loopCount = 0;
  7890. +
  7891. +           loopCount = _playersShuffle.size();
  7892. +
  7893. +           for (int i = 0; i < loopCount; i++)
  7894. +           {
  7895. +               if (_playersShuffle != null)
  7896. +                   playersShuffleTemp.add(_playersShuffle.get(i));
  7897. +           }
  7898. +
  7899. +           _playersShuffle = playersShuffleTemp;
  7900. +           playersShuffleTemp.clear();
  7901. +       }
  7902. +
  7903. +       return true;
  7904. +   }
  7905. +
  7906. +   public static void shuffleTeams()
  7907. +   {
  7908. +       int teamCount = 0, playersCount = 0;
  7909. +
  7910. +       for (;;)
  7911. +       {
  7912. +           if (_playersShuffle.isEmpty())
  7913. +               break;
  7914. +
  7915. +           int playerToAddIndex = Rnd.nextInt(_playersShuffle.size());
  7916. +           Player player = null;
  7917. +           player = _playersShuffle.get(playerToAddIndex);
  7918. +           player._originalNameColorTvT = player.getAppearance().getNameColor();
  7919. +           player._originalTitleTvT = player.getTitle();
  7920. +           player._originalKarmaTvT = player.getKarma();
  7921. +
  7922. +           _players.add(player);
  7923. +           _players.get(playersCount)._teamNameTvT = _teams.get(teamCount);
  7924. +           _savePlayers.add(_players.get(playersCount).getName());
  7925. +           _savePlayerTeams.add(_teams.get(teamCount));
  7926. +           playersCount++;
  7927. +
  7928. +           if (teamCount == _teams.size() - 1)
  7929. +               teamCount = 0;
  7930. +           else
  7931. +               teamCount++;
  7932. +
  7933. +           _playersShuffle.remove(playerToAddIndex);
  7934. +       }
  7935. +   }
  7936. +
  7937. +   public static void setUserData()
  7938. +   {
  7939. +       for (Player player : _players)
  7940. +       {
  7941. +           player.getAppearance().setNameColor(_teamColors.get(_teams.indexOf(player._teamNameTvT)));
  7942. +           player.setKarma(0);
  7943. +
  7944. +           if (Config.TVT_AURA)
  7945. +           {
  7946. +               if (_teams.size() >= 2)
  7947. +                   player.setTeam(_teams.indexOf(player._teamNameTvT) + 1);
  7948. +           }
  7949. +           player.broadcastUserInfo();
  7950. +       }
  7951. +   }
  7952. +
  7953. +   public static void finishEvent()
  7954. +   {
  7955. +       if (!finishEventOk())
  7956. +       {
  7957. +           if (Config.DEBUG)
  7958. +               _log.log(Level.FINER, "TvT Engine[finishEvent]: finishEventOk() = false");
  7959. +           return;
  7960. +       }
  7961. +
  7962. +       _started = false;
  7963. +       unspawnEventNpc();
  7964. +       processTopTeam();
  7965. +
  7966. +       if (_topKills == 0)
  7967. +           AnnounceToPlayers(true, _eventName + "No team wins the match(nobody killed).");
  7968. +       else
  7969. +       {
  7970. +           AnnounceToPlayers(true, _eventName + " " + _topTeam + "'s win the match! " + _topKills + " kills.");
  7971. +           rewardTeam(_topTeam);
  7972. +           playKneelAnimation(_topTeam);
  7973. +       }
  7974. +
  7975. +       if (Config.TVT_ANNOUNCE_TEAM_STATS)
  7976. +       {
  7977. +           AnnounceToPlayers(true, _eventName + " Team Statistics:");
  7978. +           for (String team : _teams)
  7979. +           {
  7980. +               int _kills = teamKillsCount(team);
  7981. +               AnnounceToPlayers(true, "Team: " + team + " - Kills: " + _kills);
  7982. +           }
  7983. +       }
  7984. +
  7985. +       teleportFinish();
  7986. +   }
  7987. +
  7988. +   // show losers and winners animations
  7989. +   public static void playKneelAnimation(String teamName)
  7990. +   {
  7991. +       for (Player player : _players)
  7992. +       {
  7993. +           if (player != null)
  7994. +           {
  7995. +               if (!player._teamNameTvT.equals(teamName))
  7996. +                   player.broadcastPacket(new SocialAction(player, 7),2000);
  7997. +               else if (player._teamNameTvT.equals(teamName))
  7998. +                   player.broadcastPacket(new SocialAction(player, 3),2000);
  7999. +           }
  8000. +       }
  8001. +   }
  8002. +
  8003. +   private static boolean finishEventOk()
  8004. +   {
  8005. +       if (!_started)
  8006. +           return false;
  8007. +
  8008. +       _inProgress = false;
  8009. +       if (Config.TVT_CLOSE_COLISEUM_DOORS)
  8010. +           openColiseumDoors();
  8011. +
  8012. +       return true;
  8013. +   }
  8014. +
  8015. +   public static void processTopTeam()
  8016. +   {
  8017. +       for (String team : _teams)
  8018. +       {
  8019. +           if (teamKillsCount(team) > _topKills)
  8020. +           {
  8021. +               _topTeam = team;
  8022. +               _topKills = teamKillsCount(team);
  8023. +           }
  8024. +       }
  8025. +   }
  8026. +
  8027. +   public static void rewardTeam(String teamName)
  8028. +   {
  8029. +       for (Player player : _players)
  8030. +       {
  8031. +           if (player != null && player.isOnline() && player._inEventTvT)
  8032. +           {
  8033. +               if (player._teamNameTvT.equals(teamName) && (player._countTvTkills > 0 || Config.TVT_PRICE_NO_KILLS))
  8034. +               {
  8035. +                   player.addItem("TvT: " + _eventName, _rewardId, _rewardAmount, player, true);
  8036. +
  8037. +                   _playerWon = 1;
  8038. +
  8039. +                   NpcHtmlMessage nhm = new NpcHtmlMessage(5);
  8040. +                   StringBuilder replyMSG = new StringBuilder("");
  8041. +
  8042. +                   replyMSG.append("<html><body>Your team wins the event. Look in your inventory for the reward.</body></html>");
  8043. +
  8044. +                   nhm.setHtml(replyMSG.toString());
  8045. +                   player.sendPacket(nhm);
  8046. +
  8047. +                   // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  8048. +                   player.sendPacket(ActionFailed.STATIC_PACKET);
  8049. +               }
  8050. +           }
  8051. +       }
  8052. +   }
  8053. +
  8054. +   public static void abortEvent()
  8055. +   {
  8056. +       if (!_joining && !_teleport && !_started)
  8057. +           return;
  8058. +       if (_joining && !_teleport && !_started)
  8059. +       {
  8060. +           unspawnEventNpc();
  8061. +           cleanTvT();
  8062. +           _joining = false;
  8063. +           AnnounceToPlayers(true, _eventName + "Match aborted!");
  8064. +           return;
  8065. +       }
  8066. +       _joining = false;
  8067. +       _teleport = false;
  8068. +       _started = false;
  8069. +       _inProgress = false;
  8070. +       unspawnEventNpc();
  8071. +       AnnounceToPlayers(true, _eventName + "Match aborted!");
  8072. +       teleportFinish();
  8073. +   }
  8074. +
  8075. +   public static void sit()
  8076. +   {
  8077. +       _sitForced = !_sitForced;
  8078. +
  8079. +       for (Player player : _players)
  8080. +       {
  8081. +           if (player != null)
  8082. +           {
  8083. +               if (_sitForced)
  8084. +               {
  8085. +                   player.stopMove(null);
  8086. +                   player.abortAttack();
  8087. +                   player.abortCast();
  8088. +
  8089. +                   if (!player.isSitting())
  8090. +                       player.sitDown();
  8091. +               }
  8092. +               else
  8093. +               {
  8094. +                   if (player.isSitting())
  8095. +                       player.standUp();
  8096. +               }
  8097. +           }
  8098. +       }
  8099. +   }
  8100. +
  8101. +   public static void dumpData()
  8102. +   {
  8103. +       _log.info("");
  8104. +       _log.info("");
  8105. +
  8106. +       if (!_joining && !_teleport && !_started)
  8107. +       {
  8108. +           _log.info("<<---------------------------------->>");
  8109. +           _log.info(">> TvT Engine infos dump (INACTIVE) <<");
  8110. +           _log.info("<<--^----^^-----^----^^------^^----->>");
  8111. +       }
  8112. +       else if (_joining && !_teleport && !_started)
  8113. +       {
  8114. +           _log.info("<<--------------------------------->>");
  8115. +           _log.info(">> TvT Engine infos dump (JOINING) <<");
  8116. +           _log.info("<<--^----^^-----^----^^------^----->>");
  8117. +       }
  8118. +       else if (!_joining && _teleport && !_started)
  8119. +       {
  8120. +           _log.info("<<---------------------------------->>");
  8121. +           _log.info(">> TvT Engine infos dump (TELEPORT) <<");
  8122. +           _log.info("<<--^----^^-----^----^^------^^----->>");
  8123. +       }
  8124. +       else if (!_joining && !_teleport && _started)
  8125. +       {
  8126. +           _log.info("<<--------------------------------->>");
  8127. +           _log.info(">> TvT Engine infos dump (STARTED) <<");
  8128. +           _log.info("<<--^----^^-----^----^^------^----->>");
  8129. +       }
  8130. +
  8131. +       _log.info("Name: " + _eventName);
  8132. +       _log.info("Desc: " + _eventDesc);
  8133. +       _log.info("Join location: " + _joiningLocationName);
  8134. +       _log.info("Min lvl: " + _minlvl);
  8135. +       _log.info("Max lvl: " + _maxlvl);
  8136. +       _log.info("");
  8137. +       _log.info("##########################");
  8138. +       _log.info("# _teams(Vector<String>) #");
  8139. +       _log.info("##########################");
  8140. +
  8141. +       for (String team : _teams)
  8142. +           _log.info(team + " Kills Done :" + _teamKillsCount.get(_teams.indexOf(team)));
  8143. +
  8144. +       if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  8145. +       {
  8146. +           _log.info("");
  8147. +           _log.info("#########################################");
  8148. +           _log.info("# _playersShuffle(Vector<Player>) #");
  8149. +           _log.info("#########################################");
  8150. +
  8151. +           for (Player player : _playersShuffle)
  8152. +           {
  8153. +               if (player != null)
  8154. +                   _log.info("Name: " + player.getName());
  8155. +           }
  8156. +       }
  8157. +
  8158. +       _log.info("");
  8159. +       _log.info("##################################");
  8160. +       _log.info("# _players(Vector<Player>) #");
  8161. +       _log.info("##################################");
  8162. +
  8163. +       for (Player player : _players)
  8164. +       {
  8165. +           if (player != null)
  8166. +               _log.info("Name: " + player.getName() + "   Team: " + player._teamNameTvT + "  Kills Done:" + player._countTvTkills);
  8167. +       }
  8168. +
  8169. +       _log.info("");
  8170. +       _log.info("#####################################################################");
  8171. +       _log.info("# _savePlayers(Vector<String>) and _savePlayerTeams(Vector<String>) #");
  8172. +       _log.info("#####################################################################");
  8173. +
  8174. +       for (String player : _savePlayers)
  8175. +           _log.info("Name: " + player + " Team: " + _savePlayerTeams.get(_savePlayers.indexOf(player)));
  8176. +
  8177. +       _log.info("");
  8178. +       _log.info("");
  8179. +   }
  8180. +
  8181. +   public static void loadData()
  8182. +   {
  8183. +       _eventName = "";
  8184. +       _eventDesc = "";
  8185. +       _topTeam = "";
  8186. +       _joiningLocationName = "";
  8187. +       _teams = new ArrayList<>();
  8188. +       _savePlayers = new ArrayList<>();
  8189. +       _savePlayerTeams = new ArrayList<>();
  8190. +       _players = new ArrayList<>();
  8191. +       _playersShuffle = new ArrayList<>();
  8192. +       _teamPlayersCount = new ArrayList<>();
  8193. +       _teamKillsCount = new ArrayList<>();
  8194. +       _teamColors = new ArrayList<>();
  8195. +       _teamsX = new ArrayList<>();
  8196. +       _teamsY = new ArrayList<>();
  8197. +       _teamsZ = new ArrayList<>();
  8198. +       _joining = false;
  8199. +       _teleport = false;
  8200. +       _started = false;
  8201. +       _sitForced = false;
  8202. +       _npcId = 0;
  8203. +       _npcX = 0;
  8204. +       _npcY = 0;
  8205. +       _npcZ = 0;
  8206. +       _npcHeading = 0;
  8207. +       _rewardId = 0;
  8208. +       _rewardAmount = 0;
  8209. +       _topKills = 0;
  8210. +       _minlvl = 0;
  8211. +       _maxlvl = 0;
  8212. +       _joinTime = 0;
  8213. +       _eventTime = 0;
  8214. +       _minPlayers = 0;
  8215. +       _maxPlayers = 0;
  8216. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  8217. +       {
  8218. +           PreparedStatement statement;
  8219. +           ResultSet rs;
  8220. +           statement = con.prepareStatement("SELECT * FROM tvt");
  8221. +           rs = statement.executeQuery();
  8222. +
  8223. +           int teams = 0;
  8224. +
  8225. +           while (rs.next())
  8226. +           {
  8227. +               _eventName = rs.getString("eventName");
  8228. +               _eventDesc = rs.getString("eventDesc");
  8229. +               _joiningLocationName = rs.getString("joiningLocation");
  8230. +               _minlvl = rs.getInt("minlvl");
  8231. +               _maxlvl = rs.getInt("maxlvl");
  8232. +               _npcId = rs.getInt("npcId");
  8233. +               _npcX = rs.getInt("npcX");
  8234. +               _npcY = rs.getInt("npcY");
  8235. +               _npcZ = rs.getInt("npcZ");
  8236. +               _npcHeading = rs.getInt("npcHeading");
  8237. +               _rewardId = rs.getInt("rewardId");
  8238. +               _rewardAmount = rs.getInt("rewardAmount");
  8239. +               teams = rs.getInt("teamsCount");
  8240. +               _joinTime = rs.getInt("joinTime");
  8241. +               _eventTime = rs.getInt("eventTime");
  8242. +               _minPlayers = rs.getInt("minPlayers");
  8243. +               _maxPlayers = rs.getInt("maxPlayers");
  8244. +           }
  8245. +           rs.close();
  8246. +           statement.close();
  8247. +
  8248. +           int index = -1;
  8249. +           if (teams > 0)
  8250. +               index = 0;
  8251. +           while (index < teams && index > -1)
  8252. +           {
  8253. +               statement = con.prepareStatement("SELECT * FROM tvt_teams WHERE teamId=?");
  8254. +               statement.setInt(1, index);
  8255. +               rs = statement.executeQuery();
  8256. +               while (rs.next())
  8257. +               {
  8258. +                   _teams.add(rs.getString("teamName"));
  8259. +                   _teamPlayersCount.add(0);
  8260. +                   _teamKillsCount.add(0);
  8261. +                   _teamColors.add(0);
  8262. +                   _teamsX.add(0);
  8263. +                   _teamsY.add(0);
  8264. +                   _teamsZ.add(0);
  8265. +                   _teamsX.set(index, rs.getInt("teamX"));
  8266. +                   _teamsY.set(index, rs.getInt("teamY"));
  8267. +                   _teamsZ.set(index, rs.getInt("teamZ"));
  8268. +                   _teamColors.set(index, rs.getInt("teamColor"));
  8269. +               }
  8270. +               index++;
  8271. +               rs.close();
  8272. +               statement.close();
  8273. +           }
  8274. +       }
  8275. +       catch (Exception e)
  8276. +       {
  8277. +           _log.warning(TvT.class.getSimpleName() + ":  Exception: TvT.loadData(): ");
  8278. +           if (Config.DEVELOPER)
  8279. +               e.printStackTrace();
  8280. +       }
  8281. +   }
  8282. +
  8283. +   public static void saveData()
  8284. +   {
  8285. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  8286. +       {
  8287. +           PreparedStatement statement;
  8288. +
  8289. +           statement = con.prepareStatement("DELETE FROM tvt");
  8290. +           statement.execute();
  8291. +           statement.close();
  8292. +
  8293. +           statement = con.prepareStatement("INSERT INTO tvt (eventName, eventDesc, joiningLocation, minlvl, maxlvl, npcId, npcX, npcY, npcZ, npcHeading, rewardId, rewardAmount, teamsCount, joinTime, eventTime, minPlayers, maxPlayers) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  8294. +           statement.setString(1, _eventName);
  8295. +           statement.setString(2, _eventDesc);
  8296. +           statement.setString(3, _joiningLocationName);
  8297. +           statement.setInt(4, _minlvl);
  8298. +           statement.setInt(5, _maxlvl);
  8299. +           statement.setInt(6, _npcId);
  8300. +           statement.setInt(7, _npcX);
  8301. +           statement.setInt(8, _npcY);
  8302. +           statement.setInt(9, _npcZ);
  8303. +           statement.setInt(10, _npcHeading);
  8304. +           statement.setInt(11, _rewardId);
  8305. +           statement.setInt(12, _rewardAmount);
  8306. +           statement.setInt(13, _teams.size());
  8307. +           statement.setInt(14, _joinTime);
  8308. +           statement.setInt(15, _eventTime);
  8309. +           statement.setInt(16, _minPlayers);
  8310. +           statement.setInt(17, _maxPlayers);
  8311. +           statement.execute();
  8312. +           statement.close();
  8313. +
  8314. +           statement = con.prepareStatement("DELETE FROM tvt_teams");
  8315. +           statement.execute();
  8316. +           statement.close();
  8317. +
  8318. +           for (String teamName : _teams)
  8319. +           {
  8320. +               int index = _teams.indexOf(teamName);
  8321. +
  8322. +               if (index == -1)
  8323. +                   return;
  8324. +               statement = con.prepareStatement("INSERT INTO tvt_teams (teamId ,teamName, teamX, teamY, teamZ, teamColor) VALUES (?, ?, ?, ?, ?, ?)");
  8325. +               statement.setInt(1, index);
  8326. +               statement.setString(2, teamName);
  8327. +               statement.setInt(3, _teamsX.get(index));
  8328. +               statement.setInt(4, _teamsY.get(index));
  8329. +               statement.setInt(5, _teamsZ.get(index));
  8330. +               statement.setInt(6, _teamColors.get(index));
  8331. +               statement.execute();
  8332. +               statement.close();
  8333. +           }
  8334. +       }
  8335. +       catch (Exception e)
  8336. +       {
  8337. +           _log.warning(TvT.class.getSimpleName() + ":  Exception: TvT.saveData(): ");
  8338. +           if (Config.DEVELOPER)
  8339. +               e.printStackTrace();
  8340. +       }
  8341. +   }
  8342. +
  8343. +   public static void showEventHtml(Player eventPlayer, String objectId)
  8344. +   {
  8345. +       try
  8346. +       {
  8347. +           NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  8348. +
  8349. +           StringBuilder replyMSG = new StringBuilder("<html><body>");
  8350. +           replyMSG.append("TvT Match<br><br><br>");
  8351. +           replyMSG.append("Current event...<br1>");
  8352. +           replyMSG.append("    ... name:&nbsp;<font color=\"00FF00\">" + _eventName + "</font><br1>");
  8353. +           replyMSG.append("    ... description:&nbsp;<font color=\"00FF00\">" + _eventDesc + "</font><br>");
  8354. +           if (Config.TVT_ANNOUNCE_REWARD)
  8355. +               replyMSG.append("    ... reward: (" + _rewardAmount + ") " + ItemTable.getInstance().getTemplate(_rewardId).getName() + "<br>");
  8356. +
  8357. +           if (!_started && !_joining)
  8358. +               replyMSG.append("<center>Wait till the admin/gm start the participation.</center>");
  8359. +           else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && !checkMaxPlayers(_playersShuffle.size()))
  8360. +           {
  8361. +               if (!TvT._started)
  8362. +                   replyMSG.append("<font color=\"FFFF00\">The event has reached its maximum capacity.</font><br>Keep checking, someone may crit and you can steal their spot.");
  8363. +           }
  8364. +           else if (eventPlayer.isCursedWeaponEquipped() && !Config.TVT_JOIN_CURSED)
  8365. +               replyMSG.append("<font color=\"FFFF00\">You can't participate in this event with a cursed Weapon.</font><br>");
  8366. +           else if (!_started && _joining && eventPlayer.getLevel() >= _minlvl && eventPlayer.getLevel() <= _maxlvl)
  8367. +           {
  8368. +               if (_players.contains(eventPlayer) || checkShufflePlayers(eventPlayer))
  8369. +               {
  8370. +                   if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE"))
  8371. +                       replyMSG.append("You are already participating in team <font color=\"LEVEL\">" + eventPlayer._teamNameTvT + "</font><br><br>");
  8372. +                   else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  8373. +                       replyMSG.append("You are already participating!<br><br>");
  8374. +
  8375. +                   replyMSG.append("<table border=\"0\"><tr>");
  8376. +                   replyMSG.append("<td width=\"200\">Wait till event start or</td>");
  8377. +                   replyMSG.append("<td width=\"60\"><center><button value=\"remove\" action=\"bypass -h npc_" + objectId + "_tvt_player_leave\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></td>");
  8378. +                   replyMSG.append("<td width=\"100\">your participation!</td>");
  8379. +                   replyMSG.append("</tr></table>");
  8380. +               }
  8381. +               else
  8382. +               {
  8383. +                   replyMSG.append("You want to participate in the event?<br><br>");
  8384. +                   replyMSG.append("<td width=\"200\">Your level : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font></td><br>");
  8385. +                   replyMSG.append("<td width=\"200\">Min level : <font color=\"00FF00\">" + _minlvl + "</font></td><br>");
  8386. +                   replyMSG.append("<td width=\"200\">Max level : <font color=\"00FF00\">" + _maxlvl + "</font></td><br><br>");
  8387. +
  8388. +                   if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE"))
  8389. +                   {
  8390. +                       replyMSG.append("<center><table border=\"0\">");
  8391. +
  8392. +                       for (String team : _teams)
  8393. +                       {
  8394. +                           replyMSG.append("<tr><td width=\"100\"><font color=\"LEVEL\">" + team + "</font>&nbsp;(" + teamPlayersCount(team) + " joined)</td>");
  8395. +                           replyMSG.append("<td width=\"60\"><button value=\"Join\" action=\"bypass -h npc_" + objectId + "_tvt_player_join " + team + "\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  8396. +                       }
  8397. +
  8398. +                       replyMSG.append("</table></center>");
  8399. +                   }
  8400. +                   else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  8401. +                   {
  8402. +                       replyMSG.append("<center><table border=\"0\">");
  8403. +
  8404. +                       for (String team : _teams)
  8405. +                           replyMSG.append("<tr><td width=\"100\"><font color=\"LEVEL\">" + team + "</font></td>");
  8406. +
  8407. +                       replyMSG.append("</table></center><br>");
  8408. +
  8409. +                       replyMSG.append("<button value=\"Join\" action=\"bypass -h npc_" + objectId + "_tvt_player_join eventShuffle\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  8410. +                       replyMSG.append("Teams will be randomly generated!");
  8411. +                   }
  8412. +               }
  8413. +           }
  8414. +           else if (_started && !_joining)
  8415. +               replyMSG.append("<center>TvT match is in progress.</center>");
  8416. +           else if (eventPlayer.getLevel() < _minlvl || eventPlayer.getLevel() >= _maxlvl)
  8417. +           {
  8418. +               replyMSG.append("Your level : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font><br>");
  8419. +               replyMSG.append("Min level : <font color=\"00FF00\">" + _minlvl + "</font><br>");
  8420. +               replyMSG.append("Max level : <font color=\"00FF00\">" + _maxlvl + "</font><br><br>");
  8421. +               replyMSG.append("<font color=\"FFFF00\">You can't participate in this event.</font><br>");
  8422. +           }
  8423. +           // Show how many players joined & how many are still needed to join
  8424. +           replyMSG.append("<br>There are " + _playersShuffle.size() + " player(s) participating in this event.<br>");
  8425. +           if (_joining)
  8426. +           {
  8427. +               if (_playersShuffle.size() < _minPlayers)
  8428. +               {
  8429. +                   int playersNeeded = _minPlayers - _playersShuffle.size();
  8430. +                   replyMSG.append("The event will not start unless " + playersNeeded + " more player(s) joins!");
  8431. +               }
  8432. +           }
  8433. +           replyMSG.append("</body></html>");
  8434. +           adminReply.setHtml(replyMSG.toString());
  8435. +           eventPlayer.sendPacket(adminReply);
  8436. +
  8437. +           // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  8438. +           eventPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  8439. +       }
  8440. +       catch (Exception e)
  8441. +       {
  8442. +           _log.warning(TvT.class.getSimpleName() + ":  TvT Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception");
  8443. +           if (Config.DEVELOPER)
  8444. +               e.printStackTrace();
  8445. +       }
  8446. +   }
  8447. +
  8448. +   public static void addPlayer(Player player, String teamName)
  8449. +   {
  8450. +       if (!addPlayerOk(teamName, player))
  8451. +           return;
  8452. +
  8453. +       if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE"))
  8454. +       {
  8455. +           player._teamNameTvT = teamName;
  8456. +           _players.add(player);
  8457. +           setTeamPlayersCount(teamName, teamPlayersCount(teamName) + 1);
  8458. +       }
  8459. +       else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  8460. +           _playersShuffle.add(player);
  8461. +
  8462. +       player._inEventTvT = true;
  8463. +       player._countTvTkills = 0;
  8464. +
  8465. +       // notify player that he signed up in event
  8466. +       NpcHtmlMessage html = new NpcHtmlMessage(1);
  8467. +       html.setFile("data/html/mods/Participation.htm");
  8468. +       player.sendPacket(html);
  8469. +
  8470. +       if (Config.TVT_ANNOUNCE_SIGNUPS)
  8471. +           Broadcast.announceToOnlinePlayers("Player " + player.getName() + " has Signed Up in TvT!");
  8472. +   }
  8473. +
  8474. +   public synchronized static void removeOfflinePlayers()
  8475. +   {
  8476. +       try
  8477. +       {
  8478. +           if (_playersShuffle == null || _playersShuffle.isEmpty())
  8479. +               return;
  8480. +           for (Player player : _playersShuffle)
  8481. +           {
  8482. +               if (player == null)
  8483. +                   _playersShuffle.remove(player);
  8484. +               else if (player.isOnline() || player.isInJail())
  8485. +                   removePlayer(player);
  8486. +               if (_playersShuffle.size() == 0 || _playersShuffle.isEmpty())
  8487. +                   break;
  8488. +           }
  8489. +       }
  8490. +       catch (Exception e)
  8491. +       {
  8492. +           _log.warning(TvT.class.getSimpleName() + ": TVT unknown error");
  8493. +           if (Config.DEVELOPER)
  8494. +               e.printStackTrace();
  8495. +       }
  8496. +   }
  8497. +
  8498. +   public static boolean checkShufflePlayers(Player eventPlayer)
  8499. +   {
  8500. +       try
  8501. +       {
  8502. +           for (Player player : _playersShuffle)
  8503. +           {
  8504. +               if (player == null || player.isOnline())
  8505. +               {
  8506. +                   _playersShuffle.remove(player);
  8507. +                   eventPlayer._inEventTvT = false;
  8508. +                   continue;
  8509. +               }
  8510. +               else if (player.getObjectId() == eventPlayer.getObjectId())
  8511. +               {
  8512. +                   eventPlayer._inEventTvT = true;
  8513. +                   eventPlayer._countTvTkills = 0;
  8514. +                   return true;
  8515. +               }
  8516. +               // this 1 is incase player got new objectid after DC or reconnect
  8517. +               else if (player.getName().equals(eventPlayer.getName()))
  8518. +               {
  8519. +                   _playersShuffle.remove(player);
  8520. +                   _playersShuffle.add(eventPlayer);
  8521. +                   eventPlayer._inEventTvT = true;
  8522. +                   eventPlayer._countTvTkills = 0;
  8523. +                   return true;
  8524. +               }
  8525. +           }
  8526. +       }
  8527. +       catch (Exception e)
  8528. +       {
  8529. +       }
  8530. +       return false;
  8531. +   }
  8532. +
  8533. +   public static boolean addPlayerOk(String teamName, Player eventPlayer)
  8534. +   {
  8535. +       try
  8536. +       {
  8537. +           if(OlympiadManager.getInstance().isRegisteredInComp(eventPlayer) || eventPlayer.isInOlympiadMode() || eventPlayer.getOlympiadGameId() >0)
  8538. +           {
  8539. +               eventPlayer.sendMessage("You can't register while you are in olympiad!");
  8540. +               return false;
  8541. +           }
  8542. +           if (checkShufflePlayers(eventPlayer) || eventPlayer._inEventTvT)
  8543. +           {
  8544. +               eventPlayer.sendMessage("You are already participating in the event!");
  8545. +               return false;
  8546. +           }
  8547. +           if (eventPlayer._inEventCTF || eventPlayer._inEventDM || eventPlayer._inEventVIP)
  8548. +           {
  8549. +               eventPlayer.sendMessage("You are already participating in another event!");
  8550. +               return false;
  8551. +           }
  8552. +
  8553. +           for (Player player : _players)
  8554. +           {
  8555. +               if (player.getObjectId() == eventPlayer.getObjectId())
  8556. +               {
  8557. +                   eventPlayer.sendMessage("You are already participating in the event!");
  8558. +                   return false;
  8559. +               }
  8560. +               else if (player.getName() == eventPlayer.getName())
  8561. +               {
  8562. +                   eventPlayer.sendMessage("You are already participating in the event!");
  8563. +                   return false;
  8564. +               }
  8565. +           }
  8566. +           if (_players.contains(eventPlayer))
  8567. +           {
  8568. +               eventPlayer.sendMessage("You are already participating in the event!");
  8569. +               return false;
  8570. +           }
  8571. +           if (CTF._savePlayers.contains(eventPlayer.getName()))
  8572. +           {
  8573. +               eventPlayer.sendMessage("You are already participating in another event!");
  8574. +               return false;
  8575. +           }
  8576. +       }
  8577. +       catch (Exception e)
  8578. +       {
  8579. +           _log.warning(TvT.class.getSimpleName() + ":  TvT Engine exception: ");
  8580. +           if (Config.DEVELOPER)
  8581. +               e.printStackTrace();
  8582. +       }
  8583. +
  8584. +       if (Config.TVT_EVEN_TEAMS.equals("NO"))
  8585. +           return true;
  8586. +       else if (Config.TVT_EVEN_TEAMS.equals("BALANCE"))
  8587. +       {
  8588. +           boolean allTeamsEqual = true;
  8589. +           int countBefore = -1;
  8590. +
  8591. +           for (int playersCount : _teamPlayersCount)
  8592. +           {
  8593. +               if (countBefore == -1)
  8594. +                   countBefore = playersCount;
  8595. +
  8596. +               if (countBefore != playersCount)
  8597. +               {
  8598. +                   allTeamsEqual = false;
  8599. +                   break;
  8600. +               }
  8601. +
  8602. +               countBefore = playersCount;
  8603. +           }
  8604. +
  8605. +           if (allTeamsEqual)
  8606. +               return true;
  8607. +
  8608. +           countBefore = Integer.MAX_VALUE;
  8609. +
  8610. +           for (int teamPlayerCount : _teamPlayersCount)
  8611. +           {
  8612. +               if (teamPlayerCount < countBefore)
  8613. +                   countBefore = teamPlayerCount;
  8614. +           }
  8615. +
  8616. +           List<String> joinableTeams = new ArrayList<>();
  8617. +
  8618. +           for (String team : _teams)
  8619. +           {
  8620. +               if (teamPlayersCount(team) == countBefore)
  8621. +                   joinableTeams.add(team);
  8622. +           }
  8623. +
  8624. +           if (joinableTeams.contains(teamName))
  8625. +               return true;
  8626. +       }
  8627. +       else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  8628. +           return true;
  8629. +
  8630. +       eventPlayer.sendMessage("Too many players in team \"" + teamName + "\"");
  8631. +       return false;
  8632. +   }
  8633. +
  8634. +   public static synchronized void addDisconnectedPlayer(Player player)
  8635. +   {
  8636. +       if ((Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && (_teleport || _started)) || (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE") && (_teleport || _started)))
  8637. +       {
  8638. +           if (Config.TVT_ON_START_REMOVE_ALL_EFFECTS)
  8639. +           {
  8640. +               for (L2Effect e : player.getAllEffects())
  8641. +               {
  8642. +                   if (e != null)
  8643. +                       e.exit();
  8644. +               }
  8645. +           }
  8646. +
  8647. +           player._teamNameTvT = _savePlayerTeams.get(_savePlayers.indexOf(player.getName()));
  8648. +           for (Player p : _players)
  8649. +           {
  8650. +               if (p == null)
  8651. +                   continue;
  8652. +               // check by name incase player got new objectId
  8653. +               else if (p.getName().equals(player.getName()))
  8654. +               {
  8655. +                   player._originalNameColorTvT = player.getAppearance().getNameColor();
  8656. +                   player._originalTitleTvT = player.getTitle();
  8657. +                   player._originalKarmaTvT = player.getKarma();
  8658. +                   player._inEventTvT = true;
  8659. +                   player._countTvTkills = p._countTvTkills;
  8660. +                   _players.remove(p); // removing old object id from vector
  8661. +                   _players.add(player); // adding new objectId to vector
  8662. +                   break;
  8663. +               }
  8664. +           }
  8665. +
  8666. +           player.getAppearance().setNameColor(_teamColors.get(_teams.indexOf(player._teamNameTvT)));
  8667. +           player.setKarma(0);
  8668. +           if (Config.TVT_AURA)
  8669. +           {
  8670. +               if (_teams.size() >= 2)
  8671. +                   player.setTeam(_teams.indexOf(player._teamNameTvT) + 1);
  8672. +           }
  8673. +           player.broadcastUserInfo();
  8674. +           player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameTvT)), _teamsY.get(_teams.indexOf(player._teamNameTvT)), _teamsZ.get(_teams.indexOf(player._teamNameTvT)), 0);
  8675. +       }
  8676. +   }
  8677. +
  8678. +   public static void removePlayer(Player player)
  8679. +   {
  8680. +       if (player._inEventTvT)
  8681. +       {
  8682. +           if (!_joining)
  8683. +           {
  8684. +               player.getAppearance().setNameColor(player._originalNameColorTvT);
  8685. +               player.setTitle(player._originalTitleTvT);
  8686. +               player.setKarma(player._originalKarmaTvT);
  8687. +               if (Config.TVT_AURA)
  8688. +               {
  8689. +                   if (_teams.size() >= 2)
  8690. +                       player.setTeam(0);// clear aura :P
  8691. +               }
  8692. +               player.broadcastUserInfo();
  8693. +           }
  8694. +           player._teamNameTvT = "";
  8695. +           player._countTvTkills = 0;
  8696. +           player._inEventTvT = false;
  8697. +
  8698. +           if ((Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE")) && _players.contains(player))
  8699. +           {
  8700. +               setTeamPlayersCount(player._teamNameTvT, teamPlayersCount(player._teamNameTvT) - 1);
  8701. +               _players.remove(player);
  8702. +           }
  8703. +           else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && (!_playersShuffle.isEmpty() && _playersShuffle.contains(player)))
  8704. +               _playersShuffle.remove(player);
  8705. +       }
  8706. +   }
  8707. +
  8708. +   public static void cleanTvT()
  8709. +   {
  8710. +       _log.info("TvT: Cleaning players.");
  8711. +       for (Player player : _players)
  8712. +       {
  8713. +           if (player != null)
  8714. +           {
  8715. +               removePlayer(player);
  8716. +               if (_savePlayers.contains(player.getName()))
  8717. +                   _savePlayers.remove(player.getName());
  8718. +               player._inEventTvT = false;
  8719. +           }
  8720. +       }
  8721. +       if (_playersShuffle != null && !_playersShuffle.isEmpty())
  8722. +       {
  8723. +           for (Player player : _playersShuffle)
  8724. +           {
  8725. +               if (player != null)
  8726. +                   player._inEventTvT = false;
  8727. +           }
  8728. +       }
  8729. +       _log.info("TvT: Cleaning teams.");
  8730. +       for (String team : _teams)
  8731. +       {
  8732. +           int index = _teams.indexOf(team);
  8733. +
  8734. +           _teamPlayersCount.set(index, 0);
  8735. +           _teamKillsCount.set(index, 0);
  8736. +       }
  8737. +
  8738. +       _topKills = 0;
  8739. +       _topTeam = "";
  8740. +       _players.clear();
  8741. +       _playersShuffle.clear();
  8742. +       _savePlayers.clear();
  8743. +       _savePlayerTeams.clear();
  8744. +       _log.info("Cleaning TvT done.");
  8745. +   }
  8746. +
  8747. +   public static void unspawnEventNpc()
  8748. +   {
  8749. +       if (_npcSpawn == null)
  8750. +           return;
  8751. +
  8752. +       _npcSpawn.getNpc().deleteMe();
  8753. +       _npcSpawn.setRespawnState(false);
  8754. +       SpawnTable.getInstance().deleteSpawn(_npcSpawn, true);
  8755. +   }
  8756. +
  8757. +   public static void teleportFinish()
  8758. +   {
  8759. +       AnnounceToPlayers(false, _eventName + "Teleport back to participation NPC in 20 seconds!");
  8760. +
  8761. +       ThreadPool.schedule(new Runnable()
  8762. +       {
  8763. +           @Override
  8764. +           public void run()
  8765. +           {
  8766. +               for (Player player : _players)
  8767. +               {
  8768. +                   if (player != null)
  8769. +                   {
  8770. +                       if (player.isOnline())
  8771. +                           player.teleToLocation(_npcX, _npcY, _npcZ, 0);
  8772. +                       else
  8773. +                       {
  8774. +                           try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  8775. +                           {
  8776. +                               PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=? WHERE char_name=?");
  8777. +                               statement.setInt(1, _npcX);
  8778. +                               statement.setInt(2, _npcY);
  8779. +                               statement.setInt(3, _npcZ);
  8780. +                               statement.setString(4, player.getName());
  8781. +                               statement.execute();
  8782. +                               statement.close();
  8783. +                           }
  8784. +                           catch (SQLException se)
  8785. +                           {
  8786. +                               _log.warning(TvT.class.getSimpleName() + ": " + se);
  8787. +                           }
  8788. +                       }
  8789. +                   }
  8790. +               }
  8791. +               _log.info("TvT: Teleport done.");
  8792. +               cleanTvT();
  8793. +           }
  8794. +       }, 20000);
  8795. +   }
  8796. +
  8797. +   public static int teamKillsCount(String teamName)
  8798. +   {
  8799. +       int index = _teams.indexOf(teamName);
  8800. +
  8801. +       if (index == -1)
  8802. +           return -1;
  8803. +
  8804. +       return _teamKillsCount.get(index);
  8805. +   }
  8806. +
  8807. +   public static void setTeamKillsCount(String teamName, int teamKillsCount)
  8808. +   {
  8809. +       int index = _teams.indexOf(teamName);
  8810. +
  8811. +       if (index == -1)
  8812. +           return;
  8813. +
  8814. +       _teamKillsCount.set(index, teamKillsCount);
  8815. +   }
  8816. +
  8817. +   public static int teamPlayersCount(String teamName)
  8818. +   {
  8819. +       int index = _teams.indexOf(teamName);
  8820. +
  8821. +       if (index == -1)
  8822. +           return -1;
  8823. +
  8824. +       return _teamPlayersCount.get(index);
  8825. +   }
  8826. +
  8827. +   public static void setTeamPlayersCount(String teamName, int teamPlayersCount)
  8828. +   {
  8829. +       int index = _teams.indexOf(teamName);
  8830. +
  8831. +       if (index == -1)
  8832. +           return;
  8833. +
  8834. +       _teamPlayersCount.set(index, teamPlayersCount);
  8835. +   }
  8836. +
  8837. +   public static long _intervalBetweenMatchs = 0;
  8838. +
  8839. +   /**
  8840. +    * The type of TvT Event
  8841. +    * 1 = Manual
  8842. +    * 2 = Automatic
  8843. +    */
  8844. +   public static int _eventType = 0;
  8845. +
  8846. +   private static boolean _inProgress = false;
  8847. +   private static boolean _finished = false;
  8848. +   private static boolean _aborted = false;
  8849. +
  8850. +   /**
  8851. +    * Opens All Coliseum Doors
  8852. +    */
  8853. +   private static void closeColiseumDoors()
  8854. +   {
  8855. +       Broadcast.announceToOnlinePlayers("Closing Coliseum Doors, TvT event has just started !");
  8856. +       DoorTable.getInstance().getDoor(24190001).closeMe();// west gate out
  8857. +       DoorTable.getInstance().getDoor(24190002).closeMe();// west gate in
  8858. +       DoorTable.getInstance().getDoor(24190003).closeMe();// east gate out
  8859. +       DoorTable.getInstance().getDoor(24190004).closeMe();// east gate in
  8860. +
  8861. +       try
  8862. +       {
  8863. +           // just to give a lil delay :P
  8864. +           Thread.sleep(20);
  8865. +       }
  8866. +       catch (InterruptedException ie)
  8867. +       {
  8868. +           _log.warning(TvT.class.getSimpleName() + ": Error, " + ie.getMessage());
  8869. +           if (Config.DEVELOPER)
  8870. +           {
  8871. +               ie.printStackTrace();
  8872. +           }
  8873. +       }
  8874. +   }
  8875. +
  8876. +   /**
  8877. +    * Open all Coliseum Doors
  8878. +    */
  8879. +   private static void openColiseumDoors()
  8880. +   {
  8881. +       Broadcast.announceToOnlinePlayers("Opening Coliseum Doors, TvT event has finished!");
  8882. +       DoorTable.getInstance().getDoor(24190001).openMe();
  8883. +       DoorTable.getInstance().getDoor(24190002).openMe();
  8884. +       DoorTable.getInstance().getDoor(24190003).openMe();
  8885. +       DoorTable.getInstance().getDoor(24190004).openMe();
  8886. +
  8887. +   }
  8888. +   /**
  8889. +    * Returns the event type by name.
  8890. +    *
  8891. +    * @param value
  8892. +    * @return
  8893. +    */
  8894. +   public static String getEventTypeByName(int value)
  8895. +   {
  8896. +       String type = String.valueOf(value);
  8897. +
  8898. +       switch (value)
  8899. +       {
  8900. +           case 0:
  8901. +               type = ("None");
  8902. +           break;
  8903. +
  8904. +           case 1:
  8905. +               type = ("Manual");
  8906. +           break;
  8907. +
  8908. +           case 2:
  8909. +               type = ("Automatic");
  8910. +           break;
  8911. +       }
  8912. +       return type;
  8913. +   }
  8914. +   /**
  8915. +    * just an announcer to send termination messages
  8916. +    */
  8917. +   public static void sendFinalMessages()
  8918. +   {
  8919. +       if (_finished && !_aborted)
  8920. +           Broadcast.announceToOnlinePlayers("TvT: Thank you For Participating At, " + "TVT Event.");
  8921. +   }
  8922. +}
  8923. \ No newline at end of file
  8924. Index: config/events.properties
  8925. ===================================================================
  8926. --- config/events.properties    (revision 2)
  8927. +++ config/events.properties    (working copy)
  8928. @@ -1,3 +1,144 @@
  8929. +#==================#
  8930. +#    TVT Event     #
  8931. +#==================#
  8932. +#If yes the event will start automatically the give times
  8933. +TvTAutomatedEvent = True
  8934. +#What times should the event start
  8935. +TvTStartUpTimes = 15:50
  8936. +
  8937. +# Options:
  8938. +# - NO = not even teams.  
  8939. +# - BALANCE : Players can only join team with lowest player count.  
  8940. +# - SHUFFLE : Players can only participate to the event and not direct to a team. Teams will be schuffeled in teleporting teams.  
  8941. +TvTEvenTeams = SHUFFLE
  8942. +
  8943. +# players there not participated in tvt can target tvt participants?
  8944. +TvTAllowInterference = False
  8945. +
  8946. +# tvt participants can use potions?
  8947. +TvTAllowPotions = False
  8948. +
  8949. +# tvt participants can summon by item?
  8950. +TvTAllowSummon = False
  8951. +
  8952. +# remove all effects of tvt participants on event start?
  8953. +TvTOnStartRemoveAllEffects = True
  8954. +
  8955. +# unsummon pet of tvt participants on event start?
  8956. +TvTOnStartUnsummonPet = True
  8957. +
  8958. +# on revive participants regain full hp/mp/cp ?
  8959. +TvTReviveRecovery = True
  8960. +
  8961. +# announce all team statistics
  8962. +TvTAnnounceTeamStats = True
  8963. +
  8964. +# start auto event on server boot?
  8965. +TvTAutoStartUpOnBoot = False
  8966. +
  8967. +# Only reads if "TvTAutoStartUpOnBoot = true"
  8968. +# here you can set the time that server will wait for start first event on boot
  8969. +# default = 10 (time in minutes)
  8970. +FirstEventDelay = 5
  8971. +
  8972. +# we must close coliseum doors on tvt start up?
  8973. +TvTCloseColiseumDoors = True
  8974. +
  8975. +# allow/disallow team1 players to heal enemy team
  8976. +TvTAllowEnemyHealing = False
  8977. +
  8978. +# Same team members can use skills each other?
  8979. +TvTAllowTeamCasting = False
  8980. +
  8981. +# Same team members can attack each other?
  8982. +TvTAllowTeamAttacking = False
  8983. +
  8984. +# if true announce to all players the loc and npc name.
  8985. +TvTAnnounceLocNpc = True
  8986. +
  8987. +# if true announce to all players who is participating.
  8988. +TvTAnnounceSignUp = False
  8989. +
  8990. +# give price with 0 kills
  8991. +TvTPriceNoKills = False
  8992. +
  8993. +# players with cursed weapon are allowed to join ?
  8994. +TvTJoinWithCursedWeapon = True
  8995. +
  8996. +# Delay on revive when dead, NOTE: 20000 equals to 20 seconds, minimum 1000 (1 second)
  8997. +TVTReviveDelay = 20000
  8998. +
  8999. +# place an aura on participants team ?
  9000. +TvTAura = True
  9001. +
  9002. +# announce reward
  9003. +TvTAnnounceReward = True
  9004. +
  9005. +#==================#
  9006. +#    CTF Engine    #
  9007. +#==================#
  9008. +#If yes the event will start automatically the give times
  9009. +CTFAutomatedEvent = True
  9010. +#What times should the event start
  9011. +CTFStartUpTimes = 17:00,18:00,19:00
  9012. +
  9013. +# CTFEvenTeams = NO|BALANCE|SHUFFLE
  9014. +# NO means: not even teams.
  9015. +# BALANCE means: Players can only join team with lowest player count.
  9016. +# SHUFFLE means: Players can only participate to the event and not direct to a team. Teams will be shuffled on teams teleport.
  9017. +CTFEvenTeams = SHUFFLE
  9018. +
  9019. +# Players that are not participating in CTF can target CTF participants?
  9020. +CTFAllowInterference = False
  9021. +
  9022. +# CTF participants can use potion's?
  9023. +CTFAllowPotions = False
  9024. +
  9025. +# CTF participants can summon by item?
  9026. +CTFAllowSummon = False
  9027. +
  9028. +# Remove all effects of CTF participants on event start?
  9029. +CTFOnStartRemoveAllEffects = True
  9030. +
  9031. +# Unsummon pet of CTF participants on event start?
  9032. +CTFOnStartUnsummonPet = True
  9033. +
  9034. +# On revive participants regain full HP/MP/CP?
  9035. +CTFReviveRecovery = False
  9036. +
  9037. +# Announce all team statistics
  9038. +CTFAnnounceTeamStats = False
  9039. +
  9040. +# Announce reward
  9041. +CTFAnnounceReward = False
  9042. +
  9043. +# Players with cursed weapon are allowed to join?
  9044. +CTFJoinWithCursedWeapon = True
  9045. +
  9046. +# Delay on revive when dead, NOTE: 20000 equals to 20 seconds, minimum 1000 (1 second)
  9047. +CTFReviveDelay = 20000
  9048. +
  9049. +#==================#
  9050. +#     DM Engine    #
  9051. +#==================#
  9052. +# players there not participated in DM can target DM participants?
  9053. +DMAllowInterference = True
  9054. +
  9055. +# DM participants can use potion's?
  9056. +DMAllowPotions = False
  9057. +
  9058. +# DM participants can summon by item?
  9059. +DMAllowSummon = False
  9060. +
  9061. +# remove all effects of DM participants on event start?  
  9062. +DMOnStartRemoveAllEffects = True
  9063. +
  9064. +# unsummon pet of DM participants on event start?
  9065. +DMOnStartUnsummonPet = True
  9066. +
  9067. +# Delay on revive when dead, NOTE: 20000 equals to 20 seconds, minimum 1000 (1 second)
  9068. +DMReviveDelay = 20000
  9069. +
  9070.  #=============================================================
  9071.  #          Character Killing Monuments (by paytaly)
  9072.  #=============================================================
  9073. @@ -35,6 +176,10 @@
  9074.  # Default: FFFFFF (white)
  9075.  CKMPKNpcNameColor = FFFFFF
  9076.  
  9077. +# Reward Item Top PvP & Pk
  9078. +RewardItemId = 3470
  9079. +RewardAmmount = 1
  9080. +
  9081.  #=============================================================
  9082.  #                          Olympiad
  9083.  #=============================================================
  9084. Index: java/net/sf/l2j/Config.java
  9085. ===================================================================
  9086. --- java/net/sf/l2j/Config.java (revision 3)
  9087. +++ java/net/sf/l2j/Config.java (working copy)
  9088. @@ -42,6 +42,7 @@
  9089.     // --------------------------------------------------
  9090.     // RandomZone settings
  9091.     // --------------------------------------------------  
  9092. +  
  9093.     public static int REFRESH;
  9094.     public static int RANDOM_RANGE;
  9095.     public static int COORDINATES_X;
  9096. @@ -138,6 +139,61 @@
  9097.     // Events settings
  9098.     // --------------------------------------------------
  9099.    
  9100. +   /** TvT Settings */
  9101. +   public static boolean TVT_ALLOW_AUTOEVENT;
  9102. +   public static String TVT_EVENT_TIMES;
  9103. +   public static boolean TVT_ALLOW_INTERFERENCE;
  9104. +   public static boolean TVT_ALLOW_POTIONS;
  9105. +   public static boolean TVT_ALLOW_SUMMON;
  9106. +   public static boolean TVT_ON_START_REMOVE_ALL_EFFECTS;
  9107. +   public static boolean TVT_ON_START_UNSUMMON_PET;
  9108. +   public static boolean TVT_REVIVE_RECOVERY;
  9109. +   public static boolean TVT_ANNOUNCE_TEAM_STATS;
  9110. +   public static boolean TVT_CLOSE_COLISEUM_DOORS;
  9111. +   public static boolean TVT_ALLOW_ENEMY_HEALING;
  9112. +   public static boolean TVT_ALLOW_TEAM_CASTING;
  9113. +   public static boolean TVT_ALLOW_TEAM_ATTACKING;
  9114. +   public static boolean TVT_ANNOUNCE_REGISTRATION_LOC_NPC;
  9115. +   public static boolean TVT_ANNOUNCE_SIGNUPS;
  9116. +   public static boolean TVT_JOIN_CURSED;
  9117. +   public static boolean TVT_PRICE_NO_KILLS;
  9118. +   public static boolean TVT_AURA;
  9119. +   public static String TVT_EVEN_TEAMS;
  9120. +   public static boolean TVT_ANNOUNCE_REWARD;
  9121. +   public static int FIRST_TVT_DELAY;
  9122. +   public static long TVT_REVIVE_DELAY;
  9123. +  
  9124. +   /**DM Settings */
  9125. +   public static boolean DM_ALLOW_INTERFERENCE;
  9126. +   public static boolean DM_ALLOW_POTIONS;
  9127. +   public static boolean DM_ALLOW_SUMMON;
  9128. +   public static boolean DM_ON_START_REMOVE_ALL_EFFECTS;
  9129. +   public static boolean DM_ON_START_UNSUMMON_PET;
  9130. +   public static boolean ARENA_ENABLED;
  9131. +   public static int ARENA_INTERVAL;
  9132. +   public static int ARENA_REWARD_ID;
  9133. +   public static int ARENA_REWARD_COUNT;
  9134. +   public static boolean FISHERMAN_ENABLED;
  9135. +   public static int FISHERMAN_INTERVAL;
  9136. +   public static int FISHERMAN_REWARD_ID;
  9137. +   public static int FISHERMAN_REWARD_COUNT;
  9138. +   public static long DM_REVIVE_DELAY;
  9139. +  
  9140. +   /** CTF Settings*/
  9141. +   public static boolean ALLOW_CTF_AUTOEVENT;
  9142. +   public static String CTF_EVENT_TIMES;
  9143. +   public static String CTF_EVEN_TEAMS;
  9144. +   public static boolean CTF_ALLOW_INTERFERENCE;
  9145. +   public static boolean CTF_ALLOW_POTIONS;
  9146. +   public static boolean CTF_ALLOW_SUMMON;
  9147. +   public static boolean CTF_ON_START_REMOVE_ALL_EFFECTS;
  9148. +   public static boolean CTF_ON_START_UNSUMMON_PET;
  9149. +   public static boolean CTF_ANNOUNCE_TEAM_STATS;
  9150. +   public static boolean CTF_ANNOUNCE_REWARD;
  9151. +   public static boolean CTF_JOIN_CURSED;
  9152. +   public static boolean CTF_REVIVE_RECOVERY;
  9153. +   public static long CTF_REVIVE_DELAY;
  9154. +  
  9155.     /** Character Killing Monument settings */
  9156.     public static boolean CKM_ENABLED;
  9157.     public static long CKM_CYCLE_LENGTH;
  9158. @@ -149,7 +205,7 @@
  9159.     public static int CKM_PK_NPC_NAME_COLOR;
  9160.     public static int EVENT_MONUMENT_STATUET_REWARD_ID;
  9161.     public static int EVENT_MONUMENT_STATUET_REWARD_AMOUNT;
  9162. -    
  9163. +  
  9164.     /** Olympiad */
  9165.     public static int ALT_OLY_START_TIME;
  9166.     public static int ALT_OLY_MIN;
  9167. @@ -753,7 +809,7 @@
  9168.         }
  9169.         return result;
  9170.     }
  9171. -
  9172. +  
  9173.     /**
  9174.      * Load Random Zone settings.
  9175.      */
  9176. @@ -861,6 +917,66 @@
  9177.     private static final void loadEvents()
  9178.     {
  9179.         final ExProperties events = initProperties(EVENTS_FILE);
  9180. +      
  9181. +       TVT_ALLOW_AUTOEVENT = Boolean.parseBoolean(events.getProperty("TvTAutomatedEvent", "true"));
  9182. +       TVT_EVENT_TIMES= events.getProperty("TvTStartUpTimes", "17:00,18:00,19:00");
  9183. +       FIRST_TVT_DELAY = Integer.parseInt(events.getProperty("FirstEventDelay", "10"));
  9184. +       TVT_AURA = Boolean.parseBoolean(events.getProperty("TvTAura", "true"));
  9185. +       TVT_JOIN_CURSED = Boolean.parseBoolean(events.getProperty("TvTJoinWithCursedWeapon", "true"));
  9186. +       TVT_PRICE_NO_KILLS = Boolean.parseBoolean(events.getProperty("TvTPriceNoKills", "false"));
  9187. +       TVT_ALLOW_ENEMY_HEALING = Boolean.parseBoolean(events.getProperty("TvTAllowEnemyHealing", "false"));
  9188. +       TVT_ALLOW_TEAM_CASTING = Boolean.parseBoolean(events.getProperty("TvTAllowTeamCasting", "false"));
  9189. +       TVT_ALLOW_TEAM_ATTACKING = Boolean.parseBoolean(events.getProperty("TvTAllowTeamAttacking", "false"));
  9190. +       TVT_CLOSE_COLISEUM_DOORS = Boolean.parseBoolean(events.getProperty("TvTCloseColiseumDoors", "false"));
  9191. +       TVT_ALLOW_INTERFERENCE = Boolean.parseBoolean(events.getProperty("TvTAllowInterference", "false"));
  9192. +       TVT_ALLOW_POTIONS = Boolean.parseBoolean(events.getProperty("TvTAllowPotions", "false"));
  9193. +       TVT_ALLOW_SUMMON = Boolean.parseBoolean(events.getProperty("TvTAllowSummon", "false"));
  9194. +       TVT_ON_START_REMOVE_ALL_EFFECTS = Boolean.parseBoolean(events.getProperty("TvTOnStartRemoveAllEffects", "true"));
  9195. +       TVT_ON_START_UNSUMMON_PET = Boolean.parseBoolean(events.getProperty("TvTOnStartUnsummonPet", "true"));
  9196. +       TVT_REVIVE_RECOVERY = Boolean.parseBoolean(events.getProperty("TvTReviveRecovery", "false"));
  9197. +       TVT_ANNOUNCE_TEAM_STATS = Boolean.parseBoolean(events.getProperty("TvTAnnounceTeamStats", "false"));
  9198. +       TVT_EVEN_TEAMS = events.getProperty("TvTEvenTeams", "BALANCE");
  9199. +       TVT_ANNOUNCE_SIGNUPS = Boolean.parseBoolean(events.getProperty("TvTAnnounceSignUp", "false"));
  9200. +       TVT_ANNOUNCE_REGISTRATION_LOC_NPC = Boolean.parseBoolean(events.getProperty("TvTAnnounceLocNpc", "true"));
  9201. +       TVT_ANNOUNCE_TEAM_STATS = Boolean.parseBoolean(events.getProperty("TvTAnnounceTeamStats", "false"));
  9202. +       TVT_ANNOUNCE_REWARD = Boolean.parseBoolean(events.getProperty("TvTAnnounceReward", "false"));
  9203. +       TVT_PRICE_NO_KILLS = Boolean.parseBoolean(events.getProperty("TvTPriceNoKills", "false"));
  9204. +       TVT_JOIN_CURSED = Boolean.parseBoolean(events.getProperty("TvTJoinWithCursedWeapon", "true"));
  9205. +       TVT_REVIVE_DELAY = Long.parseLong(events.getProperty("TVTReviveDelay", "20000"));
  9206. +       if (TVT_REVIVE_DELAY < 1000)
  9207. +       {
  9208. +           TVT_REVIVE_DELAY = 1000; // can't be set less then 1 second
  9209. +       }
  9210. +      
  9211. +       DM_ALLOW_INTERFERENCE = Boolean.parseBoolean(events.getProperty("DMAllowInterference", "false"));
  9212. +       DM_ALLOW_POTIONS = Boolean.parseBoolean(events.getProperty("DMAllowPotions", "false"));
  9213. +       DM_ALLOW_SUMMON = Boolean.parseBoolean(events.getProperty("DMAllowSummon", "false"));
  9214. +       DM_ON_START_REMOVE_ALL_EFFECTS = Boolean.parseBoolean(events.getProperty("DMOnStartRemoveAllEffects", "true"));
  9215. +       DM_ON_START_UNSUMMON_PET = Boolean.parseBoolean(events.getProperty("DMOnStartUnsummonPet", "true"));
  9216. +       DM_REVIVE_DELAY = Long.parseLong(events.getProperty("DMReviveDelay", "20000"));
  9217. +       if (DM_REVIVE_DELAY < 1000)
  9218. +       {
  9219. +           DM_REVIVE_DELAY = 1000; // can't be set less then 1 second
  9220. +       }
  9221. +      
  9222. +       ALLOW_CTF_AUTOEVENT = Boolean.parseBoolean(events.getProperty("CTFAutomatedEvent", "true"));
  9223. +       CTF_EVENT_TIMES= events.getProperty("CTFStartUpTimes", "17:00,18:00,19:00");
  9224. +       CTF_EVEN_TEAMS = events.getProperty("CTFEvenTeams", "BALANCE");
  9225. +       CTF_ALLOW_INTERFERENCE = Boolean.parseBoolean(events.getProperty("CTFAllowInterference", "false"));
  9226. +       CTF_ALLOW_POTIONS = Boolean.parseBoolean(events.getProperty("CTFAllowPotions", "false"));
  9227. +       CTF_ALLOW_SUMMON = Boolean.parseBoolean(events.getProperty("CTFAllowSummon", "false"));
  9228. +       CTF_ON_START_REMOVE_ALL_EFFECTS = Boolean.parseBoolean(events.getProperty("CTFOnStartRemoveAllEffects", "true"));
  9229. +       CTF_ON_START_UNSUMMON_PET = Boolean.parseBoolean(events.getProperty("CTFOnStartUnsummonPet", "true"));
  9230. +       CTF_ANNOUNCE_TEAM_STATS = Boolean.parseBoolean(events.getProperty("CTFAnnounceTeamStats", "false"));
  9231. +       CTF_ANNOUNCE_REWARD = Boolean.parseBoolean(events.getProperty("CTFAnnounceReward", "false"));
  9232. +       CTF_JOIN_CURSED = Boolean.parseBoolean(events.getProperty("CTFJoinWithCursedWeapon", "true"));
  9233. +       CTF_REVIVE_RECOVERY = Boolean.parseBoolean(events.getProperty("CTFReviveRecovery", "false"));
  9234. +       CTF_REVIVE_DELAY = Long.parseLong(events.getProperty("CTFReviveDelay", "20000"));
  9235. +       if (CTF_REVIVE_DELAY < 1000)
  9236. +       {
  9237. +           CTF_REVIVE_DELAY = 1000; // can't be set less then 1 second
  9238. +       }
  9239. +      
  9240.         CKM_ENABLED = events.getProperty("CKMEnabled", false);
  9241.         CKM_CYCLE_LENGTH = events.getProperty("CKMCycleLength", 86400000);
  9242.         CKM_PVP_NPC_TITLE = events.getProperty("CKMPvPNpcTitle", "%kills% PvPs in the last 24h");
  9243. @@ -871,7 +987,7 @@
  9244.         CKM_PK_NPC_NAME_COLOR = Integer.decode("0x" + events.getProperty("CKMPKNpcNameColor", "FFFFFF"));
  9245.         EVENT_MONUMENT_STATUET_REWARD_ID = Integer.parseInt(events.getProperty("RewardItemId", "57"));
  9246.         EVENT_MONUMENT_STATUET_REWARD_AMOUNT = Integer.parseInt(events.getProperty("RewardAmmount", "57"));
  9247. -        
  9248. +      
  9249.         ALT_OLY_START_TIME = events.getProperty("AltOlyStartTime", 18);
  9250.         ALT_OLY_MIN = events.getProperty("AltOlyMin", 0);
  9251.         ALT_OLY_CPERIOD = events.getProperty("AltOlyCPeriod", 21600000);
  9252. @@ -1445,7 +1561,7 @@
  9253.     public static final void loadGameServer()
  9254.     {
  9255.         _log.info("Loading gameserver configuration files.");
  9256. -
  9257. +      
  9258.         // randomzone settings
  9259.         loadRandomZone();
  9260.        
  9261. Index: java/net/sf/l2j/gameserver/model/entity/engine/DM.java
  9262. ===================================================================
  9263. --- java/net/sf/l2j/gameserver/model/entity/engine/DM.java  (revision 0)
  9264. +++ java/net/sf/l2j/gameserver/model/entity/engine/DM.java  (working copy)
  9265. @@ -0,0 +1,700 @@
  9266. +/*
  9267. + * This program is free software: you can redistribute it and/or modify it under
  9268. + * the terms of the GNU General Public License as published by the Free Software
  9269. + * Foundation, either version 3 of the License, or (at your option) any later
  9270. + * version.
  9271. + *
  9272. + * This program is distributed in the hope that it will be useful, but WITHOUT
  9273. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9274. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  9275. + * details.
  9276. + *
  9277. + * You should have received a copy of the GNU General Public License along with
  9278. + * this program. If not, see <http://www.gnu.org/licenses/>.
  9279. + */
  9280. +package net.sf.l2j.gameserver.model.entity.engine;
  9281. +
  9282. +import java.sql.Connection;
  9283. +import java.sql.PreparedStatement;
  9284. +import java.sql.ResultSet;
  9285. +import java.util.ArrayList;
  9286. +import java.util.List;
  9287. +import java.util.logging.Logger;
  9288. +
  9289. +import net.sf.l2j.Config;
  9290. +import net.sf.l2j.L2DatabaseFactory;
  9291. +import net.sf.l2j.commons.concurrent.ThreadPool;
  9292. +import net.sf.l2j.gameserver.datatables.NpcTable;
  9293. +import net.sf.l2j.gameserver.datatables.SpawnTable;
  9294. +import net.sf.l2j.gameserver.model.L2Effect;
  9295. +import net.sf.l2j.gameserver.model.L2Spawn;
  9296. +import net.sf.l2j.gameserver.model.actor.Summon;
  9297. +import net.sf.l2j.gameserver.model.actor.instance.Pet;
  9298. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  9299. +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  9300. +import net.sf.l2j.gameserver.model.group.Party;
  9301. +import net.sf.l2j.gameserver.model.group.Party.MessageType;
  9302. +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  9303. +import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  9304. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  9305. +import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  9306. +import net.sf.l2j.gameserver.util.Broadcast;
  9307. +
  9308. +/**
  9309. + * @author SqueezeD Edited By TheEnd
  9310. + */
  9311. +public class DM
  9312. +{
  9313. +   private final static Logger _log = Logger.getLogger(DM.class.getName());
  9314. +   public static String _eventName = new String(), _eventDesc = new String(), _joiningLocationName = new String();
  9315. +   public static List<String> _savePlayers = new ArrayList<>();
  9316. +   public static List<Player> _players = new ArrayList<>();
  9317. +   public static boolean _joining = false, _teleport = false, _started = false, _sitForced = false;
  9318. +   public static L2Spawn _npcSpawn;
  9319. +   public static Player _topPlayer;
  9320. +   public static int _npcId = 0, _npcX = 0, _npcY = 0, _npcZ = 0, _rewardId = 0, _rewardAmount = 0, _topKills = 0,
  9321. +           _minlvl = 0, _maxlvl = 0, _playerColors = 0, _playerX = 0, _playerY = 0, _playerZ = 0;
  9322. +
  9323. +   public static void setNpcPos(Player activeChar)
  9324. +   {
  9325. +       _npcX = activeChar.getX();
  9326. +       _npcY = activeChar.getY();
  9327. +       _npcZ = activeChar.getZ();
  9328. +   }
  9329. +
  9330. +   public static boolean checkMaxLevel(int maxlvl)
  9331. +   {
  9332. +       if (_minlvl >= maxlvl)
  9333. +           return false;
  9334. +
  9335. +       return true;
  9336. +   }
  9337. +
  9338. +   public static boolean checkMinLevel(int minlvl)
  9339. +   {
  9340. +       if (_maxlvl <= minlvl)
  9341. +           return false;
  9342. +
  9343. +       return true;
  9344. +   }
  9345. +
  9346. +   public static void setPlayersPos(Player activeChar)
  9347. +   {
  9348. +       _playerX = activeChar.getX();
  9349. +       _playerY = activeChar.getY();
  9350. +       _playerZ = activeChar.getZ();
  9351. +   }
  9352. +
  9353. +   public static boolean checkPlayerOk()
  9354. +   {
  9355. +       if (_started || _teleport || _joining)
  9356. +           return false;
  9357. +
  9358. +       return true;
  9359. +   }
  9360. +
  9361. +   public static void startJoin(Player activeChar)
  9362. +   {
  9363. +       if (!startJoinOk())
  9364. +       {
  9365. +           if (!Config.DEBUG)
  9366. +               _log.fine("DM Engine[startJoin(" + activeChar.getName() + ")]: startJoinOk() = false");
  9367. +           return;
  9368. +       }
  9369. +
  9370. +       _joining = true;
  9371. +       spawnEventNpc(activeChar);
  9372. +       Broadcast.announceToOnlinePlayers(_eventName + "(DM): Joinable in " + _joiningLocationName + "!");
  9373. +   }
  9374. +
  9375. +   private static boolean startJoinOk()
  9376. +   {
  9377. +       if (_started || _teleport || _joining || _eventName.equals("") || _joiningLocationName.equals("") || _eventDesc.equals("") || _npcId == 0 || _npcX == 0 || _npcY == 0 || _npcZ == 0 || _rewardId == 0 || _rewardAmount == 0 || _playerX == 0 || _playerY == 0 || _playerZ == 0)
  9378. +           return false;
  9379. +
  9380. +       return true;
  9381. +   }
  9382. +
  9383. +   private static void spawnEventNpc(Player activeChar)
  9384. +   {
  9385. +       NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
  9386. +
  9387. +       try
  9388. +       {
  9389. +           _npcSpawn = new L2Spawn(tmpl);
  9390. +           _npcSpawn.setLoc(_npcX, _npcY, _npcZ, activeChar.getHeading());
  9391. +           _npcSpawn.setRespawnDelay(1);
  9392. +
  9393. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  9394. +
  9395. +           _npcSpawn.setRespawnState(true);
  9396. +           _npcSpawn.doSpawn(false);
  9397. +           _npcSpawn.getNpc().getStatus().setCurrentHp(999999999);
  9398. +           _npcSpawn.getNpc().setTitle(_eventName);
  9399. +           _npcSpawn.getNpc()._isEventMobDM = true;
  9400. +           _npcSpawn.getNpc().isAggressive();
  9401. +           _npcSpawn.getNpc().decayMe();
  9402. +           _npcSpawn.getNpc().spawnMe(_npcSpawn.getNpc().getX(), _npcSpawn.getNpc().getY(), _npcSpawn.getNpc().getZ());
  9403. +
  9404. +           _npcSpawn.getNpc().broadcastPacket(new MagicSkillUse(_npcSpawn.getNpc(), _npcSpawn.getNpc(), 1034, 1, 1, 1));
  9405. +       }
  9406. +       catch (Exception e)
  9407. +       {
  9408. +           _log.warning(DM.class.getSimpleName() + ":  DM Engine[spawnEventNpc(" + activeChar.getName() + ")]: exception: " + e.getMessage());
  9409. +       }
  9410. +   }
  9411. +
  9412. +   public static void teleportStart()
  9413. +   {
  9414. +       if (!_joining || _started || _teleport)
  9415. +           return;
  9416. +
  9417. +       _joining = false;
  9418. +       Broadcast.announceToOnlinePlayers(_eventName + "(DM): Teleport to team spot in 20 seconds!");
  9419. +
  9420. +       setUserData();
  9421. +       ThreadPool.schedule(new Runnable()
  9422. +       {
  9423. +           @Override
  9424. +           public void run()
  9425. +           {
  9426. +               DM.sit();
  9427. +
  9428. +               for (Player player : DM._players)
  9429. +               {
  9430. +                   if (player != null)
  9431. +                   {
  9432. +                       if (Config.DM_ON_START_UNSUMMON_PET)
  9433. +                       {
  9434. +                           // Remove Summon's buffs
  9435. +                           if (player.getPet() != null)
  9436. +                           {
  9437. +                               Summon summon = player.getPet();
  9438. +                               for (L2Effect e : summon.getAllEffects())
  9439. +                                   e.exit();
  9440. +
  9441. +                               if (summon instanceof Pet)
  9442. +                                   summon.unSummon(player);
  9443. +                           }
  9444. +                       }
  9445. +
  9446. +                       if (Config.DM_ON_START_REMOVE_ALL_EFFECTS)
  9447. +                       {
  9448. +                           for (L2Effect e : player.getAllEffects())
  9449. +                           {
  9450. +                               if (e != null)
  9451. +                                   e.exit();
  9452. +                           }
  9453. +                       }
  9454. +
  9455. +                       // Remove player from his party
  9456. +                       if (player.getParty() != null)
  9457. +                       {
  9458. +                           Party party = player.getParty();
  9459. +                           party.removePartyMember(player, MessageType.EXPELLED);
  9460. +                       }
  9461. +                       player.teleToLocation(_playerX, _playerY, _playerZ, 0);
  9462. +                   }
  9463. +               }
  9464. +           }
  9465. +       }, 20000);
  9466. +       _teleport = true;
  9467. +   }
  9468. +
  9469. +   public static void startEvent(Player activeChar)
  9470. +   {
  9471. +       if (!startEventOk())
  9472. +       {
  9473. +           if (Config.DEBUG)
  9474. +               _log.fine("DM Engine[startEvent(" + activeChar.getName() + ")]: startEventOk() = false");
  9475. +           return;
  9476. +       }
  9477. +
  9478. +       _teleport = false;
  9479. +       sit();
  9480. +       Broadcast.announceToOnlinePlayers(_eventName + "(DM): Started. Go to kill your enemies!");
  9481. +       _started = true;
  9482. +   }
  9483. +
  9484. +   private static boolean startEventOk()
  9485. +   {
  9486. +       if (_joining || !_teleport || _started)
  9487. +           return false;
  9488. +
  9489. +       return true;
  9490. +   }
  9491. +
  9492. +   public static void setUserData()
  9493. +   {
  9494. +       for (Player player : _players)
  9495. +       {
  9496. +           player._originalNameColorDM = player.getAppearance().getNameColor();
  9497. +           player._originalKarmaDM = player.getKarma();
  9498. +           player._inEventDM = true;
  9499. +           player._countDMkills = 0;
  9500. +           player.getAppearance().setNameColor(_playerColors);
  9501. +           player.setKarma(0);
  9502. +           player.broadcastUserInfo();
  9503. +       }
  9504. +   }
  9505. +
  9506. +   public static void removeUserData()
  9507. +   {
  9508. +       for (Player player : _players)
  9509. +       {
  9510. +           player.getAppearance().setNameColor(player._originalNameColorDM);
  9511. +           player.setKarma(player._originalKarmaDM);
  9512. +           player._inEventDM = false;
  9513. +           player._countDMkills = 0;
  9514. +           player.broadcastUserInfo();
  9515. +       }
  9516. +   }
  9517. +
  9518. +   public static void finishEvent(Player activeChar)
  9519. +   {
  9520. +       if (!finishEventOk())
  9521. +       {
  9522. +           if (Config.DEBUG)
  9523. +               _log.fine("DM Engine[finishEvent(" + activeChar.getName() + ")]: finishEventOk() = false");
  9524. +           return;
  9525. +       }
  9526. +
  9527. +       _started = false;
  9528. +       unspawnEventNpc();
  9529. +       processTopPlayer();
  9530. +
  9531. +       if (_topKills == 0)
  9532. +           Broadcast.announceToOnlinePlayers(_eventName + "(DM): No players win the match(nobody killed).");
  9533. +       else
  9534. +       {
  9535. +           Broadcast.announceToOnlinePlayers(_eventName + "(DM): " + _topPlayer.getName() + " wins the match! " + _topKills + " kills.");
  9536. +           rewardPlayer(activeChar);
  9537. +       }
  9538. +
  9539. +       teleportFinish();
  9540. +   }
  9541. +
  9542. +   private static boolean finishEventOk()
  9543. +   {
  9544. +       if (!_started)
  9545. +           return false;
  9546. +
  9547. +       return true;
  9548. +   }
  9549. +
  9550. +   public static void processTopPlayer()
  9551. +   {
  9552. +       for (Player player : _players)
  9553. +       {
  9554. +           if (player._countDMkills > _topKills)
  9555. +           {
  9556. +               _topPlayer = player;
  9557. +               _topKills = player._countDMkills;
  9558. +           }
  9559. +       }
  9560. +   }
  9561. +
  9562. +   /**
  9563. +    * @param activeChar
  9564. +    */
  9565. +   public static void rewardPlayer(Player activeChar)
  9566. +   {
  9567. +       if (_topPlayer != null)
  9568. +       {
  9569. +           _topPlayer.addItem("DM Event: " + _eventName, _rewardId, _rewardAmount, _topPlayer, true);
  9570. +
  9571. +           StatusUpdate su = new StatusUpdate(_topPlayer);
  9572. +           su.addAttribute(StatusUpdate.CUR_LOAD, _topPlayer.getCurrentLoad());
  9573. +           _topPlayer.sendPacket(su);
  9574. +
  9575. +           NpcHtmlMessage nhm = new NpcHtmlMessage(5);
  9576. +           StringBuilder replyMSG = new StringBuilder("");
  9577. +
  9578. +           replyMSG.append("<html><body>You won the event. Look in your inventory for the reward.</body></html>");
  9579. +
  9580. +           nhm.setHtml(replyMSG.toString());
  9581. +           _topPlayer.sendPacket(nhm);
  9582. +
  9583. +           // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  9584. +           _topPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  9585. +       }
  9586. +   }
  9587. +
  9588. +   public static void abortEvent()
  9589. +   {
  9590. +       if (!_joining && !_teleport && !_started)
  9591. +           return;
  9592. +
  9593. +       _joining = false;
  9594. +       _teleport = false;
  9595. +       _started = false;
  9596. +       unspawnEventNpc();
  9597. +       Broadcast.announceToOnlinePlayers(_eventName + "(DM): Match aborted!");
  9598. +       teleportFinish();
  9599. +   }
  9600. +
  9601. +   public static void sit()
  9602. +   {
  9603. +       if (_sitForced)
  9604. +           _sitForced = false;
  9605. +       else
  9606. +           _sitForced = true;
  9607. +
  9608. +       for (Player player : _players)
  9609. +       {
  9610. +           if (player != null)
  9611. +           {
  9612. +               if (_sitForced)
  9613. +               {
  9614. +                   player.stopMove(null);
  9615. +                   player.abortAttack();
  9616. +                   player.abortCast();
  9617. +
  9618. +                   if (!player.isSitting())
  9619. +                       player.sitDown();
  9620. +               }
  9621. +               else
  9622. +               {
  9623. +                   if (player.isSitting())
  9624. +                       player.standUp();
  9625. +               }
  9626. +           }
  9627. +       }
  9628. +   }
  9629. +
  9630. +   public static void dumpData()
  9631. +   {
  9632. +       _log.info("");
  9633. +       _log.info("");
  9634. +
  9635. +       if (!_joining && !_teleport && !_started)
  9636. +       {
  9637. +           _log.info("<<---------------------------------->>");
  9638. +           _log.info(">> DM Engine infos dump (INACTIVE) <<");
  9639. +           _log.info("<<--^----^^-----^----^^------^^----->>");
  9640. +       }
  9641. +       else if (_joining && !_teleport && !_started)
  9642. +       {
  9643. +           _log.info("<<--------------------------------->>");
  9644. +           _log.info(">> DM Engine infos dump (JOINING) <<");
  9645. +           _log.info("<<--^----^^-----^----^^------^----->>");
  9646. +       }
  9647. +       else if (!_joining && _teleport && !_started)
  9648. +       {
  9649. +           _log.info("<<---------------------------------->>");
  9650. +           _log.info(">> DM Engine infos dump (TELEPORT) <<");
  9651. +           _log.info("<<--^----^^-----^----^^------^^----->>");
  9652. +       }
  9653. +       else if (!_joining && !_teleport && _started)
  9654. +       {
  9655. +           _log.info("<<--------------------------------->>");
  9656. +           _log.info(">> DM Engine infos dump (STARTED) <<");
  9657. +           _log.info("<<--^----^^-----^----^^------^----->>");
  9658. +       }
  9659. +
  9660. +       _log.info("Name: " + _eventName);
  9661. +       _log.info("Desc: " + _eventDesc);
  9662. +       _log.info("Join location: " + _joiningLocationName);
  9663. +       _log.info("Min lvl: " + _minlvl);
  9664. +       _log.info("Max lvl: " + _maxlvl);
  9665. +
  9666. +       _log.info("");
  9667. +       _log.info("##################################");
  9668. +       _log.info("# _players(Vector<Player>) #");
  9669. +       _log.info("##################################");
  9670. +
  9671. +       _log.info("Total Players : " + _players.size());
  9672. +
  9673. +       for (Player player : _players)
  9674. +       {
  9675. +           if (player != null)
  9676. +               _log.info("Name: " + player.getName() + " kills :" + player._countDMkills);
  9677. +       }
  9678. +
  9679. +       _log.info("");
  9680. +       _log.info("################################");
  9681. +       _log.info("# _savePlayers(Vector<String>) #");
  9682. +       _log.info("################################");
  9683. +
  9684. +       for (String player : _savePlayers)
  9685. +           _log.info("Name: " + player);
  9686. +
  9687. +       _log.info("");
  9688. +       _log.info("");
  9689. +   }
  9690. +
  9691. +   public static void loadData()
  9692. +   {
  9693. +       _eventName = new String();
  9694. +       _eventDesc = new String();
  9695. +       _joiningLocationName = new String();
  9696. +       _savePlayers = new ArrayList<>();
  9697. +       _players = new ArrayList<>();
  9698. +       _topPlayer = null;
  9699. +       _npcSpawn = null;
  9700. +       _joining = false;
  9701. +       _teleport = false;
  9702. +       _started = false;
  9703. +       _sitForced = false;
  9704. +       _npcId = 0;
  9705. +       _npcX = 0;
  9706. +       _npcY = 0;
  9707. +       _npcZ = 0;
  9708. +       _rewardId = 0;
  9709. +       _rewardAmount = 0;
  9710. +       _topKills = 0;
  9711. +       _minlvl = 0;
  9712. +       _maxlvl = 0;
  9713. +       _playerColors = 0;
  9714. +       _playerX = 0;
  9715. +       _playerY = 0;
  9716. +       _playerZ = 0;
  9717. +
  9718. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  9719. +       {
  9720. +           PreparedStatement statement;
  9721. +           ResultSet rs;
  9722. +
  9723. +           statement = con.prepareStatement("SELECT * FROM dm");
  9724. +           rs = statement.executeQuery();
  9725. +
  9726. +           while (rs.next())
  9727. +           {
  9728. +               _eventName = rs.getString("eventName");
  9729. +               _eventDesc = rs.getString("eventDesc");
  9730. +               _joiningLocationName = rs.getString("joiningLocation");
  9731. +               _minlvl = rs.getInt("minlvl");
  9732. +               _maxlvl = rs.getInt("maxlvl");
  9733. +               _npcId = rs.getInt("npcId");
  9734. +               _npcX = rs.getInt("npcX");
  9735. +               _npcY = rs.getInt("npcY");
  9736. +               _npcZ = rs.getInt("npcZ");
  9737. +               _rewardId = rs.getInt("rewardId");
  9738. +               _rewardAmount = rs.getInt("rewardAmount");
  9739. +               _playerColors = rs.getInt("color");
  9740. +               _playerX = rs.getInt("playerX");
  9741. +               _playerY = rs.getInt("playerY");
  9742. +               _playerZ = rs.getInt("playerZ");
  9743. +
  9744. +           }
  9745. +           rs.close();
  9746. +           statement.close();
  9747. +       }
  9748. +       catch (Exception e)
  9749. +       {
  9750. +           _log.warning(DM.class.getSimpleName() + ":  Exception: DM.loadData(): " + e.getMessage());
  9751. +       }
  9752. +   }
  9753. +
  9754. +   public static void saveData()
  9755. +   {
  9756. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  9757. +       {
  9758. +           PreparedStatement statement;
  9759. +
  9760. +           statement = con.prepareStatement("DELETE FROM dm");
  9761. +           statement.execute();
  9762. +           statement.close();
  9763. +
  9764. +           statement = con.prepareStatement("INSERT INTO dm (eventName, eventDesc, joiningLocation, minlvl, maxlvl, npcId, npcX, npcY, npcZ, rewardId, rewardAmount, color, playerX, playerY, playerZ ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
  9765. +           statement.setString(1, _eventName);
  9766. +           statement.setString(2, _eventDesc);
  9767. +           statement.setString(3, _joiningLocationName);
  9768. +           statement.setInt(4, _minlvl);
  9769. +           statement.setInt(5, _maxlvl);
  9770. +           statement.setInt(6, _npcId);
  9771. +           statement.setInt(7, _npcX);
  9772. +           statement.setInt(8, _npcY);
  9773. +           statement.setInt(9, _npcZ);
  9774. +           statement.setInt(10, _rewardId);
  9775. +           statement.setInt(11, _rewardAmount);
  9776. +           statement.setInt(12, _playerColors);
  9777. +           statement.setInt(13, _playerX);
  9778. +           statement.setInt(14, _playerY);
  9779. +           statement.setInt(15, _playerZ);
  9780. +           statement.execute();
  9781. +           statement.close();
  9782. +       }
  9783. +       catch (Exception e)
  9784. +       {
  9785. +           _log.warning(DM.class.getSimpleName() + ":  Exception: DM.saveData(): " + e.getMessage());
  9786. +       }
  9787. +   }
  9788. +
  9789. +   public static void showEventHtml(Player eventPlayer, String objectId)
  9790. +   {
  9791. +       try
  9792. +       {
  9793. +           NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  9794. +
  9795. +           StringBuilder replyMSG = new StringBuilder("<html><body>");
  9796. +           replyMSG.append("DM Match<br><br><br>");
  9797. +           replyMSG.append("Current event...<br1>");
  9798. +           replyMSG.append("   ... name:&nbsp;<font color=\"00FF00\">" + _eventName + "</font><br1>");
  9799. +           replyMSG.append("   ... description:&nbsp;<font color=\"00FF00\">" + _eventDesc + "</font><br><br>");
  9800. +
  9801. +           if (!_started && !_joining)
  9802. +               replyMSG.append("<center>Wait till the admin/gm start the participation.</center>");
  9803. +           else if (!_started && _joining && eventPlayer.getLevel() >= _minlvl && eventPlayer.getLevel() < _maxlvl)
  9804. +           {
  9805. +               if (_players.contains(eventPlayer))
  9806. +               {
  9807. +                   replyMSG.append("You are already participating!<br><br>");
  9808. +
  9809. +                   replyMSG.append("<table border=\"0\"><tr>");
  9810. +                   replyMSG.append("<td width=\"200\">Wait till event start or</td>");
  9811. +                   replyMSG.append("<td width=\"60\"><center><button value=\"remove\" action=\"bypass -h npc_" + objectId + "_dmevent_player_leave\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></td>");
  9812. +                   replyMSG.append("<td width=\"100\">your participation!</td>");
  9813. +                   replyMSG.append("</tr></table>");
  9814. +               }
  9815. +               else
  9816. +               {
  9817. +                   replyMSG.append("You want to participate in the event?<br><br>");
  9818. +                   replyMSG.append("<td width=\"200\">Admin set min lvl : <font color=\"00FF00\">" + _minlvl + "</font></td><br>");
  9819. +                   replyMSG.append("<td width=\"200\">Admin set max lvl : <font color=\"00FF00\">" + _maxlvl + "</font></td><br><br>");
  9820. +
  9821. +                   replyMSG.append("<button value=\"Join\" action=\"bypass -h npc_" + objectId + "_dmevent_player_join\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  9822. +
  9823. +               }
  9824. +           }
  9825. +           else if (_started && !_joining)
  9826. +               replyMSG.append("<center>DM match is in progress.</center>");
  9827. +           else if (eventPlayer.getLevel() < _minlvl || eventPlayer.getLevel() > _maxlvl)
  9828. +           {
  9829. +               replyMSG.append("Your lvl : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font><br>");
  9830. +               replyMSG.append("Admin set min lvl : <font color=\"00FF00\">" + _minlvl + "</font><br>");
  9831. +               replyMSG.append("Admin set max lvl : <font color=\"00FF00\">" + _maxlvl + "</font><br><br>");
  9832. +               replyMSG.append("<font color=\"FFFF00\">You can't participate to this event.</font><br>");
  9833. +           }
  9834. +
  9835. +           replyMSG.append("</body></html>");
  9836. +           adminReply.setHtml(replyMSG.toString());
  9837. +           eventPlayer.sendPacket(adminReply);
  9838. +
  9839. +           // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  9840. +           eventPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  9841. +       }
  9842. +       catch (Exception e)
  9843. +       {
  9844. +           _log.warning(DM.class.getSimpleName() + ":  DM Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception" + e.getMessage());
  9845. +       }
  9846. +   }
  9847. +
  9848. +   public static void addPlayer(Player player)
  9849. +   {
  9850. +       if (!addPlayerOk(player))
  9851. +           return;
  9852. +       _players.add(player);
  9853. +       player._originalNameColorDM = player.getAppearance().getNameColor();
  9854. +       player._originalKarmaDM = player.getKarma();
  9855. +       player._inEventDM = true;
  9856. +       player._countDMkills = 0;
  9857. +       _savePlayers.add(player.getName());
  9858. +
  9859. +   }
  9860. +
  9861. +   public static boolean addPlayerOk(Player eventPlayer)
  9862. +   {
  9863. +
  9864. +       if (eventPlayer._inEventDM)
  9865. +       {
  9866. +           eventPlayer.sendMessage("You are already participating in the event!");
  9867. +           return false;
  9868. +       }
  9869. +
  9870. +       return true;
  9871. +   }
  9872. +
  9873. +   public static synchronized void addDisconnectedPlayer(Player player)
  9874. +   {
  9875. +       if ((_teleport || _started) || _savePlayers.contains(player.getName()))
  9876. +       {
  9877. +           if (Config.DM_ON_START_REMOVE_ALL_EFFECTS)
  9878. +           {
  9879. +               for (L2Effect e : player.getAllEffects())
  9880. +               {
  9881. +                   if (e != null)
  9882. +                       e.exit();
  9883. +               }
  9884. +           }
  9885. +           for (Player p : _players)
  9886. +           {
  9887. +               if (p == null)
  9888. +               {
  9889. +                   continue;
  9890. +               }
  9891. +               // check by name incase player got new objectId
  9892. +               else if (p.getName().equals(player.getName()))
  9893. +               {
  9894. +                   player._originalNameColorDM = player.getAppearance().getNameColor();
  9895. +                   player._originalKarmaDM = player.getKarma();
  9896. +                   player._inEventDM = true;
  9897. +                   player._countDMkills = p._countDMkills;
  9898. +                   _players.remove(p); // removing old object id from vector
  9899. +                   _players.add(player); // adding new objectId to vector
  9900. +                   break;
  9901. +               }
  9902. +           }
  9903. +
  9904. +           player.getAppearance().setNameColor(_playerColors);
  9905. +           player.setKarma(0);
  9906. +           player.broadcastUserInfo();
  9907. +           player.teleToLocation(_playerX, _playerY, _playerZ, 0);
  9908. +       }
  9909. +   }
  9910. +
  9911. +   public static void removePlayer(Player player)
  9912. +   {
  9913. +       if (player != null)
  9914. +           _players.remove(player);
  9915. +   }
  9916. +
  9917. +   public static void cleanDM()
  9918. +   {
  9919. +       for (Player player : _players)
  9920. +       {
  9921. +           removePlayer(player);
  9922. +       }
  9923. +
  9924. +       _savePlayers = new ArrayList<>();
  9925. +       _topPlayer = null;
  9926. +       _npcSpawn = null;
  9927. +       _joining = false;
  9928. +       _teleport = false;
  9929. +       _started = false;
  9930. +       _sitForced = false;
  9931. +       _topKills = 0;
  9932. +       _players = new ArrayList<>();
  9933. +
  9934. +   }
  9935. +
  9936. +   public static void unspawnEventNpc()
  9937. +   {
  9938. +       if (_npcSpawn == null)
  9939. +           return;
  9940. +
  9941. +       _npcSpawn.getNpc().deleteMe();
  9942. +       _npcSpawn.setRespawnState(false);
  9943. +       SpawnTable.getInstance().deleteSpawn(_npcSpawn, true);
  9944. +   }
  9945. +
  9946. +   public static void teleportFinish()
  9947. +   {
  9948. +       Broadcast.announceToOnlinePlayers(_eventName + "(DM): Teleport back to participation NPC in 20 seconds!");
  9949. +
  9950. +       removeUserData();
  9951. +       ThreadPool.schedule(new Runnable()
  9952. +       {
  9953. +           @Override
  9954. +           public void run()
  9955. +           {
  9956. +               for (Player player : _players)
  9957. +               {
  9958. +                   if (player != null && player.isOnline())
  9959. +                       player.teleToLocation(_npcX, _npcY, _npcZ, 0);
  9960. +               }
  9961. +               cleanDM();
  9962. +           }
  9963. +       }, 20000);
  9964. +   }
  9965. +}
  9966. \ No newline at end of file
  9967. Index: java/net/sf/l2j/gameserver/handler/itemhandlers/SummonItems.java
  9968. ===================================================================
  9969. --- java/net/sf/l2j/gameserver/handler/itemhandlers/SummonItems.java    (revision 1)
  9970. +++ java/net/sf/l2j/gameserver/handler/itemhandlers/SummonItems.java    (working copy)
  9971. @@ -2,8 +2,8 @@
  9972.  
  9973.  import java.util.logging.Level;
  9974.  
  9975. +import net.sf.l2j.Config;
  9976.  import net.sf.l2j.commons.concurrent.ThreadPool;
  9977. -
  9978.  import net.sf.l2j.gameserver.datatables.NpcTable;
  9979.  import net.sf.l2j.gameserver.datatables.SummonItemsData;
  9980.  import net.sf.l2j.gameserver.handler.IItemHandler;
  9981. @@ -16,9 +16,13 @@
  9982.  import net.sf.l2j.gameserver.model.actor.instance.Pet;
  9983.  import net.sf.l2j.gameserver.model.actor.instance.Player;
  9984.  import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  9985. +import net.sf.l2j.gameserver.model.entity.engine.CTF;
  9986. +import net.sf.l2j.gameserver.model.entity.engine.DM;
  9987. +import net.sf.l2j.gameserver.model.entity.engine.TvT;
  9988.  import net.sf.l2j.gameserver.model.item.SummonItem;
  9989.  import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
  9990.  import net.sf.l2j.gameserver.network.SystemMessageId;
  9991. +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  9992.  import net.sf.l2j.gameserver.network.serverpackets.MagicSkillLaunched;
  9993.  import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  9994.  import net.sf.l2j.gameserver.network.serverpackets.SetupGauge;
  9995. @@ -41,7 +45,13 @@
  9996.             activeChar.sendPacket(SystemMessageId.CANT_MOVE_SITTING);
  9997.             return;
  9998.         }
  9999. -      
  10000. +
  10001. +       if ((activeChar._inEventTvT && TvT._started && !Config.TVT_ALLOW_SUMMON) || (activeChar._inEventCTF && CTF._started && !Config.CTF_ALLOW_SUMMON) || (activeChar._inEventDM && DM._started && !Config.DM_ALLOW_SUMMON))
  10002. +       {
  10003. +           activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  10004. +           return;
  10005. +       }
  10006. +
  10007.         if (activeChar.isInObserverMode())
  10008.             return;
  10009.        
  10010. Index: java/net/sf/l2j/gameserver/model/entity/engine/CTF.java
  10011. ===================================================================
  10012. --- java/net/sf/l2j/gameserver/model/entity/engine/CTF.java (revision 0)
  10013. +++ java/net/sf/l2j/gameserver/model/entity/engine/CTF.java (working copy)
  10014. @@ -0,0 +1,2223 @@
  10015. +/*
  10016. + * This program is free software: you can redistribute it and/or modify it under
  10017. + * the terms of the GNU General Public License as published by the Free Software
  10018. + * Foundation, either version 3 of the License, or (at your option) any later
  10019. + * version.
  10020. + *
  10021. + * This program is distributed in the hope that it will be useful, but WITHOUT
  10022. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10023. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10024. + * details.
  10025. + *
  10026. + * You should have received a copy of the GNU General Public License along with
  10027. + * this program. If not, see <http://www.gnu.org/licenses/>.
  10028. + */
  10029. +package net.sf.l2j.gameserver.model.entity.engine;
  10030. +
  10031. +import java.sql.Connection;
  10032. +import java.sql.PreparedStatement;
  10033. +import java.sql.ResultSet;
  10034. +import java.sql.SQLException;
  10035. +import java.util.ArrayList;
  10036. +import java.util.List;
  10037. +import java.util.logging.Logger;
  10038. +
  10039. +import net.sf.l2j.Config;
  10040. +import net.sf.l2j.L2DatabaseFactory;
  10041. +import net.sf.l2j.commons.concurrent.ThreadPool;
  10042. +import net.sf.l2j.commons.random.Rnd;
  10043. +import net.sf.l2j.gameserver.datatables.ItemTable;
  10044. +import net.sf.l2j.gameserver.datatables.NpcTable;
  10045. +import net.sf.l2j.gameserver.datatables.SpawnTable;
  10046. +import net.sf.l2j.gameserver.model.L2Effect;
  10047. +import net.sf.l2j.gameserver.model.L2Radar;
  10048. +import net.sf.l2j.gameserver.model.L2Spawn;
  10049. +import net.sf.l2j.gameserver.model.actor.Summon;
  10050. +import net.sf.l2j.gameserver.model.actor.instance.Pet;
  10051. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  10052. +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  10053. +import net.sf.l2j.gameserver.model.group.Party;
  10054. +import net.sf.l2j.gameserver.model.group.Party.MessageType;
  10055. +import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
  10056. +import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
  10057. +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  10058. +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  10059. +import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
  10060. +import net.sf.l2j.gameserver.network.serverpackets.ItemList;
  10061. +import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  10062. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  10063. +import net.sf.l2j.gameserver.network.serverpackets.RadarControl;
  10064. +import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
  10065. +import net.sf.l2j.gameserver.util.Broadcast;
  10066. +
  10067. +/**
  10068. + * @author SqueezeD & Darki699 (idea by FBIAgent)
  10069. + */
  10070. +public class CTF
  10071. +{
  10072. +   private final static Logger _log = Logger.getLogger(CTF.class.getName());
  10073. +   private static int _FlagNPC = 35062, _FLAG_IN_HAND_ITEM_ID = 6718;
  10074. +   public static String _eventName = new String(), _eventDesc = new String(), _topTeam = new String(),
  10075. +   _joiningLocationName = new String();
  10076. +   public static List<String> _teams = new ArrayList<>(), _savePlayers = new ArrayList<>(),
  10077. +           _savePlayerTeams = new ArrayList<>();
  10078. +   public static List<Player> _players = new ArrayList<>(),
  10079. +           _playersShuffle = new ArrayList<>();
  10080. +   public static List<Integer> _teamPlayersCount = new ArrayList<>(), _teamColors = new ArrayList<>(),
  10081. +           _teamsX = new ArrayList<>(), _teamsY = new ArrayList<>(), _teamsZ = new ArrayList<>();
  10082. +   public static boolean _joining = false, _teleport = false, _started = false, _sitForced = false;
  10083. +   public static L2Spawn _npcSpawn;
  10084. +   public static int _npcId = 0, _npcX = 0, _npcY = 0, _npcZ = 0, _npcHeading = 0, _rewardId = 0, _rewardAmount = 0,
  10085. +           _minlvl = 0, _maxlvl = 0, _joinTime = 0, _eventTime = 0, _minPlayers = 0, _maxPlayers = 0;
  10086. +   public static List<Integer> _teamPointsCount = new ArrayList<>();
  10087. +   public static List<Integer> _flagIds = new ArrayList<>(), _flagsX = new ArrayList<>(),
  10088. +           _flagsY = new ArrayList<>(), _flagsZ = new ArrayList<>();
  10089. +   public static List<L2Spawn> _flagSpawns = new ArrayList<>(), _throneSpawns = new ArrayList<>();
  10090. +   public static List<Boolean> _flagsTaken = new ArrayList<>();
  10091. +   public static int _topScore = 0, eventCenterX = 0, eventCenterY = 0, eventCenterZ = 0, eventOffset = 0;
  10092. +
  10093. +   public static void showFlagHtml(Player eventPlayer, String objectId, String teamName)
  10094. +   {
  10095. +       if (eventPlayer == null)
  10096. +           return;
  10097. +
  10098. +       try
  10099. +       {
  10100. +           NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  10101. +
  10102. +           StringBuilder replyMSG = new StringBuilder();
  10103. +
  10104. +           replyMSG.append("<html><body><center>");
  10105. +           replyMSG.append("CTF Flag<br><br>");
  10106. +           replyMSG.append("<font color=\"00FF00\">" + teamName + "'s Flag</font><br>");
  10107. +           if (eventPlayer._teamNameCTF != null && eventPlayer._teamNameCTF.equals(teamName))
  10108. +               replyMSG.append("<font color=\"LEVEL\">This is your Flag</font><br>");
  10109. +           else
  10110. +               replyMSG.append("<font color=\"LEVEL\">Enemy Flag!</font><br>");
  10111. +           if (_started)
  10112. +               processInFlagRange(eventPlayer);
  10113. +           else
  10114. +               replyMSG.append("CTF match is not in progress yet.<br>Wait for a GM to start the event<br>");
  10115. +           replyMSG.append("</center></body></html>");
  10116. +           adminReply.setHtml(replyMSG.toString());
  10117. +           eventPlayer.sendPacket(adminReply);
  10118. +       }
  10119. +       catch (Exception e)
  10120. +       {
  10121. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception: " + e.getStackTrace());
  10122. +       }
  10123. +   }
  10124. +
  10125. +   public static void CheckRestoreFlags()
  10126. +   {
  10127. +       List<Integer> teamsTakenFlag = new ArrayList<>();
  10128. +       try
  10129. +       {
  10130. +           for (Player player : _players)
  10131. +           { // if there's a player with a flag
  10132. +               // add the index of the team who's FLAG WAS TAKEN to the list
  10133. +               if (player != null)
  10134. +               {
  10135. +                   if (player.isOnline() && player._haveFlagCTF)// logged off with a flag in his hands
  10136. +                   {
  10137. +                       AnnounceToPlayers(false, _eventName + "(CTF): " + player.getName() + " logged off with a CTF flag!");
  10138. +                       player._haveFlagCTF = false;
  10139. +                       if (_teams.indexOf(player._teamNameHaveFlagCTF) >= 0)
  10140. +                       {
  10141. +                           if (_flagsTaken.get(_teams.indexOf(player._teamNameHaveFlagCTF)))
  10142. +                           {
  10143. +                               _flagsTaken.set(_teams.indexOf(player._teamNameHaveFlagCTF), false);
  10144. +                               spawnFlag(player._teamNameHaveFlagCTF);
  10145. +                               AnnounceToPlayers(false, _eventName + "(CTF): " + player._teamNameHaveFlagCTF + " flag now returned to place.");
  10146. +                           }
  10147. +                       }
  10148. +                       removeFlagFromPlayer(player);
  10149. +                       player._teamNameHaveFlagCTF = null;
  10150. +                       return;
  10151. +                   }
  10152. +                   else if (player._haveFlagCTF)
  10153. +                       teamsTakenFlag.add(_teams.indexOf(player._teamNameHaveFlagCTF));
  10154. +               }
  10155. +           }
  10156. +           // Go over the list of ALL teams
  10157. +           for (String team : _teams)
  10158. +           {
  10159. +               if (team == null)
  10160. +                   continue;
  10161. +               int index = _teams.indexOf(team);
  10162. +               if (!teamsTakenFlag.contains(index))
  10163. +               {
  10164. +                   if (_flagsTaken.get(index))
  10165. +                   {
  10166. +                       _flagsTaken.set(index, false);
  10167. +                       spawnFlag(team);
  10168. +                       AnnounceToPlayers(false, _eventName + "(CTF): " + team + " flag returned due to player error.");
  10169. +                   }
  10170. +               }
  10171. +           }
  10172. +           // Check if a player ran away from the event holding a flag:
  10173. +           for (Player player : _players)
  10174. +           {
  10175. +               if ((player != null) && player._haveFlagCTF)
  10176. +               {
  10177. +                   if (isOutsideCTFArea(player))
  10178. +                   {
  10179. +                       AnnounceToPlayers(false, _eventName + "(CTF): " + player.getName() + " escaped from the event holding a flag!");
  10180. +                       player._haveFlagCTF = false;
  10181. +                       if (_teams.indexOf(player._teamNameHaveFlagCTF) >= 0)
  10182. +                       {
  10183. +                           if (_flagsTaken.get(_teams.indexOf(player._teamNameHaveFlagCTF)))
  10184. +                           {
  10185. +                               _flagsTaken.set(_teams.indexOf(player._teamNameHaveFlagCTF), false);
  10186. +                               spawnFlag(player._teamNameHaveFlagCTF);
  10187. +                               AnnounceToPlayers(false, _eventName + "(CTF): " + player._teamNameHaveFlagCTF + " flag now returned to place.");
  10188. +                           }
  10189. +                       }
  10190. +                       removeFlagFromPlayer(player);
  10191. +                       player._teamNameHaveFlagCTF = null;
  10192. +                       player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ.get(_teams.indexOf(player._teamNameCTF)), 0);
  10193. +                       player.sendMessage("You have been returned to your team spawn");
  10194. +                       return;
  10195. +                   }
  10196. +               }
  10197. +           }
  10198. +       }
  10199. +       catch (Exception e)
  10200. +       {
  10201. +           _log.warning(CTF.class.getSimpleName() + ":  CTF.restoreFlags() Error:" + e.toString());
  10202. +       }
  10203. +   }
  10204. +
  10205. +   public static void kickPlayerFromCTf(Player playerToKick)
  10206. +   {
  10207. +       if (playerToKick == null)
  10208. +           return;
  10209. +
  10210. +       if (_joining)
  10211. +       {
  10212. +           _playersShuffle.remove(playerToKick);
  10213. +           _players.remove(playerToKick);
  10214. +           playerToKick._inEventCTF = false;
  10215. +           playerToKick._teamNameCTF = new String();
  10216. +       }
  10217. +       if (_started || _teleport)
  10218. +       {
  10219. +           _playersShuffle.remove(playerToKick);
  10220. +           playerToKick._inEventCTF = false;
  10221. +           removePlayer(playerToKick);
  10222. +           if (playerToKick.isOnline())
  10223. +           {
  10224. +               playerToKick.getAppearance().setNameColor(playerToKick._originalNameColorCTF);
  10225. +               playerToKick.setKarma(playerToKick._originalKarmaCTF);
  10226. +               playerToKick.setTitle(playerToKick._originalTitleCTF);
  10227. +               playerToKick.broadcastUserInfo();
  10228. +               playerToKick.sendMessage("You have been kicked from the CTF.");
  10229. +               playerToKick.teleToLocation(_npcX, _npcY, _npcZ, 0);
  10230. +           }
  10231. +       }
  10232. +   }
  10233. +
  10234. +   public static void AnnounceToPlayers(Boolean toall, String announce)
  10235. +   {
  10236. +       if (toall)
  10237. +           Broadcast.announceToOnlinePlayers(announce);
  10238. +       else
  10239. +       {
  10240. +           CreatureSay cs = new CreatureSay(0, 2, "", "Announcements : " + announce);
  10241. +           if (_players != null && !_players.isEmpty())
  10242. +           {
  10243. +               for (Player player : _players)
  10244. +               {
  10245. +                   if (player != null && player.isOnline())
  10246. +                       player.sendPacket(cs);
  10247. +               }
  10248. +           }
  10249. +       }
  10250. +   }
  10251. +
  10252. +   public static void Started(Player player)
  10253. +   {
  10254. +       player._teamNameHaveFlagCTF = null;
  10255. +       player._haveFlagCTF = false;
  10256. +   }
  10257. +
  10258. +   public static void StartEvent()
  10259. +   {
  10260. +       for (Player player : _players)
  10261. +       {
  10262. +           if (player != null)
  10263. +           {
  10264. +               player._teamNameHaveFlagCTF = null;
  10265. +               player._haveFlagCTF = false;
  10266. +           }
  10267. +       }
  10268. +       AnnounceToPlayers(false, _eventName + "(CTF): Started. Go Capture the Flags!");
  10269. +   }
  10270. +
  10271. +   public static void addFlagToPlayer(Player _player)
  10272. +   {
  10273. +       // remove items from the player hands (right, left, both)
  10274. +       // This is NOT a BUG, I don't want them to see the icon they have 8D
  10275. +       ItemInstance wpn = _player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  10276. +       if (wpn == null)
  10277. +       {
  10278. +           wpn = _player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  10279. +           if (wpn != null)
  10280. +               _player.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_LHAND);
  10281. +       }
  10282. +       else
  10283. +       {
  10284. +           _player.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_RHAND);
  10285. +           wpn = _player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  10286. +           if (wpn != null)
  10287. +               _player.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_LHAND);
  10288. +       }
  10289. +       // add the flag in his hands
  10290. +       _player.getInventory().equipItem(ItemTable.getInstance().createItem("", CTF._FLAG_IN_HAND_ITEM_ID, 1, _player, null));
  10291. +       _player.broadcastPacket(new SocialAction(_player, 16),2000); // amazing glow
  10292. +       _player._haveFlagCTF = true;
  10293. +       _player.broadcastUserInfo();
  10294. +       CreatureSay cs = new CreatureSay(_player.getObjectId(), 15, ":", "You got it! Run back! ::"); // 8D
  10295. +       _player.sendPacket(cs);
  10296. +   }
  10297. +
  10298. +   public static void removeFlagFromPlayer(Player player)
  10299. +   {
  10300. +       ItemInstance wpn = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  10301. +       player._haveFlagCTF = false;
  10302. +       if (wpn != null)
  10303. +       {
  10304. +           ItemInstance[] unequiped = player.getInventory().unEquipItemInBodySlotAndRecord(wpn);
  10305. +           player.getInventory().destroyItemByItemId("", CTF._FLAG_IN_HAND_ITEM_ID, 1, player, null);
  10306. +           InventoryUpdate iu = new InventoryUpdate();
  10307. +           for (ItemInstance element : unequiped)
  10308. +               iu.addModifiedItem(element);
  10309. +           player.sendPacket(iu);
  10310. +           player.sendPacket(new ItemList(player, true)); // get your weapon back now ...
  10311. +           player.abortAttack();
  10312. +           player.broadcastUserInfo();
  10313. +       }
  10314. +       else
  10315. +       {
  10316. +           player.getInventory().destroyItemByItemId("", CTF._FLAG_IN_HAND_ITEM_ID, 1, player, null);
  10317. +           player.sendPacket(new ItemList(player, true)); // get your weapon back now ...
  10318. +           player.abortAttack();
  10319. +           player.broadcastUserInfo();
  10320. +       }
  10321. +   }
  10322. +
  10323. +   public static void setTeamFlag(String teamName, Player activeChar)
  10324. +   {
  10325. +       int index = _teams.indexOf(teamName);
  10326. +
  10327. +       if (index == -1)
  10328. +           return;
  10329. +       addOrSet(_teams.indexOf(teamName), null, false, _FlagNPC, activeChar.getX(), activeChar.getY(), activeChar.getZ());
  10330. +   }
  10331. +
  10332. +   public static void setTeamFlag(String teamName, int x, int y, int z)
  10333. +   {
  10334. +       int index = _teams.indexOf(teamName);
  10335. +
  10336. +       if (index == -1)
  10337. +           return;
  10338. +       addOrSet(_teams.indexOf(teamName), null, false, _FlagNPC, x, y, z);
  10339. +   }
  10340. +
  10341. +   public static void spawnAllFlags()
  10342. +   {
  10343. +       while (_flagSpawns.size() < _teams.size())
  10344. +           _flagSpawns.add(null);
  10345. +       while (_throneSpawns.size() < _teams.size())
  10346. +           _throneSpawns.add(null);
  10347. +       for (String team : _teams)
  10348. +       {
  10349. +           int index = _teams.indexOf(team);
  10350. +           NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_flagIds.get(index));
  10351. +           NpcTemplate throne = NpcTable.getInstance().getTemplate(32027);
  10352. +           try
  10353. +           {
  10354. +               // spawn throne
  10355. +               _throneSpawns.set(index, new L2Spawn(throne));
  10356. +               _throneSpawns.get(index).setLoc(_flagsX.get(index), _flagsY.get(index), _flagsZ.get(index) - 10, 0);
  10357. +               _throneSpawns.get(index).setRespawnDelay(1);
  10358. +              
  10359. +               SpawnTable.getInstance().addNewSpawn(_throneSpawns.get(index), false);
  10360. +              
  10361. +               _throneSpawns.get(index).setRespawnState(true);
  10362. +               _throneSpawns.get(index).doSpawn(false);
  10363. +               _throneSpawns.get(index).getNpc().getStatus().setCurrentHp(999999999);
  10364. +               _throneSpawns.get(index).getNpc().decayMe();
  10365. +               _throneSpawns.get(index).getNpc().spawnMe(_throneSpawns.get(index).getNpc().getX(), _throneSpawns.get(index).getNpc().getY(), _throneSpawns.get(index).getNpc().getZ());
  10366. +               _throneSpawns.get(index).getNpc().setTitle(team + " Throne");
  10367. +               _throneSpawns.get(index).getNpc().broadcastPacket(new MagicSkillUse(_throneSpawns.get(index).getNpc(), _throneSpawns.get(index).getNpc(), 1036, 1, 5500, 1));
  10368. +               _throneSpawns.get(index).getNpc()._isCTF_throneSpawn = true;
  10369. +
  10370. +               // spawn flag
  10371. +               _flagSpawns.set(index, new L2Spawn(tmpl));
  10372. +               _flagSpawns.get(index).setLoc(_flagsX.get(index), _flagsY.get(index), _flagsZ.get(index), 0);
  10373. +               _flagSpawns.get(index).setRespawnDelay(1);
  10374. +              
  10375. +               SpawnTable.getInstance().addNewSpawn(_flagSpawns.get(index), false);
  10376. +              
  10377. +               _flagSpawns.get(index).setRespawnState(true);
  10378. +               _flagSpawns.get(index).doSpawn(false);
  10379. +               _flagSpawns.get(index).getNpc().getStatus().setCurrentHp(999999999);
  10380. +               _flagSpawns.get(index).getNpc().setTitle(team + "'s Flag");
  10381. +               _flagSpawns.get(index).getNpc()._CTF_FlagTeamName = team;
  10382. +               _flagSpawns.get(index).getNpc().decayMe();
  10383. +               _flagSpawns.get(index).getNpc().spawnMe(_flagSpawns.get(index).getNpc().getX(), _flagSpawns.get(index).getNpc().getY(), _flagSpawns.get(index).getNpc().getZ());
  10384. +               _flagSpawns.get(index).getNpc()._isCTF_Flag = true;
  10385. +               if (index == (_teams.size() - 1))
  10386. +                   calculateOutSideOfCTF(); // sets event boundaries so players don't run with the flag.
  10387. +           }
  10388. +           catch (Exception e)
  10389. +           {
  10390. +               _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[spawnAllFlags()]: exception: " + e.getStackTrace());
  10391. +           }
  10392. +       }
  10393. +   }
  10394. +
  10395. +   public static void processTopTeam()
  10396. +   {
  10397. +       _topTeam = null;
  10398. +       for (String team : _teams)
  10399. +       {
  10400. +           if (teamPointsCount(team) == _topScore && _topScore > 0)
  10401. +               _topTeam = null;
  10402. +           if (teamPointsCount(team) > _topScore)
  10403. +           {
  10404. +               _topTeam = team;
  10405. +               _topScore = teamPointsCount(team);
  10406. +           }
  10407. +       }
  10408. +       if (_topScore <= 0)
  10409. +       {
  10410. +           AnnounceToPlayers(true, _eventName + "(CTF): No flags taken.");
  10411. +       }
  10412. +       else
  10413. +       {
  10414. +           if (_topTeam == null)
  10415. +               AnnounceToPlayers(true, _eventName + "(CTF): Maximum flags taken : " + _topScore + " flags! No one won.");
  10416. +           else
  10417. +           {
  10418. +               AnnounceToPlayers(true, _eventName + "(CTF): Team " + _topTeam + " wins the match, with " + _topScore + " flags taken!");
  10419. +               rewardTeam(_topTeam);
  10420. +           }
  10421. +       }
  10422. +       teleportFinish();
  10423. +   }
  10424. +
  10425. +   public static void unspawnAllFlags()
  10426. +   {
  10427. +       try
  10428. +       {
  10429. +           if ((_throneSpawns == null) || (_flagSpawns == null) || (_teams == null))
  10430. +               return;
  10431. +           for (String team : _teams)
  10432. +           {
  10433. +               int index = _teams.indexOf(team);
  10434. +               if (_throneSpawns.get(index) != null)
  10435. +               {
  10436. +                   _throneSpawns.get(index).getNpc().deleteMe();
  10437. +                   _throneSpawns.get(index).setRespawnState(false);
  10438. +                   SpawnTable.getInstance().deleteSpawn(_throneSpawns.get(index), true);
  10439. +               }
  10440. +               if (_flagSpawns.get(index) != null)
  10441. +               {
  10442. +                   _flagSpawns.get(index).getNpc().deleteMe();
  10443. +                   _flagSpawns.get(index).setRespawnState(false);
  10444. +                   SpawnTable.getInstance().deleteSpawn(_flagSpawns.get(index), true);
  10445. +               }
  10446. +           }
  10447. +           _throneSpawns.clear();
  10448. +       }
  10449. +       catch (Throwable t)
  10450. +       {
  10451. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[unspawnAllFlags()]: exception: " + t.getStackTrace());
  10452. +       }
  10453. +   }
  10454. +
  10455. +   private static void unspawnFlag(String teamName)
  10456. +   {
  10457. +       int index = _teams.indexOf(teamName);
  10458. +
  10459. +       _flagSpawns.get(index).getNpc().deleteMe();
  10460. +       _flagSpawns.get(index).setRespawnState(false);
  10461. +       SpawnTable.getInstance().deleteSpawn(_flagSpawns.get(index), true);
  10462. +   }
  10463. +
  10464. +   public static void spawnFlag(String teamName)
  10465. +   {
  10466. +       int index = _teams.indexOf(teamName);
  10467. +       NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_flagIds.get(index));
  10468. +
  10469. +       try
  10470. +       {
  10471. +           _flagSpawns.set(index, new L2Spawn(tmpl));
  10472. +
  10473. +           _flagSpawns.get(index).setLoc(_flagsX.get(index), _flagsY.get(index), _flagsZ.get(index), 0);
  10474. +           _flagSpawns.get(index).setRespawnDelay(1);
  10475. +
  10476. +           SpawnTable.getInstance().addNewSpawn(_flagSpawns.get(index), false);
  10477. +
  10478. +           _flagSpawns.get(index).setRespawnState(true);
  10479. +           _flagSpawns.get(index).doSpawn(false);
  10480. +           _flagSpawns.get(index).getNpc().getStatus().setCurrentHp(999999999);
  10481. +           _flagSpawns.get(index).getNpc().setTitle(teamName + "'s Flag");
  10482. +           _flagSpawns.get(index).getNpc()._CTF_FlagTeamName = teamName;
  10483. +           _flagSpawns.get(index).getNpc()._isCTF_Flag = true;
  10484. +           _flagSpawns.get(index).getNpc().decayMe();
  10485. +           _flagSpawns.get(index).getNpc().spawnMe(_flagSpawns.get(index).getNpc().getX(), _flagSpawns.get(index).getNpc().getY(), _flagSpawns.get(index).getNpc().getZ());
  10486. +       }
  10487. +       catch (Exception e)
  10488. +       {
  10489. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[spawnFlag(" + teamName + ")]: exception: " + e.getStackTrace());
  10490. +       }
  10491. +   }
  10492. +
  10493. +   public static boolean InRangeOfFlag(Player _player, int flagIndex, int offset)
  10494. +   {
  10495. +       if (_player.getX() > CTF._flagsX.get(flagIndex) - offset && _player.getX() < CTF._flagsX.get(flagIndex) + offset && _player.getY() > CTF._flagsY.get(flagIndex) - offset && _player.getY() < CTF._flagsY.get(flagIndex) + offset && _player.getZ() > CTF._flagsZ.get(flagIndex) - offset && _player.getZ() < CTF._flagsZ.get(flagIndex) + offset)
  10496. +           return true;
  10497. +       return false;
  10498. +   }
  10499. +
  10500. +   public static void processInFlagRange(Player _player)
  10501. +   {
  10502. +       try
  10503. +       {
  10504. +           CheckRestoreFlags();
  10505. +           for (String team : _teams)
  10506. +           {
  10507. +               if (team.equals(_player._teamNameCTF))
  10508. +               {
  10509. +                   int indexOwn = _teams.indexOf(_player._teamNameCTF);
  10510. +
  10511. +                   // if player is near his team flag holding the enemy flag
  10512. +                   if (InRangeOfFlag(_player, indexOwn, 100) && !_flagsTaken.get(indexOwn) && _player._haveFlagCTF)
  10513. +                   {
  10514. +                       int indexEnemy = _teams.indexOf(_player._teamNameHaveFlagCTF);
  10515. +                       // return enemy flag to place
  10516. +                       _flagsTaken.set(indexEnemy, false);
  10517. +                       spawnFlag(_player._teamNameHaveFlagCTF);
  10518. +                       // remove the flag from this player
  10519. +                       _player.broadcastPacket(new SocialAction(_player, 16),2000); // amazing glow
  10520. +                       _player.broadcastUserInfo();
  10521. +                       _player.broadcastPacket(new SocialAction(_player, 3),2000); // Victory
  10522. +                       _player.broadcastUserInfo();
  10523. +                       removeFlagFromPlayer(_player);
  10524. +                       _teamPointsCount.set(indexOwn, teamPointsCount(team) + 1);
  10525. +                          
  10526. +                       _player.broadcastUserInfo();
  10527. +                      
  10528. +                       AnnounceToPlayers(false, _eventName + "(CTF): " + _player.getName() + " scores for " + _player._teamNameCTF + ".");
  10529. +                   }
  10530. +               }
  10531. +               else
  10532. +               {
  10533. +                   int indexEnemy = _teams.indexOf(team);
  10534. +                   // if the player is near a enemy flag
  10535. +                   if (InRangeOfFlag(_player, indexEnemy, 100) && !_flagsTaken.get(indexEnemy) && !_player._haveFlagCTF && !_player.isDead())
  10536. +                   {
  10537. +                       if (_player.isRiding() || _player.isFlying())
  10538. +                       {
  10539. +                           _player.sendPacket(ActionFailed.STATIC_PACKET);
  10540. +                           break;
  10541. +                       }
  10542. +
  10543. +                       _flagsTaken.set(indexEnemy, true);
  10544. +                       unspawnFlag(team);
  10545. +                       _player._teamNameHaveFlagCTF = team;
  10546. +                       addFlagToPlayer(_player);
  10547. +                       _player.broadcastUserInfo();
  10548. +                       _player._haveFlagCTF = true;
  10549. +                       AnnounceToPlayers(false, _eventName + "(CTF): " + team + " flag taken by " + _player.getName() + "...");
  10550. +                       pointTeamTo(_player, team);
  10551. +                       break;
  10552. +                   }
  10553. +               }
  10554. +           }
  10555. +       }
  10556. +       catch (Exception e)
  10557. +       {
  10558. +           e.printStackTrace();
  10559. +       }
  10560. +   }
  10561. +
  10562. +   public static void pointTeamTo(Player hasFlag, String ourFlag)
  10563. +   {
  10564. +       try
  10565. +       {
  10566. +           for (Player player : _players)
  10567. +           {
  10568. +               if (player != null && player.isOnline())
  10569. +               {
  10570. +                   if (player._teamNameCTF.equals(ourFlag))
  10571. +                   {
  10572. +                       player.sendMessage(hasFlag.getName() + " took your flag!");
  10573. +                       if (player._haveFlagCTF)
  10574. +                       {
  10575. +                           player.sendMessage("You can not return the flag to headquarters, until your flag is returned to it's place.");
  10576. +                           player.sendPacket(new RadarControl(1, 1, player.getX(), player.getY(), player.getZ()));
  10577. +                       }
  10578. +                       else
  10579. +                       {
  10580. +                           player.sendPacket(new RadarControl(0, 1, hasFlag.getX(), hasFlag.getY(), hasFlag.getZ()));
  10581. +                           L2Radar rdr = new L2Radar(player);
  10582. +                           L2Radar.RadarOnPlayer radar = rdr.new RadarOnPlayer(hasFlag, player);
  10583. +                           ThreadPool.schedule(radar, 10000 + Rnd.get(30000));
  10584. +                       }
  10585. +                   }
  10586. +               }
  10587. +           }
  10588. +       }
  10589. +       catch (Throwable t)
  10590. +       {
  10591. +       }
  10592. +   }
  10593. +
  10594. +   public static int teamPointsCount(String teamName)
  10595. +   {
  10596. +       int index = _teams.indexOf(teamName);
  10597. +
  10598. +       if (index == -1)
  10599. +           return -1;
  10600. +
  10601. +       return _teamPointsCount.get(index);
  10602. +   }
  10603. +
  10604. +   public static void setTeamPointsCount(String teamName, int teamPointCount)
  10605. +   {
  10606. +       int index = _teams.indexOf(teamName);
  10607. +
  10608. +       if (index == -1)
  10609. +           return;
  10610. +
  10611. +       _teamPointsCount.set(index, teamPointCount);
  10612. +   }
  10613. +
  10614. +   public static int teamPlayersCount(String teamName)
  10615. +   {
  10616. +       int index = _teams.indexOf(teamName);
  10617. +
  10618. +       if (index == -1)
  10619. +           return -1;
  10620. +
  10621. +       return _teamPlayersCount.get(index);
  10622. +   }
  10623. +
  10624. +   public static void setTeamPlayersCount(String teamName, int teamPlayersCount)
  10625. +   {
  10626. +       int index = _teams.indexOf(teamName);
  10627. +
  10628. +       if (index == -1)
  10629. +           return;
  10630. +
  10631. +       _teamPlayersCount.set(index, teamPlayersCount);
  10632. +   }
  10633. +
  10634. +   public static void setNpcPos(Player activeChar)
  10635. +   {
  10636. +       _npcX = activeChar.getX();
  10637. +       _npcY = activeChar.getY();
  10638. +       _npcZ = activeChar.getZ();
  10639. +       _npcHeading = activeChar.getHeading();
  10640. +   }
  10641. +
  10642. +   public static void setNpcPos(int x, int y, int z)
  10643. +   {
  10644. +       _npcX = x;
  10645. +       _npcY = y;
  10646. +       _npcZ = z;
  10647. +   }
  10648. +
  10649. +   public static void addTeam(String teamName)
  10650. +   {
  10651. +       if (!checkTeamOk())
  10652. +       {
  10653. +           if (Config.DEBUG)
  10654. +               _log.fine("CTF Engine[addTeam(" + teamName + ")]: checkTeamOk() = false");
  10655. +           return;
  10656. +       }
  10657. +
  10658. +       if (teamName.equals(" "))
  10659. +           return;
  10660. +
  10661. +       _teams.add(teamName);
  10662. +       _teamPlayersCount.add(0);
  10663. +       _teamColors.add(0);
  10664. +       _teamsX.add(0);
  10665. +       _teamsY.add(0);
  10666. +       _teamsZ.add(0);
  10667. +       _teamPointsCount.add(0);
  10668. +       addOrSet(_teams.indexOf(teamName), null, false, _FlagNPC, 0, 0, 0);
  10669. +   }
  10670. +
  10671. +   private static void addOrSet(int listSize, L2Spawn flagSpawn, boolean flagsTaken, int flagId, int flagX, int flagY, int flagZ)
  10672. +   {
  10673. +       while (_flagsX.size() <= listSize)
  10674. +       {
  10675. +           _flagSpawns.add(null);
  10676. +           _flagsTaken.add(false);
  10677. +           _flagIds.add(_FlagNPC);
  10678. +           _flagsX.add(0);
  10679. +           _flagsY.add(0);
  10680. +           _flagsZ.add(0);
  10681. +       }
  10682. +       _flagSpawns.set(listSize, flagSpawn);
  10683. +       _flagsTaken.set(listSize, flagsTaken);
  10684. +       _flagIds.set(listSize, flagId);
  10685. +       _flagsX.set(listSize, flagX);
  10686. +       _flagsY.set(listSize, flagY);
  10687. +       _flagsZ.set(listSize, flagZ);
  10688. +   }
  10689. +
  10690. +   public static boolean checkMaxLevel(int maxlvl)
  10691. +   {
  10692. +       if (_minlvl >= maxlvl)
  10693. +           return false;
  10694. +
  10695. +       return true;
  10696. +   }
  10697. +
  10698. +   public static boolean checkMinLevel(int minlvl)
  10699. +   {
  10700. +       if (_maxlvl <= minlvl)
  10701. +           return false;
  10702. +
  10703. +       return true;
  10704. +   }
  10705. +
  10706. +   /** returns true if participated players is higher or equal then minimum needed players
  10707. +    * @param players
  10708. +    * @return */
  10709. +   public static boolean checkMinPlayers(int players)
  10710. +   {
  10711. +       if (_minPlayers <= players)
  10712. +           return true;
  10713. +
  10714. +       return false;
  10715. +   }
  10716. +
  10717. +   /** returns true if max players is higher or equal then participated players
  10718. +    * @param players
  10719. +    * @return */
  10720. +   public static boolean checkMaxPlayers(int players)
  10721. +   {
  10722. +       if (_maxPlayers > players)
  10723. +           return true;
  10724. +
  10725. +       return false;
  10726. +   }
  10727. +
  10728. +   public static void removeTeam(String teamName)
  10729. +   {
  10730. +       if (!checkTeamOk() || _teams.isEmpty())
  10731. +       {
  10732. +           if (Config.DEBUG)
  10733. +               _log.fine("CTF Engine[removeTeam(" + teamName + ")]: checkTeamOk() = false");
  10734. +           return;
  10735. +       }
  10736. +
  10737. +       if (teamPlayersCount(teamName) > 0)
  10738. +       {
  10739. +           if (Config.DEBUG)
  10740. +               _log.fine("CTF Engine[removeTeam(" + teamName + ")]: teamPlayersCount(teamName) > 0");
  10741. +           return;
  10742. +       }
  10743. +
  10744. +       int index = _teams.indexOf(teamName);
  10745. +
  10746. +       if (index == -1)
  10747. +           return;
  10748. +
  10749. +       _teamsZ.remove(index);
  10750. +       _teamsY.remove(index);
  10751. +       _teamsX.remove(index);
  10752. +       _teamColors.remove(index);
  10753. +       _teamPointsCount.remove(index);
  10754. +       _teamPlayersCount.remove(index);
  10755. +       _teams.remove(index);
  10756. +       _flagSpawns.remove(index);
  10757. +       _flagsTaken.remove(index);
  10758. +       _flagIds.remove(index);
  10759. +       _flagsX.remove(index);
  10760. +       _flagsY.remove(index);
  10761. +       _flagsZ.remove(index);
  10762. +   }
  10763. +
  10764. +   public static void setTeamPos(String teamName, Player activeChar)
  10765. +   {
  10766. +       int index = _teams.indexOf(teamName);
  10767. +
  10768. +       if (index == -1)
  10769. +           return;
  10770. +
  10771. +       _teamsX.set(index, activeChar.getX());
  10772. +       _teamsY.set(index, activeChar.getY());
  10773. +       _teamsZ.set(index, activeChar.getZ());
  10774. +   }
  10775. +
  10776. +   public static void setTeamPos(String teamName, int x, int y, int z)
  10777. +   {
  10778. +       int index = _teams.indexOf(teamName);
  10779. +
  10780. +       if (index == -1)
  10781. +           return;
  10782. +
  10783. +       _teamsX.set(index, x);
  10784. +       _teamsY.set(index, y);
  10785. +       _teamsZ.set(index, z);
  10786. +   }
  10787. +
  10788. +   public static void setTeamColor(String teamName, int color)
  10789. +   {
  10790. +       if (!checkTeamOk())
  10791. +           return;
  10792. +
  10793. +       int index = _teams.indexOf(teamName);
  10794. +
  10795. +       if (index == -1)
  10796. +           return;
  10797. +
  10798. +       _teamColors.set(index, color);
  10799. +   }
  10800. +
  10801. +   public static boolean checkTeamOk()
  10802. +   {
  10803. +       if (_started || _teleport || _joining)
  10804. +           return false;
  10805. +
  10806. +       return true;
  10807. +   }
  10808. +
  10809. +   public static void startJoin(Player activeChar)
  10810. +   {
  10811. +       if (!startJoinOk())
  10812. +       {
  10813. +           activeChar.sendMessage("Event not setted propertly.");
  10814. +           if (Config.DEBUG)
  10815. +               _log.fine("CTF Engine[startJoin(" + activeChar.getName() + ")]: startJoinOk() = false");
  10816. +           return;
  10817. +       }
  10818. +
  10819. +       _joining = true;
  10820. +       spawnEventNpc(activeChar);
  10821. +       AnnounceToPlayers(true, _eventName + " (CTF)!");
  10822. +       if (Config.CTF_ANNOUNCE_REWARD)
  10823. +           AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).getName());
  10824. +       AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
  10825. +       AnnounceToPlayers(true, "Joinable in " + _joiningLocationName + "!");
  10826. +   }
  10827. +
  10828. +   public static void startJoin()
  10829. +   {
  10830. +       if (!startJoinOk())
  10831. +       {
  10832. +           _log.warning(CTF.class.getSimpleName() + ":  Event not setted propertly.");
  10833. +           if (Config.DEBUG)
  10834. +               _log.fine("CTF Engine[startJoin(startJoinOk() = false");
  10835. +           return;
  10836. +       }
  10837. +
  10838. +       _joining = true;
  10839. +       spawnEventNpc();
  10840. +       AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
  10841. +       AnnounceToPlayers(true, "Joinable in " + _joiningLocationName + "!");
  10842. +       if (Config.CTF_ANNOUNCE_REWARD)
  10843. +           AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).getName());
  10844. +   }
  10845. +
  10846. +   public static boolean startAutoJoin()
  10847. +   {
  10848. +       if (!startJoinOk())
  10849. +       {
  10850. +           if (Config.DEBUG)
  10851. +               _log.fine("CTF Engine[startJoin]: startJoinOk() = false");
  10852. +           return false;
  10853. +       }
  10854. +
  10855. +       _joining = true;
  10856. +       spawnEventNpc();
  10857. +       AnnounceToPlayers(true, _eventName + " (CTF)!");
  10858. +       if (Config.CTF_ANNOUNCE_REWARD)
  10859. +           AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).getName());
  10860. +       AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
  10861. +       AnnounceToPlayers(true, "Joinable in " + _joiningLocationName + "!");
  10862. +       return true;
  10863. +   }
  10864. +
  10865. +   public static boolean startJoinOk()
  10866. +   {
  10867. +       if (_started || _teleport || _joining || _teams.size() < 2 || _eventName.equals("") || _joiningLocationName.equals("") || _eventDesc.equals("") || _npcId == 0 || _npcX == 0 || _npcY == 0 || _npcZ == 0 || _rewardId == 0 || _rewardAmount == 0 || _teamsX.contains(0) || _teamsY.contains(0) || _teamsZ.contains(0))
  10868. +           return false;
  10869. +       try
  10870. +       {
  10871. +           if (_flagsX.contains(0) || _flagsY.contains(0) || _flagsZ.contains(0) || _flagIds.contains(0))
  10872. +               return false;
  10873. +           if (_flagsX.size() < _teams.size() || _flagsY.size() < _teams.size() || _flagsZ.size() < _teams.size() || _flagIds.size() < _teams.size())
  10874. +               return false;
  10875. +       }
  10876. +       catch (ArrayIndexOutOfBoundsException e)
  10877. +       {
  10878. +           return false;
  10879. +       }
  10880. +       return true;
  10881. +   }
  10882. +
  10883. +   private static void spawnEventNpc(Player activeChar)
  10884. +   {
  10885. +       NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
  10886. +
  10887. +       try
  10888. +       {
  10889. +           _npcSpawn = new L2Spawn(tmpl);
  10890. +           _npcSpawn.setLoc(_npcX, _npcY, _npcZ, _npcHeading);
  10891. +           _npcSpawn.setRespawnDelay(1);
  10892. +
  10893. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  10894. +
  10895. +           _npcSpawn.setRespawnState(true);
  10896. +           _npcSpawn.doSpawn(false);
  10897. +           _npcSpawn.getNpc().getStatus().setCurrentHp(999999999);
  10898. +           _npcSpawn.getNpc().setTitle(_eventName);
  10899. +           _npcSpawn.getNpc()._isEventMobCTF = true;
  10900. +           _npcSpawn.getNpc().isAggressive();
  10901. +           _npcSpawn.getNpc().decayMe();
  10902. +           _npcSpawn.getNpc().spawnMe(_npcSpawn.getNpc().getX(), _npcSpawn.getNpc().getY(), _npcSpawn.getNpc().getZ());
  10903. +
  10904. +           _npcSpawn.getNpc().broadcastPacket(new MagicSkillUse(_npcSpawn.getNpc(), _npcSpawn.getNpc(), 1034, 1, 1, 1));
  10905. +       }
  10906. +       catch (Exception e)
  10907. +       {
  10908. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[spawnEventNpc(" + activeChar.getName() + ")]: exception: " + e.getMessage());
  10909. +       }
  10910. +   }
  10911. +
  10912. +   private static void spawnEventNpc()
  10913. +   {
  10914. +       NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
  10915. +
  10916. +       try
  10917. +       {
  10918. +           _npcSpawn = new L2Spawn(tmpl);
  10919. +
  10920. +           _npcSpawn.setLoc(_npcX, _npcY, _npcZ, _npcHeading);
  10921. +           _npcSpawn.setRespawnDelay(1);
  10922. +
  10923. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  10924. +
  10925. +           _npcSpawn.setRespawnState(true);
  10926. +           _npcSpawn.doSpawn(false);
  10927. +           _npcSpawn.getNpc().getStatus().setCurrentHp(999999999);
  10928. +           _npcSpawn.getNpc().setTitle(_eventName);
  10929. +           _npcSpawn.getNpc()._isEventMobCTF = true;
  10930. +           _npcSpawn.getNpc().isAggressive();
  10931. +           _npcSpawn.getNpc().decayMe();
  10932. +           _npcSpawn.getNpc().spawnMe(_npcSpawn.getNpc().getX(), _npcSpawn.getNpc().getY(), _npcSpawn.getNpc().getZ());
  10933. +
  10934. +           _npcSpawn.getNpc().broadcastPacket(new MagicSkillUse(_npcSpawn.getNpc(), _npcSpawn.getNpc(), 1034, 1, 1, 1));
  10935. +       }
  10936. +       catch (Exception e)
  10937. +       {
  10938. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[spawnEventNpc(exception: " + e.getMessage());
  10939. +       }
  10940. +   }
  10941. +
  10942. +   public static void teleportStart()
  10943. +   {
  10944. +       if (!_joining || _started || _teleport)
  10945. +           return;
  10946. +
  10947. +       if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && checkMinPlayers(_playersShuffle.size()))
  10948. +       {
  10949. +           removeOfflinePlayers();
  10950. +           shuffleTeams();
  10951. +       }
  10952. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !checkMinPlayers(_playersShuffle.size()))
  10953. +       {
  10954. +           AnnounceToPlayers(true, "Not enough players for event. Min Requested : " + _minPlayers + ", Participating : " + _playersShuffle.size());
  10955. +           return;
  10956. +       }
  10957. +
  10958. +       _joining = false;
  10959. +       AnnounceToPlayers(true, _eventName + "(CTF): Teleport to team spot in 20 seconds!");
  10960. +
  10961. +       setUserData();
  10962. +       ThreadPool.schedule(new Runnable()
  10963. +       {
  10964. +           @Override
  10965. +           public void run()
  10966. +           {
  10967. +               CTF.sit();
  10968. +               CTF.spawnAllFlags();
  10969. +               for (Player player : _players)
  10970. +               {
  10971. +                   if (player != null)
  10972. +                   {
  10973. +                       if (Config.CTF_ON_START_UNSUMMON_PET)
  10974. +                       {
  10975. +                           // Remove Summon's buffs
  10976. +                           if (player.getPet() != null)
  10977. +                           {
  10978. +                               Summon summon = player.getPet();
  10979. +                               for (L2Effect e : summon.getAllEffects())
  10980. +                                   if (e != null)
  10981. +                                       e.exit();
  10982. +
  10983. +                               if (summon instanceof Pet)
  10984. +                                   summon.unSummon(player);
  10985. +                           }
  10986. +                       }
  10987. +
  10988. +                       if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
  10989. +                       {
  10990. +                           for (L2Effect e : player.getAllEffects())
  10991. +                           {
  10992. +                               if (e != null)
  10993. +                                   e.exit();
  10994. +                           }
  10995. +                       }
  10996. +
  10997. +                       // Remove player from his party
  10998. +                       if (player.getParty() != null)
  10999. +                       {
  11000. +                           Party party = player.getParty();
  11001. +                           party.removePartyMember(player, MessageType.EXPELLED);
  11002. +                       }
  11003. +                       player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ.get(_teams.indexOf(player._teamNameCTF)), 0);
  11004. +                   }
  11005. +               }
  11006. +           }
  11007. +       }, 20000);
  11008. +       _teleport = true;
  11009. +   }
  11010. +
  11011. +   public static boolean teleportAutoStart()
  11012. +   {
  11013. +       if (!_joining || _started || _teleport)
  11014. +           return false;
  11015. +
  11016. +       if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && checkMinPlayers(_playersShuffle.size()))
  11017. +       {
  11018. +           removeOfflinePlayers();
  11019. +           shuffleTeams();
  11020. +       }
  11021. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !checkMinPlayers(_playersShuffle.size()))
  11022. +       {
  11023. +           AnnounceToPlayers(true, "Not enough players for event. Min Requested : " + _minPlayers + ", Participating : " + _playersShuffle.size());
  11024. +           return false;
  11025. +       }
  11026. +
  11027. +       _joining = false;
  11028. +       AnnounceToPlayers(false, _eventName + "(CTF): Teleport to team spot in 20 seconds!");
  11029. +
  11030. +       setUserData();
  11031. +       ThreadPool.schedule(new Runnable()
  11032. +       {
  11033. +           @Override
  11034. +           public void run()
  11035. +           {
  11036. +               sit();
  11037. +               spawnAllFlags();
  11038. +
  11039. +               for (Player player : _players)
  11040. +               {
  11041. +                   if (player != null)
  11042. +                   {
  11043. +                       if (Config.CTF_ON_START_UNSUMMON_PET)
  11044. +                       {
  11045. +                           // Remove Summon's buffs
  11046. +                           if (player.getPet() != null)
  11047. +                           {
  11048. +                               Summon summon = player.getPet();
  11049. +                               for (L2Effect e : summon.getAllEffects())
  11050. +                                   if (e != null)
  11051. +                                       e.exit();
  11052. +
  11053. +                               if (summon instanceof Pet)
  11054. +                                   summon.unSummon(player);
  11055. +                           }
  11056. +                       }
  11057. +                       if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
  11058. +                       {
  11059. +                           for (L2Effect e : player.getAllEffects())
  11060. +                           {
  11061. +                               if (e != null)
  11062. +                                   e.exit();
  11063. +                           }
  11064. +                       }
  11065. +
  11066. +                       // Remove player from his party
  11067. +                       if (player.getParty() != null)
  11068. +                       {
  11069. +                           Party party = player.getParty();
  11070. +                           party.removePartyMember(player, MessageType.EXPELLED);
  11071. +                       }
  11072. +
  11073. +                       player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ.get(_teams.indexOf(player._teamNameCTF)), 0);
  11074. +                   }
  11075. +               }
  11076. +           }
  11077. +       }, 20000);
  11078. +       _teleport = true;
  11079. +       return true;
  11080. +   }
  11081. +
  11082. +   public static void startEvent(Player activeChar)
  11083. +   {
  11084. +       if (!startEventOk())
  11085. +       {
  11086. +           if (Config.DEBUG)
  11087. +               _log.fine("CTF Engine[startEvent(" + activeChar.getName() + ")]: startEventOk() = false");
  11088. +           return;
  11089. +       }
  11090. +
  11091. +       _teleport = false;
  11092. +       sit();
  11093. +       _started = true;
  11094. +       StartEvent();
  11095. +   }
  11096. +
  11097. +   public static void setJoinTime(int time)
  11098. +   {
  11099. +       _joinTime = time;
  11100. +   }
  11101. +
  11102. +   public static void setEventTime(int time)
  11103. +   {
  11104. +       _eventTime = time;
  11105. +   }
  11106. +
  11107. +   public static boolean startAutoEvent()
  11108. +   {
  11109. +       if (!startEventOk())
  11110. +       {
  11111. +           if (Config.DEBUG)
  11112. +               _log.fine("CTF Engine[startEvent]: startEventOk() = false");
  11113. +           return false;
  11114. +       }
  11115. +
  11116. +       _teleport = false;
  11117. +       sit();
  11118. +       AnnounceToPlayers(true, _eventName + "(CTF): Started. Go Capture the Flags!");
  11119. +       _started = true;
  11120. +       return true;
  11121. +   }
  11122. +
  11123. +   public static synchronized void autoEvent()
  11124. +   {
  11125. +       if (startAutoJoin())
  11126. +       {
  11127. +           if (_joinTime > 0)
  11128. +               waiter(_joinTime * 60 * 1000); // minutes for join event
  11129. +           else if (_joinTime <= 0)
  11130. +           {
  11131. +               abortEvent();
  11132. +               return;
  11133. +           }
  11134. +           if (teleportAutoStart())
  11135. +           {
  11136. +               waiter(1 * 30 * 1000); // 30 seconds wait time until start fight after teleported
  11137. +               if (startAutoEvent())
  11138. +               {
  11139. +                   waiter(_eventTime * 60 * 1000); // minutes for event time
  11140. +                   finishEvent();
  11141. +               }
  11142. +           }
  11143. +           else if (!teleportAutoStart())
  11144. +           {
  11145. +               abortEvent();
  11146. +           }
  11147. +       }
  11148. +   }
  11149. +
  11150. +   private static synchronized void waiter(long interval)
  11151. +   {
  11152. +       long startWaiterTime = System.currentTimeMillis();
  11153. +       int seconds = (int) (interval / 1000);
  11154. +
  11155. +       while (startWaiterTime + interval > System.currentTimeMillis())
  11156. +       {
  11157. +           seconds--; // here because we don't want to see two time announce at the same time
  11158. +
  11159. +           if (_joining || _started || _teleport)
  11160. +           {
  11161. +               switch (seconds)
  11162. +               {
  11163. +                   case 3600: // 1 hour left
  11164. +                       if (_joining)
  11165. +                       {
  11166. +                           AnnounceToPlayers(true, _eventName + "(CTF): Joinable in " + _joiningLocationName + "!");
  11167. +                           AnnounceToPlayers(true, "CTF Event: " + seconds / 60 / 60 + " hour(s) till registration close!");
  11168. +                       }
  11169. +                       else if (_started)
  11170. +                           AnnounceToPlayers(false, "CTF Event: " + seconds / 60 / 60 + " hour(s) till event finish!");
  11171. +
  11172. +                   break;
  11173. +                   case 1800: // 30 minutes left
  11174. +                   case 600: // 10 minutes left
  11175. +                   case 180: // 3 minutes left
  11176. +                   case 120: // 2 minutes left
  11177. +                   case 60: // 1 minute left
  11178. +                       if (_joining)
  11179. +                       {
  11180. +                           removeOfflinePlayers();
  11181. +                           AnnounceToPlayers(true, _eventName + "(CTF): Joinable in " + _joiningLocationName + "!");
  11182. +                           AnnounceToPlayers(true, "CTF Event: " + seconds / 60 + " minute(s) till registration ends!");
  11183. +                       }
  11184. +                       else if (_started)
  11185. +                           AnnounceToPlayers(false, "CTF Event: " + seconds / 60 + " minute(s) till event ends!");
  11186. +
  11187. +                   break;
  11188. +                   case 30: // 30 seconds left
  11189. +                   case 10: // 10 seconds left
  11190. +                   case 3: // 3 seconds left
  11191. +                   case 2: // 2 seconds left
  11192. +                   case 1: // 1 seconds left
  11193. +                       if (_joining)
  11194. +                           AnnounceToPlayers(true, "CTF Event: " + seconds + " second(s) till registration close!");
  11195. +                       else if (_teleport)
  11196. +                           AnnounceToPlayers(false, "CTF Event: " + seconds + " seconds(s) till fight starts!");
  11197. +                       else if (_started)
  11198. +                           AnnounceToPlayers(false, "CTF Event: " + seconds + " second(s) till event ends!");
  11199. +
  11200. +                   break;
  11201. +               }
  11202. +           }
  11203. +
  11204. +           long startOneSecondWaiterStartTime = System.currentTimeMillis();
  11205. +
  11206. +           // only the try catch with Thread.sleep(1000) give bad countdown on high wait times
  11207. +           while (startOneSecondWaiterStartTime + 1000 > System.currentTimeMillis())
  11208. +           {
  11209. +               try
  11210. +               {
  11211. +                   Thread.sleep(1);
  11212. +               }
  11213. +               catch (InterruptedException ie)
  11214. +               {
  11215. +               }
  11216. +           }
  11217. +       }
  11218. +   }
  11219. +
  11220. +   private static boolean startEventOk()
  11221. +   {
  11222. +       if (_joining || !_teleport || _started)
  11223. +           return false;
  11224. +
  11225. +       if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  11226. +       {
  11227. +           if (_teamPlayersCount.contains(0))
  11228. +               return false;
  11229. +       }
  11230. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  11231. +       {
  11232. +           List<Player> playersShuffleTemp = new ArrayList<>();
  11233. +           int loopCount = 0;
  11234. +
  11235. +           loopCount = _playersShuffle.size();
  11236. +
  11237. +           for (int i = 0; i < loopCount; i++)
  11238. +           {
  11239. +               if (_playersShuffle != null)
  11240. +                   playersShuffleTemp.add(_playersShuffle.get(i));
  11241. +           }
  11242. +
  11243. +           _playersShuffle = playersShuffleTemp;
  11244. +           playersShuffleTemp.clear();
  11245. +
  11246. +           // if (_playersShuffle.size() < (_teams.size()*2)){
  11247. +           // return false;
  11248. +           // }
  11249. +       }
  11250. +
  11251. +       return true;
  11252. +   }
  11253. +
  11254. +   public static void shuffleTeams()
  11255. +   {
  11256. +       int teamCount = 0, playersCount = 0;
  11257. +
  11258. +       for (;;)
  11259. +       {
  11260. +           if (_playersShuffle.isEmpty())
  11261. +               break;
  11262. +
  11263. +           int playerToAddIndex = Rnd.nextInt(_playersShuffle.size());
  11264. +           Player player = null;
  11265. +           player = _playersShuffle.get(playerToAddIndex);
  11266. +           player._originalNameColorCTF = player.getAppearance().getNameColor();
  11267. +           player._originalKarmaCTF = player.getKarma();
  11268. +
  11269. +           _players.add(player);
  11270. +           _players.get(playersCount)._teamNameCTF = _teams.get(teamCount);
  11271. +           _savePlayers.add(_players.get(playersCount).getName());
  11272. +           _savePlayerTeams.add(_teams.get(teamCount));
  11273. +           playersCount++;
  11274. +
  11275. +           if (teamCount == _teams.size() - 1)
  11276. +               teamCount = 0;
  11277. +           else
  11278. +               teamCount++;
  11279. +
  11280. +           _playersShuffle.remove(playerToAddIndex);
  11281. +       }
  11282. +   }
  11283. +
  11284. +   public static void setUserData()
  11285. +   {
  11286. +       for (Player player : _players)
  11287. +       {
  11288. +           player.getAppearance().setNameColor(_teamColors.get(_teams.indexOf(player._teamNameCTF)));
  11289. +           player.setKarma(0);
  11290. +           player.broadcastUserInfo();
  11291. +       }
  11292. +   }
  11293. +
  11294. +   public static void finishEvent()
  11295. +   {
  11296. +       if (!finishEventOk())
  11297. +       {
  11298. +           if (Config.DEBUG)
  11299. +               _log.fine("CTF Engine[finishEvent]: finishEventOk() = false");
  11300. +           return;
  11301. +       }
  11302. +
  11303. +       _started = false;
  11304. +       unspawnEventNpc();
  11305. +       unspawnAllFlags();
  11306. +       processTopTeam();
  11307. +
  11308. +       if (_topScore != 0)
  11309. +           playKneelAnimation(_topTeam);
  11310. +
  11311. +       if (Config.CTF_ANNOUNCE_TEAM_STATS)
  11312. +       {
  11313. +           AnnounceToPlayers(true, _eventName + " Team Statistics:");
  11314. +           for (String team : _teams)
  11315. +           {
  11316. +               int _flags_ = teamFlagCount(team);
  11317. +               AnnounceToPlayers(true, "Team: " + team + " - Flags taken: " + _flags_);
  11318. +           }
  11319. +       }
  11320. +
  11321. +       teleportFinish();
  11322. +   }
  11323. +
  11324. +   // show losers and winners animations
  11325. +   public static void playKneelAnimation(String teamName)
  11326. +   {
  11327. +       for (Player player : _players)
  11328. +       {
  11329. +           if (player != null && player.isOnline() && player._inEventCTF == true)
  11330. +           {
  11331. +               if (!player._teamNameCTF.equals(teamName))
  11332. +               {
  11333. +                   player.broadcastPacket(new SocialAction(player, 7),2000);
  11334. +               }
  11335. +               else if (player._teamNameCTF.equals(teamName))
  11336. +               {
  11337. +                   player.broadcastPacket(new SocialAction(player, 3),2000);
  11338. +               }
  11339. +           }
  11340. +       }
  11341. +   }
  11342. +
  11343. +   private static boolean finishEventOk()
  11344. +   {
  11345. +       if (!_started)
  11346. +           return false;
  11347. +
  11348. +       return true;
  11349. +   }
  11350. +
  11351. +   public static void rewardTeam(String teamName)
  11352. +   {
  11353. +       for (Player player : _players)
  11354. +       {
  11355. +           if (player != null)
  11356. +           {
  11357. +               if (player._teamNameCTF.equals(teamName))
  11358. +               {
  11359. +                   player.addItem("CTF Event: " + _eventName, _rewardId, _rewardAmount, player, true);
  11360. +
  11361. +                   NpcHtmlMessage nhm = new NpcHtmlMessage(5);
  11362. +                   StringBuilder replyMSG = new StringBuilder();
  11363. +
  11364. +                   replyMSG.append("<html><body>Your team wins the event. Look in your inventory for the reward.</body></html>");
  11365. +
  11366. +                   nhm.setHtml(replyMSG.toString());
  11367. +                   player.sendPacket(nhm);
  11368. +
  11369. +                   // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  11370. +                   player.sendPacket(ActionFailed.STATIC_PACKET);
  11371. +               }
  11372. +           }
  11373. +       }
  11374. +   }
  11375. +
  11376. +   public static void abortEvent()
  11377. +   {
  11378. +       if (!_joining && !_teleport && !_started)
  11379. +           return;
  11380. +       if (_joining && !_teleport && !_started)
  11381. +       {
  11382. +           unspawnEventNpc();
  11383. +           cleanCTF();
  11384. +           _joining = false;
  11385. +           AnnounceToPlayers(true, _eventName + "(CTF): Match aborted!");
  11386. +           return;
  11387. +       }
  11388. +       _joining = false;
  11389. +       _teleport = false;
  11390. +       _started = false;
  11391. +       unspawnEventNpc();
  11392. +       unspawnAllFlags();
  11393. +       AnnounceToPlayers(true, _eventName + "(CTF): Match aborted!");
  11394. +       teleportFinish();
  11395. +   }
  11396. +
  11397. +   public static void sit()
  11398. +   {
  11399. +       if (_sitForced)
  11400. +           _sitForced = false;
  11401. +       else
  11402. +           _sitForced = true;
  11403. +
  11404. +       for (Player player : _players)
  11405. +       {
  11406. +           if (player != null)
  11407. +           {
  11408. +               if (_sitForced)
  11409. +               {
  11410. +                   player.stopMove(null);
  11411. +                   player.abortAttack();
  11412. +                   player.abortCast();
  11413. +
  11414. +                   if (!player.isSitting())
  11415. +                       player.sitDown();
  11416. +               }
  11417. +               else
  11418. +               {
  11419. +                   if (player.isSitting())
  11420. +                       player.standUp();
  11421. +               }
  11422. +           }
  11423. +       }
  11424. +   }
  11425. +
  11426. +   public static void dumpData()
  11427. +   {
  11428. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  11429. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  11430. +
  11431. +       if (!_joining && !_teleport && !_started)
  11432. +       {
  11433. +           _log.warning(CTF.class.getSimpleName() + ":  <<---------------------------------->>");
  11434. +           _log.warning(CTF.class.getSimpleName() + ":  >> CTF Engine infos dump (INACTIVE) <<");
  11435. +           _log.warning(CTF.class.getSimpleName() + ":  <<--^----^^-----^----^^------^^----->>");
  11436. +       }
  11437. +       else if (_joining && !_teleport && !_started)
  11438. +       {
  11439. +           _log.warning(CTF.class.getSimpleName() + ":  <<--------------------------------->>");
  11440. +           _log.warning(CTF.class.getSimpleName() + ":  >> CTF Engine infos dump (JOINING) <<");
  11441. +           _log.warning(CTF.class.getSimpleName() + ":  <<--^----^^-----^----^^------^----->>");
  11442. +       }
  11443. +       else if (!_joining && _teleport && !_started)
  11444. +       {
  11445. +           _log.warning(CTF.class.getSimpleName() + ":  <<---------------------------------->>");
  11446. +           _log.warning(CTF.class.getSimpleName() + ":  >> CTF Engine infos dump (TELEPORT) <<");
  11447. +           _log.warning(CTF.class.getSimpleName() + ":  <<--^----^^-----^----^^------^^----->>");
  11448. +       }
  11449. +       else if (!_joining && !_teleport && _started)
  11450. +       {
  11451. +           _log.warning(CTF.class.getSimpleName() + ":  <<--------------------------------->>");
  11452. +           _log.warning(CTF.class.getSimpleName() + ":  >> CTF Engine infos dump (STARTED) <<");
  11453. +           _log.warning(CTF.class.getSimpleName() + ":  <<--^----^^-----^----^^------^----->>");
  11454. +       }
  11455. +
  11456. +       _log.warning(CTF.class.getSimpleName() + ":  Name: " + _eventName);
  11457. +       _log.warning(CTF.class.getSimpleName() + ":  Desc: " + _eventDesc);
  11458. +       _log.warning(CTF.class.getSimpleName() + ":  Join location: " + _joiningLocationName);
  11459. +       _log.warning(CTF.class.getSimpleName() + ":  Min lvl: " + _minlvl);
  11460. +       _log.warning(CTF.class.getSimpleName() + ":  Max lvl: " + _maxlvl);
  11461. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  11462. +       _log.warning(CTF.class.getSimpleName() + ":  ##########################");
  11463. +       _log.warning(CTF.class.getSimpleName() + ":  # _teams(Vector<String>) #");
  11464. +       _log.warning(CTF.class.getSimpleName() + ":  ##########################");
  11465. +
  11466. +       for (String team : _teams)
  11467. +           _log.warning(CTF.class.getSimpleName() + ": " + team + " Flags Taken :" + _teamPointsCount.get(_teams.indexOf(team)));
  11468. +
  11469. +       if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  11470. +       {
  11471. +           _log.warning(CTF.class.getSimpleName() + ":  ");
  11472. +           _log.warning(CTF.class.getSimpleName() + ":  #########################################");
  11473. +           _log.warning(CTF.class.getSimpleName() + ":  # _playersShuffle(Vector<Player>) #");
  11474. +           _log.warning(CTF.class.getSimpleName() + ":  #########################################");
  11475. +
  11476. +           for (Player player : _playersShuffle)
  11477. +           {
  11478. +               if (player != null)
  11479. +                   _log.warning(CTF.class.getSimpleName() + ":  Name: " + player.getName());
  11480. +           }
  11481. +       }
  11482. +
  11483. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  11484. +       _log.warning(CTF.class.getSimpleName() + ":  ##################################");
  11485. +       _log.warning(CTF.class.getSimpleName() + ":  # _players(Vector<Player>) #");
  11486. +       _log.warning(CTF.class.getSimpleName() + ":  ##################################");
  11487. +
  11488. +       for (Player player : _players)
  11489. +       {
  11490. +           if (player != null)
  11491. +               _log.warning(CTF.class.getSimpleName() + ":  Name: " + player.getName() + "   Team: " + player._teamNameCTF + "  Flags :" + player._countCTFflags);
  11492. +       }
  11493. +
  11494. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  11495. +       _log.warning(CTF.class.getSimpleName() + ":  #####################################################################");
  11496. +       _log.warning(CTF.class.getSimpleName() + ":  # _savePlayers(Vector<String>) and _savePlayerTeams(Vector<String>) #");
  11497. +       _log.warning(CTF.class.getSimpleName() + ":  #####################################################################");
  11498. +
  11499. +       for (String player : _savePlayers)
  11500. +           _log.warning(CTF.class.getSimpleName() + ":  Name: " + player + "   Team: " + _savePlayerTeams.get(_savePlayers.indexOf(player)));
  11501. +
  11502. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  11503. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  11504. +       _log.warning(CTF.class.getSimpleName() + ":  **********==CTF==************");
  11505. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._teamPointsCount:" + _teamPointsCount.toString());
  11506. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._flagIds:" + _flagIds.toString());
  11507. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._flagSpawns:" + _flagSpawns.toString());
  11508. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._throneSpawns:" + _throneSpawns.toString());
  11509. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._flagsTaken:" + _flagsTaken.toString());
  11510. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._flagsX:" + _flagsX.toString());
  11511. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._flagsY:" + _flagsY.toString());
  11512. +       _log.warning(CTF.class.getSimpleName() + ":  CTF._flagsZ:" + _flagsZ.toString());
  11513. +       _log.warning(CTF.class.getSimpleName() + ":  ************EOF**************");
  11514. +       _log.warning(CTF.class.getSimpleName() + ":  ");
  11515. +   }
  11516. +
  11517. +   public static void loadData()
  11518. +   {
  11519. +       _eventName = new String();
  11520. +       _eventDesc = new String();
  11521. +       _topTeam = new String();
  11522. +       _joiningLocationName = new String();
  11523. +       _teams = new ArrayList<>();
  11524. +       _savePlayers = new ArrayList<>();
  11525. +       _savePlayerTeams = new ArrayList<>();
  11526. +       _players = new ArrayList<>();
  11527. +       _playersShuffle = new ArrayList<>();
  11528. +       _teamPlayersCount = new ArrayList<>();
  11529. +       _teamPointsCount = new ArrayList<>();
  11530. +       _teamColors = new ArrayList<>();
  11531. +       _teamsX = new ArrayList<>();
  11532. +       _teamsY = new ArrayList<>();
  11533. +       _teamsZ = new ArrayList<>();
  11534. +
  11535. +       _throneSpawns = new ArrayList<>();
  11536. +       _flagSpawns = new ArrayList<>();
  11537. +       _flagsTaken = new ArrayList<>();
  11538. +       _flagIds = new ArrayList<>();
  11539. +       _flagsX = new ArrayList<>();
  11540. +       _flagsY = new ArrayList<>();
  11541. +       _flagsZ = new ArrayList<>();
  11542. +
  11543. +       _joining = false;
  11544. +       _teleport = false;
  11545. +       _started = false;
  11546. +       _sitForced = false;
  11547. +       _npcId = 0;
  11548. +       _npcX = 0;
  11549. +       _npcY = 0;
  11550. +       _npcZ = 0;
  11551. +       _npcHeading = 0;
  11552. +       _rewardId = 0;
  11553. +       _rewardAmount = 0;
  11554. +       _topScore = 0;
  11555. +       _minlvl = 0;
  11556. +       _maxlvl = 0;
  11557. +       _joinTime = 0;
  11558. +       _eventTime = 0;
  11559. +       _minPlayers = 0;
  11560. +       _maxPlayers = 0;
  11561. +
  11562. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  11563. +       {
  11564. +           PreparedStatement statement;
  11565. +           ResultSet rs;
  11566. +
  11567. +           statement = con.prepareStatement("SELECT * FROM ctf");
  11568. +           rs = statement.executeQuery();
  11569. +
  11570. +           int teams = 0;
  11571. +
  11572. +           while (rs.next())
  11573. +           {
  11574. +               _eventName = rs.getString("eventName");
  11575. +               _eventDesc = rs.getString("eventDesc");
  11576. +               _joiningLocationName = rs.getString("joiningLocation");
  11577. +               _minlvl = rs.getInt("minlvl");
  11578. +               _maxlvl = rs.getInt("maxlvl");
  11579. +               _npcId = rs.getInt("npcId");
  11580. +               _npcX = rs.getInt("npcX");
  11581. +               _npcY = rs.getInt("npcY");
  11582. +               _npcZ = rs.getInt("npcZ");
  11583. +               _npcHeading = rs.getInt("npcHeading");
  11584. +               _rewardId = rs.getInt("rewardId");
  11585. +               _rewardAmount = rs.getInt("rewardAmount");
  11586. +               teams = rs.getInt("teamsCount");
  11587. +               _joinTime = rs.getInt("joinTime");
  11588. +               _eventTime = rs.getInt("eventTime");
  11589. +               _minPlayers = rs.getInt("minPlayers");
  11590. +               _maxPlayers = rs.getInt("maxPlayers");
  11591. +           }
  11592. +           rs.close();
  11593. +           statement.close();
  11594. +
  11595. +           int index = -1;
  11596. +           if (teams > 0)
  11597. +               index = 0;
  11598. +           while (index < teams && index > -1)
  11599. +           {
  11600. +               statement = con.prepareStatement("SELECT * FROM ctf_teams WHERE teamId=?");
  11601. +               statement.setInt(1, index);
  11602. +               rs = statement.executeQuery();
  11603. +               while (rs.next())
  11604. +               {
  11605. +                   _teams.add(rs.getString("teamName"));
  11606. +                   _teamPlayersCount.add(0);
  11607. +                   _teamPointsCount.add(0);
  11608. +                   _teamColors.add(0);
  11609. +                   _teamsX.add(0);
  11610. +                   _teamsY.add(0);
  11611. +                   _teamsZ.add(0);
  11612. +                   _teamsX.set(index, rs.getInt("teamX"));
  11613. +                   _teamsY.set(index, rs.getInt("teamY"));
  11614. +                   _teamsZ.set(index, rs.getInt("teamZ"));
  11615. +                   _teamColors.set(index, rs.getInt("teamColor"));
  11616. +                   _flagsX.add(0);
  11617. +                   _flagsY.add(0);
  11618. +                   _flagsZ.add(0);
  11619. +                   _flagsX.set(index, rs.getInt("flagX"));
  11620. +                   _flagsY.set(index, rs.getInt("flagY"));
  11621. +                   _flagsZ.set(index, rs.getInt("flagZ"));
  11622. +                   _flagSpawns.add(null);
  11623. +                   _flagIds.add(_FlagNPC);
  11624. +                   _flagsTaken.add(false);
  11625. +
  11626. +               }
  11627. +               index++;
  11628. +               rs.close();
  11629. +               statement.close();
  11630. +           }
  11631. +       }
  11632. +       catch (Exception e)
  11633. +       {
  11634. +           _log.warning(CTF.class.getSimpleName() + ":  Exception: CTF.loadData(): " + e.getMessage());
  11635. +       }
  11636. +   }
  11637. +
  11638. +   public static void saveData()
  11639. +   {
  11640. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  11641. +       {
  11642. +           PreparedStatement statement;
  11643. +
  11644. +           statement = con.prepareStatement("DELETE FROM ctf");
  11645. +           statement.execute();
  11646. +           statement.close();
  11647. +
  11648. +           statement = con.prepareStatement("INSERT INTO ctf (eventName, eventDesc, joiningLocation, minlvl, maxlvl, npcId, npcX, npcY, npcZ, npcHeading, rewardId, rewardAmount, teamsCount, joinTime, eventTime, minPlayers, maxPlayers) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
  11649. +           statement.setString(1, _eventName);
  11650. +           statement.setString(2, _eventDesc);
  11651. +           statement.setString(3, _joiningLocationName);
  11652. +           statement.setInt(4, _minlvl);
  11653. +           statement.setInt(5, _maxlvl);
  11654. +           statement.setInt(6, _npcId);
  11655. +           statement.setInt(7, _npcX);
  11656. +           statement.setInt(8, _npcY);
  11657. +           statement.setInt(9, _npcZ);
  11658. +           statement.setInt(10, _npcHeading);
  11659. +           statement.setInt(11, _rewardId);
  11660. +           statement.setInt(12, _rewardAmount);
  11661. +           statement.setInt(13, _teams.size());
  11662. +           statement.setInt(14, _joinTime);
  11663. +           statement.setInt(15, _eventTime);
  11664. +           statement.setInt(16, _minPlayers);
  11665. +           statement.setInt(17, _maxPlayers);
  11666. +           statement.execute();
  11667. +           statement.close();
  11668. +
  11669. +           statement = con.prepareStatement("DELETE FROM ctf_teams");
  11670. +           statement.execute();
  11671. +           statement.close();
  11672. +
  11673. +           for (String teamName : _teams)
  11674. +           {
  11675. +               int index = _teams.indexOf(teamName);
  11676. +
  11677. +               if (index == -1)
  11678. +                   return;
  11679. +               statement = con.prepareStatement("INSERT INTO ctf_teams (teamId ,teamName, teamX, teamY, teamZ, teamColor, flagX, flagY, flagZ) VALUES (?,?,?,?,?,?,?,?,?)");
  11680. +               statement.setInt(1, index);
  11681. +               statement.setString(2, teamName);
  11682. +               statement.setInt(3, _teamsX.get(index));
  11683. +               statement.setInt(4, _teamsY.get(index));
  11684. +               statement.setInt(5, _teamsZ.get(index));
  11685. +               statement.setInt(6, _teamColors.get(index));
  11686. +               statement.setInt(7, _flagsX.get(index));
  11687. +               statement.setInt(8, _flagsY.get(index));
  11688. +               statement.setInt(9, _flagsZ.get(index));
  11689. +               statement.execute();
  11690. +               statement.close();
  11691. +           }
  11692. +       }
  11693. +       catch (Exception e)
  11694. +       {
  11695. +           _log.warning(CTF.class.getSimpleName() + ":  Exception: CTF.saveData(): " + e.getMessage());
  11696. +       }
  11697. +   }
  11698. +
  11699. +   public static void showEventHtml(Player eventPlayer, String objectId)
  11700. +   {
  11701. +       try
  11702. +       {
  11703. +           NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  11704. +           StringBuilder replyMSG = new StringBuilder();
  11705. +
  11706. +           replyMSG.append("<html><body>");
  11707. +           replyMSG.append("CTF Match<br><br><br>");
  11708. +           replyMSG.append("Current event...<br>");
  11709. +           replyMSG.append("   ... description:&nbsp;<font color=\"00FF00\">" + _eventDesc + "</font><br>");
  11710. +           if (Config.CTF_ANNOUNCE_REWARD)
  11711. +               replyMSG.append("   ... reward: (" + _rewardAmount + ") " + ItemTable.getInstance().getTemplate(_rewardId).getName() + "<br>");
  11712. +
  11713. +           if (!_started && !_joining)
  11714. +               replyMSG.append("<center>Wait till the admin/gm start the participation.</center>");
  11715. +           else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !checkMaxPlayers(_playersShuffle.size()))
  11716. +           {
  11717. +               if (!CTF._started)
  11718. +               {
  11719. +                   replyMSG.append("<font color=\"FFFF00\">The event has reached its maximum capacity.</font><br>Keep checking, someone may crit and you can steal their spot.");
  11720. +               }
  11721. +           }
  11722. +           else if (eventPlayer.isCursedWeaponEquipped() && !Config.CTF_JOIN_CURSED)
  11723. +           {
  11724. +               replyMSG.append("<font color=\"FFFF00\">You can't participate in this event with a cursed Weapon.</font><br>");
  11725. +           }
  11726. +           else if (!_started && _joining && eventPlayer.getLevel() >= _minlvl && eventPlayer.getLevel() <= _maxlvl)
  11727. +           {
  11728. +               if (_players.contains(eventPlayer) || checkShufflePlayers(eventPlayer))
  11729. +               {
  11730. +                   if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  11731. +                       replyMSG.append("You are already participating in team <font color=\"LEVEL\">" + eventPlayer._teamNameCTF + "</font><br><br>");
  11732. +                   else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  11733. +                       replyMSG.append("You are already participating!<br><br>");
  11734. +
  11735. +                   replyMSG.append("<table border=\"0\"><tr>");
  11736. +                   replyMSG.append("<td width=\"200\">Wait till event start or</td>");
  11737. +                   replyMSG.append("<td width=\"60\"><center><button value=\"remove\" action=\"bypass -h npc_" + objectId + "_ctf_player_leave\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></td>");
  11738. +                   replyMSG.append("<td width=\"100\">your participation!</td>");
  11739. +                   replyMSG.append("</tr></table>");
  11740. +               }
  11741. +               else
  11742. +               {
  11743. +                   replyMSG.append("<td width=\"200\">Your level : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font></td><br>");
  11744. +                   replyMSG.append("<td width=\"200\">Min level : <font color=\"00FF00\">" + _minlvl + "</font></td><br>");
  11745. +                   replyMSG.append("<td width=\"200\">Max level : <font color=\"00FF00\">" + _maxlvl + "</font></td><br><br>");
  11746. +
  11747. +                   if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  11748. +                   {
  11749. +                       replyMSG.append("<center><table border=\"0\">");
  11750. +
  11751. +                       for (String team : _teams)
  11752. +                       {
  11753. +                           replyMSG.append("<tr><td width=\"100\"><font color=\"LEVEL\">" + team + "</font>&nbsp;(" + teamPlayersCount(team) + " joined)</td>");
  11754. +                           replyMSG.append("<td width=\"60\"><button value=\"Join\" action=\"bypass -h npc_" + objectId + "_ctf_player_join " + team + "\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  11755. +                       }
  11756. +
  11757. +                       replyMSG.append("</table></center>");
  11758. +                   }
  11759. +                   else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  11760. +                   {
  11761. +                       replyMSG.append("<center><table border=\"0\">");
  11762. +
  11763. +                       for (String team : _teams)
  11764. +                           replyMSG.append("<tr><td width=\"100\"><font color=\"LEVEL\">" + team + "</font></td>");
  11765. +
  11766. +                       replyMSG.append("</table></center><br>");
  11767. +
  11768. +                       replyMSG.append("<button value=\"Join\" action=\"bypass -h npc_" + objectId + "_ctf_player_join eventShuffle\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  11769. +                       replyMSG.append("Teams will be randomly generated!");
  11770. +                   }
  11771. +               }
  11772. +           }
  11773. +           else if (_started && !_joining)
  11774. +               replyMSG.append("<center>CTF match is in progress.</center>");
  11775. +           else if (eventPlayer.getLevel() < _minlvl || eventPlayer.getLevel() > _maxlvl)
  11776. +           {
  11777. +               replyMSG.append("Your lvl : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font><br>");
  11778. +               replyMSG.append("Min level : <font color=\"00FF00\">" + _minlvl + "</font><br>");
  11779. +               replyMSG.append("Max level : <font color=\"00FF00\">" + _maxlvl + "</font><br><br>");
  11780. +               replyMSG.append("<font color=\"FFFF00\">You can't participatein this event.</font><br>");
  11781. +           }
  11782. +           // Show how many players joined & how many are still needed to join
  11783. +           replyMSG.append("<br>There are " + _playersShuffle.size() + " player(s) participating in this event.<br>");
  11784. +           if (_joining)
  11785. +           {
  11786. +               if (_playersShuffle.size() < _minPlayers)
  11787. +               {
  11788. +                   int playersNeeded = _minPlayers - _playersShuffle.size();
  11789. +                   replyMSG.append("The event will not start unless " + playersNeeded + " more player(s) joins!");
  11790. +               }
  11791. +           }
  11792. +
  11793. +           replyMSG.append("</body></html>");
  11794. +           adminReply.setHtml(replyMSG.toString());
  11795. +           eventPlayer.sendPacket(adminReply);
  11796. +
  11797. +           // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  11798. +           eventPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  11799. +       }
  11800. +       catch (Exception e)
  11801. +       {
  11802. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception" + e.getMessage());
  11803. +       }
  11804. +   }
  11805. +
  11806. +   public static void addPlayer(Player player, String teamName)
  11807. +   {
  11808. +       if (!addPlayerOk(teamName, player))
  11809. +           return;
  11810. +
  11811. +       if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  11812. +       {
  11813. +           player._teamNameCTF = teamName;
  11814. +           _players.add(player);
  11815. +           setTeamPlayersCount(teamName, teamPlayersCount(teamName) + 1);
  11816. +       }
  11817. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  11818. +           _playersShuffle.add(player);
  11819. +
  11820. +       player._inEventCTF = true;
  11821. +       player._countCTFflags = 0;
  11822. +   }
  11823. +
  11824. +   public static synchronized void removeOfflinePlayers()
  11825. +   {
  11826. +       try
  11827. +       {
  11828. +           if (_playersShuffle == null)
  11829. +               return;
  11830. +           else if (_playersShuffle.isEmpty())
  11831. +               return;
  11832. +           else if (_playersShuffle.size() > 0)
  11833. +           {
  11834. +               for (Player player : _playersShuffle)
  11835. +               {
  11836. +                   if (player == null)
  11837. +                       _playersShuffle.remove(player);
  11838. +                   else if (player.isOnline() || player.isInJail())
  11839. +                       removePlayer(player);
  11840. +                   if (_playersShuffle.size() == 0 || _playersShuffle.isEmpty())
  11841. +                       break;
  11842. +               }
  11843. +           }
  11844. +       }
  11845. +       catch (Exception e)
  11846. +       {
  11847. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Engine exception: " + e.getMessage());
  11848. +           return;
  11849. +       }
  11850. +   }
  11851. +
  11852. +   public static boolean checkShufflePlayers(Player eventPlayer)
  11853. +   {
  11854. +       try
  11855. +       {
  11856. +           for (Player player : _playersShuffle)
  11857. +           {
  11858. +               if (player == null || player.isOnline())
  11859. +               {
  11860. +                   _playersShuffle.remove(player);
  11861. +                   eventPlayer._inEventCTF = false;
  11862. +                   continue;
  11863. +               }
  11864. +               else if (player.getObjectId() == eventPlayer.getObjectId())
  11865. +               {
  11866. +                   eventPlayer._inEventCTF = true;
  11867. +                   eventPlayer._countCTFflags = 0;
  11868. +                   return true;
  11869. +               }
  11870. +               // this 1 is in case player got new object id after DC or reconnect
  11871. +               else if (player.getName().equals(eventPlayer.getName()))
  11872. +               {
  11873. +                   _playersShuffle.remove(player);
  11874. +                   _playersShuffle.add(eventPlayer);
  11875. +                   eventPlayer._inEventCTF = true;
  11876. +                   eventPlayer._countCTFflags = 0;
  11877. +                   return true;
  11878. +               }
  11879. +           }
  11880. +       }
  11881. +       catch (Exception e)
  11882. +       {
  11883. +       }
  11884. +       return false;
  11885. +   }
  11886. +
  11887. +   public static boolean addPlayerOk(String teamName, Player eventPlayer)
  11888. +   {
  11889. +       try
  11890. +       {
  11891. +           if (checkShufflePlayers(eventPlayer) || eventPlayer._inEventCTF)
  11892. +           {
  11893. +               eventPlayer.sendMessage("You are already participating in the event!");
  11894. +               return false;
  11895. +           }
  11896. +
  11897. +           for (Player player : _players)
  11898. +           {
  11899. +               if (player.getObjectId() == eventPlayer.getObjectId())
  11900. +               {
  11901. +                   eventPlayer.sendMessage("You are already participating in the event!");
  11902. +                   return false;
  11903. +               }
  11904. +               else if (player.getName() == eventPlayer.getName())
  11905. +               {
  11906. +                   eventPlayer.sendMessage("You are already participating in the event!");
  11907. +                   return false;
  11908. +               }
  11909. +           }
  11910. +           if (_players.contains(eventPlayer))
  11911. +           {
  11912. +               eventPlayer.sendMessage("You are already participating in the event!");
  11913. +               return false;
  11914. +           }
  11915. +       }
  11916. +       catch (Exception e)
  11917. +       {
  11918. +           _log.warning(CTF.class.getSimpleName() + ":  CTF Siege Engine exception: " + e.getMessage());
  11919. +       }
  11920. +
  11921. +       if (Config.CTF_EVEN_TEAMS.equals("NO"))
  11922. +           return true;
  11923. +       else if (Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  11924. +       {
  11925. +           boolean allTeamsEqual = true;
  11926. +           int countBefore = -1;
  11927. +
  11928. +           for (int playersCount : _teamPlayersCount)
  11929. +           {
  11930. +               if (countBefore == -1)
  11931. +                   countBefore = playersCount;
  11932. +
  11933. +               if (countBefore != playersCount)
  11934. +               {
  11935. +                   allTeamsEqual = false;
  11936. +                   break;
  11937. +               }
  11938. +
  11939. +               countBefore = playersCount;
  11940. +           }
  11941. +
  11942. +           if (allTeamsEqual)
  11943. +               return true;
  11944. +
  11945. +           countBefore = Integer.MAX_VALUE;
  11946. +
  11947. +           for (int teamPlayerCount : _teamPlayersCount)
  11948. +           {
  11949. +               if (teamPlayerCount < countBefore)
  11950. +                   countBefore = teamPlayerCount;
  11951. +           }
  11952. +
  11953. +           List<String> joinableTeams = new ArrayList<>();
  11954. +
  11955. +           for (String team : _teams)
  11956. +           {
  11957. +               if (teamPlayersCount(team) == countBefore)
  11958. +                   joinableTeams.add(team);
  11959. +           }
  11960. +
  11961. +           if (joinableTeams.contains(teamName))
  11962. +               return true;
  11963. +       }
  11964. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  11965. +           return true;
  11966. +
  11967. +       eventPlayer.sendMessage("Too many players in team \"" + teamName + "\"");
  11968. +       return false;
  11969. +   }
  11970. +
  11971. +   public static synchronized void addDisconnectedPlayer(Player player)
  11972. +   {
  11973. +       /*
  11974. +        * !!! CAUTION !!!
  11975. +        * Do NOT fix multiple object Ids on this event or you will ruin the flag reposition check!!!
  11976. +        * All Multiple object Ids will be collected by the Garbage Collector, after the event ends, memory sweep is made!!!
  11977. +        */
  11978. +
  11979. +       if ((Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && (_teleport || _started)) || (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE") && (_teleport || _started)))
  11980. +       {
  11981. +           if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
  11982. +           {
  11983. +               for (L2Effect e : player.getAllEffects())
  11984. +               {
  11985. +                   if (e != null)
  11986. +                       e.exit();
  11987. +               }
  11988. +           }
  11989. +
  11990. +           player._teamNameCTF = _savePlayerTeams.get(_savePlayers.indexOf(player.getName()));
  11991. +           for (Player p : _players)
  11992. +           {
  11993. +               if (p == null)
  11994. +               {
  11995. +                   continue;
  11996. +               }
  11997. +               // check by name in case player got new objectId
  11998. +               else if (p.getName().equals(player.getName()))
  11999. +               {
  12000. +                   player._originalNameColorCTF = player.getAppearance().getNameColor();
  12001. +                   player._originalKarmaCTF = player.getKarma();
  12002. +                   player._inEventCTF = true;
  12003. +                   player._countCTFflags = p._countCTFflags;
  12004. +                   _players.remove(p); // removing old object id from vector
  12005. +                   _players.add(player); // adding new objectId to vector
  12006. +                   break;
  12007. +               }
  12008. +           }
  12009. +           player.getAppearance().setNameColor(_teamColors.get(_teams.indexOf(player._teamNameCTF)));
  12010. +           player.setKarma(0);
  12011. +           player.broadcastUserInfo();
  12012. +           player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ.get(_teams.indexOf(player._teamNameCTF)), 0);
  12013. +           Started(player);
  12014. +           CheckRestoreFlags();
  12015. +       }
  12016. +   }
  12017. +
  12018. +   public static void removePlayer(Player player)
  12019. +   {
  12020. +       if (player._inEventCTF)
  12021. +       {
  12022. +           if (!_joining)
  12023. +           {
  12024. +               player.getAppearance().setNameColor(player._originalNameColorCTF);
  12025. +               player.setKarma(player._originalKarmaCTF);
  12026. +               player.broadcastUserInfo();
  12027. +           }
  12028. +           player._teamNameCTF = new String();
  12029. +           player._countCTFflags = 0;
  12030. +           player._inEventCTF = false;
  12031. +
  12032. +           if ((Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE")) && _players.contains(player))
  12033. +           {
  12034. +               setTeamPlayersCount(player._teamNameCTF, teamPlayersCount(player._teamNameCTF) - 1);
  12035. +               _players.remove(player);
  12036. +           }
  12037. +           else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && (!_playersShuffle.isEmpty() && _playersShuffle.contains(player)))
  12038. +               _playersShuffle.remove(player);
  12039. +       }
  12040. +   }
  12041. +
  12042. +   public static void cleanCTF()
  12043. +   {
  12044. +       _log.warning(CTF.class.getSimpleName() + ":  CTF : Cleaning players.");
  12045. +       for (Player player : _players)
  12046. +       {
  12047. +           if (player != null)
  12048. +           {
  12049. +               if (player._haveFlagCTF)
  12050. +                   removeFlagFromPlayer(player);
  12051. +               else
  12052. +                   player.getInventory().destroyItemByItemId("", CTF._FLAG_IN_HAND_ITEM_ID, 1, player, null);
  12053. +               player._haveFlagCTF = false;
  12054. +               removePlayer(player);
  12055. +               if (_savePlayers.contains(player.getName()))
  12056. +                   _savePlayers.remove(player.getName());
  12057. +               player._inEventCTF = false;
  12058. +           }
  12059. +       }
  12060. +       if (_playersShuffle != null && !_playersShuffle.isEmpty())
  12061. +       {
  12062. +           for (Player player : _playersShuffle)
  12063. +           {
  12064. +               if (player != null)
  12065. +                   player._inEventCTF = false;
  12066. +           }
  12067. +       }
  12068. +       _log.warning(CTF.class.getSimpleName() + ":  CTF : Cleaning teams and flags.");
  12069. +       for (String team : _teams)
  12070. +       {
  12071. +           int index = _teams.indexOf(team);
  12072. +           _teamPointsCount.set(index, 0);
  12073. +           _flagSpawns.set(index, null);
  12074. +           _flagsTaken.set(index, false);
  12075. +           _teamPlayersCount.set(index, 0);
  12076. +           _teamPointsCount.set(index, 0);
  12077. +       }
  12078. +       _topScore = 0;
  12079. +       _topTeam = new String();
  12080. +       _players.clear();
  12081. +       _playersShuffle.clear();
  12082. +       _savePlayers.clear();
  12083. +       _savePlayerTeams.clear();
  12084. +       _teamPointsCount.clear();
  12085. +       _flagSpawns.clear();
  12086. +       _flagsTaken.clear();
  12087. +       _teamPlayersCount.clear();
  12088. +       _log.warning(CTF.class.getSimpleName() + ":  Cleaning CTF done.");
  12089. +       _log.warning(CTF.class.getSimpleName() + ":  Loading new data from MySql");
  12090. +       loadData();
  12091. +   }
  12092. +
  12093. +   public static void unspawnEventNpc()
  12094. +   {
  12095. +       if (_npcSpawn == null)
  12096. +           return;
  12097. +
  12098. +       _npcSpawn.getNpc().deleteMe();
  12099. +       _npcSpawn.setRespawnState(false);
  12100. +       SpawnTable.getInstance().deleteSpawn(_npcSpawn, true);
  12101. +   }
  12102. +
  12103. +   public static void teleportFinish()
  12104. +   {
  12105. +       AnnounceToPlayers(false, _eventName + "(CTF): Teleport back to participation NPC in 20 seconds!");
  12106. +       ThreadPool.schedule(new Runnable()
  12107. +       {
  12108. +           @SuppressWarnings("synthetic-access")
  12109. +           @Override
  12110. +           public void run()
  12111. +           {
  12112. +               for (Player player : _players)
  12113. +               {
  12114. +                   if (player != null)
  12115. +                   {
  12116. +                       if (player.isOnline())
  12117. +                           player.teleToLocation(_npcX, _npcY, _npcZ, 0);
  12118. +                       else
  12119. +                       {
  12120. +                           try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  12121. +                           {
  12122. +                               PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=? WHERE char_name=?");
  12123. +                               statement.setInt(1, _npcX);
  12124. +                               statement.setInt(2, _npcY);
  12125. +                               statement.setInt(3, _npcZ);
  12126. +                               statement.setString(4, player.getName());
  12127. +                               statement.execute();
  12128. +                               statement.close();
  12129. +                           }
  12130. +                           catch (SQLException se)
  12131. +                           {
  12132. +                               _log.warning(CTF.class.getSimpleName() + ":  CTF Engine exception: " + se.getMessage());
  12133. +                           }
  12134. +                       }
  12135. +                   }
  12136. +               }
  12137. +               cleanCTF();
  12138. +           }
  12139. +       }, 20000);
  12140. +   }
  12141. +
  12142. +   public static int teamFlagCount(String teamName)
  12143. +   {
  12144. +       int index = _teams.indexOf(teamName);
  12145. +
  12146. +       if (index == -1)
  12147. +           return -1;
  12148. +
  12149. +       return _teamPointsCount.get(index);
  12150. +   }
  12151. +
  12152. +   public static void setTeamFlagCount(String teamName, int teamFlagCount)
  12153. +   {
  12154. +       int index = _teams.indexOf(teamName);
  12155. +
  12156. +       if (index == -1)
  12157. +           return;
  12158. +
  12159. +       _teamPointsCount.set(index, teamFlagCount);
  12160. +   }
  12161. +
  12162. +   /**
  12163. +    * Used to calculate the event CTF area, so that players don't run off with the flag.
  12164. +    * Essential, since a player may take the flag just so other teams can't score points.
  12165. +    * This function is Only called upon ONE time on BEGINING OF EACH EVENT right after we spawn the flags.
  12166. +    */
  12167. +   private static void calculateOutSideOfCTF()
  12168. +   {
  12169. +       if ((_teams == null) || (_flagSpawns == null) || (_teamsX == null) || (_teamsY == null) || (_teamsZ == null))
  12170. +           return;
  12171. +
  12172. +       int division = _teams.size() * 2, pos = 0;
  12173. +       int[] locX = new int[division], locY = new int[division], locZ = new int[division];
  12174. +       // Get all coordinates in order to create a polygon:
  12175. +       for (L2Spawn flag : _flagSpawns)
  12176. +       {
  12177. +           flag.setLoc(locX[pos], locY[pos], locZ[pos], pos);
  12178. +          
  12179. +           pos++;
  12180. +           if (pos > division / 2)
  12181. +               break;
  12182. +       }
  12183. +
  12184. +       for (int x = 0; x < _teams.size(); x++)
  12185. +       {
  12186. +           locX[pos] = _teamsX.get(x);
  12187. +           locY[pos] = _teamsY.get(x);
  12188. +           locZ[pos] = _teamsZ.get(x);
  12189. +           pos++;
  12190. +           if (pos > division)
  12191. +               break;
  12192. +       }
  12193. +
  12194. +       // find the polygon center, note that it's not the mathematical center of the polygon,
  12195. +       // rather than a point which centers all coordinates:
  12196. +       int centerX = 0, centerY = 0, centerZ = 0;
  12197. +       for (int x = 0; x < pos; x++)
  12198. +       {
  12199. +           centerX += (locX[x] / division);
  12200. +           centerY += (locY[x] / division);
  12201. +           centerZ += (locZ[x] / division);
  12202. +       }
  12203. +
  12204. +       // now let's find the farthest distance from the "center" to the egg shaped sphere
  12205. +       // surrounding the polygon, size x1.5 (for maximum logical area to wander...):
  12206. +       int maxX = 0, maxY = 0, maxZ = 0;
  12207. +       for (int x = 0; x < pos; x++)
  12208. +       {
  12209. +           if (maxX < 2 * Math.abs(centerX - locX[x]))
  12210. +               maxX = (2 * Math.abs(centerX - locX[x]));
  12211. +           if (maxY < 2 * Math.abs(centerY - locY[x]))
  12212. +               maxY = (2 * Math.abs(centerY - locY[x]));
  12213. +           if (maxZ < 2 * Math.abs(centerZ - locZ[x]))
  12214. +               maxZ = (2 * Math.abs(centerZ - locZ[x]));
  12215. +       }
  12216. +
  12217. +       // centerX,centerY,centerZ are the coordinates of the "event center".
  12218. +       // so let's save those coordinates to check on the players:
  12219. +       eventCenterX = centerX;
  12220. +       eventCenterY = centerY;
  12221. +       eventCenterZ = centerZ;
  12222. +       eventOffset = maxX;
  12223. +       if (eventOffset < maxY)
  12224. +           eventOffset = maxY;
  12225. +       if (eventOffset < maxZ)
  12226. +           eventOffset = maxZ;
  12227. +   }
  12228. +
  12229. +   public static boolean isOutsideCTFArea(Player _player)
  12230. +   {
  12231. +       if ((_player == null) || (_player.isOnline()))
  12232. +           return true;
  12233. +       if (!(_player.getX() > eventCenterX - eventOffset && _player.getX() < eventCenterX + eventOffset && _player.getY() > eventCenterY - eventOffset && _player.getY() < eventCenterY + eventOffset && _player.getZ() > eventCenterZ - eventOffset && _player.getZ() < eventCenterZ + eventOffset))
  12234. +           return true;
  12235. +       return false;
  12236. +   }
  12237. +}
  12238. \ No newline at end of file
  12239. Index: java/net/sf/l2j/gameserver/model/entity/engine/EventHandlerTvT.java
  12240. ===================================================================
  12241. --- java/net/sf/l2j/gameserver/model/entity/engine/EventHandlerTvT.java (revision 0)
  12242. +++ java/net/sf/l2j/gameserver/model/entity/engine/EventHandlerTvT.java (working copy)
  12243. @@ -0,0 +1,91 @@
  12244. +/*
  12245. + * This program is free software: you can redistribute it and/or modify it under
  12246. + * the terms of the GNU General Public License as published by the Free Software
  12247. + * Foundation, either version 3 of the License, or (at your option) any later
  12248. + * version.
  12249. + *
  12250. + * This program is distributed in the hope that it will be useful, but WITHOUT
  12251. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12252. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  12253. + * details.
  12254. + *
  12255. + * You should have received a copy of the GNU General Public License along with
  12256. + * this program. If not, see <http://www.gnu.org/licenses/>.
  12257. + */
  12258. +package net.sf.l2j.gameserver.model.entity.engine;
  12259. +
  12260. +import java.util.ArrayList;
  12261. +import java.util.Calendar;
  12262. +import java.util.List;
  12263. +import java.util.logging.Logger;
  12264. +
  12265. +import net.sf.l2j.Config;
  12266. +import net.sf.l2j.commons.concurrent.ThreadPool;
  12267. +
  12268. +/**
  12269. + * @author Boorinio
  12270. + */
  12271. +public class EventHandlerTvT
  12272. +{
  12273. +   private static final Logger _log = Logger.getLogger(EventHandlerTvT.class.getName());
  12274. +   public List<Long> datesTvT = new ArrayList<>();
  12275. +  
  12276. +   public void startHandler()
  12277. +   {
  12278. +       loadConfisTvT(false);
  12279. +       getNextTimeStampTvT();
  12280. +       _log.info(EventHandlerTvT.class.getSimpleName() + ": TvT handler initiated.");
  12281. +   }
  12282. +  
  12283. +   public void loadConfisTvT(boolean NextDay)
  12284. +   {
  12285. +       datesTvT.clear();
  12286. +       for (String times : Config.TVT_EVENT_TIMES.split(","))
  12287. +       {
  12288. +           String[] timesSplited = times.split(":");
  12289. +           int hour = Integer.parseInt(timesSplited[0]);
  12290. +           int minute = Integer.parseInt(timesSplited[1]);
  12291. +           Calendar time = Calendar.getInstance();
  12292. +           if (!NextDay)
  12293. +           {
  12294. +               time.set(Calendar.HOUR_OF_DAY, hour);
  12295. +               time.set(Calendar.MINUTE, minute);
  12296. +           }
  12297. +           else
  12298. +           {
  12299. +               time.set(Calendar.DAY_OF_MONTH, Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + 1);
  12300. +               time.set(Calendar.HOUR_OF_DAY, hour);
  12301. +               time.set(Calendar.MINUTE, minute);
  12302. +           }
  12303. +           datesTvT.add(time.getTimeInMillis());
  12304. +       }
  12305. +   }
  12306. +  
  12307. +   public void getNextTimeStampTvT()
  12308. +   {
  12309. +       boolean found = false;
  12310. +       for (Long stamp : datesTvT)
  12311. +       {
  12312. +           if (stamp > System.currentTimeMillis())
  12313. +           {
  12314. +               ThreadPool.schedule(new Runnable()
  12315. +               {
  12316. +                   @Override
  12317. +                   public void run()
  12318. +                   {
  12319. +                       TvT.loadData();
  12320. +                       TvT.autoEvent();
  12321. +                       getNextTimeStampTvT();
  12322. +                   }
  12323. +               }, stamp - System.currentTimeMillis());
  12324. +               found = true;
  12325. +               break;
  12326. +           }
  12327. +       }
  12328. +       if (!found)
  12329. +       {
  12330. +           loadConfisTvT(true);
  12331. +           getNextTimeStampTvT();
  12332. +       }
  12333. +   }
  12334. +}
  12335. Index: java/net/sf/l2j/gameserver/model/L2Radar.java
  12336. ===================================================================
  12337. --- java/net/sf/l2j/gameserver/model/L2Radar.java   (revision 1)
  12338. +++ java/net/sf/l2j/gameserver/model/L2Radar.java   (working copy)
  12339. @@ -3,6 +3,7 @@
  12340.  import java.util.ArrayList;
  12341.  import java.util.List;
  12342.  
  12343. +import net.sf.l2j.commons.concurrent.ThreadPool;
  12344.  import net.sf.l2j.gameserver.model.actor.instance.Player;
  12345.  import net.sf.l2j.gameserver.network.serverpackets.RadarControl;
  12346.  
  12347. @@ -54,6 +55,37 @@
  12348.             _player.sendPacket(new RadarControl(0, 1, tempMarker._x, tempMarker._y, tempMarker._z));
  12349.     }
  12350.    
  12351. +   public class RadarOnPlayer implements Runnable
  12352. +   {
  12353. +       private final Player _myTarget, _me;
  12354. +      
  12355. +       public RadarOnPlayer(Player target, Player me)
  12356. +       {
  12357. +           _me = me;
  12358. +           _myTarget = target;
  12359. +       }
  12360. +      
  12361. +       @Override
  12362. +       public void run()
  12363. +       {
  12364. +           try
  12365. +           {
  12366. +               if (_me == null || _me.isOnline())
  12367. +                   return;
  12368. +              
  12369. +               _me.sendPacket(new RadarControl(1, 1, _me.getX(), _me.getY(), _me.getZ()));
  12370. +               if (_myTarget == null || _myTarget.isOnline() || !_myTarget._haveFlagCTF)
  12371. +                   return;
  12372. +              
  12373. +               _me.sendPacket(new RadarControl(0, 1, _myTarget.getX(), _myTarget.getY(), _myTarget.getZ()));
  12374. +               ThreadPool.schedule(new RadarOnPlayer(_myTarget, _me), 15000);
  12375. +           }
  12376. +           catch (Throwable t)
  12377. +           {
  12378. +           }
  12379. +       }
  12380. +   }  
  12381. +  
  12382.     public static class RadarMarker
  12383.     {
  12384.         // Simple class to model radar points.
  12385. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminEventEngine.java
  12386. ===================================================================
  12387. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminEventEngine.java   (revision 0)
  12388. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminEventEngine.java   (working copy)
  12389. @@ -0,0 +1,769 @@
  12390. +/*
  12391. + * This program is free software: you can redistribute it and/or modify it under
  12392. + * the terms of the GNU General Public License as published by the Free Software
  12393. + * Foundation, either version 3 of the License, or (at your option) any later
  12394. + * version.
  12395. + *
  12396. + * This program is distributed in the hope that it will be useful, but WITHOUT
  12397. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12398. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  12399. + * details.
  12400. + *
  12401. + * You should have received a copy of the GNU General Public License along with
  12402. + * this program. If not, see <http://www.gnu.org/licenses/>.
  12403. + */
  12404. +package net.sf.l2j.gameserver.handler.admincommandhandlers;
  12405. +
  12406. +import java.io.BufferedInputStream;
  12407. +import java.io.BufferedReader;
  12408. +import java.io.DataInputStream;
  12409. +import java.io.File;
  12410. +import java.io.FileInputStream;
  12411. +import java.io.FileOutputStream;
  12412. +import java.io.InputStreamReader;
  12413. +import java.io.PrintStream;
  12414. +import java.util.Iterator;
  12415. +import java.util.LinkedList;
  12416. +import java.util.StringTokenizer;
  12417. +import java.util.logging.Logger;
  12418. +
  12419. +import net.sf.l2j.Config;
  12420. +import net.sf.l2j.gameserver.datatables.SpawnTable;
  12421. +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  12422. +import net.sf.l2j.gameserver.model.L2Object.PolyType;
  12423. +import net.sf.l2j.gameserver.model.L2Spawn;
  12424. +import net.sf.l2j.gameserver.model.World;
  12425. +import net.sf.l2j.gameserver.model.actor.Npc;
  12426. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  12427. +import net.sf.l2j.gameserver.model.entity.L2Event;
  12428. +import net.sf.l2j.gameserver.network.serverpackets.CharInfo;
  12429. +import net.sf.l2j.gameserver.network.serverpackets.ItemList;
  12430. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  12431. +import net.sf.l2j.gameserver.network.serverpackets.Revive;
  12432. +import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
  12433. +import net.sf.l2j.gameserver.network.serverpackets.UserInfo;
  12434. +
  12435. +/**
  12436. + * This class handles following admin commands:
  12437. + * - admin = shows menu
  12438. + */
  12439. +public class AdminEventEngine implements IAdminCommandHandler
  12440. +{
  12441. +   protected static final Logger _log = Logger.getLogger(AdminEventEngine.class.getName());
  12442. +
  12443. +   private static final String[] ADMIN_COMMANDS =
  12444. +   {/** @formatter:off */
  12445. +       "admin_event",
  12446. +       "admin_event_new",
  12447. +       "admin_event_choose",
  12448. +       "admin_event_store",
  12449. +       "admin_event_set",
  12450. +       "admin_event_change_teams_number",
  12451. +       "admin_event_announce",
  12452. +       "admin_event_panel",
  12453. +       "admin_event_control_begin",
  12454. +       "admin_event_control_teleport",
  12455. +       "admin_add",
  12456. +       "admin_event_see",
  12457. +       "admin_event_del",
  12458. +       "admin_delete_buffer",
  12459. +       "admin_event_control_sit",
  12460. +       "admin_event_name",
  12461. +       "admin_event_control_kill",
  12462. +       "admin_event_control_res",
  12463. +       "admin_event_control_poly",
  12464. +       "admin_event_control_unpoly",
  12465. +       "admin_event_control_prize",
  12466. +       "admin_event_control_chatban",
  12467. +       "admin_event_control_finish"
  12468. +   };/** @formatter:off */
  12469. +   private static String tempBuffer = "";
  12470. +   private static String tempName = "";
  12471. +   private static String tempName2 = "";
  12472. +   private static boolean npcsDeleted = false;
  12473. +
  12474. +   @Override
  12475. +   public boolean useAdminCommand(String command, Player activeChar)
  12476. +   {
  12477. +       if (command.equals("admin_event"))
  12478. +           showMainPage(activeChar);
  12479. +
  12480. +       else if (command.equals("admin_event_new"))
  12481. +       {
  12482. +           showNewEventPage(activeChar);
  12483. +       }
  12484. +       else if (command.startsWith("admin_add"))
  12485. +       {
  12486. +           tempBuffer += command.substring(10);
  12487. +           showNewEventPage(activeChar);
  12488. +
  12489. +       }
  12490. +       else if (command.startsWith("admin_event_see"))
  12491. +       {
  12492. +           String eventName = command.substring(16);
  12493. +           try (DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("data/events/" + eventName)));
  12494. +               BufferedReader inbr = new BufferedReader(new InputStreamReader(in)))
  12495. +           {
  12496. +               NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  12497. +               StringBuilder replyMSG = new StringBuilder("<html><body>");
  12498. +               replyMSG.append("<center><font color=\"LEVEL\">" + eventName + "</font><font color=\"FF0000\"> bY " + inbr.readLine() + "</font></center><br>");
  12499. +
  12500. +               replyMSG.append("<br>" + inbr.readLine());
  12501. +               replyMSG.append("</body></html>");
  12502. +               adminReply.setHtml(replyMSG.toString());
  12503. +               activeChar.sendPacket(adminReply);
  12504. +           }
  12505. +           catch (Exception e)
  12506. +           {
  12507. +               _log.warning(AdminEventEngine.class.getName() + ": Error " + eventName);
  12508. +               if (Config.DEVELOPER)
  12509. +                   e.printStackTrace();
  12510. +           }
  12511. +
  12512. +       }
  12513. +       else if (command.startsWith("admin_event_del"))
  12514. +       {
  12515. +           String eventName = command.substring(16);
  12516. +           File file = new File("data/events/" + eventName);
  12517. +           file.delete();
  12518. +           showMainPage(activeChar);
  12519. +       }
  12520. +
  12521. +       else if (command.startsWith("admin_event_name"))
  12522. +       {
  12523. +           tempName += command.substring(17);
  12524. +           showNewEventPage(activeChar);
  12525. +       }
  12526. +
  12527. +       else if (command.equalsIgnoreCase("admin_delete_buffer"))
  12528. +       {
  12529. +           try
  12530. +           {
  12531. +               tempBuffer += tempBuffer.substring(0, tempBuffer.length() - 10);
  12532. +               showNewEventPage(activeChar);
  12533. +           }
  12534. +           catch (Exception e)
  12535. +           {
  12536. +               tempBuffer = "";
  12537. +           }
  12538. +       }
  12539. +
  12540. +       else if (command.startsWith("admin_event_store"))
  12541. +       {
  12542. +
  12543. +           try (FileOutputStream file = new FileOutputStream("data/events/" + tempName);
  12544. +               PrintStream p = new PrintStream(file))
  12545. +           {
  12546. +               ;
  12547. +               p.println(activeChar.getName());
  12548. +               p.println(tempBuffer);
  12549. +           }
  12550. +           catch (Exception e)
  12551. +           {
  12552. +               _log.warning(AdminEventEngine.class.getName() + ": could not store data/events/" + tempName);
  12553. +               if (Config.DEVELOPER)
  12554. +                   e.printStackTrace();
  12555. +           }
  12556. +           tempBuffer = "";
  12557. +           tempName = "";
  12558. +           showMainPage(activeChar);
  12559. +       }
  12560. +       else if (command.startsWith("admin_event_set"))
  12561. +       {
  12562. +           L2Event.eventName = command.substring(16);
  12563. +           showEventParameters(activeChar, 2);
  12564. +       }
  12565. +       else if (command.startsWith("admin_event_change_teams_number"))
  12566. +       {
  12567. +           showEventParameters(activeChar, Integer.parseInt(command.substring(32)));
  12568. +       }
  12569. +       else if (command.startsWith("admin_event_panel"))
  12570. +       {
  12571. +           showEventControl(activeChar);
  12572. +       }
  12573. +       else if (command.startsWith("admin_event_control_begin"))
  12574. +       {
  12575. +           try
  12576. +           {
  12577. +               L2Event.active = true;
  12578. +               L2Event.players.clear();
  12579. +               L2Event.connectionLossData.clear();
  12580. +
  12581. +               for (int j = 0; j < L2Event.teamsNumber; j++)
  12582. +               {
  12583. +                   LinkedList<String> link = new LinkedList<>();
  12584. +                   L2Event.players.put(j + 1, link);
  12585. +
  12586. +               }
  12587. +               int i = 0;
  12588. +
  12589. +               while (L2Event.participatingPlayers.size() > 0)
  12590. +               {
  12591. +                   String target = getMaxLeveledPlayer();
  12592. +
  12593. +                   if (!target.equals(""))
  12594. +                   {
  12595. +                       L2Event.players.get(i + 1).add(target);
  12596. +                       i = (i + 1) % L2Event.teamsNumber;
  12597. +                   }
  12598. +               }
  12599. +               destroyEventNpcs();
  12600. +               npcsDeleted = true;
  12601. +           }
  12602. +           catch (Exception e)
  12603. +           {
  12604. +               if (Config.DEVELOPER)
  12605. +               {
  12606. +                   e.printStackTrace();
  12607. +               }
  12608. +           }
  12609. +           showEventControl(activeChar);
  12610. +       }
  12611. +       else if (command.startsWith("admin_event_control_teleport"))
  12612. +       {
  12613. +           StringTokenizer st = new StringTokenizer(command.substring(29), "-");
  12614. +
  12615. +           while (st.hasMoreElements())
  12616. +           {
  12617. +               teleportTeam(activeChar, Integer.parseInt(st.nextToken()));
  12618. +           }
  12619. +           showEventControl(activeChar);
  12620. +       }
  12621. +
  12622. +       else if (command.startsWith("admin_event_control_sit"))
  12623. +       {
  12624. +           StringTokenizer st = new StringTokenizer(command.substring(24), "-");
  12625. +
  12626. +           while (st.hasMoreElements())
  12627. +           {
  12628. +               sitTeam(Integer.parseInt(st.nextToken()));
  12629. +           }
  12630. +           showEventControl(activeChar);
  12631. +       }
  12632. +       else if (command.startsWith("admin_event_control_kill"))
  12633. +       {
  12634. +           StringTokenizer st = new StringTokenizer(command.substring(25), "-");
  12635. +
  12636. +           while (st.hasMoreElements())
  12637. +           {
  12638. +               killTeam(activeChar, Integer.parseInt(st.nextToken()));
  12639. +           }
  12640. +           showEventControl(activeChar);
  12641. +       }
  12642. +       else if (command.startsWith("admin_event_control_res"))
  12643. +       {
  12644. +           StringTokenizer st = new StringTokenizer(command.substring(24), "-");
  12645. +
  12646. +           while (st.hasMoreElements())
  12647. +           {
  12648. +               resTeam(Integer.parseInt(st.nextToken()));
  12649. +           }
  12650. +           showEventControl(activeChar);
  12651. +       }
  12652. +       else if (command.startsWith("admin_event_control_poly"))
  12653. +       {
  12654. +           StringTokenizer st0 = new StringTokenizer(command.substring(25));
  12655. +           StringTokenizer st = new StringTokenizer(st0.nextToken(), "-");
  12656. +           String id = st0.nextToken();
  12657. +           while (st.hasMoreElements())
  12658. +           {
  12659. +               polyTeam(Integer.parseInt(st.nextToken()), id);
  12660. +           }
  12661. +           showEventControl(activeChar);
  12662. +       }
  12663. +       else if (command.startsWith("admin_event_control_unpoly"))
  12664. +       {
  12665. +           StringTokenizer st = new StringTokenizer(command.substring(27), "-");
  12666. +
  12667. +           while (st.hasMoreElements())
  12668. +           {
  12669. +               unpolyTeam(Integer.parseInt(st.nextToken()));
  12670. +           }
  12671. +           showEventControl(activeChar);
  12672. +       }
  12673. +       else if (command.startsWith("admin_event_control_prize"))
  12674. +       {
  12675. +           StringTokenizer st0 = new StringTokenizer(command.substring(26));
  12676. +           StringTokenizer st = new StringTokenizer(st0.nextToken(), "-");
  12677. +           String n = st0.nextToken();
  12678. +           StringTokenizer st1 = new StringTokenizer(n, "*");
  12679. +           n = st1.nextToken();
  12680. +           String type = "";
  12681. +           if (st1.hasMoreElements())
  12682. +               type = st1.nextToken();
  12683. +
  12684. +           String id = st0.nextToken();
  12685. +           while (st.hasMoreElements())
  12686. +           {
  12687. +               regardTeam(activeChar, Integer.parseInt(st.nextToken()), Integer.parseInt(n), Integer.parseInt(id), type);
  12688. +           }
  12689. +           showEventControl(activeChar);
  12690. +       }
  12691. +       else if (command.startsWith("admin_event_control_finish"))
  12692. +       {
  12693. +           for (int i = 0; i < L2Event.teamsNumber; i++)
  12694. +           {
  12695. +               telePlayersBack(i + 1);
  12696. +           }
  12697. +
  12698. +           L2Event.eventName = "";
  12699. +           L2Event.teamsNumber = 0;
  12700. +           L2Event.names.clear();
  12701. +           L2Event.participatingPlayers.clear();
  12702. +           L2Event.players.clear();
  12703. +           L2Event.id = 12760;
  12704. +           L2Event.npcs.clear();
  12705. +           L2Event.active = false;
  12706. +           npcsDeleted = false;
  12707. +       }
  12708. +
  12709. +       else if (command.startsWith("admin_event_announce"))
  12710. +       {
  12711. +           StringTokenizer st = new StringTokenizer(command.substring(21));
  12712. +           L2Event.id = Integer.parseInt(st.nextToken());
  12713. +           L2Event.teamsNumber = Integer.parseInt(st.nextToken());
  12714. +           String temp = " ";
  12715. +           String temp2 = "";
  12716. +           while (st.hasMoreElements())
  12717. +           {
  12718. +               temp += st.nextToken() + " ";
  12719. +           }
  12720. +
  12721. +           st = new StringTokenizer(temp, "-");
  12722. +
  12723. +           Integer i = 1;
  12724. +
  12725. +           while (st.hasMoreElements())
  12726. +           {
  12727. +               temp2 = st.nextToken();
  12728. +               if (!temp2.equals(" "))
  12729. +               {
  12730. +                   L2Event.names.put(i, temp2.substring(1, temp2.length() - 1));
  12731. +                   i++;
  12732. +               }
  12733. +           }
  12734. +
  12735. +           L2Event.participatingPlayers.clear();
  12736. +
  12737. +           muestraNpcConInfoAPlayers(activeChar, L2Event.id);
  12738. +
  12739. +           NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  12740. +
  12741. +           StringBuilder replyMSG = new StringBuilder("<html><body>");
  12742. +
  12743. +           replyMSG.append("<center><font color=\"LEVEL\">[ L2J EVENT ENGINE</font></center><br>");
  12744. +           replyMSG.append("<center>The event <font color=\"LEVEL\">" + L2Event.eventName + "</font> has been announced, now you can type //event_panel to see the event panel control</center><br>");
  12745. +           replyMSG.append("</body></html>");
  12746. +           adminReply.setHtml(replyMSG.toString());
  12747. +           activeChar.sendPacket(adminReply);
  12748. +       }
  12749. +       return true;
  12750. +   }
  12751. +
  12752. +   @Override
  12753. +   public String[] getAdminCommandList()
  12754. +   {
  12755. +       return ADMIN_COMMANDS;
  12756. +   }
  12757. +
  12758. +   String showStoredEvents()
  12759. +   {
  12760. +       File dir = new File("data/events");
  12761. +       String[] files = dir.list();
  12762. +       String result = "";
  12763. +       if (files == null)
  12764. +       {
  12765. +           result = "No 'data/events' directory!";
  12766. +           return result;
  12767. +       }
  12768. +       for (int i = 0; i < files.length; i++)
  12769. +       {
  12770. +
  12771. +           File file = new File("data/events/" + files[i]);
  12772. +           result += "<font color=\"LEVEL\">" + file.getName() + " </font><br><button value=\"select\" action=\"bypass -h admin_event_set " + file.getName() + "\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"><button value=\"ver\" action=\"bypass -h admin_event_see " + file.getName() + "\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"><button value=\"delete\" action=\"bypass -h admin_event_del " + file.getName() + "\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"><br><br>";
  12773. +       }
  12774. +       return result;
  12775. +   }
  12776. +
  12777. +   public void showMainPage(Player activeChar)
  12778. +   {
  12779. +       NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  12780. +
  12781. +       StringBuilder replyMSG = new StringBuilder("<html><body>");
  12782. +
  12783. +       replyMSG.append("<center><font color=\"LEVEL\">[ L2J EVENT ENGINE ]</font></center><br>");
  12784. +       replyMSG.append("<br><center><button value=\"Create NEW event \" action=\"bypass -h admin_event_new\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
  12785. +       replyMSG.append("<center><br>Stored Events<br></center>");
  12786. +       replyMSG.append(showStoredEvents());
  12787. +       replyMSG.append("</body></html>");
  12788. +
  12789. +       adminReply.setHtml(replyMSG.toString());
  12790. +       activeChar.sendPacket(adminReply);
  12791. +   }
  12792. +
  12793. +   public void showNewEventPage(Player activeChar)
  12794. +   {
  12795. +       NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  12796. +
  12797. +       StringBuilder replyMSG = new StringBuilder("<html><body>");
  12798. +
  12799. +       replyMSG.append("<center><font color=\"LEVEL\">[ L2J EVENT ENGINE ]</font></center><br>");
  12800. +       replyMSG.append("<br><center>Event's Title <br><font color=\"LEVEL\">");
  12801. +       if (tempName.equals(""))
  12802. +           replyMSG.append("Use //event_name text to insert a new title");
  12803. +       else
  12804. +           replyMSG.append(tempName);
  12805. +       replyMSG.append("</font></center><br><br>Event's description<br>");
  12806. +       if (tempBuffer.equals(""))
  12807. +           replyMSG.append("Use //add text o //delete_buffer to modify this text field");
  12808. +       else
  12809. +           replyMSG.append(tempBuffer);
  12810. +
  12811. +       if (!(tempName.equals("") && tempBuffer.equals("")))
  12812. +           replyMSG.append("<br><button value=\"Crear\" action=\"bypass -h admin_event_store\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
  12813. +
  12814. +       replyMSG.append("</body></html>");
  12815. +
  12816. +       adminReply.setHtml(replyMSG.toString());
  12817. +       activeChar.sendPacket(adminReply);
  12818. +   }
  12819. +
  12820. +   public void showEventParameters(Player activeChar, int teamnumbers)
  12821. +   {
  12822. +       NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  12823. +
  12824. +       StringBuilder replyMSG = new StringBuilder("<html><body>");
  12825. +
  12826. +       replyMSG.append("<center><font color=\"LEVEL\">[ L2J EVENT ENGINE ]</font></center><br>");
  12827. +       replyMSG.append("<center><font color=\"LEVEL\">" + L2Event.eventName + "</font></center><br>");
  12828. +       replyMSG.append("<br><center><button value=\"Change number of teams to\" action=\"bypass -h admin_event_change_teams_number $event_teams_number\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"> <edit var=\"event_teams_number\" width=100 height=20><br><br>");
  12829. +       replyMSG.append("<font color=\"LEVEL\">Team's Names</font><br>");
  12830. +       for (int i = 0; i < teamnumbers; i++)
  12831. +       {
  12832. +           replyMSG.append((i + 1) + ".- <edit var=\"event_teams_name" + (i + 1) + "\" width=100 height=20><br>");
  12833. +       }
  12834. +       replyMSG.append("<br><br>Announcer NPC id<edit var=\"event_npcid\" width=100 height=20><br><br><button value=\"Announce Event!!\" action=\"bypass -h admin_event_announce $event_npcid " + teamnumbers + " ");
  12835. +       for (int i = 0; i < teamnumbers; i++)
  12836. +       {
  12837. +           replyMSG.append("$event_teams_name" + (i + 1) + " - ");
  12838. +       }
  12839. +       replyMSG.append("\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
  12840. +       replyMSG.append("</body></html>");
  12841. +
  12842. +       adminReply.setHtml(replyMSG.toString());
  12843. +       activeChar.sendPacket(adminReply);
  12844. +   }
  12845. +
  12846. +   void muestraNpcConInfoAPlayers(Player activeChar, int id)
  12847. +   {
  12848. +       L2Event.npcs.clear();
  12849. +       LinkedList<Player> temp = new LinkedList<>();
  12850. +       temp.clear();
  12851. +       for (Player player : World.getInstance().getPlayers())
  12852. +       {
  12853. +
  12854. +           if (!temp.contains(player))
  12855. +           {
  12856. +               L2Event.spawn(player, id);
  12857. +               temp.add(player);
  12858. +           }
  12859. +           for (Player playertemp : player.getKnownType(Player.class))
  12860. +           {
  12861. +               if ((Math.abs(playertemp.getX() - player.getX()) < 500) && (Math.abs(playertemp.getY() - player.getY()) < 500) && (Math.abs(playertemp.getZ() - player.getZ()) < 500))
  12862. +                   temp.add(playertemp);
  12863. +           }
  12864. +       }
  12865. +       L2Event.announceAllPlayers(activeChar.getName() + " wants to make an event !!! (you'll find a npc with the details around)");
  12866. +   }
  12867. +
  12868. +   void showEventControl(Player activeChar)
  12869. +   {
  12870. +       NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  12871. +
  12872. +       StringBuilder replyMSG = new StringBuilder("<html><body>");
  12873. +
  12874. +       replyMSG.append("<center><font color=\"LEVEL\">[ L2J EVENT ENGINE ]</font></center><br><font color=\"LEVEL\">" + L2Event.eventName + "</font><br><br><table width=200>");
  12875. +       replyMSG.append("<tr><td>Apply this command to teams number </td><td><edit var=\"team_number\" width=100 height=15></td></tr>");
  12876. +       replyMSG.append("<tr><td>&nbsp;</td></tr>");
  12877. +       if (!npcsDeleted)
  12878. +           replyMSG.append("<tr><td><button value=\"Start\" action=\"bypass -h admin_event_control_begin\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><font color=\"LEVEL\">Destroys all event npcs so no more people can't participate now on</font></td></tr>");
  12879. +       replyMSG.append("<tr><td>&nbsp;</td></tr>");
  12880. +       replyMSG.append("<tr><td><button value=\"Teleport\" action=\"bypass -h admin_event_control_teleport $team_number\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><font color=\"LEVEL\">Teleports the specified team to your position</font></td></tr>");
  12881. +       replyMSG.append("<tr><td>&nbsp;</td></tr>");
  12882. +       replyMSG.append("<tr><td><button value=\"Sit\" action=\"bypass -h admin_event_control_sit $team_number\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><font color=\"LEVEL\">Sits/Stands up the team</font></td></tr>");
  12883. +       replyMSG.append("<tr><td>&nbsp;</td></tr>");
  12884. +       replyMSG.append("<tr><td><button value=\"Kill\" action=\"bypass -h admin_event_control_kill $team_number\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><font color=\"LEVEL\">Finish with the life of all the players in the selected team</font></td></tr>");
  12885. +       replyMSG.append("<tr><td>&nbsp;</td></tr>");
  12886. +       replyMSG.append("<tr><td><button value=\"Resurrect\" action=\"bypass -h admin_event_control_res $team_number\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><font color=\"LEVEL\">Resurrect Team's members</font></td></tr>");
  12887. +       replyMSG.append("<tr><td>&nbsp;</td></tr>");
  12888. +       replyMSG.append("<tr><td><button value=\"Polymorph\" action=\"bypass -h admin_event_control_poly $team_number $poly_id\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><edit var=\"poly_id\" width=100 height=15><font color=\"LEVEL\">Polymorphs the team into the NPC with the id specified</font></td></tr>");
  12889. +       replyMSG.append("<tr><td>&nbsp;</td></tr>");
  12890. +       replyMSG.append("<tr><td><button value=\"UnPolymorph\" action=\"bypass -h admin_event_control_unpoly $team_number\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><font color=\"LEVEL\">Unpolymorph the team</font></td></tr>");
  12891. +       replyMSG.append("<tr><td>&nbsp;</td></tr>");
  12892. +       replyMSG.append("<tr><td>&nbsp;</td></tr>");
  12893. +       replyMSG.append("<tr><td><button value=\"Give Item\" action=\"bypass -h admin_event_control_prize $team_number $n $id\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"> number <edit var=\"n\" width=100 height=15> item id <edit var=\"id\" width=100 height=15></td><td><font color=\"LEVEL\">Give the specified item id to every single member of the team, you can put 5*level, 5*kills or 5 in the number field for example</font></td></tr>");
  12894. +       replyMSG.append("<tr><td>&nbsp;</td></tr>");
  12895. +       replyMSG.append("<tr><td><button value=\"End\" action=\"bypass -h admin_event_control_finish\" width=90 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><font color=\"LEVEL\">Will finish the event teleporting back all the players</font></td></tr>");
  12896. +       replyMSG.append("</table></body></html>");
  12897. +
  12898. +       adminReply.setHtml(replyMSG.toString());
  12899. +       activeChar.sendPacket(adminReply);
  12900. +   }
  12901. +
  12902. +   String getMaxLeveledPlayer()
  12903. +   {
  12904. +       Iterator<?> it = L2Event.participatingPlayers.iterator();
  12905. +       Player pc = null;
  12906. +       int max = 0;
  12907. +       String name = "";
  12908. +       while (it.hasNext())
  12909. +       {
  12910. +           try
  12911. +           {
  12912. +               tempName2 = it.next().toString();
  12913. +               pc = World.getInstance().getPlayer(tempName2);
  12914. +               if (max < pc.getLevel())
  12915. +               {
  12916. +                   max = pc.getLevel();
  12917. +                   name = pc.getName();
  12918. +               }
  12919. +           }
  12920. +           catch (Exception e)
  12921. +           {
  12922. +               try
  12923. +               {
  12924. +                   L2Event.participatingPlayers.remove(tempName2);
  12925. +               }
  12926. +               catch (Exception e2)
  12927. +               {
  12928. +
  12929. +               }
  12930. +           }
  12931. +       }
  12932. +       L2Event.participatingPlayers.remove(name);
  12933. +       return name;
  12934. +   }
  12935. +
  12936. +   void destroyEventNpcs()
  12937. +   {
  12938. +       Npc npc;
  12939. +       while (L2Event.npcs.size() > 0)
  12940. +       {
  12941. +           try
  12942. +           {
  12943. +               npc = (Npc) World.getInstance().getObject(Integer.parseInt(L2Event.npcs.getFirst()));
  12944. +               L2Spawn spawn = npc.getSpawn();
  12945. +
  12946. +               if (spawn != null)
  12947. +               {
  12948. +                   spawn.setRespawnState(false);
  12949. +                   SpawnTable.getInstance().deleteSpawn(spawn, true);
  12950. +               }
  12951. +               npc.deleteMe();
  12952. +               L2Event.npcs.removeFirst();
  12953. +           }
  12954. +           catch (Exception e)
  12955. +           {
  12956. +               L2Event.npcs.removeFirst();
  12957. +           }
  12958. +       }
  12959. +   }
  12960. +
  12961. +   void teleportTeam(Player activeChar, int team)
  12962. +   {
  12963. +       LinkedList<?> linked = L2Event.players.get(team);
  12964. +       Iterator<?> it = linked.iterator();
  12965. +       while (it.hasNext())
  12966. +       {
  12967. +           try
  12968. +           {
  12969. +               Player pc = World.getInstance().getPlayer(it.next().toString());
  12970. +               pc.setTitle(L2Event.names.get(team));
  12971. +               pc.teleToLocation(activeChar.getX(), activeChar.getY(), activeChar.getZ(), 0);
  12972. +           }
  12973. +           catch (Exception e)
  12974. +           {
  12975. +
  12976. +           }
  12977. +       }
  12978. +   }
  12979. +
  12980. +   void sitTeam(int team)
  12981. +   {
  12982. +       LinkedList<?> linked = L2Event.players.get(team);
  12983. +       Iterator<?> it = linked.iterator();
  12984. +       while (it.hasNext())
  12985. +       {
  12986. +           try
  12987. +           {
  12988. +               Player pc = World.getInstance().getPlayer(it.next().toString());
  12989. +               pc.eventSitForced = !pc.eventSitForced;
  12990. +               if (pc.eventSitForced)
  12991. +                   pc.sitDown();
  12992. +               else
  12993. +                   pc.standUp();
  12994. +           }
  12995. +           catch (Exception e)
  12996. +           {
  12997. +           }
  12998. +       }
  12999. +   }
  13000. +
  13001. +   void killTeam(Player activeChar, int team)
  13002. +   {
  13003. +       LinkedList<?> linked = L2Event.players.get(team);
  13004. +       Iterator<?> it = linked.iterator();
  13005. +       while (it.hasNext())
  13006. +       {
  13007. +           try
  13008. +           {
  13009. +               Player target = World.getInstance().getPlayer(it.next().toString());
  13010. +               target.reduceCurrentHp(target.getMaxHp() + target.getMaxCp() + 1, activeChar, null);
  13011. +           }
  13012. +           catch (Exception e)
  13013. +           {
  13014. +           }
  13015. +       }
  13016. +   }
  13017. +
  13018. +   void resTeam(int team)
  13019. +   {
  13020. +       LinkedList<?> linked = L2Event.players.get(team);
  13021. +       Iterator<?> it = linked.iterator();
  13022. +       while (it.hasNext())
  13023. +       {
  13024. +           try
  13025. +           {
  13026. +               Player character = World.getInstance().getPlayer(it.next().toString());
  13027. +               character.setCurrentHpMp(character.getMaxHp(), character.getMaxMp());
  13028. +               character.setCurrentCp(character.getMaxCp());
  13029. +               Revive revive = new Revive(character);
  13030. +               SocialAction sa = new SocialAction(character, 15);
  13031. +               character.broadcastPacket(sa);
  13032. +               character.sendPacket(sa);
  13033. +               character.sendPacket(revive);
  13034. +               character.broadcastPacket(revive);
  13035. +           }
  13036. +           catch (Exception e)
  13037. +           {
  13038. +           }
  13039. +       }
  13040. +   }
  13041. +
  13042. +   void polyTeam(int team, String id)
  13043. +   {
  13044. +       LinkedList<?> linked = L2Event.players.get(team);
  13045. +       Iterator<?> it = linked.iterator();
  13046. +       while (it.hasNext())
  13047. +       {
  13048. +           try
  13049. +           {
  13050. +               Player target = World.getInstance().getPlayer(it.next().toString());
  13051. +               target.polymorph(null, 1);
  13052. +               target.teleToLocation(target.getX(), target.getY(), target.getZ(), 0);
  13053. +              
  13054. +               CharInfo info1 = new CharInfo(target);
  13055. +               target.broadcastPacket(info1);
  13056. +               UserInfo info2 = new UserInfo(target);
  13057. +               target.sendPacket(info2);
  13058. +           }
  13059. +           catch (Exception e)
  13060. +           {
  13061. +           }
  13062. +       }
  13063. +   }
  13064. +
  13065. +   void unpolyTeam(int team)
  13066. +   {
  13067. +       LinkedList<?> linked = L2Event.players.get(team);
  13068. +       Iterator<?> it = linked.iterator();
  13069. +       while (it.hasNext())
  13070. +       {
  13071. +           try
  13072. +           {
  13073. +               Player target = World.getInstance().getPlayer(it.next().toString());
  13074. +
  13075. +               if (target.getPolyType() == PolyType.NPC)
  13076. +               {
  13077. +                   target.polymorph(null, 1);
  13078. +                   target.decayMe();
  13079. +                   target.spawnMe(target.getX(), target.getY(), target.getZ());
  13080. +               }
  13081. +              
  13082. +               CharInfo info1 = new CharInfo(target);
  13083. +               target.broadcastPacket(info1);
  13084. +               UserInfo info2 = new UserInfo(target);
  13085. +               target.sendPacket(info2);
  13086. +           }
  13087. +           catch (Exception e)
  13088. +           {
  13089. +           }
  13090. +       }
  13091. +   }
  13092. +
  13093. +   private static void createItem(Player activeChar, Player player, int id, int num)
  13094. +   {
  13095. +       player.getInventory().addItem("Event", id, num, player, activeChar);
  13096. +       ItemList il = new ItemList(player, true);
  13097. +       player.sendPacket(il);
  13098. +
  13099. +       NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  13100. +       StringBuilder replyMSG = new StringBuilder("<html><body>");
  13101. +
  13102. +       replyMSG.append("CONGRATULATIONS, you should have a present in your inventory");
  13103. +       replyMSG.append("</body></html>");
  13104. +
  13105. +       adminReply.setHtml(replyMSG.toString());
  13106. +       player.sendPacket(adminReply);
  13107. +   }
  13108. +
  13109. +   void regardTeam(Player activeChar, int team, int n, int id, String type)
  13110. +   {
  13111. +       LinkedList<?> linked = L2Event.players.get(team);
  13112. +       int temp = n;
  13113. +       Iterator<?> it = linked.iterator();
  13114. +       while (it.hasNext())
  13115. +       {
  13116. +           try
  13117. +           {
  13118. +               Player target = World.getInstance().getPlayer(it.next().toString());
  13119. +               if (type.equalsIgnoreCase("level"))
  13120. +                   temp = n * target.getLevel();
  13121. +               else if (type.equalsIgnoreCase("kills"))
  13122. +                   temp = n * target.kills.size();
  13123. +               else
  13124. +                   temp = n;
  13125. +               createItem(activeChar, target, id, temp);
  13126. +           }
  13127. +           catch (Exception e)
  13128. +           {
  13129. +           }
  13130. +       }
  13131. +   }
  13132. +
  13133. +   void telePlayersBack(int team)
  13134. +   {
  13135. +       resTeam(team);
  13136. +       unpolyTeam(team);
  13137. +       LinkedList<?> linked = L2Event.players.get(team);
  13138. +       Iterator<?> it = linked.iterator();
  13139. +       while (it.hasNext())
  13140. +       {
  13141. +           try
  13142. +           {
  13143. +               Player target = World.getInstance().getPlayer(it.next().toString());
  13144. +               target.setTitle(target.eventTitle);
  13145. +               target.setKarma(target.eventkarma);
  13146. +               target.setPvpKills(target.eventpvpkills);
  13147. +               target.setPkKills(target.eventpkkills);
  13148. +               target.teleToLocation(target.eventX, target.eventY, target.eventZ, 0);
  13149. +               target.kills.clear();
  13150. +               target.eventSitForced = false;
  13151. +               target.atEvent = false;
  13152. +           }
  13153. +           catch (Exception e)
  13154. +           {
  13155. +           }
  13156. +       }
  13157. +   }
  13158. +}
  13159. \ No newline at end of file
  13160. Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestJoinParty.java
  13161. ===================================================================
  13162. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestJoinParty.java  (revision 3)
  13163. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestJoinParty.java  (working copy)
  13164. @@ -1,8 +1,12 @@
  13165.  package net.sf.l2j.gameserver.network.clientpackets;
  13166.  
  13167. +import net.sf.l2j.Config;
  13168.  import net.sf.l2j.gameserver.model.BlockList;
  13169.  import net.sf.l2j.gameserver.model.World;
  13170.  import net.sf.l2j.gameserver.model.actor.instance.Player;
  13171. +import net.sf.l2j.gameserver.model.entity.engine.CTF;
  13172. +import net.sf.l2j.gameserver.model.entity.engine.DM;
  13173. +import net.sf.l2j.gameserver.model.entity.engine.TvT;
  13174.  import net.sf.l2j.gameserver.model.group.Party;
  13175.  import net.sf.l2j.gameserver.model.group.Party.LootRule;
  13176.  import net.sf.l2j.gameserver.network.SystemMessageId;
  13177. @@ -27,7 +31,7 @@
  13178.         final Player requestor = getClient().getActiveChar();
  13179.         if (requestor == null)
  13180.             return;
  13181. -
  13182. +      
  13183.         final Player target = World.getInstance().getPlayer(_name);
  13184.         if (target == null)
  13185.         {
  13186. @@ -46,69 +50,88 @@
  13187.             requestor.sendPacket(SystemMessageId.YOU_HAVE_INVITED_THE_WRONG_TARGET);
  13188.             return;
  13189.         }
  13190. -      
  13191. -       if (target.isInParty())
  13192. +  
  13193. +       if (((TvT._started && !Config.TVT_ALLOW_INTERFERENCE) || (CTF._started && !Config.CTF_ALLOW_INTERFERENCE) || (DM._started && !Config.DM_ALLOW_INTERFERENCE)))
  13194.         {
  13195. -           requestor.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_IS_ALREADY_IN_PARTY).addCharName(target));
  13196. -           return;
  13197. -       }
  13198. -      
  13199. -       if (target.getClient().isDetached())
  13200. -       {
  13201. -           requestor.sendMessage("The player you tried to invite is in offline mode.");
  13202. -           return;
  13203. -       }
  13204. -      
  13205. -       if (target.isInJail() || requestor.isInJail())
  13206. -       {
  13207. -           requestor.sendMessage("The player you tried to invite is currently jailed.");
  13208. -           return;
  13209. -       }
  13210. -      
  13211. -       if (target.isInOlympiadMode() || requestor.isInOlympiadMode())
  13212. -           return;
  13213. -      
  13214. -       if (requestor.isProcessingRequest())
  13215. -       {
  13216. -           requestor.sendPacket(SystemMessageId.WAITING_FOR_ANOTHER_REPLY);
  13217. -           return;
  13218. -       }
  13219. -      
  13220. -       if (target.isProcessingRequest())
  13221. -       {
  13222. -           requestor.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_IS_BUSY_TRY_LATER).addCharName(target));
  13223. -           return;
  13224. -       }
  13225. -      
  13226. -       final Party party = requestor.getParty();
  13227. -       if (party != null)
  13228. -       {
  13229. -           if (!party.isLeader(requestor))
  13230. +           if ((target._inEventTvT && !requestor._inEventTvT) || (!target._inEventTvT && requestor._inEventTvT))
  13231.             {
  13232. -               requestor.sendPacket(SystemMessageId.ONLY_LEADER_CAN_INVITE);
  13233. +               requestor.sendPacket(SystemMessageId.INCORRECT_TARGET);
  13234.                 return;
  13235.             }
  13236. +           if ((target._inEventCTF && !requestor._inEventCTF) || (!target._inEventCTF && requestor._inEventCTF))
  13237. +           {
  13238. +               requestor.sendPacket(SystemMessageId.INCORRECT_TARGET);
  13239. +               return;
  13240. +           }
  13241. +           if ((target._inEventDM && !requestor._inEventDM) || (!target._inEventDM && requestor._inEventDM))
  13242. +           {
  13243. +               requestor.sendPacket(SystemMessageId.INCORRECT_TARGET);
  13244. +               return;
  13245. +           }
  13246.            
  13247. -           if (party.getMembersCount() >= 9)
  13248. +           if (target.isInParty())
  13249.             {
  13250. -               requestor.sendPacket(SystemMessageId.PARTY_FULL);
  13251. +               requestor.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_IS_ALREADY_IN_PARTY).addCharName(target));
  13252.                 return;
  13253.             }
  13254.            
  13255. -           if (party.getPendingInvitation() && !party.isInvitationRequestExpired())
  13256. +           if (target.getClient().isDetached())
  13257.             {
  13258. +               requestor.sendMessage("The player you tried to invite is in offline mode.");
  13259. +               return;
  13260. +           }
  13261. +          
  13262. +           if (target.isInJail() || requestor.isInJail())
  13263. +           {
  13264. +               requestor.sendMessage("The player you tried to invite is currently jailed.");
  13265. +               return;
  13266. +           }
  13267. +          
  13268. +           if (target.isInOlympiadMode() || requestor.isInOlympiadMode())
  13269. +               return;
  13270. +          
  13271. +           if (requestor.isProcessingRequest())
  13272. +           {
  13273.                 requestor.sendPacket(SystemMessageId.WAITING_FOR_ANOTHER_REPLY);
  13274.                 return;
  13275.             }
  13276.            
  13277. -           party.setPendingInvitation(true);
  13278. +           if (target.isProcessingRequest())
  13279. +           {
  13280. +               requestor.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_IS_BUSY_TRY_LATER).addCharName(target));
  13281. +               return;
  13282. +           }
  13283. +          
  13284. +           final Party party = requestor.getParty();
  13285. +           if (party != null)
  13286. +           {
  13287. +               if (!party.isLeader(requestor))
  13288. +               {
  13289. +                   requestor.sendPacket(SystemMessageId.ONLY_LEADER_CAN_INVITE);
  13290. +                   return;
  13291. +               }
  13292. +              
  13293. +               if (party.getMembersCount() >= 9)
  13294. +               {
  13295. +                   requestor.sendPacket(SystemMessageId.PARTY_FULL);
  13296. +                   return;
  13297. +               }
  13298. +              
  13299. +               if (party.getPendingInvitation() && !party.isInvitationRequestExpired())
  13300. +               {
  13301. +                   requestor.sendPacket(SystemMessageId.WAITING_FOR_ANOTHER_REPLY);
  13302. +                   return;
  13303. +               }
  13304. +              
  13305. +               party.setPendingInvitation(true);
  13306. +           }
  13307. +           else
  13308. +               requestor.setLootRule(LootRule.VALUES[_itemDistribution]);
  13309. +          
  13310. +           requestor.onTransactionRequest(target);
  13311. +           requestor.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_INVITED_S1_TO_PARTY).addCharName(target));
  13312. +          
  13313. +           target.sendPacket(new AskJoinParty(requestor.getName(), (party != null) ? party.getLootRule().ordinal() : _itemDistribution));
  13314.         }
  13315. -       else
  13316. -           requestor.setLootRule(LootRule.VALUES[_itemDistribution]);
  13317. -      
  13318. -       requestor.onTransactionRequest(target);
  13319. -       requestor.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_INVITED_S1_TO_PARTY).addCharName(target));
  13320. -      
  13321. -       target.sendPacket(new AskJoinParty(requestor.getName(), (party != null) ? party.getLootRule().ordinal() : _itemDistribution));
  13322.     }
  13323.  }
  13324. \ No newline at end of file
  13325. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminDMEngine.java
  13326. ===================================================================
  13327. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminDMEngine.java  (revision 0)
  13328. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminDMEngine.java  (working copy)
  13329. @@ -0,0 +1,238 @@
  13330. +/*
  13331. + * This program is free software: you can redistribute it and/or modify it under
  13332. + * the terms of the GNU General Public License as published by the Free Software
  13333. + * Foundation, either version 3 of the License, or (at your option) any later
  13334. + * version.
  13335. + *
  13336. + * This program is distributed in the hope that it will be useful, but WITHOUT
  13337. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13338. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  13339. + * details.
  13340. + *
  13341. + * You should have received a copy of the GNU General Public License along with
  13342. + * this program. If not, see <http://www.gnu.org/licenses/>.
  13343. + */
  13344. +package net.sf.l2j.gameserver.handler.admincommandhandlers;
  13345. +
  13346. +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  13347. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  13348. +import net.sf.l2j.gameserver.model.entity.engine.DM;
  13349. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  13350. +import net.sf.l2j.gameserver.util.Util;
  13351. +
  13352. +/**
  13353. + * @author SqueezeD
  13354. + */
  13355. +public class AdminDMEngine implements IAdminCommandHandler
  13356. +{
  13357. +   private static final String[] ADMIN_COMMANDS =
  13358. +   {/** @formatter:off */
  13359. +       "admin_dmevent",
  13360. +       "admin_dmevent_name",
  13361. +       "admin_dmevent_desc",
  13362. +       "admin_dmevent_join_loc",
  13363. +       "admin_dmevent_minlvl",
  13364. +       "admin_dmevent_maxlvl",
  13365. +       "admin_dmevent_npc",
  13366. +       "admin_dmevent_npc_pos",
  13367. +       "admin_dmevent_reward",
  13368. +       "admin_dmevent_reward_amount",
  13369. +       "admin_dmevent_spawnpos",
  13370. +       "admin_dmevent_color",
  13371. +       "admin_dmevent_join",
  13372. +       "admin_dmevent_teleport",
  13373. +       "admin_dmevent_start",
  13374. +       "admin_dmevent_abort",
  13375. +       "admin_dmevent_finish",
  13376. +       "admin_dmevent_sit",
  13377. +       "admin_dmevent_dump",
  13378. +       "admin_dmevent_save",
  13379. +       "admin_dmevent_load"
  13380. +   };/** @formatter:on */
  13381. +
  13382. +   @Override
  13383. +   public boolean useAdminCommand(String command, Player activeChar)
  13384. +   {
  13385. +       if (command.equals("admin_dmevent"))
  13386. +           showMainPage(activeChar);
  13387. +       else if (command.startsWith("admin_dmevent_name "))
  13388. +       {
  13389. +           DM._eventName = command.substring(19);
  13390. +           showMainPage(activeChar);
  13391. +       }
  13392. +       else if (command.startsWith("admin_dmevent_desc "))
  13393. +       {
  13394. +           DM._eventDesc = command.substring(19);
  13395. +           showMainPage(activeChar);
  13396. +       }
  13397. +       else if (command.startsWith("admin_dmevent_minlvl "))
  13398. +       {
  13399. +           if (!DM.checkMinLevel(Integer.valueOf(command.substring(21))))
  13400. +               return false;
  13401. +           DM._minlvl = Integer.valueOf(command.substring(21));
  13402. +           showMainPage(activeChar);
  13403. +       }
  13404. +       else if (command.startsWith("admin_dmevent_maxlvl "))
  13405. +       {
  13406. +           if (!DM.checkMaxLevel(Integer.valueOf(command.substring(21))))
  13407. +               return false;
  13408. +           DM._maxlvl = Integer.valueOf(command.substring(21));
  13409. +           showMainPage(activeChar);
  13410. +       }
  13411. +       else if (command.startsWith("admin_dmevent_join_loc "))
  13412. +       {
  13413. +           DM._joiningLocationName = command.substring(23);
  13414. +           showMainPage(activeChar);
  13415. +       }
  13416. +       else if (command.startsWith("admin_dmevent_npc "))
  13417. +       {
  13418. +           DM._npcId = Integer.valueOf(command.substring(18));
  13419. +           showMainPage(activeChar);
  13420. +       }
  13421. +       else if (command.equals("admin_dmevent_npc_pos"))
  13422. +       {
  13423. +           DM.setNpcPos(activeChar);
  13424. +           showMainPage(activeChar);
  13425. +       }
  13426. +       else if (command.startsWith("admin_dmevent_reward "))
  13427. +       {
  13428. +           DM._rewardId = Integer.valueOf(command.substring(21));
  13429. +           showMainPage(activeChar);
  13430. +       }
  13431. +       else if (command.startsWith("admin_dmevent_reward_amount "))
  13432. +       {
  13433. +           DM._rewardAmount = Integer.valueOf(command.substring(28));
  13434. +           showMainPage(activeChar);
  13435. +       }
  13436. +       else if (command.equals("admin_dmevent_spawnpos"))
  13437. +       {
  13438. +           DM.setPlayersPos(activeChar);
  13439. +           showMainPage(activeChar);
  13440. +       }
  13441. +       else if (command.startsWith("admin_dmevent_color "))
  13442. +       {
  13443. +           DM._playerColors = Integer.decode("0x" + Util.reverseColor(command.substring(20))); // name/title color in client is BGR, not RGB
  13444. +           showMainPage(activeChar);
  13445. +       }
  13446. +       else if (command.equals("admin_dmevent_join"))
  13447. +       {
  13448. +           DM.startJoin(activeChar);
  13449. +           showMainPage(activeChar);
  13450. +       }
  13451. +       else if (command.equals("admin_dmevent_teleport"))
  13452. +       {
  13453. +           DM.teleportStart();
  13454. +           showMainPage(activeChar);
  13455. +       }
  13456. +       else if (command.equals("admin_dmevent_start"))
  13457. +       {
  13458. +           DM.startEvent(activeChar);
  13459. +           showMainPage(activeChar);
  13460. +       }
  13461. +       else if (command.equals("admin_dmevent_abort"))
  13462. +       {
  13463. +           activeChar.sendMessage("Aborting event");
  13464. +           DM.abortEvent();
  13465. +           showMainPage(activeChar);
  13466. +       }
  13467. +       else if (command.equals("admin_dmevent_finish"))
  13468. +       {
  13469. +           DM.finishEvent(activeChar);
  13470. +           showMainPage(activeChar);
  13471. +       }
  13472. +       else if (command.equals("admin_dmevent_sit"))
  13473. +       {
  13474. +           DM.sit();
  13475. +           showMainPage(activeChar);
  13476. +       }
  13477. +       else if (command.equals("admin_dmevent_load"))
  13478. +       {
  13479. +           DM.loadData();
  13480. +           showMainPage(activeChar);
  13481. +       }
  13482. +       else if (command.equals("admin_dmevent_save"))
  13483. +       {
  13484. +           DM.saveData();
  13485. +           showMainPage(activeChar);
  13486. +       }
  13487. +       else if (command.equals("admin_dmevent_dump"))
  13488. +           DM.dumpData();
  13489. +
  13490. +       return true;
  13491. +   }
  13492. +
  13493. +   @Override
  13494. +   public String[] getAdminCommandList()
  13495. +   {
  13496. +       return ADMIN_COMMANDS;
  13497. +   }
  13498. +
  13499. +   public void showMainPage(Player activeChar)
  13500. +   {
  13501. +       NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  13502. +       StringBuilder replyMSG = new StringBuilder("<html><body>");
  13503. +
  13504. +       replyMSG.append("<center><font color=\"LEVEL\">[dm Engine - by SqueezeD]</font></center><br><br><br>");
  13505. +       replyMSG.append("<table><tr><td><edit var=\"input1\" width=\"125\"></td><td><edit var=\"input2\" width=\"125\"></td></tr></table>");
  13506. +       replyMSG.append("<table border=\"0\"><tr>");
  13507. +       replyMSG.append("<td width=\"100\"><button value=\"Name\" action=\"bypass -h admin_dmevent_name $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13508. +       replyMSG.append("<td width=\"100\"><button value=\"Description\" action=\"bypass -h admin_dmevent_desc $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13509. +       replyMSG.append("<td width=\"100\"><button value=\"Join Location\" action=\"bypass -h admin_dmevent_join_loc $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13510. +       replyMSG.append("</tr></table><br><table><tr>");
  13511. +       replyMSG.append("</tr></table><br><table><tr>");
  13512. +       replyMSG.append("<td width=\"100\"><button value=\"Max lvl\" action=\"bypass -h admin_dmevent_maxlvl $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13513. +       replyMSG.append("<td width=\"100\"><button value=\"Min lvl\" action=\"bypass -h admin_dmevent_minlvl $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13514. +       replyMSG.append("</tr></table><br><table><tr>");
  13515. +       replyMSG.append("<td width=\"100\"><button value=\"NPC\" action=\"bypass -h admin_dmevent_npc $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13516. +       replyMSG.append("<td width=\"100\"><button value=\"NPC Pos\" action=\"bypass -h admin_dmevent_npc_pos\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13517. +       replyMSG.append("</tr></table><br><table><tr>");
  13518. +       replyMSG.append("<td width=\"100\"><button value=\"Reward\" action=\"bypass -h admin_dmevent_reward $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13519. +       replyMSG.append("<td width=\"100\"><button value=\"Reward Amount\" action=\"bypass -h admin_dmevent_reward_amount $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13520. +       replyMSG.append("</tr></table><br><table><tr>");
  13521. +       replyMSG.append("<td width=\"100\"><button value=\"DM Color\" action=\"bypass -h admin_dmevent_color $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13522. +       replyMSG.append("<td width=\"100\"><button value=\"DM SpawnPos\" action=\"bypass -h admin_dmevent_spawnpos\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13523. +       replyMSG.append("</tr></table><table><br><br><tr>");
  13524. +       replyMSG.append("<td width=\"100\"><button value=\"Join\" action=\"bypass -h admin_dmevent_join\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13525. +       replyMSG.append("<td width=\"100\"><button value=\"Teleport\" action=\"bypass -h admin_dmevent_teleport\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13526. +       replyMSG.append("<td width=\"100\"><button value=\"Start\" action=\"bypass -h admin_dmevent_start\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13527. +       replyMSG.append("</tr></table><table><tr>");
  13528. +       replyMSG.append("<td width=\"100\"><button value=\"Abort\" action=\"bypass -h admin_dmevent_abort\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13529. +       replyMSG.append("<td width=\"100\"><button value=\"Finish\" action=\"bypass -h admin_dmevent_finish\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13530. +       replyMSG.append("</tr></table><br><table><tr>");
  13531. +       replyMSG.append("<td width=\"100\"><button value=\"Sit Force\" action=\"bypass -h admin_dmevent_sit\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13532. +       replyMSG.append("<td width=\"100\"><button value=\"Dump\" action=\"bypass -h admin_dmevent_dump\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13533. +       replyMSG.append("</tr></table><br><br><table><tr>");
  13534. +       replyMSG.append("<td width=\"100\"><button value=\"Save\" action=\"bypass -h admin_dmevent_save\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13535. +       replyMSG.append("<td width=\"100\"><button value=\"Load\" action=\"bypass -h admin_dmevent_load\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13536. +       replyMSG.append("</tr></table><br><br>");
  13537. +       replyMSG.append("Current event...<br1>");
  13538. +       replyMSG.append("    ... name:&nbsp;<font color=\"00FF00\">" + DM._eventName + "</font><br1>");
  13539. +       replyMSG.append("    ... description:&nbsp;<font color=\"00FF00\">" + DM._eventDesc + "</font><br1>");
  13540. +       replyMSG.append("    ... joining location name:&nbsp;<font color=\"00FF00\">" + DM._joiningLocationName + "</font><br1>");
  13541. +       replyMSG.append("    ... joining NPC ID:&nbsp;<font color=\"00FF00\">" + DM._npcId + " on pos " + DM._npcX + "," + DM._npcY + "," + DM._npcZ + "</font><br1>");
  13542. +       replyMSG.append("    ... reward ID:&nbsp;<font color=\"00FF00\">" + DM._rewardId + "</font><br1>");
  13543. +       replyMSG.append("    ... reward Amount:&nbsp;<font color=\"00FF00\">" + DM._rewardAmount + "</font><br><br>");
  13544. +       replyMSG.append("    ... Min lvl:&nbsp;<font color=\"00FF00\">" + DM._minlvl + "</font><br>");
  13545. +       replyMSG.append("    ... Max lvl:&nbsp;<font color=\"00FF00\">" + DM._maxlvl + "</font><br><br>");
  13546. +       replyMSG.append("    ... Death Match Color:&nbsp;<font color=\"00FF00\">" + DM._playerColors + "</font><br>");
  13547. +       replyMSG.append("    ... Death Match Spawn Pos:&nbsp;<font color=\"00FF00\">" + DM._playerX + "," + DM._playerY + "," + DM._playerZ + "</font><br><br>");
  13548. +       replyMSG.append("Current players:<br1>");
  13549. +
  13550. +       if (!DM._started)
  13551. +       {
  13552. +           replyMSG.append("<br1>");
  13553. +           replyMSG.append(DM._players.size() + " players participating.");
  13554. +           replyMSG.append("<br><br>");
  13555. +       }
  13556. +       else if (DM._started)
  13557. +       {
  13558. +           replyMSG.append("<br1>");
  13559. +           replyMSG.append(DM._players.size() + " players in fighting event.");
  13560. +           replyMSG.append("<br><br>");
  13561. +       }
  13562. +
  13563. +       replyMSG.append("</body></html>");
  13564. +       adminReply.setHtml(replyMSG.toString());
  13565. +       activeChar.sendPacket(adminReply);
  13566. +   }
  13567. +}
  13568. \ No newline at end of file
  13569. Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
  13570. ===================================================================
  13571. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java (revision 3)
  13572. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java (working copy)
  13573. @@ -14,6 +14,10 @@
  13574.  import net.sf.l2j.gameserver.model.actor.instance.OlympiadManagerNpc;
  13575.  import net.sf.l2j.gameserver.model.actor.instance.Player;
  13576.  import net.sf.l2j.gameserver.model.entity.Hero;
  13577. +import net.sf.l2j.gameserver.model.entity.L2Event;
  13578. +import net.sf.l2j.gameserver.model.entity.engine.CTF;
  13579. +import net.sf.l2j.gameserver.model.entity.engine.DM;
  13580. +import net.sf.l2j.gameserver.model.entity.engine.TvT;
  13581.  import net.sf.l2j.gameserver.model.olympiad.OlympiadManager;
  13582.  import net.sf.l2j.gameserver.network.SystemMessageId;
  13583.  import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  13584. @@ -100,6 +104,81 @@
  13585.                     if (object != null && object instanceof Npc && endOfId > 0 && ((Npc) object).canInteract(activeChar))
  13586.                         ((Npc) object).onBypassFeedback(activeChar, _command.substring(endOfId + 1));
  13587.                    
  13588. +                   if (_command.substring(endOfId + 1).startsWith("event_participate"))
  13589. +                   {
  13590. +                       L2Event.inscribePlayer(activeChar);
  13591. +                   }
  13592. +                   else if (_command.substring(endOfId + 1).startsWith("tvt_player_join "))
  13593. +                   {
  13594. +                       String teamName = _command.substring(endOfId + 1).substring(16);
  13595. +                      
  13596. +                       if (TvT._joining)
  13597. +                       {
  13598. +                           TvT.addPlayer(activeChar, teamName);
  13599. +                       }
  13600. +                       else
  13601. +                       {
  13602. +                           activeChar.sendMessage("The event is already started. You can not join now!");
  13603. +                       }
  13604. +                   }
  13605. +                   else if (_command.substring(endOfId + 1).startsWith("tvt_player_leave"))
  13606. +                   {
  13607. +                       if (TvT._joining)
  13608. +                       {
  13609. +                           TvT.removePlayer(activeChar);
  13610. +                       }
  13611. +                       else
  13612. +                       {
  13613. +                           activeChar.sendMessage("The event is already started. You can not leave now!");
  13614. +                       }
  13615. +                   }
  13616. +                   else if (_command.substring(endOfId + 1).startsWith("dmevent_player_join"))
  13617. +                   {
  13618. +                       if (DM._joining)
  13619. +                       {
  13620. +                           DM.addPlayer(activeChar);
  13621. +                       }
  13622. +                       else
  13623. +                       {
  13624. +                           activeChar.sendMessage("The event is already started. You can not join now!");
  13625. +                       }
  13626. +                   }
  13627. +                   else if (_command.substring(endOfId + 1).startsWith("dmevent_player_leave"))
  13628. +                   {
  13629. +                       if (DM._joining)
  13630. +                       {
  13631. +                           DM.removePlayer(activeChar);
  13632. +                       }
  13633. +                       else
  13634. +                       {
  13635. +                           activeChar.sendMessage("The event is already started. You can not leave now!");
  13636. +                       }
  13637. +                   }
  13638. +                   else if (_command.substring(endOfId + 1).startsWith("ctf_player_join "))
  13639. +                   {
  13640. +                       String teamName = _command.substring(endOfId + 1).substring(16);
  13641. +                      
  13642. +                       if (CTF._joining)
  13643. +                       {
  13644. +                           CTF.addPlayer(activeChar, teamName);
  13645. +                       }
  13646. +                       else
  13647. +                       {
  13648. +                           activeChar.sendMessage("The event is already started. You can not join now!");
  13649. +                       }
  13650. +                   }
  13651. +                   else if (_command.substring(endOfId + 1).startsWith("ctf_player_leave"))
  13652. +                   {
  13653. +                       if (CTF._joining)
  13654. +                       {
  13655. +                           CTF.removePlayer(activeChar);
  13656. +                       }
  13657. +                       else
  13658. +                       {
  13659. +                           activeChar.sendMessage("The event is already started. You can not leave now!");
  13660. +                       }
  13661. +                   }
  13662. +                  
  13663.                     activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  13664.                 }
  13665.                 catch (NumberFormatException nfe)
  13666. @@ -163,7 +242,7 @@
  13667.                     activeChar.sendPacket(SystemMessageId.WHILE_YOU_ARE_ON_THE_WAITING_LIST_YOU_ARE_NOT_ALLOWED_TO_WATCH_THE_GAME);
  13668.                     return;
  13669.                 }
  13670. -
  13671. +              
  13672.                 final int arenaId = Integer.parseInt(_command.substring(12).trim());
  13673.                 activeChar.enterOlympiadObserverMode(arenaId);
  13674.             }
  13675. Index: java/net/sf/l2j/gameserver/model/actor/instance/BroadcastingTower.java
  13676. ===================================================================
  13677. --- java/net/sf/l2j/gameserver/model/actor/instance/BroadcastingTower.java  (revision 1)
  13678. +++ java/net/sf/l2j/gameserver/model/actor/instance/BroadcastingTower.java  (working copy)
  13679. @@ -29,7 +29,13 @@
  13680.             final int x = Integer.parseInt(st.nextToken());
  13681.             final int y = Integer.parseInt(st.nextToken());
  13682.             final int z = Integer.parseInt(st.nextToken());
  13683. -          
  13684. +
  13685. +           if (player._inEventTvT || player._inEventDM || player._inEventCTF)
  13686. +           {
  13687. +               player.sendMessage("You already participated in Event!");
  13688. +               return;
  13689. +           }
  13690. +
  13691.             if (command.startsWith("observeSiege") && CastleManager.getInstance().getSiege(x, y, z) == null)
  13692.             {
  13693.                 player.sendPacket(SystemMessageId.ONLY_VIEW_SIEGE);
  13694. @@ -36,6 +42,12 @@
  13695.                 return;
  13696.             }
  13697.            
  13698. +           if (player._inEventTvT || player._inEventDM || player._inEventCTF)
  13699. +           {
  13700. +               player.sendMessage("You already participated in Event!");
  13701. +               return;
  13702. +           }
  13703. +
  13704.             if (player.reduceAdena("Broadcast", cost, this, true))
  13705.             {
  13706.                 player.enterObserverMode(x, y, z);
  13707. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminTvTEngine.java
  13708. ===================================================================
  13709. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminTvTEngine.java (revision 0)
  13710. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminTvTEngine.java (working copy)
  13711. @@ -0,0 +1,364 @@
  13712. +/*
  13713. + * This program is free software: you can redistribute it and/or modify it under
  13714. + * the terms of the GNU General Public License as published by the Free Software
  13715. + * Foundation, either version 3 of the License, or (at your option) any later
  13716. + * version.
  13717. + *
  13718. + * This program is distributed in the hope that it will be useful, but WITHOUT
  13719. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13720. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  13721. + * details.
  13722. + *
  13723. + * You should have received a copy of the GNU General Public License along with
  13724. + * this program. If not, see <http://www.gnu.org/licenses/>.
  13725. + */
  13726. +package net.sf.l2j.gameserver.handler.admincommandhandlers;
  13727. +
  13728. +/**
  13729. + * @author: FBIagent / fixed by SqueezeD
  13730. + */
  13731. +import java.util.StringTokenizer;
  13732. +
  13733. +import net.sf.l2j.Config;
  13734. +import net.sf.l2j.commons.concurrent.ThreadPool;
  13735. +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  13736. +import net.sf.l2j.gameserver.model.World;
  13737. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  13738. +import net.sf.l2j.gameserver.model.entity.engine.TvT;
  13739. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  13740. +import net.sf.l2j.gameserver.util.Util;
  13741. +
  13742. +public class AdminTvTEngine implements IAdminCommandHandler
  13743. +{
  13744. +   private static final String[] ADMIN_COMMANDS =
  13745. +   {/** @formatter:off */
  13746. +       "admin_tvt",
  13747. +       "admin_tvt_name",
  13748. +       "admin_tvt_desc",
  13749. +       "admin_tvt_join_loc",
  13750. +       "admin_tvt_minlvl",
  13751. +       "admin_tvt_maxlvl",
  13752. +       "admin_tvt_npc",
  13753. +       "admin_tvt_npc_pos",
  13754. +       "admin_tvt_reward",
  13755. +       "admin_tvt_reward_amount",
  13756. +       "admin_tvt_team_add",
  13757. +       "admin_tvt_team_remove",
  13758. +       "admin_tvt_team_pos",
  13759. +       "admin_tvt_team_color",
  13760. +       "admin_tvt_join",
  13761. +       "admin_tvt_teleport",
  13762. +       "admin_tvt_start",
  13763. +       "admin_tvt_abort",
  13764. +       "admin_tvt_finish",
  13765. +       "admin_tvt_sit",
  13766. +       "admin_tvt_dump",
  13767. +       "admin_tvt_save",
  13768. +       "admin_tvt_load",
  13769. +       "admin_tvt_jointime",
  13770. +       "admin_tvt_eventtime",
  13771. +       "admin_tvt_autoevent",
  13772. +       "admin_tvt_minplayers",
  13773. +       "admin_tvt_maxplayers",
  13774. +       "admin_tvtkick",
  13775. +   };/** @formatter:on */
  13776. +
  13777. +   @Override
  13778. +   public boolean useAdminCommand(String command, Player activeChar)
  13779. +   {
  13780. +       if (command.equals("admin_tvt"))
  13781. +           showMainPage(activeChar);
  13782. +       else if (command.startsWith("admin_tvt_name "))
  13783. +       {
  13784. +           TvT._eventName = command.substring(15);
  13785. +           showMainPage(activeChar);
  13786. +       }
  13787. +       else if (command.startsWith("admin_tvt_desc "))
  13788. +       {
  13789. +           TvT._eventDesc = command.substring(15);
  13790. +           showMainPage(activeChar);
  13791. +       }
  13792. +       else if (command.startsWith("admin_tvt_minlvl "))
  13793. +       {
  13794. +           if (!TvT.checkMinLevel(Integer.valueOf(command.substring(17))))
  13795. +               return false;
  13796. +           TvT._minlvl = Integer.valueOf(command.substring(17));
  13797. +           showMainPage(activeChar);
  13798. +       }
  13799. +       else if (command.startsWith("admin_tvt_maxlvl "))
  13800. +       {
  13801. +           if (!TvT.checkMaxLevel(Integer.valueOf(command.substring(17))))
  13802. +               return false;
  13803. +           TvT._maxlvl = Integer.valueOf(command.substring(17));
  13804. +           showMainPage(activeChar);
  13805. +       }
  13806. +       else if (command.startsWith("admin_tvt_minplayers "))
  13807. +       {
  13808. +           TvT._minPlayers = Integer.valueOf(command.substring(21));
  13809. +           showMainPage(activeChar);
  13810. +       }
  13811. +       else if (command.startsWith("admin_tvt_maxplayers "))
  13812. +       {
  13813. +           TvT._maxPlayers = Integer.valueOf(command.substring(21));
  13814. +           showMainPage(activeChar);
  13815. +       }
  13816. +       else if (command.startsWith("admin_tvt_join_loc "))
  13817. +       {
  13818. +           TvT._joiningLocationName = command.substring(19);
  13819. +           showMainPage(activeChar);
  13820. +       }
  13821. +       else if (command.startsWith("admin_tvt_npc "))
  13822. +       {
  13823. +           TvT._npcId = Integer.valueOf(command.substring(14));
  13824. +           showMainPage(activeChar);
  13825. +       }
  13826. +       else if (command.equals("admin_tvt_npc_pos"))
  13827. +       {
  13828. +           TvT.setNpcPos(activeChar);
  13829. +           showMainPage(activeChar);
  13830. +       }
  13831. +       else if (command.startsWith("admin_tvt_reward "))
  13832. +       {
  13833. +           TvT._rewardId = Integer.valueOf(command.substring(17));
  13834. +           showMainPage(activeChar);
  13835. +       }
  13836. +       else if (command.startsWith("admin_tvt_reward_amount "))
  13837. +       {
  13838. +           TvT._rewardAmount = Integer.valueOf(command.substring(24));
  13839. +           showMainPage(activeChar);
  13840. +       }
  13841. +       else if (command.startsWith("admin_tvt_jointime "))
  13842. +       {
  13843. +           TvT._joinTime = Integer.valueOf(command.substring(19));
  13844. +           showMainPage(activeChar);
  13845. +       }
  13846. +       else if (command.startsWith("admin_tvt_eventtime "))
  13847. +       {
  13848. +           TvT._eventTime = Integer.valueOf(command.substring(20));
  13849. +           showMainPage(activeChar);
  13850. +       }
  13851. +       else if (command.startsWith("admin_tvt_team_add "))
  13852. +       {
  13853. +           String teamName = command.substring(19);
  13854. +
  13855. +           TvT.addTeam(teamName);
  13856. +           showMainPage(activeChar);
  13857. +       }
  13858. +       else if (command.startsWith("admin_tvt_team_remove "))
  13859. +       {
  13860. +           String teamName = command.substring(22);
  13861. +
  13862. +           TvT.removeTeam(teamName);
  13863. +           showMainPage(activeChar);
  13864. +       }
  13865. +       else if (command.startsWith("admin_tvt_team_pos "))
  13866. +       {
  13867. +           String teamName = command.substring(19);
  13868. +
  13869. +           TvT.setTeamPos(teamName, activeChar);
  13870. +           showMainPage(activeChar);
  13871. +       }
  13872. +       else if (command.startsWith("admin_tvt_team_color "))
  13873. +       {
  13874. +           String[] params;
  13875. +
  13876. +           params = command.split(" ");
  13877. +
  13878. +           if (params.length != 3)
  13879. +           {
  13880. +               activeChar.sendMessage("Wrong usege: //tvt_team_color <colorHex> <teamName>");
  13881. +               return false;
  13882. +           }
  13883. +
  13884. +           TvT.setTeamColor(command.substring(params[0].length() + params[1].length() + 2), Integer.decode("0x" + Util.reverseColor(params[1])));
  13885. +           showMainPage(activeChar);
  13886. +       }
  13887. +       else if (command.equals("admin_tvt_join"))
  13888. +       {
  13889. +           TvT.startJoin(activeChar);
  13890. +           showMainPage(activeChar);
  13891. +       }
  13892. +       else if (command.equals("admin_tvt_teleport"))
  13893. +       {
  13894. +           TvT.teleportStart();
  13895. +           showMainPage(activeChar);
  13896. +       }
  13897. +       else if (command.equals("admin_tvt_start"))
  13898. +       {
  13899. +           TvT.startEvent(activeChar);
  13900. +           showMainPage(activeChar);
  13901. +       }
  13902. +       else if (command.equals("admin_tvt_abort"))
  13903. +       {
  13904. +           activeChar.sendMessage("Aborting event");
  13905. +           TvT.abortEvent();
  13906. +           showMainPage(activeChar);
  13907. +       }
  13908. +       else if (command.equals("admin_tvt_finish"))
  13909. +       {
  13910. +           TvT.finishEvent();
  13911. +           showMainPage(activeChar);
  13912. +       }
  13913. +       else if (command.equals("admin_tvt_sit"))
  13914. +       {
  13915. +           TvT.sit();
  13916. +           showMainPage(activeChar);
  13917. +       }
  13918. +       else if (command.equals("admin_tvt_load"))
  13919. +       {
  13920. +           TvT.loadData();
  13921. +           showMainPage(activeChar);
  13922. +       }
  13923. +       else if (command.equals("admin_tvt_autoevent"))
  13924. +       {
  13925. +           if (TvT._joinTime > 0 && TvT._eventTime > 0)
  13926. +               ThreadPool.schedule(new Runnable()
  13927. +               {
  13928. +                   @Override
  13929. +                   public void run()
  13930. +                   {
  13931. +                       TvT.autoEvent();
  13932. +                   }
  13933. +               }, 0);
  13934. +           else
  13935. +               activeChar.sendMessage("Wrong usege: join time or event time invallid.");
  13936. +           showMainPage(activeChar);
  13937. +       }
  13938. +       else if (command.equals("admin_tvt_save"))
  13939. +       {
  13940. +           TvT.saveData();
  13941. +           showMainPage(activeChar);
  13942. +       }
  13943. +       else if (command.equals("admin_tvt_dump"))
  13944. +           TvT.dumpData();
  13945. +       else if (command.startsWith("admin_tvtkick"))
  13946. +       {
  13947. +           StringTokenizer st = new StringTokenizer(command);
  13948. +           if (st.countTokens() > 1)
  13949. +           {
  13950. +               st.nextToken();
  13951. +               String plyr = st.nextToken();
  13952. +               Player playerToKick = World.getInstance().getPlayer(plyr);
  13953. +               if (playerToKick != null)
  13954. +               {
  13955. +                   TvT.kickPlayerFromTvt(playerToKick);
  13956. +                   activeChar.sendMessage("You kicked " + playerToKick.getName() + " from the TvT.");
  13957. +               }
  13958. +               else
  13959. +                   activeChar.sendMessage("Wrong usege: //tvtkick <player>");
  13960. +           }
  13961. +       }
  13962. +       return true;
  13963. +   }
  13964. +
  13965. +   @Override
  13966. +   public String[] getAdminCommandList()
  13967. +   {
  13968. +       return ADMIN_COMMANDS;
  13969. +   }
  13970. +
  13971. +   public void showMainPage(Player activeChar)
  13972. +   {
  13973. +       NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  13974. +       StringBuilder replyMSG = new StringBuilder("<html><body>");
  13975. +
  13976. +       replyMSG.append("<center><font color=\"LEVEL\">[TvT Engine]</font></center><br><br><br>");
  13977. +       replyMSG.append("<table><tr><td><edit var=\"input1\" width=\"125\"></td><td><edit var=\"input2\" width=\"125\"></td></tr></table>");
  13978. +       replyMSG.append("<table border=\"0\"><tr>");
  13979. +       replyMSG.append("<td width=\"100\"><button value=\"Name\" action=\"bypass -h admin_tvt_name $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13980. +       replyMSG.append("<td width=\"100\"><button value=\"Description\" action=\"bypass -h admin_tvt_desc $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13981. +       replyMSG.append("<td width=\"100\"><button value=\"Join Location\" action=\"bypass -h admin_tvt_join_loc $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13982. +       replyMSG.append("</tr></table><br><table><tr>");
  13983. +       replyMSG.append("</tr></table><br><table><tr>");
  13984. +       replyMSG.append("<td width=\"100\"><button value=\"Max lvl\" action=\"bypass -h admin_tvt_maxlvl $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13985. +       replyMSG.append("<td width=\"100\"><button value=\"Min lvl\" action=\"bypass -h admin_tvt_minlvl $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13986. +       replyMSG.append("</tr></table><br><table><tr>");
  13987. +       replyMSG.append("</tr></table><br><table><tr>");
  13988. +       replyMSG.append("<td width=\"100\"><button value=\"Max players\" action=\"bypass -h admin_tvt_maxplayers $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13989. +       replyMSG.append("<td width=\"100\"><button value=\"Min players\" action=\"bypass -h admin_tvt_minplayers $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13990. +       replyMSG.append("</tr></table><br><table><tr>");
  13991. +       replyMSG.append("<td width=\"100\"><button value=\"NPC\" action=\"bypass -h admin_tvt_npc $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13992. +       replyMSG.append("<td width=\"100\"><button value=\"NPC Pos\" action=\"bypass -h admin_tvt_npc_pos\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13993. +       replyMSG.append("</tr></table><br><table><tr>");
  13994. +       replyMSG.append("<td width=\"100\"><button value=\"Reward\" action=\"bypass -h admin_tvt_reward $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13995. +       replyMSG.append("<td width=\"100\"><button value=\"Reward Amount\" action=\"bypass -h admin_tvt_reward_amount $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13996. +       replyMSG.append("</tr></table><br><table><tr>");
  13997. +       replyMSG.append("<td width=\"100\"><button value=\"Join Time\" action=\"bypass -h admin_tvt_jointime $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13998. +       replyMSG.append("<td width=\"100\"><button value=\"Event Time\" action=\"bypass -h admin_tvt_eventtime $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  13999. +       replyMSG.append("</tr></table><br><table><tr>");
  14000. +       replyMSG.append("<td width=\"100\"><button value=\"Team Add\" action=\"bypass -h admin_tvt_team_add $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14001. +       replyMSG.append("<td width=\"100\"><button value=\"Team Color\" action=\"bypass -h admin_tvt_team_color $input1 $input2\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14002. +       replyMSG.append("<td width=\"100\"><button value=\"Team Pos\" action=\"bypass -h admin_tvt_team_pos $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14003. +       replyMSG.append("</tr></table><table><tr>");
  14004. +       replyMSG.append("<td width=\"100\"><button value=\"Team Remove\" action=\"bypass -h admin_tvt_team_remove $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14005. +       replyMSG.append("</tr></table><br><table><tr>");
  14006. +       replyMSG.append("<td width=\"100\"><button value=\"Join\" action=\"bypass -h admin_tvt_join\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14007. +       replyMSG.append("<td width=\"100\"><button value=\"Teleport\" action=\"bypass -h admin_tvt_teleport\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14008. +       replyMSG.append("<td width=\"100\"><button value=\"Start\" action=\"bypass -h admin_tvt_start\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14009. +       replyMSG.append("</tr></table><table><tr>");
  14010. +       replyMSG.append("<td width=\"100\"><button value=\"Abort\" action=\"bypass -h admin_tvt_abort\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14011. +       replyMSG.append("<td width=\"100\"><button value=\"Finish\" action=\"bypass -h admin_tvt_finish\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14012. +       // L2EMU_ADD
  14013. +       replyMSG.append("</tr></table><br><table><tr>");
  14014. +       replyMSG.append("<td width=\"100\"><button value=\"Sit Force\" action=\"bypass -h admin_tvt_sit\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14015. +       replyMSG.append("<td width=\"100\"><button value=\"Dump\" action=\"bypass -h admin_tvt_dump\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14016. +       replyMSG.append("</tr></table><br><br><table><tr>");
  14017. +       replyMSG.append("<td width=\"100\"><button value=\"Save\" action=\"bypass -h admin_tvt_save\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14018. +       replyMSG.append("<td width=\"100\"><button value=\"Load\" action=\"bypass -h admin_tvt_load\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14019. +       replyMSG.append("<td width=\"100\"><button value=\"Auto Event\" action=\"bypass -h admin_tvt_autoevent\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  14020. +       replyMSG.append("</tr></table><br><br>");
  14021. +       replyMSG.append("Current event...<br1>");
  14022. +       // L2EMU_ADD
  14023. +       replyMSG.append("    ... Event Type:&nbsp;<font color=\"00FF00\">" + TvT.getEventTypeByName(TvT._eventType) + "</font><br1>");
  14024. +       // L2EMU_ADD
  14025. +       replyMSG.append("    ... name:&nbsp;<font color=\"00FF00\">" + TvT._eventName + "</font><br1>");
  14026. +       replyMSG.append("    ... description:&nbsp;<font color=\"00FF00\">" + TvT._eventDesc + "</font><br1>");
  14027. +       replyMSG.append("    ... joining location name:&nbsp;<font color=\"00FF00\">" + TvT._joiningLocationName + "</font><br1>");
  14028. +       replyMSG.append("    ... joining NPC ID:&nbsp;<font color=\"00FF00\">" + TvT._npcId + " on pos " + TvT._npcX + "," + TvT._npcY + "," + TvT._npcZ + "</font><br1>");
  14029. +       replyMSG.append("    ... reward ID:&nbsp;<font color=\"00FF00\">" + TvT._rewardId + "</font><br1>");
  14030. +       replyMSG.append("    ... reward Amount:&nbsp;<font color=\"00FF00\">" + TvT._rewardAmount + "</font><br><br>");
  14031. +       replyMSG.append("    ... Min lvl:&nbsp;<font color=\"00FF00\">" + TvT._minlvl + "</font><br>");
  14032. +       replyMSG.append("    ... Max lvl:&nbsp;<font color=\"00FF00\">" + TvT._maxlvl + "</font><br><br>");
  14033. +       replyMSG.append("    ... Min Players:&nbsp;<font color=\"00FF00\">" + TvT._minPlayers + "</font><br>");
  14034. +       replyMSG.append("    ... Max Players:&nbsp;<font color=\"00FF00\">" + TvT._maxPlayers + "</font><br><br>");
  14035. +       replyMSG.append("    ... Joining Time:&nbsp;<font color=\"00FF00\">" + TvT._joinTime + "</font><br>");
  14036. +       replyMSG.append("    ... Event Timer:&nbsp;<font color=\"00FF00\">" + TvT._eventTime + "</font><br><br>");
  14037. +       replyMSG.append("Current teams:<br1>");
  14038. +       replyMSG.append("<center><table border=\"0\">");
  14039. +
  14040. +       for (String team : TvT._teams)
  14041. +       {
  14042. +           replyMSG.append("<tr><td width=\"100\"><font color=\"LEVEL\">" + team + "</font>");
  14043. +
  14044. +           if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE"))
  14045. +               replyMSG.append("&nbsp;(" + TvT.teamPlayersCount(team) + " joined)");
  14046. +           else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  14047. +           {
  14048. +               if (TvT._teleport || TvT._started)
  14049. +                   replyMSG.append("&nbsp;(" + TvT.teamPlayersCount(team) + " in)");
  14050. +           }
  14051. +
  14052. +           replyMSG.append("</td></tr><tr><td>");
  14053. +           replyMSG.append(TvT._teamColors.get(TvT._teams.indexOf(team)));
  14054. +           replyMSG.append("</td></tr><tr><td>");
  14055. +           replyMSG.append(TvT._teamsX.get(TvT._teams.indexOf(team)) + ", " + TvT._teamsY.get(TvT._teams.indexOf(team)) + ", " + TvT._teamsZ.get(TvT._teams.indexOf(team)));
  14056. +           replyMSG.append("</td></tr><tr><td width=\"60\"><button value=\"Remove\" action=\"bypass -h admin_tvt_team_remove " + team + "\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  14057. +       }
  14058. +
  14059. +       replyMSG.append("</table></center>");
  14060. +
  14061. +       if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
  14062. +       {
  14063. +           if (!TvT._started)
  14064. +           {
  14065. +               replyMSG.append("<br1>");
  14066. +               replyMSG.append(TvT._playersShuffle.size() + " players participating. Waiting to shuffle in teams(done on teleport)!");
  14067. +               replyMSG.append("<br><br>");
  14068. +           }
  14069. +       }
  14070. +
  14071. +       replyMSG.append("</body></html>");
  14072. +       adminReply.setHtml(replyMSG.toString());
  14073. +       activeChar.sendPacket(adminReply);
  14074. +   }
  14075. +}
  14076. \ No newline at end of file
  14077. #P Datapack
  14078. Index: data/xml/admin_commands_rights.xml
  14079. ===================================================================
  14080. --- data/xml/admin_commands_rights.xml  (revision 1)
  14081. +++ data/xml/admin_commands_rights.xml  (working copy)
  14082. @@ -344,5 +344,119 @@
  14083.     <!-- ZONE -->
  14084.     <aCar name="admin_zone_check" accessLevel="1" />
  14085.     <aCar name="admin_zone_visual" accessLevel="1" />
  14086. +   <!-- ADMIN EVENT ENGINE -->
  14087. +   <aCar name="admin_event" accessLevel="1" />
  14088. +   <aCar name="admin_event_new" accessLevel="1" />
  14089. +   <aCar name="admin_event_choose" accessLevel="1" />
  14090. +   <aCar name="admin_event_store" accessLevel="1" />
  14091. +   <aCar name="admin_event_set" accessLevel="1" />
  14092. +   <aCar name="admin_event_change_teams_number" accessLevel="1" />
  14093. +   <aCar name="admin_event_announce" accessLevel="1" />
  14094. +   <aCar name="admin_event_panel" accessLevel="1" />
  14095. +   <aCar name="admin_event_control_begin" accessLevel="1" />
  14096. +   <aCar name="admin_event_control_teleport" accessLevel="1" />
  14097. +   <aCar name="admin_add" accessLevel="1" />
  14098. +   <aCar name="admin_event_see" accessLevel="1" />
  14099. +   <aCar name="admin_event_del" accessLevel="1" />
  14100. +   <aCar name="admin_delete_buffer" accessLevel="1" />
  14101. +   <aCar name="admin_event_control_sit" accessLevel="1" />
  14102. +   <aCar name="admin_event_name" accessLevel="1" />
  14103. +   <aCar name="admin_event_control_kill" accessLevel="1" />
  14104. +   <aCar name="admin_event_control_res" accessLevel="1" />
  14105. +   <aCar name="admin_event_control_poly" accessLevel="1" />
  14106. +   <aCar name="admin_event_control_unpoly" accessLevel="1" />
  14107. +   <aCar name="admin_event_control_prize" accessLevel="1" />
  14108. +   <aCar name="admin_event_control_chatban" accessLevel="1" />
  14109. +   <aCar name="admin_event_control_finish" accessLevel="1" />
  14110. +
  14111. +   <!-- ADMIN TvT Event -->
  14112. +   <aCar name="admin_tvt" accessLevel="1" />
  14113. +   <aCar name="admin_tvt_name" accessLevel="1" />
  14114. +   <aCar name="admin_tvt_desc" accessLevel="1" />
  14115. +   <aCar name="admin_tvt_join_loc" accessLevel="1" />
  14116. +   <aCar name="admin_tvt_minlvl" accessLevel="1" />
  14117. +   <aCar name="admin_tvt_maxlvl" accessLevel="1" />
  14118. +   <aCar name="admin_tvt_npc" accessLevel="1" />
  14119. +   <aCar name="admin_tvt_npc_pos" accessLevel="1" />
  14120. +   <aCar name="admin_tvt_reward" accessLevel="1" />
  14121. +   <aCar name="admin_tvt_reward_amount" accessLevel="1" />
  14122. +   <aCar name="admin_tvt_team_add" accessLevel="1" />
  14123. +   <aCar name="admin_tvt_team_remove" accessLevel="1" />
  14124. +   <aCar name="admin_tvt_team_pos" accessLevel="1" />
  14125. +   <aCar name="admin_tvt_team_color" accessLevel="1" />
  14126. +   <aCar name="admin_tvt_join" accessLevel="1" />
  14127. +   <aCar name="admin_tvt_teleport" accessLevel="1" />
  14128. +   <aCar name="admin_tvt_start" accessLevel="1" />
  14129. +   <aCar name="admin_tvt_abort" accessLevel="1" />
  14130. +   <aCar name="admin_tvt_finish" accessLevel="1" />
  14131. +   <aCar name="admin_tvt_sit" accessLevel="1" />
  14132. +   <aCar name="admin_tvt_dump" accessLevel="1" />
  14133. +   <aCar name="admin_tvt_save" accessLevel="1" />
  14134. +   <aCar name="admin_tvt_load" accessLevel="1" />
  14135. +   <aCar name="admin_tvt_jointime" accessLevel="1" />
  14136. +   <aCar name="admin_tvt_eventtime" accessLevel="1" />
  14137. +   <aCar name="admin_tvt_autoevent" accessLevel="1" />
  14138. +   <aCar name="admin_tvt_minplayers" accessLevel="1" />
  14139. +   <aCar name="admin_tvt_maxplayers" accessLevel="1" />
  14140. +   <aCar name="admin_tvtkick" accessLevel="1" />
  14141. +   <aCar name="admin_tvt_interval" accessLevel="1" />
  14142.    
  14143. +   <!-- ADMIN CTF Event -->
  14144. +   <aCar name="admin_ctf" accessLevel="1" />
  14145. +   <aCar name="admin_ctf_name" accessLevel="1" />
  14146. +   <aCar name="admin_ctf_desc" accessLevel="1" />
  14147. +   <aCar name="admin_ctf_join_loc" accessLevel="1" />
  14148. +   <aCar name="admin_ctf_edit" accessLevel="1" />
  14149. +   <aCar name="admin_ctf_control" accessLevel="1" />
  14150. +   <aCar name="admin_ctf_minlvl" accessLevel="1" />
  14151. +   <aCar name="admin_ctf_maxlvl" accessLevel="1" />
  14152. +   <aCar name="admin_ctf_tele_npc" accessLevel="1" />
  14153. +   <aCar name="admin_ctf_tele_team" accessLevel="1" />
  14154. +   <aCar name="admin_ctf_tele_flag" accessLevel="1" />
  14155. +   <aCar name="admin_ctf_npc" accessLevel="1" />
  14156. +   <aCar name="admin_ctf_npc_pos" accessLevel="1" />
  14157. +   <aCar name="admin_ctf_reward" accessLevel="1" />
  14158. +   <aCar name="admin_ctf_reward_amount" accessLevel="1" />
  14159. +   <aCar name="admin_ctf_team_add" accessLevel="1" />
  14160. +   <aCar name="admin_ctf_team_remove" accessLevel="1" />
  14161. +   <aCar name="admin_ctf_team_pos" accessLevel="1" />
  14162. +   <aCar name="admin_ctf_team_color" accessLevel="1" />
  14163. +   <aCar name="admin_ctf_team_flag" accessLevel="1" />
  14164. +   <aCar name="admin_ctf_join" accessLevel="1" />
  14165. +   <aCar name="admin_ctf_teleport" accessLevel="1" />
  14166. +   <aCar name="admin_ctf_start" accessLevel="1" />
  14167. +   <aCar name="admin_ctf_abort" accessLevel="1" />
  14168. +   <aCar name="admin_ctf_finish" accessLevel="1" />
  14169. +   <aCar name="admin_ctf_sit" accessLevel="1" />
  14170. +   <aCar name="admin_ctf_dump" accessLevel="1" />
  14171. +   <aCar name="admin_ctf_save" accessLevel="1" />
  14172. +   <aCar name="admin_ctf_load" accessLevel="1" />
  14173. +   <aCar name="admin_ctf_jointime" accessLevel="1" />
  14174. +   <aCar name="admin_ctf_eventtime" accessLevel="1" />
  14175. +   <aCar name="admin_ctf_autoevent" accessLevel="1" />
  14176. +   <aCar name="admin_ctf_minplayers" accessLevel="1" />
  14177. +   <aCar name="admin_ctf_maxplayers" accessLevel="1" />
  14178. +  
  14179. +   <!-- ADMIN DM Event -->
  14180. +   <aCar name="admin_dmevent" accessLevel="1" />
  14181. +   <aCar name="admin_dmevent_name" accessLevel="1" />
  14182. +   <aCar name="admin_dmevent_desc" accessLevel="1" />
  14183. +   <aCar name="admin_dmevent_join_loc" accessLevel="1" />
  14184. +   <aCar name="admin_dmevent_minlvl" accessLevel="1" />
  14185. +   <aCar name="admin_dmevent_maxlvl" accessLevel="1" />
  14186. +   <aCar name="admin_dmevent_npc" accessLevel="1" />
  14187. +   <aCar name="admin_dmevent_npc_pos" accessLevel="1" />
  14188. +   <aCar name="admin_dmevent_reward" accessLevel="1" />
  14189. +   <aCar name="admin_dmevent_reward_amount" accessLevel="1" />
  14190. +   <aCar name="admin_dmevent_spawnpos" accessLevel="1" />
  14191. +   <aCar name="admin_dmevent_color" accessLevel="1" />
  14192. +   <aCar name="admin_dmevent_join" accessLevel="1" />
  14193. +   <aCar name="admin_dmevent_teleport" accessLevel="1" />
  14194. +   <aCar name="admin_dmevent_start" accessLevel="1" />
  14195. +   <aCar name="admin_dmevent_abort" accessLevel="1" />
  14196. +   <aCar name="admin_dmevent_finish" accessLevel="1" />
  14197. +   <aCar name="admin_dmevent_sit" accessLevel="1" />
  14198. +   <aCar name="admin_dmevent_dump" accessLevel="1" />
  14199. +   <aCar name="admin_dmevent_save" accessLevel="1" />
  14200. +   <aCar name="admin_dmevent_load" accessLevel="1" />
  14201.  </list>
  14202. \ No newline at end of file
  14203. Index: sql/tvt_teams.sql
  14204. ===================================================================
  14205. --- sql/tvt_teams.sql   (revision 0)
  14206. +++ sql/tvt_teams.sql   (working copy)
  14207. @@ -0,0 +1,22 @@
  14208. +SET FOREIGN_KEY_CHECKS=0;
  14209. +-- ----------------------------
  14210. +-- Table structure for `tvt_teams`
  14211. +-- -----------------------------
  14212. +
  14213. +CREATE TABLE `tvt_teams` (
  14214. +  `teamId` int(4) NOT NULL DEFAULT '0',
  14215. +  `teamName` varchar(255) NOT NULL DEFAULT '',
  14216. +  `teamX` int(11) NOT NULL DEFAULT '0',
  14217. +  `teamY` int(11) NOT NULL DEFAULT '0',
  14218. +  `teamZ` int(11) NOT NULL DEFAULT '0',
  14219. +  `teamColor` int(11) NOT NULL DEFAULT '0',
  14220. +  PRIMARY KEY (`teamId`)
  14221. +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPRESSED COMMENT='L2jHellas Table';
  14222. +
  14223. +-- ----------------------------
  14224. +-- Records of `tvt_teams`
  14225. +-- ----------------------------
  14226. +INSERT INTO `tvt_teams` VALUES
  14227. +('0', 'Wolfs', '148179', '45841', '-3413', '16711680'),
  14228. +('1', 'Beasts', '150787', '45822', '-3413', '255'),
  14229. +('2', 'Vampires', '149496', '47826', '-3413', '26367');
  14230. \ No newline at end of file
  14231. Index: sql/ctf.sql
  14232. ===================================================================
  14233. --- sql/ctf.sql (revision 0)
  14234. +++ sql/ctf.sql (working copy)
  14235. @@ -0,0 +1,24 @@
  14236. +SET FOREIGN_KEY_CHECKS=0;
  14237. +-- ----------------------------
  14238. +-- Table structure for `ctf`
  14239. +-- ----------------------------
  14240. +
  14241. +CREATE TABLE `ctf` (
  14242. +  `eventName` varchar(255) NOT NULL DEFAULT '',
  14243. +  `eventDesc` varchar(255) NOT NULL DEFAULT '',
  14244. +  `joiningLocation` varchar(255) NOT NULL DEFAULT '',
  14245. +  `minlvl` int(4) NOT NULL DEFAULT '0',
  14246. +  `maxlvl` int(4) NOT NULL DEFAULT '0',
  14247. +  `npcId` int(11) NOT NULL DEFAULT '0',
  14248. +  `npcX` int(11) NOT NULL DEFAULT '0',
  14249. +  `npcY` int(11) NOT NULL DEFAULT '0',
  14250. +  `npcZ` int(11) NOT NULL DEFAULT '0',
  14251. +  `npcHeading` int(11) NOT NULL DEFAULT '0',
  14252. +  `rewardId` int(11) NOT NULL DEFAULT '0',
  14253. +  `rewardAmount` int(11) NOT NULL DEFAULT '0',
  14254. +  `teamsCount` int(4) NOT NULL DEFAULT '0',
  14255. +  `joinTime` int(11) NOT NULL DEFAULT '0',
  14256. +  `eventTime` int(11) NOT NULL DEFAULT '0',
  14257. +  `minPlayers` int(4) NOT NULL DEFAULT '0',
  14258. +  `maxPlayers` int(4) NOT NULL DEFAULT '0'
  14259. +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPRESSED COMMENT='L2jHellas Table';
  14260. \ No newline at end of file
  14261. Index: data/xml/npcs/50000-50999.xml
  14262. ===================================================================
  14263. --- data/xml/npcs/50000-50999.xml   (revision 2)
  14264. +++ data/xml/npcs/50000-50999.xml   (working copy)
  14265. @@ -175,4 +175,109 @@
  14266.         <set name="attackRange" val="40"/>
  14267.         <ai type="DEFAULT" ssCount="0" ssRate="0" spsCount="0" spsRate="0" aggro="0" canMove="true" seedable="false"/>
  14268.     </npc>
  14269. +   <npc id="50011" idTemplate="31309" name="Aioria" title="TvT Manager">
  14270. +       <set name="level" val="70"/>
  14271. +       <set name="radius" val="8"/>
  14272. +       <set name="height" val="21.5"/>
  14273. +       <set name="rHand" val="0"/>
  14274. +       <set name="lHand" val="0"/>
  14275. +       <set name="type" val="Folk"/>
  14276. +       <set name="exp" val="0"/>
  14277. +       <set name="sp" val="0"/>
  14278. +       <set name="hp" val="2444.46819"/>
  14279. +       <set name="mp" val="1345.8"/>
  14280. +       <set name="hpRegen" val="7.5"/>
  14281. +       <set name="mpRegen" val="2.7"/>
  14282. +       <set name="pAtk" val="688.86373"/>
  14283. +       <set name="pDef" val="295.91597"/>
  14284. +       <set name="mAtk" val="470.40463"/>
  14285. +       <set name="mDef" val="216.53847"/>
  14286. +       <set name="crit" val="4"/>
  14287. +       <set name="atkSpd" val="253"/>
  14288. +       <set name="str" val="40"/>
  14289. +       <set name="int" val="21"/>
  14290. +       <set name="dex" val="30"/>
  14291. +       <set name="wit" val="20"/>
  14292. +       <set name="con" val="43"/>
  14293. +       <set name="men" val="20"/>
  14294. +       <set name="corpseTime" val="7"/>
  14295. +       <set name="walkSpd" val="50"/>
  14296. +       <set name="runSpd" val="120"/>
  14297. +       <set name="dropHerbGroup" val="0"/>
  14298. +       <ai type="DEFAULT" ssCount="0" ssRate="0" spsCount="0" spsRate="0" aggro="0" canMove="true" seedable="false"/>
  14299. +       <skills>
  14300. +           <skill id="4045" level="1"/>
  14301. +           <skill id="4416" level="14"/>
  14302. +       </skills>
  14303. +   </npc>
  14304. +   <npc id="50012" idTemplate="31309" name="Leon" title="CTF Manager">
  14305. +       <set name="level" val="70"/>
  14306. +       <set name="radius" val="8"/>
  14307. +       <set name="height" val="21.5"/>
  14308. +       <set name="rHand" val="0"/>
  14309. +       <set name="lHand" val="0"/>
  14310. +       <set name="type" val="Folk"/>
  14311. +       <set name="exp" val="0"/>
  14312. +       <set name="sp" val="0"/>
  14313. +       <set name="hp" val="2444.46819"/>
  14314. +       <set name="mp" val="1345.8"/>
  14315. +       <set name="hpRegen" val="7.5"/>
  14316. +       <set name="mpRegen" val="2.7"/>
  14317. +       <set name="pAtk" val="688.86373"/>
  14318. +       <set name="pDef" val="295.91597"/>
  14319. +       <set name="mAtk" val="470.40463"/>
  14320. +       <set name="mDef" val="216.53847"/>
  14321. +       <set name="crit" val="4"/>
  14322. +       <set name="atkSpd" val="253"/>
  14323. +       <set name="str" val="40"/>
  14324. +       <set name="int" val="21"/>
  14325. +       <set name="dex" val="30"/>
  14326. +       <set name="wit" val="20"/>
  14327. +       <set name="con" val="43"/>
  14328. +       <set name="men" val="20"/>
  14329. +       <set name="corpseTime" val="7"/>
  14330. +       <set name="walkSpd" val="50"/>
  14331. +       <set name="runSpd" val="120"/>
  14332. +       <set name="dropHerbGroup" val="0"/>
  14333. +       <ai type="DEFAULT" ssCount="0" ssRate="0" spsCount="0" spsRate="0" aggro="0" canMove="true" seedable="false"/>
  14334. +       <skills>
  14335. +           <skill id="4045" level="1"/>
  14336. +           <skill id="4416" level="14"/>
  14337. +       </skills>
  14338. +   </npc>
  14339. +   <npc id="50013" idTemplate="31309" name="Aioria" title="TvT Manager">
  14340. +       <set name="level" val="70"/>
  14341. +       <set name="radius" val="8"/>
  14342. +       <set name="height" val="21.5"/>
  14343. +       <set name="rHand" val="0"/>
  14344. +       <set name="lHand" val="0"/>
  14345. +       <set name="type" val="Folk"/>
  14346. +       <set name="exp" val="0"/>
  14347. +       <set name="sp" val="0"/>
  14348. +       <set name="hp" val="2444.46819"/>
  14349. +       <set name="mp" val="1345.8"/>
  14350. +       <set name="hpRegen" val="7.5"/>
  14351. +       <set name="mpRegen" val="2.7"/>
  14352. +       <set name="pAtk" val="688.86373"/>
  14353. +       <set name="pDef" val="295.91597"/>
  14354. +       <set name="mAtk" val="470.40463"/>
  14355. +       <set name="mDef" val="216.53847"/>
  14356. +       <set name="crit" val="4"/>
  14357. +       <set name="atkSpd" val="253"/>
  14358. +       <set name="str" val="40"/>
  14359. +       <set name="int" val="21"/>
  14360. +       <set name="dex" val="30"/>
  14361. +       <set name="wit" val="20"/>
  14362. +       <set name="con" val="43"/>
  14363. +       <set name="men" val="20"/>
  14364. +       <set name="corpseTime" val="7"/>
  14365. +       <set name="walkSpd" val="50"/>
  14366. +       <set name="runSpd" val="120"/>
  14367. +       <set name="dropHerbGroup" val="0"/>
  14368. +       <ai type="DEFAULT" ssCount="0" ssRate="0" spsCount="0" spsRate="0" aggro="0" canMove="true" seedable="false"/>
  14369. +       <skills>
  14370. +           <skill id="4045" level="1"/>
  14371. +           <skill id="4416" level="14"/>
  14372. +       </skills>
  14373. +   </npc>
  14374.  </list>
  14375. \ No newline at end of file
  14376. Index: sql/dm.sql
  14377. ===================================================================
  14378. --- sql/dm.sql  (revision 0)
  14379. +++ sql/dm.sql  (working copy)
  14380. @@ -0,0 +1,22 @@
  14381. +SET FOREIGN_KEY_CHECKS=0;
  14382. +-- ----------------------------
  14383. +-- Table structure for `dm`
  14384. +-- ----------------------------
  14385. +
  14386. +CREATE TABLE `dm` (
  14387. +  `eventName` varchar(255) NOT NULL DEFAULT '',
  14388. +  `eventDesc` varchar(255) NOT NULL DEFAULT '',
  14389. +  `joiningLocation` varchar(255) NOT NULL DEFAULT '',
  14390. +  `minlvl` int(4) NOT NULL DEFAULT '0',
  14391. +  `maxlvl` int(4) NOT NULL DEFAULT '0',
  14392. +  `npcId` int(8) NOT NULL DEFAULT '0',
  14393. +  `npcX` int(11) NOT NULL DEFAULT '0',
  14394. +  `npcY` int(11) NOT NULL DEFAULT '0',
  14395. +  `npcZ` int(11) NOT NULL DEFAULT '0',
  14396. +  `rewardId` int(11) NOT NULL DEFAULT '0',
  14397. +  `rewardAmount` int(11) NOT NULL DEFAULT '0',
  14398. +  `color` int(11) NOT NULL DEFAULT '0',
  14399. +  `playerX` int(11) NOT NULL DEFAULT '0',
  14400. +  `playerY` int(11) NOT NULL DEFAULT '0',
  14401. +  `playerZ` int(11) NOT NULL DEFAULT '0'
  14402. +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPRESSED COMMENT='L2jHellas Table';
  14403. \ No newline at end of file
  14404. Index: sql/tvt.sql
  14405. ===================================================================
  14406. --- sql/tvt.sql (revision 0)
  14407. +++ sql/tvt.sql (working copy)
  14408. @@ -0,0 +1,30 @@
  14409. +SET FOREIGN_KEY_CHECKS=0;
  14410. +-- ----------------------------
  14411. +-- Table structure for `tvt`
  14412. +-- ----------------------------
  14413. +
  14414. +CREATE TABLE `tvt` (
  14415. +  `eventName` varchar(255) NOT NULL DEFAULT '',
  14416. +  `eventDesc` varchar(255) NOT NULL DEFAULT '',
  14417. +  `joiningLocation` varchar(255) NOT NULL DEFAULT '',
  14418. +  `minlvl` int(4) NOT NULL DEFAULT '0',
  14419. +  `maxlvl` int(4) NOT NULL DEFAULT '0',
  14420. +  `npcId` int(8) NOT NULL DEFAULT '0',
  14421. +  `npcX` int(11) NOT NULL DEFAULT '0',
  14422. +  `npcY` int(11) NOT NULL DEFAULT '0',
  14423. +  `npcZ` int(11) NOT NULL DEFAULT '0',
  14424. +  `npcHeading` int(11) NOT NULL DEFAULT '0',
  14425. +  `rewardId` int(11) NOT NULL DEFAULT '0',
  14426. +  `rewardAmount` int(11) NOT NULL DEFAULT '0',
  14427. +  `teamsCount` int(4) NOT NULL DEFAULT '0',
  14428. +  `joinTime` int(11) NOT NULL DEFAULT '0',
  14429. +  `eventTime` int(11) NOT NULL DEFAULT '0',
  14430. +  `minPlayers` int(4) NOT NULL DEFAULT '0',
  14431. +  `maxPlayers` int(4) NOT NULL DEFAULT '0'
  14432. +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPRESSED COMMENT='L2jHellas Table';
  14433. +
  14434. +-- ----------------------------
  14435. +-- Records of `tvt`
  14436. +-- ----------------------------
  14437. +INSERT INTO `tvt` values
  14438. +('TVT', 'A PvP Event', 'Giran', 1, 81, 70010, 82688, 148677, -3469, 0, 57, 100000, 2, 5, 10, 2, 50);
  14439. \ No newline at end of file
  14440. Index: data/html/mods/Participation.htm
  14441. ===================================================================
  14442. --- data/html/mods/Participation.htm    (revision 0)
  14443. +++ data/html/mods/Participation.htm    (working copy)
  14444. @@ -0,0 +1,5 @@
  14445. +<html><body><br><center>
  14446. +Successfully, you have signed up in event!<br>
  14447. +Please wait till event starts!<br><br>
  14448. +<a action="bypass -h npc_%objectId%_Chat 0">Ok</a>
  14449. +</center></html></body>
  14450. \ No newline at end of file
  14451. Index: sql/ctf_teams.sql
  14452. ===================================================================
  14453. --- sql/ctf_teams.sql   (revision 0)
  14454. +++ sql/ctf_teams.sql   (working copy)
  14455. @@ -0,0 +1,17 @@
  14456. +SET FOREIGN_KEY_CHECKS=0;
  14457. +-- ----------------------------
  14458. +-- Table structure for `ctf_teams`
  14459. +-- ----------------------------
  14460. +
  14461. +CREATE TABLE `ctf_teams` (
  14462. +  `teamId` int(4) NOT NULL DEFAULT '0',
  14463. +  `teamName` varchar(255) NOT NULL DEFAULT '',
  14464. +  `teamX` int(11) NOT NULL DEFAULT '0',
  14465. +  `teamY` int(11) NOT NULL DEFAULT '0',
  14466. +  `teamZ` int(11) NOT NULL DEFAULT '0',
  14467. +  `teamColor` int(11) NOT NULL DEFAULT '0',
  14468. +  `flagX` int(11) NOT NULL DEFAULT '0',
  14469. +  `flagY` int(11) NOT NULL DEFAULT '0',
  14470. +  `flagZ` int(11) NOT NULL DEFAULT '0',
  14471. +  PRIMARY KEY (`teamId`)
  14472. +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPRESSED COMMENT='L2jHellas Table';
  14473. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement