Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 52d3cb3ebf | |||
| 68b0175b3d | |||
| 0e0a486c01 | |||
| 2cfbe0f785 |
@@ -40,5 +40,17 @@ private:
|
||||
};
|
||||
std::vector<EntityAtMaxValuePickupStruct> m_PickupAtMaximum;
|
||||
void DoPickup(EntityWrapper &player, EntityWrapper &trigger);
|
||||
//class
|
||||
enum class PlayerClass {
|
||||
Assault,
|
||||
Defender,
|
||||
Sniper,
|
||||
None
|
||||
};
|
||||
//helper methods
|
||||
bool DoesPlayerHaveMaxAmmo(EntityWrapper &player);
|
||||
PlayerClass DetermineClass(EntityWrapper &player);
|
||||
void SetPlayerAmmo(EntityWrapper &player, int ammoGain);
|
||||
int GetPlayerMaxAmmo(EntityWrapper &player);
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
|
||||
#include "Rendering/Util/CommonFunctions.h"
|
||||
//#define INDICATOR_TEST
|
||||
#include "Core/ConfigFile.h"
|
||||
|
||||
class DamageIndicatorSystem : public ImpureSystem
|
||||
{
|
||||
@@ -41,8 +40,6 @@ private:
|
||||
std::vector<DamageIndicatorStruct> updateDamageIndicatorVector;
|
||||
float CalculateAngle(EntityWrapper player, glm::vec3 enemyPos);
|
||||
|
||||
bool m_NetworkEnabled;
|
||||
|
||||
//for tests
|
||||
#ifdef INDICATOR_TEST
|
||||
glm::vec3 DamageIndicatorTest(EntityWrapper player);
|
||||
|
||||
@@ -37,8 +37,7 @@ void AmmoPickupSystem::Update(double dt)
|
||||
|
||||
//erase the current element (somePickup)
|
||||
it = m_ETriggerTouchVector.erase(it);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
@@ -48,7 +47,7 @@ void AmmoPickupSystem::Update(double dt)
|
||||
m_PickupAtMaximum.erase(it);
|
||||
break;
|
||||
}
|
||||
if ((int)it->player["AssaultWeapon"]["Ammo"] < (int)it->player["AssaultWeapon"]["MaxAmmo"]) {
|
||||
if (!DoesPlayerHaveMaxAmmo(it->player)) {
|
||||
DoPickup(it->player, it->trigger);
|
||||
m_PickupAtMaximum.erase(it);
|
||||
break;
|
||||
@@ -56,6 +55,58 @@ void AmmoPickupSystem::Update(double dt)
|
||||
}
|
||||
}
|
||||
}
|
||||
bool AmmoPickupSystem::DoesPlayerHaveMaxAmmo(EntityWrapper &player) {
|
||||
PlayerClass playerClass = DetermineClass(player);
|
||||
if (playerClass == PlayerClass::Defender) {
|
||||
return !((int)player["DefenderWeapon"]["Ammo"] < (int)player["DefenderWeapon"]["MaxAmmo"]);
|
||||
} else if (playerClass == PlayerClass::Sniper) {
|
||||
return !((int)player["SniperWeapon"]["Ammo"] < (int)player["SniperWeapon"]["MaxAmmo"]);
|
||||
} else if (playerClass == PlayerClass::Assault) {
|
||||
return !((int)player["AssaultWeapon"]["Ammo"] < (int)player["AssaultWeapon"]["MaxAmmo"]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void AmmoPickupSystem::SetPlayerAmmo(EntityWrapper &player, int ammoGain) {
|
||||
int maxWeaponAmmo = GetPlayerMaxAmmo(player);
|
||||
|
||||
PlayerClass playerClass = DetermineClass(player);
|
||||
if (playerClass == PlayerClass::Defender) {
|
||||
(int&)player["DefenderWeapon"]["Ammo"] = std::min((int)player["DefenderWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
|
||||
} else if (playerClass == PlayerClass::Sniper) {
|
||||
(int&)player["SniperWeapon"]["Ammo"] = std::min((int)player["SniperWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
|
||||
} else if (playerClass == PlayerClass::Assault) {
|
||||
(int&)player["AssaultWeapon"]["Ammo"] = std::min((int)player["AssaultWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
|
||||
} else {
|
||||
//unknown class - ignore
|
||||
}
|
||||
}
|
||||
int AmmoPickupSystem::GetPlayerMaxAmmo(EntityWrapper &player) {
|
||||
PlayerClass playerClass = DetermineClass(player);
|
||||
if (playerClass == PlayerClass::Defender) {
|
||||
return (int)player["DefenderWeapon"]["MaxAmmo"];
|
||||
} else if (playerClass == PlayerClass::Sniper) {
|
||||
return (int)player["SniperWeapon"]["MaxAmmo"];
|
||||
} else if (playerClass == PlayerClass::Assault) {
|
||||
return (int)player["AssaultWeapon"]["MaxAmmo"];
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
AmmoPickupSystem::PlayerClass AmmoPickupSystem::DetermineClass(EntityWrapper &player)
|
||||
{
|
||||
//determine the class based on what component the inflictor-player has
|
||||
if (m_World->HasComponent(player.ID, "DashAbility")) {
|
||||
return PlayerClass::Assault;
|
||||
}
|
||||
if (m_World->HasComponent(player.ID, "ShieldAbility")) {
|
||||
return PlayerClass::Defender;
|
||||
}
|
||||
if (m_World->HasComponent(player.ID, "SprintAbility")) {
|
||||
return PlayerClass::Sniper;
|
||||
}
|
||||
return PlayerClass::None;
|
||||
}
|
||||
|
||||
bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
||||
{
|
||||
@@ -63,7 +114,7 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
||||
return false;
|
||||
}
|
||||
//TODO: add other weapontypes
|
||||
if (!e.Entity.HasComponent("AssaultWeapon")) {
|
||||
if (DetermineClass(e.Entity) == PlayerClass::None) {
|
||||
return false;
|
||||
}
|
||||
if (!e.Trigger.HasComponent("AmmoPickup")) {
|
||||
@@ -71,7 +122,7 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
||||
}
|
||||
|
||||
//if at maxammo, save the trigger-touch to a vector since standing inside it will not re-trigger the trigger
|
||||
if ((int)e.Entity["AssaultWeapon"]["Ammo"] >= (int)e.Entity["AssaultWeapon"]["MaxAmmo"]) {
|
||||
if (DoesPlayerHaveMaxAmmo(e.Entity)) {
|
||||
m_PickupAtMaximum.push_back({ e.Entity, e.Trigger });
|
||||
return false;
|
||||
}
|
||||
@@ -85,19 +136,16 @@ bool AmmoPickupSystem::OnAmmoPickup(Events::AmmoPickup & e)
|
||||
return false;
|
||||
}
|
||||
//TODO: add other weapontypes
|
||||
if (!e.Player.HasComponent("AssaultWeapon")) {
|
||||
if (DetermineClass(e.Player) == PlayerClass::None) {
|
||||
return false;
|
||||
}
|
||||
int maxWeaponAmmo = (int)e.Player["AssaultWeapon"]["MaxAmmo"];
|
||||
int& currentAmmo = (int)e.Player["AssaultWeapon"]["Ammo"];
|
||||
//cant pick up ammopacks if you are already at MaxAmmo
|
||||
if (currentAmmo >= maxWeaponAmmo) {
|
||||
if (DoesPlayerHaveMaxAmmo(e.Player)) {
|
||||
return false;
|
||||
}
|
||||
SetPlayerAmmo(e.Player, e.AmmoGain);
|
||||
|
||||
currentAmmo = std::min(currentAmmo + e.AmmoGain, maxWeaponAmmo);
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
|
||||
@@ -119,7 +167,7 @@ void AmmoPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
|
||||
if (!trigger.Valid()) {
|
||||
return;
|
||||
}
|
||||
int maxWeaponAmmo = (int)player["AssaultWeapon"]["MaxAmmo"];
|
||||
int maxWeaponAmmo = GetPlayerMaxAmmo(player);
|
||||
int ammoGiven = 0.01*(double)trigger["AmmoPickup"]["AmmoGain"] * maxWeaponAmmo;
|
||||
|
||||
Events::AmmoPickup ePlayerAmmoPickup;
|
||||
|
||||
@@ -10,11 +10,10 @@ DamageIndicatorSystem::DamageIndicatorSystem(SystemParams params)
|
||||
//load texture to cache
|
||||
auto texture = CommonFunctions::LoadTexture("Textures/DamageIndicator.png", false);
|
||||
auto entityFile = ResourceManager::Load<EntityXMLFile>("Schema/Entities/DamageIndicator.xml");
|
||||
m_NetworkEnabled = ResourceManager::Load<ConfigFile>("Config.ini")->Get("Networking.StartNetwork", false);
|
||||
}
|
||||
|
||||
void DamageIndicatorSystem::Update(double dt) {
|
||||
if ((!IsServer || !m_NetworkEnabled) && LocalPlayer.Valid()) {
|
||||
if (!IsServer && LocalPlayer.Valid()) {
|
||||
for (auto& iter = updateDamageIndicatorVector.begin(); iter != updateDamageIndicatorVector.end(); iter++) {
|
||||
if (!iter->spriteEntity.Valid()) {
|
||||
updateDamageIndicatorVector.erase(iter);
|
||||
@@ -41,15 +40,10 @@ bool DamageIndicatorSystem::OnPlayerDamage(Events::PlayerDamage& e)
|
||||
return false;
|
||||
}
|
||||
|
||||
//friendly fire - return
|
||||
if (e.Damage < 0.1f) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glm::vec3 inflictorPos = e.Inflictor["Transform"]["Position"];
|
||||
//if testing
|
||||
#ifdef INDICATOR_TEST
|
||||
inflictorPos = DamageIndicatorTest(e.Victim);
|
||||
inflictorPos = DamageIndicatorTest(e.Victim);
|
||||
#endif
|
||||
|
||||
float angleBetweenVectors = CalculateAngle(e.Victim, inflictorPos);
|
||||
@@ -61,7 +55,7 @@ bool DamageIndicatorSystem::OnPlayerDamage(Events::PlayerDamage& e)
|
||||
//simply set the rotation z-wise to the angleBetweenVectors
|
||||
sprite["Transform"]["Orientation"] = glm::vec3(0, 0, angleBetweenVectors);
|
||||
|
||||
if (!IsServer || !m_NetworkEnabled) {
|
||||
if (!IsServer) {
|
||||
updateDamageIndicatorVector.emplace_back(sprite, inflictorPos);
|
||||
}
|
||||
|
||||
@@ -128,7 +122,7 @@ glm::vec3 DamageIndicatorSystem::DamageIndicatorTest(EntityWrapper player) {
|
||||
}
|
||||
m_TestVar++;
|
||||
|
||||
auto inflictorPos = glm::vec3(currentPos.x + testVar*6.0f, currentPos.y, currentPos.z + testVar2*6.0f);
|
||||
auto inflictorPos = glm::vec3(currentPos.x + testVar*6.0f, currentPos.y, currentPos.z + testVar2*6.0f);
|
||||
|
||||
//load the explosioneffect XML
|
||||
auto deathEffect = ResourceManager::Load<EntityXMLFile>("Schema/Entities/PlayerDeathExplosionWithCamera.xml");
|
||||
|
||||
Reference in New Issue
Block a user