Skip to content

Commit

Permalink
Merge pull request #751 from DeviousNull/multiboss-state-updates
Browse files Browse the repository at this point in the history
Add support for BarManager updates with multiple bosses.
  • Loading branch information
AntlerForce authored Sep 14, 2024
2 parents 7b34823 + fc7ccf4 commit 12c8d77
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions libs/liblobby/lobby/lobby.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ end
-- message = {"BattleStateChanged": {"locked": "locked", "autoBalance": "advanced", "teamSize": "8", "nbTeams": "2", "balanceMode": "clan;skill", "preset": "team", "boss": "Fireball"}}
function Lobby:ParseBarManager(battleID, message)
local battleInfo = {}
local newBoss
local newBosses

local barManagerSettings = spJsonDecode(message)
if not barManagerSettings['BattleStateChanged'] then
Expand All @@ -1523,13 +1523,13 @@ function Lobby:ParseBarManager(battleID, message)
battleInfo["bossed"] = false
else
battleInfo["bossed"] = true
newBoss = v
newBosses = v
end
elseif WG.Chobby.Configuration.barMngSettings[k] then
battleInfo[k] = v
end
end
return battleInfo, newBoss
return battleInfo, newBosses
end

function Lobby:_OnSaidBattleEx(userName, message, sayTime)
Expand All @@ -1541,21 +1541,26 @@ function Lobby:_OnSaidBattleEx(userName, message, sayTime)
Spring.Log(LOG_SECTION, LOG_WARNING, "couldn't match barmanager message to any known battle", tostring(founder))
return
end
local battleInfo, newBoss = self:ParseBarManager(battleID, bmMessage)
local battleInfo, newBosses = self:ParseBarManager(battleID, bmMessage)
if next(battleInfo) then
self:super("_OnUpdateBattleInfo", battleID, battleInfo)

if battleInfo.bossed ~= nil then
local battleUsers = self.battles[battleID].users
local bossStates = {}
for _, battleUserName in pairs(battleUsers) do
if self.userBattleStatus[battleUserName].isBoss then
bossStates[battleUserName] = false
end
end
if battleInfo.bossed then
self:_OnUpdateUserBattleStatus(newBoss, {isBoss = true})
else
local battleUsers = self.battles[battleID].users
for _, battleUserName in pairs(battleUsers) do
if self.userBattleStatus[battleUserName] and self.userBattleStatus[battleUserName].isBoss then
self:_OnUpdateUserBattleStatus(battleUserName, {isBoss = false})
end
for bossUsername in string.gmatch(newBosses, "([^,]+)") do
bossStates[bossUsername] = true
end
end
for battleUserName,bossState in pairs(bossStates) do
self:_OnUpdateUserBattleStatus(battleUserName, {isBoss = bossState})
end
end

end
Expand Down

0 comments on commit 12c8d77

Please sign in to comment.