2026-07-25 22:15:39 -04:00
|
|
|
class_name FishingShopStock
|
|
|
|
|
extends RefCounted
|
|
|
|
|
|
|
|
|
|
const ItemCatalogType = preload("res://items/item_catalog.gd")
|
|
|
|
|
const ItemDataType = preload("res://items/item_data.gd")
|
|
|
|
|
const PlayerBagType = preload("res://inventory/player_bag.gd")
|
|
|
|
|
const PlayerWalletType = preload("res://economy/player_wallet.gd")
|
2026-08-06 01:00:52 -04:00
|
|
|
const WORM_MAX_STACK: int = 10
|
2026-07-25 22:15:39 -04:00
|
|
|
|
|
|
|
|
const ITEM_PRICES: Dictionary[StringName, int] = {
|
2026-08-06 01:00:52 -04:00
|
|
|
&"worms": 1,
|
2026-07-25 22:15:39 -04:00
|
|
|
&"coffee": 20,
|
|
|
|
|
&"energy_drink": 35,
|
|
|
|
|
&"snack": 30,
|
|
|
|
|
&"fish_finder": 60,
|
|
|
|
|
}
|
|
|
|
|
const ITEM_ORDER: Array[StringName] = [
|
2026-08-06 01:00:52 -04:00
|
|
|
&"worms",
|
2026-07-25 22:15:39 -04:00
|
|
|
&"coffee",
|
|
|
|
|
&"energy_drink",
|
|
|
|
|
&"snack",
|
|
|
|
|
&"fish_finder",
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func get_price(item_id: StringName) -> int:
|
|
|
|
|
return ITEM_PRICES.get(item_id, -1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func get_stock_item_ids() -> Array[StringName]:
|
|
|
|
|
return ITEM_ORDER.duplicate()
|
|
|
|
|
|
|
|
|
|
|
2026-08-06 01:00:52 -04:00
|
|
|
static func get_purchase_quantity(item_id: StringName, owned: int) -> int:
|
|
|
|
|
if item_id == &"worms":
|
|
|
|
|
return maxi(WORM_MAX_STACK - owned, 0)
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func is_bait_topoff(item_id: StringName) -> bool:
|
|
|
|
|
return item_id == &"worms"
|
|
|
|
|
|
|
|
|
|
|
2026-07-25 22:15:39 -04:00
|
|
|
static func purchase_one(
|
|
|
|
|
item_id: StringName,
|
|
|
|
|
wallet: PlayerWalletType,
|
|
|
|
|
bag: PlayerBagType,
|
|
|
|
|
catalog: ItemCatalogType,
|
|
|
|
|
) -> bool:
|
|
|
|
|
if wallet == null or bag == null or catalog == null:
|
|
|
|
|
return false
|
|
|
|
|
var price: int = get_price(item_id)
|
|
|
|
|
var item: ItemDataType = catalog.get_item_by_id(item_id)
|
|
|
|
|
if (
|
|
|
|
|
price < 0
|
|
|
|
|
or item == null
|
|
|
|
|
or not item.is_valid()
|
2026-08-06 01:00:52 -04:00
|
|
|
or (item.category != ItemDataType.Category.CONSUMABLE and not is_bait_topoff(item_id))
|
2026-07-25 22:15:39 -04:00
|
|
|
or not item.stackable
|
2026-08-06 01:00:52 -04:00
|
|
|
or (not item.usable and not is_bait_topoff(item_id))
|
2026-07-25 22:15:39 -04:00
|
|
|
or not bag.can_add_item(item_id, 1)
|
|
|
|
|
or not wallet.can_afford(price)
|
|
|
|
|
):
|
|
|
|
|
return false
|
|
|
|
|
if not wallet.debit(price):
|
|
|
|
|
return false
|
|
|
|
|
if bag.add_item(item_id, 1):
|
|
|
|
|
return true
|
|
|
|
|
if not wallet.credit(price):
|
|
|
|
|
push_error("Fishing Shop failed to roll back an item purchase.")
|
|
|
|
|
return false
|