Add in loadout system to Player class.

pull/28/head
sigonasr2 1 year ago
parent 795d59f1a4
commit 7e371f6779
  1. 1
      Crawler/Item.h
  2. 23
      Crawler/Player.cpp
  3. 4
      Crawler/Player.h
  4. 3
      Crawler/assets/config/Player.txt
  5. 2
      Crawler/assets/config/items/items.txt

@ -17,6 +17,7 @@ typedef std::function<bool(Crawler*,ItemProps)> ItemScript;
class Item{
friend class Inventory;
friend class Palyer;
private:
uint32_t amt;
ItemInfo*it;

@ -719,3 +719,26 @@ 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--;
}
}

@ -45,6 +45,7 @@ private:
float spin_angle=0;
float lastAnimationFlip=0;
float manaTickTimer=0;
std::array<Item,3>loadout;
std::pair<std::string,float> 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;

@ -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

@ -2,5 +2,5 @@ ItemConfiguration
{
Item Database = "ItemDatabase.txt"
Item Scripts = "ItemScript.txt"
Item Categories = "ItemCategory.txt"
Item Categories = "ItemCategory.txt
}
Loading…
Cancel
Save