Skip to content

Commit

Permalink
Merge branch 'develop' into checktimesincelastcombat-function
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonSlayer62 authored Jan 29, 2025
2 parents 4eb0033 + 05f757f commit 1578223
Showing 12 changed files with 131 additions and 43 deletions.
6 changes: 3 additions & 3 deletions data/js/item/equip_effects/skill_boosting_equipment.js
Original file line number Diff line number Diff line change
@@ -31,18 +31,18 @@ function onEquip( pEquipper, iEquipped )
}
}

function onUnequip( pUnquipper, iUnequipped )
function onUnequip( pUnequipper, iUnequipped )
{
var skillBonusID = iUnequipped.GetTag( "skillBonusID" );
var skillBonusVal = iUnequipped.GetTag( "skillBonusVal" );

switch( skillBonusID )
{
case 7: // Blacksmithing
pUnquipper.skills.blacksmithing -= skillBonusVal;
pUnequipper.skills.blacksmithing -= skillBonusVal;
break;
case 45: // Mining
pUnquipper.skills.mining -= skillBonusVal;
pUnequipper.skills.mining -= skillBonusVal;
break;
default:
break;
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~
10 changes: 10 additions & 0 deletions source/Changelog.txt
Original file line number Diff line number Diff line change
@@ -3,6 +3,11 @@

1/05/2024 - Dragon Slayer/Xuri

22/01/2025 - Dragon Slayer
Fixed an issue that prevented onUnequip JS event from triggering on items being unequipped
Minor cleanup of skill_boosting_equipment.js script


21/01/2025 - Dragon Slayer
Fixed damage dealt in combat was incorrectly modified while applying defense modifiers. (combat.cpp)

@@ -114,6 +119,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

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

CIP_ARTIFACTRARITY,
CIP_DURABILITYHPBONUS,
CIP_NAME2,
CIP_ISITEM,
CIP_ISCHAR,
3 changes: 2 additions & 1 deletion source/UOXJSPropertyFuncs.cpp
Original file line number Diff line number Diff line change
@@ -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;
@@ -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;
2 changes: 2 additions & 0 deletions source/UOXJSPropertySpecs.h
Original file line number Diff line number Diff line change
@@ -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 },
71 changes: 37 additions & 34 deletions source/cChar.cpp
Original file line number Diff line number Diff line change
@@ -2924,24 +2924,24 @@ bool CChar::WearItem( CItem *toWear )
}

scriptTriggers.clear();
scriptTriggers.shrink_to_fit();
scriptTriggers = this->GetScriptTriggers();
for( auto i : scriptTriggers )
{
cScript *tScript = JSMapping->GetScript( i );
if( tScript != nullptr )
{
// If script returns false, prevent item from being equipped
if( tScript->OnEquipAttempt( this, toWear ) == 0 )
{
CSocket *mSock = this->GetSocket();
if( mSock != nullptr )
{
Bounce( mSock, toWear );
}
return false;
}
}
scriptTriggers.shrink_to_fit();
scriptTriggers = this->GetScriptTriggers();
for( auto i : scriptTriggers )
{
cScript *tScript = JSMapping->GetScript( i );
if( tScript != nullptr )
{
// If script returns false, prevent item from being equipped
if( tScript->OnEquipAttempt( this, toWear ) == 0 )
{
CSocket *mSock = this->GetSocket();
if( mSock != nullptr )
{
Bounce( mSock, toWear );
}
return false;
}
}
}

bool rValue = true;
@@ -2970,7 +2970,7 @@ bool CChar::WearItem( CItem *toWear )
IncStaminaLeech( itemLayers[tLayer]->GetStaminaLeech() );
IncManaLeech( itemLayers[tLayer]->GetManaLeech() );

IncHitChance( itemLayers[tLayer]->GetHitChance() );
IncHitChance( itemLayers[tLayer]->GetHitChance() );
IncDefenseChance( itemLayers[tLayer]->GetDefenseChance() );

IncHealthBonus( itemLayers[tLayer]->GetHealthBonus() );
@@ -3030,20 +3030,20 @@ bool CChar::TakeOffItem( ItemLayers Layer )
}

scriptTriggers.clear();
scriptTriggers.shrink_to_fit();
scriptTriggers = this->GetScriptTriggers();
for( auto i : scriptTriggers )
{
cScript *tScript = JSMapping->GetScript( i );
if( tScript != nullptr )
{
// If script returns false, prevent item from being equipped
if( tScript->OnUnequipAttempt( this, itemLayers[Layer] ) == 0 )
{
return false;
}
}
}
scriptTriggers.shrink_to_fit();
scriptTriggers = this->GetScriptTriggers();
for( auto i : scriptTriggers )
{
cScript *tScript = JSMapping->GetScript( i );
if( tScript != nullptr )
{
// If script returns false, prevent item from being equipped
if( tScript->OnUnequipAttempt( this, itemLayers[Layer] ) == 0 )
{
return false;
}
}
}

if( Layer == IL_PACKITEM ) // It's our pack!
{
@@ -3055,7 +3055,7 @@ bool CChar::TakeOffItem( ItemLayers Layer )

IncSwingSpeedIncrease( -itemLayers[Layer]->GetSwingSpeedIncrease() );

IncHealthLeech( -itemLayers[Layer]->GetHealthLeech() );
IncHealthLeech( -itemLayers[Layer]->GetHealthLeech() );
IncStaminaLeech( -itemLayers[Layer]->GetStaminaLeech() );
IncManaLeech( -itemLayers[Layer]->GetManaLeech() );

@@ -3078,6 +3078,9 @@ bool CChar::TakeOffItem( ItemLayers Layer )
}
}

scriptTriggers.clear();
scriptTriggers.shrink_to_fit();
scriptTriggers = itemLayers[Layer]->GetScriptTriggers();
for( auto i : scriptTriggers )
{
cScript *tScript = JSMapping->GetScript( i );
31 changes: 30 additions & 1 deletion source/cItem.cpp
Original file line number Diff line number Diff line change
@@ -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
@@ -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;
@@ -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()
@@ -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 ));
@@ -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;
@@ -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 );
11 changes: 9 additions & 2 deletions source/cItem.h
Original file line number Diff line number Diff line change
@@ -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
@@ -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 );
29 changes: 27 additions & 2 deletions source/items.cpp
Original file line number Diff line number Diff line change
@@ -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 )
@@ -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!
2 changes: 2 additions & 0 deletions source/ssection.cpp
Original file line number Diff line number Diff line change
@@ -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,
@@ -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},
1 change: 1 addition & 0 deletions source/ssection.h
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ enum DFNTAGS
DFNTAG_CREATOR,
DFNTAG_CUSTOMSTRINGTAG,
DFNTAG_CUSTOMINTTAG,
DFNTAG_DURABILITYHPBONUS,
DFNTAG_DAMAGE,
DFNTAG_DAMAGEABLE,
DFNTAG_DECAY,

0 comments on commit 1578223

Please sign in to comment.