2023-04-09 05:35:35 +00:00
|
|
|
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2024-06-10 07:19:47 +00:00
|
|
|
---@class GameEvent.Dying : GameEvent
|
|
|
|
local Dying = GameEvent:subclass("GameEvent.Dying")
|
|
|
|
function Dying:main()
|
2023-02-28 17:43:44 +00:00
|
|
|
local dyingStruct = table.unpack(self.data)
|
2023-08-10 19:19:59 +00:00
|
|
|
local room = self.room
|
|
|
|
local logic = room.logic
|
|
|
|
local dyingPlayer = room:getPlayerById(dyingStruct.who)
|
2023-02-28 17:43:44 +00:00
|
|
|
dyingPlayer.dying = true
|
2023-08-10 19:19:59 +00:00
|
|
|
room:broadcastProperty(dyingPlayer, "dying")
|
|
|
|
room:sendLog{
|
2023-02-28 17:43:44 +00:00
|
|
|
type = "#EnterDying",
|
|
|
|
from = dyingPlayer.id,
|
|
|
|
}
|
2023-08-10 19:19:59 +00:00
|
|
|
logic:trigger(fk.EnterDying, dyingPlayer, dyingStruct)
|
2023-02-28 17:43:44 +00:00
|
|
|
|
|
|
|
if dyingPlayer.hp < 1 then
|
2023-08-10 19:19:59 +00:00
|
|
|
-- room.logic:trigger(fk.Dying, dyingPlayer, dyingStruct)
|
|
|
|
local savers = room:getAlivePlayers()
|
2023-04-04 08:25:37 +00:00
|
|
|
for _, p in ipairs(savers) do
|
2024-01-29 02:19:10 +00:00
|
|
|
if not p.dead then
|
|
|
|
if dyingPlayer.hp > 0 or dyingPlayer.dead or logic:trigger(fk.AskForPeaches, p, dyingStruct) then
|
|
|
|
break
|
|
|
|
end
|
2023-04-04 08:25:37 +00:00
|
|
|
end
|
|
|
|
end
|
2023-08-10 19:19:59 +00:00
|
|
|
logic:trigger(fk.AskForPeachesDone, dyingPlayer, dyingStruct)
|
2023-02-28 17:43:44 +00:00
|
|
|
end
|
2023-08-12 17:40:08 +00:00
|
|
|
end
|
|
|
|
|
2024-06-10 07:19:47 +00:00
|
|
|
function Dying:exit()
|
2023-08-12 17:40:08 +00:00
|
|
|
local room = self.room
|
|
|
|
local logic = room.logic
|
|
|
|
local dyingStruct = self.data[1]
|
|
|
|
|
|
|
|
local dyingPlayer = room:getPlayerById(dyingStruct.who)
|
2023-02-28 17:43:44 +00:00
|
|
|
|
2023-08-12 17:40:08 +00:00
|
|
|
if dyingPlayer.dying then
|
2023-02-28 17:43:44 +00:00
|
|
|
dyingPlayer.dying = false
|
2023-08-10 19:19:59 +00:00
|
|
|
room:broadcastProperty(dyingPlayer, "dying")
|
2023-02-28 17:43:44 +00:00
|
|
|
end
|
2023-08-12 17:40:08 +00:00
|
|
|
logic:trigger(fk.AfterDying, dyingPlayer, dyingStruct, self.interrupted)
|
2023-02-28 17:43:44 +00:00
|
|
|
end
|
|
|
|
|
2024-06-10 07:19:47 +00:00
|
|
|
---@class GameEvent.Death : GameEvent
|
|
|
|
local Death = GameEvent:subclass("GameEvent.Death")
|
|
|
|
function Death:prepare()
|
2023-08-11 16:50:17 +00:00
|
|
|
local deathStruct = table.unpack(self.data)
|
|
|
|
local room = self.room
|
|
|
|
local victim = room:getPlayerById(deathStruct.who)
|
|
|
|
if victim.dead then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-10 07:19:47 +00:00
|
|
|
function Death:main()
|
2023-02-28 17:43:44 +00:00
|
|
|
local deathStruct = table.unpack(self.data)
|
2023-08-10 19:19:59 +00:00
|
|
|
local room = self.room
|
|
|
|
local victim = room:getPlayerById(deathStruct.who)
|
2023-02-28 17:43:44 +00:00
|
|
|
victim.dead = true
|
2023-12-10 10:55:16 +00:00
|
|
|
|
|
|
|
if victim.rest <= 0 then
|
|
|
|
victim._splayer:setDied(true)
|
|
|
|
end
|
|
|
|
|
2023-08-10 19:19:59 +00:00
|
|
|
table.removeOne(room.alive_players, victim)
|
2023-02-28 17:43:44 +00:00
|
|
|
|
2023-08-10 19:19:59 +00:00
|
|
|
local logic = room.logic
|
2023-02-28 17:43:44 +00:00
|
|
|
logic:trigger(fk.BeforeGameOverJudge, victim, deathStruct)
|
|
|
|
|
|
|
|
local killer = deathStruct.damage and deathStruct.damage.from or nil
|
|
|
|
if killer then
|
2023-08-10 19:19:59 +00:00
|
|
|
room:sendLog{
|
2023-02-28 17:43:44 +00:00
|
|
|
type = "#KillPlayer",
|
|
|
|
to = {killer.id},
|
|
|
|
from = victim.id,
|
2023-12-10 10:55:16 +00:00
|
|
|
arg = (victim.rest > 0 and 'unknown' or victim.role),
|
2023-02-28 17:43:44 +00:00
|
|
|
}
|
|
|
|
else
|
2023-08-10 19:19:59 +00:00
|
|
|
room:sendLog{
|
2023-02-28 17:43:44 +00:00
|
|
|
type = "#KillPlayerWithNoKiller",
|
|
|
|
from = victim.id,
|
2023-12-10 10:55:16 +00:00
|
|
|
arg = (victim.rest > 0 and 'unknown' or victim.role),
|
2023-02-28 17:43:44 +00:00
|
|
|
}
|
|
|
|
end
|
2023-08-10 19:19:59 +00:00
|
|
|
room:sendLogEvent("Death", {to = victim.id})
|
2023-02-28 17:43:44 +00:00
|
|
|
|
2023-12-10 10:55:16 +00:00
|
|
|
if victim.rest == 0 then
|
|
|
|
room:broadcastProperty(victim, "role")
|
|
|
|
end
|
2023-08-10 19:19:59 +00:00
|
|
|
room:broadcastProperty(victim, "dead")
|
2023-02-28 17:43:44 +00:00
|
|
|
|
2023-03-14 12:48:08 +00:00
|
|
|
victim.drank = 0
|
2023-08-10 19:19:59 +00:00
|
|
|
room:broadcastProperty(victim, "drank")
|
2023-12-10 10:55:16 +00:00
|
|
|
victim.shield = 0
|
|
|
|
room:broadcastProperty(victim, "shield")
|
2023-03-14 12:48:08 +00:00
|
|
|
|
2023-02-28 17:43:44 +00:00
|
|
|
logic:trigger(fk.GameOverJudge, victim, deathStruct)
|
|
|
|
logic:trigger(fk.Death, victim, deathStruct)
|
|
|
|
logic:trigger(fk.BuryVictim, victim, deathStruct)
|
2023-04-30 10:55:59 +00:00
|
|
|
|
|
|
|
logic:trigger(fk.Deathed, victim, deathStruct)
|
2023-02-28 17:43:44 +00:00
|
|
|
end
|
2023-12-10 10:55:16 +00:00
|
|
|
|
2024-06-10 07:19:47 +00:00
|
|
|
---@class GameEvent.Revive : GameEvent
|
|
|
|
local Revive = GameEvent:subclass("GameEvent.Revive")
|
|
|
|
function Revive:main()
|
2023-12-10 10:55:16 +00:00
|
|
|
local room = self.room
|
|
|
|
local player, sendLog, reason = table.unpack(self.data)
|
|
|
|
|
|
|
|
if not player.dead then return end
|
|
|
|
room:setPlayerProperty(player, "dead", false)
|
|
|
|
player._splayer:setDied(false)
|
|
|
|
room:setPlayerProperty(player, "dying", false)
|
|
|
|
room:setPlayerProperty(player, "hp", player.maxHp)
|
|
|
|
table.insertIfNeed(room.alive_players, player)
|
|
|
|
|
|
|
|
sendLog = (sendLog == nil) and true or sendLog
|
|
|
|
if sendLog then
|
|
|
|
room:sendLog { type = "#Revive", from = player.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
reason = reason or ""
|
|
|
|
room.logic:trigger(fk.AfterPlayerRevived, player, { reason = reason })
|
|
|
|
end
|
2024-06-10 07:19:47 +00:00
|
|
|
|
|
|
|
return { Dying, Death, Revive }
|