/
LazyCraftingCertification.lua
141 lines (129 loc) · 7.23 KB
/
LazyCraftingCertification.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
LazyCraftingCertification = {}
-- This isn't strictly necessary, but we'll use this string later when registering events.
-- Better to define it in a single place rather than retyping the same string.
LazyCraftingCertification.name = "Lazy Crafting Certification"
-- Next we create a function that will initialize our addon
function LazyCraftingCertification.Initialize()
-- ...but we don't have anything to initialize yet. We'll come back to this.
end
-- Then we create an event handler function which will be called when the "addon loaded" event
-- occurs. We'll use this to initialize our addon after all of its resources are fully loaded.
function LazyCraftingCertification.OnAddOnLoaded(event, addonName)
-- The event fires each time *any* addon loads - but we only care about when our own addon loads.
if addonName == LazyCraftingCertification.name then
LazyCraftingCertification.Initialize()
--unregister the event again as our addon was loaded now and we do not need it anymore to be run for each other addon that will load
EVENT_MANAGER:UnregisterForEvent(LazyCraftingCertification.name, EVENT_ADD_ON_LOADED)
end
end
function LazyCraftingCertification.InventoryChange(eventCode, bagId, slotIndex, isNewItem, itemSoundCategory, updateReason, stackCountChange)
local link = GetItemLink(bagId, slotIndex)
if (link == "|H0:item:55462:3:1:0:0:0:0:0:0:0:0:0:0:0:1:0:0:1:0:0:0|h|h") then
local count = GetNumJournalQuests()
for i = 1, count do
local name = GetJournalQuestName(i)
if (string.find(name,"Certification")) then
CallSecureProtected("UseItem", bagId, slotIndex) -- learn the roast pig
end
end
end
end
local function LCCGetBackbackSlotByItemName(name)
-- TODO: lazy - only checks backpack, returns first match so if you have an epic iron dagger with tri-stat on it ... why?
local bagToScan = SHARED_INVENTORY:GenerateFullSlotData(nil, BAG_BACKPACK)
for index, slot in pairs(bagToScan) do
if (slot.name == name) then
return slot.slotIndex
end
end
return nil
end
local function LCCGetCurrentPlayerRacialPatternId()
-- we need the pattern ID for the current character race since it'll know that pattern by default
-- TODO: this will probably break for imperials
local characterId = GetCurrentCharacterId()
for i = 1, GetNumCharacters() do
local name, gender, level, classId, raceId, alliance, id, locationId = GetCharacterInfo(i)
if (characterId == id) then
return raceId
end
end
end
function LazyCraftingCertification.CraftingStation(eventCode, craftSkill, sameStation)
-- d("opened crafting station sameStation:" .. tostring(sameStation))
local count = GetNumJournalQuests()
for i = 1, count do
local name = GetJournalQuestName(i)
if (string.find(name,"Certification")) then
local questName, backgroundText, activeStepText, activeStepType, activeStepTrackerOverrideText, completed, tracked, questLevel, pushed, questType,_ = GetJournalQuestInfo(i)
-- d("questName:" .. questName .. " activeStepType:" .. activeStepType .. " activeStepText:" .. activeStepText)
if craftSkill == CRAFTING_TYPE_PROVISIONING then
LLC_Global:CraftProvisioningItemByRecipeId(45911) -- roast pig
end
if craftSkill == CRAFTING_TYPE_ENCHANTING then
LLC_Global:CraftEnchantingItemId(45855, 45831, 45850) -- jora, oko, ta
end
if craftSkill == CRAFTING_TYPE_ALCHEMY then
LLC_Global:CraftAlchemyItemId(883, 30164,30163,nil, 1, true,'1')
end
if craftSkill == CRAFTING_TYPE_CLOTHIER then
if (string.find(activeStepText,"craft")) then
LLC_Global:CraftSmithingItemByLevel(4, false, 1,LCCGetCurrentPlayerRacialPatternId() ,1 ,false, CRAFTING_TYPE_CLOTHIER, 0, 1,true)
end
if (string.find(activeStepText,"deconstruct")) then
slotIndex = LCCGetBackbackSlotByItemName("Homespun Gloves")
PrepareDeconstructMessage()
AddItemToDeconstructMessage(BAG_BACKPACK,slotIndex,1)
SendDeconstructMessage()
end
end
if craftSkill == CRAFTING_TYPE_BLACKSMITHING then
if (string.find(activeStepText,"craft")) then
LLC_Global:CraftSmithingItemByLevel(7, false, 1,LCCGetCurrentPlayerRacialPatternId() ,1 ,false, CRAFTING_TYPE_BLACKSMITHING, 0, 1,true)
end
if (string.find(activeStepText,"deconstruct")) then
slotIndex = LCCGetBackbackSlotByItemName("Iron Dagger")
PrepareDeconstructMessage()
AddItemToDeconstructMessage(BAG_BACKPACK,slotIndex,1)
SendDeconstructMessage()
end
end
if craftSkill == CRAFTING_TYPE_WOODWORKING then
if (string.find(activeStepText,"craft")) then
LLC_Global:CraftSmithingItemByLevel(1, false, 1,LCCGetCurrentPlayerRacialPatternId() ,1 ,false, CRAFTING_TYPE_WOODWORKING, 0, 1,true)
end
if (string.find(activeStepText,"deconstruct")) then
slotIndex = LCCGetBackbackSlotByItemName("Maple Bow")
PrepareDeconstructMessage()
AddItemToDeconstructMessage(BAG_BACKPACK,slotIndex,1)
SendDeconstructMessage()
end
end
if craftSkill == CRAFTING_TYPE_JEWELRYCRAFTING then
if (string.find(activeStepText,"craft and deliver")) then --the word "craft" appears in the decon step
LLC_Global:CraftSmithingItemByLevel(1, false, 1,LCCGetCurrentPlayerRacialPatternId() ,1 ,false, CRAFTING_TYPE_JEWELRYCRAFTING, 0, 1,true)
end
if (string.find(activeStepText,"deconstruct")) then
slotIndex = LCCGetBackbackSlotByItemName("Pewter Ring")
PrepareDeconstructMessage()
AddItemToDeconstructMessage(BAG_BACKPACK,slotIndex,1)
SendDeconstructMessage()
end
end
-- /script patternName, baseName, _, numMaterials, numTraitsRequired, numTraitsKnown, resultingItemFilterType = GetSmithingPatternInfo(3); d(patternName)
-- /script LLC_Global:CraftSmithingItemByLevel(4, false, 1,5 ,1 ,false, CRAFTING_TYPE_CLOTHIER, 0, 1,true)
end
end
end
local function LCCScratch()
end
-- Finally, we'll register our event handler function to be called when the proper event occurs.
-->This event EVENT_ADD_ON_LOADED will be called for EACH of the addns/libraries enabled, this is why there needs to be a check against the addon name
-->within your callback function! Else the very first addon loaded would run your code + all following addons too.
EVENT_MANAGER:RegisterForEvent(LazyCraftingCertification.name, EVENT_ADD_ON_LOADED, LazyCraftingCertification.OnAddOnLoaded)
EVENT_MANAGER:RegisterForEvent(LazyCraftingCertification.name, EVENT_INVENTORY_SINGLE_SLOT_UPDATE, LazyCraftingCertification.InventoryChange)
EVENT_MANAGER:AddFilterForEvent(LazyCraftingCertification.name, EVENT_INVENTORY_SINGLE_SLOT_UPDATE, REGISTER_FILTER_IS_NEW_ITEM, true)
EVENT_MANAGER:AddFilterForEvent(LazyCraftingCertification.name, EVENT_INVENTORY_SINGLE_SLOT_UPDATE, REGISTER_FILTER_BAG_ID, BAG_BACKPACK)
EVENT_MANAGER:AddFilterForEvent(LazyCraftingCertification.name, EVENT_INVENTORY_SINGLE_SLOT_UPDATE, REGISTER_FILTER_INVENTORY_UPDATE_REASON, INVENTORY_UPDATE_REASON_DEFAULT)
EVENT_MANAGER:RegisterForEvent(LazyCraftingCertification.name, EVENT_CRAFTING_STATION_INTERACT, LazyCraftingCertification.CraftingStation)
-- SLASH_COMMANDS["/lcc"] = LCCScratch