@ -105,6 +105,7 @@ void ItemInfo::InitializeItems(){
std : : vector < ItemAttribute > statValueList ;
uint32_t sellValue = 0 ;
uint32_t buyValue = 0 ;
bool useDuringCast = false ;
for ( auto & [ itemKey , itemValue ] : data [ key ] . GetKeys ( ) ) {
std : : string keyName = itemKey ;
if ( keyName = = " Description " ) {
@ -159,6 +160,9 @@ void ItemInfo::InitializeItems(){
it . enhancement = enhancementStats ;
}
if ( scriptName ! = " " ) {
if ( scriptName = = " RestoreDuringCast " ) {
useDuringCast = true ;
}
if ( ! ITEM_SCRIPTS . count ( scriptName ) ) {
ERR ( " Could not load script " < < scriptName < < " for Item " < < key < < " ! " )
}
@ -173,6 +177,7 @@ void ItemInfo::InitializeItems(){
it . set = setName ;
it . buyValue = buyValue ;
it . sellValue = sellValue ;
it . useDuringCast = useDuringCast ;
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! " ) ;
@ -233,31 +238,53 @@ const uint32_t ItemProps::PropCount(const std::string&prop)const{
void ItemInfo : : InitializeScripts ( ) {
ITEM_SCRIPTS [ " Restore " ] = [ ] ( Crawler * game , ItemProps props ) {
auto ParseItemScriptData = [ & ] ( const std : : string & propName , std : : function < void ( Crawler * , int ) > action , BuffType type ) {
auto ParseItemScriptData = [ & ] ( const std : : string & propName , std : : function < void ( Crawler * , int ) > action ) {
int restoreAmt = props . GetIntProp ( propName ) ;
action ( game , restoreAmt ) ;
if ( restoreAmt > 0 & & props . PropCount ( propName ) = = 3 ) {
game - > GetPlayer ( ) - > AddBuff ( type , props . GetFloatProp ( propName , 2 ) , restoreAmt , props . GetFloatProp ( propName , 1 ) , action ) ;
game - > GetPlayer ( ) - > AddBuff ( RESTORATION , props . GetFloatProp ( propName , 2 ) , restoreAmt , props . GetFloatProp ( propName , 1 ) , action ) ;
}
} ;
ParseItemScriptData ( " HP Restore " , [ & ] ( Crawler * game , int restoreAmt ) {
game - > GetPlayer ( ) - > Heal ( restoreAmt ) ;
} , RESTORATION ) ;
} ) ;
ParseItemScriptData ( " HP % Restore " , [ & ] ( Crawler * game , int restoreAmt ) {
game - > GetPlayer ( ) - > Heal ( int ( game - > GetPlayer ( ) - > GetMaxHealth ( ) * restoreAmt / 100.0f ) ) ;
} , RESTORATION ) ;
} ) ;
ParseItemScriptData ( " MP Restore " , [ & ] ( Crawler * game , int restoreAmt ) {
game - > GetPlayer ( ) - > RestoreMana ( restoreAmt ) ;
} , RESTORATION ) ;
} ) ;
ParseItemScriptData ( " MP % Restore " , [ & ] ( Crawler * game , int restoreAmt ) {
game - > GetPlayer ( ) - > RestoreMana ( int ( game - > GetPlayer ( ) - > GetMaxMana ( ) * props . GetIntProp ( " MP % Restore " ) / 100.f ) ) ;
} , RESTORATION ) ;
} ) ;
return true ;
} ;
ITEM_SCRIPTS [ " Buff " ] = [ ] ( Crawler * game , ItemProps props ) {
game - > GetPlayer ( ) - > AddBuff ( BuffType : : ATTACK_PCT_UP , props . GetFloatProp ( " Attack % " , 1 ) , props . GetFloatProp ( " Attack % " , 0 ) / 100 ) ;
return true ;
} ;
ITEM_SCRIPTS [ " RestoreDuringCast " ] = [ & ] ( Crawler * game , ItemProps props ) {
auto ParseItemScriptData = [ & ] ( const std : : string & propName , std : : function < void ( Crawler * , int ) > action ) {
int restoreAmt = props . GetIntProp ( propName ) ;
action ( game , restoreAmt ) ;
if ( restoreAmt > 0 & & props . PropCount ( propName ) = = 3 ) {
game - > GetPlayer ( ) - > AddBuff ( RESTORATION_DURING_CAST , props . GetFloatProp ( propName , 2 ) , restoreAmt , props . GetFloatProp ( propName , 1 ) , action ) ;
}
} ;
ParseItemScriptData ( " HP Restore " , [ & ] ( Crawler * game , int restoreAmt ) {
game - > GetPlayer ( ) - > Heal ( restoreAmt ) ;
} ) ;
ParseItemScriptData ( " HP % Restore " , [ & ] ( Crawler * game , int restoreAmt ) {
game - > GetPlayer ( ) - > Heal ( int ( game - > GetPlayer ( ) - > GetMaxHealth ( ) * restoreAmt / 100.0f ) ) ;
} ) ;
ParseItemScriptData ( " MP Restore " , [ & ] ( Crawler * game , int restoreAmt ) {
game - > GetPlayer ( ) - > RestoreMana ( restoreAmt ) ;
} ) ;
ParseItemScriptData ( " MP % Restore " , [ & ] ( Crawler * game , int restoreAmt ) {
game - > GetPlayer ( ) - > RestoreMana ( int ( game - > GetPlayer ( ) - > GetMaxMana ( ) * props . GetIntProp ( " MP % Restore " ) / 100.f ) ) ;
} ) ;
return true ;
} ;
ITEM_SCRIPTS . SetInitialized ( ) ;
std : : cout < < ITEM_SCRIPTS . size ( ) < < " item scripts have been loaded. " < < std : : endl ;
@ -748,4 +775,12 @@ bool Item::IsBlank(std::weak_ptr<Item>item){
const bool Item : : _IsBlank ( ) const {
Item : : IsBlankStaticCallCounter + + ;
return IsBlank ( ) ;
} ;
} ;
const bool Item : : UseDuringCast ( ) const {
return it - > UseDuringCast ( ) ;
}
const bool ItemInfo : : UseDuringCast ( ) const {
return useDuringCast ;
}