|
|
|
|
#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 <EFBFBD> 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"
|
|
|
|
|
|
|
|
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
|
|
|
using namespace olc::utils;
|
|
|
|
|
|
|
|
|
|
INCLUDE_GFX
|
|
|
|
|
|
|
|
|
|
namespace PlayerTests
|
|
|
|
|
{
|
|
|
|
|
TEST_CLASS(PlayerTest)
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
std::unique_ptr<AiL>testGame;
|
|
|
|
|
InputGroup testKeyboardInput;
|
|
|
|
|
Player*player;
|
|
|
|
|
HWButton*testKey;
|
|
|
|
|
TEST_METHOD_INITIALIZE(PlayerInitialize){
|
|
|
|
|
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();
|
|
|
|
|
player=testGame->GetPlayer();
|
|
|
|
|
//Setup key "0" as a test input
|
|
|
|
|
testKeyboardInput.AddKeybind(Input{InputType::KEY,0});
|
|
|
|
|
testKey=&testGame->pKeyboardState[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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(PlayerAlive){
|
|
|
|
|
Assert::IsTrue(player->IsAlive());
|
|
|
|
|
}
|
|
|
|
|
TEST_METHOD(PlayerTakesDamage){
|
|
|
|
|
player->Hurt(30,player->OnUpperLevel(),player->GetZ());
|
|
|
|
|
Assert::AreEqual(70,player->GetHealth());
|
|
|
|
|
}
|
|
|
|
|
TEST_METHOD(PlayerBlockingTakesNoDamage){
|
|
|
|
|
player->SetState(State::BLOCK);
|
|
|
|
|
player->Hurt(30,player->OnUpperLevel(),player->GetZ());
|
|
|
|
|
Assert::AreEqual(100,player->GetHealth());
|
|
|
|
|
}
|
|
|
|
|
TEST_METHOD(PlayerIframesPreventsDamage){
|
|
|
|
|
player->ApplyIframes(0.5f);
|
|
|
|
|
player->Hurt(30,player->OnUpperLevel(),player->GetZ());
|
|
|
|
|
Assert::AreEqual(100,player->GetHealth());
|
|
|
|
|
}
|
|
|
|
|
TEST_METHOD(PlayerConsumesManaOnRightClickAbilityUse){
|
|
|
|
|
int abilityManaCost{player->GetRightClickAbility().manaCost};
|
|
|
|
|
testKey->bHeld=true; //Force the key to be held down for testing purposes.
|
|
|
|
|
player->CheckAndPerformAbility(player->GetRightClickAbility(),testKeyboardInput);
|
|
|
|
|
Assert::AreEqual(player->GetMaxMana()-abilityManaCost,player->GetMana());
|
|
|
|
|
}
|
|
|
|
|
TEST_METHOD(PlayerConsumesManaOnAbility1Use){
|
|
|
|
|
int abilityManaCost{player->GetAbility1().manaCost};
|
|
|
|
|
testKey->bHeld=true; //Force the key to be held down for testing purposes.
|
|
|
|
|
player->CheckAndPerformAbility(player->GetAbility1(),testKeyboardInput);
|
|
|
|
|
Assert::AreEqual(player->GetMaxMana()-abilityManaCost,player->GetMana());
|
|
|
|
|
}
|
|
|
|
|
TEST_METHOD(PlayerConsumesManaOnAbility2Use){
|
|
|
|
|
int abilityManaCost{player->GetAbility2().manaCost};
|
|
|
|
|
testKey->bHeld=true; //Force the key to be held down for testing purposes.
|
|
|
|
|
player->CheckAndPerformAbility(player->GetAbility2(),testKeyboardInput);
|
|
|
|
|
Assert::AreEqual(player->GetMaxMana()-abilityManaCost,player->GetMana());
|
|
|
|
|
}
|
|
|
|
|
TEST_METHOD(PlayerConsumesManaOnAbility3Use){
|
|
|
|
|
int abilityManaCost{player->GetAbility3().manaCost};
|
|
|
|
|
testKey->bHeld=true; //Force the key to be held down for testing purposes.
|
|
|
|
|
player->CheckAndPerformAbility(player->GetAbility3(),testKeyboardInput);
|
|
|
|
|
Assert::AreEqual(player->GetMaxMana()-abilityManaCost,player->GetMana());
|
|
|
|
|
}
|
|
|
|
|
TEST_METHOD(PlayerConsumesManaOnAbility4Use){
|
|
|
|
|
int abilityManaCost{player->GetAbility4().manaCost};
|
|
|
|
|
testKey->bHeld=true; //Force the key to be held down for testing purposes.
|
|
|
|
|
player->CheckAndPerformAbility(player->GetAbility4(),testKeyboardInput);
|
|
|
|
|
Assert::AreEqual(player->GetMaxMana()-abilityManaCost,player->GetMana());
|
|
|
|
|
}
|
|
|
|
|
TEST_METHOD(WarriorBlockActivatesBlock){
|
|
|
|
|
player->GetRightClickAbility().action(player,player->GetPos());
|
|
|
|
|
Assert::AreEqual(int(State::BLOCK),int(player->GetState()));
|
|
|
|
|
}
|
|
|
|
|
TEST_METHOD(WizardCastDoesNotConsumeManaImmediately){
|
|
|
|
|
testGame->ChangePlayerClass(WIZARD);
|
|
|
|
|
player=testGame->GetPlayer(); //The player pointer has been reassigned...
|
|
|
|
|
//Ability 3 is Meteor, which is a cast. Mana should not be consumed for a spell that begins as a cast.
|
|
|
|
|
testKey->bHeld=true; //Force the key to be held down for testing purposes.
|
|
|
|
|
player->CheckAndPerformAbility(player->GetAbility3(),testKeyboardInput);
|
|
|
|
|
Assert::AreEqual(player->GetMaxMana(),player->GetMana());
|
|
|
|
|
}
|
|
|
|
|
TEST_METHOD(RangerCastDoesNotConsumeManaImmediately){
|
|
|
|
|
testGame->ChangePlayerClass(RANGER);
|
|
|
|
|
player=testGame->GetPlayer(); //The player pointer has been reassigned...
|
|
|
|
|
//Ability 2 is Charged Shot, which is a cast. Mana should not be consumed for a spell that begins as a cast.
|
|
|
|
|
testKey->bHeld=true; //Force the key to be held down for testing purposes.
|
|
|
|
|
player->CheckAndPerformAbility(player->GetAbility2(),testKeyboardInput);
|
|
|
|
|
Assert::AreEqual(player->GetMaxMana(),player->GetMana());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|