Blow.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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.model.olympiad.Olympiad;
  17. import net.sf.l2j.gameserver.ai.CtrlIntention;
  18. import net.sf.l2j.gameserver.handler.ISkillHandler;
  19. import net.sf.l2j.gameserver.model.L2Character;
  20. import net.sf.l2j.gameserver.model.L2Effect;
  21. import net.sf.l2j.gameserver.model.L2ItemInstance;
  22. import net.sf.l2j.gameserver.model.L2Object;
  23. import net.sf.l2j.gameserver.model.L2Skill;
  24. import net.sf.l2j.gameserver.model.L2Summon;
  25. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  26. import net.sf.l2j.gameserver.model.actor.instance.L2SummonInstance;
  27. import net.sf.l2j.gameserver.network.SystemMessageId;
  28. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  29. import net.sf.l2j.gameserver.skills.Env;
  30. import net.sf.l2j.gameserver.skills.Formulas;
  31. import net.sf.l2j.gameserver.skills.Stats;
  32. import net.sf.l2j.gameserver.skills.funcs.Func;
  33. import net.sf.l2j.gameserver.templates.item.L2WeaponType;
  34. import net.sf.l2j.gameserver.templates.skills.L2SkillType;
  35. import net.sf.l2j.gameserver.util.Util;
  36. /**
  37. *
  38. * @author Steuf
  39. */
  40. public class Blow implements ISkillHandler
  41. {
  42. private static final L2SkillType[] SKILL_IDS =
  43. {
  44. L2SkillType.BLOW
  45. };
  46. public final static byte FRONT = 50;
  47. public final static byte SIDE = 60;
  48. public final static byte BEHIND = 70;
  49. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  50. {
  51. if (activeChar.isAlikeDead())
  52. return;
  53. for (L2Character target: (L2Character[]) targets)
  54. {
  55. if (target.isAlikeDead())
  56. continue;
  57. // Check firstly if target dodges skill
  58. boolean skillIsEvaded = Formulas.getInstance().calcPhysicalSkillEvasion(target, skill);
  59. byte _successChance = SIDE;
  60. if (activeChar.isBehindTarget())
  61. _successChance = BEHIND;
  62. else if (activeChar.isInFrontOfTarget())
  63. _successChance = FRONT;
  64. //If skill requires Crit or skill requires behind,
  65. //calculate chance based on DEX, Position and on self BUFF
  66. boolean success = true;
  67. if ((skill.getCondition() & L2Skill.COND_BEHIND) != 0)
  68. success = (_successChance == BEHIND);
  69. if ((skill.getCondition() & L2Skill.COND_CRIT) != 0)
  70. success = (success && Formulas.getInstance().calcBlow(activeChar, target, _successChance));
  71. if (!skillIsEvaded && success)
  72. {
  73. if (skill.hasEffects())
  74. {
  75. if (target.reflectSkill(skill))
  76. {
  77. activeChar.stopSkillEffects(skill.getId());
  78. skill.getEffects(target, activeChar);
  79. SystemMessage sm = new SystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  80. sm.addSkillName(skill);
  81. activeChar.sendPacket(sm);
  82. }
  83. }
  84. L2ItemInstance weapon = activeChar.getActiveWeaponInstance();
  85. boolean soul = (weapon != null && weapon.getChargedSoulshot() == L2ItemInstance.CHARGED_SOULSHOT && weapon.getItemType() == L2WeaponType.DAGGER);
  86. byte shld = Formulas.getInstance().calcShldUse(activeChar, target);
  87. // Crit rate base crit rate for skill, modified with STR bonus
  88. boolean crit = false;
  89. if (Formulas.getInstance().calcCrit(skill.getBaseCritRate() * 10 * Formulas.getInstance().getSTRBonus(activeChar)))
  90. crit = true;
  91. double damage = (int) Formulas.getInstance().calcBlowDamage(activeChar, target, skill, shld, soul);
  92. if (crit)
  93. {
  94. damage *= 2;
  95. // Vicious Stance is special after C5, and only for BLOW skills
  96. // Adds directly to damage
  97. L2Effect vicious = activeChar.getFirstEffect(312);
  98. if (vicious != null && damage > 1)
  99. {
  100. for (Func func : vicious.getStatFuncs())
  101. {
  102. Env env = new Env();
  103. env.player = activeChar;
  104. env.target = target;
  105. env.skill = skill;
  106. env.value = damage;
  107. func.calc(env);
  108. damage = (int) env.value;
  109. }
  110. }
  111. }
  112. if (soul)
  113. weapon.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  114. if (skill.getDmgDirectlyToHP() && target instanceof L2PcInstance)
  115. {
  116. L2PcInstance player = (L2PcInstance) target;
  117. if (!player.isInvul())
  118. {
  119. // Check and calculate transfered damage
  120. L2Summon summon = player.getPet();
  121. if (summon != null && summon instanceof L2SummonInstance && Util.checkIfInRange(900, player, summon, true))
  122. {
  123. int tDmg = (int)damage * (int)player.getStat().calcStat(Stats.TRANSFER_DAMAGE_PERCENT, 0, null, null) /100;
  124. // Only transfer dmg up to current HP, it should not be killed
  125. if (summon.getCurrentHp() < tDmg) tDmg = (int)summon.getCurrentHp() - 1;
  126. if (tDmg > 0)
  127. {
  128. summon.reduceCurrentHp(tDmg, activeChar ,skill);
  129. damage -= tDmg;
  130. }
  131. }
  132. if (damage >= player.getCurrentHp())
  133. {
  134. if (player.isInDuel())
  135. player.setCurrentHp(1);
  136. else
  137. {
  138. player.setCurrentHp(0);
  139. if (player.isInOlympiadMode())
  140. {
  141. player.abortAttack();
  142. player.abortCast();
  143. player.getStatus().stopHpMpRegeneration();
  144. player.setIsDead(true);
  145. player.setIsPendingRevive(true);
  146. if (player.getPet() != null)
  147. player.getPet().getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null);
  148. }
  149. else
  150. player.doDie(activeChar);
  151. }
  152. }
  153. else
  154. player.setCurrentHp(player.getCurrentHp() - damage);
  155. }
  156. SystemMessage smsg = new SystemMessage(SystemMessageId.S1_RECEIVED_DAMAGE_OF_S3_FROM_S2);
  157. smsg.addPcName(player);
  158. smsg.addCharName(activeChar);
  159. smsg.addNumber((int)damage);
  160. player.sendPacket(smsg);
  161. }
  162. else
  163. target.reduceCurrentHp(damage, activeChar, skill);
  164. // Manage attack or cast break of the target (calculating rate, sending message...)
  165. if (!target.isRaid() && Formulas.getInstance().calcAtkBreak(target, damage))
  166. {
  167. target.breakAttack();
  168. target.breakCast();
  169. }
  170. if(activeChar instanceof L2PcInstance)
  171. {
  172. L2PcInstance activePlayer = (L2PcInstance) activeChar;
  173. activePlayer.sendPacket(new SystemMessage(SystemMessageId.S1_HAD_CRITICAL_HIT).addPcName(activePlayer));
  174. SystemMessage sm = new SystemMessage(SystemMessageId.YOU_DID_S1_DMG);
  175. sm.addNumber((int) damage);
  176. activePlayer.sendPacket(sm);
  177. if (activePlayer.isInOlympiadMode() &&
  178. target instanceof L2PcInstance &&
  179. ((L2PcInstance)target).isInOlympiadMode() &&
  180. ((L2PcInstance)target).getOlympiadGameId() == activePlayer.getOlympiadGameId())
  181. {
  182. Olympiad.getInstance().notifyCompetitorDamage(activePlayer, (int) damage, activePlayer.getOlympiadGameId());
  183. }
  184. }
  185. }
  186. // Sending system messages
  187. if (skillIsEvaded)
  188. {
  189. if (activeChar instanceof L2PcInstance)
  190. {
  191. SystemMessage sm = new SystemMessage(SystemMessageId.S1_DODGES_ATTACK);
  192. sm.addString(target.getName());
  193. ((L2PcInstance) activeChar).sendPacket(sm);
  194. }
  195. if (target instanceof L2PcInstance)
  196. {
  197. SystemMessage sm = new SystemMessage(SystemMessageId.AVOIDED_S1_ATTACK);
  198. sm.addString(activeChar.getName());
  199. ((L2PcInstance) target).sendPacket(sm);
  200. }
  201. }
  202. //Possibility of a lethal strike
  203. Formulas.getInstance().calcLethalHit(activeChar, target, skill);
  204. L2Effect effect = activeChar.getFirstEffect(skill.getId());
  205. //Self Effect
  206. if (effect != null && effect.isSelfEffect())
  207. effect.exit();
  208. skill.getEffectsSelf(activeChar);
  209. }
  210. }
  211. public L2SkillType[] getSkillIds()
  212. {
  213. return SKILL_IDS;
  214. }
  215. }