Blow.java 7.3 KB

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