From f793dbeba5884c00d4c7225d189cb0e2a84b10d6 Mon Sep 17 00:00:00 2001 From: Tercioo Date: Wed, 10 Apr 2019 18:39:19 -0300 Subject: [PATCH] API 2.0 Updates, /details api --- core/windows.lua | 22 +- functions/api2.lua | 1006 +++++++++++++++++++++++++++++--------------- 2 files changed, 679 insertions(+), 349 deletions(-) diff --git a/core/windows.lua b/core/windows.lua index 42e12e2a..b2bcef2e 100644 --- a/core/windows.lua +++ b/core/windows.lua @@ -4832,6 +4832,8 @@ local returnLines = {} local currentSelected = 1 + local api = Details.API_Description.namespaces[1].api + --on select api on the menu local onSelectAPI = function (self) local apiName = apiFunctionNames [self.index] @@ -4841,7 +4843,7 @@ end --fill the box in the right with information about the API - local apiInfo = Details.API_Description [self.index] + local apiInfo = api [self.index] if (not apiInfo) then Details:Msg ("API information for api not found", apiName) return @@ -4870,9 +4872,9 @@ returnValues = returnValues .. " = " if (parameters ~= "") then - Api2Frame.ApiCopy.text = returnValues .. apiName .. "( " .. parameters .. " )" + Api2Frame.ApiCopy.text = returnValues .. "Details." .. apiName .. "( " .. parameters .. " )" else - Api2Frame.ApiCopy.text = returnValues .. apiName .. "()" + Api2Frame.ApiCopy.text = returnValues .. "Details." .. apiName .. "()" end Api2Frame.ApiCopy:SetFocus (true) @@ -4935,7 +4937,7 @@ end end - for apiIndex, apiDesc in ipairs (Details.API_Description) do + for apiIndex, apiDesc in ipairs (api) do tinsert (apiFunctionNames, apiDesc.name) end @@ -4943,7 +4945,7 @@ DetailsFramework:ReskinSlider (api2ScrollMenu) api2ScrollMenu:SetPoint ("topleft", Api2Frame, "topleft", 10, yStart) Api2Frame.scrollMenu = api2ScrollMenu - + local lineOnEnter = function (self) self:SetBackdropColor (unpack (backdropColorOnEnter)) end @@ -4987,6 +4989,10 @@ --api desc Api2Frame.ApiFunctionDesc = DetailsFramework:CreateLabel (Api2Frame) Api2Frame.ApiFunctionDesc:SetPoint ("topleft", Api2Frame.ApiFunctionName, "bottomleft", 0, -2) + Api2Frame.ApiFunctionDesc.width = infoWidth + Api2Frame.ApiFunctionDesc.height = 22 + Api2Frame.ApiFunctionDesc.valign = "top" + --api func to copy local apiCopyString = DetailsFramework:CreateLabel (Api2Frame, "Copy String", 12, "orange") apiCopyString:SetPoint ("topleft", Api2Frame.ApiFunctionDesc, "bottomleft", 0, -20) @@ -4995,13 +5001,13 @@ Api2Frame.ApiCopy:SetTemplate (DetailsFramework:GetTemplate ("button", "DETAILS_CUSTOMDISPLAY_CODE_BOX")) --parameters - local parametersYStart = yStart - 100 + local parametersYStart = yStart - 110 local parametersString = DetailsFramework:CreateLabel (Api2Frame, "Parameters", 12, "orange") parametersString:SetPoint ("topleft", Api2Frame, "topleft", xAnchorPoint, parametersYStart) parametersYStart = parametersYStart - 20 - local space1, space2, space3 = 100, 200, 300 + local space1, space2, space3 = 150, 300, 450 local parametersHeader = CreateFrame ("frame", nil, Api2Frame) parametersHeader:SetSize (infoWidth, 20) parametersHeader:SetPoint ("topleft", Api2Frame, "topleft", xAnchorPoint, parametersYStart) @@ -5021,7 +5027,7 @@ GameCooltip2:SetOwner (self) --fill the box in the right with information about the API - local apiInfo = Details.API_Description [currentSelected] + local apiInfo = api [currentSelected] if (not apiInfo) then return end diff --git a/functions/api2.lua b/functions/api2.lua index 61f772ab..01954ed5 100644 --- a/functions/api2.lua +++ b/functions/api2.lua @@ -41,14 +41,58 @@ local getUnitName = function (unitId) end end +--return the spell object and the spellId +local getSpellObject = function (playerObject, spellId, isLiteral) + local parameterType = type (spellId) + + if (parameterType == "number" and isLiteral) then + --is the id of a spell and literal, directly get the spell object + return playerObject.spells._ActorTable [spellId], spellId + + else + local passedSpellName + if (parameterType == "string") then + --passed a spell name, make the spell be in lower case + passedSpellName = spellId:lower() + + elseif (parameterType == "number") then + --passed a number but with literal off, transform the spellId into a spell name + local spellName = GetSpellInfo (spellid) + if (spellName) then + passedSpellName = spellName:lower() + end + end + + if (passedSpellName) then + for thisSpellId, spellObject in pairs (playerObject.spells._ActorTable) do + local spellName = Details.GetSpellInfo (thisSpellId) + if (spellName) then + if (spellName:lower() == passedSpellName) then + return spellObject, thisSpellId + end + end + end + end + end +end + --api -Details.API_Description = {} +Details.API_Description = { + addon = "Details! Damage Meter", + namespaces = { + { + name = "Details", + order = 1, + api = {}, + } + }, +} --[=[ Details.SegmentElapsedTime (segment) --=]=] -tinsert (Details.API_Description, { +tinsert (Details.API_Description.namespaces[1].api, { name = "SegmentElapsedTime", desc = "Return the total elapsed time of a segment.", parameters = { @@ -80,10 +124,88 @@ function Details.SegmentElapsedTime (segment) return combatObject:GetCombatTime() end +--[=[ + Details.SegmentOffensiveUnits (segment) +--=]=] +tinsert (Details.API_Description.namespaces[1].api, { + name = "SegmentOffensiveUnits", + desc = "Return a numeric (ipairs) table with name of units that inflicted damage on the segment.", + parameters = { + { + name = "includePlayerUnits", + type = "boolean", + default = "true", + desc = "Include names of player units, e.g. name of players in your dungeon or raid group.", + }, + { + name = "includeEnemyUnits", + type = "boolean", + default = "false", + desc = "Include names of enemy units, e.g. name of a boss and their adds.", + }, + { + name = "includeFriendlyPetUnits", + type = "boolean", + default = "false", + desc = "Include names of player pets.", + }, + { + name = "segment", + type = "number", + default = "0", + desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", + }, + }, + returnValues = { + { + name = "unitNames", + type = "table", + desc = "A table with unit names.", + } + }, + type = 1, --damage +}) + +function Details.SegmentOffensiveUnits (includePlayerUnits, includeEnemyUnits, includeFriendlyPetUnits, segment) + segment = segment or 0 + if (type (includePlayerUnits) ~= "boolean") then + includePlayerUnits = true + end + + local combatObject = getCombatObject (segment) + + local units = {} + local nextIndex = 1 + + if (not combatObject) then + return units + end + + local damageContainer = combatObject:GetContainer (DETAILS_ATTRIBUTE_DAMAGE) + for i = 1, #damageContainer._ActorTable do + local playerObject = damageContainer._ActorTable [i] + + if (includePlayerUnits and playerObject.grupo) then + units [nextIndex] = playerObject:GetName() + nextIndex = nextIndex + 1 + + elseif (includeEnemyUnits and playerObject:IsEnemy()) then + units [nextIndex] = playerObject:GetName() + nextIndex = nextIndex + 1 + + elseif (includeFriendlyPetUnits and playerObject:IsPetOrGuardian()) then + units [nextIndex] = playerObject:GetName() + nextIndex = nextIndex + 1 + end + end + + return units +end + --[=[ Details.UnitDamage (unitId, segment) --=]=] -tinsert (Details.API_Description, { +tinsert (Details.API_Description.namespaces[1].api, { name = "UnitDamage", desc = "Query the damage of a unit.", parameters = { @@ -129,305 +251,10 @@ function Details.UnitDamage (unitId, segment) end ---[=[ - Details.UnitSpellDamage (unitId, spellId, segment) ---=]=] -tinsert (Details.API_Description, { - name = "UnitSpellDamage", - desc = "Query the total damage done of a spell casted by the unit.", - parameters = { - { - name = "unitId", - type = "string", - desc = "The ID of an unit, example: 'player', 'target', 'raid5'. Accept unit names.", - required = true, - }, - { - name = "spellId", - type = "number", - desc = "Id of a spell to query the damage done. Accept spell names.", - required = true, - }, - { - name = "segment", - default = "0", - type = "number", - desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", - }, - }, - returnValues = { - { - name = "unitSpellDamage", - type = "number", - desc = "Number representing the spell damage done.", - } - }, - type = 1, --damage -}) - -function Details.UnitSpellDamage (unitId, spellId, segment) - segment = segment or 0 - local combatObject = getCombatObject (segment) - - if (not combatObject) then - return 0 - end - - local unitName = getUnitName (unitId) - - local playerObject = getActorObjectFromCombat (combatObject, 1, unitName) - if (not playerObject) then - return 0 - end - - if (type (spellId) == "string") then - local newSpellId = select (7, GetSpellInfo (spellId)) - if (not newSpellId) then - local passedSpellName = spellId:lower() - for damageSpellId, spellInfo in pairs (playerObject.spells._ActorTable) do - local spellName = GetSpellInfo (damageSpellId) - if (spellName:lower() == passedSpellName) then - spellId = damageSpellId - break - end - end - else - spellId = newSpellId - end - end - - local spell = playerObject.spells._ActorTable [spellId] - return spell and spell.total or 0 -end - - ---[=[ - Details.UnitSpells (unitId, segment) ---=]=] -tinsert (Details.API_Description, { - name = "UnitDamageSpells", - desc = "Return a numeric table with spells IDs used by the unit.", - parameters = { - { - name = "unitId", - type = "string", - desc = "The ID of an unit, example: 'player', 'target', 'raid5'. Accept unit names.", - required = true, - }, - { - name = "segment", - type = "number", - default = "0", - desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", - }, - }, - returnValues = { - { - name = "unitSpellDamage", - type = "number", - desc = "Number representing the spell damage done.", - } - }, - type = 1, --damage -}) - -function Details.UnitDamageSpells (unitId, segment) - segment = segment or 0 - local combatObject = getCombatObject (segment) - - if (not combatObject) then - return {} - end - - local unitName = getUnitName (unitId) - - local playerObject = getActorObjectFromCombat (combatObject, 1, unitName) - if (not playerObject) then - return {} - end - - local unitSpells = playerObject.spells._ActorTable - local resultTable = {} - for spellId, spellObject in pairs (unitSpells) do - resultTable [#resultTable + 1] = spellId - end - - return resultTable -end - - ---[=[ - Details.UnitDamageTaken (unitId, segment) ---=]=] -tinsert (Details.API_Description, { - name = "UnitDamageTaken", - desc = "Query the unit damage taken.", - parameters = { - { - name = "unitId", - type = "string", - desc = "The ID of an unit, example: 'player', 'target', 'raid5'. Accept unit names.", - required = true, - }, - { - name = "segment", - type = "number", - default = "0", - desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", - }, - }, - returnValues = { - { - name = "unitDamageTaken", - type = "number", - desc = "Number representing the damage taken by the unit.", - } - }, - type = 1, --damage -}) - -function Details.UnitDamageTaken (unitId, segment) - segment = segment or 0 - local combatObject = getCombatObject (segment) - - if (not combatObject) then - return 0 - end - - local unitName = getUnitName (unitId) - - local playerObject = getActorObjectFromCombat (combatObject, 1, unitName) - if (not playerObject) then - return 0 - end - - return playerObject.damage_taken -end - ---[=[ - Details.UnitDamageOnUnit (unitId, targetUnitId, segment) ---=]=] -tinsert (Details.API_Description, { - name = "UnitDamageOnUnit", - desc = "Query the unit damage done on another unit.", - parameters = { - { - name = "unitId", - type = "string", - desc = "The ID of an unit, example: 'player', 'target', 'raid5'. Accept unit names.", - required = true, - }, - { - name = "targetUnitId", - type = "string", - desc = "Name or ID of an unit, example: 'Thrall', 'Jaina', 'player', 'target', 'raid5'.", - required = true, - }, - { - name = "segment", - type = "number", - default = "0", - desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", - }, - }, - returnValues = { - { - name = "unitDamageOnUnit", - type = "number", - desc = "Number representing the damage done by the unit on the target unit.", - } - }, - type = 1, --damage -}) - -function Details.UnitDamageOnUnit (unitId, targetUnitId, segment) - segment = segment or 0 - local combatObject = getCombatObject (segment) - - if (not combatObject) then - return 0 - end - - local unitName = getUnitName (unitId) - - local playerObject = getActorObjectFromCombat (combatObject, 1, unitName) - if (not playerObject) then - return 0 - end - - local targetName = getUnitName (targetUnitId) - return playerObject.targets [targetName] or 0 -end - ---[=[ - Details.UnitDamageTakenFromSpell (unitId, spellId, segment) ---=]=] -tinsert (Details.API_Description, { - name = "UnitDamageTakenFromSpell", - desc = "Query the unit damage taken from a spell.", - parameters = { - { - name = "unitId", - type = "string", - desc = "The ID of an unit, example: 'player', 'target', 'raid5'. Accept unit names.", - required = true, - }, - { - name = "spellId", - type = "number", - desc = "Id of a spell to query its damage to an unit. Accept spell names.", - required = true, - }, - { - name = "segment", - type = "number", - default = "0", - desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", - }, - }, - returnValues = { - { - name = "unitDamageTakenFromSpell", - type = "number", - desc = "Number representing the damage taken by the unit from a spell.", - } - }, - type = 1, --damage -}) - -function Details.UnitDamageTakenFromSpell (unitId, spellId, segment) - segment = segment or 0 - local combatObject = getCombatObject (segment) - - if (not combatObject) then - return 0 - end - - local unitName = getUnitName (unitId) - local damageContainer = combatObject:GetContainer (DETAILS_ATTRIBUTE_DAMAGE) - - local totalDamageTaken = 0 - local spellName = GetSpellInfo (spellId) or spellId - - for i = 1, #damageContainer._ActorTable do - local playerObject = damageContainer._ActorTable [i] - local unitSpells = playerObject.spells._ActorTable - - for spellId, spellObject in pairs (unitSpells) do - local thisSpellName = GetSpellInfo (spellId) - if (thisSpellName == spellName) then - totalDamageTaken = totalDamageTaken + (spellObject.targets [unitName] or 0) - end - end - end - - return totalDamageTaken -end - --[=[ Details.UnitDamageInfo (unitId, segment) --=]=] -tinsert (Details.API_Description, { +tinsert (Details.API_Description.namespaces[1].api, { name = "UnitDamageInfo", desc = "Return a table with damage information.", parameters = { @@ -489,10 +316,82 @@ function Details.UnitDamageInfo (unitId, segment) end + + --[=[ - Details.UnitSpellInfo (unitId, spellId, segment) + Details.UnitDamageBySpell (unitId, spellId, segment) --=]=] -tinsert (Details.API_Description, { +tinsert (Details.API_Description.namespaces[1].api, { + name = "UnitDamageBySpell", + desc = "Query the total damage done of a spell casted by the unit.", + parameters = { + { + name = "unitId", + type = "string", + desc = "The ID of an unit, example: 'player', 'target', 'raid5'. Accept unit names.", + required = true, + }, + { + name = "spellId", + type = "number", + desc = "Id of a spell to query the damage done. Accept spell names.", + required = true, + }, + { + name = "isLiteral", + type = "boolean", + default = "true", + desc = "Search for the spell without transforming the spellId into a spell name before the search.", + }, + { + name = "segment", + default = "0", + type = "number", + desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", + }, + }, + returnValues = { + { + name = "unitSpellDamage", + type = "number", + desc = "Number representing the spell damage done.", + } + }, + type = 1, --damage +}) + +function Details.UnitDamageBySpell (unitId, spellId, isLiteral, segment) + if (type (isLiteral) ~= "boolean") then + isLiteral = true + end + segment = segment or 0 + local combatObject = getCombatObject (segment) + + if (not combatObject) then + return 0 + end + + local unitName = getUnitName (unitId) + + local playerObject = getActorObjectFromCombat (combatObject, 1, unitName) + if (not playerObject) then + return 0 + end + + local spellObject, spellId = getSpellObject (playerObject, spellId, isLiteral) + print (spellObject, spellId, isLiteral) + if (spellObject) then + return spellObject.total + else + return 0 + end +end + + +--[=[ + Details.UnitDamageSpellInfo (unitId, spellId, segment) +--=]=] +tinsert (Details.API_Description.namespaces[1].api, { name = "UnitDamageSpellInfo", desc = "Return a table with the spell damage information.", parameters = { @@ -508,6 +407,12 @@ tinsert (Details.API_Description, { desc = "Id of a spell to query its damage to an unit. Accept spell names.", required = true, }, + { + name = "isLiteral", + type = "boolean", + default = "true", + desc = "Search for the spell without transforming the spellId into a spell name before the search.", + }, { name = "segment", type = "number", @@ -525,8 +430,12 @@ tinsert (Details.API_Description, { type = 1, --damage }) -function Details.UnitDamageSpellInfo (unitId, spellId, segment) +function Details.UnitDamageSpellInfo (unitId, spellId, isLiteral, segment) + if (type (isLiteral) ~= "boolean") then + isLiteral = true + end segment = segment or 0 + local combatObject = getCombatObject (segment) if (not combatObject) then @@ -556,48 +465,463 @@ function Details.UnitDamageSpellInfo (unitId, spellId, segment) return spellInfo end - local miscPlayerObject = getActorObjectFromCombat (combatObject, 4, unitName) - - local spellName = GetSpellInfo (spellId) or spellId - local spellObject - - for thisSpellId, thisSpellObject in pairs (playerObject.spells._ActorTable) do - local thisSpellName = GetSpellInfo (thisSpellId) - if (thisSpellName == spellName) then - spellObject = thisSpellObject - spellId = thisSpellId - - if (miscPlayerObject) then - local castedAmount = miscPlayerObject.spell_cast and miscPlayerObject.spell_cast [spellId] - if (castedAmount) then - spellInfo.casted = castedAmount - else - for castedSpellId, castedAmount in pairs (miscPlayerObject.spell_cast) do - local castedSpellName = GetSpellInfo (castedSpellId) - if (castedSpellName == spellName) then - spellInfo.casted = castedAmount - end - end - end - end - break - end + local spellObject, spellId = getSpellObject (playerObject, spellId, isLiteral) + if (not spellObject) then + return spellInfo end - spellInfo.total = spellObject.total - spellInfo.count = spellObject.counter - spellInfo.spellId = spellId - spellInfo.name = spellName - spellInfo.regularMin = spellObject.n_min - spellInfo.regularMax = spellObject.n_max - spellInfo.regularAmount = spellObject.n_amt - spellInfo.regularDamage = spellObject.n_dmg - spellInfo.criticalMin = spellObject.c_min - spellInfo.criticalMax = spellObject.c_max - spellInfo.criticalAmount = spellObject.c_amt - spellInfo.criticalDamage = spellObject.c_dmg - + local miscPlayerObject = getActorObjectFromCombat (combatObject, 4, unitName) + if (miscPlayerObject) then + local spellName = GetSpellInfo (spellId) + local castedAmount = miscPlayerObject.spell_cast and miscPlayerObject.spell_cast [spellId] + + if (castedAmount) then + spellInfo.casted = castedAmount + else + for castedSpellId, castedAmount in pairs (miscPlayerObject.spell_cast) do + local castedSpellName = GetSpellInfo (castedSpellId) + if (castedSpellName == spellName) then + spellInfo.casted = castedAmount + break + end + end + end + end + + if (spellObject) then + spellInfo.total = spellObject.total + spellInfo.count = spellObject.counter + spellInfo.spellId = spellId + spellInfo.name = spellName + spellInfo.regularMin = spellObject.n_min + spellInfo.regularMax = spellObject.n_max + spellInfo.regularAmount = spellObject.n_amt + spellInfo.regularDamage = spellObject.n_dmg + spellInfo.criticalMin = spellObject.c_min + spellInfo.criticalMax = spellObject.c_max + spellInfo.criticalAmount = spellObject.c_amt + spellInfo.criticalDamage = spellObject.c_dmg + end + return spellInfo end +--[=[ + Details.UnitDamageSpellOnUnit (unitId, spellId, segment) +--=]=] +tinsert (Details.API_Description.namespaces[1].api, { + name = "UnitDamageSpellOnUnit", + desc = "Query the damage done of a spell into a specific target.", + parameters = { + { + name = "unitId", + type = "string", + desc = "The ID of an unit, example: 'player', 'target', 'raid5'. Accept unit names.", + required = true, + }, + { + name = "spellId", + type = "number", + desc = "Id of a spell to query its damage to an unit. Accept spell names.", + required = true, + }, + { + name = "targetUnitId", + type = "string", + desc = "Name or ID of an unit, example: 'Thrall', 'Jaina', 'player', 'target', 'raid5'.", + required = true, + }, + { + name = "isLiteral", + type = "boolean", + default = "true", + desc = "Search for the spell without transforming the spellId into a spell name before the search.", + }, + { + name = "segment", + type = "number", + default = "0", + desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", + }, + }, + returnValues = { + { + name = "unitDamageSpellOnUnit", + type = "number", + desc = "Damage done by the spell into the target.", + } + }, + type = 1, --damage +}) + +function Details.UnitDamageSpellOnUnit (unitId, spellId, targetUnitId, isLiteral, segment) + if (type (isLiteral) ~= "boolean") then + isLiteral = true + end + segment = segment or 0 + + local combatObject = getCombatObject (segment) + + if (not combatObject) then + return 0 + end + + local unitName = getUnitName (unitId) + local playerObject = getActorObjectFromCombat (combatObject, 1, unitName) + if (not playerObject) then + return 0 + end + + local spellObject, spellId = getSpellObject (playerObject, spellId, isLiteral) + if (spellObject) then + local targetName = getUnitName (targetUnitId) + return spellObject.targets [targetName] or 0 + else + return 0 + end +end + +--[=[ + Details.UnitDamageTaken (unitId, segment) +--=]=] +tinsert (Details.API_Description.namespaces[1].api, { + name = "UnitDamageTaken", + desc = "Query the unit damage taken.", + parameters = { + { + name = "unitId", + type = "string", + desc = "The ID of an unit, example: 'player', 'target', 'raid5'. Accept unit names.", + required = true, + }, + { + name = "segment", + type = "number", + default = "0", + desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", + }, + }, + returnValues = { + { + name = "unitDamageTaken", + type = "number", + desc = "Number representing the damage taken by the unit.", + } + }, + type = 1, --damage +}) + +function Details.UnitDamageTaken (unitId, segment) + segment = segment or 0 + local combatObject = getCombatObject (segment) + + if (not combatObject) then + return 0 + end + + local unitName = getUnitName (unitId) + + local playerObject = getActorObjectFromCombat (combatObject, 1, unitName) + if (not playerObject) then + return 0 + end + + return playerObject.damage_taken +end + +--[=[ + Details.UnitDamageOnUnit (unitId, targetUnitId, segment) +--=]=] +tinsert (Details.API_Description.namespaces[1].api, { + name = "UnitDamageOnUnit", + desc = "Query the unit damage done on another unit.", + parameters = { + { + name = "unitId", + type = "string", + desc = "The ID of an unit, example: 'player', 'target', 'raid5'. Accept unit names.", + required = true, + }, + { + name = "targetUnitId", + type = "string", + desc = "Name or ID of an unit, example: 'Thrall', 'Jaina', 'player', 'target', 'raid5'.", + required = true, + }, + { + name = "segment", + type = "number", + default = "0", + desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", + }, + }, + returnValues = { + { + name = "unitDamageOnUnit", + type = "number", + desc = "Number representing the damage done by the unit on the target unit.", + } + }, + type = 1, --damage +}) + +function Details.UnitDamageOnUnit (unitId, targetUnitId, segment) + segment = segment or 0 + local combatObject = getCombatObject (segment) + + if (not combatObject) then + return 0 + end + + local unitName = getUnitName (unitId) + + local playerObject = getActorObjectFromCombat (combatObject, 1, unitName) + if (not playerObject) then + return 0 + end + + local targetName = getUnitName (targetUnitId) + return playerObject.targets [targetName] or 0 +end + +--[=[ + Details.UnitDamageTakenFromSpell (unitId, spellId, segment) +--=]=] +tinsert (Details.API_Description.namespaces[1].api, { + name = "UnitDamageTakenFromSpell", + desc = "Query the unit damage taken from a spell.", + parameters = { + { + name = "unitId", + type = "string", + desc = "The ID of an unit, example: 'player', 'target', 'raid5'. Accept unit names.", + required = true, + }, + { + name = "spellId", + type = "number", + desc = "Id of a spell to query its damage to an unit. Accept spell names.", + required = true, + }, + { + name = "segment", + type = "number", + default = "0", + desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", + }, + }, + returnValues = { + { + name = "unitDamageTakenFromSpell", + type = "number", + desc = "Number representing the damage taken by the unit from a spell.", + } + }, + type = 1, --damage +}) + +function Details.UnitDamageTakenFromSpell (unitId, spellId, isLiteral, segment) + segment = segment or 0 + if (type (isLiteral) ~= "boolean") then + isLiteral = true + end + + local combatObject = getCombatObject (segment) + + if (not combatObject) then + return 0 + end + + local unitName = getUnitName (unitId) + local damageContainer = combatObject:GetContainer (DETAILS_ATTRIBUTE_DAMAGE) + + local totalDamageTaken = 0 + if (isLiteral and type (spellId) == "number") then + for i = 1, #damageContainer._ActorTable do + for thisSpellId, spellObject in pairs (damageContainer._ActorTable [i].spells._ActorTable) do + if (thisSpellId == spellId) then + totalDamageTaken = totalDamageTaken + (spellObject.targets [unitName] or 0) + end + end + end + else + local spellName = GetSpellInfo (spellId) or spellId + for i = 1, #damageContainer._ActorTable do + for thisSpellId, spellObject in pairs (damageContainer._ActorTable [i].spells._ActorTable) do + local thisSpellName = GetSpellInfo (thisSpellId) + if (thisSpellName == spellName) then + totalDamageTaken = totalDamageTaken + (spellObject.targets [unitName] or 0) + end + end + end + end + + return totalDamageTaken +end + + +--[=[ + Details.UnitOffensiveSpells (unitId, segment) +--=]=] +tinsert (Details.API_Description.namespaces[1].api, { + name = "UnitOffensiveSpells", + desc = "Return a numeric (ipairs) table with spells IDs used by the unit.", + parameters = { + { + name = "unitId", + type = "string", + desc = "The ID of an unit, example: 'player', 'target', 'raid5'. Accept unit names.", + required = true, + }, + { + name = "segment", + type = "number", + default = "0", + desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", + }, + }, + returnValues = { + { + name = "unitSpellDamage", + type = "number", + desc = "Number representing the spell damage done.", + } + }, + type = 1, --damage +}) + +function Details.UnitOffensiveSpells (unitId, segment) + segment = segment or 0 + local combatObject = getCombatObject (segment) + + if (not combatObject) then + return {} + end + + local unitName = getUnitName (unitId) + + local playerObject = getActorObjectFromCombat (combatObject, 1, unitName) + if (not playerObject) then + return {} + end + + local unitSpells = playerObject.spells._ActorTable + local resultTable = {} + for spellId, spellObject in pairs (unitSpells) do + resultTable [#resultTable + 1] = spellId + end + + return resultTable +end + +--[=[ + Details.UnitOffensiveTargets (unitId, segment) +--=]=] +tinsert (Details.API_Description.namespaces[1].api, { + name = "UnitOffensiveTargets", + desc = "Return a numeric (ipairs) table with names of targets the unit inflicted damage. You may query the amount of damage with Details.UnitDamageOnUnit( unitId, targetName ).", + parameters = { + { + name = "unitId", + type = "string", + desc = "The ID of an unit, example: 'player', 'target', 'raid5'. Accept unit names.", + required = true, + }, + { + name = "segment", + type = "number", + default = "0", + desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", + }, + }, + returnValues = { + { + name = "offensiveTargetNames", + type = "table", + desc = "Table containing names of all offensive targets of the unit.", + } + }, + type = 1, --damage +}) + +function Details.UnitOffensiveTargets (unitId, segment) + segment = segment or 0 + local combatObject = getCombatObject (segment) + + if (not combatObject) then + return 0 + end + + local unitName = getUnitName (unitId) + local offensiveTargetNames = {} + + local playerObject = getActorObjectFromCombat (combatObject, 1, unitName) + if (not playerObject) then + return offensiveTargetNames + end + + for targetName, _ in pairs (playerObject.targets) do + offensiveTargetNames [#offensiveTargetNames + 1] = targetName + end + + return offensiveTargetNames +end + + +--[=[ + Details.UnitOffensivePets (unitId, segment) +--=]=] +tinsert (Details.API_Description.namespaces[1].api, { + name = "UnitOffensivePets", + desc = "Return a numeric (ipairs) table with all pet names the unit has. Individual pet information can be queried with Details.UnitDamage( petName ).", + parameters = { + { + name = "unitId", + type = "string", + desc = "The ID of an unit, example: 'player', 'target', 'raid5'. Accept unit names.", + required = true, + }, + { + name = "segment", + type = "number", + default = "0", + desc = "Which segment to retrive data, default value is zero (current segment). Use -1 for overall data or value from 1 to 25 for other segments.", + }, + }, + returnValues = { + { + name = "petNames", + type = "table", + desc = "Table containing names of all pets the unit has.", + } + }, + type = 1, --damage +}) + +function Details.UnitOffensivePets (unitId, segment) + segment = segment or 0 + local combatObject = getCombatObject (segment) + + if (not combatObject) then + return 0 + end + + local unitName = getUnitName (unitId) + local petNames = {} + + local playerObject = getActorObjectFromCombat (combatObject, 1, unitName) + if (not playerObject) then + return petNames + end + + for i = 1, #playerObject.pets do + petNames [#petNames + 1] = playerObject.pets [i] + end + + return petNames +end + + + + --stop auto complete: doo ende endp elsez \ No newline at end of file