2020-03-22 19:05:26 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
using JsonKnownTypes;
|
|
|
|
|
|
//using JM.LinqFaster;
|
|
|
|
|
|
using MessagePack;
|
|
|
|
|
|
using MessagePack.Formatters;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
|
// TODO: USE THIS EVERYWHERE
|
|
|
|
|
|
using static Unity.Mathematics.math;
|
|
|
|
|
|
|
2020-04-23 03:31:17 +01:00
|
|
|
|
[Union(0, typeof(SimpleCommodity)),
|
|
|
|
|
|
Union(1, typeof(CompoundCommodity)),
|
|
|
|
|
|
Union(2, typeof(Gear)),
|
|
|
|
|
|
JsonObject(MemberSerialization.OptIn),
|
|
|
|
|
|
JsonConverter(typeof(JsonKnownTypesConverter<ItemInstance>))]
|
2020-03-22 19:05:26 +00:00
|
|
|
|
public abstract class ItemInstance : DatabaseEntry
|
|
|
|
|
|
{
|
2020-04-09 07:48:45 +01:00
|
|
|
|
[JsonProperty("data"), Key(1)] public Guid Data;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
|
|
|
|
|
|
public float Mass => Context.GetMass(this);
|
2020-06-05 04:16:33 +01:00
|
|
|
|
public float ThermalMass => Context.GetThermalMass(this);
|
|
|
|
|
|
public float Size => Context.GetSize(this);
|
2020-03-22 19:05:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-23 03:31:17 +01:00
|
|
|
|
[Union(0, typeof(CompoundCommodity)),
|
|
|
|
|
|
Union(1, typeof(Gear)),
|
|
|
|
|
|
JsonObject(MemberSerialization.OptIn),
|
2020-04-09 07:48:45 +01:00
|
|
|
|
JsonConverter(typeof(JsonKnownTypesConverter<CraftedItemInstance>))]
|
2020-03-22 19:05:26 +00:00
|
|
|
|
public abstract class CraftedItemInstance : ItemInstance
|
|
|
|
|
|
{
|
2020-04-09 07:48:45 +01:00
|
|
|
|
[JsonProperty("quality"), Key(2)] public float Quality;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
|
2020-04-28 01:50:50 +01:00
|
|
|
|
[JsonProperty("ingredients"), Key(3)] public List<Guid> Ingredients = new List<Guid>();
|
2020-04-09 07:48:45 +01:00
|
|
|
|
|
2020-04-30 02:54:31 +01:00
|
|
|
|
[JsonProperty("blueprint"), Key(4)] public Guid Blueprint;
|
2020-06-02 07:01:03 +01:00
|
|
|
|
|
|
|
|
|
|
[JsonProperty("name"), Key(5)] public string Name;
|
2020-06-05 04:16:33 +01:00
|
|
|
|
|
|
|
|
|
|
[JsonProperty("sourceEntity"), Key(6)] public Guid SourceEntity;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-09 07:48:45 +01:00
|
|
|
|
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
2020-03-22 19:05:26 +00:00
|
|
|
|
public class CompoundCommodity : CraftedItemInstance {}
|
|
|
|
|
|
|
2020-04-09 07:48:45 +01:00
|
|
|
|
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
2020-03-22 19:05:26 +00:00
|
|
|
|
public class SimpleCommodity : ItemInstance
|
|
|
|
|
|
{
|
2020-04-09 07:48:45 +01:00
|
|
|
|
[JsonProperty("quantity"), Key(2)] public int Quantity;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
|
|
|
|
|
|
public SimpleCommodityData ItemData => Context.GetData(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-09 07:48:45 +01:00
|
|
|
|
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
2020-06-06 03:21:03 +01:00
|
|
|
|
public class Gear : CraftedItemInstance, IDynamicProperties
|
2020-03-22 19:05:26 +00:00
|
|
|
|
{
|
2020-06-05 04:16:33 +01:00
|
|
|
|
[JsonProperty("durability"), Key(7)] public float Durability;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
|
|
|
|
|
|
public EquippableItemData ItemData => Context.GetData(this);
|
2020-06-06 03:21:03 +01:00
|
|
|
|
|
|
|
|
|
|
public event Action OnChanged;
|
|
|
|
|
|
|
|
|
|
|
|
public void Change()
|
|
|
|
|
|
{
|
|
|
|
|
|
OnChanged?.Invoke();
|
|
|
|
|
|
}
|
2020-03-22 19:05:26 +00:00
|
|
|
|
}
|