feat: implemented rifle reload with placeholder anim

This commit is contained in:
Sara 2025-08-06 18:45:02 +02:00
parent 150231c67c
commit 68abfdd383
25 changed files with 26775 additions and 3 deletions

View file

@ -9,6 +9,9 @@ void WeaponBase::_bind_methods() {
BIND_HPROPERTY(Variant::OBJECT, anim, PROPERTY_HINT_NODE_TYPE, AnimationPlayer::get_class_static());
BIND_PROPERTY(Variant::INT, max_ammo);
BIND_PROPERTY(Variant::INT, loaded_ammo);
ClassDB::bind_method(D_METHOD("reload_full"), &self_type::reload_full);
ClassDB::bind_method(D_METHOD("reload_num", "num"), &self_type::reload_num);
ClassDB::bind_method(D_METHOD("ammo_empty"), &self_type::ammo_empty);
}
void WeaponBase::ready() {
@ -91,3 +94,19 @@ bool WeaponBase::try_use_ammo(int amount) {
return false;
}
}
bool WeaponBase::ammo_empty() const {
return this->loaded_ammo <= 0;
}
void WeaponBase::reload_full() {
// TODO: take difference between loaded and max out of inventory
set_loaded_ammo(this->max_ammo);
}
void WeaponBase::reload_num(int num) {
int const space{ this->max_ammo - this->loaded_ammo };
num = MIN(num, space);
// TODO: take num out of ammo inventory
set_loaded_ammo(this->loaded_ammo + num);
}