Skip to content

Commit

Permalink
v1.0.5
Browse files Browse the repository at this point in the history
Fix for Cataclysm mounts
Added support for aquatic mounts, so if in water and you have a aquatic favorite mount that can be used in that area it will summon that, as long as you don't use the Flying or Ground specific slash command or keybind.
  • Loading branch information
Lith77 committed Dec 6, 2024
1 parent c6cf4fa commit ad18f08
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 29 deletions.
105 changes: 91 additions & 14 deletions LithStable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ LithStable = LibStub("AceAddon-3.0"):NewAddon(LithStable, addonName, "AceConsole
-- State variables
LithStable.lastFlyingMount = nil
LithStable.lastGroundMount = nil
LithStable.lastAquaticMount = nil
LithStable.pendingMount = nil
LithStable.pendingMountType = nil
--LithStable.aquaticMountBackup = false

function LithStable:OnInitialize()
-- Initialize settings
Expand All @@ -14,6 +16,10 @@ function LithStable:OnInitialize()
-- Load last mount states from character saved variables
self.lastFlyingMount = self.db.char.state.lastFlyingMount
self.lastGroundMount = self.db.char.state.lastGroundMount
self.lastAquaticMount = self.db.char.state.lastAquaticMount

-- Initialize aquaticMountBackup
--self:UpdateAquaticMountBackup()

-- Register slash commands
self:RegisterChatCommand("ls", "HandleSlashCommand")
Expand All @@ -39,8 +45,19 @@ function LithStable:OnInitialize()
end
end

--[[
function LithStable:UpdateAquaticMountBackup()
if self.db.char.useSharedSettings then
self.aquaticMountBackup = self.db.profile.settings.aquaticBackup
else
self.aquaticMountBackup = self.db.char.settings.aquaticBackup
end
end]]

function LithStable:HandleSlashCommand(msg)
local command = string.lower(msg)
--local command = string.lower(msg)
local args = {strsplit(" ", msg)}
local command = string.lower(args[1] or "")
if command == "help" then
self:printHelp()
elseif command == "debug" then
Expand All @@ -52,14 +69,27 @@ function LithStable:HandleSlashCommand(msg)
elseif command == "flying" then
self:SummonRandomMount("flying", true)
elseif command == "ground" then
self:SummonRandomMount("ground", true)
self:SummonRandomMount("ground", true)
elseif command == "debugam" then
if args[2] then
local mountID = tonumber(args[2])
if mountID then
self:DebugPrintAnyMount(mountID)
else
print(format('|cFF8000FF%s|r|cffffffff%s|r %s', 'Lith', 'Stable:', "Invalid mount ID. Please provide a valid number."))
end
else
print(format('|cFF8000FF%s|r|cffffffff%s|r %s', 'Lith', 'Stable:', "Usage: /ls debugam [mount_id]"))
end
else
self:SummonRandomMount(nil, false)
end
end


-- Main mount summoning function
function LithStable:SummonRandomMount(rMountType, forceType)

if not self:CheckCooldown() then
return
end
Expand All @@ -79,19 +109,24 @@ function LithStable:SummonRandomMount(rMountType, forceType)

local favoriteMounts = {
ground = {},
flying = {}
flying = {},
aquatic = {}
}
local canFly = self:CanFlyInCurrentZone()
local isSubmerged = IsSubmerged()
local isSwimming = IsSwimming()
local unusableFavorites = {}

for i = 1, C_MountJournal.GetNumMounts() do
local name, spellID, icon, isActive, isUsable, sourceType, isFavorite, isFactionSpecific, faction, shouldHideOnChar, isCollected, mountID = C_MountJournal.GetMountInfoByID(i)
if mountID then
local name, spellID, icon, isActive, isUsable, sourceType, isFavorite, isFactionSpecific, faction, shouldHideOnChar, isCollected, mountID = C_MountJournal.GetMountInfoByID(C_MountJournal.GetDisplayedMountID(i))

if mountID and isCollected and isUsable then
local localUsable, reason = C_MountJournal.GetMountUsabilityByID(mountID, false)
if isCollected and isFavorite and not shouldHideOnChar then
if isUsable and localUsable then
if self:IsFlyingMount(mountID) then
table.insert(favoriteMounts.flying, mountID)
elseif self:IsAquaticMount(mountID) then
table.insert(favoriteMounts.aquatic, mountID)
else
table.insert(favoriteMounts.ground, mountID)
end
Expand All @@ -109,45 +144,86 @@ function LithStable:SummonRandomMount(rMountType, forceType)
end
end

--print("isSubmerged:", isSubmerged)
--print("isSwimming:", isSwimming)
--print("canFly:", canFly)
--print("favoriteMounts.aquatic:", #favoriteMounts.aquatic)
--print("favoriteMounts.flying:", #favoriteMounts.flying)
--print("favoriteMounts.ground:", #favoriteMounts.ground)
--print("self.aquaticMountBackup:", self.aquaticMountBackup)

local mountList
local isFlying = false
if rMountType == "flying" and (canFly or forceType) then
local isAquatic = false

if (isSubmerged or isSwimming) and not forceType then
if #favoriteMounts.aquatic > 0 then
mountList = favoriteMounts.aquatic
isAquatic = true
--[[ removed because not all flying mounts can be summoned in water, and no way to know
elseif self.aquaticMountBackup and canFly and #favoriteMounts.flying > 0 then
mountList = favoriteMounts.flying
isFlying = true
print("flying")
elseif self.aquaticMountBackup and #favoriteMounts.ground > 0 then
mountList = favoriteMounts.ground
print("ground")]]
else
print(format('|cFF8000FF%s|r|cffffffff%s|r %s', 'Lith', 'Stable:', "No aquatic mounts available."))
return
end
LithStable:SRM(mountList, isFlying, isAquatic);
return
elseif rMountType == "flying" and (canFly or forceType) then
if #favoriteMounts.flying > 0 then
mountList = favoriteMounts.flying
isFlying = true
else
mountList = favoriteMounts.ground
print(format('|cFF8000FF%s|r|cffffffff%s|r %s', 'Lith', 'Stable:', "No flying mounts available. Summoning a ground mount instead"))
end
LithStable:SRM(mountList, isFlying, isAquatic);
return
elseif rMountType == "ground" or (rMountType ~= "flying" and not canFly and not forceType) then
mountList = favoriteMounts.ground
LithStable:SRM(mountList, isFlying, isAquatic);
return
else
if canFly and #favoriteMounts.flying > 0 then
mountList = favoriteMounts.flying
isFlying = true
else
mountList = favoriteMounts.ground
end
LithStable:SRM(mountList, isFlying, isAquatic);
return
end
end

function LithStable:SRM(mountList, isFlying, isAquatic)
if #mountList > 0 then
local selectedMount, selectedIndex
if isFlying then
selectedMount, selectedIndex = self:GetRandomMountExcludingLast(mountList, self:GetLastMount("flying"), true)
selectedMount, selectedIndex = self:GetRandomMountExcludingLast(mountList, self:GetLastMount("flying"), true, false)
elseif isAquatic then
selectedMount, selectedIndex = self:GetRandomMountExcludingLast(mountList, self:GetLastMount("aquatic"), false, true)
else
selectedMount, selectedIndex = self:GetRandomMountExcludingLast(mountList, self:GetLastMount("ground"), false)
selectedMount, selectedIndex = self:GetRandomMountExcludingLast(mountList, self:GetLastMount("ground"), false, false)
end

local actualIsFlying = self:IsFlyingMount(selectedMount)
local actualIsAquatic = self:IsAquaticMount(selectedMount)

self.pendingMount = selectedMount
self.pendingMountType = actualIsFlying and "flying" or "ground"
if selectedMount == self.lastFlyingMount or self.lastGroundMount then
self.pendingMountType = actualIsFlying and "flying" or (actualIsAquatic and "aquatic" or "ground")

if selectedMount == self.lastFlyingMount or self.lastGroundMount or self.lastAquaticMount then
C_Timer.After(0.3, function()
C_MountJournal.SummonByID(selectedMount)
end)
return
end

C_MountJournal.SummonByID(selectedMount)
else
print(format('|cFF8000FF%s|r|cffffffff%s|r %s', 'Lith', 'Stable:', "You have no suitable favorite mounts available."))
Expand Down Expand Up @@ -212,7 +288,7 @@ mountEventFrame:SetScript("OnEvent", function(self, event)
end

for i = 1, C_MountJournal.GetNumMounts() do
local _, _, _, _, _, _, isFavorite, _, _, _, _, mountID = C_MountJournal.GetMountInfoByID(i)
local _, _, _, _, _, _, isFavorite, _, _, _, _, mountID = C_MountJournal.GetMountInfoByID(C_MountJournal.GetDisplayedMountID(i))
if mountID then
LithStable.db.char.favorites.mounts[mountID] = isFavorite or nil
end
Expand All @@ -221,7 +297,7 @@ mountEventFrame:SetScript("OnEvent", function(self, event)
if IsMounted() and LithStable.pendingMount then
local activeMount = nil
for i = 1, C_MountJournal.GetNumMounts() do
local _, _, _, isActive, _, _, _, _, _, _, _, mountID = C_MountJournal.GetMountInfoByID(i)
local _, _, _, isActive, _, _, _, _, _, _, _, mountID = C_MountJournal.GetMountInfoByID(C_MountJournal.GetDisplayedMountID(i))
if isActive then
activeMount = mountID
break
Expand All @@ -230,8 +306,9 @@ mountEventFrame:SetScript("OnEvent", function(self, event)

if activeMount == LithStable.pendingMount then
local isFlying = LithStable:IsFlyingMount(LithStable.pendingMount)
local isAquatic = LithStable:IsAquaticMount(LithStable.pendingMount)
-- Always save to character specific state
LithStable:SetLastMount(isFlying and "flying" or "ground", LithStable.pendingMount)
LithStable:SetLastMount(isFlying and "flying" or isAquatic and "aquatic" or "ground", LithStable.pendingMount)
end
end

Expand Down
2 changes: 1 addition & 1 deletion LithStable.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: |cFF8000FFLith|rStable
## Notes: For when choosing a mount is harder than downing Deathwing. Let RNG be your Dragon Soul!
## Author: Lith
## Version: 1.0.4
## Version: 1.0.5
## SavedVariables: LithStableDB

# Libraries (embedded)
Expand Down
3 changes: 3 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
LithStable, Summons a random favorite mount
V1.0.5:
- Fix for Cataclysm mounts
- Added support for aquatic mounts, so if in water and you have a aquatic favorite mount that can be used in that area it will summon that, as long as you don't use the Flying or Ground specific slash command or keybind.
V1.0.4:
- Added options that are saved shared or per character
- Addon now keeps track of last used flying and ground mount.
Expand Down
54 changes: 51 additions & 3 deletions debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@ function LithStable:DebugPrintFavorites()

local availableMounts = {
ground = {},
flying = {}
flying = {},
aquatic = {}
}
local unusableFavorites = {}

-- Use the same mount collection logic as in SummonRandomMount
for i = 1, C_MountJournal.GetNumMounts() do
local name, spellID, _, isActive, isUsable, sourceType, isFavorite, isFactionSpecific, faction, shouldHideOnChar, isCollected, mountID = C_MountJournal.GetMountInfoByID(i)
local name, spellID, _, isActive, isUsable, sourceType, isFavorite, isFactionSpecific, faction, shouldHideOnChar, isCollected, mountID = C_MountJournal.GetMountInfoByID(C_MountJournal.GetDisplayedMountID(i))
if mountID then
local localUsable, reason = C_MountJournal.GetMountUsabilityByID(mountID, false)
if isCollected and isFavorite and not shouldHideOnChar then
local mountTypeStr = self:IsFlyingMount(mountID) and "Flying" or "Ground"
local mountTypeStr = self:IsFlyingMount(mountID) and "Flying" or (self:IsAquaticMount(mountID) and "Aquatic" or "Ground")
if isUsable and localUsable then
-- Add to available mounts list
local statusStr = "Usable"
print(string.format("%s (SpellID: %d): %s, %s", name, spellID, mountTypeStr, statusStr))
if self:IsFlyingMount(mountID) then
table.insert(availableMounts.flying, name)
elseif self:IsAquaticMount(mountID) then
table.insert(availableMounts.aquatic, name)
else
table.insert(availableMounts.ground, name)
end
Expand All @@ -48,6 +51,11 @@ function LithStable:DebugPrintFavorites()
if #availableMounts.ground > 0 then
print(" " .. table.concat(availableMounts.ground, ", "))
end

print("Available Aquatic Mounts:", #availableMounts.aquatic)
if #availableMounts.aquatic > 0 then
print(" " .. table.concat(availableMounts.aquatic, ", "))
end

if #unusableFavorites > 0 then
print("Unusable Favorite Mounts:", #unusableFavorites)
Expand Down Expand Up @@ -89,5 +97,45 @@ function LithStable:DebugPrintLastMounts()
print("Last Ground Mount: None")
end

-- Print last aquatic mount
if self.lastAquaticMount then
local name = C_MountJournal.GetMountInfoByID(self.lastAquaticMount)
if name then
local _, _, _, _, mountTypeID = C_MountJournal.GetMountInfoExtraByID(self.lastAquaticMount)
print(string.format("Last Aquatic Mount: %s (ID: %d, Type: %d)", name, self.lastAquaticMount, mountTypeID))
end
else
print("Last Aquatic Mount: None")
end

print("---------------------------------------")
end
function LithStable:DebugPrintAnyMount(spellID)
local mountID = C_MountJournal.GetMountFromSpell(spellID)
local name, spellID, icon, isActive, isUsable, sourceType, isFavorite, isFactionSpecific, faction, shouldHideOnChar, isCollected, realMountID = C_MountJournal.GetMountInfoByID(mountID)
local _, _, _, _, mountTypeID = C_MountJournal.GetMountInfoExtraByID(mountID)
local localUsable, reason = C_MountJournal.GetMountUsabilityByID(mountID, false)
print("---------------------------------------")
if name then
print(string.format("Mount Name: %s", name))
print(string.format("Spell ID: %d", spellID))
print(string.format("Icon: %s", icon))
print(string.format("Is Active: %s", tostring(isActive)))
print(string.format("Is Usable: %s", tostring(isUsable)))
print(string.format("Is localUsable: %s", tostring(localUsable)))
if not localUsable then
print(string.format("Reason: %s", reason))
end
print(string.format("Source Type: %s", sourceType))
print(string.format("Is Favorite: %s", tostring(isFavorite)))
print(string.format("Is Faction Specific: %s", tostring(isFactionSpecific)))
print(string.format("Faction: %s", faction or "None"))
print(string.format("Should Hide on Character: %s", tostring(shouldHideOnChar)))
print(string.format("Is Collected: %s", tostring(isCollected)))
print(string.format("Mount ID: %d", realMountID))
print(string.format("MountType ID: %d", mountTypeID))
else
print(string.format("|cFF8000FF%s|r|cffffffff%s|r %s", 'Lith', 'Stable:', "No mount information available for the specified mount ID."))
end
print("---------------------------------------")
end
Loading

0 comments on commit ad18f08

Please sign in to comment.