EnergyAttack.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.effecthandlers;
  20. import com.l2jserver.gameserver.enums.ShotType;
  21. import com.l2jserver.gameserver.model.StatsSet;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.conditions.Condition;
  25. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  26. import com.l2jserver.gameserver.model.effects.L2EffectType;
  27. import com.l2jserver.gameserver.model.items.L2Weapon;
  28. import com.l2jserver.gameserver.model.items.type.WeaponType;
  29. import com.l2jserver.gameserver.model.skills.BuffInfo;
  30. import com.l2jserver.gameserver.model.skills.Skill;
  31. import com.l2jserver.gameserver.model.stats.BaseStats;
  32. import com.l2jserver.gameserver.model.stats.Formulas;
  33. import com.l2jserver.gameserver.model.stats.Stats;
  34. import com.l2jserver.util.Rnd;
  35. /**
  36. * Energy Attack effect implementation.
  37. * @author NosBit
  38. */
  39. public final class EnergyAttack extends AbstractEffect
  40. {
  41. private final double _power;
  42. private final int _criticalChance;
  43. private final boolean _ignoreShieldDefence;
  44. public EnergyAttack(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  45. {
  46. super(attachCond, applyCond, set, params);
  47. _power = params.getDouble("power", 0);
  48. _criticalChance = params.getInt("criticalChance", 0);
  49. _ignoreShieldDefence = params.getBoolean("ignoreShieldDefence", false);
  50. }
  51. @Override
  52. public boolean calcSuccess(BuffInfo info)
  53. {
  54. // TODO: Verify this on retail
  55. return !Formulas.calcPhysicalSkillEvasion(info.getEffector(), info.getEffected(), info.getSkill());
  56. }
  57. @Override
  58. public L2EffectType getEffectType()
  59. {
  60. return L2EffectType.PHYSICAL_ATTACK;
  61. }
  62. @Override
  63. public boolean isInstant()
  64. {
  65. return true;
  66. }
  67. @Override
  68. public void onStart(BuffInfo info)
  69. {
  70. final L2PcInstance attacker = info.getEffector() instanceof L2PcInstance ? (L2PcInstance) info.getEffector() : null;
  71. if (attacker == null)
  72. {
  73. return;
  74. }
  75. final L2Character target = info.getEffected();
  76. final Skill skill = info.getSkill();
  77. double attack = attacker.getPAtk(target);
  78. double defence = target.getPDef(attacker);
  79. if (!_ignoreShieldDefence)
  80. {
  81. byte shield = Formulas.calcShldUse(attacker, target, skill, true);
  82. switch (shield)
  83. {
  84. case Formulas.SHIELD_DEFENSE_FAILED:
  85. {
  86. break;
  87. }
  88. case Formulas.SHIELD_DEFENSE_SUCCEED:
  89. {
  90. defence += target.getShldDef();
  91. break;
  92. }
  93. case Formulas.SHIELD_DEFENSE_PERFECT_BLOCK:
  94. {
  95. defence = -1;
  96. break;
  97. }
  98. }
  99. }
  100. double damage = 1;
  101. boolean critical = false;
  102. if (defence != -1)
  103. {
  104. double damageMultiplier = Formulas.calcWeaponTraitBonus(attacker, target) * Formulas.calcAttributeBonus(attacker, target, skill) * Formulas.calcGeneralTraitBonus(attacker, target, skill.getTraitType(), true);
  105. boolean ss = info.getSkill().useSoulShot() && attacker.isChargedShot(ShotType.SOULSHOTS);
  106. double ssBoost = ss ? 2 : 1.0;
  107. double weaponTypeBoost;
  108. L2Weapon weapon = attacker.getActiveWeaponItem();
  109. if ((weapon != null) && ((weapon.getItemType() == WeaponType.BOW) || (weapon.getItemType() == WeaponType.CROSSBOW)))
  110. {
  111. weaponTypeBoost = 70;
  112. }
  113. else
  114. {
  115. weaponTypeBoost = 77;
  116. }
  117. // charge count should be the count before casting the skill but since its reduced before calling effects
  118. // we add skill consume charges to current charges
  119. double energyChargesBoost = (((attacker.getCharges() + skill.getChargeConsume()) - 1) * 0.2) + 1;
  120. attack += _power;
  121. attack *= ssBoost;
  122. attack *= energyChargesBoost;
  123. attack *= weaponTypeBoost;
  124. damage = attack / defence;
  125. damage *= damageMultiplier;
  126. if (target instanceof L2PcInstance)
  127. {
  128. damage *= attacker.getStat().calcStat(Stats.PVP_PHYS_SKILL_DMG, 1.0);
  129. damage *= target.getStat().calcStat(Stats.PVP_PHYS_SKILL_DEF, 1.0);
  130. damage = attacker.getStat().calcStat(Stats.PHYSICAL_SKILL_POWER, damage);
  131. }
  132. critical = (BaseStats.STR.calcBonus(attacker) * _criticalChance) > (Rnd.nextDouble() * 100);
  133. if (critical)
  134. {
  135. damage *= 2;
  136. }
  137. }
  138. if (damage > 0)
  139. {
  140. attacker.sendDamageMessage(target, (int) damage, false, critical, false);
  141. target.reduceCurrentHp(damage, attacker, skill);
  142. target.notifyDamageReceived(damage, attacker, skill, critical, false);
  143. // Check if damage should be reflected
  144. Formulas.calcDamageReflected(attacker, target, skill, critical);
  145. }
  146. }
  147. }