2021-08-08 18:57:58 +00:00
|
|
|
|
using QSB.ClientServerStateSync;
|
|
|
|
|
using QSB.Events;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2021-11-18 11:34:14 +00:00
|
|
|
|
using QSB.RespawnSync;
|
2020-08-09 11:38:35 +00:00
|
|
|
|
using QSB.Utility;
|
2020-08-09 11:19:51 +00:00
|
|
|
|
|
2020-11-03 17:56:48 +00:00
|
|
|
|
namespace QSB.DeathSync.Events
|
2020-08-09 11:19:51 +00:00
|
|
|
|
{
|
2021-03-07 22:55:56 +00:00
|
|
|
|
public class PlayerDeathEvent : QSBEvent<PlayerDeathMessage>
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
public override EventType Type => EventType.PlayerDeath;
|
2020-08-09 11:38:35 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public override void SetupListener() => GlobalMessenger<DeathType>.AddListener(EventNames.QSBPlayerDeath, Handler);
|
|
|
|
|
public override void CloseListener() => GlobalMessenger<DeathType>.RemoveListener(EventNames.QSBPlayerDeath, Handler);
|
2020-08-15 19:32:58 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private void Handler(DeathType type) => SendEvent(CreateMessage(type));
|
2020-08-15 19:52:43 +00:00
|
|
|
|
|
2021-03-07 22:55:56 +00:00
|
|
|
|
private PlayerDeathMessage CreateMessage(DeathType type) => new PlayerDeathMessage
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
2021-03-29 13:36:16 +00:00
|
|
|
|
EnumValue = type,
|
2021-03-07 22:55:56 +00:00
|
|
|
|
NecronomiconIndex = Necronomicon.GetRandomIndex(type)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
};
|
2020-08-10 16:17:54 +00:00
|
|
|
|
|
2021-06-23 11:06:08 +00:00
|
|
|
|
public override void OnReceiveLocal(bool server, PlayerDeathMessage message)
|
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
|
|
|
|
RespawnManager.Instance.OnPlayerDeath(player);
|
2021-08-08 18:57:58 +00:00
|
|
|
|
ClientStateManager.Instance.OnDeath();
|
2021-06-23 11:06:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-07 22:55:56 +00:00
|
|
|
|
public override void OnReceiveRemote(bool server, PlayerDeathMessage message)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-06-23 11:06:08 +00:00
|
|
|
|
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
|
|
|
|
var playerName = player.Name;
|
2021-03-29 13:36:16 +00:00
|
|
|
|
var deathMessage = Necronomicon.GetPhrase(message.EnumValue, message.NecronomiconIndex);
|
2020-12-02 21:23:01 +00:00
|
|
|
|
DebugLog.ToAll(string.Format(deathMessage, playerName));
|
2021-06-23 11:06:08 +00:00
|
|
|
|
|
|
|
|
|
RespawnManager.Instance.OnPlayerDeath(player);
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|