5 using System.Collections.Generic;
15 [
Serialize(
"",
IsPropertySaveable.Yes, description:
"Tag of the item that must be used. Note that the item needs to have been tagged by the event - this does not refer to the tags that can be set per-item in the sub editor.")]
18 [
Serialize(
"",
IsPropertySaveable.Yes, description:
"Tag of the character that must use the item. If there's multiple matching characters, it's enough if any of them use the item. If empty, it doesn't matter who uses the item.")]
21 [
Serialize(
"",
IsPropertySaveable.Yes, description:
"Name of the ItemComponent that the character must use. If empty, the character attempts to use all of them.")]
30 [
Serialize(
"",
IsPropertySaveable.Yes, description:
"Optional tag to apply to the hull the target item is inside when the item is used.")]
33 [
Serialize(
"",
IsPropertySaveable.Yes, description:
"Optional tag to apply to the hull the target item is inside, and all the hulls it's linked to, when the item is used.")]
39 private bool isFinished;
41 private readonly HashSet<Entity> targets =
new HashSet<Entity>();
42 private readonly HashSet<ItemComponent> targetComponents =
new HashSet<ItemComponent>();
44 private int useCount = 0;
46 private Identifier onUseEventIdentifier;
47 private Identifier OnUseEventIdentifier
51 if (onUseEventIdentifier.IsEmpty)
55 return onUseEventIdentifier;
63 DebugConsole.ThrowError($
"Error in event \"{ParentEvent.Prefab.Identifier}\". {nameof(ItemTag)} not set in {nameof(WaitForItemUsedAction)}.");
90 public override void Update(
float deltaTime)
95 private void TryRegisterTargets()
100 if (targets.Contains(target)) {
continue; }
101 if (target is not Item item) {
continue; }
104 item.GetComponents<
ItemComponent>().ForEach(ic => Register(ic));
108 Register(targetItemComponent);
113 DebugConsole.ThrowError($
"Failed to find the component {TargetItemComponent} on item {item.Prefab.Identifier}");
119 targets.Add(ic.
Item);
120 targetComponents.Add(ic);
121 ic.
OnUsed.RegisterOverwriteExisting(
122 OnUseEventIdentifier,
123 i => { OnItemUsed(i.Item, i.User); });
127 private void DeregisterTargets()
131 ic.
OnUsed.Deregister(OnUseEventIdentifier);
133 targetComponents.Clear();
152 return $
"{ToolBox.GetDebugSymbol(isFinished)} {nameof(WaitForItemUsedAction)} -> ({ItemTag})";
readonly ScriptedEvent ParentEvent
void ApplyTagsToHulls(Entity entity, Identifier hullTag, Identifier linkedHullTag)
The base class for components holding the different functionalities of the item
readonly NamedEvent< ItemUseInfo > OnUsed
readonly Identifier Identifier
void AddTarget(Identifier tag, Entity target)
List< EventAction > Actions
IEnumerable< Entity > GetTargets(Identifier tag)
Waits for some item(s) to be used before continuing the execution of the event.
override void Update(float deltaTime)
override bool IsFinished(ref string goTo)
Has the action finished.
Identifier ApplyTagToUser
Identifier ApplyTagToHull
Identifier ApplyTagToItem
WaitForItemUsedAction(ScriptedEvent parentEvent, ContentXElement element)
override string ToDebugString()
Rich test to display in debugdraw
Identifier ApplyTagToLinkedHulls
Identifier TargetItemComponent