-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67dcdb6
commit 178bc12
Showing
3 changed files
with
297 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Interface: 90002 | ||
## Title: Craft Logger | ||
## Author: Pantalaîmon / EU-Blackhand | ||
## Version: 0.1 | ||
## SavedVariables: CraftLog | ||
|
||
main.lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd"> | ||
<Editbox name="RecipeExporter"> | ||
<Size> | ||
<AbsDimension x="400" y="600" /> | ||
</Size> | ||
<Anchors> | ||
<Anchor point="CENTER" /> | ||
</Anchors> | ||
<Scripts> | ||
</Scripts> | ||
</Editbox> | ||
</Ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
--create frame | ||
|
||
local f = CreateFrame("Frame") | ||
local castGUID | ||
local debugToggle = false | ||
local optionalReagentsIlvl = { | ||
[185960] = { [190] = 225, [210] = 235, [225] = 249, [235] = 262 }, --VoO -> +2 | ||
[187784] = { [190] = 235, [210] = 249, [225] = 262, [235] = 291 }, --VotE -> +3 | ||
[183942] = 87, --NCM -> 87 | ||
[173381] = 117, --CM1 -> 117 | ||
[173382] = 168, --CM2 -> 168 | ||
[173383] = 200, --CM3 -> 200 | ||
[173384] = 230, --CMotCI -> 230 | ||
[187741] = 233, --CM4 -> 233 | ||
[187742] = 262 --CMotFO -> 262 | ||
} | ||
local optionalReagentsInventory = { | ||
[185960] = 0, --VoO -> +2 | ||
[187784] = 0, --VotE -> +3 | ||
[183942] = 0, --NCM -> 87 | ||
[173381] = 0, --CM1 -> 117 | ||
[173382] = 0, --CM2 -> 168 | ||
[173383] = 0, --CM3 -> 200 | ||
[173384] = 0, --CMotCI -> 230 | ||
[187741] = 0, --CM4 -> 233 | ||
[187742] = 0 --CMotFO -> 262 | ||
} | ||
|
||
local prospectingInventory = { | ||
[173110] = 0, -- Umbryl | ||
[173108] = 0, -- Oriblase | ||
[173109] = 0, -- Angerseye | ||
[173172] = 0, -- Essence of Servitude | ||
[173173] = 0, -- Essence of Valor | ||
[173171] = 0, -- Essence of Torment | ||
[173170] = 0 -- Essence of Rebirth | ||
} | ||
local prospectingSpellIDs = { | ||
[359492] = true, -- Progenium | ||
[311953] = true, -- Elethium | ||
[311948] = true, -- Laestrite | ||
[311950] = true, -- Oxxein | ||
[311951] = true, -- Phaedrum | ||
[311952] = true, -- Sinvyr | ||
[311949] = true -- Solenium | ||
} | ||
|
||
local delayedSpell, delayedTimestamp | ||
|
||
--structure of CraftLog table | ||
--CraftLog { | ||
-- [date] = { | ||
-- [itemlink] = { | ||
-- [ilvl] = { | ||
-- [-] = numused, | ||
-- [+] = numproduced | ||
-- } | ||
-- } | ||
-- } | ||
--} | ||
|
||
--register events | ||
f:RegisterEvent("UNIT_SPELLCAST_START") | ||
f:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") | ||
f:RegisterEvent("BAG_UPDATE_DELAYED") | ||
f:RegisterEvent("ADDON_LOADED") | ||
|
||
--handle slash commands | ||
|
||
function SlashCraftLog(arg1) | ||
if (arg1 == "") then | ||
print("use /craftlog debug to toggle debug mode") | ||
--toggle debug mode | ||
elseif (arg1 == "debug") then | ||
debugToggle = not debugToggle | ||
if (debugToggle) then | ||
print("CraftLog Debug Mode is now on") | ||
else | ||
print("CraftLog Debug Mode is now off") | ||
end | ||
end | ||
end | ||
|
||
--handle events | ||
f:SetScript("OnEvent", function(self, event, ...) | ||
if (event == "UNIT_SPELLCAST_START") then | ||
OnUnitSpellcastStart(event, ...) | ||
elseif (event == "UNIT_SPELLCAST_SUCCEEDED") then | ||
OnUnitSpellcastSucceeded(event, ...) | ||
elseif (event == "BAG_UPDATE_DELAYED") then | ||
OnBagUpdateDelayed(event, ...) | ||
elseif (event == "ADDON_LOADED") then | ||
InitializeSavedVariables(...) | ||
end | ||
end) | ||
|
||
function InitializeSavedVariables(...) | ||
local arg1 = ... | ||
if (arg1 == "CraftLog") then | ||
if (CraftLog == nil) then | ||
CraftLog = {} | ||
end | ||
end | ||
end | ||
|
||
function OnUnitSpellcastStart(event, ...) | ||
local unit, cast, spell = ... | ||
|
||
-- only run if caster is the player and tradeskillUI is open | ||
if (unit == "player" and C_TradeSkillUI.IsTradeSkillReady()) then | ||
--print start of cast event details | ||
if (debugToggle) then print(event.." "..cast.." "..spell) end | ||
|
||
--set castGUID to check if UNIT_SPELLCAST_SUCCEEDED matches | ||
castGUID = cast | ||
|
||
--check if optional reagents are available | ||
if not (C_TradeSkillUI.GetOptionalReagentInfo(spell)[1] == nil) then | ||
if (debugToggle) then print("optional reagents:") end | ||
--add inventory of optional reagents | ||
for k, v in pairs(optionalReagentsInventory) do | ||
optionalReagentsInventory[k] = GetItemCount(k, true, false, true) | ||
if (debugToggle) then print(optionalReagentsInventory[k].." x "..k) end | ||
end | ||
end | ||
|
||
--check if we are prospecting | ||
if not (prospectingSpellIDs[spell] == nil) then | ||
if (debugToggle) then print("prospecting...") end | ||
for k, v in pairs(prospectingInventory) do | ||
prospectingInventory[k] = GetItemCount(k, true, false, true) | ||
if (debugToggle) then print(prospectingInventory[k].." x "..k) end | ||
end | ||
end | ||
end | ||
end | ||
|
||
function OnUnitSpellcastSucceeded(event, ...) | ||
local unit, cast, spell = ... | ||
local timestamp = date('%Y-%m-%d') | ||
|
||
-- only run if caster is player and castGUID matches | ||
if (unit == "player" and cast == castGUID) then | ||
--store spell and timestamp for retrieval after OnBagUpdateDelayed(event, ...) fires | ||
if (debugToggle) then print(event.." "..cast.." "..spell) end | ||
delayedSpell = spell | ||
delayedTimestamp = timestamp | ||
else | ||
delayedSpell = nil | ||
delayedTimestamp = nil | ||
end | ||
|
||
end | ||
|
||
function addItemToCraftLog(timestamp, link, ilvl, dir, amount) | ||
--first craft for the day | ||
if (CraftLog[timestamp] == nil) then CraftLog[timestamp] = {} end | ||
--first craft of the day using/producing optional reagent | ||
if (CraftLog[timestamp][link] == nil) then CraftLog[timestamp][link] = {} end | ||
--first craft of the day using/producing optional reagent @ ilvl | ||
if (CraftLog[timestamp][link][ilvl] == nil) then CraftLog[timestamp][link][ilvl] = {} end | ||
--first craft of the day using optional reagent | ||
if (CraftLog[timestamp][link][ilvl][dir] == nil) then | ||
CraftLog[timestamp][link][ilvl][dir] = amount | ||
else | ||
CraftLog[timestamp][link][ilvl][dir] = CraftLog[timestamp][link][ilvl][dir] + amount | ||
end | ||
if (debugToggle) then print(timestamp.." "..dir.." "..amount.." "..link) end | ||
end | ||
|
||
function OnBagUpdateDelayed(event, ...) | ||
if (debugToggle) then print(event) end | ||
if not (delayedSpell == nil) and not (delayedTimestamp == nil) then | ||
--retrieve stored spell and timestamp | ||
local spell = delayedSpell | ||
local timestamp = delayedTimestamp | ||
local itemproduced | ||
|
||
-- log item produced | ||
if not (prospectingSpellIDs[spell] == nil) then | ||
--prospecting | ||
if (debugToggle) then print("using prospecing/milling logic (WIP)") end | ||
for i = 1, C_TradeSkillUI.GetRecipeNumReagents(spell) do | ||
local itemused = C_TradeSkillUI.GetRecipeReagentItemLink(spell,i) | ||
local _, _, _, ilvlused = GetItemInfo(itemused) | ||
local _, _, numitemused, _ = C_TradeSkillUI.GetRecipeReagentInfo(spell,i) | ||
--log used items | ||
addItemToCraftLog(timestamp, itemused, ilvlused, "-", numitemused) | ||
end | ||
|
||
-- TODO: work out the prospecting results, current solution is buggy af | ||
-- if (debugToggle) then print("prospecting results:") end | ||
-- for k, v in pairs(prospectingInventory) do | ||
-- local amount = GetItemCount(k, true, false, true) - prospectingInventory[k] | ||
-- local _, itemLink, _, ilvlproduced = GetItemInfo(k) | ||
-- if (debugToggle) then print(amount.." x "..k) end | ||
-- addItemToCraftLog(timestamp, itemLink, ilvlproduced, "+", amount) | ||
-- end | ||
|
||
else | ||
--default crafting | ||
if (debugToggle) then print("using default crafting logic") end | ||
itemproduced = C_TradeSkillUI.GetRecipeItemLink(spell) | ||
end | ||
--only continue if itemproduced exists aka tradeskill used | ||
if not (itemproduced == nil) then | ||
local numitemproduced = C_TradeSkillUI.GetRecipeNumItemsProduced(spell) | ||
local _, _, _, ilvlproduced = GetItemInfo(itemproduced) | ||
|
||
--check if optional reagents are available | ||
if not (C_TradeSkillUI.GetOptionalReagentInfo(spell)[1] == nil) then | ||
--remove inventory of optional reagents | ||
for k, v in pairs(optionalReagentsInventory) do | ||
local optionalReagent, optionalReagentIlvl | ||
local amount = optionalReagentsInventory[k] - GetItemCount(k, true, false, true) | ||
optionalReagentsInventory[k] = GetItemCount(k, true, false, true) | ||
--if optional reagent is still > 0 it was used -> adjust ilvlproduced accordingly | ||
if (amount>0) then | ||
--set used optional reagent | ||
_, optionalReagent, _, optionalReagentIlvl = GetItemInfo(k) | ||
|
||
--crafted a legendary? | ||
if (ilvlproduced >= 190) then | ||
ilvlproduced = optionalReagentsIlvl[k][ilvlproduced] | ||
--crafted something else? | ||
else | ||
ilvlproduced = optionalReagentsIlvl[k] | ||
end | ||
if (debugToggle) then print(optionalReagent.." used to change ilvl to "..ilvlproduced) end | ||
|
||
--add optional reagent to CraftLog | ||
addItemToCraftLog(timestamp, optionalReagent, optionalReagentIlvl, "-", amount) | ||
end | ||
end | ||
end | ||
|
||
--iterate through reagents to log items used | ||
for i = 1, C_TradeSkillUI.GetRecipeNumReagents(spell) do | ||
local itemused = C_TradeSkillUI.GetRecipeReagentItemLink(spell,i) | ||
local _, _, _, ilvlused = GetItemInfo(itemused) | ||
local _, _, numitemused, _ = C_TradeSkillUI.GetRecipeReagentInfo(spell,i) | ||
--log used items | ||
addItemToCraftLog(timestamp, itemused, ilvlused, "-", numitemused) | ||
end | ||
--log produced item | ||
addItemToCraftLog(timestamp, itemproduced, ilvlproduced, "+", numitemproduced) | ||
end | ||
|
||
--reset delayed spell and timestamp | ||
delayedSpell = nil | ||
delayedTimestamp = nil | ||
end | ||
end | ||
|
||
--register slash commands | ||
SLASH_CRAFTLOG1 = "/cl" | ||
SLASH_CRAFTLOG2 = "/craftlog" | ||
|
||
SlashCmdList["CRAFTLOG"] = SlashCraftLog | ||
|
||
|
||
--on UNIT_SPELLCAST_START | ||
-- snapshot inventory | ||
|
||
--on UNIT_SPELLCAST_SUCCEEDED | ||
-- if player | ||
-- spellid = arg3 | ||
-- itemproduced = C_TradeSkillUI.GetRecipeItemLink( spellid ) | ||
-- if C_TradeSkillUI.GetOptionalReagentInfo( spellid ) > 0 | ||
-- diff snapshot and current inventory to determine optional reagent used and resulting ilvl | ||
-- numitemproduced = C_TradeSkillUI.GetRecipeNumItemsProduced( spellid ) | ||
-- for each C_TradeSkillUI.GetRecipeNumReagents( spellid ) | ||
-- itemused = C_TradeSkillUI.GetRecipeReagentItemLink( spellid, reagentindex ) | ||
-- _, _, _, numitemused, _ = C_TradeSkillUI.GetRecipeReagentInfo( spellid, reagentIndex ) | ||
|
||
--cloth hands 291 = 338998 | ||
--cloth hands 249 = 332068 | ||
--r1-4 have different spellids, effective ilvl/optional reagent via inventory diff between start/success of craft |