Adds repeating DoAfters to Food and Drink (#15233)

This commit is contained in:
keronshb
2023-04-15 18:14:26 -04:00
committed by GitHub
parent 39e59f11bf
commit c6aae19a16
7 changed files with 33 additions and 11 deletions

View File

@@ -127,6 +127,7 @@ public sealed class DoAfterArgs
[DataField("blockDuplicate")]
public bool BlockDuplicate = true;
//TODO: User pref to not cancel on second use on specific doafters
/// <summary>
/// If true, this will cancel any duplicate DoAfters when attempting to add a new DoAfter. See also
/// <see cref="DuplicateConditions"/>.
@@ -206,6 +207,7 @@ public sealed class DoAfterArgs
#endregion
//The almighty pyramid returns.......
public DoAfterArgs(DoAfterArgs other)
{
User = other.User;

View File

@@ -15,6 +15,12 @@ public abstract class DoAfterEvent : HandledEntityEventArgs
[NonSerialized]
public DoAfter DoAfter = default!;
//TODO: User pref to toggle repeat on specific doafters
/// <summary>
/// If set to true while handling this event, then the DoAfter will automatically be repeated.
/// </summary>
public bool Repeat = false;
/// <summary>
/// Duplicate the current event. This is used by state handling, and should copy by value unless the reference
/// types are immutable.

View File

@@ -117,7 +117,14 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
}
doAfter.Completed = true;
RaiseDoAfterEvents(doAfter, component);
if (doAfter.Args.Event.Repeat)
{
doAfter.StartTime = GameTiming.CurTime;
doAfter.Completed = false;
}
}
private bool ShouldCancel(DoAfter doAfter,

View File

@@ -83,6 +83,8 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
private void RaiseDoAfterEvents(DoAfter doAfter, DoAfterComponent component)
{
var ev = doAfter.Args.Event;
ev.Handled = false;
ev.Repeat = false;
ev.DoAfter = doAfter;
if (Exists(doAfter.Args.EventTarget))