StrSiegeAssault.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 com.l2jserver.gameserver.handler.ISkillHandler;
  17. import com.l2jserver.gameserver.instancemanager.CastleManager;
  18. import com.l2jserver.gameserver.instancemanager.FortManager;
  19. import com.l2jserver.gameserver.model.L2ItemInstance;
  20. import com.l2jserver.gameserver.model.L2Object;
  21. import com.l2jserver.gameserver.model.L2Skill;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.entity.Castle;
  26. import com.l2jserver.gameserver.model.entity.Fort;
  27. import com.l2jserver.gameserver.skills.Formulas;
  28. import com.l2jserver.gameserver.templates.item.L2WeaponType;
  29. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  30. /**
  31. * @author _tomciaaa_
  32. *
  33. */
  34. public class StrSiegeAssault implements ISkillHandler
  35. {
  36. private static final L2SkillType[] SKILL_IDS =
  37. {
  38. L2SkillType.STRSIEGEASSAULT
  39. };
  40. /**
  41. *
  42. * @see com.l2jserver.gameserver.handler.ISkillHandler#useSkill(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.L2Skill, com.l2jserver.gameserver.model.L2Object[])
  43. */
  44. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  45. {
  46. if (!(activeChar instanceof L2PcInstance))
  47. return;
  48. L2PcInstance player = (L2PcInstance) activeChar;
  49. if (!player.isRidingStrider())
  50. return;
  51. if (!(player.getTarget() instanceof L2DoorInstance))
  52. return;
  53. Castle castle = CastleManager.getInstance().getCastle(player);
  54. Fort fort = FortManager.getInstance().getFort(player);
  55. if ((castle == null) && (fort == null))
  56. return;
  57. if (castle != null)
  58. {
  59. if (!player.checkIfOkToUseStriderSiegeAssault(castle))
  60. return;
  61. }
  62. else
  63. {
  64. if (!player.checkIfOkToUseStriderSiegeAssault(fort))
  65. return;
  66. }
  67. try
  68. {
  69. // damage calculation
  70. int damage = 0;
  71. for (L2Character target: (L2Character[]) targets)
  72. {
  73. L2ItemInstance weapon = activeChar.getActiveWeaponInstance();
  74. if (activeChar instanceof L2PcInstance && target instanceof L2PcInstance && ((L2PcInstance)target).isFakeDeath())
  75. {
  76. target.stopFakeDeath(true);
  77. }
  78. else if (target.isDead())
  79. continue;
  80. boolean dual = activeChar.isUsingDualWeapon();
  81. byte shld = Formulas.calcShldUse(activeChar, target, skill);
  82. boolean crit = Formulas.calcCrit(activeChar.getCriticalHit(target, skill), true, target);
  83. boolean soul = (weapon != null && weapon.getChargedSoulshot() == L2ItemInstance.CHARGED_SOULSHOT && weapon.getItemType() != L2WeaponType.DAGGER);
  84. if (!crit && (skill.getCondition() & L2Skill.COND_CRIT) != 0)
  85. damage = 0;
  86. else
  87. damage = skill.isStaticDamage() ? (int)skill.getPower() : (int) Formulas.calcPhysDam(activeChar, target, skill, shld, crit, dual, soul);
  88. if (damage > 0)
  89. {
  90. target.reduceCurrentHp(damage, activeChar, skill);
  91. if (soul && weapon != null)
  92. weapon.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  93. activeChar.sendDamageMessage(target, damage, false, false, false);
  94. }
  95. else
  96. activeChar.sendMessage(skill.getName() + " failed.");
  97. }
  98. }
  99. catch (Exception e)
  100. {
  101. player.sendMessage("Error using siege assault:" + e);
  102. }
  103. }
  104. /**
  105. *
  106. * @see com.l2jserver.gameserver.handler.ISkillHandler#getSkillIds()
  107. */
  108. public L2SkillType[] getSkillIds()
  109. {
  110. return SKILL_IDS;
  111. }
  112. public static void main(String[] args)
  113. {
  114. new StrSiegeAssault();
  115. }
  116. }