comparison Turok/Modules/Utilities/PetBattle.lua @ 6:a9b8b0866ece

clear out log jam
author Nenue
date Sun, 21 Feb 2016 08:32:53 -0500
parents
children 9400a0ff8540
comparison
equal deleted inserted replaced
5:8a9a6637f082 6:a9b8b0866ece
1 --- ${PACKAGE_NAME}
2 -- @file-author@
3 -- @project-revision@ @project-hash@
4 -- @file-revision@ @file-hash@
5 -- Created: 1/17/2016 6:51 PM
6
7 local ADDON, Turok = ...
8 local T, _G, pairs, pairs = Turok.Addon, _G, pairs, ipairs
9 local mod = T:NewModule("PetBattle")
10 local print = function(...) _G.print('Petz', ...) end
11 local trace = function(self, e, ...)
12 print(e, ...)
13 end
14
15 local PBS
16 local turn_font = [[Interface\Addons\Turok\Media\font\ArchivoNarrow-Bold.ttf]]
17 local turn_size = 24
18 local turn_outline = 'OUTLINE'
19 local icon_size = 64
20 local spacing = 5
21 local padding = 0
22 local strongweak_size = 20
23
24 local cpb = C_PetBattles
25 T.defaults.petbattle = {
26 swatch = {
27 anchor = 'BOTTOM', anchorTo = 'BOTTOM',
28 parent = 'UIParent',
29 x = 0, y =240,
30 width = 200, height = 100,
31 font = [[Interface\Addons\Turok\Media\font\ArchivoNarrow-Bold.ttf]],
32 size = 16,
33 },
34 spell = {
35 anchor = 'TOPLEFT', anchorTo = 'TOPLEFT',
36 size = 24,
37 width = 72, height = 72,
38 x = 0, y =0,
39 padding = 0,
40 spacing = 0,
41 },
42 sideSwatch = {
43 width = 100, height = 50, padding = 0, spacing = 5,
44 anchor = 'TOPLEFT', anchorTo = 'BOTTOMLEFT', x = 0, y = 0,
45 parent = 'TkPetSwatch',
46 },
47 sideSpell = {
48 anchor = 'TOPLEFT', anchorTo = 'TOPLEFT',
49 size = 16,
50 width = 36, height = 36,
51 padding = 0,
52 spacing = 0,
53 },
54 icon = {
55 size = 72,
56 width = 64,
57 height = 64,
58 }
59 }
60 mod.abilityButtons = {}
61 mod.switcherButtons = {}
62 mod.icons = {}
63 mod.strongweak = {}
64 mod.turns = {}
65 mod.petlist = {}
66 local PLAYER, ENEMY = 1, 2
67 local function PBS_UpdateEnemySwatch(self)
68
69 print('UpdateSwatch')
70 local db = TurokData.petbattle.swatch
71 local playerActivePet = cpb.GetActivePet(PLAYER)
72 local enemyActivePet = cpb.GetActivePet(ENEMY)
73 local enemyNumPets = cpb.GetNumPets(ENEMY)
74 local playerPetType = cpb.GetPetType(PLAYER, playerActivePet)
75 local enemyPetType = cpb.GetPetType(ENEMY, enemyActivePet)
76 local enemyPetName = cpb.GetName(ENEMY, playerActivePet)
77 for petSlot=1, 3 do
78 local swatchFrame = (petSlot == enemyActivePet) and self or ((petSlot < enemyNumPets) and self.sideSwatch or self.sideSwatch2)
79 local db = (swatchFrame == self) and db.spell or db.sideSpell
80 local type = cpb.GetPetType(ENEMY, petSlot)
81 print(cText(' PetType='), enemyActivePet)
82 print(cText(' current='), enemyPetType)
83 for spellSlot=1, 3 do
84 print(' ', cText('PetSlotOffset='), cNum(petSlot), cText('AbilitySlotOffset'), cNum(spellSlot))
85 local id, name, texture, cooldown, desc, numTurns, attackType, noStrongWeakHints = cpb.GetAbilityInfo(ENEMY, petSlot, spellSlot)
86 local usable, remaining = cpb.GetAbilityState(ENEMY, petSlot, spellSlot)
87
88 --print('info', cpb.GetAbilityInfo(ENEMY, petSlot, spellSlot))
89 -- print('effect', cpb.GetAbilityEffectInfo(id, turnIdx, effectIdx, paramName)
90 --print('state', cpb.GetAbilityState(ENEMY,petSlot,spellSlot))
91 --print('statemod', cpb.GetAbilityStateModification(ENEMY,petSlot,spellSlot))
92 --print('proc', cpb.GetAbilityProcTurnIndex(ENEMY,petSlot,spellSlot))
93 --print('statemod', cpb.GetAbilityState(ENEMY,petSlot,spellSlot))
94 local AbilityButton, icon, strong, turns -- Icon, Strength/Weakness, Turns cooldown
95 if not swatchFrame.buttons[spellSlot] then
96 swatchFrame.buttons[spellSlot] = CreateFrame('Frame', 'TkPetSpell'..spellSlot, swatchFrame, 'TkPetSpellTemplate')
97 AbilityButton = swatchFrame.buttons[spellSlot]
98
99 AbilityButton:SetSize(db.width, db.height)
100 AbilityButton:SetPoint(db.anchor, swatchFrame, db.anchor, (spellSlot-1)*(db.width+ db.spacing), 0)
101
102 AbilityButton.icon:SetSize(db.width, db.height)
103 AbilityButton.icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
104
105 AbilityButton.strongWeakHint:SetSize(strongweak_size, strongweak_size)
106 AbilityButton.strongWeakHint:SetPoint('CENTER', swatchFrame.buttons[spellSlot], 'CENTER', 0, 0)
107
108 AbilityButton.turnsLeft:SetFont(turn_font, turn_size, turn_outline)
109 AbilityButton.turnsLeft:SetPoint('CENTER', icon, 'CENTER')
110 else
111 AbilityButton = swatchFrame.buttons[spellSlot]
112 end
113 local icon, strong , turns = AbilityButton.icon, AbilityButton.strongWeakHint, AbilityButton.turnsLeft
114
115 print('Working on:', swatchFrame, AbilityButton)
116 print('AbilityState('..petSlot..', '..spellSlot..')', 'usable=', usable, 'turnsLeft=', remaining)
117 print(cWord(name), cKey(attackType))
118
119 if petSlot > enemyNumPets then
120 -- this will also eval true when pet battle over since numPets will be 0
121 AbilityButton.popOut:Play()
122 else
123 local abilityChanged
124 if id ~= AbilityButton.spellID then
125 abilityChanged = true
126 AbilityButton.spellID = id
127 AbilityButton.spellName = name
128 AbilityButton.spellDesc = desc
129 AbilityButton.spellType = attackType
130 AbilityButton.spellMaxCooldown = cooldown
131 AbilityButton.spellDesc = desc
132 AbilityButton.spellCooldown = remaining
133 AbilityButton.spellNumTurns = numTurns
134 end
135 if AbilityButton.petType ~= enemyPetType then
136 AbilityButton.petType = enemyPetType
137 AbilityButton.noStrongWeakHints = noStrongWeakHints
138 end
139
140 if not usable then
141 icon:SetDesaturated(true)
142 icon:SetVertexColor(0.5, 0.5, 0.5, 1)
143 else
144 icon:SetDesaturated(false)
145 icon:SetVertexColor(1, 1, 1, 1)
146 end
147
148 icon:SetTexture(texture)
149 turns:SetText((cooldown > 0) and cooldown or nil)
150 --AbilityButton.damage:SetText()
151
152 print('noStrongWeakHints', noStrongWeakHints)
153 print('abilityModification', cpb.GetAttackModifier(enemyPetType, playerPetType))
154 local modifier = cpb.GetAttackModifier(enemyPetType, playerPetType)
155 if not noStrongWeakHints then
156 if modifier < 1 then
157 strong:SetTexture(0,1,0,0.5)
158 else
159 strong:SetTexture(1,0,0,0.5)
160 end
161
162 strong:Show()
163 else
164 strong:Hide()
165 end
166 if numTurns then
167 print('numTurns=',numTurns)
168 end
169 if not AbilityButton:IsVisible() or abilityChanged then
170 AbilityButton:Show()
171 AbilityButton.popIn:Play()
172 end
173
174 end
175
176
177 end
178 swatchFrame:SetSize(db.width*3+db.spacing*2+db.padding*2, db.height+padding*2)
179 swatchFrame.petName = enemyPetName
180 swatchFrame.petType = enemyPetType
181 local db = (swatchFrame == self) and db.swatch or db.sideSwatch
182 swatchFrame:Show()
183 end
184 end
185
186 local function PBS_Switch ()
187 print('Switch button was clicked.')
188 end
189 mod.PLAYER_ENTERING_WORLD = function(self, e)
190 print(cpb.IsInBattle())
191 if cpb.IsInBattle() then
192 PBS_UpdateEnemySwatch(PBS, e, 2)
193 end
194
195
196 if _G.PetBattleFrame.BottomFrame.SwitchPetButton then
197 print("There's a pet battle frame button ")
198 --_G.PetBattleFrame.BottomFrame.SwitchPetButton:SetScript('OnClick', PBS_Switch)
199 end
200 end
201
202 local PBS_Hide = function()
203 for i = 1, 3 do
204 if PBS.buttons[i] then
205 PBS.buttons[i].popOut:Play()
206 end
207 if PBS.sideSwatch.buttons[i] then
208 PBS.sideSwatch.buttons[i].popOut:Play()
209 end
210 if PBS.sideSwatch2.buttons[i] then
211 PBS.sideSwatch2.buttons[i].popOut:Play()
212 end
213 end
214 end
215
216 local PBS_Event = function(self, e, ...)
217 print('event', e)
218 local owner = ...
219 if e == 'PET_BATTLE_PET_ROUND_PLAYBACK_COMPLETE' or e == 'PET_BATTLE_OPENING_DONE' then
220 PBS_UpdateEnemySwatch(PBS)
221 elseif e == 'PET_BATTLE_CLOSE' then
222 PBS_Hide(PBS)
223 end
224 end
225 function mod:OnEnable()
226 PBS = CreateFrame('Frame', 'TkPetSwatch', UIParent, 'TkPetSwatchTemplate')
227 PBS.buttons = {}
228 PBS.sideSwatch = CreateFrame('Frame', 'TkSideSwatch', PBS, 'TkPetSwatchTemplate')
229 PBS.sideSwatch.buttons = {}
230 PBS.sideSwatch2 = CreateFrame('Frame', 'TkSideSwatch', PBS, 'TkPetSwatchTemplate')
231 PBS.sideSwatch2.buttons = {}
232 local db = TurokData.petbattle
233 T.SetFrameLayout(PBS, db.swatch)
234 T.SetFrameLayout(PBS.sideSwatch, db.sideSwatch)
235 T.SetFrameLayout(PBS.sideSwatch2, db.sideSwatch)
236 PBS.sideSwatch2:ClearAllPoints()
237 PBS.sideSwatch2:SetPoint('LEFT', PBS.sideSwatch, 'RIGHT', db.sideSpell.spacing, 0)
238
239 mod.effectIndex = {
240 cpb.GetAllEffectNames()
241 }
242
243 PBS:SetScript('OnEvent', PBS_Event)
244 PBS:RegisterEvent('PET_BATTLE_OPENING_DONE')
245 PBS:RegisterEvent('PET_BATTLE_PET_CHANGED')
246 PBS:RegisterEvent('PET_BATTLE_OVER')
247 PBS:RegisterEvent('PET_BATTLE_CLOSE')
248 PBS:RegisterEvent('PET_BATTLE_ABILITY_CHANGED')
249 PBS:RegisterEvent('PET_BATTLE_ACTION_SELECTED')
250 --PBS:RegisterEvent('PET_BATTLE_AURA_APPLIED')
251 --PBS:RegisterEvent('PET_BATTLE_AURA_CANCELED')
252 --PBS:RegisterEvent('PET_BATTLE_PET_TYPE_CHANGED')
253 PBS:RegisterEvent('PET_BATTLE_TURN_STARTED')
254 --PBS:RegisterEvent('PET_BATTLE_HEALTH_CHANGED')
255 --PBS:RegisterEvent('PET_BATTLE_MAX_HEALTH_CHANGED')
256 PBS:RegisterEvent('PET_BATTLE_PET_ROUND_RESULTS')
257 PBS:RegisterEvent('PET_BATTLE_PET_ROUND_PLAYBACK_COMPLETE')
258 end
259
260 --[[
261 mod.PET_BATTLE_OPENING_DONE = trace
262 mod.PET_BATTLE_OPENING_START = trace
263 mod.PET_BATTLE_OVER = trace
264 mod.PET_BATTLE_ABILITY_CHANGED = trace
265 mod.PET_BATTLE_ACTION_SELECTED = trace
266 mod.PET_BATTLE_AURA_APPLIED = trace -- <team> <slot> <id>
267 mod.PET_BATTLE_AURA_CANCELED = trace -- <team> <slot> <id>
268 mod.PET_BATTLE_AURA_CHANGED = trace -- <team> <slot> <id>
269 mod.PET_BATTLE_CAPTURED = trace
270 mod.PET_BATTLE_CLOSE = trace
271 mod.PET_BATTLE_FINAL_ROUND = trace -- <team>
272 mod.PET_BATTLE_HEALTH_CHANGED = trace -- <team> <pet slot> <delta>
273 mod.PET_BATTLE_LEVEL_CHANGED = trace
274 mod.PET_BATTLE_LOOT_RECEIVED = trace
275 mod.PET_BATTLE_MAX_HEALTH_CHANGED = trace
276 mod.PET_BATTLE_PET_CHANGED = trace -- <team>
277 mod.PET_BATTLE_PET_TYPE_CHANGED = trace -- <team> <slot> <type>
278 mod.PET_BATTLE_PET_ROUND_PLAYBACK_COMPLETE = trace -- <round number>
279 mod.PET_BATTLE_PET_ROUND_RESULTS = trace -- <round number>
280 mod.PET_BATTLE_PVP_DUEL_REQUESTED = trace
281 mod.PET_BATTLE_PVP_DUEL_REQUEST_CANCEL = trace
282 mod.PET_BATTLE_QUEUE_PROPOSAL_ACCEPTED = trace
283 mod.PET_BATTLE_QUEUE_PROPOSAL_DECLINED = trace
284 mod.PET_BATTLE_QUEUE_PROPOSE_MATCH = trace
285 mod.PET_BATTLE_QUEUE_STATUS = trace
286 mod.PET_BATTLE_TURN_STARTED = trace
287 mod.PET_BATTLE_XP_CHANGED = trace -- <team> <slot> <exp>
288 --]]