1 QuestHelper_File
["quest.lua"] = "Development Version"
3 local function QuestKnown(self
)
4 if not self
.target
and not self
.destination
then
6 self
.target
= self
.qh
:GetObjective("monster", self
.o
.finish
)
7 elseif self
.fb
.finish
then
8 self
.target
= self
.qh
:GetObjective("monster", self
.fb
.finish
)
10 self
.destination
= self
.o
.pos
11 elseif self
.fb
.pos
then
12 self
.destination
= self
.fb
.pos
15 return (self
.target
or self
.destination
) and self
:DefaultKnown() and (self
.destination
or self
.target
:Known())
18 local function QuestAppendPositions(self
, objective
, weight
, why
)
19 why2
= why
and why
.."\n" or ""
22 self
.target
:AppendPositions(self
, 1, why2
..QHFormat("OBJECTIVE_TALK", self
.o
.finish
or self
.fb
.finish
))
23 elseif self
.destination
then
24 for i
, p
in ipairs(self
.destination
) do
25 self
:AddLoc(p
[1], p
[2], p
[3], p
[4], p
[5])
30 QuestHelper
.default_objective_quest_param
=
33 AppendPositions
= QuestAppendPositions
36 for key
, value
in pairs(QuestHelper
.default_objective_param
) do
37 if not QuestHelper
.default_objective_quest_param
[key
] then
38 QuestHelper
.default_objective_quest_param
[key
] = value
42 QuestHelper
.default_objective_quest_meta
= { __index
= QuestHelper
.default_objective_quest_param
}
44 function QuestHelper
:GetQuest(name
, level
, hash
)
46 if QuestHelper_Quests
[self
.faction
] then
47 for l
, quest_list
in ipairs(QuestHelper_Quests
[self
.faction
]) do
48 if quest_list
[name
] then
56 QuestHelper_StaticData
[self
.locale
] and
57 QuestHelper_StaticData
[self
.locale
].quest
[self
.faction
] then
58 for l
, quest_list
in ipairs(QuestHelper_StaticData
[self
.locale
].quest
[self
.faction
]) do
59 if quest_list
[name
] then
67 error("Don't know of a quest named '"..name
.."' for your faction.")
70 self
:TextOut("Determined the quest level of '"..name
.."' to be "..level
..".")
73 local bracket
= self
.quest_objects
[level
]
77 self
.quest_objects
[level
] = bracket
80 local bracket2
= bracket
[name
]
84 bracket
[name
] = bracket2
87 local quest_object
= bracket2
[hash
or -1]
89 if not quest_object
then
90 quest_object
= self
:NewObjectiveObject()
91 quest_object
.icon_id
= 7
92 quest_object
.icon_bg
= 15
93 setmetatable(quest_object
, QuestHelper
.default_objective_quest_meta
)
95 quest_object
.cat
= "quest"
96 quest_object
.obj
= level
.."/"..(hash
or "").."/"..name
98 bracket2
[hash
or -1] = quest_object
100 local fbracket
= QuestHelper_Quests
[self
.faction
]
104 QuestHelper_Quests
[self
.faction
] = fbracket
107 bracket
= fbracket
[level
]
111 fbracket
[level
] = bracket
114 quest_object
.o
= bracket
[name
]
116 if not quest_object
.o
then
118 quest_object
.o
= {hash
=hash
}
119 bracket
[name
] = quest_object
.o
120 else -- Not going to actually save the quest without a hash.
125 local l
= QuestHelper_StaticData
[self
.locale
]
128 fbracket
= l
.quest
[self
.faction
]
130 bracket
= fbracket
[level
]
132 quest_object
.fb
= bracket
[name
]
136 if not quest_object
.fb
then
140 if quest_object
.o
.hash
and quest_object
.o
.hash
~= hash
then
141 if not quest_object
.o
.alt
then quest_object
.o
.alt
= {} end
142 local real_quest_data
= quest_object
.o
.alt
[hash
]
143 if not real_quest_data
then
144 real_quest_data
= {hash
=hash
}
145 quest_object
.o
.alt
[hash
] = real_quest_data
147 quest_object
.o
= real_quest_data
148 elseif not quest_object
.o
.hash
then
149 -- Not setting the hash now, as we might not actually have the correct quest loaded.
150 -- When we can verify our data is correct, we'll assign a value.
151 quest_object
.need_hash
= true
154 if hash
and quest_object
.fb
.hash
and quest_object
.fb
.hash
~= hash
then
155 quest_object
.fb
= quest_object
.fb
.alt
and quest_object
.fb
.alt
[hash
]
156 if not quest_object
.fb
then
161 -- TODO: If we have some other source of information (like LightHeaded) add its data to quest_object.fb
168 function QuestHelper
:PurgeItemFromQuest(quest
, item_name
, item_object
)
170 for hash
, alt_quest
in pairs(quest
.alt
) do
171 self
:PurgeItemFromQuest(alt_quest
, item_name
, item_object
)
176 local item_data
= quest
.item
[item_name
]
178 quest
.item
[item_name
] = nil
179 if not next(quest
.item
, nil) then quest
.item
= nil end
181 if item_data
.pos
then
182 for i
, pos
in ipairs(item_data
.pos
) do
183 self
:AppendObjectivePosition(item_object
, unpack(pos
))
186 if item_data
.drop
then
187 for monster
, count
in pairs(item_data
.drop
) do
188 self
:AppendObjectiveDrop(item_object
, monster
, count
)
192 if item_data
.contained
then
193 for item
, count
in pairs(item_data
.contained
) do
194 self
:AppendItemObjectiveContained(item_object
, item
, count
)
199 if item_object
.bad_pos
then
200 for i
, pos
in ipairs(item_object
.bad_pos
) do
201 self
:AppendObjectivePosition(item_object
, unpack(pos
))
203 item_object
.bad_pos
= nil
204 elseif item_object
.bad_drop
then
205 for monster
, count
in pairs(item_object
.bad_drop
) do
206 self
:AppendObjectiveDrop(item_object
, monster
, count
)
208 item_object
.bad_drop
= nil
214 function QuestHelper
:PurgeQuestItem(item_name
, item_object
)
215 for faction
, level_list
in pairs(QuestHelper_Quests
) do
216 for level
, quest_list
in pairs(level_list
) do
217 for quest_name
, quest
in pairs(quest_list
) do
218 self
:PurgeItemFromQuest(quest
, item_name
, item_object
)
224 function QuestHelper
:AppendQuestPosition(quest
, item_name
, i
, x
, y
, w
)
225 local item_list
= quest
.o
.item
227 if not item_list
then
229 quest
.o
.item
= item_list
232 local item
= item_list
[item_name
]
236 item_list
[item_name
] = item
242 return -- If it's dropped by a monster, don't record the position we got the item at.
244 item
.pos
= self
:AppendPosition({}, i
, x
, y
, w
)
246 self
:AppendPosition(pos
, i
, x
, y
, w
)
250 function QuestHelper
:AppendQuestDrop(quest
, item_name
, monster_name
, count
)
251 local item_list
= quest
.o
.item
253 if not item_list
then
255 quest
.o
.item
= item_list
258 local item
= item_list
[item_name
]
262 item_list
[item_name
] = item
265 local drop
= item
.drop
268 drop
[monster_name
] = (drop
[monster_name
] or 0) + (count
or 1)
270 item
.drop
= {[monster_name
] = count
or 1}
271 item
.pos
= nil -- If we know monsters drop the item, don't record the position we got the item at.