extends NinePatchRect @export var data : Dictionary = {"id" : ""} ## Contains all buy options. Must have "id" key. @export var price : float @export var clickable : BaseButton @onready var ship = get_tree().current_scene.get_node("MainShip") func _ready(): clickable.button_up.connect(_button_up) func _button_up(): if ship.money >= price: ship.money -= price bought_action() func bought_action(): match data["id"]: "hp": if ship.hull.hp >= ship.hull.max_hp: ship.hull.hp = ship.hull.max_hp ship.money += price return ship.hull.hp += 1 while(ship.hull.hp < ship.hull.max_hp and ship.money >= price): ship.hull.hp += 1 ship.money -= price if ship.hull.hp > ship.hull.max_hp: ship.hull.hp = ship.hull.max_hp "rockets": if ship.hull.ammunition["Rockets"] == ship.hull.max_ammunition["Rockets"]: ship.money += price return var rocket_price : float = price / data["amount"] if ship.hull.ammunition["Rockets"] + data["amount"] > ship.hull.max_ammunition["Rockets"]: var rockets_left = ship.hull.max_ammunition["Rockets"] - ship.hull.ammunition["Rockets"] for i in range(rockets_left + 1): ship.money += rocket_price ship.hull.ammunition["Rockets"] = ship.hull.max_ammunition["Rockets"] else: ship.hull.ammunition["Rockets"] += data["amount"] "fuel": if ship.hull.fuel == ship.hull.max_fuel: ship.money += price return if ship.hull.fuel + data["amount"] > ship.hull.max_fuel: ship.hull.fuel = ship.hull.max_fuel else: ship.hull.fuel += data["amount"] "weapon": var primary_slot = ship.get_node("PrimaryWeapon") var secondary_slot = ship.get_node("SecondaryWeapon") var bought_weapon = get_tree().current_scene.bought_weapon var slot = primary_slot if data["slot"] == "primary" else secondary_slot if !bought_weapon[data["weapon"]]: bought_weapon[data["weapon"]] = true else: ship.money += price for node in slot.get_children(): node.queue_free() var weapon_inst = Game.get_weapon(data['weapon']).instantiate() weapon_inst.id = data['weapon'] weapon_inst.position = data["position"] slot.add_child(weapon_inst)