diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index 7dc24a2c..1ba783de 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -192,6 +192,8 @@ bool FirstPersonInputController::OnLockMouse(const Events::LockMou template void FirstPersonInputController::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer) { + ImGui::Text(std::to_string(m_AssaultDashCoolDownTimer).c_str()); + m_AssaultDashDoubleTapDeltaTime += dt; m_AssaultDashCoolDownTimer -= dt; //cooldown = assaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work) diff --git a/include/Game/Systems/AmmoPickupSystem.h b/include/Game/Systems/AmmoPickupSystem.h index 0fbd9e08..46db2585 100644 --- a/include/Game/Systems/AmmoPickupSystem.h +++ b/include/Game/Systems/AmmoPickupSystem.h @@ -20,6 +20,8 @@ public: private: EventRelay m_ETriggerTouch; bool OnTriggerTouch(Events::TriggerTouch& e); + EventRelay m_ETriggerLeave; + bool OnTriggerLeave(Events::TriggerLeave& e); struct NewAmmoPickup { glm::vec3 Pos; @@ -28,6 +30,13 @@ private: double DecreaseThisRespawnTimer; EntityID parentID; }; + struct EntityAtMaxValuePickupStruct { + EntityWrapper player; + EntityWrapper pickup; + }; std::vector m_ETriggerTouchVector; + std::vector m_AmmoPickupAtMaxHealthAmmo; + + void DoPickup(EntityWrapper &player, EntityWrapper &trigger); }; #endif diff --git a/resources/Schema/Entities/aim_rays.xml b/resources/Schema/Entities/aim_rays.xml index c8dac9a3..cc43d88e 100644 --- a/resources/Schema/Entities/aim_rays.xml +++ b/resources/Schema/Entities/aim_rays.xml @@ -215,7 +215,8 @@ Models\Core\UnitCube.mesh - + + true @@ -241,7 +242,8 @@ Models\Core\UnitCube.mesh - + + true @@ -256,6 +258,25 @@ + + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + 8 + + + + + + + + + + + diff --git a/src/Game/Systems/AmmoPickupSystem.cpp b/src/Game/Systems/AmmoPickupSystem.cpp index 250fa494..62e8358f 100644 --- a/src/Game/Systems/AmmoPickupSystem.cpp +++ b/src/Game/Systems/AmmoPickupSystem.cpp @@ -4,6 +4,7 @@ AmmoPickupSystem::AmmoPickupSystem(SystemParams params) : System(params) { EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &AmmoPickupSystem::OnTriggerTouch); + EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &AmmoPickupSystem::OnTriggerLeave); } void AmmoPickupSystem::Update(double dt) @@ -36,6 +37,18 @@ void AmmoPickupSystem::Update(double dt) break; } } + //still touching AmmoPickupAtMaxHealthAmmo? + for (auto& it = m_AmmoPickupAtMaxHealthAmmo.begin(); it != m_AmmoPickupAtMaxHealthAmmo.end(); ++it) { + if (!it->player.Valid() || !it->pickup.Valid()) { + m_AmmoPickupAtMaxHealthAmmo.erase(it); + break; + } + if ((int)it->player["AssaultWeapon"]["Ammo"] < (int)it->player["AssaultWeapon"]["MaxAmmo"]) { + DoPickup(it->player, it->pickup); + m_AmmoPickupAtMaxHealthAmmo.erase(it); + break; + } + } } @@ -53,27 +66,50 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e) } int maxWeaponAmmo = (int)e.Entity["AssaultWeapon"]["MaxAmmo"]; int& currentAmmo = (int)e.Entity["AssaultWeapon"]["Ammo"]; - - int ammoGiven = 0.01*(double)e.Trigger["AmmoPickup"]["AmmoGain"] * maxWeaponAmmo; //cant pick up ammopacks if you are already at MaxAmmo if (currentAmmo >= maxWeaponAmmo) { + m_AmmoPickupAtMaxHealthAmmo.push_back({ e.Entity, e.Trigger }); return false; } + DoPickup(e.Entity, e.Trigger); + return true; +} - //personEntered = e.Entity, thingEntered = e.Trigger +bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) { + //triggerleave erases possible AmmoPickupAtMaxHealthAmmo + for (auto& it = m_AmmoPickupAtMaxHealthAmmo.begin(); it != m_AmmoPickupAtMaxHealthAmmo.end(); ++it) { + if (it->pickup.ID == e.Trigger.ID && it->player.ID == e.Entity.ID) { + m_AmmoPickupAtMaxHealthAmmo.erase(it); + break; + } + } + return true; +} +void AmmoPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) { + auto& weaponEntity = player["AssaultWeapon"]; + auto& pickup = trigger["AmmoPickup"]; + auto& gain = pickup["AmmoGain"]; + int maxValue = (int)weaponEntity["MaxAmmo"]; + int& currentValue = (int)weaponEntity["Ammo"]; + + //cant pick up if you are already at max + if (currentValue >= maxValue) { + return; + } + + int ammoGiven = 0.01*(double)gain * maxValue; Events::AmmoPickup ePlayerAmmoPickup; ePlayerAmmoPickup.AmmoGain = ammoGiven; - ePlayerAmmoPickup.Player = e.Entity; + ePlayerAmmoPickup.Player = player; m_EventBroker->Publish(ePlayerAmmoPickup); //immediately give the player the ammo - currentAmmo = std::min(currentAmmo + ammoGiven, maxWeaponAmmo); + currentValue = std::min(currentValue + ammoGiven, 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({ e.Trigger["Transform"]["Position"], e.Trigger["AmmoPickup"]["AmmoGain"], - e.Trigger["AmmoPickup"]["RespawnTimer"], e.Trigger["AmmoPickup"]["RespawnTimer"], m_World->GetParent(e.Trigger.ID) }); + m_ETriggerTouchVector.push_back({ trigger["Transform"]["Position"], gain, + pickup["RespawnTimer"], pickup["RespawnTimer"], m_World->GetParent(trigger.ID) }); //delete the ammopickup - m_World->DeleteEntity(e.Trigger.ID); - return true; + m_World->DeleteEntity(trigger.ID); } diff --git a/src/Game/Systems/PlayerSpawnSystem.cpp b/src/Game/Systems/PlayerSpawnSystem.cpp index 9e98b0c3..a57d48a6 100644 --- a/src/Game/Systems/PlayerSpawnSystem.cpp +++ b/src/Game/Systems/PlayerSpawnSystem.cpp @@ -208,12 +208,12 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e) void PlayerSpawnSystem::CheckForLatePlayers(double dt) { for (size_t i = 0; i < m_LatePlayersVector.size(); i++) { - auto& req = m_SpawnRequests[i]; + auto& req = m_LatePlayersVector[i]; req.timeSinceDeath += dt; if (req.timeSinceDeath > 2.5f) { //good but, this will only spawn them in the next cycle - i.e. not immediately //m_SpawnRequests.push_back(spawnReq); - + //insta spawn auto playerSpawns = m_World->GetComponents("PlayerSpawn"); for (auto& cPlayerSpawn : *playerSpawns) {