FreeKill/lua/server/events/death.lua

129 lines
3.5 KiB
Lua
Raw Normal View History

-- 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()
local dyingStruct = table.unpack(self.data)
local room = self.room
local logic = room.logic
local dyingPlayer = room:getPlayerById(dyingStruct.who)
dyingPlayer.dying = true
room:broadcastProperty(dyingPlayer, "dying")
room:sendLog{
type = "#EnterDying",
from = dyingPlayer.id,
}
logic:trigger(fk.EnterDying, dyingPlayer, dyingStruct)
if dyingPlayer.hp < 1 then
-- room.logic:trigger(fk.Dying, dyingPlayer, dyingStruct)
local savers = room:getAlivePlayers()
for _, p in ipairs(savers) do
if not p.dead then
if dyingPlayer.hp > 0 or dyingPlayer.dead or logic:trigger(fk.AskForPeaches, p, dyingStruct) then
break
end
end
end
logic:trigger(fk.AskForPeachesDone, dyingPlayer, dyingStruct)
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-08-12 17:40:08 +00:00
if dyingPlayer.dying then
dyingPlayer.dying = false
room:broadcastProperty(dyingPlayer, "dying")
end
2023-08-12 17:40:08 +00:00
logic:trigger(fk.AfterDying, dyingPlayer, dyingStruct, self.interrupted)
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()
local deathStruct = table.unpack(self.data)
local room = self.room
local victim = room:getPlayerById(deathStruct.who)
victim.dead = true
if victim.rest <= 0 then
victim._splayer:setDied(true)
end
table.removeOne(room.alive_players, victim)
local logic = room.logic
logic:trigger(fk.BeforeGameOverJudge, victim, deathStruct)
local killer = deathStruct.damage and deathStruct.damage.from or nil
if killer then
room:sendLog{
type = "#KillPlayer",
to = {killer.id},
from = victim.id,
arg = (victim.rest > 0 and 'unknown' or victim.role),
}
else
room:sendLog{
type = "#KillPlayerWithNoKiller",
from = victim.id,
arg = (victim.rest > 0 and 'unknown' or victim.role),
}
end
room:sendLogEvent("Death", {to = victim.id})
if victim.rest == 0 then
room:broadcastProperty(victim, "role")
end
room:broadcastProperty(victim, "dead")
victim.drank = 0
room:broadcastProperty(victim, "drank")
victim.shield = 0
room:broadcastProperty(victim, "shield")
logic:trigger(fk.GameOverJudge, victim, deathStruct)
logic:trigger(fk.Death, victim, deathStruct)
logic:trigger(fk.BuryVictim, victim, deathStruct)
logic:trigger(fk.Deathed, victim, deathStruct)
end
2024-06-10 07:19:47 +00:00
---@class GameEvent.Revive : GameEvent
local Revive = GameEvent:subclass("GameEvent.Revive")
function Revive:main()
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 }