2023-04-09 13:35:35 +08:00
|
|
|
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-03-01 01:43:44 +08:00
|
|
|
GameEvent.functions[GameEvent.Dying] = function(self)
|
|
|
|
local dyingStruct = table.unpack(self.data)
|
2023-08-11 03:19:59 +08:00
|
|
|
local room = self.room
|
|
|
|
local logic = room.logic
|
|
|
|
local dyingPlayer = room:getPlayerById(dyingStruct.who)
|
2023-03-01 01:43:44 +08:00
|
|
|
dyingPlayer.dying = true
|
2023-08-11 03:19:59 +08:00
|
|
|
room:broadcastProperty(dyingPlayer, "dying")
|
|
|
|
room:sendLog{
|
2023-03-01 01:43:44 +08:00
|
|
|
type = "#EnterDying",
|
|
|
|
from = dyingPlayer.id,
|
|
|
|
}
|
2023-08-11 03:19:59 +08:00
|
|
|
logic:trigger(fk.EnterDying, dyingPlayer, dyingStruct)
|
2023-03-01 01:43:44 +08:00
|
|
|
|
|
|
|
if dyingPlayer.hp < 1 then
|
2023-08-11 03:19:59 +08:00
|
|
|
-- room.logic:trigger(fk.Dying, dyingPlayer, dyingStruct)
|
|
|
|
local savers = room:getAlivePlayers()
|
2023-04-04 16:25:37 +08:00
|
|
|
for _, p in ipairs(savers) do
|
2023-08-11 03:19:59 +08:00
|
|
|
if dyingPlayer.hp > 0 or dyingPlayer.dead or logic:trigger(fk.AskForPeaches, p, dyingStruct) then
|
2023-04-04 16:25:37 +08:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2023-08-11 03:19:59 +08:00
|
|
|
logic:trigger(fk.AskForPeachesDone, dyingPlayer, dyingStruct)
|
2023-03-01 01:43:44 +08:00
|
|
|
end
|
|
|
|
|
2023-04-04 16:25:37 +08:00
|
|
|
if not dyingPlayer.dead and dyingPlayer.dying then
|
2023-03-01 01:43:44 +08:00
|
|
|
dyingPlayer.dying = false
|
2023-08-11 03:19:59 +08:00
|
|
|
room:broadcastProperty(dyingPlayer, "dying")
|
2023-03-01 01:43:44 +08:00
|
|
|
end
|
2023-08-11 03:19:59 +08:00
|
|
|
logic:trigger(fk.AfterDying, dyingPlayer, dyingStruct)
|
2023-03-01 01:43:44 +08:00
|
|
|
end
|
|
|
|
|
2023-08-12 00:50:17 +08: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-03-01 01:43:44 +08:00
|
|
|
GameEvent.functions[GameEvent.Death] = function(self)
|
|
|
|
local deathStruct = table.unpack(self.data)
|
2023-08-11 03:19:59 +08:00
|
|
|
local room = self.room
|
|
|
|
local victim = room:getPlayerById(deathStruct.who)
|
2023-03-01 01:43:44 +08:00
|
|
|
victim.dead = true
|
2023-06-16 23:04:31 +08:00
|
|
|
victim._splayer:setDied(true)
|
2023-08-11 03:19:59 +08:00
|
|
|
table.removeOne(room.alive_players, victim)
|
2023-03-01 01:43:44 +08:00
|
|
|
|
2023-08-11 03:19:59 +08:00
|
|
|
local logic = room.logic
|
2023-03-01 01:43:44 +08:00
|
|
|
logic:trigger(fk.BeforeGameOverJudge, victim, deathStruct)
|
|
|
|
|
|
|
|
local killer = deathStruct.damage and deathStruct.damage.from or nil
|
|
|
|
if killer then
|
2023-08-11 03:19:59 +08:00
|
|
|
room:sendLog{
|
2023-03-01 01:43:44 +08:00
|
|
|
type = "#KillPlayer",
|
|
|
|
to = {killer.id},
|
|
|
|
from = victim.id,
|
|
|
|
arg = victim.role,
|
|
|
|
}
|
|
|
|
else
|
2023-08-11 03:19:59 +08:00
|
|
|
room:sendLog{
|
2023-03-01 01:43:44 +08:00
|
|
|
type = "#KillPlayerWithNoKiller",
|
|
|
|
from = victim.id,
|
|
|
|
arg = victim.role,
|
|
|
|
}
|
|
|
|
end
|
2023-08-11 03:19:59 +08:00
|
|
|
room:sendLogEvent("Death", {to = victim.id})
|
2023-03-01 01:43:44 +08:00
|
|
|
|
2023-08-11 03:19:59 +08:00
|
|
|
room:broadcastProperty(victim, "role")
|
|
|
|
room:broadcastProperty(victim, "dead")
|
2023-03-01 01:43:44 +08:00
|
|
|
|
2023-03-14 20:48:08 +08:00
|
|
|
victim.drank = 0
|
2023-08-11 03:19:59 +08:00
|
|
|
room:broadcastProperty(victim, "drank")
|
2023-03-14 20:48:08 +08:00
|
|
|
|
2023-03-01 01:43:44 +08:00
|
|
|
logic:trigger(fk.GameOverJudge, victim, deathStruct)
|
|
|
|
logic:trigger(fk.Death, victim, deathStruct)
|
|
|
|
logic:trigger(fk.BuryVictim, victim, deathStruct)
|
2023-04-30 18:55:59 +08:00
|
|
|
|
|
|
|
logic:trigger(fk.Deathed, victim, deathStruct)
|
2023-03-01 01:43:44 +08:00
|
|
|
end
|