2020-12-14 16:24:52 +00:00
|
|
|
|
using QSB.Events;
|
2020-12-14 19:31:31 +00:00
|
|
|
|
using QSB.Patches;
|
2020-12-14 21:20:53 +00:00
|
|
|
|
using System.Linq;
|
2020-08-13 19:46:16 +00: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 19:46:16 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
RespawnOnDeath.Instance.ResetShip();
|
|
|
|
|
RespawnOnDeath.Instance.ResetPlayer();
|
2020-08-13 19:46:16 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
// Prevent original death method from running.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-08-13 19:46:16 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public static void BroadcastDeath(DeathType deathType) => GlobalMessenger<DeathType>.FireEvent(EventNames.QSBPlayerDeath, deathType);
|
2020-08-23 13:51:45 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public override void DoPatches()
|
|
|
|
|
{
|
2020-12-14 16:24:52 +00:00
|
|
|
|
QSBCore.Helper.HarmonyHelper.AddPrefix<DeathManager>("KillPlayer", typeof(DeathPatches), nameof(PreFinishDeathSequence));
|
|
|
|
|
QSBCore.Helper.HarmonyHelper.AddPostfix<DeathManager>("KillPlayer", typeof(DeathPatches), nameof(BroadcastDeath));
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-13 19:46:16 +00:00
|
|
|
|
}
|