warc222

Random Fight v2 author PonyRider

Sep 29th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.12 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/net/sf/l2j/gameserver/network/clientpackets/Logout.java
  4. ===================================================================
  5. --- java/net/sf/l2j/gameserver/network/clientpackets/Logout.java (revision 1)
  6. +++ java/net/sf/l2j/gameserver/network/clientpackets/Logout.java (working copy)
  7. @@ -17,6 +17,7 @@
  8. import net.sf.l2j.Config;
  9. import net.sf.l2j.gameserver.SevenSignsFestival;
  10. import net.sf.l2j.gameserver.model.L2Party;
  11. +import net.sf.l2j.gameserver.model.RandomFight;
  12. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  13. import net.sf.l2j.gameserver.model.zone.ZoneId;
  14. import net.sf.l2j.gameserver.network.SystemMessageId;
  15. @@ -60,6 +61,13 @@
  16. return;
  17. }
  18.  
  19. + if(RandomFight.players.contains(player))
  20. + {
  21. + player.sendMessage("You can't logout when you are in random fight event.");
  22. + player.sendPacket(ActionFailed.STATIC_PACKET);
  23. + return;
  24. + }
  25. +
  26. if (AttackStanceTaskManager.getInstance().getAttackStanceTask(player) && !player.isGM())
  27. {
  28. if (Config.DEBUG)
  29. Index: config/players.properties
  30. ===================================================================
  31. --- config/players.properties (revision 1)
  32. +++ config/players.properties (working copy)
  33. @@ -45,6 +45,15 @@
  34. # Death Penalty chance if killed by mob (in %), 20 by default
  35. DeathPenaltyChance = 20
  36.  
  37. +#Random Fight Event
  38. +AllowRandomFight = True
  39. +#Random Fight every how many minutes
  40. +EveryMinutes = 3
  41. +#ID of the reward Item , default:LIFE STONES
  42. +RewardId=8762
  43. +#COUNT of the reward item : default : 5
  44. +RewardCount = 5
  45. +
  46. #=============================================================
  47. # Inventory / Warehouse
  48. #=============================================================
  49. Index: java/net/sf/l2j/gameserver/GameServer.java
  50. ===================================================================
  51. --- java/net/sf/l2j/gameserver/GameServer.java (revision 1)
  52. +++ java/net/sf/l2j/gameserver/GameServer.java (working copy)
  53. @@ -90,6 +90,7 @@
  54. import net.sf.l2j.gameserver.model.L2World;
  55. import net.sf.l2j.gameserver.model.PartyMatchRoomList;
  56. import net.sf.l2j.gameserver.model.PartyMatchWaitingList;
  57. +import net.sf.l2j.gameserver.model.RandomFight;
  58. import net.sf.l2j.gameserver.model.entity.Castle;
  59. import net.sf.l2j.gameserver.model.entity.Hero;
  60. import net.sf.l2j.gameserver.model.olympiad.Olympiad;
  61. @@ -237,6 +238,9 @@
  62. Olympiad.getInstance();
  63. Hero.getInstance();
  64.  
  65. + if(Config.ALLOW_RANDOM_FIGHT)
  66. + RandomFight.getInstance();
  67. +
  68. Util.printSection("Four Sepulchers");
  69. FourSepulchersManager.getInstance().init();
  70.  
  71. Index: java/net/sf/l2j/gameserver/network/clientpackets/Say2.java
  72. ===================================================================
  73. --- java/net/sf/l2j/gameserver/network/clientpackets/Say2.java (revision 1)
  74. +++ java/net/sf/l2j/gameserver/network/clientpackets/Say2.java (working copy)
  75. @@ -21,6 +21,7 @@
  76. import net.sf.l2j.Config;
  77. import net.sf.l2j.gameserver.handler.ChatHandler;
  78. import net.sf.l2j.gameserver.handler.IChatHandler;
  79. +import net.sf.l2j.gameserver.model.RandomFight;
  80. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  81. import net.sf.l2j.gameserver.network.SystemMessageId;
  82. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  83. @@ -171,6 +172,10 @@
  84. return;
  85. }
  86.  
  87. + checkRandomFight(_text,activeChar);
  88. + if(_text.equalsIgnoreCase("?register") || _text.equalsIgnoreCase("?unregister"))
  89. + return;
  90. +
  91. if (_type == PETITION_PLAYER && activeChar.isGM())
  92. _type = PETITION_GM;
  93.  
  94. @@ -214,6 +219,45 @@
  95. return false;
  96. }
  97.  
  98. + void checkRandomFight(String text,L2PcInstance player)
  99. + {
  100. + if(text.equalsIgnoreCase("?register"))
  101. + {
  102. + if(RandomFight.players.contains(player))
  103. + {
  104. + player.sendMessage("You have already registed to the event.");
  105. + return;
  106. + }
  107. + if(RandomFight.state == RandomFight.State.INACTIVE)
  108. + return;
  109. + if(RandomFight.state != RandomFight.State.REGISTER)
  110. + {
  111. + player.sendMessage("Event has already started.");
  112. + return;
  113. + }
  114. + RandomFight.players.add(player);
  115. + player.sendMessage("You registed to the event!!");
  116. + return;
  117. + }
  118. + if(text.equalsIgnoreCase("?unregister"))
  119. + {
  120. + if(!RandomFight.players.contains(player))
  121. + {
  122. + player.sendMessage("You haven't registed to the event.");
  123. + return;
  124. + }
  125. + if(RandomFight.state == RandomFight.State.INACTIVE)
  126. + return;
  127. + if(RandomFight.state != RandomFight.State.REGISTER)
  128. + {
  129. + player.sendMessage("Event has already started.");
  130. + return;
  131. + }
  132. + RandomFight.players.remove(player);
  133. + player.sendMessage("You unregisted from the event!!");
  134. + }
  135. + }
  136. +
  137. @Override
  138. protected boolean triggersOnActionRequest()
  139. {
  140. Index: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  141. ===================================================================
  142. --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 1)
  143. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (working copy)
  144. @@ -37,6 +37,7 @@
  145.  
  146. import net.sf.l2j.Config;
  147. import net.sf.l2j.L2DatabaseFactory;
  148. +import net.sf.l2j.gameserver.Announcements;
  149. import net.sf.l2j.gameserver.GameTimeController;
  150. import net.sf.l2j.gameserver.GeoData;
  151. import net.sf.l2j.gameserver.ItemsAutoDestroy;
  152. @@ -103,6 +104,7 @@
  153. import net.sf.l2j.gameserver.model.PartyMatchRoom;
  154. import net.sf.l2j.gameserver.model.PartyMatchRoomList;
  155. import net.sf.l2j.gameserver.model.PartyMatchWaitingList;
  156. +import net.sf.l2j.gameserver.model.RandomFight;
  157. import net.sf.l2j.gameserver.model.ShortCuts;
  158. import net.sf.l2j.gameserver.model.ShotType;
  159. import net.sf.l2j.gameserver.model.TradeList;
  160. @@ -4077,6 +4079,19 @@
  161. {
  162. L2PcInstance pk = killer.getActingPlayer();
  163.  
  164. + if(RandomFight.state == RandomFight.State.FIGHT)
  165. + {
  166. + if(RandomFight.players.contains(this) && RandomFight.players.contains(pk))
  167. + {
  168. + pk.sendMessage("You are the winner!!!");
  169. + Announcements.announceToAll("Random Fight Results:"+pk.getName()+" is the winner.");
  170. + Announcements.announceToAll("Event Ended.");
  171. + pk.addItem("",Config.RANDOM_FIGHT_REWARD_ID, Config.RANDOM_FIGHT_REWARD_COUNT, null, true);
  172. + RandomFight.revert();
  173. + RandomFight.clean();
  174. + }
  175. + }
  176. +
  177. // Clear resurrect xp calculation
  178. setExpBeforeDeath(0);
  179.  
  180. Index: java/net/sf/l2j/Config.java
  181. ===================================================================
  182. --- java/net/sf/l2j/Config.java (revision 1)
  183. +++ java/net/sf/l2j/Config.java (working copy)
  184. @@ -383,6 +383,11 @@
  185. public static boolean ALT_GAME_DELEVEL;
  186. public static int DEATH_PENALTY_CHANCE;
  187.  
  188. + public static boolean ALLOW_RANDOM_FIGHT;
  189. + public static int EVERY_MINUTES;
  190. + public static int RANDOM_FIGHT_REWARD_ID;
  191. + public static int RANDOM_FIGHT_REWARD_COUNT;
  192. +
  193. /** Inventory & WH */
  194. public static int INVENTORY_MAXIMUM_NO_DWARF;
  195. public static int INVENTORY_MAXIMUM_DWARF;
  196. @@ -987,6 +992,12 @@
  197. ALT_GAME_DELEVEL = players.getProperty("Delevel", true);
  198. DEATH_PENALTY_CHANCE = players.getProperty("DeathPenaltyChance", 20);
  199.  
  200. + ALLOW_RANDOM_FIGHT = players.getProperty("AllowRandomFight",true);
  201. + EVERY_MINUTES = players.getProperty("EveryMinutes",3);
  202. + RANDOM_FIGHT_REWARD_ID = players.getProperty("RewardId" , 8762);
  203. + RANDOM_FIGHT_REWARD_COUNT = players.getProperty("RewardCount" , 5);
  204. +
  205. +
  206. INVENTORY_MAXIMUM_NO_DWARF = players.getProperty("MaximumSlotsForNoDwarf", 80);
  207. INVENTORY_MAXIMUM_DWARF = players.getProperty("MaximumSlotsForDwarf", 100);
  208. INVENTORY_MAXIMUM_QUEST_ITEMS = players.getProperty("MaximumSlotsForQuestItems", 100);
  209. Index: java/net/sf/l2j/gameserver/model/RandomFight.java
  210. ===================================================================
  211. --- java/net/sf/l2j/gameserver/model/RandomFight.java (revision 0)
  212. +++ java/net/sf/l2j/gameserver/model/RandomFight.java (revision 0)
  213. @@ -0,0 +1,273 @@
  214. +/*
  215. + * This program is free software: you can redistribute it and/or modify it under
  216. + * the terms of the GNU General Public License as published by the Free Software
  217. + * Foundation, either version 3 of the License, or (at your option) any later
  218. + * version.
  219. + *
  220. + * This program is distributed in the hope that it will be useful, but WITHOUT
  221. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  222. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  223. + * details.
  224. + *
  225. + * You should have received a copy of the GNU General Public License along with
  226. + * this program. If not, see <http://www.gnu.org/licenses/>.
  227. + */
  228. +package net.sf.l2j.gameserver.model;
  229. +
  230. +import java.util.Vector;
  231. +
  232. +import net.sf.l2j.Config;
  233. +import net.sf.l2j.gameserver.ThreadPoolManager;
  234. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  235. +import net.sf.l2j.gameserver.model.olympiad.OlympiadManager;
  236. +import net.sf.l2j.gameserver.util.Broadcast;
  237. +import net.sf.l2j.util.Rnd;
  238. +
  239. +/**
  240. + * @author lioy
  241. + *
  242. + */
  243. +public class RandomFight
  244. +{
  245. + public static enum State{INACTIVE,REGISTER,LOADING,FIGHT}
  246. + public static State state = State.INACTIVE;
  247. +
  248. + public static Vector<L2PcInstance> players = new Vector<>();
  249. +
  250. + protected void openRegistrations()
  251. + {
  252. + state = State.REGISTER;
  253. + Broadcast.announceToOnlinePlayers("Random Fight Event will start in 1 minute.");
  254. + Broadcast.announceToOnlinePlayers("To register press ?register");
  255. + ThreadPoolManager.getInstance().scheduleGeneral(new checkRegist(), 60000 );
  256. + }
  257. +
  258. + protected void checkRegistrations()
  259. + {
  260. + state=State.LOADING;
  261. +
  262. + if(players.isEmpty() || players.size() < 2)
  263. + {
  264. + Broadcast.announceToOnlinePlayers("Random Fight Event will not start cause of no many partitipations, we are sorry.");
  265. + clean();
  266. + return;
  267. + }
  268. + Broadcast.announceToOnlinePlayers("Amount of players Registed: "+players.size());
  269. + Broadcast.announceToOnlinePlayers("2 Random players will be choosen in 30 seconds!");
  270. + ThreadPoolManager.getInstance().scheduleGeneral(new pickPlayers(), 30000 );
  271. + }
  272. +
  273. +
  274. + protected void pickPlayers()
  275. + {
  276. + if(players.isEmpty() || players.size() < 2)
  277. + {
  278. + Broadcast.announceToOnlinePlayers("Random Fight Event aborted because no many partitipations, we are sorry.");
  279. + clean();
  280. + return;
  281. + }
  282. +
  283. + for(L2PcInstance p : players)
  284. + if(p.isInOlympiadMode() || OlympiadManager.getInstance().isRegistered(p))
  285. + {
  286. + players.remove(p);
  287. + p.sendMessage("You automatically left from event because of your olympiad obligations.");
  288. + }
  289. +
  290. +
  291. + int rnd1=Rnd.get(players.size());
  292. + int rnd2=Rnd.get(players.size());
  293. +
  294. + while(rnd2==rnd1)
  295. + rnd2=Rnd.get(players.size());
  296. +
  297. + for(L2PcInstance player : players)
  298. + {
  299. + if(player != players.get(rnd1) && player != players.get(rnd2))
  300. + players.remove(player);
  301. + }
  302. +
  303. + Broadcast.announceToOnlinePlayers("Players selected: "+players.firstElement().getName()+" || "+players.lastElement().getName());
  304. + Broadcast.announceToOnlinePlayers("Players will be teleported in 15 seconds");
  305. + ThreadPoolManager.getInstance().scheduleGeneral(new teleportPlayers(), 15000);
  306. + }
  307. +
  308. +
  309. + protected void teleport()
  310. + {
  311. + if(players.isEmpty() || players.size() < 2)
  312. + {
  313. + Broadcast.announceToOnlinePlayers("Random Fight Event aborted because no many partitipations, we are sorry.");
  314. + clean();
  315. + return;
  316. + }
  317. + Broadcast.announceToOnlinePlayers("Players teleported!");
  318. +
  319. + players.firstElement().teleToLocation(113474,15552,3968,0);
  320. + players.lastElement().teleToLocation(112990,15489,3968,0);
  321. + players.firstElement().setTeam(1);
  322. + players.lastElement().setTeam(2);
  323. +
  324. + //para,etc
  325. +
  326. + players.firstElement().sendMessage("Fight will begin in 15 seconds!");
  327. + players.lastElement().sendMessage("Fight will begin in 15 seconds!");
  328. +
  329. + ThreadPoolManager.getInstance().scheduleGeneral(new fight(), 15000);
  330. + }
  331. +
  332. + protected void startFight()
  333. + {
  334. +
  335. + if(players.isEmpty() || players.size() < 2)
  336. + {
  337. + Broadcast.announceToOnlinePlayers("One of the players isn't online, event aborted we are sorry!");
  338. + clean();
  339. + return;
  340. + }
  341. +
  342. + state = State.FIGHT;
  343. + Broadcast.announceToOnlinePlayers("FIGHT STARTED!");
  344. + players.firstElement().sendMessage("Start Fight!!");
  345. + players.lastElement().sendMessage("Start Fight!");
  346. + ThreadPoolManager.getInstance().scheduleGeneral(new checkLast(), 120000 );
  347. + }
  348. +
  349. + protected void lastCheck()
  350. + {
  351. + if(state == State.FIGHT)
  352. + {
  353. + if(players.isEmpty() || players.size() < 2)
  354. + {
  355. + revert();
  356. + clean();
  357. + return;
  358. + }
  359. +
  360. + int alive=0;
  361. + for(L2PcInstance player : players)
  362. + {
  363. + if(!player.isDead())
  364. + alive++;
  365. + }
  366. +
  367. + if(alive==2)
  368. + {
  369. + Broadcast.announceToOnlinePlayers("Random Fight ended tie!");
  370. + clean();
  371. + revert();
  372. + }
  373. + }
  374. + }
  375. +
  376. + public static void revert()
  377. + {
  378. + if(!players.isEmpty())
  379. + for(L2PcInstance p : players)
  380. + {
  381. + if(p == null)
  382. + continue;
  383. +
  384. + if(p.isDead())
  385. + p.doRevive();
  386. +
  387. + p.setCurrentHp(p.getMaxHp());
  388. + p.setCurrentCp(p.getMaxCp());
  389. + p.setCurrentMp(p.getMaxMp());
  390. + p.broadcastUserInfo();
  391. + p.teleToLocation(82698,148638,-3473,0);
  392. +
  393. + }
  394. + }
  395. +
  396. + public static void clean()
  397. + {
  398. +
  399. + if(state == State.FIGHT)
  400. + for(L2PcInstance p : players)
  401. + p.setTeam(0);
  402. +
  403. +
  404. + players.clear();
  405. + state = State.INACTIVE;
  406. +
  407. + }
  408. +
  409. + protected RandomFight()
  410. + {
  411. + ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Event(), 60000 * Config.EVERY_MINUTES , 60000 * Config.EVERY_MINUTES);
  412. + }
  413. +
  414. + public static RandomFight getInstance()
  415. + {
  416. + return SingletonHolder._instance;
  417. + }
  418. +
  419. + private static class SingletonHolder
  420. + {
  421. + protected static final RandomFight _instance = new RandomFight();
  422. + }
  423. +
  424. + protected class Event implements Runnable
  425. + {
  426. + @Override
  427. + public void run()
  428. + {
  429. + if(state == State.INACTIVE)
  430. + openRegistrations();
  431. + }
  432. +
  433. + }
  434. +
  435. + protected class checkRegist implements Runnable
  436. + {
  437. +
  438. + @Override
  439. + public void run()
  440. + {
  441. + checkRegistrations();
  442. + }
  443. +
  444. + }
  445. +
  446. + protected class pickPlayers implements Runnable
  447. + {
  448. + @Override
  449. + public void run()
  450. + {
  451. + pickPlayers();
  452. + }
  453. +
  454. + }
  455. +
  456. + protected class teleportPlayers implements Runnable
  457. + {
  458. + @Override
  459. + public void run()
  460. + {
  461. + teleport();
  462. + }
  463. +
  464. + }
  465. +
  466. + protected class fight implements Runnable
  467. + {
  468. +
  469. + @Override
  470. + public void run()
  471. + {
  472. + startFight();
  473. + }
  474. +
  475. + }
  476. +
  477. + protected class checkLast implements Runnable
  478. + {
  479. + @Override
  480. + public void run()
  481. + {
  482. + lastCheck();
  483. + }
  484. +
  485. + }
  486. +}
  487. Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java
  488. ===================================================================
  489. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java (revision 1)
  490. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java (working copy)
  491. @@ -17,11 +17,13 @@
  492. import net.sf.l2j.Config;
  493. import net.sf.l2j.gameserver.SevenSignsFestival;
  494. import net.sf.l2j.gameserver.model.L2Party;
  495. +import net.sf.l2j.gameserver.model.RandomFight;
  496. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  497. import net.sf.l2j.gameserver.model.zone.ZoneId;
  498. import net.sf.l2j.gameserver.network.L2GameClient;
  499. import net.sf.l2j.gameserver.network.L2GameClient.GameClientState;
  500. import net.sf.l2j.gameserver.network.SystemMessageId;
  501. +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  502. import net.sf.l2j.gameserver.network.serverpackets.CharSelectInfo;
  503. import net.sf.l2j.gameserver.network.serverpackets.RestartResponse;
  504. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  505. @@ -66,6 +68,13 @@
  506. return;
  507. }
  508.  
  509. + if(RandomFight.players.contains(player))
  510. + {
  511. + player.sendMessage("You can't restart when you are in random fight event.");
  512. + player.sendPacket(ActionFailed.STATIC_PACKET);
  513. + return;
  514. + }
  515. +
  516. if (AttackStanceTaskManager.getInstance().getAttackStanceTask(player) && !player.isGM())
  517. {
  518. if (Config.DEBUG)
Add Comment
Please, Sign In to add comment