Blow.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (C) 2004-2013 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.skillhandlers;
  20. import java.util.logging.Level;
  21. import java.util.logging.LogRecord;
  22. import java.util.logging.Logger;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.handler.ISkillHandler;
  25. import com.l2jserver.gameserver.model.L2Object;
  26. import com.l2jserver.gameserver.model.ShotType;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.effects.L2Effect;
  30. import com.l2jserver.gameserver.model.skills.L2Skill;
  31. import com.l2jserver.gameserver.model.skills.L2SkillType;
  32. import com.l2jserver.gameserver.model.stats.BaseStats;
  33. import com.l2jserver.gameserver.model.stats.Env;
  34. import com.l2jserver.gameserver.model.stats.Formulas;
  35. import com.l2jserver.gameserver.network.SystemMessageId;
  36. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  37. /**
  38. * @author Steuf
  39. */
  40. public class Blow implements ISkillHandler
  41. {
  42. private static final Logger _logDamage = Logger.getLogger("damage");
  43. private static final L2SkillType[] SKILL_IDS =
  44. {
  45. L2SkillType.BLOW
  46. };
  47. @Override
  48. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  49. {
  50. if (activeChar.isAlikeDead())
  51. {
  52. return;
  53. }
  54. boolean ss = skill.useSoulShot() && activeChar.isChargedShot(ShotType.SOULSHOTS);
  55. boolean sps = skill.useSpiritShot() && activeChar.isChargedShot(ShotType.SPIRITSHOTS);
  56. boolean bss = skill.useSpiritShot() && activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS);
  57. for (L2Character target : (L2Character[]) targets)
  58. {
  59. if (target.isAlikeDead())
  60. {
  61. continue;
  62. }
  63. // Check firstly if target dodges skill
  64. final boolean skillIsEvaded = Formulas.calcPhysicalSkillEvasion(target, skill);
  65. if (!skillIsEvaded && Formulas.calcBlowSuccess(activeChar, target, skill))
  66. {
  67. final byte reflect = Formulas.calcSkillReflect(target, skill);
  68. if (skill.hasEffects())
  69. {
  70. if (reflect == Formulas.SKILL_REFLECT_SUCCEED)
  71. {
  72. activeChar.stopSkillEffects(skill.getId());
  73. skill.getEffects(target, activeChar);
  74. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  75. sm.addSkillName(skill);
  76. activeChar.sendPacket(sm);
  77. }
  78. else
  79. {
  80. final byte shld = Formulas.calcShldUse(activeChar, target, skill);
  81. target.stopSkillEffects(skill.getId());
  82. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  83. {
  84. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  85. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  86. sm.addSkillName(skill);
  87. target.sendPacket(sm);
  88. }
  89. else
  90. {
  91. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  92. sm.addCharName(target);
  93. sm.addSkillName(skill);
  94. activeChar.sendPacket(sm);
  95. }
  96. }
  97. }
  98. byte shld = Formulas.calcShldUse(activeChar, target, skill);
  99. double damage = skill.isStaticDamage() ? skill.getPower() : (int) Formulas.calcBlowDamage(activeChar, target, skill, shld, ss);
  100. if (!skill.isStaticDamage() && (skill.getMaxSoulConsumeCount() > 0) && activeChar.isPlayer())
  101. {
  102. // Souls Formula (each soul increase +4%)
  103. int chargedSouls = (activeChar.getActingPlayer().getSouls() <= skill.getMaxSoulConsumeCount()) ? activeChar.getActingPlayer().getSouls() : skill.getMaxSoulConsumeCount();
  104. damage *= 1 + (chargedSouls * 0.04);
  105. }
  106. // Crit rate base crit rate for skill, modified with STR bonus
  107. if (!skill.isStaticDamage() && Formulas.calcCrit(skill.getBaseCritRate() * 10 * BaseStats.STR.calcBonus(activeChar), true, target))
  108. {
  109. damage *= 2;
  110. }
  111. if (Config.LOG_GAME_DAMAGE && activeChar.isPlayable() && (damage > Config.LOG_GAME_DAMAGE_THRESHOLD))
  112. {
  113. LogRecord record = new LogRecord(Level.INFO, "");
  114. record.setParameters(new Object[]
  115. {
  116. activeChar,
  117. " did damage ",
  118. (int) damage,
  119. skill,
  120. " to ",
  121. target
  122. });
  123. record.setLoggerName("pdam");
  124. _logDamage.log(record);
  125. }
  126. target.reduceCurrentHp(damage, activeChar, skill);
  127. // vengeance reflected damage
  128. if ((reflect & Formulas.SKILL_REFLECT_VENGEANCE) != 0)
  129. {
  130. if (target.isPlayer())
  131. {
  132. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.COUNTERED_C1_ATTACK);
  133. sm.addCharName(activeChar);
  134. target.sendPacket(sm);
  135. }
  136. if (activeChar.isPlayer())
  137. {
  138. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_PERFORMING_COUNTERATTACK);
  139. sm.addCharName(target);
  140. activeChar.sendPacket(sm);
  141. }
  142. // Formula from Diego Vargas post: http://www.l2guru.com/forum/showthread.php?p=3122630
  143. // 1189 x Your PATK / PDEF of target
  144. double vegdamage = ((1189 * target.getPAtk(activeChar)) / activeChar.getPDef(target));
  145. activeChar.reduceCurrentHp(vegdamage, target, skill);
  146. }
  147. // Manage attack or cast break of the target (calculating rate, sending message...)
  148. if (!target.isRaid() && Formulas.calcAtkBreak(target, damage))
  149. {
  150. target.breakAttack();
  151. target.breakCast();
  152. }
  153. if (activeChar.isPlayer())
  154. {
  155. L2PcInstance activePlayer = activeChar.getActingPlayer();
  156. activePlayer.sendDamageMessage(target, (int) damage, false, true, false);
  157. }
  158. }
  159. // Sending system messages
  160. if (skillIsEvaded)
  161. {
  162. if (activeChar.isPlayer())
  163. {
  164. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DODGES_ATTACK);
  165. sm.addString(target.getName());
  166. activeChar.getActingPlayer().sendPacket(sm);
  167. }
  168. if (target.isPlayer())
  169. {
  170. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AVOIDED_C1_ATTACK);
  171. sm.addString(activeChar.getName());
  172. target.getActingPlayer().sendPacket(sm);
  173. }
  174. }
  175. // Possibility of a lethal strike
  176. Formulas.calcLethalHit(activeChar, target, skill);
  177. // Self Effect
  178. if (skill.hasSelfEffects())
  179. {
  180. final L2Effect effect = activeChar.getFirstEffect(skill.getId());
  181. if ((effect != null) && effect.isSelfEffect())
  182. {
  183. effect.exit();
  184. }
  185. skill.getEffectsSelf(activeChar);
  186. }
  187. activeChar.setChargedShot(ShotType.SOULSHOTS, false);
  188. }
  189. }
  190. @Override
  191. public L2SkillType[] getSkillIds()
  192. {
  193. return SKILL_IDS;
  194. }
  195. }