Skip to content

Commit

Permalink
Merge pull request #292 from DragonSlayer62/leech-aos-propties
Browse files Browse the repository at this point in the history
Added AOS  Leech Properties
  • Loading branch information
Xoduz authored Jan 25, 2025
2 parents 0c14fe6 + d002b87 commit 841469c
Show file tree
Hide file tree
Showing 14 changed files with 240 additions and 4 deletions.
56 changes: 56 additions & 0 deletions data/js/combat/leechstats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function onEquip( pEquipper, iEquipped )
{
pEquipper.AddScriptTrigger( 7003 );
}

// Remove script trigger on unequip
function onUnequip( pUnequipper, iUnequipped )
{
pUnequipper.RemoveScriptTrigger( 7003 );
}

function onDamageDeal( attacker, damaged, damageValue, damageType )
{
// Fetch weapon in main hand or secondary hand
var iWeapon = attacker.FindItemLayer( 0x01 );
if( !ValidateObject( iWeapon ))
{
iWeapon = attacker.FindItemLayer( 0x02 );
}

if( ValidateObject( iWeapon ))
{ // Apply leech effects based on weapon properties
ApplyLeech( attacker, damaged, damageValue, iWeapon, 'healthLeech', 30 );
ApplyLeech( attacker, damaged, damageValue, iWeapon, 'staminaLeech', 100 );
ApplyLeech( attacker, damaged, damageValue, iWeapon, 'manaLeech', 40 );
}

return true;
}

function ApplyLeech( attacker, damaged, damageValue, weapon, leechType, multiplier )
{
// Get the leech amount for the specified leech type from the weapon
var leechPercentVal = weapon[ leechType ];
if( leechPercentVal > 0 )
{
// Calculate the percent of health restored to the attacker
var leechAmt = Math.round( damageValue * ( leechPercentVal / 100 ) * ( multiplier/100 ));

// Apply the leech effect based on the leech type
switch( leechType )
{
case 'healthLeech':
attacker.Heal( leechAmt );
break;
case 'staminaLeech':
attacker.stamina += leechAmt;
break;
case 'manaLeech':
attacker.mana += leechAmt;
break;
}

attacker.SoundEffect( 0x44D, true );
}
}
1 change: 1 addition & 0 deletions data/js/jse_fileassociations.scp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
// Combat Scripts [7000-7499]
//-------------------------------------------
7000=combat/peacemake_effect.js
7003=combat/leechstats.js

//-------------------------------------------
// Misc Player Scripts [8000-8499]
Expand Down
22 changes: 22 additions & 0 deletions source/CPacketSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7473,6 +7473,28 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou
tempEntry.ourText = oldstrutil::number( cItem.GetTempVar( CITV_MOREZ ));
FinalizeData( tempEntry, totalStringLen );
}

if( cItem.GetManaLeech() > 0 )
{
tempEntry.stringNum = 1060427; // hit mana leech ~1_val~%
tempEntry.ourText = oldstrutil::number( cItem.GetManaLeech() );
FinalizeData( tempEntry, totalStringLen );
}

if( cItem.GetStaminaLeech() > 0 )
{
tempEntry.stringNum = 1060430; // hit stamina leech ~1_val~%
tempEntry.ourText = oldstrutil::number( cItem.GetStaminaLeech() );
FinalizeData( tempEntry, totalStringLen );
}

if( cItem.GetHealthLeech() > 0 )
{
tempEntry.stringNum = 1060422; // hit life leech ~1_val~%
tempEntry.ourText = oldstrutil::number( cItem.GetHealthLeech() );
FinalizeData( tempEntry, totalStringLen );
}

if( cItem.GetType() == IT_SPELLCHANNELING )
{
tempEntry.stringNum = 1060482; // spell channeling
Expand Down
9 changes: 9 additions & 0 deletions source/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
18/06/2024 - Dragon Slayer
Added three new DFN tags for Items:
HEALTHLEECH=# // It gives an attacker the ability to leech health from his opponent every time he successfully delivers a hit adds it to himself.
STAMINALEECH=# // It gives an attacker the ability to leech Stamina from his opponent every time he successfully delivers a hit adds it to himself.
MANALEECH=# // It gives an attacker the ability to leech Mana from his opponent every time he successfully delivers a hit adds it to himself.
These are also available as JS Engine object properties: .healthLeech, .staminaLeech and .manaLeech
Added leechstats.js file that controls the combat for the properties. (script 7003)
To add this script to a weapon only. add in SCRIPT=7003, HEALTHLEECH=# or STAMINALEECH=# or MANALEECH=# it can also be all three on the weapon.

14/06/2024 - Dragon Slayer
Added two new DFN tags for Items:
HITCHANCE=# // Increases the player's chance to hit a target with wrestling, melee and ranged weapons.
Expand Down
4 changes: 3 additions & 1 deletion source/UOXJSPropertyEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,9 @@ enum CI_Properties
CIP_SECTIONALIST,
CIP_MININTERVAL,
CIP_MAXINTERVAL,

CIP_HEALTHLEECH,
CIP_STAMINALEECH,
CIP_MANALEECH,
CIP_ISNEWBIE,
CIP_ISDISPELLABLE,
CIP_MADEWITH,
Expand Down
6 changes: 6 additions & 0 deletions source/UOXJSPropertyFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,9 @@ 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_HEALTHLEECH: *vp = INT_TO_JSVAL( gPriv->GetHealthLeech() ); break;
case CIP_STAMINALEECH: *vp = INT_TO_JSVAL( gPriv->GetStaminaLeech() ); break;
case CIP_MANALEECH: *vp = INT_TO_JSVAL( gPriv->GetManaLeech() ); break;
case CIP_HITCHANCE: *vp = INT_TO_JSVAL( gPriv->GetHitChance() ); break;
case CIP_DEFENSECHANCE: *vp = INT_TO_JSVAL( gPriv->GetDefenseChance() ); break;
case CIP_HEALTHBONUS: *vp = INT_TO_JSVAL( gPriv->GetHealthBonus() ); break;
Expand Down Expand Up @@ -1328,6 +1331,9 @@ JSBool CItemProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp
case CIP_DAMAGERAIN: gPriv->SetWeatherDamage( RAIN, encaps.toBool() ); break;
case CIP_DAMAGESNOW: gPriv->SetWeatherDamage( SNOW, encaps.toBool() ); break;
case CIP_SPEED: gPriv->SetSpeed( static_cast<UI08>( encaps.toInt() )); break;
case CIP_HEALTHLEECH: gPriv->SetHealthLeech( static_cast<SI16>( encaps.toInt() )); break;
case CIP_STAMINALEECH: gPriv->SetStaminaLeech( static_cast<SI16>( encaps.toInt() )); break;
case CIP_MANALEECH: gPriv->SetManaLeech( static_cast<SI16>( encaps.toInt() )); break;
case CIP_HITCHANCE: gPriv->SetHitChance( static_cast<SI16>( encaps.toInt() )); break;
case CIP_DEFENSECHANCE: gPriv->SetDefenseChance( static_cast<SI16>( encaps.toInt() )); break;
case CIP_HEALTHBONUS: gPriv->SetHealthBonus( static_cast<SI16>( encaps.toInt() )); break;
Expand Down
4 changes: 4 additions & 0 deletions source/UOXJSPropertySpecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ inline JSPropertySpec CItemProps[] =
{ "ammoFXRender", CIP_AMMOFXRENDER, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "speed", CIP_SPEED, JSPROP_ENUMANDPERM, nullptr, nullptr },

{ "healthLeech", CIP_HEALTHLEECH, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "staminaLeech", CIP_STAMINALEECH, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "manaLeech", CIP_MANALEECH, JSPROP_ENUMANDPERM, nullptr, nullptr },

{ "hitChance", CIP_HITCHANCE, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "defenseChance", CIP_DEFENSECHANCE, JSPROP_ENUMANDPERM, nullptr, nullptr },

Expand Down
92 changes: 91 additions & 1 deletion source/cBaseObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ const SI16 DEFBASE_KILLS = 0;
const UI16 DEFBASE_RESIST = 0;
const bool DEFBASE_NAMEREQUESTACTIVE = 0;
const ExpansionRuleset DEFBASE_ORIGIN = ER_UO;
const SI16 DEFBASE_HEALTHLEECH = 0;
const SI16 DEFBASE_STAMINALEECH = 0;
const SI16 DEFBASE_MANALEECH = 0;

const SI16 DEFBASE_HITCHANCE = 0;
const SI16 DEFBASE_DEFENSECHANCE = 0;
Expand All @@ -118,7 +121,8 @@ mana( DEFBASE_MANA ), stamina( DEFBASE_STAMINA ), scriptTrig( DEFBASE_SCPTRIG ),
in2( DEFBASE_INT2 ), FilePosition( DEFBASE_FP ),
poisoned( DEFBASE_POISONED ), carve( DEFBASE_CARVE ), oldLocX( 0 ), oldLocY( 0 ), oldLocZ( 0 ), oldTargLocX( 0 ), oldTargLocY( 0 ),
fame( DEFBASE_FAME ), karma( DEFBASE_KARMA ), kills( DEFBASE_KILLS ), subRegion( DEFBASE_SUBREGION ), nameRequestActive( DEFBASE_NAMEREQUESTACTIVE ), origin( DEFBASE_ORIGIN ),
healthBonus( DEFBASE_HEALTHBONUS ),staminaBonus( DEFBASE_STAMINABONOS ), manaBonus( DEFBASE_MANABONUS ), hitChance( DEFBASE_HITCHANCE ), defenseChance( DEFBASE_DEFENSECHANCE )
healthBonus( DEFBASE_HEALTHBONUS ),staminaBonus( DEFBASE_STAMINABONOS ), manaBonus( DEFBASE_MANABONUS ), hitChance( DEFBASE_HITCHANCE ), defenseChance( DEFBASE_DEFENSECHANCE ),
healthLeech( DEFBASE_HEALTHLEECH ), staminaLeech( DEFBASE_STAMINALEECH ), manaLeech( DEFBASE_MANALEECH )
{
multis = nullptr;
tempMulti = INVALIDSERIAL;
Expand Down Expand Up @@ -1680,6 +1684,25 @@ void CBaseObject::SetIntelligence2( SI16 nVal )
}

//o------------------------------------------------------------------------------------------------o
//| Function - CBaseObject::GetHealthLeech()
//| CBaseObject::SetHealthLeech()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets/Sets the Health Leech
//o------------------------------------------------------------------------------------------------o
SI16 CBaseObject::GetHealthLeech( void ) const
{
return healthLeech;
}
void CBaseObject::SetHealthLeech( SI16 nVal )
{
healthLeech = nVal;

if( CanBeObjType( OT_ITEM ))
{
( static_cast<CItem *>( this ))->UpdateRegion();
}
}

//| Function - CBaseObject::GetHealthBonus()
//| CBaseObject::SetHealthBonus()
//o------------------------------------------------------------------------------------------------o
Expand All @@ -1701,6 +1724,25 @@ void CBaseObject::SetHealthBonus( SI16 nVal )
}

//o------------------------------------------------------------------------------------------------o
//| Function - CBaseObject::GetStaminaLeech()
//| CBaseObject::SetStaminaLeech()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets/Sets the Stamina Leech
//o------------------------------------------------------------------------------------------------o
SI16 CBaseObject::GetStaminaLeech( void ) const
{
return staminaLeech;
}
void CBaseObject::SetStaminaLeech( SI16 nVal )
{
staminaLeech = nVal;

if( CanBeObjType( OT_ITEM ))
{
( static_cast<CItem *>( this ))->UpdateRegion();
}
}

//| Function - CBaseObject::GetStaminaBonus()
//| CBaseObject::SetStaminaBonus()
//o------------------------------------------------------------------------------------------------o
Expand All @@ -1722,6 +1764,25 @@ void CBaseObject::SetStaminaBonus( SI16 nVal )
}

//o------------------------------------------------------------------------------------------------o
//| Function - CBaseObject::GetManaLeech()
//| CBaseObject::SetManaLeech()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets/Sets the Mana Leech
//o------------------------------------------------------------------------------------------------o
SI16 CBaseObject::GetManaLeech( void ) const
{
return manaLeech;
}
void CBaseObject::SetManaLeech( SI16 nVal )
{
manaLeech = nVal;

if( CanBeObjType( OT_ITEM ))
{
( static_cast<CItem *>( this ))->UpdateRegion();
}
}

//| Function - CBaseObject::GetManaBonus()
//| CBaseObject::SetManaBonus()
//o------------------------------------------------------------------------------------------------o
Expand Down Expand Up @@ -1773,6 +1834,35 @@ void CBaseObject::IncIntelligence( SI16 toInc )
}

//o------------------------------------------------------------------------------------------------o
//| Function - CBaseObject::IncHealthLeech()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Increments the object's Health Leech Points value
//o------------------------------------------------------------------------------------------------o
void CBaseObject::IncHealthLeech( SI16 toInc )
{
SetHealthLeech( healthLeech + toInc );
}

//o------------------------------------------------------------------------------------------------o
//| Function - CBaseObject::IncStaminaLeech()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Increments the object's Stamina Leech Points value
//o------------------------------------------------------------------------------------------------o
void CBaseObject::IncStaminaLeech( SI16 toInc )
{
SetStaminaLeech( staminaLeech + toInc );
}

//o------------------------------------------------------------------------------------------------o
//| Function - CBaseObject::IncManaLeech()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Increments the object's Mana Leech Points value
//o------------------------------------------------------------------------------------------------o
void CBaseObject::IncManaLeech( SI16 toInc )
{
SetManaLeech( manaLeech + toInc );
}

//| Function - CBaseObject::IncHitChance()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Increments the object's Hit Chance value
Expand Down
17 changes: 16 additions & 1 deletion source/cBaseObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class CBaseObject
SI32 weight;
SI16 mana;
SI16 stamina;
SI16 healthLeech;
SI16 staminaLeech;
SI16 manaLeech;
UI16 scriptTrig;
SI16 st2;
SI16 dx2;
Expand Down Expand Up @@ -268,6 +271,19 @@ class CBaseObject
void IncIntelligence( SI16 toInc = 1 );


SI16 GetHealthLeech( void ) const;
virtual void SetHealthLeech( SI16 nVal );

SI16 GetStaminaLeech( void ) const;
virtual void SetStaminaLeech( SI16 nVal );

SI16 GetManaLeech( void ) const;
virtual void SetManaLeech( SI16 nVal );

void IncHealthLeech( SI16 toInc = 1 );
void IncStaminaLeech( SI16 toInc = 1 );
void IncManaLeech( SI16 toInc = 1 );

void IncHitChance( SI16 toInc = 1 );
void IncDefenseChance( SI16 toInc = 1 );

Expand All @@ -280,7 +296,6 @@ class CBaseObject
SI16 GetManaBonus( void ) const;
virtual void SetManaBonus( SI16 nVal );


virtual void PostLoadProcessing( void );
virtual bool LoadRemnants( void ) = 0;

Expand Down
10 changes: 9 additions & 1 deletion source/cChar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2922,7 +2922,11 @@ bool CChar::WearItem( CItem *toWear )
IncDexterity2( itemLayers[tLayer]->GetDexterity2() );
IncIntelligence2( itemLayers[tLayer]->GetIntelligence2() );

IncHitChance( itemLayers[tLayer]->GetHitChance() );
IncHealthLeech( itemLayers[tLayer]->GetHealthLeech() );
IncStaminaLeech( itemLayers[tLayer]->GetStaminaLeech() );
IncManaLeech( itemLayers[tLayer]->GetManaLeech() );

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

IncHealthBonus( itemLayers[tLayer]->GetHealthBonus() );
Expand Down Expand Up @@ -2989,6 +2993,10 @@ bool CChar::TakeOffItem( ItemLayers Layer )
IncDexterity2( -itemLayers[Layer]->GetDexterity2() );
IncIntelligence2( -itemLayers[Layer]->GetIntelligence2() );

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

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

Expand Down
11 changes: 11 additions & 0 deletions source/cItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,9 @@ auto CItem::CopyData( CItem *target ) -> void
target->SetStamina( GetStamina() );
target->SetStrength( GetStrength() );
target->SetStrength2( GetStrength2() );
target->SetHealthLeech( GetHealthLeech() );
target->SetStaminaLeech( GetStaminaLeech() );
target->SetManaLeech( GetManaLeech() );
target->SetTitle( GetTitle() );
target->SetType( GetType() );
target->SetBuyValue( GetBuyValue() );
Expand Down Expand Up @@ -1767,6 +1770,7 @@ bool CItem::DumpBody( std::ostream &outStream ) const
outStream << "ArtifactRarity=" + std::to_string( GetArtifactRarity() ) + newLine;
outStream << "Movable=" + std::to_string( GetMovable() ) + newLine;
outStream << "Priv=" + std::to_string( GetPriv() ) + newLine;
outStream << "LeechStats=" + std::to_string( GetHealthLeech() ) + "," + std::to_string( GetStaminaLeech() ) + "," + std::to_string( GetManaLeech() ) + newLine;
outStream << "Value=" + std::to_string( GetBuyValue() ) + "," + std::to_string( GetSellValue() ) + "," + std::to_string( GetVendorPrice() ) + newLine;
outStream << "Restock=" + std::to_string( GetRestock() ) + newLine;
outStream << "AC=" + std::to_string( GetArmourClass() ) + newLine;
Expand Down Expand Up @@ -1972,6 +1976,13 @@ bool CItem::HandleLine( std::string &UTag, std::string &data )
SetWeatherDamage( LIGHTNING, static_cast<UI16>( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 );
rValue = true;
}
else if( UTag == "LEECHSTATS" )
{
SetHealthLeech( static_cast<SI16>( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )));
SetStaminaLeech( static_cast<SI16>( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )));
SetManaLeech( static_cast<SI16>( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 )));
rValue = true;
}
break;
case 'M':
if( UTag == "MAXITEMS" )
Expand Down
3 changes: 3 additions & 0 deletions source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect
}
break;
case DFNTAG_AC: applyTo->SetArmourClass( static_cast<UI08>( ndata )); break;
case DFNTAG_HEALTHLEECH: applyTo->SetHealthLeech( static_cast<SI16>( ndata )); break;
case DFNTAG_STAMINALEECH: applyTo->SetStaminaLeech( static_cast<SI16>( ndata )); break;
case DFNTAG_MANALEECH: applyTo->SetManaLeech( static_cast<SI16>( ndata )); break;
case DFNTAG_BASERANGE: applyTo->SetBaseRange( static_cast<UI08>( ndata )); break;
case DFNTAG_HEALTHBONUS: applyTo->SetHealthBonus( static_cast<SI16>( ndata )); break;
case DFNTAG_STAMINABONUS: applyTo->SetStaminaBonus( static_cast<SI16>( ndata )); break;
Expand Down
Loading

0 comments on commit 841469c

Please sign in to comment.