2023-04-09 05:35:35 +00:00
|
|
|
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-02-28 17:43:44 +00:00
|
|
|
GameEvent.functions[GameEvent.Dying] = function(self)
|
|
|
|
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
|
2023-08-10 19:19:59 +00:00
|
|
|
if dyingPlayer.hp > 0 or dyingPlayer.dead or logic:trigger(fk.AskForPeaches, p, dyingStruct) then
|
2023-04-04 08:25:37 +00:00
|
|
|
break
|
|
|
|
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
|
|
|
|
|
|
|
|
GameEvent.exit_funcs[GameEvent.Dying] = function(self)
|
|
|
|
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
|
|
|
|
|
2023-08-11 16:50:17 +00:00
|
|
|
GameEvent.prepare_funcs[GameEvent.Death] = function(self)
|
|
|
|
local deathStruct = table.unpack(self.data)
|
|
|
|
local room = self.room
|
|
|
|
local victim = room:getPlayerById(deathStruct.who)
|
|
|
|
if victim.dead then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-28 17:43:44 +00:00
|
|
|
GameEvent.functions[GameEvent.Death] = function(self)
|
|
|
|
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-06-16 15:04:31 +00:00
|
|
|
victim._splayer:setDied(true)
|
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,
|
|
|
|
arg = victim.role,
|
|
|
|
}
|
|
|
|
else
|
2023-08-10 19:19:59 +00:00
|
|
|
room:sendLog{
|
2023-02-28 17:43:44 +00:00
|
|
|
type = "#KillPlayerWithNoKiller",
|
|
|
|
from = victim.id,
|
|
|
|
arg = victim.role,
|
|
|
|
}
|
|
|
|
end
|
2023-08-10 19:19:59 +00:00
|
|
|
room:sendLogEvent("Death", {to = victim.id})
|
2023-02-28 17:43:44 +00:00
|
|
|
|
2023-08-10 19:19:59 +00:00
|
|
|
room:broadcastProperty(victim, "role")
|
|
|
|
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-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
|