feat: reloading withdraws ammo from inventory
This commit is contained in:
parent
a2035e0db0
commit
ed85b557a7
8 changed files with 92 additions and 17 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include "wave_survival/player_body.h"
|
||||
#include "wave_survival/player_camera.h"
|
||||
#include "wave_survival/player_input.h"
|
||||
#include "wave_survival/weapon_inventory.h"
|
||||
|
||||
void Revolver::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("start_recoil"), &self_type::start_recoil);
|
||||
|
|
@ -51,9 +52,11 @@ void Revolver::stop_running() {
|
|||
}
|
||||
|
||||
void Revolver::start_reloading() {
|
||||
this->alt_active = false;
|
||||
get_anim()->queue("double_to_reload");
|
||||
get_anim()->queue("reload_one");
|
||||
if (get_inventory()->get_pistol_ammo() > 0) {
|
||||
this->alt_active = false;
|
||||
get_anim()->queue("double_to_reload");
|
||||
get_anim()->queue("reload_one");
|
||||
}
|
||||
}
|
||||
|
||||
void Revolver::play_equip_anim() {
|
||||
|
|
@ -106,8 +109,9 @@ void Revolver::on_reload() {
|
|||
|
||||
void Revolver::on_animation_finished(String old_anim) {
|
||||
if (old_anim == "reload_one" && get_anim()->get_queue().is_empty()) {
|
||||
reload_num(1);
|
||||
if (get_loaded_ammo() < get_max_ammo()) {
|
||||
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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue