1 QuestHelper_File
["quest.lua"] = "Development Version"
2 QuestHelper_Loadtime
["quest.lua"] = GetTime()
4 local function QuestKnown(self
)
5 if not self
.target
and not self
.destination
then
7 self
.target
= self
.qh
:GetObjective("monster", self
.o
.finish
)
8 elseif self
.fb
.finish
then
9 self
.target
= self
.qh
:GetObjective("monster", self
.fb
.finish
)
10 elseif self
.o
.pos
then
11 self
.destination
= self
.o
.pos
12 elseif self
.fb
.pos
then
13 self
.destination
= self
.fb
.pos
16 return (self
.target
or self
.destination
) and self
:DefaultKnown() and (self
.destination
or self
.target
:Known())
19 local function QuestAppendPositions(self
, objective
, weight
, why
, restrict
)
20 why2
= why
and why
.."\n" or ""
23 self
.target
:AppendPositions(self
, 1, why2
..QHFormat("OBJECTIVE_TALK", self
.o
.finish
or self
.fb
.finish
), restrict
)
24 elseif self
.destination
then
25 for i
, p
in ipairs(self
.destination
) do
26 if not restrict
or not self
.qh
:Disallowed(p
[1]) then
27 self
:AddLoc(p
[1], p
[2], p
[3], p
[4], p
[5])
33 QuestHelper
.default_objective_quest_param
=
36 AppendPositions
= QuestAppendPositions
39 for key
, value
in pairs(QuestHelper
.default_objective_param
) do
40 if not QuestHelper
.default_objective_quest_param
[key
] then
41 QuestHelper
.default_objective_quest_param
[key
] = value
45 QuestHelper
.default_objective_quest_meta
= { __index
= QuestHelper
.default_objective_quest_param
}
47 function QuestHelper
:GetQuest(name
, level
, hash
)
49 if QuestHelper_Quests_Local
[self
.faction
] then
50 for l
, quest_list
in ipairs(QuestHelper_Quests_Local
[self
.faction
]) do
51 if quest_list
[name
] then
59 QuestHelper_StaticData
[self
.locale
] and
60 QuestHelper_StaticData
[self
.locale
].quest
[self
.faction
] then
61 for l
, quest_list
in ipairs(QuestHelper_StaticData
[self
.locale
].quest
[self
.faction
]) do
62 if quest_list
[name
] then
70 error("Don't know of a quest named '"..name
.."' for your faction.")
73 self
:TextOut("Determined the quest level of '"..name
.."' to be "..level
..".")
76 local bracket
= self
.quest_objects
[level
]
80 self
.quest_objects
[level
] = bracket
83 local bracket2
= bracket
[name
]
87 bracket
[name
] = bracket2
90 local quest_object
= bracket2
[hash
or -1]
92 if not quest_object
then
93 quest_object
= self
:NewObjectiveObject()
94 quest_object
.icon_id
= 7
95 quest_object
.icon_bg
= 15
96 setmetatable(quest_object
, QuestHelper
.default_objective_quest_meta
)
98 quest_object
.cat
= "quest"
99 quest_object
.obj
= level
.."/"..(hash
or "").."/"..name
101 bracket2
[hash
or -1] = quest_object
103 local fbracket
= QuestHelper_Quests_Local
[self
.faction
]
107 QuestHelper_Quests_Local
[self
.faction
] = fbracket
110 bracket
= fbracket
[level
]
114 fbracket
[level
] = bracket
117 quest_object
.o
= bracket
[name
]
119 if not quest_object
.o
then
121 quest_object
.o
= {hash
=hash
}
122 bracket
[name
] = quest_object
.o
123 else -- Not going to actually save the quest without a hash.
128 local l
= QuestHelper_StaticData
[self
.locale
]
131 fbracket
= l
.quest
[self
.faction
]
133 bracket
= fbracket
[level
]
135 quest_object
.fb
= bracket
[name
]
139 if not quest_object
.fb
then
143 if quest_object
.o
.hash
and quest_object
.o
.hash
~= hash
then
144 if not quest_object
.o
.alt
then quest_object
.o
.alt
= {} end
145 local real_quest_data
= quest_object
.o
.alt
[hash
]
146 if not real_quest_data
then
147 real_quest_data
= {hash
=hash
}
148 quest_object
.o
.alt
[hash
] = real_quest_data
150 quest_object
.o
= real_quest_data
151 elseif not quest_object
.o
.hash
then
152 -- Not setting the hash now, as we might not actually have the correct quest loaded.
153 -- When we can verify our data is correct, we'll assign a value.
154 quest_object
.need_hash
= true
157 if hash
and quest_object
.fb
.hash
and quest_object
.fb
.hash
~= hash
then
158 quest_object
.fb
= quest_object
.fb
.alt
and quest_object
.fb
.alt
[hash
]
159 if not quest_object
.fb
then
164 -- TODO: If we have some other source of information (like LightHeaded) add its data to quest_object.fb
171 function QuestHelper
:PurgeItemFromQuest(quest
, item_name
, item_object
)
173 for hash
, alt_quest
in pairs(quest
.alt
) do
174 self
:PurgeItemFromQuest(alt_quest
, item_name
, item_object
)
179 local item_data
= quest
.item
[item_name
]
181 quest
.item
[item_name
] = nil
182 if not next(quest
.item
, nil) then quest
.item
= nil end
184 if item_data
.pos
then
185 for i
, pos
in ipairs(item_data
.pos
) do
186 self
:AppendObjectivePosition(item_object
, unpack(pos
))
189 if item_data
.drop
then
190 for monster
, count
in pairs(item_data
.drop
) do
191 self
:AppendObjectiveDrop(item_object
, monster
, count
)
195 if item_data
.contained
then
196 for item
, count
in pairs(item_data
.contained
) do
197 self
:AppendItemObjectiveContained(item_object
, item
, count
)
202 if item_object
.bad_pos
then
203 for i
, pos
in ipairs(item_object
.bad_pos
) do
204 self
:AppendObjectivePosition(item_object
, unpack(pos
))
206 item_object
.bad_pos
= nil
207 elseif item_object
.bad_drop
then
208 for monster
, count
in pairs(item_object
.bad_drop
) do
209 self
:AppendObjectiveDrop(item_object
, monster
, count
)
211 item_object
.bad_drop
= nil
217 function QuestHelper
:PurgeQuestItem(item_name
, item_object
)
218 for faction
, level_list
in pairs(QuestHelper_Quests_Local
) do
219 for level
, quest_list
in pairs(level_list
) do
220 for quest_name
, quest
in pairs(quest_list
) do
221 self
:PurgeItemFromQuest(quest
, item_name
, item_object
)
227 function QuestHelper
:AppendQuestPosition(quest
, item_name
, i
, x
, y
, w
)
228 local item_list
= quest
.o
.item
230 if not item_list
then
232 quest
.o
.item
= item_list
235 local item
= item_list
[item_name
]
239 item_list
[item_name
] = item
245 return -- If it's dropped by a monster, don't record the position we got the item at.
247 item
.pos
= self
:AppendPosition({}, i
, x
, y
, w
)
249 self
:AppendPosition(pos
, i
, x
, y
, w
)
253 function QuestHelper
:AppendQuestDrop(quest
, item_name
, monster_name
, count
)
254 local item_list
= quest
.o
.item
256 if not item_list
then
258 quest
.o
.item
= item_list
261 local item
= item_list
[item_name
]
265 item_list
[item_name
] = item
268 local drop
= item
.drop
271 drop
[monster_name
] = (drop
[monster_name
] or 0) + (count
or 1)
273 item
.drop
= {[monster_name
] = count
or 1}
274 item
.pos
= nil -- If we know monsters drop the item, don't record the position we got the item at.