Implemented equipping of items, reading of slot types from item database, and prepared set items and stats structures.
This commit is contained in:
+55
-1
@@ -53,11 +53,25 @@ std::map<IT,Item>Inventory::_inventory;
|
||||
std::map<ITCategory,std::vector<Item>>Inventory::sortedInv;
|
||||
std::vector<ItemOverlay>ItemOverlay::items;
|
||||
std::map<std::string,ItemSet>ItemSet::sets;
|
||||
std::map<EquipSlot,Item*>Inventory::equipment;
|
||||
std::map<std::string,EquipSlot>ItemInfo::nameToEquipSlot;
|
||||
|
||||
ItemInfo::ItemInfo()
|
||||
:customProps({nullptr,nullptr}),img(nullptr){}
|
||||
|
||||
void ItemInfo::InitializeItems(){
|
||||
for(int i=int(EquipSlot::HELMET);i<=int(EquipSlot::RING2);i<<=1){
|
||||
Inventory::equipment[EquipSlot(i)]=nullptr;
|
||||
}
|
||||
|
||||
nameToEquipSlot["Helmet"]=EquipSlot::HELMET;
|
||||
nameToEquipSlot["Weapon"]=EquipSlot::WEAPON;
|
||||
nameToEquipSlot["Armor"]=EquipSlot::ARMOR;
|
||||
nameToEquipSlot["Gloves"]=EquipSlot::GLOVES;
|
||||
nameToEquipSlot["Pants"]=EquipSlot::PANTS;
|
||||
nameToEquipSlot["Shoes"]=EquipSlot::SHOES;
|
||||
nameToEquipSlot["Ring1"]=EquipSlot::RING1;
|
||||
nameToEquipSlot["Ring2"]=EquipSlot::RING2;
|
||||
|
||||
InitializeScripts();
|
||||
|
||||
@@ -74,6 +88,7 @@ void ItemInfo::InitializeItems(){
|
||||
|
||||
std::string scriptName="",description="",category="";
|
||||
float castTime=0;
|
||||
std::vector<std::string> slot;
|
||||
float cooldownTime="Item.Item Cooldown Time"_F;
|
||||
for(auto&itemKey:DATA["ItemDatabase"][key.first].GetKeys()){
|
||||
std::string keyName=itemKey.first;
|
||||
@@ -91,6 +106,11 @@ void ItemInfo::InitializeItems(){
|
||||
}else
|
||||
if(keyName=="Cooldown Time"){
|
||||
castTime=float(DATA["ItemDatabase"][key.first][keyName].GetReal());
|
||||
}else
|
||||
if(keyName=="Slot"){
|
||||
for(auto&val:DATA["ItemDatabase"][key.first][keyName].GetValues()){
|
||||
slot.push_back(val);
|
||||
}
|
||||
}else{ //THis is a custom override modifier for a script. NO-OP
|
||||
}
|
||||
}
|
||||
@@ -107,6 +127,13 @@ void ItemInfo::InitializeItems(){
|
||||
it.category=category;
|
||||
it.castTime=castTime;
|
||||
it.cooldownTime=cooldownTime;
|
||||
it.slot=EquipSlot::NONE;
|
||||
if(slot.size()>0){
|
||||
for(std::string&s:slot){
|
||||
if(!nameToEquipSlot.count(s))ERR("WARNING! Tried to add item "<<it.name<<" to slot "<<s<<" which doesn't exist!");
|
||||
it.slot=it.slot|nameToEquipSlot[s];
|
||||
}
|
||||
}
|
||||
if(!ITEM_CATEGORIES.count(it.category)){
|
||||
ERR("WARNING! Tried to add item "<<it.name<<" to category "<<it.category<<" which does not exist!")
|
||||
}
|
||||
@@ -174,7 +201,12 @@ void Inventory::AddItem(IT it,uint32_t amt,bool monsterDrop){
|
||||
InsertIntoStageInventoryCategory(it,amt,monsterDrop);
|
||||
}
|
||||
|
||||
Item Inventory::GetItem(IT it){
|
||||
Item Inventory::CopyItem(IT it){
|
||||
if(!_inventory.count(it))return Item::BLANK;
|
||||
return _inventory.at(it);
|
||||
}
|
||||
|
||||
Item&Inventory::GetItem(IT it){
|
||||
if(!_inventory.count(it))return Item::BLANK;
|
||||
return _inventory.at(it);
|
||||
}
|
||||
@@ -412,6 +444,7 @@ const ItemSet&Item::GetItemSet()const{
|
||||
};
|
||||
|
||||
const Stats&ItemSet::operator[](int setPieces)const{
|
||||
if(setPieces<=0||setPieces>=9)ERR("Piece count is invalid! Expecting a value (1-8) but got "<<setPieces);
|
||||
return setBonuses[setPieces];
|
||||
};
|
||||
|
||||
@@ -420,4 +453,25 @@ void ItemSet::AddSetBonus(int pieceCount,const Stats&bonuses){
|
||||
for(int i=pieceCount-1;i<setBonuses.size();i++){
|
||||
setBonuses[i]+=bonuses;
|
||||
}
|
||||
}
|
||||
|
||||
void Inventory::EquipItem(Item&it,EquipSlot slot){
|
||||
if(!(it.it->slot&slot))return;
|
||||
EquipSlot equippedSlot=GetSlotEquippedIn(it);
|
||||
if(equippedSlot!=EquipSlot::NONE)UnequipItem(equippedSlot);
|
||||
if(GetEquip(slot)!=nullptr)UnequipItem(slot);
|
||||
Inventory::equipment[slot]=⁢
|
||||
};
|
||||
void Inventory::UnequipItem(EquipSlot slot){
|
||||
Inventory::equipment[slot]=nullptr;
|
||||
};
|
||||
EquipSlot Inventory::GetSlotEquippedIn(Item&it){
|
||||
for(int i=int(EquipSlot::HELMET);i<=int(EquipSlot::RING2);i<<=1){
|
||||
EquipSlot slot=EquipSlot(i);
|
||||
if(GetEquip(slot)==&it)return slot;
|
||||
}
|
||||
return EquipSlot::NONE;
|
||||
};
|
||||
Item*Inventory::GetEquip(EquipSlot slot){
|
||||
return Inventory::equipment[slot];
|
||||
}
|
||||
Reference in New Issue
Block a user