Advertisement
horato

Cancel System

Sep 12th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.98 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2J_Server_BETA
  3. Index: java/com/l2jserver/gameserver/skills/effects/EffectCancel.java
  4. ===================================================================
  5. --- java/com/l2jserver/gameserver/skills/effects/EffectCancel.java (revision 4769)
  6. +++ java/com/l2jserver/gameserver/skills/effects/EffectCancel.java (working copy)
  7. @@ -17,6 +17,7 @@
  8. import java.util.logging.Logger;
  9.  
  10. import com.l2jserver.Config;
  11. +import com.l2jserver.gameserver.model.CancelSystem;
  12. import com.l2jserver.gameserver.model.L2Effect;
  13. import com.l2jserver.gameserver.model.actor.L2Character;
  14. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  15. @@ -130,7 +131,10 @@
  16. if (negateAbnormalType.equalsIgnoreCase(eff.getAbnormalType()) && effect.getSkill().getNegateAbnormals().get(negateAbnormalType) >= eff.getAbnormalLvl())
  17. {
  18. if (calcCancelSuccess(eff, cancelLvl, (int)rate))
  19. + {
  20. eff.exit();
  21. + CancelSystem.onCancel(target.getActingPlayer(), effect);
  22. + }
  23. }
  24. }
  25. }
  26. @@ -159,6 +163,7 @@
  27. if (eff.getSkill().getId() == lastCanceledSkillId)
  28. {
  29. eff.exit(); // this skill already canceled
  30. + CancelSystem.onCancel(target.getActingPlayer(), effect);
  31. continue;
  32. }
  33.  
  34. @@ -168,6 +173,7 @@
  35. lastCanceledSkillId = eff.getSkill().getId();
  36.  
  37. eff.exit();
  38. + CancelSystem.onCancel(target.getActingPlayer(), effect);
  39. count--;
  40.  
  41. if (count == 0)
  42. @@ -190,6 +196,7 @@
  43. if (eff.getSkill().getId() == lastCanceledSkillId)
  44. {
  45. eff.exit(); // this skill already canceled
  46. + CancelSystem.onCancel(target.getActingPlayer(), effect);
  47. continue;
  48. }
  49.  
  50. @@ -198,6 +205,7 @@
  51.  
  52. lastCanceledSkillId = eff.getSkill().getId();
  53. eff.exit();
  54. + CancelSystem.onCancel(target.getActingPlayer(), effect);
  55. count--;
  56.  
  57. if (count == 0)
  58. Index: java/com/l2jserver/gameserver/model/CancelSystem.java
  59. ===================================================================
  60. --- java/com/l2jserver/gameserver/model/CancelSystem.java (revision 0)
  61. +++ java/com/l2jserver/gameserver/model/CancelSystem.java (revision 0)
  62. @@ -0,0 +1,54 @@
  63. +/*
  64. + * This program is free software: you can redistribute it and/or modify it under
  65. + * the terms of the GNU General Public License as published by the Free Software
  66. + * Foundation, either version 3 of the License, or (at your option) any later
  67. + * version.
  68. + *
  69. + * This program is distributed in the hope that it will be useful, but WITHOUT
  70. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  71. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  72. + * details.
  73. + *
  74. + * You should have received a copy of the GNU General Public License along with
  75. + * this program. If not, see <http://www.gnu.org/licenses/>.
  76. + */
  77. +package com.l2jserver.gameserver.model;
  78. +
  79. +import com.l2jserver.gameserver.ThreadPoolManager;
  80. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  81. +import com.l2jserver.gameserver.network.serverpackets.ExShowScreenMessage;
  82. +import com.l2jserver.gameserver.skills.Env;
  83. +
  84. +/**
  85. + *
  86. + * @author horato
  87. + *
  88. + */
  89. +
  90. +public class CancelSystem
  91. +{
  92. +
  93. + public static void onCancel(final L2PcInstance player, final L2Effect eff)
  94. + {
  95. + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  96. + {
  97. + public void run()
  98. + {
  99. + restore(player, eff);
  100. + }
  101. +
  102. + }, 30*1000);
  103. + }
  104. +
  105. + private static void restore(L2PcInstance player, L2Effect eff)
  106. + {
  107. + Env env = new Env();
  108. + env.target = player;
  109. + env.skill = eff.getSkill();
  110. + L2Effect effect = eff.getEffectTemplate().getStolenEffect(env, eff);
  111. + if (effect != null)
  112. + effect.scheduleEffect();
  113. + player.sendPacket(new ExShowScreenMessage("Your stolen effect has been given back", 5000));
  114. + }
  115. +
  116. +}
  117. #P L2J_DataPack_BETA
  118. Index: data/scripts/handlers/skillhandlers/Cancel.java
  119. ===================================================================
  120. --- data/scripts/handlers/skillhandlers/Cancel.java (revision 8223)
  121. +++ data/scripts/handlers/skillhandlers/Cancel.java (working copy)
  122. @@ -16,6 +16,7 @@
  123.  
  124. import com.l2jserver.Config;
  125. import com.l2jserver.gameserver.handler.ISkillHandler;
  126. +import com.l2jserver.gameserver.model.CancelSystem;
  127. import com.l2jserver.gameserver.model.L2Effect;
  128. import com.l2jserver.gameserver.model.L2ItemInstance;
  129. import com.l2jserver.gameserver.model.L2Object;
  130. @@ -23,6 +24,7 @@
  131. import com.l2jserver.gameserver.model.actor.L2Character;
  132. import com.l2jserver.gameserver.model.actor.L2Npc;
  133. import com.l2jserver.gameserver.model.actor.L2Summon;
  134. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  135. import com.l2jserver.gameserver.skills.Formulas;
  136. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  137. import com.l2jserver.util.Rnd;
  138. @@ -145,7 +147,11 @@
  139. if (negateAbnormalType.equalsIgnoreCase(eff.getAbnormalType()) && skill.getNegateAbnormals().get(negateAbnormalType) >= eff.getAbnormalLvl())
  140. {
  141. if (calcCancelSuccess(eff, cancelLvl, (int)rate, minRate, maxRate))
  142. + {
  143. eff.exit();
  144. + if(target instanceof L2PcInstance)
  145. + CancelSystem.onCancel(target.getActingPlayer(), eff);
  146. + }
  147. }
  148. }
  149. }
  150. @@ -171,6 +177,8 @@
  151. if (effect.getSkill().getId() == lastCanceledSkillId)
  152. {
  153. effect.exit(); // this skill already canceled
  154. + if(target instanceof L2PcInstance)
  155. + CancelSystem.onCancel(target.getActingPlayer(), effect);
  156. continue;
  157. }
  158.  
  159. @@ -179,6 +187,8 @@
  160.  
  161. lastCanceledSkillId = effect.getSkill().getId();
  162. effect.exit();
  163. + if(target instanceof L2PcInstance)
  164. + CancelSystem.onCancel(target.getActingPlayer(), effect);
  165. count--;
  166.  
  167. if (count == 0)
  168. @@ -201,7 +211,8 @@
  169. if (effect.getSkill().getId() == lastCanceledSkillId)
  170. {
  171. effect.exit(); // this skill already canceled
  172. - continue;
  173. + if(target instanceof L2PcInstance)
  174. + CancelSystem.onCancel(target.getActingPlayer(), effect); continue;
  175. }
  176.  
  177. if (!calcCancelSuccess(effect, cancelLvl, (int)rate, minRate, maxRate))
  178. @@ -209,6 +220,8 @@
  179.  
  180. lastCanceledSkillId = effect.getSkill().getId();
  181. effect.exit();
  182. + if(target instanceof L2PcInstance)
  183. + CancelSystem.onCancel(target.getActingPlayer(), effect);
  184. count--;
  185.  
  186. if (count == 0)
  187. Index: data/scripts/handlers/skillhandlers/StealBuffs.java
  188. ===================================================================
  189. --- data/scripts/handlers/skillhandlers/StealBuffs.java (revision 8223)
  190. +++ data/scripts/handlers/skillhandlers/StealBuffs.java (working copy)
  191. @@ -13,11 +13,16 @@
  192. * this program. If not, see <http://www.gnu.org/licenses/>.
  193. */
  194. package handlers.skillhandlers;
  195. -
  196. +/*
  197. + * This class is called when 'steal divinity' skill is used.
  198. + * Each buff have its own chance to be stealed defined by the 'chance' variable
  199. + *
  200. + * */
  201. import java.util.ArrayList;
  202. import java.util.logging.Level;
  203.  
  204. import com.l2jserver.gameserver.handler.ISkillHandler;
  205. +import com.l2jserver.gameserver.model.CancelSystem;
  206. import com.l2jserver.gameserver.model.L2Effect;
  207. import com.l2jserver.gameserver.model.L2ItemInstance;
  208. import com.l2jserver.gameserver.model.L2Object;
  209. @@ -31,13 +36,11 @@
  210. import com.l2jserver.gameserver.skills.Env;
  211. import com.l2jserver.gameserver.skills.Formulas;
  212. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  213. +import com.l2jserver.util.Rnd;
  214.  
  215. public class StealBuffs implements ISkillHandler
  216. {
  217. - private static final L2SkillType[] SKILL_IDS =
  218. - {
  219. - L2SkillType.STEAL_BUFF
  220. - };
  221. + private static final L2SkillType[] SKILL_IDS = { L2SkillType.STEAL_BUFF };
  222.  
  223. /**
  224. *
  225. @@ -75,12 +78,14 @@
  226. L2Character target;
  227. L2Effect effect;
  228.  
  229. - int count = (int)skill.getPower();
  230. - for (L2Object obj: targets)
  231. + int count = (int) skill.getPower();
  232. + // Chance for buff to be stealed
  233. + int chance = 70;
  234. + for (L2Object obj : targets)
  235. {
  236. if (!(obj instanceof L2Character))
  237. continue;
  238. - target = (L2Character)obj;
  239. + target = (L2Character) obj;
  240.  
  241. if (target.isDead())
  242. continue;
  243. @@ -90,67 +95,53 @@
  244.  
  245. Env env;
  246. int lastSkillId = 0;
  247. - final L2Effect[] effects = target.getAllEffects();
  248. final ArrayList<L2Effect> toSteal = new ArrayList<L2Effect>(count);
  249. + final ArrayList<L2Effect> effects = new ArrayList<L2Effect>(target.getAllEffects().length);
  250.  
  251. - for (int i = effects.length; --i >= 0;) // reverse order
  252. + for (L2Effect eff : target.getAllEffects())
  253. {
  254. - effect = effects[i];
  255. - if (effect == null)
  256. + if (eff == null)
  257. continue;
  258.  
  259. - if (!effect.canBeStolen()) // remove effect if can't be stolen
  260. - {
  261. - effects[i] = null;
  262. + if (!eff.canBeStolen()) // Do not add effect if can't be stolen
  263. continue;
  264. - }
  265.  
  266. // if eff time is smaller than 5 sec, will not be stolen, just to save CPU,
  267. // avoid synchronization(?) problems and NPEs
  268. - if (effect.getAbnormalTime() - effect.getTime() < 5)
  269. - {
  270. - effects[i] = null;
  271. + if (eff.getAbnormalTime() - eff.getTime() < 5)
  272. continue;
  273. - }
  274.  
  275. - // first pass - only dances/songs
  276. - if (!effect.getSkill().isDance())
  277. - continue;
  278. -
  279. - if (effect.getSkill().getId() != lastSkillId)
  280. - {
  281. - lastSkillId = effect.getSkill().getId();
  282. - count--;
  283. - }
  284. -
  285. - toSteal.add(effect);
  286. - if (count == 0)
  287. - break;
  288. + effects.add(eff);
  289. }
  290. -
  291. - if (count > 0) // second pass
  292. + while (count >= 0 && effects.size() > 0)
  293. {
  294. - lastSkillId = 0;
  295. - for (int i = effects.length; --i >= 0;)
  296. + if (Rnd.get(1, 100) >= 100 - chance)
  297. {
  298. - effect = effects[i];
  299. - if (effect == null)
  300. - continue;
  301. -
  302. - // second pass - all except dances/songs
  303. - if (effect.getSkill().isDance())
  304. - continue;
  305. -
  306. - if (effect.getSkill().getId() != lastSkillId)
  307. + if (effects.size() >= (int) skill.getPower() - 1)
  308. {
  309. - lastSkillId = effect.getSkill().getId();
  310. - count--;
  311. + effect = effects.get(Rnd.get(1, effects.size() - 1));
  312. +
  313. + if (effect.getSkill().getId() != lastSkillId)
  314. + {
  315. + lastSkillId = effect.getSkill().getId();
  316. + count--;
  317. + toSteal.add(effect);
  318. + }
  319. }
  320. -
  321. - toSteal.add(effect);
  322. - if (count == 0)
  323. - break;
  324. + else
  325. + {
  326. + if (effects.size() > 0)
  327. + {
  328. + for (L2Effect eff : effects)
  329. + {
  330. + toSteal.add(eff);
  331. + count--;
  332. + }
  333. + }
  334. + }
  335. }
  336. + else
  337. + count--;
  338. }
  339.  
  340. if (toSteal.size() == 0)
  341. @@ -178,6 +169,7 @@
  342. }
  343. // Finishing stolen effect
  344. eff.exit();
  345. + CancelSystem.onCancel(target.getActingPlayer(), eff);
  346. }
  347. catch (RuntimeException e)
  348. {
  349. @@ -211,4 +203,4 @@
  350. return SKILL_IDS;
  351. }
  352.  
  353. -}
  354. \ No newline at end of file
  355. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement