Add fish selling, buyer profiles, and player wallet
This commit is contained in:
parent
fb04615600
commit
d2fe367891
25 changed files with 738 additions and 5 deletions
45
economy/player_wallet.gd
Normal file
45
economy/player_wallet.gd
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
class_name PlayerWallet
|
||||
extends Node
|
||||
|
||||
signal balance_changed(new_balance: int, delta: int)
|
||||
|
||||
@export var current_balance: int = 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
current_balance = maxi(current_balance, 0)
|
||||
|
||||
|
||||
func get_balance() -> int:
|
||||
return current_balance
|
||||
|
||||
|
||||
func can_afford(amount: int) -> bool:
|
||||
return amount >= 0 and current_balance >= amount
|
||||
|
||||
|
||||
func can_credit(amount: int) -> bool:
|
||||
return (
|
||||
amount >= 0
|
||||
and current_balance <= 9223372036854775807 - amount
|
||||
)
|
||||
|
||||
|
||||
func credit(amount: int) -> bool:
|
||||
if not can_credit(amount):
|
||||
return false
|
||||
if amount == 0:
|
||||
return true
|
||||
current_balance += amount
|
||||
balance_changed.emit(current_balance, amount)
|
||||
return true
|
||||
|
||||
|
||||
func debit(amount: int) -> bool:
|
||||
if not can_afford(amount):
|
||||
return false
|
||||
if amount == 0:
|
||||
return true
|
||||
current_balance -= amount
|
||||
balance_changed.emit(current_balance, -amount)
|
||||
return true
|
||||
Loading…
Add table
Add a link
Reference in a new issue