BossForever

CTF Hi5

Apr 30th, 2013
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 160.94 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P Datapack
  3. Index: dist/sql/game/ctf_teams.sql
  4. ===================================================================
  5. --- dist/sql/game/ctf_teams.sql (revision 0)
  6. +++ dist/sql/game/ctf_teams.sql (working copy)
  7. @@ -0,0 +1,19 @@
  8. +CREATE TABLE IF NOT EXISTS `ctf_teams` (
  9. +  `teamId` int(4) NOT NULL DEFAULT '0',
  10. +  `teamName` varchar(255) NOT NULL DEFAULT '',
  11. +  `teamX` int(11) NOT NULL DEFAULT '0',
  12. +  `teamY` int(11) NOT NULL DEFAULT '0',
  13. +  `teamZ` int(11) NOT NULL DEFAULT '0',
  14. +  `teamColor` int(11) NOT NULL DEFAULT '0',
  15. +  `flagX` int(11) NOT NULL DEFAULT '0',
  16. +  `flagY` int(11) NOT NULL DEFAULT '0',
  17. +  `flagZ` int(11) NOT NULL DEFAULT '0',
  18. +  `teamBaseX` int(11) NOT NULL DEFAULT '0',
  19. +  `teamBaseY` int(11) NOT NULL DEFAULT '0',
  20. +  `teamBaseZ` int(11) NOT NULL DEFAULT '0',
  21. +  PRIMARY KEY (`teamId`)
  22. +) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  23. +
  24. +INSERT INTO `ctf_teams` (`teamId`, `teamName`, `teamX`, `teamY`, `teamZ`, `teamColor`, `flagX`, `flagY`, `flagZ`, `teamBaseX`, `teamBaseY`, `teamBaseZ`) VALUES
  25. +(1, 'Blue', -6238, 246661, -1901, 255, -3986, 246678, -1916, 0, 0, 0),
  26. +(0, 'Red', -7443, 241418, -1900, 16711680, -8696, 242454, -1875, 0, 0, 0);
  27. \ No newline at end of file
  28. Index: dist/game/data/scripts/handlers/voicedcommandhandlers/CTFCmd.java
  29. ===================================================================
  30. --- dist/game/data/scripts/handlers/voicedcommandhandlers/CTFCmd.java   (revision 0)
  31. +++ dist/game/data/scripts/handlers/voicedcommandhandlers/CTFCmd.java   (working copy)
  32. @@ -0,0 +1,158 @@
  33. +package handlers.voicedcommandhandlers;
  34. +
  35. +import l2jcrimmerproject.gameserver.handler.IVoicedCommandHandler;
  36. +import l2jcrimmerproject.gameserver.model.actor.instance.L2PcInstance;
  37. +import l2jcrimmerproject.gameserver.model.entity.CTF;
  38. +import l2jcrimmerproject.gameserver.network.serverpackets.NpcHtmlMessage;
  39. +
  40. +public class CTFCmd implements IVoicedCommandHandler
  41. +{
  42. +   private static final String[] VOICED_COMMANDS =
  43. +   {
  44. +       "joinctf",
  45. +       "leavectf",
  46. +       "infoctf"
  47. +   };
  48. +  
  49. +   @Override
  50. +   public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
  51. +   {
  52. +       if (command.startsWith("joinctf"))
  53. +       {
  54. +           JoinCTF(activeChar);
  55. +       }
  56. +       else if (command.startsWith("leavectf"))
  57. +       {
  58. +           LeaveCTF(activeChar);
  59. +       }
  60. +      
  61. +       else if (command.startsWith("infoctf"))
  62. +       {
  63. +           SendCTFinfo(activeChar);
  64. +       }
  65. +      
  66. +       return true;
  67. +   }
  68. +  
  69. +   @Override
  70. +   public String[] getVoicedCommandList()
  71. +   {
  72. +       return VOICED_COMMANDS;
  73. +   }
  74. +  
  75. +   public boolean JoinCTF(L2PcInstance activeChar)
  76. +   {
  77. +       if (activeChar == null)
  78. +       {
  79. +           return false;
  80. +       }
  81. +       NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  82. +      
  83. +       if (!CTF._joining) // check if ctf event is running or/and joining is avaliable
  84. +       {
  85. +           npcHtmlMessage.setHtml("<html><body>You can not register now: CTF event joining is not avaliable.</body></html>");
  86. +           activeChar.sendPacket(npcHtmlMessage);
  87. +           return false;
  88. +       }
  89. +       else if (activeChar._inEventCTF) // check if player is already registered in ctf event
  90. +       {
  91. +           npcHtmlMessage.setHtml("<html><body>You are participating this event already.</body></html>");
  92. +           activeChar.sendPacket(npcHtmlMessage);
  93. +           return false;
  94. +       }
  95. +       else if (activeChar.isCursedWeaponEquipped()) // check if player is holding a cursed weapon
  96. +       {
  97. +           npcHtmlMessage.setHtml("<html><body>You are not allowed to participate to the Event holding a Cursed Weapon.</body></html>");
  98. +           activeChar.sendPacket(npcHtmlMessage);
  99. +           return false;
  100. +       }
  101. +       else if (activeChar.isInOlympiadMode()) // check if player is in olympiads - dunno why, but sometimes simple doesnt work this check =/
  102. +       {
  103. +           npcHtmlMessage.setHtml("<html><body>You are not allowed to participate to the Event while in Olympiad.</body></html>");
  104. +           activeChar.sendPacket(npcHtmlMessage);
  105. +           return false;
  106. +       }
  107. +       else if (activeChar.isInJail()) // check if player is in jail
  108. +       {
  109. +           npcHtmlMessage.setHtml("<html><body>You are not allowed to participate to the Event while in Jail.</body></html>");
  110. +           activeChar.sendPacket(npcHtmlMessage);
  111. +           return false;
  112. +       }
  113. +       else if (activeChar.getLevel() < CTF._minlvl)
  114. +       {
  115. +           npcHtmlMessage.setHtml("<html><body>Your level is too low to participate at this Event.</body></html>");
  116. +           activeChar.sendPacket(npcHtmlMessage);
  117. +           return false;
  118. +       }
  119. +       else if (activeChar.getKarma() > 0) // check player karma - dunno why karma players cant participate - looks useless since player can register while not with karma and do pk after that ;)
  120. +       {
  121. +           npcHtmlMessage.setHtml("<html><body>You are not allowed to participate to the Event with Karma.</body></html>");
  122. +           activeChar.sendPacket(npcHtmlMessage);
  123. +           return false;
  124. +       }
  125. +       else if (CTF._maxPlayers == CTF._playersShuffle.size()) // check player karma - dunno why karma players cant participate - looks useless since player can register while not with karma and do pk after that ;)
  126. +       {
  127. +           npcHtmlMessage.setHtml("<html><body>Sorry,CTF Event is full.</body></html>");
  128. +           activeChar.sendPacket(npcHtmlMessage);
  129. +           return false;
  130. +       }
  131. +       else
  132. +       // send dialog confirmation to player that he is registered in ctf event and add him
  133. +       {
  134. +           npcHtmlMessage.setHtml("<html><body>Your participation in the CTF event has been aproved.</body></html>");
  135. +           activeChar.sendPacket(npcHtmlMessage);
  136. +           CTF.addPlayer(activeChar, "");
  137. +           return true;
  138. +       }
  139. +   }
  140. +  
  141. +   public boolean LeaveCTF(L2PcInstance activeChar)
  142. +   {
  143. +       if (activeChar == null)
  144. +       {
  145. +           return false;
  146. +       }
  147. +      
  148. +       NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  149. +      
  150. +       if (!CTF._joining) // check if CTF event is running or joining is avaliable
  151. +       {
  152. +           npcHtmlMessage.setHtml("<html><body>You can not unregister now cause there is no CTF event running.</body></html>");
  153. +           activeChar.sendPacket(npcHtmlMessage);
  154. +           return false;
  155. +       }
  156. +       else if (CTF._teleport || CTF._started) // check if ctf event has already teleported and started
  157. +       {
  158. +           npcHtmlMessage.setHtml("<html><body>You can not leave after CTF event has started.</body></html>");
  159. +           activeChar.sendPacket(npcHtmlMessage);
  160. +           return false;
  161. +       }
  162. +       else
  163. +       // send dialog confirmation to player that he is unregistered from ctf event and remove him
  164. +       {
  165. +           npcHtmlMessage.setHtml("<html><body>Your participation in the CTF event has been removed.</body></html>");
  166. +           activeChar.sendPacket(npcHtmlMessage);
  167. +           CTF.removePlayer(activeChar);
  168. +           return true;
  169. +       }
  170. +   }
  171. +  
  172. +   public boolean SendCTFinfo(L2PcInstance activeChar)
  173. +   {
  174. +       if (activeChar == null)
  175. +       {
  176. +           return false;
  177. +       }
  178. +       NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  179. +      
  180. +       if (CTF._joining)
  181. +       {
  182. +           npcHtmlMessage.setHtml("<html><body>There are " + CTF._playersShuffle.size() + " players participating in this event.</body></html>");
  183. +           activeChar.sendPacket(npcHtmlMessage);
  184. +           return true;
  185. +       }
  186. +       npcHtmlMessage.setHtml("<html><body>There is no Event in progress.</body></html>");
  187. +       activeChar.sendPacket(npcHtmlMessage);
  188. +       return false;
  189. +   }
  190. +}
  191. \ No newline at end of file
  192. Index: dist/game/data/scripts/handlers/actionhandlers/L2NpcAction.java
  193. ===================================================================
  194. --- dist/game/data/scripts/handlers/actionhandlers/L2NpcAction.java (revision 12)
  195. +++ dist/game/data/scripts/handlers/actionhandlers/L2NpcAction.java (working copy)
  196. @@ -28,6 +28,7 @@
  197.  import l2jcrimmerproject.gameserver.model.actor.L2Character;
  198.  import l2jcrimmerproject.gameserver.model.actor.L2Npc;
  199.  import l2jcrimmerproject.gameserver.model.actor.instance.L2PcInstance;
  200. +import l2jcrimmerproject.gameserver.model.entity.CTF;
  201.  import l2jcrimmerproject.gameserver.model.entity.L2Event;
  202.  import l2jcrimmerproject.gameserver.model.quest.Quest;
  203.  import l2jcrimmerproject.gameserver.model.quest.Quest.QuestEventType;
  204. @@ -135,6 +136,18 @@
  205.                     {
  206.                         L2Event.showEventHtml(activeChar, String.valueOf(target.getObjectId()));
  207.                     }
  208. +                   else if (((L2Npc) target)._isEventMobCTF)
  209. +                   {
  210. +                       CTF.showEventHtml(activeChar, String.valueOf(target.getObjectId()));
  211. +                   }
  212. +                   else if (((L2Npc) target)._isCTF_Flag && activeChar._inEventCTF)
  213. +                   {
  214. +                       CTF.showFlagHtml(activeChar, String.valueOf(target.getObjectId()), ((L2Npc) target)._CTF_FlagTeamName);
  215. +                   }
  216. +                   else if (((L2Npc) target)._isCTF_throneSpawn)
  217. +                   {
  218. +                       CTF.CheckRestoreFlags();
  219. +                   }
  220.                     else
  221.                     {
  222.                         List<Quest> qlsa = npc.getTemplate().getEventQuests(QuestEventType.QUEST_START);
  223. Index: dist/game/data/scripts/handlers/admincommandhandlers/AdminCTFEngine.java
  224. ===================================================================
  225. --- dist/game/data/scripts/handlers/admincommandhandlers/AdminCTFEngine.java    (revision 0)
  226. +++ dist/game/data/scripts/handlers/admincommandhandlers/AdminCTFEngine.java    (working copy)
  227. @@ -0,0 +1,548 @@
  228. +package handlers.admincommandhandlers;
  229. +
  230. +import javolution.text.TextBuilder;
  231. +import l2jcrimmerproject.Config;
  232. +import l2jcrimmerproject.gameserver.ThreadPoolManager;
  233. +import l2jcrimmerproject.gameserver.datatables.ItemTable;
  234. +import l2jcrimmerproject.gameserver.handler.IAdminCommandHandler;
  235. +import l2jcrimmerproject.gameserver.model.actor.instance.L2PcInstance;
  236. +import l2jcrimmerproject.gameserver.model.entity.CTF;
  237. +import l2jcrimmerproject.gameserver.network.serverpackets.NpcHtmlMessage;
  238. +
  239. +public class AdminCTFEngine implements IAdminCommandHandler
  240. +{
  241. +   private static final String[] ADMIN_COMMANDS =
  242. +   {
  243. +       "admin_ctf",
  244. +       "admin_ctf_name",
  245. +       "admin_ctf_desc",
  246. +       "admin_ctf_join_loc",
  247. +       "admin_ctf_edit",
  248. +       "admin_ctf_control",
  249. +       "admin_ctf_minlvl",
  250. +       "admin_ctf_maxlvl",
  251. +       "admin_ctf_tele_npc",
  252. +       "admin_ctf_tele_team",
  253. +       "admin_ctf_tele_team_base",
  254. +       "admin_ctf_tele_flag",
  255. +       "admin_ctf_npc",
  256. +       "admin_ctf_npc_pos",
  257. +       "admin_ctf_reward",
  258. +       "admin_ctf_reward_amount",
  259. +       "admin_ctf_team_add",
  260. +       "admin_ctf_team_remove",
  261. +       "admin_ctf_team_pos",
  262. +       "admin_ctf_team_base_pos",
  263. +       "admin_ctf_team_color",
  264. +       "admin_ctf_team_flag",
  265. +       "admin_ctf_join",
  266. +       "admin_ctf_teleport",
  267. +       "admin_ctf_start",
  268. +       "admin_ctf_abort",
  269. +       "admin_ctf_finish",
  270. +       "admin_ctf_sit",
  271. +       "admin_ctf_dump",
  272. +       "admin_ctf_save",
  273. +       "admin_ctf_load",
  274. +       "admin_ctf_jointime",
  275. +       "admin_ctf_eventtime",
  276. +       "admin_ctf_autoevent",
  277. +       "admin_ctf_minplayers",
  278. +       "admin_ctf_maxplayers",
  279. +       "admin_ctf_flagholdtime"
  280. +   };
  281. +  
  282. +   @Override
  283. +   public boolean useAdminCommand(String command, L2PcInstance activeChar)
  284. +   {
  285. +       try
  286. +       {
  287. +           if (command.equals("admin_ctf"))
  288. +           {
  289. +               showMainPage(activeChar);
  290. +           }
  291. +           else if (command.startsWith("admin_ctf_name "))
  292. +           {
  293. +               CTF._eventName = command.substring(15);
  294. +               showMainPage(activeChar);
  295. +           }
  296. +           else if (command.startsWith("admin_ctf_desc "))
  297. +           {
  298. +               CTF._eventDesc = command.substring(15);
  299. +               showMainPage(activeChar);
  300. +           }
  301. +           else if (command.startsWith("admin_ctf_minlvl "))
  302. +           {
  303. +               if (!CTF.checkMinLevel(Integer.valueOf(command.substring(17))))
  304. +               {
  305. +                   return false;
  306. +               }
  307. +               CTF._minlvl = Integer.valueOf(command.substring(17));
  308. +               showMainPage(activeChar);
  309. +           }
  310. +           else if (command.startsWith("admin_ctf_team_flag "))
  311. +           {
  312. +               String[] params;
  313. +              
  314. +               params = command.split(" ");
  315. +              
  316. +               if (params.length != 2)
  317. +               {
  318. +                   activeChar.sendMessage("Wrong usge: //ctf_team_flag <teamName>");
  319. +                   return false;
  320. +               }
  321. +              
  322. +               CTF.setTeamFlag(params[1], activeChar);
  323. +               showMainPage(activeChar);
  324. +           }
  325. +           else if (command.equals("admin_ctf_edit"))
  326. +           {
  327. +               showEditPage(activeChar);
  328. +           }
  329. +           else if (command.equals("admin_ctf_control"))
  330. +           {
  331. +               showControlPage(activeChar);
  332. +           }
  333. +           else if (command.equals("admin_ctf_tele_npc"))
  334. +           {
  335. +               activeChar.teleToLocation(CTF._npcX, CTF._npcY, CTF._npcZ);
  336. +               showMainPage(activeChar);
  337. +           }
  338. +           else if (command.startsWith("admin_ctf_tele_team "))
  339. +           {
  340. +               for (String t : CTF._teams)
  341. +               {
  342. +                   if (t.equals(command.substring(20)))
  343. +                   {
  344. +                       int index = CTF._teams.indexOf(t);
  345. +                       activeChar.teleToLocation(CTF._teamsX.get(index), CTF._teamsY.get(index), CTF._teamsZ.get(index));
  346. +                   }
  347. +               }
  348. +               showMainPage(activeChar);
  349. +           }
  350. +           else if (command.startsWith("admin_ctf_tele_team_base "))
  351. +           {
  352. +               for (String t : CTF._teams)
  353. +               {
  354. +                   if (t.equals(command.substring(20)))
  355. +                   {
  356. +                       int index = CTF._teams.indexOf(t);
  357. +                       activeChar.teleToLocation(CTF._teamsBaseX.get(index), CTF._teamsBaseY.get(index), CTF._teamsBaseZ.get(index));
  358. +                   }
  359. +               }
  360. +               showMainPage(activeChar);
  361. +           }
  362. +           else if (command.startsWith("admin_ctf_tele_flag "))
  363. +           {
  364. +               for (String t : CTF._teams)
  365. +               {
  366. +                   if (t.equals(command.substring(20)))
  367. +                   {
  368. +                       int index = CTF._teams.indexOf(t);
  369. +                       activeChar.teleToLocation(CTF._flagsX.get(index), CTF._flagsY.get(index), CTF._flagsZ.get(index));
  370. +                   }
  371. +               }
  372. +               showMainPage(activeChar);
  373. +           }
  374. +           else if (command.startsWith("admin_ctf_maxlvl "))
  375. +           {
  376. +               if (!CTF.checkMaxLevel(Integer.valueOf(command.substring(17))))
  377. +               {
  378. +                   return false;
  379. +               }
  380. +               CTF._maxlvl = Integer.valueOf(command.substring(17));
  381. +               showMainPage(activeChar);
  382. +           }
  383. +           else if (command.startsWith("admin_ctf_minplayers "))
  384. +           {
  385. +               CTF._minPlayers = Integer.valueOf(command.substring(21));
  386. +               showMainPage(activeChar);
  387. +           }
  388. +           else if (command.startsWith("admin_ctf_maxplayers "))
  389. +           {
  390. +               CTF._maxPlayers = Integer.valueOf(command.substring(21));
  391. +               showMainPage(activeChar);
  392. +           }
  393. +           else if (command.startsWith("admin_ctf_join_loc "))
  394. +           {
  395. +               CTF._joiningLocationName = command.substring(19);
  396. +               showMainPage(activeChar);
  397. +           }
  398. +           else if (command.startsWith("admin_ctf_npc "))
  399. +           {
  400. +               CTF._npcId = Integer.valueOf(command.substring(14));
  401. +               showMainPage(activeChar);
  402. +           }
  403. +           else if (command.equals("admin_ctf_npc_pos"))
  404. +           {
  405. +               CTF.setNpcPos(activeChar);
  406. +               showMainPage(activeChar);
  407. +           }
  408. +           else if (command.startsWith("admin_ctf_reward "))
  409. +           {
  410. +               CTF._rewardId = Integer.valueOf(command.substring(17));
  411. +               showMainPage(activeChar);
  412. +           }
  413. +           else if (command.startsWith("admin_ctf_reward_amount "))
  414. +           {
  415. +               CTF._rewardAmount = Integer.valueOf(command.substring(24));
  416. +               showMainPage(activeChar);
  417. +           }
  418. +           else if (command.startsWith("admin_ctf_jointime "))
  419. +           {
  420. +               CTF._joinTime = Integer.valueOf(command.substring(19));
  421. +               showMainPage(activeChar);
  422. +           }
  423. +           else if (command.startsWith("admin_ctf_eventtime "))
  424. +           {
  425. +               CTF._eventTime = Integer.valueOf(command.substring(20));
  426. +               showMainPage(activeChar);
  427. +           }
  428. +           else if (command.startsWith("admin_ctf_flagholdtime "))
  429. +           {
  430. +               CTF._flagHoldTime = Integer.valueOf(command.substring(20));
  431. +               showMainPage(activeChar);
  432. +           }
  433. +           else if (command.startsWith("admin_ctf_team_add "))
  434. +           {
  435. +               String teamName = command.substring(19);
  436. +              
  437. +               CTF.addTeam(teamName);
  438. +               showMainPage(activeChar);
  439. +           }
  440. +           else if (command.startsWith("admin_ctf_team_remove "))
  441. +           {
  442. +               String teamName = command.substring(22);
  443. +              
  444. +               CTF.removeTeam(teamName);
  445. +               showMainPage(activeChar);
  446. +           }
  447. +           else if (command.startsWith("admin_ctf_team_pos "))
  448. +           {
  449. +               String teamName = command.substring(19);
  450. +              
  451. +               CTF.setTeamPos(teamName, activeChar);
  452. +               showMainPage(activeChar);
  453. +           }
  454. +           else if (command.startsWith("admin_ctf_team_base__pos "))
  455. +           {
  456. +               String teamName = command.substring(19);
  457. +              
  458. +               CTF.setTeamBasePos(teamName, activeChar);
  459. +               showMainPage(activeChar);
  460. +           }
  461. +           else if (command.startsWith("admin_ctf_team_color "))
  462. +           {
  463. +               String[] params;
  464. +              
  465. +               params = command.split(" ");
  466. +              
  467. +               if (params.length != 3)
  468. +               {
  469. +                   activeChar.sendMessage("Wrong usege: //ctf_team_color <colorHex> <teamName>");
  470. +                   return false;
  471. +               }
  472. +              
  473. +               // name/title color in client is BGR, not RGB
  474. +               CTF.setTeamColor(command.substring(params[0].length() + params[1].length() + 2), Integer.decode("0x" + (params[1])));
  475. +               showMainPage(activeChar);
  476. +           }
  477. +           else if (command.equals("admin_ctf_join"))
  478. +           {
  479. +               if (!CTF._joining && !CTF._teleport && !CTF._started)
  480. +               {
  481. +                   CTF.startJoin(activeChar);
  482. +                   showMainPage(activeChar);
  483. +               }
  484. +               else
  485. +               {
  486. +                   activeChar.sendMessage("An Event cycle is already running. Let's wait till it's done.");
  487. +               }
  488. +           }
  489. +           else if (command.equals("admin_ctf_teleport"))
  490. +           {
  491. +               if (!CTF._teleport && !CTF._started)
  492. +               {
  493. +                   CTF.teleportStart();
  494. +                   showMainPage(activeChar);
  495. +               }
  496. +               else
  497. +               {
  498. +                   activeChar.sendMessage("An Event cycle is already running. Let's wait till it's done.");
  499. +               }
  500. +           }
  501. +           else if (command.equals("admin_ctf_start"))
  502. +           {
  503. +               if (!CTF._started)
  504. +               {
  505. +                   CTF.startEvent(activeChar);
  506. +                   showMainPage(activeChar);
  507. +               }
  508. +               else
  509. +               {
  510. +                   activeChar.sendMessage("An Event cycle is already running. Let's wait till it's done.");
  511. +               }
  512. +           }
  513. +           else if (command.equals("admin_ctf_abort"))
  514. +           {
  515. +               activeChar.sendMessage("Aborting event");
  516. +               CTF.abortEvent();
  517. +               showMainPage(activeChar);
  518. +           }
  519. +           else if (command.equals("admin_ctf_finish"))
  520. +           {
  521. +               CTF.finishEvent();
  522. +               showMainPage(activeChar);
  523. +           }
  524. +           else if (command.equals("admin_ctf_load"))
  525. +           {
  526. +               CTF.loadData();
  527. +               showMainPage(activeChar);
  528. +           }
  529. +           else if (command.equals("admin_ctf_autoevent"))
  530. +           {
  531. +               if (!CTF._started)
  532. +               {
  533. +                   if ((CTF._joinTime > 0) && (CTF._eventTime > 0))
  534. +                   {
  535. +                       ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  536. +                       {
  537. +                           @Override
  538. +                           public void run()
  539. +                           {
  540. +                               CTF.autoEvent();
  541. +                           }
  542. +                       }, 0);
  543. +                   }
  544. +                   else
  545. +                   {
  546. +                       activeChar.sendMessage("Wrong usege: join time or event time invalid.");
  547. +                   }
  548. +               }
  549. +               else
  550. +               {
  551. +                   activeChar.sendMessage("A CTF Event has already been started.");
  552. +               }
  553. +              
  554. +               showMainPage(activeChar);
  555. +           }
  556. +           else if (command.equals("admin_ctf_save"))
  557. +           {
  558. +               CTF.saveData();
  559. +               showMainPage(activeChar);
  560. +           }
  561. +           else if (command.equals("admin_ctf_dump"))
  562. +           {
  563. +               CTF.dumpData();
  564. +           }
  565. +          
  566. +           return true;
  567. +       }
  568. +       catch (Exception e)
  569. +       {
  570. +           activeChar.sendMessage("The command was not used correctly");
  571. +           return false;
  572. +       }
  573. +   }
  574. +  
  575. +   @Override
  576. +   public String[] getAdminCommandList()
  577. +   {
  578. +       return ADMIN_COMMANDS;
  579. +   }
  580. +  
  581. +   public void showEditPage(L2PcInstance activeChar)
  582. +   {
  583. +       NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  584. +       TextBuilder replyMSG = new TextBuilder();
  585. +      
  586. +       replyMSG.append("<html><body>");
  587. +       replyMSG.append("<center><font color=\"LEVEL\">[CTF Engine by Darki699]</font></center><br><br><br>");
  588. +       replyMSG.append("<table><tr><td><edit var=\"input1\" width=\"125\"></td><td><edit var=\"input2\" width=\"125\"></td></tr></table>");
  589. +       replyMSG.append("<table border=\"0\"><tr>");
  590. +       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>");
  591. +       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>");
  592. +       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>");
  593. +       replyMSG.append("</tr></table><br><table><tr>");
  594. +       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>");
  595. +       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>");
  596. +       replyMSG.append("</tr></table><br><table><tr>");
  597. +       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>");
  598. +       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>");
  599. +       replyMSG.append("</tr></table><br><table><tr>");
  600. +       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>");
  601. +       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>");
  602. +       replyMSG.append("</tr></table><br><table><tr>");
  603. +       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>");
  604. +       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>");
  605. +       replyMSG.append("</tr></table><br><table><tr>");
  606. +       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>");
  607. +       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>");
  608. +       replyMSG.append("<td width=\"100\"><button value=\"Hold Time\" action=\"bypass -h admin_ctf_flagholdtime $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  609. +       replyMSG.append("</tr></table><br><table><tr>");
  610. +       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>");
  611. +       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>");
  612. +       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>");
  613. +       replyMSG.append("</tr></table><table><tr>");
  614. +       if (Config.CTF_BASE_TELEPORT_FIRST)
  615. +       {
  616. +           replyMSG.append("<td width=\"100\"><button value=\"Team Base Pos\" action=\"bypass -h admin_ctf_team_base_pos $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  617. +       }
  618. +       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>");
  619. +       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>");
  620. +       replyMSG.append("</tr></table><br>");
  621. +       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>");
  622. +      
  623. +       adminReply.setHtml(replyMSG.toString());
  624. +       activeChar.sendPacket(adminReply);
  625. +   }
  626. +  
  627. +   public void showControlPage(L2PcInstance activeChar)
  628. +   {
  629. +       NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  630. +       TextBuilder replyMSG = new TextBuilder();
  631. +      
  632. +       replyMSG.append("<html><body>");
  633. +       replyMSG.append("<center><font color=\"LEVEL\">[CTF Engine by Darki699]</font></center><br><br><br>");
  634. +       replyMSG.append("<table border=\"0\"><tr>");
  635. +       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>");
  636. +       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>");
  637. +       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>");
  638. +       replyMSG.append("</tr></table><table><tr>");
  639. +       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>");
  640. +       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>");
  641. +       replyMSG.append("</tr></table><br><table><tr>");
  642. +       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>");
  643. +       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>");
  644. +       replyMSG.append("</tr></table><br><br><table><tr>");
  645. +       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>");
  646. +       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>");
  647. +       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>");
  648. +       replyMSG.append("</tr></table><br>");
  649. +       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>");
  650. +      
  651. +       adminReply.setHtml(replyMSG.toString());
  652. +       activeChar.sendPacket(adminReply);
  653. +   }
  654. +  
  655. +   public void showMainPage(L2PcInstance activeChar)
  656. +   {
  657. +       NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  658. +       TextBuilder replyMSG = new TextBuilder();
  659. +       replyMSG.append("<html><body>");
  660. +      
  661. +       replyMSG.append("<center><font color=\"LEVEL\">[CTF Engine by Darki699]</font></center><br><br><br>");
  662. +      
  663. +       replyMSG.append("<table><tr>");
  664. +       if (!CTF._joining && !CTF._started && !CTF._teleport)
  665. +       {
  666. +           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>");
  667. +       }
  668. +       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>");
  669. +       replyMSG.append("</tr></table><br>");
  670. +       replyMSG.append("<br><font color=\"LEVEL\">Current event...</font><br>");
  671. +       replyMSG.append("    ... name: <font color=\"00FF00\">" + CTF._eventName + "</font><br>");
  672. +       replyMSG.append("    ... description: <font color=\"00FF00\">" + CTF._eventDesc + "</font><br>");
  673. +       replyMSG.append("    ... joining location name: <font color=\"00FF00\">" + CTF._joiningLocationName + "</font><br>");
  674. +       replyMSG.append("    ... joining NPC ID: <font color=\"00FF00\">" + CTF._npcId + " on pos " + CTF._npcX + "," + CTF._npcY + "," + CTF._npcZ + "</font><br>");
  675. +       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>");
  676. +       replyMSG.append("    ... reward ID: <font color=\"00FF00\">" + CTF._rewardId + "</font><br>");
  677. +       if (ItemTable.getInstance().getTemplate(CTF._rewardId) != null)
  678. +       {
  679. +           replyMSG.append("    ... reward Item: <font color=\"00FF00\">" + ItemTable.getInstance().getTemplate(CTF._rewardId).getName() + "</font><br>");
  680. +       }
  681. +       else
  682. +       {
  683. +           replyMSG.append("    ... reward Item: <font color=\"00FF00\">(unknown)</font><br>");
  684. +       }
  685. +       replyMSG.append("    ... reward Amount: <font color=\"00FF00\">" + CTF._rewardAmount + "</font><br>");
  686. +       replyMSG.append("    ... Min lvl: <font color=\"00FF00\">" + CTF._minlvl + "</font><br>");
  687. +       replyMSG.append("    ... Max lvl: <font color=\"00FF00\">" + CTF._maxlvl + "</font><br><br>");
  688. +       replyMSG.append("    ... Min Players: <font color=\"00FF00\">" + CTF._minPlayers + "</font><br>");
  689. +       replyMSG.append("    ... Max Players: <font color=\"00FF00\">" + CTF._maxPlayers + "</font><br>");
  690. +       replyMSG.append("    ... Joining Time: <font color=\"00FF00\">" + CTF._joinTime + "</font><br>");
  691. +       replyMSG.append("    ... Event Time: <font color=\"00FF00\">" + CTF._eventTime + "</font><br>");
  692. +       replyMSG.append("    ... Flag Hold Time: <font color=\"00FF00\">" + CTF._flagHoldTime + "</font><br>");
  693. +       if ((CTF._teams != null) && !CTF._teams.isEmpty())
  694. +       {
  695. +           replyMSG.append("<font color=\"LEVEL\">Current teams:</font><br>");
  696. +       }
  697. +       replyMSG.append("<center><table border=\"0\">");
  698. +      
  699. +       for (String team : CTF._teams)
  700. +       {
  701. +           replyMSG.append("<tr><td width=\"100\">Name: <font color=\"FF0000\">" + team + "</font>");
  702. +          
  703. +           if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  704. +           {
  705. +               replyMSG.append(" (" + CTF.teamPlayersCount(team) + " joined)");
  706. +           }
  707. +           else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  708. +           {
  709. +               if (CTF._teleport || CTF._started)
  710. +               {
  711. +                   replyMSG.append(" (" + CTF.teamPlayersCount(team) + " in)");
  712. +               }
  713. +           }
  714. +           replyMSG.append("</td></tr><tr><td>");
  715. +          
  716. +           String c = Integer.toHexString(CTF._teamColors.get(CTF._teams.indexOf(team)));
  717. +           while (c.length() < 6)
  718. +           {
  719. +               c = "0" + c;
  720. +           }
  721. +           replyMSG.append("Color: <font color=\"00FF00\">0x" + c.toUpperCase() + "</font><font color=\"" + c + "\"> =) </font>");
  722. +          
  723. +           replyMSG.append("</td></tr><tr><td>");
  724. +           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\">");
  725. +           replyMSG.append("</td></tr><tr><td>");
  726. +           replyMSG.append(CTF._teamsX.get(CTF._teams.indexOf(team)) + ", " + CTF._teamsY.get(CTF._teams.indexOf(team)) + ", " + CTF._teamsZ.get(CTF._teams.indexOf(team)));
  727. +           replyMSG.append("</td></tr><tr><td>");
  728. +           if (Config.CTF_BASE_TELEPORT_FIRST)
  729. +           {
  730. +               replyMSG.append("<button value=\"Tele->TeamBase\" action=\"bypass -h admin_ctf_tele_team_base " + team + "\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  731. +               replyMSG.append("</td></tr><tr><td>");
  732. +               replyMSG.append(CTF._teamsBaseX.get(CTF._teams.indexOf(team)) + ", " + CTF._teamsBaseY.get(CTF._teams.indexOf(team)) + ", " + CTF._teamsBaseZ.get(CTF._teams.indexOf(team)));
  733. +               replyMSG.append("</td></tr><tr><td>");
  734. +           }
  735. +           replyMSG.append("Flag Id: <font color=\"00FF00\">" + CTF._flagIds.get(CTF._teams.indexOf(team)) + "</font>");
  736. +           replyMSG.append("</td></tr><tr><td>");
  737. +           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\">");
  738. +           replyMSG.append("</td></tr><tr><td>");
  739. +           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>");
  740. +           if (!CTF._joining && !CTF._started && !CTF._teleport)
  741. +           {
  742. +               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>");
  743. +           }
  744. +       }
  745. +      
  746. +       replyMSG.append("</table></center>");
  747. +      
  748. +       if (!CTF._joining && !CTF._started && !CTF._teleport)
  749. +       {
  750. +           if (CTF.startJoinOk())
  751. +           {
  752. +               replyMSG.append("<br>");
  753. +               replyMSG.append("Event is now set up. Press JOIN to start the registration.<br>");
  754. +               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\"><br>");
  755. +               replyMSG.append("<br>");
  756. +           }
  757. +           else
  758. +           {
  759. +               replyMSG.append("<br>");
  760. +               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.<br>");
  761. +               replyMSG.append("<br>");
  762. +           }
  763. +       }
  764. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !CTF._started)
  765. +       {
  766. +           replyMSG.append("<br>");
  767. +           replyMSG.append(CTF._playersShuffle.size() + " players participating. Waiting to shuffle in teams(done on teleport)!");
  768. +           replyMSG.append("<br><br>");
  769. +       }
  770. +      
  771. +       replyMSG.append("</body></html>");
  772. +       adminReply.setHtml(replyMSG.toString());
  773. +       activeChar.sendPacket(adminReply);
  774. +   }
  775. +}
  776. \ No newline at end of file
  777. Index: dist/sql/game/custom/custom_npc.sql
  778. ===================================================================
  779. --- dist/sql/game/custom/custom_npc.sql (revision 12)
  780. +++ dist/sql/game/custom/custom_npc.sql (working copy)
  781. @@ -45,6 +45,8 @@
  782.  (50007,31324,'Andromeda',1,'L2J Wedding Manager',1,'NPC.a_casino_FDarkElf',8.00,23.00,70,'female','L2WeddingManager',40,2444,2444,0.00,0.00,10,10,10,10,10,10,0,0,500,500,500,500,278,1,333,0,0,0,28,120,0,0),
  783.  (70010,31606,'Catrina',1,'L2J TvT Event Manager',1,'Monster2.queen_of_cat',8.00,15.00,70,'female','L2TvTEventNpc',40,2444,2444,0.00,0.00,10,10,10,10,10,10,0,0,500,500,500,500,278,1,333,0,0,0,28,120,0,0),
  784.  (1000003,32226,'Shiela',1,'L2J NPC Buffer',1,'LineageNPC2.K_F1_grand',11.00,22.25,70,'male','L2NpcBuffer',40,2444,2444,0.00,0.00,10,10,10,10,10,10,0,0,500,500,500,500,278,1,333,0,0,0,28,120,0,0),
  785. +(70012,31606,'Pathy',1,'CTF Event',1,'LineageNPC2.K_F1_grand',8.00,15.00,70,'female','L2Npc',40,2444,2444,0.00,0.00,10,10,10,10,10,10,0,0,500,500,500,500,278,1,333,0,0,0,28,120,0,0),
  786. +
  787.  -- eventmod Elpies
  788.  (900100,20432,'Elpy',1,'',1,'LineageMonster.elpy',5.00,4.50,1,'male','L2EventMonster',40,40,36,3.16,0.91,40,43,30,21,20,20,35,2,8,40,7,25,230,1,333,0,0,0,50,80,0,0),
  789.  -- eventmod Rabbits
  790. Index: dist/sql/game/ctf.sql
  791. ===================================================================
  792. --- dist/sql/game/ctf.sql   (revision 0)
  793. +++ dist/sql/game/ctf.sql   (working copy)
  794. @@ -0,0 +1,23 @@
  795. +CREATE TABLE IF NOT EXISTS `ctf` (
  796. +  `eventName` varchar(255) NOT NULL DEFAULT '',
  797. +  `eventDesc` varchar(255) NOT NULL DEFAULT '',
  798. +  `joiningLocation` varchar(255) NOT NULL DEFAULT '',
  799. +  `minlvl` int(4) NOT NULL DEFAULT '0',
  800. +  `maxlvl` int(4) NOT NULL DEFAULT '0',
  801. +  `npcId` int(11) NOT NULL DEFAULT '0',
  802. +  `npcX` int(11) NOT NULL DEFAULT '0',
  803. +  `npcY` int(11) NOT NULL DEFAULT '0',
  804. +  `npcZ` int(11) NOT NULL DEFAULT '0',
  805. +  `npcHeading` int(11) NOT NULL DEFAULT '0',
  806. +  `rewardId` int(11) NOT NULL DEFAULT '0',
  807. +  `rewardAmount` int(11) NOT NULL DEFAULT '0',
  808. +  `teamsCount` int(4) NOT NULL DEFAULT '0',
  809. +  `joinTime` int(11) NOT NULL DEFAULT '0',
  810. +  `eventTime` int(11) NOT NULL DEFAULT '0',
  811. +  `minPlayers` int(4) NOT NULL DEFAULT '0',
  812. +  `maxPlayers` int(4) NOT NULL DEFAULT '0',
  813. +  `flagHoldTime` int(11) NOT NULL
  814. +) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  815. +
  816. +INSERT INTO `ctf` (`eventName`, `eventDesc`, `joiningLocation`, `minlvl`, `maxlvl`, `npcId`, `npcX`, `npcY`, `npcZ`, `npcHeading`, `rewardId`, `rewardAmount`, `teamsCount`, `joinTime`, `eventTime`, `minPlayers`, `maxPlayers`, `flagHoldTime`) VALUES
  817. +('Capture The Flag', 'Capture Flag', 'Giran', 85, 85, 70012, 83425, 148585, -3406, 33068, 3470, 10, 2, 15, 15, 4, 100, 120);
  818. Index: dist/game/data/scripts/handlers/MasterHandler.java
  819. ===================================================================
  820. --- dist/game/data/scripts/handlers/MasterHandler.java  (revision 12)
  821. +++ dist/game/data/scripts/handlers/MasterHandler.java  (working copy)
  822. @@ -57,6 +57,7 @@
  823.  import handlers.admincommandhandlers.AdminBlockIp;
  824.  import handlers.admincommandhandlers.AdminBuffs;
  825.  import handlers.admincommandhandlers.AdminCHSiege;
  826. +import handlers.admincommandhandlers.AdminCTFEngine;
  827.  import handlers.admincommandhandlers.AdminCache;
  828.  import handlers.admincommandhandlers.AdminCamera;
  829.  import handlers.admincommandhandlers.AdminChangeAccessLevel;
  830. @@ -294,6 +295,7 @@
  831.  import handlers.usercommandhandlers.Time;
  832.  import handlers.usercommandhandlers.Unstuck;
  833.  import handlers.voicedcommandhandlers.Banking;
  834. +import handlers.voicedcommandhandlers.CTFCmd;
  835.  import handlers.voicedcommandhandlers.ChangePassword;
  836.  import handlers.voicedcommandhandlers.ChaosCmd;
  837.  import handlers.voicedcommandhandlers.ChatAdmin;
  838. @@ -372,6 +374,7 @@
  839.             AdminClan.class,
  840.             AdminPcCondOverride.class,
  841.             AdminCreateItem.class,
  842. +           (Config.CTF_EVENT_ENABLED ? AdminCTFEngine.class : null),
  843.             AdminCursedWeapons.class,
  844.             AdminDebug.class,
  845.             AdminDelete.class,
  846. @@ -600,6 +603,7 @@
  847.             (Config.L2JMOD_HELLBOUND_STATUS ? Hellbound.class : null),
  848.             (Config.ENABLE_CHAOS_EVENT ? ChaosCmd.class : null),
  849.             (Config.ENABLE_REPAIR_COMMAND ? Repair.class : null),
  850. +           (Config.CTF_ALLOW_VOICE_COMMAND ? CTFCmd.class : null),
  851.         },
  852.         {
  853.             // Target Handlers
  854. #P Core
  855. Index: java/l2jcrimmerproject/gameserver/model/actor/L2Summon.java
  856. ===================================================================
  857. --- java/l2jcrimmerproject/gameserver/model/actor/L2Summon.java (revision 12)
  858. +++ java/l2jcrimmerproject/gameserver/model/actor/L2Summon.java (working copy)
  859. @@ -623,6 +623,7 @@
  860.        
  861.         // Get the target for the skill
  862.         L2Object target = null;
  863. +      
  864.         switch (skill.getTargetType())
  865.         {
  866.         // OWNER_PET should be cast even if no target has been found
  867. @@ -683,7 +684,7 @@
  868.             }
  869.            
  870.             // Summons can cast skills on NPCs inside peace zones.
  871. -           if (isInsidePeaceZone(this, target) && !getOwner().getAccessLevel().allowPeaceAttack())
  872. +           if (isInsidePeaceZone(this, target) && !getOwner().getAccessLevel().allowPeaceAttack() && (!this.isInFunEvent() || !target.isInFunEvent()))
  873.             {
  874.                 // If summon or target is in a peace zone, send a system message:
  875.                 sendPacket(SystemMessageId.TARGET_IN_PEACEZONE);
  876. Index: java/l2jcrimmerproject/gameserver/model/skills/L2Skill.java
  877. ===================================================================
  878. --- java/l2jcrimmerproject/gameserver/model/skills/L2Skill.java (revision 12)
  879. +++ java/l2jcrimmerproject/gameserver/model/skills/L2Skill.java (working copy)
  880. @@ -50,6 +50,7 @@
  881.  import l2jcrimmerproject.gameserver.model.effects.EffectTemplate;
  882.  import l2jcrimmerproject.gameserver.model.effects.L2Effect;
  883.  import l2jcrimmerproject.gameserver.model.effects.L2EffectType;
  884. +import l2jcrimmerproject.gameserver.model.entity.CTF;
  885.  import l2jcrimmerproject.gameserver.model.entity.TvTEvent;
  886.  import l2jcrimmerproject.gameserver.model.entity.TvTRoundEvent;
  887.  import l2jcrimmerproject.gameserver.model.holders.ItemHolder;
  888. @@ -1240,6 +1241,14 @@
  889.         final L2PcInstance targetPlayer = target.getActingPlayer();
  890.         if (player != null)
  891.         {
  892. +           if ((CTF._started && !Config.CTF_ALLOW_INTERFERENCE) && !player.isGM())
  893. +           {
  894. +               if ((targetPlayer._inEventCTF && !player._inEventCTF) || (!targetPlayer._inEventCTF && player._inEventCTF))
  895. +               {
  896. +                   return false;
  897. +               }
  898. +           }
  899. +          
  900.             if (targetPlayer != null)
  901.             {
  902.                 if ((targetPlayer == caster) || (targetPlayer == player))
  903. Index: java/l2jcrimmerproject/gameserver/model/L2Object.java
  904. ===================================================================
  905. --- java/l2jcrimmerproject/gameserver/model/L2Object.java   (revision 12)
  906. +++ java/l2jcrimmerproject/gameserver/model/L2Object.java   (working copy)
  907. @@ -713,6 +713,12 @@
  908.         // default implementation
  909.     }
  910.    
  911. +   public boolean isInFunEvent()
  912. +   {
  913. +       L2PcInstance player = getActingPlayer();
  914. +       return (player == null ? false : player.isInFunEvent());
  915. +   }
  916. +  
  917.     /**
  918.      * Not Implemented.<BR>
  919.      * <BR>
  920. Index: dist/game/config/Events/CTF.properties
  921. ===================================================================
  922. --- dist/game/config/Events/CTF.properties  (revision 0)
  923. +++ dist/game/config/Events/CTF.properties  (working copy)
  924. @@ -0,0 +1,42 @@
  925. +# ---------------------------------------------------------------------------
  926. +#  Capture The Flag
  927. +# ---------------------------------------------------------------------------
  928. +#This parameter is to turn on/off the auto CTF at server start .
  929. +#If True, it writes into gameserver console: CTFEventEngine: Started.
  930. +#If False, it writes into gameserver console: CTFEventEngine: Engine is disabled.
  931. +
  932. +CTFEventEnabled = False
  933. +
  934. +#This is where you will chose the time where the CTF Event will take place automatically
  935. +# Times CTF will occur (24h format)
  936. +CTFEventInterval = 7:00,11:00,15:00,19:00,23:00,3:00
  937. +# CTFEvenTeams = NO|BALANCE|SHUFFLE
  938. +# NO means: not even teams.
  939. +# BALANCE means: Players can only join team with lowest player count.
  940. +# SHUFFLE means: Players can only participate to the event and not direct to a team. Teams will be shuffled on teams teleport.
  941. +CTFEvenTeams = SHUFFLE
  942. +# Allow voiced command on CTF Event?
  943. +CTFAllowVoiceCommand = False
  944. +# Players that are not participating in CTF can target ctf participants?
  945. +CTFAllowInterference = False
  946. +# CTF participants can use potions?
  947. +CTFAllowPotions = False
  948. +# CTF participants can summon by item?
  949. +CTFAllowSummon = False
  950. +# Remove all effects of CTF participants on event start?
  951. +CTFOnStartRemoveAllEffects = True
  952. +# Unsummon pet of CTF participants on event start?
  953. +CTFOnStartUnsummonPet = True
  954. +# On revive participants regain full HP/MP/CP?
  955. +CTFReviveRecovery = False
  956. +# Announce all team statistics
  957. +CTFAnnounceTeamStats = False
  958. +# Announce reward
  959. +CTFAnnounceReward = False
  960. +# Players with cursed weapon are allowed to join?
  961. +CTFJoinWithCursedWeapon = True
  962. +# Delay on revive when dead, NOTE: 20000 equals to 20 seconds, minimum 1000 (1 second)
  963. +CTFReviveDelay = 20000
  964. +# Would you like to have a base for the players to have first, then teleport into battle?
  965. +# If True, You must set-up in CTF admin panel
  966. +CTFTeleportToBaseFirst = True
  967. Index: java/l2jcrimmerproject/gameserver/network/clientpackets/RequestBypassToServer.java
  968. ===================================================================
  969. --- java/l2jcrimmerproject/gameserver/network/clientpackets/RequestBypassToServer.java  (revision 12)
  970. +++ java/l2jcrimmerproject/gameserver/network/clientpackets/RequestBypassToServer.java  (working copy)
  971. @@ -23,7 +23,6 @@
  972.  import java.util.logging.Level;
  973.  
  974.  import javolution.util.FastList;
  975. -
  976.  import l2jcrimmerproject.Config;
  977.  import l2jcrimmerproject.gameserver.ai.CtrlIntention;
  978.  import l2jcrimmerproject.gameserver.communitybbs.CommunityBoard;
  979. @@ -38,6 +37,7 @@
  980.  import l2jcrimmerproject.gameserver.model.actor.L2Npc;
  981.  import l2jcrimmerproject.gameserver.model.actor.instance.L2MerchantSummonInstance;
  982.  import l2jcrimmerproject.gameserver.model.actor.instance.L2PcInstance;
  983. +import l2jcrimmerproject.gameserver.model.entity.CTF;
  984.  import l2jcrimmerproject.gameserver.model.entity.Hero;
  985.  import l2jcrimmerproject.gameserver.model.items.instance.L2ItemInstance;
  986.  import l2jcrimmerproject.gameserver.network.SystemMessageId;
  987. @@ -192,6 +192,31 @@
  988.                     }
  989.                    
  990.                     activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  991. +                  
  992. +                   if (_command.substring(endOfId + 1).startsWith("ctf_player_join "))
  993. +                   {
  994. +                       String teamName = _command.substring(endOfId + 1).substring(16);
  995. +                      
  996. +                       if (CTF._joining)
  997. +                       {
  998. +                           CTF.addPlayer(activeChar, teamName);
  999. +                       }
  1000. +                       else
  1001. +                       {
  1002. +                           activeChar.sendMessage("The event is already started. You can not join now!");
  1003. +                       }
  1004. +                   }
  1005. +                   else if (_command.substring(endOfId + 1).startsWith("ctf_player_leave"))
  1006. +                   {
  1007. +                       if (CTF._joining)
  1008. +                       {
  1009. +                           CTF.removePlayer(activeChar);
  1010. +                       }
  1011. +                       else
  1012. +                       {
  1013. +                           activeChar.sendMessage("The event is already started. You can not leave now!");
  1014. +                       }
  1015. +                   }
  1016.                 }
  1017.                 catch (NumberFormatException nfe)
  1018.                 {
  1019. Index: java/l2jcrimmerproject/gameserver/network/clientpackets/EnterWorld.java
  1020. ===================================================================
  1021. --- java/l2jcrimmerproject/gameserver/network/clientpackets/EnterWorld.java (revision 12)
  1022. +++ java/l2jcrimmerproject/gameserver/network/clientpackets/EnterWorld.java (working copy)
  1023. @@ -53,6 +53,7 @@
  1024.  import l2jcrimmerproject.gameserver.model.PcCondOverride;
  1025.  import l2jcrimmerproject.gameserver.model.actor.instance.L2ClassMasterInstance;
  1026.  import l2jcrimmerproject.gameserver.model.actor.instance.L2PcInstance;
  1027. +import l2jcrimmerproject.gameserver.model.entity.CTF;
  1028.  import l2jcrimmerproject.gameserver.model.entity.Couple;
  1029.  import l2jcrimmerproject.gameserver.model.entity.Fort;
  1030.  import l2jcrimmerproject.gameserver.model.entity.FortSiege;
  1031. @@ -598,6 +599,11 @@
  1032.        
  1033.         L2ClassMasterInstance.showQuestionMark(activeChar);
  1034.        
  1035. +       if (CTF._savePlayers.contains(activeChar.getName()))
  1036. +       {
  1037. +           CTF.addDisconnectedPlayer(activeChar);
  1038. +       }
  1039. +      
  1040.         int birthday = activeChar.checkBirthDay();
  1041.         if (birthday == 0)
  1042.         {
  1043. Index: java/l2jcrimmerproject/gameserver/model/actor/L2Npc.java
  1044. ===================================================================
  1045. --- java/l2jcrimmerproject/gameserver/model/actor/L2Npc.java    (revision 12)
  1046. +++ java/l2jcrimmerproject/gameserver/model/actor/L2Npc.java    (working copy)
  1047. @@ -60,6 +60,7 @@
  1048.  import l2jcrimmerproject.gameserver.model.actor.status.NpcStatus;
  1049.  import l2jcrimmerproject.gameserver.model.actor.templates.L2NpcTemplate;
  1050.  import l2jcrimmerproject.gameserver.model.actor.templates.L2NpcTemplate.AIType;
  1051. +import l2jcrimmerproject.gameserver.model.entity.CTF;
  1052.  import l2jcrimmerproject.gameserver.model.entity.Castle;
  1053.  import l2jcrimmerproject.gameserver.model.entity.Fort;
  1054.  import l2jcrimmerproject.gameserver.model.entity.clanhall.SiegableHall;
  1055. @@ -122,6 +123,12 @@
  1056.     private boolean _eventMob = false;
  1057.     private boolean _isInTown = false;
  1058.    
  1059. +   /** CTF */
  1060. +   public boolean _isEventMobCTF = false;
  1061. +   public boolean _isCTF_throneSpawn = false;
  1062. +   public boolean _isCTF_Flag = false;
  1063. +   public String _CTF_FlagTeamName;
  1064. +  
  1065.     /** True if this L2Npc is autoattackable **/
  1066.     private boolean _isAutoAttackable = false;
  1067.    
  1068. @@ -1708,6 +1715,18 @@
  1069.         {
  1070.             html = HtmCache.getInstance().getHtm(player.getHtmlPrefix(), "data/html/trainer/" + npcId + "-noteach.htm");
  1071.         }
  1072. +       else if (_isEventMobCTF)
  1073. +       {
  1074. +           CTF.showEventHtml(player, String.valueOf(getObjectId()));
  1075. +       }
  1076. +       else if (_isCTF_Flag && player._inEventCTF)
  1077. +       {
  1078. +           CTF.showFlagHtml(player, String.valueOf(this.getObjectId()), _CTF_FlagTeamName);
  1079. +       }
  1080. +       else if (_isCTF_throneSpawn)
  1081. +       {
  1082. +           CTF.CheckRestoreFlags();
  1083. +       }
  1084.        
  1085.         if (html == null)
  1086.         {
  1087. Index: java/l2jcrimmerproject/gameserver/network/SystemMessageId.java
  1088. ===================================================================
  1089. --- java/l2jcrimmerproject/gameserver/network/SystemMessageId.java  (revision 12)
  1090. +++ java/l2jcrimmerproject/gameserver/network/SystemMessageId.java  (working copy)
  1091. @@ -29,14 +29,14 @@
  1092.  
  1093.  import javax.xml.parsers.DocumentBuilderFactory;
  1094.  
  1095. +import l2jcrimmerproject.Config;
  1096. +import l2jcrimmerproject.gameserver.model.clientstrings.Builder;
  1097. +import l2jcrimmerproject.gameserver.network.serverpackets.SystemMessage;
  1098. +
  1099.  import org.w3c.dom.Document;
  1100.  import org.w3c.dom.NamedNodeMap;
  1101.  import org.w3c.dom.Node;
  1102.  
  1103. -import l2jcrimmerproject.Config;
  1104. -import l2jcrimmerproject.gameserver.model.clientstrings.Builder;
  1105. -import l2jcrimmerproject.gameserver.network.serverpackets.SystemMessage;
  1106. -
  1107.  /**
  1108.   * @author Noctarius, Nille02, crion, Forsaiken
  1109.   */
  1110. @@ -14998,10 +14998,18 @@
  1111.      * Array containing all SystemMessageIds<br>
  1112.      * Important: Always initialize with a length of the highest SystemMessageId + 1!!!
  1113.      */
  1114. +  
  1115. +   /**
  1116. +    * ID: 3038<br>
  1117. +    * Message: You cannot mount a steed while you holding a flag. male guards do, so beware.
  1118. +    */
  1119. +   public static final SystemMessageId YOU_CANNOT_MOUNT_A_STEED_WHILE_HOLDING_A_FLAG;
  1120. +  
  1121.     private static SystemMessageId[] VALUES;
  1122.    
  1123.     static
  1124.     {
  1125. +      
  1126.         YOU_HAVE_BEEN_DISCONNECTED = new SystemMessageId(0);
  1127.         THE_SERVER_WILL_BE_COMING_DOWN_IN_S1_SECONDS = new SystemMessageId(1);
  1128.         S1_DOES_NOT_EXIST = new SystemMessageId(2);
  1129. @@ -17481,6 +17489,7 @@
  1130.         THOMAS_D_TURKEY_APPEARED = new SystemMessageId(6503);
  1131.         THOMAS_D_TURKEY_DEFETED = new SystemMessageId(6504);
  1132.         THOMAS_D_TURKEY_DISAPPEARED = new SystemMessageId(6505);
  1133. +       YOU_CANNOT_MOUNT_A_STEED_WHILE_HOLDING_A_FLAG = new SystemMessageId(6506);
  1134.        
  1135.         buildFastLookupTable();
  1136.     }
  1137. Index: java/l2jcrimmerproject/gameserver/GameServer.java
  1138. ===================================================================
  1139. --- java/l2jcrimmerproject/gameserver/GameServer.java   (revision 12)
  1140. +++ java/l2jcrimmerproject/gameserver/GameServer.java   (working copy)
  1141. @@ -115,6 +115,7 @@
  1142.  import l2jcrimmerproject.gameserver.model.L2World;
  1143.  import l2jcrimmerproject.gameserver.model.PartyMatchRoomList;
  1144.  import l2jcrimmerproject.gameserver.model.PartyMatchWaitingList;
  1145. +import l2jcrimmerproject.gameserver.model.entity.CTF;
  1146.  import l2jcrimmerproject.gameserver.model.entity.Hero;
  1147.  import l2jcrimmerproject.gameserver.model.entity.TvTManager;
  1148.  import l2jcrimmerproject.gameserver.model.entity.TvTRoundManager;
  1149. @@ -379,6 +380,7 @@
  1150.        
  1151.         TvTManager.getInstance();
  1152.         TvTRoundManager.getInstance();
  1153. +       CTF.getInstance();
  1154.         KnownListUpdateTaskManager.getInstance();
  1155.        
  1156.         if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)
  1157. Index: java/l2jcrimmerproject/gameserver/network/clientpackets/RequestUnEquipItem.java
  1158. ===================================================================
  1159. --- java/l2jcrimmerproject/gameserver/network/clientpackets/RequestUnEquipItem.java (revision 12)
  1160. +++ java/l2jcrimmerproject/gameserver/network/clientpackets/RequestUnEquipItem.java (working copy)
  1161. @@ -58,7 +58,11 @@
  1162.         {
  1163.             return;
  1164.         }
  1165. -      
  1166. +       if (activeChar._haveFlagCTF)
  1167. +       {
  1168. +           activeChar.sendMessage("You can't unequip a CTF flag.");
  1169. +           return;
  1170. +       }
  1171.         final L2ItemInstance item = activeChar.getInventory().getPaperdollItemByL2ItemId(_slot);
  1172.         // Wear-items are not to be unequipped.
  1173.         if (item == null)
  1174. Index: java/l2jcrimmerproject/gameserver/network/clientpackets/UseItem.java
  1175. ===================================================================
  1176. --- java/l2jcrimmerproject/gameserver/network/clientpackets/UseItem.java    (revision 12)
  1177. +++ java/l2jcrimmerproject/gameserver/network/clientpackets/UseItem.java    (working copy)
  1178. @@ -234,7 +234,7 @@
  1179.                         return;
  1180.                     }
  1181.                    
  1182. -                   if (activeChar.isMounted())
  1183. +                   if (activeChar.isMounted() || (activeChar._inEventCTF && activeChar._haveFlagCTF))
  1184.                     {
  1185.                         activeChar.sendPacket(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
  1186.                         return;
  1187. Index: java/l2jcrimmerproject/gameserver/model/actor/stat/PcStat.java
  1188. ===================================================================
  1189. --- java/l2jcrimmerproject/gameserver/model/actor/stat/PcStat.java  (revision 12)
  1190. +++ java/l2jcrimmerproject/gameserver/model/actor/stat/PcStat.java  (working copy)
  1191. @@ -19,7 +19,6 @@
  1192.  package l2jcrimmerproject.gameserver.model.actor.stat;
  1193.  
  1194.  import javolution.util.FastList;
  1195. -
  1196.  import l2jcrimmerproject.Config;
  1197.  import l2jcrimmerproject.gameserver.datatables.ExperienceTable;
  1198.  import l2jcrimmerproject.gameserver.datatables.NpcTable;
  1199. @@ -28,6 +27,7 @@
  1200.  import l2jcrimmerproject.gameserver.model.actor.instance.L2ClassMasterInstance;
  1201.  import l2jcrimmerproject.gameserver.model.actor.instance.L2PcInstance;
  1202.  import l2jcrimmerproject.gameserver.model.actor.instance.L2PetInstance;
  1203. +import l2jcrimmerproject.gameserver.model.entity.CTF;
  1204.  import l2jcrimmerproject.gameserver.model.entity.RecoBonus;
  1205.  import l2jcrimmerproject.gameserver.model.quest.QuestState;
  1206.  import l2jcrimmerproject.gameserver.model.stats.Stats;
  1207. @@ -268,6 +268,14 @@
  1208.             getActiveChar().sendPacket(SystemMessageId.YOU_INCREASED_YOUR_LEVEL);
  1209.            
  1210.             L2ClassMasterInstance.showQuestionMark(getActiveChar());
  1211. +           if (getActiveChar().isInFunEvent())
  1212. +           {
  1213. +               if (getActiveChar()._inEventCTF && (CTF._maxlvl == getLevel()) && !CTF._started)
  1214. +               {
  1215. +                   CTF.removePlayer(getActiveChar());
  1216. +               }
  1217. +               getActiveChar().sendMessage("Your event sign up was canceled.");
  1218. +           }
  1219.         }
  1220.        
  1221.         // Give AutoGet skills and all normal skills if Auto-Learn is activated.
  1222. Index: java/l2jcrimmerproject/Config.java
  1223. ===================================================================
  1224. --- java/l2jcrimmerproject/Config.java  (revision 12)
  1225. +++ java/l2jcrimmerproject/Config.java  (working copy)
  1226. @@ -90,6 +90,7 @@
  1227.     public static final String CRIMMER_CUSTOM_FILE = "./config/Mods/Custom.properties";
  1228.     public static final String TVT_ROUND_FILE = "./config/Events/TvTRound.properties";
  1229.     public static final String CHAOS_ENGINE_FILE = "./config/Events/ChaosEngine.properties";
  1230. +   public static final String CTF_FILE = "./config/Events/CTF.properties";
  1231.     public static final String LOGIN_CONFIGURATION_FILE = "./config/Network/LoginServer.properties";
  1232.     public static final String NPC_CONFIG_FILE = "./config/Main/NPC.properties";
  1233.     public static final String PVP_CONFIG_FILE = "./config/Main/PVP.properties";
  1234. @@ -818,6 +819,24 @@
  1235.     public static boolean ALLOW_INFO_AND_RATES_COMMAND;
  1236.     public static boolean ENABLE_REPAIR_COMMAND;
  1237.     // --------------------------------------------------
  1238. +   // CTF Variable Definitions
  1239. +   // --------------------------------------------------
  1240. +   public static boolean CTF_EVENT_ENABLED;
  1241. +   public static String[] CTF_EVENT_INTERVAL;
  1242. +   public static String CTF_EVEN_TEAMS;
  1243. +   public static boolean CTF_ALLOW_VOICE_COMMAND;
  1244. +   public static boolean CTF_ALLOW_INTERFERENCE;
  1245. +   public static boolean CTF_ALLOW_POTIONS;
  1246. +   public static boolean CTF_ALLOW_SUMMON;
  1247. +   public static boolean CTF_ON_START_REMOVE_ALL_EFFECTS;
  1248. +   public static boolean CTF_ON_START_UNSUMMON_PET;
  1249. +   public static boolean CTF_ANNOUNCE_TEAM_STATS;
  1250. +   public static boolean CTF_ANNOUNCE_REWARD;
  1251. +   public static boolean CTF_JOIN_CURSED;
  1252. +   public static boolean CTF_REVIVE_RECOVERY;
  1253. +   public static long CTF_REVIVE_DELAY;
  1254. +   public static boolean CTF_BASE_TELEPORT_FIRST;
  1255. +   // --------------------------------------------------
  1256.     // Tvt Round Variable Definitions
  1257.     // --------------------------------------------------
  1258.     public static boolean TVT_ROUND_EVENT_ENABLED;
  1259. @@ -3311,7 +3330,39 @@
  1260.                     }
  1261.                 }
  1262.                
  1263. +               // ctf
  1264. +               L2Properties CTF = new L2Properties();
  1265. +               final File ctf = new File(CHAOS_ENGINE_FILE);
  1266. +               try (InputStream is = new FileInputStream(ctf))
  1267. +               {
  1268. +                   CTF.load(is);
  1269. +               }
  1270. +               catch (Exception e)
  1271. +               {
  1272. +                   _log.log(Level.SEVERE, "Error while loading Chaos Engine settings!", e);
  1273. +               }
  1274. +               CTF_EVENT_ENABLED = Boolean.parseBoolean(CTF.getProperty("CTFEventEnabled", "false"));
  1275. +               CTF_EVENT_INTERVAL = CTF.getProperty("CTFEventInterval", "20:00").split(",");
  1276. +               CTF_EVEN_TEAMS = CTF.getProperty("CTFEvenTeams", "BALANCE");
  1277. +               CTF_ALLOW_VOICE_COMMAND = Boolean.parseBoolean(CTF.getProperty("CTFAllowVoiceCommand", "false"));
  1278. +               CTF_ALLOW_INTERFERENCE = Boolean.parseBoolean(CTF.getProperty("CTFAllowInterference", "false"));
  1279. +               CTF_ALLOW_POTIONS = Boolean.parseBoolean(CTF.getProperty("CTFAllowPotions", "false"));
  1280. +               CTF_ALLOW_SUMMON = Boolean.parseBoolean(CTF.getProperty("CTFAllowSummon", "false"));
  1281. +               CTF_ON_START_REMOVE_ALL_EFFECTS = Boolean.parseBoolean(CTF.getProperty("CTFOnStartRemoveAllEffects", "true"));
  1282. +               CTF_ON_START_UNSUMMON_PET = Boolean.parseBoolean(CTF.getProperty("CTFOnStartUnsummonPet", "true"));
  1283. +               CTF_ANNOUNCE_TEAM_STATS = Boolean.parseBoolean(CTF.getProperty("CTFAnnounceTeamStats", "false"));
  1284. +               CTF_ANNOUNCE_REWARD = Boolean.parseBoolean(CTF.getProperty("CTFAnnounceReward", "false"));
  1285. +               CTF_JOIN_CURSED = Boolean.parseBoolean(CTF.getProperty("CTFJoinWithCursedWeapon", "true"));
  1286. +               CTF_REVIVE_RECOVERY = Boolean.parseBoolean(CTF.getProperty("CTFReviveRecovery", "false"));
  1287. +               CTF_REVIVE_DELAY = Long.parseLong(CTF.getProperty("CTFReviveDelay", "20000"));
  1288. +               CTF_BASE_TELEPORT_FIRST = Boolean.parseBoolean(CTF.getProperty("CTFTeleportToBaseFirst", "false"));
  1289. +              
  1290. +               if (CTF_REVIVE_DELAY < 1000)
  1291. +               {
  1292. +                   CTF_REVIVE_DELAY = 1000; // can't be set less then 1 second
  1293. +               }
  1294.             }
  1295. +          
  1296.             // Load PvP L2Properties file (if exists)
  1297.             final File pvp = new File(PVP_CONFIG_FILE);
  1298.             L2Properties PVPSettings = new L2Properties();
  1299. @@ -4426,6 +4477,37 @@
  1300.             case "weddingdivorcecosts":
  1301.                 L2JMOD_WEDDING_DIVORCE_COSTS = Integer.parseInt(pValue);
  1302.                 break;
  1303. +           // L2JMOD CTF Event
  1304. +           case "CTFEvenTeams":
  1305. +               CTF_EVEN_TEAMS = pValue;
  1306. +               break;
  1307. +           case "CTFAllowVoiceCommand":
  1308. +               CTF_ALLOW_VOICE_COMMAND = Boolean.parseBoolean(pValue);
  1309. +               break;
  1310. +           case "CTFAllowInterference":
  1311. +               CTF_ALLOW_INTERFERENCE = Boolean.parseBoolean(pValue);
  1312. +               break;
  1313. +           case "CTFAllowPotions":
  1314. +               CTF_ALLOW_POTIONS = Boolean.parseBoolean(pValue);
  1315. +               break;
  1316. +           case "CTFAllowSummon":
  1317. +               CTF_ALLOW_SUMMON = Boolean.parseBoolean(pValue);
  1318. +               break;
  1319. +           case "CTFOnStartRemoveAllEffects":
  1320. +               CTF_ON_START_REMOVE_ALL_EFFECTS = Boolean.parseBoolean(pValue);
  1321. +               break;
  1322. +           case "CTFOnStartUnsummonPet":
  1323. +               CTF_ON_START_UNSUMMON_PET = Boolean.parseBoolean(pValue);
  1324. +               break;
  1325. +           case "CTFReviveDelay":
  1326. +               CTF_REVIVE_DELAY = Long.parseLong(pValue);
  1327. +               break;
  1328. +           case "CTFEventEnabled":
  1329. +               CTF_EVENT_ENABLED = Boolean.parseBoolean(pValue);
  1330. +               break;
  1331. +           case "CTFEventInterval":
  1332. +               CTF_EVENT_INTERVAL = pValue.split(",");
  1333. +               break;
  1334.             case "tvteventenabled":
  1335.                 TVT_EVENT_ENABLED = Boolean.parseBoolean(pValue);
  1336.                 break;
  1337. Index: java/l2jcrimmerproject/gameserver/model/skills/l2skills/L2SkillTeleport.java
  1338. ===================================================================
  1339. --- java/l2jcrimmerproject/gameserver/model/skills/l2skills/L2SkillTeleport.java    (revision 12)
  1340. +++ java/l2jcrimmerproject/gameserver/model/skills/l2skills/L2SkillTeleport.java    (working copy)
  1341. @@ -111,6 +111,12 @@
  1342.                 {
  1343.                     L2PcInstance targetChar = target.getActingPlayer();
  1344.                    
  1345. +                   // Check to see if the current player target is in CTF
  1346. +                   if (targetChar._inEventCTF)
  1347. +                   {
  1348. +                       targetChar.sendMessage("You may not use an escape skill in a Event.");
  1349. +                       continue;
  1350. +                   }
  1351.                     // Check to see if player is in a duel
  1352.                     if (targetChar.isInDuel())
  1353.                     {
  1354. Index: java/l2jcrimmerproject/gameserver/model/L2Radar.java
  1355. ===================================================================
  1356. --- java/l2jcrimmerproject/gameserver/model/L2Radar.java    (revision 12)
  1357. +++ java/l2jcrimmerproject/gameserver/model/L2Radar.java    (working copy)
  1358. @@ -19,7 +19,7 @@
  1359.  package l2jcrimmerproject.gameserver.model;
  1360.  
  1361.  import javolution.util.FastList;
  1362. -
  1363. +import l2jcrimmerproject.gameserver.ThreadPoolManager;
  1364.  import l2jcrimmerproject.gameserver.model.actor.instance.L2PcInstance;
  1365.  import l2jcrimmerproject.gameserver.network.serverpackets.RadarControl;
  1366.  
  1367. @@ -127,4 +127,40 @@
  1368.             return true;
  1369.         }
  1370.     }
  1371. +  
  1372. +   public class RadarOnPlayer implements Runnable
  1373. +   {
  1374. +       private final L2PcInstance _myTarget, _me;
  1375. +      
  1376. +       public RadarOnPlayer(L2PcInstance target, L2PcInstance me)
  1377. +       {
  1378. +           _me = me;
  1379. +           _myTarget = target;
  1380. +       }
  1381. +      
  1382. +       @Override
  1383. +       public void run()
  1384. +       {
  1385. +           try
  1386. +           {
  1387. +               if ((_me == null) || !_me.isOnline())
  1388. +               {
  1389. +                   return;
  1390. +               }
  1391. +              
  1392. +               _me.sendPacket(new RadarControl(1, 1, _me.getX(), _me.getY(), _me.getZ()));
  1393. +               if ((_myTarget == null) || !_myTarget.isOnline() || !_myTarget._haveFlagCTF)
  1394. +               {
  1395. +                   return;
  1396. +               }
  1397. +              
  1398. +               _me.sendPacket(new RadarControl(0, 1, _myTarget.getX(), _myTarget.getY(), _myTarget.getZ()));
  1399. +               ThreadPoolManager.getInstance().scheduleGeneral(new RadarOnPlayer(_myTarget, _me), 15000);
  1400. +           }
  1401. +           catch (Throwable t)
  1402. +           {
  1403. +              
  1404. +           }
  1405. +       }
  1406. +   }
  1407.  }
  1408. Index: java/l2jcrimmerproject/gameserver/model/actor/instance/L2VillageMasterInstance.java
  1409. ===================================================================
  1410. --- java/l2jcrimmerproject/gameserver/model/actor/instance/L2VillageMasterInstance.java (revision 12)
  1411. +++ java/l2jcrimmerproject/gameserver/model/actor/instance/L2VillageMasterInstance.java (working copy)
  1412. @@ -511,6 +511,11 @@
  1413.                         allowAddition = false;
  1414.                     }
  1415.                    
  1416. +                   if (player._inEventCTF)
  1417. +                   {
  1418. +                       player.sendMessage("You have already been registered in a waiting list of an event.");
  1419. +                       return;
  1420. +                   }
  1421.                     if (allowAddition)
  1422.                     {
  1423.                         if (!player.getSubClasses().isEmpty())
  1424. @@ -559,6 +564,13 @@
  1425.                     /**
  1426.                      * If the character is less than level 75 on any of their previously chosen classes then disallow them to change to their most recently added sub-class choice. Note: paramOne = classIndex
  1427.                      */
  1428. +                  
  1429. +                   if (player._inEventCTF)
  1430. +                   {
  1431. +                       player.sendMessage("You have already been registered in a waiting list of an event.");
  1432. +                       return;
  1433. +                   }
  1434. +                  
  1435.                     if (!player.getFloodProtectors().getSubclass().tryPerformAction("change class"))
  1436.                     {
  1437.                         _log.warning(L2VillageMasterInstance.class.getName() + ": Player " + player.getName() + " has performed a subclass change too fast");
  1438. Index: java/l2jcrimmerproject/gameserver/model/entity/CTF.java
  1439. ===================================================================
  1440. --- java/l2jcrimmerproject/gameserver/model/entity/CTF.java (revision 0)
  1441. +++ java/l2jcrimmerproject/gameserver/model/entity/CTF.java (working copy)
  1442. @@ -0,0 +1,3059 @@
  1443. +/*
  1444. + * This program is free software: you can redistribute it and/or modify it under
  1445. + * the terms of the GNU General Public License as published by the Free Software
  1446. + * Foundation, either version 3 of the License, or (at your option) any later
  1447. + * version.
  1448. + *
  1449. + * This program is distributed in the hope that it will be useful, but WITHOUT
  1450. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1451. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1452. + * details.
  1453. + *
  1454. + * You should have received a copy of the GNU General Public License along with
  1455. + * this program. If not, see <http://www.gnu.org/licenses/>.
  1456. + */
  1457. +package l2jcrimmerproject.gameserver.model.entity;
  1458. +
  1459. +import java.sql.Connection;
  1460. +import java.sql.PreparedStatement;
  1461. +import java.sql.ResultSet;
  1462. +import java.sql.SQLException;
  1463. +import java.util.Calendar;
  1464. +import java.util.Map;
  1465. +import java.util.Vector;
  1466. +import java.util.concurrent.ScheduledFuture;
  1467. +import java.util.logging.Logger;
  1468. +
  1469. +import javolution.text.TextBuilder;
  1470. +import javolution.util.FastMap;
  1471. +import l2jcrimmerproject.Config;
  1472. +import l2jcrimmerproject.L2DatabaseFactory;
  1473. +import l2jcrimmerproject.gameserver.Announcements;
  1474. +import l2jcrimmerproject.gameserver.ThreadPoolManager;
  1475. +import l2jcrimmerproject.gameserver.datatables.ItemTable;
  1476. +import l2jcrimmerproject.gameserver.datatables.NpcTable;
  1477. +import l2jcrimmerproject.gameserver.datatables.SpawnTable;
  1478. +import l2jcrimmerproject.gameserver.model.L2Party;
  1479. +import l2jcrimmerproject.gameserver.model.L2Party.messageType;
  1480. +import l2jcrimmerproject.gameserver.model.L2Radar;
  1481. +import l2jcrimmerproject.gameserver.model.L2Spawn;
  1482. +import l2jcrimmerproject.gameserver.model.actor.L2Summon;
  1483. +import l2jcrimmerproject.gameserver.model.actor.instance.L2PcInstance;
  1484. +import l2jcrimmerproject.gameserver.model.actor.instance.L2PetInstance;
  1485. +import l2jcrimmerproject.gameserver.model.actor.templates.L2NpcTemplate;
  1486. +import l2jcrimmerproject.gameserver.model.effects.L2Effect;
  1487. +import l2jcrimmerproject.gameserver.model.effects.L2EffectType;
  1488. +import l2jcrimmerproject.gameserver.model.itemcontainer.Inventory;
  1489. +import l2jcrimmerproject.gameserver.model.items.instance.L2ItemInstance;
  1490. +import l2jcrimmerproject.gameserver.network.SystemMessageId;
  1491. +import l2jcrimmerproject.gameserver.network.serverpackets.ActionFailed;
  1492. +import l2jcrimmerproject.gameserver.network.serverpackets.CreatureSay;
  1493. +import l2jcrimmerproject.gameserver.network.serverpackets.InventoryUpdate;
  1494. +import l2jcrimmerproject.gameserver.network.serverpackets.ItemList;
  1495. +import l2jcrimmerproject.gameserver.network.serverpackets.MagicSkillUse;
  1496. +import l2jcrimmerproject.gameserver.network.serverpackets.NpcHtmlMessage;
  1497. +import l2jcrimmerproject.gameserver.network.serverpackets.PlaySound;
  1498. +import l2jcrimmerproject.gameserver.network.serverpackets.RadarControl;
  1499. +import l2jcrimmerproject.gameserver.network.serverpackets.SocialAction;
  1500. +import l2jcrimmerproject.gameserver.network.serverpackets.SystemMessage;
  1501. +import l2jcrimmerproject.util.Rnd;
  1502. +
  1503. +public class CTF
  1504. +{
  1505. +   /** Task for event cycles<br> */
  1506. +   public CTFStartTask _task1;
  1507. +  
  1508. +   private CTF()
  1509. +   {
  1510. +       if (Config.CTF_EVENT_ENABLED)
  1511. +       {
  1512. +           loadData();
  1513. +           this.scheduleCTFEventStart();
  1514. +           _log.warning("CTF Event Engine: Started.");
  1515. +       }
  1516. +       else
  1517. +       {
  1518. +           _log.warning("CTF Event Engine: Disabled by config.");
  1519. +       }
  1520. +   }
  1521. +  
  1522. +   /**
  1523. +    * Initialize new/Returns the one and only instance<br>
  1524. +    * <br>
  1525. +    * @return CTF<br>
  1526. +    */
  1527. +   public static CTF getInstance()
  1528. +   {
  1529. +       return SingletonHolder._instance;
  1530. +   }
  1531. +  
  1532. +   /**
  1533. +    * Starts CTFStartTask
  1534. +    */
  1535. +   public void scheduleCTFEventStart()
  1536. +   {
  1537. +       try
  1538. +       {
  1539. +           Calendar currentTime = Calendar.getInstance();
  1540. +           Calendar nextStartTime = null;
  1541. +           Calendar testStartTime = null;
  1542. +           for (String timeOfDay : Config.CTF_EVENT_INTERVAL)
  1543. +           {
  1544. +               // Creating a Calendar object from the specified interval value
  1545. +               testStartTime = Calendar.getInstance();
  1546. +               testStartTime.setLenient(true);
  1547. +               String[] splitTimeOfDay = timeOfDay.split(":");
  1548. +               testStartTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(splitTimeOfDay[0]));
  1549. +               testStartTime.set(Calendar.MINUTE, Integer.parseInt(splitTimeOfDay[1]));
  1550. +               // If the date is in the past, make it the next day (Example: Checking for "1:00", when the time is 23:57.)
  1551. +               if (testStartTime.getTimeInMillis() < currentTime.getTimeInMillis())
  1552. +               {
  1553. +                   testStartTime.add(Calendar.DAY_OF_MONTH, 1);
  1554. +               }
  1555. +               // Check for the test date to be the minimum (smallest in the specified list)
  1556. +               if ((nextStartTime == null) || (testStartTime.getTimeInMillis() < nextStartTime.getTimeInMillis()))
  1557. +               {
  1558. +                   nextStartTime = testStartTime;
  1559. +               }
  1560. +           }
  1561. +           _task1 = new CTFStartTask(nextStartTime.getTimeInMillis());
  1562. +           ThreadPoolManager.getInstance().executeTask(_task1);
  1563. +       }
  1564. +       catch (Exception e)
  1565. +       {
  1566. +           _log.warning("CTFEventEngine: Error figuring out a start time. Check CTFEventInterval in config file.");
  1567. +       }
  1568. +   }
  1569. +  
  1570. +   public void skipDelay()
  1571. +   {
  1572. +       if (_task1.nextRun.cancel(false))
  1573. +       {
  1574. +           _task1.setStartTime(System.currentTimeMillis());
  1575. +           ThreadPoolManager.getInstance().executeTask(_task1);
  1576. +       }
  1577. +   }
  1578. +  
  1579. +   /**
  1580. +    * Class forCTFT cycles
  1581. +    */
  1582. +   class CTFStartTask implements Runnable
  1583. +   {
  1584. +       private long _startTime;
  1585. +       public ScheduledFuture<?> nextRun;
  1586. +      
  1587. +       public CTFStartTask(long startTime)
  1588. +       {
  1589. +           _startTime = startTime;
  1590. +       }
  1591. +      
  1592. +       public void setStartTime(long startTime)
  1593. +       {
  1594. +           _startTime = startTime;
  1595. +       }
  1596. +      
  1597. +       /**
  1598. +        * @see java.lang.Runnable#run()
  1599. +        */
  1600. +       @Override
  1601. +       public void run()
  1602. +       {
  1603. +           int delay = (int) Math.round((_startTime - System.currentTimeMillis()) / 1000.0);
  1604. +          
  1605. +           int nextMsg = 0;
  1606. +           if (delay > 3600)
  1607. +           {
  1608. +               nextMsg = delay - 3600;
  1609. +           }
  1610. +           else if (delay > 1800)
  1611. +           {
  1612. +               nextMsg = delay - 1800;
  1613. +           }
  1614. +           else if (delay > 900)
  1615. +           {
  1616. +               nextMsg = delay - 900;
  1617. +           }
  1618. +           else if (delay > 600)
  1619. +           {
  1620. +               nextMsg = delay - 600;
  1621. +           }
  1622. +           else if (delay > 300)
  1623. +           {
  1624. +               nextMsg = delay - 300;
  1625. +           }
  1626. +           else if (delay > 60)
  1627. +           {
  1628. +               nextMsg = delay - 60;
  1629. +           }
  1630. +           else if (delay > 5)
  1631. +           {
  1632. +               nextMsg = delay - 5;
  1633. +           }
  1634. +           else if (delay > 0)
  1635. +           {
  1636. +               nextMsg = delay;
  1637. +           }
  1638. +           else
  1639. +           {
  1640. +               // start
  1641. +              
  1642. +               autoEvent();
  1643. +               _task1.setStartTime(System.currentTimeMillis() + (60000L * 225));
  1644. +               ThreadPoolManager.getInstance().executeTask(_task1);
  1645. +           }
  1646. +          
  1647. +           if (delay > 0)
  1648. +           {
  1649. +               nextRun = ThreadPoolManager.getInstance().scheduleGeneral(this, nextMsg * 1000);
  1650. +           }
  1651. +       }
  1652. +   }
  1653. +  
  1654. +   public final static Logger _log = Logger.getLogger(CTF.class.getName());
  1655. +   private static int _FlagNPC = 35062, _FLAG_IN_HAND_ITEM_ID = 6718;
  1656. +   public static String _eventName = new String(), _eventDesc = new String(), _topTeam = new String(), _joiningLocationName = new String();
  1657. +   public static Vector<String> _teams = new Vector<>(), _savePlayers = new Vector<>(), _savePlayerTeams = new Vector<>();
  1658. +   public static Vector<L2PcInstance> _players = new Vector<>(), _playersShuffle = new Vector<>();
  1659. +   public static Vector<Integer> _teamPlayersCount = new Vector<>(), _teamColors = new Vector<>(), _teamsX = new Vector<>(), _teamsY = new Vector<>(), _teamsZ = new Vector<>(), _teamsBaseX = new Vector<>(), _teamsBaseY = new Vector<>(), _teamsBaseZ = new Vector<>();
  1660. +   public static boolean _joining = false, _teleport = false, _started = false, _sitForced = false;
  1661. +   public static L2Spawn _npcSpawn;
  1662. +   public static int _npcId = 0, _npcX = 0, _npcY = 0, _npcZ = 0, _npcHeading = 0, _rewardId = 0, _rewardAmount = 0, _minlvl = 0, _maxlvl = 0, _joinTime = 0, _eventTime = 0, _minPlayers = 0, _maxPlayers = 0;
  1663. +   public static long _flagHoldTime = 0;
  1664. +   public static Vector<Integer> _teamPointsCount = new Vector<>();
  1665. +   public static Vector<Integer> _flagIds = new Vector<>(), _flagsX = new Vector<>(), _flagsY = new Vector<>(), _flagsZ = new Vector<>();
  1666. +   public static Vector<L2Spawn> _flagSpawns = new Vector<>(), _throneSpawns = new Vector<>();
  1667. +   public static Vector<Boolean> _flagsTaken = new Vector<>(), _flagsNotRemoved = new Vector<>();
  1668. +   public static int _topScore = 0, eventCenterX = 0, eventCenterY = 0, eventCenterZ = 0, eventOffset = 0;
  1669. +   public static Map<String, Integer> _playerScores = new FastMap<>();
  1670. +  
  1671. +   public static void showFlagHtml(L2PcInstance eventPlayer, String objectId, String teamName)
  1672. +   {
  1673. +       if (eventPlayer == null)
  1674. +       {
  1675. +           return;
  1676. +       }
  1677. +      
  1678. +       try
  1679. +       {
  1680. +           NpcHtmlMessage adminReply = new NpcHtmlMessage(0);
  1681. +          
  1682. +           TextBuilder replyMSG = new TextBuilder();
  1683. +          
  1684. +           replyMSG.append("<html><body><center>");
  1685. +           replyMSG.append("CTF Flag<br><br>");
  1686. +           replyMSG.append("<font color=\"00FF00\">" + teamName + "'s Flag</font><br>");
  1687. +           if ((eventPlayer._teamNameCTF != null) && eventPlayer._teamNameCTF.equals(teamName))
  1688. +           {
  1689. +               replyMSG.append("<font color=\"LEVEL\">This is your Flag</font><br>");
  1690. +           }
  1691. +           else
  1692. +           {
  1693. +               replyMSG.append("<font color=\"LEVEL\">Enemy Flag!</font><br>");
  1694. +           }
  1695. +           if (_started)
  1696. +           {
  1697. +               processInFlagRange(eventPlayer);
  1698. +           }
  1699. +           else
  1700. +           {
  1701. +               replyMSG.append("CTF match is not in progress yet.<br>Wait for a GM to start the event<br>");
  1702. +           }
  1703. +           replyMSG.append("</center></body></html>");
  1704. +           adminReply.setHtml(replyMSG.toString());
  1705. +           eventPlayer.sendPacket(adminReply);
  1706. +       }
  1707. +       catch (Exception e)
  1708. +       {
  1709. +           _log.warning("" + "CTF Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception: " + e.getStackTrace());
  1710. +       }
  1711. +   }
  1712. +  
  1713. +   public static void CheckRestoreFlags()
  1714. +   {
  1715. +       Vector<Integer> teamsTakenFlag = new Vector<>();
  1716. +       try
  1717. +       {
  1718. +           for (L2PcInstance player : _players)
  1719. +           { // if there's a player with a flag
  1720. +               // add the index of the team who's FLAG WAS TAKEN to the list
  1721. +               if (player != null)
  1722. +               {
  1723. +                   if (!player.isOnline() && player._haveFlagCTF)// logged off with a flag in his hands
  1724. +                   {
  1725. +                       AnnounceToPlayers(false, "CTF Event: " + player.getName() + " logged off with a CTF flag!");
  1726. +                       player._haveFlagCTF = false;
  1727. +                       if (_teams.indexOf(player._teamNameHaveFlagCTF) >= 0)
  1728. +                       {
  1729. +                           if (_flagsTaken.get(_teams.indexOf(player._teamNameHaveFlagCTF)))
  1730. +                           {
  1731. +                               _flagsTaken.set(_teams.indexOf(player._teamNameHaveFlagCTF), false);
  1732. +                               spawnFlag(player._teamNameHaveFlagCTF);
  1733. +                               AnnounceToPlayers(false, "CTF Event: " + player._teamNameHaveFlagCTF + " flag now returned to place.");
  1734. +                           }
  1735. +                       }
  1736. +                       removeFlagFromPlayer(player);
  1737. +                       player._teamNameHaveFlagCTF = null;
  1738. +                       return;
  1739. +                   }
  1740. +                   else if (player._haveFlagCTF)
  1741. +                   {
  1742. +                       teamsTakenFlag.add(_teams.indexOf(player._teamNameHaveFlagCTF));
  1743. +                   }
  1744. +               }
  1745. +           }
  1746. +           // Go over the list of ALL teams
  1747. +           for (String team : _teams)
  1748. +           {
  1749. +               if (team == null)
  1750. +               {
  1751. +                   continue;
  1752. +               }
  1753. +               int index = _teams.indexOf(team);
  1754. +               if (!teamsTakenFlag.contains(index))
  1755. +               {
  1756. +                   if (_flagsTaken.get(index))
  1757. +                   {
  1758. +                       _flagsTaken.set(index, false);
  1759. +                       spawnFlag(team);
  1760. +                       AnnounceToPlayers(false, "CTF Event: " + team + " flag returned due to player error.");
  1761. +                   }
  1762. +               }
  1763. +           }
  1764. +           // Check if a player ran away from the event holding a flag:
  1765. +           for (L2PcInstance player : _players)
  1766. +           {
  1767. +               if ((player != null) && player._haveFlagCTF)
  1768. +               {
  1769. +                   if (isOutsideCTFArea(player))
  1770. +                   {
  1771. +                       AnnounceToPlayers(false, "CTF Event: " + player.getName() + " escaped from the event holding a flag!");
  1772. +                       player._haveFlagCTF = false;
  1773. +                       if (_teams.indexOf(player._teamNameHaveFlagCTF) >= 0)
  1774. +                       {
  1775. +                           if (_flagsTaken.get(_teams.indexOf(player._teamNameHaveFlagCTF)))
  1776. +                           {
  1777. +                               _flagsTaken.set(_teams.indexOf(player._teamNameHaveFlagCTF), false);
  1778. +                               spawnFlag(player._teamNameHaveFlagCTF);
  1779. +                               AnnounceToPlayers(false, "CTF Event: " + player._teamNameHaveFlagCTF + " flag now returned to place.");
  1780. +                           }
  1781. +                       }
  1782. +                       removeFlagFromPlayer(player);
  1783. +                       player._teamNameHaveFlagCTF = null;
  1784. +                       if (Config.CTF_BASE_TELEPORT_FIRST)
  1785. +                       {
  1786. +                           player.teleToLocation(_teamsBaseX.get(_teams.indexOf(player._teamNameCTF)), _teamsBaseY.get(_teams.indexOf(player._teamNameCTF)), _teamsBaseZ.get(_teams.indexOf(player._teamNameCTF)));
  1787. +                          
  1788. +                           ThreadPoolManager.getInstance().scheduleGeneral(new BaseTeleportTask(player, false), 10000);
  1789. +                          
  1790. +                           player.sendMessage("You have been returned to your base. You will be sent into battle in 10 seconds.");
  1791. +                       }
  1792. +                       else
  1793. +                       {
  1794. +                           player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ.get(_teams.indexOf(player._teamNameCTF)));
  1795. +                           player.sendMessage("You have been returned to your team spawn.");
  1796. +                       }
  1797. +                       return;
  1798. +                   }
  1799. +               }
  1800. +           }
  1801. +       }
  1802. +       catch (Exception e)
  1803. +       {
  1804. +           _log.warning("CTF.restoreFlags() Error:" + e.toString());
  1805. +       }
  1806. +   }
  1807. +  
  1808. +   public static void kickPlayerFromCTf(L2PcInstance playerToKick)
  1809. +   {
  1810. +       if (playerToKick == null)
  1811. +       {
  1812. +           return;
  1813. +       }
  1814. +      
  1815. +       if (_joining)
  1816. +       {
  1817. +           _playersShuffle.remove(playerToKick);
  1818. +           _players.remove(playerToKick);
  1819. +           playerToKick._inEventCTF = false;
  1820. +           playerToKick._teamNameCTF = new String();
  1821. +       }
  1822. +       if (_started || _teleport)
  1823. +       {
  1824. +           _playersShuffle.remove(playerToKick);
  1825. +           playerToKick._inEventCTF = false;
  1826. +           removePlayer(playerToKick);
  1827. +           if (playerToKick.isOnline())
  1828. +           {
  1829. +               playerToKick.getAppearance().setNameColor(playerToKick._originalNameColorCTF);
  1830. +               playerToKick.setKarma(playerToKick._originalKarmaCTF);
  1831. +               playerToKick.setTitle(playerToKick._originalTitleCTF);
  1832. +               playerToKick.broadcastUserInfo();
  1833. +               playerToKick.sendMessage("You have been kicked from the CTF.");
  1834. +               playerToKick.teleToLocation(_npcX, _npcY, _npcZ, false);
  1835. +           }
  1836. +       }
  1837. +   }
  1838. +  
  1839. +   public static void AnnounceToPlayers(Boolean toall, String announce)
  1840. +   {
  1841. +       if (toall)
  1842. +       {
  1843. +           Announcements.getInstance().announceToAll(announce);
  1844. +       }
  1845. +       else
  1846. +       {
  1847. +           CreatureSay cs = new CreatureSay(0, 2, "", "Announcements : " + announce);
  1848. +           if ((_players != null) && !_players.isEmpty())
  1849. +           {
  1850. +               for (L2PcInstance player : _players)
  1851. +               {
  1852. +                   if ((player != null) && player.isOnline())
  1853. +                   {
  1854. +                       player.sendPacket(cs);
  1855. +                   }
  1856. +               }
  1857. +           }
  1858. +       }
  1859. +   }
  1860. +  
  1861. +   public static void Started(L2PcInstance player)
  1862. +   {
  1863. +       player._teamNameHaveFlagCTF = null;
  1864. +       player._haveFlagCTF = false;
  1865. +   }
  1866. +  
  1867. +   public static void StartEvent()
  1868. +   {
  1869. +       for (L2PcInstance player : _players)
  1870. +       {
  1871. +           if (player != null)
  1872. +           {
  1873. +               player._teamNameHaveFlagCTF = null;
  1874. +               player._haveFlagCTF = false;
  1875. +           }
  1876. +       }
  1877. +   }
  1878. +  
  1879. +   public static void addFlagToPlayer(L2PcInstance _player)
  1880. +   {
  1881. +       // remove items from the player hands (right, left, both)
  1882. +       // This is NOT a BUG, I don't want them to see the icon they have 8D
  1883. +       L2ItemInstance wpn = _player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  1884. +       L2ItemInstance wpn2 = _player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  1885. +       if (wpn != null)
  1886. +       {
  1887. +           _player.getInventory().unEquipItemInBodySlotAndRecord(wpn.getItem().getBodyPart());
  1888. +           if (wpn2 != null)
  1889. +           {
  1890. +               _player.getInventory().unEquipItemInBodySlotAndRecord(wpn2.getItem().getBodyPart());
  1891. +           }
  1892. +       }
  1893. +       // add the flag in his hands
  1894. +       _player.getInventory().equipItem(ItemTable.getInstance().createItem("", CTF._FLAG_IN_HAND_ITEM_ID, 1, _player, null));
  1895. +       _player.broadcastPacket(new SocialAction(_player.getObjectId(), 16)); // amazing glow
  1896. +       _player._haveFlagCTF = true;
  1897. +       _player.broadcastUserInfo();
  1898. +       CreatureSay cs = new CreatureSay(_player.getObjectId(), 15, ":", "You got it! Run back! ::"); // 8D
  1899. +       _player.sendPacket(cs);
  1900. +      
  1901. +       // Start the flag holding timer
  1902. +       _flagsNotRemoved.set(_teams.indexOf(_player._teamNameCTF), true);
  1903. +       flagHoldTimer(_player, _flagHoldTime);
  1904. +      
  1905. +       // If player is invisible, make them visible
  1906. +       if (_player.getAppearance().getInvisible())
  1907. +       {
  1908. +           @SuppressWarnings("unused")
  1909. +           L2Effect eInvisible = _player.getFirstEffect(L2EffectType.HIDE);
  1910. +       }
  1911. +   }
  1912. +  
  1913. +   public static void removeFlagFromPlayer(L2PcInstance player)
  1914. +   {
  1915. +       L2ItemInstance wpn = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  1916. +       player._haveFlagCTF = false;
  1917. +      
  1918. +       // Reset boolean of whether the holder's flag has not been removed yet to false and kill the flagHoldTimer thread
  1919. +       _flagsNotRemoved.set(_teams.indexOf(player._teamNameCTF), false);
  1920. +      
  1921. +       if (wpn != null)
  1922. +       {
  1923. +           L2ItemInstance[] unequiped = player.getInventory().unEquipItemInBodySlotAndRecord(wpn.getItem().getBodyPart());
  1924. +           player.getInventory().destroyItemByItemId("", CTF._FLAG_IN_HAND_ITEM_ID, 1, player, null);
  1925. +           InventoryUpdate iu = new InventoryUpdate();
  1926. +           for (L2ItemInstance element : unequiped)
  1927. +           {
  1928. +               iu.addModifiedItem(element);
  1929. +           }
  1930. +           player.sendPacket(iu);
  1931. +           player.sendPacket(new ItemList(player, true)); // get your weapon back now ...
  1932. +           player.abortAttack();
  1933. +           player.broadcastUserInfo();
  1934. +       }
  1935. +       else
  1936. +       {
  1937. +           player.getInventory().destroyItemByItemId("", CTF._FLAG_IN_HAND_ITEM_ID, 1, player, null);
  1938. +           player.sendPacket(new ItemList(player, true)); // get your weapon back now ...
  1939. +           player.abortAttack();
  1940. +           player.broadcastUserInfo();
  1941. +       }
  1942. +   }
  1943. +  
  1944. +   public static void setTeamFlag(String teamName, L2PcInstance activeChar)
  1945. +   {
  1946. +       int index = _teams.indexOf(teamName);
  1947. +      
  1948. +       if (index == -1)
  1949. +       {
  1950. +           return;
  1951. +       }
  1952. +       addOrSet(_teams.indexOf(teamName), null, false, _FlagNPC, activeChar.getX(), activeChar.getY(), activeChar.getZ());
  1953. +   }
  1954. +  
  1955. +   public static void setTeamFlag(String teamName, int x, int y, int z)
  1956. +   {
  1957. +       int index = _teams.indexOf(teamName);
  1958. +      
  1959. +       if (index == -1)
  1960. +       {
  1961. +           return;
  1962. +       }
  1963. +       addOrSet(_teams.indexOf(teamName), null, false, _FlagNPC, x, y, z);
  1964. +   }
  1965. +  
  1966. +   public static void spawnAllFlags()
  1967. +   {
  1968. +       while (_flagSpawns.size() < _teams.size())
  1969. +       {
  1970. +           _flagSpawns.add(null);
  1971. +       }
  1972. +       while (_throneSpawns.size() < _teams.size())
  1973. +       {
  1974. +           _throneSpawns.add(null);
  1975. +       }
  1976. +       for (String team : _teams)
  1977. +       {
  1978. +           int index = _teams.indexOf(team);
  1979. +           L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_flagIds.get(index));
  1980. +           L2NpcTemplate throne = NpcTable.getInstance().getTemplate(32027);
  1981. +           try
  1982. +           {
  1983. +               // spawn throne
  1984. +               _throneSpawns.set(index, new L2Spawn(throne));
  1985. +               _throneSpawns.get(index).setLocx(_flagsX.get(index));
  1986. +               _throneSpawns.get(index).setLocy(_flagsY.get(index));
  1987. +               _throneSpawns.get(index).setLocz(_flagsZ.get(index) - 10);
  1988. +               _throneSpawns.get(index).setAmount(1);
  1989. +               _throneSpawns.get(index).setHeading(0);
  1990. +               _throneSpawns.get(index).setRespawnDelay(1);
  1991. +               SpawnTable.getInstance().addNewSpawn(_throneSpawns.get(index), false);
  1992. +               _throneSpawns.get(index).init();
  1993. +               _throneSpawns.get(index).getLastSpawn().getStatus().setCurrentHp(999999999);
  1994. +               _throneSpawns.get(index).getLastSpawn().decayMe();
  1995. +               _throneSpawns.get(index).getLastSpawn().spawnMe(_throneSpawns.get(index).getLastSpawn().getX(), _throneSpawns.get(index).getLastSpawn().getY(), _throneSpawns.get(index).getLastSpawn().getZ());
  1996. +               _throneSpawns.get(index).getLastSpawn().setTitle(team + " Throne");
  1997. +               _throneSpawns.get(index).getLastSpawn().broadcastPacket(new MagicSkillUse(_throneSpawns.get(index).getLastSpawn(), _throneSpawns.get(index).getLastSpawn(), 1036, 1, 5500, 1));
  1998. +               _throneSpawns.get(index).getLastSpawn()._isCTF_throneSpawn = true;
  1999. +              
  2000. +               // spawn flag
  2001. +               _flagSpawns.set(index, new L2Spawn(tmpl));
  2002. +               _flagSpawns.get(index).setLocx(_flagsX.get(index));
  2003. +               _flagSpawns.get(index).setLocy(_flagsY.get(index));
  2004. +               _flagSpawns.get(index).setLocz(_flagsZ.get(index));
  2005. +               _flagSpawns.get(index).setAmount(1);
  2006. +               _flagSpawns.get(index).setHeading(0);
  2007. +               _flagSpawns.get(index).setRespawnDelay(1);
  2008. +               SpawnTable.getInstance().addNewSpawn(_flagSpawns.get(index), false);
  2009. +               _flagSpawns.get(index).init();
  2010. +               _flagSpawns.get(index).getLastSpawn().getStatus().setCurrentHp(999999999);
  2011. +               _flagSpawns.get(index).getLastSpawn().setTitle(team + "'s Flag");
  2012. +               _flagSpawns.get(index).getLastSpawn()._CTF_FlagTeamName = team;
  2013. +               _flagSpawns.get(index).getLastSpawn().decayMe();
  2014. +               _flagSpawns.get(index).getLastSpawn().spawnMe(_flagSpawns.get(index).getLastSpawn().getX(), _flagSpawns.get(index).getLastSpawn().getY(), _flagSpawns.get(index).getLastSpawn().getZ());
  2015. +               _flagSpawns.get(index).getLastSpawn()._isCTF_Flag = true;
  2016. +               if (index == (_teams.size() - 1))
  2017. +               {
  2018. +                   calculateOutSideOfCTF(); // sets event boundaries so players don't run with the flag.
  2019. +               }
  2020. +           }
  2021. +           catch (Exception e)
  2022. +           {
  2023. +               _log.warning("CTF Engine[spawnAllFlags()]: exception: " + e.getStackTrace());
  2024. +           }
  2025. +       }
  2026. +   }
  2027. +  
  2028. +   public static void processTopTeam()
  2029. +   {
  2030. +      
  2031. +       _topTeam = null;
  2032. +       for (String team : _teams)
  2033. +       {
  2034. +           if ((teamPointsCount(team) == _topScore) && (_topScore > 0))
  2035. +           {
  2036. +               _topTeam = null;
  2037. +           }
  2038. +           if (teamPointsCount(team) > _topScore)
  2039. +           {
  2040. +               _topTeam = team;
  2041. +               _topScore = teamPointsCount(team);
  2042. +           }
  2043. +       }
  2044. +       if (_topScore <= 0)
  2045. +       {
  2046. +           AnnounceToPlayers(true, "CTF Event: No flags taken.");
  2047. +       }
  2048. +       else
  2049. +       {
  2050. +           if (_topTeam == null)
  2051. +           {
  2052. +               AnnounceToPlayers(true, "CTF Event: Maximum flags taken : " + _topScore + " flags! No one won.");
  2053. +           }
  2054. +           else
  2055. +           {
  2056. +               AnnounceToPlayers(true, "CTF Event: Team " + _topTeam + " wins the match, with " + _topScore + " flags taken!");
  2057. +               rewardTeam(_topTeam);
  2058. +           }
  2059. +       }
  2060. +   }
  2061. +  
  2062. +   public static void unspawnAllFlags()
  2063. +   {
  2064. +       try
  2065. +       {
  2066. +           if ((_throneSpawns == null) || (_flagSpawns == null) || (_teams == null))
  2067. +           {
  2068. +               return;
  2069. +           }
  2070. +           for (String team : _teams)
  2071. +           {
  2072. +               int index = _teams.indexOf(team);
  2073. +               if (_throneSpawns.get(index) != null)
  2074. +               {
  2075. +                   _throneSpawns.get(index).getLastSpawn().deleteMe();
  2076. +                   _throneSpawns.get(index).stopRespawn();
  2077. +                   SpawnTable.getInstance().deleteSpawn(_throneSpawns.get(index), true);
  2078. +               }
  2079. +               if (_flagSpawns.get(index) != null)
  2080. +               {
  2081. +                   _flagSpawns.get(index).getLastSpawn().deleteMe();
  2082. +                   _flagSpawns.get(index).stopRespawn();
  2083. +                   SpawnTable.getInstance().deleteSpawn(_flagSpawns.get(index), true);
  2084. +               }
  2085. +           }
  2086. +           _throneSpawns.removeAllElements();
  2087. +       }
  2088. +       catch (Throwable t)
  2089. +       {
  2090. +           _log.warning("CTF Engine[unspawnAllFlags()]: exception: " + t.getStackTrace());
  2091. +       }
  2092. +   }
  2093. +  
  2094. +   private static void unspawnFlag(String teamName)
  2095. +   {
  2096. +       int index = _teams.indexOf(teamName);
  2097. +      
  2098. +       _flagSpawns.get(index).getLastSpawn().deleteMe();
  2099. +       _flagSpawns.get(index).stopRespawn();
  2100. +       SpawnTable.getInstance().deleteSpawn(_flagSpawns.get(index), true);
  2101. +   }
  2102. +  
  2103. +   public static void spawnFlag(String teamName)
  2104. +   {
  2105. +       int index = _teams.indexOf(teamName);
  2106. +       L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_flagIds.get(index));
  2107. +      
  2108. +       try
  2109. +       {
  2110. +           _flagSpawns.set(index, new L2Spawn(tmpl));
  2111. +          
  2112. +           _flagSpawns.get(index).setLocx(_flagsX.get(index));
  2113. +           _flagSpawns.get(index).setLocy(_flagsY.get(index));
  2114. +           _flagSpawns.get(index).setLocz(_flagsZ.get(index));
  2115. +           _flagSpawns.get(index).setAmount(1);
  2116. +           _flagSpawns.get(index).setHeading(0);
  2117. +           _flagSpawns.get(index).setRespawnDelay(1);
  2118. +          
  2119. +           SpawnTable.getInstance().addNewSpawn(_flagSpawns.get(index), false);
  2120. +          
  2121. +           _flagSpawns.get(index).init();
  2122. +           _flagSpawns.get(index).getLastSpawn().getStatus().setCurrentHp(999999999);
  2123. +           _flagSpawns.get(index).getLastSpawn().setTitle(teamName + "'s Flag");
  2124. +           _flagSpawns.get(index).getLastSpawn()._CTF_FlagTeamName = teamName;
  2125. +           _flagSpawns.get(index).getLastSpawn()._isCTF_Flag = true;
  2126. +           _flagSpawns.get(index).getLastSpawn().decayMe();
  2127. +           _flagSpawns.get(index).getLastSpawn().spawnMe(_flagSpawns.get(index).getLastSpawn().getX(), _flagSpawns.get(index).getLastSpawn().getY(), _flagSpawns.get(index).getLastSpawn().getZ());
  2128. +       }
  2129. +       catch (Exception e)
  2130. +       {
  2131. +           _log.warning("CTF Engine[spawnFlag(" + teamName + ")]: exception: " + e.getStackTrace());
  2132. +       }
  2133. +   }
  2134. +  
  2135. +   public static boolean InRangeOfFlag(L2PcInstance _player, int flagIndex, int offset)
  2136. +   {
  2137. +       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)))
  2138. +       {
  2139. +           return true;
  2140. +       }
  2141. +       return false;
  2142. +   }
  2143. +  
  2144. +   public static void processInFlagRange(L2PcInstance _player)
  2145. +   {
  2146. +       try
  2147. +       {
  2148. +           CheckRestoreFlags();
  2149. +           for (String team : _teams)
  2150. +           {
  2151. +               if (team.equals(_player._teamNameCTF))
  2152. +               {
  2153. +                   int indexOwn = _teams.indexOf(_player._teamNameCTF);
  2154. +                  
  2155. +                   // if player is near his team flag holding the enemy flag
  2156. +                   if (InRangeOfFlag(_player, indexOwn, 100) && !_flagsTaken.get(indexOwn) && _player._haveFlagCTF)
  2157. +                   {
  2158. +                       int indexEnemy = _teams.indexOf(_player._teamNameHaveFlagCTF);
  2159. +                       // return enemy flag to place
  2160. +                       _flagsTaken.set(indexEnemy, false);
  2161. +                       spawnFlag(_player._teamNameHaveFlagCTF);
  2162. +                       // remove the flag from this player
  2163. +                       _player.broadcastPacket(new SocialAction(_player.getObjectId(), 16)); // amazing glow
  2164. +                       _player.broadcastUserInfo();
  2165. +                       _player.broadcastPacket(new SocialAction(_player.getObjectId(), 3)); // Victory
  2166. +                       _player.broadcastUserInfo();
  2167. +                       removeFlagFromPlayer(_player);
  2168. +                       _teamPointsCount.set(indexOwn, teamPointsCount(team) + 1);
  2169. +                       _player.broadcastPacket(new PlaySound(0, "ItemSound.quest_finish", 1, _player.getObjectId(), _player.getX(), _player.getY(), _player.getZ()));
  2170. +                       _player.broadcastUserInfo();
  2171. +                       _playerScores.put(_player.getName(), playerScoresCount(_player.getName()) + 1);
  2172. +                       AnnounceToPlayers(false, "CTF Event: " + _player.getName() + " scores for " + _player._teamNameCTF + " team.");
  2173. +                       AnnounceToPlayers(false, "CTF Event: Scores - " + _teams.get(0) + ": " + teamPointsCount(_teams.get(0)) + " " + _teams.get(1) + ": " + teamPointsCount(_teams.get(1)));
  2174. +                   }
  2175. +               }
  2176. +               else
  2177. +               {
  2178. +                   int indexEnemy = _teams.indexOf(team);
  2179. +                   // if the player is near a enemy flag
  2180. +                   if (InRangeOfFlag(_player, indexEnemy, 100) && !_flagsTaken.get(indexEnemy) && !_player._haveFlagCTF && !_player.isDead())
  2181. +                   {
  2182. +                       if (_player.isRidingStrider() || _player.isFlying())
  2183. +                       {
  2184. +                           _player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_CANNOT_BOARD_AN_AIRSHIP_WHILE_A_PET_OR_A_SERVITOR_IS_SUMMONED));
  2185. +                           break;
  2186. +                       }
  2187. +                      
  2188. +                       _flagsTaken.set(indexEnemy, true);
  2189. +                       unspawnFlag(team);
  2190. +                       _player._teamNameHaveFlagCTF = team;
  2191. +                       addFlagToPlayer(_player);
  2192. +                       _player.broadcastUserInfo();
  2193. +                       _player._haveFlagCTF = true;
  2194. +                       AnnounceToPlayers(false, "CTF Event: " + team + " flag taken by " + _player.getName() + "...");
  2195. +                       pointTeamTo(_player, team);
  2196. +                       break;
  2197. +                   }
  2198. +               }
  2199. +           }
  2200. +       }
  2201. +       catch (Exception e)
  2202. +       {
  2203. +           e.printStackTrace();
  2204. +       }
  2205. +   }
  2206. +  
  2207. +   public static void pointTeamTo(L2PcInstance hasFlag, String ourFlag)
  2208. +   {
  2209. +       try
  2210. +       {
  2211. +           for (L2PcInstance player : _players)
  2212. +           {
  2213. +               if ((player != null) && player.isOnline())
  2214. +               {
  2215. +                   if (player._teamNameCTF.equals(ourFlag))
  2216. +                   {
  2217. +                       player.sendMessage(hasFlag.getName() + " took your flag!");
  2218. +                       if (player._haveFlagCTF)
  2219. +                       {
  2220. +                           player.sendMessage("You can not return the flag to headquarters, until your flag is returned to it's place.");
  2221. +                           player.sendPacket(new RadarControl(1, 1, player.getX(), player.getY(), player.getZ()));
  2222. +                       }
  2223. +                       else
  2224. +                       {
  2225. +                           player.sendPacket(new RadarControl(0, 1, hasFlag.getX(), hasFlag.getY(), hasFlag.getZ()));
  2226. +                           L2Radar rdr = new L2Radar(player);
  2227. +                           L2Radar.RadarOnPlayer radar = rdr.new RadarOnPlayer(hasFlag, player);
  2228. +                           ThreadPoolManager.getInstance().scheduleGeneral(radar, 10000 + Rnd.get(30000));
  2229. +                       }
  2230. +                   }
  2231. +               }
  2232. +           }
  2233. +       }
  2234. +       catch (Throwable t)
  2235. +       {
  2236. +       }
  2237. +   }
  2238. +  
  2239. +   private static int playerScoresCount(String player)
  2240. +   {
  2241. +       if (_playerScores.containsKey(player))
  2242. +       {
  2243. +           return _playerScores.get(player);
  2244. +       }
  2245. +       else if (player != null)
  2246. +       {
  2247. +           _playerScores.put(player, 0);
  2248. +           return _playerScores.get(player);
  2249. +       }
  2250. +       else
  2251. +       {
  2252. +           return 0;
  2253. +       }
  2254. +   }
  2255. +  
  2256. +   public static int teamPointsCount(String teamName)
  2257. +   {
  2258. +       int index = _teams.indexOf(teamName);
  2259. +      
  2260. +       if (index == -1)
  2261. +       {
  2262. +           return -1;
  2263. +       }
  2264. +      
  2265. +       return _teamPointsCount.get(index);
  2266. +   }
  2267. +  
  2268. +   public static void setTeamPointsCount(String teamName, int teamPointCount)
  2269. +   {
  2270. +       int index = _teams.indexOf(teamName);
  2271. +      
  2272. +       if (index == -1)
  2273. +       {
  2274. +           return;
  2275. +       }
  2276. +      
  2277. +       _teamPointsCount.set(index, teamPointCount);
  2278. +   }
  2279. +  
  2280. +   public static int teamPlayersCount(String teamName)
  2281. +   {
  2282. +       int index = _teams.indexOf(teamName);
  2283. +      
  2284. +       if (index == -1)
  2285. +       {
  2286. +           return -1;
  2287. +       }
  2288. +      
  2289. +       return _teamPlayersCount.get(index);
  2290. +   }
  2291. +  
  2292. +   public static void setTeamPlayersCount(String teamName, int teamPlayersCount)
  2293. +   {
  2294. +       int index = _teams.indexOf(teamName);
  2295. +      
  2296. +       if (index == -1)
  2297. +       {
  2298. +           return;
  2299. +       }
  2300. +      
  2301. +       _teamPlayersCount.set(index, teamPlayersCount);
  2302. +   }
  2303. +  
  2304. +   public static void setNpcPos(L2PcInstance activeChar)
  2305. +   {
  2306. +       _npcX = activeChar.getX();
  2307. +       _npcY = activeChar.getY();
  2308. +       _npcZ = activeChar.getZ();
  2309. +       _npcHeading = activeChar.getHeading();
  2310. +   }
  2311. +  
  2312. +   public static void setNpcPos(int x, int y, int z)
  2313. +   {
  2314. +       _npcX = x;
  2315. +       _npcY = y;
  2316. +       _npcZ = z;
  2317. +   }
  2318. +  
  2319. +   public static void addTeam(String teamName)
  2320. +   {
  2321. +       if (!checkTeamOk())
  2322. +       {
  2323. +           if (Config.DEBUG)
  2324. +           {
  2325. +               _log.fine("CTF Engine[addTeam(" + teamName + ")]: checkTeamOk() = false");
  2326. +           }
  2327. +           return;
  2328. +       }
  2329. +      
  2330. +       if (teamName.equals(" "))
  2331. +       {
  2332. +           return;
  2333. +       }
  2334. +      
  2335. +       _teams.add(teamName);
  2336. +       _teamPlayersCount.add(0);
  2337. +       _teamColors.add(0);
  2338. +       _teamsX.add(0);
  2339. +       _teamsY.add(0);
  2340. +       _teamsZ.add(0);
  2341. +       _teamsBaseX.add(0);
  2342. +       _teamsBaseY.add(0);
  2343. +       _teamsBaseZ.add(0);
  2344. +       _teamPointsCount.add(0);
  2345. +       addOrSet(_teams.indexOf(teamName), null, false, _FlagNPC, 0, 0, 0);
  2346. +   }
  2347. +  
  2348. +   private static void addOrSet(int listSize, L2Spawn flagSpawn, boolean flagsTaken, int flagId, int flagX, int flagY, int flagZ)
  2349. +   {
  2350. +       while (_flagsX.size() <= listSize)
  2351. +       {
  2352. +           _flagSpawns.add(null);
  2353. +           _flagsTaken.add(false);
  2354. +           _flagIds.add(_FlagNPC);
  2355. +           _flagsX.add(0);
  2356. +           _flagsY.add(0);
  2357. +           _flagsZ.add(0);
  2358. +       }
  2359. +       _flagSpawns.set(listSize, flagSpawn);
  2360. +       _flagsTaken.set(listSize, flagsTaken);
  2361. +       _flagIds.set(listSize, flagId);
  2362. +       _flagsX.set(listSize, flagX);
  2363. +       _flagsY.set(listSize, flagY);
  2364. +       _flagsZ.set(listSize, flagZ);
  2365. +   }
  2366. +  
  2367. +   public static boolean checkMaxLevel(int maxlvl)
  2368. +   {
  2369. +       if (_minlvl >= maxlvl)
  2370. +       {
  2371. +           return false;
  2372. +       }
  2373. +      
  2374. +       return true;
  2375. +   }
  2376. +  
  2377. +   public static boolean checkMinLevel(int minlvl)
  2378. +   {
  2379. +       if (_maxlvl <= minlvl)
  2380. +       {
  2381. +           return false;
  2382. +       }
  2383. +      
  2384. +       return true;
  2385. +   }
  2386. +  
  2387. +   /**
  2388. +    * returns true if participated players is higher or equal then minimum needed players
  2389. +    * @param players
  2390. +    * @return
  2391. +    */
  2392. +   public static boolean checkMinPlayers(int players)
  2393. +   {
  2394. +       if (_minPlayers <= players)
  2395. +       {
  2396. +           return true;
  2397. +       }
  2398. +      
  2399. +       return false;
  2400. +   }
  2401. +  
  2402. +   /**
  2403. +    * returns true if max players is higher or equal then participated players
  2404. +    * @param players
  2405. +    * @return
  2406. +    */
  2407. +   public static boolean checkMaxPlayers(int players)
  2408. +   {
  2409. +       if (_maxPlayers > players)
  2410. +       {
  2411. +           return true;
  2412. +       }
  2413. +      
  2414. +       return false;
  2415. +   }
  2416. +  
  2417. +   public static void removeTeam(String teamName)
  2418. +   {
  2419. +       if (!checkTeamOk() || _teams.isEmpty())
  2420. +       {
  2421. +           if (Config.DEBUG)
  2422. +           {
  2423. +               _log.fine("CTF Engine[removeTeam(" + teamName + ")]: checkTeamOk() = false");
  2424. +           }
  2425. +           return;
  2426. +       }
  2427. +      
  2428. +       if (teamPlayersCount(teamName) > 0)
  2429. +       {
  2430. +           if (Config.DEBUG)
  2431. +           {
  2432. +               _log.fine("CTF Engine[removeTeam(" + teamName + ")]: teamPlayersCount(teamName) > 0");
  2433. +           }
  2434. +           return;
  2435. +       }
  2436. +      
  2437. +       int index = _teams.indexOf(teamName);
  2438. +      
  2439. +       if (index == -1)
  2440. +       {
  2441. +           return;
  2442. +       }
  2443. +      
  2444. +       _teamsZ.remove(index);
  2445. +       _teamsY.remove(index);
  2446. +       _teamsX.remove(index);
  2447. +       _teamsBaseZ.remove(index);
  2448. +       _teamsBaseY.remove(index);
  2449. +       _teamsBaseX.remove(index);
  2450. +       _teamColors.remove(index);
  2451. +       _teamPointsCount.remove(index);
  2452. +       _teamPlayersCount.remove(index);
  2453. +       _teams.remove(index);
  2454. +       _flagSpawns.remove(index);
  2455. +       _flagsTaken.remove(index);
  2456. +       _flagIds.remove(index);
  2457. +       _flagsX.remove(index);
  2458. +       _flagsY.remove(index);
  2459. +       _flagsZ.remove(index);
  2460. +   }
  2461. +  
  2462. +   public static void setTeamPos(String teamName, L2PcInstance activeChar)
  2463. +   {
  2464. +       int index = _teams.indexOf(teamName);
  2465. +      
  2466. +       if (index == -1)
  2467. +       {
  2468. +           return;
  2469. +       }
  2470. +      
  2471. +       _teamsX.set(index, activeChar.getX());
  2472. +       _teamsY.set(index, activeChar.getY());
  2473. +       _teamsZ.set(index, activeChar.getZ());
  2474. +   }
  2475. +  
  2476. +   public static void setTeamPos(String teamName, int x, int y, int z)
  2477. +   {
  2478. +       int index = _teams.indexOf(teamName);
  2479. +      
  2480. +       if (index == -1)
  2481. +       {
  2482. +           return;
  2483. +       }
  2484. +      
  2485. +       _teamsX.set(index, x);
  2486. +       _teamsY.set(index, y);
  2487. +       _teamsZ.set(index, z);
  2488. +   }
  2489. +  
  2490. +   public static void setTeamBasePos(String teamName, L2PcInstance activeChar)
  2491. +   {
  2492. +       int index = _teams.indexOf(teamName);
  2493. +      
  2494. +       if (index == -1)
  2495. +       {
  2496. +           return;
  2497. +       }
  2498. +      
  2499. +       _teamsBaseX.set(index, activeChar.getX());
  2500. +       _teamsBaseY.set(index, activeChar.getY());
  2501. +       _teamsBaseZ.set(index, activeChar.getZ());
  2502. +   }
  2503. +  
  2504. +   public static void setTeamBasePos(String teamName, int x, int y, int z)
  2505. +   {
  2506. +       int index = _teams.indexOf(teamName);
  2507. +      
  2508. +       if (index == -1)
  2509. +       {
  2510. +           return;
  2511. +       }
  2512. +      
  2513. +       _teamsBaseX.set(index, x);
  2514. +       _teamsBaseY.set(index, y);
  2515. +       _teamsBaseZ.set(index, z);
  2516. +   }
  2517. +  
  2518. +   public static void setTeamColor(String teamName, int color)
  2519. +   {
  2520. +       if (!checkTeamOk())
  2521. +       {
  2522. +           return;
  2523. +       }
  2524. +      
  2525. +       int index = _teams.indexOf(teamName);
  2526. +      
  2527. +       if (index == -1)
  2528. +       {
  2529. +           return;
  2530. +       }
  2531. +      
  2532. +       _teamColors.set(index, color);
  2533. +   }
  2534. +  
  2535. +   public static boolean checkTeamOk()
  2536. +   {
  2537. +       if (_started || _teleport || _joining)
  2538. +       {
  2539. +           return false;
  2540. +       }
  2541. +      
  2542. +       return true;
  2543. +   }
  2544. +  
  2545. +   public static void startJoin(L2PcInstance activeChar)
  2546. +   {
  2547. +       if (!startJoinOk())
  2548. +       {
  2549. +           activeChar.sendMessage("Event not setted propertly.");
  2550. +           if (Config.DEBUG)
  2551. +           {
  2552. +               _log.fine("CTF Engine[startJoin(" + activeChar.getName() + ")]: startJoinOk() = false");
  2553. +           }
  2554. +           return;
  2555. +       }
  2556. +      
  2557. +       _joining = true;
  2558. +       spawnEventNpc(activeChar);
  2559. +       AnnounceToPlayers(true, "CTF Event: Registration opened for 15 minute(s)! Use .joinctf command to register. Rewards: 10 gold bars for all the winners!");
  2560. +   }
  2561. +  
  2562. +   public static void startJoin()
  2563. +   {
  2564. +       if (!startJoinOk())
  2565. +       {
  2566. +           _log.warning("Event not setted propertly.");
  2567. +           if (Config.DEBUG)
  2568. +           {
  2569. +               _log.fine("CTF Engine[startJoin(startJoinOk() = false");
  2570. +           }
  2571. +           return;
  2572. +       }
  2573. +      
  2574. +       _joining = true;
  2575. +       spawnEventNpc();
  2576. +   }
  2577. +  
  2578. +   public static boolean startAutoJoin()
  2579. +   {
  2580. +       if (!startJoinOk())
  2581. +       {
  2582. +           if (Config.DEBUG)
  2583. +           {
  2584. +               _log.fine("CTF Engine[startJoin]: startJoinOk() = false");
  2585. +           }
  2586. +           return false;
  2587. +       }
  2588. +      
  2589. +       _joining = true;
  2590. +       spawnEventNpc();
  2591. +       AnnounceToPlayers(true, "CTF Event: Registration opened for 15 minute(s)! Use .joinctf command to register.");
  2592. +       return true;
  2593. +   }
  2594. +  
  2595. +   public static boolean startJoinOk()
  2596. +   {
  2597. +       if (Config.CTF_BASE_TELEPORT_FIRST && (_teamsBaseX.contains(0) || _teamsBaseY.contains(0) || _teamsBaseZ.contains(0)))
  2598. +       {
  2599. +           return false;
  2600. +       }
  2601. +       else 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) || (_flagHoldTime == 0))
  2602. +       {
  2603. +           return false;
  2604. +       }
  2605. +       try
  2606. +       {
  2607. +           if (_flagsX.contains(0) || _flagsY.contains(0) || _flagsZ.contains(0) || _flagIds.contains(0))
  2608. +           {
  2609. +               return false;
  2610. +           }
  2611. +           if ((_flagsX.size() < _teams.size()) || (_flagsY.size() < _teams.size()) || (_flagsZ.size() < _teams.size()) || (_flagIds.size() < _teams.size()))
  2612. +           {
  2613. +               return false;
  2614. +           }
  2615. +       }
  2616. +       catch (ArrayIndexOutOfBoundsException e)
  2617. +       {
  2618. +           return false;
  2619. +       }
  2620. +       return true;
  2621. +   }
  2622. +  
  2623. +   private static void spawnEventNpc(L2PcInstance activeChar)
  2624. +   {
  2625. +       L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
  2626. +      
  2627. +       try
  2628. +       {
  2629. +           _npcSpawn = new L2Spawn(tmpl);
  2630. +          
  2631. +           _npcSpawn.setLocx(_npcX);
  2632. +           _npcSpawn.setLocy(_npcY);
  2633. +           _npcSpawn.setLocz(_npcZ);
  2634. +           _npcSpawn.setAmount(1);
  2635. +           _npcSpawn.setHeading(_npcHeading);
  2636. +           _npcSpawn.setRespawnDelay(1);
  2637. +          
  2638. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  2639. +          
  2640. +           _npcSpawn.init();
  2641. +           _npcSpawn.getLastSpawn().getStatus().setCurrentHp(999999999);
  2642. +           _npcSpawn.getLastSpawn().setTitle(_eventName);
  2643. +           _npcSpawn.getLastSpawn()._isEventMobCTF = true;
  2644. +           _npcSpawn.getLastSpawn().isAggressive();
  2645. +           _npcSpawn.getLastSpawn().decayMe();
  2646. +           _npcSpawn.getLastSpawn().spawnMe(_npcSpawn.getLastSpawn().getX(), _npcSpawn.getLastSpawn().getY(), _npcSpawn.getLastSpawn().getZ());
  2647. +          
  2648. +           _npcSpawn.getLastSpawn().broadcastPacket(new MagicSkillUse(_npcSpawn.getLastSpawn(), _npcSpawn.getLastSpawn(), 1034, 1, 1, 1));
  2649. +       }
  2650. +       catch (Exception e)
  2651. +       {
  2652. +           _log.warning("CTF Engine[spawnEventNpc(" + activeChar.getName() + ")]: exception: " + e.getMessage());
  2653. +       }
  2654. +   }
  2655. +  
  2656. +   public static class BaseTeleportTask implements Runnable
  2657. +   {
  2658. +       L2PcInstance player;
  2659. +       boolean onBegin;
  2660. +      
  2661. +       public BaseTeleportTask(L2PcInstance _player, boolean _onBegin)
  2662. +       {
  2663. +           player = _player;
  2664. +           onBegin = _onBegin;
  2665. +       }
  2666. +      
  2667. +       public BaseTeleportTask(boolean _onBegin)
  2668. +       {
  2669. +           onBegin = _onBegin;
  2670. +       }
  2671. +      
  2672. +       @Override
  2673. +       public void run()
  2674. +       {
  2675. +           if (CTF._teleport || CTF._started)
  2676. +           {
  2677. +               if (onBegin)
  2678. +               {
  2679. +                   spawnAllFlags();
  2680. +                  
  2681. +                   for (L2PcInstance players : _players)
  2682. +                   {
  2683. +                       new BaseTeleportTask(players, false).run();
  2684. +                   }
  2685. +               }
  2686. +               else
  2687. +               {
  2688. +                   if (player != null)
  2689. +                   {
  2690. +                       player.teleToLocation(CTF._teamsX.get(CTF._teams.indexOf(player._teamNameCTF)), CTF._teamsY.get(CTF._teams.indexOf(player._teamNameCTF)), CTF._teamsZ.get(CTF._teams.indexOf(player._teamNameCTF)), false);
  2691. +                   }
  2692. +               }
  2693. +           }
  2694. +       }
  2695. +   }
  2696. +  
  2697. +   private static void spawnEventNpc()
  2698. +   {
  2699. +       L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
  2700. +      
  2701. +       try
  2702. +       {
  2703. +           _npcSpawn = new L2Spawn(tmpl);
  2704. +          
  2705. +           _npcSpawn.setLocx(_npcX);
  2706. +           _npcSpawn.setLocy(_npcY);
  2707. +           _npcSpawn.setLocz(_npcZ);
  2708. +           _npcSpawn.setAmount(1);
  2709. +           _npcSpawn.setHeading(_npcHeading);
  2710. +           _npcSpawn.setRespawnDelay(1);
  2711. +          
  2712. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  2713. +          
  2714. +           _npcSpawn.init();
  2715. +           _npcSpawn.getLastSpawn().getStatus().setCurrentHp(999999999);
  2716. +           _npcSpawn.getLastSpawn().setTitle(_eventName);
  2717. +           _npcSpawn.getLastSpawn()._isEventMobCTF = true;
  2718. +           _npcSpawn.getLastSpawn().isAggressive();
  2719. +           _npcSpawn.getLastSpawn().decayMe();
  2720. +           _npcSpawn.getLastSpawn().spawnMe(_npcSpawn.getLastSpawn().getX(), _npcSpawn.getLastSpawn().getY(), _npcSpawn.getLastSpawn().getZ());
  2721. +          
  2722. +           _npcSpawn.getLastSpawn().broadcastPacket(new MagicSkillUse(_npcSpawn.getLastSpawn(), _npcSpawn.getLastSpawn(), 1034, 1, 1, 1));
  2723. +       }
  2724. +       catch (Exception e)
  2725. +       {
  2726. +           _log.warning("CTF Engine[spawnEventNpc(exception: " + e.getMessage());
  2727. +       }
  2728. +   }
  2729. +  
  2730. +   public static void teleportStart()
  2731. +   {
  2732. +       if (!_joining || _started || _teleport)
  2733. +       {
  2734. +           return;
  2735. +       }
  2736. +      
  2737. +       if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && checkMinPlayers(_playersShuffle.size()))
  2738. +       {
  2739. +           removeOfflinePlayers();
  2740. +           shuffleTeams();
  2741. +       }
  2742. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !checkMinPlayers(_playersShuffle.size()))
  2743. +       {
  2744. +           return;
  2745. +       }
  2746. +      
  2747. +       _joining = false;
  2748. +       setUserData();
  2749. +      
  2750. +       if (Config.CTF_BASE_TELEPORT_FIRST)
  2751. +       {
  2752. +           AnnounceToPlayers(true, "CTF Event: Teleporting to team base. The fight will being in 20 seconds!");
  2753. +          
  2754. +           for (L2PcInstance player : _players)
  2755. +           {
  2756. +               if (player != null)
  2757. +               {
  2758. +                   if (Config.CTF_ON_START_UNSUMMON_PET)
  2759. +                   {
  2760. +                       // Remove Summon's buffs
  2761. +                       if (player.getSummon() != null)
  2762. +                       {
  2763. +                           L2Summon summon = player.getSummon();
  2764. +                           for (L2Effect e : summon.getAllEffects())
  2765. +                           {
  2766. +                               if (e != null)
  2767. +                               {
  2768. +                                   e.exit();
  2769. +                               }
  2770. +                           }
  2771. +                          
  2772. +                           if (summon instanceof L2PetInstance)
  2773. +                           {
  2774. +                               summon.unSummon(player);
  2775. +                           }
  2776. +                       }
  2777. +                   }
  2778. +                  
  2779. +                   if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
  2780. +                   {
  2781. +                       for (L2Effect e : player.getAllEffects())
  2782. +                       {
  2783. +                           if (e != null)
  2784. +                           {
  2785. +                               e.exit();
  2786. +                           }
  2787. +                       }
  2788. +                   }
  2789. +                  
  2790. +                   // Remove player from his party
  2791. +                   if (player.getParty() != null)
  2792. +                   {
  2793. +                       L2Party party = player.getParty();
  2794. +                       party.removePartyMember(player, messageType.Expelled);
  2795. +                   }
  2796. +                  
  2797. +                   player.teleToLocation(_teamsBaseX.get(_teams.indexOf(player._teamNameCTF)), _teamsBaseY.get(_teams.indexOf(player._teamNameCTF)), _teamsBaseZ.get(_teams.indexOf(player._teamNameCTF)));
  2798. +               }
  2799. +           }
  2800. +           ThreadPoolManager.getInstance().scheduleGeneral(new BaseTeleportTask(true), 20000);
  2801. +       }
  2802. +       else
  2803. +       {
  2804. +           AnnounceToPlayers(true, "CTF Event: Teleporting to team spot in 15 seconds!");
  2805. +          
  2806. +           ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  2807. +           {
  2808. +               @Override
  2809. +               public void run()
  2810. +               {
  2811. +                   spawnAllFlags();
  2812. +                  
  2813. +                   for (L2PcInstance player : _players)
  2814. +                   {
  2815. +                       if (player != null)
  2816. +                       {
  2817. +                           if (Config.CTF_ON_START_UNSUMMON_PET)
  2818. +                           {
  2819. +                               // Remove Summon's buffs
  2820. +                               if (player.getSummon() != null)
  2821. +                               {
  2822. +                                   L2Summon summon = player.getSummon();
  2823. +                                   for (L2Effect e : summon.getAllEffects())
  2824. +                                   {
  2825. +                                       if (e != null)
  2826. +                                       {
  2827. +                                           e.exit();
  2828. +                                       }
  2829. +                                   }
  2830. +                                  
  2831. +                                   if (summon instanceof L2PetInstance)
  2832. +                                   {
  2833. +                                       summon.unSummon(player);
  2834. +                                   }
  2835. +                               }
  2836. +                           }
  2837. +                          
  2838. +                           if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
  2839. +                           {
  2840. +                               for (L2Effect e : player.getAllEffects())
  2841. +                               {
  2842. +                                   if (e != null)
  2843. +                                   {
  2844. +                                       e.exit();
  2845. +                                   }
  2846. +                               }
  2847. +                           }
  2848. +                          
  2849. +                           // Remove player from his party
  2850. +                           if (player.getParty() != null)
  2851. +                           {
  2852. +                               L2Party party = player.getParty();
  2853. +                               party.removePartyMember(player, messageType.Expelled);
  2854. +                           }
  2855. +                          
  2856. +                           player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ.get(_teams.indexOf(player._teamNameCTF)));
  2857. +                       }
  2858. +                   }
  2859. +               }
  2860. +           }, 15000);
  2861. +       }
  2862. +       _teleport = true;
  2863. +   }
  2864. +  
  2865. +   public static boolean teleportAutoStart()
  2866. +   {
  2867. +       if (!_joining || _started || _teleport)
  2868. +       {
  2869. +           return false;
  2870. +       }
  2871. +      
  2872. +       if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && checkMinPlayers(_playersShuffle.size()))
  2873. +       {
  2874. +           removeOfflinePlayers();
  2875. +           shuffleTeams();
  2876. +       }
  2877. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !checkMinPlayers(_playersShuffle.size()))
  2878. +       {
  2879. +           AnnounceToPlayers(true, "CTF Event: Not enough players registered.");
  2880. +           return false;
  2881. +       }
  2882. +      
  2883. +       _joining = false;
  2884. +       setUserData();
  2885. +      
  2886. +       if (Config.CTF_BASE_TELEPORT_FIRST)
  2887. +       {
  2888. +           AnnounceToPlayers(true, "CTF Event: Teleporting to team base. The fight will being in 20 seconds!");
  2889. +          
  2890. +           for (L2PcInstance player : _players)
  2891. +           {
  2892. +               if (player != null)
  2893. +               {
  2894. +                   if (Config.CTF_ON_START_UNSUMMON_PET)
  2895. +                   {
  2896. +                       // Remove Summon's buffs
  2897. +                       if (player.getSummon() != null)
  2898. +                       {
  2899. +                           L2Summon summon = player.getSummon();
  2900. +                           for (L2Effect e : summon.getAllEffects())
  2901. +                           {
  2902. +                               if (e != null)
  2903. +                               {
  2904. +                                   e.exit();
  2905. +                               }
  2906. +                           }
  2907. +                          
  2908. +                           if (summon instanceof L2PetInstance)
  2909. +                           {
  2910. +                               summon.unSummon(player);
  2911. +                           }
  2912. +                       }
  2913. +                   }
  2914. +                  
  2915. +                   if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
  2916. +                   {
  2917. +                       for (L2Effect e : player.getAllEffects())
  2918. +                       {
  2919. +                           if (e != null)
  2920. +                           {
  2921. +                               e.exit();
  2922. +                           }
  2923. +                       }
  2924. +                   }
  2925. +                  
  2926. +                   // Remove player from his party
  2927. +                   if (player.getParty() != null)
  2928. +                   {
  2929. +                       L2Party party = player.getParty();
  2930. +                       party.removePartyMember(player, messageType.Expelled);
  2931. +                   }
  2932. +                  
  2933. +                   player.teleToLocation(_teamsBaseX.get(_teams.indexOf(player._teamNameCTF)), _teamsBaseY.get(_teams.indexOf(player._teamNameCTF)), _teamsBaseZ.get(_teams.indexOf(player._teamNameCTF)));
  2934. +               }
  2935. +           }
  2936. +           ThreadPoolManager.getInstance().scheduleGeneral(new BaseTeleportTask(true), 30000);
  2937. +       }
  2938. +       else
  2939. +       {
  2940. +           AnnounceToPlayers(false, "CTF Event: Teleporting to team spot in 15 seconds!");
  2941. +          
  2942. +           ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  2943. +           {
  2944. +               @Override
  2945. +               public void run()
  2946. +               {
  2947. +                   spawnAllFlags();
  2948. +                  
  2949. +                   for (L2PcInstance player : _players)
  2950. +                   {
  2951. +                       if (player != null)
  2952. +                       {
  2953. +                           if (Config.CTF_ON_START_UNSUMMON_PET)
  2954. +                           {
  2955. +                               // Remove Summon's buffs
  2956. +                               if (player.getSummon() != null)
  2957. +                               {
  2958. +                                   L2Summon summon = player.getSummon();
  2959. +                                   for (L2Effect e : summon.getAllEffects())
  2960. +                                   {
  2961. +                                       if (e != null)
  2962. +                                       {
  2963. +                                           e.exit();
  2964. +                                       }
  2965. +                                   }
  2966. +                                  
  2967. +                                   if (summon instanceof L2PetInstance)
  2968. +                                   {
  2969. +                                       summon.unSummon(player);
  2970. +                                   }
  2971. +                               }
  2972. +                           }
  2973. +                          
  2974. +                           if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
  2975. +                           {
  2976. +                               for (L2Effect e : player.getAllEffects())
  2977. +                               {
  2978. +                                   if (e != null)
  2979. +                                   {
  2980. +                                       e.exit();
  2981. +                                   }
  2982. +                               }
  2983. +                           }
  2984. +                          
  2985. +                           // Remove player from his party
  2986. +                           if (player.getParty() != null)
  2987. +                           {
  2988. +                               L2Party party = player.getParty();
  2989. +                               party.removePartyMember(player, messageType.Expelled);
  2990. +                           }
  2991. +                          
  2992. +                           player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ.get(_teams.indexOf(player._teamNameCTF)));
  2993. +                       }
  2994. +                   }
  2995. +               }
  2996. +           }, 15000);
  2997. +       }
  2998. +       _teleport = true;
  2999. +       return true;
  3000. +   }
  3001. +  
  3002. +   public static void startEvent(L2PcInstance activeChar)
  3003. +   {
  3004. +       if (!startEventOk())
  3005. +       {
  3006. +           if (Config.DEBUG)
  3007. +           {
  3008. +               _log.fine("CTF Engine[startEvent(" + activeChar.getName() + ")]: startEventOk() = false");
  3009. +           }
  3010. +           return;
  3011. +       }
  3012. +      
  3013. +       _teleport = false;
  3014. +      
  3015. +       _started = true;
  3016. +       StartEvent();
  3017. +   }
  3018. +  
  3019. +   public static void setJoinTime(int time)
  3020. +   {
  3021. +       _joinTime = time;
  3022. +   }
  3023. +  
  3024. +   public static void setEventTime(int time)
  3025. +   {
  3026. +       _eventTime = time;
  3027. +   }
  3028. +  
  3029. +   public static boolean startAutoEvent()
  3030. +   {
  3031. +       if (!startEventOk())
  3032. +       {
  3033. +           if (Config.DEBUG)
  3034. +           {
  3035. +               _log.fine("CTF Engine[startEvent]: startEventOk() = false");
  3036. +           }
  3037. +           return false;
  3038. +       }
  3039. +      
  3040. +       _teleport = false;
  3041. +      
  3042. +       _started = true;
  3043. +       return true;
  3044. +   }
  3045. +  
  3046. +   public static synchronized void autoEvent()
  3047. +   {
  3048. +       if (startAutoJoin())
  3049. +       {
  3050. +           if (_joinTime > 0)
  3051. +           {
  3052. +               waiter(_joinTime * 60 * 1000); // minutes for join event
  3053. +           }
  3054. +           else if (_joinTime <= 0)
  3055. +           {
  3056. +               abortEvent();
  3057. +               return;
  3058. +           }
  3059. +           if (teleportAutoStart())
  3060. +           {
  3061. +               waiter(1 * 1 * 1000); // 1 seconds wait time until start fight after teleported
  3062. +              
  3063. +               if (startAutoEvent())
  3064. +               {
  3065. +                   AnnounceToPlayers(true, "CTF Event: Started. Go Capture the Flags!");
  3066. +                   waiter(_eventTime * 60 * 1000); // minutes for event time
  3067. +                   finishEvent();
  3068. +               }
  3069. +           }
  3070. +           else if (!teleportAutoStart())
  3071. +           {
  3072. +               abortEvent();
  3073. +           }
  3074. +       }
  3075. +   }
  3076. +  
  3077. +   // a scheduled time to remove the flag after a user set time _flagHoldTime
  3078. +   private static void flagHoldTimer(final L2PcInstance _player, final long interval)
  3079. +   {
  3080. +       ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  3081. +       {
  3082. +           @Override
  3083. +           @SuppressWarnings("null")
  3084. +           public void run()
  3085. +           {
  3086. +               if (_started)
  3087. +               {
  3088. +                   try
  3089. +                   // just to be sure
  3090. +                   {
  3091. +                       long countDown = System.currentTimeMillis();
  3092. +                       int seconds = (int) interval;
  3093. +                      
  3094. +                       while (((countDown + (interval * 1000)) > System.currentTimeMillis()) && (_flagsNotRemoved.get(_teams.indexOf(_player._teamNameCTF)) != false))
  3095. +                       {
  3096. +                           seconds--;
  3097. +                          
  3098. +                           switch (seconds)
  3099. +                           {
  3100. +                               case 600: // 10 minutes left
  3101. +                                   if ((_player != null) && _player._haveFlagCTF)
  3102. +                                   {
  3103. +                                       _player.sendMessage("You have 10 minutes to capture the flag or it will be returned.");
  3104. +                                   }
  3105. +                                   break;
  3106. +                               case 300: // 5 minutes left
  3107. +                                   if ((_player != null) && _player._haveFlagCTF)
  3108. +                                   {
  3109. +                                       _player.sendMessage("You have 5 minutes to capture the flag or it will be returned.");
  3110. +                                   }
  3111. +                                   break;
  3112. +                               case 240: // 4 minutes left
  3113. +                                   if ((_player != null) && _player._haveFlagCTF)
  3114. +                                   {
  3115. +                                       _player.sendMessage("You have 5 minutes to capture the flag or it will be returned.");
  3116. +                                   }
  3117. +                                   break;
  3118. +                               case 180: // 3 minutes left
  3119. +                                   if ((_player != null) && _player._haveFlagCTF)
  3120. +                                   {
  3121. +                                       _player.sendMessage("You have 3 minutes to capture the flag or it will be returned.");
  3122. +                                   }
  3123. +                                   break;
  3124. +                               case 120: // 2 minutes left
  3125. +                                   if ((_player != null) && _player._haveFlagCTF)
  3126. +                                   {
  3127. +                                       _player.sendMessage("You have 2 minutes to capture the flag or it will be returned.");
  3128. +                                   }
  3129. +                                   break;
  3130. +                               case 60: // 1 minute left
  3131. +                                   if ((_player != null) && _player._haveFlagCTF)
  3132. +                                   {
  3133. +                                       _player.sendMessage("You have 1 minute to capture the flag or it will be returned.");
  3134. +                                   }
  3135. +                                   break;
  3136. +                               case 30: // 30 seconds left
  3137. +                                   if ((_player != null) && _player._haveFlagCTF)
  3138. +                                   {
  3139. +                                       _player.sendMessage("You have 30 seconds to capture the flag or it will be returned.");
  3140. +                                   }
  3141. +                                   break;
  3142. +                               case 10: // 10 seconds left
  3143. +                                   if ((_player != null) && _player._haveFlagCTF)
  3144. +                                   {
  3145. +                                       _player.sendMessage("You have 10 seconds to capture the flag or it will be returned.");
  3146. +                                   }
  3147. +                                   break;
  3148. +                               case 1: // 1 seconds left
  3149. +                                   if ((_player != null) && _player._haveFlagCTF)
  3150. +                                   {
  3151. +                                       removeFlagFromPlayer(_player);
  3152. +                                       _flagsTaken.set(_teams.indexOf(_player._teamNameHaveFlagCTF), false);
  3153. +                                       spawnFlag(_player._teamNameHaveFlagCTF);
  3154. +                                       _player.sendMessage("You've held the flag for too long. The enemy flag has been returned.");
  3155. +                                       AnnounceToPlayers(false, "CTF Event: " + _player.getName() + " held the flag for too long. " + _player._teamNameCTF + " flag has been returned.");
  3156. +                                   }
  3157. +                                   break;
  3158. +                           }
  3159. +                           long startOneSecondWaiterStartTime = System.currentTimeMillis();
  3160. +                          
  3161. +                           // only the try catch with Thread.sleep(1000) give bad countdown on high wait times
  3162. +                           while ((startOneSecondWaiterStartTime + 1000) > System.currentTimeMillis())
  3163. +                           {
  3164. +                               try
  3165. +                               {
  3166. +                                   Thread.sleep(1);
  3167. +                               }
  3168. +                               catch (InterruptedException ie)
  3169. +                               {
  3170. +                               }
  3171. +                           }
  3172. +                       }
  3173. +                   }
  3174. +                   catch (Exception e)
  3175. +                   {
  3176. +                       _log.warning("Exception: CTF.flagHoldTimer(): " + e.getMessage());
  3177. +                   }
  3178. +               }
  3179. +           }
  3180. +       }, 1);
  3181. +   }
  3182. +  
  3183. +   private static synchronized void waiter(long interval)
  3184. +   {
  3185. +       long startWaiterTime = System.currentTimeMillis();
  3186. +       int seconds = (int) (interval / 1000);
  3187. +      
  3188. +       while ((startWaiterTime + interval) > System.currentTimeMillis())
  3189. +       {
  3190. +           seconds--; // here because we don't want to see two time announce at the same time
  3191. +          
  3192. +           if (_joining || _started || _teleport)
  3193. +           {
  3194. +               switch (seconds)
  3195. +               {
  3196. +                   case 3600: // 1 hour left
  3197. +                       if (_joining)
  3198. +                       {
  3199. +                           AnnounceToPlayers(true, "CTF Event: " + (seconds / 60 / 60) + " hour(s) until registration ends! Use .joinctf command to register.");
  3200. +                       }
  3201. +                       else if (_started)
  3202. +                       {
  3203. +                           AnnounceToPlayers(false, "CTF Event: " + (seconds / 60 / 60) + " hour(s) until event ends!");
  3204. +                       }
  3205. +                      
  3206. +                       break;
  3207. +                   case 600: // 10 minutes left
  3208. +                   case 300: // 5 minutes left
  3209. +                   case 60: // 1 minute left
  3210. +                       if (_joining)
  3211. +                       {
  3212. +                           removeOfflinePlayers();
  3213. +                           AnnounceToPlayers(true, "CTF Event: " + (seconds / 60) + " minute(s) until registration ends! Use .joinctf command to register.");
  3214. +                       }
  3215. +                       else if (_started)
  3216. +                       {
  3217. +                           AnnounceToPlayers(false, "CTF Event: " + (seconds / 60) + " minute(s) until event ends!");
  3218. +                       }
  3219. +                      
  3220. +                       break;
  3221. +                  
  3222. +                   case 5: // 5 seconds left
  3223. +                      
  3224. +                       if (_joining)
  3225. +                       {
  3226. +                           AnnounceToPlayers(true, "CTF Event: " + seconds + " second(s) until registration ends! Use .joinctf command to register.");
  3227. +                       }
  3228. +                       else if (_teleport)
  3229. +                       {
  3230. +                           AnnounceToPlayers(false, "CTF Event: " + seconds + " seconds(s) until ends starts!");
  3231. +                       }
  3232. +                       else if (_started)
  3233. +                       {
  3234. +                           AnnounceToPlayers(false, "CTF Event: " + seconds + " second(s) until event ends!");
  3235. +                       }
  3236. +                      
  3237. +                       break;
  3238. +               }
  3239. +           }
  3240. +          
  3241. +           long startOneSecondWaiterStartTime = System.currentTimeMillis();
  3242. +          
  3243. +           // only the try catch with Thread.sleep(1000) give bad countdown on high wait times
  3244. +           while ((startOneSecondWaiterStartTime + 1000) > System.currentTimeMillis())
  3245. +           {
  3246. +               try
  3247. +               {
  3248. +                   Thread.sleep(1);
  3249. +               }
  3250. +               catch (InterruptedException ie)
  3251. +               {
  3252. +               }
  3253. +           }
  3254. +       }
  3255. +   }
  3256. +  
  3257. +   private static boolean startEventOk()
  3258. +   {
  3259. +       if (_joining || !_teleport || _started)
  3260. +       {
  3261. +           return false;
  3262. +       }
  3263. +      
  3264. +       if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  3265. +       {
  3266. +           if (_teamPlayersCount.contains(0))
  3267. +           {
  3268. +               return false;
  3269. +           }
  3270. +       }
  3271. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  3272. +       {
  3273. +           Vector<L2PcInstance> playersShuffleTemp = new Vector<>();
  3274. +           int loopCount = 0;
  3275. +          
  3276. +           loopCount = _playersShuffle.size();
  3277. +          
  3278. +           for (int i = 0; i < loopCount; i++)
  3279. +           {
  3280. +               if (_playersShuffle != null)
  3281. +               {
  3282. +                   playersShuffleTemp.add(_playersShuffle.get(i));
  3283. +               }
  3284. +           }
  3285. +          
  3286. +           _playersShuffle = playersShuffleTemp;
  3287. +           playersShuffleTemp.clear();
  3288. +          
  3289. +           // if (_playersShuffle.size() < (_teams.size()*2)){
  3290. +           // return false;
  3291. +           // }
  3292. +       }
  3293. +      
  3294. +       return true;
  3295. +   }
  3296. +  
  3297. +   public static void shuffleTeams()
  3298. +   {
  3299. +       int teamCount = 0, playersCount = 0;
  3300. +      
  3301. +       for (;;)
  3302. +       {
  3303. +           if (_playersShuffle.isEmpty())
  3304. +           {
  3305. +               break;
  3306. +           }
  3307. +          
  3308. +           int playerToAddIndex = Rnd.nextInt(_playersShuffle.size());
  3309. +           L2PcInstance player = null;
  3310. +           player = _playersShuffle.get(playerToAddIndex);
  3311. +           player._originalNameColorCTF = player.getAppearance().getNameColor();
  3312. +           player._originalKarmaCTF = player.getKarma();
  3313. +          
  3314. +           _players.add(player);
  3315. +           _players.get(playersCount)._teamNameCTF = _teams.get(teamCount);
  3316. +           _savePlayers.add(_players.get(playersCount).getName());
  3317. +           _savePlayerTeams.add(_teams.get(teamCount));
  3318. +           playersCount++;
  3319. +          
  3320. +           if (teamCount == (_teams.size() - 1))
  3321. +           {
  3322. +               teamCount = 0;
  3323. +           }
  3324. +           else
  3325. +           {
  3326. +               teamCount++;
  3327. +           }
  3328. +          
  3329. +           _playersShuffle.remove(playerToAddIndex);
  3330. +       }
  3331. +   }
  3332. +  
  3333. +   public static void setUserData()
  3334. +   {
  3335. +       for (L2PcInstance player : _players)
  3336. +       {
  3337. +           if (_teams.indexOf(player._teamNameCTF) == 0)
  3338. +           {
  3339. +               player.setTeam(2);
  3340. +               player.setKarma(0);
  3341. +               player.broadcastUserInfo();
  3342. +           }
  3343. +           else
  3344. +           {
  3345. +               player.setTeam(_teams.indexOf(player._teamNameCTF));
  3346. +           }
  3347. +           player.setKarma(0);
  3348. +           player.broadcastUserInfo();
  3349. +       }
  3350. +   }
  3351. +  
  3352. +   public static void finishEvent()
  3353. +   {
  3354. +       if (!finishEventOk())
  3355. +       {
  3356. +           if (Config.DEBUG)
  3357. +           {
  3358. +               _log.fine("CTF Engine[finishEvent]: finishEventOk() = false");
  3359. +           }
  3360. +           return;
  3361. +       }
  3362. +      
  3363. +       _started = false;
  3364. +       unspawnEventNpc();
  3365. +       unspawnAllFlags();
  3366. +       processTopTeam();
  3367. +      
  3368. +       if (_topScore != 0)
  3369. +       {
  3370. +           playKneelAnimation(_topTeam);
  3371. +       }
  3372. +      
  3373. +       if (Config.CTF_ANNOUNCE_TEAM_STATS)
  3374. +       {
  3375. +           AnnounceToPlayers(true, _eventName + " Team Statistics:");
  3376. +           for (String team : _teams)
  3377. +           {
  3378. +               int _flags_ = teamFlagCount(team);
  3379. +               AnnounceToPlayers(true, "Team: " + team + " - Flags taken: " + _flags_);
  3380. +           }
  3381. +       }
  3382. +      
  3383. +       teleportFinish();
  3384. +   }
  3385. +  
  3386. +   // show loosers and winners animations
  3387. +   public static void playKneelAnimation(String teamName)
  3388. +   {
  3389. +       for (L2PcInstance player : _players)
  3390. +       {
  3391. +           if ((player != null) && player.isOnline() && (player._inEventCTF == true))
  3392. +           {
  3393. +               if (!player._teamNameCTF.equals(teamName))
  3394. +               {
  3395. +                   player.broadcastPacket(new SocialAction(player.getObjectId(), 7));
  3396. +               }
  3397. +               else if (player._teamNameCTF.equals(teamName))
  3398. +               {
  3399. +                   player.broadcastPacket(new SocialAction(player.getObjectId(), 3));
  3400. +               }
  3401. +           }
  3402. +       }
  3403. +   }
  3404. +  
  3405. +   private static boolean finishEventOk()
  3406. +   {
  3407. +       if (!_started)
  3408. +       {
  3409. +           return false;
  3410. +       }
  3411. +      
  3412. +       return true;
  3413. +   }
  3414. +  
  3415. +   /*
  3416. +    * Erro nas mensagens public static void rewardTeam(String teamName) { for (L2PcInstance player : _players) { if (player != null) { if (player._teamNameCTF.equals(teamName)) { player.addItem("CTF Event: " + _eventName, _rewardId, _rewardAmount, player, true); NpcHtmlMessage nhm = new
  3417. +    * NpcHtmlMessage(0); TextBuilder replyMSG = new TextBuilder(); int count = 0; replyMSG.append("<html><body><center><font color=\"FF66OO\">PG-L][ Rare CTF Event</font><br>Your team won!<br></center>"); replyMSG.append("<center>-= <font color=\"99CC00\">Best Flag Runners</font> =-</center><br>");
  3418. +    * replyMSG.append("<table width=\"200\" align=\"center\"><tr align=\"center\"><td>"); for (String team : _teams) { replyMSG.append("<font color=\"LEVEL\">" + team + "</font>"); for (L2PcInstance p : _players) { if (_playerScores.containsKey(p.getName())) { if (p._teamNameCTF.equals(team)) {
  3419. +    * replyMSG.append("<br>" + ++count + ". " + p.getName() + " - " + _playerScores.get(p.getName())); } } } if (((_teams.indexOf(team) + 1) % 2) != 0) { if (team == _teams.lastElement()) replyMSG.append("</td></tr></table></body></html>"); else replyMSG.append("</td><td>"); } else { if (team ==
  3420. +    * _teams.lastElement()) replyMSG.append("</td></tr></table></body></html>"); else replyMSG.append("</td></tr><tr><td>"); } count = 0; } nhm.setHtml(replyMSG.toString()); player.sendPacket(nhm); // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait
  3421. +    * another packet player.sendPacket(ActionFailed.STATIC_PACKET); } else { NpcHtmlMessage nhm = new NpcHtmlMessage(0); TextBuilder replyMSG = new TextBuilder(); int count = 0;
  3422. +    * replyMSG.append("<html><body><center><font color=\"FF66OO\">PG-L][ Rare CTF Event</font><br>Better luck next time!<br></center>"); replyMSG.append("<center>-= <font color=\"99CC00\">Best Flag Runners</font> =-</center><br>");
  3423. +    * replyMSG.append("<table width=\"200\" align=\"center\"><center><tr align=\"center\"><td>"); for (String team : _teams) { replyMSG.append("<font color=\"LEVEL\">" + team + "</font>"); for (L2PcInstance p : _players) { if (_playerScores.containsKey(p.getName())) { if
  3424. +    * (p._teamNameCTF.equals(team)) { replyMSG.append("<br>" + ++count + ". " + p.getName() + " - " + _playerScores.get(p.getName())); } } } if (((_teams.indexOf(team) + 1) % 2) != 0) { if (team == _teams.lastElement()) replyMSG.append("</td></tr></table></body></html>"); else
  3425. +    * replyMSG.append("</td><td>"); } else { if (team == _teams.lastElement()) replyMSG.append("</td></tr></table></body></html>"); else replyMSG.append("</td></tr><tr><td>"); } count = 0; } nhm.setHtml(replyMSG.toString()); player.sendPacket(nhm); // Send a Server->Client ActionFailed to the
  3426. +    * L2PcInstance in order to avoid that the client wait another packet player.sendPacket(ActionFailed.STATIC_PACKET); } } } }
  3427. +    */
  3428. +  
  3429. +   public static void rewardTeam(String teamName)
  3430. +   {
  3431. +       for (L2PcInstance player : _players)
  3432. +       {
  3433. +           if (player != null)
  3434. +           {
  3435. +               if (player._teamNameCTF.equals(teamName))
  3436. +               {
  3437. +                   player.addItem("CTF Event: " + _eventName, _rewardId, _rewardAmount, player, true);
  3438. +                  
  3439. +                   NpcHtmlMessage nhm = new NpcHtmlMessage(5);
  3440. +                   TextBuilder replyMSG = new TextBuilder();
  3441. +                  
  3442. +                   replyMSG.append("<html><body>Your team wins the event. Look in your inventory for the reward.</body></html>");
  3443. +                  
  3444. +                   nhm.setHtml(replyMSG.toString());
  3445. +                   player.sendPacket(nhm);
  3446. +                  
  3447. +                   // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  3448. +                   player.sendPacket(ActionFailed.STATIC_PACKET);
  3449. +               }
  3450. +           }
  3451. +       }
  3452. +   }
  3453. +  
  3454. +   public static void abortEvent()
  3455. +   {
  3456. +       if (_joining && !_teleport && !_started)
  3457. +       {
  3458. +           unspawnEventNpc();
  3459. +           cleanCTF();
  3460. +           _joining = false;
  3461. +           AnnounceToPlayers(true, "CTF Event: Match aborted!");
  3462. +           return;
  3463. +       }
  3464. +       _joining = false;
  3465. +       _teleport = false;
  3466. +       _started = false;
  3467. +       unspawnEventNpc();
  3468. +       unspawnAllFlags();
  3469. +       teleportFinish();
  3470. +   }
  3471. +  
  3472. +   public static void dumpData()
  3473. +   {
  3474. +       _log.warning("");
  3475. +       _log.warning("");
  3476. +      
  3477. +       if (!_joining && !_teleport && !_started)
  3478. +       {
  3479. +           _log.warning("<<---------------------------------->>");
  3480. +           _log.warning(">> CTF Engine infos dump (INACTIVE) <<");
  3481. +           _log.warning("<<--^----^^-----^----^^------^^----->>");
  3482. +       }
  3483. +       else if (_joining && !_teleport && !_started)
  3484. +       {
  3485. +           _log.warning("<<--------------------------------->>");
  3486. +           _log.warning(">> CTF Engine infos dump (JOINING) <<");
  3487. +           _log.warning("<<--^----^^-----^----^^------^----->>");
  3488. +       }
  3489. +       else if (!_joining && _teleport && !_started)
  3490. +       {
  3491. +           _log.warning("<<---------------------------------->>");
  3492. +           _log.warning(">> CTF Engine infos dump (TELEPORT) <<");
  3493. +           _log.warning("<<--^----^^-----^----^^------^^----->>");
  3494. +       }
  3495. +       else if (!_joining && !_teleport && _started)
  3496. +       {
  3497. +           _log.warning("<<--------------------------------->>");
  3498. +           _log.warning(">> CTF Engine infos dump (STARTED) <<");
  3499. +           _log.warning("<<--^----^^-----^----^^------^----->>");
  3500. +       }
  3501. +      
  3502. +       _log.warning("Name: " + _eventName);
  3503. +       _log.warning("Desc: " + _eventDesc);
  3504. +       _log.warning("Join location: " + _joiningLocationName);
  3505. +       _log.warning("Min lvl: " + _minlvl);
  3506. +       _log.warning("Max lvl: " + _maxlvl);
  3507. +       _log.warning("");
  3508. +       _log.warning("##########################");
  3509. +       _log.warning("# _teams(Vector<String>) #");
  3510. +       _log.warning("##########################");
  3511. +      
  3512. +       for (String team : _teams)
  3513. +       {
  3514. +           _log.warning(team + " Flags Taken :" + _teamPointsCount.get(_teams.indexOf(team)));
  3515. +       }
  3516. +      
  3517. +       if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  3518. +       {
  3519. +           _log.warning("");
  3520. +           _log.warning("#########################################");
  3521. +           _log.warning("# _playersShuffle(Vector<L2PcInstance>) #");
  3522. +           _log.warning("#########################################");
  3523. +          
  3524. +           for (L2PcInstance player : _playersShuffle)
  3525. +           {
  3526. +               if (player != null)
  3527. +               {
  3528. +                   _log.warning("Name: " + player.getName());
  3529. +               }
  3530. +           }
  3531. +       }
  3532. +      
  3533. +       _log.warning("");
  3534. +       _log.warning("##################################");
  3535. +       _log.warning("# _players(Vector<L2PcInstance>) #");
  3536. +       _log.warning("##################################");
  3537. +      
  3538. +       for (L2PcInstance player : _players)
  3539. +       {
  3540. +           if (player != null)
  3541. +           {
  3542. +               _log.warning("Name: " + player.getName() + "   Team: " + player._teamNameCTF + "  Flags :" + player._countCTFflags);
  3543. +           }
  3544. +       }
  3545. +      
  3546. +       _log.warning("");
  3547. +       _log.warning("#####################################################################");
  3548. +       _log.warning("# _savePlayers(Vector<String>) and _savePlayerTeams(Vector<String>) #");
  3549. +       _log.warning("#####################################################################");
  3550. +      
  3551. +       for (String player : _savePlayers)
  3552. +       {
  3553. +           _log.warning("Name: " + player + "  Team: " + _savePlayerTeams.get(_savePlayers.indexOf(player)));
  3554. +       }
  3555. +      
  3556. +       _log.warning("");
  3557. +       _log.warning("");
  3558. +       _log.warning("**********==CTF==************");
  3559. +       _log.warning("CTF._teamPointsCount:" + _teamPointsCount.toString());
  3560. +       _log.warning("CTF._flagIds:" + _flagIds.toString());
  3561. +       _log.warning("CTF._flagSpawns:" + _flagSpawns.toString());
  3562. +       _log.warning("CTF._throneSpawns:" + _throneSpawns.toString());
  3563. +       _log.warning("CTF._flagsTaken:" + _flagsTaken.toString());
  3564. +       _log.warning("CTF._flagsX:" + _flagsX.toString());
  3565. +       _log.warning("CTF._flagsY:" + _flagsY.toString());
  3566. +       _log.warning("CTF._flagsZ:" + _flagsZ.toString());
  3567. +       _log.warning("************EOF**************");
  3568. +       _log.warning("");
  3569. +   }
  3570. +  
  3571. +   public static void loadData()
  3572. +   {
  3573. +       _eventName = new String();
  3574. +       _eventDesc = new String();
  3575. +       _topTeam = new String();
  3576. +       _joiningLocationName = new String();
  3577. +       _teams = new Vector<>();
  3578. +       _savePlayers = new Vector<>();
  3579. +       _savePlayerTeams = new Vector<>();
  3580. +       _players = new Vector<>();
  3581. +       _playersShuffle = new Vector<>();
  3582. +       _teamPlayersCount = new Vector<>();
  3583. +       _teamPointsCount = new Vector<>();
  3584. +       _teamColors = new Vector<>();
  3585. +       _teamsX = new Vector<>();
  3586. +       _teamsY = new Vector<>();
  3587. +       _teamsZ = new Vector<>();
  3588. +       _teamsBaseX = new Vector<>();
  3589. +       _teamsBaseY = new Vector<>();
  3590. +       _teamsBaseZ = new Vector<>();
  3591. +       _playerScores = new FastMap<>();
  3592. +      
  3593. +       _throneSpawns = new Vector<>();
  3594. +       _flagSpawns = new Vector<>();
  3595. +       _flagsTaken = new Vector<>();
  3596. +       _flagIds = new Vector<>();
  3597. +       _flagsX = new Vector<>();
  3598. +       _flagsY = new Vector<>();
  3599. +       _flagsZ = new Vector<>();
  3600. +       _flagsNotRemoved = new Vector<>();
  3601. +      
  3602. +       _joining = false;
  3603. +       _teleport = false;
  3604. +       _started = false;
  3605. +       _sitForced = false;
  3606. +       _npcId = 0;
  3607. +       _npcX = 0;
  3608. +       _npcY = 0;
  3609. +       _npcZ = 0;
  3610. +       _npcHeading = 0;
  3611. +       _rewardId = 0;
  3612. +       _rewardAmount = 0;
  3613. +       _topScore = 0;
  3614. +       _minlvl = 0;
  3615. +       _maxlvl = 0;
  3616. +       _joinTime = 0;
  3617. +       _eventTime = 0;
  3618. +       _minPlayers = 0;
  3619. +       _maxPlayers = 0;
  3620. +       _flagHoldTime = 0;
  3621. +      
  3622. +       Connection con = null;
  3623. +       try
  3624. +       {
  3625. +           PreparedStatement statement;
  3626. +           ResultSet rs;
  3627. +          
  3628. +           con = L2DatabaseFactory.getInstance().getConnection();
  3629. +          
  3630. +           statement = con.prepareStatement("Select * from ctf");
  3631. +           rs = statement.executeQuery();
  3632. +          
  3633. +           int teams = 0;
  3634. +          
  3635. +           while (rs.next())
  3636. +           {
  3637. +               _eventName = rs.getString("eventName");
  3638. +               _eventDesc = rs.getString("eventDesc");
  3639. +               _joiningLocationName = rs.getString("joiningLocation");
  3640. +               _minlvl = rs.getInt("minlvl");
  3641. +               _maxlvl = rs.getInt("maxlvl");
  3642. +               _npcId = rs.getInt("npcId");
  3643. +               _npcX = rs.getInt("npcX");
  3644. +               _npcY = rs.getInt("npcY");
  3645. +               _npcZ = rs.getInt("npcZ");
  3646. +               _npcHeading = rs.getInt("npcHeading");
  3647. +               _rewardId = rs.getInt("rewardId");
  3648. +               _rewardAmount = rs.getInt("rewardAmount");
  3649. +               teams = rs.getInt("teamsCount");
  3650. +               _joinTime = rs.getInt("joinTime");
  3651. +               _eventTime = rs.getInt("eventTime");
  3652. +               _minPlayers = rs.getInt("minPlayers");
  3653. +               _maxPlayers = rs.getInt("maxPlayers");
  3654. +               _flagHoldTime = rs.getInt("flagHoldTime");
  3655. +           }
  3656. +           statement.close();
  3657. +          
  3658. +           int index = -1;
  3659. +           if (teams > 0)
  3660. +           {
  3661. +               index = 0;
  3662. +           }
  3663. +           while ((index < teams) && (index > -1))
  3664. +           {
  3665. +               statement = con.prepareStatement("Select * from ctf_teams where teamId = ?");
  3666. +               statement.setInt(1, index);
  3667. +               rs = statement.executeQuery();
  3668. +               while (rs.next())
  3669. +               {
  3670. +                   _teams.add(rs.getString("teamName"));
  3671. +                   _teamPlayersCount.add(0);
  3672. +                   _teamPointsCount.add(0);
  3673. +                   _teamColors.add(0);
  3674. +                   _teamsX.add(0);
  3675. +                   _teamsY.add(0);
  3676. +                   _teamsZ.add(0);
  3677. +                   _teamsX.set(index, rs.getInt("teamX"));
  3678. +                   _teamsY.set(index, rs.getInt("teamY"));
  3679. +                   _teamsZ.set(index, rs.getInt("teamZ"));
  3680. +                   _teamColors.set(index, rs.getInt("teamColor"));
  3681. +                   _flagsX.add(0);
  3682. +                   _flagsY.add(0);
  3683. +                   _flagsZ.add(0);
  3684. +                   _flagsX.set(index, rs.getInt("flagX"));
  3685. +                   _flagsY.set(index, rs.getInt("flagY"));
  3686. +                   _flagsZ.set(index, rs.getInt("flagZ"));
  3687. +                   if (Config.CTF_BASE_TELEPORT_FIRST)
  3688. +                   {
  3689. +                       _teamsBaseX.add(0);
  3690. +                       _teamsBaseY.add(0);
  3691. +                       _teamsBaseZ.add(0);
  3692. +                       _teamsBaseX.set(index, rs.getInt("teamBaseX"));
  3693. +                       _teamsBaseY.set(index, rs.getInt("teamBaseY"));
  3694. +                       _teamsBaseZ.set(index, rs.getInt("teamBaseZ"));
  3695. +                   }
  3696. +                   _flagSpawns.add(null);
  3697. +                   _flagIds.add(_FlagNPC);
  3698. +                   _flagsTaken.add(false);
  3699. +                   _flagsNotRemoved.add(false);
  3700. +               }
  3701. +               index++;
  3702. +               statement.close();
  3703. +           }
  3704. +       }
  3705. +       catch (Exception e)
  3706. +       {
  3707. +           _log.warning("Exception: CTF.loadData(): " + e.getMessage());
  3708. +       }
  3709. +       finally
  3710. +       {
  3711. +           try
  3712. +           {
  3713. +               if (con != null)
  3714. +               {
  3715. +                   con.close();
  3716. +               }
  3717. +           }
  3718. +           catch (SQLException e)
  3719. +           {
  3720. +               e.printStackTrace();
  3721. +           }
  3722. +       }
  3723. +   }
  3724. +  
  3725. +   public static void saveData()
  3726. +   {
  3727. +       Connection con = null;
  3728. +       try
  3729. +       {
  3730. +           con = L2DatabaseFactory.getInstance().getConnection();
  3731. +           PreparedStatement statement;
  3732. +          
  3733. +           statement = con.prepareStatement("Delete from ctf");
  3734. +           statement.execute();
  3735. +           statement.close();
  3736. +          
  3737. +           statement = con.prepareStatement("INSERT INTO ctf (eventName, eventDesc, joiningLocation, minlvl, maxlvl, npcId, npcX, npcY, npcZ, npcHeading, rewardId, rewardAmount, teamsCount, joinTime, eventTime, minPlayers, maxPlayers, flagHoldTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  3738. +           statement.setString(1, _eventName);
  3739. +           statement.setString(2, _eventDesc);
  3740. +           statement.setString(3, _joiningLocationName);
  3741. +           statement.setInt(4, _minlvl);
  3742. +           statement.setInt(5, _maxlvl);
  3743. +           statement.setInt(6, _npcId);
  3744. +           statement.setInt(7, _npcX);
  3745. +           statement.setInt(8, _npcY);
  3746. +           statement.setInt(9, _npcZ);
  3747. +           statement.setInt(10, _npcHeading);
  3748. +           statement.setInt(11, _rewardId);
  3749. +           statement.setInt(12, _rewardAmount);
  3750. +           statement.setInt(13, _teams.size());
  3751. +           statement.setInt(14, _joinTime);
  3752. +           statement.setInt(15, _eventTime);
  3753. +           statement.setInt(16, _minPlayers);
  3754. +           statement.setInt(17, _maxPlayers);
  3755. +           statement.setLong(18, _flagHoldTime);
  3756. +           statement.execute();
  3757. +           statement.close();
  3758. +          
  3759. +           statement = con.prepareStatement("Delete from ctf_teams");
  3760. +           statement.execute();
  3761. +           statement.close();
  3762. +          
  3763. +           for (String teamName : _teams)
  3764. +           {
  3765. +               int index = _teams.indexOf(teamName);
  3766. +              
  3767. +               if (index == -1)
  3768. +               {
  3769. +                   return;
  3770. +               }
  3771. +               if (Config.CTF_BASE_TELEPORT_FIRST)
  3772. +               {
  3773. +                   statement = con.prepareStatement("INSERT INTO ctf_teams (teamId ,teamName, teamX, teamY, teamZ, teamColor, flagX, flagY, flagZ, teamBaseX, teamBaseY, teamBaseZ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  3774. +                   statement.setInt(1, index);
  3775. +                   statement.setString(2, teamName);
  3776. +                   statement.setInt(3, _teamsX.get(index));
  3777. +                   statement.setInt(4, _teamsY.get(index));
  3778. +                   statement.setInt(5, _teamsZ.get(index));
  3779. +                   statement.setInt(6, _teamColors.get(index));
  3780. +                   statement.setInt(7, _flagsX.get(index));
  3781. +                   statement.setInt(8, _flagsY.get(index));
  3782. +                   statement.setInt(9, _flagsZ.get(index));
  3783. +                   statement.setInt(10, _teamsBaseX.get(index));
  3784. +                   statement.setInt(11, _teamsBaseY.get(index));
  3785. +                   statement.setInt(12, _teamsBaseZ.get(index));
  3786. +                   statement.execute();
  3787. +                   statement.close();
  3788. +               }
  3789. +               else
  3790. +               {
  3791. +                   statement = con.prepareStatement("INSERT INTO ctf_teams (teamId ,teamName, teamX, teamY, teamZ, teamColor, flagX, flagY, flagZ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
  3792. +                   statement.setInt(1, index);
  3793. +                   statement.setString(2, teamName);
  3794. +                   statement.setInt(3, _teamsX.get(index));
  3795. +                   statement.setInt(4, _teamsY.get(index));
  3796. +                   statement.setInt(5, _teamsZ.get(index));
  3797. +                   statement.setInt(6, _teamColors.get(index));
  3798. +                   statement.setInt(7, _flagsX.get(index));
  3799. +                   statement.setInt(8, _flagsY.get(index));
  3800. +                   statement.setInt(9, _flagsZ.get(index));
  3801. +                   statement.execute();
  3802. +                   statement.close();
  3803. +               }
  3804. +           }
  3805. +       }
  3806. +       catch (Exception e)
  3807. +       {
  3808. +           _log.warning("Exception: CTF.saveData(): " + e.getMessage());
  3809. +       }
  3810. +       finally
  3811. +       {
  3812. +           try
  3813. +           {
  3814. +               if (con != null)
  3815. +               {
  3816. +                   con.close();
  3817. +               }
  3818. +           }
  3819. +           catch (SQLException e)
  3820. +           {
  3821. +               e.printStackTrace();
  3822. +           }
  3823. +       }
  3824. +   }
  3825. +  
  3826. +   public static void showEventHtml(L2PcInstance eventPlayer, String objectId)
  3827. +   {
  3828. +       try
  3829. +       {
  3830. +           NpcHtmlMessage adminReply = new NpcHtmlMessage(0);
  3831. +           TextBuilder replyMSG = new TextBuilder();
  3832. +          
  3833. +           replyMSG.append("<html><body>");
  3834. +           replyMSG.append("CTF Match<br><br><br>");
  3835. +           replyMSG.append("Current event...<br>");
  3836. +           replyMSG.append("   ... description:&nbsp;<font color=\"00FF00\">" + _eventDesc + "</font><br>");
  3837. +           if (Config.CTF_ANNOUNCE_REWARD)
  3838. +           {
  3839. +               replyMSG.append("   ... reward: (" + _rewardAmount + ") " + ItemTable.getInstance().getTemplate(_rewardId).getName() + "<br>");
  3840. +           }
  3841. +          
  3842. +           if (!_started && !_joining)
  3843. +           {
  3844. +               replyMSG.append("<center>Wait till the admin/gm start the participation.</center>");
  3845. +           }
  3846. +           else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !checkMaxPlayers(_playersShuffle.size()))
  3847. +           {
  3848. +               if (!CTF._started)
  3849. +               {
  3850. +                   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.");
  3851. +               }
  3852. +           }
  3853. +           else if (eventPlayer.isCursedWeaponEquipped() && !Config.CTF_JOIN_CURSED)
  3854. +           {
  3855. +               replyMSG.append("<font color=\"FFFF00\">You can't participate in this event with a cursed Weapon.</font><br>");
  3856. +           }
  3857. +           else if (!_started && _joining && (eventPlayer.getLevel() >= _minlvl) && (eventPlayer.getLevel() <= _maxlvl))
  3858. +           {
  3859. +               if (_players.contains(eventPlayer) || checkShufflePlayers(eventPlayer))
  3860. +               {
  3861. +                   if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  3862. +                   {
  3863. +                       replyMSG.append("You are already participating in team <font color=\"LEVEL\">" + eventPlayer._teamNameCTF + "</font><br><br>");
  3864. +                   }
  3865. +                   else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  3866. +                   {
  3867. +                       replyMSG.append("You are already participating!<br><br>");
  3868. +                   }
  3869. +                  
  3870. +                   replyMSG.append("<table border=\"0\"><tr>");
  3871. +                   replyMSG.append("<td width=\"200\">Wait till event start or</td>");
  3872. +                   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>");
  3873. +                   replyMSG.append("<td width=\"100\">your participation!</td>");
  3874. +                   replyMSG.append("</tr></table>");
  3875. +               }
  3876. +               else
  3877. +               {
  3878. +                   replyMSG.append("<td width=\"200\">Your level : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font></td><br>");
  3879. +                   replyMSG.append("<td width=\"200\">Min level : <font color=\"00FF00\">" + _minlvl + "</font></td><br>");
  3880. +                   replyMSG.append("<td width=\"200\">Max level : <font color=\"00FF00\">" + _maxlvl + "</font></td><br><br>");
  3881. +                  
  3882. +                   if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  3883. +                   {
  3884. +                       replyMSG.append("<center><table border=\"0\">");
  3885. +                      
  3886. +                       for (String team : _teams)
  3887. +                       {
  3888. +                           replyMSG.append("<tr><td width=\"100\"><font color=\"LEVEL\">" + team + "</font>&nbsp;(" + teamPlayersCount(team) + " joined)</td>");
  3889. +                           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>");
  3890. +                       }
  3891. +                      
  3892. +                       replyMSG.append("</table></center>");
  3893. +                   }
  3894. +                   else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  3895. +                   {
  3896. +                       replyMSG.append("<center><table border=\"0\">");
  3897. +                      
  3898. +                       for (String team : _teams)
  3899. +                       {
  3900. +                           replyMSG.append("<tr><td width=\"100\"><font color=\"LEVEL\">" + team + "</font></td>");
  3901. +                       }
  3902. +                      
  3903. +                       replyMSG.append("</table></center><br>");
  3904. +                      
  3905. +                       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\">");
  3906. +                       replyMSG.append("Teams will be randomly generated!");
  3907. +                   }
  3908. +               }
  3909. +           }
  3910. +           else if (_started && !_joining)
  3911. +           {
  3912. +               replyMSG.append("<center>CTF match is in progress.</center>");
  3913. +           }
  3914. +           else if ((eventPlayer.getLevel() < _minlvl) || (eventPlayer.getLevel() > _maxlvl))
  3915. +           {
  3916. +               replyMSG.append("Your lvl : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font><br>");
  3917. +               replyMSG.append("Min level : <font color=\"00FF00\">" + _minlvl + "</font><br>");
  3918. +               replyMSG.append("Max level : <font color=\"00FF00\">" + _maxlvl + "</font><br><br>");
  3919. +               replyMSG.append("<font color=\"FFFF00\">You can't participatein this event.</font><br>");
  3920. +           }
  3921. +           // Show how many players joined & how many are still needed to join
  3922. +           replyMSG.append("<br>There are " + _playersShuffle.size() + " player(s) participating in this event.<br>");
  3923. +           if (_joining)
  3924. +           {
  3925. +               if (_playersShuffle.size() < _minPlayers)
  3926. +               {
  3927. +                   int playersNeeded = _minPlayers - _playersShuffle.size();
  3928. +                   replyMSG.append("The event will not start unless " + playersNeeded + " more player(s) joins!");
  3929. +               }
  3930. +           }
  3931. +          
  3932. +           replyMSG.append("</body></html>");
  3933. +           adminReply.setHtml(replyMSG.toString());
  3934. +           eventPlayer.sendPacket(adminReply);
  3935. +          
  3936. +           // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  3937. +           eventPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  3938. +       }
  3939. +       catch (Exception e)
  3940. +       {
  3941. +           _log.warning("CTF Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception" + e.getMessage());
  3942. +       }
  3943. +   }
  3944. +  
  3945. +   public static void addPlayer(L2PcInstance player, String teamName)
  3946. +   {
  3947. +       if (!addPlayerOk(teamName, player))
  3948. +       {
  3949. +           return;
  3950. +       }
  3951. +      
  3952. +       if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  3953. +       {
  3954. +           player._teamNameCTF = teamName;
  3955. +           _players.add(player);
  3956. +           setTeamPlayersCount(teamName, teamPlayersCount(teamName) + 1);
  3957. +       }
  3958. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  3959. +       {
  3960. +           _playersShuffle.add(player);
  3961. +       }
  3962. +      
  3963. +       player._inEventCTF = true;
  3964. +       player._countCTFflags = 0;
  3965. +   }
  3966. +  
  3967. +   public static synchronized void removeOfflinePlayers()
  3968. +   {
  3969. +       try
  3970. +       {
  3971. +           if (_playersShuffle == null)
  3972. +           {
  3973. +               return;
  3974. +           }
  3975. +           else if (_playersShuffle.isEmpty())
  3976. +           {
  3977. +               return;
  3978. +           }
  3979. +           else if (_playersShuffle.size() > 0)
  3980. +           {
  3981. +               for (L2PcInstance player : _playersShuffle)
  3982. +               {
  3983. +                   if (player == null)
  3984. +                   {
  3985. +                       _playersShuffle.remove(player);
  3986. +                   }
  3987. +                   else if (!player.isOnline() || player.isInJail())
  3988. +                   {
  3989. +                       removePlayer(player);
  3990. +                   }
  3991. +                   if ((_playersShuffle.size() == 0) || _playersShuffle.isEmpty())
  3992. +                   {
  3993. +                       break;
  3994. +                   }
  3995. +               }
  3996. +           }
  3997. +       }
  3998. +       catch (Exception e)
  3999. +       {
  4000. +           _log.warning("CTF Engine exception: " + e.getMessage());
  4001. +           return;
  4002. +       }
  4003. +   }
  4004. +  
  4005. +   public static boolean checkShufflePlayers(L2PcInstance eventPlayer)
  4006. +   {
  4007. +       try
  4008. +       {
  4009. +           for (L2PcInstance player : _playersShuffle)
  4010. +           {
  4011. +               if ((player == null) || !player.isOnline())
  4012. +               {
  4013. +                   _playersShuffle.remove(player);
  4014. +                   eventPlayer._inEventCTF = false;
  4015. +                   continue;
  4016. +               }
  4017. +               else if (player.getObjectId() == eventPlayer.getObjectId())
  4018. +               {
  4019. +                   eventPlayer._inEventCTF = true;
  4020. +                   eventPlayer._countCTFflags = 0;
  4021. +                   return true;
  4022. +               }
  4023. +               // this 1 is incase player got new objectid after DC or reconnect
  4024. +               else if (player.getName().equals(eventPlayer.getName()))
  4025. +               {
  4026. +                   _playersShuffle.remove(player);
  4027. +                   _playersShuffle.add(eventPlayer);
  4028. +                   eventPlayer._inEventCTF = true;
  4029. +                   eventPlayer._countCTFflags = 0;
  4030. +                   return true;
  4031. +               }
  4032. +           }
  4033. +       }
  4034. +       catch (Exception e)
  4035. +       {
  4036. +       }
  4037. +       return false;
  4038. +   }
  4039. +  
  4040. +   public static boolean addPlayerOk(String teamName, L2PcInstance eventPlayer)
  4041. +   {
  4042. +       try
  4043. +       {
  4044. +           if (checkShufflePlayers(eventPlayer) || eventPlayer._inEventCTF)
  4045. +           {
  4046. +               eventPlayer.sendMessage("You are already participating in the event!");
  4047. +               return false;
  4048. +           }
  4049. +          
  4050. +           for (L2PcInstance player : _players)
  4051. +           {
  4052. +               if (player.getObjectId() == eventPlayer.getObjectId())
  4053. +               {
  4054. +                   eventPlayer.sendMessage("You are already participating in the event!");
  4055. +                   return false;
  4056. +               }
  4057. +               else if (player.getName() == eventPlayer.getName())
  4058. +               {
  4059. +                   eventPlayer.sendMessage("You are already participating in the event!");
  4060. +                   return false;
  4061. +               }
  4062. +           }
  4063. +           if (_players.contains(eventPlayer))
  4064. +           {
  4065. +               eventPlayer.sendMessage("You are already participating in the event!");
  4066. +               return false;
  4067. +           }
  4068. +       }
  4069. +       catch (Exception e)
  4070. +       {
  4071. +           _log.warning("CTF Siege Engine exception: " + e.getMessage());
  4072. +       }
  4073. +      
  4074. +       if (Config.CTF_EVEN_TEAMS.equals("NO"))
  4075. +       {
  4076. +           return true;
  4077. +       }
  4078. +       else if (Config.CTF_EVEN_TEAMS.equals("BALANCE"))
  4079. +       {
  4080. +           boolean allTeamsEqual = true;
  4081. +           int countBefore = -1;
  4082. +          
  4083. +           for (int playersCount : _teamPlayersCount)
  4084. +           {
  4085. +               if (countBefore == -1)
  4086. +               {
  4087. +                   countBefore = playersCount;
  4088. +               }
  4089. +              
  4090. +               if (countBefore != playersCount)
  4091. +               {
  4092. +                   allTeamsEqual = false;
  4093. +                   break;
  4094. +               }
  4095. +              
  4096. +               countBefore = playersCount;
  4097. +           }
  4098. +          
  4099. +           if (allTeamsEqual)
  4100. +           {
  4101. +               return true;
  4102. +           }
  4103. +          
  4104. +           countBefore = Integer.MAX_VALUE;
  4105. +          
  4106. +           for (int teamPlayerCount : _teamPlayersCount)
  4107. +           {
  4108. +               if (teamPlayerCount < countBefore)
  4109. +               {
  4110. +                   countBefore = teamPlayerCount;
  4111. +               }
  4112. +           }
  4113. +          
  4114. +           Vector<String> joinableTeams = new Vector<>();
  4115. +          
  4116. +           for (String team : _teams)
  4117. +           {
  4118. +               if (teamPlayersCount(team) == countBefore)
  4119. +               {
  4120. +                   joinableTeams.add(team);
  4121. +               }
  4122. +           }
  4123. +          
  4124. +           if (joinableTeams.contains(teamName))
  4125. +           {
  4126. +               return true;
  4127. +           }
  4128. +       }
  4129. +       else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
  4130. +       {
  4131. +           return true;
  4132. +       }
  4133. +      
  4134. +       eventPlayer.sendMessage("Too many players in team \"" + teamName + "\"");
  4135. +       return false;
  4136. +   }
  4137. +  
  4138. +   public static synchronized void addDisconnectedPlayer(L2PcInstance player)
  4139. +   {
  4140. +       /*
  4141. +        * !!! CAUTION !!! Do NOT fix multiple object Ids on this event or you will ruin the flag reposition check!!! All Multiple object Ids will be collected by the Garbage Collector, after the event ends, memory sweep is made!!!
  4142. +        */
  4143. +      
  4144. +       if ((Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && (_teleport || _started)) || (Config.CTF_EVEN_TEAMS.equals("NO") || (Config.CTF_EVEN_TEAMS.equals("BALANCE") && (_teleport || _started))))
  4145. +       {
  4146. +           if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
  4147. +           {
  4148. +               for (L2Effect e : player.getAllEffects())
  4149. +               {
  4150. +                   if (e != null)
  4151. +                   {
  4152. +                       e.exit();
  4153. +                   }
  4154. +               }
  4155. +           }
  4156. +          
  4157. +           player._teamNameCTF = _savePlayerTeams.get(_savePlayers.indexOf(player.getName()));
  4158. +           for (L2PcInstance p : _players)
  4159. +           {
  4160. +               if (p == null)
  4161. +               {
  4162. +                   continue;
  4163. +               }
  4164. +               // check by name incase player got new objectId
  4165. +               else if (p.getName().equals(player.getName()))
  4166. +               {
  4167. +                   player._originalNameColorCTF = player.getAppearance().getNameColor();
  4168. +                   player._originalKarmaCTF = player.getKarma();
  4169. +                   player._inEventCTF = true;
  4170. +                   player._countCTFflags = p._countCTFflags;
  4171. +                   _players.remove(p); // removing old object id from vector
  4172. +                   _players.add(player); // adding new objectId to vector
  4173. +                   break;
  4174. +               }
  4175. +           }
  4176. +           player.setTeam(_teams.indexOf(player._teamNameCTF));
  4177. +           player.setKarma(0);
  4178. +           player.broadcastUserInfo();
  4179. +           if (Config.CTF_BASE_TELEPORT_FIRST)
  4180. +           {
  4181. +               player.sendMessage("We missed you! You will be sent back into battle in 10 seconds!");
  4182. +              
  4183. +               player.teleToLocation(_teamsBaseX.get(_teams.indexOf(player._teamNameCTF)), _teamsBaseY.get(_teams.indexOf(player._teamNameCTF)), _teamsBaseZ.get(_teams.indexOf(player._teamNameCTF)));
  4184. +              
  4185. +               ThreadPoolManager.getInstance().scheduleGeneral(new BaseTeleportTask(player, false), 10000);
  4186. +           }
  4187. +           else
  4188. +           {
  4189. +               player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ.get(_teams.indexOf(player._teamNameCTF)));
  4190. +           }
  4191. +           Started(player);
  4192. +           CheckRestoreFlags();
  4193. +       }
  4194. +   }
  4195. +  
  4196. +   public static void removePlayer(L2PcInstance player)
  4197. +   {
  4198. +       if (player._inEventCTF)
  4199. +       {
  4200. +           if (!_joining)
  4201. +           {
  4202. +               player.getAppearance().setNameColor(player._originalNameColorCTF);
  4203. +               player.setKarma(player._originalKarmaCTF);
  4204. +               player.broadcastUserInfo();
  4205. +           }
  4206. +           player._teamNameCTF = new String();
  4207. +           player._countCTFflags = 0;
  4208. +           player._inEventCTF = false;
  4209. +          
  4210. +           if ((Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE")) && _players.contains(player))
  4211. +           {
  4212. +               setTeamPlayersCount(player._teamNameCTF, teamPlayersCount(player._teamNameCTF) - 1);
  4213. +               _players.remove(player);
  4214. +           }
  4215. +           else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && (!_playersShuffle.isEmpty() && _playersShuffle.contains(player)))
  4216. +           {
  4217. +               _playersShuffle.remove(player);
  4218. +           }
  4219. +       }
  4220. +   }
  4221. +  
  4222. +   public static void cleanCTF()
  4223. +   {
  4224. +       _log.warning("CTF : Cleaning players.");
  4225. +       for (L2PcInstance player : _players)
  4226. +       {
  4227. +           if (player != null)
  4228. +           {
  4229. +               if (player._haveFlagCTF)
  4230. +               {
  4231. +                   removeFlagFromPlayer(player);
  4232. +               }
  4233. +               else
  4234. +               {
  4235. +                   player.getInventory().destroyItemByItemId("", CTF._FLAG_IN_HAND_ITEM_ID, 1, player, null);
  4236. +               }
  4237. +               player._haveFlagCTF = false;
  4238. +               removePlayer(player);
  4239. +               if (_savePlayers.contains(player.getName()))
  4240. +               {
  4241. +                   _savePlayers.remove(player.getName());
  4242. +               }
  4243. +               player._inEventCTF = false;
  4244. +           }
  4245. +       }
  4246. +       if ((_playersShuffle != null) && !_playersShuffle.isEmpty())
  4247. +       {
  4248. +           for (L2PcInstance player : _playersShuffle)
  4249. +           {
  4250. +               if (player != null)
  4251. +               {
  4252. +                   player._inEventCTF = false;
  4253. +               }
  4254. +           }
  4255. +       }
  4256. +       _log.warning("CTF : Cleaning teams and flags.");
  4257. +       for (String team : _teams)
  4258. +       {
  4259. +           int index = _teams.indexOf(team);
  4260. +           _teamPointsCount.set(index, 0);
  4261. +           _flagSpawns.set(index, null);
  4262. +           _flagsTaken.set(index, false);
  4263. +           _teamPlayersCount.set(index, 0);
  4264. +           _teamPointsCount.set(index, 0);
  4265. +           _flagsNotRemoved.set(index, false);
  4266. +       }
  4267. +       _topScore = 0;
  4268. +       _topTeam = new String();
  4269. +       _players = new Vector<>();
  4270. +       _playersShuffle = new Vector<>();
  4271. +       _savePlayers = new Vector<>();
  4272. +       _savePlayerTeams = new Vector<>();
  4273. +       _teamPointsCount = new Vector<>();
  4274. +       _flagSpawns = new Vector<>();
  4275. +       _flagsTaken = new Vector<>();
  4276. +       _teamPlayersCount = new Vector<>();
  4277. +       _flagsNotRemoved = new Vector<>();
  4278. +       _playerScores = new FastMap<>();
  4279. +       _log.warning("Cleaning CTF done.");
  4280. +       _log.warning("Loading new data from MySql");
  4281. +       loadData();
  4282. +   }
  4283. +  
  4284. +   public static void unspawnEventNpc()
  4285. +   {
  4286. +       if (_npcSpawn == null)
  4287. +       {
  4288. +           return;
  4289. +       }
  4290. +      
  4291. +       _npcSpawn.getLastSpawn().deleteMe();
  4292. +       _npcSpawn.stopRespawn();
  4293. +       SpawnTable.getInstance().deleteSpawn(_npcSpawn, true);
  4294. +   }
  4295. +  
  4296. +   public static void teleportFinish()
  4297. +   {
  4298. +       AnnounceToPlayers(false, "CTF Event: Teleport back to participation NPC in 15 seconds!");
  4299. +       ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  4300. +       {
  4301. +           @Override
  4302. +           public void run()
  4303. +           {
  4304. +               for (L2PcInstance player : _players)
  4305. +               {
  4306. +                   if (player != null)
  4307. +                   {
  4308. +                       if (player.isOnline())
  4309. +                       {
  4310. +                           player.setTeam(0);
  4311. +                           player.broadcastUserInfo();
  4312. +                           player.teleToLocation(_npcX, _npcY, _npcZ, false);
  4313. +                       }
  4314. +                      
  4315. +                       else
  4316. +                       {
  4317. +                           Connection con = null;
  4318. +                           try
  4319. +                           {
  4320. +                               con = L2DatabaseFactory.getInstance().getConnection();
  4321. +                              
  4322. +                               PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=? WHERE char_name=?");
  4323. +                               statement.setInt(1, _npcX);
  4324. +                               statement.setInt(2, _npcY);
  4325. +                               statement.setInt(3, _npcZ);
  4326. +                               statement.setString(4, player.getName());
  4327. +                               statement.execute();
  4328. +                               statement.close();
  4329. +                           }
  4330. +                           catch (SQLException se)
  4331. +                           {
  4332. +                               _log.warning("CTF Engine exception: " + se.getMessage());
  4333. +                           }
  4334. +                           finally
  4335. +                           {
  4336. +                               try
  4337. +                               {
  4338. +                                   if (con != null)
  4339. +                                   {
  4340. +                                       con.close();
  4341. +                                   }
  4342. +                               }
  4343. +                               catch (SQLException e)
  4344. +                               {
  4345. +                                   e.printStackTrace();
  4346. +                               }
  4347. +                           }
  4348. +                       }
  4349. +                   }
  4350. +               }
  4351. +               cleanCTF();
  4352. +           }
  4353. +       }, 15000);
  4354. +   }
  4355. +  
  4356. +   public static int teamFlagCount(String teamName)
  4357. +   {
  4358. +       int index = _teams.indexOf(teamName);
  4359. +      
  4360. +       if (index == -1)
  4361. +       {
  4362. +           return -1;
  4363. +       }
  4364. +      
  4365. +       return _teamPointsCount.get(index);
  4366. +   }
  4367. +  
  4368. +   public static void setTeamFlagCount(String teamName, int teamFlagCount)
  4369. +   {
  4370. +       int index = _teams.indexOf(teamName);
  4371. +      
  4372. +       if (index == -1)
  4373. +       {
  4374. +           return;
  4375. +       }
  4376. +      
  4377. +       _teamPointsCount.set(index, teamFlagCount);
  4378. +   }
  4379. +  
  4380. +   /**
  4381. +    * Used to calculate the event CTF area, so that players don't run off with the flag. Essential, since a player may take the flag just so other teams can't score points. This function is Only called upon ONE time on BEGINING OF EACH EVENT right after we spawn the flags.
  4382. +    */
  4383. +   private static void calculateOutSideOfCTF()
  4384. +   {
  4385. +       if ((_teams == null) || (_flagSpawns == null) || (_teamsX == null) || (_teamsY == null) || (_teamsZ == null))
  4386. +       {
  4387. +           return;
  4388. +       }
  4389. +      
  4390. +       int division = _teams.size() * 2, pos = 0;
  4391. +       int[] locX = new int[division], locY = new int[division], locZ = new int[division];
  4392. +       // Get all coordinates inorder to create a polygon:
  4393. +       for (L2Spawn flag : _flagSpawns)
  4394. +       {
  4395. +           locX[pos] = flag.getLocx();
  4396. +           locY[pos] = flag.getLocy();
  4397. +           locZ[pos] = flag.getLocz();
  4398. +           pos++;
  4399. +           if (pos > (division / 2))
  4400. +           {
  4401. +               break;
  4402. +           }
  4403. +       }
  4404. +      
  4405. +       for (int x = 0; x < _teams.size(); x++)
  4406. +       {
  4407. +           locX[pos] = _teamsX.get(x);
  4408. +           locY[pos] = _teamsY.get(x);
  4409. +           locZ[pos] = _teamsZ.get(x);
  4410. +           pos++;
  4411. +           if (pos > division)
  4412. +           {
  4413. +               break;
  4414. +           }
  4415. +       }
  4416. +      
  4417. +       // find the polygon center, note that it's not the mathematical center of the polygon,
  4418. +       // rather than a point which centers all coordinates:
  4419. +       int centerX = 0, centerY = 0, centerZ = 0;
  4420. +       for (int x = 0; x < pos; x++)
  4421. +       {
  4422. +           centerX += (locX[x] / division);
  4423. +           centerY += (locY[x] / division);
  4424. +           centerZ += (locZ[x] / division);
  4425. +       }
  4426. +      
  4427. +       // now let's find the furthest distance from the "center" to the egg shaped sphere
  4428. +       // surrounding the polygon, size x1.5 (for maximum logical area to wander...):
  4429. +       int maxX = 0, maxY = 0, maxZ = 0;
  4430. +       for (int x = 0; x < pos; x++)
  4431. +       {
  4432. +           if (maxX < (2 * Math.abs(centerX - locX[x])))
  4433. +           {
  4434. +               maxX = (2 * Math.abs(centerX - locX[x]));
  4435. +           }
  4436. +           if (maxY < (2 * Math.abs(centerY - locY[x])))
  4437. +           {
  4438. +               maxY = (2 * Math.abs(centerY - locY[x]));
  4439. +           }
  4440. +           if (maxZ < (2 * Math.abs(centerZ - locZ[x])))
  4441. +           {
  4442. +               maxZ = (2 * Math.abs(centerZ - locZ[x]));
  4443. +           }
  4444. +       }
  4445. +      
  4446. +       // centerX,centerY,centerZ are the coordinates of the "event center".
  4447. +       // so let's save those coordinates to check on the players:
  4448. +       eventCenterX = centerX;
  4449. +       eventCenterY = centerY;
  4450. +       eventCenterZ = centerZ;
  4451. +       eventOffset = maxX;
  4452. +       if (eventOffset < maxY)
  4453. +       {
  4454. +           eventOffset = maxY;
  4455. +       }
  4456. +       if (eventOffset < maxZ)
  4457. +       {
  4458. +           eventOffset = maxZ;
  4459. +       }
  4460. +   }
  4461. +  
  4462. +   /**
  4463. +    * Called on every potion use
  4464. +    * @param playerObjectId
  4465. +    * @param player
  4466. +    * @return boolean: true if player is allowed to use potions, otherwise false
  4467. +    */
  4468. +   public static boolean onPotionUse(int playerObjectId, L2PcInstance player)
  4469. +   {
  4470. +       if (!_started)
  4471. +       {
  4472. +           return true;
  4473. +       }
  4474. +      
  4475. +       // if (CTF.startEventOk() && !Config.CTF_ALLOW_POTIONS)
  4476. +       if (((player != null) && player.isOnline() && (player._inEventCTF == true)) && !Config.CTF_ALLOW_POTIONS)
  4477. +       {
  4478. +           return false;
  4479. +       }
  4480. +       return true;
  4481. +   }
  4482. +  
  4483. +   public static boolean isOutsideCTFArea(L2PcInstance _player)
  4484. +   {
  4485. +       if ((_player == null) || !_player.isOnline())
  4486. +       {
  4487. +           return true;
  4488. +       }
  4489. +       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))))
  4490. +       {
  4491. +           return true;
  4492. +       }
  4493. +       return false;
  4494. +   }
  4495. +  
  4496. +   @SuppressWarnings("synthetic-access")
  4497. +   private static class SingletonHolder
  4498. +   {
  4499. +       protected static final CTF _instance = new CTF();
  4500. +   }
  4501. +}
  4502. \ No newline at end of file
  4503. Index: java/l2jcrimmerproject/gameserver/model/actor/instance/L2PcInstance.java
  4504. ===================================================================
  4505. --- java/l2jcrimmerproject/gameserver/model/actor/instance/L2PcInstance.java    (revision 12)
  4506. +++ java/l2jcrimmerproject/gameserver/model/actor/instance/L2PcInstance.java    (working copy)
  4507. @@ -164,6 +164,8 @@
  4508.  import l2jcrimmerproject.gameserver.model.effects.EffectTemplate;
  4509.  import l2jcrimmerproject.gameserver.model.effects.L2Effect;
  4510.  import l2jcrimmerproject.gameserver.model.effects.L2EffectType;
  4511. +import l2jcrimmerproject.gameserver.model.entity.CTF;
  4512. +import l2jcrimmerproject.gameserver.model.entity.CTF.BaseTeleportTask;
  4513.  import l2jcrimmerproject.gameserver.model.entity.Castle;
  4514.  import l2jcrimmerproject.gameserver.model.entity.ChaosEngine;
  4515.  import l2jcrimmerproject.gameserver.model.entity.Duel;
  4516. @@ -537,6 +539,15 @@
  4517.         }
  4518.     }
  4519.    
  4520. +   /** CTF */
  4521. +   public String _teamNameCTF, _teamNameHaveFlagCTF, _originalTitleCTF;
  4522. +   public int _originalNameColorCTF, _originalKarmaCTF, _countCTFflags;
  4523. +   public boolean _inEventCTF = false, _haveFlagCTF = false;
  4524. +  
  4525. +   public boolean atEvent = false;
  4526. +  
  4527. +   public Future<?> _posCheckerCTF = null;
  4528. +  
  4529.     /** Olympiad */
  4530.     private boolean _inOlympiadMode = false;
  4531.     private boolean _OlympiadStart = false;
  4532. @@ -3390,6 +3401,10 @@
  4533.         {
  4534.             sendMessage("A dark force beyond your mortal understanding makes your knees to shake when you try to stand up...");
  4535.         }
  4536. +       else if (CTF._sitForced && _inEventCTF)
  4537. +       {
  4538. +           sendMessage("The Admin/GM handle if you sit or stand in this match!");
  4539. +       }
  4540.         else if (_waitTypeSitting && !isInStoreMode() && !isAlikeDead())
  4541.         {
  4542.             if (_effects.isAffected(EffectFlag.RELAXING))
  4543. @@ -4643,6 +4658,12 @@
  4544.         return true;
  4545.     }
  4546.    
  4547. +   @Override
  4548. +   public boolean isInFunEvent()
  4549. +   {
  4550. +       return (atEvent || (CTF._started && _inEventCTF));
  4551. +   }
  4552. +  
  4553.     /**
  4554.      * Returns true if cp update should be done, false if not
  4555.      * @return boolean
  4556. @@ -5754,6 +5775,47 @@
  4557.            
  4558.             TvTEvent.onKill(killer, this);
  4559.            
  4560. +           if (_inEventCTF)
  4561. +           {
  4562. +               if (CTF._teleport || CTF._started)
  4563. +               {
  4564. +                   if (Config.CTF_BASE_TELEPORT_FIRST)
  4565. +                   {
  4566. +                       sendMessage("Get ready! You will be sent into battle in " + (Config.CTF_REVIVE_DELAY / 1000) + " seconds!");
  4567. +                      
  4568. +                       if (_haveFlagCTF)
  4569. +                       {
  4570. +                           removeCTFFlagOnDie();
  4571. +                       }
  4572. +                      
  4573. +                       teleToLocation(CTF._teamsBaseX.get(CTF._teams.indexOf(_teamNameCTF)), CTF._teamsBaseY.get(CTF._teams.indexOf(_teamNameCTF)), CTF._teamsBaseZ.get(CTF._teams.indexOf(_teamNameCTF)), false);
  4574. +                      
  4575. +                       doRevive();
  4576. +                      
  4577. +                       ThreadPoolManager.getInstance().scheduleGeneral(new BaseTeleportTask(this, false), Config.CTF_REVIVE_DELAY);
  4578. +                   }
  4579. +                   else
  4580. +                   {
  4581. +                       sendMessage("You will be revived and teleported to team flag in " + (Config.CTF_REVIVE_DELAY / 1000) + " seconds!");
  4582. +                      
  4583. +                       if (_haveFlagCTF)
  4584. +                       {
  4585. +                           removeCTFFlagOnDie();
  4586. +                       }
  4587. +                      
  4588. +                       ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  4589. +                       {
  4590. +                           @Override
  4591. +                           public void run()
  4592. +                           {
  4593. +                               teleToLocation(CTF._teamsX.get(CTF._teams.indexOf(_teamNameCTF)), CTF._teamsY.get(CTF._teams.indexOf(_teamNameCTF)), CTF._teamsZ.get(CTF._teams.indexOf(_teamNameCTF)), false);
  4594. +                               doRevive();
  4595. +                           }
  4596. +                       }, Config.CTF_REVIVE_DELAY);
  4597. +                   }
  4598. +               }
  4599. +           }
  4600. +          
  4601.             TvTRoundEvent.onKill(killer, this);
  4602.            
  4603.             if (L2Event.isParticipant(pk) && (pk != null))
  4604. @@ -5925,9 +5987,19 @@
  4605.         return true;
  4606.     }
  4607.    
  4608. +   public void removeCTFFlagOnDie()
  4609. +   {
  4610. +       CTF._flagsTaken.set(CTF._teams.indexOf(_teamNameHaveFlagCTF), false);
  4611. +       CTF.spawnFlag(_teamNameHaveFlagCTF);
  4612. +       CTF.removeFlagFromPlayer(this);
  4613. +       broadcastUserInfo();
  4614. +       _haveFlagCTF = false;
  4615. +       CTF.AnnounceToPlayers(false, CTF._eventName + "(CTF): " + _teamNameHaveFlagCTF + "'s flag returned.");
  4616. +   }
  4617. +  
  4618.     private void onDieDropItem(L2Character killer)
  4619.     {
  4620. -       if (L2Event.isParticipant(this) || (killer == null))
  4621. +       if (L2Event.isParticipant(this) || (CTF._started && _inEventCTF) || (killer == null))
  4622.         {
  4623.             return;
  4624.         }
  4625. @@ -6059,6 +6131,11 @@
  4626.             return;
  4627.         }
  4628.        
  4629. +       if (_inEventCTF)
  4630. +       {
  4631. +           return;
  4632. +       }
  4633. +      
  4634.         L2PcInstance targetPlayer = target.getActingPlayer();
  4635.        
  4636.         if (targetPlayer == null)
  4637. @@ -6164,6 +6241,10 @@
  4638.     {
  4639.         if ((target instanceof L2PcInstance) && AntiFeedManager.getInstance().check(this, target))
  4640.         {
  4641. +           if (CTF._started && _inEventCTF)
  4642. +           {
  4643. +               return;
  4644. +           }
  4645.             // Add karma to attacker and increase its PK counter
  4646.             setPvpKills(getPvpKills() + 1);
  4647.            
  4648. @@ -6184,6 +6265,12 @@
  4649.      */
  4650.     public void increasePkKillsAndKarma(L2Character target)
  4651.     {
  4652. +      
  4653. +       if (CTF._started && _inEventCTF)
  4654. +       {
  4655. +           return;
  4656. +       }
  4657. +      
  4658.         int baseKarma = Config.KARMA_MIN_KARMA;
  4659.         int newKarma = baseKarma;
  4660.         int karmaLimit = Config.KARMA_MAX_KARMA;
  4661. @@ -6314,6 +6401,10 @@
  4662.         {
  4663.             return;
  4664.         }
  4665. +       if (CTF._started && _inEventCTF && player_target._inEventCTF)
  4666. +       {
  4667. +           return;
  4668. +       }
  4669.        
  4670.         if ((isInDuel() && (player_target.getDuelId() == getDuelId())))
  4671.         {
  4672. @@ -6427,7 +6518,7 @@
  4673.        
  4674.         // Calculate the Experience loss
  4675.         long lostExp = 0;
  4676. -       if (!L2Event.isParticipant(this))
  4677. +       if (!L2Event.isParticipant(this) && !_inEventCTF)
  4678.         {
  4679.             if (lvl < ExperienceTable.getInstance().getMaxLevel())
  4680.             {
  4681. @@ -7190,6 +7281,12 @@
  4682.                 sendPacket(SystemMessageId.STRIDER_CANT_BE_RIDDEN_WHILE_DEAD);
  4683.                 return false;
  4684.             }
  4685. +           else if (_haveFlagCTF)
  4686. +           {
  4687. +               // You cannot mount a steed while holding a flag.
  4688. +               sendPacket(ActionFailed.STATIC_PACKET);
  4689. +               sendPacket(SystemMessageId.YOU_CANNOT_MOUNT_A_STEED_WHILE_HOLDING_A_FLAG);
  4690. +           }
  4691.             else if (pet.isDead())
  4692.             {
  4693.                 // A dead strider cannot be ridden.
  4694. @@ -9192,6 +9289,11 @@
  4695.                 return true;
  4696.             }
  4697.            
  4698. +           if (CTF._started && ((L2PcInstance) attacker)._inEventCTF)
  4699. +           {
  4700. +               return true;
  4701. +           }
  4702. +          
  4703.             // Check if the attacker is not in the same clan
  4704.             if ((getClan() != null) && getClan().isMember(attacker.getObjectId()))
  4705.             {
  4706. @@ -9931,6 +10033,10 @@
  4707.      */
  4708.     public boolean checkPvpSkill(L2Object target, L2Skill skill)
  4709.     {
  4710. +       if (_inEventCTF && CTF._started)
  4711. +       {
  4712. +           return true;
  4713. +       }
  4714.         return checkPvpSkill(target, skill, false);
  4715.     }
  4716.    
  4717. @@ -10826,6 +10932,11 @@
  4718.         return _inOlympiadMode;
  4719.     }
  4720.    
  4721. +   public boolean isInEventCTF()
  4722. +   {
  4723. +       return _inEventCTF;
  4724. +   }
  4725. +  
  4726.     public boolean isInDuel()
  4727.     {
  4728.         return _isInDuel;
  4729. @@ -11628,6 +11739,12 @@
  4730.             {
  4731.                 getParty().getDimensionalRift().memberRessurected(this);
  4732.             }
  4733. +           if (_inEventCTF && CTF._started && Config.CTF_REVIVE_RECOVERY)
  4734. +           {
  4735. +               getStatus().setCurrentHp(getMaxHp());
  4736. +               getStatus().setCurrentMp(getMaxMp());
  4737. +               getStatus().setCurrentCp(getMaxCp());
  4738. +           }
  4739.             ChaosEngine chaos = new ChaosEngine();
  4740.             if (_inChaosEvent)
  4741.             {
  4742. Index: java/l2jcrimmerproject/gameserver/model/CursedWeapon.java
  4743. ===================================================================
  4744. --- java/l2jcrimmerproject/gameserver/model/CursedWeapon.java   (revision 12)
  4745. +++ java/l2jcrimmerproject/gameserver/model/CursedWeapon.java   (working copy)
  4746. @@ -35,6 +35,7 @@
  4747.  import l2jcrimmerproject.gameserver.model.actor.L2Attackable;
  4748.  import l2jcrimmerproject.gameserver.model.actor.L2Character;
  4749.  import l2jcrimmerproject.gameserver.model.actor.instance.L2PcInstance;
  4750. +import l2jcrimmerproject.gameserver.model.entity.CTF;
  4751.  import l2jcrimmerproject.gameserver.model.items.L2Item;
  4752.  import l2jcrimmerproject.gameserver.model.items.instance.L2ItemInstance;
  4753.  import l2jcrimmerproject.gameserver.model.skills.L2Skill;
  4754. @@ -441,6 +442,13 @@
  4755.        
  4756.         _isActivated = true;
  4757.        
  4758. +       if (player._inEventCTF && !Config.CTF_JOIN_CURSED)
  4759. +       {
  4760. +           if (player._inEventCTF)
  4761. +           {
  4762. +               CTF.removePlayer(player);
  4763. +           }
  4764. +       }
  4765.         // Player holding it data
  4766.         _player = player;
  4767.         _playerId = _player.getObjectId();
Advertisement
Add Comment
Please, Sign In to add comment