Guest User

Untitled

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