Restore the stable legacy Unity project
This commit is contained in:
parent
56a156ee87
commit
7006a6b0dd
2070 changed files with 180490 additions and 169303 deletions
|
|
@ -1,33 +1,54 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
/* 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;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-5), RuntimeInspectable]
|
||||
public class ItemUsageData : BehaviorData
|
||||
{
|
||||
[InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("item"), Key(1), RuntimeInspectable]
|
||||
public Guid Item;
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new ItemUsage(this, item);
|
||||
}
|
||||
|
||||
public override Behavior CreateInstance(ConsumableItemEffect item)
|
||||
{
|
||||
return new ItemUsage(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemUsage : Behavior
|
||||
{
|
||||
private readonly string _itemKey;
|
||||
private ItemUsageData _data;
|
||||
|
||||
public ItemUsage(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
||||
public ItemUsage(ItemUsageData data, EquippedItem item) : base(data, item)
|
||||
{
|
||||
_itemKey = definition.ItemKey(1);
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public ItemUsage(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
||||
public ItemUsage(ItemUsageData data, ConsumableItemEffect item) : base(data, item)
|
||||
{
|
||||
_itemKey = definition.ItemKey(1);
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public override bool Execute(float dt)
|
||||
{
|
||||
var cargo = Entity.FindItemInCargo(_itemKey);
|
||||
var cargo = Entity.FindItemInCargo(_data.Item);
|
||||
if (cargo == null) return false;
|
||||
|
||||
var item = cargo.GetFirstItem(_itemKey);
|
||||
var item = cargo.ItemsOfType[_data.Item][0];
|
||||
if (item is SimpleCommodity simpleCommodity)
|
||||
cargo.Remove(simpleCommodity, 1);
|
||||
if (item is CraftedItemInstance craftedItemInstance)
|
||||
cargo.Remove(craftedItemInstance);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue