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.
262 lines
11 KiB
262 lines
11 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"
|
|
|
|
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->EnableTestingMode();
|
|
ItemAttribute::Initialize();
|
|
ItemInfo::InitializeItems();
|
|
testGame->InitializePlayer();
|
|
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,{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()-15,game->GetPlayer()->GetHealth());
|
|
Assert::AreEqual(testMonster2.GetMaxHealth()-15,testMonster2.GetHealth());
|
|
}
|
|
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());
|
|
}
|
|
};
|
|
} |