2023-01-07 10:44:15 +00:00
|
|
|
extends Node3D
|
|
|
|
|
|
|
|
enum GUN_STATE {
|
|
|
|
ACTIVE,
|
|
|
|
SWITCHING,
|
|
|
|
INACTIVE
|
|
|
|
}
|
|
|
|
|
|
|
|
var active_weapon: BaseWeapon
|
|
|
|
|
|
|
|
signal weapon_switched(weapon: BaseWeapon)
|
|
|
|
|
|
|
|
var player: Player:
|
|
|
|
get:
|
|
|
|
return player
|
|
|
|
set(p):
|
|
|
|
player = p
|
|
|
|
self._on_player_set(p)
|
|
|
|
|
|
|
|
|
|
|
|
var weapons: Array = [
|
2023-01-08 01:25:48 +00:00
|
|
|
load("res://player/onhand/PeaShooter.tscn").instantiate()
|
2023-01-07 10:44:15 +00:00
|
|
|
# load("res://Player/Weapons/Arm.tscn").instantiate(),
|
|
|
|
# load("res://Player/Weapons/ak47.tscn").instantiate(),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
2023-01-08 01:25:48 +00:00
|
|
|
self._switch_weapon(BaseWeapon.WeaponSlot.ONE)
|
2023-01-07 10:44:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_player_set(player: Player) -> void:
|
|
|
|
for weapon in weapons:
|
|
|
|
weapon.player = player
|
|
|
|
|
|
|
|
|
2023-01-08 12:13:09 +00:00
|
|
|
func _input(_event: InputEvent) -> void:
|
2023-01-07 10:44:15 +00:00
|
|
|
if Input.is_action_just_pressed("slot1"):
|
|
|
|
_switch_weapon(BaseWeapon.WeaponSlot.ONE)
|
2023-01-08 01:25:48 +00:00
|
|
|
# elif Input.is_action_just_pressed("slot2"):
|
|
|
|
# _switch_weapon(BaseWeapon.WeaponSlot.TWO)
|
|
|
|
# elif Input.is_action_just_pressed("slot3"):
|
|
|
|
# _switch_weapon(BaseWeapon.WeaponSlot.THREE)
|
2023-01-07 10:44:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _switch_weapon(slot: BaseWeapon.WeaponSlot):
|
|
|
|
# TODO: play anim ecc ecc
|
|
|
|
# Try to get the correct weapon per the given `slot`
|
|
|
|
for weapon in weapons:
|
|
|
|
if weapon.weaponSlot == slot:
|
|
|
|
# Remove active weapon
|
|
|
|
if active_weapon:
|
2023-01-08 12:13:09 +00:00
|
|
|
active_weapon.on_switch_out()
|
2023-01-07 10:44:15 +00:00
|
|
|
remove_child(active_weapon)
|
|
|
|
|
|
|
|
# Add new weapon
|
|
|
|
add_child(weapon)
|
|
|
|
active_weapon = weapon
|
2023-01-08 12:13:09 +00:00
|
|
|
active_weapon.on_switch_in()
|
2023-01-07 10:44:15 +00:00
|
|
|
emit_signal("weapon_switched", weapon)
|
|
|
|
break
|