1 QuestHelper_File
["quest.lua"] = "Development Version"
2 QuestHelper_Loadtime
["quest.lua"] = GetTime()
6 local function QuestKnown(self
)
7 if not self
.target
and not self
.destination
then
9 self
.target
= self
.qh
:GetObjective("monster", self
.o
.finish
)
10 elseif self
.fb
.finish
then
11 self
.target
= self
.qh
:GetObjective("monster", self
.fb
.finish
)
12 elseif self
.o
.pos
then
13 self
.destination
= self
.o
.pos
14 elseif self
.fb
.pos
then
15 self
.destination
= self
.fb
.pos
18 return (self
.target
or self
.destination
) and self
:DefaultKnown() and (self
.destination
or self
.target
:Known())
21 local function QuestAppendPositions(self
, objective
, weight
, why
, restrict
)
22 why2
= why
and why
.."\n" or ""
25 self
.target
:AppendPositions(self
, 1, why2
..QHFormat("OBJECTIVE_TALK", self
.o
.finish
or self
.fb
.finish
), restrict
)
26 elseif self
.destination
then
27 for i
, p
in ipairs(self
.destination
) do
28 if not restrict
or not self
.qh
:Disallowed(p
[1]) then
29 self
:AddLoc(p
[1], p
[2], p
[3], p
[4], p
[5])
35 QuestHelper
.default_objective_quest_param
=
38 AppendPositions
= QuestAppendPositions
41 for key
, value
in pairs(QuestHelper
.default_objective_param
) do
42 if not QuestHelper
.default_objective_quest_param
[key
] then
43 QuestHelper
.default_objective_quest_param
[key
] = value
47 QuestHelper
.default_objective_quest_meta
= { __index
= QuestHelper
.default_objective_quest_param
}
49 function QuestHelper
:GetQuest(name
, level
, hash
)
51 if QuestHelper_Quests_Local
[self
.faction
] then
52 for l
, quest_list
in ipairs(QuestHelper_Quests_Local
[self
.faction
]) do
53 if quest_list
[name
] then
61 QuestHelper_StaticData
[self
.locale
] and
62 QuestHelper_StaticData
[self
.locale
].quest
[self
.faction
] then
63 for l
, quest_list
in ipairs(QuestHelper_StaticData
[self
.locale
].quest
[self
.faction
]) do
64 if quest_list
[name
] then
72 error("Don't know of a quest named '"..name
.."' for your faction.")
75 self
:TextOut("Determined the quest level of '"..name
.."' to be "..level
..".")
78 local bracket
= self
.quest_objects
[level
]
82 self
.quest_objects
[level
] = bracket
85 local bracket2
= bracket
[name
]
89 bracket
[name
] = bracket2
92 local quest_object
= bracket2
[hash
or -1]
94 if not quest_object
then
95 quest_object
= self
:NewObjectiveObject()
96 quest_object
.icon_id
= 7
97 quest_object
.icon_bg
= 15
98 setmetatable(quest_object
, QuestHelper
.default_objective_quest_meta
)
100 quest_object
.cat
= "quest"
101 quest_object
.obj
= level
.."/"..(hash
or "").."/"..name
103 bracket2
[hash
or -1] = quest_object
105 local fbracket
= QuestHelper_Quests_Local
[self
.faction
]
109 QuestHelper_Quests_Local
[self
.faction
] = fbracket
112 bracket
= fbracket
[level
]
116 fbracket
[level
] = bracket
119 quest_object
.o
= bracket
[name
]
121 if not quest_object
.o
then
123 quest_object
.o
= {hash
=hash
}
124 bracket
[name
] = quest_object
.o
125 else -- Not going to actually save the quest without a hash.
130 local l
= QuestHelper_StaticData
[self
.locale
]
133 fbracket
= l
.quest
[self
.faction
]
135 bracket
= fbracket
[level
]
137 quest_object
.fb
= bracket
[name
]
141 if not quest_object
.fb
then
145 if quest_object
.o
.hash
and quest_object
.o
.hash
~= hash
then
146 if not quest_object
.o
.alt
then quest_object
.o
.alt
= {} end
147 local real_quest_data
= quest_object
.o
.alt
[hash
]
148 if not real_quest_data
then
149 real_quest_data
= {hash
=hash
}
150 quest_object
.o
.alt
[hash
] = real_quest_data
152 quest_object
.o
= real_quest_data
153 elseif not quest_object
.o
.hash
then
154 -- Not setting the hash now, as we might not actually have the correct quest loaded.
155 -- When we can verify our data is correct, we'll assign a value.
156 quest_object
.need_hash
= true
159 if hash
and quest_object
.fb
.hash
and quest_object
.fb
.hash
~= hash
then
160 quest_object
.fb
= quest_object
.fb
.alt
and quest_object
.fb
.alt
[hash
]
161 if not quest_object
.fb
then
166 -- TODO: If we have some other source of information (like LightHeaded) add its data to quest_object.fb
173 function QuestHelper
:PurgeItemFromQuest(quest
, item_name
, item_object
)
175 for hash
, alt_quest
in pairs(quest
.alt
) do
176 self
:PurgeItemFromQuest(alt_quest
, item_name
, item_object
)
181 local item_data
= quest
.item
[item_name
]
183 quest
.item
[item_name
] = nil
184 if not next(quest
.item
, nil) then quest
.item
= nil end
186 if item_data
.pos
then
187 for i
, pos
in ipairs(item_data
.pos
) do
188 self
:AppendObjectivePosition(item_object
, unpack(pos
))
191 if item_data
.drop
then
192 for monster
, count
in pairs(item_data
.drop
) do
193 self
:AppendObjectiveDrop(item_object
, monster
, count
)
197 if item_data
.contained
then
198 for item
, count
in pairs(item_data
.contained
) do
199 self
:AppendItemObjectiveContained(item_object
, item
, count
)
204 if item_object
.bad_pos
then
205 for i
, pos
in ipairs(item_object
.bad_pos
) do
206 self
:AppendObjectivePosition(item_object
, unpack(pos
))
208 item_object
.bad_pos
= nil
209 elseif item_object
.bad_drop
then
210 for monster
, count
in pairs(item_object
.bad_drop
) do
211 self
:AppendObjectiveDrop(item_object
, monster
, count
)
213 item_object
.bad_drop
= nil
219 function QuestHelper
:PurgeQuestItem(item_name
, item_object
)
220 for faction
, level_list
in pairs(QuestHelper_Quests_Local
) do
221 for level
, quest_list
in pairs(level_list
) do
222 for quest_name
, quest
in pairs(quest_list
) do
223 self
:PurgeItemFromQuest(quest
, item_name
, item_object
)
229 function QuestHelper
:AppendQuestPosition(quest
, item_name
, i
, x
, y
, w
)
230 local item_list
= quest
.o
.item
232 if not item_list
then
234 quest
.o
.item
= item_list
237 local item
= item_list
[item_name
]
241 item_list
[item_name
] = item
247 return -- If it's dropped by a monster, don't record the position we got the item at.
249 item
.pos
= self
:AppendPosition({}, i
, x
, y
, w
)
251 self
:AppendPosition(pos
, i
, x
, y
, w
)
255 function QuestHelper
:AppendQuestDrop(quest
, item_name
, monster_name
, count
)
256 local item_list
= quest
.o
.item
258 if not item_list
then
260 quest
.o
.item
= item_list
263 local item
= item_list
[item_name
]
267 item_list
[item_name
] = item
270 local drop
= item
.drop
273 drop
[monster_name
] = (drop
[monster_name
] or 0) + (count
or 1)
275 item
.drop
= {[monster_name
] = count
or 1}
276 item
.pos
= nil -- If we know monsters drop the item, don't record the position we got the item at.