FreeKill/lua/server/events/judge.lua

71 lines
1.8 KiB
Lua

-- SPDX-License-Identifier: GPL-3.0-or-later
GameEvent.functions[GameEvent.Judge] = function(self)
local data = table.unpack(self.data)
local self = self.room
local who = data.who
self.logic:trigger(fk.StartJudge, who, data)
data.card = data.card or Fk:getCardById(self:getNCards(1)[1])
if data.reason ~= "" then
self:sendLog{
type = "#StartJudgeReason",
from = who.id,
arg = data.reason,
}
end
self:sendLog{
type = "#InitialJudge",
from = who.id,
card = {data.card.id},
}
self:moveCardTo(data.card, Card.Processing, nil, fk.ReasonJudge)
self:sendFootnote({ data.card.id }, {
type = "##JudgeCard",
arg = data.reason,
})
self.logic:trigger(fk.AskForRetrial, who, data)
self.logic:trigger(fk.FinishRetrial, who, data)
Fk:filterCard(data.card.id, who, data)
self:sendLog{
type = "#JudgeResult",
from = who.id,
card = {data.card.id},
}
self:sendFootnote({ data.card.id }, {
type = "##JudgeCard",
arg = data.reason,
})
if data.pattern then
self:delay(400);
self:setCardEmotion(data.card.id, data.card:matchPattern(data.pattern) and "judgegood" or "judgebad")
self:delay(900);
end
if self.logic:trigger(fk.FinishJudge, who, data) then
self.logic:breakEvent()
end
end
GameEvent.cleaners[GameEvent.Judge] = function(self)
local data = table.unpack(self.data)
local self = self.room
if (self.interrupted or not data.skipDrop) and self:getCardArea(data.card.id) == Card.Processing then
self:moveCardTo(data.card, Card.DiscardPile, nil, fk.ReasonJudge)
end
if not self.interrupted then return end
-- prohibit access to judge.card
setmetatable(data, {
__index = function(self, key)
if key == "card" then
error("__manuallyBreak")
end
return rawget(self, key)
end
})
end