From e57f281ac4b88aa1b148ce1f13f0adc8515331e1 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 8 Jul 2024 07:24:02 -0500 Subject: [PATCH] Add tests for CDR checking. Move Game State initialize change to Main Menu into the actual initialization function instead of hiding inside the Game State's Initialize function. 78/78 tests passing. --- Adventures in Lestoria Tests/PlayerTests.cpp | 25 ++++++++++++- .../AdventuresInLestoria.cpp | 35 ++++++++++--------- Adventures in Lestoria/GameState.cpp | 2 -- Adventures in Lestoria/Minimap.cpp | 1 + Adventures in Lestoria/Player.cpp | 20 ++++++----- Adventures in Lestoria/Version.h | 2 +- 6 files changed, 56 insertions(+), 29 deletions(-) diff --git a/Adventures in Lestoria Tests/PlayerTests.cpp b/Adventures in Lestoria Tests/PlayerTests.cpp index 52fa5529..94da90fd 100644 --- a/Adventures in Lestoria Tests/PlayerTests.cpp +++ b/Adventures in Lestoria Tests/PlayerTests.cpp @@ -74,6 +74,9 @@ namespace PlayerTests Menu::InitializeMenus(); Tutorial::Initialize(); Stats::InitializeDamageReductionTable(); + + GameState::Initialize(); + GameState::STATE=GameState::states.at(States::State::GAME_RUN); #pragma region Setup a fake test map and test monster game->MAP_DATA["CAMPAIGN_1_1"]; @@ -90,7 +93,9 @@ namespace PlayerTests Menu::themes.SetInitialized(); GFX.SetInitialized(); } - + TEST_METHOD_CLEANUP(CleanupTests){ + testGame->EndGame(); + } TEST_METHOD(PlayerAlive){ Assert::IsTrue(player->IsAlive()); } @@ -416,5 +421,23 @@ namespace PlayerTests Inventory::EquipItem(setArmor,EquipSlot::ARMOR); Assert::AreEqual(2.f,player->GetMoveSpdMult(),L"100% Move Spd should double the move speed from 100% to 200%"); } + TEST_METHOD(CDRStatEquipCheck){ + std::weak_ptrsetArmor{Inventory::AddItem("Test Armor2"s)}; + + Assert::AreEqual(0.f,player->GetCooldownReductionPct(),L"CDR is 0%"); + + Inventory::EquipItem(setArmor,EquipSlot::ARMOR); + Assert::AreEqual(1.f,player->GetCooldownReductionPct(),L"Player should have 100% CDR"); + testKey->bHeld=true; //Force the key to be held down for testing purposes. + player->CheckAndPerformAbility(player->GetAbility1(),testKeyboardInput); + player->CheckAndPerformAbility(player->GetAbility2(),testKeyboardInput); + player->CheckAndPerformAbility(player->GetAbility3(),testKeyboardInput); + player->CheckAndPerformAbility(player->GetAbility4(),testKeyboardInput); + game->OnUserUpdate(0.01f); //Let 0.01 seconds go by. All abilities should be off cooldown. + Assert::AreEqual(0.f,player->GetAbility1().cooldown,L"Using an ability with 100% CDR should result in a 0 second cooldown."); + Assert::AreEqual(0.f,player->GetAbility2().cooldown,L"Using an ability with 100% CDR should result in a 0 second cooldown."); + Assert::AreEqual(0.f,player->GetAbility3().cooldown,L"Using an ability with 100% CDR should result in a 0 second cooldown."); + Assert::AreEqual(0.f,player->GetAbility4().cooldown,L"Using an ability with 100% CDR should result in a 0 second cooldown."); + } }; } diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index f4082515..60152d1a 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -304,6 +304,7 @@ bool AiL::OnUserCreate(){ ChangePlayerClass(WARRIOR); GameState::Initialize(); + GameState::ChangeState(States::MAIN_MENU); Unlock::Initialize(); ItemDrop::Initialize(); @@ -376,23 +377,24 @@ bool AiL::OnUserUpdate(float fElapsedTime){ InputListener::Update(); Tutorial::Update(); Audio::Update(); - GameState::STATE->Draw(this); - RenderMenu(); - GameState::STATE->DrawOverlay(this); - RenderFadeout(); - LoadingScreen::Draw(); - RenderVersionInfo(); - #ifndef __EMSCRIPTEN__ - if(Discord){ - auto result=Discord->RunCallbacks(); - if(result!=::discord::Result::Ok){ - LOG("Discord Error Code "<TestingModeEnabled()){ + GameState::STATE->Draw(this); + RenderMenu(); + GameState::STATE->DrawOverlay(this); + RenderFadeout(); + LoadingScreen::Draw(); + RenderVersionInfo(); + #ifndef __EMSCRIPTEN__ + if(Discord){ + auto result=Discord->RunCallbacks(); + if(result!=::discord::Result::Ok){ + LOG("Discord Error Code "<TestingModeEnabled())return; loadedChunks[map].insert(std::format("{}_{}",chunkPos.x,chunkPos.y)); if(game->GetCurrentMapName()!=map)return; //Don't update the minimap when the map name doesn't match the current map. diff --git a/Adventures in Lestoria/Player.cpp b/Adventures in Lestoria/Player.cpp index 68af0f7b..bb0e136d 100644 --- a/Adventures in Lestoria/Player.cpp +++ b/Adventures in Lestoria/Player.cpp @@ -875,16 +875,20 @@ void Player::Moved(MoveFlag::MoveFlag flags){ } } const std::map>&zoneData=game->GetZones(game->GetCurrentLevel()); - for(const ZoneData&upperLevelZone:zoneData.at("UpperZone")){ - if(geom2d::overlaps(upperLevelZone.zone,pos)){ - upperLevel=true; + if(zoneData.count("UpperZone")){ + for(const ZoneData&upperLevelZone:zoneData.at("UpperZone")){ + if(geom2d::overlaps(upperLevelZone.zone,pos)){ + upperLevel=true; + } } - } - for(const ZoneData&lowerLevelZone:zoneData.at("LowerZone")){ - if(geom2d::overlaps(lowerLevelZone.zone,pos)){ - upperLevel=false; + }else if(!game->TestingModeEnabled())ERR(std::format("WARNING! Map {} is missing Upper Zones! THIS SHOULD NOT BE HAPPENING!",game->GetCurrentMapDisplayName())); + if(zoneData.count("LowerZone")){ + for(const ZoneData&lowerLevelZone:zoneData.at("LowerZone")){ + if(geom2d::overlaps(lowerLevelZone.zone,pos)){ + upperLevel=false; + } } - } + }else if(!game->TestingModeEnabled())ERR(std::format("WARNING! Map {} is missing Lower Zones! THIS SHOULD NOT BE HAPPENING!",game->GetCurrentMapDisplayName())); EnvironmentalAudio::UpdateEnvironmentalAudio(); if(!std::isfinite(pos.x)){ diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 48b86885..07169f43 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 1 #define VERSION_MINOR 2 #define VERSION_PATCH 3 -#define VERSION_BUILD 9928 +#define VERSION_BUILD 9937 #define stringify(a) stringify_(a) #define stringify_(a) #a