warc222

FrozenFear's Request]Working Pvp Flag Zone

Jan 2nd, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.19 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P trunk3
  3. Index: gameserver/head-src/com/l2jfrozen/gameserver/model/zone/type/L2FlagZone.java
  4. ===================================================================
  5. --- gameserver/head-src/com/l2jfrozen/gameserver/model/zone/type/L2FlagZone.java (revision 0)
  6. +++ gameserver/head-src/com/l2jfrozen/gameserver/model/zone/type/L2FlagZone.java (revision 0)
  7. @@ -0,0 +1,185 @@
  8. +/*
  9. + * This program is free software: you can redistribute it and/or modify it under
  10. + * the terms of the GNU General Public License as published by the Free Software
  11. + * Foundation, either version 3 of the License, or (at your option) any later
  12. + * version.
  13. + *
  14. + * This program is distributed in the hope that it will be useful, but WITHOUT
  15. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17. + * details.
  18. + *
  19. + * You should have received a copy of the GNU General Public License along with
  20. + * this program. If not, see <http://www.gnu.org/licenses/>.
  21. + */
  22. +package com.l2jfrozen.gameserver.model.zone.type;
  23. +
  24. +import java.util.concurrent.Future;
  25. +
  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.actor.instance.L2MonsterInstance;
  30. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  31. +import com.l2jfrozen.gameserver.model.actor.instance.L2PlayableInstance;
  32. +import com.l2jfrozen.gameserver.model.zone.L2ZoneType;
  33. +import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
  34. +import com.l2jfrozen.util.random.Rnd;
  35. +
  36. +/**
  37. + * @author Strato
  38. + * @author Elfocrash (for the correction)
  39. + */
  40. +public class L2FlagZone extends L2ZoneType
  41. +{
  42. + private int _skillId;
  43. + private int _chance;
  44. + private int _initialDelay;
  45. + private int _skillLvl;
  46. + private int _reuse;
  47. + private boolean _enabled;
  48. + private String _target;
  49. + private Future<?> _task;
  50. + public L2FlagZone(int id)
  51. + {
  52. + super(id);
  53. + _skillId = 1323;
  54. + _skillLvl = 1;
  55. + _chance = 100;
  56. + _initialDelay = 0;
  57. + _reuse = 30000;
  58. + _enabled = true;
  59. + _target = "pc";
  60. + }
  61. +
  62. + @Override
  63. + public void setParameter(String name, String value)
  64. + {
  65. + if(name.equals("skillId"))
  66. + {
  67. + _skillId = Integer.parseInt(value);
  68. + }
  69. + else if(name.equals("skillLvl"))
  70. + {
  71. + _skillLvl = Integer.parseInt(value);
  72. + }
  73. + else if(name.equals("chance"))
  74. + {
  75. + _chance = Integer.parseInt(value);
  76. + }
  77. + else if(name.equals("initialDelay"))
  78. + {
  79. + _initialDelay = Integer.parseInt(value);
  80. + }
  81. + else if(name.equals("default_enabled"))
  82. + {
  83. + _enabled = Boolean.parseBoolean(value);
  84. + }
  85. + else if(name.equals("target"))
  86. + {
  87. + _target = String.valueOf(value);
  88. + }
  89. + else if(name.equals("reuse"))
  90. + {
  91. + _reuse = Integer.parseInt(value);
  92. + }
  93. + else
  94. + {
  95. + super.setParameter(name, value);
  96. + }
  97. + }
  98. +
  99. + @Override
  100. + protected void onEnter(L2Character character)
  101. + {
  102. + if (character instanceof L2PcInstance)
  103. + {
  104. + // Set pvp flag
  105. + ((L2PcInstance) character).setPvpFlag(1);
  106. + ((L2PcInstance) character).sendMessage("You entered a Pvp Flag zone.Have fun!!!");
  107. + ((L2PcInstance) character).broadcastUserInfo();
  108. + if((character instanceof L2PlayableInstance && _target.equalsIgnoreCase("pc") || character instanceof L2PcInstance && _target.equalsIgnoreCase("pc_only") || character instanceof L2MonsterInstance && _target.equalsIgnoreCase("npc")) && _task == null)
  109. + {
  110. + _task = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new ApplySkill(/*this*/), _initialDelay, _reuse);
  111. + }
  112. + }
  113. + }
  114. +
  115. + @Override
  116. + protected void onExit(L2Character character)
  117. + {
  118. + if (character instanceof L2PcInstance)
  119. + {
  120. + ((L2PcInstance) character).setPvpFlag(0);
  121. + ((L2PcInstance) character).sendMessage("You left the Pvp Flag zone.BAAAAD!!");
  122. + ((L2PcInstance) character).broadcastUserInfo();
  123. + }
  124. + if(_characterList.isEmpty() && _task != null)
  125. + {
  126. + _task.cancel(true);
  127. + _task = null;
  128. + }
  129. + }
  130. +
  131. + public L2Skill getSkill()
  132. + {
  133. + return SkillTable.getInstance().getInfo(_skillId, _skillLvl);
  134. + }
  135. +
  136. + public String getTargetType()
  137. + {
  138. + return _target;
  139. + }
  140. +
  141. + public boolean isEnabled()
  142. + {
  143. + return _enabled;
  144. + }
  145. +
  146. + public int getChance()
  147. + {
  148. + return _chance;
  149. + }
  150. +
  151. + public void setZoneEnabled(boolean val)
  152. + {
  153. + _enabled = val;
  154. + }
  155. + class ApplySkill implements Runnable
  156. + {
  157. + @Override
  158. + public void run()
  159. + {
  160. + if(isEnabled())
  161. + {
  162. + for(L2Character temp : _characterList.values())
  163. + {
  164. + if(temp != null && !temp.isDead())
  165. + {
  166. + if((temp instanceof L2PlayableInstance && getTargetType().equalsIgnoreCase("pc") || temp instanceof L2PcInstance && getTargetType().equalsIgnoreCase("pc_only") || temp instanceof L2MonsterInstance && getTargetType().equalsIgnoreCase("npc")) && Rnd.get(100) < getChance())
  167. + {
  168. + L2Skill skill = null;
  169. + if((skill=getSkill())==null){
  170. + System.out.println("ATTENTION: error on zone with id "+getId());
  171. + System.out.println("Skill "+_skillId+","+_skillLvl+" not present between skills");
  172. + }else
  173. + skill.getEffects(temp, temp);
  174. + }
  175. + }
  176. + }
  177. + }
  178. + }
  179. + }
  180. +
  181. + @Override
  182. + public void onDieInside(L2Character character)
  183. + {
  184. +
  185. + }
  186. +
  187. + @Override
  188. + public void onReviveInside(L2Character character)
  189. + {
  190. + onEnter(character);
  191. + }
  192. +}
  193. \ No newline at end of file
  194. Index: gameserver/head-src/com/l2jfrozen/gameserver/datatables/xml/ZoneData.java
  195. ===================================================================
  196. --- gameserver/head-src/com/l2jfrozen/gameserver/datatables/xml/ZoneData.java (revision 909)
  197. +++ gameserver/head-src/com/l2jfrozen/gameserver/datatables/xml/ZoneData.java (working copy)
  198. @@ -63,6 +63,7 @@
  199. import com.l2jfrozen.gameserver.model.zone.type.L2OlympiadStadiumZone;
  200. import com.l2jfrozen.gameserver.model.zone.type.L2PeaceZone;
  201. import com.l2jfrozen.gameserver.model.zone.type.L2PoisonZone;
  202. +import com.l2jfrozen.gameserver.model.zone.type.L2FlagZone;
  203. import com.l2jfrozen.gameserver.model.zone.type.L2SwampZone;
  204. import com.l2jfrozen.gameserver.model.zone.type.L2TownZone;
  205. import com.l2jfrozen.gameserver.model.zone.type.L2WaterZone;
  206. @@ -278,6 +279,10 @@
  207. {
  208. temp = new L2SwampZone(zoneId);
  209. }
  210. + else if(zoneType.equals("FlagZone"))
  211. + {
  212. + temp = new L2FlagZone(zoneId);
  213. + }
  214.  
  215. // Check for unknown type
  216. if(temp == null)
Advertisement
Add Comment
Please, Sign In to add comment