* add translation for askforguanxing

* fix bug: observer will kill room that not take action

* fix bug: observe and reconnect

* fix bug: notifyCardMove

* fix bug: hegmony nullification

* fix bug: never show test generals in normal askforgeneral

* if game doesn't start, marshal() will only send simple information
This commit is contained in:
notify 2023-02-16 00:54:39 +08:00 committed by GitHub
parent 3fe92b4344
commit b2dfd69a16
7 changed files with 50 additions and 9 deletions

View File

@ -444,6 +444,7 @@ Fk:loadTranslationTable{
[" thinking..."] = " 思考中...",
["AskForGeneral"] = "选择武将",
["AskForGuanxiong"] = "观星",
["AskForChoice"] = "选择",
["PlayCard"] = "出牌",

View File

@ -185,6 +185,9 @@ function Engine:getGeneralsRandomly(num, generalPool, except, filter)
generalPool = generalPool or self.generals
except = except or {}
for _, g in ipairs(self.packages["test_p_0"].generals) do
table.insert(except, g.name)
end
local availableGenerals = {}
for _, general in pairs(generalPool) do

View File

@ -66,6 +66,15 @@ function table.clone(self)
return ret
end
-- similar to table.clone but not recursively
function table.simpleClone(self)
local ret = {}
for k, v in pairs(self) do
ret[k] = v
end
return ret
end
-- if table does not contain the element, we insert it
function table:insertIfNeed(element)
if not table.contains(self, element) then

View File

@ -34,6 +34,7 @@ function GameLogic:run()
self:chooseGenerals()
self:prepareForStart()
self.room.game_started = true
self:action()
end

View File

@ -4,6 +4,7 @@
---@field alive_players ServerPlayer[]
---@field observers fk.ServerPlayer[]
---@field current ServerPlayer
---@field game_started boolean
---@field game_finished boolean
---@field timeout integer
---@field tag table<string, any>
@ -80,6 +81,7 @@ function Room:initialize(_room)
self.alive_players = {}
self.observers = {}
self.current = nil
self.game_started = false
self.game_finished = false
self.timeout = _room:getTimeout()
self.tag = {}
@ -173,6 +175,9 @@ end
---@param sortBySeat boolean
---@return ServerPlayer[]
function Room:getAllPlayers(sortBySeat)
if not self.game_started then
return { table.unpack(self.players) }
end
if sortBySeat == nil or sortBySeat then
local current = self.current
local temp = current.next
@ -505,19 +510,28 @@ function Room:notifyMoveCards(players, card_moves, forceVisible)
for _, move in ipairs(arg) do
-- local to = self:getPlayerById(move.to)
local function infosContainArea(info, area)
for _, i in ipairs(info) do
if i.fromArea == area then
return true
end
end
return false
end
-- forceVisible make the move visible
-- FIXME: move.moveInfo is an array, fix this
move.moveVisible = (forceVisible)
-- if move is relevant to player, it should be open
or ((move.from == p.id) or (move.to == p.id and move.toArea ~= Card.PlayerSpecial))
-- cards move from/to equip/judge/discard/processing should be open
or move.moveInfo.fromArea == Card.PlayerEquip
or infosContainArea(move.moveInfo, Card.PlayerEquip)
or move.toArea == Card.PlayerEquip
or move.moveInfo.fromArea == Card.PlayerJudge
or infosContainArea(move.moveInfo, Card.PlayerJudge)
or move.toArea == Card.PlayerJudge
or move.moveInfo.fromArea == Card.DiscardPile
or infosContainArea(move.moveInfo, Card.DiscardPile)
or move.toArea == Card.DiscardPile
or move.moveInfo.fromArea == Card.Processing
or infosContainArea(move.moveInfo, Card.Processing)
or move.toArea == Card.Processing
-- TODO: PlayerSpecial
@ -1413,7 +1427,7 @@ function Room:useCard(cardUseEvent)
collaboratorsIndex[toId] = collaboratorsIndex[toId] + 1
self:doCardEffect(cardEffectEvent)
self:doCardEffect(table.simpleClone(cardEffectEvent))
end
end
end
@ -2276,6 +2290,7 @@ function Room:shuffleDrawPile()
end
function Room:gameOver(winner)
self.game_started = false
self.game_finished = true
for _, p in ipairs(self.players) do

View File

@ -93,6 +93,17 @@ end
---@param player ServerPlayer
function ServerPlayer:marshal(player)
local room = self.room
if not room.game_started then
-- If game does not starts, that mean we are entering room that
-- all players are choosing their generals.
-- Note that when we are in this function, the main thread must be
-- calling delay() or waiting for reply.
if self.role_shown then
room:notifyProperty(player, self, "role")
end
return
end
room:notifyProperty(player, self, "maxHp")
room:notifyProperty(player, self, "hp")
room:notifyProperty(player, self, "gender")
@ -165,7 +176,7 @@ function ServerPlayer:marshal(player)
end
for k, v in pairs(self.cardUsedHistory) do
player:doNotify("AddCardUseHistory", json.encode{k, v})
player:doNotify("AddCardUseHistory", json.encode{k, v[1]})
end
if self.role_shown then

View File

@ -154,12 +154,13 @@ function getAreaItem(area, id) {
if (area === Card.PlayerHand) {
return photo.handcardArea;
} else if (area === Card.PlayerEquip)
} else if (area === Card.PlayerEquip) {
return photo.equipArea;
else if (area === Card.PlayerJudge)
} else if (area === Card.PlayerJudge) {
return photo.delayedTrickArea;
else if (area === Card.PlayerSpecial)
} else if (area === Card.PlayerSpecial) {
return photo.specialArea;
}
return null;
}