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