2026-09-12 01:12:12 +02: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/. */
|
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
using System;
|
2020-03-22 19:05:26 +00:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
2026-08-10 14:57:50 +01:00
|
|
|
using JsonKnownTypes;
|
|
|
|
|
//using JM.LinqFaster;
|
|
|
|
|
using MessagePack;
|
|
|
|
|
using MessagePack.Formatters;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
using static Unity.Mathematics.math;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2026-09-12 01:12:12 +02:00
|
|
|
[Union(0, typeof(SimpleCommodity)),
|
|
|
|
|
Union(1, typeof(CompoundCommodity)),
|
2026-08-10 14:57:50 +01:00
|
|
|
Union(2, typeof(EquippableItem)),
|
|
|
|
|
Union(3, typeof(ConsumableItem)),
|
2026-09-12 01:12:12 +02:00
|
|
|
JsonObject(MemberSerialization.OptIn),
|
2026-08-10 14:57:50 +01:00
|
|
|
JsonConverter(typeof(JsonKnownTypesConverter<ItemInstance>))]
|
2020-12-10 23:20:38 +00:00
|
|
|
public abstract class ItemInstance
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
[JsonProperty("data"), Key(0)] public DatabaseLink<ItemData> Data;
|
|
|
|
|
[JsonProperty("rotation"), Key(1)] public ItemRotation Rotation;
|
2020-03-22 19:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-09-12 01:12:12 +02:00
|
|
|
[Union(0, typeof(CompoundCommodity)),
|
|
|
|
|
Union(1, typeof(EquippableItem)),
|
|
|
|
|
Union(2, typeof(ConsumableItem)),
|
2026-08-10 14:57:50 +01:00
|
|
|
JsonObject(MemberSerialization.OptIn),
|
|
|
|
|
JsonConverter(typeof(JsonKnownTypesConverter<CraftedItemInstance>))]
|
2020-03-22 19:05:26 +00:00
|
|
|
public abstract class CraftedItemInstance : ItemInstance
|
|
|
|
|
{
|
2026-09-12 01:12:12 +02:00
|
|
|
// The workmanship of this particular unit, as distinct from the parts that went into it.
|
2026-08-10 14:57:50 +01:00
|
|
|
[JsonProperty("quality"), Key(2)] public float Quality;
|
|
|
|
|
|
2026-09-12 01:12:12 +02:00
|
|
|
// The part filling each of the design's roles, one level deep. Empty on items made before roles existed,
|
|
|
|
|
// and on parts themselves; stats then read Quality as they always did.
|
|
|
|
|
[JsonProperty("ingredients"), Key(3)] public List<RoleFill> Ingredients = new List<RoleFill>();
|
|
|
|
|
|
|
|
|
|
// The manufacturer's branded product this was built as, naming it and carrying its flavor text.
|
|
|
|
|
[JsonProperty("product"), Key(4)] public Guid Product;
|
|
|
|
|
|
|
|
|
|
// The quality a stat reads for one of the design's roles. An unnamed role, a design without roles, and an
|
|
|
|
|
// item built before roles existed all fall back to this item's own workmanship.
|
|
|
|
|
public float QualityForRole(string role)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(role) || Ingredients == null) return Quality;
|
|
|
|
|
foreach (var fill in Ingredients)
|
|
|
|
|
if (fill.Role == role) return fill.Quality;
|
|
|
|
|
return Quality;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// One filled slot: the design's role name and how good the part that went into it turned out to be.
|
|
|
|
|
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
|
|
|
|
public class RoleFill
|
|
|
|
|
{
|
|
|
|
|
[JsonProperty("role"), Key(0)] public string Role;
|
|
|
|
|
[JsonProperty("quality"), Key(1)] public float Quality;
|
2020-03-22 19:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
2020-12-10 23:20:38 +00:00
|
|
|
public class CompoundCommodity : CraftedItemInstance { }
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
2020-03-22 19:05:26 +00:00
|
|
|
public class SimpleCommodity : ItemInstance
|
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
[JsonProperty("quantity"), Key(2)] public int Quantity;
|
2020-03-22 19:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
2020-12-10 23:20:38 +00:00
|
|
|
public class EquippableItem : CraftedItemInstance
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
[JsonProperty("durability"), Key(7)] public float Durability;
|
|
|
|
|
[JsonProperty("override"), Key(8)] public bool OverrideShutdown;
|
2021-04-18 05:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
2021-04-18 05:13:20 +01:00
|
|
|
public class ConsumableItem : CraftedItemInstance
|
|
|
|
|
{
|
2026-09-12 01:12:12 +02:00
|
|
|
}
|