74 lines
2.3 KiB
GDScript
74 lines
2.3 KiB
GDScript
# shop_rules_test —— ClientVS22 出售价格、anti-flag 与贵重物品确认规则回归。
|
|
extends SceneTree
|
|
|
|
const ShopUI = preload("res://ui/shop_ui.gd")
|
|
|
|
class FakeClient extends Node:
|
|
var calls: Array = []
|
|
func get_shop_items() -> Array:
|
|
return []
|
|
func get_shop() -> Dictionary:
|
|
return {"tabs": [{"name": "", "items": []}]}
|
|
func shop_sell(cell: int, count: int) -> bool:
|
|
calls.append([cell, count])
|
|
return true
|
|
|
|
class FakeProto extends Node:
|
|
var items: Dictionary = {}
|
|
func item(vnum: int) -> Dictionary:
|
|
return items.get(vnum, {})
|
|
|
|
var _failed := false
|
|
|
|
func _check(ok: bool, label: String) -> void:
|
|
if ok:
|
|
return
|
|
_failed = true
|
|
push_error("FAIL: " + label)
|
|
|
|
func _init() -> void:
|
|
var host := Control.new()
|
|
root.add_child(host)
|
|
var client := FakeClient.new()
|
|
root.add_child(client)
|
|
var proto := FakeProto.new()
|
|
proto.items = {
|
|
31: {"sell_price": 6000, "flags": 0, "anti_flags": 0},
|
|
32: {"sell_price": 1000, "flags": 1 << 3, "anti_flags": 0},
|
|
33: {"sell_price": 1000, "flags": 0, "anti_flags": 1 << 8},
|
|
34: {"sell_price": 1000, "flags": 0, "anti_flags": 0},
|
|
}
|
|
root.add_child(proto)
|
|
var shop := ShopUI.new()
|
|
root.add_child(shop)
|
|
shop.setup(client, host, proto)
|
|
shop.open()
|
|
shop._set_mode(2)
|
|
|
|
_check(shop._sell_price(31, 3) == 3600, "normal sell price is unit price * count / 5")
|
|
_check(shop._sell_price(32, 30000) == 6, "count-per-1-gold uses count / unit price / 5")
|
|
_check(not shop._drop_to_sell({"window": 1, "cell": 3, "vnum": 33, "count": 1}),
|
|
"anti-flag sell is rejected")
|
|
_check(client.calls.is_empty(), "anti-flag does not send sell packet")
|
|
|
|
shop._sell_quantity.value = 2
|
|
_check(shop._drop_to_sell({"window": 1, "cell": 4, "vnum": 31, "count": 4}),
|
|
"valuable sell enters confirmation flow")
|
|
_check(shop._sell_confirm != null and client.calls.is_empty(),
|
|
"valuable sell waits for confirmation")
|
|
if shop._sell_confirm:
|
|
shop._sell_confirm.confirmed.emit()
|
|
_check(client.calls == [[4, 2]], "confirmed valuable sell sends selected count")
|
|
|
|
shop._sell_quantity.value = 1
|
|
_check(shop._drop_to_sell({"window": 1, "cell": 5, "vnum": 34, "count": 3}),
|
|
"ordinary sell sends immediately")
|
|
_check(client.calls == [[4, 2], [5, 1]], "ordinary sell uses selected count")
|
|
|
|
host.queue_free()
|
|
if _failed:
|
|
quit(1)
|
|
else:
|
|
print("PASS: shop_rules_test (price + anti-flag + confirmation)")
|
|
quit(0)
|