diff --git a/Adventures in Lestoria Tests/ItemTests.cpp b/Adventures in Lestoria Tests/ItemTests.cpp index 7b8f5cc2..ce0c7534 100644 --- a/Adventures in Lestoria Tests/ItemTests.cpp +++ b/Adventures in Lestoria Tests/ItemTests.cpp @@ -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([](){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([&](){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."); + } }; } diff --git a/Adventures in Lestoria/Item.cpp b/Adventures in Lestoria/Item.cpp index 926a816a..33570380 100644 --- a/Adventures in Lestoria/Item.cpp +++ b/Adventures in Lestoria/Item.cpp @@ -93,6 +93,7 @@ void ItemInfo::InitializeItems(){ Inventory::loadoutItemsUsed={}; Inventory::sortedInv.clear(); Inventory::blacksmithInventory.clear(); + Inventory::_inventory.clear(); ITEM_CONVERSIONS.Reset(); ITEM_DATA.Reset(); diff --git a/Adventures in Lestoria/Item.h b/Adventures in Lestoria/Item.h index 32ef202c..6222ea08 100644 --- a/Adventures in Lestoria/Item.h +++ b/Adventures in Lestoria/Item.h @@ -250,6 +250,7 @@ class Inventory{ friend class Item; friend class SaveFile; friend class InventoryCreator; + friend class ItemTests::ItemTest; public: static std::weak_ptrAddItem(IT it,uint32_t amt=1,bool monsterDrop=false); //Returns the actual amount available in your main inventory. diff --git a/Adventures in Lestoria/Player.h b/Adventures in Lestoria/Player.h index 919d4dc8..82358fa7 100644 --- a/Adventures in Lestoria/Player.h +++ b/Adventures in Lestoria/Player.h @@ -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 diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index f0b8ec60..a9fe173f 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -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