2026-06-13 04:56:50 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2020-12-22 03:13:43 +00:00
|
|
|
* 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/. */
|
|
|
|
|
|
2020-05-12 01:42:13 +01:00
|
|
|
using System.Linq;
|
2021-04-18 05:13:20 +01:00
|
|
|
public class ItemUsage : Behavior
|
2020-05-11 01:17:10 +01:00
|
|
|
{
|
2026-06-15 17:48:36 +01:00
|
|
|
private readonly string _itemKey;
|
2020-05-11 01:17:10 +01:00
|
|
|
|
2026-06-15 19:06:13 +01:00
|
|
|
public ItemUsage(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
2021-04-18 05:13:20 +01:00
|
|
|
{
|
2026-06-15 19:06:13 +01:00
|
|
|
_itemKey = definition.ItemKey(1);
|
2021-04-18 05:13:20 +01:00
|
|
|
}
|
2020-05-11 01:17:10 +01:00
|
|
|
|
2026-06-15 19:06:13 +01:00
|
|
|
public ItemUsage(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
2020-05-11 01:17:10 +01:00
|
|
|
{
|
2026-06-15 19:06:13 +01:00
|
|
|
_itemKey = definition.ItemKey(1);
|
2020-05-11 01:17:10 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public override bool Execute(float dt)
|
2020-05-11 01:17:10 +01:00
|
|
|
{
|
2026-06-15 17:48:36 +01:00
|
|
|
var cargo = Entity.FindItemInCargo(_itemKey);
|
2020-12-10 23:20:38 +00:00
|
|
|
if (cargo == null) return false;
|
2020-05-12 01:42:13 +01:00
|
|
|
|
2026-06-15 17:48:36 +01:00
|
|
|
var item = cargo.GetFirstItem(_itemKey);
|
2020-12-10 23:20:38 +00:00
|
|
|
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
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
return true;
|
2020-05-11 01:17:10 +01:00
|
|
|
}
|
2026-06-14 23:09:49 +01:00
|
|
|
}
|