Advertisement
Deedlit

Support for better script control over AI

Dec 21st, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 28.29 KB | None | 0 0
  1. Index: java/com/l2jserver/gameserver/enums/QuestEventType.java
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. --- java/com/l2jserver/gameserver/enums/QuestEventType.java (revision 6319)
  7. +++ java/com/l2jserver/gameserver/enums/QuestEventType.java (revision )
  8. @@ -42,7 +42,10 @@
  9.     ON_MOVE_FINISHED(true), // onMoveFinished action, triggered when NPC stops after moving
  10.     ON_NODE_ARRIVED(true), // onNodeArrived action, triggered when NPC, controlled by Walking Manager, arrives to next node
  11.     ON_SEE_CREATURE(true), // onSeeCreature action, triggered when NPC's known list include the character
  12. -   ON_ROUTE_FINISHED(true); // onRouteFinished action, triggered when NPC, controlled by Walking Manager, arrives to last node
  13. +   ON_ROUTE_FINISHED(true), // onRouteFinished action, triggered when NPC, controlled by Walking Manager, arrives to last node
  14. +   ON_AI_TASK_RUN(true), // Executed before L2AttackableAI task run
  15. +   ON_AI_INTENTION(true), // Executed as first in AI's "setIntention()". Allows custom AI control.
  16. +   ON_AI_EVENT(true); // Executed as first, in AI's "notifyEvent()". Allows custom AI control.
  17.    
  18.     // control whether this event type is allowed for the same npc template in multiple quests
  19.     // or if the npc must be registered in at most one quest for the specified event
  20. Index: java/com/l2jserver/gameserver/ai/IntentionCommand.java
  21. IDEA additional info:
  22. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  23. <+>UTF-8
  24. ===================================================================
  25. --- java/com/l2jserver/gameserver/ai/IntentionCommand.java  (revision )
  26. +++ java/com/l2jserver/gameserver/ai/IntentionCommand.java  (revision )
  27. @@ -0,0 +1,44 @@
  28. +/*
  29. + * This program is free software: you can redistribute it and/or modify it under
  30. + * the terms of the GNU General Public License as published by the Free Software
  31. + * Foundation, either version 3 of the License, or (at your option) any later
  32. + * version.
  33. + *
  34. + * This program is distributed in the hope that it will be useful, but WITHOUT
  35. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  36. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  37. + * details.
  38. + *
  39. + * You should have received a copy of the GNU General Public License along with
  40. + * this program. If not, see <http://www.gnu.org/licenses/>.
  41. + */
  42. +package com.l2jserver.gameserver.ai;
  43. +
  44. +public class IntentionCommand
  45. +{
  46. +   protected final CtrlIntention _crtlIntention;
  47. +
  48. +   protected final Object _arg0, _arg1;
  49. +
  50. +   protected IntentionCommand(CtrlIntention pIntention, Object pArg0, Object pArg1)
  51. +   {
  52. +       _crtlIntention = pIntention;
  53. +       _arg0 = pArg0;
  54. +       _arg1 = pArg1;
  55. +   }
  56. +
  57. +   public CtrlIntention getCtrlIntention()
  58. +   {
  59. +       return _crtlIntention;
  60. +   }
  61. +
  62. +   public Object getArg0()
  63. +   {
  64. +       return _arg0;
  65. +   }
  66. +
  67. +   public Object getArg1()
  68. +   {
  69. +       return _arg1;
  70. +   }
  71. +}
  72. \ No newline at end of file
  73. Index: java/com/l2jserver/gameserver/ai/L2AttackableAI.java
  74. IDEA additional info:
  75. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  76. <+>UTF-8
  77. ===================================================================
  78. --- java/com/l2jserver/gameserver/ai/L2AttackableAI.java    (revision 6319)
  79. +++ java/com/l2jserver/gameserver/ai/L2AttackableAI.java    (revision )
  80. @@ -18,15 +18,6 @@
  81.   */
  82.  package com.l2jserver.gameserver.ai;
  83.  
  84. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
  85. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
  86. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
  87. -
  88. -import java.util.ArrayList;
  89. -import java.util.Collection;
  90. -import java.util.List;
  91. -import java.util.concurrent.Future;
  92. -
  93.  import com.l2jserver.Config;
  94.  import com.l2jserver.gameserver.GameTimeController;
  95.  import com.l2jserver.gameserver.GeoData;
  96. @@ -34,34 +25,30 @@
  97.  import com.l2jserver.gameserver.datatables.NpcTable;
  98.  import com.l2jserver.gameserver.datatables.TerritoryTable;
  99.  import com.l2jserver.gameserver.enums.AIType;
  100. +import com.l2jserver.gameserver.enums.QuestEventControl;
  101.  import com.l2jserver.gameserver.enums.QuestEventType;
  102.  import com.l2jserver.gameserver.instancemanager.DimensionalRiftManager;
  103.  import com.l2jserver.gameserver.model.L2Object;
  104.  import com.l2jserver.gameserver.model.Location;
  105. -import com.l2jserver.gameserver.model.actor.L2Attackable;
  106. -import com.l2jserver.gameserver.model.actor.L2Character;
  107. -import com.l2jserver.gameserver.model.actor.L2Npc;
  108. -import com.l2jserver.gameserver.model.actor.L2Playable;
  109. -import com.l2jserver.gameserver.model.actor.L2Summon;
  110. -import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  111. -import com.l2jserver.gameserver.model.actor.instance.L2FestivalMonsterInstance;
  112. -import com.l2jserver.gameserver.model.actor.instance.L2FriendlyMobInstance;
  113. -import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
  114. -import com.l2jserver.gameserver.model.actor.instance.L2GuardInstance;
  115. -import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  116. -import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  117. -import com.l2jserver.gameserver.model.actor.instance.L2RaidBossInstance;
  118. -import com.l2jserver.gameserver.model.actor.instance.L2RiftInvaderInstance;
  119. -import com.l2jserver.gameserver.model.actor.instance.L2StaticObjectInstance;
  120. +import com.l2jserver.gameserver.model.actor.*;
  121. +import com.l2jserver.gameserver.model.actor.instance.*;
  122.  import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  123.  import com.l2jserver.gameserver.model.effects.L2EffectType;
  124.  import com.l2jserver.gameserver.model.quest.Quest;
  125. +import com.l2jserver.gameserver.model.quest.QuestEventRunResult;
  126.  import com.l2jserver.gameserver.model.skills.L2Skill;
  127.  import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  128.  import com.l2jserver.gameserver.model.zone.ZoneId;
  129.  import com.l2jserver.gameserver.util.Util;
  130.  import com.l2jserver.util.Rnd;
  131.  
  132. +import java.util.ArrayList;
  133. +import java.util.Collection;
  134. +import java.util.List;
  135. +import java.util.concurrent.Future;
  136. +
  137. +import static com.l2jserver.gameserver.ai.CtrlIntention.*;
  138. +
  139.  /**
  140.   * This class manages AI of L2Attackable.
  141.   */
  142. @@ -109,8 +96,25 @@
  143.     @Override
  144.     public void run()
  145.     {
  146. +       boolean breakExec = false;
  147. +       final L2Npc me = getNpc();
  148. +       List<Quest> qe = me.getTemplate().getEventQuests(QuestEventType.ON_AI_TASK_RUN);
  149. +       if (qe != null)
  150. +       {
  151. +           for (Quest quest : qe)
  152. +           {
  153. +               QuestEventRunResult r = quest.notifyAITaskRun(me);
  154. +               if (!breakExec && r.getCallerExecControl() == QuestEventControl.BREAK)
  155. +                   breakExec = true;
  156. +               if (r.getLoopControl() == QuestEventControl.BREAK) // dp script resulted in request to abort loop.
  157. +                   break;
  158. +           }
  159. +       }
  160. +       if (breakExec) // one of dp scripts resulted in request to abort caller method execution.
  161. +           return;
  162. +
  163.         // Launch actions corresponding to the Event Think
  164. -       onEvtThink();
  165. +       notifyEvent(CtrlEvent.EVT_THINK); // NOTE: Szponiasty: using notifyEvent instead of onEvtThink(), to allow running dp side quest scripts that control AI on ev
  166.     }
  167.    
  168.     /**
  169. Index: java/com/l2jserver/gameserver/enums/QuestEventControl.java
  170. IDEA additional info:
  171. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  172. <+>UTF-8
  173. ===================================================================
  174. --- java/com/l2jserver/gameserver/enums/QuestEventControl.java  (revision )
  175. +++ java/com/l2jserver/gameserver/enums/QuestEventControl.java  (revision )
  176. @@ -0,0 +1,30 @@
  177. +/*
  178. + * This program is free software: you can redistribute it and/or modify it under
  179. + * the terms of the GNU General Public License as published by the Free Software
  180. + * Foundation, either version 3 of the License, or (at your option) any later
  181. + * version.
  182. + *
  183. + * This program is distributed in the hope that it will be useful, but WITHOUT
  184. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  185. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  186. + * details.
  187. + *
  188. + * You should have received a copy of the GNU General Public License along with
  189. + * this program. If not, see <http://www.gnu.org/licenses/>.
  190. + */
  191. +package com.l2jserver.gameserver.enums;
  192. +
  193. +/**
  194. + * ==============================================<br>
  195. + * QuestEventControl - Quest event result used for controlling core behavior, depending on scipts.<br>
  196. + * ==============================================<br>
  197. + * @author Szponiasty
  198. + */
  199. +public enum QuestEventControl
  200. +{
  201. +   /** Informs AI, to continue certain task. */
  202. +   CONTINUE,
  203. +   /** Informs AI, to break certain task. */
  204. +   BREAK,
  205. +   UNDETERMINED;
  206. +}
  207. Index: java/com/l2jserver/gameserver/model/quest/QuestEventRunResult.java
  208. IDEA additional info:
  209. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  210. <+>UTF-8
  211. ===================================================================
  212. --- java/com/l2jserver/gameserver/model/quest/QuestEventRunResult.java  (revision )
  213. +++ java/com/l2jserver/gameserver/model/quest/QuestEventRunResult.java  (revision )
  214. @@ -0,0 +1,102 @@
  215. +/*
  216. + * This program is free software: you can redistribute it and/or modify it under
  217. + * the terms of the GNU General Public License as published by the Free Software
  218. + * Foundation, either version 3 of the License, or (at your option) any later
  219. + * version.
  220. + *
  221. + * This program is distributed in the hope that it will be useful, but WITHOUT
  222. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  223. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  224. + * details.
  225. + *
  226. + * You should have received a copy of the GNU General Public License along with
  227. + * this program. If not, see <http://www.gnu.org/licenses/>.
  228. + */
  229. +package com.l2jserver.gameserver.model.quest;
  230. +
  231. +import com.l2jserver.gameserver.enums.QuestEventControl;
  232. +
  233. +import java.util.logging.Logger;
  234. +
  235. +/**
  236. + * ==============================================<br>
  237. + * QuestEventRunResult - Quest result holder, for passing more info back to core and allowing better control over AI's.<br>
  238. + * ==============================================<br>
  239. + * @author Szponiasty
  240. + */
  241. +public class QuestEventRunResult
  242. +{
  243. +   protected static final Logger _log = Logger.getLogger(QuestEventRunResult.class.getSimpleName());
  244. +
  245. +   /* ========================== FIELDS ================================= */
  246. +
  247. +   private final QuestEventControl _loopControl;
  248. +   private final QuestEventControl _callerExecControl;
  249. +
  250. +   private final String _debugInfo;
  251. +
  252. +   private final Object[] _additionalData;
  253. +
  254. +   /* ========================== CONSTRUCTORS =========================== */
  255. +
  256. +   /**
  257. +    * This class is used to pass more extensive result information from DP AI/Quest events, back to core, to allow better control over behaviors.
  258. +    * @param loopControl   determines, if next existing event of the same type, should be executed, or execution loop should be breaked.
  259. +    * @param callerExecControl    determines if further execution of code that called event, should be continued, or method should be aborted.
  260. +    * @param debugInfo    some short descriptive info, to be logged/showed while debugging, for better understanding.
  261. +    * @param additionalData    any additional data (if any), to be passed back.
  262. +    */
  263. +   public QuestEventRunResult(QuestEventControl loopControl, QuestEventControl callerExecControl, String debugInfo, Object... additionalData)
  264. +   {
  265. +       _loopControl = loopControl;
  266. +       _callerExecControl = callerExecControl;
  267. +       _debugInfo = debugInfo;
  268. +       if (additionalData != null)
  269. +       {
  270. +           _additionalData = new Object[additionalData.length];
  271. +           int i = 0;
  272. +           for (Object data : additionalData)
  273. +               _additionalData[i++] = data;
  274. +       }
  275. +       else
  276. +           _additionalData = null;
  277. +   }
  278. +
  279. +   /* ========================== MAIN BODY ============================== */
  280. +
  281. +   /**
  282. +    * Get all additional (if any) datas, returned by event.
  283. +    * @return
  284. +    */
  285. +   public final Object[] getAdditionalData()
  286. +   {
  287. +       return _additionalData;
  288. +   }
  289. +
  290. +   /**
  291. +    * Get additional info used for debugging (if any), returned by event.
  292. +    * @return
  293. +    */
  294. +   public final String getDebugInfo()
  295. +   {
  296. +       return _debugInfo;
  297. +   }
  298. +
  299. +   /**
  300. +    * Get execution of next events of same type, in current loop, control.
  301. +    * @return
  302. +    */
  303. +   public final QuestEventControl getLoopControl()
  304. +   {
  305. +       return _loopControl;
  306. +   }
  307. +
  308. +   /**
  309. +    * Get caller method execution control.
  310. +    * @return
  311. +    */
  312. +   public final QuestEventControl getCallerExecControl()
  313. +   {
  314. +       return _callerExecControl;
  315. +   }
  316. +}
  317. Index: java/com/l2jserver/gameserver/model/quest/Quest.java
  318. IDEA additional info:
  319. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  320. <+>UTF-8
  321. ===================================================================
  322. --- java/com/l2jserver/gameserver/model/quest/Quest.java    (revision 6319)
  323. +++ java/com/l2jserver/gameserver/model/quest/Quest.java    (revision )
  324. @@ -18,30 +18,17 @@
  325.   */
  326.  package com.l2jserver.gameserver.model.quest;
  327.  
  328. -import java.sql.Connection;
  329. -import java.sql.PreparedStatement;
  330. -import java.sql.ResultSet;
  331. -import java.util.ArrayList;
  332. -import java.util.Collection;
  333. -import java.util.HashMap;
  334. -import java.util.HashSet;
  335. -import java.util.List;
  336. -import java.util.Map;
  337. -import java.util.Set;
  338. -import java.util.concurrent.locks.ReentrantReadWriteLock;
  339. -import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
  340. -import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
  341. -import java.util.logging.Level;
  342. -import java.util.logging.Logger;
  343. -
  344.  import com.l2jserver.Config;
  345.  import com.l2jserver.L2DatabaseFactory;
  346.  import com.l2jserver.gameserver.GameTimeController;
  347.  import com.l2jserver.gameserver.ThreadPoolManager;
  348. +import com.l2jserver.gameserver.ai.CtrlEvent;
  349. +import com.l2jserver.gameserver.ai.IntentionCommand;
  350.  import com.l2jserver.gameserver.cache.HtmCache;
  351.  import com.l2jserver.gameserver.datatables.DoorTable;
  352.  import com.l2jserver.gameserver.datatables.ItemTable;
  353.  import com.l2jserver.gameserver.datatables.NpcTable;
  354. +import com.l2jserver.gameserver.enums.QuestEventControl;
  355.  import com.l2jserver.gameserver.enums.QuestEventType;
  356.  import com.l2jserver.gameserver.enums.QuestSound;
  357.  import com.l2jserver.gameserver.enums.TrapAction;
  358. @@ -78,14 +65,7 @@
  359.  import com.l2jserver.gameserver.model.zone.L2ZoneType;
  360.  import com.l2jserver.gameserver.network.NpcStringId;
  361.  import com.l2jserver.gameserver.network.SystemMessageId;
  362. -import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  363. -import com.l2jserver.gameserver.network.serverpackets.ExShowScreenMessage;
  364. -import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  365. -import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  366. -import com.l2jserver.gameserver.network.serverpackets.NpcQuestHtmlMessage;
  367. -import com.l2jserver.gameserver.network.serverpackets.SpecialCamera;
  368. -import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  369. -import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  370. +import com.l2jserver.gameserver.network.serverpackets.*;
  371.  import com.l2jserver.gameserver.scripting.ManagedScript;
  372.  import com.l2jserver.gameserver.scripting.ScriptManager;
  373.  import com.l2jserver.gameserver.util.MinionList;
  374. @@ -93,6 +73,16 @@
  375.  import com.l2jserver.util.Rnd;
  376.  import com.l2jserver.util.Util;
  377.  
  378. +import java.sql.Connection;
  379. +import java.sql.PreparedStatement;
  380. +import java.sql.ResultSet;
  381. +import java.util.*;
  382. +import java.util.concurrent.locks.ReentrantReadWriteLock;
  383. +import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
  384. +import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
  385. +import java.util.logging.Level;
  386. +import java.util.logging.Logger;
  387. +
  388.  /**
  389.   * Quest main class.
  390.   * @author Luis Arias
  391. @@ -124,7 +114,10 @@
  392.    
  393.     private static final String DEFAULT_NO_QUEST_MSG = "<html><body>You are either not on a quest that involves this NPC, or you don't meet this NPC's minimum quest requirements.</body></html>";
  394.     private static final String DEFAULT_ALREADY_COMPLETED_MSG = "<html><body>This quest has already been completed.</body></html>";
  395. -  
  396. +
  397. +   public static final QuestEventRunResult UNDETERMINED_RESULT = new QuestEventRunResult(QuestEventControl.CONTINUE, QuestEventControl.CONTINUE, null);
  398. +   public static final QuestEventRunResult UNDETERMINED_RESULT_WITH_EXCEPTION = new QuestEventRunResult(QuestEventControl.CONTINUE, QuestEventControl.CONTINUE, "Exception on onNotifyAI...() in notifyAI...().");
  399. +
  400.     private static final String QUEST_DELETE_FROM_CHAR_QUERY = "DELETE FROM character_quests WHERE charId=? AND name=?";
  401.     private static final String QUEST_DELETE_FROM_CHAR_QUERY_NON_REPEATABLE_QUERY = "DELETE FROM character_quests WHERE charId=? AND name=? AND var!=?";
  402.    
  403. @@ -543,9 +536,94 @@
  404.             _log.log(Level.WARNING, "Exception on onSpawn() in notifySpawn(): " + e.getMessage(), e);
  405.         }
  406.     }
  407. -  
  408. +
  409.     /**
  410. +    * @param npc the NPC
  411. +    */
  412. +   public final QuestEventRunResult notifyAITaskRun(L2Npc npc)
  413. +   {
  414. +       try
  415. +       {
  416. +           QuestEventRunResult r = onNotifyAITaskRun(npc);
  417. +           return r != null ? r : UNDETERMINED_RESULT;
  418. +       }
  419. +       catch (Exception e)
  420. +       {
  421. +           _log.log(Level.WARNING, "Exception on onNotifyAITaskRun() in notifyAITaskRun(): " + e.getMessage(), e);
  422. +           return UNDETERMINED_RESULT_WITH_EXCEPTION;
  423. +       }
  424. +   }
  425. +
  426. +   /**
  427. +    * Executed by L2Attackable.run(), before evtThink().
  428. +    * @param npc
  429. +    * @return
  430. +    */
  431. +   public QuestEventRunResult onNotifyAITaskRun(final L2Npc npc)
  432. +   {
  433. +       return null;
  434. +   }
  435. +
  436. +   /**
  437. +    * @param npc the NPC
  438. +    */
  439. +   public final QuestEventRunResult notifyAIIntention(L2Npc npc, IntentionCommand intentionCommand)
  440. +   {
  441. +       try
  442. +       {
  443. +           QuestEventRunResult r = onNotifyAIIntention(npc, intentionCommand);
  444. +           return r != null ? r : UNDETERMINED_RESULT;
  445. +       }
  446. +       catch (Exception e)
  447. +       {
  448. +           _log.log(Level.WARNING, "Exception on onNotifyAIIntention() in notifyAIIntention(): " + e.getMessage(), e);
  449. +           return UNDETERMINED_RESULT_WITH_EXCEPTION;
  450. +       }
  451. +   }
  452. +
  453. +   /**
  454. +    * Executed by AI's, in setIntention() before anything else.
  455. +    * @param npc
  456. +    * @param intentionCommand
  457. +    * @return
  458. +    */
  459. +   public QuestEventRunResult onNotifyAIIntention(final L2Npc npc, final IntentionCommand intentionCommand)
  460. +   {
  461. +       return null;
  462. +   }
  463. +
  464. +   /**
  465. +    * @param npc the NPC
  466. +    */
  467. +   public final QuestEventRunResult notifyAIEvent(L2Npc npc, CtrlEvent event, Object arg0, Object arg1)
  468. +   {
  469. +       try
  470. +       {
  471. +           QuestEventRunResult r = onNotifyAIEvent(npc, event, arg0, arg1);
  472. +           return r != null ? r : UNDETERMINED_RESULT;
  473. +       }
  474. +       catch (Exception e)
  475. +       {
  476. +           _log.log(Level.WARNING, "Exception on onNotifyAIEvent() in notifyAIEvent(): " + e.getMessage(), e);
  477. +           return UNDETERMINED_RESULT_WITH_EXCEPTION;
  478. +       }
  479. +   }
  480. +
  481. +   /**
  482. +    * Executed by as first thing, in AbstractAI.notifyEvent().
  483. +    * @param npc
  484.      * @param event
  485. +    * @param arg0
  486. +    * @param arg1
  487. +    * @return
  488. +    */
  489. +   public QuestEventRunResult onNotifyAIEvent(final L2Npc npc, final CtrlEvent event, final Object arg0, final Object arg1)
  490. +   {
  491. +       return null;
  492. +   }
  493. +
  494. +   /**
  495. +    * @param event
  496.      * @param npc
  497.      * @param player
  498.      * @return {@code false} if there was an error or the message was sent, {@code true} otherwise
  499. @@ -1819,8 +1897,64 @@
  500.     public void addAttackId(int npcId)
  501.     {
  502.         addEventId(QuestEventType.ON_ATTACK, npcId);
  503. +   }
  504. +
  505. +   /**
  506. +    * See {@link Quest#addAITaskRun(int)}
  507. +    * @param npcIds
  508. +    */
  509. +   public void addAITaskRun(int... npcIds)
  510. +   {
  511. +       for (int npcId : npcIds)
  512. +           addAITaskRun(npcId);
  513. +   }
  514. +
  515. +   /**
  516. +    * Add the quest to the NPC's AI task run (executed by active L2AttackableAI's)
  517. +    */
  518. +   public void addAITaskRun(int npcId)
  519. +   {
  520. +       addEventId(QuestEventType.ON_AI_TASK_RUN, npcId);
  521. +   }
  522. +
  523. +   /**
  524. +    * See {@link Quest#addAIIntention(int)}
  525. +    * @param npcIds
  526. +    */
  527. +   public void addAIIntention(int... npcIds)
  528. +   {
  529. +       for (int npcId : npcIds)
  530. +           addAIIntention(npcId);
  531. +   }
  532. +
  533. +   /**
  534. +    * Add the quest to the NPC's AI setIntention() run
  535. +    * @param npcId
  536. +    */
  537. +   public void addAIIntention(int npcId)
  538. +   {
  539. +       addEventId(QuestEventType.ON_AI_INTENTION, npcId);
  540. +   }
  541. +
  542. +   /**
  543. +    * See {@link Quest#addAIEvent(int)}
  544. +    * @param npcIds
  545. +    */
  546. +   public void addAIEvent(int... npcIds)
  547. +   {
  548. +       for (int npcId : npcIds)
  549. +           addAIEvent(npcId);
  550. +   }
  551. +
  552. +   /**
  553. +    * Add the quest to the NPC's AI notify event run
  554. +    * @param npcId
  555. +    */
  556. +   public void addAIEvent(int npcId)
  557. +   {
  558. +       addEventId(QuestEventType.ON_AI_EVENT, npcId);
  559.     }
  560. -  
  561. +
  562.     /**
  563.      * Add the quest to the NPC's startQuest
  564.      * @param npcIds
  565. Index: java/com/l2jserver/gameserver/ai/L2CharacterAI.java
  566. IDEA additional info:
  567. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  568. <+>UTF-8
  569. ===================================================================
  570. --- java/com/l2jserver/gameserver/ai/L2CharacterAI.java (revision 6319)
  571. +++ java/com/l2jserver/gameserver/ai/L2CharacterAI.java (revision )
  572. @@ -18,20 +18,6 @@
  573.   */
  574.  package com.l2jserver.gameserver.ai;
  575.  
  576. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
  577. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
  578. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_CAST;
  579. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_FOLLOW;
  580. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
  581. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_INTERACT;
  582. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_MOVE_TO;
  583. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_PICK_UP;
  584. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_REST;
  585. -
  586. -import java.util.List;
  587. -
  588. -import javolution.util.FastList;
  589. -
  590.  import com.l2jserver.Config;
  591.  import com.l2jserver.gameserver.GameTimeController;
  592.  import com.l2jserver.gameserver.GeoData;
  593. @@ -62,7 +48,12 @@
  594.  import com.l2jserver.gameserver.network.serverpackets.AutoAttackStop;
  595.  import com.l2jserver.gameserver.taskmanager.AttackStanceTaskManager;
  596.  import com.l2jserver.util.Rnd;
  597. +import javolution.util.FastList;
  598.  
  599. +import java.util.List;
  600. +
  601. +import static com.l2jserver.gameserver.ai.CtrlIntention.*;
  602. +
  603.  /**
  604.   * This class manages AI of L2Character.<br>
  605.   * L2CharacterAI :
  606. @@ -75,24 +66,6 @@
  607.   */
  608.  public class L2CharacterAI extends AbstractAI
  609.  {
  610. -   public static class IntentionCommand
  611. -   {
  612. -       protected final CtrlIntention _crtlIntention;
  613. -       protected final Object _arg0, _arg1;
  614. -      
  615. -       protected IntentionCommand(CtrlIntention pIntention, Object pArg0, Object pArg1)
  616. -       {
  617. -           _crtlIntention = pIntention;
  618. -           _arg0 = pArg0;
  619. -           _arg1 = pArg1;
  620. -       }
  621. -      
  622. -       public CtrlIntention getCtrlIntention()
  623. -       {
  624. -           return _crtlIntention;
  625. -       }
  626. -   }
  627. -  
  628.     /**
  629.      * Cast Task
  630.      * @author Zoey76
  631. @@ -211,7 +184,7 @@
  632.             }
  633.            
  634.             // Launch the Think Event
  635. -           onEvtThink();
  636. +           notifyEvent(CtrlEvent.EVT_THINK); // NOTE: Szponiasty: using notifyEvent instead of onEvtThink(), to allow running dp side quest scripts that control AI on event trigger.
  637.         }
  638.     }
  639.    
  640. @@ -707,7 +680,7 @@
  641.     protected void onEvtReadyToAct()
  642.     {
  643.         // Launch actions corresponding to the Event Think
  644. -       onEvtThink();
  645. +       notifyEvent(CtrlEvent.EVT_THINK); // NOTE: Szponiasty: using notifyEvent instead of onEvtThink(), to allow running dp side quest scripts that control AI on ev
  646.     }
  647.    
  648.     /**
  649. @@ -765,7 +738,7 @@
  650.         }
  651.        
  652.         // Launch actions corresponding to the Event Think
  653. -       onEvtThink();
  654. +       notifyEvent(CtrlEvent.EVT_THINK);
  655.     }
  656.    
  657.     /**
  658. @@ -779,7 +752,7 @@
  659.     protected void onEvtArrivedRevalidate()
  660.     {
  661.         // Launch actions corresponding to the Event Think
  662. -       onEvtThink();
  663. +       notifyEvent(CtrlEvent.EVT_THINK);
  664.     }
  665.    
  666.     /**
  667. @@ -804,7 +777,7 @@
  668.         clientStopMoving(blocked_at_loc);
  669.        
  670.         // Launch actions corresponding to the Event Think
  671. -       onEvtThink();
  672. +       notifyEvent(CtrlEvent.EVT_THINK);
  673.     }
  674.    
  675.     /**
  676. @@ -906,7 +879,7 @@
  677.         }
  678.        
  679.         // Launch actions corresponding to the Event Think
  680. -       onEvtThink();
  681. +       notifyEvent(CtrlEvent.EVT_THINK);
  682.     }
  683.    
  684.     /**
  685. Index: java/com/l2jserver/gameserver/ai/AbstractAI.java
  686. IDEA additional info:
  687. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  688. <+>UTF-8
  689. ===================================================================
  690. --- java/com/l2jserver/gameserver/ai/AbstractAI.java    (revision 6319)
  691. +++ java/com/l2jserver/gameserver/ai/AbstractAI.java    (revision )
  692. @@ -18,31 +18,28 @@
  693.   */
  694.  package com.l2jserver.gameserver.ai;
  695.  
  696. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
  697. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_FOLLOW;
  698. -import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
  699. -
  700. -import java.util.concurrent.Future;
  701. -import java.util.logging.Logger;
  702. -
  703.  import com.l2jserver.gameserver.GameTimeController;
  704.  import com.l2jserver.gameserver.ThreadPoolManager;
  705. +import com.l2jserver.gameserver.enums.QuestEventControl;
  706. +import com.l2jserver.gameserver.enums.QuestEventType;
  707.  import com.l2jserver.gameserver.model.L2Object;
  708.  import com.l2jserver.gameserver.model.Location;
  709.  import com.l2jserver.gameserver.model.actor.L2Character;
  710. +import com.l2jserver.gameserver.model.actor.L2Npc;
  711.  import com.l2jserver.gameserver.model.actor.L2Summon;
  712.  import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  713. +import com.l2jserver.gameserver.model.quest.Quest;
  714. +import com.l2jserver.gameserver.model.quest.QuestEventRunResult;
  715.  import com.l2jserver.gameserver.model.skills.L2Skill;
  716. -import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  717. -import com.l2jserver.gameserver.network.serverpackets.AutoAttackStart;
  718. -import com.l2jserver.gameserver.network.serverpackets.AutoAttackStop;
  719. -import com.l2jserver.gameserver.network.serverpackets.Die;
  720. -import com.l2jserver.gameserver.network.serverpackets.MoveToLocation;
  721. -import com.l2jserver.gameserver.network.serverpackets.MoveToPawn;
  722. -import com.l2jserver.gameserver.network.serverpackets.StopMove;
  723. -import com.l2jserver.gameserver.network.serverpackets.StopRotation;
  724. +import com.l2jserver.gameserver.network.serverpackets.*;
  725.  import com.l2jserver.gameserver.taskmanager.AttackStanceTaskManager;
  726.  
  727. +import java.util.List;
  728. +import java.util.concurrent.Future;
  729. +import java.util.logging.Logger;
  730. +
  731. +import static com.l2jserver.gameserver.ai.CtrlIntention.*;
  732. +
  733.  /**
  734.   * Mother class of all objects AI in the world.<br>
  735.   * AbastractAI :<br>
  736. @@ -184,8 +181,19 @@
  737.     {
  738.         return _actor;
  739.     }
  740. -  
  741. +
  742.     /**
  743. +    * If actor is L2Npc insrance, returns (L2Npc)getActor(). Otherwise returns null.
  744. +    * @return
  745. +    */
  746. +   public final L2Npc getNpc()
  747. +   {
  748. +       if (_actor instanceof L2Npc)
  749. +           return (L2Npc)_actor;
  750. +       return null;
  751. +   }
  752. +
  753. +   /**
  754.      * @return the current Intention.
  755.      */
  756.     @Override
  757. @@ -264,6 +272,23 @@
  758.     @Override
  759.     public final void setIntention(CtrlIntention intention, Object arg0, Object arg1)
  760.     {
  761. +       boolean breakExec = false;
  762. +       final L2Npc me = getNpc();
  763. +       List<Quest> qe = null;
  764. +       if (me != null && (qe = me.getTemplate().getEventQuests(QuestEventType.ON_AI_INTENTION)) != null)
  765. +       {
  766. +           for (Quest quest : qe)
  767. +           {
  768. +               QuestEventRunResult r = quest.notifyAIIntention(me, new IntentionCommand(intention, arg0, arg1));
  769. +               if (!breakExec && r.getCallerExecControl() == QuestEventControl.BREAK)
  770. +                   breakExec = true;
  771. +               if (r.getLoopControl() == QuestEventControl.BREAK) // dp script resulted in request to abort loop.
  772. +                   break;
  773. +           }
  774. +       }
  775. +       if (breakExec) // one of dp scripts resulted in request to abort caller method execution.
  776. +           return;
  777. +
  778.         // Stop the follow mode if necessary
  779.         if ((intention != AI_INTENTION_FOLLOW) && (intention != AI_INTENTION_ATTACK))
  780.         {
  781. @@ -340,6 +365,23 @@
  782.     @Override
  783.     public final void notifyEvent(CtrlEvent evt, Object arg0, Object arg1)
  784.     {
  785. +       boolean breakExec = false;
  786. +       final L2Npc me = getNpc();
  787. +       List<Quest> qe = null;
  788. +       if (me != null && (qe = me.getTemplate().getEventQuests(QuestEventType.ON_AI_EVENT)) != null)
  789. +       {
  790. +           for (Quest quest : qe)
  791. +           {
  792. +               QuestEventRunResult r = quest.notifyAIEvent(me, evt, arg0, arg1);
  793. +               if (!breakExec && r.getCallerExecControl() == QuestEventControl.BREAK)
  794. +                   breakExec = true;
  795. +               if (r.getLoopControl() == QuestEventControl.BREAK) // dp script resulted in request to abort loop.
  796. +                   break;
  797. +           }
  798. +       }
  799. +       if (breakExec) // one of dp scripts resulted in request to abort caller method execution.
  800. +           return;
  801. +
  802.         if ((!_actor.isVisible() && !_actor.isTeleporting()) || !_actor.hasAI())
  803.         {
  804.             return;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement