Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
#63 Track pets damage and show it on the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
onechiporenko committed Nov 4, 2020
1 parent 3500702 commit 25f6127
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### v1.4.0

* [#63](https://github.com/onechiporenko/my-dungeons-book/issues/63) Track pets damage and show it on the UI
* [#69](https://github.com/onechiporenko/my-dungeons-book/issues/69) Add toggle to show counts for all casts
* [#68](https://github.com/onechiporenko/my-dungeons-book/issues/68) Don't save "0" for party member spec
* [#67](https://github.com/onechiporenko/my-dungeons-book/issues/67) "infM" is shown when there are no crits
Expand Down
5 changes: 5 additions & 0 deletions Events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ function MyDungeonsBook:CHALLENGE_MODE_START()
self.db.char.challenges[id].players.player = self:ParseUnitInfoWithWowApi("player");
for _, unitId in pairs(self:GetPartyRoster()) do
self:UpdateUnitInfo(UnitGUID(unitId));
local petUnitId = unitId .. "pet";
if (UnitExists(petUnitId)) then
self:TrackSummonnedByPartyMembersUnit(UnitName(unitId), UnitGUID(unitId), UnitName(petUnitId), UnitGUID(petUnitId));
self:DebugPrint(string.format("%s is saved is pet for %s", UnitName(petUnitId) or petUnitId, UnitName(unitId) or unitId));
end
end
NotifyInspect("player");
for i = 1, 4 do
Expand Down
55 changes: 28 additions & 27 deletions Mechanics/Common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ function MyDungeonsBook:TrackAllDamageDoneToPartyMembers(unit, spellId, amount)
end

--[[--
Track all damage done by party members (including pets)
Track all damage done by party members (including pets and other summonned units)
@param[type=string] sourceUnitName
@param[type=GUID] sourceUnitGUID
Expand All @@ -330,19 +330,20 @@ Track all damage done by party members (including pets)
function MyDungeonsBook:TrackAllDamageDoneByPartyMembers(sourceUnitName, sourceUnitGUID, spellId, amount, overkill, crit)
local id = self.db.char.activeChallengeId;
local type = strsplit("-", sourceUnitGUID);
if ((type ~= "Pet") and (type ~= "Player")) then
self:InitMechanics1Lvl("PARTY-MEMBERS-SUMMON");
local summonedUnitOwner = self.db.char.challenges[id].mechanics["PARTY-MEMBERS-SUMMON"][sourceUnitGUID];
local sourceUnitNameToUse = sourceUnitName;
if ((not summonedUnitOwner) and (type ~= "Pet") and (type ~= "Player")) then
return;
end
if (type == "Pet") then
local petOwnerId = getPetOwnerWithTooltip(sourceUnitGUID);
if (petOwnerId) then
sourceUnitName = string.format("%s (%s)", sourceUnitName, UnitName(petOwnerId));
end
end
local key = "ALL-DAMAGE-DONE-BY-PARTY-MEMBERS";
self:InitMechanics3Lvl(key, sourceUnitName, spellId);
if (not self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].hits) then
self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId] = {
self:InitMechanics4Lvl(key, sourceUnitName, "spells", spellId);
if (summonedUnitOwner) then
self:InitMechanics3Lvl(key, sourceUnitName, "meta");
self.db.char.challenges[id].mechanics[key][sourceUnitName].meta.unitName = summonedUnitOwner; -- save original unit name
end
if (not self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].hits) then
self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId] = {
hits = 0,
amount = 0,
overkill = 0,
Expand All @@ -353,34 +354,34 @@ function MyDungeonsBook:TrackAllDamageDoneByPartyMembers(sourceUnitName, sourceU
hitsNotCrit = 0,
maxNotCrit = 0,
minNotCrit = math.huge,
amountNotCrit = 0,
amountNotCrit = 0
};
end
local realAmount = amount or 0;
local realOverkill = 0;
if (overkill and overkill > 0) then
realOverkill = overkill;
end
self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].hits = self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].hits + 1;
self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].amount = self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].amount + realAmount;
self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].overkill = self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].overkill + realOverkill;
self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].hits = self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].hits + 1;
self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].amount = self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].amount + realAmount;
self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].overkill = self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].overkill + realOverkill;
if (crit) then
self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].hitsCrit = self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].hitsCrit + 1;
self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].amountCrit = self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].amountCrit + realAmount;
if (realAmount > self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].maxCrit) then
self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].maxCrit = realAmount;
self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].hitsCrit = self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].hitsCrit + 1;
self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].amountCrit = self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].amountCrit + realAmount;
if (realAmount > self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].maxCrit) then
self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].maxCrit = realAmount;
end
if (realAmount < self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].minCrit) then
self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].minCrit = realAmount;
if (realAmount < self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].minCrit) then
self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].minCrit = realAmount;
end
else
self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].hitsNotCrit = self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].hitsNotCrit + 1;
self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].amountNotCrit = self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].amountNotCrit + realAmount;
if (realAmount > self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].maxNotCrit) then
self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].maxNotCrit = realAmount;
self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].hitsNotCrit = self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].hitsNotCrit + 1;
self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].amountNotCrit = self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].amountNotCrit + realAmount;
if (realAmount > self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].maxNotCrit) then
self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].maxNotCrit = realAmount;
end
if (realAmount < self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].minNotCrit) then
self.db.char.challenges[id].mechanics[key][sourceUnitName][spellId].minNotCrit = realAmount;
if (realAmount < self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].minNotCrit) then
self.db.char.challenges[id].mechanics[key][sourceUnitName].spells[spellId].minNotCrit = realAmount;
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,38 @@ function MyDungeonsBook:DamageDoneByPartyMemberFrame_GetHeadersForTable()
};
end

local function proceedSpellStats(spellId, spellStats, summaryRow, unitName)
local row = {
cols = {
{value = spellId},
{value = spellId},
{value = spellId},
{value = spellStats.hits},
{value = spellStats.amount},
{value = spellStats.overkill},
{value = (spellStats.hitsCrit or 0) / spellStats.hits * 100},
{value = spellStats.hitsCrit or 0},
{value = (spellStats.maxCrit == 0 and "-") or spellStats.maxCrit},
{value = (spellStats.minCrit == math.huge and "-") or spellStats.minCrit},
{value = (spellStats.maxNotCrit == 0 and "-") or spellStats.maxNotCrit},
{value = (spellStats.minNotCrit == math.huge and "-") or spellStats.minNotCrit},
},
meta = {
unitName = unitName
}
};
summaryRow.cols[4].value = summaryRow.cols[4].value + spellStats.hits;
summaryRow.cols[5].value = summaryRow.cols[5].value + spellStats.amount;
summaryRow.cols[6].value = summaryRow.cols[6].value + spellStats.overkill;
summaryRow.cols[8].value = summaryRow.cols[8].value + spellStats.hitsCrit;
return row, summaryRow;
end

--[[--
Map data about own casts by party member `unitId` for challenge with id `challengeId`.
Pets and other summonned units are included.
@param[type=number] challengeId
@param[type=string] key for mechanics table
@param[type=unitId] unitId
Expand Down Expand Up @@ -213,27 +242,21 @@ function MyDungeonsBook:DamageDoneByPartyMemberFrame_GetDataForTable(challengeId
{value = ""}
}
};
for spellId, spellStats in pairs(mechanicsData) do
tinsert(tableData, {
cols = {
{value = spellId},
{value = spellId},
{value = spellId},
{value = spellStats.hits},
{value = spellStats.amount},
{value = spellStats.overkill},
{value = (spellStats.hitsCrit or 0) / spellStats.hits * 100},
{value = spellStats.hitsCrit or 0},
{value = (spellStats.maxCrit == 0 and "-") or spellStats.maxCrit},
{value = (spellStats.minCrit == math.huge and "-") or spellStats.minCrit},
{value = (spellStats.maxNotCrit == 0 and "-") or spellStats.maxNotCrit},
{value = (spellStats.minNotCrit == math.huge and "-") or spellStats.minNotCrit},
}
});
summaryRow.cols[4].value = summaryRow.cols[4].value + spellStats.hits;
summaryRow.cols[5].value = summaryRow.cols[5].value + spellStats.amount;
summaryRow.cols[6].value = summaryRow.cols[6].value + spellStats.overkill;
summaryRow.cols[8].value = summaryRow.cols[8].value + spellStats.hitsCrit;
for spellId, spellStats in pairs(mechanicsData.spells or mechanicsData) do
if (spellId ~= "meta") then
local row = proceedSpellStats(spellId, spellStats, summaryRow);
tinsert(tableData, row);
end
end
for unitName, damageDoneByUnit in pairs(mechanics) do
if (damageDoneByUnit.meta and (damageDoneByUnit.meta.unitName == name or damageDoneByUnit.meta.unitName == nameAndRealm) and damageDoneByUnit.meta.unitName ~= unitName) then
for spellId, spellStats in pairs(damageDoneByUnit.spells or damageDoneByUnit) do
if (spellId ~= "meta") then
local row = proceedSpellStats(spellId, spellStats, summaryRow, unitName);
tinsert(tableData, row);
end
end
end
end
summaryRow.cols[7].value = summaryRow.cols[8].value / summaryRow.cols[4].value * 100;
tinsert(tableData, summaryRow);
Expand Down
13 changes: 10 additions & 3 deletions Utils/Table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,21 @@ function MyDungeonsBook:Table_Cell_FormatAsSpellLink(rowFrame, cellFrame, data,
local spellId = data[realrow].cols[column].value;
if (spellId) then
if (spellId == -2) then
(cellFrame.text or cellFrame):SetText(L["Swing Damage"]);
local cellText = L["Swing Damage"];
if (data[realrow].meta and data[realrow].meta.unitName) then
cellText = string.format("%s (%s)", cellText, data[realrow].meta.unitName);
end
(cellFrame.text or cellFrame):SetText(cellText);
else
if (spellId == -1) then
(cellFrame.text or cellFrame):SetText(L["Sum"]);
else
if (spellId > 0) then
local spellLink = GetSpellLink(spellId);
(cellFrame.text or cellFrame):SetText(spellLink);
local cellText = GetSpellLink(spellId);
if (data[realrow].meta and data[realrow].meta.unitName) then
cellText = string.format("%s (%s)", cellText, data[realrow].meta.unitName);
end
(cellFrame.text or cellFrame):SetText(cellText);
else
(cellFrame.text or cellFrame):SetText("");
end
Expand Down

0 comments on commit 25f6127

Please sign in to comment.