Use typed item mass and thermal facts
This commit is contained in:
parent
0568ea71db
commit
a8f6df5bb1
160 changed files with 344 additions and 275 deletions
|
|
@ -8,12 +8,14 @@ using Unity.Mathematics;
|
|||
|
||||
public interface IRuntimeItemProjectionReader
|
||||
{
|
||||
AetheriaRuntimeCatalogItem GetRuntimeItem(Guid guid);
|
||||
ItemData Get(Guid guid);
|
||||
T Get<T>(Guid guid) where T : ItemData;
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemProjectionReader
|
||||
{
|
||||
private readonly Dictionary<Guid, AetheriaRuntimeCatalogItem> _typedItems;
|
||||
private readonly Dictionary<Guid, ItemData> _items;
|
||||
private static readonly IReadOnlyDictionary<int, Type> BehaviorTypesByUnionKey = new Dictionary<int, Type>
|
||||
{
|
||||
|
|
@ -54,12 +56,22 @@ public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemProjectionReader
|
|||
{
|
||||
if (catalog == null) throw new ArgumentNullException(nameof(catalog));
|
||||
|
||||
_typedItems = catalog.Items
|
||||
.Where(item => Guid.TryParse(item.LegacyId, out _))
|
||||
.ToDictionary(item => Guid.Parse(item.LegacyId), item => item);
|
||||
|
||||
_items = catalog.Items
|
||||
.Select(ProjectItem)
|
||||
.Where(item => item != null)
|
||||
.ToDictionary(item => item.ID, item => item);
|
||||
}
|
||||
|
||||
public AetheriaRuntimeCatalogItem GetRuntimeItem(Guid guid)
|
||||
{
|
||||
_typedItems.TryGetValue(guid, out var item);
|
||||
return item;
|
||||
}
|
||||
|
||||
public ItemData Get(Guid guid)
|
||||
{
|
||||
ItemData item;
|
||||
|
|
@ -90,6 +102,7 @@ public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemProjectionReader
|
|||
projected.Description = item.Description;
|
||||
projected.Manufacturer = ParseGuid(item.ManufacturerLegacyId);
|
||||
projected.Mass = (float)item.Mass;
|
||||
projected.SpecificHeat = (float)item.SpecificHeat;
|
||||
projected.Shape = ProjectShape(item.ShapeWidth, item.ShapeHeight, item.ShapeCells);
|
||||
projected.Price = item.Price;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.State.Unity;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
|
|
@ -57,6 +58,12 @@ public class ItemManager
|
|||
return _itemProjections.Get<T>(id);
|
||||
}
|
||||
|
||||
public AetheriaRuntimeCatalogItem GetRuntimeItem(ItemInstance item)
|
||||
{
|
||||
var itemId = item?.Data?.ItemId ?? Guid.Empty;
|
||||
return itemId == Guid.Empty ? null : _itemProjections.GetRuntimeItem(itemId);
|
||||
}
|
||||
|
||||
public RuntimeItemReference CreateReference(ItemData item)
|
||||
{
|
||||
return new RuntimeItemReference(item);
|
||||
|
|
@ -107,21 +114,32 @@ public class ItemManager
|
|||
|
||||
public float GetMass(ItemInstance item)
|
||||
{
|
||||
var typedItem = GetRuntimeItem(item);
|
||||
if (typedItem == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return item switch
|
||||
{
|
||||
CraftedItemInstance _ => GetData(item).Mass,
|
||||
SimpleCommodity commodity => GetData(item).Mass * commodity.Quantity,
|
||||
CraftedItemInstance _ => (float)typedItem.Mass,
|
||||
SimpleCommodity commodity => (float)typedItem.Mass * commodity.Quantity,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
public float GetThermalMass(ItemInstance item)
|
||||
{
|
||||
var data = GetData(item);
|
||||
var typedItem = GetRuntimeItem(item);
|
||||
if (typedItem == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return item switch
|
||||
{
|
||||
CraftedItemInstance _ => data.Mass * data.SpecificHeat,
|
||||
SimpleCommodity commodity => data.Mass * data.SpecificHeat * commodity.Quantity,
|
||||
CraftedItemInstance _ => (float)(typedItem.Mass * typedItem.SpecificHeat),
|
||||
SimpleCommodity commodity => (float)(typedItem.Mass * typedItem.SpecificHeat * commodity.Quantity),
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
|
@ -145,8 +163,10 @@ public class ItemManager
|
|||
|
||||
public int GetPrice(CraftedItemInstance item)
|
||||
{
|
||||
var data = GetData(item);
|
||||
return (int) (GameplaySettings.QualityPriceModifier.Evaluate(item.Quality) * data.Price);
|
||||
var typedItem = GetRuntimeItem(item);
|
||||
return typedItem == null
|
||||
? 0
|
||||
: (int) (GameplaySettings.QualityPriceModifier.Evaluate(item.Quality) * typedItem.Price);
|
||||
}
|
||||
|
||||
public SimpleCommodity CreateInstance(SimpleCommodityData item, int count)
|
||||
|
|
|
|||
Loading…
Reference in a new issue