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
|
|
|
}
|
2023-09-06 14:16:09 +00:00
|
|
|
local prompt = "#askForPindian:::" .. pindianData.reason
|
2023-12-12 12:06:07 +00:00
|
|
|
local data = { "choose_cards_skill", prompt, false, extraData }
|
2023-03-14 12:48:08 +00:00
|
|
|
|
|
|
|
local targets = {}
|
2023-08-24 13:37:06 +00:00
|
|
|
local moveInfos = {}
|
2023-03-14 12:48:08 +00:00
|
|
|
if not pindianData.fromCard then
|
|
|
|
table.insert(targets, pindianData.from)
|
|
|
|
pindianData.from.request_data = json.encode(data)
|
2023-08-24 13:37:06 +00: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 13:22:03 +00:00
|
|
|
from = pindianData.from.id,
|
2023-08-24 13:37:06 +00:00
|
|
|
fromArea = room:getCardArea(_pindianCard.id),
|
|
|
|
toArea = Card.Processing,
|
|
|
|
moveReason = fk.ReasonPut,
|
|
|
|
skillName = pindianData.reason,
|
|
|
|
moveVisible = true,
|
|
|
|
})
|
2023-03-14 12:48:08 +00:00
|
|
|
end
|
|
|
|
for _, to in ipairs(pindianData.tos) do
|
2023-09-27 12:56:12 +00:00
|
|
|
if pindianData.results[to.id] and pindianData.results[to.id].toCard then
|
|
|
|
local _pindianCard = pindianData.results[to.id].toCard
|
|
|
|
local pindianCard = _pindianCard:clone(_pindianCard.suit, _pindianCard.number)
|
|
|
|
pindianCard:addSubcard(_pindianCard.id)
|
|
|
|
|
|
|
|
pindianData.results[to.id].toCard = pindianCard
|
|
|
|
|
|
|
|
table.insert(moveInfos, {
|
|
|
|
ids = { _pindianCard.id },
|
|
|
|
from = to.id,
|
|
|
|
fromArea = room:getCardArea(_pindianCard.id),
|
|
|
|
toArea = Card.Processing,
|
|
|
|
moveReason = fk.ReasonPut,
|
|
|
|
skillName = pindianData.reason,
|
|
|
|
moveVisible = true,
|
|
|
|
})
|
|
|
|
else
|
2023-03-14 12:48:08 +00:00
|
|
|
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
|
|
|
|
|
|
|
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
|