FreeKill/lua/server/events/death.lua
Ho-spair 19a2cc5ed7
Initial kingdom choosing (#143)
- 实现副势力概念,用于应对双势力机制;
- 完善神将及拥有副势力的武将开局选择势力的机制;
- 完成势力技概念;
- 实现ViewAsSkill在响应时对使用和打出的区分。

---------

Co-authored-by: notify <notify-ctrl@qq.com>
2023-04-30 18:55:59 +08:00

72 lines
2.1 KiB
Lua

-- SPDX-License-Identifier: GPL-3.0-or-later
GameEvent.functions[GameEvent.Dying] = function(self)
local dyingStruct = table.unpack(self.data)
local self = self.room
local dyingPlayer = self:getPlayerById(dyingStruct.who)
dyingPlayer.dying = true
self:broadcastProperty(dyingPlayer, "dying")
self:sendLog{
type = "#EnterDying",
from = dyingPlayer.id,
}
self.logic:trigger(fk.EnterDying, dyingPlayer, dyingStruct)
if dyingPlayer.hp < 1 then
-- self.logic:trigger(fk.Dying, dyingPlayer, dyingStruct)
local savers = self:getAlivePlayers()
for _, p in ipairs(savers) do
if dyingPlayer.hp > 0 or dyingPlayer.dead or self.logic:trigger(fk.AskForPeaches, p, dyingStruct) then
break
end
end
self.logic:trigger(fk.AskForPeachesDone, dyingPlayer, dyingStruct)
end
if not dyingPlayer.dead and dyingPlayer.dying then
dyingPlayer.dying = false
self:broadcastProperty(dyingPlayer, "dying")
end
self.logic:trigger(fk.AfterDying, dyingPlayer, dyingStruct)
end
GameEvent.functions[GameEvent.Death] = function(self)
local deathStruct = table.unpack(self.data)
local self = self.room
local victim = self:getPlayerById(deathStruct.who)
victim.dead = true
table.removeOne(self.alive_players, victim)
local logic = self.logic
logic:trigger(fk.BeforeGameOverJudge, victim, deathStruct)
local killer = deathStruct.damage and deathStruct.damage.from or nil
if killer then
self:sendLog{
type = "#KillPlayer",
to = {killer.id},
from = victim.id,
arg = victim.role,
}
else
self:sendLog{
type = "#KillPlayerWithNoKiller",
from = victim.id,
arg = victim.role,
}
end
self:sendLogEvent("Death", {to = victim.id})
self:broadcastProperty(victim, "role")
self:broadcastProperty(victim, "dead")
victim.drank = 0
self:broadcastProperty(victim, "drank")
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