diff --git a/include/Engine/Core/EShoot.h b/include/Engine/Core/EShoot.h index d9b9e20b..3887606b 100644 --- a/include/Engine/Core/EShoot.h +++ b/include/Engine/Core/EShoot.h @@ -12,7 +12,7 @@ struct Shoot : Event { //shotgun etc has different amounts of damage probably (a sniper shot might one-shot) //also different weapons will have different spread - std::string weaponType; + int currentlyEquippedItem; //currentAimingPoint must be sent, in case the camera is moved while the event is being processed glm::vec2 currentAimingPoint; }; diff --git a/include/Game/PlayerSystem.h b/include/Game/PlayerSystem.h index 87dc6f5d..3544c63c 100644 --- a/include/Game/PlayerSystem.h +++ b/include/Game/PlayerSystem.h @@ -35,6 +35,11 @@ private: bool PlayerSystem::OnLeave(const Events::TriggerLeave &event); EventRelay m_MouseRelease; bool PlayerSystem::OnMouseRelease(const Events::MouseRelease& e); + enum class HeldItem { + None = 0, + PrimaryWeapon = 1, + SecondaryWeapon = 2 + }; }; #endif \ No newline at end of file diff --git a/src/Game/PlayerSystem.cpp b/src/Game/PlayerSystem.cpp index 2e2120d9..ca39ed4f 100644 --- a/src/Game/PlayerSystem.cpp +++ b/src/Game/PlayerSystem.cpp @@ -27,39 +27,39 @@ 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"]; - double currentAmmo = (double)0; - double currentCoolDownTimer = (double)0; + double currentAmmo = 0.0; + double currentCoolDownTimer = 0.0; - if (fabs((double)player["EquippedItem"] - (double)1) < (double) 0.0001f) { + if (fabs((double)player["EquippedItem"] - (double)HeldItem::PrimaryWeapon) < 0.0001) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); currentAmmo = (double)currentItem["Ammo"]; currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; } - if (fabs((double)player["EquippedItem"] - (double)2) < (double) 0.0001f) { + if (fabs((double)player["EquippedItem"] - (double)HeldItem::SecondaryWeapon) < 0.0001) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); currentAmmo = (double)currentItem["Ammo"]; currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; } - if (currentHealth > (double)0.0f && currentAmmo > (double)0.0f && currentCoolDownTimer < (double)0.001f) { + if (currentHealth > 0.0 && currentAmmo > 0.0 && currentCoolDownTimer < 0.001) { //decrease ammo count //TODO: temp, set the cooldowntimer - probably done in some other system (itemSystem?) later - if (fabs((double)player["EquippedItem"] - (double)1) < (double) 0.0001f) { + if (fabs((double)player["EquippedItem"] - (double)HeldItem::PrimaryWeapon) < 0.0001) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); int currentAmmoInt = (int)((double)currentItem["Ammo"]); currentItem["Ammo"] = (double)(currentAmmoInt - 1); - currentItem["CoolDownTimer"] = (double)2; + currentItem["CoolDownTimer"] = 2.0;//change later! } - if (fabs((double)player["EquippedItem"] - (double)2) < (double) 0.0001f) { + if (fabs((double)player["EquippedItem"] - (double)HeldItem::SecondaryWeapon) < 0.0001) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); int currentAmmoInt = (int)((double)currentItem["Ammo"]); currentItem["Ammo"] = (double)(currentAmmoInt - 1); - currentItem["CoolDownTimer"] = (double)2; + currentItem["CoolDownTimer"] = 2.0;//change later! } //create and publish the shoot event Events::Shoot eShoot; eShoot.currentAimingPoint = aimingCoordinates; - eShoot.weaponType = (int)player["EquippedItem"]; + eShoot.currentlyEquippedItem = (int) ((double)player["EquippedItem"]); m_EventBroker->Publish(eShoot); } } diff --git a/src/Tests/ShootEventTest.cpp b/src/Tests/ShootEventTest.cpp index 22c2a0eb..67a9985e 100644 --- a/src/Tests/ShootEventTest.cpp +++ b/src/Tests/ShootEventTest.cpp @@ -148,47 +148,47 @@ ShootEventTest::~ShootEventTest() void ShootEventTest::TestSetup1(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) { //set currentweap - player["EquippedItem"] = (double)1.0f; + player["EquippedItem"] = 1.0; //set ammo set cooldown - pItem["Ammo"] = (double)100.0f; - pItem["CoolDownTimer"] = (double)0.0f; + pItem["Ammo"] = 100.0; + pItem["CoolDownTimer"] = 0.0; } void ShootEventTest::TestSetup2(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) { //set currentweap - player["EquippedItem"] = (double)2.0f; + player["EquippedItem"] = 2.0; //set ammo set cooldown - sItem["Ammo"] = (double)10.0f; - sItem["CoolDownTimer"] = (double)0.0f; + sItem["Ammo"] = 10.0; + sItem["CoolDownTimer"] = 0.0; } void ShootEventTest::TestSetup3(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) { - player["EquippedItem"] = (double)0.0f; - pItem["Ammo"] = (double)100.0f; - sItem["Ammo"] = (double)100.0f; + player["EquippedItem"] = 0.0; + pItem["Ammo"] = 100.0; + sItem["Ammo"] = 100.0; //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; + player["EquippedItem"] = 1.0; //set ammo set cooldown - pItem["Ammo"] = (double)100.0f; - pItem["CoolDownTimer"] = (double)5.0f; + pItem["Ammo"] = 100.0; + pItem["CoolDownTimer"] = 5.0; //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) + if (currentAmmo == 99.0) 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) + if (currentAmmo == 9.0) TestSucceeded = true; } void ShootEventTest::TestSuccess3() { @@ -201,7 +201,7 @@ void ShootEventTest::TestSuccess3() { //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) + if (currentAmmo != 100.0 || currentAmmoSecondary != 100.0) TestSucceeded = false; } void ShootEventTest::TestSuccess4() { @@ -213,7 +213,7 @@ void ShootEventTest::TestSuccess4() { 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) + if (currentAmmo != 100.0) TestSucceeded = false; } void ShootEventTest::Tick()