12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 21 ■ Responding to the Combat Log <strong>and</strong> Threat In<strong>for</strong>mation 405Updating Pet MappingsThe strategy you’re going to take with pets is to map the pet GUID to theowner GUID, so multiple pets get collapsed into a single amount <strong>of</strong> damage.Add the following function that will take a unitID <strong>and</strong> update the GUID map<strong>for</strong> that unit’s pets:function CombatStatus:UpdatePets(unit)local petUnitif unit == “player“ thenpetUnit = “pet“elsepetUnit = unit:gsub(“(party)(%d)“, “%1pet%2“)endif petUnit <strong>and</strong> UnitExists(petUnit) thenlocal guid = UnitGUID(unit)local petGUID = UnitGUID(petUnit)self.pet_guids[petGUID] = guid .. “pet“endendTo look up in<strong>for</strong>mation about pets you need to use the unitID <strong>for</strong> the pet,but you’re only given the unitID <strong>for</strong> the owner. For party members these IDsare partypet1, partypet2, partypet3, <strong>and</strong>partypet4. Youcanuseasimplesubstitution using patterns to trans<strong>for</strong>m party1 into partypet1, asshowninthe preceding code.You need to cover the special case <strong>of</strong> the player’s pet, which is just theunitID ‘‘pet.’’ Once you have the correct unitID, you check to see if the unitexists <strong>and</strong> if so you get the GUID. Rather than doing a direct mapping fromthe pet GUID to the owner GUID, you do a mapping from the pet GUID to theowner GUID with the string ‘‘pet’’ added to the end.If you didn’t add this string you would need to store the pet’s damage inanother table (because the damage table is indexed by GUID). Otherwise, youwouldnolongerbeabletodistinguishbetweenthepets<strong>and</strong>theoriginalunititself.Storing Damage <strong>and</strong> Healing In<strong>for</strong>mationYou’re using the COMBAT_LOG_EVENT_UNFILTERED to get in<strong>for</strong>mation about yourparty’s damage <strong>and</strong> healing, so you need a function that extracts the rightin<strong>for</strong>mation from the various possible events. Create the following function inCombatStatus.lua:local damageEvents = {SWING_DAMAGE = true,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!