feat: implemented partial revolver reload

This commit is contained in:
Sara 2025-08-11 14:59:08 +02:00
parent 7e3afd6c64
commit 34db607145
2 changed files with 29 additions and 9 deletions

View file

@ -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() { void Revolver::play_equip_anim() {
get_anim()->play("equip", 0.0); get_anim()->play("equip", 0.0);
queue_idle_anim(); queue_idle_anim();
@ -82,8 +89,8 @@ void Revolver::shoot() {
void Revolver::cock_hammer() { void Revolver::cock_hammer() {
if (!this->alt_active && animation_is_idle()) { if (!this->alt_active && animation_is_idle()) {
stop_running();
this->alt_active = true; this->alt_active = true;
stop_running();
get_anim()->queue("to_single"); get_anim()->queue("to_single");
queue_idle_anim(); queue_idle_anim();
} }
@ -91,7 +98,11 @@ void Revolver::cock_hammer() {
void Revolver::on_primary_fire(bool pressed) { void Revolver::on_primary_fire(bool pressed) {
if (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) { 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) }; int const available{ get_inventory()->withdraw_pistol_ammo(1) };
reload_num(available); reload_num(available);
if (available > 0 && get_loaded_ammo() < get_max_ammo()) { if (get_anim()->get_queue().is_empty()) {
get_anim()->queue("reload_one"); if (available > 0 && get_loaded_ammo() < get_max_ammo()) {
} else { get_anim()->queue("reload_one");
get_anim()->queue("reload_to_double"); } else {
get_anim()->queue("idle_double"); get_anim()->queue("reload_to_double");
get_anim()->queue("idle_double");
}
} }
} }
} }
void Revolver::ready() { void Revolver::ready() {
this->muzzle = cast_to<HitscanMuzzle>(get_node(NodePath("%HitscanMuzzle"))); this->muzzle = cast_to<HitscanMuzzle>(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_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_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)); get_input()->connect(PlayerInput::sig_alt_mode, callable_mp(this, &self_type::on_alt_mode));

View file

@ -11,6 +11,7 @@ class Revolver : public WeaponBase {
void start_running(); void start_running();
void stop_running(); void stop_running();
void start_reloading(); void start_reloading();
void stop_reloading();
void interrupt_reloading(); void interrupt_reloading();
void interrupt_running(); void interrupt_running();
void play_equip_anim(); void play_equip_anim();
@ -19,6 +20,7 @@ class Revolver : public WeaponBase {
void on_primary_fire(bool pressed); void on_primary_fire(bool pressed);
void on_alt_mode(bool pressed); void on_alt_mode(bool pressed);
void on_reload(); void on_reload();
void on_animation_changed(String old_anim, String new_anim);
void on_animation_finished(String old_anim); void on_animation_finished(String old_anim);
void ready(); void ready();
void process(double delta); void process(double delta);
@ -47,7 +49,7 @@ private:
double recoil_time{ 0.1 }; double recoil_time{ 0.1 };
double recoil_timer{ 0.0 }; double recoil_timer{ 0.0 };
double run_animation_delay{ 0.8 }; double run_animation_delay{ 0.4 };
double run_animation_timer{ 0.0 }; double run_animation_timer{ 0.0 };
}; };