Proper firing logic handling
This commit is contained in:
parent
b58c740e06
commit
6a317d1913
12 changed files with 44 additions and 20 deletions
|
@ -4,12 +4,13 @@ class_name Weapon
|
|||
|
||||
signal fired()
|
||||
signal fire_failed()
|
||||
signal fire_allowed()
|
||||
|
||||
@onready var barrel = $"Barrel"
|
||||
@export var uses_hands: Array[CommandQueue.Side]
|
||||
|
||||
@export var max_ammo: int = 7
|
||||
var ammo: int = max_ammo
|
||||
var ammo: int
|
||||
@export var ammo_consumption: int = 1
|
||||
|
||||
@export var fire_mode: BaseFireMode
|
||||
|
@ -20,15 +21,19 @@ var ammo: int = max_ammo
|
|||
var is_firing: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
ammo = max_ammo
|
||||
fire_mode.barrel = barrel
|
||||
fire_mode.tree = get_tree()
|
||||
fire_mode.fire_allowed.connect(on_fire_allowed)
|
||||
barrel.fired.connect(on_barrel_fired)
|
||||
|
||||
## Begin to fire
|
||||
func request_fire() -> void:
|
||||
if not is_firing and ammo >= ammo_consumption:
|
||||
is_firing = true
|
||||
fire_mode._on_fire_begin()
|
||||
elif ammo < ammo_consumption:
|
||||
end_fire()
|
||||
fire_failed.emit()
|
||||
|
||||
func _process(_dt) -> void:
|
||||
|
@ -45,6 +50,12 @@ func on_barrel_fired() -> void:
|
|||
is_firing = true
|
||||
ammo -= ammo_consumption
|
||||
fired.emit()
|
||||
if ammo < ammo_consumption:
|
||||
end_fire()
|
||||
|
||||
func on_fire_allowed() -> void:
|
||||
fire_allowed.emit()
|
||||
is_firing = false
|
||||
|
||||
func reload() -> void:
|
||||
ammo = max_ammo
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue