40 lines
1.6 KiB
C#
40 lines
1.6 KiB
C#
using IntoTheAbyss.Events;
|
|
using IntoTheAbyss.Runtime.Scripts;
|
|
using RPGCore.Core.Objects;
|
|
using RPGCore.ObjectModules.EventObjectModule;
|
|
using RPGCore.StatusEffect.ObjectModules.StatusObjectModule;
|
|
using RPGCoreCommon.Settings;
|
|
|
|
namespace IntoTheAbyss.ObjectExtensions
|
|
{
|
|
public static class BaseObjectExtensions
|
|
{
|
|
/// <summary>Try to kill this object.</summary>
|
|
public static void Death(this BaseObject obj)
|
|
{
|
|
var deathStatusDefinitionSO = SettingsManager.Get<IntoTheAbyssSettings>().deathStatusDefinitionSO;
|
|
if (obj.GetComponent<StatusModule>().Check(deathStatusDefinitionSO)) return;
|
|
|
|
var deathEvent = new DeathEvent { target = obj };
|
|
|
|
obj.events.InvokeBefore(deathEvent);
|
|
if (deathEvent.isPrevented) return;
|
|
obj.GetComponent<StatusModule>().Apply(deathStatusDefinitionSO);
|
|
obj.events.InvokeAfter(deathEvent);
|
|
}
|
|
|
|
/// <summary>Try to revive this object.</summary>
|
|
public static void Revive(this BaseObject obj)
|
|
{
|
|
var deathStatusDefinitionSO = SettingsManager.Get<IntoTheAbyssSettings>().deathStatusDefinitionSO;
|
|
if (obj.GetComponent<StatusModule>().Check(deathStatusDefinitionSO) == false) return;
|
|
|
|
var reviveEvent = new ReviveEvent { target = obj };
|
|
|
|
obj.events.InvokeBefore(reviveEvent);
|
|
if (reviveEvent.isPrevented) return;
|
|
obj.GetComponent<StatusModule>().Remove(deathStatusDefinitionSO);
|
|
obj.events.InvokeAfter(reviveEvent);
|
|
}
|
|
}
|
|
} |