vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2  
3 Enchantrix v3.6.1 (Platypus)
4 $Id: Enchantrix.lua 859 2006-05-11 13:35:49Z aradan $
5  
6 By Norganna
7 http://enchantrix.org/
8  
9 This is an addon for World of Warcraft that add a list of what an item
10 disenchants into to the items that you mouse-over in the game.
11  
12 License:
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License
15 as published by the Free Software Foundation; either version 2
16 of the License, or (at your option) any later version.
17  
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22  
23 You should have received a copy of the GNU General Public License
24 along with this program(see GLP.txt); if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  
27 ]]
28  
29 -- Local functions
30 local addonLoaded
31 local onLoad
32 local pickupInventoryItemHook
33 local pickupContainerItemHook
34 local onEvent
35  
36 Enchantrix.Version = "3.6.1"
37 if (Enchantrix.Version == "<".."%version%>") then
38 Enchantrix.Version = "3.5.DEV"
39 end
40  
41 local DisenchantEvent = {}
42  
43 -- This function differs from onLoad in that it is executed
44 -- after variables have been loaded.
45 function addonLoaded(hookArgs, event, addOnName)
46 if (event ~= "ADDON_LOADED") or (string.lower(addOnName) ~= "enchantrix") then
47 return
48 end
49 Stubby.UnregisterEventHook("ADDON_LOADED", "Enchantrix")
50  
51 -- Call AddonLoaded for other objects
52 Enchantrix.Storage.AddonLoaded() -- Sets up saved variables so should be called first
53 Enchantrix.Barker.AddonLoaded()
54 Enchantrix.Command.AddonLoaded()
55 Enchantrix.Config.AddonLoaded()
56 Enchantrix.Locale.AddonLoaded()
57 Enchantrix.Tooltip.AddonLoaded()
58  
59 Enchantrix.Revision = Enchantrix.Util.GetRevision("$Revision: 859 $")
60 for name, obj in pairs(Enchantrix) do
61 if type(obj) == "table" then
62 Enchantrix.Revision = math.max(Enchantrix.Revision, Enchantrix.Util.GetRevision(obj.Revision))
63 end
64 end
65  
66 Stubby.RegisterAddOnHook("Auctioneer", "Enchantrix", Enchantrix.Command.AuctioneerLoaded);
67  
68 -- Register disenchant detection hooks
69 Stubby.RegisterFunctionHook("PickupContainerItem", 400, pickupContainerItemHook)
70 Stubby.RegisterFunctionHook("PickupInventoryItem", 400, pickupInventoryItemHook)
71  
72 Stubby.RegisterEventHook("SPELLCAST_START", "Enchantrix", onEvent)
73 Stubby.RegisterEventHook("SPELLCAST_STOP", "Enchantrix", onEvent)
74 Stubby.RegisterEventHook("SPELLCAST_FAILED", "Enchantrix", onEvent)
75 Stubby.RegisterEventHook("SPELLCAST_INTERRUPTED", "Enchantrix", onEvent)
76 Stubby.RegisterEventHook("LOOT_OPENED", "Enchantrix", onEvent)
77  
78 local vstr = string.format("%s-%d", Enchantrix.Version, Enchantrix.Revision)
79 Enchantrix.Util.ChatPrint(string.format(_ENCH('FrmtWelcome'), vstr), 0.8, 0.8, 0.2)
80 Enchantrix.Util.ChatPrint(_ENCH('FrmtCredit'), 0.6, 0.6, 0.1)
81 end
82  
83 -- Register our temporary command hook with stubby
84 function onLoad()
85 Stubby.RegisterBootCode("Enchantrix", "CommandHandler", [[
86 local function cmdHandler(msg)
87 local i,j, cmd, param = string.find(string.lower(msg), "^([^ ]+) (.+)$")
88 if (not cmd) then cmd = string.lower(msg) end
89 if (not cmd) then cmd = "" end
90 if (not param) then param = "" end
91 if (cmd == "load") then
92 if (param == "") then
93 Stubby.Print("Manually loading Enchantrix...")
94 LoadAddOn("Enchantrix")
95 elseif (param == "always") then
96 Stubby.Print("Setting Enchantrix to always load for this character")
97 Stubby.SetConfig("Enchantrix", "LoadType", param)
98 LoadAddOn("Enchantrix")
99 elseif (param == "never") then
100 Stubby.Print("Setting Enchantrix to never load automatically for this character (you may still load manually)")
101 Stubby.SetConfig("Enchantrix", "LoadType", param)
102 else
103 Stubby.Print("Your command was not understood")
104 end
105 else
106 Stubby.Print("Enchantrix is currently not loaded.")
107 Stubby.Print(" You may load it now by typing |cffffffff/enchantrix load|r")
108 Stubby.Print(" You may also set your loading preferences for this character by using the following commands:")
109 Stubby.Print(" |cffffffff/enchantrix load always|r - Enchantrix will always load for this character")
110 Stubby.Print(" |cffffffff/enchantrix load never|r - Enchantrix will never load automatically for this character (you may still load it manually)")
111 end
112 end
113 SLASH_ENCHANTRIX1 = "/enchantrix"
114 SLASH_ENCHANTRIX2 = "/enchant"
115 SLASH_ENCHANTRIX3 = "/enx"
116 SlashCmdList["ENCHANTRIX"] = cmdHandler
117 ]]);
118  
119 Stubby.RegisterBootCode("Enchantrix", "Triggers", [[
120 if Stubby.GetConfig("Enchantrix", "LoadType") == "always" then
121 LoadAddOn("Enchantrix")
122 else
123 Stubby.Print("]].._ENCH('MesgNotloaded')..[[")
124 end
125 ]]);
126  
127 SLASH_ENCHANTRIX1 = "/enchantrix";
128 SLASH_ENCHANTRIX2 = "/enchant";
129 SLASH_ENCHANTRIX3 = "/enx";
130 SlashCmdList["ENCHANTRIX"] = function(msg) Enchantrix.Command.HandleCommand(msg) end
131  
132 Stubby.RegisterEventHook("ADDON_LOADED", "Enchantrix", addonLoaded)
133 end
134  
135 function pickupInventoryItemHook(funcArgs, retVal, slot)
136 -- Remember last activated item
137 if slot then
138 DisenchantEvent.spellTarget = GetInventoryItemLink("player", slot)
139 end
140 end
141  
142 function pickupContainerItemHook(funcArgs, retVal, bag, slot)
143 -- Remember last activated item
144 if bag and slot then
145 DisenchantEvent.spellTarget = GetContainerItemLink(bag, slot)
146 end
147 end
148  
149 function onEvent(funcVars, event, spellName, spellDuration)
150 if event == "SPELLCAST_START" then
151 if spellName == _ENCH('ArgSpellname') then
152 DisenchantEvent.started = DisenchantEvent.spellTarget
153 DisenchantEvent.finished = nil
154 DisenchantEvent.startTime = GetTime()
155 DisenchantEvent.spellDuration = spellDuration / 1000 -- Convert ms to s
156 else
157 DisenchantEvent.started = nil
158 DisenchantEvent.finished = nil
159 end
160 return
161 end
162 if (event == "SPELLCAST_FAILED") or (event == "SPELLCAST_INTERRUPTED") then
163 DisenchantEvent.started = nil
164 DisenchantEvent.finished = nil
165 return
166 end
167 if event == "SPELLCAST_STOP" then
168 DisenchantEvent.finished = DisenchantEvent.started
169 DisenchantEvent.started = nil
170 return
171 end
172 if event == "LOOT_OPENED" then
173 if DisenchantEvent.finished then
174 -- Make sure loot windows opens within a few seconds from expected spell completion time
175 -- Normal range of lootLatency appears to be around -0.1 - 0.7s
176 local lootLatency = GetTime() - (DisenchantEvent.startTime + DisenchantEvent.spellDuration)
177 if (lootLatency > -1) and (lootLatency < 2) then
178 Enchantrix.Util.ChatPrint(string.format(_ENCH("FrmtFound"), DisenchantEvent.finished))
179 local sig = Enchantrix.Util.GetSigFromLink(DisenchantEvent.finished)
180 for i = 1, GetNumLootItems(), 1 do
181 if LootSlotIsItem(i) then
182 local icon, name, quantity, rarity = GetLootSlotInfo(i)
183 local link = GetLootSlotLink(i)
184 Enchantrix.Util.ChatPrint(string.format(" %s x%d", link, quantity))
185 -- Save result
186 local reagentID = Enchantrix.Util.GetItemIdFromLink(link)
187 if reagentID then
188 Enchantrix.Storage.SaveDisenchant(sig, reagentID, quantity)
189 end
190 end
191 end
192 end
193 end
194 DisenchantEvent.started = nil
195 DisenchantEvent.finished = nil
196 return
197 end
198 end
199  
200 -- Execute on load
201 onLoad()