WarriorFishingBlock.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package ai.group_template;
  20. import ai.npc.AbstractNpcAI;
  21. import com.l2jserver.gameserver.ai.CtrlEvent;
  22. import com.l2jserver.gameserver.model.L2Object;
  23. import com.l2jserver.gameserver.model.actor.L2Attackable;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.network.NpcStringId;
  27. import com.l2jserver.gameserver.network.clientpackets.Say2;
  28. /**
  29. * Warrior Fishing Block AI.
  30. * @author Zoey76
  31. */
  32. public final class WarriorFishingBlock extends AbstractNpcAI
  33. {
  34. // Monsters
  35. private static final int[] MONSTERS =
  36. {
  37. 18319, // Caught Frog
  38. 18320, // Caught Undine
  39. 18321, // Caught Rakul
  40. 18322, // Caught Sea Giant
  41. 18323, // Caught Sea Horse Soldier
  42. 18324, // Caught Homunculus
  43. 18325, // Caught Flava
  44. 18326, // Caught Gigantic Eye
  45. };
  46. // NPC Strings
  47. private static final NpcStringId[] NPC_STRINGS_ON_SPAWN =
  48. {
  49. NpcStringId.CROAK_CROAK_FOOD_LIKE_S1_IN_THIS_PLACE,
  50. NpcStringId.S1_HOW_LUCKY_I_AM,
  51. NpcStringId.PRAY_THAT_YOU_CAUGHT_A_WRONG_FISH_S1
  52. };
  53. private static final NpcStringId[] NPC_STRINGS_ON_ATTACK =
  54. {
  55. NpcStringId.DO_YOU_KNOW_WHAT_A_FROG_TASTES_LIKE,
  56. NpcStringId.I_WILL_SHOW_YOU_THE_POWER_OF_A_FROG,
  57. NpcStringId.I_WILL_SWALLOW_AT_A_MOUTHFUL
  58. };
  59. private static final NpcStringId[] NPC_STRINGS_ON_KILL =
  60. {
  61. NpcStringId.UGH_NO_CHANCE_HOW_COULD_THIS_ELDER_PASS_AWAY_LIKE_THIS,
  62. NpcStringId.CROAK_CROAK_A_FROG_IS_DYING,
  63. NpcStringId.A_FROG_TASTES_BAD_YUCK
  64. };
  65. // Misc
  66. private static final int CHANCE_TO_SHOUT_ON_ATTACK = 33;
  67. private static final int DESPAWN_TIME = 50; // 50 seconds to despawn
  68. public WarriorFishingBlock()
  69. {
  70. super(WarriorFishingBlock.class.getSimpleName(), "ai/group_template");
  71. addAttackId(MONSTERS);
  72. addKillId(MONSTERS);
  73. addSpawnId(MONSTERS);
  74. }
  75. @Override
  76. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  77. {
  78. switch (event)
  79. {
  80. case "SPAWN":
  81. {
  82. final L2Object obj = npc.getTarget();
  83. if ((obj == null) || !obj.isPlayer())
  84. {
  85. npc.decayMe();
  86. }
  87. else
  88. {
  89. final L2PcInstance target = obj.getActingPlayer();
  90. broadcastNpcSay(npc, Say2.NPC_ALL, NPC_STRINGS_ON_SPAWN[getRandom(NPC_STRINGS_ON_SPAWN.length)], target.getName());
  91. ((L2Attackable) npc).addDamageHate(target, 0, 2000);
  92. npc.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, target);
  93. npc.addAttackerToAttackByList(target);
  94. startQuestTimer("DESPAWN", DESPAWN_TIME * 1000, npc, target);
  95. }
  96. break;
  97. }
  98. case "DESPAWN":
  99. {
  100. npc.decayMe();
  101. break;
  102. }
  103. }
  104. return super.onAdvEvent(event, npc, player);
  105. }
  106. @Override
  107. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  108. {
  109. if (getRandom(100) < CHANCE_TO_SHOUT_ON_ATTACK)
  110. {
  111. broadcastNpcSay(npc, Say2.NPC_ALL, NPC_STRINGS_ON_ATTACK[getRandom(NPC_STRINGS_ON_ATTACK.length)]);
  112. }
  113. return super.onAttack(npc, attacker, damage, isSummon);
  114. }
  115. @Override
  116. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  117. {
  118. broadcastNpcSay(npc, Say2.NPC_ALL, NPC_STRINGS_ON_KILL[getRandom(NPC_STRINGS_ON_KILL.length)]);
  119. cancelQuestTimer("DESPAWN", npc, killer);
  120. return super.onKill(npc, killer, isSummon);
  121. }
  122. @Override
  123. public String onSpawn(L2Npc npc)
  124. {
  125. startQuestTimer("SPAWN", 2000, npc, null);
  126. return super.onSpawn(npc);
  127. }
  128. public static void main(String[] args)
  129. {
  130. new WarriorFishingBlock();
  131. }
  132. }