diff --git a/Crawler/Item.h b/Crawler/Item.h index 06520a16..625540dc 100644 --- a/Crawler/Item.h +++ b/Crawler/Item.h @@ -17,6 +17,7 @@ typedef std::function ItemScript; class Item{ friend class Inventory; + friend class Palyer; private: uint32_t amt; ItemInfo*it; diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index 04b62df8..24a24e38 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -718,4 +718,27 @@ void Player::ConsumeMana(int amt){ void Player::SetSizeMult(float size){ this->size=size; +} + +Item&Player::GetLoadoutItem(int slot){ + if(slot<0||slot>loadout.size()-1)ERR("Invalid inventory slot "+std::to_string(slot)+", please choose a slot in range (0-"+std::to_string(loadout.size()-1)+")."); + return loadout[slot]; +} + +void Player::SetLoadoutItem(int slot,std::string itemName){ + if(slot<0||slot>loadout.size()-1)ERR("Invalid inventory slot "+std::to_string(slot)+", please choose a slot in range (0-"+std::to_string(loadout.size()-1)+")."); + if(Inventory::GetItemCount(itemName)>0){ + GetLoadoutItem(slot)=Inventory::GetItem(itemName); + GetLoadoutItem(slot).amt=std::min((uint32_t)"Player.Item Loadout Limit"_I,GetLoadoutItem(slot).Amt()); //We are only allowed to have up to 10 maximum of an item on a journey. + }else{ + ERR("Trying to set item "+itemName+" in Loadout slot "+std::to_string(slot)+" when said item does not exist in our inventory!"); + } +} +void Player::UseLoadoutItem(int slot){ + if(slot<0||slot>loadout.size()-1)ERR("Invalid inventory slot "+std::to_string(slot)+", please choose a slot in range (0-"+std::to_string(loadout.size()-1)+")."); + if(GetLoadoutItem(slot).Amt()>0){ + Inventory::UseItem(loadout[slot].Name()); + GetLoadoutItem(slot).OnUseAction(); + GetLoadoutItem(slot).amt--; + } } \ No newline at end of file diff --git a/Crawler/Player.h b/Crawler/Player.h index 4738beb5..f9c07929 100644 --- a/Crawler/Player.h +++ b/Crawler/Player.h @@ -45,6 +45,7 @@ private: float spin_angle=0; float lastAnimationFlip=0; float manaTickTimer=0; + std::arrayloadout; std::pair notEnoughManaDisplay={"",0}; float teleportAttemptWaitTime=0; //If a teleport fails, we wait awhile before trying again, it's expensive. State::State state=State::NORMAL; @@ -157,6 +158,9 @@ public: Key GetLastReleasedMovementKey(); float GetSwordSwingTimer(); bool OnUpperLevel(); + Item&GetLoadoutItem(int slot); + void SetLoadoutItem(int slot,std::string itemName); + void UseLoadoutItem(int slot); //Triggers when the player has moved. void Moved(); virtual ~Player()=default; diff --git a/Crawler/assets/config/Player.txt b/Crawler/assets/config/Player.txt index 1ae9697e..2908ccc8 100644 --- a/Crawler/assets/config/Player.txt +++ b/Crawler/assets/config/Player.txt @@ -9,6 +9,9 @@ Player # How much speed the player loses while no momentum is being added. Friction = 400 + # How many of any one type of item we can bring to the battlefield max per slot. + Item Loadout Limit = 10 + # Each attack will have _N,_E,_S,_W appended to them once read in-game. PLAYER_ANIMATION[0] = WARRIOR_WALK PLAYER_ANIMATION[1] = WARRIOR_IDLE diff --git a/Crawler/assets/config/items/items.txt b/Crawler/assets/config/items/items.txt index 345e9e05..338580c6 100644 --- a/Crawler/assets/config/items/items.txt +++ b/Crawler/assets/config/items/items.txt @@ -2,5 +2,5 @@ ItemConfiguration { Item Database = "ItemDatabase.txt" Item Scripts = "ItemScript.txt" - Item Categories = "ItemCategory.txt" + Item Categories = "ItemCategory.txt } \ No newline at end of file