Aetheria/Assets/Scripts/ServerShared/Behaviors/ItemUsage.cs

33 lines
1 KiB
C#
Raw Normal View History

2026-06-13 04:56:50 +01:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Linq;
public class ItemUsage : Behavior
{
private readonly string _itemKey;
2026-06-15 19:06:13 +01:00
public ItemUsage(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
{
2026-06-15 19:06:13 +01:00
_itemKey = definition.ItemKey(1);
}
2026-06-15 19:06:13 +01:00
public ItemUsage(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
{
2026-06-15 19:06:13 +01:00
_itemKey = definition.ItemKey(1);
}
public override bool Execute(float dt)
{
var cargo = Entity.FindItemInCargo(_itemKey);
if (cargo == null) return false;
var item = cargo.GetFirstItem(_itemKey);
if (item is SimpleCommodity simpleCommodity)
cargo.Remove(simpleCommodity, 1);
if (item is CraftedItemInstance craftedItemInstance)
cargo.Remove(craftedItemInstance);
2026-06-13 04:56:50 +01:00
return true;
}
2026-06-14 23:09:49 +01:00
}