Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions addons/battle/alerts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,31 @@ function Alerts:OnEnable()
end

function Alerts:Verify()
local rareUpgrades = Addon.Battle:AnyRareUpgrade()
if not rareUpgrades and Addon.Battle:IsWildBattle() and not self.popped and Addon.sets.forfeitNoRareUpgrades then
self.popped = true

LibStub('Sushi-3.1').Popup {
id = ADDON .. 'Alerts',
text = L.AskForfeit, button1 = "Quit, No Rare Upgrades", button2 = "Stay",
OnAccept = C_PetBattles.ForfeitGame,
hideOnEscape = 1,
}
end

local upgrades = Addon.Battle:AnyUpgrade()
if not upgrades and Addon.Battle:IsWildBattle() and not self.popped and Addon.sets.forfeit then
self.popped = true

LibStub('Sushi-3.1').Popup {
id = ADDON .. 'Alerts',
text = L.AskForfeit, button1 = QUIT, button2 = NO,
OnAccept = C_PetBattles.ForfeitGame,
hideOnEscape = 1,
}
id = ADDON .. 'Alerts',
text = L.AskForfeit, button1 = "Quit, No Upgrades", button2 = "Stay",
OnAccept = C_PetBattles.ForfeitGame,
hideOnEscape = 1,
}
end

self:SetShown(upgrades and not self.shown and Addon.sets.alertUpgrades)
self:SetShown(upgrades and not self.shown and Addon.sets.alertUpgrades)
end

function Alerts:Reset()
Expand Down
27 changes: 27 additions & 0 deletions addons/battle/battle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ function Battle:AnyUpgrade()
end
end

function Battle:AnyRareUpgrade()
for i = 1, self:NumPets(Enum.BattlePetOwner.Enemy) do
local pet = self(Enum.BattlePetOwner.Enemy, i)
if pet:IsUpgradeAndRare() then
return true
end
end
end

function Battle:GetRival()
if self:IsPvE() then
local specie1 = self(Enum.BattlePetOwner.Enemy, 1):GetSpecie()
Expand Down Expand Up @@ -84,6 +93,24 @@ function Battle:IsUpgrade()
return false
end

function Battle:IsUpgradeAndRare()
if self:IsWildBattle() and not self:IsAlly() then
if self:GetSpecie() and self:GetSource() == 5 then
local _, quality = self:GetBestOwned()

if quality > 3 then -- Player's best pet is rare, so it can never be an upgrade
return false
end

if self:GetQuality() > 3 then -- The wild pet is rare (and ours is not), so it is an upgrade
return true
end
end
end

return false
end

function Battle:CanSwap()
return self:IsAlly() and C_PetBattles.CanPetSwapIn(self.index)
end
Expand Down
1 change: 1 addition & 0 deletions addons/config/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function Options:OnMain()
self:AddCheck('Switcher')
self:AddCheck('AlertUpgrades')
self:AddCheck('Forfeit')
self:AddCheck('ForfeitNoRareUpgrades')
end

function Options:OnFAQ()
Expand Down
2 changes: 2 additions & 0 deletions addons/main/localization/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ L.AlertUpgradesTip = 'If disabled, an upgrades alert box will not be shown in co
L.FAQDescription = 'These are the most frequently asked questions. To see the tutorials again, reset the addon settings using the "Defaults" button at the lower left corner.'
L.Forfeit = 'Prompt for Forfeit'
L.ForfeitTip = 'If enabled, will ask whether to forfeit a wild battle when no upgrades are available.'
L.ForfeitNoRareUpgrades = 'Prompt Forfeit No Rare'
L.ForfeitNoRareUpgradesTip = 'If enabled, will ask whether to forfeit a wild battle when no rare upgrades are available.'
L.OptionsDescription = 'These options allow you to toggle PetTracker general features on and off. Gotta catch them all!'
L.RivalPortraits = 'Rival Portraits'
L.RivalPortraitsTip = 'If enabled, rivals will be marked by their portraits when shown in the world and battle map.'
Expand Down