From 34db6071458551fc1d9605ff64c38b757fe19f30 Mon Sep 17 00:00:00 2001 From: Sara Date: Mon, 11 Aug 2025 14:59:08 +0200 Subject: [PATCH] feat: implemented partial revolver reload --- modules/wave_survival/weapons/revolver.cpp | 34 +++++++++++++++++----- modules/wave_survival/weapons/revolver.h | 4 ++- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/modules/wave_survival/weapons/revolver.cpp b/modules/wave_survival/weapons/revolver.cpp index 59ae9594..140ab3eb 100644 --- a/modules/wave_survival/weapons/revolver.cpp +++ b/modules/wave_survival/weapons/revolver.cpp @@ -59,6 +59,13 @@ void Revolver::start_reloading() { } } +void Revolver::stop_reloading() { + if (get_anim()->get_current_animation() == "reload_one") { + get_anim()->queue("reload_to_double"); + get_anim()->queue("idle_double"); + } +} + void Revolver::play_equip_anim() { get_anim()->play("equip", 0.0); queue_idle_anim(); @@ -82,8 +89,8 @@ void Revolver::shoot() { void Revolver::cock_hammer() { if (!this->alt_active && animation_is_idle()) { - stop_running(); this->alt_active = true; + stop_running(); get_anim()->queue("to_single"); queue_idle_anim(); } @@ -91,7 +98,11 @@ void Revolver::cock_hammer() { void Revolver::on_primary_fire(bool pressed) { if (pressed) { - shoot(); + if (get_anim()->get_queue().is_empty() && get_anim()->get_current_animation() == "reload_one") { + stop_reloading(); + } else { + shoot(); + } } } @@ -107,21 +118,28 @@ void Revolver::on_reload() { } } +void Revolver::on_animation_changed(String old_anim, String new_anim) { + on_animation_finished(old_anim); +} + void Revolver::on_animation_finished(String old_anim) { - if (old_anim == "reload_one" && get_anim()->get_queue().is_empty()) { + if (old_anim == "reload_one") { int const available{ get_inventory()->withdraw_pistol_ammo(1) }; reload_num(available); - if (available > 0 && get_loaded_ammo() < get_max_ammo()) { - get_anim()->queue("reload_one"); - } else { - get_anim()->queue("reload_to_double"); - get_anim()->queue("idle_double"); + if (get_anim()->get_queue().is_empty()) { + if (available > 0 && get_loaded_ammo() < get_max_ammo()) { + get_anim()->queue("reload_one"); + } else { + get_anim()->queue("reload_to_double"); + get_anim()->queue("idle_double"); + } } } } void Revolver::ready() { this->muzzle = cast_to(get_node(NodePath("%HitscanMuzzle"))); + get_anim()->connect("animation_changed", callable_mp(this, &self_type::on_animation_changed)); get_anim()->connect("animation_finished", callable_mp(this, &self_type::on_animation_finished)); get_input()->connect(PlayerInput::sig_primary_fire, callable_mp(this, &self_type::on_primary_fire)); get_input()->connect(PlayerInput::sig_alt_mode, callable_mp(this, &self_type::on_alt_mode)); diff --git a/modules/wave_survival/weapons/revolver.h b/modules/wave_survival/weapons/revolver.h index 80b50508..00b0c3c3 100644 --- a/modules/wave_survival/weapons/revolver.h +++ b/modules/wave_survival/weapons/revolver.h @@ -11,6 +11,7 @@ class Revolver : public WeaponBase { void start_running(); void stop_running(); void start_reloading(); + void stop_reloading(); void interrupt_reloading(); void interrupt_running(); void play_equip_anim(); @@ -19,6 +20,7 @@ class Revolver : public WeaponBase { void on_primary_fire(bool pressed); void on_alt_mode(bool pressed); void on_reload(); + void on_animation_changed(String old_anim, String new_anim); void on_animation_finished(String old_anim); void ready(); void process(double delta); @@ -47,7 +49,7 @@ private: double recoil_time{ 0.1 }; double recoil_timer{ 0.0 }; - double run_animation_delay{ 0.8 }; + double run_animation_delay{ 0.4 }; double run_animation_timer{ 0.0 }; };