Pdam.java 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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.datatables.SkillTable;
  21. import com.l2jserver.gameserver.handler.ISkillHandler;
  22. import com.l2jserver.gameserver.model.L2Effect;
  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.L2Summon;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.item.instance.L2ItemInstance;
  30. import com.l2jserver.gameserver.model.item.type.L2WeaponType;
  31. import com.l2jserver.gameserver.network.SystemMessageId;
  32. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  33. import com.l2jserver.gameserver.skills.BaseStats;
  34. import com.l2jserver.gameserver.skills.Env;
  35. import com.l2jserver.gameserver.skills.Formulas;
  36. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  37. public class Pdam implements ISkillHandler
  38. {
  39. private static final Logger _log = Logger.getLogger(Pdam.class.getName());
  40. private static final Logger _logDamage = Logger.getLogger("damage");
  41. private static final L2SkillType[] SKILL_IDS =
  42. {
  43. L2SkillType.PDAM, L2SkillType.FATAL
  44. };
  45. /**
  46. *
  47. * @see com.l2jserver.gameserver.handler.ISkillHandler#useSkill(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.L2Skill, com.l2jserver.gameserver.model.L2Object[])
  48. */
  49. @Override
  50. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  51. {
  52. if (activeChar.isAlikeDead())
  53. return;
  54. int damage = 0;
  55. if (Config.DEBUG)
  56. {
  57. _log.fine("Begin Skill processing in Pdam.java " + skill.getSkillType());
  58. }
  59. L2ItemInstance weapon = activeChar.getActiveWeaponInstance();
  60. boolean soul = (weapon != null && weapon.getChargedSoulshot() == L2ItemInstance.CHARGED_SOULSHOT && weapon.getItemType() != L2WeaponType.DAGGER);
  61. // If there is no weapon equipped, check for an active summon.
  62. if (weapon == null && activeChar instanceof L2Summon)
  63. {
  64. L2Summon activeSummon = (L2Summon) activeChar;
  65. if (activeSummon.getChargedSoulShot() == L2ItemInstance.CHARGED_SOULSHOT)
  66. {
  67. soul = true;
  68. activeSummon.setChargedSoulShot(L2ItemInstance.CHARGED_NONE);
  69. }
  70. }
  71. for (L2Character target: (L2Character[]) targets)
  72. {
  73. if (activeChar instanceof L2PcInstance && target instanceof L2PcInstance && ((L2PcInstance)target).isFakeDeath())
  74. {
  75. target.stopFakeDeath(true);
  76. }
  77. else if (target.isDead())
  78. continue;
  79. final boolean dual = activeChar.isUsingDualWeapon();
  80. final byte shld = Formulas.calcShldUse(activeChar, target, skill);
  81. // PDAM critical chance not affected by buffs, only by STR. Only some skills are meant to crit.
  82. boolean crit = false;
  83. if (!skill.isStaticDamage() && skill.getBaseCritRate() > 0)
  84. crit = Formulas.calcCrit(skill.getBaseCritRate() * 10 * BaseStats.STR.calcBonus(activeChar), true, target);
  85. if (!crit && (skill.getCondition() & L2Skill.COND_CRIT) != 0)
  86. damage = 0;
  87. else
  88. damage = skill.isStaticDamage() ? (int)skill.getPower() : (int) Formulas.calcPhysDam(activeChar, target, skill, shld, false, dual, soul);
  89. if (!skill.isStaticDamage() && skill.getMaxSoulConsumeCount() > 0 && activeChar instanceof L2PcInstance)
  90. {
  91. switch (((L2PcInstance) activeChar).getSouls())
  92. {
  93. case 0:
  94. break;
  95. case 1:
  96. damage *= 1.10;
  97. break;
  98. case 2:
  99. damage *= 1.12;
  100. break;
  101. case 3:
  102. damage *= 1.15;
  103. break;
  104. case 4:
  105. damage *= 1.18;
  106. break;
  107. default:
  108. damage *= 1.20;
  109. break;
  110. }
  111. }
  112. if (crit)
  113. damage *= 2; // PDAM Critical damage always 2x and not affected by buffs
  114. final boolean skillIsEvaded = Formulas.calcPhysicalSkillEvasion(target, skill);
  115. final byte reflect = Formulas.calcSkillReflect(target, skill);
  116. if (!skillIsEvaded)
  117. {
  118. if (skill.hasEffects())
  119. {
  120. L2Effect[] effects;
  121. if ((reflect & Formulas.SKILL_REFLECT_SUCCEED) != 0)
  122. {
  123. activeChar.stopSkillEffects(skill.getId());
  124. effects = skill.getEffects(target, activeChar);
  125. if (effects != null && effects.length > 0)
  126. {
  127. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  128. sm.addSkillName(skill);
  129. activeChar.sendPacket(sm);
  130. }
  131. }
  132. else
  133. {
  134. // activate attacked effects, if any
  135. target.stopSkillEffects(skill.getId());
  136. effects = skill.getEffects(activeChar, target, new Env(shld, false, false, false));
  137. if (effects != null && effects.length > 0)
  138. {
  139. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  140. sm.addSkillName(skill);
  141. target.sendPacket(sm);
  142. }
  143. }
  144. }
  145. if (damage > 0)
  146. {
  147. activeChar.sendDamageMessage(target, damage, false, crit, false);
  148. if (Config.LOG_GAME_DAMAGE
  149. && activeChar instanceof L2Playable
  150. && damage > Config.LOG_GAME_DAMAGE_THRESHOLD)
  151. {
  152. LogRecord record = new LogRecord(Level.INFO, "");
  153. record.setParameters(new Object[]{activeChar, " did damage ", damage, skill, " to ", target});
  154. record.setLoggerName("pdam");
  155. _logDamage.log(record);
  156. }
  157. // Possibility of a lethal strike
  158. Formulas.calcLethalHit(activeChar, target, skill);
  159. target.reduceCurrentHp(damage, activeChar, skill);
  160. // vengeance reflected damage
  161. if ((reflect & Formulas.SKILL_REFLECT_VENGEANCE) != 0)
  162. {
  163. if (target instanceof L2PcInstance)
  164. {
  165. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.COUNTERED_C1_ATTACK);
  166. sm.addCharName(activeChar);
  167. target.sendPacket(sm);
  168. }
  169. if (activeChar instanceof L2PcInstance)
  170. {
  171. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_PERFORMING_COUNTERATTACK);
  172. sm.addCharName(target);
  173. activeChar.sendPacket(sm);
  174. }
  175. // Formula from Diego post, 700 from rpg tests
  176. double vegdamage = (700 * target.getPAtk(activeChar) / activeChar.getPDef(target));
  177. activeChar.reduceCurrentHp(vegdamage, target, skill);
  178. }
  179. }
  180. else // No damage
  181. activeChar.sendPacket(SystemMessageId.ATTACK_FAILED);
  182. }
  183. else
  184. {
  185. if (activeChar instanceof L2PcInstance)
  186. {
  187. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DODGES_ATTACK);
  188. sm.addString(target.getName());
  189. ((L2PcInstance) activeChar).sendPacket(sm);
  190. }
  191. if (target instanceof L2PcInstance)
  192. {
  193. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AVOIDED_C1_ATTACK);
  194. sm.addString(activeChar.getName());
  195. ((L2PcInstance) target).sendPacket(sm);
  196. }
  197. // Possibility of a lethal strike despite skill is evaded
  198. Formulas.calcLethalHit(activeChar, target, skill);
  199. }
  200. if (activeChar instanceof L2PcInstance)
  201. {
  202. int soulMasteryLevel = activeChar.getSkillLevel(467);
  203. if (soulMasteryLevel > 0)
  204. {
  205. L2Skill soulmastery = SkillTable.getInstance().getInfo(467, soulMasteryLevel);
  206. if (soulmastery != null)
  207. {
  208. if (((L2PcInstance) activeChar).getSouls() < soulmastery.getNumSouls())
  209. {
  210. int count = 0;
  211. if (((L2PcInstance) activeChar).getSouls() + skill.getNumSouls() <= soulmastery.getNumSouls())
  212. count = skill.getNumSouls();
  213. else
  214. count = soulmastery.getNumSouls() - ((L2PcInstance) activeChar).getSouls();
  215. ((L2PcInstance) activeChar).increaseSouls(count);
  216. }
  217. else
  218. {
  219. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.SOUL_CANNOT_BE_INCREASED_ANYMORE);
  220. ((L2PcInstance) activeChar).sendPacket(sm);
  221. }
  222. }
  223. }
  224. }
  225. }
  226. //self Effect :]
  227. if (skill.hasSelfEffects())
  228. {
  229. final L2Effect effect = activeChar.getFirstEffect(skill.getId());
  230. if (effect != null && effect.isSelfEffect())
  231. {
  232. //Replace old effect with new one.
  233. effect.exit();
  234. }
  235. skill.getEffectsSelf(activeChar);
  236. }
  237. if (soul && weapon != null)
  238. weapon.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  239. if (skill.isSuicideAttack())
  240. activeChar.doDie(activeChar);
  241. }
  242. /**
  243. *
  244. * @see com.l2jserver.gameserver.handler.ISkillHandler#getSkillIds()
  245. */
  246. @Override
  247. public L2SkillType[] getSkillIds()
  248. {
  249. return SKILL_IDS;
  250. }
  251. }