Item Loadout Usage Tests added. 101/101 unit tests passing. Release Build 9947.

removeExposedPackKey
sigonasr2 5 months ago
parent 01d61c95f4
commit 9d95796062
  1. 55
      Adventures in Lestoria Tests/ItemTests.cpp
  2. 1
      Adventures in Lestoria/Item.cpp
  3. 1
      Adventures in Lestoria/Item.h
  4. 1
      Adventures in Lestoria/Player.h
  5. 2
      Adventures in Lestoria/Version.h

@ -123,5 +123,60 @@ namespace ItemTests
Assert::IsFalse(game->UseLoadoutItem(1),L"Using a blank loadout item slot (1) does not produce a result.");
Assert::IsFalse(game->UseLoadoutItem(2),L"Using a blank loadout item slot (2) does not produce a result.");
}
TEST_METHOD(UsingLoadoutItemOfQuantityZeroDoesNothing){
Assert::ExpectException<std::exception>([](){game->SetLoadoutItem(0,"Minor Health Potion");},L"Applying an item that doesn't exist to a loadout slot should not be allowed.");
}
TEST_METHOD(UsingLoadoutItemConsumesIt){
player->Hurt(1,player->OnUpperLevel(),player->GetZ());
Inventory::AddItem("Minor Health Potion"s,5U);
game->SetLoadoutItem(0,"Minor Health Potion");
testKey->bHeld=true; //Simulate key being pressed.
player->CheckAndPerformAbility(player->useItem1,testKeyboardInput);
Assert::AreEqual(1,Inventory::loadoutItemsUsed[0].second,L"1 Health potion considered used in loadout inventory.");
Assert::AreEqual(4U,Inventory::GetItemCount("Minor Health Potion"s),L"4 Health potions remain in player's inventory.");
Assert::AreEqual(player->useItem1.GetCooldownTime(),player->useItem1.cooldown,L"Item 1 is now on cooldown.");
}
TEST_METHOD(ItemScriptBuffTest){
player->Hurt(1,player->OnUpperLevel(),player->GetZ());
Inventory::AddItem("Stat Up Everything Potion"s,5U);
game->SetLoadoutItem(0,"Stat Up Everything Potion");
testKey->bHeld=true; //Simulate key being pressed.
Assert::ExpectException<std::exception>([&](){player->CheckAndPerformAbility(player->useItem1,testKeyboardInput);},L"If all buffs are properly applied, then some of these stat up buffs are illegal and will catch an exception.");
}
TEST_METHOD(FlatRestoreScriptTest){
player->Hurt(75,player->OnUpperLevel(),player->GetZ());
player->mana=25;
Inventory::AddItem("Flat Recovery Potion"s,5U);
game->SetLoadoutItem(0,"Flat Recovery Potion");
testKey->bHeld=true; //Simulate key being pressed.
player->CheckAndPerformAbility(player->useItem1,testKeyboardInput);
Assert::AreEqual(75,player->GetHealth(),L"Player Health is 75 after using Flat Recovery Potion.");
Assert::AreEqual(75,player->GetMana(),L"Player Mana is 75 after using Flat Recovery Potion.");
}
TEST_METHOD(PctRestoreScriptTest){
player->Hurt(75,player->OnUpperLevel(),player->GetZ());
player->mana=25;
Inventory::AddItem("Pct Recovery Potion"s,5U);
game->SetLoadoutItem(1,"Pct Recovery Potion");
testKey->bHeld=true; //Simulate key being pressed.
player->CheckAndPerformAbility(player->useItem2,testKeyboardInput);
Assert::AreEqual(75,player->GetHealth(),L"Player Health is 75 after using Pct Recovery Potion.");
Assert::AreEqual(75,player->GetMana(),L"Player Mana is 75 after using Pct Recovery Potion.");
}
TEST_METHOD(HealOverTimeTest){
player->Hurt(75,player->OnUpperLevel(),player->GetZ());
Inventory::AddItem("Bandages"s,5U);
game->SetLoadoutItem(2,"Bandages");
testKey->bHeld=true; //Simulate key being pressed.
player->CheckAndPerformAbility(player->useItem3,testKeyboardInput);
Assert::AreEqual(30,player->GetHealth(),L"Player is immediately healed for 5 health points on Bandages use.");
game->SetElapsedTime(1.f);
game->OnUserUpdate(1.f);
for(int seconds{1};seconds<=6;seconds++){
Assert::AreEqual(30+seconds*5,player->GetHealth(),L"Player is healed again for 5 health points.");
game->OnUserUpdate(1.f);
}
Assert::AreEqual(60,player->GetHealth(),L"Player should not be healed now that the Bandages effect is over.");
}
};
}

@ -93,6 +93,7 @@ void ItemInfo::InitializeItems(){
Inventory::loadoutItemsUsed={};
Inventory::sortedInv.clear();
Inventory::blacksmithInventory.clear();
Inventory::_inventory.clear();
ITEM_CONVERSIONS.Reset();
ITEM_DATA.Reset();

@ -250,6 +250,7 @@ class Inventory{
friend class Item;
friend class SaveFile;
friend class InventoryCreator;
friend class ItemTests::ItemTest;
public:
static std::weak_ptr<Item>AddItem(IT it,uint32_t amt=1,bool monsterDrop=false);
//Returns the actual amount available in your main inventory.

@ -105,6 +105,7 @@ class Player{
friend class Inventory;
friend void ItemOverlay::Draw();
friend class PlayerTests::PlayerTest;
friend class ItemTests::ItemTest;
public:
Player();
//So this is rather fascinating and only exists because we have the ability to change classes which means we need to initialize a class

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 1
#define VERSION_MINOR 2
#define VERSION_PATCH 3
#define VERSION_BUILD 9944
#define VERSION_BUILD 9947
#define stringify(a) stringify_(a)
#define stringify_(a) #a

Loading…
Cancel
Save