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

Swing Speed Increase #291

Merged
merged 22 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions data/js/commands/targeting/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ function onCallback0( socket, ourObj )
case "SECTIONID":
socket.SysMessage( ourObj.sectionID );
break;
case "SWINGSPEEDINC":
socket.SysMessage( swingSpeedIncrease );
break;
case "SHOULDSAVE":
socket.SysMessage( ourObj.shouldSave );
break;
Expand Down
4 changes: 4 additions & 0 deletions data/js/commands/targeting/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ function onCallback0( socket, ourObj )
ourObj.tempdex = nVal;
okMsg( socket );
break;
case "SWINGSPEEDINC":
ourObj.swingSpeedIncrease = nVal;
okMsg( socket );
break;
case "WIPABLE":
case "WIPEABLE":
ourObj.wipable = ( nVal == 1 );
Expand Down
19 changes: 17 additions & 2 deletions source/CPacketSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7574,7 +7574,15 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou
if( cItem.GetSpeed() > 0 )
{
tempEntry.stringNum = 1061167; // weapon speed ~1_val~
tempEntry.ourText = oldstrutil::number( cItem.GetSpeed() );
if( cwmWorldState->ServerData()->ExpansionCoreShardEra() >= ER_ML )
{
R64 wpnSpeedInSeconds = std::round(( 40000.0 / ( 200 * cItem.GetSpeed() ) * 0.5 ) * 10 ) / 10;
tempEntry.ourText = oldstrutil::format( "%.1fs", wpnSpeedInSeconds );
}
else
{
tempEntry.ourText = oldstrutil::number( cItem.GetSpeed() );
}
FinalizeData( tempEntry, totalStringLen );
}

Expand Down Expand Up @@ -7687,7 +7695,14 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou
FinalizeData( tempEntry, totalStringLen );
}

if( cItem.GetHitChance() > 0 )
if( cItem.GetSwingSpeedIncrease() > 0 )
{
tempEntry.stringNum = 1060486; // swing speed increase ~1_val~%
tempEntry.ourText = oldstrutil::number( cItem.GetSwingSpeedIncrease() );
FinalizeData( tempEntry, totalStringLen );
}

if( cItem.GetHitChance() > 0 )
{
tempEntry.stringNum = 1060415; // hit chance increase ~1_val~%
tempEntry.ourText = oldstrutil::number( cItem.GetHitChance() );
Expand Down
10 changes: 10 additions & 0 deletions source/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
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.

16/06/2024 - Dragon Slayer/Xuri
Added new DFN tags for Items and Chars:
SPEEDINCREASE=# // item and char property that increases base weapon swing speed by the specified percentage
These are also available as JS Engine object properties: .speedIncrease
Added INI Settings:
SWINGSPEEDINCREASECAP=# // Max cap for for swing speed increase a char can have.
Combat code updated with era-specific weapon swing speed calculations for different eras (LBR or earlier/AoS/ML onwards).
Note that speeds are still defined with flat values in DFNs regardless of era, but for ML and beyond speed
will be displayed as swing delay in seconds in item tooltip.

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
3 changes: 3 additions & 0 deletions source/SEFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5086,6 +5086,9 @@ JSBool SE_GetServerSetting( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN
case 349: // LOOTDECAYSWITHPLAYERCORPSE
*rval = BOOLEAN_TO_JSVAL( cwmWorldState->ServerData()->NpcCorpseLootDecay() );
break;
case 353: // SWINGSPEEDINCREASECAP
*rval = INT_TO_JSVAL( static_cast<SI16>( cwmWorldState->ServerData()->SwingSpeedIncreaseCap() ));
break;
default:
ScriptError( cx, "GetServerSetting: Invalid server setting name provided" );
return false;
Expand Down
3 changes: 2 additions & 1 deletion source/UOXJSPropertyEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ enum CC_Properties
CCP_SPAWNSERIAL,
CCP_SPATTACK,
CCP_SPDELAY,
CCP_SWINGSPEEDINCREASE,
CCP_HITCHANCE,
CCP_DEFENSECHANCE,
CCP_AITYPE,
Expand Down Expand Up @@ -524,6 +525,7 @@ enum CI_Properties
CIP_ISCONTTYPE,
CIP_CARVESECTION,
CIP_SPEED,
CIP_SWINGSPEEDINCREASE,
CIP_HEALTHBONUS,
CIP_STAMINABONUS,
CIP_MANABONUS,
Expand All @@ -544,7 +546,6 @@ enum CI_Properties
CIP_ISITEMHELD,
CIP_SECTIONID,
CIP_STEALABLE,

CIP_LOCKDDOWNS,
CIP_MAXLOCKDOWNS,
CIP_TRASHCONTAINERS,
Expand Down
4 changes: 4 additions & 0 deletions source/UOXJSPropertyFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ JSBool CItemProps_getProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp
case CIP_DAMAGEPOISON: *vp = BOOLEAN_TO_JSVAL( gPriv->GetWeatherDamage( POISON )); break;
case CIP_DAMAGERAIN: *vp = BOOLEAN_TO_JSVAL( gPriv->GetWeatherDamage( RAIN )); break;
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_HEALTHLEECH: *vp = INT_TO_JSVAL( gPriv->GetHealthLeech() ); break;
case CIP_STAMINALEECH: *vp = INT_TO_JSVAL( gPriv->GetStaminaLeech() ); break;
Expand Down Expand Up @@ -1331,6 +1332,7 @@ 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_SWINGSPEEDINCREASE: gPriv->SetSwingSpeedIncrease( static_cast<SI16>( 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;
Expand Down Expand Up @@ -2014,6 +2016,7 @@ JSBool CCharacterProps_getProperty( JSContext *cx, JSObject *obj, jsval id, jsva
case CCP_HOUSEICONS: *vp = BOOLEAN_TO_JSVAL( gPriv->ViewHouseAsIcon() ); break;
case CCP_SPATTACK: *vp = INT_TO_JSVAL( gPriv->GetSpAttack() ); break;
case CCP_SPDELAY: *vp = INT_TO_JSVAL( gPriv->GetSpDelay() ); break;
case CCP_SWINGSPEEDINCREASE: *vp = INT_TO_JSVAL( gPriv->GetSwingSpeedIncrease() ); break;
case CCP_HITCHANCE: *vp = INT_TO_JSVAL( gPriv->GetHitChance() ); break;
case CCP_DEFENSECHANCE: *vp = INT_TO_JSVAL( gPriv->GetDefenseChance() ); break;
case CCP_AITYPE: *vp = INT_TO_JSVAL( gPriv->GetNpcAiType() ); break;
Expand Down Expand Up @@ -2521,6 +2524,7 @@ JSBool CCharacterProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsva
case CCP_HOUSEICONS: gPriv->SetViewHouseAsIcon( encaps.toBool() ); break;
case CCP_SPATTACK: gPriv->SetSpAttack( static_cast<SI16>( encaps.toInt() )); break;
case CCP_SPDELAY: gPriv->SetSpDelay( static_cast<SI08>( encaps.toInt() )); break;
case CCP_SWINGSPEEDINCREASE: gPriv->SetSwingSpeedIncrease( static_cast<SI16>( encaps.toInt() )); break;
case CCP_HITCHANCE: gPriv->SetHitChance( static_cast<SI16>( encaps.toInt() )); break;
case CCP_DEFENSECHANCE: gPriv->SetDefenseChance( static_cast<SI16>( encaps.toInt() )); break;
case CCP_AITYPE: gPriv->SetNPCAiType( 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 @@ -357,6 +357,7 @@ inline JSPropertySpec CCharacterProps[] =
{ "houseicons", CCP_HOUSEICONS, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "spattack", CCP_SPATTACK, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "spdelay", CCP_SPDELAY, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "swingSpeedIncrease", CCP_SWINGSPEEDINCREASE, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "hitChance", CCP_HITCHANCE, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "defenseChance", CCP_DEFENSECHANCE, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "aitype", CCP_AITYPE, JSPROP_ENUMANDPERM, nullptr, nullptr },
Expand Down Expand Up @@ -537,6 +538,7 @@ inline JSPropertySpec CItemProps[] =
{ "ammoFXHue", CIP_AMMOFXHUE, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "ammoFXRender", CIP_AMMOFXRENDER, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "speed", CIP_SPEED, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "swingSpeedIncrease", CIP_SWINGSPEEDINCREASE , JSPROP_ENUMANDPERM, nullptr, nullptr },

{ "healthLeech", CIP_HEALTHLEECH, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "staminaLeech", CIP_STAMINALEECH, JSPROP_ENUMANDPERM, nullptr, nullptr },
Expand Down
42 changes: 40 additions & 2 deletions source/cBaseObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const SI16 DEFBASE_KILLS = 0;
const UI16 DEFBASE_RESIST = 0;
const bool DEFBASE_NAMEREQUESTACTIVE = 0;
const ExpansionRuleset DEFBASE_ORIGIN = ER_UO;
const SI16 DEFBASE_SWINGSPEEDINCREASE = 0;
const SI16 DEFBASE_HEALTHLEECH = 0;
const SI16 DEFBASE_STAMINALEECH = 0;
const SI16 DEFBASE_MANALEECH = 0;
Expand Down Expand Up @@ -122,7 +123,7 @@ 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 ),
healthLeech( DEFBASE_HEALTHLEECH ), staminaLeech( DEFBASE_STAMINALEECH ), manaLeech( DEFBASE_MANALEECH )
healthLeech( DEFBASE_HEALTHLEECH ), staminaLeech( DEFBASE_STAMINALEECH ), manaLeech( DEFBASE_MANALEECH ), swingSpeedIncrease( DEFBASE_SWINGSPEEDINCREASE )
{
multis = nullptr;
tempMulti = INVALIDSERIAL;
Expand Down Expand Up @@ -805,6 +806,7 @@ bool CBaseObject::DumpBody( std::ostream &outStream ) const
outStream << "Intelligence=" + std::to_string( intelligence ) + "," + std::to_string( temp_in2 ) + newLine;
outStream << "Strength=" + std::to_string( strength ) + "," + std::to_string( temp_st2 ) + newLine;
outStream << "HitPoints=" + std::to_string( hitpoints ) + newLine;
outStream << "SwingSpeedInc=" + std::to_string( GetSwingSpeedIncrease() ) + newLine;
outStream << "Race=" + std::to_string( race ) + newLine;
outStream << "Visible=" + std::to_string( visible ) + newLine;
outStream << "Disabled=" << ( IsDisabled() ? "1" : "0" ) << newLine;
Expand Down Expand Up @@ -1620,6 +1622,27 @@ Point3_st CBaseObject::GetLocation( void ) const
return Point3_st( x, y, z );
}

//o------------------------------------------------------------------------------------------------o
//| Function - CBaseObject::GetSwingSpeedIncrease()
//| CBaseObject::SetSwingSpeedBonus()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets/Sets the item's Swing Speed Bonus property (in percentage), which
//| adjusts the base swing speed of the equipped weapon, or characters
//o------------------------------------------------------------------------------------------------o
SI16 CBaseObject::GetSwingSpeedIncrease( void ) const
{
return swingSpeedIncrease;
}
void CBaseObject::SetSwingSpeedIncrease( SI16 newValue )
{
swingSpeedIncrease = newValue;

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

//o------------------------------------------------------------------------------------------------o
//| Function - CBaseObject::GetStrength2()
//| CBaseObject::SetStrength2()
Expand Down Expand Up @@ -1833,6 +1856,16 @@ void CBaseObject::IncIntelligence( SI16 toInc )
SetIntelligence( intelligence + toInc );
}

//o------------------------------------------------------------------------------------------------o
//| Function - CBaseObject::IncSwingSpeedIncrease()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Increments the object's swing speed bonus value
//o------------------------------------------------------------------------------------------------o
void CBaseObject::IncSwingSpeedIncrease( SI16 toInc )
{
SetSwingSpeedIncrease( swingSpeedIncrease + toInc );
}

//o------------------------------------------------------------------------------------------------o
//| Function - CBaseObject::IncHealthLeech()
//o------------------------------------------------------------------------------------------------o
Expand Down Expand Up @@ -2243,6 +2276,11 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data )
{
st2 = oldstrutil::value<SI16>( data );
}
else if( UTag == "SWINGSPEEDINC" )
{
SetSwingSpeedIncrease( static_cast<SI16>( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )));
rValue = true;
}
else if( UTag == "SCPTRIG" )
{
//scriptTrig = oldstrutil::value<UI16>(data);
Expand Down Expand Up @@ -2765,7 +2803,7 @@ void CBaseObject::CopyData( CBaseObject *target )
target->SetIntelligence2( GetIntelligence2() );
target->SetPoisoned( GetPoisoned() );
target->SetWeight( GetWeight() );

target->SetSwingSpeedIncrease( GetSwingSpeedIncrease() );
target->SetKarma( karma );
target->SetFame( fame );
target->SetKills( kills );
Expand Down
6 changes: 6 additions & 0 deletions source/cBaseObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CBaseObject
SI32 weight;
SI16 mana;
SI16 stamina;
SI16 swingSpeedIncrease;
SI16 healthLeech;
SI16 staminaLeech;
SI16 manaLeech;
Expand Down Expand Up @@ -231,6 +232,11 @@ class CBaseObject
virtual void SetHP( SI16 newValue );
void IncHP( SI16 amtToChange );

virtual SI16 GetSwingSpeedIncrease( void ) const;
virtual void SetSwingSpeedIncrease( SI16 newValue );

void IncSwingSpeedIncrease( SI16 toInc = 1 );

virtual SI16 GetHitChance( void ) const;
virtual void SetHitChance( SI16 newValue );

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

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

IncHealthLeech( itemLayers[tLayer]->GetHealthLeech() );
IncStaminaLeech( itemLayers[tLayer]->GetStaminaLeech() );
IncManaLeech( itemLayers[tLayer]->GetManaLeech() );
Expand Down Expand Up @@ -2993,7 +2995,9 @@ bool CChar::TakeOffItem( ItemLayers Layer )
IncDexterity2( -itemLayers[Layer]->GetDexterity2() );
IncIntelligence2( -itemLayers[Layer]->GetIntelligence2() );

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

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

Expand Down
23 changes: 21 additions & 2 deletions source/cServerData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ const std::map<std::string, SI32> CServerData::uox3IniCaseValue
{"SECRETSHARDKEY"s, 346},
{"MOONGATEFACETS"s, 347},
{"AUTOUNEQUIPPEDCASTING"s, 348},
{"LOOTDECAYSWITHNPCCORPSE"s, 349}
{"LOOTDECAYSWITHNPCCORPSE"s, 349},
{"SWINGSPEEDINCREASECAP"s, 353}
};
constexpr auto MAX_TRACKINGTARGETS = 128;
constexpr auto SKILLTOTALCAP = 7000;
Expand Down Expand Up @@ -723,6 +724,7 @@ auto CServerData::ResetDefaults() -> void
PetCombatTraining( true );
HirelingCombatTraining( true );
NpcCombatTraining( false );
SwingSpeedIncreaseCap( 60 );
WeaponDamageBonusType( 2 );

CheckPetControlDifficulty( true );
Expand Down Expand Up @@ -5196,7 +5198,7 @@ auto CServerData::SaveIni( const std::string &filename ) -> bool
ofsOutput << "SHOWITEMRESISTSTATS=" << ( ShowItemResistStats() ? 1 : 0 ) << '\n';
ofsOutput << "SHOWWEAPONDAMAGETYPES=" << ( ShowWeaponDamageTypes() ? 1 : 0 ) << '\n';
ofsOutput << "WEAPONDAMAGEBONUSTYPE=" << static_cast<UI16>( WeaponDamageBonusType() ) << '\n';

ofsOutput << "WEAPONSWINGSPEEDINCREASECAP=" << SwingSpeedIncreaseCap() << '\n';
ofsOutput << "}" << '\n';

ofsOutput << '\n' << "[magic]" << '\n' << "{" << '\n';
Expand Down Expand Up @@ -5395,6 +5397,20 @@ auto CServerData::TrackingRedisplayTime( UI16 value ) -> void
trackingMsgRedisplayTimer = value;
}

//o------------------------------------------------------------------------------------------------o
//| Function - CServerData::SwingSpeedIncreaseCap()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets/Sets the for swing speed cap propertie
//o------------------------------------------------------------------------------------------------o
auto CServerData::SwingSpeedIncreaseCap() const -> SI16
{
return swingSpeedIncreaseCap;
}
auto CServerData::SwingSpeedIncreaseCap( SI16 value ) -> void
{
swingSpeedIncreaseCap = value;
}


//o------------------------------------------------------------------------------------------------o
//| Function - CServerData::ParseIni()
Expand Down Expand Up @@ -6565,6 +6581,9 @@ auto CServerData::HandleLine( const std::string& tag, const std::string& value )
case 349: // LOOTDECAYSWITHNPCCORPSE
NpcCorpseLootDecay( static_cast<UI16>( std::stoul( value, nullptr, 0 )) != 0 );
break;
case 353: // SWINGSPEEDINCREASE
SwingSpeedIncreaseCap( std::stof( value ));
break;
default:
rValue = false;
break;
Expand Down
4 changes: 4 additions & 0 deletions source/cServerData.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ class CServerData
SI16 combatNpcBaseFleeAt; // % of HP where an NPC will flee, if it's not defined for them
SI16 combatNpcBaseReattackAt; // % of HP where an NPC will resume attacking
SI16 combatAttackStamina; // Amount of stamina lost when hitting an opponent
SI16 swingSpeedIncreaseCap; // The Cap for swing speed property

// Start & Location Settings
std::vector<__STARTLOCATIONDATA__> startlocations;
Expand Down Expand Up @@ -953,6 +954,9 @@ class CServerData
auto BODsFromCraftedItemsOnly( bool value ) -> void;
auto BODsFromCraftedItemsOnly() const -> bool;

auto SwingSpeedIncreaseCap( SI16 value ) -> void;
SI16 SwingSpeedIncreaseCap() const;

auto MaxControlSlots( UI08 value ) -> void;
UI08 MaxControlSlots() const;

Expand Down
Loading
Loading