StrSiegeAssault.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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.actor.instance.L2DoorInstance;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  25. import net.sf.l2j.gameserver.model.entity.Castle;
  26. import net.sf.l2j.gameserver.model.entity.Fort;
  27. import net.sf.l2j.gameserver.skills.Formulas;
  28. import net.sf.l2j.gameserver.templates.L2SkillType;
  29. import net.sf.l2j.gameserver.templates.L2WeaponType;
  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 net.sf.l2j.gameserver.handler.ISkillHandler#useSkill(net.sf.l2j.gameserver.model.L2Character, net.sf.l2j.gameserver.model.L2Skill, net.sf.l2j.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 (!activeChar.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 (!checkIfOkToUseStriderSiegeAssault(player, castle, true))
  60. return;
  61. }
  62. else
  63. {
  64. if (!checkIfOkToUseStriderSiegeAssault(player, fort, true))
  65. return;
  66. }
  67. try
  68. {
  69. // damage calculation
  70. int damage = 0;
  71. for (int index = 0; index < targets.length; index++)
  72. {
  73. L2Character target = (L2Character) targets[index];
  74. L2ItemInstance weapon = activeChar.getActiveWeaponInstance();
  75. if (activeChar instanceof L2PcInstance && target instanceof L2PcInstance && target.isFakeDeath())
  76. {
  77. target.stopFakeDeath(null);
  78. }
  79. else if (target.isDead())
  80. continue;
  81. boolean dual = activeChar.isUsingDualWeapon();
  82. boolean shld = Formulas.getInstance().calcShldUse(activeChar, target);
  83. boolean crit = Formulas.getInstance().calcCrit(activeChar.getCriticalHit(target, skill));
  84. boolean soul = (weapon != null && weapon.getChargedSoulshot() == L2ItemInstance.CHARGED_SOULSHOT && weapon.getItemType() != L2WeaponType.DAGGER);
  85. if (!crit && (skill.getCondition() & L2Skill.COND_CRIT) != 0)
  86. damage = 0;
  87. else
  88. damage = (int) Formulas.getInstance().calcPhysDam(activeChar, target, skill, shld, crit, dual, soul);
  89. if (damage > 0)
  90. {
  91. target.reduceCurrentHp(damage, activeChar);
  92. if (soul && weapon != null)
  93. weapon.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  94. activeChar.sendDamageMessage(target, damage, false, false, false);
  95. }
  96. else
  97. activeChar.sendMessage(skill.getName() + " failed.");
  98. }
  99. }
  100. catch (Exception e)
  101. {
  102. player.sendMessage("Error using siege assault:" + e);
  103. }
  104. }
  105. /**
  106. *
  107. * @see net.sf.l2j.gameserver.handler.ISkillHandler#getSkillIds()
  108. */
  109. public L2SkillType[] getSkillIds()
  110. {
  111. return SKILL_IDS;
  112. }
  113. /**
  114. * Return true if character clan place a flag<BR><BR>
  115. *
  116. * @param activeChar The L2Character of the character placing the flag
  117. * @param isCheckOnly if false, it will send a notification to the player telling him
  118. * why it failed
  119. */
  120. public static boolean checkIfOkToUseStriderSiegeAssault(L2Character activeChar, boolean isCheckOnly)
  121. {
  122. Castle castle = CastleManager.getInstance().getCastle(activeChar);
  123. Fort fort = FortManager.getInstance().getFort(activeChar);
  124. if ((castle == null) && (fort == null))
  125. return false;
  126. if (castle != null)
  127. return checkIfOkToUseStriderSiegeAssault(activeChar, castle, isCheckOnly);
  128. else
  129. return checkIfOkToUseStriderSiegeAssault(activeChar, fort, isCheckOnly);
  130. }
  131. /**
  132. *
  133. * @param activeChar
  134. * @param castle
  135. * @param isCheckOnly
  136. * @return
  137. */
  138. public static boolean checkIfOkToUseStriderSiegeAssault(L2Character activeChar, Castle castle, boolean isCheckOnly)
  139. {
  140. if (!(activeChar instanceof L2PcInstance))
  141. return false;
  142. String text = "";
  143. L2PcInstance player = (L2PcInstance) activeChar;
  144. if (castle == null || castle.getCastleId() <= 0)
  145. text = "You must be on castle ground to use strider siege assault";
  146. else if (!castle.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. /**
  159. *
  160. * @param activeChar
  161. * @param fort
  162. * @param isCheckOnly
  163. * @return
  164. */
  165. public static boolean checkIfOkToUseStriderSiegeAssault(L2Character activeChar, Fort fort, boolean isCheckOnly)
  166. {
  167. if (!(activeChar instanceof L2PcInstance))
  168. return false;
  169. String text = "";
  170. L2PcInstance player = (L2PcInstance) activeChar;
  171. if (fort == null || fort.getFortId() <= 0)
  172. text = "You must be on fort ground to use strider siege assault";
  173. else if (!fort.getSiege().getIsInProgress())
  174. text = "You can only use strider siege assault during a siege.";
  175. else if (!(player.getTarget() instanceof L2DoorInstance))
  176. text = "You can only use strider siege assault on doors and walls.";
  177. else if (!activeChar.isRidingStrider())
  178. text = "You can only use strider siege assault when on strider.";
  179. else
  180. return true;
  181. if (!isCheckOnly)
  182. player.sendMessage(text);
  183. return false;
  184. }
  185. }