The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'! https://forums.lestoria.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
AdventuresInLestoria/Adventures in Lestoria Tests/EnchantTests.cpp

295 lines
15 KiB

#pragma region License
/*
License (OLC-3)
~~~~~~~~~~~~~~~
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions or derivations of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions or derivative works in binary form must reproduce the above
copyright notice. This list of conditions and the following disclaimer must be
reproduced in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2024 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#include "CppUnitTest.h"
#include "AdventuresInLestoria.h"
#include "Tutorial.h"
#include <random>
#include <format>
#include "ItemDrop.h"
#include "DamageNumber.h"
#include <ranges>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace olc::utils;
INCLUDE_GFX
INCLUDE_ITEM_DATA
INCLUDE_DAMAGENUMBER_LIST
INCLUDE_INITIALIZEGAMECONFIGURATIONS
extern std::mt19937 rng;
namespace Test
{
template<class T>
inline static void InRange(T initialVal,std::pair<T,T>range,std::wstring_view assertMessage){
Assert::IsTrue(initialVal>=range.first&&initialVal<=range.second,std::format(L"Expected: {}~{} Actual: {} - {}",range.first,range.second,initialVal,assertMessage).c_str());
}
}
namespace EnchantTests
{
TEST_CLASS(EnchantTest)
{
public:
std::unique_ptr<AiL>testGame;
InputGroup testKeyboardInput;
Player*player;
const HWButton*testKey;
TEST_METHOD_INITIALIZE(PlayerInitialize){
InitializeGameConfigurations();
rng=std::mt19937{57189U};//Establish a fixed random seed on setup so the exact same results are generated every test run.
testGame.reset(new AiL(true));
ItemAttribute::Initialize();
ItemInfo::InitializeItems();
testGame->InitializeGraphics();
testGame->InitializeClasses();
sig::Animation::InitializeAnimations();
testGame->InitializeDefaultKeybinds();
testGame->InitializePlayer();
sig::Animation::SetupPlayerAnimations();
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"];
ItemDrop::ClearDrops();
MonsterData testMonsterData{"TestName","Test Monster",1000,10,5,{MonsterDropData{"Health Potion",100.f,1,1}},200.f};
MONSTER_DATA["TestName"]=testMonsterData;
#pragma endregion
player=testGame->GetPlayer();
//Setup key "0" as a test input
testKeyboardInput.AddKeybind(Input{InputType::KEY,0});
testKey=testGame->GetKeyboardState(0);
testGame->olc_UpdateKeyFocus(true); //Force the game to be "focused" for tests. Required if we want keyboard inputs to work.
Menu::themes.SetInitialized();
GFX.SetInitialized();
DAMAGENUMBER_LIST.clear();
}
TEST_METHOD(HealthBoostCheck){
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Assert::AreEqual(100,player->GetMaxHealth(),L"Player starts with 100 health.");
Inventory::EquipItem(nullRing,EquipSlot::RING1);
for(int i:std::ranges::iota_view(0,1000)){
nullRing.lock()->EnchantItem("Health Boost");
Test::InRange(player->GetMaxHealth(),{103,105},L"Max Health not in expected range.");
}
}
TEST_METHOD(AttackBoostCheck){
player->SetBaseStat("Attack",100.f);
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Assert::AreEqual(100,player->GetAttack(),L"Player starts with 100 attack.");
Inventory::EquipItem(nullRing,EquipSlot::RING1);
for(int i:std::ranges::iota_view(0,1000)){
nullRing.lock()->EnchantItem("Attack Boost");
Test::InRange(player->GetAttack(),{103,105},L"Attack not in expected range.");
}
}
TEST_METHOD(MovementBoostCheck){
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Assert::AreEqual(100.0_Pct,player->GetMoveSpdMult(),L"Player starts with 100% Movespd.");
Inventory::EquipItem(nullRing,EquipSlot::RING1);
for(int i:std::ranges::iota_view(0,1000)){
nullRing.lock()->EnchantItem("Movement Boost");
Test::InRange(player->GetMoveSpdMult(),{103.0_Pct,105.0_Pct},L"Move Speed not in expected range.");
}
}
TEST_METHOD(AbilityHasteCheck){
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Assert::AreEqual(0.0_Pct,player->GetCooldownReductionPct(),L"Player starts with 0% CDR.");
Inventory::EquipItem(nullRing,EquipSlot::RING1);
for(int i:std::ranges::iota_view(0,1000)){
nullRing.lock()->EnchantItem("Ability Haste");
Test::InRange(player->GetCooldownReductionPct(),{3.0_Pct,5.0_Pct},L"CDR not in expected range.");
}
}
TEST_METHOD(CritRateCheck){
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Assert::AreEqual(0.0_Pct,player->GetCritRatePct(),L"Player starts with 0% Crit Rate.");
Inventory::EquipItem(nullRing,EquipSlot::RING1);
for(int i:std::ranges::iota_view(0,1000)){
nullRing.lock()->EnchantItem("Crit Rate");
Test::InRange(player->GetCritRatePct(),{3.0_Pct,5.0_Pct},L"Crit Rate not in expected range.");
}
}
TEST_METHOD(CritDamageCheck){
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Assert::AreEqual(50.0_Pct,player->GetCritDmgPct(),L"Player starts with 50% Crit Damage.");
Inventory::EquipItem(nullRing,EquipSlot::RING1);
for(int i:std::ranges::iota_view(0,1000)){
nullRing.lock()->EnchantItem("Crit Damage");
Test::InRange(player->GetCritDmgPct(),{57.0_Pct,60.0_Pct},L"Crit Damage not in expected range.");
}
}
TEST_METHOD(StoneskinCheck){
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Assert::AreEqual(0.0_Pct,player->GetDamageReductionPct(),L"Player starts with 0% Damage Reduction.");
Inventory::EquipItem(nullRing,EquipSlot::RING1);
for(int i:std::ranges::iota_view(0,1000)){
nullRing.lock()->EnchantItem("Stoneskin");
Test::InRange(player->GetDamageReductionPct(),{3.0_Pct,5.0_Pct},L"Damage Reduction not in expected range.");
}
}
TEST_METHOD(ManaPoolCheck){
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Assert::AreEqual(100,player->GetMaxMana(),L"Player starts with 100 mana.");
Inventory::EquipItem(nullRing,EquipSlot::RING1);
for(int i:std::ranges::iota_view(0,1000)){
nullRing.lock()->EnchantItem("Mana Pool");
Test::InRange(player->GetMaxMana(),{107,112},L"Mana Pool not in expected range.");
}
}
TEST_METHOD(MagicalProtectionCheck){
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Assert::AreEqual(100,player->GetMaxHealth(),L"Player starts with 100 health.");
Assert::AreEqual(0.0_Pct,player->GetDamageReductionPct(),L"Player starts with 0% damage reduction.");
Assert::AreEqual(100.0_Pct,player->GetMoveSpdMult(),L"Player starts with 100% move speed.");
Assert::AreEqual(0.0_Pct,player->GetHP6RecoveryPct(),L"Player starts with 0% HP/6 recovery.");
Inventory::EquipItem(nullRing,EquipSlot::RING1);
for(int i:std::ranges::iota_view(0,1000)){
nullRing.lock()->EnchantItem("Magical Protection");
Test::InRange(player->GetMaxHealth(),{102,103},L"Max Health not in expected range.");
Test::InRange(player->GetDamageReductionPct(),{2.0_Pct,3.0_Pct},L"Damage Reduction not in expected range.");
Test::InRange(player->GetMoveSpdMult(),{102.0_Pct,103.0_Pct},L"Move Speed % not in expected range.");
Test::InRange(player->GetHP6RecoveryPct(),{1.0_Pct,1.0_Pct},L"HP/6 Recovery not in expected range.");
}
}
TEST_METHOD(AuraOfTheBeastCheck){
player->SetBaseStat("Attack",100.f);
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Assert::AreEqual(100,player->GetAttack(),L"Player starts with 100 attack.");
Assert::AreEqual(0.0_Pct,player->GetCritRatePct(),L"Player starts with 0% crit rate.");
Assert::AreEqual(0.0_Pct,player->GetCooldownReductionPct(),L"Player starts with 0% cooldown reduction.");
Assert::AreEqual(50.0_Pct,player->GetCritDmgPct(),L"Player starts with 50% crit rate.");
Inventory::EquipItem(nullRing,EquipSlot::RING1);
for(int i:std::ranges::iota_view(0,1000)){
nullRing.lock()->EnchantItem("Aura of the Beast");
Test::InRange(player->GetAttack(),{102,103},L"Attack not in expected range.");
Test::InRange(player->GetCritRatePct(),{2.0_Pct,3.0_Pct},L"Crit Rate not in expected range.");
Test::InRange(player->GetCooldownReductionPct(),{2.0_Pct,3.0_Pct},L"Cooldown Reduction % not in expected range.");
Test::InRange(player->GetCritDmgPct(),{53.0_Pct,57.0_Pct},L"Crit Damage not in expected range.");
}
}
TEST_METHOD(LethalTempoCheck){
MonsterData testMonsterData{"TestName","Test Monster",30,10,5,{MonsterDropData{"Health Potion",100.f,1,1}},200.f};
MONSTER_DATA["TestName"]=testMonsterData;
Monster testMonster{{},MONSTER_DATA["TestName"]};
testMonster.Hurt(0,testMonster.OnUpperLevel(),testMonster.GetZ());
Assert::AreEqual(size_t(0),player->GetBuffs(BuffType::LETHAL_TEMPO).size(),L"Lethal Tempo does not stack up without the enchant.");
testMonster.Hurt(0,testMonster.OnUpperLevel(),testMonster.GetZ(),HurtFlag::PLAYER_ABILITY);
Assert::AreEqual(size_t(0),player->GetBuffs(BuffType::LETHAL_TEMPO).size(),L"Lethal Tempo does not stack up without the enchant.");
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Inventory::EquipItem(nullRing,EquipSlot::RING1);
nullRing.lock()->EnchantItem("Lethal Tempo");
testMonster.Hurt(0,testMonster.OnUpperLevel(),testMonster.GetZ(),HurtFlag::PLAYER_ABILITY);
Assert::AreEqual(size_t(1),player->GetBuffs(BuffType::LETHAL_TEMPO).size(),L"Lethal Tempo buff is active after attacking with the enchant..");
Assert::AreEqual(0.0175f,player->GetAttackRecoveryRateReduction(),L"Lethal Tempo buff reduced attack Recovery Rate by 0.0175 (5% of 0.35).");
for(int i:std::ranges::iota_view(0,10)){
testMonster.Hurt(0,testMonster.OnUpperLevel(),testMonster.GetZ(),HurtFlag::PLAYER_ABILITY);
}
Assert::AreEqual(0.0875f,player->GetAttackRecoveryRateReduction(),L"Lethal Tempo buff should cap at 5 stacks.");
Assert::AreEqual(size_t(1),player->GetBuffs(BuffType::LETHAL_TEMPO).size(),L"Lethal Tempo buff is active.");
}
TEST_METHOD(SecondWindCheck){
Assert::AreEqual(0.0_Pct,player->GetHPRecoveryPct(),L"HP Recovery Pct is 0% at the start.");
player->Hurt(90,player->OnUpperLevel(),player->GetZ());
Assert::AreEqual(0.0_Pct,player->GetHPRecoveryPct(),L"HP Recovery Pct is still 0% without Second Wind.");
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Inventory::EquipItem(nullRing,EquipSlot::RING1);
nullRing.lock()->EnchantItem("Second Wind");
Assert::AreEqual(1.0_Pct,player->GetHPRecoveryPct(),L"HP Recovery Pct is now 1% with low health with Second Wind.");
player->Heal(11);
Assert::AreEqual(0.0_Pct,player->GetHPRecoveryPct(),L"HP Recovery Pct is now 0% since Second Wind should no longer activate above 20% health.");
}
TEST_METHOD(EmergencyRecoveryCheck){
Assert::AreEqual(0.0_Pct,player->GetHP6RecoveryPct(),0.1_Pct,L"HP Recovery/6 Pct is 0% at the start.");
Assert::AreEqual(0.0_Pct,player->GetHP4RecoveryPct(),0.1_Pct,L"HP Recovery/4 Pct is 0% at the start.");
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Inventory::EquipItem(nullRing,EquipSlot::RING1);
nullRing.lock()->EnchantItem("Emergency Recovery");
Assert::AreEqual(1.0_Pct,player->GetHP6RecoveryPct(),0.1_Pct,L"HP Recovery/6 Pct is base 1% even with full HP.");
Assert::AreEqual(0.0_Pct,player->GetHP4RecoveryPct(),0.1_Pct,L"HP Recovery/4 Pct is still 0% since the player is not lower than 30% health.");
for(int i:std::ranges::iota_view(1,7)){
player->Hurt(10,player->OnUpperLevel(),player->GetZ());
Assert::AreEqual(1.0_Pct+0.5_Pct*i,player->GetHP6RecoveryPct(),0.1_Pct,L"HP Recovery/6 Pct is increasing by 0.5% per 10% missing health.");
}
player->Hurt(10,player->OnUpperLevel(),player->GetZ());
Assert::AreEqual(0.0_Pct,player->GetHP6RecoveryPct(),0.1_Pct,L"HP Recovery/6 Pct is now 0% as the HP Recovery/4 sec version should have activated.");
Assert::AreEqual(4.5_Pct,player->GetHP4RecoveryPct(),0.1_Pct,L"HP Recovery/4 Pct is now 4.5%");
for(int i:std::ranges::iota_view(1,3)){
player->Hurt(10,player->OnUpperLevel(),player->GetZ());
Assert::AreEqual(4.5_Pct+0.5_Pct*i,player->GetHP4RecoveryPct(),0.1_Pct,L"HP Recovery/4 Pct is increasing by 0.5% per 10% missing health.");
}
}
TEST_METHOD(DeathDefianceCheck){
for(int i:std::ranges::iota_view(0,10)){
player->Heal(100);
player->Hurt(1000,player->OnUpperLevel(),player->GetZ());
if(player->IsAlive()){Assert::Fail(L"Player survived while not having the Death Defiance Enchant! THIS SHOULD NOT BE HAPPENING!");}
player->_SetIframes(0.f);
}
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)};
Inventory::EquipItem(nullRing,EquipSlot::RING1);
nullRing.lock()->EnchantItem("Death Defiance");
player->Heal(100);
for(int i:std::ranges::iota_view(0,10)){
const int prevPlayerHP{player->GetHealth()};
player->Hurt(1,player->OnUpperLevel(),player->GetZ());
Assert::AreNotEqual(prevPlayerHP,player->GetHealth(),L"Death Defiance triggered even though the player did not take lethal damage!");
player->_SetIframes(0.f);
}
bool survivedAtLeastOnce{false};
for(int i:std::ranges::iota_view(0,10)){
player->Heal(100);
player->Hurt(1000,player->OnUpperLevel(),player->GetZ());
if(player->IsAlive()){
survivedAtLeastOnce=true;
break;
}
player->_SetIframes(0.f);
}
Assert::AreEqual(true,survivedAtLeastOnce,L"Player should have survived at least one time with Death Defiance.");
}
};
}