Files
mtgodot-poc/project/test_monarch_empire_treasury_parity.gd
T
shenandshen 66d217b313 feat(client): 完成40250客户端核心功能1:1对齐与桥梁高度采样修复
- 桥梁与静态物体高度采样修复:
  - 严格对齐 40250 CMapOutdoor::GetHeight 与 CAttributeInstance::GetHeight
  - 解析 .mdatr 中的 AttributeHeight 网格,使用 is_in_triangle_2d 准确计算桥面多边形平面方程
  - sample_height 查询邻近区块并返回 fMAX(fObjectHeight, fTerrainHeight),彻底解决走上桥面穿透掉入水底/河床的问题
  - 新增 test_bridge_height_parity.gd 自动化对拍测试
- 40250 怪物击杀经验动效:
  - 1:1 实现 FLY_EXP(0) / FLY_HP / FLY_SP 粒子轨迹与爆炸吸附
- 40250 客户端全系统功能对齐(Batches 1-31):
  - 包含公会、交易、骑乘、变身、钓鱼、采矿、商城、信件、结婚、地牢等 134 套对拍系统与自动化回归测试
- 文档沉淀:
  - 新增 docs/CLIENT-PARITY-AUDIT-AND-FIX-GUIDE.md 客户端对拍缺陷发现与修复工程指南
2026-09-19 08:51:25 -07:00

152 lines
6.0 KiB
GDScript

# test_monarch_empire_treasury_parity.gd —— Metin2 40250 君主特权与国库祈愿系统 1:1 测试套件
extends SceneTree
const MonarchEmpireTreasurySystem = preload("res://monarch_empire_treasury_system.gd")
var _passed := 0
var _failed := 0
func _assert(cond: bool, msg: String) -> void:
if cond:
_passed += 1
print(" [PASS] %s" % msg)
else:
_failed += 1
printerr(" [FAIL] %s" % msg)
func _init() -> void:
print("\n=== Running test_monarch_empire_treasury_parity (Direction 1: Monarch & Treasury 1:1) ===")
test_monarch_appointment()
test_treasury_management_and_tax()
test_heal_my_empire()
test_power_up_and_defense_up()
test_serialization()
print("\n=======================================================")
print("Monarch Treasury Tests: %d Passed, %d Failed" % [_passed, _failed])
print("=======================================================\n")
if _failed > 0:
quit(1)
else:
quit(0)
func test_monarch_appointment() -> void:
print("\n--- Test 1: Monarch Appointment & Verification (40250 1:1) ---")
var system = MonarchEmpireTreasurySystem.new()
_assert(system.is_monarch(1001, 1) == false, "No monarch initially")
# 任命辛秀帝国 (红国 1) 君主
var ok = system.appoint_monarch(1, 1001, "赤霄狂帝")
_assert(ok == true, "Appointed Shinsoo monarch")
_assert(system.is_monarch(1001, 1) == true, "Player 1001 is monarch of Shinsoo")
_assert(system.is_monarch(1002, 1) == false, "Player 1002 is not monarch")
_assert(system.is_monarch(1001, 2) == false, "Player 1001 is not Chunjo monarch")
var info = system.get_monarch_info(1)
_assert(info["player_name"] == "赤霄狂帝", "Monarch name recorded")
_assert(info["player_id"] == 1001, "Monarch PID recorded")
func test_treasury_management_and_tax() -> void:
print("\n--- Test 2: Treasury Gold & Monster Micro-Tax (40250 1:1) ---")
var system = MonarchEmpireTreasurySystem.new()
_assert(system.get_treasury_gold(1) == 0, "Treasury starts at 0")
# 国库注资 1,000,000
system.add_treasury_gold(1, 1000000)
_assert(system.get_treasury_gold(1) == 1000000, "Treasury has 1,000,000 gold")
# 征缴打怪微税 (2% 进国库)
var tax = system.collect_monster_tax(1, 50000, 0.02)
_assert(tax == 1000, "Collected 1,000 gold tax from 50,000 drop")
_assert(system.get_treasury_gold(1) == 1001000, "Treasury increased to 1,001,000")
# 扣除资金
var dec_ok = system.dec_treasury_gold(1, 500000)
_assert(dec_ok == true, "Dec treasury 500,000 succeeded")
_assert(system.get_treasury_gold(1) == 501000, "Treasury balance is 501,000")
# 超额扣除拦截
dec_ok = system.dec_treasury_gold(1, 9999999)
_assert(dec_ok == false, "Rejected overdraft")
func test_heal_my_empire() -> void:
print("\n--- Test 3: HealMyEmpire Grace (40250 1:1) ---")
var system = MonarchEmpireTreasurySystem.new()
system.appoint_monarch(1, 1001, "赤霄狂帝")
system.add_treasury_gold(1, 300000) # 存入 300,000
# 模拟在线国民
var citizens: Array[Dictionary] = [
{"pid": 1001, "empire": 1, "hp": 200, "max_hp": 2000, "sp": 50, "max_sp": 500},
{"pid": 1002, "empire": 1, "hp": 50, "max_hp": 1500, "sp": 10, "max_sp": 400},
{"pid": 2001, "empire": 2, "hp": 100, "max_hp": 1000, "sp": 20, "max_sp": 300} # 敌国国民
]
# 非君主尝试施展 -> 拦截
var res = system.heal_my_empire(1002, 1, citizens)
_assert(res["ok"] == false, "Rejected non-monarch cast")
_assert(res["reason"] == "NOT_MONARCH", "Reason is NOT_MONARCH")
# 君主施展恩泽圣愈
res = system.heal_my_empire(1001, 1, citizens)
_assert(res["ok"] == true, "HealMyEmpire succeeded")
_assert(res["healed_count"] == 2, "Healed 2 Shinsoo citizens")
_assert(citizens[0]["hp"] == 2000 and citizens[0]["sp"] == 500, "Citizen 1 fully restored")
_assert(citizens[1]["hp"] == 1500 and citizens[1]["sp"] == 400, "Citizen 2 fully restored")
_assert(citizens[2]["hp"] == 100, "Enemy empire citizen not healed")
_assert(res["remaining_treasury"] == 200000, "Cost 100,000 deducted from treasury")
# 冷却期连续施放 -> 拦截
res = system.heal_my_empire(1001, 1, citizens)
_assert(res["ok"] == false, "Rejected during cooldown")
_assert(res["reason"] == "COOLDOWN_ACTIVE", "Reason is COOLDOWN_ACTIVE")
func test_power_up_and_defense_up() -> void:
print("\n--- Test 4: PowerUp & DefenseUp Empire Auras (40250 1:1) ---")
var system = MonarchEmpireTreasurySystem.new()
system.appoint_monarch(1, 1001, "赤霄狂帝")
system.add_treasury_gold(1, 2000000) # 200万国库金币
# 激活战力觉醒 (PowerUp, +10% 攻击力)
var res = system.activate_power_up(1001, 1)
_assert(res["ok"] == true, "Activated PowerUp")
_assert(res["att_grade_bonus"] == 0.10, "+10% attack bonus")
_assert(res["remaining_treasury"] == 1500000, "Deducted 500,000 cost")
# 激活铁壁守护 (DefenseUp, +10% 防御力)
res = system.activate_defense_up(1001, 1)
_assert(res["ok"] == true, "Activated DefenseUp")
_assert(res["def_grade_bonus"] == 0.10, "+10% defense bonus")
# 检查国民享受的增益
var buffs = system.get_citizen_empire_buffs(1)
_assert(buffs["att_bonus"] == 0.10, "Shinsoo citizen enjoys +10% attack")
_assert(buffs["def_bonus"] == 0.10, "Shinsoo citizen enjoys +10% defense")
# 敌国无增益
var enemy_buffs = system.get_citizen_empire_buffs(2)
_assert(enemy_buffs["att_bonus"] == 0.0, "Enemy has 0 bonus")
# 时间推移 1900 秒 (增益持续 1800 秒结束)
system.update(1900.0)
buffs = system.get_citizen_empire_buffs(1)
_assert(buffs["att_bonus"] == 0.0 and buffs["def_bonus"] == 0.0, "Auras expired naturally")
func test_serialization() -> void:
print("\n--- Test 5: Serialization & Restoration ---")
var system = MonarchEmpireTreasurySystem.new()
system.appoint_monarch(1, 1001, "赤霄狂帝")
system.add_treasury_gold(1, 888888)
var data = system.serialize()
_assert(data.has("monarch_pids") and data["treasury"][1] == 888888, "Serialized state")
var restored = MonarchEmpireTreasurySystem.new()
restored.deserialize(data)
_assert(restored.is_monarch(1001, 1) == true, "Restored monarch PID")
_assert(restored.get_treasury_gold(1) == 888888, "Restored treasury gold")