diff --git a/resources/Schema/Components/Player.xsd b/resources/Schema/Components/Player.xsd index fcf07879..9ffc28b0 100644 --- a/resources/Schema/Components/Player.xsd +++ b/resources/Schema/Components/Player.xsd @@ -4,6 +4,9 @@ + + The player charachter + @@ -11,7 +14,7 @@ - + diff --git a/resources/Schema/Components/PrimaryItem.xml b/resources/Schema/Components/PrimaryItem.xml index 540a1518..0d0ccca2 100644 --- a/resources/Schema/Components/PrimaryItem.xml +++ b/resources/Schema/Components/PrimaryItem.xml @@ -1,4 +1,4 @@ 0 0 - \ No newline at end of file + \ No newline at end of file diff --git a/resources/Schema/Components/PrimaryItem.xsd b/resources/Schema/Components/PrimaryItem.xsd index 193b9213..bbff122d 100644 --- a/resources/Schema/Components/PrimaryItem.xsd +++ b/resources/Schema/Components/PrimaryItem.xsd @@ -4,10 +4,17 @@ + + The Players Primary Item/Weapon + - - + + Ammo count + + + Cooldown till next item/weapon use + diff --git a/resources/Schema/Components/SecondaryItem.xml b/resources/Schema/Components/SecondaryItem.xml index 0fae1402..095dfef6 100644 --- a/resources/Schema/Components/SecondaryItem.xml +++ b/resources/Schema/Components/SecondaryItem.xml @@ -1,4 +1,4 @@ 0 0 - \ No newline at end of file + \ No newline at end of file diff --git a/resources/Schema/Components/SecondaryItem.xsd b/resources/Schema/Components/SecondaryItem.xsd index 44e23611..ab428920 100644 --- a/resources/Schema/Components/SecondaryItem.xsd +++ b/resources/Schema/Components/SecondaryItem.xsd @@ -4,10 +4,17 @@ + + The Players Secondary Item/Weapon + - - + + Ammo count + + + Cooldown till next item/weapon use + diff --git a/src/Game/PlayerSystem.cpp b/src/Game/PlayerSystem.cpp index f5819ea1..e40469cc 100644 --- a/src/Game/PlayerSystem.cpp +++ b/src/Game/PlayerSystem.cpp @@ -27,25 +27,35 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou leftMouseWasReleased = false; //get the health component linked to the playerId double currentHealth = (double)world->GetComponent(player.EntityID, "Health")["Health"]; - int currentAmmo = 0; - double currentCoolDownTimer = 0.0f; + double currentAmmo = (double)0; + double currentCoolDownTimer = (double)0; - if ((int)player["EquippedItem"] == 1) { + if ((double)player["EquippedItem"] == (double)1) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); currentAmmo = currentItem["Ammo"]; - //subtract 1 ammo - the ItemSystem will probably listen to eShoot and handle the CoolDownTimer - currentItem["Ammo"] = (int)currentItem["Ammo"] -1; - int test = (int)currentItem["Ammo"]; - currentCoolDownTimer = (double)world->GetComponent(player.EntityID, "PrimaryItem")["CoolDownTimer"]; + currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; } - if ((int)player["EquippedItem"] == 2) { + if ((double)player["EquippedItem"] == (double)2) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); currentAmmo = currentItem["Ammo"]; - //subtract 1 ammo - the ItemSystem will probably listen to eShoot and handle the CoolDownTimer - currentItem["Ammo"] = (int)currentItem["Ammo"] - 1; - currentCoolDownTimer = (double)world->GetComponent(player.EntityID, "SecondaryItem")["CoolDownTimer"]; + currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; } - if (currentHealth > 0.0f && currentAmmo > 0 && currentCoolDownTimer < 0.001f) { + + if (currentHealth > (double)0.0f && currentAmmo > (double)0.0f && currentCoolDownTimer < (double)0.001f) { + //decrease ammo count + //TODO: temp, set the cooldowntimer - probably done in some other system (itemSystem?) later + if ((double)player["EquippedItem"] == (double)1) { + ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); + int currentAmmoInt = (int)((double)currentItem["Ammo"]); + currentItem["Ammo"] = (double)(currentAmmoInt - 1); + currentItem["CoolDownTimer"] = (double)2; + } + if ((double)player["EquippedItem"] == (double)2) { + ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); + int currentAmmoInt = (int)((double)currentItem["Ammo"]); + currentItem["Ammo"] = (double)(currentAmmoInt - 1); + currentItem["CoolDownTimer"] = (double)2; + } //create and publish the shoot event Events::Shoot eShoot; eShoot.currentAimingPoint = aimingCoordinates; diff --git a/src/Tests/ShootEventTest.cpp b/src/Tests/ShootEventTest.cpp index 481772c1..22c2a0eb 100644 --- a/src/Tests/ShootEventTest.cpp +++ b/src/Tests/ShootEventTest.cpp @@ -3,17 +3,15 @@ using boost::unit_test_framework::test_suite; using boost::unit_test_framework::test_case; #include "ShootEventTest.h" -#include "Core\EPlayerDamage.h"; -#include "Core\EPlayerHealthPickup.h"; -#include "Core\EPlayerDeath.h"; #include "Game/HealthSystem.h" BOOST_AUTO_TEST_SUITE(ShootEventTestSuite) -//AShootEventTest != ShootEventTest -> else it confuses names! -BOOST_AUTO_TEST_CASE(AShootEventTest) +//dont use the same name as the classname in test cases... +BOOST_AUTO_TEST_CASE(ShootEventTest_PrimaryWeaponFiring) { - ShootEventTest game; + //Test firing primary weapon + ShootEventTest game(1); //100 loops will be more than enough to do the test int loops = 100; bool success = false; @@ -28,9 +26,59 @@ BOOST_AUTO_TEST_CASE(AShootEventTest) //The system will process the events, hence it will take a while before we can read anything BOOST_TEST(success); } +BOOST_AUTO_TEST_CASE(ShootEventTest_SecondaryWeaponFiring) +{ + //Test firing secondary weapon + ShootEventTest game(2); + //100 loops will be more than enough to do the test + int loops = 100; + bool success = false; + while (loops > 0) { + game.Tick(); + if (game.TestSucceeded) { + success = true; + break; + } + loops--; + } + //The system will process the events, hence it will take a while before we can read anything + BOOST_TEST(success); +} +BOOST_AUTO_TEST_CASE(ShootEventTest_NoWeaponFiring) +{ + //Test firing with no weapon equipped + ShootEventTest game(3); + //100 loops will be more than enough to do the test + int loops = 100; + bool success = false; + while (loops > 0) { + game.Tick(); + loops--; + } + //The system will process the events, hence it will take a while before we can read anything + if (game.TestSucceeded) + success = true; + BOOST_TEST(success); +} +BOOST_AUTO_TEST_CASE(ShootEventTest_WeaponOnCooldown) +{ + //Test firing with weapon on cooldown + ShootEventTest game(4); + //100 loops will be more than enough to do the test + int loops = 100; + bool success = false; + while (loops > 0) { + game.Tick(); + loops--; + } + //The system will process the events, hence it will take a while before we can read anything + if (game.TestSucceeded) + success = true; + BOOST_TEST(success); +} BOOST_AUTO_TEST_SUITE_END() -ShootEventTest::ShootEventTest() +ShootEventTest::ShootEventTest(int runTestNumber) { ResourceManager::RegisterType("ConfigFile"); ResourceManager::RegisterType("EntityXMLFile"); @@ -41,7 +89,7 @@ ShootEventTest::ShootEventTest() // Create the core event broker m_EventBroker = new EventBroker(); - // Create a world + // Create a world m_World = new World(); std::string mapToLoad = m_Config->Get("Debug.LoadMap", ""); if (!mapToLoad.empty()) { @@ -54,30 +102,40 @@ ShootEventTest::ShootEventTest() m_SystemPipeline->AddSystem(0); //The Test - //create entity which has transorm,player,model,health in it. i.e. is a player + //create entity which has transform,player,model,health in it. i.e. is a player EntityID playerID = m_World->CreateEntity(); - ComponentWrapper transform = m_World->AttachComponent(playerID, "Transform"); - ComponentWrapper model = m_World->AttachComponent(playerID, "Model"); - model["Resource"] = "Models/Core/UnitSphere.obj"; - ComponentWrapper& player = m_World->AttachComponent(playerID, "Player"); + m_PlayerID = playerID; ComponentWrapper health = m_World->AttachComponent(playerID, "Health"); - playersID = playerID; + ComponentWrapper& player = m_World->AttachComponent(playerID, "Player"); //attach 2x weaps ComponentWrapper& pItem = m_World->AttachComponent(playerID, "PrimaryItem"); - ComponentWrapper& sItem= m_World->AttachComponent(playerID, "SecondaryItem"); - //set currentweap - player["EquippedItem"] = 1; - //set ammo set cooldown - pItem["Ammo"] = 100; - pItem["CoolDownTimer"] = 0.0f; + ComponentWrapper& sItem = m_World->AttachComponent(playerID, "SecondaryItem"); - //trigger event leftmousedown + m_RunTestNumber = runTestNumber; + switch (runTestNumber) + { + case 1: + TestSetup1(player, pItem, sItem); + break; + case 2: + TestSetup2(player, pItem, sItem); + break; + case 3: + TestSetup3(player, pItem, sItem); + break; + case 4: + TestSetup4(player, pItem, sItem); + break; + default: + break; + } + + //fire once = trigger event leftmousedown Events::MouseRelease eMouseRelease; eMouseRelease.Button = GLFW_MOUSE_BUTTON_LEFT; eMouseRelease.X = 1.0f; eMouseRelease.Y = 1.0f; m_EventBroker->Publish(eMouseRelease); - } ShootEventTest::~ShootEventTest() @@ -87,6 +145,77 @@ ShootEventTest::~ShootEventTest() delete m_EventBroker; } +void ShootEventTest::TestSetup1(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) +{ + //set currentweap + player["EquippedItem"] = (double)1.0f; + //set ammo set cooldown + pItem["Ammo"] = (double)100.0f; + pItem["CoolDownTimer"] = (double)0.0f; +} +void ShootEventTest::TestSetup2(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) +{ + //set currentweap + player["EquippedItem"] = (double)2.0f; + //set ammo set cooldown + sItem["Ammo"] = (double)10.0f; + sItem["CoolDownTimer"] = (double)0.0f; +} +void ShootEventTest::TestSetup3(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) +{ + player["EquippedItem"] = (double)0.0f; + pItem["Ammo"] = (double)100.0f; + sItem["Ammo"] = (double)100.0f; + //TestSucceeded will be set to false if ammo changes during the 100 loops + TestSucceeded = true; +} +void ShootEventTest::TestSetup4(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) +{ + //set currentweap + player["EquippedItem"] = (double)1.0f; + //set ammo set cooldown + pItem["Ammo"] = (double)100.0f; + pItem["CoolDownTimer"] = (double)5.0f; + //TestSucceeded will be set to false if ammo changes during the 100 loops + TestSucceeded = true; +} +void ShootEventTest::TestSuccess1() { + //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired + double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; + if (currentAmmo == (double)99) + TestSucceeded = true; +} +void ShootEventTest::TestSuccess2() { + //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired + double currentAmmo = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"]; + if (currentAmmo == (double)9) + TestSucceeded = true; +} +void ShootEventTest::TestSuccess3() { + //try firing again + Events::MouseRelease eMouseRelease; + eMouseRelease.Button = GLFW_MOUSE_BUTTON_LEFT; + eMouseRelease.X = 1.0f; + eMouseRelease.Y = 1.0f; + m_EventBroker->Publish(eMouseRelease); + //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired + double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; + double currentAmmoSecondary = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"]; + if (currentAmmo != (double)100 || currentAmmoSecondary != (double)100) + TestSucceeded = false; +} +void ShootEventTest::TestSuccess4() { + //try firing again + Events::MouseRelease eMouseRelease; + eMouseRelease.Button = GLFW_MOUSE_BUTTON_LEFT; + eMouseRelease.X = 1.0f; + eMouseRelease.Y = 1.0f; + m_EventBroker->Publish(eMouseRelease); + //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired + double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; + if (currentAmmo != (double)100) + TestSucceeded = false; +} void ShootEventTest::Tick() { glfwPollEvents(); @@ -101,8 +230,22 @@ void ShootEventTest::Tick() m_EventBroker->Swap(); m_EventBroker->Clear(); - //if ammocount reaches 99 we know the test has succeeded, i.e. a shot has been fired - int currentAmmo = (int)m_World->GetComponent(playersID, "PrimaryItem")["Ammo"]; - if (currentAmmo ==99) - TestSucceeded = true; + switch (m_RunTestNumber) + { + case 1: + TestSuccess1(); + break; + case 2: + TestSuccess2(); + break; + case 3: + TestSuccess3(); + break; + case 4: + TestSuccess4(); + break; + default: + break; + } + } diff --git a/src/Tests/ShootEventTest.h b/src/Tests/ShootEventTest.h index 49206ceb..0ffa1f91 100644 --- a/src/Tests/ShootEventTest.h +++ b/src/Tests/ShootEventTest.h @@ -4,20 +4,14 @@ #include "Core/ResourceManager.h" #include "Core/ConfigFile.h" #include "Core/EventBroker.h" -#include "Rendering/Renderer.h" -#include "Core/InputManager.h" -#include "GUI/Frame.h" #include "Core/World.h" -#include "Rendering/RenderQueueFactory.h" #include "Input/InputProxy.h" #include "Input/KeyboardInputHandler.h" #include "Input/MouseInputHandler.h" #include "Core/EKeyDown.h" #include "Core/EntityXMLFile.h" #include "Core/SystemPipeline.h" -#include "RaptorCopterSystem.h" #include "PlayerSystem.h" -#include "Editor/EditorSystem.h" #include "Core\EMouseRelease.h" #include "Core\EShoot.h" @@ -25,19 +19,30 @@ class ShootEventTest { public: - ShootEventTest(); + ShootEventTest(int runTestNumber); ~ShootEventTest(); void Tick(); bool TestSucceeded = false; private: + void TestSetup1(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem); + void TestSetup2(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem); + void TestSetup3(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem); + void TestSetup4(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem); + void TestSuccess1(); + void TestSuccess2(); + void TestSuccess3(); + void TestSuccess4(); + double m_LastTime; ConfigFile* m_Config = nullptr; EventBroker* m_EventBroker; World* m_World; SystemPipeline* m_SystemPipeline; - int playersID; + int m_PlayerID; + int m_RunTestNumber; + }; #endif