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
Changes from 1 commit
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
Next Next commit
fixed pr
DragonSlayer62 committed Jan 17, 2025
commit 022612f19da5aee1e158d7dae55fbbb8c51aefe1
7 changes: 7 additions & 0 deletions source/CPacketSend.cpp
Original file line number Diff line number Diff line change
@@ -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~
4 changes: 4 additions & 0 deletions source/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
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

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

1 change: 1 addition & 0 deletions source/UOXJSPropertyEnums.h
Original file line number Diff line number Diff line change
@@ -462,6 +462,7 @@ enum CI_Properties
CIP_DAMAGERAIN,
CIP_DAMAGESNOW,
CIP_ARTIFACTRARITY,
CIP_DURABILITYHPBONUS,
CIP_NAME2,
CIP_ISITEM,
CIP_ISCHAR,
2 changes: 2 additions & 0 deletions source/UOXJSPropertyFuncs.cpp
Original file line number Diff line number Diff line change
@@ -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() );
@@ -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;
1 change: 1 addition & 0 deletions source/UOXJSPropertySpecs.h
Original file line number Diff line number Diff line change
@@ -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 },
27 changes: 26 additions & 1 deletion source/cItem.cpp
Original file line number Diff line number Diff line change
@@ -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()
@@ -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;
@@ -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()
@@ -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 ));
@@ -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;
@@ -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 );
4 changes: 4 additions & 0 deletions source/cItem.h
Original file line number Diff line number Diff line change
@@ -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
@@ -114,6 +115,9 @@ class CItem : public CBaseObject
virtual SI16 GetArtifactRarity(void) const;
virtual void SetArtifactRarity(SI16 newValue);

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

auto GetStealable() const -> UI08;
auto SetStealable( UI08 newValue ) -> void;

7 changes: 7 additions & 0 deletions source/items.cpp
Original file line number Diff line number Diff line change
@@ -1194,6 +1194,13 @@ 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( durabilityHpBonus > 0 )
{
iCreated->SetHP( iCreated->GetHP() + durabilityHpBonus );
}

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