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.
371 lines
16 KiB
371 lines
16 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 "config.h"
|
|
#include "ItemDrop.h"
|
|
#include "Tutorial.h"
|
|
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
using namespace olc::utils;
|
|
|
|
INCLUDE_MONSTER_DATA
|
|
INCLUDE_game
|
|
|
|
TEST_MODULE_INITIALIZE(AiLTestSuite)
|
|
{
|
|
debugLogger.open("debug.log");
|
|
}
|
|
|
|
namespace MonsterTests
|
|
{
|
|
TEST_CLASS(MonsterTest)
|
|
{
|
|
public:
|
|
std::unique_ptr<AiL>testGame;
|
|
#pragma region Setup Functions
|
|
//Makes MONSTER_DATA["TestName"] available.
|
|
void SetupTestMonster(){
|
|
testGame.reset(new AiL());
|
|
testGame->olc_SetTestingMode(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();
|
|
MonsterData testMonsterData{"TestName","Test Monster",30,10,5,{MonsterDropData{"Health Potion",100.f,1,1}},200.f};
|
|
MONSTER_DATA["TestName"]=testMonsterData;
|
|
}
|
|
void SetupMockMap(){
|
|
game->MAP_DATA["CAMPAIGN_1_1"];
|
|
ItemDrop::drops.clear();
|
|
}
|
|
#pragma endregion
|
|
|
|
TEST_METHOD_INITIALIZE(MonsterInitialize){
|
|
SetupTestMonster();
|
|
SetupMockMap();
|
|
}
|
|
~MonsterTest(){
|
|
testGame.release();
|
|
}
|
|
TEST_METHOD(DisplayNameCheck){
|
|
Assert::AreEqual("Test Monster",MONSTER_DATA["TestName"].GetDisplayName().c_str());
|
|
}
|
|
TEST_METHOD(InternalNameCheck){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
Assert::AreEqual("TestName",testMonster.GetName().c_str());
|
|
}
|
|
TEST_METHOD(HealthCheck){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
Assert::AreEqual(testMonster.GetHealth(),testMonster.GetMaxHealth());
|
|
Assert::AreEqual(testMonster.GetHealth(),30);
|
|
}
|
|
TEST_METHOD(Deal5Damage)
|
|
{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.Hurt(5,testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
Assert::AreEqual(testMonster.GetHealth(),testMonster.GetMaxHealth()-5);
|
|
}
|
|
TEST_METHOD(IFrameShouldResultInNoDamage){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.ApplyIframes(0.5f);
|
|
testMonster.Hurt(5,testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
Assert::AreEqual(testMonster.GetHealth(),testMonster.GetMaxHealth());
|
|
}
|
|
TEST_METHOD(BeingInTheAirShouldAvoidAttacksFromTheGround){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.SetZ(2.f);
|
|
testMonster.Hurt(5,testMonster.OnUpperLevel(),0.f);
|
|
Assert::AreEqual(testMonster.GetHealth(),testMonster.GetMaxHealth());
|
|
}
|
|
TEST_METHOD(MonstersDeal10Damage_NoDamageReduction)
|
|
{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
Monster testMonster2{{},MONSTER_DATA["TestName"]};
|
|
game->GetPlayer()->Hurt(testMonster.GetAttack(),testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
testMonster2.Hurt(testMonster.GetAttack(),testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
Assert::AreEqual(game->GetPlayer()->GetMaxHealth()-10,game->GetPlayer()->GetHealth());
|
|
Assert::AreEqual(testMonster2.GetMaxHealth()-10,testMonster2.GetHealth());
|
|
}
|
|
TEST_METHOD(DoubleAttackPctModifierWorks){
|
|
Monster buffMonster{{},MONSTER_DATA["TestName"]};
|
|
buffMonster.AddBuff(BuffType::STAT_UP,5,100._Pct,{ItemAttribute::Get("Attack %")});
|
|
|
|
Monster testMonster2{{},MONSTER_DATA["TestName"]};
|
|
game->GetPlayer()->Hurt(buffMonster.GetAttack(),buffMonster.OnUpperLevel(),buffMonster.GetZ());
|
|
testMonster2.Hurt(buffMonster.GetAttack(),buffMonster.OnUpperLevel(),buffMonster.GetZ());
|
|
Assert::AreEqual(game->GetPlayer()->GetMaxHealth()-20,game->GetPlayer()->GetHealth());
|
|
Assert::AreEqual(testMonster2.GetMaxHealth()-20,testMonster2.GetHealth());
|
|
}
|
|
TEST_METHOD(AttackUpModifierWorks){
|
|
Monster buffMonster{{},MONSTER_DATA["TestName"]};
|
|
buffMonster.AddBuff(BuffType::STAT_UP,5,5.f,{"Attack"});
|
|
|
|
Monster testMonster2{{},MONSTER_DATA["TestName"]};
|
|
game->GetPlayer()->Hurt(buffMonster.GetAttack(),buffMonster.OnUpperLevel(),buffMonster.GetZ());
|
|
testMonster2.Hurt(buffMonster.GetAttack(),buffMonster.OnUpperLevel(),buffMonster.GetZ());
|
|
Assert::AreEqual(game->GetPlayer()->GetMaxHealth()-15,game->GetPlayer()->GetHealth(),L"Player Health is now 85.");
|
|
Assert::AreEqual(testMonster2.GetMaxHealth()-15,testMonster2.GetHealth(),L"Monster Health is now 15.");
|
|
}
|
|
TEST_METHOD(HealthUpModifierWorks){
|
|
Monster buffMonster{{},MONSTER_DATA["TestName"]};
|
|
buffMonster.AddBuff(BuffType::STAT_UP,5,5.f,{"Health"});
|
|
|
|
Assert::AreEqual(35,buffMonster.GetMaxHealth(),L"Monster Max Health is now 35.");
|
|
Assert::AreEqual(30,buffMonster.GetHealth(),L"Monster Current Health is still 30.");
|
|
}
|
|
TEST_METHOD(AttackUpPctModifierWorks){
|
|
Monster buffMonster{{},MONSTER_DATA["TestName"]};
|
|
buffMonster.AddBuff(BuffType::STAT_UP,5,100.0_Pct,{"Attack %"});
|
|
|
|
Monster testMonster2{{},MONSTER_DATA["TestName"]};
|
|
game->GetPlayer()->Hurt(buffMonster.GetAttack(),buffMonster.OnUpperLevel(),buffMonster.GetZ());
|
|
testMonster2.Hurt(buffMonster.GetAttack(),buffMonster.OnUpperLevel(),buffMonster.GetZ());
|
|
Assert::AreEqual(game->GetPlayer()->GetMaxHealth()-20,game->GetPlayer()->GetHealth(),L"Player Health is now 80.");
|
|
Assert::AreEqual(testMonster2.GetMaxHealth()-20,testMonster2.GetHealth(),L"Monster Health is now 10.");
|
|
}
|
|
TEST_METHOD(MonsterIsConsideredDeadAt0Health){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.Hurt(testMonster.GetMaxHealth(),testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
Assert::AreEqual(true,testMonster.IsDead());
|
|
}
|
|
TEST_METHOD(ItemDropSpawnsWhenMonsterIsKilled){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.Hurt(testMonster.GetMaxHealth(),testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
Assert::AreEqual(size_t(1),ItemDrop::GetDrops().size());
|
|
}
|
|
TEST_METHOD(MoveSpdSetCorrectly){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
Assert::AreEqual(2.f,testMonster.GetMoveSpdMult());
|
|
}
|
|
TEST_METHOD(SlowdownBuffTest){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::SLOWDOWN,5.f,0.5f);
|
|
Assert::AreEqual(1.f,testMonster.GetMoveSpdMult());
|
|
}
|
|
TEST_METHOD(SelfInflictedSlowdownTest){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::SELF_INFLICTED_SLOWDOWN,5.f,0.5f);
|
|
Assert::AreEqual(1.f,testMonster.GetMoveSpdMult());
|
|
}
|
|
TEST_METHOD(SpeedBoostTest){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::SPEEDBOOST,5.f,0.5f);
|
|
Assert::AreEqual(3.f,testMonster.GetMoveSpdMult());
|
|
}
|
|
TEST_METHOD(LockOnSpeedBoostTest){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::LOCKON_SPEEDBOOST,5.f,0.5f);
|
|
Assert::AreEqual(3.f,testMonster.GetMoveSpdMult());
|
|
}
|
|
TEST_METHOD(AdditiveMoveSpdBuffsTest){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::SLOWDOWN,5.f,0.5f);
|
|
testMonster.AddBuff(BuffType::SPEEDBOOST,5.f,0.75f);
|
|
Assert::AreEqual(2.5f,testMonster.GetMoveSpdMult());
|
|
}
|
|
TEST_METHOD(DamageReductionBuffTest){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::DAMAGE_REDUCTION,5.f,0.25f);
|
|
|
|
testMonster.Hurt(testMonster.GetAttack(),testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
//25% damage reduction should result in 7.5 health taken, When ceiling'd results in 8 health taken.
|
|
Assert::AreEqual(22,testMonster.GetHealth());
|
|
}
|
|
TEST_METHOD(BarrierBuffTest){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::BARRIER_DAMAGE_REDUCTION,5.f,0.5f);
|
|
|
|
testMonster.Hurt(testMonster.GetAttack(),testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
//50% damage reduction should result in 5 health taken
|
|
Assert::AreEqual(25,testMonster.GetHealth());
|
|
}
|
|
TEST_METHOD(AdditiveDamageReductionTest){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::DAMAGE_REDUCTION,5.f,0.25f);
|
|
testMonster.AddBuff(BuffType::BARRIER_DAMAGE_REDUCTION,5.f,0.5f);
|
|
|
|
testMonster.Hurt(testMonster.GetAttack(),testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
//25+50% damage reduction should result in 2.5 health taken. When ceiling'd, results in 3 health taken.
|
|
Assert::AreEqual(27,testMonster.GetHealth());
|
|
}
|
|
TEST_METHOD(MaximumDamageReductionTest){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::DAMAGE_REDUCTION,5.f,INFINITY);
|
|
|
|
testMonster.Hurt(testMonster.GetAttack(),testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
//At 100% or more damage reduction, the monster should take 0 damage.
|
|
Assert::AreEqual(30,testMonster.GetHealth());
|
|
}
|
|
TEST_METHOD(TrueDamageTest){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
|
|
testMonster._DealTrueDamage(testMonster.GetAttack()*3);
|
|
Assert::AreEqual(0,testMonster.GetHealth());
|
|
}
|
|
TEST_METHOD(TrueDamageTestWith100PctDamageReduction){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::DAMAGE_REDUCTION,5.f,INFINITY);
|
|
|
|
testMonster._DealTrueDamage(testMonster.GetAttack()*3);
|
|
//Damage reduction should not affect true damage at all.
|
|
Assert::AreEqual(0,testMonster.GetHealth());
|
|
}
|
|
TEST_METHOD(CriticalRateTest){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
|
|
game->GetPlayer()->SetBaseStat(ItemAttribute::Get("Crit Rate"),100.f);
|
|
|
|
testMonster.Hurt(5,testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
//If crit rate works 100% of the time, getting hurt should deal crit dmg % more damage (which defaults to 50%). Ceiling 7.5 damage to 8.
|
|
Assert::AreEqual(22,testMonster.GetHealth());
|
|
}
|
|
TEST_METHOD(CriticalDamageTest){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
|
|
game->GetPlayer()->SetBaseStat(ItemAttribute::Get("Crit Rate"),100.f);
|
|
game->GetPlayer()->SetBaseStat(ItemAttribute::Get("Crit Dmg"),150.f);
|
|
|
|
testMonster.Hurt(5,testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
//If crit rate works 100% of the time, getting hurt will deal 150% more damage. Ceiling 12.5 damage to 13.
|
|
Assert::AreEqual(17,testMonster.GetHealth());
|
|
}
|
|
TEST_METHOD(ShouldNotDieNormallyTest){
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.diesNormally=false;
|
|
|
|
testMonster.Hurt(1000,testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
testMonster.Hurt(1000,testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
testMonster.Hurt(1000,testMonster.OnUpperLevel(),testMonster.GetZ());
|
|
//Health should continue to remain at 1 and the monster should remain alive if the dies normally flag is false.
|
|
Assert::AreEqual(1,testMonster.GetHealth());
|
|
Assert::IsTrue(testMonster.IsAlive());
|
|
}
|
|
TEST_METHOD(IllegalDefenseStatUpBuffCheck){
|
|
try{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::STAT_UP,5.f,5.f,{"Defense"});
|
|
Assert::Fail(L"Adding a Defense buff succeeded! This should NOT be allowed!");
|
|
}catch(std::exception&e){}
|
|
}
|
|
TEST_METHOD(IllegalMoveSpdStatUpBuffCheck){
|
|
try{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::STAT_UP,5.f,5.f,{"Move Spd %"});
|
|
Assert::Fail(L"Adding a Move Spd % buff succeeded! This should NOT be allowed!");
|
|
}catch(std::exception&e){}
|
|
}
|
|
TEST_METHOD(IllegalDefensePctStatUpBuffCheck){
|
|
try{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::STAT_UP,5.f,5.f,{"Defense %"});
|
|
Assert::Fail(L"Adding a Defense % buff succeeded! This should NOT be allowed!");
|
|
}catch(std::exception&e){}
|
|
}
|
|
TEST_METHOD(IllegalCDRStatUpBuffCheck){
|
|
try{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::STAT_UP,5.f,5.f,{"CDR"});
|
|
Assert::Fail(L"Adding a CDR buff succeeded! This should NOT be allowed!");
|
|
}catch(std::exception&e){}
|
|
}
|
|
TEST_METHOD(IllegalCritRateStatUpBuffCheck){
|
|
try{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::STAT_UP,5.f,5.f,{"Crit Rate"});
|
|
Assert::Fail(L"Adding a Crit Rate buff succeeded! This should NOT be allowed!");
|
|
}catch(std::exception&e){}
|
|
}
|
|
TEST_METHOD(IllegalCritDmgStatUpBuffCheck){
|
|
try{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::STAT_UP,5.f,5.f,{"Crit Damage"});
|
|
Assert::Fail(L"Adding a Crit Damage buff succeeded! This should NOT be allowed!");
|
|
}catch(std::exception&e){}
|
|
}
|
|
TEST_METHOD(IllegalHPRecoveryPctStatUpBuffCheck){
|
|
try{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::STAT_UP,5.f,5.f,{"HP Recovery %"});
|
|
Assert::Fail(L"Adding a HP Recovery % buff succeeded! This should NOT be allowed!");
|
|
}catch(std::exception&e){}
|
|
}
|
|
TEST_METHOD(IllegalHP6RecoveryPctStatUpBuffCheck){
|
|
try{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::STAT_UP,5.f,5.f,{"HP6 Recovery %"});
|
|
Assert::Fail(L"Adding a HP6 Recovery % buff succeeded! This should NOT be allowed!");
|
|
}catch(std::exception&e){}
|
|
}
|
|
TEST_METHOD(IllegalHP4RecoveryPctStatUpBuffCheck){
|
|
try{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::STAT_UP,5.f,5.f,{"HP4 Recovery %"});
|
|
Assert::Fail(L"Adding a HP4 Recovery % buff succeeded! This should NOT be allowed!");
|
|
}catch(std::exception&e){}
|
|
}
|
|
TEST_METHOD(IllegalDamageReductionStatUpBuffCheck){
|
|
try{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::STAT_UP,5.f,5.f,{"Damage Reduction"});
|
|
Assert::Fail(L"Adding a Damage Reduction buff succeeded! This should NOT be allowed!");
|
|
}catch(std::exception&e){}
|
|
}
|
|
TEST_METHOD(IllegalAttackSpdStatUpBuffCheck){
|
|
try{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::STAT_UP,5.f,5.f,{"Attack Spd"});
|
|
Assert::Fail(L"Adding a Attack Spd buff succeeded! This should NOT be allowed!");
|
|
}catch(std::exception&e){};
|
|
}
|
|
TEST_METHOD(IllegalManaStatUpBuffCheck){
|
|
try{
|
|
Monster testMonster{{},MONSTER_DATA["TestName"]};
|
|
testMonster.AddBuff(BuffType::STAT_UP,5.f,5.f,{"Mana"});
|
|
Assert::Fail(L"Adding a Mana buff succeeded! This should NOT be allowed!");
|
|
}catch(std::exception&e){}
|
|
}
|
|
};
|
|
} |