Advertisement
cunder

Multifuntion Zone

May 3rd, 2015
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.14 KB | None | 0 0
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. /*
  16. * This program is free software: you can redistribute it and/or modify it under
  17. * the terms of the GNU General Public License as published by the Free Software
  18. * Foundation, either version 3 of the License, or (at your option) any later
  19. * version.
  20. *
  21. * This program is distributed in the hope that it will be useful, but WITHOUT
  22. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  23. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  24. * details.
  25. *
  26. * You should have received a copy of the GNU General Public License along with
  27. * this program. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29. package com.l2jserver.gameserver.model.zone.type;
  30.  
  31. import java.io.File;
  32. import java.io.FileInputStream;
  33. import java.util.ArrayList;
  34. import java.util.List;
  35. import java.util.Properties;
  36.  
  37.  
  38. import com.l2jserver.gameserver.ThreadPoolManager;
  39. import com.l2jserver.gameserver.datatables.SkillData;
  40. import com.l2jserver.gameserver.model.actor.L2Character;
  41. import com.l2jserver.gameserver.model.actor.L2Summon;
  42. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  43. import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
  44. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  45. import com.l2jserver.gameserver.model.skills.Skill;
  46. import com.l2jserver.gameserver.model.zone.ZoneId;
  47. import com.l2jserver.util.Rnd;
  48.  
  49. /**
  50. * @author Wyatt
  51. * @version 1.3
  52. */
  53.  
  54. public class L2MultiFunctionZone extends L2RespawnZone
  55. {
  56.  
  57. public L2MultiFunctionZone(int id)
  58. {
  59. super(id);
  60. loadConfigs();
  61. }
  62.  
  63. public static boolean pvp_enabled, restart_zone, store_zone, logout_zone, revive_noblesse, revive_heal, revive, remove_buffs, remove_pets, give_noblesse;
  64. static int radius, enchant, revive_delay;
  65. static int[][] spawn_loc;
  66. Skill noblesse = SkillData.getInstance().getSkill(1323, 1);
  67. private static List<String> items = new ArrayList<>();
  68. private static List<String> grades = new ArrayList<>(), classes = new ArrayList<>();
  69. public static List<int[]> rewards;
  70. static String[] gradeNames =
  71. {
  72. "",
  73. "D",
  74. "C",
  75. "B",
  76. "A",
  77. "S",
  78. "S80",
  79. "S84"
  80. };
  81.  
  82. @Override
  83. protected void onEnter(L2Character character)
  84. {
  85. character.setInsideZone(ZoneId.NO_SUMMON_FRIEND, true);
  86. character.setInsideZone(ZoneId.MULTI_FUNCTION, true);
  87. if (!store_zone)
  88. {
  89. character.setInsideZone(ZoneId.NO_STORE, true);
  90. }
  91.  
  92. if (character instanceof L2PcInstance)
  93. {
  94. L2PcInstance activeChar = ((L2PcInstance) character);
  95. if ((classes != null) && classes.contains("" + activeChar.getClassId().getId()))
  96. {
  97. activeChar.teleToLocation(83597, 147888, -3405);
  98. activeChar.sendMessage("Your class is not allowed in the MultiFunction zone.");
  99. return;
  100. }
  101.  
  102. for (L2ItemInstance o : activeChar.getInventory().getItems())
  103. {
  104. if (o.isEquipable() && o.isEquipped() && !checkItem(o))
  105. {
  106. int slot = activeChar.getInventory().getSlotFromItem(o);
  107. activeChar.getInventory().unEquipItemInBodySlot(slot);
  108. activeChar.sendMessage(o.getName() + " unequiped because is not allowed inside this zone.");
  109. }
  110. }
  111. activeChar.sendMessage("You entered in a MultiFunction zone.");
  112. clear(activeChar);
  113. if (give_noblesse)
  114. {
  115. noblesse.applyEffects(activeChar, activeChar);
  116. }
  117. if (pvp_enabled)
  118. {
  119. activeChar.updatePvPFlag(1);
  120. }
  121. }
  122. }
  123.  
  124. @Override
  125. protected void onExit(L2Character character)
  126. {
  127. character.setInsideZone(ZoneId.NO_SUMMON_FRIEND, false);
  128. character.setInsideZone(ZoneId.MULTI_FUNCTION, false);
  129. if (!store_zone)
  130. {
  131. character.setInsideZone(ZoneId.NO_STORE, false);
  132. }
  133.  
  134. if (character instanceof L2PcInstance)
  135. {
  136. L2PcInstance activeChar = ((L2PcInstance) character);
  137. activeChar.sendMessage("You left from a MultiFunction zone.");
  138.  
  139. if (pvp_enabled)
  140. {
  141. activeChar.stopPvPFlag();
  142. }
  143. }
  144. }
  145.  
  146. @Override
  147. public void onDieInside(final L2Character character)
  148. {
  149. if (character instanceof L2PcInstance)
  150. {
  151. final L2PcInstance activeChar = ((L2PcInstance) character);
  152. if (revive)
  153. {
  154. ThreadPoolManager.getInstance().scheduleGeneral(() ->
  155. {
  156. activeChar.doRevive();
  157. heal(activeChar);
  158. int[] loc = spawn_loc[Rnd.get(spawn_loc.length)];
  159. activeChar.teleToLocation(loc[0] + Rnd.get(-radius, radius), loc[1] + Rnd.get(-radius, radius), loc[2]);
  160. }, revive_delay * 1000);
  161. }
  162. }
  163. }
  164.  
  165. @Override
  166. public void onReviveInside(L2Character character)
  167. {
  168. if (character instanceof L2PcInstance)
  169. {
  170. L2PcInstance activeChar = ((L2PcInstance) character);
  171. if (revive_noblesse)
  172. {
  173. noblesse.applyEffects(activeChar, activeChar);
  174. }
  175. if (revive_heal)
  176. {
  177. heal(activeChar);
  178. }
  179. }
  180. }
  181.  
  182. private void clear(L2PcInstance player)
  183. {
  184. if (remove_buffs)
  185. {
  186. player.stopAllEffectsExceptThoseThatLastThroughDeath();
  187. if (remove_pets)
  188. {
  189. L2Summon pet = player.getSummon();
  190. if (pet != null)
  191. {
  192. pet.stopAllEffectsExceptThoseThatLastThroughDeath();
  193. pet.unSummon(player);
  194. }
  195. }
  196. }
  197. else
  198. {
  199. if (remove_pets)
  200. {
  201. L2Summon pet = player.getSummon();
  202. if (pet != null)
  203. {
  204. pet.unSummon(player);
  205. }
  206. }
  207. }
  208. }
  209.  
  210. static void heal(L2PcInstance activeChar)
  211. {
  212. activeChar.setCurrentHp(activeChar.getMaxHp());
  213. activeChar.setCurrentCp(activeChar.getMaxCp());
  214. activeChar.setCurrentMp(activeChar.getMaxMp());
  215. }
  216.  
  217. public static void givereward(L2PcInstance player)
  218. {
  219. if (player.isInsideZone(ZoneId.MULTI_FUNCTION))
  220. {
  221. for (int[] reward : rewards)
  222. {
  223. PcInventory inv = player.getInventory();
  224. inv.addItem("Custom Reward", reward[0], reward[1], player, player);
  225. player.sendMessage("Your have received a Reward!");
  226. }
  227. }
  228. }
  229.  
  230. public static boolean checkItem(L2ItemInstance item)
  231. {
  232. int o = item.getItem().getCrystalType().ordinal();
  233. int e = item.getEnchantLevel();
  234.  
  235. if ((enchant != 0) && (e >= enchant))
  236. {
  237. return false;
  238. }
  239.  
  240. if (grades.contains(gradeNames[o]))
  241. {
  242. return false;
  243. }
  244.  
  245. if ((items != null) && items.contains("" + item.getId()))
  246. {
  247. return false;
  248. }
  249. return true;
  250. }
  251.  
  252. private static void loadConfigs()
  253. {
  254. try
  255. {
  256. Properties prop = new Properties();
  257. prop.load(new FileInputStream(new File("./config/MultiFunctionZone.properties")));
  258. pvp_enabled = Boolean.parseBoolean(prop.getProperty("EnablePvP", "False"));
  259. spawn_loc = parseItemsList(prop.getProperty("SpawnLoc", "150111,144740,-12248"));
  260. revive_delay = Integer.parseInt(prop.getProperty("ReviveDelay", "10"));
  261. if (revive_delay != 0)
  262. {
  263. revive = true;
  264. }
  265. give_noblesse = Boolean.parseBoolean(prop.getProperty("GiveNoblesse", "False"));
  266. String[] propertySplit = prop.getProperty("Items", "").split(",");
  267. if (propertySplit.length != 0)
  268. {
  269. for (String i : propertySplit)
  270. {
  271. items.add(i);
  272. }
  273. }
  274. propertySplit = prop.getProperty("Grades", "").split(",");
  275. if (propertySplit.length != 0)
  276. {
  277. for (String i : propertySplit)
  278. {
  279. if (i.equals("D") || i.equals("C") || i.equals("B") || i.equals("A") || i.equals("S") || i.equals("S80") || i.equals("S84"))
  280. {
  281. grades.add(i);
  282. }
  283. }
  284. }
  285. propertySplit = prop.getProperty("Classes", "").split(",");
  286. if (propertySplit.length != 0)
  287. {
  288. for (String i : propertySplit)
  289. {
  290. classes.add(i);
  291. }
  292. }
  293. radius = Integer.parseInt(prop.getProperty("RespawnRadius", "500"));
  294. enchant = Integer.parseInt(prop.getProperty("Enchant", "0"));
  295. remove_buffs = Boolean.parseBoolean(prop.getProperty("RemoveBuffs", "False"));
  296. remove_pets = Boolean.parseBoolean(prop.getProperty("RemovePets", "False"));
  297. restart_zone = Boolean.parseBoolean(prop.getProperty("NoRestartZone", "False"));
  298. store_zone = Boolean.parseBoolean(prop.getProperty("NoStoreZone", "False"));
  299. logout_zone = Boolean.parseBoolean(prop.getProperty("NoLogoutZone", "False"));
  300. revive_noblesse = Boolean.parseBoolean(prop.getProperty("ReviveNoblesse", "False"));
  301. revive_heal = Boolean.parseBoolean(prop.getProperty("ReviveHeal", "False"));
  302. rewards = new ArrayList<>();
  303. propertySplit = prop.getProperty("Rewards", "57,100000").split(";");
  304. for (String reward : propertySplit)
  305. {
  306. String[] rewardSplit = reward.split(",");
  307. if (rewardSplit.length == 2)
  308. {
  309. try
  310. {
  311. rewards.add(new int[]
  312. {
  313. Integer.parseInt(rewardSplit[0]),
  314. Integer.parseInt(rewardSplit[1])
  315. });
  316. }
  317. catch (NumberFormatException nfe)
  318. {
  319. }
  320. }
  321. }
  322. }
  323. catch (Exception e)
  324. {
  325. e.printStackTrace();
  326. }
  327. }
  328.  
  329. private static int[][] parseItemsList(String line)
  330. {
  331. final String[] propertySplit = line.split(";");
  332. if (propertySplit.length == 0)
  333. {
  334. return null;
  335. }
  336.  
  337. int i = 0;
  338. String[] valueSplit;
  339. final int[][] result = new int[propertySplit.length][];
  340. for (String value : propertySplit)
  341. {
  342. valueSplit = value.split(",");
  343. if (valueSplit.length != 3)
  344. {
  345. return null;
  346. }
  347.  
  348. result[i] = new int[3];
  349. try
  350. {
  351. result[i][0] = Integer.parseInt(valueSplit[0]);
  352. }
  353. catch (NumberFormatException e)
  354. {
  355. return null;
  356. }
  357. try
  358. {
  359. result[i][1] = Integer.parseInt(valueSplit[1]);
  360. }
  361. catch (NumberFormatException e)
  362. {
  363. return null;
  364. }
  365. try
  366. {
  367. result[i][2] = Integer.parseInt(valueSplit[2]);
  368. }
  369. catch (NumberFormatException e)
  370. {
  371. return null;
  372. }
  373. i++;
  374. }
  375. return result;
  376. }
  377. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement