vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 function ChatCast_Trade_OnLoad()
2 this:RegisterEvent("TRADE_SHOW");
3 this:RegisterEvent("TRADE_REQUEST");
4 this:RegisterEvent("TRADE_UPDATE");
5 this:RegisterEvent("TRADE_ACCEPT_UPDATE")
6 this:RegisterEvent("TRADE_CLOSED")
7 this:RegisterEvent("TRADE_REQUEST_CANCELLED")
8 this:RegisterEvent("SPELLCAST_START");
9 this:RegisterEvent("SPELLCAST_INTERRUPTED");
10 this:RegisterEvent("SPELLCAST_STOP");
11 this:RegisterEvent("SPELLCAST_FAILED");
12 end
13  
14 function ChatCast_Trade_OnEvent()
15 if (event == "TRADE_SHOW" or event == "TRADE_REQUEST") then
16 ChatCast_DoTrade();
17 elseif (event == "TRADE_UPDATE" or event == "TRADE_ACCEPT_UPDATE") then
18 ChatCast_FinishTrade();
19 elseif (event == "TRADE_CLOSED" or event == "TRADE_REQUEST_CANCELLED") then
20 ChatCast.Trading = nil;
21 elseif (event == "SPELLCAST_STOP") then
22 if (ChatCast.Trading) then
23 if (ChatCast.Trading.creating == 1) then
24 ChatCast.Trading.creating = 3.5
25 end
26 end
27 elseif (event == "SPELLCAST_FAILED" or event == "SPELLCAST_INTERRUPT") then
28 if (ChatCast.Trading) then ChatCast.Trading = nil
29 if (ChatCast.Feedback) then DEFAULT_CHAT_FRAME:AddMessage(CCLocale.UI.text.fb_createfail .. " " .. arg1 .. ".") end
30 end
31 elseif (event == "UI_ERROR_MESSAGE") then
32 if (ChatCast.Feedback) then
33 if arg1 == "Interrupted" then DEFAULT_CHAT_FRAME:AddMessage(CCLocale.UI.text.fb_createfail .. " " .. arg1 .. ".")
34 elseif arg1 == "Trade target is too far away." then DEFAULT_CHAT_FRAME:AddMessage(string.format(CCLocale.UI.text.fb_tradefail,ChatCast.Trading.name) .. " " .. arg1)
35 end
36 end
37 if (ChatCast.Trading) then ChatCast.Trading = nil end
38 end
39 end
40 -- Trade functions
41 function ChatCast_FindItem(item,quantity)
42 for container=0,NUM_CONTAINER_FRAMES do
43 for slot=1,GetContainerNumSlots(container) do
44 local _, count, _, _ = GetContainerItemInfo(container, slot)
45 if (count and count >= quantity) then
46 GameTooltip:SetBagItem(container,slot)
47 if item == getglobal("GameTooltipTextLeft1"):GetText() then
48 return container, slot;
49 end
50 end
51 end
52 end
53 return nil,nil
54 end;
55  
56 function ChatCast_LookupItem(info, item)
57 local target_rank, spellName, spellRank, iclass, inumber, target_rankt
58 local j = 0
59 if item == "_Healthstone" then iclass, inumber, target_rankt = "WARLOCK", 4, 10
60 elseif item == "_Soulstone" then iclass, inumber, target_rankt = "WARLOCK", 5, 60
61 elseif item == "_Water" then iclass, inumber, target_rankt = "MAGE", 6, 5
62 elseif item == "_Food" then iclass, inumber, target_rankt = "MAGE", 7, 7
63 end
64 DEFAULT_CHAT_FRAME:AddMessage(item)
65 if ChatCast_SpellLibrary[iclass][inumber] then
66 for i=1, table.getn(ChatCast_SpellLibrary[iclass][inumber].rank), 1 do
67 if UnitLevel("player") >= ChatCast_SpellLibrary[iclass][inumber].rank[i] and UnitLevel("target") >= ChatCast_SpellLibrary[iclass][inumber].rank[i] - target_rankt then
68 target_rank = i
69 end
70 end
71 if info == "item" then return ChatCast_SpellLibrary[iclass][inumber].rankitem[target_rank]
72 elseif info == "spell" then
73 if target_rank then
74 if item == "_Water" or item == "_Food" then return ChatCast_SpellLibrary[iclass][inumber].spellname .. string.format(CCLocale.UI.rank, target_rank) end
75 local i = 1
76 while true do
77 spellName, spellRank = GetSpellName(i, 1)
78 if not spellName then
79 break
80 elseif spellName == ChatCast_SpellLibrary[iclass][inumber].spellname[target_rank] then
81 return i
82 end
83 i = i + 1
84 end
85 end
86 end
87 end
88 return nil
89 end
90  
91 function ChatCast_CreateItem(item)
92 if item == "_Healthstone" or item == "_Soulstone" or item == "_Water" or item == "_Food" then
93 local spellid = ChatCast_LookupItem("spell", item)
94 if spellid then
95 if ChatCast.Trading then ChatCast.Trading.creating = 1 end
96 if (ChatCast.Feedback) then DEFAULT_CHAT_FRAME:AddMessage(string.format(CCLocale.UI.text.fb_creating, (ChatCast.Trading and ChatCast.Trading.itemname or item))) end
97 if item == "_Healthstone" or item == "_Soulstone" then
98 CastSpell(spellid,BOOKTYPE_SPELL)
99 elseif item == "_Water" or item == "_Food" then
100 CastSpellByName(spellid)
101 end
102 end
103 end
104 end
105  
106 function ChatCast_Soulstone(name)
107 if not name then return end
108 local itemname = ChatCast_LookupItem("item", "_Soulstone")
109 local container, slot = ChatCast_FindItem(itemname, 1)
110 if container and slot then
111 local oldtarget
112 if UnitName("target") then oldtarget = UnitName("target") end
113 if ChatCast_Target(name) then
114 UseContainerItem(container, slot)
115 end
116 else
117 ChatCast_CreateItem("_Soulstone")
118 end
119 end
120  
121 function ChatCast_InitiateTrade(name, item, quantity)
122 if not name or not item or not quantity then return nil end
123 local oldtarget, itemname = nil,nil
124 if UnitName("target") then oldtarget = UnitName("target") end
125 if ChatCast_Target(name) then
126 if item == "_Healthstone" or item == "_Water" or item == "_Food" then itemname = ChatCast_LookupItem("item", item) else itemname = item end
127 local cca, ccb = ChatCast_FindItem(itemname, quantity)
128 ChatCast.Trading = {
129 name = name,
130 itemname = itemname,
131 time = 4,
132 quantity = quantity,
133 creating = nil
134 }
135 ChatCastFrame:Show()
136 if cca and ccb then
137 InitiateTrade("target")
138 -- if ChatCast.Feedback then DEFAULT_CHAT_FRAME:AddMessage(string.format(CCLocale.UI.text.fb_trading, name)) end
139 else
140 ChatCast_CreateItem(item)
141 end
142 else
143 if ChatCast.Feedback then DEFAULT_CHAT_FRAME:AddMessage(string.format(CCLocale.UI.text.fb_targetfail, name)) end
144 ChatCast.Trading = nil
145 end
146 if oldtarget then ChatCast_Target(oldtarget) else ClearTarget() end
147 end
148  
149 function ChatCast_DoTrade()
150 if ChatCast.Trading then
151 if ChatCast.Trading.time > 0.1 then
152 if not ChatCast.Trading.container or not ChatCast.Trading.slot then
153 ChatCast.Trading.container, ChatCast.Trading.slot = ChatCast_FindItem(ChatCast.Trading.itemname, ChatCast.Trading.quantity)
154 end
155 if ChatCast.Trading.container and ChatCast.Trading.slot then
156 PickupContainerItem(ChatCast.Trading.container, ChatCast.Trading.slot)
157 ClickTradeButton(1)
158 ChatCast.Trading.ready = 1.5
159 if CursorHasItem() then
160 PickupContainerItem(ChatCast.Trading.container, ChatCast.Trading.slot);
161 return;
162 end
163 end
164 end
165 end
166 end
167  
168 function ChatCast_FinishTrade()
169 if ChatCast.Trading then
170 AcceptTrade()
171 ChatCast.Trading = nil
172 end
173 end
174  
175 function ChatCast_Trade_OnUpdate()
176 if CC_AttackTimer and CC_AttackTimer > 0 then
177 CC_AttackTimer = CC_AttackTimer - arg1
178 if CC_AttackTimer < 0 then
179 AttackTarget()
180 ChatCastFrame:Hide()
181 end
182 elseif ChatCast.Trading then
183 if not ChatCast.Trading.creating then
184 if TradeFrame:IsShown() and ChatCast.Trading.ready then
185 if ChatCast.Trading.ready < 0.1 then
186 ChatCast_FinishTrade()
187 else
188 ChatCast.Trading.ready = ChatCast.Trading.ready - arg1
189 end
190 elseif ChatCast.Trading.time < 0.1 then
191 if ChatCast.Feedback then DEFAULT_CHAT_FRAME:AddMessage(string.format(CCLocale.UI.text.fb_tradefail, ChatCast.Trading.name)) end
192 ChatCast.Trading = nil
193 else
194 ChatCast.Trading.time = ChatCast.Trading.time - arg1
195 end
196 elseif ChatCast.Trading.creating > 2 then
197 ChatCast.Trading.creating = ChatCast.Trading.creating - arg1
198 if ChatCast.Trading.creating <= 2 then
199 ChatCast_InitiateTrade(ChatCast.Trading.name, ChatCast.Trading.itemname, ChatCast.Trading.quantity)
200 end
201 end
202 else ChatCastFrame:Hide()
203 end
204 end