Hide legacy catalog reader behind ItemManager
This commit is contained in:
parent
be1c8801ed
commit
fabbd088e2
8 changed files with 34 additions and 17 deletions
|
|
@ -90,7 +90,7 @@ public static class EntitySerializer
|
|||
private static void Restore(ItemManager itemManager, Zone zone, EntityPack pack, Entity entity, bool instantiate = false)
|
||||
{
|
||||
entity.Name = pack.Name;
|
||||
entity.Faction = itemManager.ItemData.Get<Faction>(pack.Faction);
|
||||
entity.Faction = itemManager.GetCatalogEntry<Faction>(pack.Faction);
|
||||
entity.Children = pack.Children.Select(c =>
|
||||
{
|
||||
var child = Unpack(itemManager, zone, c, instantiate);
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ public class ItemManager
|
|||
|
||||
// private Guid _forceLoadZone;
|
||||
|
||||
// public GlobalData GlobalData => _globalData ?? (_globalData = ItemData.GetAll<GlobalData>().FirstOrDefault());
|
||||
public ILegacyCatalogReader ItemData { get; }
|
||||
// public GlobalData GlobalData => _globalData ?? (_globalData = GetCatalogEntries<GlobalData>().FirstOrDefault());
|
||||
private readonly ILegacyCatalogReader _itemData;
|
||||
public GameplaySettings GameplaySettings { get; }
|
||||
|
||||
// public double Time
|
||||
|
|
@ -49,11 +49,21 @@ public class ItemManager
|
|||
|
||||
public ItemManager(ILegacyCatalogReader itemData, GameplaySettings settings, Action<string> logger)
|
||||
{
|
||||
ItemData = itemData;
|
||||
_itemData = itemData;
|
||||
GameplaySettings = settings;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public T GetCatalogEntry<T>(Guid id) where T : DatabaseEntry
|
||||
{
|
||||
return _itemData.Get<T>(id);
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetCatalogEntries<T>() where T : DatabaseEntry
|
||||
{
|
||||
return _itemData.GetAll<T>();
|
||||
}
|
||||
|
||||
public void Log(string s)
|
||||
{
|
||||
_logger(s);
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public class LoadoutGenerator
|
|||
|
||||
public T[] RandomItems<T>(int count, float sizeExponent, Predicate<T> filter = null) where T : EquippableItemData
|
||||
{
|
||||
return ItemManager.ItemData.GetAll<T>()
|
||||
return ItemManager.GetCatalogEntries<T>()
|
||||
.Where(item =>
|
||||
item.Price > 0 &&
|
||||
item.Manufacturer != Guid.Empty &&
|
||||
|
|
@ -137,7 +137,7 @@ public class LoadoutGenerator
|
|||
.WeightedRandomElements(ref Random, item =>
|
||||
Faction == null ? 1 :
|
||||
(item.Manufacturer == Faction.ID ? 1 : Faction.Allegiance.ContainsKey(item.Manufacturer) ? Faction.Allegiance[item.Manufacturer] : 0.0f / // Prioritize items from allied manufacturers
|
||||
(Galaxy?.ContainsFaction(item.Manufacturer) ?? false ? Zone?.Distance[Galaxy.HomeZones[ItemManager.ItemData.Get<Faction>(item.Manufacturer)]] ?? 1 : 1)) * // Penalize distance to manufacturer headquarters
|
||||
(Galaxy?.ContainsFaction(item.Manufacturer) ?? false ? Zone?.Distance[Galaxy.HomeZones[ItemManager.GetCatalogEntry<Faction>(item.Manufacturer)]] ?? 1 : 1)) * // Penalize distance to manufacturer headquarters
|
||||
pow(item.Shape.Coordinates.Length, sizeExponent) / // Prioritize larger items
|
||||
pow(item.Price, PriceExponent), // Penalize item price to a controllable degree
|
||||
count
|
||||
|
|
@ -243,4 +243,4 @@ public class InvalidLoadoutException : Exception
|
|||
: base(message, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue