83 lines
2.4 KiB
GDScript
83 lines
2.4 KiB
GDScript
extends Node3D
|
|
|
|
@export var item : Resource
|
|
@export var is_pickup : bool = false
|
|
@export var is_random : bool = false
|
|
@export_enum("Ammo", "Stamina", "Health", "Money","Weapon") var pickup_type: int
|
|
@export var pickup_amount : int
|
|
@export var item_name : String
|
|
@export var item_price : int
|
|
@export var number_uses = 1
|
|
@onready var anim_player = $AnimationPlayer
|
|
@onready var vend_ray = $VendRay
|
|
@onready var price_label = $Price
|
|
@onready var item_label: Label3D = $"Item"
|
|
@onready var level_control = get_tree().current_scene
|
|
|
|
var active = true
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
if active == true:
|
|
price_label.text = str("$",item_price)
|
|
item_label.text = str(item_name)
|
|
else:
|
|
price_label.text = "offline"
|
|
|
|
func interact():
|
|
if active == true:
|
|
if GameGlobals.money >= item_price:
|
|
GameGlobals.money -= item_price
|
|
anim_player.play("vend")
|
|
price_label.text = "vending..."
|
|
else:
|
|
var original_text = price_label.text
|
|
price_label.text = "too poor"
|
|
await get_tree().create_timer(2.0).timeout
|
|
price_label.text = original_text
|
|
|
|
func vend():
|
|
var item_vend
|
|
if is_pickup:
|
|
item_vend = level_control.ITEM_PICKUP.instantiate()
|
|
var item_stats
|
|
item_stats = level_control.pickup_spawn(is_random)
|
|
##SET VARIABLES
|
|
item_vend.pickup_type = pickup_type
|
|
if level_control.player.gun != null:
|
|
if level_control.player.gun.weapon_info.bullet.ammo_type != 5:
|
|
item_vend.ammo_type = level_control.player.gun.weapon_info.bullet.ammo_type
|
|
else:
|
|
item_vend.ammo_type = item_stats["ammo_type"]
|
|
if pickup_type == 0:
|
|
if level_control.player.gun != null:
|
|
item_vend.value = level_control.player.gun.weapon_info.max_ammo
|
|
else:
|
|
item_vend.value = item_stats["value"]
|
|
else:
|
|
item_vend.value = pickup_amount
|
|
else:
|
|
item_vend = item.instantiate()
|
|
item_vend.position = vend_ray.global_position
|
|
item_vend.transform.basis = vend_ray.global_transform.basis
|
|
item_vend.linear_velocity += vend_ray.global_transform.basis * Vector3(0,0,3)
|
|
if number_uses <= 1:
|
|
active = false
|
|
price_label.text = "offline"
|
|
get_parent().add_child(item_vend)
|
|
price_label.text = str("$",item_price)
|
|
|
|
func save():
|
|
var save_dict = {
|
|
"filename" : get_scene_file_path(),
|
|
"parent" : get_parent().get_path(),
|
|
"pos_x" : position.x,
|
|
"pos_y" : position.y,
|
|
"pos_z" : position.z,
|
|
"rot_x" : rotation.x,
|
|
"rot_y" : rotation.y,
|
|
"rot_z" : rotation.z,
|
|
"active" : active
|
|
}
|
|
return save_dict
|