Add unit defeat event reactions
This commit is contained in:
@@ -92,7 +92,7 @@ $validConditionTypes = @(
|
||||
"all",
|
||||
"any"
|
||||
)
|
||||
$validTriggers = @("battle_start", "battle_begin", "turn_start", "unit_reaches_tile")
|
||||
$validTriggers = @("battle_start", "battle_begin", "turn_start", "unit_reaches_tile", "unit_defeated")
|
||||
$validActions = @("log", "dialogue", "set_objective", "grant_item", "grant_items", "spawn_deployment", "spawn_deployments", "withdraw_unit", "withdraw_units")
|
||||
$validEffects = @("heal_hp", "heal_mp", "cure_status")
|
||||
$validItemKinds = @("weapon", "armor", "accessory", "consumable")
|
||||
@@ -398,6 +398,55 @@ function Check-Unit-Reaches-Event-When($When, [string]$ScenarioId, [int]$Width,
|
||||
}
|
||||
}
|
||||
|
||||
function Check-Unit-Defeated-Event-When($When, [string]$ScenarioId, $KnownUnitIds) {
|
||||
$unitIdsValue = $null
|
||||
if (Has-Prop $When "unit_ids") {
|
||||
$unitIdsValue = $When.unit_ids
|
||||
if ($null -ne $unitIdsValue -and -not ($unitIdsValue -is [System.Array])) {
|
||||
Fail "Scenario $ScenarioId unit_defeated event unit_ids must be an array."
|
||||
}
|
||||
foreach ($unitIdValue in @($unitIdsValue)) {
|
||||
$unitId = [string]$unitIdValue
|
||||
if ([string]::IsNullOrWhiteSpace($unitId)) {
|
||||
Fail "Scenario $ScenarioId unit_defeated event has empty unit id."
|
||||
}
|
||||
if ($null -ne $KnownUnitIds -and (-not $KnownUnitIds.Contains($unitId))) {
|
||||
Fail "Scenario $ScenarioId unit_defeated event references unknown unit: $unitId"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$officerIdsValue = $null
|
||||
if (Has-Prop $When "officer_ids") {
|
||||
$officerIdsValue = $When.officer_ids
|
||||
if ($null -ne $officerIdsValue -and -not ($officerIdsValue -is [System.Array])) {
|
||||
Fail "Scenario $ScenarioId unit_defeated event officer_ids must be an array."
|
||||
}
|
||||
foreach ($officerIdValue in @($officerIdsValue)) {
|
||||
$officerId = [string]$officerIdValue
|
||||
if ([string]::IsNullOrWhiteSpace($officerId) -or (-not $officerIds.Contains($officerId))) {
|
||||
Fail "Scenario $ScenarioId unit_defeated event references unknown officer: $officerId"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$team = [string](Get-Prop $When "team" "")
|
||||
if (-not [string]::IsNullOrWhiteSpace($team) -and $team -ne "player" -and $team -ne "enemy") {
|
||||
Fail "Scenario $ScenarioId unit_defeated event has unknown team: $team"
|
||||
}
|
||||
$unitIdCount = 0
|
||||
if ($null -ne $unitIdsValue) {
|
||||
$unitIdCount = @($unitIdsValue).Count
|
||||
}
|
||||
$officerIdCount = 0
|
||||
if ($null -ne $officerIdsValue) {
|
||||
$officerIdCount = @($officerIdsValue).Count
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($team) -and $unitIdCount -le 0 -and $officerIdCount -le 0) {
|
||||
Fail "Scenario $ScenarioId unit_defeated event needs team, unit_ids, or officer_ids."
|
||||
}
|
||||
}
|
||||
|
||||
function Resolve-Class-Id($Deployment, [string]$ScenarioId) {
|
||||
$classId = [string](Get-Prop $Deployment "class_id" "")
|
||||
if (-not [string]::IsNullOrWhiteSpace($classId)) {
|
||||
@@ -1763,6 +1812,9 @@ foreach ($scenario in $campaign.scenarios) {
|
||||
if ($trigger -eq "unit_reaches_tile") {
|
||||
Check-Unit-Reaches-Event-When $when $scenarioId $width $height $rows $knownUnitIds
|
||||
}
|
||||
if ($trigger -eq "unit_defeated") {
|
||||
Check-Unit-Defeated-Event-When $when $scenarioId $knownUnitIds
|
||||
}
|
||||
foreach ($action in (Get-Prop $event "actions" @())) {
|
||||
$actionType = [string]$action.type
|
||||
if (-not $validActions.Contains($actionType)) {
|
||||
|
||||
Reference in New Issue
Block a user