feat: reloading withdraws ammo from inventory

This commit is contained in:
Sara 2025-08-10 16:37:02 +02:00
parent a2035e0db0
commit ed85b557a7
8 changed files with 92 additions and 17 deletions

View file

@ -9,7 +9,6 @@ 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);
}
@ -62,6 +61,14 @@ PlayerCamera *WeaponBase::get_camera() const {
return this->camera;
}
WeaponInventory *WeaponBase::get_inventory() const {
return this->inventory;
}
void WeaponBase::_set_inventory(WeaponInventory *inventory) {
this->inventory = inventory;
}
void WeaponBase::set_body(PlayerBody *body) {
this->body = body;
}
@ -99,11 +106,6 @@ 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);