2020-11-03 21:42:14 +00:00
|
|
|
|
using QSB.EventsCore;
|
2020-08-21 14:04:13 +01:00
|
|
|
|
using System.Linq;
|
2020-08-13 21:46:16 +02:00
|
|
|
|
|
|
|
|
|
namespace QSB.DeathSync
|
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class DeathPatches : QSBPatch
|
|
|
|
|
{
|
|
|
|
|
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;
|
2020-11-03 21:11:10 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public static bool PreFinishDeathSequence(DeathType deathType)
|
|
|
|
|
{
|
|
|
|
|
if (RespawnOnDeath.Instance.AllowedDeathTypes.Contains(deathType))
|
|
|
|
|
{
|
|
|
|
|
// Allow real death
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-08-13 21:46:16 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
RespawnOnDeath.Instance.ResetShip();
|
|
|
|
|
RespawnOnDeath.Instance.ResetPlayer();
|
2020-08-13 21:46:16 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
// Prevent original death method from running.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-08-13 21:46:16 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public static void BroadcastDeath(DeathType deathType) => GlobalMessenger<DeathType>.FireEvent(EventNames.QSBPlayerDeath, deathType);
|
2020-08-23 15:51:45 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public override void DoPatches()
|
|
|
|
|
{
|
|
|
|
|
QSB.Helper.HarmonyHelper.AddPrefix<DeathManager>("KillPlayer", typeof(DeathPatches), nameof(PreFinishDeathSequence));
|
|
|
|
|
QSB.Helper.HarmonyHelper.AddPostfix<DeathManager>("KillPlayer", typeof(DeathPatches), nameof(BroadcastDeath));
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-13 21:46:16 +02:00
|
|
|
|
}
|