Advertisement
Guest User

Lucky Chests by Pony & Thug[Event]

a guest
Mar 2nd, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.06 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java
  4. ===================================================================
  5. --- java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java (revision 0)
  6. +++ java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java (revision 0)
  7. @@ -0,0 +1,15 @@
  8. +
  9. +package net.sf.l2j.gameserver.handler;
  10. +
  11. +import java.util.logging.Logger;
  12. +
  13. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  14. +
  15. +public interface IVoicedCommandHandler
  16. +{
  17. + public static Logger _log = Logger.getLogger(IVoicedCommandHandler.class.getName());
  18. +
  19. + public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params);
  20. +
  21. + public String[] getVoicedCommandList();
  22. +}
  23. \ No newline at end of file
  24. Index: java/net/sf/l2j/gameserver/model/actor/instance/L2LuckyChestInstance.java
  25. ===================================================================
  26. --- java/net/sf/l2j/gameserver/model/actor/instance/L2LuckyChestInstance.java (revision 0)
  27. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2LuckyChestInstance.java (revision 0)
  28. @@ -0,0 +1,62 @@
  29. +package net.sf.l2j.gameserver.model.actor.instance;
  30. +
  31. +import net.sf.l2j.Config;
  32. +import net.sf.l2j.gameserver.ThreadPoolManager;
  33. +import net.sf.l2j.gameserver.model.entity.LuckyChests;
  34. +import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate;
  35. +import net.sf.l2j.util.Rnd;
  36. +
  37. +/*
  38. + * @author ponyrider && Thug
  39. + *
  40. + */
  41. +public class L2LuckyChestInstance extends L2NpcInstance
  42. +{
  43. + public L2LuckyChestInstance(int objectId, L2NpcTemplate template)
  44. + {
  45. + super(objectId, template);
  46. + }
  47. +
  48. + private static int REWARD_RATE = Config.LUCKY_CHEST_REWARD_RATE;
  49. + private static int[][] REWARDS = Config.LUCKY_CHEST_REWARDS;
  50. +
  51. + @Override
  52. + public void onSpawn()
  53. + {
  54. + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  55. + {
  56. + @Override
  57. + public void run()
  58. + {
  59. + if(this!=null)
  60. + {
  61. + getSpawn().stopRespawn();
  62. + deleteMe();
  63. + }
  64. + }
  65. + }, 150000);
  66. + }
  67. +
  68. + @Override
  69. + public void showChatWindow(L2PcInstance player)
  70. + {
  71. + if(player == null)
  72. + return;
  73. +
  74. + if(!LuckyChests.getInstance().getPlayers().contains(player))
  75. + return;
  76. +
  77. + if(Rnd.get(100) < REWARD_RATE)
  78. + {
  79. + for(int[] rewardArray : REWARDS)
  80. + player.addItem("Lucky Chest", rewardArray[0], rewardArray[1], null, true);
  81. + }
  82. + else
  83. + player.sendMessage("Nothing happened!");
  84. +
  85. +
  86. + this.deleteMe();
  87. +
  88. + }
  89. +
  90. +}
  91. Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestMagicSkillUse.java
  92. ===================================================================
  93. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestMagicSkillUse.java (revision 1)
  94. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestMagicSkillUse.java (working copy)
  95. @@ -16,8 +16,10 @@
  96.  
  97. import net.sf.l2j.Config;
  98. import net.sf.l2j.gameserver.datatables.SkillTable;
  99. +import net.sf.l2j.gameserver.model.L2Object;
  100. import net.sf.l2j.gameserver.model.L2Skill;
  101. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  102. +import net.sf.l2j.gameserver.model.entity.LuckyChests;
  103. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  104. import net.sf.l2j.gameserver.templates.skills.L2SkillType;
  105.  
  106. @@ -49,6 +51,15 @@
  107. return;
  108. }
  109.  
  110. +
  111. + if(!LuckyChests.getInstance().canAct(activeChar))
  112. + return;
  113. +
  114. + L2Object target = activeChar.getTarget();
  115. + if(target instanceof L2PcInstance)
  116. + if(LuckyChests.getInstance().getPlayers().contains(target))
  117. + return;
  118. +
  119. // Get the level of the used skill
  120. final int level = activeChar.getSkillLevel(_magicId);
  121. if (level <= 0)
  122. Index: java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
  123. ===================================================================
  124. --- java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (revision 1)
  125. +++ java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (working copy)
  126. @@ -44,6 +44,7 @@
  127. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminInvul;
  128. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminKick;
  129. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminLevel;
  130. +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminLuckyChest;
  131. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminMaintenance;
  132. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminMammon;
  133. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminManor;
  134. @@ -67,6 +68,7 @@
  135. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminTeleport;
  136. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminUnblockIp;
  137. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminZone;
  138. +import net.sf.l2j.gameserver.model.entity.LuckyChests;
  139.  
  140. public class AdminCommandHandler
  141. {
  142. @@ -88,6 +90,7 @@
  143. registerAdminCommandHandler(new AdminBuffs());
  144. registerAdminCommandHandler(new AdminCache());
  145. registerAdminCommandHandler(new AdminCamera());
  146. + registerAdminCommandHandler(new AdminLuckyChest());
  147. registerAdminCommandHandler(new AdminChangeAccessLevel());
  148. registerAdminCommandHandler(new AdminCreateItem());
  149. registerAdminCommandHandler(new AdminCursedWeapons());
  150. Index: java/net/sf/l2j/gameserver/network/clientpackets/Say2.java
  151. ===================================================================
  152. --- java/net/sf/l2j/gameserver/network/clientpackets/Say2.java (revision 1)
  153. +++ java/net/sf/l2j/gameserver/network/clientpackets/Say2.java (working copy)
  154. @@ -22,6 +22,7 @@
  155. import net.sf.l2j.gameserver.handler.ChatHandler;
  156. import net.sf.l2j.gameserver.handler.IChatHandler;
  157. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  158. +import net.sf.l2j.gameserver.model.entity.LuckyChests;
  159. import net.sf.l2j.gameserver.network.SystemMessageId;
  160. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  161. import net.sf.l2j.gameserver.util.IllegalPlayerAction;
  162. @@ -141,6 +142,7 @@
  163. return;
  164. }
  165.  
  166. +
  167. if (_text.isEmpty())
  168. {
  169. _log.warning(activeChar.getName() + ": sending empty text. Possible packet hack.");
  170. Index: config/events.properties
  171. ===================================================================
  172. --- config/events.properties (revision 1)
  173. +++ config/events.properties (working copy)
  174. @@ -251,4 +251,12 @@
  175. AltFishChampionshipReward2 = 500000
  176. AltFishChampionshipReward3 = 300000
  177. AltFishChampionshipReward4 = 200000
  178. -AltFishChampionshipReward5 = 100000
  179. \ No newline at end of file
  180. +AltFishChampionshipReward5 = 100000
  181. +
  182. +#Lucky chests event
  183. +#Percent ( % ) rate to reward
  184. +LuckyChestRewardRate = 80
  185. +#Lucky chest rewards id and count
  186. +LuckyChestRewards = 57,100000000;
  187. +#Times
  188. +LuckyInterval = 16:00,17:00,16:45
  189. \ No newline at end of file
  190. Index: java/net/sf/l2j/gameserver/model/L2Spawn.java
  191. ===================================================================
  192. --- java/net/sf/l2j/gameserver/model/L2Spawn.java (revision 1)
  193. +++ java/net/sf/l2j/gameserver/model/L2Spawn.java (working copy)
  194. @@ -28,6 +28,7 @@
  195. import net.sf.l2j.gameserver.model.actor.L2Character;
  196. import net.sf.l2j.gameserver.model.actor.L2Npc;
  197. import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
  198. +import net.sf.l2j.gameserver.model.entity.LuckyChests;
  199. import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate;
  200. import net.sf.l2j.util.Rnd;
  201.  
  202. @@ -402,6 +403,8 @@
  203. // Reset decay info
  204. mob.setDecayed(false);
  205.  
  206. +
  207. +
  208. // Set the HP and MP of the L2Npc to the max
  209. mob.setCurrentHpMp(mob.getMaxHp(), mob.getMaxMp());
  210.  
  211. @@ -422,6 +425,8 @@
  212. ((L2Attackable) mob).setChampion(Rnd.get(100) < Config.CHAMPION_FREQUENCY);
  213. }
  214.  
  215. +
  216. +
  217. // Link the L2Npc to this L2Spawn
  218. mob.setSpawn(this);
  219.  
  220. Index: java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java
  221. ===================================================================
  222. --- java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java (revision 0)
  223. +++ java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java (revision 0)
  224. @@ -0,0 +1,61 @@
  225. +
  226. +package net.sf.l2j.gameserver.handler;
  227. +
  228. +import gnu.trove.map.hash.TIntObjectHashMap;
  229. +
  230. +import java.util.logging.Logger;
  231. +
  232. +import net.sf.l2j.Config;
  233. +import net.sf.l2j.gameserver.handler.voicedcommandhandlers.LuckyChestsCommand;
  234. +
  235. +public class VoicedCommandHandler
  236. +{
  237. + private static Logger _log = Logger.getLogger(ItemHandler.class.getName());
  238. +
  239. + private final TIntObjectHashMap<IVoicedCommandHandler> _datatable;
  240. +
  241. + public static VoicedCommandHandler getInstance()
  242. + {
  243. + return SingletonHolder._instance;
  244. + }
  245. +
  246. + protected VoicedCommandHandler()
  247. + {
  248. + _datatable = new TIntObjectHashMap<>();
  249. +
  250. + registerHandler(new LuckyChestsCommand());
  251. + }
  252. +
  253. + public void registerHandler(IVoicedCommandHandler handler)
  254. + {
  255. + String[] ids = handler.getVoicedCommandList();
  256. + for (int i = 0; i < ids.length; i++)
  257. + {
  258. + if (Config.DEBUG)
  259. + _log.fine("Adding handler for command " + ids[i]);
  260. + _datatable.put(ids[i].hashCode(), handler);
  261. + }
  262. + }
  263. +
  264. + public IVoicedCommandHandler getHandler(String voicedCommand)
  265. + {
  266. + String command = voicedCommand;
  267. + if (voicedCommand.indexOf(" ") != -1)
  268. + {
  269. + command = voicedCommand.substring(0, voicedCommand.indexOf(" "));
  270. + }
  271. + if (Config.DEBUG)
  272. + _log.fine("getting handler for command: " + command + " -> " + (_datatable.get(command.hashCode()) != null));
  273. + return _datatable.get(command.hashCode());
  274. + }
  275. +
  276. + public int size()
  277. + {
  278. + return _datatable.size();
  279. + }
  280. +
  281. + private static class SingletonHolder
  282. + {
  283. + protected static final VoicedCommandHandler _instance = new VoicedCommandHandler();
  284. + }
  285. +}
  286. \ No newline at end of file
  287. Index: java/net/sf/l2j/gameserver/model/actor/L2Npc.java
  288. ===================================================================
  289. --- java/net/sf/l2j/gameserver/model/actor/L2Npc.java (revision 1)
  290. +++ java/net/sf/l2j/gameserver/model/actor/L2Npc.java (working copy)
  291. @@ -55,6 +55,7 @@
  292. import net.sf.l2j.gameserver.model.actor.stat.NpcStat;
  293. import net.sf.l2j.gameserver.model.actor.status.NpcStatus;
  294. import net.sf.l2j.gameserver.model.entity.Castle;
  295. +import net.sf.l2j.gameserver.model.entity.LuckyChests;
  296. import net.sf.l2j.gameserver.model.quest.Quest;
  297. import net.sf.l2j.gameserver.model.quest.QuestEventType;
  298. import net.sf.l2j.gameserver.model.quest.QuestState;
  299. @@ -283,6 +284,8 @@
  300.  
  301. // Set the name of the L2Character
  302. setName(template.getName());
  303. +
  304. +
  305. }
  306.  
  307. @Override
  308. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminLuckyChest.java
  309. ===================================================================
  310. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminLuckyChest.java (revision 0)
  311. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminLuckyChest.java (revision 0)
  312. @@ -0,0 +1,50 @@
  313. +/*
  314. + * This program is free software: you can redistribute it and/or modify it under
  315. + * the terms of the GNU General Public License as published by the Free Software
  316. + * Foundation, either version 3 of the License, or (at your option) any later
  317. + * version.
  318. + *
  319. + * This program is distributed in the hope that it will be useful, but WITHOUT
  320. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  321. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  322. + * details.
  323. + *
  324. + * You should have received a copy of the GNU General Public License along with
  325. + * this program. If not, see <http://www.gnu.org/licenses/>.
  326. + */
  327. +package net.sf.l2j.gameserver.handler.admincommandhandlers;
  328. +
  329. +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  330. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  331. +import net.sf.l2j.gameserver.model.entity.LuckyChests;
  332. +
  333. +/**
  334. + * @author ponyrider && Thug
  335. + *
  336. + */
  337. +public class AdminLuckyChest implements IAdminCommandHandler
  338. +{
  339. +
  340. + private static final String[] ADMIN_COMMANDS =
  341. + {
  342. + "admin_start_lucky_chest",
  343. + };
  344. +
  345. + @Override
  346. + public boolean useAdminCommand(String command, L2PcInstance activeChar)
  347. + {
  348. + if(command.startsWith("admin_start_lucky_chest"))
  349. + {
  350. + LuckyChests.getInstance();
  351. + }
  352. +
  353. + return true;
  354. + }
  355. +
  356. + @Override
  357. + public String[] getAdminCommandList()
  358. + {
  359. + return ADMIN_COMMANDS;
  360. + }
  361. +
  362. +}
  363. Index: java/net/sf/l2j/gameserver/model/entity/LuckyChests.java
  364. ===================================================================
  365. --- java/net/sf/l2j/gameserver/model/entity/LuckyChests.java (revision 0)
  366. +++ java/net/sf/l2j/gameserver/model/entity/LuckyChests.java (revision 0)
  367. @@ -0,0 +1,348 @@
  368. +/*
  369. + * This program is free software: you can redistribute it and/or modify it under
  370. + * the terms of the GNU General Public License as published by the Free Software
  371. + * Foundation, either version 3 of the License, or (at your option) any later
  372. + * version.
  373. + *
  374. + * This program is distributed in the hope that it will be useful, but WITHOUT
  375. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  376. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  377. + * details.
  378. + *
  379. + * You should have received a copy of the GNU General Public License along with
  380. + * this program. If not, see <http://www.gnu.org/licenses/>.
  381. + */
  382. +package net.sf.l2j.gameserver.model.entity;
  383. +
  384. +
  385. +import java.util.List;
  386. +import java.util.concurrent.CopyOnWriteArrayList;
  387. +
  388. +import net.sf.l2j.Config;
  389. +import net.sf.l2j.gameserver.ThreadPoolManager;
  390. +import net.sf.l2j.gameserver.datatables.NpcTable;
  391. +import net.sf.l2j.gameserver.datatables.SpawnTable;
  392. +import net.sf.l2j.gameserver.model.L2Spawn;
  393. +import net.sf.l2j.gameserver.model.TaskScheduler;
  394. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  395. +import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate;
  396. +import net.sf.l2j.gameserver.util.Broadcast;
  397. +
  398. +/**
  399. + * @author ponyrider && Thug
  400. + *
  401. + */
  402. +public class LuckyChests
  403. +{
  404. + public int[][] SPAWN_LOCATIONS =
  405. + {
  406. + {-91386,150381,-3626},
  407. + {-91365,149653,-3626},
  408. + {-91354,149791,-3626},
  409. + {-91350,149923,-3626},
  410. + {-91344,150052,-3626},
  411. + {-91352,150177,-3626},
  412. + {-91333,150585,-3626},
  413. + {-91328,150670,-3626},
  414. + {-91327,150797,-3626},
  415. + {-91327,150922,-3626},
  416. + {-91212,150915,-3626},
  417. + {-91212,150795,-3626},
  418. + {-91216,150619,-3626},
  419. + {-91213,150492,-3626},
  420. + {-91212,150331,-3626},
  421. + {-91205,150184,-3626},
  422. + {-91202,150047,-3626},
  423. + {-91193,149914,-3626},
  424. + {-91193,149700,-3626},
  425. + {-91183,149503,-3626},
  426. + {-91047,149473,-3626},
  427. + {-91043,149667,-3626},
  428. + {-91025,149834,-3626},
  429. + {-91013,150020,-3626},
  430. + {-90995,150247,-3626},
  431. + {-90977,150491,-3626},
  432. + {-90962,150703,-3626},
  433. + {-90944,150890,-3626},
  434. + {-90856,150934,-3626},
  435. + {-90838,150715,-3626},
  436. + {-90826,150558,-3626},
  437. + {-90819,150417,-3626},
  438. + {-90815,150256,-3626},
  439. + {-90809,150087,-3626},
  440. + {-90815,149883,-3626},
  441. + {-90801,149674,-3626},
  442. + {-90768,149479,-3626},
  443. + {-90661,149390,-3626},
  444. + {-90621,149506,-3626},
  445. + {-90616,149696,-3626},
  446. + {-90611,149894,-3626},
  447. + {-90616,150083,-3626},
  448. + {-90615,150241,-3626},
  449. + {-90626,150410,-3626},
  450. + {-90641,150575,-3626},
  451. + {-90606,150738,-3626},
  452. + {-90539,150684,-3626},
  453. + {-90536,150513,-3626},
  454. + {-90516,150298,-3626},
  455. + {-90502,150088,-3626},
  456. + {-90498,149879,-3626},
  457. + {-90509,149624,-3626},
  458. +
  459. +
  460. +
  461. + };
  462. +
  463. + protected static List<L2PcInstance> players = new CopyOnWriteArrayList<>();
  464. + private static enum State {OFF,REGISTER,WAIT,ACTIVE};
  465. + public static State state = State.OFF;
  466. + private int MOB_COUNTER=1;
  467. +
  468. + public int getMobCounter()
  469. + {
  470. + return MOB_COUNTER;
  471. + }
  472. +
  473. + public void setMobCounter(int realCounter)
  474. + {
  475. + MOB_COUNTER = realCounter;
  476. + }
  477. +
  478. + public void increaseMobCounter()
  479. + {
  480. + MOB_COUNTER++;
  481. + }
  482. +
  483. + public List<L2PcInstance> getPlayers()
  484. + {
  485. + return players;
  486. + }
  487. +
  488. + public LuckyChests()
  489. + {
  490. + TaskScheduler.scheduleTask(new Runnable()
  491. + {
  492. + @Override
  493. + public void run()
  494. + {
  495. + if(state != State.OFF)
  496. + return;
  497. + Broadcast.announceToOnlinePlayers("Lucky Chests event registrations are opened.");
  498. + Broadcast.announceToOnlinePlayers("Registrations will close in 4 minutes.");
  499. + Broadcast.announceToOnlinePlayers("Press .join_lucky to register or .leave_lucky to leave the event.");
  500. + openRegistrations();
  501. + }
  502. + }, Config.LUCKY_CHEST_INTERVAL.toString());
  503. + }
  504. +
  505. +
  506. +
  507. +
  508. + public void openRegistrations()
  509. + {
  510. + state = State.REGISTER;
  511. + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  512. + {
  513. + @Override
  514. + public void run()
  515. + {
  516. + Broadcast.announceToOnlinePlayers("Registrations of Lucky Chests event will close in 3 minutes.");
  517. + Broadcast.announceToOnlinePlayers("Press .join_lucky to register or .leave_lucky to leave the event.");
  518. + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  519. + {
  520. + @Override
  521. + public void run()
  522. + {
  523. + Broadcast.announceToOnlinePlayers("Registrations of Lucky Chests event will close in 2 minutes.");
  524. + Broadcast.announceToOnlinePlayers("Press .join_lucky to register or .leave_lucky to leave the event.");
  525. + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  526. + {
  527. + @Override
  528. + public void run()
  529. + {
  530. + Broadcast.announceToOnlinePlayers("Registrations of Lucky Chests event will close in 1 minutes.");
  531. + Broadcast.announceToOnlinePlayers("Press .join_lucky to register or .leave_lucky to leave the event.");
  532. + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  533. + {
  534. + @Override
  535. + public void run()
  536. + {
  537. + Broadcast.announceToOnlinePlayers("Registrations of Lucky Chests just closed!");
  538. + Broadcast.announceToOnlinePlayers("Registed players will be teleported in 10 seconds!");
  539. + closeRegistrations();
  540. + }
  541. + }, 60000);
  542. + }
  543. + }, 60000);
  544. + }
  545. + }, 60000);
  546. + }
  547. + }, 60000);
  548. + }
  549. +
  550. + public void closeRegistrations()
  551. + {
  552. + state = State.WAIT;
  553. + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  554. + {
  555. + @Override
  556. + public void run()
  557. + {
  558. + for(L2PcInstance player : players)
  559. + {
  560. + if(player == null) continue;
  561. +
  562. + player.teleToLocation(-91474, 150512, -3626, 0);
  563. + player.sendMessage("You are now being teleported in event area!");
  564. + player.sendMessage("Lucky chests will be spawned in some seconds!");
  565. + }
  566. + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  567. + {
  568. + @Override
  569. + public void run()
  570. + {
  571. + runEvent();
  572. + }
  573. + }, 8000);
  574. +
  575. + }
  576. + }, 10000);
  577. + }
  578. +
  579. + public boolean registerPlayer(L2PcInstance player)
  580. + {
  581. + if(state != State.REGISTER)
  582. + {
  583. + if(state == State.OFF)
  584. + player.sendMessage("Event is not active");
  585. + else
  586. + player.sendMessage("Event is already active, registrations are closed");
  587. +
  588. + return false;
  589. + }
  590. + if(players.contains(player))
  591. + {
  592. + player.sendMessage("You have been already registed in event");
  593. + return false;
  594. + }
  595. +
  596. + players.add(player);
  597. + player.sendMessage("You successfully registed to Lucky Crests!");
  598. + return true;
  599. + }
  600. +
  601. + public boolean unregisterPlayer(L2PcInstance player)
  602. + {
  603. + if(state != State.REGISTER)
  604. + {
  605. + if(state == State.OFF)
  606. + player.sendMessage("Event is not active");
  607. + else
  608. + player.sendMessage("Event is already active, registrations are closed");
  609. +
  610. + return false;
  611. + }
  612. + if(!players.contains(player))
  613. + {
  614. + player.sendMessage("You haven't even registed to event");
  615. + return false;
  616. + }
  617. +
  618. + players.remove(player);
  619. + player.sendMessage("You successfully unregisted from Lucky Crests!");
  620. + return true;
  621. + }
  622. +
  623. + public void runEvent()
  624. + {
  625. + state = State.ACTIVE;
  626. + Broadcast.announceToOnlinePlayers("Lucky Chests event started!");
  627. + for(int[] spawnLoc : SPAWN_LOCATIONS)
  628. + {
  629. + int x = spawnLoc[0];
  630. + int y = spawnLoc[1];
  631. + int z = spawnLoc[2];
  632. + L2NpcTemplate template;
  633. + template = NpcTable.getInstance().getTemplate(55520);
  634. + try
  635. + {
  636. + final L2Spawn spawn = new L2Spawn(template);
  637. + spawn.setLocx(x);
  638. + spawn.setLocy(y);
  639. + spawn.setLocz(z);
  640. + spawn.setHeading(0);
  641. + spawn.setRespawnDelay(8);
  642. + SpawnTable.getInstance().addNewSpawn(spawn, false);
  643. + spawn.init();
  644. +
  645. +
  646. +
  647. + }
  648. + catch(Exception e)
  649. + {
  650. + Broadcast.announceToOnlinePlayers("There was a problem spawning lucky chests , sorry event cancelled.");
  651. + state = State.OFF;
  652. + }
  653. + }
  654. +
  655. + for(L2PcInstance player : players)
  656. + {
  657. + if(player == null) continue;
  658. + player.sendMessage("Lucky chests spawned! Start talking them!");
  659. + player.sendMessage("Event will end in 1 minutes!");
  660. + }
  661. +
  662. + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  663. + {
  664. + @Override
  665. + public void run()
  666. + {
  667. + stopEvent();
  668. + }
  669. + }, 120000);
  670. +
  671. +
  672. + }
  673. +
  674. + public void stopEvent()
  675. + {
  676. + state = State.OFF;
  677. +
  678. + for(L2PcInstance player : players)
  679. + {
  680. + if(player == null) continue;
  681. +
  682. + player.sendMessage("Event ended!");
  683. + player.teleToLocation(82840, 148639, -3474, 0);
  684. + players.remove(player);
  685. + }
  686. +
  687. + Broadcast.announceToOnlinePlayers("Lucky Chests event ended!");
  688. +
  689. +
  690. + }
  691. +
  692. + public static LuckyChests getInstance()
  693. + {
  694. + return SingletonHolder._instance;
  695. + }
  696. +
  697. + private static class SingletonHolder
  698. + {
  699. + protected static final LuckyChests _instance = new LuckyChests();
  700. + }
  701. +
  702. + public void checkIfLogout(L2PcInstance player)
  703. + {
  704. + if(players.contains(player))
  705. + players.remove(player);
  706. + }
  707. +
  708. + public boolean canAct(L2PcInstance player)
  709. + {
  710. + if(players.contains(player))
  711. + return false;
  712. +
  713. + return true;
  714. + }
  715. +}
  716. Index: java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java
  717. ===================================================================
  718. --- java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java (revision 1)
  719. +++ java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java (working copy)
  720. @@ -14,7 +14,11 @@
  721. */
  722. package net.sf.l2j.gameserver.handler.chathandlers;
  723.  
  724. +import java.util.StringTokenizer;
  725. +
  726. import net.sf.l2j.gameserver.handler.IChatHandler;
  727. +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  728. +import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
  729. import net.sf.l2j.gameserver.model.BlockList;
  730. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  731. import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  732. @@ -37,15 +41,43 @@
  733. @Override
  734. public void handleChat(int type, L2PcInstance activeChar, String params, String text)
  735. {
  736. - CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
  737. + boolean vcd_used = false;
  738. + if (text.startsWith("."))
  739. + {
  740. + StringTokenizer st = new StringTokenizer(text);
  741. + IVoicedCommandHandler vch;
  742. + String command = "";
  743.  
  744. - for (L2PcInstance player : activeChar.getKnownList().getKnownTypeInRadius(L2PcInstance.class, 1250))
  745. - {
  746. - if (!BlockList.isBlocked(player, activeChar))
  747. - player.sendPacket(cs);
  748. - }
  749. -
  750. - activeChar.sendPacket(cs);
  751. + if (st.countTokens() > 1)
  752. + {
  753. + command = st.nextToken().substring(1);
  754. + params = text.substring(command.length() + 2);
  755. + vch = VoicedCommandHandler.getInstance().getHandler(command);
  756. + }
  757. + else
  758. + {
  759. + command = text.substring(1);
  760. + vch = VoicedCommandHandler.getInstance().getHandler(command);
  761. + }
  762. +
  763. + if (vch != null)
  764. + {
  765. + vch.useVoicedCommand(command, activeChar, params);
  766. + vcd_used = true;
  767. + }
  768. + }
  769. + if (!vcd_used)
  770. + {
  771. + CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
  772. +
  773. + for (L2PcInstance player : activeChar.getKnownList().getKnownType(L2PcInstance.class))
  774. + {
  775. + if (activeChar.isInsideRadius(player, 1250, false, true) && !BlockList.isBlocked(player, activeChar))
  776. + player.sendPacket(cs);
  777. + }
  778. +
  779. + activeChar.sendPacket(cs);
  780. + }
  781. }
  782.  
  783. /**
  784. Index: java/net/sf/l2j/gameserver/GameServer.java
  785. ===================================================================
  786. --- java/net/sf/l2j/gameserver/GameServer.java (revision 1)
  787. +++ java/net/sf/l2j/gameserver/GameServer.java (working copy)
  788. @@ -24,7 +24,8 @@
  789. import java.util.logging.Level;
  790. import java.util.logging.LogManager;
  791. import java.util.logging.Logger;
  792. -
  793. +import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
  794. +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  795. import net.sf.l2j.Config;
  796. import net.sf.l2j.L2DatabaseFactory;
  797. import net.sf.l2j.Server;
  798. @@ -92,6 +93,7 @@
  799. import net.sf.l2j.gameserver.model.PartyMatchWaitingList;
  800. import net.sf.l2j.gameserver.model.entity.Castle;
  801. import net.sf.l2j.gameserver.model.entity.Hero;
  802. +import net.sf.l2j.gameserver.model.entity.LuckyChests;
  803. import net.sf.l2j.gameserver.model.olympiad.Olympiad;
  804. import net.sf.l2j.gameserver.model.olympiad.OlympiadGameManager;
  805. import net.sf.l2j.gameserver.network.L2GameClient;
  806. @@ -158,6 +160,7 @@
  807. ArmorSetsTable.getInstance();
  808. FishTable.getInstance();
  809. SpellbookTable.getInstance();
  810. + LuckyChests.getInstance();
  811.  
  812. Util.printSection("Augments");
  813. AugmentationData.getInstance();
  814. @@ -275,7 +278,7 @@
  815. _log.config("ItemHandler: Loaded " + ItemHandler.getInstance().size() + " handlers.");
  816. _log.config("SkillHandler: Loaded " + SkillHandler.getInstance().size() + " handlers.");
  817. _log.config("UserCommandHandler: Loaded " + UserCommandHandler.getInstance().size() + " handlers.");
  818. -
  819. + _log.config("VoicedCommandHandler: Loaded " + VoicedCommandHandler.getInstance().size() + " handlers.");
  820. if (Config.ALLOW_WEDDING)
  821. CoupleManager.getInstance();
  822.  
  823. Index: java/net/sf/l2j/gameserver/model/TaskScheduler.java
  824. ===================================================================
  825. --- java/net/sf/l2j/gameserver/model/TaskScheduler.java (revision 0)
  826. +++ java/net/sf/l2j/gameserver/model/TaskScheduler.java (revision 0)
  827. @@ -0,0 +1,84 @@
  828. +package net.sf.l2j.gameserver.model;
  829. +
  830. +import java.util.Calendar;
  831. +
  832. +import net.sf.l2j.gameserver.ThreadPoolManager;
  833. +
  834. +
  835. +
  836. +public class TaskScheduler
  837. +
  838. +{
  839. +
  840. + public static void scheduleTask(final Runnable task, final String times)
  841. + {
  842. +
  843. + Calendar cld = Calendar.getInstance();
  844. +
  845. +
  846. +
  847. + String[] times_splitted = times.split(";");
  848. +
  849. +
  850. +
  851. + int i = times_splitted.length;
  852. +
  853. +
  854. +
  855. + for (String time : times_splitted)
  856. +
  857. + {
  858. +
  859. + String[] time_splitted = time.split(":");
  860. +
  861. +
  862. +
  863. + int hour = Integer.parseInt(time_splitted[0]), minutes = Integer.parseInt(time_splitted[1]);
  864. + cld.set(Calendar.HOUR_OF_DAY, hour);
  865. +
  866. + cld.set(Calendar.MINUTE, minutes);
  867. +
  868. + cld.set(Calendar.SECOND, 0);
  869. +
  870. +
  871. +
  872. + if (System.currentTimeMillis() > cld.getTimeInMillis())
  873. + {
  874. + cld.set(Calendar.DAY_OF_MONTH, cld.get(Calendar.DAY_OF_MONTH)+1);
  875. + cld.set(Calendar.HOUR_OF_DAY, hour);
  876. + cld.set(Calendar.MINUTE, minutes);
  877. + cld.set(Calendar.SECOND, 0);
  878. + }
  879. +
  880. + ThreadPoolManager.getInstance().scheduleGeneral(task, cld.getTimeInMillis()-System.currentTimeMillis());
  881. + i--;
  882. +
  883. +
  884. +
  885. + if (i == 0)
  886. +
  887. + {
  888. +
  889. + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  890. +
  891. + {
  892. +
  893. + @Override
  894. +
  895. + public void run()
  896. +
  897. + {
  898. +
  899. + scheduleTask(task, times);
  900. +
  901. + }
  902. +
  903. + }, cld.getTimeInMillis()-System.currentTimeMillis());
  904. +
  905. + }
  906. +
  907. + }
  908. +
  909. + }
  910. +
  911. +}
  912. \ No newline at end of file
  913. Index: java/net/sf/l2j/gameserver/network/clientpackets/AttackRequest.java
  914. ===================================================================
  915. --- java/net/sf/l2j/gameserver/network/clientpackets/AttackRequest.java (revision 1)
  916. +++ java/net/sf/l2j/gameserver/network/clientpackets/AttackRequest.java (working copy)
  917. @@ -17,6 +17,7 @@
  918. import net.sf.l2j.gameserver.model.L2Object;
  919. import net.sf.l2j.gameserver.model.L2World;
  920. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  921. +import net.sf.l2j.gameserver.model.entity.LuckyChests;
  922. import net.sf.l2j.gameserver.network.SystemMessageId;
  923. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  924.  
  925. @@ -53,6 +54,7 @@
  926. return;
  927. }
  928.  
  929. +
  930. // avoid using expensive operations if not needed
  931. final L2Object target;
  932. if (activeChar.getTargetId() == _objectId)
  933. @@ -63,6 +65,10 @@
  934. if (target == null)
  935. return;
  936.  
  937. +
  938. + if(!LuckyChests.getInstance().canAct(activeChar) || LuckyChests.getInstance().getPlayers().contains(target))
  939. + return;
  940. +
  941. if (activeChar.getTarget() != target)
  942. target.onAction(activeChar);
  943. else
  944. Index: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  945. ===================================================================
  946. --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 1)
  947. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (working copy)
  948. @@ -126,6 +126,7 @@
  949. import net.sf.l2j.gameserver.model.entity.Castle;
  950. import net.sf.l2j.gameserver.model.entity.Duel;
  951. import net.sf.l2j.gameserver.model.entity.Hero;
  952. +import net.sf.l2j.gameserver.model.entity.LuckyChests;
  953. import net.sf.l2j.gameserver.model.entity.Siege;
  954. import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
  955. import net.sf.l2j.gameserver.model.itemcontainer.ItemContainer;
  956. @@ -9272,6 +9273,7 @@
  957. @Override
  958. public void deleteMe()
  959. {
  960. + LuckyChests.getInstance().checkIfLogout(this);
  961. cleanup();
  962. store();
  963. super.deleteMe();
  964. Index: java/net/sf/l2j/Config.java
  965. ===================================================================
  966. --- java/net/sf/l2j/Config.java (revision 1)
  967. +++ java/net/sf/l2j/Config.java (working copy)
  968. @@ -225,6 +225,10 @@
  969. public static int ALT_FISH_CHAMPIONSHIP_REWARD_4;
  970. public static int ALT_FISH_CHAMPIONSHIP_REWARD_5;
  971.  
  972. + public static int LUCKY_CHEST_REWARD_RATE;
  973. + public static int[][] LUCKY_CHEST_REWARDS;
  974. + public static String LUCKY_CHEST_INTERVAL;
  975. +
  976. // --------------------------------------------------
  977. // HexID
  978. // --------------------------------------------------
  979. @@ -870,6 +874,10 @@
  980. ALT_FISH_CHAMPIONSHIP_REWARD_4 = events.getProperty("AltFishChampionshipReward4", 200000);
  981. ALT_FISH_CHAMPIONSHIP_REWARD_5 = events.getProperty("AltFishChampionshipReward5", 100000);
  982.  
  983. + LUCKY_CHEST_REWARD_RATE = events.getProperty("LuckyChestRewardRate",70);
  984. + LUCKY_CHEST_REWARDS = parseItemsList(events.getProperty("LuckyChestRewards", "57,100000000;"));
  985. + LUCKY_CHEST_INTERVAL = events.getProperty("LuckyInterval","16:00,17:00,16:45");
  986. +
  987. // FloodProtector
  988. ExProperties security = load(FLOOD_PROTECTOR_FILE);
  989. loadFloodProtectorConfig(security, FLOOD_PROTECTOR_ROLL_DICE, "RollDice", "42");
  990. Index: java/net/sf/l2j/gameserver/model/actor/knownlist/CharKnownList.java
  991. ===================================================================
  992. --- java/net/sf/l2j/gameserver/model/actor/knownlist/CharKnownList.java (revision 1)
  993. +++ java/net/sf/l2j/gameserver/model/actor/knownlist/CharKnownList.java (working copy)
  994. @@ -14,8 +14,11 @@
  995. */
  996. package net.sf.l2j.gameserver.model.actor.knownlist;
  997.  
  998. +import java.util.Collection;
  999. +
  1000. import net.sf.l2j.gameserver.model.L2Object;
  1001. import net.sf.l2j.gameserver.model.actor.L2Character;
  1002. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1003.  
  1004. public class CharKnownList extends ObjectKnownList
  1005. {
  1006. @@ -38,6 +41,7 @@
  1007. getActiveChar().setAI(null);
  1008. }
  1009.  
  1010. +
  1011. @Override
  1012. public boolean removeKnownObject(L2Object object)
  1013. {
  1014. Index: java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/LuckyChestsCommand.java
  1015. ===================================================================
  1016. --- java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/LuckyChestsCommand.java (revision 0)
  1017. +++ java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/LuckyChestsCommand.java (revision 0)
  1018. @@ -0,0 +1,56 @@
  1019. +/*
  1020. + * This program is free software: you can redistribute it and/or modify it under
  1021. + * the terms of the GNU General Public License as published by the Free Software
  1022. + * Foundation, either version 3 of the License, or (at your option) any later
  1023. + * version.
  1024. + *
  1025. + * This program is distributed in the hope that it will be useful, but WITHOUT
  1026. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1027. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1028. + * details.
  1029. + *
  1030. + * You should have received a copy of the GNU General Public License along with
  1031. + * this program. If not, see <http://www.gnu.org/licenses/>.
  1032. + */
  1033. +package net.sf.l2j.gameserver.handler.voicedcommandhandlers;
  1034. +
  1035. +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  1036. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1037. +import net.sf.l2j.gameserver.model.entity.LuckyChests;
  1038. +
  1039. +/**
  1040. + * @author ponyrider && Thug
  1041. + *
  1042. + */
  1043. +public class LuckyChestsCommand implements IVoicedCommandHandler
  1044. +{
  1045. +
  1046. + private static final String VOICED_COMMANDS[] =
  1047. + {
  1048. + "join_lucky",
  1049. + "leave_lucky"
  1050. + };
  1051. +
  1052. +
  1053. + @Override
  1054. + public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
  1055. + {
  1056. + if(command.startsWith(VOICED_COMMANDS[0]))
  1057. + {
  1058. + LuckyChests.getInstance().registerPlayer(activeChar);
  1059. + }
  1060. + else if(command.startsWith(VOICED_COMMANDS[1]))
  1061. + {
  1062. + LuckyChests.getInstance().unregisterPlayer(activeChar);
  1063. + }
  1064. +
  1065. + return true;
  1066. + }
  1067. +
  1068. + @Override
  1069. + public String[] getVoicedCommandList()
  1070. + {
  1071. + return VOICED_COMMANDS;
  1072. + }
  1073. +
  1074. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement