StrSiegeAssault.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.ShotType;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  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.skills.L2Skill;
  26. import com.l2jserver.gameserver.model.skills.L2SkillType;
  27. import com.l2jserver.gameserver.model.stats.Formulas;
  28. /**
  29. * @author _tomciaaa_
  30. */
  31. public class StrSiegeAssault implements ISkillHandler
  32. {
  33. private static final L2SkillType[] SKILL_IDS =
  34. {
  35. L2SkillType.STRSIEGEASSAULT
  36. };
  37. @Override
  38. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  39. {
  40. if (!activeChar.isPlayer())
  41. return;
  42. L2PcInstance player = activeChar.getActingPlayer();
  43. if (!player.isRidingStrider())
  44. return;
  45. if (!player.getTarget().isDoor())
  46. return;
  47. Castle castle = CastleManager.getInstance().getCastle(player);
  48. Fort fort = FortManager.getInstance().getFort(player);
  49. if ((castle == null) && (fort == null))
  50. return;
  51. if (castle != null)
  52. {
  53. if (!player.checkIfOkToUseStriderSiegeAssault(castle))
  54. return;
  55. }
  56. else
  57. {
  58. if (!player.checkIfOkToUseStriderSiegeAssault(fort))
  59. return;
  60. }
  61. try
  62. {
  63. // damage calculation
  64. int damage = 0;
  65. boolean ss = skill.isPhysical() && activeChar.isChargedShot(ShotType.SOULSHOTS);
  66. for (L2Character target: (L2Character[]) targets)
  67. {
  68. if (activeChar.isPlayer() && target.isPlayer() && target.getActingPlayer().isFakeDeath())
  69. {
  70. target.stopFakeDeath(true);
  71. }
  72. else if (target.isDead())
  73. continue;
  74. boolean dual = activeChar.isUsingDualWeapon();
  75. byte shld = Formulas.calcShldUse(activeChar, target, skill);
  76. boolean crit = Formulas.calcCrit(activeChar.getCriticalHit(target, skill), true, target);
  77. if (!crit && (skill.getCondition() & L2Skill.COND_CRIT) != 0)
  78. damage = 0;
  79. else
  80. damage = skill.isStaticDamage() ? (int)skill.getPower() : (int) Formulas.calcPhysDam(activeChar, target, skill, shld, crit, dual, ss);
  81. if (damage > 0)
  82. {
  83. target.reduceCurrentHp(damage, activeChar, skill);
  84. activeChar.sendDamageMessage(target, damage, false, false, false);
  85. }
  86. else
  87. activeChar.sendMessage(skill.getName() + " failed.");
  88. }
  89. activeChar.setChargedShot(ShotType.SOULSHOTS, false);
  90. }
  91. catch (Exception e)
  92. {
  93. player.sendMessage("Error using siege assault:" + e);
  94. }
  95. }
  96. @Override
  97. public L2SkillType[] getSkillIds()
  98. {
  99. return SKILL_IDS;
  100. }
  101. public static void main(String[] args)
  102. {
  103. new StrSiegeAssault();
  104. }
  105. }