Pdam.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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.datatables.SkillTable;
  25. import com.l2jserver.gameserver.handler.ISkillHandler;
  26. import com.l2jserver.gameserver.model.L2Object;
  27. import com.l2jserver.gameserver.model.ShotType;
  28. import com.l2jserver.gameserver.model.actor.L2Character;
  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. public class Pdam implements ISkillHandler
  38. {
  39. private static final Logger _logDamage = Logger.getLogger("damage");
  40. private static final L2SkillType[] SKILL_IDS =
  41. {
  42. L2SkillType.PDAM,
  43. L2SkillType.FATAL
  44. };
  45. @Override
  46. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  47. {
  48. if (activeChar.isAlikeDead())
  49. {
  50. return;
  51. }
  52. if (((skill.getFlyRadius() > 0) || (skill.getFlyType() != null)) && activeChar.isMovementDisabled())
  53. {
  54. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  55. sm.addSkillName(skill);
  56. activeChar.sendPacket(sm);
  57. return;
  58. }
  59. int damage = 0;
  60. boolean ss = skill.useSoulShot() && activeChar.isChargedShot(ShotType.SOULSHOTS);
  61. for (L2Character target : (L2Character[]) targets)
  62. {
  63. if (activeChar.isPlayer() && target.isPlayer() && target.getActingPlayer().isFakeDeath())
  64. {
  65. target.stopFakeDeath(true);
  66. }
  67. else if (target.isDead())
  68. {
  69. continue;
  70. }
  71. final boolean dual = activeChar.isUsingDualWeapon();
  72. final byte shld = Formulas.calcShldUse(activeChar, target, skill);
  73. // PDAM critical chance not affected by buffs, only by STR. Only some skills are meant to crit.
  74. boolean crit = false;
  75. if (!skill.isStaticDamage() && (skill.getBaseCritRate() > 0))
  76. {
  77. crit = Formulas.calcCrit(skill.getBaseCritRate() * 10 * BaseStats.STR.calcBonus(activeChar), true, target);
  78. }
  79. if (!crit && ((skill.getCondition() & L2Skill.COND_CRIT) != 0))
  80. {
  81. damage = 0;
  82. }
  83. else
  84. {
  85. damage = skill.isStaticDamage() ? (int) skill.getPower() : (int) Formulas.calcPhysDam(activeChar, target, skill, shld, false, dual, ss);
  86. }
  87. if (!skill.isStaticDamage() && (skill.getMaxSoulConsumeCount() > 0) && activeChar.isPlayer())
  88. {
  89. // Souls Formula (each soul increase +4%)
  90. int chargedSouls = (activeChar.getActingPlayer().getChargedSouls() <= skill.getMaxSoulConsumeCount()) ? activeChar.getActingPlayer().getChargedSouls() : skill.getMaxSoulConsumeCount();
  91. damage *= 1 + (chargedSouls * 0.04);
  92. }
  93. if (crit)
  94. {
  95. damage *= 2; // PDAM Critical damage always 2x and not affected by buffs
  96. }
  97. final boolean skillIsEvaded = Formulas.calcPhysicalSkillEvasion(target, skill);
  98. final byte reflect = Formulas.calcSkillReflect(target, skill);
  99. if (!skillIsEvaded)
  100. {
  101. if (skill.hasEffects())
  102. {
  103. L2Effect[] effects;
  104. if ((reflect & Formulas.SKILL_REFLECT_SUCCEED) != 0)
  105. {
  106. activeChar.stopSkillEffects(skill.getId());
  107. effects = skill.getEffects(target, activeChar);
  108. if ((effects != null) && (effects.length > 0))
  109. {
  110. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  111. sm.addSkillName(skill);
  112. activeChar.sendPacket(sm);
  113. }
  114. }
  115. else
  116. {
  117. // activate attacked effects, if any
  118. target.stopSkillEffects(skill.getId());
  119. effects = skill.getEffects(activeChar, target, new Env(shld, false, false, false));
  120. if ((effects != null) && (effects.length > 0))
  121. {
  122. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  123. sm.addSkillName(skill);
  124. target.sendPacket(sm);
  125. }
  126. }
  127. }
  128. if (damage > 0)
  129. {
  130. activeChar.sendDamageMessage(target, damage, false, crit, false);
  131. if (Config.LOG_GAME_DAMAGE && activeChar.isPlayable() && (damage > Config.LOG_GAME_DAMAGE_THRESHOLD))
  132. {
  133. LogRecord record = new LogRecord(Level.INFO, "");
  134. record.setParameters(new Object[]
  135. {
  136. activeChar,
  137. " did damage ",
  138. damage,
  139. skill,
  140. " to ",
  141. target
  142. });
  143. record.setLoggerName("pdam");
  144. _logDamage.log(record);
  145. }
  146. // Possibility of a lethal strike
  147. Formulas.calcLethalHit(activeChar, target, skill);
  148. target.reduceCurrentHp(damage, activeChar, skill);
  149. // vengeance reflected damage
  150. if ((reflect & Formulas.SKILL_REFLECT_VENGEANCE) != 0)
  151. {
  152. if (target.isPlayer())
  153. {
  154. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.COUNTERED_C1_ATTACK);
  155. sm.addCharName(activeChar);
  156. target.sendPacket(sm);
  157. }
  158. if (activeChar.isPlayer())
  159. {
  160. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_PERFORMING_COUNTERATTACK);
  161. sm.addCharName(target);
  162. activeChar.sendPacket(sm);
  163. }
  164. // Formula from Diego Vargas post: http://www.l2guru.com/forum/showthread.php?p=3122630
  165. // 1189 x Your PATK / PDEF of target
  166. double vegdamage = ((1189 * target.getPAtk(activeChar)) / activeChar.getPDef(target));
  167. activeChar.reduceCurrentHp(vegdamage, target, skill);
  168. }
  169. }
  170. else
  171. {
  172. // No damage
  173. activeChar.sendPacket(SystemMessageId.ATTACK_FAILED);
  174. }
  175. }
  176. else
  177. {
  178. if (activeChar.isPlayer())
  179. {
  180. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DODGES_ATTACK);
  181. sm.addString(target.getName());
  182. activeChar.getActingPlayer().sendPacket(sm);
  183. }
  184. if (target.isPlayer())
  185. {
  186. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AVOIDED_C1_ATTACK);
  187. sm.addString(activeChar.getName());
  188. target.getActingPlayer().sendPacket(sm);
  189. }
  190. // Possibility of a lethal strike despite skill is evaded
  191. Formulas.calcLethalHit(activeChar, target, skill);
  192. }
  193. if (activeChar.isPlayer())
  194. {
  195. int soulMasteryLevel = activeChar.getSkillLevel(467);
  196. if (soulMasteryLevel > 0)
  197. {
  198. L2Skill soulmastery = SkillTable.getInstance().getInfo(467, soulMasteryLevel);
  199. if (soulmastery != null)
  200. {
  201. if (activeChar.getActingPlayer().getChargedSouls() < soulmastery.getNumSouls())
  202. {
  203. int count = 0;
  204. if ((activeChar.getActingPlayer().getChargedSouls() + skill.getNumSouls()) <= soulmastery.getNumSouls())
  205. {
  206. count = skill.getNumSouls();
  207. }
  208. else
  209. {
  210. count = soulmastery.getNumSouls() - activeChar.getActingPlayer().getChargedSouls();
  211. }
  212. activeChar.getActingPlayer().increaseSouls(count);
  213. }
  214. else
  215. {
  216. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.SOUL_CANNOT_BE_INCREASED_ANYMORE);
  217. activeChar.getActingPlayer().sendPacket(sm);
  218. }
  219. }
  220. }
  221. }
  222. }
  223. // self Effect :]
  224. if (skill.hasSelfEffects())
  225. {
  226. final L2Effect effect = activeChar.getFirstEffect(skill.getId());
  227. if ((effect != null) && effect.isSelfEffect())
  228. {
  229. // Replace old effect with new one.
  230. effect.exit();
  231. }
  232. skill.getEffectsSelf(activeChar);
  233. }
  234. activeChar.setChargedShot(ShotType.SOULSHOTS, false);
  235. if (skill.isSuicideAttack())
  236. {
  237. activeChar.doDie(activeChar);
  238. }
  239. }
  240. @Override
  241. public L2SkillType[] getSkillIds()
  242. {
  243. return SKILL_IDS;
  244. }
  245. }