Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Durability HP Bonus support #326

Merged
merged 10 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions source/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
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) to the hp and max hp as a bonus
DragonSlayer62 marked this conversation as resolved.
Show resolved Hide resolved

09/05/2024 - Dragon Slayer
Added ArtifactRarity AOS Property for items
-ARTIFACTRARITY=#
Expand Down
1 change: 1 addition & 0 deletions source/UOXJSPropertyEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ enum CI_Properties
CIP_DAMAGERAIN,
CIP_DAMAGESNOW,
CIP_ARTIFACTRARITY,
CIP_DURABILITYHPBONUS,
CIP_NAME2,
CIP_ISITEM,
CIP_ISCHAR,
Expand Down
2 changes: 2 additions & 0 deletions source/UOXJSPropertyFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ JSBool CItemProps_getProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp
case CIP_DAMAGERAIN: *vp = BOOLEAN_TO_JSVAL( gPriv->GetWeatherDamage( RAIN )); break;
case CIP_DAMAGESNOW: *vp = BOOLEAN_TO_JSVAL( gPriv->GetWeatherDamage( SNOW )); break;
case CIP_SPEED: *vp = INT_TO_JSVAL( gPriv->GetSpeed() ); break;
case CIP_DURABILITYHPBONUS: *vp = INT_TO_JSVAL( gPriv->GetDurabilityHpBonus() ); break;
case CIP_ARTIFACTRARITY: *vp = INT_TO_JSVAL( gPriv->GetArtifactRarity() ); break;
case CIP_NAME2:
tString = JS_NewStringCopyZ( cx, gPriv->GetName2().c_str() );
Expand Down Expand Up @@ -1323,6 +1324,7 @@ JSBool CItemProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp
case CIP_DAMAGESNOW: gPriv->SetWeatherDamage( SNOW, encaps.toBool() ); break;
case CIP_SPEED: gPriv->SetSpeed( static_cast<UI08>( 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
1 change: 1 addition & 0 deletions source/UOXJSPropertySpecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ inline JSPropertySpec CItemProps[] =
{ "ammoFXRender", CIP_AMMOFXRENDER, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "speed", CIP_SPEED, 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
27 changes: 26 additions & 1 deletion source/cItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ 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;

//o------------------------------------------------------------------------------------------------o
//| Function - CItem()
Expand All @@ -108,7 +109,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)
tempLastTraded( DEFITEM_TEMPLASTTRADED ), stealable( DEFITEM_STEALABLE ), artifactRarity(DEFITEM_ARTIFACTRARITY), durabilityHpBonus( DEFITEM_DURABLITITYHPBONUS )
{
spells[0] = spells[1] = spells[2] = 0;
value[0] = value[1] = value[2] = 0;
Expand Down Expand Up @@ -1374,6 +1375,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 @@ -1655,6 +1673,7 @@ auto CItem::CopyData( CItem *target ) -> void
target->SetSpawn( GetSpawn() );
target->SetSpeed( GetSpeed() );
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 @@ -1755,6 +1774,7 @@ bool CItem::DumpBody( std::ostream &outStream ) const
outStream << "MaxHP=" + std::to_string( GetMaxHP() ) + newLine;
outStream << "Speed=" + std::to_string( GetSpeed() ) + 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 << "Value=" + std::to_string( GetBuyValue() ) + "," + std::to_string( GetSellValue() ) + "," + std::to_string( GetVendorPrice() ) + newLine;
Expand Down Expand Up @@ -1877,6 +1897,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
8 changes: 6 additions & 2 deletions source/cItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CItem : public CBaseObject
SERIAL creator; // Store the serial of the player made this item
SI08 gridLoc;
SI16 artifactRarity;
SI16 durabilityHpBonus;
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 @@ -111,8 +112,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);

auto GetStealable() const -> UI08;
auto SetStealable( UI08 newValue ) -> void;
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 @@ -1194,10 +1195,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_DYEHAIR,
Expand Down Expand Up @@ -319,6 +320,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
Loading