Mercurial > wow > turok
view Turok/Modules/Utilities/PetBattle.lua @ 9:9400a0ff8540
Ugh
Timer:
- container update directionality
- talent update iterates over a non-volatile table to carry out updates
- index management steps organized
- talentRow status implemented, returns the spell associated with the talent chosen from that row
CombatLog:
- sort out font controls and unbork arguments
author | Nenue |
---|---|
date | Sun, 21 Feb 2016 13:08:30 -0500 |
parents | a9b8b0866ece |
children |
line wrap: on
line source
--- ${PACKAGE_NAME} -- @file-author@ -- @project-revision@ @project-hash@ -- @file-revision@ @file-hash@ -- Created: 1/17/2016 6:51 PM local ADDON, Turok = ... local T, _G, pairs, pairs = Turok.Addon, _G, pairs, ipairs local mod = T:NewModule("PetBattle") local print = function(...) if not DEBUG then return end if _G.Devian and _G.DevianDB.workspace ~= 1 then _G.print('Petz', ...) end end local trace = function(self, e, ...) print(e, ...) end local PBS local turn_font = [[Interface\Addons\Turok\Media\font\ArchivoNarrow-Bold.ttf]] local turn_size = 24 local turn_outline = 'OUTLINE' local icon_size = 64 local spacing = 5 local padding = 0 local strongweak_size = 20 local cpb = C_PetBattles T.defaults.petbattle = { swatch = { anchor = 'BOTTOM', anchorTo = 'BOTTOM', parent = 'UIParent', x = 0, y =240, width = 200, height = 100, font = [[Interface\Addons\Turok\Media\font\ArchivoNarrow-Bold.ttf]], size = 16, }, spell = { anchor = 'TOPLEFT', anchorTo = 'TOPLEFT', size = 24, width = 72, height = 72, x = 0, y =0, padding = 0, spacing = 0, }, sideSwatch = { width = 100, height = 50, padding = 0, spacing = 5, anchor = 'TOPLEFT', anchorTo = 'BOTTOMLEFT', x = 0, y = 0, parent = 'TkPetSwatch', }, sideSpell = { anchor = 'TOPLEFT', anchorTo = 'TOPLEFT', size = 16, width = 36, height = 36, padding = 0, spacing = 0, }, icon = { size = 72, width = 64, height = 64, } } mod.abilityButtons = {} mod.switcherButtons = {} mod.icons = {} mod.strongweak = {} mod.turns = {} mod.petlist = {} local PLAYER, ENEMY = 1, 2 local function PBS_UpdateEnemySwatch(self) print('UpdateSwatch') local db = TurokData.petbattle.swatch local playerActivePet = cpb.GetActivePet(PLAYER) local enemyActivePet = cpb.GetActivePet(ENEMY) local enemyNumPets = cpb.GetNumPets(ENEMY) local playerPetType = cpb.GetPetType(PLAYER, playerActivePet) local enemyPetType = cpb.GetPetType(ENEMY, enemyActivePet) local enemyPetName = cpb.GetName(ENEMY, playerActivePet) for petSlot=1, 3 do local swatchFrame = (petSlot == enemyActivePet) and self or ((petSlot < enemyNumPets) and self.sideSwatch or self.sideSwatch2) local db = (swatchFrame == self) and db.spell or db.sideSpell local type = cpb.GetPetType(ENEMY, petSlot) print(cText(' PetType='), enemyActivePet) print(cText(' current='), enemyPetType) for spellSlot=1, 3 do print(' ', cText('PetSlotOffset='), cNum(petSlot), cText('AbilitySlotOffset'), cNum(spellSlot)) local id, name, texture, cooldown, desc, numTurns, attackType, noStrongWeakHints = cpb.GetAbilityInfo(ENEMY, petSlot, spellSlot) local usable, remaining = cpb.GetAbilityState(ENEMY, petSlot, spellSlot) --print('info', cpb.GetAbilityInfo(ENEMY, petSlot, spellSlot)) -- print('effect', cpb.GetAbilityEffectInfo(id, turnIdx, effectIdx, paramName) --print('state', cpb.GetAbilityState(ENEMY,petSlot,spellSlot)) --print('statemod', cpb.GetAbilityStateModification(ENEMY,petSlot,spellSlot)) --print('proc', cpb.GetAbilityProcTurnIndex(ENEMY,petSlot,spellSlot)) --print('statemod', cpb.GetAbilityState(ENEMY,petSlot,spellSlot)) local AbilityButton, icon, strong, turns -- Icon, Strength/Weakness, Turns cooldown if not swatchFrame.buttons[spellSlot] then swatchFrame.buttons[spellSlot] = CreateFrame('Frame', 'TkPetSpell'..spellSlot, swatchFrame, 'TkPetSpellTemplate') AbilityButton = swatchFrame.buttons[spellSlot] AbilityButton:SetSize(db.width, db.height) AbilityButton:SetPoint(db.anchor, swatchFrame, db.anchor, (spellSlot-1)*(db.width+ db.spacing), 0) AbilityButton.icon:SetSize(db.width, db.height) AbilityButton.icon:SetTexCoord(0.1, 0.9, 0.1, 0.9) AbilityButton.strongWeakHint:SetSize(strongweak_size, strongweak_size) AbilityButton.strongWeakHint:SetPoint('CENTER', swatchFrame.buttons[spellSlot], 'CENTER', 0, 0) AbilityButton.turnsLeft:SetFont(turn_font, turn_size, turn_outline) AbilityButton.turnsLeft:SetPoint('CENTER', icon, 'CENTER') else AbilityButton = swatchFrame.buttons[spellSlot] end local icon, strong , turns = AbilityButton.icon, AbilityButton.strongWeakHint, AbilityButton.turnsLeft print('Working on:', swatchFrame, AbilityButton) print('AbilityState('..petSlot..', '..spellSlot..')', 'usable=', usable, 'turnsLeft=', remaining) print(cWord(name), cKey(attackType)) if petSlot > enemyNumPets then -- this will also eval true when pet battle over since numPets will be 0 AbilityButton.popOut:Play() else local abilityChanged if id ~= AbilityButton.spellID then abilityChanged = true AbilityButton.spellID = id AbilityButton.spellName = name AbilityButton.spellDesc = desc AbilityButton.spellType = attackType AbilityButton.spellMaxCooldown = cooldown AbilityButton.spellDesc = desc AbilityButton.spellCooldown = remaining AbilityButton.spellNumTurns = numTurns end if AbilityButton.petType ~= enemyPetType then AbilityButton.petType = enemyPetType AbilityButton.noStrongWeakHints = noStrongWeakHints end if not usable then icon:SetDesaturated(true) icon:SetVertexColor(0.5, 0.5, 0.5, 1) else icon:SetDesaturated(false) icon:SetVertexColor(1, 1, 1, 1) end icon:SetTexture(texture) turns:SetText((cooldown > 0) and cooldown or nil) --AbilityButton.damage:SetText() print('noStrongWeakHints', noStrongWeakHints) print('abilityModification', cpb.GetAttackModifier(enemyPetType, playerPetType)) local modifier = cpb.GetAttackModifier(enemyPetType, playerPetType) if not noStrongWeakHints then if modifier < 1 then strong:SetTexture(0,1,0,0.5) else strong:SetTexture(1,0,0,0.5) end strong:Show() else strong:Hide() end if numTurns then print('numTurns=',numTurns) end if not AbilityButton:IsVisible() or abilityChanged then AbilityButton:Show() AbilityButton.popIn:Play() end end end swatchFrame:SetSize(db.width*3+db.spacing*2+db.padding*2, db.height+padding*2) swatchFrame.petName = enemyPetName swatchFrame.petType = enemyPetType local db = (swatchFrame == self) and db.swatch or db.sideSwatch swatchFrame:Show() end end local function PBS_Switch () print('Switch button was clicked.') end mod.PLAYER_ENTERING_WORLD = function(self, e) print(cpb.IsInBattle()) if cpb.IsInBattle() then PBS_UpdateEnemySwatch(PBS, e, 2) end if _G.PetBattleFrame.BottomFrame.SwitchPetButton then print("There's a pet battle frame button ") --_G.PetBattleFrame.BottomFrame.SwitchPetButton:SetScript('OnClick', PBS_Switch) end end local PBS_Hide = function() for i = 1, 3 do if PBS.buttons[i] then PBS.buttons[i].popOut:Play() end if PBS.sideSwatch.buttons[i] then PBS.sideSwatch.buttons[i].popOut:Play() end if PBS.sideSwatch2.buttons[i] then PBS.sideSwatch2.buttons[i].popOut:Play() end end end local PBS_Event = function(self, e, ...) print('event', e) local owner = ... if e == 'PET_BATTLE_PET_ROUND_PLAYBACK_COMPLETE' or e == 'PET_BATTLE_OPENING_DONE' then PBS_UpdateEnemySwatch(PBS) elseif e == 'PET_BATTLE_CLOSE' then PBS_Hide(PBS) end end function mod:OnEnable() PBS = CreateFrame('Frame', 'TkPetSwatch', UIParent, 'TkPetSwatchTemplate') PBS.buttons = {} PBS.sideSwatch = CreateFrame('Frame', 'TkSideSwatch', PBS, 'TkPetSwatchTemplate') PBS.sideSwatch.buttons = {} PBS.sideSwatch2 = CreateFrame('Frame', 'TkSideSwatch', PBS, 'TkPetSwatchTemplate') PBS.sideSwatch2.buttons = {} local db = TurokData.petbattle T.SetFrameLayout(PBS, db.swatch) T.SetFrameLayout(PBS.sideSwatch, db.sideSwatch) T.SetFrameLayout(PBS.sideSwatch2, db.sideSwatch) PBS.sideSwatch2:ClearAllPoints() PBS.sideSwatch2:SetPoint('LEFT', PBS.sideSwatch, 'RIGHT', db.sideSpell.spacing, 0) mod.effectIndex = { cpb.GetAllEffectNames() } PBS:SetScript('OnEvent', PBS_Event) PBS:RegisterEvent('PET_BATTLE_OPENING_DONE') PBS:RegisterEvent('PET_BATTLE_PET_CHANGED') PBS:RegisterEvent('PET_BATTLE_OVER') PBS:RegisterEvent('PET_BATTLE_CLOSE') PBS:RegisterEvent('PET_BATTLE_ABILITY_CHANGED') PBS:RegisterEvent('PET_BATTLE_ACTION_SELECTED') --PBS:RegisterEvent('PET_BATTLE_AURA_APPLIED') --PBS:RegisterEvent('PET_BATTLE_AURA_CANCELED') --PBS:RegisterEvent('PET_BATTLE_PET_TYPE_CHANGED') PBS:RegisterEvent('PET_BATTLE_TURN_STARTED') --PBS:RegisterEvent('PET_BATTLE_HEALTH_CHANGED') --PBS:RegisterEvent('PET_BATTLE_MAX_HEALTH_CHANGED') PBS:RegisterEvent('PET_BATTLE_PET_ROUND_RESULTS') PBS:RegisterEvent('PET_BATTLE_PET_ROUND_PLAYBACK_COMPLETE') end --[[ mod.PET_BATTLE_OPENING_DONE = trace mod.PET_BATTLE_OPENING_START = trace mod.PET_BATTLE_OVER = trace mod.PET_BATTLE_ABILITY_CHANGED = trace mod.PET_BATTLE_ACTION_SELECTED = trace mod.PET_BATTLE_AURA_APPLIED = trace -- <team> <slot> <id> mod.PET_BATTLE_AURA_CANCELED = trace -- <team> <slot> <id> mod.PET_BATTLE_AURA_CHANGED = trace -- <team> <slot> <id> mod.PET_BATTLE_CAPTURED = trace mod.PET_BATTLE_CLOSE = trace mod.PET_BATTLE_FINAL_ROUND = trace -- <team> mod.PET_BATTLE_HEALTH_CHANGED = trace -- <team> <pet slot> <delta> mod.PET_BATTLE_LEVEL_CHANGED = trace mod.PET_BATTLE_LOOT_RECEIVED = trace mod.PET_BATTLE_MAX_HEALTH_CHANGED = trace mod.PET_BATTLE_PET_CHANGED = trace -- <team> mod.PET_BATTLE_PET_TYPE_CHANGED = trace -- <team> <slot> <type> mod.PET_BATTLE_PET_ROUND_PLAYBACK_COMPLETE = trace -- <round number> mod.PET_BATTLE_PET_ROUND_RESULTS = trace -- <round number> mod.PET_BATTLE_PVP_DUEL_REQUESTED = trace mod.PET_BATTLE_PVP_DUEL_REQUEST_CANCEL = trace mod.PET_BATTLE_QUEUE_PROPOSAL_ACCEPTED = trace mod.PET_BATTLE_QUEUE_PROPOSAL_DECLINED = trace mod.PET_BATTLE_QUEUE_PROPOSE_MATCH = trace mod.PET_BATTLE_QUEUE_STATUS = trace mod.PET_BATTLE_TURN_STARTED = trace mod.PET_BATTLE_XP_CHANGED = trace -- <team> <slot> <exp> --]]