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