2023-04-09 05:35:35 +00:00
|
|
|
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-12-20 04:51:54 +00:00
|
|
|
---@param victim ServerPlayer
|
|
|
|
local function getWinner(victim)
|
|
|
|
local room = victim.room
|
|
|
|
local winner = ""
|
|
|
|
local alive = room.alive_players
|
|
|
|
|
|
|
|
if victim.role == "lord" then
|
|
|
|
if #alive == 1 and alive[1].role == "renegade" then
|
2023-03-20 06:53:56 +00:00
|
|
|
winner = "renegade"
|
2022-12-20 04:51:54 +00:00
|
|
|
else
|
|
|
|
winner = "rebel"
|
|
|
|
end
|
|
|
|
elseif victim.role ~= "loyalist" then
|
|
|
|
local lord_win = true
|
|
|
|
for _, p in ipairs(alive) do
|
|
|
|
if p.role == "rebel" or p.role == "renegade" then
|
|
|
|
lord_win = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if lord_win then
|
|
|
|
winner = "lord+loyalist"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return winner
|
|
|
|
end
|
|
|
|
|
|
|
|
---@param killer ServerPlayer
|
|
|
|
local function rewardAndPunish(killer, victim)
|
|
|
|
if killer.dead then return end
|
|
|
|
if victim.role == "rebel" then
|
|
|
|
killer:drawCards(3, "kill")
|
|
|
|
elseif victim.role == "loyalist" and killer.role == "lord" then
|
|
|
|
killer:throwAllCards("he")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-01 12:51:01 +00:00
|
|
|
GameRule = fk.CreateTriggerSkill{
|
2022-04-30 07:27:56 +00:00
|
|
|
name = "game_rule",
|
2023-01-16 13:04:28 +00:00
|
|
|
refresh_events = {
|
2022-04-30 07:27:56 +00:00
|
|
|
fk.GameStart, fk.DrawInitialCards, fk.TurnStart,
|
|
|
|
fk.EventPhaseProceeding, fk.EventPhaseEnd, fk.EventPhaseChanging,
|
2023-04-08 12:45:55 +00:00
|
|
|
fk.RoundStart,
|
2022-12-20 04:51:54 +00:00
|
|
|
fk.AskForPeaches, fk.AskForPeachesDone,
|
|
|
|
fk.GameOverJudge, fk.BuryVictim,
|
2022-04-30 07:27:56 +00:00
|
|
|
},
|
|
|
|
priority = 0,
|
2022-04-01 12:51:01 +00:00
|
|
|
|
2023-01-16 13:04:28 +00:00
|
|
|
can_refresh = function(self, event, target, player, data)
|
2022-04-30 07:27:56 +00:00
|
|
|
return (target == player) or (target == nil)
|
|
|
|
end,
|
2022-04-01 12:51:01 +00:00
|
|
|
|
2023-01-16 13:04:28 +00:00
|
|
|
on_refresh = function(self, event, target, player, data)
|
2023-04-08 12:45:55 +00:00
|
|
|
local room = player.room
|
|
|
|
if room:getTag("SkipGameRule") then
|
|
|
|
room:setTag("SkipGameRule", false)
|
2022-04-30 07:27:56 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2023-01-29 10:11:41 +00:00
|
|
|
if event == fk.GameStart then
|
2023-04-08 12:45:55 +00:00
|
|
|
room:setTag("FirstRound", true)
|
|
|
|
room:setTag("RoundCount", 0)
|
2022-04-30 07:27:56 +00:00
|
|
|
return false
|
|
|
|
end
|
2022-04-02 13:39:44 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
switch(event, {
|
|
|
|
[fk.DrawInitialCards] = function()
|
|
|
|
if data.num > 0 then
|
|
|
|
-- TODO: need a new function to call the UI
|
|
|
|
local cardIds = room:getNCards(data.num)
|
|
|
|
player:addCards(Player.Hand, cardIds)
|
2023-02-15 11:54:35 +00:00
|
|
|
for _, id in ipairs(cardIds) do
|
|
|
|
Fk:filterCard(id, player)
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
local move_to_notify = {} ---@type CardsMoveStruct
|
|
|
|
move_to_notify.toArea = Card.PlayerHand
|
2022-05-02 06:00:47 +00:00
|
|
|
move_to_notify.to = player.id
|
2022-04-30 07:27:56 +00:00
|
|
|
move_to_notify.moveInfo = {}
|
2022-12-18 04:52:52 +00:00
|
|
|
move_to_notify.moveReason = fk.ReasonDraw
|
2022-04-30 07:27:56 +00:00
|
|
|
for _, id in ipairs(cardIds) do
|
2023-02-26 08:51:29 +00:00
|
|
|
table.insert(move_to_notify.moveInfo,
|
2022-04-30 07:27:56 +00:00
|
|
|
{ cardId = id, fromArea = Card.DrawPile })
|
2022-04-02 07:11:13 +00:00
|
|
|
end
|
2022-12-20 04:51:54 +00:00
|
|
|
room:notifyMoveCards(nil, {move_to_notify})
|
2022-04-02 13:39:44 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
for _, id in ipairs(cardIds) do
|
2022-09-14 05:01:10 +00:00
|
|
|
room:setCardArea(id, Card.PlayerHand, player.id)
|
2022-04-30 07:27:56 +00:00
|
|
|
end
|
2022-04-08 10:39:58 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
room.logic:trigger(fk.AfterDrawInitialCards, player, data)
|
|
|
|
end
|
|
|
|
end,
|
2023-04-08 12:45:55 +00:00
|
|
|
[fk.RoundStart] = function()
|
|
|
|
if room:getTag("FirstRound") then
|
|
|
|
room:setTag("FirstRound", false)
|
2022-04-30 07:27:56 +00:00
|
|
|
end
|
2022-04-08 10:39:58 +00:00
|
|
|
|
2023-04-08 12:45:55 +00:00
|
|
|
room:setTag("RoundCount", room:getTag("RoundCount") + 1)
|
2023-04-19 16:19:48 +00:00
|
|
|
room:doBroadcastNotify("UpdateRoundNum", room:getTag("RoundCount"))
|
2023-04-08 12:45:55 +00:00
|
|
|
|
|
|
|
for _, p in ipairs(room.players) do
|
|
|
|
p:setCardUseHistory("", 0, Player.HistoryRound)
|
|
|
|
p:setSkillUseHistory("", 0, Player.HistoryRound)
|
|
|
|
for name, _ in pairs(p.mark) do
|
|
|
|
if name:endsWith("-round") then
|
|
|
|
room:setPlayerMark(p, name, 0)
|
|
|
|
end
|
2023-01-29 10:11:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-18 04:52:52 +00:00
|
|
|
room:sendLog{ type = "$AppendSeparator" }
|
2023-04-08 12:45:55 +00:00
|
|
|
end,
|
|
|
|
[fk.TurnStart] = function()
|
2022-04-30 07:27:56 +00:00
|
|
|
if not player.faceup then
|
|
|
|
player:turnOver()
|
|
|
|
elseif not player.dead then
|
|
|
|
player:play()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
[fk.EventPhaseProceeding] = function()
|
|
|
|
switch(player.phase, {
|
|
|
|
[Player.PhaseNone] = function()
|
|
|
|
error("You should never proceed PhaseNone")
|
|
|
|
end,
|
|
|
|
[Player.RoundStart] = function()
|
2023-02-26 08:51:29 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
end,
|
|
|
|
[Player.Start] = function()
|
2023-02-26 08:51:29 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
end,
|
|
|
|
[Player.Judge] = function()
|
2022-12-20 10:40:17 +00:00
|
|
|
local cards = player:getCardIds(Player.Judge)
|
|
|
|
for i = #cards, 1, -1 do
|
2023-01-29 10:11:41 +00:00
|
|
|
local card
|
|
|
|
card = player:removeVirtualEquip(cards[i])
|
|
|
|
if not card then
|
|
|
|
card = Fk:getCardById(cards[i])
|
|
|
|
end
|
2022-12-20 10:40:17 +00:00
|
|
|
room:moveCardTo(card, Card.Processing, nil, fk.ReasonPut, self.name)
|
|
|
|
|
|
|
|
---@type CardEffectEvent
|
|
|
|
local effect_data = {
|
2023-01-16 11:13:07 +00:00
|
|
|
card = card,
|
2022-12-20 10:40:17 +00:00
|
|
|
to = player.id,
|
|
|
|
tos = { {player.id} },
|
|
|
|
}
|
|
|
|
room:doCardEffect(effect_data)
|
|
|
|
if effect_data.isCancellOut and card.skill then
|
|
|
|
card.skill:onNullified(room, effect_data)
|
|
|
|
end
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
end,
|
|
|
|
[Player.Draw] = function()
|
2023-01-21 16:49:11 +00:00
|
|
|
local data = {
|
|
|
|
n = 2
|
|
|
|
}
|
|
|
|
room.logic:trigger(fk.DrawNCards, player, data)
|
|
|
|
room:drawCards(player, data.n, self.name)
|
|
|
|
room.logic:trigger(fk.AfterDrawNCards, player, data)
|
2022-04-30 07:27:56 +00:00
|
|
|
end,
|
|
|
|
[Player.Play] = function()
|
|
|
|
while not player.dead do
|
2022-05-01 10:37:13 +00:00
|
|
|
room:notifyMoveFocus(player, "PlayCard")
|
2022-05-02 06:00:47 +00:00
|
|
|
local result = room:doRequest(player, "PlayCard", player.id)
|
2022-04-30 07:27:56 +00:00
|
|
|
if result == "" then break end
|
2022-04-02 13:39:44 +00:00
|
|
|
|
2023-01-16 11:13:07 +00:00
|
|
|
local use = room:handleUseCardReply(player, result)
|
|
|
|
if use then
|
2022-09-14 05:01:10 +00:00
|
|
|
room:useCard(use)
|
2022-04-30 07:27:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
[Player.Discard] = function()
|
|
|
|
local discardNum = #player:getCardIds(Player.Hand) - player:getMaxCards()
|
|
|
|
if discardNum > 0 then
|
|
|
|
room:askForDiscard(player, discardNum, discardNum, false, self.name)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
[Player.Finish] = function()
|
2023-02-26 08:51:29 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
end,
|
|
|
|
[Player.NotActive] = function()
|
2023-02-26 08:51:29 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
[fk.EventPhaseEnd] = function()
|
|
|
|
if player.phase == Player.Play then
|
2023-02-27 03:59:24 +00:00
|
|
|
for _, p in ipairs(room.players) do
|
|
|
|
p:setCardUseHistory("", 0, Player.HistoryPhase)
|
|
|
|
p:setSkillUseHistory("", 0, Player.HistoryPhase)
|
2023-04-08 12:45:55 +00:00
|
|
|
for name, _ in pairs(p.mark) do
|
|
|
|
if name:endsWith("-phase") then
|
|
|
|
room:setPlayerMark(p, name, 0)
|
|
|
|
end
|
|
|
|
end
|
2023-02-27 03:59:24 +00:00
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
[fk.EventPhaseChanging] = function()
|
|
|
|
-- TODO: copy but dont copy all
|
2023-01-29 10:11:41 +00:00
|
|
|
if data.to == Player.NotActive then
|
2023-02-27 03:59:24 +00:00
|
|
|
for _, p in ipairs(room.players) do
|
|
|
|
p:setCardUseHistory("", 0, Player.HistoryTurn)
|
|
|
|
p:setSkillUseHistory("", 0, Player.HistoryTurn)
|
2023-04-08 12:45:55 +00:00
|
|
|
for name, _ in pairs(p.mark) do
|
|
|
|
if name:endsWith("-turn") then
|
|
|
|
room:setPlayerMark(p, name, 0)
|
|
|
|
end
|
|
|
|
end
|
2023-02-27 03:59:24 +00:00
|
|
|
end
|
2023-01-29 10:11:41 +00:00
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
end,
|
2022-12-20 04:51:54 +00:00
|
|
|
[fk.AskForPeaches] = function()
|
2023-04-04 08:25:37 +00:00
|
|
|
local dyingPlayer = room:getPlayerById(data.who)
|
|
|
|
while dyingPlayer.hp < 1 do
|
|
|
|
local pattern = "peach"
|
|
|
|
if player == dyingPlayer then
|
|
|
|
pattern = pattern .. ",analeptic"
|
|
|
|
end
|
2023-03-14 12:48:08 +00:00
|
|
|
|
2023-04-04 08:25:37 +00:00
|
|
|
local peach_use = room:askForUseCard(player, "peach", pattern)
|
|
|
|
if not peach_use then break end
|
|
|
|
peach_use.tos = { {dyingPlayer.id} }
|
|
|
|
if peach_use.card.trueName == "analeptic" then
|
|
|
|
peach_use.extra_data = peach_use.extra_data or {}
|
|
|
|
peach_use.extra_data.analepticRecover = true
|
2022-12-20 04:51:54 +00:00
|
|
|
end
|
2023-04-04 08:25:37 +00:00
|
|
|
room:useCard(peach_use)
|
2022-12-20 04:51:54 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
[fk.AskForPeachesDone] = function()
|
2023-04-04 08:25:37 +00:00
|
|
|
if player.hp < 1 and not data.ignoreDeath then
|
2022-12-20 04:51:54 +00:00
|
|
|
---@type DeathStruct
|
|
|
|
local deathData = {
|
|
|
|
who = player.id,
|
|
|
|
damage = data.damage,
|
|
|
|
}
|
|
|
|
room:killPlayer(deathData)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
[fk.GameOverJudge] = function()
|
|
|
|
local winner = getWinner(player)
|
|
|
|
if winner ~= "" then
|
|
|
|
room:gameOver(winner)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
[fk.BuryVictim] = function()
|
|
|
|
player:bury()
|
|
|
|
if room.tag["SkipNormalDeathProcess"] then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
local damage = data.damage
|
|
|
|
if damage and damage.from then
|
2023-02-15 11:54:35 +00:00
|
|
|
local killer = damage.from
|
2022-12-20 04:51:54 +00:00
|
|
|
rewardAndPunish(killer, player);
|
|
|
|
end
|
|
|
|
end,
|
2022-04-30 07:27:56 +00:00
|
|
|
default = function()
|
|
|
|
print("game_rule: Event=" .. event)
|
|
|
|
room:askForSkillInvoke(player, "rule")
|
2022-04-02 07:11:13 +00:00
|
|
|
end,
|
2022-04-30 07:27:56 +00:00
|
|
|
})
|
|
|
|
return false
|
|
|
|
end,
|
2022-04-02 07:11:13 +00:00
|
|
|
|
2022-04-01 12:51:01 +00:00
|
|
|
}
|