2023-04-09 13:35:35 +08:00
|
|
|
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-03-14 20:48:08 +08:00
|
|
|
GameEvent.functions[GameEvent.Pindian] = function(self)
|
|
|
|
local pindianData = table.unpack(self.data)
|
2023-04-28 10:27:56 +08:00
|
|
|
local room = self.room
|
|
|
|
local logic = room.logic
|
|
|
|
logic:trigger(fk.StartPindian, pindianData.from, pindianData)
|
2023-03-14 20:48:08 +08:00
|
|
|
|
|
|
|
if pindianData.reason ~= "" then
|
2023-04-28 10:27:56 +08:00
|
|
|
room:sendLog{
|
2023-03-14 20:48:08 +08:00
|
|
|
type = "#StartPindianReason",
|
|
|
|
from = pindianData.from.id,
|
|
|
|
arg = pindianData.reason,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
local extraData = {
|
|
|
|
num = 1,
|
|
|
|
min_num = 1,
|
|
|
|
include_equip = false,
|
2023-04-28 10:27:56 +08:00
|
|
|
pattern = ".",
|
|
|
|
reason = pindianData.reason,
|
2023-03-14 20:48:08 +08:00
|
|
|
}
|
2023-09-06 22:16:09 +08:00
|
|
|
local prompt = "#askForPindian:::" .. pindianData.reason
|
|
|
|
local data = { "choose_cards_skill", prompt, false, json.encode(extraData) }
|
2023-03-14 20:48:08 +08:00
|
|
|
|
|
|
|
local targets = {}
|
2023-08-24 21:37:06 +08:00
|
|
|
local moveInfos = {}
|
2023-03-14 20:48:08 +08:00
|
|
|
if not pindianData.fromCard then
|
|
|
|
table.insert(targets, pindianData.from)
|
|
|
|
pindianData.from.request_data = json.encode(data)
|
2023-08-24 21:37:06 +08:00
|
|
|
else
|
|
|
|
local _pindianCard = pindianData.fromCard
|
|
|
|
local pindianCard = _pindianCard:clone(_pindianCard.suit, _pindianCard.number)
|
|
|
|
pindianCard:addSubcard(_pindianCard.id)
|
|
|
|
|
|
|
|
pindianData.fromCard = pindianCard
|
|
|
|
|
|
|
|
table.insert(moveInfos, {
|
|
|
|
ids = { _pindianCard.id },
|
2023-08-27 21:22:03 +08:00
|
|
|
from = pindianData.from.id,
|
2023-08-24 21:37:06 +08:00
|
|
|
fromArea = room:getCardArea(_pindianCard.id),
|
|
|
|
toArea = Card.Processing,
|
|
|
|
moveReason = fk.ReasonPut,
|
|
|
|
skillName = pindianData.reason,
|
|
|
|
moveVisible = true,
|
|
|
|
})
|
2023-03-14 20:48:08 +08:00
|
|
|
end
|
|
|
|
for _, to in ipairs(pindianData.tos) do
|
|
|
|
if not (pindianData.results[to.id] and pindianData.results[to.id].toCard) then
|
|
|
|
table.insert(targets, to)
|
|
|
|
to.request_data = json.encode(data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-28 10:27:56 +08:00
|
|
|
room:notifyMoveFocus(targets, "AskForPindian")
|
|
|
|
room:doBroadcastRequest("AskForUseActiveSkill", targets)
|
2023-03-14 20:48:08 +08:00
|
|
|
|
|
|
|
for _, p in ipairs(targets) do
|
2023-06-24 14:48:49 +08:00
|
|
|
local _pindianCard
|
2023-03-14 20:48:08 +08:00
|
|
|
if p.reply_ready then
|
|
|
|
local replyCard = json.decode(p.client_reply).card
|
2023-06-24 14:48:49 +08:00
|
|
|
_pindianCard = Fk:getCardById(json.decode(replyCard).subcards[1])
|
2023-03-14 20:48:08 +08:00
|
|
|
else
|
2023-06-24 14:48:49 +08:00
|
|
|
_pindianCard = Fk:getCardById(p:getCardIds(Player.Hand)[1])
|
2023-03-14 20:48:08 +08:00
|
|
|
end
|
|
|
|
|
2023-06-24 14:48:49 +08:00
|
|
|
local pindianCard = _pindianCard:clone(_pindianCard.suit, _pindianCard.number)
|
|
|
|
pindianCard:addSubcard(_pindianCard.id)
|
|
|
|
|
2023-03-14 20:48:08 +08:00
|
|
|
if p == pindianData.from then
|
|
|
|
pindianData.fromCard = pindianCard
|
|
|
|
else
|
|
|
|
pindianData.results[p.id] = pindianData.results[p.id] or {}
|
|
|
|
pindianData.results[p.id].toCard = pindianCard
|
|
|
|
end
|
|
|
|
|
|
|
|
table.insert(moveInfos, {
|
2023-06-24 14:48:49 +08:00
|
|
|
ids = { _pindianCard.id },
|
2023-03-14 20:48:08 +08:00
|
|
|
from = p.id,
|
|
|
|
toArea = Card.Processing,
|
|
|
|
moveReason = fk.ReasonPut,
|
|
|
|
skillName = pindianData.reason,
|
|
|
|
moveVisible = true,
|
|
|
|
})
|
2023-04-28 10:27:56 +08:00
|
|
|
|
|
|
|
room:sendLog{
|
|
|
|
type = "#ShowPindianCard",
|
|
|
|
from = p.id,
|
2023-06-24 14:48:49 +08:00
|
|
|
card = { _pindianCard.id },
|
2023-04-28 10:27:56 +08:00
|
|
|
}
|
2023-03-14 20:48:08 +08:00
|
|
|
end
|
|
|
|
|
2023-04-28 10:27:56 +08:00
|
|
|
room:moveCards(table.unpack(moveInfos))
|
2023-03-14 20:48:08 +08:00
|
|
|
|
2023-04-28 10:27:56 +08:00
|
|
|
logic:trigger(fk.PindianCardsDisplayed, nil, pindianData)
|
2023-03-14 20:48:08 +08:00
|
|
|
|
|
|
|
for toId, result in pairs(pindianData.results) do
|
2023-04-28 10:27:56 +08:00
|
|
|
local to = room:getPlayerById(toId)
|
2023-03-14 20:48:08 +08:00
|
|
|
if pindianData.fromCard.number > result.toCard.number then
|
2023-04-28 10:27:56 +08:00
|
|
|
result.winner = pindianData.from
|
|
|
|
elseif pindianData.fromCard.number < result.toCard.number then
|
|
|
|
result.winner = to
|
2023-03-14 20:48:08 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local singlePindianData = {
|
|
|
|
from = pindianData.from,
|
2023-04-28 10:27:56 +08:00
|
|
|
to = to,
|
2023-03-14 20:48:08 +08:00
|
|
|
fromCard = pindianData.fromCard,
|
|
|
|
toCard = result.toCard,
|
2023-04-28 10:27:56 +08:00
|
|
|
winner = result.winner,
|
2023-08-12 19:19:03 +08:00
|
|
|
reason = pindianData.reason,
|
2023-04-28 10:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
room:sendLog{
|
|
|
|
type = "#ShowPindianResult",
|
|
|
|
from = pindianData.from.id,
|
|
|
|
to = { toId },
|
|
|
|
arg = result.winner == pindianData.from and "pindianwin" or "pindiannotwin"
|
2023-03-14 20:48:08 +08:00
|
|
|
}
|
2023-04-28 10:27:56 +08:00
|
|
|
logic:trigger(fk.PindianResultConfirmed, nil, singlePindianData)
|
2023-03-14 20:48:08 +08:00
|
|
|
end
|
|
|
|
|
2023-04-28 10:27:56 +08:00
|
|
|
if logic:trigger(fk.PindianFinished, pindianData.from, pindianData) then
|
|
|
|
logic:breakEvent()
|
2023-03-14 20:48:08 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
GameEvent.cleaners[GameEvent.Pindian] = function(self)
|
|
|
|
local pindianData = table.unpack(self.data)
|
2023-04-28 10:27:56 +08:00
|
|
|
local room = self.room
|
2023-03-14 20:48:08 +08:00
|
|
|
|
|
|
|
local toProcessingArea = {}
|
2023-04-28 10:27:56 +08:00
|
|
|
local leftFromCardIds = room:getSubcardsByRule(pindianData.fromCard, { Card.Processing })
|
2023-03-14 20:48:08 +08:00
|
|
|
if #leftFromCardIds > 0 then
|
|
|
|
table.insertTable(toProcessingArea, leftFromCardIds)
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, result in pairs(pindianData.results) do
|
2023-04-28 10:27:56 +08:00
|
|
|
local leftToCardIds = room:getSubcardsByRule(result.toCard, { Card.Processing })
|
2023-03-14 20:48:08 +08:00
|
|
|
if #leftToCardIds > 0 then
|
|
|
|
table.insertTable(toProcessingArea, leftToCardIds)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if #toProcessingArea > 0 then
|
2023-04-28 10:27:56 +08:00
|
|
|
room:moveCards({
|
2023-03-14 20:48:08 +08:00
|
|
|
ids = toProcessingArea,
|
|
|
|
toArea = Card.DiscardPile,
|
|
|
|
moveReason = fk.ReasonPutIntoDiscardPile,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
if not self.interrupted then return end
|
|
|
|
end
|