1 local function QuestKnown(self
)
2 if not self
.target
and not self
.destination
then
4 self
.target
= self
.qh
:GetObjective("monster", self
.o
.finish
)
5 elseif self
.fb
.finish
then
6 self
.target
= self
.qh
:GetObjective("monster", self
.fb
.finish
)
8 self
.destination
= self
.o
.pos
9 elseif self
.fb
.pos
then
10 self
.destination
= self
.fb
.pos
13 return (self
.target
or self
.destination
) and self
:DefaultKnown() and (self
.destination
or self
.target
:Known())
16 local function QuestAppendPositions(self
, objective
, weight
, why
)
17 why2
= why
and why
.."\n" or ""
20 self
.target
:AppendPositions(self
, 1, why2
..QHFormat("OBJECTIVE_TALK", self
.o
.finish
or self
.fb
.finish
))
21 elseif self
.destination
then
22 for i
, p
in ipairs(self
.destination
) do
23 self
:AddLoc(p
[1], p
[2], p
[3], p
[4], p
[5])
28 function QuestHelper
:GetQuest(name
, level
, hash
)
30 if QuestHelper_Quests
[self
.faction
] then
31 for l
, quest_list
in ipairs(QuestHelper_Quests
[self
.faction
]) do
32 if quest_list
[name
] then
40 QuestHelper_StaticData
[self
.locale
] and
41 QuestHelper_StaticData
[self
.locale
].quest
[self
.faction
] then
42 for l
, quest_list
in ipairs(QuestHelper_StaticData
[self
.locale
].quest
[self
.faction
]) do
43 if quest_list
[name
] then
51 error("Don't know of a quest named '"..name
.."' for your faction.")
54 self
:TextOut("Determined the quest level of '"..name
.."' to be "..level
..".")
57 local bracket
= self
.quest_objects
[level
]
61 self
.quest_objects
[level
] = bracket
64 local bracket2
= bracket
[name
]
68 bracket
[name
] = bracket2
71 local quest_object
= bracket2
[hash
or -1]
73 if not quest_object
then
74 quest_object
= self
:NewObjectiveObject()
75 quest_object
.icon_id
= 7
76 quest_object
.icon_bg
= 15
77 quest_object
.AppendPositions
= QuestAppendPositions
78 quest_object
.Known
= QuestKnown
79 quest_object
.cat
= "quest"
80 quest_object
.obj
= level
.."/"..(hash
or "").."/"..name
82 bracket2
[hash
or -1] = quest_object
84 local fbracket
= QuestHelper_Quests
[self
.faction
]
88 QuestHelper_Quests
[self
.faction
] = fbracket
91 bracket
= fbracket
[level
]
95 fbracket
[level
] = bracket
98 quest_object
.o
= bracket
[name
]
100 if not quest_object
.o
then
102 quest_object
.o
= {hash
=hash
}
103 bracket
[name
] = quest_object
.o
104 else -- Not going to actually save the quest without a hash.
109 local l
= QuestHelper_StaticData
[self
.locale
]
112 fbracket
= l
.quest
[self
.faction
]
114 bracket
= fbracket
[level
]
116 quest_object
.fb
= bracket
[name
]
120 if not quest_object
.fb
then
124 if quest_object
.o
.hash
and quest_object
.o
.hash
~= hash
then
125 if not quest_object
.o
.alt
then quest_object
.o
.alt
= {} end
126 local real_quest_data
= quest_object
.o
.alt
[hash
]
127 if not real_quest_data
then
128 real_quest_data
= {hash
=hash
}
129 quest_object
.o
.alt
[hash
] = real_quest_data
131 quest_object
.o
= real_quest_data
132 elseif not quest_object
.o
.hash
then
133 -- Not setting the hash now, as we might not actually have the correct quest loaded.
134 -- When we can verify our data is correct, we'll assign a value.
135 quest_object
.need_hash
= true
138 if hash
and quest_object
.fb
.hash
and quest_object
.fb
.hash
~= hash
then
139 quest_object
.fb
= quest_object
.fb
.alt
and quest_object
.fb
.alt
[hash
]
140 if not quest_object
.fb
then
145 -- TODO: If we have some other source of information (like LightHeaded) add its data to quest_object.fb
152 function QuestHelper
:PurgeItemFromQuest(quest
, item_name
, item_object
)
154 for hash
, alt_quest
in pairs(quest
.alt
) do
155 self
:PurgeItemFromQuest(alt_quest
, item_name
, item_object
)
160 local item_data
= quest
.item
[item_name
]
162 quest
.item
[item_name
] = nil
163 if not next(quest
.item
, nil) then quest
.item
= nil end
165 if item_data
.pos
then
166 for i
, pos
in ipairs(item_data
.pos
) do
167 self
:AppendObjectivePosition(item_object
, unpack(pos
))
170 if item_data
.drop
then
171 for monster
, count
in pairs(item_data
.drop
) do
172 self
:AppendObjectiveDrop(item_object
, monster
, count
)
176 if item_data
.contained
then
177 for item
, count
in pairs(item_data
.contained
) do
178 self
:AppendItemObjectiveContained(item_object
, item
, count
)
183 if item_object
.bad_pos
then
184 for i
, pos
in ipairs(item_object
.bad_pos
) do
185 self
:AppendObjectivePosition(item_object
, unpack(pos
))
187 item_object
.bad_pos
= nil
188 elseif item_object
.bad_drop
then
189 for monster
, count
in pairs(item_object
.bad_drop
) do
190 self
:AppendObjectiveDrop(item_object
, monster
, count
)
192 item_object
.bad_drop
= nil
198 function QuestHelper
:PurgeQuestItem(item_name
, item_object
)
199 for faction
, level_list
in pairs(QuestHelper_Quests
) do
200 for level
, quest_list
in pairs(level_list
) do
201 for quest_name
, quest
in pairs(quest_list
) do
202 self
:PurgeItemFromQuest(quest
, item_name
, item_object
)
208 function QuestHelper
:AppendQuestPosition(quest
, item_name
, i
, x
, y
, w
)
209 local item_list
= quest
.o
.item
211 if not item_list
then
213 quest
.o
.item
= item_list
216 local item
= item_list
[item_name
]
220 item_list
[item_name
] = item
226 return -- If it's dropped by a monster, don't record the position we got the item at.
228 item
.pos
= self
:AppendPosition({}, i
, x
, y
, w
)
230 self
:AppendPosition(pos
, i
, x
, y
, w
)
234 function QuestHelper
:AppendQuestDrop(quest
, item_name
, monster_name
, count
)
235 local item_list
= quest
.o
.item
237 if not item_list
then
239 quest
.o
.item
= item_list
242 local item
= item_list
[item_name
]
246 item_list
[item_name
] = item
249 local drop
= item
.drop
252 drop
[monster_name
] = (drop
[monster_name
] or 0) + (count
or 1)
254 item
.drop
= {[monster_name
] = count
or 1}
255 item
.pos
= nil -- If we know monsters drop the item, don't record the position we got the item at.