Gordon.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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.individual;
  16. import java.util.Collection;
  17. import ai.group_template.L2AttackableAIScript;
  18. import com.l2jserver.gameserver.ai.CtrlIntention;
  19. import com.l2jserver.gameserver.datatables.SpawnTable;
  20. import com.l2jserver.gameserver.model.L2CharPosition;
  21. import com.l2jserver.gameserver.model.L2Spawn;
  22. import com.l2jserver.gameserver.model.actor.L2Attackable;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. /**
  26. * Gordon AI
  27. * @author TOFIZ
  28. * @version $Revision: 1.1 $ $Date: 2008/08/21 $
  29. */
  30. public class Gordon extends L2AttackableAIScript
  31. {
  32. private static final int GORDON = 29095;
  33. private static int _npcMoveX = 0;
  34. private static int _npcMoveY = 0;
  35. private static int _isWalkTo = 0;
  36. private static int _npcBlock = 0;
  37. private static int X = 0;
  38. private static int Y = 0;
  39. private static int Z = 0;
  40. private static final int[][] WALKS = {
  41. {141569, -45908, -2387},{142494, -45456, -2397},{142922, -44561, -2395},
  42. {143672, -44130, -2398},{144557, -43378, -2325},{145839, -43267, -2301},
  43. {147044, -43601, -2307},{148140, -43206, -2303},{148815, -43434, -2328},
  44. {149862, -44151, -2558},{151037, -44197, -2708},{152555, -42756, -2836},
  45. {154808, -39546, -3236},{155333, -39962, -3272},{156531, -41240, -3470},
  46. {156863, -43232, -3707},{156783, -44198, -3764},{158169, -45163, -3541},
  47. {158952, -45479, -3473},{160039, -46514, -3634},{160244, -47429, -3656},
  48. {159155, -48109, -3665},{159558, -51027, -3523},{159396, -53362, -3244},
  49. {160872, -56556, -2789},{160857, -59072, -2613},{160410, -59888, -2647},
  50. {158770, -60173, -2673},{156368, -59557, -2638},{155188, -59868, -2642},
  51. {154118, -60591, -2731},{153571, -61567, -2821},{153457, -62819, -2886},
  52. {152939, -63778, -3003},{151816, -64209, -3120},{147655, -64826, -3433},
  53. {145422, -64576, -3369},{144097, -64320, -3404},{140780, -61618, -3096},
  54. {139688, -61450, -3062},{138267, -61743, -3056},{138613, -58491, -3465},
  55. {138139, -57252, -3517},{139555, -56044, -3310},{139107, -54537, -3240},
  56. {139279, -53781, -3091},{139810, -52687, -2866},{139657, -52041, -2793},
  57. {139215, -51355, -2698},{139334, -50514, -2594},{139817, -49715, -2449},
  58. {139824, -48976, -2263},{140130, -47578, -2213},{140483, -46339, -2382},
  59. {141569, -45908, -2387}};
  60. private static boolean _isAttacked = false;
  61. private static boolean _isSpawned = false;
  62. public Gordon (int id, String name, String descr)
  63. {
  64. super(id,name,descr);
  65. int[] mobs = {GORDON};
  66. registerMobs(mobs, QuestEventType.ON_ATTACK, QuestEventType.ON_KILL, QuestEventType.ON_SPAWN);
  67. // wait 2 minutes after Start AI
  68. startQuestTimer("check_ai", 120000, null, null, true);
  69. _isSpawned = false;
  70. _isAttacked = false;
  71. _isWalkTo = 1;
  72. _npcMoveX = 0;
  73. _npcMoveY = 0;
  74. _npcBlock = 0;
  75. }
  76. public L2Npc findTemplate(int npcId)
  77. {
  78. L2Npc npc = null;
  79. for (L2Spawn spawn : SpawnTable.getInstance().getSpawnTable())
  80. {
  81. if (spawn != null && spawn.getNpcid() == npcId)
  82. {
  83. npc = spawn.getLastSpawn();
  84. break;
  85. }
  86. }
  87. return npc;
  88. }
  89. @Override
  90. public String onAdvEvent (String event, L2Npc npc, L2PcInstance player)
  91. {
  92. X = WALKS[_isWalkTo-1][0];
  93. Y = WALKS[_isWalkTo-1][1];
  94. Z = WALKS[_isWalkTo-1][2];
  95. if (event.equalsIgnoreCase("time_isAttacked"))
  96. {
  97. _isAttacked = false;
  98. if (npc.getNpcId() == GORDON)
  99. {
  100. npc.setWalking();
  101. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(X, Y, Z, 0));
  102. }
  103. }
  104. else if (event.equalsIgnoreCase("check_ai"))
  105. {
  106. cancelQuestTimer("check_ai", null, null);
  107. if (_isSpawned == false)
  108. {
  109. L2Npc gordon_ai = findTemplate(GORDON);
  110. if (gordon_ai != null)
  111. {
  112. _isSpawned = true;
  113. startQuestTimer("Start", 1000, gordon_ai, null, true);
  114. return super.onAdvEvent(event, npc, player);
  115. }
  116. }
  117. }
  118. else if (event.equalsIgnoreCase("Start"))
  119. {
  120. if (npc != null && _isSpawned == true)
  121. {
  122. // check if player have Cursed Weapon and in radius
  123. if (npc.getNpcId() == GORDON)
  124. {
  125. Collection<L2PcInstance> chars = npc.getKnownList().getKnownPlayers().values();
  126. if (chars != null && chars.size() > 0)
  127. {
  128. for (L2PcInstance pc : chars)
  129. {
  130. if (pc.isCursedWeaponEquipped() && pc.isInsideRadius(npc,5000,false,false))
  131. {
  132. npc.setRunning();
  133. ((L2Attackable)npc).addDamageHate(pc,0,9999);
  134. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, pc);
  135. _isAttacked = true;
  136. cancelQuestTimer("time_isAttacked",null, null);
  137. startQuestTimer("time_isAttacked",180000, npc, null);
  138. return super.onAdvEvent(event, npc, player);
  139. }
  140. }
  141. }
  142. }
  143. // end check
  144. if (_isAttacked == true)
  145. return super.onAdvEvent(event, npc, player);
  146. if (npc.getNpcId() == GORDON && (npc.getX()-50) <= X && (npc.getX()+50) >= X && (npc.getY()-50) <= Y && (npc.getY()+50) >= Y)
  147. {
  148. _isWalkTo++;
  149. if (_isWalkTo > 55)
  150. _isWalkTo = 1;
  151. X = WALKS[_isWalkTo-1][0];
  152. Y = WALKS[_isWalkTo-1][1];
  153. Z = WALKS[_isWalkTo-1][2];
  154. npc.setWalking();
  155. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO,new L2CharPosition(X, Y, Z, 0));
  156. }
  157. // Test for unblock Npc
  158. if (npc.getX() != _npcMoveX && npc.getY() != _npcMoveY)
  159. {
  160. _npcMoveX = npc.getX();
  161. _npcMoveY = npc.getY();
  162. _npcBlock = 0;
  163. }
  164. else if (npc.getNpcId() == GORDON)
  165. {
  166. _npcBlock++;
  167. if (_npcBlock > 2)
  168. {
  169. npc.teleToLocation(X, Y, Z);
  170. return super.onAdvEvent(event, npc, player);
  171. }
  172. if (_npcBlock > 0)
  173. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO,new L2CharPosition(X, Y, Z, 0));
  174. }
  175. // End Test unblock Npc
  176. }
  177. }
  178. return super.onAdvEvent(event, npc, player);
  179. }
  180. @Override
  181. public String onSpawn (L2Npc npc)
  182. {
  183. if (npc.getNpcId() == GORDON && _npcBlock == 0)
  184. {
  185. _isSpawned = true;
  186. _isWalkTo = 1;
  187. startQuestTimer("Start", 1000, npc, null, true);
  188. }
  189. return super.onSpawn(npc);
  190. }
  191. @Override
  192. public String onAttack (L2Npc npc, L2PcInstance player, int damage, boolean isPet)
  193. {
  194. if (npc.getNpcId() == GORDON)
  195. {
  196. _isAttacked = true;
  197. cancelQuestTimer("time_isAttacked", null, null);
  198. startQuestTimer("time_isAttacked", 180000, npc, null);
  199. if (player != null)
  200. {
  201. npc.setRunning();
  202. ((L2Attackable)npc).addDamageHate(player, 0, 100);
  203. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  204. }
  205. }
  206. return super.onAttack(npc, player, damage, isPet);
  207. }
  208. @Override
  209. public String onKill (L2Npc npc, L2PcInstance killer, boolean isPet)
  210. {
  211. if (npc.getNpcId() == GORDON)
  212. {
  213. cancelQuestTimer("Start", null, null);
  214. cancelQuestTimer("time_isAttacked", null, null);
  215. _isSpawned = false;
  216. }
  217. return super.onKill(npc,killer,isPet);
  218. }
  219. public static void main(String[] args)
  220. {
  221. new Gordon(-1,"gordon","ai");
  222. }
  223. }