Use typed state for consumable activation
This commit is contained in:
parent
6707dcaba8
commit
5d96355439
162 changed files with 412 additions and 296 deletions
Binary file not shown.
|
|
@ -408,14 +408,15 @@ internal static class LegacyCatalogReader
|
|||
BehaviorKinds = behaviorKinds,
|
||||
BehaviorCount = behaviorPayloads.Length,
|
||||
MaxStack = unionKey == 0 ? GetInt(payload, 9) : 0,
|
||||
Stackable = false,
|
||||
Duration = 0,
|
||||
Stackable = unionName == "ConsumableItemData" && GetBool(payload, 11),
|
||||
Duration = unionName == "ConsumableItemData" ? GetDouble(payload, 12) : 0,
|
||||
Durability = unionKey is 2 or 3 or 29 or 30 or 31 ? GetDouble(payload, 12) : 0,
|
||||
MinimumTemperature = unionKey is 2 or 3 or 29 or 30 or 31 ? GetDouble(payload, 13) : 0,
|
||||
MaximumTemperature = unionKey is 2 or 3 or 29 or 30 or 31 ? GetDouble(payload, 14) : 0,
|
||||
ThermalPerformanceCurveKeys = unionKey is 2 or 3 or 29 or 30 or 31 ? ReadCurveKeys(payload, 17) : [],
|
||||
ThermalResilience = unionKey is 2 or 3 or 29 or 30 or 31 ? GetPositiveDoubleOrDefault(payload, 18, 1) : 1,
|
||||
AudioStats = unionKey is 2 or 3 or 29 or 30 or 31 ? ReadAudioStats(payload, 22) : [],
|
||||
EffectivenessCurveKeys = unionName == "ConsumableItemData" ? ReadCurveKeys(payload, 14) : [],
|
||||
HullPrefab = unionKey == 3 ? GetString(payload, 24) : "",
|
||||
HullGridOffset = unionKey == 3 ? GetDouble(payload, 26) : 0,
|
||||
HullArmor = unionKey == 3 ? GetDouble(payload, 27) : 0,
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ internal static class AetheriaRuntimeCatalogSnapshotMapper
|
|||
item.HullType,
|
||||
item.BehaviorKinds,
|
||||
item.MaxStack,
|
||||
item.Stackable,
|
||||
item.Duration,
|
||||
item.Durability,
|
||||
item.WeaponRange,
|
||||
item.WeaponCaliber,
|
||||
|
|
@ -59,6 +61,7 @@ internal static class AetheriaRuntimeCatalogSnapshotMapper
|
|||
item.DockingMaxSizeY,
|
||||
item.ActionBarIcon,
|
||||
item.AudioStats.Select(FromState).ToArray(),
|
||||
item.EffectivenessCurveKeys.Select(FromState).ToArray(),
|
||||
item.SimpleCommodityCategory,
|
||||
item.CompoundCommodityCategory);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,9 @@ var importedThermalCurveItems = items.Count(item => item.ThermalPerformanceCurve
|
|||
var thermalResilienceItems = items.Count(item => item.ThermalResilience > 0);
|
||||
var audioStatItems = items.Count(item => item.AudioStats.Length > 0);
|
||||
var audioStatCount = items.Sum(item => item.AudioStats.Length);
|
||||
var consumableItems = items.Count(item => item.Category == "ConsumableItemData");
|
||||
var consumableDurationItems = items.Count(item => item.Category == "ConsumableItemData" && item.Duration > 0);
|
||||
var consumableEffectivenessItems = items.Count(item => item.EffectivenessCurveKeys.Length > 0);
|
||||
var actionBarIconItems = items.Count(item => !string.IsNullOrWhiteSpace(item.ActionBarIcon));
|
||||
var dockingBayItems = items.Count(item => item.Category == "DockingBayData");
|
||||
var dockingBayMaxSizeItems = items.Count(item =>
|
||||
|
|
@ -396,6 +399,7 @@ Console.WriteLine($"Item definitions: {items.Length}");
|
|||
Console.WriteLine($"Priced/manufactured/specific-heat/conductive/shaped items: {pricedItems}/{manufacturedItems}/{specificHeatItems}/{conductiveItems}/{shapedItems}");
|
||||
Console.WriteLine($"Thermal resilience items: {thermalResilienceItems}");
|
||||
Console.WriteLine($"Audio stat items/stats: {audioStatItems}/{audioStatCount}");
|
||||
Console.WriteLine($"Consumable duration/effectiveness items: {consumableDurationItems}/{consumableEffectivenessItems} of {consumableItems}");
|
||||
Console.WriteLine($"Shape masks: {shapedMaskItems}");
|
||||
Console.WriteLine($"Interior masks/hardpoint hosts/hardpoints: {interiorShapeItems}/{hardpointHostItems}/{hardpointCount}");
|
||||
Console.WriteLine($"Behavior payload items/payloads/fields/legacy refs: {behaviorPayloadItems}/{behaviorPayloadCount}/{behaviorFieldCount}/{behaviorLegacyRefCount}");
|
||||
|
|
|
|||
|
|
@ -159,6 +159,9 @@ public sealed class AetheriaItemDefinition
|
|||
|
||||
[Key(48)]
|
||||
public AetheriaItemAudioStat[] AudioStats { get; set; } = [];
|
||||
|
||||
[Key(49)]
|
||||
public AetheriaCurveKey[] EffectivenessCurveKeys { get; set; } = [];
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
|
|||
|
|
@ -58,16 +58,13 @@ public abstract class ActionBarBinding
|
|||
public class ActionBarConsumableBinding : ActionBarBinding
|
||||
{
|
||||
public AetheriaRuntimeCatalogItem Target { get; }
|
||||
private readonly Func<ConsumableItemData> _resolveLegacyTarget;
|
||||
|
||||
public ActionBarConsumableBinding(
|
||||
Entity entity,
|
||||
ActionBarSlot slot,
|
||||
AetheriaRuntimeCatalogItem target,
|
||||
Func<ConsumableItemData> resolveLegacyTarget) : base(entity, slot)
|
||||
AetheriaRuntimeCatalogItem target) : base(entity, slot)
|
||||
{
|
||||
Target = target;
|
||||
_resolveLegacyTarget = resolveLegacyTarget;
|
||||
Slot.QuantityRemaining.gameObject.SetActive(true);
|
||||
Slot.Label.gameObject.SetActive(false);
|
||||
Slot.Icon.gameObject.SetActive(false);
|
||||
|
|
@ -75,9 +72,7 @@ public class ActionBarConsumableBinding : ActionBarBinding
|
|||
|
||||
public override void Activate()
|
||||
{
|
||||
var legacyTarget = ResolveLegacyTarget();
|
||||
if (legacyTarget != null)
|
||||
Entity.TryActivateConsumable(legacyTarget);
|
||||
Entity.TryActivateConsumable(Target);
|
||||
}
|
||||
|
||||
public override void Deactivate()
|
||||
|
|
@ -87,25 +82,20 @@ public class ActionBarConsumableBinding : ActionBarBinding
|
|||
public override void Update()
|
||||
{
|
||||
Slot.QuantityRemaining.text = $"{Entity.CountItemsInCargo(TargetLegacyId)}";
|
||||
var legacyTarget = ResolveLegacyTarget();
|
||||
if (legacyTarget == null)
|
||||
if (TargetLegacyId == Guid.Empty)
|
||||
{
|
||||
Slot.Fill.fillAmount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
var instance = Entity.FindActiveConsumable(legacyTarget);
|
||||
var instance = Entity.FindActiveConsumable(TargetLegacyId);
|
||||
if (instance == null) Slot.Fill.fillAmount = 0;
|
||||
else Slot.Fill.fillAmount = instance.RemainingDuration / instance.Data.Duration;
|
||||
else Slot.Fill.fillAmount = instance.RemainingDuration / instance.Duration;
|
||||
}
|
||||
|
||||
private Guid TargetLegacyId =>
|
||||
Guid.TryParse(Target.LegacyId, out var legacyId) ? legacyId : Guid.Empty;
|
||||
|
||||
private ConsumableItemData ResolveLegacyTarget()
|
||||
{
|
||||
return _resolveLegacyTarget?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public class ActionBarGearBinding : ActionBarBinding
|
||||
|
|
|
|||
|
|
@ -743,8 +743,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
slot.Binding = new ActionBarConsumableBinding(
|
||||
CurrentEntity,
|
||||
slot,
|
||||
consumable,
|
||||
() => ItemManager.GetData(itemInstanceDragAction.Item) as ConsumableItemData);
|
||||
consumable);
|
||||
return true;
|
||||
case WeaponGroupDragObject weaponGroupDragAction:
|
||||
slot.Binding = new ActionBarWeaponGroupBinding(CurrentEntity, slot, weaponGroupDragAction.Group);
|
||||
|
|
|
|||
|
|
@ -121,6 +121,14 @@ public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemProjectionReader
|
|||
simple.MaxStack = item.MaxStack;
|
||||
}
|
||||
|
||||
if (projected is ConsumableItemData consumable)
|
||||
{
|
||||
consumable.Stackable = item.Stackable;
|
||||
consumable.Duration = (float)item.Duration;
|
||||
consumable.Effectiveness = ProjectCurve(item.EffectivenessCurveKeys);
|
||||
consumable.Behaviors = ProjectBehaviors(item).ToList();
|
||||
}
|
||||
|
||||
if (projected is EquippableItemData equippable)
|
||||
{
|
||||
equippable.Durability = (float)item.Durability;
|
||||
|
|
@ -175,6 +183,20 @@ public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemProjectionReader
|
|||
.ToArray();
|
||||
}
|
||||
|
||||
private static BezierCurve ProjectCurve(IReadOnlyList<AetheriaRuntimeCurveKey> keys)
|
||||
{
|
||||
return new BezierCurve
|
||||
{
|
||||
Keys = keys == null || keys.Count == 0
|
||||
? new[] { new float4(0, 1, 0, 0), new float4(1, 1, 0, 0) }
|
||||
: keys.Select(key => new float4(
|
||||
(float)key.Time,
|
||||
(float)key.Value,
|
||||
(float)key.InTangent,
|
||||
(float)key.OutTangent)).ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
private static IEnumerable<AudioStat> ProjectAudioStats(AetheriaRuntimeCatalogItem item)
|
||||
{
|
||||
return item.AudioStats.Select(audioStat => new AudioStat
|
||||
|
|
|
|||
|
|
@ -316,27 +316,67 @@ public abstract class Entity
|
|||
|
||||
public ConsumableItemEffect FindActiveConsumable(ConsumableItemData data)
|
||||
{
|
||||
return _activeConsumables.FirstOrDefault(ac => ac.Data.ID == data.ID);
|
||||
return data == null ? null : FindActiveConsumable(data.ID);
|
||||
}
|
||||
|
||||
public ConsumableItemEffect FindActiveConsumable(Guid itemId)
|
||||
{
|
||||
return _activeConsumables.FirstOrDefault(ac => ac.Item?.Data?.ItemId == itemId);
|
||||
}
|
||||
|
||||
public bool CanActivateConsumable(ConsumableItemData data)
|
||||
{
|
||||
return data.Stackable || FindActiveConsumable(data) == null;
|
||||
var typedItem = ItemManager.GetRuntimeItem(data?.ID ?? Guid.Empty);
|
||||
if (typedItem == null)
|
||||
return data != null && (data.Stackable || FindActiveConsumable(data) == null);
|
||||
|
||||
return CanActivateConsumable(typedItem);
|
||||
}
|
||||
|
||||
public bool CanActivateConsumable(AetheriaRuntimeCatalogItem item)
|
||||
{
|
||||
var itemId = GetLegacyGuid(item);
|
||||
return item != null && itemId != Guid.Empty && (item.Stackable || FindActiveConsumable(itemId) == null);
|
||||
}
|
||||
|
||||
public bool TryActivateConsumable(ConsumableItemData data)
|
||||
{
|
||||
var typedItem = ItemManager.GetRuntimeItem(data?.ID ?? Guid.Empty);
|
||||
if (typedItem != null)
|
||||
return TryActivateConsumable(typedItem);
|
||||
|
||||
if (!CanActivateConsumable(data)) return false;
|
||||
|
||||
|
||||
var bay = FindItemInCargo(data.ID);
|
||||
if (bay == null) return false;
|
||||
|
||||
|
||||
var item = (ConsumableItem) bay.ItemsOfType[data.ID].First();
|
||||
ActivateConsumable(item);
|
||||
bay.Remove(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryActivateConsumable(AetheriaRuntimeCatalogItem typedItem)
|
||||
{
|
||||
if (!CanActivateConsumable(typedItem)) return false;
|
||||
|
||||
var itemId = GetLegacyGuid(typedItem);
|
||||
var bay = FindItemInCargo(itemId);
|
||||
if (bay == null) return false;
|
||||
|
||||
var item = (ConsumableItem)bay.ItemsOfType[itemId].First();
|
||||
ActivateConsumable(item);
|
||||
bay.Remove(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Guid GetLegacyGuid(AetheriaRuntimeCatalogItem item)
|
||||
{
|
||||
return item != null && Guid.TryParse(item.LegacyId, out var legacyId)
|
||||
? legacyId
|
||||
: Guid.Empty;
|
||||
}
|
||||
|
||||
private void MapEntity()
|
||||
{
|
||||
var typedHull = ItemManager.GetRuntimeItem(Hull);
|
||||
|
|
@ -1209,13 +1249,21 @@ public class ConsumableItemEffect
|
|||
public ConsumableItem Item { get; }
|
||||
public ConsumableItemData Data { get; }
|
||||
public Behavior[] Behaviors { get; }
|
||||
public AetheriaRuntimeCatalogItem RuntimeItem { get; }
|
||||
public float Duration => Math.Max(_duration, float.Epsilon);
|
||||
|
||||
private readonly float _duration;
|
||||
private readonly BezierCurve _effectiveness;
|
||||
|
||||
public ConsumableItemEffect(ConsumableItem item, Entity entity)
|
||||
{
|
||||
Item = item;
|
||||
Entity = entity;
|
||||
RuntimeItem = entity.ItemManager.GetRuntimeItem(item);
|
||||
Data = entity.ItemManager.GetData(item) as ConsumableItemData;
|
||||
RemainingDuration = Data.Duration;
|
||||
_duration = RuntimeItem?.Duration > 0 ? (float)RuntimeItem.Duration : Data?.Duration ?? 0;
|
||||
_effectiveness = CreateEffectivenessCurve(RuntimeItem, Data);
|
||||
RemainingDuration = _duration;
|
||||
|
||||
Behaviors = entity.ItemManager.GetRuntimeBehaviorProjections(item)
|
||||
.Select(bd => bd.CreateInstance(this))
|
||||
|
|
@ -1238,7 +1286,8 @@ public class ConsumableItemEffect
|
|||
|
||||
public float Evaluate(PerformanceStat stat)
|
||||
{
|
||||
var effectiveness = Data.Effectiveness.Evaluate((Data.Duration - RemainingDuration) / Data.Duration);
|
||||
var duration = Math.Max(_duration, float.Epsilon);
|
||||
var effectiveness = _effectiveness.Evaluate((duration - RemainingDuration) / duration);
|
||||
var quality = pow(Item.Quality, stat.QualityExponent);
|
||||
|
||||
var result = lerp(stat.Min, stat.Max, effectiveness * quality);
|
||||
|
|
@ -1247,6 +1296,28 @@ public class ConsumableItemEffect
|
|||
return stat.Min;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static BezierCurve CreateEffectivenessCurve(AetheriaRuntimeCatalogItem item, ConsumableItemData fallback)
|
||||
{
|
||||
if (item?.EffectivenessCurveKeys != null && item.EffectivenessCurveKeys.Count > 0)
|
||||
{
|
||||
return new BezierCurve
|
||||
{
|
||||
Keys = item.EffectivenessCurveKeys
|
||||
.Select(key => new float4(
|
||||
(float)key.Time,
|
||||
(float)key.Value,
|
||||
(float)key.InTangent,
|
||||
(float)key.OutTangent))
|
||||
.ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
return fallback?.Effectiveness ?? new BezierCurve
|
||||
{
|
||||
Keys = new[] { new float4(0, 1, 0, 0), new float4(1, 1, 0, 0) }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class EquippedItem
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue