Amount check
This commit is contained in:
parent
d918533ebe
commit
82539c5af8
3 changed files with 15 additions and 2 deletions
|
|
@ -17,12 +17,15 @@ func buy(player_id: int, weapon: WeaponResource) -> void:
|
||||||
match weapon.slot:
|
match weapon.slot:
|
||||||
"ability":
|
"ability":
|
||||||
slot = weapon_system.get_empty_ability_slot()
|
slot = weapon_system.get_empty_ability_slot()
|
||||||
|
if not weapon_system.can_add_ability(weapon.get_gid(),slot):
|
||||||
|
return
|
||||||
var anything:
|
var anything:
|
||||||
slot = anything
|
slot = anything
|
||||||
|
|
||||||
if not weapon_system.can_add(slot):
|
if not weapon_system.can_add(slot):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var player_data = Session.player_data[player_id]
|
var player_data = Session.player_data[player_id]
|
||||||
player_data["money"] -= weapon.cost
|
player_data["money"] -= weapon.cost
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,7 @@ class_name WeaponResource
|
||||||
@export var dropped_scene: PackedScene
|
@export var dropped_scene: PackedScene
|
||||||
@export var weapon_system_scene: PackedScene
|
@export var weapon_system_scene: PackedScene
|
||||||
@export var slot: StringName
|
@export var slot: StringName
|
||||||
|
|
||||||
|
func get_gid() -> StringName:
|
||||||
|
var path_split: PackedStringArray = resource_path.split("/")
|
||||||
|
return path_split[len(path_split)-1].trim_suffix(".tres")
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,12 @@ func get_empty_ability_slot() -> StringName:
|
||||||
return "ability_third"
|
return "ability_third"
|
||||||
return "ability_first"
|
return "ability_first"
|
||||||
|
|
||||||
|
func can_add_ability(ability: StringName, slot: StringName) -> bool:
|
||||||
|
for ability_slot in ["ability_first","ability_second","ability_third"]:
|
||||||
|
if slots[ability_slot] != null and slots[ability_slot].registry_entry == ability:
|
||||||
|
return false
|
||||||
|
return can_add(slot)
|
||||||
|
|
||||||
func switch(to: StringName, exit: bool = true):
|
func switch(to: StringName, exit: bool = true):
|
||||||
if slots.has(to) == false or slots[to] == null or slots[to] == current_state or (multiplayer.get_remote_sender_id() != 1 and is_multiplayer_authority() == false):
|
if slots.has(to) == false or slots[to] == null or slots[to] == current_state or (multiplayer.get_remote_sender_id() != 1 and is_multiplayer_authority() == false):
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue