Add camp talk supply claims
This commit is contained in:
195
tools/smoke_camp_conversation_rewards.gd
Normal file
195
tools/smoke_camp_conversation_rewards.gd
Normal file
@@ -0,0 +1,195 @@
|
||||
extends SceneTree
|
||||
|
||||
const BattleSceneScript := preload("res://scripts/scenes/battle_scene.gd")
|
||||
|
||||
const CAMPAIGN_PATH := "res://data/campaign/campaign.json"
|
||||
const SCENARIO_ID := "001_yellow_turbans"
|
||||
const SCENARIO_PATH := "res://data/scenarios/001_yellow_turbans.json"
|
||||
const CONVERSATION_ID := "northern_woods_cache"
|
||||
const SAVE_PATH := "user://campaign_save.json"
|
||||
const MANUAL_SAVE_PATH := "user://campaign_manual_save.json"
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
var save_backup := _backup_user_file(SAVE_PATH)
|
||||
var manual_backup := _backup_user_file(MANUAL_SAVE_PATH)
|
||||
var failures: Array[String] = []
|
||||
|
||||
_check_claim_updates_campaign_and_battle(failures)
|
||||
_check_shop_and_armory_preserve_claim(failures)
|
||||
_check_manual_checkpoint_reverts_claim(failures)
|
||||
_check_completed_replay_cannot_claim(failures)
|
||||
|
||||
if not _restore_user_file(SAVE_PATH, save_backup):
|
||||
failures.append("could not restore automatic campaign save")
|
||||
if not _restore_user_file(MANUAL_SAVE_PATH, manual_backup):
|
||||
failures.append("could not restore manual campaign save")
|
||||
|
||||
if failures.is_empty():
|
||||
print("camp conversation rewards smoke ok")
|
||||
quit(0)
|
||||
return
|
||||
|
||||
for failure in failures:
|
||||
push_error(failure)
|
||||
quit(1)
|
||||
|
||||
|
||||
func _check_claim_updates_campaign_and_battle(failures: Array[String]) -> void:
|
||||
var scene = _new_prebattle_scene(failures, "claim update")
|
||||
if scene == null:
|
||||
return
|
||||
var conversation: Dictionary = scene._camp_conversation_by_id(CONVERSATION_ID)
|
||||
if not _check_cache_conversation(failures, conversation):
|
||||
scene.free()
|
||||
return
|
||||
|
||||
var before := int(scene.campaign_state.get_inventory_snapshot().get("bean", 0))
|
||||
if not scene._format_camp_conversation_button_text(conversation).contains("available"):
|
||||
failures.append("camp conversation button should show available before claim")
|
||||
scene._apply_camp_conversation_effects(conversation)
|
||||
|
||||
var campaign_after := int(scene.campaign_state.get_inventory_snapshot().get("bean", 0))
|
||||
var battle_after := int(scene.state.get_inventory_snapshot().get("bean", 0))
|
||||
if campaign_after != before + 1:
|
||||
failures.append("camp conversation should add one Bean to campaign inventory")
|
||||
if battle_after != before + 1:
|
||||
failures.append("camp conversation should refresh loaded battle inventory")
|
||||
if not scene.campaign_state.has_claimed_camp_conversation_effects(SCENARIO_ID, CONVERSATION_ID):
|
||||
failures.append("camp conversation claim should be saved in campaign ledger")
|
||||
if not scene._format_camp_conversation_button_text(conversation).contains("claimed"):
|
||||
failures.append("camp conversation button should show claimed after claim")
|
||||
|
||||
scene._apply_camp_conversation_effects(conversation)
|
||||
var duplicate_after := int(scene.campaign_state.get_inventory_snapshot().get("bean", 0))
|
||||
if duplicate_after != campaign_after:
|
||||
failures.append("camp conversation should not duplicate rewards")
|
||||
scene.free()
|
||||
|
||||
|
||||
func _check_shop_and_armory_preserve_claim(failures: Array[String]) -> void:
|
||||
var scene = _new_prebattle_scene(failures, "shop and armory preservation")
|
||||
if scene == null:
|
||||
return
|
||||
var conversation: Dictionary = scene._camp_conversation_by_id(CONVERSATION_ID)
|
||||
if not _check_cache_conversation(failures, conversation):
|
||||
scene.free()
|
||||
return
|
||||
scene._apply_camp_conversation_effects(conversation)
|
||||
var claimed_beans := int(scene.campaign_state.get_inventory_snapshot().get("bean", 0))
|
||||
|
||||
scene.campaign_state.gold = 1000
|
||||
var antidote: Dictionary = scene.state.get_item_def("antidote")
|
||||
var price := int(antidote.get("price", 0))
|
||||
if price <= 0 or not scene.campaign_state.try_buy_item("antidote", price, SCENARIO_ID, scene.state.get_shop_stock_limit("antidote")):
|
||||
failures.append("shop purchase after camp claim should save")
|
||||
else:
|
||||
scene.state.set_inventory_snapshot(scene.campaign_state.get_inventory_snapshot())
|
||||
var after_buy := int(scene.campaign_state.get_inventory_snapshot().get("bean", 0))
|
||||
if after_buy != claimed_beans:
|
||||
failures.append("shop purchase should preserve camp-claimed Bean")
|
||||
|
||||
if not scene.campaign_state.try_save_prebattle_loadout(scene.state.get_player_roster_snapshot(), scene.state.get_inventory_snapshot()):
|
||||
failures.append("armory save after camp claim should save")
|
||||
else:
|
||||
var after_armory := int(scene.campaign_state.get_inventory_snapshot().get("bean", 0))
|
||||
if after_armory != claimed_beans:
|
||||
failures.append("armory save should preserve camp-claimed Bean")
|
||||
if not scene.campaign_state.has_claimed_camp_conversation_effects(SCENARIO_ID, CONVERSATION_ID):
|
||||
failures.append("armory save should preserve camp claim ledger")
|
||||
scene.free()
|
||||
|
||||
|
||||
func _check_manual_checkpoint_reverts_claim(failures: Array[String]) -> void:
|
||||
var scene = _new_prebattle_scene(failures, "manual checkpoint")
|
||||
if scene == null:
|
||||
return
|
||||
if not scene.campaign_state.save_manual_game():
|
||||
failures.append("manual checkpoint before camp claim should save")
|
||||
scene.free()
|
||||
return
|
||||
var conversation: Dictionary = scene._camp_conversation_by_id(CONVERSATION_ID)
|
||||
scene._apply_camp_conversation_effects(conversation)
|
||||
if int(scene.campaign_state.get_inventory_snapshot().get("bean", 0)) != 1:
|
||||
failures.append("camp claim should add Bean before manual restore")
|
||||
if not scene.campaign_state.load_manual_game():
|
||||
failures.append("manual checkpoint should load after camp claim")
|
||||
else:
|
||||
if int(scene.campaign_state.get_inventory_snapshot().get("bean", 0)) != 0:
|
||||
failures.append("loading older manual checkpoint should revert camp reward inventory")
|
||||
if scene.campaign_state.has_claimed_camp_conversation_effects(SCENARIO_ID, CONVERSATION_ID):
|
||||
failures.append("loading older manual checkpoint should revert camp claim ledger")
|
||||
scene.free()
|
||||
|
||||
|
||||
func _check_completed_replay_cannot_claim(failures: Array[String]) -> void:
|
||||
var scene = _new_prebattle_scene(failures, "completed replay")
|
||||
if scene == null:
|
||||
return
|
||||
scene.campaign_state.completed_scenarios.append(SCENARIO_ID)
|
||||
var conversation: Dictionary = scene._camp_conversation_by_id(CONVERSATION_ID)
|
||||
scene._apply_camp_conversation_effects(conversation)
|
||||
if int(scene.campaign_state.get_inventory_snapshot().get("bean", 0)) != 0:
|
||||
failures.append("completed replay should not claim camp supplies")
|
||||
if scene.campaign_state.has_claimed_camp_conversation_effects(SCENARIO_ID, CONVERSATION_ID):
|
||||
failures.append("completed replay should not write camp claim ledger")
|
||||
scene.free()
|
||||
|
||||
|
||||
func _new_prebattle_scene(failures: Array[String], label: String):
|
||||
var scene = BattleSceneScript.new()
|
||||
if not scene.campaign_state.load_campaign(CAMPAIGN_PATH):
|
||||
failures.append("%s could not load campaign data" % label)
|
||||
scene.free()
|
||||
return null
|
||||
scene.campaign_state.start_new(SCENARIO_ID)
|
||||
scene.active_scenario_id = SCENARIO_ID
|
||||
if not scene.state.load_battle(
|
||||
SCENARIO_PATH,
|
||||
scene.campaign_state.get_roster_overrides(),
|
||||
scene.campaign_state.get_inventory_snapshot(),
|
||||
scene.campaign_state.get_flags_snapshot(),
|
||||
scene.campaign_state.get_joined_officers_snapshot()
|
||||
):
|
||||
failures.append("%s could not load scenario" % label)
|
||||
scene.free()
|
||||
return null
|
||||
return scene
|
||||
|
||||
|
||||
func _check_cache_conversation(failures: Array[String], conversation: Dictionary) -> bool:
|
||||
if conversation.is_empty():
|
||||
failures.append("could not find cache camp conversation")
|
||||
return false
|
||||
var effects: Array = conversation.get("effects", [])
|
||||
if effects.is_empty():
|
||||
failures.append("cache camp conversation should expose effects")
|
||||
return false
|
||||
var effect: Dictionary = effects[0]
|
||||
if str(effect.get("type", "")) != "grant_item":
|
||||
failures.append("cache camp conversation effect should be grant_item")
|
||||
if str(effect.get("item_id", "")) != "bean":
|
||||
failures.append("cache camp conversation should grant Bean")
|
||||
if int(effect.get("count", 0)) != 1:
|
||||
failures.append("cache camp conversation should grant one Bean")
|
||||
return true
|
||||
|
||||
|
||||
func _backup_user_file(path: String) -> Dictionary:
|
||||
var exists := FileAccess.file_exists(path)
|
||||
return {
|
||||
"exists": exists,
|
||||
"content": FileAccess.get_file_as_string(path) if exists else ""
|
||||
}
|
||||
|
||||
|
||||
func _restore_user_file(path: String, backup: Dictionary) -> bool:
|
||||
if bool(backup.get("exists", false)):
|
||||
var file := FileAccess.open(path, FileAccess.WRITE)
|
||||
if file == null:
|
||||
return false
|
||||
file.store_string(str(backup.get("content", "")))
|
||||
return true
|
||||
if FileAccess.file_exists(path):
|
||||
return DirAccess.remove_absolute(ProjectSettings.globalize_path(path)) == OK
|
||||
return true
|
||||
@@ -39,6 +39,7 @@ func _check_battle_visual_data(failures: Array[String]) -> void:
|
||||
_check_camp_conversation(failures, conversations[0], "cao_cao_strategy", "officer", "cao_cao")
|
||||
_check_camp_conversation(failures, conversations[1], "xiahou_dun_vanguard", "officer", "xiahou_dun")
|
||||
_check_camp_conversation(failures, conversations[2], "northern_woods_cache", "topic", "")
|
||||
_check_camp_conversation_effect(failures, conversations[2], "bean", 1)
|
||||
var merchant := state.get_shop_merchant()
|
||||
if merchant.is_empty() or (merchant.get("lines", []) as Array).is_empty():
|
||||
failures.append("001 shop should expose merchant lines")
|
||||
@@ -88,6 +89,11 @@ func _check_scene_texture_loading(failures: Array[String]) -> void:
|
||||
failures.append("battle scene should find Cao Cao camp conversation by id")
|
||||
elif not scene._format_camp_conversation_button_text(strategy).contains("Cao Cao"):
|
||||
failures.append("camp conversation button text should include label/speaker")
|
||||
var cache := scene._camp_conversation_by_id("northern_woods_cache")
|
||||
if cache.is_empty():
|
||||
failures.append("battle scene should find cache camp conversation by id")
|
||||
elif not scene._format_camp_conversation_button_text(cache).contains("Supply Bean"):
|
||||
failures.append("camp conversation button text should preview supply effect")
|
||||
scene.free()
|
||||
|
||||
|
||||
@@ -282,6 +288,20 @@ func _check_attack_motion_signal(failures: Array[String]) -> void:
|
||||
failures.append("attack motion signal missing expected Cao Cao attack: %s" % str(motions))
|
||||
|
||||
|
||||
func _check_camp_conversation_effect(failures: Array[String], conversation: Dictionary, expected_item_id: String, expected_count: int) -> void:
|
||||
var effects: Array = conversation.get("effects", [])
|
||||
if effects.is_empty():
|
||||
failures.append("camp conversation %s should expose effects" % str(conversation.get("id", "")))
|
||||
return
|
||||
var effect: Dictionary = effects[0]
|
||||
if str(effect.get("type", "")) != "grant_item":
|
||||
failures.append("camp conversation effect should be grant_item: %s" % str(effect))
|
||||
if str(effect.get("item_id", "")) != expected_item_id:
|
||||
failures.append("camp conversation effect item mismatch: %s" % str(effect))
|
||||
if int(effect.get("count", 0)) != expected_count:
|
||||
failures.append("camp conversation effect count mismatch: %s" % str(effect))
|
||||
|
||||
|
||||
func _check_camp_conversation(failures: Array[String], conversation: Dictionary, expected_id: String, expected_group: String, expected_officer_id: String) -> void:
|
||||
if str(conversation.get("id", "")) != expected_id:
|
||||
failures.append("camp conversation id mismatch: expected %s got %s" % [expected_id, str(conversation.get("id", ""))])
|
||||
|
||||
@@ -106,6 +106,7 @@ $validSkillEffectTypes = @("stat_bonus", "damage_over_time", "action_lock")
|
||||
$validSkillAreaShapes = @("single", "diamond")
|
||||
$validDialogueSides = @("left", "right")
|
||||
$validCampConversationGroups = @("officer", "topic")
|
||||
$validCampConversationEffectTypes = @("grant_item")
|
||||
$validPortraitPathPattern = '^res://.+\.(png|jpg|jpeg|webp)$'
|
||||
$minimumPortraitDimension = 512
|
||||
$portraitImageInspectorReady = $false
|
||||
@@ -1769,6 +1770,28 @@ function Check-Camp-Conversations($Conversations, [string]$ScenarioId) {
|
||||
foreach ($conversationLine in @($conversationLines)) {
|
||||
Check-Dialogue-Line $conversationLine "Scenario $ScenarioId briefing camp_conversations $conversationId"
|
||||
}
|
||||
if (Has-Prop $conversation "effects") {
|
||||
$rawEffects = Get-Prop $conversation "effects" $null
|
||||
$effects = @($rawEffects)
|
||||
if ($null -eq $rawEffects -or $effects.Count -le 0) {
|
||||
Fail "Scenario $ScenarioId briefing camp_conversations $conversationId effects must be an array."
|
||||
}
|
||||
foreach ($effect in $effects) {
|
||||
if ($effect -is [string] -or $effect -is [System.Array]) {
|
||||
Fail "Scenario $ScenarioId briefing camp_conversations $conversationId has malformed effect."
|
||||
}
|
||||
$effectType = [string](Get-Prop $effect "type" "")
|
||||
if (-not $validCampConversationEffectTypes.Contains($effectType)) {
|
||||
Fail "Scenario $ScenarioId briefing camp_conversations $conversationId has unknown effect: $effectType"
|
||||
}
|
||||
if ($effectType -eq "grant_item") {
|
||||
Check-Event-Grant-Item $effect "Scenario $ScenarioId briefing camp_conversations $conversationId grant_item"
|
||||
}
|
||||
if ((Has-Prop $effect "text") -and [string]::IsNullOrWhiteSpace([string](Get-Prop $effect "text" ""))) {
|
||||
Fail "Scenario $ScenarioId briefing camp_conversations $conversationId effect text must not be empty."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user