diff --git a/include/Engine/Core/EAmmoPickup.h b/include/Engine/Core/EAmmoPickup.h new file mode 100644 index 00000000..6d854d48 --- /dev/null +++ b/include/Engine/Core/EAmmoPickup.h @@ -0,0 +1,18 @@ +#ifndef EAmmoPickup_h__ +#define EAmmoPickup_h__ + +#include "EventBroker.h" +#include "../Core/EntityWrapper.h" + +namespace Events +{ + + struct AmmoPickup : Event + { + EntityWrapper Player; + int AmmoGain; + }; + +} + +#endif \ No newline at end of file diff --git a/include/Game/Systems/AmmoPickupSystem.h b/include/Game/Systems/AmmoPickupSystem.h new file mode 100644 index 00000000..a54b8495 --- /dev/null +++ b/include/Game/Systems/AmmoPickupSystem.h @@ -0,0 +1,32 @@ +#ifndef AmmoPickupSystem_h__ +#define AmmoPickupSystem_h__ + +#include "Core/System.h" +#include "Core/Transform.h" +#include "Core/ResourceManager.h" +#include "Core/EntityFileParser.h" +#include "Core/EPickupSpawned.h" +#include "Core/EAmmoPickup.h" +#include "Engine/Collision/ETrigger.h" +#include "Common.h" + +class AmmoPickupSystem : public ImpureSystem +{ +public: + AmmoPickupSystem(SystemParams params); + + virtual void Update(double dt) override; + +private: + EventRelay m_ETriggerTouch; + bool OnTriggerTouch(Events::TriggerTouch& e); + + struct NewAmmoPickup { + glm::vec3 Pos; + double AmmoGain; + double RespawnTimer; + double DecreaseThisRespawnTimer; + }; + std::vector m_ETriggerTouchVector; +}; +#endif diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index f950e8c8..53e666de 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -32,6 +32,7 @@ + diff --git a/resources/Schema/Components/AmmoPickup.xml b/resources/Schema/Components/AmmoPickup.xml new file mode 100644 index 00000000..6da0b6fa --- /dev/null +++ b/resources/Schema/Components/AmmoPickup.xml @@ -0,0 +1,5 @@ + + + 3 + 30 + \ No newline at end of file diff --git a/resources/Schema/Components/AmmoPickup.xsd b/resources/Schema/Components/AmmoPickup.xsd new file mode 100644 index 00000000..1970eb78 --- /dev/null +++ b/resources/Schema/Components/AmmoPickup.xsd @@ -0,0 +1,21 @@ + + + + + + + + An Ammo Pickup + + + + + The respawn timer for a ammo pickup + + + How much percent ammo gain the player will get + + + + + diff --git a/resources/Schema/Entities/AmmoPickup.xml b/resources/Schema/Entities/AmmoPickup.xml new file mode 100644 index 00000000..534b76e2 --- /dev/null +++ b/resources/Schema/Entities/AmmoPickup.xml @@ -0,0 +1,18 @@ + + + + + + + + Models/Core/UnitSphere.mesh + + + + + + + + + + diff --git a/resources/Schema/Entities/AmmoPickupTest.xml b/resources/Schema/Entities/AmmoPickupTest.xml new file mode 100644 index 00000000..22690c65 --- /dev/null +++ b/resources/Schema/Entities/AmmoPickupTest.xml @@ -0,0 +1,294 @@ + + + + + + + + + + + + Models/LevelBase/MapVersion1.mesh + + + + + + + + + 2 + + + Models/DirectionalLightWidget.mesh + false + + + + + + + + + + + + + 8 + 2.7999999523162842 + + + + + + + + + + + 8 + 2.7999999523162842 + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + false + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + false + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + 22 + + + Models/Core/UnitSphere.mesh + + + + + + + + + + + + + 1 + 22 + + + Models/Core/UnitSphere.mesh + + + + + + + + + + + + + 4 + 44 + + + Models/Core/UnitSphere.mesh + + + + + + + + + + + diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 96b02711..1408bec7 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -14,6 +14,7 @@ #include "Game/Systems/CapturePointSystem.h" #include "Game/Systems/CapturePointHUDSystem.h" #include "Game/Systems/PickupSpawnSystem.h" +#include "Game/Systems/AmmoPickupSystem.h" #include "Game/Systems/DamageIndicatorSystem.h" #include "Game/Systems/Weapon/WeaponSystem.h" #include "Rendering/AnimationSystem.h" @@ -124,6 +125,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); + m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); // Populate Octree with collidables ++updateOrderLevel; diff --git a/src/Game/Systems/AmmoPickupSystem.cpp b/src/Game/Systems/AmmoPickupSystem.cpp new file mode 100644 index 00000000..f6778fe4 --- /dev/null +++ b/src/Game/Systems/AmmoPickupSystem.cpp @@ -0,0 +1,78 @@ +#include "Systems/AmmoPickupSystem.h" + +AmmoPickupSystem::AmmoPickupSystem(SystemParams params) + : System(params) +{ + EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &AmmoPickupSystem::OnTriggerTouch); +} + +void AmmoPickupSystem::Update(double dt) +{ + for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it) + { + auto& ammoPickupPosition = *it; + //set the double timer value (value 3) + ammoPickupPosition.DecreaseThisRespawnTimer -= dt; + if (ammoPickupPosition.DecreaseThisRespawnTimer < 0.0) { + //spawn and delete the vector item + auto entityFile = ResourceManager::Load("Schema/Entities/AmmoPickup.xml"); + EntityFileParser parser(entityFile); + EntityID ammoPickupID = parser.MergeEntities(m_World); + + //let the world know a pickup has spawned (graphics effects, etc) + Events::PickupSpawned ePickupSpawned; + ePickupSpawned.Pickup = EntityWrapper(m_World, ammoPickupID); + 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; + + //erase the current element (AmmoPickupPosition) + m_ETriggerTouchVector.erase(it); + break; + } + } +} + + +bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e) +{ + if (e.Entity != LocalPlayer) { + return false; + } + //TODO: add other weapontypes + if (!e.Entity.HasComponent("AssaultWeapon")) { + return false; + } + if (!e.Trigger.HasComponent("AmmoPickup")) { + return false; + } + 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) { + return false; + } + + //personEntered = e.Entity, thingEntered = e.Trigger + Events::AmmoPickup ePlayerAmmoPickup; + ePlayerAmmoPickup.AmmoGain = ammoGiven; + ePlayerAmmoPickup.Player = e.Entity; + m_EventBroker->Publish(ePlayerAmmoPickup); + //immediately give the player the ammo + currentAmmo = std::min(currentAmmo + ammoGiven, maxWeaponAmmo); + + //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({ (glm::vec3)e.Trigger["Transform"]["Position"] ,e.Trigger["AmmoPickup"]["AmmoGain"], + e.Trigger["AmmoPickup"]["RespawnTimer"],e.Trigger["AmmoPickup"]["RespawnTimer"] }); + + //delete the ammopickup + m_World->DeleteEntity(e.Trigger.ID); + return true; +}