StrSiegeAssault.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 net.sf.l2j.gameserver.handler.skillhandlers;
  16. import net.sf.l2j.gameserver.handler.ISkillHandler;
  17. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  18. import net.sf.l2j.gameserver.instancemanager.FortManager;
  19. import net.sf.l2j.gameserver.model.L2Character;
  20. import net.sf.l2j.gameserver.model.L2ItemInstance;
  21. import net.sf.l2j.gameserver.model.L2Object;
  22. import net.sf.l2j.gameserver.model.L2Skill;
  23. import net.sf.l2j.gameserver.model.L2Skill.SkillType;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  25. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  26. import net.sf.l2j.gameserver.model.entity.Castle;
  27. import net.sf.l2j.gameserver.model.entity.Fort;
  28. import net.sf.l2j.gameserver.skills.Formulas;
  29. import net.sf.l2j.gameserver.templates.L2WeaponType;
  30. /**
  31. * @author _tomciaaa_
  32. *
  33. */
  34. public class StrSiegeAssault implements ISkillHandler
  35. {
  36. //private static Logger _log = Logger.getLogger(StrSiegeAssault.class.getName());
  37. private static final SkillType[] SKILL_IDS = {SkillType.STRSIEGEASSAULT};
  38. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  39. {
  40. if (!(activeChar instanceof L2PcInstance)) return;
  41. L2PcInstance player = (L2PcInstance)activeChar;
  42. if (!activeChar.isRidingStrider()) return;
  43. if (!(player.getTarget() instanceof L2DoorInstance)) return;
  44. Castle castle = CastleManager.getInstance().getCastle(player);
  45. Fort fort = FortManager.getInstance().getFort(player);
  46. if ((castle == null) && (fort == null))
  47. return;
  48. if ( castle != null )
  49. {
  50. if (!checkIfOkToUseStriderSiegeAssault(player, castle, true)) return;
  51. }
  52. else
  53. {
  54. if (!checkIfOkToUseStriderSiegeAssault(player, fort, true)) return;
  55. }
  56. try
  57. {
  58. // damage calculation
  59. int damage = 0;
  60. for(int index = 0;index < targets.length;index++)
  61. {
  62. L2Character target = (L2Character)targets[index];
  63. L2ItemInstance weapon = activeChar.getActiveWeaponInstance();
  64. if (activeChar instanceof L2PcInstance && target instanceof L2PcInstance
  65. && target.isFakeDeath())
  66. {
  67. target.stopFakeDeath(null);
  68. }
  69. else if (target.isDead())
  70. continue;
  71. boolean dual = activeChar.isUsingDualWeapon();
  72. boolean shld = Formulas.getInstance().calcShldUse(activeChar, target);
  73. boolean crit = Formulas.getInstance().calcCrit(activeChar.getCriticalHit(target, skill));
  74. boolean soul = (weapon!= null && weapon.getChargedSoulshot() == L2ItemInstance.CHARGED_SOULSHOT && weapon.getItemType() != L2WeaponType.DAGGER );
  75. if(!crit && (skill.getCondition() & L2Skill.COND_CRIT) != 0)
  76. damage = 0;
  77. else
  78. damage = (int)Formulas.getInstance().calcPhysDam(
  79. activeChar, target, skill, shld, crit, dual, soul);
  80. if (damage > 0)
  81. {
  82. target.reduceCurrentHp(damage, activeChar);
  83. if (soul && weapon!= null)
  84. weapon.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  85. activeChar.sendDamageMessage(target, damage, false, false, false);
  86. }
  87. else
  88. activeChar.sendMessage(skill.getName() + " failed.");
  89. }
  90. }
  91. catch (Exception e)
  92. {
  93. player.sendMessage("Error using siege assault:" + e);
  94. }
  95. }
  96. public SkillType[] getSkillIds()
  97. {
  98. return SKILL_IDS;
  99. }
  100. /**
  101. * Return true if character clan place a flag<BR><BR>
  102. *
  103. * @param activeChar The L2Character of the character placing the flag
  104. * @param isCheckOnly if false, it will send a notification to the player telling him
  105. * why it failed
  106. */
  107. public static boolean checkIfOkToUseStriderSiegeAssault(L2Character activeChar, boolean isCheckOnly)
  108. {
  109. Castle castle = CastleManager.getInstance().getCastle(activeChar);
  110. Fort fort = FortManager.getInstance().getFort(activeChar);
  111. if ((castle == null) && (fort == null))
  112. return false;
  113. if (castle != null)
  114. return checkIfOkToUseStriderSiegeAssault(activeChar, castle, isCheckOnly);
  115. else
  116. return checkIfOkToUseStriderSiegeAssault(activeChar, fort, isCheckOnly);
  117. }
  118. public static boolean checkIfOkToUseStriderSiegeAssault(L2Character activeChar, Castle castle, boolean isCheckOnly)
  119. {
  120. if (!(activeChar instanceof L2PcInstance))
  121. return false;
  122. String text = "";
  123. L2PcInstance player = (L2PcInstance)activeChar;
  124. if (castle == null || castle.getCastleId() <= 0)
  125. text = "You must be on castle ground to use strider siege assault";
  126. else if (!castle.getSiege().getIsInProgress())
  127. text = "You can only use strider siege assault during a siege.";
  128. else if (!(player.getTarget() instanceof L2DoorInstance))
  129. text = "You can only use strider siege assault on doors and walls.";
  130. else if (!activeChar.isRidingStrider())
  131. text = "You can only use strider siege assault when on strider.";
  132. else
  133. return true;
  134. if (!isCheckOnly)
  135. player.sendMessage(text);
  136. return false;
  137. }
  138. public static boolean checkIfOkToUseStriderSiegeAssault(L2Character activeChar, Fort fort, boolean isCheckOnly)
  139. {
  140. if (!(activeChar instanceof L2PcInstance))
  141. return false;
  142. String text = "";
  143. L2PcInstance player = (L2PcInstance)activeChar;
  144. if (fort == null || fort.getFortId() <= 0)
  145. text = "You must be on fort ground to use strider siege assault";
  146. else if (!fort.getSiege().getIsInProgress())
  147. text = "You can only use strider siege assault during a siege.";
  148. else if (!(player.getTarget() instanceof L2DoorInstance))
  149. text = "You can only use strider siege assault on doors and walls.";
  150. else if (!activeChar.isRidingStrider())
  151. text = "You can only use strider siege assault when on strider.";
  152. else
  153. return true;
  154. if (!isCheckOnly)
  155. player.sendMessage(text);
  156. return false;
  157. }
  158. }