forked from ESOUIMods/LibQuestData
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibQuestData_Scan.lua
765 lines (713 loc) · 30.4 KB
/
LibQuestData_Scan.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
local lib = _G["LibQuestData"]
local internal = _G["LibQuestData_Internal"]
local LMD = LibMapData
-- Local variables
local reward
-- Init saved variables table
local GPS = LibGPS3
local LMP = LibMapPins
local quest_found
function lib:get_giver_when_object(id)
if internal:is_empty_or_nil(lib.questid_giver_lookup[id]) then
--d("If giver is an object, one was not found")
return {}
else
--d("Giver is an object, found one")
return lib.questid_giver_lookup[id]
end
end
local function get_sv_quest_info(zone)
--d(zone)
-- if type(zone) ~= "string"
if internal:is_empty_or_nil(LibQuestData_SavedVariables.quests[zone]) then
--d("get_sv_quest_info it was nil")
return {}
else
--d("get_sv_quest_info was not nil")
return LibQuestData_SavedVariables.quests[zone]
end
end
local function is_giver_in_sv(id)
--d(id)
if internal:is_empty_or_nil(LibQuestData_SavedVariables["giver_names"][id]) then
--d("The Quest ID and name set to an NPC or Unknown, was not found in the SV table")
return false
else
--d("The Quest ID and name is already in the SV table")
return true
end
end
local function is_questname_in_sv(id)
--d(id)
--[[Note to self:
Originally I saved it with a key for the name and realized
it's faster to copy paste with an ID number.
Since this is the save game information I don't have a
lookup table for this nor should I make one. Converting
the quest name to a quest ID is pointless. Just ensure
I look at the table for quest names, return an empty
table without an error
Needs different way to handle this or leave it since
the assignment overwrites the value each time regardless.
]]--
if internal:is_empty_or_nil(LibQuestData_SavedVariables["quest_names"][id]) then
--d("is_questname_in_sv it was nil")
return false
else
--d("is_questname_in_sv was not nil")
--d(LibQuestData_SavedVariables["quest_names"][id])
return true
end
end
local function get_quest_list_sv(zone)
--d(zone)
if type(zone) == "string" and LibQuestData_SavedVariables["location_info"][zone] ~= nil then
return LibQuestData_SavedVariables["location_info"][zone]
else
return {}
end
end
-- Event handler function for EVENT_QUEST_ADDED
local function OnQuestAdded(eventCode, journalIndex, questName, objectiveName)
--internal.dm("Debug", "OnQuestAdded")
if LMD.questShared then
LMD.questShared = false
return
end
--internal.dm("Debug", journalIndex)
-- -1 for these means it is undefined since 0 is a valid value
local quest_type = -1
local quest_display_type = -1
local repeat_type = -1
local zone_name = ""
local objective_name = ""
local zone_index = -1
local poi_index = -1
local quest_id = -1
-- "-1" means it has not been completed. Once complete set it to the time stamp
-- I am considering using this to see if I can calculate order for Zone quests
-- Add quest to saved variables table in correct zone element
local zone = LMP:GetZoneAndSubzone(true, false, true)
if LibQuestData_SavedVariables.quests[zone] == nil then LibQuestData_SavedVariables.quests[zone] = {} end
local local_x, local_y = GetMapPlayerPosition("player")
local global_x, global_y, zoneMapIndex = GPS:LocalToGlobal(local_x, local_y)
if journalIndex then
quest_type = GetJournalQuestType(journalIndex)
quest_display_type = GetJournalQuestInstanceDisplayType(journalIndex)
repeat_type = GetJournalQuestRepeatType(journalIndex)
zone_name, objective_name, zone_index, poi_index = GetJournalQuestLocationInfo(journalIndex)
--internal.dm("Debug", quest_type)
--internal.dm("Debug", quest_display_type)
end
local quest = {
["zone_name"] = zone_name,
["zone_index"] = zone_index,
["poi_index"] = poi_index,
["quest_type"] = quest_type,
["quest_display_type"] = quest_display_type,
["repeat_type"] = repeat_type,
["name"] = questName,
["x"] = local_x,
["y"] = local_y,
["gpsx"] = global_x,
["gpsy"] = global_y,
["giver"] = lib.questGiverName,
["questID"] = quest_id, -- assign this and get the ID when the quest is removed
["api"] = GetAPIVersion(),
["lang"] = GetCVar("language.2"),
}
if lib.questGiverName == nil then
quest["giver"] = LMD.lastInteractionTarget
end
quest_found = false
local quests_in_zone = get_sv_quest_info(zone)
for num_entry, quest_from_table in pairs(quests_in_zone) do
if quest_from_table.name == questName then
quest_found = true
end
end
if quest_found then
--d("quest found")
else
--d("quest not found")
table.insert(LibQuestData_SavedVariables.quests[zone], quest)
end
end
EVENT_MANAGER:RegisterForEvent(lib.libName, EVENT_QUEST_ADDED, OnQuestAdded) -- Verified
-- Event handler function for EVENT_CHATTER_END
local function OnChatterEnd(eventCode)
--d("OnChatterEnd")
lib.questGiverName = nil
reward = nil
-- Stop listening for the quest added event because it would only be for shared quests
-- Shar I added if EVENT_QUEST_SHARED to OnQuestAdded UnregisterForEvent EVENT_QUEST_ADDED
-- EVENT_MANAGER:UnregisterForEvent(lib.libName, EVENT_QUEST_ADDED)
-- using LibMapData for LMD.questShared
EVENT_MANAGER:UnregisterForEvent(lib.libName, EVENT_CHATTER_END) -- Verified
end
-- Event handler function for EVENT_QUEST_OFFERED
-- Note runs when you click writ board
local function OnQuestOffered(eventCode)
--d("OnQuestOffered")
-- Get the name of the NPC or intractable object
-- (This could also be done in OnQuestAdded directly, but it's saver here because we are sure the dialogue is open)
lib.questGiverName = GetUnitName("interact")
-- Now that the quest has been offered we can start listening for the quest added event
-- Shar I added if EVENT_QUEST_SHARED to OnQuestAdded UnregisterForEvent EVENT_QUEST_ADDED
-- EVENT_MANAGER:RegisterForEvent(lib.libName, EVENT_QUEST_ADDED, OnQuestAdded)
-- using LibMapData for LMD.questShared
EVENT_MANAGER:RegisterForEvent(lib.libName, EVENT_CHATTER_END, OnChatterEnd) -- Verified
end
EVENT_MANAGER:RegisterForEvent(lib.libName, EVENT_QUEST_OFFERED, OnQuestOffered) -- Verified
-- Event handler function for EVENT_QUEST_COMPLETE_DIALOG
local function OnQuestCompleteDialog(eventCode, journalIndex)
--d("OnQuestCompleteDialog")
local numRewards = GetJournalQuestNumRewards(journalIndex)
if numRewards <= 0 then return end
reward = {}
for i = 1, numRewards do
local rewardType = GetJournalQuestRewardInfo(journalIndex, i)
table.insert(reward, rewardType)
end
end
EVENT_MANAGER:RegisterForEvent(lib.libName, EVENT_QUEST_COMPLETE_DIALOG, OnQuestCompleteDialog) -- Verified
local function has_undefined_data(info)
--[[
This is used for both the main database and the save file
]]--
local undefined = false
if info[lib.quest_map_pin_index.global_x] == -10 then
--d("global_x was -10 so undefined")
undefined = true
end
--[[
No quest Giver so it is undefined
]]--
if info[lib.quest_map_pin_index.quest_giver] == -1 then
--d("quest_giver was -1 so undefined")
undefined = true
end
--[[ Very old format
The save file might only have 1 to 5
]]--
if #info <= 5 then
--d("#info <= 5 data format")
--[[
meaning it's an old format and therefore it is all
undefined.
]]--
return true
end
--[[
4/2/2021 New Format
There are now exactly 6 fields.
]]--
if #info == 6 then
--d("#info == 6 data format")
--[[
meaning it's the new format and therefore it is all
probably okay, will return true if previous checks
failed
]]--
return undefined
end
--[[
There were about 10 quests that didn't get a giver
and will be nil. Less then or equal to 8 because
there are 9 fields.
]]--
if #info <= 8 then
--d("#info <= 8 data format")
--[[
meaning it's an old format and therefore it is all
undefined.
]]--
return true
end
return undefined
end
-- map pins not Quest Data table with zone store entries
local function update_older_quest_info(source_data)
--internal.dm("Debug", "update_older_quest_info")
local old_quest_giver_value = 9 -- Updated, was 9 now 6
if not source_data then return end
-- source data is the table of all the quests in the zone
--[[
build a new table with quest location info that is properly defined
discard all quest information that needs updated because the new
data is already correct
]]--
--internal.dm("Debug", #source_data)
local result_table = {}
local found = false
for num_entry, quest_entry in ipairs(source_data) do
if #quest_entry <= 5 then
--internal.dm("Debug", "info is in the old format add new information")
quest_entry[lib.quest_map_pin_index.quest_giver] = -1 -- Arbitrary number pointing to an NPC Name 81004, "Abnur Tharn" << -1 = Undefined >>
table.insert(result_table, quest_entry)
found = true
end
if #quest_entry > 6 then
local new_quest_entry
--internal.dm("Debug", "info is not in the old format so we need to convert it")
new_quest_entry[lib.quest_map_pin_index.local_x] = quest_entry[lib.quest_map_pin_index.local_x]
new_quest_entry[lib.quest_map_pin_index.local_y] = quest_entry[lib.quest_map_pin_index.local_y]
new_quest_entry[lib.quest_map_pin_index.global_x] = quest_entry[lib.quest_map_pin_index.global_x]
new_quest_entry[lib.quest_map_pin_index.global_y] = quest_entry[lib.quest_map_pin_index.global_y]
new_quest_entry[lib.quest_map_pin_index.quest_id] = quest_entry[lib.quest_map_pin_index.quest_id]
new_quest_entry[lib.quest_map_pin_index.quest_giver] = quest_entry[old_quest_giver_value]
table.insert(result_table, new_quest_entry)
found = true
end
if #quest_entry == 6 then
--internal.dm("Debug", "info is in the new format so no convertion needed")
table.insert(result_table, quest_entry)
found = true
end
if found then
--internal.dm("Debug", "We found something")
else
--internal.dm("Debug", "Shit Hit the fan")
end
end
--internal.dm("Debug", #result_table)
return result_table
end
local function remove_older_quest_info(source_data, quest_info)
-- source data is the table of all the quests in the zone
--[[
build a new table with quest location info that is properly defined
discard all quest information that needs updated because the new
data is already correct
]]--
local result_table = {}
for num_entry, quest_entry in ipairs(source_data) do
if quest_entry[lib.quest_map_pin_index.quest_id] == quest_info[lib.quest_map_pin_index.quest_id] then
local distance = zo_round(GPS:GetLocalDistanceInMeters(quest_entry[lib.quest_map_pin_index.local_x],
quest_entry[lib.quest_map_pin_index.local_y], quest_info[lib.quest_map_pin_index.local_x],
quest_info[lib.quest_map_pin_index.local_y]))
--d("Distance: "..distance)
if distance <= 25 then
table.remove(source_data, num_entry)
end
end
end
end
-- set alliance
local function SetQuestSeries(the_zone)
local value = 0
if IsInImperialCity() or IsInCyrodiil() then
if lib.player_alliance == ALLIANCE_ALDMERI_DOMINION then value = lib.quest_series_type.quest_type_ad end
if lib.player_alliance == ALLIANCE_EBONHEART_PACT then value = lib.quest_series_type.quest_type_ep end
if lib.player_alliance == ALLIANCE_DAGGERFALL_COVENANT then value = lib.quest_series_type.quest_type_dc end
end
return value
end
-- Event handler function for EVENT_QUEST_REMOVED
local function OnQuestRemoved(eventCode, isCompleted, journalIndex, questName, zoneIndex, poiIndex, questID)
--internal.dm("Debug", "OnQuestRemoved")
--internal.dm("Debug", questName)
local quest_to_update = nil
local the_zone
local the_entry
local giver_name_result
local quest_info_changed = false
local save_quest_location = true
--local my_pos_x, my_pos_y = GetMapPlayerPosition("player")
for zone, zone_quests in pairs(LibQuestData_SavedVariables.quests) do
for num_entry, quest_from_table in pairs(zone_quests) do
if quest_from_table.zone_index and quest_from_table.poi_index then
if quest_from_table.zone_index == zoneIndex and quest_from_table.poi_index == poiIndex and quest_from_table.name == questName then
--internal.dm("Debug", "Detailed quest info was all true")
the_zone = zone
the_entry = num_entry
quest_to_update = quest_from_table
break
end
elseif quest_from_table.name == questName then
--internal.dm("Debug", "Quest name was true due to old information")
the_zone = zone
the_entry = num_entry
quest_to_update = quest_from_table
break
end
end
end
if quest_to_update == nil then
return
end
if quest_to_update.zone_name then
--internal.dm("Debug", "zone_name: " .. quest_to_update.zone_name)
end
if quest_to_update.zone_index then
--internal.dm("Debug", "zone_index: " .. quest_to_update.zone_index)
--internal.dm("Debug", "zoneIndex: " .. tostring(zoneIndex))
end
if quest_to_update.poi_index then
--internal.dm("Debug", "poi_index: " .. quest_to_update.poi_index)
--internal.dm("Debug", "poiIndex: " .. tostring(poiIndex))
end
if not quest_to_update.quest_display_type then
--internal.dm("Debug", "quest_display_type did not exist, set to 0")
quest_to_update.quest_display_type = INSTANCE_DISPLAY_TYPE_NONE
end
--internal.dm("Debug", "questID: " .. questID)
if questID >= 1 then
if quest_to_update.questID == -1 then
quest_to_update.questID = questID
end
end
--[[ set quest giver to it's ID number using the name of the NPC ]]--
--[[ Check if Quest Giver is an Object, Sign, Note ]]--
LibQuestData_SavedVariables["giver_names"] = LibQuestData_SavedVariables["giver_names"] or {}
local temp_giver = lib:get_giver_when_object(quest_to_update.questID)
--internal.dm("Debug", "temp_giver was:")
--internal.dm("Debug", temp_giver)
if internal:is_empty_or_nil(temp_giver) then
--d("The temp_giver was nil")
-- meaning no giver object found
else
--d("The temp_giver was not nil")
-- meaning there was a giver object found
quest_to_update.giver = lib:get_quest_giver(temp_giver)
--d(temp_giver)
--d(quest_to_update.giver)
--d(lib.quest_givers["en"][quest_to_update.giver])
end
--internal.dm("Debug", "quest giver table was")
--quest_to_update.giver = "The Fish Object"
--internal.dm("Debug", quest_to_update.giver)
giver_name_result = lib:get_npcids_table(quest_to_update.giver)
--internal.dm("Debug", giver_name_result)
if giver_name_result == nil then
--[[ Check if Quest Giver is simply nil or empty, unassigned ]]--
if internal:is_empty_or_nil(quest_to_update.giver) then
--internal.dm("Debug", "Quest giver was nil, it is an empty table now from previous function")
-- meaning set it to Unknown Target
quest_to_update.giver = "Unknown Target"
--d(quest_to_update.giver)
else
--internal.dm("Debug", "not empty or nil so continue")
end
--[[
At this point we know:
1: The quest giver was not in the main database
2: It was/wasn't a sign of note, object
3: The quest_to_update.giver was/wasn't nil and set to Unknown
Result: The Quest Giver has been set to the object if it was a sign
or post, or to Unknown if quest_to_update.giver was nil. Otherwise
nothing happened to quest_to_update.giver because it's a valid
NPC name but not in the main database yet.
Next Step: Simply save the valid NPC name or Unknown using the QuestID
as a key. Then I can make a custom Quest Giver ID for it.
]]--
--d("quest giver lookup table is nil look in sv now")
--d(giver_name_result)
if is_giver_in_sv(quest_to_update.questID) then
--internal.dm("Debug", "The giver was in the SV file")
-- meaning don't save it because the NPC name was not in
-- the Lua file but was in the save vars and I need an
-- arbitrary value, use the string for now
else
--internal.dm("Debug", "The giver was not in the SV file")
LibQuestData_SavedVariables.giver_names[quest_to_update.questID] = quest_to_update.giver
end
giver_name_result = quest_to_update.giver
else
--internal.dm("Debug", "quest giver lookup table is not nil")
-- meaning we found it don't add it but I need the number
giver_name_result = lib:get_npcids_table(quest_to_update.giver)[1]
--internal.dm("Debug", giver_name_result)
end
--internal.dm("Debug", "end result was")
--internal.dm("Debug", giver_name_result)
--[[ set quest name ]]--
--d(quest_to_update.questID)
--d("Quest Name Please")
--d(lib:get_quest_name(quest_to_update.questID))
LibQuestData_SavedVariables["quest_names"] = LibQuestData_SavedVariables["quest_names"] or {}
local temp_quest_name = lib:get_quest_name(quest_to_update.questID)
if temp_quest_name == "Unknown Name" then
--d("quest name is Unknown Name - So not found")
if is_questname_in_sv(quest_to_update.questID) then
--d("returned true so it was in the sv")
else
--d("returned false so it was not in the sv")
LibQuestData_SavedVariables["quest_names"][quest_to_update.questID] = quest_to_update.name
end
else
-- get_questname_sv
--d("quest name is not Unknown Name - So it was found")
--d(lib:get_quest_name(quest_to_update.questID))
-- is the quest name different from a previous version of the game
if temp_quest_name ~= questName then
if is_questname_in_sv(quest_to_update.questID) then
--d("returned true so it was in the sv")
else
--d("returned false so it was not in the sv")
LibQuestData_SavedVariables["quest_names"][quest_to_update.questID] = quest_to_update.name
end
else
--seems to be the same so don't save it
end
end
--[[ Add Quest Information
Step 1: Use series of comparisons to see if values are different
and if they are save the new quest information.
At first they will all be different for API but check
anyway.
]]--
local currentApiVersion = GetAPIVersion()
local the_quest_info = {
[lib.quest_data_index.quest_type] = quest_to_update.quest_type,
[lib.quest_data_index.quest_repeat] = quest_to_update.repeat_type,
[lib.quest_data_index.game_api] = currentApiVersion,
[lib.quest_data_index.quest_line] = 10000,
[lib.quest_data_index.quest_number] = 10000,
[lib.quest_data_index.quest_series] = SetQuestSeries(the_zone),
[lib.quest_data_index.quest_display_type] = quest_to_update.quest_display_type,
}
LibQuestData_SavedVariables["quest_info"] = LibQuestData_SavedVariables["quest_info"] or {}
local temp_quest_info = lib.quest_data[quest_to_update.questID]
if temp_quest_info == nil then
--d("quest information is nil")
-- meaning I need to create it and save it, no compare
LibQuestData_SavedVariables["quest_info"][quest_to_update.questID] = the_quest_info
else
--d("quest information is not nill")
-- meaning I need to compare things and save if different
--[[
Depreciated
if temp_quest_info[lib.quest_data_index.quest_name] ~= quest_to_update.questID then
temp_quest_info [lib.quest_data_index.quest_name] = quest_to_update.questID
quest_info_changed = true
end
]]--
-- quest_giver_is_object lib.quest_data_index.quest_giver, depreciated
-- update alliance, just set it with checking if it changed for now
if IsInImperialCity() or IsInCyrodiil() then
if lib.player_alliance == ALLIANCE_ALDMERI_DOMINION then temp_quest_info[lib.quest_data_index.quest_series] = lib.quest_series_type.quest_type_ad end
if lib.player_alliance == ALLIANCE_EBONHEART_PACT then temp_quest_info[lib.quest_data_index.quest_series] = lib.quest_series_type.quest_type_ep end
if lib.player_alliance == ALLIANCE_DAGGERFALL_COVENANT then temp_quest_info[lib.quest_data_index.quest_series] = lib.quest_series_type.quest_type_dc end
quest_info_changed = true
end
if not temp_quest_info[lib.quest_data_index.quest_display_type] then temp_quest_info[lib.quest_data_index.quest_display_type] = INSTANCE_DISPLAY_TYPE_NONE end
if temp_quest_info[lib.quest_data_index.quest_display_type] ~= quest_to_update.quest_display_type then
temp_quest_info[lib.quest_data_index.quest_display_type] = quest_to_update.quest_display_type
quest_info_changed = true
end
if temp_quest_info[lib.quest_data_index.quest_type] ~= quest_to_update.quest_type then
temp_quest_info[lib.quest_data_index.quest_type] = quest_to_update.quest_type
quest_info_changed = true
end
if temp_quest_info[lib.quest_data_index.quest_repeat] ~= quest_to_update.repeat_type then
temp_quest_info[lib.quest_data_index.quest_repeat] = quest_to_update.repeat_type
quest_info_changed = true
end
if temp_quest_info[lib.quest_data_index.game_api] < currentApiVersion then
temp_quest_info[lib.quest_data_index.game_api] = currentApiVersion
quest_info_changed = true
end
-- quest_line is set manually
-- quest_number is set manually
-- quest_series is set manually
--d(temp_quest_info)
--[[ Check Saved Vars format ]]--
if LibQuestData_SavedVariables.quest_info[quest_to_update.questID] ~= nil and #LibQuestData_SavedVariables.quest_info[quest_to_update.questID] > 7 then
--internal.dm("Debug", "old format")
--[[
Not technically a change but the SavedVariables data is the old format
so update it. It doesn't matter about what it is the main database has
been converted already.
]]--
quest_info_changed = true
end
--[[ Do not need to check main database format because it was updated ]]--
if quest_info_changed then
--internal.dm("Debug", "save the table")
--internal.dm("Debug", temp_quest_info)
LibQuestData_SavedVariables.quest_info[quest_to_update.questID] = temp_quest_info
else
--internal.dm("Debug", "do not save the table")
end
end
local the_quest_loc_info = {
[lib.quest_map_pin_index.local_x] = quest_to_update.x,
[lib.quest_map_pin_index.local_y] = quest_to_update.y,
[lib.quest_map_pin_index.global_x] = quest_to_update.gpsx,
[lib.quest_map_pin_index.global_y] = quest_to_update.gpsy,
[lib.quest_map_pin_index.quest_id] = quest_to_update.questID,
[lib.quest_map_pin_index.quest_giver] = giver_name_result,
}
--[[
At this point save_quest_location is false and will not be set to false in this
loop. It will only be true if there is the potential it is a secondary location
for the same quest.
Not sure I want to do this twice but later on in another loop I will look at the
LibGPS value to also determine whether or not to save the information.
Neeed to think this over but for now I am hoping the second loop will allow me to
decide that if the information is about to be saved and it passed the first two
verifications, only then can it be checked against -10.
Also it might be better to build a table of the quests in the zone with the same
questID and then check against that instead. Probably more efficent but I want to
get this done for Greymore's Rough draft.
If I make a table I want to make the table from the main database first, then the SV
and then determine that there are pins that already exist so don't save the
information.
]]--
local regular_quest_list = internal:get_zone_quests(the_zone)
--d(quest_to_update.questID)
for num_entry, quest_entry_table in ipairs(regular_quest_list) do
--d(num_entry)
--d(quest_entry_table)
if quest_entry_table[lib.quest_map_pin_index.quest_id] == quest_to_update.questID then
--d("Found an entry with the same quest ID so check LibGPS")
-- my_pos_x, my_pos_y : not this may not be important because I know where I was standing
local distance = zo_round(GPS:GetLocalDistanceInMeters(quest_entry_table[lib.quest_map_pin_index.local_x],
quest_entry_table[lib.quest_map_pin_index.local_y], quest_to_update.x, quest_to_update.y))
--d(distance)
--d(quest_entry_table)
if distance <= 25 then
--d("The quest from the main database was close to the quest to update")
--d("However is it -10?")
if has_undefined_data(quest_entry_table) then
--internal.dm("Debug", "quest_entry_table had undefined data")
-- save_quest_location = true
else
--internal.dm("Debug", "quest_entry_table was defined properly")
save_quest_location = false
end
if quest_entry_table[lib.quest_map_pin_index.quest_giver] ~= giver_name_result then
--internal.dm("Debug", "The giver name is different so this may need updated")
save_quest_location = true
else
--internal.dm("Debug", "The giver name was the same")
-- save_quest_location = false
end
else
--internal.dm("Debug", "The quest from the main database was NOT close to the quest to update")
--internal.dm("Debug", "Could be set to true for saving to the SV file")
-- meaning it should not be where I am standing
-- consider saving the location
-- question, how to avoid duplicates though
end
end
end
--internal.dm("Debug", "done first pass")
--[[So save_quest_location is true by default in case it is a new
quest that doesn't exist in the main database. If we are going to
save it check saved vars first
]]--
--internal.dm("Debug", "save_quest_location: "..tostring(save_quest_location))
-- the api changed so save the location regardless
if LibQuestData_SavedVariables["location_info"] == nil then
--internal.dm("Debug", "location_info was nil")
LibQuestData_SavedVariables["location_info"] = {}
end
if LibQuestData_SavedVariables["location_info"][the_zone] == nil then
--internal.dm("Debug", "location_info the_zone was nil")
LibQuestData_SavedVariables["location_info"][the_zone] = {}
end
-- clear all old entries
LibQuestData_SavedVariables["location_info"][the_zone] = update_older_quest_info(LibQuestData_SavedVariables["location_info"][the_zone])
-- now look for duplicates
if save_quest_location then
local saved_vars_quest_list = get_quest_list_sv(the_zone)
for num_entry, sv_quest_entry in ipairs(saved_vars_quest_list) do
--internal.dm("Debug", "Num Entry: "..num_entry)
--internal.dm("Debug", sv_quest_entry)
if sv_quest_entry[lib.quest_map_pin_index.quest_id] == quest_to_update.questID then
--internal.dm("Debug", "found that the entry 5 was equal to the ID of this quest in the SV file")
-- meaning it is in the saved vars file don't duplicate it
local distance = zo_round(GPS:GetLocalDistanceInMeters(sv_quest_entry[lib.quest_map_pin_index.local_x],
sv_quest_entry[lib.quest_map_pin_index.local_y], quest_to_update.x, quest_to_update.y))
--internal.dm("Debug", "Distance: "..distance)
if internal:is_in(quest_to_update.questID, lib.quest_giver_moves) then
--internal.dm("Debug", "We found a quest giver that moves")
save_quest_location = false
else
--internal.dm("Debug", "We did not find a quest giver that moves")
end
--[[
This should prevent saving prologue quests however, when the
quest has has_undefined_data then it may save anyway to be examined
manually and added
]]--
if internal:is_in(quest_to_update.questID, lib.prologue_quest_list) then
--internal.dm("Debug", "We found a prologue quest that can be accepted anywhere")
save_quest_location = false
else
--internal.dm("Debug", "We did not find a prologue quest")
end
if internal:is_in(quest_to_update.questID, lib.object_quest_starter_list) then
--internal.dm("Debug", "This was a starter quest from an object like a note")
save_quest_location = false
else
--internal.dm("Debug", "This was not a starter quest from an object like a note")
end
if distance <= 25 then
--internal.dm("Debug", "The quest to be saved is close to one already in the SV file")
save_quest_location = false
else
--internal.dm("Debug", "The quest to be saved is not close one in the SV file")
end
--[[
This may save some quests even though they were set to false and
need to be examined manually
]]--
if has_undefined_data(sv_quest_entry) then
--internal.dm("Debug", "sv_quest_entry had undefined data")
remove_older_quest_info(LibQuestData_SavedVariables["location_info"][the_zone], the_quest_loc_info)
save_quest_location = true
else
--internal.dm("Debug", "sv_quest_entry was defined properly")
end
end
end
end
--internal.dm("Debug", "done second pass")
--[[ Save the qest location
Somehow the quest was in the constants file and the LibGPS was -10
so I determined I needed to save the updated location. Then after
looking in the saved vars file for LibQuestData we did not see an
entry for this quest in the zone so it needs to be saved.
]]--
--save_quest_location = false
--internal.dm("Debug", "About To Save")
if (save_quest_location and lib.supported_lang) or internal:is_master_player() then
--internal.dm("Debug", "save_quest_location is true saving")
--internal.dm("Debug", the_zone)
if LibQuestData_SavedVariables["location_info"][the_zone] == nil then
--internal.dm("Debug", "location_info was nil")
LibQuestData_SavedVariables["location_info"][the_zone] = {}
end
--internal.dm("Debug", "table insert into location_info")
table.insert(LibQuestData_SavedVariables["location_info"][the_zone], the_quest_loc_info)
else
--internal.dm("Debug", "save_quest_location was false not saving")
end
--d(the_zone)
--d(the_entry)
table.remove(LibQuestData_SavedVariables.quests[the_zone], the_entry)
--internal.dm("Debug", "Quest Recording Done")
if not isCompleted then
return
end
if isCompleted then
if not LibQuestData_SavedVariables.reward_info then LibQuestData_SavedVariables.reward_info = {} end
if not LibQuestData_SavedVariables.reward_info[questID] then LibQuestData_SavedVariables.reward_info[questID] = {} end
LibQuestData_SavedVariables.reward_info[questID] = reward
reward = nil
lib:set_conditional_quests(questID)
end
end
EVENT_MANAGER:RegisterForEvent(lib.libName, EVENT_QUEST_REMOVED, OnQuestRemoved) -- Verified
local function show_quests()
for zone, zone_quests in pairs(LibQuestData_SavedVariables.quests) do
d("zone: " .. zone)
for num_entry, quest_from_table in pairs(zone_quests) do
local quest_to_update = quest_from_table
d("Quest Name: " .. quest_to_update.name)
end
end
end