-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFishingOutfitter.lua
148 lines (135 loc) · 4.65 KB
/
FishingOutfitter.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
-- Interface with the Outfitter addon by mundocani
if ( Outfitter and Outfitter.OnLoad ) then
local FL = LibStub("LibFishing-1.0");
-- 5.0.4 has a problem with a global "_" (see some for loops below)
local _
local function OutfitterSwitch(outfitName)
-- this uses a static string of "Fishing" *not* the translation
local vOut, vCat, _ = Outfitter:FindOutfitByName(Outfitter.cFishingOutfit);
if ( not vOut ) then
local _, sname = FL:GetFishingSpellInfo();
vOut, vCat, _ = Outfitter:FindOutfitByName(sname);
end
if ( vOut ) then
local wasPole = FishingBuddy.ReadyForFishing();
if ( wasPole ) then
Outfitter:RemoveOutfit(vOut);
else
vOut.Disabled = nil;
Outfitter:WearOutfit(vOut, vCat);
end
Outfitter:Update(true);
-- return true if we're expecting to have a pole equipped
return (not wasPole);
end
end
local function RemoveOldOutfits()
local vName = "Fishing Buddy";
-- nuke all of the outfits named 'Fishing Buddy' since they're
-- likely wrong, so that we can create a new 'good' one
local vOut,_,_ = Outfitter:FindOutfitByName(vName);
while ( vOut and not vOut.StoredInEM ) do
Outfitter:DeleteOutfit(vOut);
vOut,_,_ = Outfitter:FindOutfitByName(vName);
end
end
local function WaitForOutfitter()
if ( Outfitter and Outfitter:IsInitialized() ) then
FishingOutfitterFrame:Hide();
-- throw any of these that exist away and make a new one
RemoveOldOutfits();
-- create the default fishing outfit, if it doesn't exist
local vOutfit,_,_ = Outfitter:FindOutfitByName(Outfitter.cFishingOutfit);
local outfit = FL:GetFishingOutfitItems(true);
if ( not vOutfit and outfit ) then
vOutfit = Outfitter:NewEmptyOutfit();
for _,item in pairs(outfit) do
local pItemInfo = Outfitter:GetItemInfoFromLink(item.link)
vOutfit:AddItem(item.slotname, pItemInfo)
end
vOutfit.Name = Outfitter.cFishingOutfit;
vOutfit.StatConfig = {{StatID = "FISHING"}};
local vCategoryID = Outfitter:AddOutfit(vOutfit);
-- we're done
end
end
end
FishingBuddy.OutfitManager.WaitForOutfitter = WaitForOutfitter;
local outfitterOutfitDone = false;
local function OutfitterInitialize()
if ( not outfitterOutfitDone ) then
outfitterOutfitDone = true;
FishingOutfitterFrame:Show();
end
end
-- calculate scores based on Outfitter
local function StylePoints(outfit)
local isp = FishingBuddy.OutfitManager.ItemStylePoints;
local points = 0;
if ( outfit )then
for slot in pairs(outfit.Items) do
points = points + isp(outfit.Items[slot].Code,
outfit.Items[slot].EnchantCode);
end
end
return points;
end
local function BonusPoints(outfit, vStatID)
local points = 0;
if ( outfit )then
for slot,item in pairs(outfit.Items) do
if ( item and item.Link ) then
points = points + FL:FishingBonusPoints(item.Link);
end
end
end
return points;
end
local Saved_Outfitter_ShowOutfitTooltip = Outfitter.ShowOutfitTooltip;
local function Patch_ShowOutfitTooltip(self, pOutfit, pOwner, pMissingItems, pBankedItems, pShowEmptyTooltips, pTooltipAnchor)
Saved_Outfitter_ShowOutfitTooltip(self, pOutfit, pOwner, pMissingItems, pBankedItems, pShowEmptyTooltips, pTooltipAnchor);
if ((pOutfit.StatID and pOutfit.StatID == "FISHING") or
(pOutfit.StatConfig and pOutfit.StatConfig[1] and pOutfit.StatConfig[1].StatID == "FISHING")) then
local vDescription;
local bp = BonusPoints(pOutfit, "FISHING");
if ( bp >= 0 ) then
bp = "+"..bp;
else
bp = 0 - bp;
bp = "-"..bp;
end
bp = Outfitter.LibStatLogic:GetStatNameFromID("FISHING").." "..bp;
local sp = StylePoints(pOutfit);
local pstring;
if ( sp == 1 ) then
pstring = FBConstants.POINT;
else
pstring = FBConstants.POINTS;
end
vDescription = string.format(FBConstants.CONFIG_OUTFITTER_TEXT, bp, sp)..pstring;
if (self:GetOutfitDescription(pOutfit)) then
GameTooltip:AddLine(vDescription, 1, 1, 1)
else
GameTooltip:SetOwner(pOwner, pTooltipAnchor or "ANCHOR_LEFT")
GameTooltip:AddLine(pOutfit:GetName())
GameTooltip:AddLine(vDescription, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b, true)
end
GameTooltip:Show();
end
end
-- point to our new function so we get our own tooltip
-- Let's not, and say we did. This changes too often and it doesn't get much feedback
-- Outfitter.ShowOutfitTooltip = Patch_ShowOutfitTooltip;
local wasfishing = false;
local OutfitterEvents = {};
OutfitterEvents["PLAYER_REGEN_DISABLE"] = function()
if ( FishingBuddy.ReadyForFishing() ) then
local vOut,_,_ = Outfitter:FindOutfitByStatID("FISHING");
Outfitter:RemoveOutfit(vOut);
end
end
FishingBuddy.OutfitManager.RegisterManager("Outfitter",
OutfitterInitialize,
function(useme) end,
OutfitterSwitch);
end; -- If Outfitter.OnLoad