Add finite prebattle shop stock
This commit is contained in:
@@ -802,6 +802,41 @@ function Resolve-Shop-Item-Id($Entry, [string]$Context) {
|
||||
Fail "$Context has a malformed shop item entry."
|
||||
}
|
||||
|
||||
function Check-Shop-Stock-Value($Value, [string]$Context) {
|
||||
$isInteger = (
|
||||
$Value -is [byte] -or
|
||||
$Value -is [int16] -or
|
||||
$Value -is [int] -or
|
||||
$Value -is [long]
|
||||
)
|
||||
if (-not $isInteger -or [long]$Value -lt 0) {
|
||||
Fail "$Context stock must be a non-negative integer."
|
||||
}
|
||||
}
|
||||
|
||||
function Check-Shop-Entry-Stock($Entry, [string]$ItemId, [string]$Context) {
|
||||
if (-not (Has-Prop $Entry "stock")) {
|
||||
return
|
||||
}
|
||||
Check-Shop-Stock-Value (Get-Prop $Entry "stock" $null) "$Context item $ItemId"
|
||||
}
|
||||
|
||||
function Check-Shop-Stock-Block($Stock, $AllowedItemIds, [string]$Context) {
|
||||
if ($null -eq $Stock -or $Stock -is [System.Array] -or $Stock -is [string] -or $Stock -is [ValueType]) {
|
||||
Fail "$Context stock must be an object."
|
||||
}
|
||||
foreach ($prop in @($Stock.PSObject.Properties)) {
|
||||
$itemId = [string]$prop.Name
|
||||
if ([string]::IsNullOrWhiteSpace($itemId)) {
|
||||
Fail "$Context stock has an empty item id."
|
||||
}
|
||||
if (-not $AllowedItemIds.Contains($itemId)) {
|
||||
Fail "$Context stock references item outside that shop branch: $itemId"
|
||||
}
|
||||
Check-Shop-Stock-Value $prop.Value "$Context stock $itemId"
|
||||
}
|
||||
}
|
||||
|
||||
function Check-Shop($Shop, [string]$ScenarioId) {
|
||||
if ($null -eq $Shop) {
|
||||
return
|
||||
@@ -831,11 +866,15 @@ function Check-Shop($Shop, [string]$ScenarioId) {
|
||||
if (-not $itemIds.Contains($itemId)) {
|
||||
Fail "Scenario $ScenarioId shop references unknown item: $itemId"
|
||||
}
|
||||
Check-Shop-Entry-Stock $entry $itemId "Scenario $ScenarioId shop"
|
||||
$item = Find-Item-Def $itemId
|
||||
if ([int](Get-Prop $item "price" 0) -le 0) {
|
||||
Fail "Scenario $ScenarioId shop item $itemId has no positive price."
|
||||
}
|
||||
}
|
||||
if (Has-Prop $Shop "stock") {
|
||||
Check-Shop-Stock-Block $Shop.stock $seenShopItems "Scenario $ScenarioId shop"
|
||||
}
|
||||
|
||||
$conditionalItems = Get-Prop $Shop "conditional_items" @()
|
||||
foreach ($block in @($conditionalItems)) {
|
||||
@@ -866,11 +905,15 @@ function Check-Shop($Shop, [string]$ScenarioId) {
|
||||
if (-not $itemIds.Contains($itemId)) {
|
||||
Fail "Scenario $ScenarioId shop conditional_items references unknown item: $itemId"
|
||||
}
|
||||
Check-Shop-Entry-Stock $entry $itemId "Scenario $ScenarioId shop conditional_items"
|
||||
$item = Find-Item-Def $itemId
|
||||
if ([int](Get-Prop $item "price" 0) -le 0) {
|
||||
Fail "Scenario $ScenarioId shop conditional item $itemId has no positive price."
|
||||
}
|
||||
}
|
||||
if (Has-Prop $block "stock") {
|
||||
Check-Shop-Stock-Block $block.stock $seenConditionalItems "Scenario $ScenarioId shop conditional_items"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user