Guest User

TheEnd

a guest
Sep 1st, 2009
3,461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 50.53 KB | None | 0 0
  1. Index: java/net/sf/l2j/gameserver/model/entity/DM.java
  2. ===================================================================
  3. --- java/net/sf/l2j/gameserver/model/entity/DM.java (revision 0)
  4. +++ java/net/sf/l2j/gameserver/model/entity/DM.java (revision 0)
  5.  -0,0 +1,734 @@
  6. +/*
  7. + * This program is free software: you can redistribute it and/or modify it under
  8. + * the terms of the GNU General Public License as published by the Free Software
  9. + * Foundation, either version 3 of the License, or (at your option) any later
  10. + * version.
  11. + *
  12. + * This program is distributed in the hope that it will be useful, but WITHOUT
  13. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  14. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  15. + * details.
  16. + *
  17. + * You should have received a copy of the GNU General Public License along with
  18. + * this program. If not, see <http://www.gnu.org/licenses/>.
  19. + */
  20. +package net.sf.l2j.gameserver.model.entity;
  21. +/**
  22. + *
  23. + * @author SqueezeD Edited By TheEnd
  24. + *
  25. + */
  26. +
  27. +import java.sql.Connection;
  28. +import java.sql.PreparedStatement;
  29. +import java.sql.ResultSet;
  30. +import java.sql.SQLException;
  31. +import java.util.Vector;
  32. +
  33. +import javolution.text.TextBuilder;
  34. +
  35. +import java.util.logging.Logger;
  36. +
  37. +import net.sf.l2j.Config;
  38. +import net.sf.l2j.L2DatabaseFactory;
  39. +import net.sf.l2j.gameserver.Announcements;
  40. +import net.sf.l2j.gameserver.ThreadPoolManager;
  41. +import net.sf.l2j.gameserver.datatables.NpcTable;
  42. +import net.sf.l2j.gameserver.datatables.SpawnTable;
  43. +import net.sf.l2j.gameserver.model.L2Effect;
  44. +import net.sf.l2j.gameserver.model.L2Party;
  45. +import net.sf.l2j.gameserver.model.L2Spawn;
  46. +import net.sf.l2j.gameserver.model.actor.L2Summon;
  47. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  48. +import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  49. +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  50. +import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  51. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  52. +import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  53. +import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate;
  54. +
  55. +public class DM
  56. +{  
  57. +   private final static Logger _log = Logger.getLogger(DM.class.getName());
  58. +   public static String _eventName = new String(),
  59. +                        _eventDesc = new String(),
  60. +                        _joiningLocationName = new String();
  61. +   public static Vector<String> _savePlayers = new Vector<String>();
  62. +   public static Vector<L2PcInstance> _players = new Vector<L2PcInstance>();
  63. +   public static boolean _joining = false,
  64. +                         _teleport = false,
  65. +                         _started = false,
  66. +                         _sitForced = false;
  67. +   public static L2Spawn _npcSpawn;
  68. +   public static L2PcInstance _topPlayer;
  69. +   public static int _npcId = 0,
  70. +                     _npcX = 0,
  71. +                     _npcY = 0,
  72. +                     _npcZ = 0,
  73. +                     _rewardId = 0,
  74. +                     _rewardAmount = 0,
  75. +                     _topKills = 0,
  76. +                     _minlvl = 0,
  77. +                     _maxlvl = 0,
  78. +                     _playerColors = 0,
  79. +                     _playerX = 0,
  80. +                     _playerY = 0,
  81. +                     _playerZ = 0;
  82. +
  83. +   public static void setNpcPos(L2PcInstance activeChar)
  84. +   {
  85. +       _npcX = activeChar.getX();
  86. +       _npcY = activeChar.getY();
  87. +       _npcZ = activeChar.getZ();
  88. +   }
  89. +
  90. +   public static boolean checkMaxLevel(int maxlvl)
  91. +   {
  92. +       if (_minlvl >= maxlvl)
  93. +           return false;
  94. +      
  95. +       return true;
  96. +   }
  97. +
  98. +   public static boolean checkMinLevel(int minlvl)
  99. +   {
  100. +       if (_maxlvl <= minlvl)
  101. +           return false;
  102. +      
  103. +       return true;
  104. +   }
  105. +
  106. +   public static void setPlayersPos(L2PcInstance activeChar)
  107. +   {
  108. +       _playerX = activeChar.getX();
  109. +       _playerY = activeChar.getY();
  110. +       _playerZ = activeChar.getZ();
  111. +   }
  112. +
  113. +   public static boolean checkPlayerOk()
  114. +   {
  115. +       if (_started || _teleport || _joining)
  116. +           return false;
  117. +      
  118. +       return true;
  119. +   }
  120. +
  121. +   public static void startJoin(L2PcInstance activeChar)
  122. +   {
  123. +       if (!startJoinOk())
  124. +       {
  125. +           if (!Config.DEBUG)
  126. +               _log.fine("DM Engine[startJoin(" + activeChar.getName() + ")]: startJoinOk() = false");
  127. +           return;
  128. +       }
  129. +      
  130. +       _joining = true;
  131. +       spawnEventNpc(activeChar);
  132. +       Announcements.getInstance().announceToAll(_eventName + "(DM): Joinable in " + _joiningLocationName + "!");
  133. +   }
  134. +
  135. +   private static boolean startJoinOk()
  136. +   {
  137. +       if (_started || _teleport || _joining || _eventName.equals("") ||
  138. +           _joiningLocationName.equals("") || _eventDesc.equals("") || _npcId == 0 ||
  139. +           _npcX == 0 || _npcY == 0 || _npcZ == 0 || _rewardId == 0 || _rewardAmount == 0 ||
  140. +           _playerX == 0 || _playerY == 0 || _playerZ == 0)
  141. +           return false;
  142. +      
  143. +       return true;
  144. +   }
  145. +
  146. +   private static void spawnEventNpc(L2PcInstance activeChar)
  147. +   {
  148. +       L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
  149. +
  150. +       try
  151. +       {
  152. +           _npcSpawn = new L2Spawn(tmpl);
  153. +
  154. +           _npcSpawn.setLocx(_npcX);
  155. +           _npcSpawn.setLocy(_npcY);
  156. +           _npcSpawn.setLocz(_npcZ);
  157. +           _npcSpawn.setAmount(1);
  158. +           _npcSpawn.setHeading(activeChar.getHeading());
  159. +           _npcSpawn.setRespawnDelay(1);
  160. +
  161. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  162. +
  163. +           _npcSpawn.init();
  164. +           _npcSpawn.getLastSpawn().getStatus().setCurrentHp(999999999);
  165. +           _npcSpawn.getLastSpawn().setTitle(_eventName);
  166. +           _npcSpawn.getLastSpawn()._isEventMobDM = true;
  167. +           _npcSpawn.getLastSpawn().isAggressive();
  168. +           _npcSpawn.getLastSpawn().decayMe();
  169. +           _npcSpawn.getLastSpawn().spawnMe(_npcSpawn.getLastSpawn().getX(), _npcSpawn.getLastSpawn().getY(), _npcSpawn.getLastSpawn().getZ());
  170. +
  171. +           _npcSpawn.getLastSpawn().broadcastPacket(new MagicSkillUse(_npcSpawn.getLastSpawn(), _npcSpawn.getLastSpawn(), 1034, 1, 1, 1));
  172. +       }
  173. +       catch (Exception e)
  174. +       {
  175. +           _log.warning("DM Engine[spawnEventNpc(" + activeChar.getName() + ")]: exception: " + e.getMessage());
  176. +       }
  177. +   }
  178. +
  179. +   public static void teleportStart()
  180. +   {
  181. +       if (!_joining || _started || _teleport)
  182. +           return;
  183. +      
  184. +       _joining = false;
  185. +       Announcements.getInstance().announceToAll(_eventName + "(DM): Teleport to team spot in 20 seconds!");
  186. +
  187. +       setUserData();
  188. +       ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  189. +       {
  190. +           public void run()
  191. +           {
  192. +               DM.sit();
  193. +
  194. +               for (L2PcInstance player : DM._players)
  195. +               {
  196. +                   if (player !=  null)
  197. +                   {
  198. +                       if (Config.DM_ON_START_UNSUMMON_PET)
  199. +                       {
  200. +                           //Remove Summon's buffs
  201. +                           if (player.getPet() != null)
  202. +                           {
  203. +                               L2Summon summon = player.getPet();
  204. +                               for (L2Effect e : summon.getAllEffects())
  205. +                                   e.exit();
  206. +
  207. +                               if (summon instanceof L2PetInstance)
  208. +                                   summon.unSummon(player);
  209. +                           }
  210. +                       }
  211. +
  212. +                       if (Config.DM_ON_START_REMOVE_ALL_EFFECTS)
  213. +                       {
  214. +                           for (L2Effect e : player.getAllEffects())
  215. +                           {
  216. +                               if (e != null) e.exit();
  217. +                           }
  218. +                       }
  219. +
  220. +                       // Remove player from his party
  221. +                       if (player.getParty() != null)
  222. +                       {
  223. +                           L2Party party = player.getParty();
  224. +                           party.removePartyMember(player);
  225. +                       }
  226. +                       player.teleToLocation(_playerX, _playerY, _playerZ, false);
  227. +                   }
  228. +               }
  229. +           }
  230. +       }, 20000);
  231. +       _teleport = true;
  232. +   }
  233. +  
  234. +   public static void startEvent(L2PcInstance activeChar)
  235. +   {
  236. +       if (!startEventOk())
  237. +       {
  238. +           if (Config.DEBUG)
  239. +               _log.fine("DM Engine[startEvent(" + activeChar.getName() + ")]: startEventOk() = false");
  240. +           return;
  241. +       }
  242. +      
  243. +       _teleport = false;
  244. +       sit();
  245. +       Announcements.getInstance().announceToAll(_eventName + "(DM): Started. Go to kill your enemies!");
  246. +       _started = true;
  247. +   }
  248. +
  249. +   private static boolean startEventOk()
  250. +   {
  251. +       if (_joining || !_teleport || _started)
  252. +           return false;
  253. +      
  254. +       return true;
  255. +   }
  256. +
  257. +   public static void setUserData()
  258. +   {
  259. +       for (L2PcInstance player : _players)
  260. +       {
  261. +           player._originalNameColorDM = player.getAppearance().getNameColor();
  262. +           player._originalKarmaDM = player.getKarma();
  263. +           player._inEventDM = true;
  264. +           player._countDMkills = 0;
  265. +           player.getAppearance().setNameColor(_playerColors);
  266. +           player.setKarma(0);
  267. +           player.broadcastUserInfo();
  268. +       }
  269. +   }
  270. +
  271. +   public static void removeUserData()
  272. +   {
  273. +       for (L2PcInstance player : _players)
  274. +       {
  275. +           player.getAppearance().setNameColor(player._originalNameColorDM);
  276. +           player.setKarma(player._originalKarmaDM);
  277. +           player._inEventDM = false;
  278. +           player._countDMkills = 0;
  279. +           player.broadcastUserInfo();
  280. +       }
  281. +   }
  282. +
  283. +   public static void finishEvent(L2PcInstance activeChar)
  284. +   {
  285. +       if (!finishEventOk())
  286. +       {
  287. +           if (Config.DEBUG)
  288. +               _log.fine("DM Engine[finishEvent(" + activeChar.getName() + ")]: finishEventOk() = false");
  289. +           return;
  290. +       }
  291. +
  292. +       _started = false;
  293. +       unspawnEventNpc();
  294. +       processTopPlayer();
  295. +
  296. +       if (_topKills == 0)
  297. +           Announcements.getInstance().announceToAll(_eventName + "(DM): No players win the match(nobody killed).");
  298. +       else
  299. +       {
  300. +           Announcements.getInstance().announceToAll(_eventName + "(DM): " + _topPlayer.getName() + " wins the match! " + _topKills + " kills.");
  301. +           rewardPlayer(activeChar);
  302. +       }
  303. +      
  304. +       teleportFinish();
  305. +   }
  306. +
  307. +   private static boolean finishEventOk()
  308. +   {
  309. +       if (!_started)
  310. +           return false;
  311. +      
  312. +       return true;
  313. +   }
  314. +
  315. +   public static void processTopPlayer()
  316. +   {
  317. +       for (L2PcInstance player : _players)
  318. +       {
  319. +           if (player._countDMkills > _topKills)
  320. +           {
  321. +               _topPlayer = player;
  322. +               _topKills = player._countDMkills;
  323. +           }
  324. +       }
  325. +   }
  326. +
  327. +   /**
  328. +    * @param activeChar  
  329. +    */
  330. +   public static void rewardPlayer(L2PcInstance activeChar)
  331. +   {
  332. +       if (_topPlayer != null)
  333. +       {
  334. +           _topPlayer.addItem("DM Event: " + _eventName, _rewardId, _rewardAmount, _topPlayer, true);
  335. +
  336. +           StatusUpdate su = new StatusUpdate(_topPlayer.getObjectId());
  337. +           su.addAttribute(StatusUpdate.CUR_LOAD, _topPlayer.getCurrentLoad());
  338. +           _topPlayer.sendPacket(su);
  339. +
  340. +           NpcHtmlMessage nhm = new NpcHtmlMessage(5);
  341. +           TextBuilder replyMSG = new TextBuilder("");
  342. +
  343. +           replyMSG.append("<html><body>You won the event. Look in your inventory for the reward.</body></html>");
  344. +
  345. +           nhm.setHtml(replyMSG.toString());
  346. +           _topPlayer.sendPacket(nhm);
  347. +
  348. +           // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  349. +           _topPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  350. +       }
  351. +   }
  352. +
  353. +   public static void abortEvent()
  354. +   {
  355. +       if (!_joining && !_teleport && !_started)
  356. +           return;
  357. +      
  358. +       _joining = false;
  359. +       _teleport = false;
  360. +       _started = false;
  361. +       unspawnEventNpc();
  362. +       Announcements.getInstance().announceToAll(_eventName + "(DM): Match aborted!");
  363. +       teleportFinish();
  364. +   }
  365. +
  366. +   public static void sit()
  367. +   {
  368. +       if (_sitForced)
  369. +           _sitForced = false;
  370. +       else
  371. +           _sitForced = true;
  372. +      
  373. +       for (L2PcInstance player : _players)
  374. +       {
  375. +           if (player != null)
  376. +           {
  377. +               if (_sitForced)
  378. +               {
  379. +                   player.stopMove(null, false);
  380. +                   player.abortAttack();
  381. +                   player.abortCast();
  382. +                  
  383. +                   if (!player.isSitting())
  384. +                       player.sitDown();
  385. +               }
  386. +               else
  387. +               {
  388. +                   if (player.isSitting())
  389. +                       player.standUp();
  390. +               }
  391. +           }
  392. +       }
  393. +   }
  394. +
  395. +   public static void dumpData()
  396. +   {
  397. +       _log.info("");
  398. +       _log.info("");
  399. +      
  400. +       if (!_joining && !_teleport && !_started)
  401. +       {
  402. +           _log.info("<<---------------------------------->>");
  403. +           _log.info(">> DM Engine infos dump (INACTIVE) <<");
  404. +           _log.info("<<--^----^^-----^----^^------^^----->>");
  405. +       }
  406. +       else if (_joining && !_teleport && !_started)
  407. +       {
  408. +           _log.info("<<--------------------------------->>");
  409. +           _log.info(">> DM Engine infos dump (JOINING) <<");
  410. +           _log.info("<<--^----^^-----^----^^------^----->>");
  411. +       }
  412. +       else if (!_joining && _teleport && !_started)
  413. +       {
  414. +           _log.info("<<---------------------------------->>");
  415. +           _log.info(">> DM Engine infos dump (TELEPORT) <<");
  416. +           _log.info("<<--^----^^-----^----^^------^^----->>");
  417. +       }
  418. +       else if (!_joining && !_teleport && _started)
  419. +       {
  420. +           _log.info("<<--------------------------------->>");
  421. +           _log.info(">> DM Engine infos dump (STARTED) <<");
  422. +           _log.info("<<--^----^^-----^----^^------^----->>");
  423. +       }
  424. +
  425. +       _log.info("Name: " + _eventName);
  426. +       _log.info("Desc: " + _eventDesc);
  427. +       _log.info("Join location: " + _joiningLocationName);
  428. +       _log.info("Min lvl: " + _minlvl);
  429. +       _log.info("Max lvl: " + _maxlvl);
  430. +      
  431. +       _log.info("");
  432. +       _log.info("##################################");
  433. +       _log.info("# _players(Vector<L2PcInstance>) #");
  434. +       _log.info("##################################");
  435. +      
  436. +       _log.info("Total Players : " + _players.size());
  437. +      
  438. +       for (L2PcInstance player : _players)
  439. +       {
  440. +           if (player != null)
  441. +               _log.info("Name: " + player.getName()+ " kills :" + player._countDMkills);
  442. +       }
  443. +      
  444. +       _log.info("");
  445. +       _log.info("################################");
  446. +       _log.info("# _savePlayers(Vector<String>) #");
  447. +       _log.info("################################");
  448. +      
  449. +       for (String player : _savePlayers)
  450. +           _log.info("Name: " + player );
  451. +      
  452. +       _log.info("");
  453. +       _log.info("");
  454. +   }
  455. +
  456. +   public static void loadData()
  457. +   {
  458. +       _eventName = new String();
  459. +       _eventDesc = new String();
  460. +       _joiningLocationName = new String();
  461. +       _savePlayers = new Vector<String>();
  462. +       _players = new Vector<L2PcInstance>();
  463. +       _topPlayer = null;
  464. +       _npcSpawn = null;
  465. +       _joining = false;
  466. +       _teleport = false;
  467. +       _started = false;
  468. +       _sitForced = false;
  469. +       _npcId = 0;
  470. +       _npcX = 0;
  471. +       _npcY = 0;
  472. +       _npcZ = 0;
  473. +       _rewardId = 0;
  474. +       _rewardAmount = 0;
  475. +       _topKills = 0;
  476. +       _minlvl = 0;
  477. +       _maxlvl = 0;
  478. +       _playerColors = 0;
  479. +       _playerX = 0;
  480. +       _playerY = 0;
  481. +       _playerZ = 0;
  482. +      
  483. +       Connection con = null;
  484. +       try
  485. +       {
  486. +           PreparedStatement statement;
  487. +           ResultSet rs;
  488. +
  489. +          
  490. +           con = L2DatabaseFactory.getInstance().getConnection();
  491. +
  492. +           statement = con.prepareStatement("Select * from dm");
  493. +           rs = statement.executeQuery();
  494. +          
  495. +           while (rs.next())
  496. +           {
  497. +               _eventName = rs.getString("eventName");
  498. +               _eventDesc = rs.getString("eventDesc");
  499. +               _joiningLocationName = rs.getString("joiningLocation");
  500. +               _minlvl = rs.getInt("minlvl");
  501. +               _maxlvl = rs.getInt("maxlvl");
  502. +               _npcId = rs.getInt("npcId");
  503. +               _npcX = rs.getInt("npcX");
  504. +               _npcY = rs.getInt("npcY");
  505. +               _npcZ = rs.getInt("npcZ");
  506. +               _rewardId = rs.getInt("rewardId");
  507. +               _rewardAmount = rs.getInt("rewardAmount");
  508. +               _playerColors = rs.getInt("color");
  509. +               _playerX = rs.getInt("playerX");
  510. +               _playerY = rs.getInt("playerY");
  511. +               _playerZ = rs.getInt("playerZ");
  512. +          
  513. +           }
  514. +           statement.close();
  515. +       }
  516. +       catch (Exception e)
  517. +       {
  518. +           _log.warning("Exception: DM.loadData(): " + e.getMessage());
  519. +       }
  520. +       finally { try { if (con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); } }
  521. +   }
  522. +
  523. +   public static void saveData()
  524. +   {
  525. +       Connection con = null;
  526. +       try
  527. +       {
  528. +           con = L2DatabaseFactory.getInstance().getConnection();
  529. +           PreparedStatement statement;
  530. +          
  531. +           statement = con.prepareStatement("Delete from dm");
  532. +           statement.execute();
  533. +           statement.close();
  534. +
  535. +           statement = con.prepareStatement("INSERT INTO dm (eventName, eventDesc, joiningLocation, minlvl, maxlvl, npcId, npcX, npcY, npcZ, rewardId, rewardAmount, color, playerX, playerY, playerZ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");  
  536. +           statement.setString(1, _eventName);
  537. +           statement.setString(2, _eventDesc);
  538. +           statement.setString(3, _joiningLocationName);
  539. +           statement.setInt(4, _minlvl);
  540. +           statement.setInt(5, _maxlvl);
  541. +           statement.setInt(6, _npcId);
  542. +           statement.setInt(7, _npcX);
  543. +           statement.setInt(8, _npcY);
  544. +           statement.setInt(9, _npcZ);
  545. +           statement.setInt(10, _rewardId);
  546. +           statement.setInt(11, _rewardAmount);
  547. +           statement.setInt(12, _playerColors);
  548. +           statement.setInt(13, _playerX);
  549. +           statement.setInt(14, _playerY);
  550. +           statement.setInt(15, _playerZ);
  551. +           statement.execute();
  552. +           statement.close();
  553. +       }
  554. +       catch (Exception e)
  555. +       {
  556. +           _log.warning("Exception: DM.saveData(): " + e.getMessage());
  557. +       }      
  558. +       finally { try { if (con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); } }
  559. +   }
  560. +
  561. +   public static void showEventHtml(L2PcInstance eventPlayer, String objectId)
  562. +   {
  563. +       try
  564. +       {
  565. +           NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  566. +
  567. +           TextBuilder replyMSG = new TextBuilder("<html><body>");
  568. +           replyMSG.append("DM Match<br><br><br>");
  569. +           replyMSG.append("Current event...<br1>");
  570. +           replyMSG.append("   ... name:&nbsp;<font color=\"00FF00\">" + _eventName + "</font><br1>");
  571. +           replyMSG.append("   ... description:&nbsp;<font color=\"00FF00\">" + _eventDesc + "</font><br><br>");
  572. +
  573. +           if (!_started && !_joining)
  574. +               replyMSG.append("<center>Wait till the admin/gm start the participation.</center>");
  575. +           else if (!_started && _joining && eventPlayer.getLevel()>=_minlvl && eventPlayer.getLevel()<_maxlvl)
  576. +           {
  577. +               if (_players.contains(eventPlayer))
  578. +               {
  579. +                   replyMSG.append("You are already participating!<br><br>");
  580. +
  581. +                   replyMSG.append("<table border=\"0\"><tr>");
  582. +                   replyMSG.append("<td width=\"200\">Wait till event start or</td>");
  583. +                   replyMSG.append("<td width=\"60\"><center><button value=\"remove\" action=\"bypass -h npc_" + objectId + "_dmevent_player_leave\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></td>");
  584. +                   replyMSG.append("<td width=\"100\">your participation!</td>");
  585. +                   replyMSG.append("</tr></table>");
  586. +               }
  587. +               else
  588. +               {
  589. +                   replyMSG.append("You want to participate in the event?<br><br>");
  590. +                   replyMSG.append("<td width=\"200\">Admin set min lvl : <font color=\"00FF00\">" + _minlvl + "</font></td><br>");
  591. +                   replyMSG.append("<td width=\"200\">Admin set max lvl : <font color=\"00FF00\">" + _maxlvl + "</font></td><br><br>");
  592. +                  
  593. +                   replyMSG.append("<button value=\"Join\" action=\"bypass -h npc_" + objectId + "_dmevent_player_join\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  594. +                  
  595. +               }
  596. +           }
  597. +           else if (_started && !_joining)
  598. +               replyMSG.append("<center>DM match is in progress.</center>");
  599. +           else if (eventPlayer.getLevel()<_minlvl || eventPlayer.getLevel()>_maxlvl )
  600. +           {
  601. +               replyMSG.append("Your lvl : <font color=\"00FF00\">" + eventPlayer.getLevel() +"</font><br>");
  602. +               replyMSG.append("Admin set min lvl : <font color=\"00FF00\">" + _minlvl + "</font><br>");
  603. +               replyMSG.append("Admin set max lvl : <font color=\"00FF00\">" + _maxlvl + "</font><br><br>");
  604. +               replyMSG.append("<font color=\"FFFF00\">You can't participate to this event.</font><br>");
  605. +           }
  606. +          
  607. +           replyMSG.append("</body></html>");
  608. +           adminReply.setHtml(replyMSG.toString());
  609. +           eventPlayer.sendPacket(adminReply);
  610. +
  611. +           // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  612. +           eventPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  613. +       }
  614. +       catch (Exception e)
  615. +       {
  616. +           _log.warning("DM Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception" + e.getMessage());
  617. +       }
  618. +   }
  619. +
  620. +   public static void addPlayer(L2PcInstance player)
  621. +   {
  622. +       if (!addPlayerOk(player))
  623. +           return;
  624. +       _players.add(player);
  625. +       player._originalNameColorDM = player.getAppearance().getNameColor();
  626. +       player._originalKarmaDM = player.getKarma();
  627. +       player._inEventDM = true;
  628. +       player._countDMkills = 0;
  629. +       _savePlayers.add(player.getName());
  630. +      
  631. +   }
  632. +
  633. +   public static boolean addPlayerOk(L2PcInstance eventPlayer)
  634. +   {
  635. +      
  636. +       if (eventPlayer._inEventDM)
  637. +       {
  638. +           eventPlayer.sendMessage("You are already participating in the event!");
  639. +           return false;
  640. +       }
  641. +      
  642. +
  643. +       return true;
  644. +   }
  645. +
  646. +   public static synchronized void addDisconnectedPlayer(L2PcInstance player)
  647. +   {
  648. +       if ((_teleport || _started) || _savePlayers.contains(player.getName()))
  649. +       {
  650. +           if (Config.DM_ON_START_REMOVE_ALL_EFFECTS)
  651. +           {
  652. +               for (L2Effect e : player.getAllEffects())
  653. +               {
  654. +                   if (e != null)
  655. +                       e.exit();
  656. +               }
  657. +           }
  658. +           for (L2PcInstance p : _players)
  659. +           {
  660. +               if (p==null)
  661. +               {
  662. +                   continue;
  663. +               }
  664. +               //check by name incase player got new objectId
  665. +               else if (p.getName().equals(player.getName()))
  666. +               {
  667. +                   player._originalNameColorDM = player.getAppearance().getNameColor();
  668. +                   player._originalKarmaDM = player.getKarma();
  669. +                   player._inEventDM = true;
  670. +                   player._countDMkills =p._countDMkills;
  671. +                   _players.remove(p); //removing old object id from vector
  672. +                   _players.add(player); //adding new objectId to vector
  673. +                   break;
  674. +               }
  675. +           }
  676. +          
  677. +           player.getAppearance().setNameColor(_playerColors);
  678. +           player.setKarma(0);
  679. +           player.broadcastUserInfo();
  680. +           player.teleToLocation(_playerX, _playerY , _playerZ, false);
  681. +       }
  682. +   }
  683. +  
  684. +   public static void removePlayer(L2PcInstance player)
  685. +   {
  686. +       if (player != null)
  687. +       {
  688. +           _players.remove(player);
  689. +       }
  690. +   }
  691. +  
  692. +   public static void cleanDM()
  693. +   {
  694. +       for (L2PcInstance player : _players)
  695. +       {
  696. +           removePlayer(player);
  697. +       }
  698. +
  699. +       _savePlayers = new Vector<String>();
  700. +       _topPlayer = null;
  701. +       _npcSpawn = null;
  702. +       _joining = false;
  703. +       _teleport = false;
  704. +       _started = false;
  705. +       _sitForced = false;
  706. +       _topKills = 0;
  707. +       _players = new Vector<L2PcInstance>();
  708. +      
  709. +   }
  710. +  
  711. +   public static void unspawnEventNpc()
  712. +   {
  713. +       if (_npcSpawn == null)
  714. +           return;
  715. +
  716. +       _npcSpawn.getLastSpawn().deleteMe();
  717. +       _npcSpawn.stopRespawn();
  718. +       SpawnTable.getInstance().deleteSpawn(_npcSpawn, true);
  719. +   }
  720. +  
  721. +   public static void teleportFinish()
  722. +   {
  723. +       Announcements.getInstance().announceToAll(_eventName + "(DM): Teleport back to participation NPC in 20 seconds!");
  724. +
  725. +       removeUserData();
  726. +       ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  727. +       {
  728. +           public void run()
  729. +           {
  730. +               for (L2PcInstance player : _players)
  731. +               {
  732. +                   if (player !=  null && player.isOnline()!=0)
  733. +                       player.teleToLocation(_npcX, _npcY, _npcZ, false);
  734. +               }
  735. +               cleanDM();
  736. +           }
  737. +       }, 20000);
  738. +   }
  739. +}
  740. \ No newline at end of file
  741. Index: java/net/sf/l2j/gameserver/model/actor/L2Summon.java
  742. ===================================================================
  743. --- java/net/sf/l2j/gameserver/model/actor/L2Summon.java    (revision 3427)
  744. +++ java/net/sf/l2j/gameserver/model/actor/L2Summon.java    (working copy)
  745.  -685,9 +685,12 @@
  746.                     && getOwner() != null
  747.                     && (!getOwner().getAccessLevel().allowPeaceAttack()))
  748.             {
  749. -               // If summon or target is in a peace zone, send a system message TARGET_IN_PEACEZONE
  750. -               sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  751. -               return;
  752. +               if(!this.isInFunEvent() || !target.isInFunEvent())
  753. +                                   {
  754. +                                       // If summon or target is in a peace zone, send a system message TARGET_IN_PEACEZONE
  755. +                                           sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  756. +                                           return;
  757. +                                   }
  758.             }
  759.  
  760.             if (getOwner() != null && getOwner().isInOlympiadMode() && !getOwner().isOlympiadStart()){
  761. Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
  762. ===================================================================
  763. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java (revision 3427)
  764. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java (working copy)
  765.  -27,10 +27,12 @@
  766.  import net.sf.l2j.gameserver.model.L2CharPosition;
  767.  import net.sf.l2j.gameserver.model.L2Object;
  768.  import net.sf.l2j.gameserver.model.L2World;
  769. +import net.sf.l2j.gameserver.model.actor.instance.L2ClassMasterInstance;
  770.  import net.sf.l2j.gameserver.model.actor.L2Npc;
  771.  import net.sf.l2j.gameserver.model.actor.instance.L2MerchantSummonInstance;
  772.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  773.  import net.sf.l2j.gameserver.model.entity.L2Event;
  774. +import net.sf.l2j.gameserver.model.entity.DM;
  775.  import net.sf.l2j.gameserver.model.olympiad.Olympiad;
  776.  import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  777.  import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  778.  -124,7 +126,22 @@
  779.                     {
  780.                         ((L2Npc)object).onBypassFeedback(activeChar, _command.substring(endOfId+1));
  781.                     }
  782. +                   if (_command.substring(endOfId+1).startsWith("dmevent_player_join"))
  783. +                    {
  784. +                        if (DM._joining)
  785. +                            DM.addPlayer(activeChar);
  786. +                        else
  787. +                            activeChar.sendMessage("The event is already started. You can not join now!");
  788. +                    }
  789. +                  
  790. +                    else if (_command.substring(endOfId+1).startsWith("dmevent_player_leave"))
  791. +                    {
  792. +                        if (DM._joining)
  793. +                            DM.removePlayer(activeChar);
  794. +                        else
  795. +                            activeChar.sendMessage("The event is already started. You can not leave now!");
  796.                     activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  797. +                    }
  798.                 }
  799.                 catch (NumberFormatException nfe) {}
  800.             }
  801. Index: java/net/sf/l2j/gameserver/model/L2Object.java
  802. ===================================================================
  803. --- java/net/sf/l2j/gameserver/model/L2Object.java  (revision 3427)
  804. +++ java/net/sf/l2j/gameserver/model/L2Object.java  (working copy)
  805.  -435,4 +435,10 @@
  806.      {
  807.          return "" + getObjectId();
  808.      }
  809. +    public boolean isInFunEvent()
  810. +       {
  811. +           L2PcInstance player = getActingPlayer();
  812. +    
  813. +           return (player == null ? false : player.isInFunEvent());
  814. +       }
  815.  }
  816. \ No newline at end of file
  817. Index: java/net/sf/l2j/gameserver/model/actor/stat/PcStat.java
  818. ===================================================================
  819. --- java/net/sf/l2j/gameserver/model/actor/stat/PcStat.java (revision 3427)
  820. +++ java/net/sf/l2j/gameserver/model/actor/stat/PcStat.java (working copy)
  821.  -21,6 +21,7 @@
  822.  import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  823.  import net.sf.l2j.gameserver.model.base.Experience;
  824.  import net.sf.l2j.gameserver.model.quest.QuestState;
  825. +import net.sf.l2j.gameserver.model.entity.DM;
  826.  import net.sf.l2j.gameserver.network.SystemMessageId;
  827.  import net.sf.l2j.gameserver.network.serverpackets.ExBrExtraUserInfo;
  828.  import net.sf.l2j.gameserver.network.serverpackets.ExVitalityPointInfo;
  829.  -200,6 +201,12 @@
  830.             getActiveChar().setCurrentCp(getMaxCp());
  831.              getActiveChar().broadcastPacket(new SocialAction(getActiveChar().getObjectId(), SocialAction.LEVEL_UP));
  832.              getActiveChar().sendPacket(new SystemMessage(SystemMessageId.YOU_INCREASED_YOUR_LEVEL));
  833. +            if (getActiveChar().isInFunEvent())
  834. +                           {
  835. +                               if (getActiveChar()._inEventDM && DM._maxlvl == getLevel() && !DM._started)
  836. +                                   DM.removePlayer(getActiveChar());
  837. +                               getActiveChar().sendMessage("Your event sign up was canceled.");
  838. +                           }
  839.          }
  840.  
  841.          getActiveChar().rewardSkills(); // Give Expertise skill of this level
  842. Index: java/net/sf/l2j/gameserver/model/actor/L2Character.java
  843. ===================================================================
  844. --- java/net/sf/l2j/gameserver/model/actor/L2Character.java (revision 3427)
  845. +++ java/net/sf/l2j/gameserver/model/actor/L2Character.java (working copy)
  846.  -5487,8 +5487,11 @@
  847.          if (isInsidePeaceZone(player))
  848.         {
  849.             // If L2Character or target is in a peace zone, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed
  850. -           player.sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  851. -           player.sendPacket(ActionFailed.STATIC_PACKET);
  852. +           if(!player.isInFunEvent() || !player.getTarget().isInFunEvent())
  853. +                           {
  854. +                               player.sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  855. +                               player.sendPacket(ActionFailed.STATIC_PACKET);
  856. +                           }
  857.         }
  858.         else if (player.isInOlympiadMode() && player.getTarget() != null && player.getTarget() instanceof L2Playable)
  859.          {
  860.  -5540,7 +5543,11 @@
  861.      */
  862.     public boolean isInsidePeaceZone(L2PcInstance attacker)
  863.     {
  864. -       return isInsidePeaceZone(attacker, this);
  865. +       if(!this.isInFunEvent() || !attacker.isInFunEvent())
  866. +                   {
  867. +                       return isInsidePeaceZone(attacker, this);
  868. +                   }
  869. +                   return false;
  870.     }
  871.  
  872.     public boolean isInsidePeaceZone(L2PcInstance attacker, L2Object target)
  873. Index: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  874. ===================================================================
  875. --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java   (revision 3427)
  876. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java   (working copy)
  877.  -134,6 +134,7 @@
  878.  import net.sf.l2j.gameserver.model.entity.Fort;
  879.  import net.sf.l2j.gameserver.model.entity.L2Event;
  880.  import net.sf.l2j.gameserver.model.entity.Siege;
  881. +import net.sf.l2j.gameserver.model.entity.DM;
  882.  import net.sf.l2j.gameserver.model.entity.TvTEvent;
  883.  import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
  884.  import net.sf.l2j.gameserver.model.itemcontainer.ItemContainer;
  885.  -682,7 +683,12 @@
  886.     public LinkedList<String> kills = new LinkedList<String>();
  887.     public boolean eventSitForced = false;
  888.     public boolean atEvent = false;
  889. +  
  890. +   /** DM Engine parameters */
  891. +   public int                              _originalNameColorDM, _countDMkills, _originalKarmaDM;
  892. +   public boolean                          _inEventDM              = false;
  893.  
  894. +
  895.     /** new loto ticket **/
  896.     private int _loto[] = new int[5];
  897.     //public static int _loto_nums[] = {0,1,2,3,4,5,6,7,8,9,};
  898.  -2974,6 +2980,8 @@
  899.         {
  900.             sendMessage("A dark force beyond your mortal understanding makes your knees to shake when you try to stand up ...");
  901.         }
  902. +       else if (DM._sitForced && _inEventDM)
  903. +                       sendMessage("The Admin/GM handle if you sit or stand in this match!");
  904.         else if (_waitTypeSitting && !isInStoreMode() && !isAlikeDead())
  905.         {
  906.             if (_relax)
  907.  -4052,6 +4060,14 @@
  908.             player.sendPacket(ActionFailed.STATIC_PACKET);
  909.             return;
  910.         }
  911. +               if (DM._started && !Config.DM_ALLOW_INTERFERENCE)
  912. +                   {
  913. +                       if ((_inEventDM && !player._inEventDM) || (!_inEventDM && player._inEventDM))
  914. +                       {
  915. +                           sendPacket(ActionFailed.STATIC_PACKET);
  916. +                           return;
  917. +                       }
  918. +                   }
  919.  
  920.         // Check if the L2PcInstance is confused
  921.         if (player.isOutOfControl())
  922.  -4091,7 +4107,7 @@
  923.             else
  924.             {
  925.                 // Check if this L2PcInstance is autoAttackable
  926. -               if (isAutoAttackable(player))
  927. +               if (isAutoAttackable(player) || (player._inEventDM && DM._started))
  928.                 {
  929.                     // Player with lvl < 21 can't attack a cursed weapon holder
  930.                     // And a cursed weapon holder  can't attack players with lvl < 21
  931.  -4160,6 +4176,10 @@
  932.         }
  933.         player.sendPacket(ActionFailed.STATIC_PACKET);
  934.     }
  935. +       public boolean isInFunEvent()
  936. +       {
  937. +           return (atEvent || (DM._started && _inEventDM));
  938. +       }
  939.    
  940.     /**
  941.      * Returns true if cp update should be done, false if not
  942.  -5256,6 +5276,39 @@
  943.            
  944.             TvTEvent.onKill(killer, this);
  945.            
  946. +            if ((killer instanceof L2PcInstance && ((L2PcInstance) killer)._inEventDM) && _inEventDM)
  947. +           {
  948. +               if (DM._teleport || DM._started)
  949. +               {
  950. +                   ((L2PcInstance) killer)._countDMkills++;
  951. +
  952. +                   sendMessage("You will be revived and teleported to spot in " + Config.DM_REVIVE_DELAY / 1000 + " seconds!");
  953. +                   ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  954. +                   {
  955. +                       public void run()
  956. +                       {
  957. +                           teleToLocation(DM._playerX, DM._playerY, DM._playerZ, false);
  958. +                           doRevive();
  959. +                       }
  960. +                   }, Config.DM_REVIVE_DELAY);
  961. +               }
  962. +           }
  963. +           else if (_inEventDM)
  964. +           {
  965. +               if (DM._teleport || DM._started)
  966. +               {
  967. +                   sendMessage("You will be revived and teleported to spot in " + Config.DM_REVIVE_DELAY / 1000 + " seconds!");
  968. +                   ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  969. +                   {
  970. +                       public void run()
  971. +                       {
  972. +                           teleToLocation(DM._playerX, DM._playerY, DM._playerZ, false);
  973. +                           doRevive();
  974. +                       }
  975. +                   }, Config.DM_REVIVE_DELAY);
  976. +               }
  977. +           }
  978. +          
  979.             if (atEvent && pk != null)
  980.             {
  981.                 pk.kills.add(getName());
  982.  -5367,7 +5420,7 @@
  983.  
  984.     private void onDieDropItem(L2Character killer)
  985.     {
  986. -       if (atEvent || killer == null)
  987. +       if (atEvent || (DM._started && _inEventDM) || killer == null)
  988.              return;
  989.  
  990.         L2PcInstance pk = killer.getActingPlayer();
  991.  -5479,6 +5532,9 @@
  992.     {
  993.         if (target == null) return;
  994.         if (!(target instanceof L2Playable)) return;
  995. +      
  996. +       if (_inEventDM)
  997. +                       return;
  998.  
  999.         L2PcInstance targetPlayer = target.getActingPlayer();
  1000.  
  1001.  -5571,6 +5627,9 @@
  1002.       */
  1003.      public void increasePvpKills()
  1004.      {
  1005. +      
  1006. +       if (DM._started && _inEventDM)
  1007. +                       return;
  1008.          // Add karma to attacker and increase its PK counter
  1009.          setPvpKills(getPvpKills() + 1);
  1010.  
  1011.  -5586,6 +5645,9 @@
  1012.       */
  1013.      public void increasePkKillsAndKarma(int targLVL)
  1014.      {
  1015. +       if (DM._started && _inEventDM)
  1016. +                       return;
  1017. +      
  1018.          int baseKarma           = Config.KARMA_MIN_KARMA;
  1019.          int newKarma            = baseKarma;
  1020.          int karmaLimit          = Config.KARMA_MAX_KARMA;
  1021.  -5666,10 +5728,16 @@
  1022.  
  1023.     public void updatePvPStatus(L2Character target)
  1024.     {
  1025. +       if (DM._started && _inEventDM)
  1026. +                       return;
  1027. +      
  1028.         L2PcInstance player_target = target.getActingPlayer();
  1029.  
  1030.          if (player_target == null)
  1031.             return;
  1032. +        
  1033. +        if (DM._started && _inEventDM && player_target._inEventDM)
  1034. +                       return;
  1035.  
  1036.          if ((isInDuel() && player_target.getDuelId() == getDuelId())) return;
  1037.          if ((!isInsideZone(ZONE_PVP) || !player_target.isInsideZone(ZONE_PVP)) && player_target.getKarma() == 0)
  1038.  -5787,7 +5855,7 @@
  1039.  
  1040.         // Calculate the Experience loss
  1041.         long lostExp = 0;
  1042. -       if (!atEvent)
  1043. +       if (!atEvent && !_inEventDM)
  1044.             if (lvl < Experience.MAX_LEVEL)
  1045.                 lostExp = Math.round((getStat().getExpForLevel(lvl+1) - getStat().getExpForLevel(lvl)) * percentLost /100);
  1046.             else
  1047.  -8684,12 +8752,13 @@
  1048.          if (skill.isOffensive())
  1049.         {
  1050.             if ((isInsidePeaceZone(this, target)) && !getAccessLevel().allowPeaceAttack())
  1051. -           {
  1052. -               // If L2Character or target is in a peace zone, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed
  1053. -               sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  1054. -               sendPacket(ActionFailed.STATIC_PACKET);
  1055. -               return false;
  1056. -           }
  1057. +               if(!this.isInFunEvent() || !target.isInFunEvent())
  1058. +                                   {
  1059. +                                       // If L2Character or target is in a peace zone, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed
  1060. +                                       sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  1061. +                                       sendPacket(ActionFailed.STATIC_PACKET);
  1062. +                                       return false;
  1063. +                                   }
  1064.  
  1065.             if (isInOlympiadMode() && !isOlympiadStart()){
  1066.                 // if L2PcInstance is in Olympia and the match isn't already start, send a Server->Client packet ActionFailed
  1067.  -8700,9 +8769,12 @@
  1068.              // Check if the target is attackable
  1069.              if (!target.isAttackable() && !getAccessLevel().allowPeaceAttack())
  1070.             {
  1071. -               // If target is not attackable, send a Server->Client packet ActionFailed
  1072. -               sendPacket(ActionFailed.STATIC_PACKET);
  1073. -               return false;
  1074. +               if(!this.isInFunEvent() || !target.isInFunEvent())
  1075. +                                   {
  1076. +                                       // If target is not attackable, send a Server->Client packet ActionFailed
  1077. +                                       sendPacket(ActionFailed.STATIC_PACKET);
  1078. +                                       return false;
  1079. +                                   }
  1080.             }
  1081.  
  1082.             // Check if a Forced ATTACK is in progress on non-attackable target
  1083.  -8772,13 +8844,14 @@
  1084.             // And this skill cannot be used in peace zone, not even on NPCs!
  1085.             if(this.isInsideZone(L2Character.ZONE_PEACE))
  1086.             {
  1087. -               //Sends a sys msg to client
  1088. -               sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  1089. -              
  1090. -               // Send a Server->Client packet ActionFailed to the L2PcInstance
  1091. -               sendPacket(ActionFailed.STATIC_PACKET);
  1092. -              
  1093. -               return false;
  1094. +               if(!this.isInFunEvent() || !target.isInFunEvent())
  1095. +                                   {
  1096. +                                           //Sends a sys msg to client
  1097. +                                           sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  1098. +                                           // Send a Server->Client packet ActionFailed to the L2PcInstance
  1099. +                                       sendPacket(ActionFailed.STATIC_PACKET);
  1100. +                                       return false;
  1101. +                                   }
  1102.             }
  1103.            
  1104.          }
  1105.  -8892,12 +8965,14 @@
  1106.             default:
  1107.                 if (!checkPvpSkill(target, skill) && !getAccessLevel().allowPeaceAttack())
  1108.                  {
  1109. -                   // Send a System Message to the L2PcInstance
  1110. -                   sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1111. -
  1112. -                   // Send a Server->Client packet ActionFailed to the L2PcInstance
  1113. -                   sendPacket(ActionFailed.STATIC_PACKET);
  1114. -                   return false;
  1115. +                   if(!this.isInFunEvent() || !target.isInFunEvent())
  1116. +                                           {
  1117. +                                               // Send a System Message to the L2PcInstance
  1118. +                                               sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1119. +                                              
  1120. +                                               // Send a Server->Client packet ActionFailed to the L2PcInstance
  1121. +                                                                       sendPacket(ActionFailed.STATIC_PACKET);
  1122. +                                                                       return false;
  1123.                 }
  1124.         }
  1125.  
  1126.  -8933,6 +9008,8 @@
  1127.          // finally, after passing all conditions
  1128.          return true;
  1129.     }
  1130. +       return dontMove;
  1131. +   }
  1132.    
  1133.     public boolean checkIfOkToUseStriderSiegeAssault(boolean isCheckOnly)
  1134.     {
  1135.  -9079,6 +9156,10 @@
  1136.      */
  1137.     public boolean checkPvpSkill(L2Object target, L2Skill skill)
  1138.     {
  1139. +      
  1140. +       if (_inEventDM && DM._started)
  1141. +                       return true;
  1142. +  
  1143.         return checkPvpSkill(target, skill, false);
  1144.     }
  1145.    
  1146.  -10703,6 +10784,7 @@
  1147.             if (!DimensionalRiftManager.getInstance().checkIfInPeaceZone(getX(), getY(), getZ()))
  1148.                 getParty().getDimensionalRift().memberRessurected(this);
  1149.         }
  1150. +      
  1151.     }
  1152.  
  1153.     @Override
  1154. Index: java/net/sf/l2j/gameserver/model/actor/L2Npc.java
  1155. ===================================================================
  1156. --- java/net/sf/l2j/gameserver/model/actor/L2Npc.java   (revision 3427)
  1157. +++ java/net/sf/l2j/gameserver/model/actor/L2Npc.java   (working copy)
  1158.  -69,6 +69,7 @@
  1159.  import net.sf.l2j.gameserver.model.entity.Castle;
  1160.  import net.sf.l2j.gameserver.model.entity.Fort;
  1161.  import net.sf.l2j.gameserver.model.entity.L2Event;
  1162. +import net.sf.l2j.gameserver.model.entity.DM;
  1163.  import net.sf.l2j.gameserver.model.itemcontainer.NpcInventory;
  1164.  import net.sf.l2j.gameserver.model.olympiad.Olympiad;
  1165.  import net.sf.l2j.gameserver.model.quest.Quest;
  1166.  -144,7 +145,8 @@
  1167.     /** The fortress index in the array of L2Fort this L2NpcInstance belongs to */
  1168.     private int _fortIndex = -2;
  1169.  
  1170. -   public boolean isEventMob = false;
  1171. +  
  1172. +   public boolean                  isEventMob              = false, _isEventMobDM = false ;
  1173.     private boolean _isInTown = false;
  1174.  
  1175.     private int _isSpoiledBy = 0;
  1176.  -685,6 +687,8 @@
  1177.                     {
  1178.                         L2Event.showEventHtml(player, String.valueOf(getObjectId()));
  1179.                     }
  1180. +                   else if (_isEventMobDM)
  1181. +                       DM.showEventHtml(player, String.valueOf(getObjectId()));
  1182.                     else
  1183.                     {
  1184.                         Quest[] qlsa = getTemplate().getEventQuests(Quest.QuestEventType.QUEST_START);
  1185. Index: java/net/sf/l2j/gameserver/model/L2Skill.java
  1186. ===================================================================
  1187. --- java/net/sf/l2j/gameserver/model/L2Skill.java   (revision 3427)
  1188. +++ java/net/sf/l2j/gameserver/model/L2Skill.java   (working copy)
  1189.  -36,6 +36,7 @@
  1190.  import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  1191.  import net.sf.l2j.gameserver.model.actor.instance.L2SiegeFlagInstance;
  1192.  import net.sf.l2j.gameserver.model.actor.instance.L2SummonInstance;
  1193. +import net.sf.l2j.gameserver.model.entity.DM;
  1194.  import net.sf.l2j.gameserver.model.entity.TvTEvent;
  1195.  import net.sf.l2j.gameserver.network.SystemMessageId;
  1196.  import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  1197.  -1637,6 +1638,12 @@
  1198.                     {
  1199.                         if (partyMember == null || partyMember == player)
  1200.                             continue;
  1201. +                       //check if allow interference is allowed if player is not on event but target is on event
  1202. +                                           if ((DM._started && !Config.DM_ALLOW_INTERFERENCE) && !player.isGM())
  1203. +                                               {
  1204. +                                                   if ((partyMember._inEventDM && !player._inEventDM) || (!partyMember._inEventDM && player._inEventDM))
  1205. +                                                       continue;
  1206. +                                               }
  1207.  
  1208.                         if (addCharacter(activeChar, partyMember, radius, false))
  1209.                             targetList.add(partyMember);
  1210.  -1937,7 +1944,12 @@
  1211.                     {
  1212.                         if (obj == null)
  1213.                             continue;
  1214. -
  1215. +                       //check if allow interference is allowed if player is not on event but target is on event
  1216. +                                                   if ((DM._started && !Config.DM_ALLOW_INTERFERENCE) && !player.isGM())
  1217. +                                                   {
  1218. +                                                       if ((player._inEventDM && !player._inEventDM) || (!player._inEventDM && player._inEventDM))
  1219. +                                                           continue;
  1220. +                                                   }
  1221.                         if (player.isInDuel())
  1222.                         {
  1223.                             if (player.getDuelId() != obj.getDuelId())
  1224. Index: java/config/l2jmods.properties
  1225. ===================================================================
  1226. --- java/config/l2jmods.properties  (revision 3427)
  1227. +++ java/config/l2jmods.properties  (working copy)
  1228.  -248,4 +248,17 @@
  1229.  # This option will enable core support for:
  1230.  # Mana Drug (item ID 726), using skill ID 9007.
  1231.  # Mana Potion (item ID 728), using skill ID 9008.
  1232. -EnableManaPotionSupport = False
  1233. \ No newline at end of file
  1234. +EnableManaPotionSupport = False
  1235. +
  1236. +#Players that are not participating in DM can target DM participants?
  1237. +DMAllowInterference = False
  1238. +# DM participants can use potions?
  1239. +DMAllowPotions = False
  1240. +# DM participants can summon by item?
  1241. +DMAllowSummon = False
  1242. +# Remove all effects of DM participants on event start?
  1243. +DMOnStartRemoveAllEffects = True
  1244. +# Unsummon pet of DM participants on event start?
  1245. +DMOnStartUnsummonPet = True
  1246. +# Delay on revive when dead, NOTE: 20000 equals to 20 seconds, minimum 1000 (1 second)
  1247. +DMReviveDelay = 20000
  1248. \ No newline at end of file
  1249. Index: java/net/sf/l2j/gameserver/model/actor/instance/L2VillageMasterInstance.java
  1250. ===================================================================
  1251. --- java/net/sf/l2j/gameserver/model/actor/instance/L2VillageMasterInstance.java    (revision 3427)
  1252. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2VillageMasterInstance.java    (working copy)
  1253.  -47,6 +47,7 @@
  1254.  import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  1255.  import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  1256.  import net.sf.l2j.gameserver.network.serverpackets.UserInfo;
  1257. +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  1258.  import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate;
  1259.  import net.sf.l2j.gameserver.util.StringUtil;
  1260.  import net.sf.l2j.gameserver.util.Util;
  1261.  -318,6 +319,11 @@
  1262.                          player.sendMessage("You may not add a new sub class before you are level 75 on your previous class.");
  1263.                          allowAddition = false;
  1264.                      }
  1265. +                    if (player._inEventDM)
  1266. +                                           {
  1267. +                                               player.sendMessage("You have already been registered in a waiting list of an event.");
  1268. +                                               return;
  1269. +                                           }
  1270.  
  1271.                      if (allowAddition)
  1272.                      {
  1273.  -404,7 +410,11 @@
  1274.                       *
  1275.                       * Note: paramOne = classIndex
  1276.                       */
  1277. -
  1278. +                   if (player._inEventDM)
  1279. +                                           {
  1280. +                                               player.sendMessage("You have already been registered in a waiting list of an event.");
  1281. +                                               return;
  1282. +                                           }
  1283.                      /*
  1284.                       * DrHouse: Despite this is not 100% retail like, it is here to avoid some exploits during subclass changes, specially
  1285.                       * on small servers. TODO: On retail, each village master doesn't offer any subclass that is not given by itself so player
  1286. Index: java/net/sf/l2j/gameserver/model/L2Radar.java
  1287. ===================================================================
  1288. --- java/net/sf/l2j/gameserver/model/L2Radar.java   (revision 3427)
  1289. +++ java/net/sf/l2j/gameserver/model/L2Radar.java   (working copy)
  1290.  -16,6 +16,7 @@
  1291.  
  1292.  import javolution.util.FastList;
  1293.  
  1294. +import net.sf.l2j.gameserver.ThreadPoolManager;
  1295.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1296.  import net.sf.l2j.gameserver.network.serverpackets.RadarControl;
  1297.  
  1298.  -127,4 +128,32 @@
  1299.             return true;
  1300.          }
  1301.      }
  1302. +    public class RadarOnPlayer implements Runnable
  1303. +        {
  1304. +           private final L2PcInstance _myTarget, _me;
  1305. +    
  1306. +            public RadarOnPlayer(L2PcInstance target, L2PcInstance me)
  1307. +          {
  1308. +                _me = me;
  1309. +                _myTarget = target;
  1310. +            }
  1311. +    
  1312. +            public void run()
  1313. +            {
  1314. +                try
  1315. +                {
  1316. +                    if (_me == null || _me.isOnline()==0)
  1317. +                        return;
  1318. +    
  1319. +                    _me.sendPacket(new RadarControl(1, 1, _me.getX(), _me.getY(), _me.getZ()));
  1320. +                    if (_myTarget == null || _myTarget.isOnline()==0 )
  1321. +                        return;
  1322. +    
  1323. +                    _me.sendPacket(new RadarControl(0, 1, _myTarget.getX(), _myTarget.getY(), _myTarget.getZ()));
  1324. +                    ThreadPoolManager.getInstance().scheduleGeneral(new RadarOnPlayer(_myTarget,_me), 15000);
  1325. +                 }
  1326. +                catch(Throwable t)
  1327. +                {}
  1328. +            }
  1329. +        }
  1330.  }
  1331. Index: java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
  1332. ===================================================================
  1333. --- java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java    (revision 3427)
  1334. +++ java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java    (working copy)
  1335.  -57,6 +57,7 @@
  1336.  import net.sf.l2j.gameserver.model.entity.L2Event;
  1337.  import net.sf.l2j.gameserver.model.entity.Siege;
  1338.  import net.sf.l2j.gameserver.model.entity.TvTEvent;
  1339. +import net.sf.l2j.gameserver.model.entity.DM;
  1340.  import net.sf.l2j.gameserver.model.olympiad.Olympiad;
  1341.  import net.sf.l2j.gameserver.model.quest.Quest;
  1342.  import net.sf.l2j.gameserver.model.quest.QuestState;
  1343.  -438,6 +439,8 @@
  1344.         RegionBBSManager.getInstance().changeCommunityBoard();
  1345.  
  1346.         TvTEvent.onLogin(activeChar);
  1347. +       if (DM._savePlayers.contains(activeChar.getName()))
  1348. +                       DM.addDisconnectedPlayer(activeChar);
  1349.     }
  1350.  
  1351.     /**
  1352. Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestActionUse.java
  1353. ===================================================================
  1354. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestActionUse.java  (revision 3427)
  1355. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestActionUse.java  (working copy)
  1356.  -171,8 +171,11 @@
  1357.                    
  1358.                     if (!activeChar.getAccessLevel().allowPeaceAttack() && activeChar.isInsidePeaceZone(pet, target))
  1359.                     {
  1360. -                       activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  1361. -                       return;
  1362. +                       if(!activeChar.isInFunEvent() || !target.isInFunEvent())
  1363. +                                                   {
  1364. +                                                       activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  1365. +                                                       return;
  1366. +                                                   }
  1367.                     }
  1368.                     if (pet.getNpcId() == 12564 || pet.getNpcId() == 12621)
  1369.                     {
  1370. Index: java/net/sf/l2j/Config.java
  1371. ===================================================================
  1372. --- java/net/sf/l2j/Config.java (revision 3427)
  1373. +++ java/net/sf/l2j/Config.java (working copy)
  1374.  -594,8 +594,13 @@
  1375.     public static boolean OFFLINE_SET_NAME_COLOR;
  1376.     public static int OFFLINE_NAME_COLOR;
  1377.     public static boolean L2JMOD_ENABLE_MANA_POTIONS_SUPPORT;
  1378. +   public static boolean       DM_ALLOW_INTERFERENCE;
  1379. +   public static boolean       DM_ALLOW_POTIONS;
  1380. +   public static boolean       DM_ALLOW_SUMMON;
  1381. +   public static boolean       DM_ON_START_REMOVE_ALL_EFFECTS;
  1382. +   public static boolean       DM_ON_START_UNSUMMON_PET;
  1383. +   public static long          DM_REVIVE_DELAY;
  1384.  
  1385. -
  1386.     //--------------------------------------------------
  1387.     // NPC Settings
  1388.     //--------------------------------------------------
  1389.  -1779,6 +1784,15 @@
  1390.                     L2JMOD_ENABLE_WAREHOUSESORTING_PRIVATE = Boolean.valueOf(L2JModSettings.getProperty("EnableWarehouseSortingPrivate", "False"));
  1391.                     L2JMOD_ENABLE_WAREHOUSESORTING_FREIGHT = Boolean.valueOf(L2JModSettings.getProperty("EnableWarehouseSortingFreight", "False"));
  1392.  
  1393. +                   DM_ALLOW_INTERFERENCE = Boolean.parseBoolean(L2JModSettings.getProperty("DMAllowInterference", "false"));
  1394. +                   DM_ALLOW_POTIONS = Boolean.parseBoolean(L2JModSettings.getProperty("DMAllowPotions", "false"));
  1395. +                   DM_ALLOW_SUMMON = Boolean.parseBoolean(L2JModSettings.getProperty("DMAllowSummon", "false"));
  1396. +                   DM_ON_START_REMOVE_ALL_EFFECTS = Boolean.parseBoolean(L2JModSettings.getProperty("DMOnStartRemoveAllEffects", "true"));
  1397. +                   DM_ON_START_UNSUMMON_PET = Boolean.parseBoolean(L2JModSettings.getProperty("DMOnStartUnsummonPet", "true"));
  1398. +                   DM_REVIVE_DELAY = Long.parseLong(L2JModSettings.getProperty("DMReviveDelay", "20000"));
  1399. +                   if (DM_REVIVE_DELAY < 1000)
  1400. +                       DM_REVIVE_DELAY = 1000; //can't be set less then 1 second
  1401. +                  
  1402.                     if (TVT_EVENT_PARTICIPATION_NPC_ID == 0)
  1403.                     {
  1404.                         TVT_EVENT_ENABLED = false;
  1405.  -2390,7 +2404,19 @@
  1406.         else if (pName.equalsIgnoreCase("EnableWarehouseSortingFreight")) L2JMOD_ENABLE_WAREHOUSESORTING_FREIGHT = Boolean.parseBoolean(pValue);
  1407.  
  1408.         else if (pName.equalsIgnoreCase("EnableManaPotionSupport")) L2JMOD_ENABLE_MANA_POTIONS_SUPPORT = Boolean.parseBoolean(pValue);
  1409. -
  1410. +       else if (pName.equalsIgnoreCase("DMAllowInterference"))
  1411. +           DM_ALLOW_INTERFERENCE = Boolean.parseBoolean(pValue);
  1412. +       else if (pName.equalsIgnoreCase("DMAllowPotions"))
  1413. +           DM_ALLOW_POTIONS = Boolean.parseBoolean(pValue);
  1414. +       else if (pName.equalsIgnoreCase("DMAllowSummon"))
  1415. +           DM_ALLOW_SUMMON = Boolean.parseBoolean(pValue);
  1416. +       else if (pName.equalsIgnoreCase("DMOnStartRemoveAllEffects"))
  1417. +           DM_ON_START_REMOVE_ALL_EFFECTS = Boolean.parseBoolean(pValue);
  1418. +       else if (pName.equalsIgnoreCase("DMOnStartUnsummonPet"))
  1419. +           DM_ON_START_UNSUMMON_PET = Boolean.parseBoolean(pValue);
  1420. +       else if (pName.equalsIgnoreCase("DMReviveDelay"))
  1421. +           DM_REVIVE_DELAY = Long.parseLong(pValue);
  1422. +      
  1423.         else if (pName.equalsIgnoreCase("MinKarma")) KARMA_MIN_KARMA = Integer.parseInt(pValue);
  1424.         else if (pName.equalsIgnoreCase("MaxKarma")) KARMA_MAX_KARMA = Integer.parseInt(pValue);
  1425.         else if (pName.equalsIgnoreCase("XPDivider")) KARMA_XP_DIVIDER = Integer.parseInt(pValue);
  1426.  
  1427. Index: java/net/sf/l2j/util/Util.java
  1428. ===================================================================
  1429. --- java/net/sf/l2j/util/Util.java  (revision 3427)
  1430. +++ java/net/sf/l2j/util/Util.java  (working copy)
  1431. @@ -142,5 +142,21 @@
  1432.         buf.position(buf.position() - data.length);
  1433.         return hex;
  1434.     }
  1435. -  
  1436. +
  1437. +   /**
  1438. +     * @param substring
  1439. +     * @return
  1440. +     */
  1441. +public static String reverseColor(String color)
  1442. +{
  1443. +   char[] ch1 = color.toCharArray();
  1444. +   char[] ch2 = new char[6];
  1445. +   ch2[0] = ch1[4];
  1446. +   ch2[1] = ch1[5];
  1447. +   ch2[2] = ch1[2];
  1448. +   ch2[3] = ch1[3];
  1449. +   ch2[4] = ch1[0];
  1450. +   ch2[5] = ch1[1];
  1451. +   return new String(ch2);
  1452.  }
Advertisement
Add Comment
Please, Sign In to add comment