andreivoinea93

Untitled

May 22nd, 2012
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.14 KB | None | 0 0
  1. Index: D:/Workspace/wks/L2_GameServer/java/config/l2jmods.properties
  2. ===================================================================
  3. --- D:/Workspace/wks/L2_GameServer/java/config/l2jmods.properties (revision 3457)
  4. +++ D:/Workspace/wks/L2_GameServer/java/config/l2jmods.properties (working copy)
  5. @@ -248,4 +248,32 @@
  6. # This option will enable core support for:
  7. # Mana Drug (item ID 726), using skill ID 9007.
  8. # Mana Potion (item ID 728), using skill ID 9008.
  9. -EnableManaPotionSupport = False
  10. \ No newline at end of file
  11. +EnableManaPotionSupport = False
  12. +
  13. +# ---------------------------------------------------------------------------
  14. +# Town War. Use //tw_start and //tw_end to run or end it.
  15. +# This gonna spawn mobs in towns. That's pretty much all.
  16. +# Long life MaxCheaters ^^.
  17. +# Vago & team...
  18. +# ---------------------------------------------------------------------------
  19. +MonsterId = 0
  20. +MaxHp = 1000
  21. +MaxMp = 1000
  22. +DropId = 0
  23. +DropChance = 0
  24. +DropMax = 0
  25. +DropMin = 0
  26. Index: D:/Workspace/wks/L2_GameServer/java/net/sf/l2j/Config.java
  27. ===================================================================
  28. --- D:/Workspace/wks/L2_GameServer/java/net/sf/l2j/Config.java (revision 3457)
  29. +++ D:/Workspace/wks/L2_GameServer/java/net/sf/l2j/Config.java (working copy)
  30. @@ -501,8 +501,15 @@
  31. public static boolean CUSTOM_TELEPORT_TABLE;
  32. public static boolean CUSTOM_DROPLIST_TABLE;
  33. public static boolean CUSTOM_MERCHANT_TABLES;
  34. + public static int TW_MOB_ID;
  35. + public static int TW_MAX_HP;
  36. + public static int TW_MAX_MP;
  37. + public static int TW_ID;
  38. + public static int TW_CHANCE;
  39. + public static int TW_MAX_DROP;
  40. + public static int TW_MIN_DROP;
  41. +
  42.  
  43. @@ -1783,6 +1795,24 @@
  44. L2JMOD_ENABLE_WAREHOUSESORTING_PRIVATE = Boolean.valueOf(L2JModSettings.getProperty("EnableWarehouseSortingPrivate", "False"));
  45. L2JMOD_ENABLE_WAREHOUSESORTING_FREIGHT = Boolean.valueOf(L2JModSettings.getProperty("EnableWarehouseSortingFreight", "False"));
  46.  
  47. TW_MOB_ID = Integer.parseInt(L2JModSettings.getProperty("MonsterId", "0"));
  48. + TW_MAX_HP = Integer.parseInt(L2JModSettings.getProperty("MaxHp", "1000"));
  49. + TW_MAX_MP = Integer.parseInt(L2JModSettings.getProperty("MaxMp", "1000"));
  50. + TW_ID = Integer.parseInt(L2JModSettings.getProperty("DropId", "0"));
  51. + TW_CHANCE = Integer.parseInt(L2JModSettings.getProperty("DropChance", "0"));
  52. + TW_MAX_DROP = Integer.parseInt(L2JModSettings.getProperty("DropMax", "0"));
  53. + TW_MIN_DROP = Integer.parseInt(L2JModSettings.getProperty("DropMin", "0"));
  54. +
  55. + if (DM_REVIVE_DELAY < 1000)
  56. + DM_REVIVE_DELAY = 1000; //can't be set less then 1 second
  57. +
  58. if (TVT_EVENT_PARTICIPATION_NPC_ID == 0)
  59. {
  60. TVT_EVENT_ENABLED = false;
  61.  
  62.  
  63. Index: D:/Workspace/wks/L2_GameServer/java/net/sf/l2j/gameserver/instancemanager/TownWar.java
  64. ===================================================================
  65. --- D:/Workspace/wks/L2_GameServer/java/net/sf/l2j/gameserver/instancemanager/TownWar.java (revision 0)
  66. +++ D:/Workspace/wks/L2_GameServer/java/net/sf/l2j/gameserver/instancemanager/TownWar.java (revision 0)
  67. @@ -0,0 +1,347 @@
  68. +/*
  69. + * This program is free software; you can redistribute it and/or modify
  70. + * it under the terms of the GNU General Public License as published by
  71. + * the Free Software Foundation; either version 2, or (at your option)
  72. + * any later version.
  73. + *
  74. + * This program is distributed in the hope that it will be useful,
  75. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  76. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  77. + * GNU General Public License for more details.
  78. + *
  79. + * You should have received a copy of the GNU General Public License
  80. + * along with this program; if not, write to the Free Software
  81. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  82. + * 02111-1307, USA.
  83. + *
  84. + * http://www.gnu.org/copyleft/gpl.html
  85. + */
  86. +
  87. +package net.sf.l2j.gameserver.instancemanager;
  88. +
  89. +import java.util.List;
  90. +import java.util.Random;
  91. +import java.util.concurrent.Future;
  92. +import java.util.logging.Logger;
  93. +
  94. +import javolution.util.FastList;
  95. +import net.sf.l2j.Config;
  96. +import net.sf.l2j.gameserver.Announcements;
  97. +import net.sf.l2j.gameserver.ThreadPoolManager;
  98. +import net.sf.l2j.gameserver.datatables.NpcTable;
  99. +import net.sf.l2j.gameserver.datatables.SpawnTable;
  100. +import net.sf.l2j.gameserver.idfactory.IdFactory;
  101. +import net.sf.l2j.gameserver.model.L2DropData;
  102. +import net.sf.l2j.gameserver.model.L2Object;
  103. +import net.sf.l2j.gameserver.model.L2Spawn;
  104. +import net.sf.l2j.gameserver.model.L2World;
  105. +import net.sf.l2j.gameserver.model.actor.L2Attackable;
  106. +import net.sf.l2j.gameserver.model.actor.L2Npc;
  107. +import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  108. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  109. +import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate;
  110. +
  111. +
  112. +public class TownWar
  113. +{
  114. +
  115. + private static TownWar _instance = new TownWar();
  116. +
  117. + private static final Logger _log = Logger.getLogger(TownWar.class.getName());
  118. + // list of trees.
  119. + protected List<L2NpcInstance> objectQueue = new FastList<L2NpcInstance>();
  120. +
  121. + protected Random rand = new Random();
  122. +
  123. + private final int last = 73099;
  124. +
  125. + int monsterid = Config.TW_MOB_ID;
  126. +
  127. + // Manager should only be Initialized once:
  128. + protected int isManagerInit = 0;
  129. +
  130. + /**
  131. + * Empty constructor
  132. + * Does nothing
  133. + */
  134. + public TownWar()
  135. + {
  136. + // nothing.
  137. + }
  138. +
  139. +
  140. + public static TownWar getInstance()
  141. + {
  142. + if (_instance == null) _instance = new TownWar();
  143. +
  144. + return _instance;
  145. + }
  146. +
  147. +
  148. +
  149. + public void init(L2PcInstance activeChar)
  150. + {
  151. +
  152. + if (isManagerInit > 0)
  153. + {
  154. + activeChar.sendMessage("TownWar has already begun or is processing. Please be patient....");
  155. + return;
  156. + }
  157. +
  158. + activeChar.sendMessage("Started!!!! This will take a 2-3 hours (in order to reduce system lags to a minimum), please be patient... The process is working in the background and will spawn mobs at a fixed rate.");
  159. +
  160. + checkIfOkToAnnounce();
  161. +
  162. + }
  163. +
  164. +
  165. + public void end(L2PcInstance activeChar)
  166. + {
  167. +
  168. + if (isManagerInit < 4)
  169. + {
  170. +
  171. + if (activeChar != null)
  172. + activeChar.sendMessage("TownWar is not activated yet. Already Ended or is now processing....");
  173. + return;
  174. +
  175. + }
  176. +
  177. + if (activeChar != null)
  178. + activeChar.sendMessage("Terminating! This may take a while, please be patient...");
  179. +
  180. + //Tasks:
  181. +
  182. + ThreadPoolManager.getInstance().executeTask(new DeleteSpawns());
  183. +
  184. +
  185. + checkIfOkToAnnounce();
  186. +
  187. + }
  188. +
  189. +
  190. +
  191. + public class DeleteSpawns implements Runnable
  192. + {
  193. +
  194. + public void run()
  195. + {
  196. +
  197. + if (objectQueue == null || objectQueue.isEmpty())
  198. + return;
  199. +
  200. + for (L2NpcInstance deleted : objectQueue)
  201. + {
  202. +
  203. + if (deleted == null)
  204. + continue;
  205. +
  206. + else
  207. + {
  208. + try
  209. + {
  210. +
  211. + L2World.getInstance().removeObject(deleted);
  212. +
  213. + deleted.decayMe();
  214. + deleted.deleteMe();
  215. +
  216. +
  217. + }
  218. +
  219. + catch(Throwable t) { continue; }
  220. + }
  221. +
  222. + }
  223. +
  224. + objectQueue.clear();
  225. + objectQueue = null;
  226. +
  227. + isManagerInit = isManagerInit - 2;
  228. + checkIfOkToAnnounce();
  229. +
  230. + }
  231. +
  232. + }
  233. +
  234. +
  235. + @SuppressWarnings("null")
  236. + void spawnOneMob(int id, int x, int y, int z)
  237. + {
  238. + try
  239. + {
  240. +
  241. + L2NpcTemplate template1 = NpcTable.getInstance().getTemplate(id);
  242. + L2Spawn spawn = new L2Spawn(template1);
  243. +
  244. + spawn.setId(IdFactory.getInstance().getNextId());
  245. +
  246. + spawn.setLocx(x);
  247. + spawn.setLocy(y);
  248. + spawn.setLocz(z);
  249. +
  250. + L2Npc monster = spawn.spawnOne(false);
  251. +
  252. + monster.getStatus().setCurrentHp(Config.TW_MAX_HP);
  253. + monster.getStatus().setCurrentMp(Config.TW_MAX_MP);
  254. +
  255. + L2DropData drop = null;
  256. + drop.setItemId(Config.TW_ID);
  257. + drop.setChance(Config.TW_CHANCE);
  258. + drop.setMaxDrop(Config.TW_MAX_DROP);
  259. + drop.setMinDrop(Config.TW_MIN_DROP);
  260. +
  261. + monster.getTemplate().addDropData(drop, 1);
  262. + L2World.getInstance().storeObject(monster);
  263. + objectQueue.add((L2NpcInstance) monster);
  264. +
  265. + }
  266. +
  267. + catch(Throwable t){}
  268. + }
  269. +
  270. + public class SpawnMobs implements Runnable
  271. + {
  272. +
  273. + private int _iterator;
  274. +
  275. + @SuppressWarnings("unchecked")
  276. + private Future _task;
  277. +
  278. +
  279. + public SpawnMobs(int iter)
  280. + {
  281. + _iterator = iter;
  282. + }
  283. +
  284. +
  285. + @SuppressWarnings("unchecked")
  286. + public void setTask(Future task)
  287. + {
  288. + _task = task;
  289. + }
  290. +
  291. + public void run()
  292. + {
  293. +
  294. + if (_task != null)
  295. + {
  296. + _task.cancel(true);
  297. + _task = null;
  298. + }
  299. +
  300. +
  301. + try
  302. + {
  303. +
  304. + L2Object obj = null;
  305. + while (obj == null)
  306. + {
  307. + obj = SpawnTable.getInstance().getTemplate(_iterator).getLastSpawn();
  308. + _iterator++;
  309. + if (obj != null && obj instanceof L2Attackable)
  310. + obj = null;
  311. + }
  312. +
  313. + if ( obj != null &&
  314. + rand.nextInt(100)<80 &&
  315. + obj instanceof L2NpcInstance &&
  316. + TownManager.getTown(obj.getX(), obj.getY(), obj.getZ()) != null &&
  317. + TownManager.getTown(obj.getX(), obj.getY(), obj.getZ()).isPeaceZone())
  318. + {
  319. +
  320. + spawnOneMob ( monsterid ,
  321. + obj.getX() + rand.nextInt(500) - 250 ,
  322. + obj.getY() + rand.nextInt(500) - 250 ,
  323. + obj.getZ());
  324. +
  325. +
  326. + }
  327. +
  328. +
  329. +
  330. + }
  331. + catch(Throwable t){}
  332. +
  333. + if (_iterator >= last)
  334. + {
  335. + isManagerInit++;
  336. + checkIfOkToAnnounce();
  337. +
  338. + return;
  339. + }
  340. +
  341. + _iterator++;
  342. + SpawnMobs ssNPCs = new SpawnMobs(_iterator);
  343. +
  344. + _task = ThreadPoolManager.getInstance().scheduleGeneral(ssNPCs, 300);
  345. + ssNPCs.setTask(_task);
  346. +
  347. + }
  348. +
  349. + }
  350. +
  351. +
  352. +
  353. +
  354. + @SuppressWarnings("unchecked")
  355. + void checkIfOkToAnnounce()
  356. + {
  357. + if (isManagerInit == 4)
  358. + {
  359. + Announcements.getInstance().announceToAll("TownWar Event has begun!");
  360. + Announcements.getInstance().announceToAll("TownWar will end in 24 hours.");
  361. + _log.info("TownWar:Init TownWar was started successfully.");
  362. +
  363. + EndEvent ee = new EndEvent();
  364. + Future task = ThreadPoolManager.getInstance().scheduleGeneral(ee , 86400000);
  365. + ee.setTask(task);
  366. +
  367. + isManagerInit = 5;
  368. + }
  369. +
  370. + if (isManagerInit == 0)
  371. + {
  372. + Announcements.getInstance().announceToAll("TownWar has ended... Hope you enjoyed the event.");
  373. + _log.info("TownWar:Terminated TownWar.");
  374. +
  375. + isManagerInit = -1;
  376. + }
  377. + }
  378. +
  379. +
  380. + public class EndEvent implements Runnable
  381. + {
  382. +
  383. + @SuppressWarnings("unchecked")
  384. + private Future _task;
  385. +
  386. +
  387. + @SuppressWarnings("unchecked")
  388. + public void setTask(Future task)
  389. + {
  390. + _task = task;
  391. + }
  392. +
  393. +
  394. + public void run()
  395. + {
  396. + if (_task != null)
  397. + {
  398. + _task.cancel(true);
  399. + _task = null;
  400. + }
  401. +
  402. + end(null);
  403. +
  404. + }
  405. +
  406. + }
  407. +
  408. +}
  409. +
  410. +
Advertisement
Add Comment
Please, Sign In to add comment