Pdam.java 9.4 KB

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