Join co-located player colors
This commit is contained in:
parent
e200ddcaad
commit
cb1b5006b9
3 changed files with 71 additions and 4 deletions
20
room.lua
20
room.lua
|
|
@ -440,8 +440,24 @@ function Room:switchPlayerColorLocal(color)
|
|||
local targetPlayer = self.player[color]
|
||||
if not targetPlayer then return false end
|
||||
|
||||
local canSwitch = not self:onlyColorIsActive(color)
|
||||
if canSwitch then
|
||||
local activeColors = self:getActiveColors()
|
||||
local canJoin = not self:colorIsActive(color) and #activeColors > 0
|
||||
if canJoin then
|
||||
local target = targetPlayer:getGridPos()
|
||||
for _, activeColor in ipairs(activeColors) do
|
||||
local activePlayer = self.player[activeColor]
|
||||
local activePos = activePlayer and activePlayer:getGridPos()
|
||||
if not activePos or activePos.x ~= target.x or activePos.y ~= target.y then
|
||||
canJoin = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local canSwitch = canJoin or not self:onlyColorIsActive(color)
|
||||
if canJoin then
|
||||
self:setActiveColor(color, true)
|
||||
elseif canSwitch then
|
||||
for _, c in ipairs(self:getPossibleColors()) do
|
||||
self:setActiveColor(c, c == color)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue