Index: C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/quest/State.java
===================================================================
--- C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/quest/State.java (revision 1470)
+++ C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/quest/State.java (working copy)
@@ -43,6 +43,7 @@
private HashMap<Integer, ArrayList<L2DropData>> _Drops;
private String[] _Events = emptyStrList;
private String _Name;
+ private int[] _AttackIds = emptyIntList;
private int[] _KillIds = emptyIntList;
private int[] _TalkIds = emptyIntList;
@@ -61,6 +62,16 @@
// =========================================================
// Method - Public
+ /**
+ * Add mob to be attacked in the list at start of the quest.<BR><BR>
+ * @param attackId
+ * @return int : attackId
+ */
+ public int addAttackId(int attackId) {
+ _AttackIds = addToIntArray(_AttackIds, attackId);
+ return attackId;
+ }
+
/**
* Add mob to be killed in the list at start of the quest.<BR><BR>
* @param killId
@@ -111,11 +122,6 @@
// =========================================================
// Method - Private
- /**
- * Add NPC in the list of NPC to be talked
- * @param talkId : ID of the NPC
- * @return int : ID of the NPC
- */
private int[] addToIntArray(int[] intArray, int value) {
int len = intArray.length;
int[] tmp = new int[len+1];
@@ -128,6 +134,14 @@
// =========================================================
// Proeprty
/**
+ * Return table of all NPC's ID to attack for quest.
+ * @return int[]
+ */
+ int[] getAttackIds() {
+ return _KillIds;
+ }
+
+ /**
* Return list of drops at this step/state of the quest.
* @return HashMap
*/
Index: C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/quest/Quest.java
===================================================================
--- C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/quest/Quest.java (revision 1470)
+++ C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/quest/Quest.java (working copy)
@@ -196,11 +196,16 @@
}
// these are methods to call from java
- public final boolean notifyEvent(String event, QuestState qs) {
- String res = null;
- try { res = onEvent(event, qs); } catch (Exception e) { return showError(qs, e); }
- return showResult(qs, res);
- }
+ public final boolean notifyAttack(L2NpcInstance npc, QuestState qs) {
+ String res = null;
+ try { res = onAttack(npc, qs); } catch (Exception e) { return showError(qs, e); }
+ return showResult(qs, res);
+ }
+ public final boolean notifyEvent(String event, QuestState qs) {
+ String res = null;
+ try { res = onEvent(event, qs); } catch (Exception e) { return showError(qs, e); }
+ return showResult(qs, res);
+ }
public final boolean notifyKill (L2NpcInstance npc, QuestState qs) {
String res = null;
try { res = onKill(npc, qs); } catch (Exception e) { return showError(qs, e); }
@@ -214,12 +219,10 @@
}
// these are methods that java calls to invoke scripts
- @SuppressWarnings("unused")
- public String onEvent(String event, QuestState qs) { return null; }
- @SuppressWarnings("unused")
- public String onKill (L2NpcInstance npc, QuestState qs) { return onEvent("", qs); }
- @SuppressWarnings("unused")
- public String onTalk (L2NpcInstance npc, QuestState qs) { return onEvent("", qs); }
+ @SuppressWarnings("unused") public String onAttack(L2NpcInstance npc, QuestState qs) { return onEvent("", qs); }
+ @SuppressWarnings("unused") public String onEvent(String event, QuestState qs) { return null; }
+ @SuppressWarnings("unused") public String onKill (L2NpcInstance npc, QuestState qs) { return onEvent("", qs); }
+ @SuppressWarnings("unused") public String onTalk (L2NpcInstance npc, QuestState qs) { return onEvent("", qs); }
/**
* Show message error to player who has an access level greater than 0
Index: C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/L2PcInstance.java
===================================================================
--- C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/L2PcInstance.java (revision 1470)
+++ C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/L2PcInstance.java (working copy)
@@ -836,6 +836,14 @@
_quests.remove(quest);
}
+ private QuestState[] addToQuestStateArray(QuestState[] questStateArray, QuestState state) {
+ int len = questStateArray.length;
+ QuestState[] tmp = new QuestState[len+1];
+ for (int i=0; i < len; i++)
+ tmp[i] = questStateArray[i];
+ tmp[len] = state;
+ return tmp;
+ }
/**
* Return a table containing all Quest in progress from the table _quests.<BR><BR>
@@ -861,6 +869,64 @@
return quests.toArray(new Quest[quests.size()]);
}
+ /**
+ * Return a table containing all QuestState to modify after a L2Attackable killing.<BR><BR>
+ *
+ * @param npcId The Identifier of the L2Attackable attacked
+ *
+ */
+ public QuestState[] getQuestsForAttacks(L2NpcInstance npc)
+ {
+ // Create a QuestState table that will contain all QuestState to modify
+ QuestState[] states = null;
+
+ // Go through the QuestState of the L2PcInstance quests
+ for (QuestState qs : _quests.values())
+ {
+ // Check if the Identifier of the L2Attackable killed is needed for the current quest
+ if (qs.waitsForKill(npc))
+ {
+ // Copy the current L2PcInstance QuestState in the QuestState table
+ if (states == null)
+ states = new QuestState[]{qs};
+ else
+ states = addToQuestStateArray(states, qs);
+ }
+ }
+
+ // Return a table containing all QuestState to modify
+ return states;
+ }
+
+ /**
+ * Return a table containing all QuestState to modify after a L2Attackable killing.<BR><BR>
+ *
+ * @param npcId The Identifier of the L2Attackable killed
+ *
+ */
+ public QuestState[] getQuestsForKills(L2NpcInstance npc)
+ {
+ // Create a QuestState table that will contain all QuestState to modify
+ QuestState[] states = null;
+
+ // Go through the QuestState of the L2PcInstance quests
+ for (QuestState qs : _quests.values())
+ {
+ // Check if the Identifier of the L2Attackable killed is needed for the current quest
+ if (qs.waitsForKill(npc))
+ {
+ // Copy the current L2PcInstance QuestState in the QuestState table
+ if (states == null)
+ states = new QuestState[]{qs};
+ else
+ states = addToQuestStateArray(states, qs);
+ }
+ }
+
+ // Return a table containing all QuestState to modify
+ return states;
+ }
+
/**
* Return a table containing all QuestState from the table _quests in which the L2PcInstance must talk to the NPC.<BR><BR>
*
@@ -869,75 +935,27 @@
*/
public QuestState[] getQuestsForTalk(int npcId)
{
+ // Create a QuestState table that will contain all QuestState to modify
QuestState[] states = null;
+ // Go through the QuestState of the L2PcInstance quests
for (QuestState qs : _quests.values())
{
+ // Check if the Identifier of the L2Attackable killed is needed for the current quest
if (qs.waitsForTalk(npcId))
{
+ // Copy the current L2PcInstance QuestState in the QuestState table
if (states == null)
- {
- states = new QuestState[]{qs};
- }
+ states = new QuestState[]{qs};
else
- {
- int len = states.length;
- QuestState[] tmp = new QuestState[len+1];
- for (int i=0; i < len; i++)
- tmp[i] = states[i];
- tmp[len] = qs;
- states = tmp;
- }
+ states = addToQuestStateArray(states, qs);
}
}
+ // Return a table containing all QuestState to modify
return states;
}
- /**
- * Return a table containing all QuestState to modify after a L2Attackable killing.<BR><BR>
- *
- * @param npcId The Identifier of the L2Attackable killed
- *
- */
- public QuestState[] getQuestsForKills(L2NpcInstance npc)
- {
- // Create a QuestState table that will contain all QuestState to modify
- QuestState[] states = null;
-
- // Go through the QuestState of the L2PcInstance quests
- for (QuestState qs : _quests.values())
- {
-
- // Check if the Identifier of the L2Attackable killed is needed for the current quest
- if (qs.waitsForKill(npc))
- {
- // Copy the current L2PcInstance QuestState in the QuestState table
- if (states == null)
- {
- // Create a new QuestState in the QuestState table
- states = new QuestState[]{qs};
- }
- else
- {
- // Add a new QuestState to the QuestState table
- int len = states.length;
-
- QuestState[] tmp = new QuestState[len+1];
-
- for (int i=0; i < len; i++)
- tmp[i] = states[i];
-
- tmp[len] = qs;
- states = tmp;
- }
- }
- }
-
- // Return a table containing all QuestState to modify
- return states;
- }
-
public QuestState processQuestEvent(String quest, String event)
{
QuestState retval = null;
Index: C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/L2Attackable.java
===================================================================
--- C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/L2Attackable.java (revision 1470)
+++ C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/L2Attackable.java (working copy)
@@ -774,6 +774,23 @@
// Notify the L2Attackable AI with EVT_ATTACKED
if (damage > 0)
getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, attacker);
+
+ try {
+ if (attacker instanceof L2PcInstance || attacker instanceof L2Summon)
+ {
+ L2PcInstance player = attacker instanceof L2PcInstance?(L2PcInstance)attacker:((L2SummonInstance)attacker).getOwner();
+
+ QuestState[] quests = player.getQuestsForAttacks(this);
+
+ if (quests != null)
+ {
+ for (QuestState qs : quests)
+ qs.getQuest().notifyAttack(this, qs);
+ }
+
+ }
+ }
+ catch (Exception e) { _log.log(Level.SEVERE, "", e); }
}