Guest User

chest

a guest
Jan 27th, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  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 ai.group;
  16.  
  17. import ai.AbstractNpcAI;
  18.  
  19. import net.sf.l2j.gameserver.datatables.SkillTable;
  20. import net.sf.l2j.gameserver.model.L2Object;
  21. import net.sf.l2j.gameserver.model.L2Skill;
  22. import net.sf.l2j.gameserver.model.actor.L2Npc;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2ChestInstance;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  25. import net.sf.l2j.gameserver.model.quest.QuestEventType;
  26. import net.sf.l2j.gameserver.util.Util;
  27. import net.sf.l2j.util.Rnd;
  28.  
  29. /**
  30. * Chest AI implementation.
  31. * @author Fulminus
  32. */
  33. public class Chests extends AbstractNpcAI
  34. {
  35. private static final int SKILL_DELUXE_KEY = 2229;
  36. private static final int SKILL_BOX_KEY = 2065;
  37.  
  38. private static final int[] NPC_IDS =
  39. {
  40. 18265,
  41. 18266,
  42. 18267,
  43. 18268,
  44. 18269,
  45. 18270,
  46. 18271,
  47. 18272,
  48. 18273,
  49. 18274,
  50. 18275,
  51. 18276,
  52. 18277,
  53. 18278,
  54. 18279,
  55. 18280,
  56. 18281,
  57. 18282,
  58. 18283,
  59. 18284,
  60. 18285,
  61. 18286,
  62. 18287,
  63. 18288,
  64. 18289,
  65. 18290,
  66. 18291,
  67. 18292,
  68. 18293,
  69. 18294,
  70. 18295,
  71. 18296,
  72. 18297,
  73. 18298,
  74. 21671,
  75. 21694,
  76. 21717,
  77. 21740,
  78. 21763,
  79. 21786,
  80. 21801,
  81. 21802,
  82. 21803,
  83. 21804,
  84. 21805,
  85. 21806,
  86. 21807,
  87. 21808,
  88. 21809,
  89. 21810,
  90. 21811,
  91. 21812,
  92. 21813,
  93. 21814,
  94. 21815,
  95. 21816,
  96. 21817,
  97. 21818,
  98. 21819,
  99. 21820,
  100. 21821,
  101. 21822
  102. };
  103.  
  104. public Chests(String name, String descr)
  105. {
  106. super(name, descr);
  107. registerMobs(NPC_IDS, QuestEventType.ON_ATTACK, QuestEventType.ON_SKILL_SEE);
  108. }
  109.  
  110. @Override
  111. public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
  112. {
  113. if (npc instanceof L2ChestInstance)
  114. {
  115. // This behavior is only run when the target of skill is the passed npc.
  116. if (!Util.contains(targets, npc))
  117. return super.onSkillSee(npc, caster, skill, targets, isPet);
  118.  
  119. final L2ChestInstance chest = ((L2ChestInstance) npc);
  120.  
  121. // If this chest has already been interacted, no further AI decisions are needed.
  122. if (!chest.isInteracted())
  123. {
  124. chest.setInteracted();
  125.  
  126. // If it's the first interaction, check if this is a box or mimic.
  127. //modified to 50% chance to open - meikis
  128. if (Rnd.get(100) < 50)
  129. {
  130. switch (skill.getId())
  131. {
  132. case SKILL_BOX_KEY:
  133. case SKILL_DELUXE_KEY:
  134. // check the chance to open the box.
  135. int keyLevelNeeded = (chest.getLevel() / 10) - skill.getLevel();
  136. if (keyLevelNeeded < 0)
  137. keyLevelNeeded *= -1;
  138.  
  139. // Regular keys got 60% to succeed.
  140. final int chance = ((skill.getId() == SKILL_BOX_KEY) ? 60 : 100) - keyLevelNeeded * 40;
  141.  
  142. // Success, die with rewards.
  143. //100% chance - meikis
  144. if (Rnd.get(100) < 101)
  145. {
  146. chest.setSpecialDrop();
  147. chest.doDie(caster);
  148. }
  149. // Used a key but failed to open: disappears with no rewards.
  150. else
  151. chest.deleteMe(); // TODO: replace for a better system (as chests attack once before decaying)
  152. break;
  153.  
  154. default:
  155. chest.doCast(SkillTable.getInstance().getInfo(4143, Math.min(10, Math.round(npc.getLevel() / 10))));
  156. break;
  157. }
  158. }
  159. // Mimic behavior : attack the caster.
  160. else
  161. attack(chest, ((isPet) ? caster.getPet() : caster));
  162. }
  163. }
  164. return super.onSkillSee(npc, caster, skill, targets, isPet);
  165. }
  166.  
  167. @Override
  168. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  169. {
  170. if (npc instanceof L2ChestInstance)
  171. {
  172. final L2ChestInstance chest = ((L2ChestInstance) npc);
  173.  
  174. // If this has already been interacted, no further AI decisions are needed.
  175. if (!chest.isInteracted())
  176. {
  177. chest.setInteracted();
  178.  
  179. // If it was a box, cast a suicide type skill.
  180. if (Rnd.get(100) < 40)
  181. chest.doCast(SkillTable.getInstance().getInfo(4143, Math.min(10, Math.round(npc.getLevel() / 10))));
  182. // Mimic behavior : attack the caster.
  183. else
  184. attack(chest, ((isPet) ? attacker.getPet() : attacker), ((damage * 100) / (chest.getLevel() + 7)));
  185. }
  186. }
  187. return super.onAttack(npc, attacker, damage, isPet);
  188. }
  189.  
  190. public static void main(String[] args)
  191. {
  192. new Chests(Chests.class.getSimpleName(), "ai/group");
  193. }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment