DamageIndicatorSystem can no longer crash if the player doesnt have a parent (rare bug)
This commit is contained in:
@@ -11,10 +11,10 @@ void AmmoPickupSystem::Update(double dt)
|
|||||||
{
|
{
|
||||||
for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it)
|
for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it)
|
||||||
{
|
{
|
||||||
auto& ammoPickupPosition = *it;
|
auto& somePickup = *it;
|
||||||
//set the double timer value (value 3)
|
//set the double timer value (value 3)
|
||||||
ammoPickupPosition.DecreaseThisRespawnTimer -= dt;
|
somePickup.DecreaseThisRespawnTimer -= dt;
|
||||||
if (ammoPickupPosition.DecreaseThisRespawnTimer < 0.0) {
|
if (somePickup.DecreaseThisRespawnTimer < 0.0) {
|
||||||
//spawn and delete the vector item
|
//spawn and delete the vector item
|
||||||
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/AmmoPickup.xml");
|
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/AmmoPickup.xml");
|
||||||
EntityFileParser parser(entityFile);
|
EntityFileParser parser(entityFile);
|
||||||
@@ -27,12 +27,12 @@ void AmmoPickupSystem::Update(double dt)
|
|||||||
|
|
||||||
//set values from the old entity to the new entity
|
//set values from the old entity to the new entity
|
||||||
auto& newAmmoPickupEntity = EntityWrapper(m_World, ammoPickupID);
|
auto& newAmmoPickupEntity = EntityWrapper(m_World, ammoPickupID);
|
||||||
newAmmoPickupEntity["Transform"]["Position"] = ammoPickupPosition.Pos;
|
newAmmoPickupEntity["Transform"]["Position"] = somePickup.Pos;
|
||||||
newAmmoPickupEntity["AmmoPickup"]["AmmoGain"] = ammoPickupPosition.AmmoGain;
|
newAmmoPickupEntity["AmmoPickup"]["AmmoGain"] = somePickup.AmmoGain;
|
||||||
newAmmoPickupEntity["AmmoPickup"]["RespawnTimer"] = ammoPickupPosition.RespawnTimer;
|
newAmmoPickupEntity["AmmoPickup"]["RespawnTimer"] = somePickup.RespawnTimer;
|
||||||
m_World->SetParent(newAmmoPickupEntity.ID, ammoPickupPosition.parentID);
|
m_World->SetParent(newAmmoPickupEntity.ID, somePickup.parentID);
|
||||||
|
|
||||||
//erase the current element (AmmoPickupPosition)
|
//erase the current element (somePickup)
|
||||||
m_ETriggerTouchVector.erase(it);
|
m_ETriggerTouchVector.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -51,10 +51,8 @@ void AmmoPickupSystem::Update(double dt)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
||||||
{
|
{
|
||||||
if (e.Entity != LocalPlayer) {
|
if (e.Entity != LocalPlayer) {
|
||||||
@@ -85,7 +83,6 @@ bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ void DamageIndicatorSystem::Update(double dt) {
|
|||||||
updateDamageIndicatorVector.erase(iter);
|
updateDamageIndicatorVector.erase(iter);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (!EntityWrapper(m_World,m_World->GetParent(LocalPlayer.ID)).Valid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto angleBetweenVectors = CalculateAngle(LocalPlayer, iter->enemyPosition);
|
auto angleBetweenVectors = CalculateAngle(LocalPlayer, iter->enemyPosition);
|
||||||
//simply set the rotation z-wise to the angleBetweenVectors
|
//simply set the rotation z-wise to the angleBetweenVectors
|
||||||
iter->spriteEntity["Transform"]["Orientation"] = glm::vec3(0, 0, angleBetweenVectors);
|
iter->spriteEntity["Transform"]["Orientation"] = glm::vec3(0, 0, angleBetweenVectors);
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ void HealthPickupSystem::Update(double dt)
|
|||||||
{
|
{
|
||||||
for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it)
|
for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it)
|
||||||
{
|
{
|
||||||
auto& healthPickupPosition = *it;
|
auto& somePickup = *it;
|
||||||
//set the double timer value (value 3)
|
//set the double timer value (value 3)
|
||||||
healthPickupPosition.DecreaseThisRespawnTimer -= dt;
|
somePickup.DecreaseThisRespawnTimer -= dt;
|
||||||
if (healthPickupPosition.DecreaseThisRespawnTimer < 0) {
|
if (somePickup.DecreaseThisRespawnTimer < 0) {
|
||||||
//spawn and delete the vector item
|
//spawn and delete the vector item
|
||||||
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/HealthPickup.xml");
|
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/HealthPickup.xml");
|
||||||
EntityFileParser parser(entityFile);
|
EntityFileParser parser(entityFile);
|
||||||
@@ -27,12 +27,13 @@ void HealthPickupSystem::Update(double dt)
|
|||||||
|
|
||||||
//set values from the old entity to the new entity
|
//set values from the old entity to the new entity
|
||||||
auto& newHealthPickupEntity = EntityWrapper(m_World, healthPickupID);
|
auto& newHealthPickupEntity = EntityWrapper(m_World, healthPickupID);
|
||||||
newHealthPickupEntity["Transform"]["Position"] = healthPickupPosition.Pos;
|
LOG_INFO("healthpickup id %i", healthPickupID);
|
||||||
newHealthPickupEntity["HealthPickup"]["HealthGain"] = healthPickupPosition.HealthGain;
|
newHealthPickupEntity["Transform"]["Position"] = somePickup.Pos;
|
||||||
newHealthPickupEntity["HealthPickup"]["RespawnTimer"] = healthPickupPosition.RespawnTimer;
|
newHealthPickupEntity["HealthPickup"]["HealthGain"] = somePickup.HealthGain;
|
||||||
m_World->SetParent(newHealthPickupEntity.ID, healthPickupPosition.parentID);
|
newHealthPickupEntity["HealthPickup"]["RespawnTimer"] = somePickup.RespawnTimer;
|
||||||
|
m_World->SetParent(newHealthPickupEntity.ID, somePickup.parentID);
|
||||||
//erase the current element (healthPickupPosition)
|
LOG_INFO("healthpickup parented to %i", somePickup.parentID);
|
||||||
|
//erase the current element (somePickup)
|
||||||
m_ETriggerTouchVector.erase(it);
|
m_ETriggerTouchVector.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -45,24 +46,27 @@ void HealthPickupSystem::Update(double dt)
|
|||||||
|
|
||||||
}
|
}
|
||||||
if ((double)it->player["Health"]["Health"] < (double)it->player["Health"]["MaxHealth"]) {
|
if ((double)it->player["Health"]["Health"] < (double)it->player["Health"]["MaxHealth"]) {
|
||||||
|
LOG_INFO("maxhealth found in pickupmax.. yada yada");
|
||||||
DoPickup(it->player, it->pickup);
|
DoPickup(it->player, it->pickup);
|
||||||
m_PickupAtMaximum.erase(it);
|
m_PickupAtMaximum.erase(it);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HealthPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
bool HealthPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
||||||
{
|
{
|
||||||
|
LOG_INFO("OnTriggerTouch");
|
||||||
if (!e.Trigger.HasComponent("HealthPickup")) {
|
if (!e.Trigger.HasComponent("HealthPickup")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//cant pick up healthpacks if you are already at MaxHealth
|
//cant pick up healthpacks if you are already at MaxHealth
|
||||||
if ((double)e.Entity["Health"]["Health"] >= (double)e.Entity["Health"]["MaxHealth"]) {
|
if ((double)e.Entity["Health"]["Health"] >= (double)e.Entity["Health"]["MaxHealth"]) {
|
||||||
|
LOG_INFO("trigger enter at maxhealth");
|
||||||
m_PickupAtMaximum.push_back({ e.Entity, e.Trigger });
|
m_PickupAtMaximum.push_back({ e.Entity, e.Trigger });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
LOG_INFO("touch doing pickup");
|
||||||
|
|
||||||
DoPickup(e.Entity, e.Trigger);
|
DoPickup(e.Entity, e.Trigger);
|
||||||
return true;
|
return true;
|
||||||
@@ -86,11 +90,13 @@ void HealthPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger)
|
|||||||
ePlayerHealthPickup.HealthAmount = healthGiven;
|
ePlayerHealthPickup.HealthAmount = healthGiven;
|
||||||
ePlayerHealthPickup.Player = player;
|
ePlayerHealthPickup.Player = player;
|
||||||
m_EventBroker->Publish(ePlayerHealthPickup);
|
m_EventBroker->Publish(ePlayerHealthPickup);
|
||||||
|
LOG_INFO("event published");
|
||||||
|
|
||||||
//copy position, healthgain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object)
|
//copy position, healthgain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object)
|
||||||
//we need to copy all values since each value can be different for each healthPickup
|
//we need to copy all values since each value can be different for each healthPickup
|
||||||
m_ETriggerTouchVector.push_back({ (glm::vec3)trigger["Transform"]["Position"] ,trigger["HealthPickup"]["HealthGain"],
|
m_ETriggerTouchVector.push_back({ (glm::vec3)trigger["Transform"]["Position"] ,trigger["HealthPickup"]["HealthGain"],
|
||||||
trigger["HealthPickup"]["RespawnTimer"],trigger["HealthPickup"]["RespawnTimer"], m_World->GetParent(trigger.ID) });
|
trigger["HealthPickup"]["RespawnTimer"],trigger["HealthPickup"]["RespawnTimer"], m_World->GetParent(trigger.ID) });
|
||||||
|
LOG_INFO("pickup set id to %i", trigger.ID);
|
||||||
|
|
||||||
//delete the healthpickup
|
//delete the healthpickup
|
||||||
m_World->DeleteEntity(trigger.ID);
|
m_World->DeleteEntity(trigger.ID);
|
||||||
|
|||||||
Reference in New Issue
Block a user