From feb24cfd6b1b04c488b2aa21977189d9aa1d48c3 Mon Sep 17 00:00:00 2001 From: hyperion51 Date: Fri, 22 May 2020 00:23:34 +0100 Subject: [PATCH] Item Quality Formula Update The process for evaluating the quality of a compound item now uses a weighted average of the item's crafting quality and the average of the ingredients' quality, instead of multiplying them --- Assets/Scripts/ServerShared/Extensions.cs | 18 ---------------- Assets/Scripts/ServerShared/GameContext.cs | 24 ++++++++++++++++++++-- Assets/Scripts/ServerShared/ItemData.cs | 20 ++++++++++-------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Assets/Scripts/ServerShared/Extensions.cs b/Assets/Scripts/ServerShared/Extensions.cs index d78fec899..69da1a0e3 100644 --- a/Assets/Scripts/ServerShared/Extensions.cs +++ b/Assets/Scripts/ServerShared/Extensions.cs @@ -23,24 +23,6 @@ public static class Extensions return baseType.GetInterfaces().Any(interfaceType.Equals); } - private static readonly Dictionary Quality = new Dictionary(); - public static float CompoundQuality(this CraftedItemInstance item) - { - if (Quality.ContainsKey(item)) return Quality[item]; - - var quality = item.Quality; - - var craftedIngredients = item.Ingredients.Where(i => i is CraftedItemInstance).ToArray(); - if (craftedIngredients.Length > 0) - { - quality *= craftedIngredients.Cast().Average(CompoundQuality); - } - - Quality[item] = quality; - - return Quality[item]; - } - public static void Send(this NetPeer peer, T message, DeliveryMethod method = DeliveryMethod.ReliableOrdered) where T : Message { peer.Send(MessagePackSerializer.Serialize(message as Message), method); diff --git a/Assets/Scripts/ServerShared/GameContext.cs b/Assets/Scripts/ServerShared/GameContext.cs index a3e0002aa..8e5715fdd 100644 --- a/Assets/Scripts/ServerShared/GameContext.cs +++ b/Assets/Scripts/ServerShared/GameContext.cs @@ -428,6 +428,26 @@ public class GameContext return AffectedStats[effect] = field.GetValue(effectObject) as PerformanceStat; } + private readonly Dictionary ItemQuality = new Dictionary(); + public float CompoundQuality(CraftedItemInstance item) + { + if (ItemQuality.ContainsKey(item)) return ItemQuality[item]; + + var quality = item.Quality; + + var craftedIngredients = item.Ingredients.Where(i => i is CraftedItemInstance).ToArray(); + if (craftedIngredients.Length > 0) + { + var ingredientQualityWeight = Cache.Get(item.Data).IngredientQualityWeight; + quality = quality * (1 - ingredientQualityWeight) + + craftedIngredients.Cast().Average(CompoundQuality) * ingredientQualityWeight; + } + + ItemQuality[item] = quality; + + return ItemQuality[item]; + } + // Determine quality of either the item itself or the specific ingredient this stat depends on public float Quality(PerformanceStat stat, Gear item) { @@ -435,7 +455,7 @@ public class GameContext var activeEffects = blueprint.StatEffects.Where(x => GetAffectedStat(blueprint, x) == stat).ToArray(); float quality; if (!activeEffects.Any()) - quality = item.CompoundQuality(); + quality = CompoundQuality(item); else { var ingredientInstances = item.Ingredients.Select(i => Cache.Get(i)).ToArray(); @@ -450,7 +470,7 @@ public class GameContext foreach (var i in ingredients) { if (i is CraftedItemInstance ci) - sum += ci.CompoundQuality(); + sum += CompoundQuality(ci); else _logger($"Blueprint stat effect for item {item.ID} specifies invalid (non crafted) ingredient!"); } diff --git a/Assets/Scripts/ServerShared/ItemData.cs b/Assets/Scripts/ServerShared/ItemData.cs index 605a2685a..ba9b0bdb4 100644 --- a/Assets/Scripts/ServerShared/ItemData.cs +++ b/Assets/Scripts/ServerShared/ItemData.cs @@ -73,12 +73,14 @@ public class SimpleCommodityData : ItemData JsonConverter(typeof(JsonKnownTypesConverter))] public abstract class CraftedItemData : ItemData { + [InspectableField, JsonProperty("ingredientQualityWeight"), Key(6)] + public float IngredientQualityWeight = .5f; } [RethinkTable("Items"), Inspectable, MessagePackObject] public class CompoundCommodityData : CraftedItemData { - [InspectableDatabaseLink(typeof(PersonalityAttribute)), JsonProperty("demandProfile"), Key(6)] + [InspectableDatabaseLink(typeof(PersonalityAttribute)), JsonProperty("demandProfile"), Key(7)] public Dictionary DemandProfile = new Dictionary(); } @@ -87,25 +89,25 @@ public class CompoundCommodityData : CraftedItemData JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter))] public abstract class EquippableItemData : CraftedItemData { - [InspectableAnimationCurve, JsonProperty("performanceCurve"), Key(6)] + [InspectableAnimationCurve, JsonProperty("performanceCurve"), Key(7)] public float4[] HeatPerformanceCurve; - [TemperatureInspectable, JsonProperty("minTemp"), Key(7)] + [TemperatureInspectable, JsonProperty("minTemp"), Key(8)] public float MinimumTemperature; - [TemperatureInspectable, JsonProperty("maxTemp"), Key(8)] + [TemperatureInspectable, JsonProperty("maxTemp"), Key(9)] public float MaximumTemperature; - [InspectableField, JsonProperty("durabilityStat"), Key(9), SimplePerformanceStat] + [InspectableField, JsonProperty("durabilityStat"), Key(10), SimplePerformanceStat] public PerformanceStat Durability = new PerformanceStat(); - [InspectableField, JsonProperty("durabilityExponent"), Key(10), SimplePerformanceStat] + [InspectableField, JsonProperty("durabilityExponent"), Key(11), SimplePerformanceStat] public PerformanceStat DurabilityExponent = new PerformanceStat(); - [InspectableField, JsonProperty("heatExponent"), Key(11), SimplePerformanceStat] + [InspectableField, JsonProperty("heatExponent"), Key(12), SimplePerformanceStat] public PerformanceStat HeatExponent = new PerformanceStat(); - [InspectableField, JsonProperty("behaviors"), Key(12)] + [InspectableField, JsonProperty("behaviors"), Key(13)] public List Behaviors = new List(); [IgnoreMember] @@ -143,7 +145,7 @@ public abstract class EquippableItemData : CraftedItemData [RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class GearData : EquippableItemData { - [InspectableField, JsonProperty("hardpointType"), Key(13)] + [InspectableField, JsonProperty("hardpointType"), Key(14)] public HardpointType Hardpoint; [IgnoreMember] public override HardpointType HardpointType => Hardpoint;