Use typed payloads for behavior construction
This commit is contained in:
parent
48178a969b
commit
18dc4a61ce
5 changed files with 37 additions and 8 deletions
|
|
@ -9,6 +9,7 @@ using Unity.Mathematics;
|
|||
public interface IRuntimeItemProjectionReader
|
||||
{
|
||||
AetheriaRuntimeCatalogItem GetRuntimeItem(Guid guid);
|
||||
IReadOnlyList<BehaviorData> GetBehaviorProjections(Guid guid);
|
||||
ItemData Get(Guid guid);
|
||||
T Get<T>(Guid guid) where T : ItemData;
|
||||
}
|
||||
|
|
@ -72,6 +73,14 @@ public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemProjectionReader
|
|||
return item;
|
||||
}
|
||||
|
||||
public IReadOnlyList<BehaviorData> GetBehaviorProjections(Guid guid)
|
||||
{
|
||||
var item = GetRuntimeItem(guid);
|
||||
return item == null
|
||||
? Array.Empty<BehaviorData>()
|
||||
: ProjectBehaviors(item);
|
||||
}
|
||||
|
||||
public ItemData Get(Guid guid)
|
||||
{
|
||||
ItemData item;
|
||||
|
|
@ -115,10 +124,7 @@ public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemProjectionReader
|
|||
if (projected is EquippableItemData equippable)
|
||||
{
|
||||
equippable.Durability = (float)item.Durability;
|
||||
equippable.Behaviors = item.BehaviorPayloads
|
||||
.Select(ProjectBehavior)
|
||||
.Where(behavior => behavior != null)
|
||||
.ToList();
|
||||
equippable.Behaviors = ProjectBehaviors(item).ToList();
|
||||
}
|
||||
|
||||
if (projected is GearData gear)
|
||||
|
|
@ -158,6 +164,14 @@ public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemProjectionReader
|
|||
return projected;
|
||||
}
|
||||
|
||||
private static BehaviorData[] ProjectBehaviors(AetheriaRuntimeCatalogItem item)
|
||||
{
|
||||
return item.BehaviorPayloads
|
||||
.Select(ProjectBehavior)
|
||||
.Where(behavior => behavior != null)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static ItemData CreateItemData(AetheriaRuntimeCatalogItem item)
|
||||
{
|
||||
switch (item.Category)
|
||||
|
|
|
|||
|
|
@ -1217,7 +1217,7 @@ public class ConsumableItemEffect
|
|||
Data = entity.ItemManager.GetData(item) as ConsumableItemData;
|
||||
RemainingDuration = Data.Duration;
|
||||
|
||||
Behaviors = Data.Behaviors
|
||||
Behaviors = entity.ItemManager.GetRuntimeBehaviorProjections(item)
|
||||
.Select(bd => bd.CreateInstance(this))
|
||||
.ToArray();
|
||||
}
|
||||
|
|
@ -1391,7 +1391,7 @@ public class EquippedItem
|
|||
.CombineLatest(Online, (enabled, online) => enabled && online).DistinctUntilChanged());
|
||||
|
||||
|
||||
Behaviors = Data.Behaviors
|
||||
Behaviors = ItemManager.GetRuntimeBehaviorProjections(item)
|
||||
.Select(bd => bd.CreateInstance(this))
|
||||
.ToArray();
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,14 @@ public class ItemManager
|
|||
return itemId == Guid.Empty ? null : _itemProjections.GetRuntimeItem(itemId);
|
||||
}
|
||||
|
||||
public IReadOnlyList<BehaviorData> GetRuntimeBehaviorProjections(ItemInstance item)
|
||||
{
|
||||
var itemId = item?.Data?.ItemId ?? Guid.Empty;
|
||||
return itemId == Guid.Empty
|
||||
? Array.Empty<BehaviorData>()
|
||||
: _itemProjections.GetBehaviorProjections(itemId);
|
||||
}
|
||||
|
||||
public Shape GetRuntimeShape(ItemInstance item)
|
||||
{
|
||||
var typedItem = GetRuntimeItem(item);
|
||||
|
|
|
|||
Loading…
Reference in a new issue