depleted ammo destruction

This commit is contained in:
Rendo 2025-11-29 00:55:07 +05:00
commit 900502ec8a
12 changed files with 68 additions and 2068 deletions

View file

@ -0,0 +1,12 @@
extends WeaponState
func enter() -> void:
machine.animation_player.play(machine.animation_prefix+"idle")
func exit() -> void:
pass
func state_input(event: InputEvent) -> void:
if event.is_action("plr_bomb"):
transition.emit("Plant")

View file

@ -0,0 +1 @@
uid://cx7j3kr1laq3s

View file

@ -0,0 +1,12 @@
extends WeaponState
func enter() -> void:
machine.animation_player.play(machine.animation_prefix+"intro")
machine.animation_player.animation_finished.connect(on_animation_finished)
func exit() -> void:
machine.animation_player.animation_finished.disconnect(on_animation_finished)
func on_animation_finished(animation: StringName):
if animation == machine.animation_prefix + "intro":
transition.emit("Idle")

View file

@ -0,0 +1 @@
uid://dmyir46aricwi

View file

@ -21,5 +21,4 @@ func on_animation_finished(animation: StringName):
func state_input(event: InputEvent) -> void:
if event.is_action_released("plr_bomb"):
return_to_previous.emit()
transition.emit("Idle")

View file

@ -7,17 +7,32 @@ class_name WeaponSubStateMachine
@export var visibility_target: StringName
@export var max_ammo: int
@onready var ammo: int = max_ammo
@onready var remaining_ammo: int = max_ammo * 3
@onready var ammo: int = max_ammo:
set(value):
if value < 0:
ammo = 0
else:
ammo = value
if ammo <= 0 and remaining_ammo <= 0:
ammo_depleted.emit()
get:
return ammo
@export var ammo_mags: int = 3
@onready var remaining_ammo: int = max_ammo * ammo_mags:
set(value):
if value < 0:
remaining_ammo = 0
else:
remaining_ammo = value
@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_depleted
var system: WeaponSystem
var animation_player: AnimationPlayer

View file

@ -52,6 +52,7 @@ func add(state: WeaponSubStateMachine, slot: StringName,ignore_parent: bool = fa
state.player_camera = camera
state.player = player
state.request_return.connect(return_to_previous)
state.ammo_depleted.connect(check_for_empty)
if current_state == null:
current_state = state
@ -133,6 +134,13 @@ func pick_up_weapon(data: Variant) -> Node:
return scene
func check_for_empty() -> void:
if is_multiplayer_authority() == false:
return
for child in get_children():
if child is WeaponSubStateMachine and child.ammo == 0 and child.remaining_ammo == 0 and child.destroy_when_empty:
child.queue_free()
func _process(delta: float) -> void:
if current_state == null:
return