Guest User

Untitled

a guest
Jul 17th, 2014
743
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Index: java/net/sf/l2j/gameserver/network/serverpackets/Die.java
  2. ===================================================================
  3. --- java/net/sf/l2j/gameserver/network/serverpackets/Die.java (revision 115)
  4. +++ java/net/sf/l2j/gameserver/network/serverpackets/Die.java (working copy)
  5. @@ -14,6 +14,7 @@
  6. */
  7. package net.sf.l2j.gameserver.network.serverpackets;
  8.  
  9. +import net.sf.l2j.gameserver.customs.eventengine.EventCommons;
  10. import net.sf.l2j.gameserver.customs.events.TvTEvent;
  11. import net.sf.l2j.gameserver.datatables.AccessLevels;
  12. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  13. @@ -61,6 +62,9 @@
  14. writeD(_charObjId);
  15. if (_activeChar instanceof L2PcInstance)
  16. {
  17. + if (!EventCommons.allowToVillage((L2PcInstance)_activeChar))
  18. + return;
  19. +
  20. if (TvTEvent.getInstance()._state == TvTEvent.EventState.RUNNING)
  21. {
  22. if (TvTEvent.getInstance()._players.contains(_activeChar))
  23. Index: java/net/sf/l2j/gameserver/customs/eventengine/EventManager.java
  24. ===================================================================
  25. --- java/net/sf/l2j/gameserver/customs/eventengine/EventManager.java (revision 0)
  26. +++ java/net/sf/l2j/gameserver/customs/eventengine/EventManager.java (revision 0)
  27. @@ -0,0 +1,149 @@
  28. +/*
  29. + * This program is free software: you can redistribute it and/or modify it under
  30. + * the terms of the GNU General Public License as published by the Free Software
  31. + * Foundation, either version 3 of the License, or (at your option) any later
  32. + * version.
  33. + *
  34. + * This program is distributed in the hope that it will be useful, but WITHOUT
  35. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  36. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  37. + * details.
  38. + *
  39. + * You should have received a copy of the GNU General Public License along with
  40. + * this program. If not, see <http://www.gnu.org/licenses/>.
  41. + */
  42. +package net.sf.l2j.gameserver.customs.eventengine;
  43. +
  44. +import com.sun.istack.internal.logging.Logger;
  45. +
  46. +import java.util.ArrayList;
  47. +import java.util.Calendar;
  48. +import java.util.List;
  49. +
  50. +import net.sf.l2j.gameserver.ThreadPoolManager;
  51. +import net.sf.l2j.gameserver.customs.eventengine.events.TvT;
  52. +
  53. +/**
  54. + * @author Anarchy
  55. + *
  56. + */
  57. +public final class EventManager
  58. +{
  59. + private static final Logger log = Logger.getLogger(EventManager.class);
  60. +
  61. + private final List<Event> events;
  62. +
  63. + public static EventManager getInstance()
  64. + {
  65. + return SingletonHolder._instance;
  66. + }
  67. +
  68. + protected EventManager()
  69. + {
  70. + events = new ArrayList<>();
  71. +
  72. + registerEvent(new TvT());
  73. +
  74. + log.config("Event Engine: Loaded "+events.size()+" events.");
  75. + }
  76. +
  77. + public List<Event> getAllEvents()
  78. + {
  79. + return events;
  80. + }
  81. +
  82. + public Event getActiveEvent(Class<?> clazz)
  83. + {
  84. + for (Event e : events)
  85. + {
  86. + if (e.getClass() == clazz)
  87. + {
  88. + return e;
  89. + }
  90. + }
  91. +
  92. + return null;
  93. + }
  94. +
  95. + protected void registerEvent(final Event e)
  96. + {
  97. + if (!events.contains(e))
  98. + events.add(e);
  99. +
  100. + switch (e.getScheduleMethod())
  101. + {
  102. + case TIMES:
  103. + {
  104. + Calendar cld = Calendar.getInstance();
  105. + String[] times_splitted = e.getScheduleTimes().split(";");
  106. + int counter = times_splitted.length;
  107. +
  108. + for (String time : times_splitted)
  109. + {
  110. + String[] hrsmins = time.split(":");
  111. + int hour = Integer.parseInt(hrsmins[0]);
  112. + int minute = Integer.parseInt(hrsmins[1]);
  113. +
  114. + cld.set(Calendar.HOUR_OF_DAY, hour);
  115. + cld.set(Calendar.MINUTE, minute);
  116. + cld.set(Calendar.SECOND, 0);
  117. +
  118. + if (cld.getTimeInMillis()-System.currentTimeMillis() <= 0)
  119. + {
  120. + cld.set(Calendar.DAY_OF_MONTH, cld.get(Calendar.DAY_OF_MONTH)+1);
  121. + cld.set(Calendar.HOUR_OF_DAY, hour);
  122. + cld.set(Calendar.MINUTE, minute);
  123. + cld.set(Calendar.SECOND, 0);
  124. + }
  125. +
  126. + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  127. + {
  128. + @Override
  129. + public void run()
  130. + {
  131. + e.runEvent();
  132. + }
  133. + }, cld.getTimeInMillis()-System.currentTimeMillis());
  134. +
  135. + counter--;
  136. +
  137. + if (counter == 0)
  138. + {
  139. + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  140. + {
  141. + @Override
  142. + public void run()
  143. + {
  144. + registerEvent(e);
  145. + }
  146. + }, cld.getTimeInMillis()-System.currentTimeMillis());
  147. + }
  148. + }
  149. +
  150. + break;
  151. + }
  152. + case FIXED:
  153. + {
  154. + String[] time_splitted = e.getScheduleTimes().split(":");
  155. + int hours = Integer.parseInt(time_splitted[0]);
  156. + int minutes = Integer.parseInt(time_splitted[1]);
  157. +
  158. + ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Runnable()
  159. + {
  160. + @Override
  161. + public void run()
  162. + {
  163. + e.runEvent();
  164. + }
  165. + }, ((hours*1000*60*60)+(minutes*1000*60))/2, (hours*1000*60*60)+(minutes*1000*60));
  166. +
  167. + break;
  168. + }
  169. + }
  170. + }
  171. +
  172. + private static class SingletonHolder
  173. + {
  174. + protected static final EventManager _instance = new EventManager();
  175. + }
  176. +}
  177. Index: java/net/sf/l2j/gameserver/customs/eventengine/EventRegister.java
  178. ===================================================================
  179. --- java/net/sf/l2j/gameserver/customs/eventengine/EventRegister.java (revision 0)
  180. +++ java/net/sf/l2j/gameserver/customs/eventengine/EventRegister.java (revision 0)
  181. @@ -0,0 +1,78 @@
  182. +/*
  183. + * This program is free software: you can redistribute it and/or modify it under
  184. + * the terms of the GNU General Public License as published by the Free Software
  185. + * Foundation, either version 3 of the License, or (at your option) any later
  186. + * version.
  187. + *
  188. + * This program is distributed in the hope that it will be useful, but WITHOUT
  189. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  190. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  191. + * details.
  192. + *
  193. + * You should have received a copy of the GNU General Public License along with
  194. + * this program. If not, see <http://www.gnu.org/licenses/>.
  195. + */
  196. +package net.sf.l2j.gameserver.customs.eventengine;
  197. +
  198. +import net.sf.l2j.gameserver.customs.eventengine.events.TvT;
  199. +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  200. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  201. +
  202. +/**
  203. + * @author Anarchy
  204. + *
  205. + */
  206. +public class EventRegister implements IVoicedCommandHandler
  207. +{
  208. + @Override
  209. + public boolean useVoicedCommand(String command, L2PcInstance activeChar)
  210. + {
  211. + if (command.startsWith("register_"))
  212. + {
  213. + String event = command.substring(9);
  214. +
  215. + if (event == null || event.isEmpty())
  216. + {
  217. + activeChar.sendMessage("Invalid command.");
  218. + return false;
  219. + }
  220. +
  221. + if (EventCommons.isInEvent(activeChar))
  222. + {
  223. + activeChar.sendMessage("You have already registered for an event.");
  224. + return false;
  225. + }
  226. +
  227. + if (event.equals("tvt"))
  228. + {
  229. + Event tvt = null;
  230. +
  231. + for (Event e : EventManager.getInstance().getAllEvents())
  232. + {
  233. + if (e.getClass() == TvT.class)
  234. + {
  235. + tvt = e;
  236. + break;
  237. + }
  238. + }
  239. +
  240. + if (tvt != null)
  241. + {
  242. + if (tvt.getState() == EventState.REGISTERING)
  243. + {
  244. + tvt.registerPlayer(activeChar);
  245. + activeChar.sendMessage("You have registered for the TvT event.");
  246. + }
  247. + }
  248. + }
  249. + }
  250. +
  251. + return true;
  252. + }
  253. +
  254. + @Override
  255. + public String[] getVoicedCommandList()
  256. + {
  257. + return new String[] { "register_" };
  258. + }
  259. +}
  260. Index: java/net/sf/l2j/gameserver/customs/eventengine/EventState.java
  261. ===================================================================
  262. --- java/net/sf/l2j/gameserver/customs/eventengine/EventState.java (revision 0)
  263. +++ java/net/sf/l2j/gameserver/customs/eventengine/EventState.java (revision 0)
  264. @@ -0,0 +1,27 @@
  265. +/*
  266. + * This program is free software: you can redistribute it and/or modify it under
  267. + * the terms of the GNU General Public License as published by the Free Software
  268. + * Foundation, either version 3 of the License, or (at your option) any later
  269. + * version.
  270. + *
  271. + * This program is distributed in the hope that it will be useful, but WITHOUT
  272. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  273. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  274. + * details.
  275. + *
  276. + * You should have received a copy of the GNU General Public License along with
  277. + * this program. If not, see <http://www.gnu.org/licenses/>.
  278. + */
  279. +package net.sf.l2j.gameserver.customs.eventengine;
  280. +
  281. +/**
  282. + * @author Anarchy
  283. + *
  284. + */
  285. +public enum EventState
  286. +{
  287. + INACTIVE,
  288. + REGISTERING,
  289. + WAITING,
  290. + RUNNING
  291. +}
  292. Index: java/net/sf/l2j/gameserver/network/clientpackets/Logout.java
  293. ===================================================================
  294. --- java/net/sf/l2j/gameserver/network/clientpackets/Logout.java (revision 115)
  295. +++ java/net/sf/l2j/gameserver/network/clientpackets/Logout.java (working copy)
  296. @@ -16,6 +16,7 @@
  297.  
  298. import net.sf.l2j.Config;
  299. import net.sf.l2j.gameserver.SevenSignsFestival;
  300. +import net.sf.l2j.gameserver.customs.eventengine.EventCommons;
  301. import net.sf.l2j.gameserver.customs.events.TvTEvent;
  302. import net.sf.l2j.gameserver.model.L2Party;
  303. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  304. @@ -39,6 +40,12 @@
  305. if (player == null)
  306. return;
  307.  
  308. + if (!EventCommons.allowExit(player))
  309. + {
  310. + player.sendPacket(ActionFailed.STATIC_PACKET);
  311. + return;
  312. + }
  313. +
  314. if (TvTEvent.getInstance()._players.contains(player))
  315. {
  316. player.sendMessage("You may not exit while having registered for TvT event.");
  317. Index: java/net/sf/l2j/gameserver/customs/eventengine/EventSchedule.java
  318. ===================================================================
  319. --- java/net/sf/l2j/gameserver/customs/eventengine/EventSchedule.java (revision 0)
  320. +++ java/net/sf/l2j/gameserver/customs/eventengine/EventSchedule.java (revision 0)
  321. @@ -0,0 +1,31 @@
  322. +/*
  323. + * This program is free software: you can redistribute it and/or modify it under
  324. + * the terms of the GNU General Public License as published by the Free Software
  325. + * Foundation, either version 3 of the License, or (at your option) any later
  326. + * version.
  327. + *
  328. + * This program is distributed in the hope that it will be useful, but WITHOUT
  329. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  330. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  331. + * details.
  332. + *
  333. + * You should have received a copy of the GNU General Public License along with
  334. + * this program. If not, see <http://www.gnu.org/licenses/>.
  335. + */
  336. +package net.sf.l2j.gameserver.customs.eventengine;
  337. +
  338. +/**
  339. + * @author Anarchy
  340. + *
  341. + */
  342. +public enum EventSchedule
  343. +{
  344. + // TIMES scheduling method works by scheduling the event
  345. + // on the specified times of day. Use this format: 19:00;22:30
  346. + TIMES,
  347. +
  348. + // FIXED scheduling method works by scheduling the event
  349. + // every hours/minutes specified. Use this format: 1:00 (it will run every 1 hour).
  350. + // NOTE: The first schedule will be the time specified divided by 2.
  351. + FIXED
  352. +}
  353. Index: java/net/sf/l2j/gameserver/customs/eventengine/EventTeam.java
  354. ===================================================================
  355. --- java/net/sf/l2j/gameserver/customs/eventengine/EventTeam.java (revision 0)
  356. +++ java/net/sf/l2j/gameserver/customs/eventengine/EventTeam.java (revision 0)
  357. @@ -0,0 +1,126 @@
  358. +/*
  359. + * This program is free software: you can redistribute it and/or modify it under
  360. + * the terms of the GNU General Public License as published by the Free Software
  361. + * Foundation, either version 3 of the License, or (at your option) any later
  362. + * version.
  363. + *
  364. + * This program is distributed in the hope that it will be useful, but WITHOUT
  365. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  366. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  367. + * details.
  368. + *
  369. + * You should have received a copy of the GNU General Public License along with
  370. + * this program. If not, see <http://www.gnu.org/licenses/>.
  371. + */
  372. +package net.sf.l2j.gameserver.customs.eventengine;
  373. +
  374. +import java.util.ArrayList;
  375. +import java.util.List;
  376. +
  377. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  378. +
  379. +/**
  380. + * @author Anarchy
  381. + *
  382. + */
  383. +public class EventTeam
  384. +{
  385. + private String name;
  386. + private int x, y, z;
  387. + private List<L2PcInstance> players;
  388. + private int score;
  389. + private int color;
  390. +
  391. + public EventTeam(String name, int x, int y, int z, int color)
  392. + {
  393. + this.name = name;
  394. + this.x = x;
  395. + this.y = y;
  396. + this.z = z;
  397. + score = 0;
  398. + this.color = color;
  399. +
  400. + players = new ArrayList<>();
  401. + }
  402. +
  403. + public void reward(int itemId, int count)
  404. + {
  405. + for (L2PcInstance p : players)
  406. + {
  407. + p.addItem("", itemId, count, null, true);
  408. + }
  409. + }
  410. +
  411. + public void teleport(int teleX, int teleY, int teleZ)
  412. + {
  413. + for (L2PcInstance p : players)
  414. + {
  415. + p.teleToLocation(teleX, teleY, teleZ, 10);
  416. + }
  417. + }
  418. +
  419. + public void teleport()
  420. + {
  421. + for (L2PcInstance p : players)
  422. + {
  423. + p.teleToLocation(x, y, z, 10);
  424. + }
  425. + }
  426. +
  427. + public void sendMessage(String msg)
  428. + {
  429. + for (L2PcInstance p : players)
  430. + {
  431. + p.sendMessage(msg);
  432. + }
  433. + }
  434. +
  435. + public void drop()
  436. + {
  437. + for (L2PcInstance p : players)
  438. + {
  439. + p.getAppearance().setNameColor(0xFFFFFF);
  440. + }
  441. + }
  442. +
  443. + public boolean containsPlayer(L2PcInstance p)
  444. + {
  445. + return players.contains(p);
  446. + }
  447. +
  448. + public void addPlayer(L2PcInstance p)
  449. + {
  450. + players.add(p);
  451. + p.getAppearance().setNameColor(color);
  452. + }
  453. +
  454. + public int getX()
  455. + {
  456. + return x;
  457. + }
  458. +
  459. + public int getY()
  460. + {
  461. + return y;
  462. + }
  463. +
  464. + public int getZ()
  465. + {
  466. + return z;
  467. + }
  468. +
  469. + public String getName()
  470. + {
  471. + return name;
  472. + }
  473. +
  474. + public int getScore()
  475. + {
  476. + return score;
  477. + }
  478. +
  479. + public void setScore(int val)
  480. + {
  481. + score = val;
  482. + }
  483. +}
  484. Index: java/net/sf/l2j/gameserver/customs/eventengine/events/TvT.java
  485. ===================================================================
  486. --- java/net/sf/l2j/gameserver/customs/eventengine/events/TvT.java (revision 0)
  487. +++ java/net/sf/l2j/gameserver/customs/eventengine/events/TvT.java (revision 0)
  488. @@ -0,0 +1,126 @@
  489. +/*
  490. + * This program is free software: you can redistribute it and/or modify it under
  491. + * the terms of the GNU General Public License as published by the Free Software
  492. + * Foundation, either version 3 of the License, or (at your option) any later
  493. + * version.
  494. + *
  495. + * This program is distributed in the hope that it will be useful, but WITHOUT
  496. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  497. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  498. + * details.
  499. + *
  500. + * You should have received a copy of the GNU General Public License along with
  501. + * this program. If not, see <http://www.gnu.org/licenses/>.
  502. + */
  503. +package net.sf.l2j.gameserver.customs.eventengine.events;
  504. +
  505. +import net.sf.l2j.gameserver.customs.eventengine.Event;
  506. +import net.sf.l2j.gameserver.customs.eventengine.EventSchedule;
  507. +import net.sf.l2j.gameserver.customs.eventengine.EventState;
  508. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  509. +
  510. +/**
  511. + * @author Anarchy
  512. + *
  513. + */
  514. +public class TvT extends Event
  515. +{
  516. + @Override
  517. + public void runEvent()
  518. + {
  519. + openRegistrations(true, "Registrations have opened.", 2*1000*60); // change
  520. + if (!proceed())
  521. + {
  522. + abortEvent(true, "Event canceled due to lack of participation.");
  523. + return;
  524. + }
  525. + splitToTeams("Red,0,0,0,00FF00;Blue,0,0,0,FFFF00");
  526. + closeRegistrations(true, "Registrations have closed. Event will start in 20 seconds.", 20*1000);
  527. + teleportTeams(true, "You have been teleported to your team's spot. Event will begin in 20 seconds.", 20*1000);
  528. + startEvent(true, "The fight has begun!", 2*1000*60); // change
  529. + endEvent(true, "The event has ended.", 0);
  530. + rewardTopTeam(3470, 1);
  531. + teleportTeamsToTown();
  532. + clear();
  533. + }
  534. +
  535. + @Override
  536. + public boolean proceed()
  537. + {
  538. + if (getState() == EventState.REGISTERING)
  539. + {
  540. + if (players.size() < teams.size()) // change
  541. + return false;
  542. + }
  543. +
  544. + return true;
  545. + }
  546. +
  547. + @Override
  548. + public EventSchedule getScheduleMethod()
  549. + {
  550. + return EventSchedule.TIMES;
  551. + }
  552. +
  553. + @Override
  554. + public String getScheduleTimes()
  555. + {
  556. + return "12:00;14:00";
  557. + }
  558. +
  559. + @Override
  560. + public String getName()
  561. + {
  562. + return "TvT";
  563. + }
  564. +
  565. + @Override
  566. + public boolean allowFight()
  567. + {
  568. + return true;
  569. + }
  570. +
  571. + @Override
  572. + public boolean allowTargetting()
  573. + {
  574. + return true;
  575. + }
  576. +
  577. + @Override
  578. + public boolean allowFriendlyFire()
  579. + {
  580. + return false;
  581. + }
  582. +
  583. + @Override
  584. + public boolean allowEscape()
  585. + {
  586. + return false;
  587. + }
  588. +
  589. + @Override
  590. + public boolean allowToVillage()
  591. + {
  592. + return false;
  593. + }
  594. +
  595. + @Override
  596. + public void onPlayerRegister(L2PcInstance p)
  597. + {
  598. +
  599. + }
  600. +
  601. + @Override
  602. + public void onDie(L2PcInstance p, L2PcInstance killer)
  603. + {
  604. + if (getPlayerTeam(p) != null)
  605. + {
  606. + if (getPlayerTeam(p) != getPlayerTeam(killer))
  607. + {
  608. + getPlayerTeam(killer).setScore(getPlayerTeam(killer).getScore()+1);
  609. + }
  610. +
  611. + res(p, 5*1000);
  612. + }
  613. + }
  614. +}
  615. Index: java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java
  616. ===================================================================
  617. --- java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java (revision 115)
  618. +++ java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java (working copy)
  619. @@ -19,6 +19,7 @@
  620. import java.util.logging.Logger;
  621.  
  622. import net.sf.l2j.Config;
  623. +import net.sf.l2j.gameserver.customs.eventengine.EventRegister;
  624. import net.sf.l2j.gameserver.handler.voicedcommandhandlers.BugReport;
  625. import net.sf.l2j.gameserver.handler.voicedcommandhandlers.ChaosEventCommands;
  626. import net.sf.l2j.gameserver.handler.voicedcommandhandlers.SellBuffs;
  627. @@ -50,6 +51,7 @@
  628.  
  629. registerVoicedCommandHandler(new SellBuffs());
  630. registerVoicedCommandHandler(new BugReport());
  631. + registerVoicedCommandHandler(new EventRegister());
  632. }
  633.  
  634. public void registerVoicedCommandHandler(IVoicedCommandHandler handler)
  635. Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java
  636. ===================================================================
  637. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java (revision 115)
  638. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java (working copy)
  639. @@ -16,6 +16,7 @@
  640.  
  641. import net.sf.l2j.Config;
  642. import net.sf.l2j.gameserver.SevenSignsFestival;
  643. +import net.sf.l2j.gameserver.customs.eventengine.EventCommons;
  644. import net.sf.l2j.gameserver.customs.events.TvTEvent;
  645. import net.sf.l2j.gameserver.model.L2Party;
  646. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  647. @@ -42,6 +43,12 @@
  648. if (player == null)
  649. return;
  650.  
  651. + if (!EventCommons.allowExit(player))
  652. + {
  653. + sendPacket(RestartResponse.valueOf(false));
  654. + return;
  655. + }
  656. +
  657. if (TvTEvent.getInstance()._players.contains(player))
  658. {
  659. player.sendMessage("You may not restart why having registered for TvT event.");
  660. Index: java/net/sf/l2j/gameserver/customs/eventengine/Event.java
  661. ===================================================================
  662. --- java/net/sf/l2j/gameserver/customs/eventengine/Event.java (revision 0)
  663. +++ java/net/sf/l2j/gameserver/customs/eventengine/Event.java (revision 0)
  664. @@ -0,0 +1,302 @@
  665. +/*
  666. + * This program is free software: you can redistribute it and/or modify it under
  667. + * the terms of the GNU General Public License as published by the Free Software
  668. + * Foundation, either version 3 of the License, or (at your option) any later
  669. + * version.
  670. + *
  671. + * This program is distributed in the hope that it will be useful, but WITHOUT
  672. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  673. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  674. + * details.
  675. + *
  676. + * You should have received a copy of the GNU General Public License along with
  677. + * this program. If not, see <http://www.gnu.org/licenses/>.
  678. + */
  679. +package net.sf.l2j.gameserver.customs.eventengine;
  680. +
  681. +import java.util.ArrayList;
  682. +import java.util.List;
  683. +
  684. +import net.sf.l2j.gameserver.ThreadPoolManager;
  685. +import net.sf.l2j.gameserver.datatables.SkillTable;
  686. +import net.sf.l2j.gameserver.model.L2World;
  687. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  688. +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  689. +
  690. +/**
  691. + * @author Anarchy
  692. + *
  693. + */
  694. +public abstract class Event
  695. +{
  696. + protected List<EventTeam> teams = new ArrayList<>();
  697. + protected List<L2PcInstance> players = new ArrayList<>();
  698. + private EventState state = EventState.INACTIVE;
  699. +
  700. + protected void res(final L2PcInstance p, long millis)
  701. + {
  702. + final EventTeam team = getPlayerTeam(p);
  703. +
  704. + if (team != null)
  705. + {
  706. + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  707. + {
  708. + @Override
  709. + public void run()
  710. + {
  711. + p.doRevive();
  712. + p.setCurrentCp(p.getMaxCp());
  713. + p.setCurrentHp(p.getMaxHp());
  714. + p.setCurrentMp(p.getMaxMp());
  715. +
  716. + p.teleToLocation(team.getX(), team.getY(), team.getZ(), 0);
  717. + }
  718. + }, millis);
  719. + }
  720. + }
  721. +
  722. + protected void removeBuff(L2PcInstance p, int skillId)
  723. + {
  724. + if (p.getFirstEffect(skillId) != null)
  725. + {
  726. + p.getFirstEffect(skillId).exit();
  727. + }
  728. + }
  729. +
  730. + protected void addBuff(L2PcInstance p, int skillId, int skillLvl)
  731. + {
  732. + SkillTable.getInstance().getInfo(7029, 1).getEffects(p, p);
  733. + }
  734. +
  735. + protected void teleportTeamsToTown()
  736. + {
  737. + for (EventTeam team : teams)
  738. + {
  739. + team.teleport(83339, 148599, -3405);
  740. + }
  741. + }
  742. +
  743. + protected void abortEvent(boolean announce, String msg)
  744. + {
  745. + if (announce)
  746. + {
  747. + announce(msg);
  748. + }
  749. +
  750. + state = EventState.INACTIVE;
  751. +
  752. + teleportTeamsToTown();
  753. + clear();
  754. + }
  755. +
  756. + protected void rewardTopTeam(int itemId, int count)
  757. + {
  758. + int i = 0;
  759. + EventTeam winner = null;
  760. +
  761. + for (EventTeam team : teams)
  762. + {
  763. + if (team.getScore() > i)
  764. + {
  765. + i = team.getScore();
  766. + winner = team;
  767. + }
  768. + }
  769. +
  770. + if (winner != null)
  771. + {
  772. + winner.reward(itemId, count);
  773. + }
  774. + }
  775. +
  776. + protected void endEvent(boolean announce, String msg, long sleepMillis)
  777. + {
  778. + if (announce)
  779. + {
  780. + announce(msg);
  781. + }
  782. +
  783. + state = EventState.INACTIVE;
  784. +
  785. + if (sleepMillis > 0)
  786. + {
  787. + sleep(sleepMillis);
  788. + }
  789. + }
  790. +
  791. + protected void startEvent(boolean sendMessage, String msg, long sleepMillis)
  792. + {
  793. + if (sendMessage)
  794. + {
  795. + for (EventTeam team : teams)
  796. + {
  797. + team.sendMessage(msg);
  798. + }
  799. + }
  800. +
  801. + state = EventState.RUNNING;
  802. +
  803. + if (sleepMillis > 0)
  804. + {
  805. + sleep(sleepMillis);
  806. + }
  807. + }
  808. +
  809. + protected void teleportTeams(boolean sendMessage, String msg, long sleepMillis)
  810. + {
  811. + if (sendMessage)
  812. + {
  813. + for (EventTeam team : teams)
  814. + {
  815. + team.sendMessage(msg);
  816. + }
  817. + }
  818. +
  819. + for (EventTeam team : teams)
  820. + {
  821. + team.teleport();
  822. + }
  823. +
  824. + if (sleepMillis > 0)
  825. + {
  826. + sleep(sleepMillis);
  827. + }
  828. + }
  829. +
  830. + protected void closeRegistrations(boolean announce, String msg, long sleepMillis)
  831. + {
  832. + if (announce)
  833. + {
  834. + announce(msg);
  835. + }
  836. +
  837. + state = EventState.WAITING;
  838. +
  839. + if (sleepMillis > 0)
  840. + {
  841. + sleep(sleepMillis);
  842. + }
  843. + }
  844. +
  845. + protected void openRegistrations(boolean announce, String msg, long sleepMillis)
  846. + {
  847. + if (announce)
  848. + {
  849. + announce(msg);
  850. + }
  851. +
  852. + state = EventState.REGISTERING;
  853. +
  854. + if (sleepMillis > 0)
  855. + {
  856. + sleep(sleepMillis);
  857. + }
  858. + }
  859. +
  860. + protected void splitToTeams(String teams_data)
  861. + {
  862. + registerTeams(teams_data);
  863. +
  864. + int i = teams.size()-1;
  865. +
  866. + for (L2PcInstance p : players)
  867. + {
  868. + teams.get(i).addPlayer(p);
  869. + i--;
  870. +
  871. + if (i == -1)
  872. + i = teams.size()-1;
  873. + }
  874. + }
  875. +
  876. + protected void registerTeams(String teams_data)
  877. + {
  878. + String[] teams_splitted = teams_data.split(";");
  879. +
  880. + for (String team : teams_splitted)
  881. + {
  882. + String[] team_data = team.split(",");
  883. +
  884. + String name = team_data[0];
  885. + int x = Integer.parseInt(team_data[1]);
  886. + int y = Integer.parseInt(team_data[2]);
  887. + int z = Integer.parseInt(team_data[3]);
  888. + int color = Integer.decode("0x"+team_data[4]);
  889. +
  890. + EventTeam t = new EventTeam(name, x, y, z, color);
  891. +
  892. + teams.add(t);
  893. + }
  894. + }
  895. +
  896. + protected void clear()
  897. + {
  898. + for (EventTeam team : teams)
  899. + team.drop();
  900. +
  901. + teams.clear();
  902. + players.clear();
  903. + }
  904. +
  905. + protected void announce(String msg)
  906. + {
  907. + CreatureSay cs = new CreatureSay(0, 15, getName(), msg);
  908. +
  909. + for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  910. + {
  911. + p.sendPacket(cs);
  912. + }
  913. + }
  914. +
  915. + protected void sleep(long millis)
  916. + {
  917. + try
  918. + {
  919. + Thread.sleep(millis);
  920. + }
  921. + catch (InterruptedException e)
  922. + {
  923. + e.printStackTrace();
  924. + }
  925. + }
  926. +
  927. + public EventTeam getPlayerTeam(L2PcInstance p)
  928. + {
  929. + for (EventTeam team : teams)
  930. + {
  931. + if (team.containsPlayer(p))
  932. + return team;
  933. + }
  934. +
  935. + return null;
  936. + }
  937. +
  938. + public void registerPlayer(L2PcInstance p)
  939. + {
  940. + players.add(p);
  941. + onPlayerRegister(p);
  942. + }
  943. +
  944. + public boolean containsPlayer(L2PcInstance p)
  945. + {
  946. + return players.contains(p);
  947. + }
  948. +
  949. + public EventState getState()
  950. + {
  951. + return state;
  952. + }
  953. +
  954. + public abstract void runEvent();
  955. + public abstract boolean proceed();
  956. + public abstract EventSchedule getScheduleMethod();
  957. + public abstract String getScheduleTimes();
  958. + public abstract String getName();
  959. + public abstract boolean allowFight();
  960. + public abstract boolean allowTargetting();
  961. + public abstract boolean allowFriendlyFire();
  962. + public abstract boolean allowEscape();
  963. + public abstract boolean allowToVillage();
  964. + public abstract void onPlayerRegister(L2PcInstance p);
  965. + public abstract void onDie(L2PcInstance p, L2PcInstance killer);
  966. +}
  967. Index: java/net/sf/l2j/gameserver/handler/skillhandlers/GetPlayer.java
  968. ===================================================================
  969. --- java/net/sf/l2j/gameserver/handler/skillhandlers/GetPlayer.java (revision 115)
  970. +++ java/net/sf/l2j/gameserver/handler/skillhandlers/GetPlayer.java (working copy)
  971. @@ -14,6 +14,7 @@
  972. */
  973. package net.sf.l2j.gameserver.handler.skillhandlers;
  974.  
  975. +import net.sf.l2j.gameserver.customs.eventengine.EventCommons;
  976. import net.sf.l2j.gameserver.customs.events.TvTEvent;
  977. import net.sf.l2j.gameserver.handler.ISkillHandler;
  978. import net.sf.l2j.gameserver.model.L2Object;
  979. @@ -44,6 +45,9 @@
  980. if (victim == null || victim.isAlikeDead())
  981. continue;
  982.  
  983. + if (!EventCommons.allowEscape(victim))
  984. + continue;
  985. +
  986. if (TvTEvent.getInstance()._players.contains(victim))
  987. {
  988. continue;
  989. Index: java/net/sf/l2j/gameserver/GameServer.java
  990. ===================================================================
  991. --- java/net/sf/l2j/gameserver/GameServer.java (revision 115)
  992. +++ java/net/sf/l2j/gameserver/GameServer.java (working copy)
  993. @@ -35,6 +35,7 @@
  994. import net.sf.l2j.gameserver.customs.CleanVoteStatus;
  995. import net.sf.l2j.gameserver.customs.PvpProtection;
  996. import net.sf.l2j.gameserver.customs.custombosses.CustomBossManager;
  997. +import net.sf.l2j.gameserver.customs.eventengine.EventManager;
  998. import net.sf.l2j.gameserver.customs.events.ChaosEvent;
  999. import net.sf.l2j.gameserver.customs.events.HourlyPvpEvent;
  1000. import net.sf.l2j.gameserver.customs.events.SoloEventManager;
  1001. @@ -298,6 +299,7 @@
  1002. BalancerLoad.LoadEm();
  1003. HourlyPvpEvent.getInstance();
  1004. SoloEventManager.getInstance();
  1005. + EventManager.getInstance();
  1006.  
  1007. Util.printSection("System");
  1008. TaskManager.getInstance();
  1009. Index: java/net/sf/l2j/gameserver/model/actor/L2Character.java
  1010. ===================================================================
  1011. --- java/net/sf/l2j/gameserver/model/actor/L2Character.java (revision 115)
  1012. +++ java/net/sf/l2j/gameserver/model/actor/L2Character.java (working copy)
  1013. @@ -32,6 +32,7 @@
  1014. import net.sf.l2j.gameserver.ai.CtrlIntention;
  1015. import net.sf.l2j.gameserver.ai.L2AttackableAI;
  1016. import net.sf.l2j.gameserver.ai.L2CharacterAI;
  1017. +import net.sf.l2j.gameserver.customs.eventengine.EventCommons;
  1018. import net.sf.l2j.gameserver.datatables.DoorTable;
  1019. import net.sf.l2j.gameserver.datatables.MapRegionTable;
  1020. import net.sf.l2j.gameserver.datatables.MapRegionTable.TeleportWhereType;
  1021. @@ -587,6 +588,15 @@
  1022. return;
  1023. }
  1024.  
  1025. + if (this instanceof L2PcInstance && target instanceof L2PcInstance)
  1026. + {
  1027. + if (!EventCommons.canAttack((L2PcInstance)this, (L2PcInstance)target))
  1028. + {
  1029. + sendPacket(ActionFailed.STATIC_PACKET);
  1030. + return;
  1031. + }
  1032. + }
  1033. +
  1034. if (!isAlikeDead())
  1035. {
  1036. if (this instanceof L2Npc && target.isAlikeDead() || !getKnownList().knowsObject(target))
  1037. @@ -1538,6 +1548,15 @@
  1038. return false;
  1039. }
  1040.  
  1041. + if (this instanceof L2PcInstance && getTarget() instanceof L2PcInstance)
  1042. + {
  1043. + if (!EventCommons.canAttack((L2PcInstance)this, (L2PcInstance)getTarget()))
  1044. + {
  1045. + sendPacket(ActionFailed.STATIC_PACKET);
  1046. + return false;
  1047. + }
  1048. + }
  1049. +
  1050. return true;
  1051. }
  1052.  
  1053. Index: java/net/sf/l2j/gameserver/handler/usercommandhandlers/Escape.java
  1054. ===================================================================
  1055. --- java/net/sf/l2j/gameserver/handler/usercommandhandlers/Escape.java (revision 115)
  1056. +++ java/net/sf/l2j/gameserver/handler/usercommandhandlers/Escape.java (working copy)
  1057. @@ -14,6 +14,7 @@
  1058. */
  1059. package net.sf.l2j.gameserver.handler.usercommandhandlers;
  1060.  
  1061. +import net.sf.l2j.gameserver.customs.eventengine.EventCommons;
  1062. import net.sf.l2j.gameserver.customs.events.TvTEvent;
  1063. import net.sf.l2j.gameserver.datatables.SkillTable;
  1064. import net.sf.l2j.gameserver.handler.IUserCommandHandler;
  1065. @@ -38,6 +39,9 @@
  1066. return false;
  1067. }
  1068.  
  1069. + if (!EventCommons.allowEscape(activeChar))
  1070. + return false;
  1071. +
  1072. activeChar.stopMove(null);
  1073.  
  1074. // Official timer 5 minutes, for GM 1 second
  1075. Index: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  1076. ===================================================================
  1077. --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 115)
  1078. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (working copy)
  1079. @@ -52,6 +52,7 @@
  1080. import net.sf.l2j.gameserver.communitybbs.Manager.ForumsBBSManager;
  1081. import net.sf.l2j.gameserver.customs.BuffShop;
  1082. import net.sf.l2j.gameserver.customs.PvpProtection;
  1083. +import net.sf.l2j.gameserver.customs.eventengine.EventCommons;
  1084. import net.sf.l2j.gameserver.customs.events.ChaosEvent;
  1085. import net.sf.l2j.gameserver.customs.events.HourlyPvpEvent;
  1086. import net.sf.l2j.gameserver.customs.events.TvTEvent;
  1087. @@ -3418,6 +3419,12 @@
  1088. // Check if the player already target this L2PcInstance
  1089. if (player.getTarget() != this)
  1090. {
  1091. + if (!EventCommons.canTarget(player, this))
  1092. + {
  1093. + player.sendPacket(ActionFailed.STATIC_PACKET);
  1094. + return;
  1095. + }
  1096. +
  1097. // Set the target of the player
  1098. player.setTarget(this);
  1099.  
  1100. @@ -4185,6 +4192,8 @@
  1101. {
  1102. L2PcInstance kl = (L2PcInstance)killer;
  1103.  
  1104. + EventCommons.onDie(this, kl);
  1105. +
  1106. if (TvTEvent.getInstance()._state == TvTEvent.EventState.RUNNING)
  1107. {
  1108. if ((TvTEvent.getInstance()._team1.contains(this) && TvTEvent.getInstance()._team2.contains(kl)) || (TvTEvent.getInstance()._team2.contains(this) && TvTEvent.getInstance()._team1.contains(kl)))
  1109. Index: java/net/sf/l2j/gameserver/customs/eventengine/EventCommons.java
  1110. ===================================================================
  1111. --- java/net/sf/l2j/gameserver/customs/eventengine/EventCommons.java (revision 0)
  1112. +++ java/net/sf/l2j/gameserver/customs/eventengine/EventCommons.java (revision 0)
  1113. @@ -0,0 +1,199 @@
  1114. +/*
  1115. + * This program is free software: you can redistribute it and/or modify it under
  1116. + * the terms of the GNU General Public License as published by the Free Software
  1117. + * Foundation, either version 3 of the License, or (at your option) any later
  1118. + * version.
  1119. + *
  1120. + * This program is distributed in the hope that it will be useful, but WITHOUT
  1121. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1122. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1123. + * details.
  1124. + *
  1125. + * You should have received a copy of the GNU General Public License along with
  1126. + * this program. If not, see <http://www.gnu.org/licenses/>.
  1127. + */
  1128. +package net.sf.l2j.gameserver.customs.eventengine;
  1129. +
  1130. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1131. +
  1132. +/**
  1133. + * @author Anarchy
  1134. + *
  1135. + * A static class for checks.
  1136. + */
  1137. +public class EventCommons
  1138. +{
  1139. + public static void onDie(L2PcInstance victim, L2PcInstance killer)
  1140. + {
  1141. + Event e = null;
  1142. +
  1143. + for (Event event : EventManager.getInstance().getAllEvents())
  1144. + {
  1145. + if (event.getState() != EventState.INACTIVE)
  1146. + {
  1147. + if (event.containsPlayer(victim) && event.containsPlayer(killer))
  1148. + {
  1149. + e = event;
  1150. + break;
  1151. + }
  1152. + }
  1153. + }
  1154. +
  1155. + if (e != null)
  1156. + {
  1157. + e.onDie(victim, killer);
  1158. + }
  1159. + }
  1160. +
  1161. + public static boolean allowToVillage(L2PcInstance player)
  1162. + {
  1163. + Event e = null;
  1164. +
  1165. + for (Event event : EventManager.getInstance().getAllEvents())
  1166. + {
  1167. + if (event.getState() != EventState.INACTIVE)
  1168. + {
  1169. + if (event.containsPlayer(player))
  1170. + {
  1171. + e = event;
  1172. + break;
  1173. + }
  1174. + }
  1175. + }
  1176. +
  1177. + if (e != null)
  1178. + {
  1179. + if (!e.allowToVillage())
  1180. + return false;
  1181. + }
  1182. +
  1183. + return true;
  1184. + }
  1185. +
  1186. + public static boolean isInEvent(L2PcInstance player)
  1187. + {
  1188. + Event e = null;
  1189. +
  1190. + for (Event event : EventManager.getInstance().getAllEvents())
  1191. + {
  1192. + if (event.getState() != EventState.INACTIVE)
  1193. + {
  1194. + if (event.containsPlayer(player))
  1195. + {
  1196. + e = event;
  1197. + break;
  1198. + }
  1199. + }
  1200. + }
  1201. +
  1202. + if (e != null)
  1203. + {
  1204. + return true;
  1205. + }
  1206. +
  1207. + return false;
  1208. + }
  1209. +
  1210. + public static boolean allowExit(L2PcInstance player)
  1211. + {
  1212. + Event e = null;
  1213. +
  1214. + for (Event event : EventManager.getInstance().getAllEvents())
  1215. + {
  1216. + if (event.getState() != EventState.INACTIVE)
  1217. + {
  1218. + if (event.containsPlayer(player))
  1219. + {
  1220. + e = event;
  1221. + break;
  1222. + }
  1223. + }
  1224. + }
  1225. +
  1226. + if (e != null)
  1227. + {
  1228. + player.sendMessage("You may not exit while in an event.");
  1229. + return false;
  1230. + }
  1231. +
  1232. + return true;
  1233. + }
  1234. +
  1235. + public static boolean allowEscape(L2PcInstance player)
  1236. + {
  1237. + Event e = null;
  1238. +
  1239. + for (Event event : EventManager.getInstance().getAllEvents())
  1240. + {
  1241. + if (event.getState() != EventState.INACTIVE)
  1242. + {
  1243. + if (event.containsPlayer(player))
  1244. + {
  1245. + e = event;
  1246. + break;
  1247. + }
  1248. + }
  1249. + }
  1250. +
  1251. + if (e != null)
  1252. + {
  1253. + if (!e.allowEscape() && e.containsPlayer(player))
  1254. + return false;
  1255. + }
  1256. +
  1257. + return true;
  1258. + }
  1259. +
  1260. + public static boolean canTarget(L2PcInstance player, L2PcInstance target)
  1261. + {
  1262. + Event e = null;
  1263. +
  1264. + for (Event event : EventManager.getInstance().getAllEvents())
  1265. + {
  1266. + if (event.getState() != EventState.INACTIVE)
  1267. + {
  1268. + if (event.containsPlayer(player) && event.containsPlayer(target))
  1269. + {
  1270. + e = event;
  1271. + break;
  1272. + }
  1273. + }
  1274. + }
  1275. +
  1276. + if (e != null)
  1277. + {
  1278. + if (!e.allowTargetting() && e.getPlayerTeam(player) != e.getPlayerTeam(target))
  1279. + return false;
  1280. + }
  1281. +
  1282. + return true;
  1283. + }
  1284. +
  1285. + public static boolean canAttack(L2PcInstance player, L2PcInstance target)
  1286. + {
  1287. + Event e = null;
  1288. +
  1289. + for (Event event : EventManager.getInstance().getAllEvents())
  1290. + {
  1291. + if (event.getState() != EventState.INACTIVE)
  1292. + {
  1293. + if (event.containsPlayer(player) && event.containsPlayer(target))
  1294. + {
  1295. + e = event;
  1296. + break;
  1297. + }
  1298. + }
  1299. + }
  1300. +
  1301. + if (e != null)
  1302. + {
  1303. + if (!e.allowFight())
  1304. + return false;
  1305. +
  1306. + if (!e.allowFriendlyFire() && e.getPlayerTeam(player) == e.getPlayerTeam(target) && e.getPlayerTeam(player) != null)
  1307. + return false;
  1308. + }
  1309. +
  1310. + return true;
  1311. + }
  1312. +}
RAW Paste Data