GetPlayerAmmo is now a SetPlayerAmmo instead to fix some potential problems if the player has no weapon at all
This commit is contained in:
@@ -50,7 +50,7 @@ private:
|
|||||||
//helper methods
|
//helper methods
|
||||||
bool DoesPlayerHaveMaxAmmo(EntityWrapper &player);
|
bool DoesPlayerHaveMaxAmmo(EntityWrapper &player);
|
||||||
PlayerClass DetermineClass(EntityWrapper &player);
|
PlayerClass DetermineClass(EntityWrapper &player);
|
||||||
int& GetPlayerAmmo(EntityWrapper &player);
|
void SetPlayerAmmo(EntityWrapper &player, int ammoGain);
|
||||||
int GetPlayerMaxAmmo(EntityWrapper &player);
|
int GetPlayerMaxAmmo(EntityWrapper &player);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -67,16 +67,18 @@ bool AmmoPickupSystem::DoesPlayerHaveMaxAmmo(EntityWrapper &player) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int& AmmoPickupSystem::GetPlayerAmmo(EntityWrapper &player) {
|
void AmmoPickupSystem::SetPlayerAmmo(EntityWrapper &player, int ammoGain) {
|
||||||
|
int maxWeaponAmmo = GetPlayerMaxAmmo(player);
|
||||||
|
|
||||||
PlayerClass playerClass = DetermineClass(player);
|
PlayerClass playerClass = DetermineClass(player);
|
||||||
if (playerClass == PlayerClass::Defender) {
|
if (playerClass == PlayerClass::Defender) {
|
||||||
return (int)player["DefenderWeapon"]["Ammo"];
|
(int&)player["DefenderWeapon"]["Ammo"] = std::min((int)player["DefenderWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
|
||||||
} else if (playerClass == PlayerClass::Sniper) {
|
} else if (playerClass == PlayerClass::Sniper) {
|
||||||
return (int)player["SniperWeapon"]["Ammo"];
|
(int&)player["SniperWeapon"]["Ammo"] = std::min((int)player["SniperWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
|
||||||
} else if (playerClass == PlayerClass::Assault) {
|
} else if (playerClass == PlayerClass::Assault) {
|
||||||
return (int)player["AssaultWeapon"]["Ammo"];
|
(int&)player["AssaultWeapon"]["Ammo"] = std::min((int)player["AssaultWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
|
||||||
} else {
|
} else {
|
||||||
//TODO: should really return something here
|
//unknown class - ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int AmmoPickupSystem::GetPlayerMaxAmmo(EntityWrapper &player) {
|
int AmmoPickupSystem::GetPlayerMaxAmmo(EntityWrapper &player) {
|
||||||
@@ -141,12 +143,9 @@ bool AmmoPickupSystem::OnAmmoPickup(Events::AmmoPickup & e)
|
|||||||
if (DoesPlayerHaveMaxAmmo(e.Player)) {
|
if (DoesPlayerHaveMaxAmmo(e.Player)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int maxWeaponAmmo = GetPlayerMaxAmmo(e.Player);
|
SetPlayerAmmo(e.Player, e.AmmoGain);
|
||||||
int& currentAmmo = GetPlayerAmmo(e.Player);
|
|
||||||
|
|
||||||
currentAmmo = std::min(currentAmmo + e.AmmoGain, maxWeaponAmmo);
|
return true;
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
|
bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user