Add finite prebattle shop stock
This commit is contained in:
@@ -248,34 +248,57 @@ func _is_condition_shape_valid(condition) -> bool:
|
||||
func _normalized_shop(source) -> Dictionary:
|
||||
var item_ids := []
|
||||
var seen := {}
|
||||
var stock := {}
|
||||
if typeof(source) != TYPE_DICTIONARY:
|
||||
return {"items": item_ids}
|
||||
return {"items": item_ids, "stock": stock}
|
||||
for entry in source.get("items", []):
|
||||
var item_id := ""
|
||||
if typeof(entry) == TYPE_DICTIONARY:
|
||||
item_id = str(entry.get("id", ""))
|
||||
else:
|
||||
item_id = str(entry)
|
||||
var item_id := _shop_item_id_from_entry(entry)
|
||||
if item_id.is_empty() or seen.has(item_id):
|
||||
continue
|
||||
seen[item_id] = true
|
||||
item_ids.append(item_id)
|
||||
_apply_shop_stock_entry(stock, item_id, entry)
|
||||
_apply_shop_stock_block(stock, source.get("stock", {}), seen)
|
||||
for block in source.get("conditional_items", []):
|
||||
if typeof(block) != TYPE_DICTIONARY:
|
||||
continue
|
||||
if not _campaign_flags_match(block.get("campaign_flags", {})):
|
||||
continue
|
||||
for entry in block.get("items", []):
|
||||
var item_id := ""
|
||||
if typeof(entry) == TYPE_DICTIONARY:
|
||||
item_id = str(entry.get("id", ""))
|
||||
else:
|
||||
item_id = str(entry)
|
||||
var item_id := _shop_item_id_from_entry(entry)
|
||||
if item_id.is_empty() or seen.has(item_id):
|
||||
continue
|
||||
seen[item_id] = true
|
||||
item_ids.append(item_id)
|
||||
return {"items": item_ids}
|
||||
_apply_shop_stock_entry(stock, item_id, entry)
|
||||
_apply_shop_stock_block(stock, block.get("stock", {}), seen)
|
||||
return {"items": item_ids, "stock": stock}
|
||||
|
||||
|
||||
func _shop_item_id_from_entry(entry) -> String:
|
||||
if typeof(entry) == TYPE_DICTIONARY:
|
||||
return str(entry.get("id", ""))
|
||||
return str(entry)
|
||||
|
||||
|
||||
func _apply_shop_stock_entry(stock: Dictionary, item_id: String, entry) -> void:
|
||||
if item_id.is_empty() or typeof(entry) != TYPE_DICTIONARY or not entry.has("stock"):
|
||||
return
|
||||
var count := int(entry.get("stock", -1))
|
||||
if count >= 0:
|
||||
stock[item_id] = count
|
||||
|
||||
|
||||
func _apply_shop_stock_block(stock: Dictionary, block, seen: Dictionary) -> void:
|
||||
if typeof(block) != TYPE_DICTIONARY:
|
||||
return
|
||||
for item_id in block.keys():
|
||||
var normalized_id := str(item_id)
|
||||
if normalized_id.is_empty() or not seen.has(normalized_id):
|
||||
continue
|
||||
var count := int(block[item_id])
|
||||
if count >= 0:
|
||||
stock[normalized_id] = count
|
||||
|
||||
|
||||
func _normalized_deployment_rules(source) -> Dictionary:
|
||||
@@ -1155,6 +1178,16 @@ func get_shop_item_ids() -> Array:
|
||||
return result
|
||||
|
||||
|
||||
func get_shop_stock_limit(item_id: String) -> int:
|
||||
var normalized := str(item_id)
|
||||
if normalized.is_empty():
|
||||
return -1
|
||||
var stock: Dictionary = shop.get("stock", {})
|
||||
if not stock.has(normalized):
|
||||
return -1
|
||||
return int(stock.get(normalized, -1))
|
||||
|
||||
|
||||
func get_formation_cells() -> Array[Vector2i]:
|
||||
return formation_cells.duplicate()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user