Blow.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.handler.skillhandlers;
  16. import net.sf.l2j.gameserver.handler.ISkillHandler;
  17. import net.sf.l2j.gameserver.model.L2Character;
  18. import net.sf.l2j.gameserver.model.L2Effect;
  19. import net.sf.l2j.gameserver.model.L2ItemInstance;
  20. import net.sf.l2j.gameserver.model.L2Object;
  21. import net.sf.l2j.gameserver.model.L2Skill;
  22. import net.sf.l2j.gameserver.model.L2Summon;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2SummonInstance;
  25. import net.sf.l2j.gameserver.network.SystemMessageId;
  26. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  27. import net.sf.l2j.gameserver.skills.Env;
  28. import net.sf.l2j.gameserver.skills.Formulas;
  29. import net.sf.l2j.gameserver.skills.Stats;
  30. import net.sf.l2j.gameserver.skills.funcs.Func;
  31. import net.sf.l2j.gameserver.templates.L2SkillType;
  32. import net.sf.l2j.gameserver.templates.L2WeaponType;
  33. import net.sf.l2j.gameserver.util.Util;
  34. /**
  35. *
  36. * @author Steuf
  37. */
  38. public class Blow implements ISkillHandler
  39. {
  40. private static final L2SkillType[] SKILL_IDS =
  41. {
  42. L2SkillType.BLOW
  43. };
  44. private int _successChance;
  45. public final static int FRONT = 50;
  46. public final static int SIDE = 60;
  47. public final static int BEHIND = 70;
  48. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  49. {
  50. if (activeChar.isAlikeDead())
  51. return;
  52. for (int index = 0; index < targets.length; index++)
  53. {
  54. L2Character target = (L2Character) targets[index];
  55. if (target.isAlikeDead())
  56. continue;
  57. if (activeChar.isBehindTarget())
  58. _successChance = BEHIND;
  59. else if (activeChar.isInFrontOfTarget())
  60. _successChance = FRONT;
  61. else
  62. _successChance = SIDE;
  63. //If skill requires Crit or skill requires behind,
  64. //calculate chance based on DEX, Position and on self BUFF
  65. if (((skill.getCondition() & L2Skill.COND_BEHIND) != 0) && _successChance == BEHIND || ((skill.getCondition() & L2Skill.COND_CRIT) != 0) && Formulas.getInstance().calcBlow(activeChar, target, _successChance))
  66. {
  67. if (skill.hasEffects())
  68. {
  69. if (target.reflectSkill(skill))
  70. {
  71. activeChar.stopSkillEffects(skill.getId());
  72. skill.getEffects((L2Character) null, activeChar);
  73. SystemMessage sm = new SystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  74. sm.addSkillName(skill);
  75. activeChar.sendPacket(sm);
  76. }
  77. }
  78. L2ItemInstance weapon = activeChar.getActiveWeaponInstance();
  79. boolean soul = (weapon != null && weapon.getChargedSoulshot() == L2ItemInstance.CHARGED_SOULSHOT && weapon.getItemType() == L2WeaponType.DAGGER);
  80. boolean shld = Formulas.getInstance().calcShldUse(activeChar, target);
  81. // Crit rate base crit rate for skill, modified with STR bonus
  82. boolean crit = false;
  83. if (Formulas.getInstance().calcCrit(skill.getBaseCritRate() * 10 * Formulas.getInstance().getSTRBonus(activeChar)))
  84. crit = true;
  85. double damage = (int) Formulas.getInstance().calcBlowDamage(activeChar, target, skill, shld, soul);
  86. if (crit)
  87. {
  88. damage *= 2;
  89. // Vicious Stance is special after C5, and only for BLOW skills
  90. // Adds directly to damage
  91. L2Effect vicious = activeChar.getFirstEffect(312);
  92. if (vicious != null && damage > 1)
  93. {
  94. for (Func func : vicious.getStatFuncs())
  95. {
  96. Env env = new Env();
  97. env.player = activeChar;
  98. env.target = target;
  99. env.skill = skill;
  100. env.value = damage;
  101. func.calc(env);
  102. damage = (int) env.value;
  103. }
  104. }
  105. }
  106. if (soul)
  107. weapon.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  108. if (skill.getDmgDirectlyToHP() && target instanceof L2PcInstance)
  109. {
  110. L2PcInstance player = (L2PcInstance) target;
  111. if (!player.isInvul())
  112. {
  113. // Check and calculate transfered damage
  114. L2Summon summon = player.getPet();
  115. if (summon != null && summon instanceof L2SummonInstance && Util.checkIfInRange(900, player, summon, true))
  116. {
  117. int tDmg = (int)damage * (int)player.getStat().calcStat(Stats.TRANSFER_DAMAGE_PERCENT, 0, null, null) /100;
  118. // Only transfer dmg up to current HP, it should not be killed
  119. if (summon.getCurrentHp() < tDmg) tDmg = (int)summon.getCurrentHp() - 1;
  120. if (tDmg > 0)
  121. {
  122. summon.reduceCurrentHp(tDmg, activeChar );
  123. damage -= tDmg;
  124. }
  125. }
  126. if (damage >= player.getCurrentHp())
  127. {
  128. if (player.isInDuel())
  129. player.setCurrentHp(1);
  130. else
  131. {
  132. player.setCurrentHp(0);
  133. if (player.isInOlympiadMode())
  134. {
  135. player.abortAttack();
  136. player.abortCast();
  137. player.getStatus().stopHpMpRegeneration();
  138. player.setIsDead(true);
  139. player.setIsPendingRevive(true);
  140. }
  141. else
  142. player.doDie(activeChar);
  143. }
  144. }
  145. else
  146. player.setCurrentHp(player.getCurrentHp() - damage);
  147. }
  148. SystemMessage smsg = new SystemMessage(SystemMessageId.S1_RECEIVED_DAMAGE_OF_S3_FROM_S2);
  149. smsg.addPcName(player);
  150. smsg.addCharName(activeChar);
  151. smsg.addNumber((int)damage);
  152. player.sendPacket(smsg);
  153. }
  154. else
  155. target.reduceCurrentHp(damage, activeChar);
  156. // Manage attack or cast break of the target (calculating rate, sending message...)
  157. if (!target.isRaid() && Formulas.getInstance().calcAtkBreak(target, damage))
  158. {
  159. target.breakAttack();
  160. target.breakCast();
  161. }
  162. if(activeChar instanceof L2PcInstance)
  163. activeChar.sendPacket(new SystemMessage(SystemMessageId.S1_HAD_CRITICAL_HIT).addPcName((L2PcInstance)activeChar));
  164. SystemMessage sm = new SystemMessage(SystemMessageId.YOU_DID_S1_DMG);
  165. sm.addNumber((int) damage);
  166. activeChar.sendPacket(sm);
  167. }
  168. //Possibility of a lethal strike
  169. Formulas.getInstance().calcLethalHit(activeChar, target, skill);
  170. L2Effect effect = activeChar.getFirstEffect(skill.getId());
  171. //Self Effect
  172. if (effect != null && effect.isSelfEffect())
  173. effect.exit();
  174. skill.getEffectsSelf(activeChar);
  175. }
  176. }
  177. public L2SkillType[] getSkillIds()
  178. {
  179. return SKILL_IDS;
  180. }
  181. }