experimental changes
This commit is contained in:
@@ -23,19 +23,20 @@ private:
|
|||||||
EventRelay<AmmoPickupSystem, Events::TriggerLeave> m_ETriggerLeave;
|
EventRelay<AmmoPickupSystem, Events::TriggerLeave> m_ETriggerLeave;
|
||||||
bool OnTriggerLeave(Events::TriggerLeave& e);
|
bool OnTriggerLeave(Events::TriggerLeave& e);
|
||||||
|
|
||||||
struct NewAmmoPickup {
|
struct NewPickup {
|
||||||
glm::vec3 Pos;
|
glm::vec3 Pos;
|
||||||
double AmmoGain;
|
double AmmoGain;
|
||||||
double RespawnTimer;
|
double RespawnTimer;
|
||||||
double DecreaseThisRespawnTimer;
|
double DecreaseThisRespawnTimer;
|
||||||
EntityID parentID;
|
EntityID parentID;
|
||||||
|
bool isAmmoPickup;
|
||||||
};
|
};
|
||||||
struct EntityAtMaxValuePickupStruct {
|
struct EntityAtMaxValuePickupStruct {
|
||||||
EntityWrapper player;
|
EntityWrapper player;
|
||||||
EntityWrapper pickup;
|
EntityWrapper pickup;
|
||||||
};
|
};
|
||||||
std::vector<NewAmmoPickup> m_ETriggerTouchVector;
|
std::vector<NewPickup> m_ETriggerTouchVector;
|
||||||
std::vector<EntityAtMaxValuePickupStruct> m_AmmoPickupAtMaxHealthAmmo;
|
std::vector<EntityAtMaxValuePickupStruct> m_PickupAtMaximum;
|
||||||
|
|
||||||
void DoPickup(EntityWrapper &player, EntityWrapper &trigger);
|
void DoPickup(EntityWrapper &player, EntityWrapper &trigger);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,12 +11,13 @@ 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/" + somePickup.isAmmoPickup ? "AmmoPickup.xml" : "HealthPickup.xml");
|
||||||
EntityFileParser parser(entityFile);
|
EntityFileParser parser(entityFile);
|
||||||
EntityID ammoPickupID = parser.MergeEntities(m_World);
|
EntityID ammoPickupID = parser.MergeEntities(m_World);
|
||||||
|
|
||||||
@@ -26,26 +27,31 @@ void AmmoPickupSystem::Update(double dt)
|
|||||||
m_EventBroker->Publish(ePickupSpawned);
|
m_EventBroker->Publish(ePickupSpawned);
|
||||||
|
|
||||||
//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& newPickupEntity = EntityWrapper(m_World, ammoPickupID);
|
||||||
newAmmoPickupEntity["Transform"]["Position"] = ammoPickupPosition.Pos;
|
newPickupEntity["Transform"]["Position"] = somePickup.Pos;
|
||||||
newAmmoPickupEntity["AmmoPickup"]["AmmoGain"] = ammoPickupPosition.AmmoGain;
|
if (somePickup.isAmmoPickup) {
|
||||||
newAmmoPickupEntity["AmmoPickup"]["RespawnTimer"] = ammoPickupPosition.RespawnTimer;
|
newPickupEntity["AmmoPickup"]["AmmoGain"] = somePickup.AmmoGain;
|
||||||
m_World->SetParent(newAmmoPickupEntity.ID, ammoPickupPosition.parentID);
|
newPickupEntity["AmmoPickup"]["RespawnTimer"] = somePickup.RespawnTimer;
|
||||||
|
} else {
|
||||||
|
newPickupEntity["HealthPickup"]["HealthGain"] = somePickup.AmmoGain;
|
||||||
|
newPickupEntity["HealthPickup"]["RespawnTimer"] = somePickup.RespawnTimer;
|
||||||
|
}
|
||||||
|
m_World->SetParent(newPickupEntity.ID, somePickup.parentID);
|
||||||
|
|
||||||
//erase the current element (AmmoPickupPosition)
|
//erase the current element (somePickup)
|
||||||
m_ETriggerTouchVector.erase(it);
|
m_ETriggerTouchVector.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//still touching AmmoPickupAtMaxHealthAmmo?
|
//still touching AmmoPickupAtMaxHealthAmmo?
|
||||||
for (auto& it = m_AmmoPickupAtMaxHealthAmmo.begin(); it != m_AmmoPickupAtMaxHealthAmmo.end(); ++it) {
|
for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) {
|
||||||
if (!it->player.Valid() || !it->pickup.Valid()) {
|
if (!it->player.Valid() || !it->pickup.Valid()) {
|
||||||
m_AmmoPickupAtMaxHealthAmmo.erase(it);
|
m_PickupAtMaximum.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((int)it->player["AssaultWeapon"]["Ammo"] < (int)it->player["AssaultWeapon"]["MaxAmmo"]) {
|
if ((int)it->player["AssaultWeapon"]["Ammo"] < (int)it->player["AssaultWeapon"]["MaxAmmo"]) {
|
||||||
DoPickup(it->player, it->pickup);
|
DoPickup(it->player, it->pickup);
|
||||||
m_AmmoPickupAtMaxHealthAmmo.erase(it);
|
m_PickupAtMaximum.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,18 +63,18 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
|||||||
if (e.Entity != LocalPlayer) {
|
if (e.Entity != LocalPlayer) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//TODO: add other weapontypes
|
if (!e.Trigger.HasComponent("AmmoPickup") && !e.Trigger.HasComponent("HealthPickup")) {
|
||||||
if (!e.Entity.HasComponent("AssaultWeapon")) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!e.Trigger.HasComponent("AmmoPickup")) {
|
//TODO: add other weapontypes
|
||||||
|
if (!e.Entity.HasComponent("AssaultWeapon")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int maxWeaponAmmo = (int)e.Entity["AssaultWeapon"]["MaxAmmo"];
|
int maxWeaponAmmo = (int)e.Entity["AssaultWeapon"]["MaxAmmo"];
|
||||||
int& currentAmmo = (int)e.Entity["AssaultWeapon"]["Ammo"];
|
int& currentAmmo = (int)e.Entity["AssaultWeapon"]["Ammo"];
|
||||||
//cant pick up ammopacks if you are already at MaxAmmo
|
//cant pick up ammopacks if you are already at MaxAmmo
|
||||||
if (currentAmmo >= maxWeaponAmmo) {
|
if (currentAmmo >= maxWeaponAmmo) {
|
||||||
m_AmmoPickupAtMaxHealthAmmo.push_back({ e.Entity, e.Trigger });
|
m_PickupAtMaximum.push_back({ e.Entity, e.Trigger });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
DoPickup(e.Entity, e.Trigger);
|
DoPickup(e.Entity, e.Trigger);
|
||||||
@@ -77,9 +83,9 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
|||||||
|
|
||||||
bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
|
bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
|
||||||
//triggerleave erases possible AmmoPickupAtMaxHealthAmmo
|
//triggerleave erases possible AmmoPickupAtMaxHealthAmmo
|
||||||
for (auto& it = m_AmmoPickupAtMaxHealthAmmo.begin(); it != m_AmmoPickupAtMaxHealthAmmo.end(); ++it) {
|
for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) {
|
||||||
if (it->pickup.ID == e.Trigger.ID && it->player.ID == e.Entity.ID) {
|
if (it->pickup.ID == e.Trigger.ID && it->player.ID == e.Entity.ID) {
|
||||||
m_AmmoPickupAtMaxHealthAmmo.erase(it);
|
m_PickupAtMaximum.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,18 +103,18 @@ void AmmoPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ammoGiven = 0.01*(double)gain * maxValue;
|
int increaseGiven = 0.01*(double)gain * maxValue;
|
||||||
Events::AmmoPickup ePlayerAmmoPickup;
|
Events::AmmoPickup ePlayerAmmoPickup;
|
||||||
ePlayerAmmoPickup.AmmoGain = ammoGiven;
|
ePlayerAmmoPickup.AmmoGain = increaseGiven;
|
||||||
ePlayerAmmoPickup.Player = player;
|
ePlayerAmmoPickup.Player = player;
|
||||||
m_EventBroker->Publish(ePlayerAmmoPickup);
|
m_EventBroker->Publish(ePlayerAmmoPickup);
|
||||||
//immediately give the player the ammo
|
//immediately give the player the ammo
|
||||||
currentValue = std::min(currentValue + ammoGiven, maxValue);
|
currentValue = std::min(currentValue + increaseGiven, maxValue);
|
||||||
|
|
||||||
//copy position, ammogain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object)
|
//copy position, ammogain, 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 ammoPickup
|
//we need to copy all values since each value can be different for each ammoPickup
|
||||||
m_ETriggerTouchVector.push_back({ trigger["Transform"]["Position"], gain,
|
m_ETriggerTouchVector.push_back({ trigger["Transform"]["Position"], gain,
|
||||||
pickup["RespawnTimer"], pickup["RespawnTimer"], m_World->GetParent(trigger.ID) });
|
pickup["RespawnTimer"], pickup["RespawnTimer"], m_World->GetParent(trigger.ID) , true });
|
||||||
|
|
||||||
//delete the ammopickup
|
//delete the ammopickup
|
||||||
m_World->DeleteEntity(trigger.ID);
|
m_World->DeleteEntity(trigger.ID);
|
||||||
|
|||||||
Reference in New Issue
Block a user