50 lines
1.4 KiB
GDScript
50 lines
1.4 KiB
GDScript
extends RigidBody3D
|
|
|
|
@export var gun_resource : Resource
|
|
@export_enum("Ammo", "Stamina", "Health", "Money","Weapon") var pickupType: int
|
|
|
|
@onready var level_control = get_tree().current_scene
|
|
|
|
var pickupable = true
|
|
var gun_already_held = false
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
add_to_group("persist")
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta):
|
|
pass
|
|
|
|
func picked_up():
|
|
for i in GameGlobals.held_guns:
|
|
if i == gun_resource:
|
|
gun_already_held = true
|
|
|
|
if !gun_already_held:
|
|
var spawn_gun = gun_resource.instantiate()
|
|
if spawn_gun.weapon_info.weapon_type == 0:
|
|
level_control.player.add_ammo(true,spawn_gun.weapon_info.gun_name,spawn_gun.weapon_info.bullet.ammo_type,spawn_gun.weapon_info.max_ammo,spawn_gun.weapon_info.start_mags)
|
|
GameGlobals.held_guns.append(gun_resource)
|
|
var instance_gun = gun_resource.instantiate()
|
|
var weapon_id = GameGlobals.held_guns.size() - 1
|
|
if level_control.player.gun != null:
|
|
level_control.player.gun.anim_player.play("swap_out")
|
|
level_control.gun_spawn(weapon_id)
|
|
SignalBus.emit_signal("weapon_list_changed")
|
|
queue_free()
|
|
|
|
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,
|
|
}
|
|
return save_dict
|