Add shop supplies and rebalance early economy
This commit is contained in:
parent
6386c5e3e3
commit
6a5923fdb8
41 changed files with 1159 additions and 52 deletions
|
|
@ -16,19 +16,13 @@ func setup(catalog: ItemCatalogType) -> void:
|
|||
|
||||
|
||||
func add_item(item_id: StringName, quantity: int = 1) -> bool:
|
||||
var item: ItemDataType = _resolve_valid_item(item_id)
|
||||
if item == null or quantity <= 0:
|
||||
if not can_add_item(item_id, quantity):
|
||||
return false
|
||||
var item: ItemDataType = _resolve_valid_item(item_id)
|
||||
var existing: OwnedItemType = get_owned_item(item_id)
|
||||
if existing != null:
|
||||
if not item.stackable:
|
||||
return false
|
||||
if existing.quantity + quantity > item.max_stack:
|
||||
return false
|
||||
existing.quantity += quantity
|
||||
else:
|
||||
if quantity > (item.max_stack if item.stackable else 1):
|
||||
return false
|
||||
var owned := OwnedItemType.new()
|
||||
owned.item_id = item_id
|
||||
owned.quantity = quantity
|
||||
|
|
@ -37,6 +31,19 @@ func add_item(item_id: StringName, quantity: int = 1) -> bool:
|
|||
return true
|
||||
|
||||
|
||||
func can_add_item(item_id: StringName, quantity: int = 1) -> bool:
|
||||
var item: ItemDataType = _resolve_valid_item(item_id)
|
||||
if item == null or quantity <= 0:
|
||||
return false
|
||||
var existing: OwnedItemType = get_owned_item(item_id)
|
||||
if existing != null:
|
||||
return (
|
||||
item.stackable
|
||||
and existing.quantity + quantity <= item.max_stack
|
||||
)
|
||||
return quantity <= (item.max_stack if item.stackable else 1)
|
||||
|
||||
|
||||
func remove_item(item_id: StringName, quantity: int = 1) -> bool:
|
||||
if quantity <= 0:
|
||||
return false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue