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");
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@
|
|||
#include "wave_survival/macros.h"
|
||||
#include "wave_survival/player_body.h"
|
||||
#include "wave_survival/player_input.h"
|
||||
#include "wave_survival/weapon_inventory.h"
|
||||
|
||||
void Rifle::_bind_methods() {
|
||||
BIND_PROPERTY(Variant::FLOAT, ads_factor);
|
||||
BIND_PROPERTY(Variant::FLOAT, run_factor);
|
||||
BIND_PROPERTY(Variant::FLOAT, recoil_force);
|
||||
BIND_PROPERTY(Variant::FLOAT, recoil_time);
|
||||
ClassDB::bind_method(D_METHOD("reload_full"), &self_type::reload_full);
|
||||
}
|
||||
|
||||
void Rifle::queue_enter_alt() {
|
||||
|
|
@ -53,7 +55,7 @@ void Rifle::shoot() {
|
|||
}
|
||||
|
||||
void Rifle::start_reload_animation() {
|
||||
if (!is_animating() && get_loaded_ammo() != get_max_ammo()) {
|
||||
if (!is_animating() && get_loaded_ammo() < get_max_ammo() && get_inventory()->get_rifle_ammo() > 0) {
|
||||
if (this->in_alt_mode) {
|
||||
get_anim()->queue("aim_to_hip");
|
||||
}
|
||||
|
|
@ -181,6 +183,11 @@ void Rifle::notify_selected() {
|
|||
play_equip_anim();
|
||||
}
|
||||
|
||||
void Rifle::reload_full() {
|
||||
int const available = get_inventory()->withdraw_rifle_ammo(get_max_ammo());
|
||||
reload_num(available);
|
||||
}
|
||||
|
||||
void Rifle::set_ads_factor(float value) {
|
||||
this->ads_factor = value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ public:
|
|||
virtual bool allows_running() const override;
|
||||
bool run_requested() const;
|
||||
virtual void notify_selected() override;
|
||||
void reload_full();
|
||||
|
||||
void set_ads_factor(float value);
|
||||
float get_ads_factor() const;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue