Price loadout restores with runtime queries
This commit is contained in:
parent
0504ca6287
commit
931272495e
5 changed files with 170 additions and 30 deletions
|
|
@ -4802,7 +4802,7 @@ static void RequireTradeItemValuesUseRuntimeQueries(string root)
|
|||
{
|
||||
"ProjectTradeItem(item)",
|
||||
"ProjectTradeItemCommit(",
|
||||
"ProjectTradeValueSettings(",
|
||||
"GameManager.ObservedTradeValueSettings()",
|
||||
"AetheriaRuntimeDaemonTradeItemQueries.ProjectTradeItem(",
|
||||
"AetheriaRuntimeTradeItemProjection TradeProjection",
|
||||
"public int Price => TradeProjection.Price",
|
||||
|
|
@ -10520,6 +10520,10 @@ static void RequireInventoryLoadoutRestoreRequestAuthority(string root)
|
|||
var actionGameManager = File.Exists(actionGameManagerPath)
|
||||
? File.ReadAllText(actionGameManagerPath)
|
||||
: throw new InvalidOperationException("Cannot verify loadout restore authority; ActionGameManager.cs is missing.");
|
||||
var tradeQueriesPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonTradeItemQueries.cs");
|
||||
var tradeQueries = File.Exists(tradeQueriesPath)
|
||||
? File.ReadAllText(tradeQueriesPath)
|
||||
: throw new InvalidOperationException("Cannot verify loadout restore authority; runtime trade item queries are missing.");
|
||||
|
||||
var requiredSymbols = new[]
|
||||
{
|
||||
|
|
@ -10545,6 +10549,14 @@ static void RequireInventoryLoadoutRestoreRequestAuthority(string root)
|
|||
"Unity loadout restore still rejects requests through renderer-local credits instead of daemon acceptance.");
|
||||
}
|
||||
|
||||
if (!actionGameManager.Contains("ObservedTradeValueSettings()", StringComparison.Ordinal) ||
|
||||
!actionGameManager.Contains("AetheriaRuntimeDaemonTradeItemQueries.TryProjectLoadoutTemplatePrice(", StringComparison.Ordinal) ||
|
||||
actionGameManager.Contains("blueprint.Price(ItemManager)", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"ActionGameManager must price loadout restore requests through shared runtime loadout queries instead of blueprint/ItemManager value authority.");
|
||||
}
|
||||
|
||||
var forbiddenActionSymbols = new[]
|
||||
{
|
||||
"TryRequestDaemonLoadoutRestore",
|
||||
|
|
@ -10626,6 +10638,22 @@ static void RequireInventoryLoadoutRestoreRequestAuthority(string root)
|
|||
throw new InvalidOperationException("InventoryPanel no longer routes loadout restore through ActionGameManager.");
|
||||
}
|
||||
|
||||
if (!inventoryPanel.Contains("AetheriaRuntimeDaemonTradeItemQueries.TryProjectLoadoutTemplatePrice(", StringComparison.Ordinal) ||
|
||||
inventoryPanel.Contains("blueprint.Price(GameManager.ItemManager)", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"InventoryPanel must label loadout restore options through shared runtime loadout price queries instead of Unity ItemManager pricing.");
|
||||
}
|
||||
|
||||
if (!tradeQueries.Contains("public static bool TryProjectLoadoutTemplatePrice(", StringComparison.Ordinal) ||
|
||||
!tradeQueries.Contains("TryProjectEntityLoadoutPrice(", StringComparison.Ordinal) ||
|
||||
!tradeQueries.Contains("typedItem.Stackable", StringComparison.Ordinal) ||
|
||||
!tradeQueries.Contains("typedItem.Price * Math.Max(1, item.Quantity)", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Shared runtime trade item queries must own typed loadout template price projection.");
|
||||
}
|
||||
|
||||
if (!actionGameManager.Contains("public IEnumerable<AetheriaRuntimeLoadoutTemplateSnapshot> ObservedLoadoutTemplates()", StringComparison.Ordinal) ||
|
||||
actionGameManager.Contains("public List<AetheriaRuntimeLoadoutTemplateSnapshot> LoadoutTemplates", StringComparison.Ordinal) ||
|
||||
inventoryPanel.Contains("GameManager.LoadoutTemplates", StringComparison.Ordinal))
|
||||
|
|
|
|||
|
|
@ -542,6 +542,24 @@ public class ActionGameManager : MonoBehaviour
|
|||
return _observedLoadoutTemplates;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeTradeValueSettings ObservedTradeValueSettings()
|
||||
{
|
||||
var priceModifier = Settings.GameplaySettings.QualityPriceModifier;
|
||||
return new AetheriaRuntimeTradeValueSettings(
|
||||
new AetheriaRuntimeExponentialLerp(
|
||||
priceModifier.Exponent,
|
||||
priceModifier.Minimum,
|
||||
priceModifier.Maximum),
|
||||
(Settings.GameplaySettings.Tiers ?? Array.Empty<RarityTier>())
|
||||
.Select(tier => new AetheriaRuntimeItemRarityTier(
|
||||
tier.Name,
|
||||
tier.Quality,
|
||||
tier.Color.x,
|
||||
tier.Color.y,
|
||||
tier.Color.z))
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
public (RarityTier tier, int upgrades) ObservedItemTier(CraftedItemInstance item)
|
||||
{
|
||||
return ItemManager.GetTier(item);
|
||||
|
|
@ -973,7 +991,15 @@ public class ActionGameManager : MonoBehaviour
|
|||
return;
|
||||
}
|
||||
|
||||
var price = blueprint.Price(ItemManager);
|
||||
if (!AetheriaRuntimeDaemonTradeItemQueries.TryProjectLoadoutTemplatePrice(
|
||||
template,
|
||||
RuntimeCatalog,
|
||||
ObservedTradeValueSettings(),
|
||||
out var price))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var observer = ResolveDaemonObserver();
|
||||
if (observer != null && observer.HasAuthoritativeState)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -181,11 +181,15 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
|
|||
|
||||
private (string text, Action action, bool enabled) LoadoutOption(AetheriaRuntimeLoadoutTemplateSnapshot template)
|
||||
{
|
||||
var blueprint = GameManager.CreateEntityConstructionBlueprint(template);
|
||||
if (blueprint == null)
|
||||
if (!AetheriaRuntimeDaemonTradeItemQueries.TryProjectLoadoutTemplatePrice(
|
||||
template,
|
||||
ActionGameManager.RuntimeCatalog,
|
||||
GameManager.ObservedTradeValueSettings(),
|
||||
out var price))
|
||||
{
|
||||
return ($"{template.Name} - unavailable", () => { }, false);
|
||||
}
|
||||
|
||||
var price = blueprint.Price(GameManager.ItemManager);
|
||||
return ($"{template.Name} - {price:n0}", () =>
|
||||
{
|
||||
GameManager.RequestRuntimeLoadoutRestore(template);
|
||||
|
|
@ -371,8 +375,11 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
|
|||
foreach (var loadoutEntry in GameManager.ObservedLoadoutTemplates().Select((template, templateIndex) => (template, templateIndex)))
|
||||
{
|
||||
var restoreCommand = AetheriaRuntimeInventoryDropdownSurfaceBuilder.LoadoutCommand(loadoutEntry.templateIndex);
|
||||
var blueprint = GameManager.CreateEntityConstructionBlueprint(loadoutEntry.template);
|
||||
if (blueprint == null)
|
||||
if (!AetheriaRuntimeDaemonTradeItemQueries.TryProjectLoadoutTemplatePrice(
|
||||
loadoutEntry.template,
|
||||
ActionGameManager.RuntimeCatalog,
|
||||
GameManager.ObservedTradeValueSettings(),
|
||||
out var price))
|
||||
{
|
||||
loadoutOptions.Add(new AetheriaRuntimeInventoryDropdownOption(
|
||||
$"{AetheriaRuntimeInventoryDropdownSurfaceBuilder.SurfaceId}.loadouts.unavailable_{loadoutEntry.templateIndex}",
|
||||
|
|
@ -381,7 +388,6 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
|
|||
continue;
|
||||
}
|
||||
|
||||
var price = blueprint.Price(GameManager.ItemManager);
|
||||
if (_dropdownCommands.ContainsKey(restoreCommand))
|
||||
{
|
||||
loadoutOptions.Add(new AetheriaRuntimeInventoryDropdownOption(
|
||||
|
|
|
|||
|
|
@ -279,13 +279,13 @@ public class TradeMenu : MonoBehaviour
|
|||
return ActionGameManager.RuntimeCatalog?.FindItem(item?.ItemKey ?? "");
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeTradeItemProjection ProjectTradeItem(ItemInstance item)
|
||||
private AetheriaRuntimeTradeItemProjection ProjectTradeItem(ItemInstance item)
|
||||
{
|
||||
var typedItem = FindTypedTradeItem(item);
|
||||
return AetheriaRuntimeDaemonTradeItemQueries.ProjectTradeItem(
|
||||
typedItem,
|
||||
ProjectTradeItemCommit(item),
|
||||
ProjectTradeValueSettings());
|
||||
GameManager.ObservedTradeValueSettings());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeLoadoutItemCommit? ProjectTradeItemCommit(ItemInstance item)
|
||||
|
|
@ -300,25 +300,6 @@ public class TradeMenu : MonoBehaviour
|
|||
durability);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeTradeValueSettings ProjectTradeValueSettings()
|
||||
{
|
||||
var source = ActionGameManager.Settings.GameplaySettings;
|
||||
var priceModifier = source.QualityPriceModifier;
|
||||
return new AetheriaRuntimeTradeValueSettings(
|
||||
new AetheriaRuntimeExponentialLerp(
|
||||
priceModifier.Exponent,
|
||||
priceModifier.Minimum,
|
||||
priceModifier.Maximum),
|
||||
(source.Tiers ?? Array.Empty<RarityTier>())
|
||||
.Select(tier => new AetheriaRuntimeItemRarityTier(
|
||||
tier.Name,
|
||||
tier.Quality,
|
||||
tier.Color.x,
|
||||
tier.Color.y,
|
||||
tier.Color.z))
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
private static double GetTypedBehaviorNumber(TradeRow row, BehaviorFilter behaviorFilter, AetheriaRuntimeBehaviorFieldMetadata field)
|
||||
{
|
||||
var payload = FindTypedBehaviorPayload(row.TypedItem, behaviorFilter);
|
||||
|
|
@ -476,7 +457,7 @@ public class TradeMenu : MonoBehaviour
|
|||
return AetheriaRuntimeDaemonTradeItemQueries.ProjectTradeItem(
|
||||
typedItem,
|
||||
ProjectTradeItemCommit(item),
|
||||
ProjectTradeValueSettings()).Price;
|
||||
GameManager.ObservedTradeValueSettings()).Price;
|
||||
}
|
||||
|
||||
private void ShowUnableToBuy(string reason)
|
||||
|
|
|
|||
|
|
@ -119,6 +119,105 @@ namespace GameCult.Aetheria.State.Verse
|
|||
durability);
|
||||
}
|
||||
|
||||
public static bool TryProjectLoadoutTemplatePrice(
|
||||
AetheriaRuntimeLoadoutTemplateSnapshot? template,
|
||||
AetheriaRuntimeCatalogSnapshot? catalog,
|
||||
AetheriaRuntimeTradeValueSettings? settings,
|
||||
out int price)
|
||||
{
|
||||
price = 0;
|
||||
return TryProjectEntityLoadoutPrice(template?.RootEntity, catalog, settings, out price);
|
||||
}
|
||||
|
||||
private static bool TryProjectEntityLoadoutPrice(
|
||||
AetheriaRuntimeEntityLoadoutSnapshot? entity,
|
||||
AetheriaRuntimeCatalogSnapshot? catalog,
|
||||
AetheriaRuntimeTradeValueSettings? settings,
|
||||
out int price)
|
||||
{
|
||||
price = 0;
|
||||
if (entity == null || catalog == null)
|
||||
return false;
|
||||
|
||||
if (!TryAddLoadoutItemPrice(entity.Hull, catalog, settings, ref price))
|
||||
return false;
|
||||
|
||||
if (!TryAddSlotPrices(entity.Equipment, catalog, settings, ref price) ||
|
||||
!TryAddSlotPrices(entity.CargoBays, catalog, settings, ref price) ||
|
||||
!TryAddSlotPrices(entity.DockingBays, catalog, settings, ref price) ||
|
||||
!TryAddCargoPrices(entity.CargoContents, catalog, settings, ref price) ||
|
||||
!TryAddCargoPrices(entity.DockingBayContents, catalog, settings, ref price))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var child in entity.Children ?? Array.Empty<AetheriaRuntimeEntityLoadoutSnapshot>())
|
||||
{
|
||||
if (!TryProjectEntityLoadoutPrice(child, catalog, settings, out var childPrice))
|
||||
return false;
|
||||
|
||||
price += childPrice;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryAddSlotPrices(
|
||||
IReadOnlyList<AetheriaRuntimeLoadoutItemSlotSnapshot>? slots,
|
||||
AetheriaRuntimeCatalogSnapshot catalog,
|
||||
AetheriaRuntimeTradeValueSettings? settings,
|
||||
ref int price)
|
||||
{
|
||||
foreach (var slot in slots ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotSnapshot>())
|
||||
{
|
||||
if (!TryAddLoadoutItemPrice(slot?.Item, catalog, settings, ref price))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryAddCargoPrices(
|
||||
IReadOnlyList<AetheriaRuntimeCargoBayLoadoutSnapshot>? bays,
|
||||
AetheriaRuntimeCatalogSnapshot catalog,
|
||||
AetheriaRuntimeTradeValueSettings? settings,
|
||||
ref int price)
|
||||
{
|
||||
foreach (var bay in bays ?? Array.Empty<AetheriaRuntimeCargoBayLoadoutSnapshot>())
|
||||
{
|
||||
if (!TryAddSlotPrices(bay?.Items, catalog, settings, ref price))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryAddLoadoutItemPrice(
|
||||
AetheriaRuntimeLoadoutItemSnapshot? item,
|
||||
AetheriaRuntimeCatalogSnapshot catalog,
|
||||
AetheriaRuntimeTradeValueSettings? settings,
|
||||
ref int price)
|
||||
{
|
||||
if (item == null || string.IsNullOrWhiteSpace(item.ItemKey))
|
||||
return false;
|
||||
|
||||
var typedItem = catalog.FindItem(item.ItemKey);
|
||||
if (typedItem == null)
|
||||
return false;
|
||||
|
||||
if (typedItem.Stackable)
|
||||
{
|
||||
price += typedItem.Price * Math.Max(1, item.Quantity);
|
||||
return true;
|
||||
}
|
||||
|
||||
price += ProjectTradeItem(
|
||||
typedItem,
|
||||
CraftedItemCommit(item.ItemKey, item.Quality, item.Durability),
|
||||
settings).Price;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeItemRarityTier? SelectTier(
|
||||
IReadOnlyList<AetheriaRuntimeItemRarityTier> tiers,
|
||||
double quality)
|
||||
|
|
|
|||
Loading…
Reference in a new issue