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 1465) +++ C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/quest/State.java (working copy) @@ -38,13 +38,13 @@ // TODO - End /** Name of the quest */ - public final String name; /** Quest object associated to the state */ public final Quest quest; - private HashMap> drops; - private String[] events = emptyStrList; - private int[] killIds = emptyIntList; - private int[] talkIds = emptyIntList; + private HashMap> _Drops; + private String[] _Events = emptyStrList; + private String _Name; + private int[] _KillIds = emptyIntList; + private int[] _TalkIds = emptyIntList; /** @@ -54,116 +54,125 @@ */ public State(String name, Quest quest) { - this.name = name; + _Name = name; this.quest = quest; quest.addState(this); } - - /** - * Return name of the quest - * @return String - */ - public String getName() - { - return name; - } - - /** - * Return name of the quest - * @return String - */ - public String toString() { - return name; - } - + + // ========================================================= + // Method - Public /** - * Return list of events - * @return String[] - */ - String[] getEvents() { - return events; - } - - /** - * Return table of all NPC's ID to kill for quest. - * @return int[] - */ - int[] getKillIds() { - return killIds; - } - - /** * Add mob to be killed in the list at start of the quest.

* @param killId * @return int : killId */ public int addKillId(int killId) { - int len = killIds.length; - int[] tmp = new int[len+1]; - for (int i=0; i < len; i++) - tmp[i] = killIds[i]; - tmp[len] =killId; - killIds = tmp; + _KillIds = addToIntArray(_KillIds, killId); return killId; } + + /** + * Add drop for the quest at this state of the quest + * @param npcId : int designating the ID of the NPC + * @param itemId : int designating the ID of the item dropped + * @param chance : int designating the chance the item dropped + */ + public void addQuestDrop(int npcId, int itemId, int chance) { + try { + if (_Drops == null) + _Drops = new HashMap>(); + L2DropData d = new L2DropData(); + d.setItemId(itemId); + d.setChance(chance); + d.setQuestID(quest.name); + d.addStates(new String[]{_Name}); + ArrayList lst = _Drops.get(npcId); + if (lst != null) { + lst.add(d); + } else { + lst = new ArrayList(); + lst.add(d); + _Drops.put(npcId, lst); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Add NPC in the list of NPC to be talked + * @param talkId : ID of the NPC + * @return int : ID of the NPC + */ + public int addTalkId(int talkId) { + _TalkIds = addToIntArray(_TalkIds, talkId); + return talkId; + } + + // ========================================================= + // 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]; + for (int i=0; i < len; i++) + tmp[i] = intArray[i]; + tmp[len] = value; + return tmp; + } + + // ========================================================= + // Proeprty + /** + * Return list of drops at this step/state of the quest. + * @return HashMap + */ + HashMap> getDrops() { + return _Drops; + } + + /** + * Return list of events + * @return String[] + */ + String[] getEvents() { + return _Events; + } + + /** + * Return table of all NPC's ID to kill for quest. + * @return int[] + */ + int[] getKillIds() { + return _KillIds; + } + + /** + * Return name of the quest + * @return String + */ + public String getName() + { + return _Name; + } /** * Return IDs of NPC to be talked for the quest * @return int[] */ int[] getTalkIds() { - return talkIds; + return _TalkIds; } - - /** - * Add NPC in the list of NPC to be talked - * @param talkId : ID of the NPC - * @return int : ID of the NPC - */ - public int addTalkId(int talkId) { - int len = talkIds.length; - int[] tmp = new int[len+1]; - for (int i=0; i < len; i++) - tmp[i] = talkIds[i]; - tmp[len] =talkId; - talkIds = tmp; - return talkId; - } - - /** - * Return list of drops at this step/state of the quest. - * @return HashMap - */ - HashMap> getDrops() { - return drops; - } - - /** - * Add drop for the quest at this state of the quest - * @param npcId : int designating the ID of the NPC - * @param itemId : int designating the ID of the item dropped - * @param chance : int designating the chance the item dropped - */ - public void addQuestDrop(int npcId, int itemId, int chance) { - try { - if (drops == null) - drops = new HashMap>(); - L2DropData d = new L2DropData(); - d.setItemId(itemId); - d.setChance(chance); - d.setQuestID(quest.name); - d.addStates(new String[]{this.name}); - ArrayList lst = drops.get(npcId); - if (lst != null) { - lst.add(d); - } else { - lst = new ArrayList(); - lst.add(d); - drops.put(npcId, lst); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - + + /** + * Return name of the quest + * @return String + */ + public String toString() { + return _Name; + } } 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 1465) +++ C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/quest/Quest.java (working copy) @@ -201,17 +201,15 @@ try { res = onEvent(event, qs); } catch (Exception e) { return showError(qs, e); } return showResult(qs, res); } - public final boolean notifyKill (int npcId, QuestState qs) { + public final boolean notifyKill (L2NpcInstance npc, QuestState qs) { String res = null; - try { res = onKill(npcId, qs); } catch (Exception e) { return showError(qs, e); } + try { res = onKill(npc, qs); } catch (Exception e) { return showError(qs, e); } return showResult(qs, res); } public final boolean notifyTalk (L2NpcInstance npc, QuestState qs) { String res = null; - int npcId = npc.getTemplate().npcId; - int objId = npc.getObjectId(); - try { res = onTalk(npcId, qs); } catch (Exception e) { return showError(qs, e); } - qs.getPlayer().setLastQuestNpcObject(objId); + try { res = onTalk(npc, qs); } catch (Exception e) { return showError(qs, e); } + qs.getPlayer().setLastQuestNpcObject(npc.getObjectId()); return showResult(qs, res); } @@ -219,9 +217,9 @@ @SuppressWarnings("unused") public String onEvent(String event, QuestState qs) { return null; } @SuppressWarnings("unused") - public String onKill (int npcId, QuestState qs) { return onEvent("", qs); } + public String onKill (L2NpcInstance npc, QuestState qs) { return onEvent("", qs); } @SuppressWarnings("unused") - public String onTalk (int npcId, QuestState qs) { return onEvent("", qs); } + 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/quest/QuestState.java =================================================================== --- C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/quest/QuestState.java (revision 1465) +++ C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/quest/QuestState.java (working copy) @@ -313,9 +313,9 @@ * @param npcId * @return boolean */ - public boolean waitsForKill(int npcId) { + public boolean waitsForKill(L2NpcInstance npc) { for (int k : state.getKillIds()) { - if (k == npcId) { + if (k == npc.getNpcId()) { return true; } } @@ -349,7 +349,7 @@ d.setItemId(itemId); d.setChance(chance); d.setQuestID(quest.name); - d.addStates(new String[]{state.name}); + d.addStates(new String[]{state.getName()}); ArrayList lst = drops.get(npcId); if (lst != null) { lst.add(d); @@ -393,12 +393,15 @@ * @param itemId : ID of the item wanted to be count * @return int */ - public int getQuestItemsCount(int itemId) { - L2ItemInstance inst = player.getInventory().getItemByItemId(itemId); - if (inst == null) - return 0; - return inst.getCount(); - } + public int getQuestItemsCount(int itemId) { + int count = 0; + for (L2ItemInstance item: player.getInventory().getItems()) + { + if (item.getItemId() == itemId) + count += item.getCount(); + } + return count; + } /** * Return the level of enchantment on the weapon of the player(Done specifically for weapon SA's) 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 1465) +++ C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/L2PcInstance.java (working copy) @@ -900,7 +900,7 @@ * @param npcId The Identifier of the L2Attackable killed * */ - public QuestState[] getQuestsForKills(int npcId) + public QuestState[] getQuestsForKills(L2NpcInstance npc) { // Create a QuestState table that will contain all QuestState to modify QuestState[] states = null; @@ -910,7 +910,7 @@ { // Check if the Identifier of the L2Attackable killed is needed for the current quest - if (qs.waitsForKill(npcId)) + if (qs.waitsForKill(npc)) { // Copy the current L2PcInstance QuestState in the QuestState table if (states == 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 1465) +++ C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/L2Attackable.java (working copy) @@ -484,7 +484,7 @@ L2PcInstance player = (L2PcInstance)killer; // Get a table containing all QuestState to modify after the L2Attackable killing - QuestState[] quests = player.getQuestsForKills(getTemplate().npcId); + QuestState[] quests = player.getQuestsForKills(this); if (quests != null) { @@ -492,7 +492,7 @@ for (QuestState qs : quests) { // Notify the Quest Engine of the L2Attackable death - qs.getQuest().notifyKill(getTemplate().npcId, qs); + qs.getQuest().notifyKill(this, qs); } } Index: C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/L2Character.java =================================================================== --- C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/L2Character.java (revision 1465) +++ C:/Development/l2j/eclipse/workspace/L2_GameserverSVN/java/net/sf/l2j/gameserver/model/L2Character.java (working copy) @@ -485,6 +485,9 @@ /** Attacking L2Character (the L2Character that attacks this one) */ private L2Character _attackingChar; + /** List of all L2Character instance that attacked (would be used for quest) */ + private ArrayList _AttackByList = new ArrayList(); + /** Attacking L2Character's Skill */ private L2Skill _attackingCharSkill; @@ -676,8 +679,11 @@ */ public void setAttackingChar (L2Character player) { - if (player != this) - _attackingChar = player; + if (player == null || player == this) + return; + + _attackingChar = player; + addAttackerToAttackByList(player); } /** @@ -691,6 +697,34 @@ _attackingCharSkill = skill; } + /** + * Add L2Character instance that is attacking to the attacker list.

+ * + * @param player The L2Character that attcks this one + * + */ + public void addAttackerToAttackByList (L2Character player) + { + if (player == null || player == this || _AttackByList.contains(player)) + return; + + _AttackByList.add(player); + } + + /** + * Add L2Character instance that is attacking to the attacker list.

+ * + * @param player The L2Character that attcks this one + * + */ + public ArrayList getAttackByList () + { + if (_AttackByList == null) + _AttackByList = new ArrayList(); + + return _AttackByList; + } + /** * Return the L2CharacterAI of the L2Character and if its null create a new one.

*/