StrSiegeAssault.java 4.3 KB

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