experimental changes
This commit is contained in:
@@ -23,19 +23,20 @@ private:
|
||||
EventRelay<AmmoPickupSystem, Events::TriggerLeave> m_ETriggerLeave;
|
||||
bool OnTriggerLeave(Events::TriggerLeave& e);
|
||||
|
||||
struct NewAmmoPickup {
|
||||
struct NewPickup {
|
||||
glm::vec3 Pos;
|
||||
double AmmoGain;
|
||||
double RespawnTimer;
|
||||
double DecreaseThisRespawnTimer;
|
||||
EntityID parentID;
|
||||
bool isAmmoPickup;
|
||||
};
|
||||
struct EntityAtMaxValuePickupStruct {
|
||||
EntityWrapper player;
|
||||
EntityWrapper pickup;
|
||||
};
|
||||
std::vector<NewAmmoPickup> m_ETriggerTouchVector;
|
||||
std::vector<EntityAtMaxValuePickupStruct> m_AmmoPickupAtMaxHealthAmmo;
|
||||
std::vector<NewPickup> m_ETriggerTouchVector;
|
||||
std::vector<EntityAtMaxValuePickupStruct> m_PickupAtMaximum;
|
||||
|
||||
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)
|
||||
{
|
||||
auto& ammoPickupPosition = *it;
|
||||
auto& somePickup = *it;
|
||||
|
||||
//set the double timer value (value 3)
|
||||
ammoPickupPosition.DecreaseThisRespawnTimer -= dt;
|
||||
if (ammoPickupPosition.DecreaseThisRespawnTimer < 0.0) {
|
||||
somePickup.DecreaseThisRespawnTimer -= dt;
|
||||
if (somePickup.DecreaseThisRespawnTimer < 0.0) {
|
||||
//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);
|
||||
EntityID ammoPickupID = parser.MergeEntities(m_World);
|
||||
|
||||
@@ -26,26 +27,31 @@ void AmmoPickupSystem::Update(double dt)
|
||||
m_EventBroker->Publish(ePickupSpawned);
|
||||
|
||||
//set values from the old entity to the new entity
|
||||
auto& newAmmoPickupEntity = EntityWrapper(m_World, ammoPickupID);
|
||||
newAmmoPickupEntity["Transform"]["Position"] = ammoPickupPosition.Pos;
|
||||
newAmmoPickupEntity["AmmoPickup"]["AmmoGain"] = ammoPickupPosition.AmmoGain;
|
||||
newAmmoPickupEntity["AmmoPickup"]["RespawnTimer"] = ammoPickupPosition.RespawnTimer;
|
||||
m_World->SetParent(newAmmoPickupEntity.ID, ammoPickupPosition.parentID);
|
||||
auto& newPickupEntity = EntityWrapper(m_World, ammoPickupID);
|
||||
newPickupEntity["Transform"]["Position"] = somePickup.Pos;
|
||||
if (somePickup.isAmmoPickup) {
|
||||
newPickupEntity["AmmoPickup"]["AmmoGain"] = somePickup.AmmoGain;
|
||||
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);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//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()) {
|
||||
m_AmmoPickupAtMaxHealthAmmo.erase(it);
|
||||
m_PickupAtMaximum.erase(it);
|
||||
break;
|
||||
}
|
||||
if ((int)it->player["AssaultWeapon"]["Ammo"] < (int)it->player["AssaultWeapon"]["MaxAmmo"]) {
|
||||
DoPickup(it->player, it->pickup);
|
||||
m_AmmoPickupAtMaxHealthAmmo.erase(it);
|
||||
m_PickupAtMaximum.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -57,18 +63,18 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
||||
if (e.Entity != LocalPlayer) {
|
||||
return false;
|
||||
}
|
||||
//TODO: add other weapontypes
|
||||
if (!e.Entity.HasComponent("AssaultWeapon")) {
|
||||
if (!e.Trigger.HasComponent("AmmoPickup") && !e.Trigger.HasComponent("HealthPickup")) {
|
||||
return false;
|
||||
}
|
||||
if (!e.Trigger.HasComponent("AmmoPickup")) {
|
||||
//TODO: add other weapontypes
|
||||
if (!e.Entity.HasComponent("AssaultWeapon")) {
|
||||
return false;
|
||||
}
|
||||
int maxWeaponAmmo = (int)e.Entity["AssaultWeapon"]["MaxAmmo"];
|
||||
int& currentAmmo = (int)e.Entity["AssaultWeapon"]["Ammo"];
|
||||
//cant pick up ammopacks if you are already at MaxAmmo
|
||||
if (currentAmmo >= maxWeaponAmmo) {
|
||||
m_AmmoPickupAtMaxHealthAmmo.push_back({ e.Entity, e.Trigger });
|
||||
m_PickupAtMaximum.push_back({ e.Entity, e.Trigger });
|
||||
return false;
|
||||
}
|
||||
DoPickup(e.Entity, e.Trigger);
|
||||
@@ -77,9 +83,9 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
||||
|
||||
bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
|
||||
//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) {
|
||||
m_AmmoPickupAtMaxHealthAmmo.erase(it);
|
||||
m_PickupAtMaximum.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -97,18 +103,18 @@ void AmmoPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
|
||||
return;
|
||||
}
|
||||
|
||||
int ammoGiven = 0.01*(double)gain * maxValue;
|
||||
int increaseGiven = 0.01*(double)gain * maxValue;
|
||||
Events::AmmoPickup ePlayerAmmoPickup;
|
||||
ePlayerAmmoPickup.AmmoGain = ammoGiven;
|
||||
ePlayerAmmoPickup.AmmoGain = increaseGiven;
|
||||
ePlayerAmmoPickup.Player = player;
|
||||
m_EventBroker->Publish(ePlayerAmmoPickup);
|
||||
//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)
|
||||
//we need to copy all values since each value can be different for each ammoPickup
|
||||
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
|
||||
m_World->DeleteEntity(trigger.ID);
|
||||
|
||||
Reference in New Issue
Block a user