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
This commit is contained in:
parent
0ae4a388f5
commit
feb24cfd6b
3 changed files with 33 additions and 29 deletions
|
|
@ -23,24 +23,6 @@ public static class Extensions
|
|||
return baseType.GetInterfaces().Any(interfaceType.Equals);
|
||||
}
|
||||
|
||||
private static readonly Dictionary<CraftedItemInstance, float> Quality = new Dictionary<CraftedItemInstance, float>();
|
||||
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<CraftedItemInstance>().Average(CompoundQuality);
|
||||
}
|
||||
|
||||
Quality[item] = quality;
|
||||
|
||||
return Quality[item];
|
||||
}
|
||||
|
||||
public static void Send<T>(this NetPeer peer, T message, DeliveryMethod method = DeliveryMethod.ReliableOrdered) where T : Message
|
||||
{
|
||||
peer.Send(MessagePackSerializer.Serialize(message as Message), method);
|
||||
|
|
|
|||
|
|
@ -428,6 +428,26 @@ public class GameContext
|
|||
return AffectedStats[effect] = field.GetValue(effectObject) as PerformanceStat;
|
||||
}
|
||||
|
||||
private readonly Dictionary<CraftedItemInstance, float> ItemQuality = new Dictionary<CraftedItemInstance, float>();
|
||||
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<CraftedItemData>(item.Data).IngredientQualityWeight;
|
||||
quality = quality * (1 - ingredientQualityWeight) +
|
||||
craftedIngredients.Cast<CraftedItemInstance>().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<ItemInstance>(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!");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,12 +73,14 @@ public class SimpleCommodityData : ItemData
|
|||
JsonConverter(typeof(JsonKnownTypesConverter<CraftedItemData>))]
|
||||
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<Guid, float> DemandProfile = new Dictionary<Guid, float>();
|
||||
}
|
||||
|
||||
|
|
@ -87,25 +89,25 @@ public class CompoundCommodityData : CraftedItemData
|
|||
JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter<EquippableItemData>))]
|
||||
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<BehaviorData> Behaviors = new List<BehaviorData>();
|
||||
|
||||
[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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue