Item Attribute systems reworked from being an enum class to being a class. Added support for the Buff Item Script to modify items. Implemented Damage Reduction proposal.

This commit is contained in:
2023-12-23 21:15:08 -06:00
parent 51cbf81204
commit 668a5ca1b1
28 changed files with 704 additions and 331 deletions
+47 -11
View File
@@ -41,6 +41,7 @@ All rights reserved.
#include "Crawler.h"
#include "Menu.h"
#include "Ability.h"
#include "AttributableStat.h"
INCLUDE_game
INCLUDE_DATA
@@ -57,6 +58,7 @@ std::map<std::string,ItemSet>ItemSet::sets;
std::map<EquipSlot,std::weak_ptr<Item>>Inventory::equipment;
std::map<std::string,EquipSlot>ItemInfo::nameToEquipSlot;
int Item::IsBlankStaticCallCounter=0;
safemap<int,float>Stats::maxDamageReductionTable;
ItemInfo::ItemInfo()
:customProps({nullptr,nullptr}),img(nullptr){}
@@ -76,11 +78,6 @@ void ItemInfo::InitializeItems(){
nameToEquipSlot["Ring2"]=EquipSlot::RING2;
InitializeScripts();
//Setup Strings to Attribute map.
for(ItemAttribute attr=ItemAttribute(int(ItemAttribute::ENUM_START)+1);attr<ItemAttribute::ENUM_END;attr=ItemAttribute(int(attr)+1)){
ItemAttributable::stringToAttribute[ItemAttributable::GetDisplayInfo(attr).name]=attr;
}
InitializeSets();
@@ -130,7 +127,7 @@ void ItemInfo::InitializeItems(){
}else
if(keyName=="StatValues"){
for(int i=0;i<data[key]["StatValues"].GetValueCount();i++){
statValueList.push_back(ItemAttributable::GetAttributeFromString(data[key]["StatValues"].GetString(i)));
statValueList.push_back(ItemAttribute::Get(data[key]["StatValues"].GetString(i)));
}
}else
if(keyName=="PartofSet"){
@@ -259,8 +256,19 @@ void ItemInfo::InitializeScripts(){
});
return true;
};
for(auto&[key,value]:ItemAttribute::attributes){
if(!DATA.GetProperty("ItemScript.Buff").HasProperty(key)){
ERR("WARNING! Buff Item Script does not support Buff "<<std::quoted(value.Name())<<"!");
}
}
ITEM_SCRIPTS["Buff"]=[](Crawler*game,ItemProps props){
game->GetPlayer()->AddBuff(BuffType::ATTACK_PCT_UP,props.GetFloatProp("Attack %",1),props.GetFloatProp("Attack %",0)/100);
for(auto&[key,value]:ItemAttribute::attributes){
float intensity=props.GetFloatProp(key,0);
if(ItemAttribute::Get(key).DisplayAsPercent())intensity/=100;
game->GetPlayer()->AddBuff(BuffType::STAT_UP,props.GetFloatProp(key,1),intensity,{ItemAttribute::Get(key)});
}
return true;
};
ITEM_SCRIPTS["RestoreDuringCast"]=[&](Crawler*game,ItemProps props){
@@ -612,11 +620,11 @@ void Inventory::EquipItem(const std::weak_ptr<Item>it,EquipSlot slot){
if(equippedSlot!=EquipSlot::NONE)UnequipItem(equippedSlot);
if(!GetEquip(slot).expired())UnequipItem(slot);
Inventory::equipment[slot]=it;
PlayerStats::RecalculateEquipStats();
game->GetPlayer()->RecalculateEquipStats();
};
void Inventory::UnequipItem(EquipSlot slot){
Inventory::equipment[slot]=Item::BLANK;
PlayerStats::RecalculateEquipStats();
game->GetPlayer()->RecalculateEquipStats();
};
EquipSlot Inventory::GetSlotEquippedIn(const std::weak_ptr<Item>it){
for(int i=int(EquipSlot::HELMET);i<=int(EquipSlot::RING2);i<<=1){
@@ -654,7 +662,7 @@ void ItemInfo::InitializeSets(){
datafile&statInfo=setInfo[std::to_string(pieceCount)];
Stats bonuses;
for(auto&[key,value]:statInfo.GetKeys()){
ItemAttribute attr=bonuses.GetAttributeFromString(key);
const ItemAttribute&attr=ItemAttribute::Get(key);
bonuses.A(attr)=statInfo[key].GetInt(0);
}
ItemSet::AddSetBonus(setName,pieceCount,bonuses);
@@ -718,7 +726,7 @@ const std::string Stats::GetStatsString(CompactText compact)const{
description+="\n";
}
}
description+=ItemAttributable::GetAttributeName(attr)+": "+std::to_string(val)+(ItemAttributable::GetDisplayInfo(attr).displayAsPercent?"%":"");
description+=std::string(attr.Name())+": "+std::to_string(int(val))+(attr.DisplayAsPercent()?"%":"");
first=false;
}
return description;
@@ -783,4 +791,32 @@ const bool Item::UseDuringCast()const{
const bool ItemInfo::UseDuringCast()const{
return useDuringCast;
}
void Stats::InitializeDamageReductionTable(){
float totalReduction=0;
maxDamageReductionTable[0]=0;
for(int i=1;i<=1000;i++){
if(i<=10){
totalReduction+=0.01;
}else
if(i<=30){
totalReduction+=0.00'5;
}else
if(i<=70){
totalReduction+=0.00'25;
}else
if(i<=150){
totalReduction+=0.00'125;
}else
if(i<=310){
totalReduction+=0.00'0625;
}else
if(i<=950){
totalReduction+=0.00'03125;
}else{
totalReduction+=0.00'1;
}
maxDamageReductionTable[i]=totalReduction;
}
}