extends SubStateMachine class_name WeaponSubStateMachine @export var animation_prefix: StringName @export var weapon_gid: StringName @export var max_ammo: int @export var ammo: int = -1: set(value): if value < 0: ammo = 0 else: ammo = value ammo_updated.emit() if ammo <= 0 and remaining_ammo <= 0: ammo_depleted.emit() get: return ammo @export var ammo_mags: int = 3 @export var remaining_ammo: int = -1: set(value): if value < 0: remaining_ammo = 0 else: remaining_ammo = value ammo_updated.emit() @export var speed_modifier: float = 1.0 @export var can_be_previous: bool = true @export var destroy_when_empty: bool = false @export var slot: StringName signal request_return signal ammo_updated signal ammo_depleted var system: WeaponSystem var animation_player: AnimationPlayer var player_camera: PlayerCamera var player: Player func _ready() -> void: if remaining_ammo == -1: remaining_ammo = max_ammo * ammo_mags if ammo == -1: ammo = max_ammo for child in get_children(): if child is WeaponState: states[child.name] = child child.machine = self child.transition.connect(on_transition_required) child.return_to_previous.connect(request_return.emit) var parent = get_parent() if parent is WeaponSystem: system = parent animation_player = system.animation_player player_camera = system.camera player = system.player request_return.connect(system.return_to_previous) ammo_depleted.connect(system.check_for_empty) ammo_updated.connect(system.on_ammo_updated) func _enter() -> void: super() player.show_weapon(weapon_gid) func _exit() -> void: super() func use_begin() -> void: if current_state != null: current_state.use_begin() func use_end() -> void: if current_state != null: current_state.use_end() func alternate_state() -> void: if current_state != null: current_state.alternate_state() # Need to clarify naming; Switch mode like firemode. For different states use # alternate_state func switch_mode() -> void: if current_state != null: current_state.switch_mode() func play(animation_name: StringName): if animation_player.current_animation == animation_prefix + animation_name: animation_player.stop() animation_player.play(animation_prefix + animation_name) func queue(animation_name: StringName): animation_player.queue(animation_prefix + animation_name)