Advertisement
horato

Steal Divinity edit for less QQ

Jun 29th, 2011
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. Datapack -> handlers.skillhandlers.StealBuffs.java
  2.  
  3. /*
  4. * This program is free software: you can redistribute it and/or modify it under
  5. * the terms of the GNU General Public License as published by the Free Software
  6. * Foundation, either version 3 of the License, or (at your option) any later
  7. * version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  12. * details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package handlers.skillhandlers;
  18.  
  19. /*
  20. * This class is called when 'steal divinity' skill is used.
  21. * Each buff have its own chance to be stealed defined by the 'chance' variable
  22. * Buffs are chosen randomly from now, no more staling last buffs or dances
  23. * */
  24. import java.util.ArrayList;
  25. import java.util.logging.Level;
  26.  
  27. import com.l2jserver.gameserver.handler.ISkillHandler;
  28. import com.l2jserver.gameserver.model.L2Effect;
  29. import com.l2jserver.gameserver.model.L2ItemInstance;
  30. import com.l2jserver.gameserver.model.L2Object;
  31. import com.l2jserver.gameserver.model.L2Skill;
  32. import com.l2jserver.gameserver.model.actor.L2Character;
  33. import com.l2jserver.gameserver.model.actor.L2Npc;
  34. import com.l2jserver.gameserver.model.actor.L2Summon;
  35. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  36. import com.l2jserver.gameserver.network.SystemMessageId;
  37. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  38. import com.l2jserver.gameserver.skills.Env;
  39. import com.l2jserver.gameserver.skills.Formulas;
  40. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  41. import com.l2jserver.util.Rnd;
  42.  
  43. public class StealBuffs implements ISkillHandler
  44. {
  45. private static final L2SkillType[] SKILL_IDS = { L2SkillType.STEAL_BUFF };
  46.  
  47. /**
  48. *
  49. * @see com.l2jserver.gameserver.handler.ISkillHandler#useSkill(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.L2Skill, com.l2jserver.gameserver.model.L2Object[])
  50. */
  51. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  52. {
  53. // discharge shots
  54. final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  55. if (weaponInst != null)
  56. {
  57. if (skill.isMagic())
  58. {
  59. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  60. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  61. else if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  62. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  63. }
  64. }
  65. else if (activeChar instanceof L2Summon)
  66. {
  67. final L2Summon activeSummon = (L2Summon) activeChar;
  68.  
  69. if (skill.isMagic())
  70. {
  71. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  72. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  73. else if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  74. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  75. }
  76. }
  77. else if (activeChar instanceof L2Npc)
  78. ((L2Npc) activeChar)._spiritshotcharged = false;
  79.  
  80. L2Character target;
  81. L2Effect effect;
  82.  
  83. int count = (int) skill.getPower();
  84. // Chance for each buff to be stealed
  85. int chance = 70;
  86. for (L2Object obj : targets)
  87. {
  88. if (!(obj instanceof L2Character))
  89. continue;
  90. target = (L2Character) obj;
  91.  
  92. if (target.isDead())
  93. continue;
  94.  
  95. if (!(target instanceof L2PcInstance))
  96. continue;
  97.  
  98. Env env;
  99. int lastSkillId = 0;
  100. final ArrayList<L2Effect> toSteal = new ArrayList<L2Effect>(count);
  101. final ArrayList<L2Effect> effects = new ArrayList<L2Effect>(target.getAllEffects().length);
  102.  
  103. for (L2Effect eff : target.getAllEffects())
  104. {
  105. if (eff == null)
  106. continue;
  107.  
  108. if (!eff.canBeStolen()) // Do not add effect if can't be stolen
  109. continue;
  110.  
  111. // if eff time is smaller than 5 sec, will not be stolen, just to save CPU,
  112. // avoid synchronization(?) problems and NPEs
  113. if (eff.getAbnormalTime() - eff.getTime() < 5)
  114. continue;
  115.  
  116. effects.add(eff);
  117. }
  118. while (count >= 0 && effects.size() > 0)
  119. {
  120. if (Rnd.get(1, 100) >= 100 - chance)
  121. {
  122. if (effects.size() >= (int) skill.getPower() - 1)
  123. {
  124. effect = effects.get(Rnd.get(1, effects.size() - 1));
  125.  
  126. if (effect.getSkill().getId() != lastSkillId)
  127. {
  128. lastSkillId = effect.getSkill().getId();
  129. count--;
  130. toSteal.add(effect);
  131. }
  132. }
  133. else
  134. {
  135. if (effects.size() > 0)
  136. {
  137. for (L2Effect eff : effects)
  138. {
  139. toSteal.add(eff);
  140. count--;
  141. }
  142. }
  143. }
  144. }
  145. else
  146. count--;
  147. }
  148.  
  149. if (toSteal.size() == 0)
  150. continue;
  151.  
  152. // stealing effects
  153. for (L2Effect eff : toSteal)
  154. {
  155. env = new Env();
  156. env.player = target;
  157. env.target = activeChar;
  158. env.skill = eff.getSkill();
  159. try
  160. {
  161. effect = eff.getEffectTemplate().getStolenEffect(env, eff);
  162. if (effect != null)
  163. {
  164. effect.scheduleEffect();
  165. if (effect.getShowIcon() && activeChar instanceof L2PcInstance)
  166. {
  167. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  168. sm.addSkillName(effect);
  169. activeChar.sendPacket(sm);
  170. }
  171. }
  172. // Finishing stolen effect
  173. eff.exit();
  174. }
  175. catch (RuntimeException e)
  176. {
  177. _log.log(Level.WARNING, "Cannot steal effect: " + eff + " Stealer: " + activeChar + " Stolen: " + target, e);
  178. }
  179. }
  180.  
  181. //Possibility of a lethal strike
  182. Formulas.calcLethalHit(activeChar, target, skill);
  183. }
  184.  
  185. if (skill.hasSelfEffects())
  186. {
  187. // Applying self-effects
  188. effect = activeChar.getFirstEffect(skill.getId());
  189. if (effect != null && effect.isSelfEffect())
  190. {
  191. //Replace old effect with new one.
  192. effect.exit();
  193. }
  194. skill.getEffectsSelf(activeChar);
  195. }
  196. }
  197.  
  198. /**
  199. *
  200. * @see com.l2jserver.gameserver.handler.ISkillHandler#getSkillIds()
  201. */
  202. public L2SkillType[] getSkillIds()
  203. {
  204. return SKILL_IDS;
  205. }
  206.  
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement