Shop
This commit is contained in:
parent
06c5fea9bd
commit
cd20f952ce
6 changed files with 116 additions and 68 deletions
29
gui/buy_menu/shop.gd
Normal file
29
gui/buy_menu/shop.gd
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
extends Node
|
||||
|
||||
|
||||
func can_buy(player_id: int,weapon: WeaponResource) -> bool:
|
||||
return Session.player_data[player_id]["money"] >= weapon.cost
|
||||
|
||||
func buy(player_id: int, weapon: WeaponResource) -> void:
|
||||
if not multiplayer.is_server() or can_buy(player_id,weapon) == false:
|
||||
return
|
||||
|
||||
var player: Player = Session.player_nodes[player_id]
|
||||
if player.hp == 0:
|
||||
return
|
||||
|
||||
var weapon_system: WeaponSystem = player.get_node("%WeaponSystem")
|
||||
var slot: StringName = ""
|
||||
match weapon.slot:
|
||||
"ability":
|
||||
slot = weapon_system.get_empty_ability_slot()
|
||||
var anything:
|
||||
slot = anything
|
||||
|
||||
if not weapon_system.can_add(slot):
|
||||
return
|
||||
|
||||
var player_data = Session.player_data[player_id]
|
||||
player_data["money"] -= weapon.cost
|
||||
|
||||
weapon_system.add(weapon.weapon_system_scene.instantiate(),slot)
|
||||
Loading…
Add table
Add a link
Reference in a new issue