Skip to content

Commit

Permalink
Merge pull request UOX3DevTeam#326 from DragonSlayer62/durabilitypr-r…
Browse files Browse the repository at this point in the history
…eplacement

Durability HP Bonus support
  • Loading branch information
Xoduz authored Jan 29, 2025
2 parents deeede6 + 20a2903 commit 05f757f
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 6 deletions.
7 changes: 7 additions & 0 deletions source/CPacketSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7467,6 +7467,13 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou
FinalizeData( tempEntry, totalStringLen );
}

if( cItem.GetDurabilityHpBonus() > 0)
{
tempEntry.stringNum = 1151780; // durability +~1_VAL~%
tempEntry.ourText = oldstrutil::number( cItem.GetDurabilityHpBonus() );
FinalizeData( tempEntry, totalStringLen );
}

if( cItem.GetType() == IT_MAGICWAND && cItem.GetTempVar( CITV_MOREZ ))
{
tempEntry.stringNum = 1060584; // uses remaining: ~1_val~
Expand Down
5 changes: 5 additions & 0 deletions source/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
13/05/2024 - Dragon Slayer
Added New Shield Type 107 so shield ID's no longer have to be in hard code for shields to work properly

11/05/2024 - Dragon Slayer/Xuri/Maarc
Added Support for new AOS property tag.
-DURABILITYHPBONUS = # - Add durability (aka Health) at percentage multiplier to hp.
.durabilityhpbonus (js)

11/05/2024 - Dragon Slayer
Updated 'get command (js/commands/targeting/get.js) to use correct object reference when getting resist values for items, and added support for getting resist values for chars

Expand Down
1 change: 1 addition & 0 deletions source/UOXJSPropertyEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ enum CI_Properties
CIP_DEFENSECHANCE,

CIP_ARTIFACTRARITY,
CIP_DURABILITYHPBONUS,
CIP_NAME2,
CIP_ISITEM,
CIP_ISCHAR,
Expand Down
3 changes: 2 additions & 1 deletion source/UOXJSPropertyFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ JSBool CItemProps_getProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp
case CIP_DAMAGESNOW: *vp = BOOLEAN_TO_JSVAL( gPriv->GetWeatherDamage( SNOW )); break;
case CIP_SWINGSPEEDINCREASE: *vp = INT_TO_JSVAL( gPriv->GetSwingSpeedIncrease() ); break;
case CIP_SPEED: *vp = INT_TO_JSVAL( gPriv->GetSpeed() ); break;
case CIP_DURABILITYHPBONUS: *vp = INT_TO_JSVAL( gPriv->GetDurabilityHpBonus() ); break;
case CIP_LOWERSTATREQ: *vp = INT_TO_JSVAL( gPriv->GetLowerStatReq() ); break;
case CIP_HEALTHLEECH: *vp = INT_TO_JSVAL( gPriv->GetHealthLeech() ); break;
case CIP_STAMINALEECH: *vp = INT_TO_JSVAL( gPriv->GetStaminaLeech() ); break;
Expand Down Expand Up @@ -1344,7 +1345,7 @@ JSBool CItemProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp
case CIP_STAMINABONUS: gPriv->SetStaminaBonus( static_cast<SI16>( encaps.toInt() )); break;
case CIP_MANABONUS: gPriv->SetManaBonus( static_cast<SI16>( encaps.toInt() )); break;
case CIP_ARTIFACTRARITY: gPriv->SetArtifactRarity( static_cast<SI16>( encaps.toInt() )); break;

case CIP_DURABILITYHPBONUS: gPriv->SetDurabilityHpBonus( static_cast<SI16>( encaps.toInt() )); break;
case CIP_NAME2: gPriv->SetName2( encaps.toString() ); break;
case CIP_RACE: gPriv->SetRace( static_cast<RACEID>( encaps.toInt() )); break;
case CIP_MAXHP: gPriv->SetMaxHP( static_cast<SI16>( encaps.toInt() )); break;
Expand Down
2 changes: 2 additions & 0 deletions source/UOXJSPropertySpecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ inline JSPropertySpec CItemProps[] =
{ "manaBonus", CIP_MANABONUS, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "artifactRarity", CIP_ARTIFACTRARITY, JSPROP_ENUMANDPERM, nullptr, nullptr },

{ "durabilityHpBonus", CIP_DURABILITYHPBONUS, JSPROP_ENUMANDPERM, nullptr, nullptr },

{ "multi", CIP_MULTI, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "maxRange", CIP_MAXRANGE, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "baseRange", CIP_BASERANGE, JSPROP_ENUMANDPERM, nullptr, nullptr },
Expand Down
31 changes: 30 additions & 1 deletion source/cItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ const UI16 DEFITEM_REGIONNUM = 255;
const UI16 DEFITEM_TEMPLASTTRADED = 0;
const SI08 DEFITEM_STEALABLE = 1;
const SI16 DEFITEM_ARTIFACTRARITY = 0;

const SI16 DEFITEM_DURABLITITYHPBONUS = 0;

const SI16 DEFITEM_LOWERSTATREQ = 0;


//o------------------------------------------------------------------------------------------------o
//| Function - CItem()
//o------------------------------------------------------------------------------------------------o
Expand All @@ -109,7 +113,7 @@ spd( DEFITEM_SPEED ), maxHp( DEFITEM_MAXHP ), amount( DEFITEM_AMOUNT ),
layer( DEFITEM_LAYER ), type( DEFITEM_TYPE ), offspell( DEFITEM_OFFSPELL ), entryMadeFrom( DEFITEM_ENTRYMADEFROM ),
creator( DEFITEM_CREATOR ), gridLoc( DEFITEM_GRIDLOC ), weightMax( DEFITEM_WEIGHTMAX ), baseWeight( DEFITEM_BASEWEIGHT ), maxItems( DEFITEM_MAXITEMS ),
maxRange( DEFITEM_MAXRANGE ), baseRange( DEFITEM_BASERANGE ), maxUses( DEFITEM_MAXUSES ), usesLeft( DEFITEM_USESLEFT ), regionNum( DEFITEM_REGIONNUM ),
tempLastTraded( DEFITEM_TEMPLASTTRADED ), stealable( DEFITEM_STEALABLE ), artifactRarity( DEFITEM_ARTIFACTRARITY ), lowerStatReq( DEFITEM_LOWERSTATREQ )
tempLastTraded( DEFITEM_TEMPLASTTRADED ), stealable( DEFITEM_STEALABLE ), artifactRarity( DEFITEM_ARTIFACTRARITY ), lowerStatReq( DEFITEM_LOWERSTATREQ ), durabilityHpBonus( DEFITEM_DURABLITITYHPBONUS )
{
spells[0] = spells[1] = spells[2] = 0;
value[0] = value[1] = value[2] = 0;
Expand Down Expand Up @@ -1392,6 +1396,23 @@ auto CItem::SetBaseWeight( SI32 newValue ) -> void
UpdateRegion();
}

//o------------------------------------------------------------------------------------------------o
//| Function - CItem::GetDurabilityHpBonus()
//| CItem::SetDurabilityHpBonus()
//| Date - 5 May, 2024
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets/Sets the Bonus hp on the object
//o------------------------------------------------------------------------------------------------o
SI16 CItem::GetDurabilityHpBonus(void) const
{
return durabilityHpBonus;
}
void CItem::SetDurabilityHpBonus(SI16 newValue)
{
durabilityHpBonus = newValue;
UpdateRegion();
}

//o------------------------------------------------------------------------------------------------o
//| Function - CItem::GetMaxItems()
//| CItem::SetMaxItems()
Expand Down Expand Up @@ -1677,6 +1698,8 @@ auto CItem::CopyData( CItem *target ) -> void

target->SetArtifactRarity( GetArtifactRarity() );

target->SetDurabilityHpBonus( GetDurabilityHpBonus() );

target->SetSpell( 0, GetSpell( 0 ));
target->SetSpell( 1, GetSpell( 1 ));
target->SetSpell( 2, GetSpell( 2 ));
Expand Down Expand Up @@ -1787,6 +1810,7 @@ bool CItem::DumpBody( std::ostream &outStream ) const
outStream << "Speed=" + std::to_string( GetSpeed() ) + newLine;
outStream << "BonusStats=" + std::to_string( GetHealthBonus() ) + "," + std::to_string( GetStaminaBonus() ) + "," + std::to_string( GetManaBonus() ) + newLine;
outStream << "ArtifactRarity=" + std::to_string( GetArtifactRarity() ) + newLine;
outStream << "DurabilityHpBonus=" + std::to_string( GetDurabilityHpBonus() ) + newLine;
outStream << "Movable=" + std::to_string( GetMovable() ) + newLine;
outStream << "Priv=" + std::to_string( GetPriv() ) + newLine;
outStream << "LowerStatReq=" + std::to_string( GetLowerStatReq() ) + newLine;
Expand Down Expand Up @@ -1918,6 +1942,11 @@ bool CItem::HandleLine( std::string &UTag, std::string &data )
SetDir( static_cast<SI08>( std::stoi(oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )));
rValue = true;
}
else if( UTag == "DURABILITYHPBONUS" )
{
SetDurabilityHpBonus( static_cast<SI16>( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )));
rValue = true;
}
else if( UTag == "DYEABLE" )
{
SetDye( static_cast<UI08>( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 );
Expand Down
11 changes: 9 additions & 2 deletions source/cItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ class CItem : public CBaseObject
SERIAL creator; // Store the serial of the player made this item
SI08 gridLoc;
SI16 artifactRarity;

SI16 durabilityHpBonus;

SI16 lowerStatReq;

SI32 weightMax; // Maximum weight a container can hold
SI32 baseWeight; // Base weight of item. Applied when item is created for the first time, based on weight. Primarily used to determine base weight of containers
UI16 maxItems; // Maximum amount of items a container can hold
Expand Down Expand Up @@ -112,8 +116,11 @@ class CItem : public CBaseObject
auto GetGridLocation() const -> SI08;
auto SetGridLocation( SI08 newLoc ) -> void;

virtual SI16 GetArtifactRarity(void) const;
virtual void SetArtifactRarity(SI16 newValue);
SI16 GetArtifactRarity(void) const;
void SetArtifactRarity(SI16 newValue);

SI16 GetDurabilityHpBonus(void) const;
void SetDurabilityHpBonus(SI16 newValue);

SI16 GetLowerStatReq( void ) const;
void SetLowerStatReq( SI16 newValue );
Expand Down
29 changes: 27 additions & 2 deletions source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect
Console.Warning( oldstrutil::format( "Invalid data found in AMOUNT tag inside item script [%s]", sectionId.c_str() ));
}
break;
case DFNTAG_DURABILITYHPBONUS: applyTo->SetDurabilityHpBonus( static_cast<SI16>( ndata )); break;
case DFNTAG_DAMAGE:
case DFNTAG_ATT:
if( ndata >= 0 )
Expand Down Expand Up @@ -1204,10 +1205,34 @@ CItem * cItem::CreateBaseScriptItem( CItem *mCont, std::string ourItem, const UI
Console.Error( "Trying to apply an item section failed" );
}

// If the durabilityhpbonus tag is on the item, it will add to its Durability (aka Health).
auto durabilityHpBonus = iCreated->GetDurabilityHpBonus();

// If maxHP has not been defined for a new item, set it to the same value as HP
if( !iCreated->GetMaxHP() && iCreated->GetHP() )
if (!iCreated->GetMaxHP() && iCreated->GetHP())
{
iCreated->SetMaxHP( iCreated->GetHP() );
iCreated->SetMaxHP(iCreated->GetHP());
}

if( durabilityHpBonus > 0 )
{
// Calculate percentage increase
auto baseHP = iCreated->GetHP();
auto baseMaxHP = iCreated->GetMaxHP();

// If maxHP has not been defined, default it to HP
if( baseMaxHP == 0 && baseHP > 0 )
{
baseMaxHP = baseHP;
iCreated->SetMaxHP( baseMaxHP );
}

// Apply the percentage bonus to HP and MaxHP
auto hpBonus = static_cast<int>( baseHP * ( durabilityHpBonus / 100.0 ));
auto maxHpBonus = static_cast<int>( baseMaxHP * ( durabilityHpBonus / 100.0 ));

iCreated->SetHP( baseHP + hpBonus );
iCreated->SetMaxHP( baseMaxHP + maxHpBonus );
}

// If maxUses is higher than usesLeft for a new item, randomize the amount of usesLeft the item should have!
Expand Down
2 changes: 2 additions & 0 deletions source/ssection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const UI08 dfnDataTypes[DFNTAG_COUNTOFTAGS] =
DFN_NODATA, // DFNTAG_DISPELLABLE,
DFN_NUMERIC, // DFNTAG_DISABLED,
DFN_NUMERIC, // DFNTAG_DOORFLAG,
DFN_NUMERIC, // DFNTAG_DURABILITYHPBONUS,
DFN_NUMERIC, // DFNTAG_DYE,
DFN_NUMERIC, // DFNTAG_DYEBEARD,
DFN_NUMERIC, // DFNTAG_DEFENSECHANCE,
Expand Down Expand Up @@ -332,6 +333,7 @@ const std::map<std::string, DFNTAGS> strToDFNTag
{"DISPELLABLE"s, DFNTAG_DISPELLABLE},
{"DISABLED"s, DFNTAG_DISABLED},
{"DOORFLAG"s, DFNTAG_DOORFLAG},
{"DURABILITYHPBONUS"s, DFNTAG_DURABILITYHPBONUS},
{"DYE"s, DFNTAG_DYE},
{"DYEABLE"s, DFNTAG_DYE},
{"DYEHAIR"s, DFNTAG_DYEHAIR},
Expand Down
1 change: 1 addition & 0 deletions source/ssection.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ enum DFNTAGS
DFNTAG_CREATOR,
DFNTAG_CUSTOMSTRINGTAG,
DFNTAG_CUSTOMINTTAG,
DFNTAG_DURABILITYHPBONUS,
DFNTAG_DAMAGE,
DFNTAG_DAMAGEABLE,
DFNTAG_DECAY,
Expand Down

0 comments on commit 05f757f

Please sign in to comment.