Player 👍
This commit is contained in:
parent
a046ae5288
commit
0ffc2b2497
5 changed files with 2101 additions and 12 deletions
|
|
@ -3,6 +3,7 @@ extends Usable
|
|||
|
||||
@export var max_ammo: int
|
||||
@export var semi_auto: bool
|
||||
@export var emptyable: bool
|
||||
@export var damage: int
|
||||
|
||||
@export var firerate: float
|
||||
|
|
@ -13,7 +14,7 @@ extends Usable
|
|||
|
||||
var ammo_amount: int
|
||||
var fire_timer: Timer
|
||||
|
||||
var state_locked: bool
|
||||
|
||||
func _ready() -> void:
|
||||
fire_timer = Timer.new()
|
||||
|
|
@ -36,15 +37,15 @@ func use_end() -> void:
|
|||
fire_timer.one_shot = true
|
||||
|
||||
func fire() -> void:
|
||||
if ammo_amount == 0:
|
||||
if ammo_amount == 0 or state_locked:
|
||||
if not semi_auto:
|
||||
fire_timer.stop()
|
||||
return
|
||||
ammo_amount -= 1
|
||||
|
||||
system.animation_player.stop()
|
||||
system.animation_player.play(prefix+"_shoot")
|
||||
system.animation_player.queue(prefix+"_idle")
|
||||
system.animation_player.play(prefix + with_empty_suffix("_shoot"))
|
||||
system.animation_player.queue(prefix + with_empty_suffix("_idle"))
|
||||
|
||||
if raycast.is_colliding():
|
||||
raycast.get_collider().hp -= damage
|
||||
|
|
@ -57,17 +58,36 @@ func switch_mode() -> void:
|
|||
pass
|
||||
|
||||
func enter() -> void:
|
||||
system.animation_player.play(prefix+"_idle")
|
||||
system.animation_player.animation_changed.connect(on_animation_changed)
|
||||
state_locked = true
|
||||
system.animation_player.stop()
|
||||
system.animation_player.play(prefix+with_empty_suffix("_intro"))
|
||||
system.animation_player.queue(prefix+with_empty_suffix("_idle"))
|
||||
|
||||
func exit() -> void:
|
||||
system.animation_player.animation_changed.disconnect(on_animation_changed)
|
||||
|
||||
func on_animation_changed(old_animation: StringName,_new_animation: StringName) -> void:
|
||||
if old_animation == prefix + with_empty_suffix("_reload"):
|
||||
state_locked = false
|
||||
ammo_amount = max_ammo
|
||||
if old_animation == prefix + with_empty_suffix("_intro"):
|
||||
state_locked = false
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not system.is_multiplayer_authority(): return
|
||||
if not system.is_multiplayer_authority() or not in_use: return
|
||||
|
||||
if event.is_action_pressed("plr_reload"):
|
||||
init_reload.rpc()
|
||||
|
||||
@rpc("call_local","authority","reliable")
|
||||
func init_reload():
|
||||
if ammo_amount == max_ammo or system.animation_player.current_animation == prefix + "_reload":
|
||||
if ammo_amount == max_ammo or state_locked:
|
||||
return
|
||||
system.animation_player.play(prefix+"_reload")
|
||||
state_locked = true
|
||||
system.animation_player.play(prefix + with_empty_suffix("_reload"))
|
||||
system.animation_player.queue(prefix + "_idle")
|
||||
ammo_amount = max_ammo
|
||||
|
||||
func with_empty_suffix(animation):
|
||||
return (animation+"_empty") if emptyable and ammo_amount == 0 else animation
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ func _ready() -> void:
|
|||
push_warning("Child of weapon system is not ability or weapon")
|
||||
|
||||
current_usable = default_pistol
|
||||
slots["knife"] = default_knife
|
||||
slots["secondary"] = default_pistol
|
||||
current_usable.enter()
|
||||
|
||||
func can_add(slot: StringName) -> bool:
|
||||
|
|
@ -47,9 +49,8 @@ func add(usable: Usable, slot: StringName) -> void:
|
|||
|
||||
|
||||
func switch(to: StringName):
|
||||
if slots.has(to) == false or slots[to] == null:
|
||||
if slots.has(to) == false or slots[to] == null or slots[to] == current_usable:
|
||||
return
|
||||
|
||||
current_usable.exit()
|
||||
current_usable.in_use = false
|
||||
current_usable = slots[to]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue