StrSiegeAssault.java 4.0 KB

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