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 21 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
17 changes: 16 additions & 1 deletion source/CPacketSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7552,7 +7552,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 @@ -7665,6 +7673,13 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou
FinalizeData( tempEntry, totalStringLen );
}

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

if( cItem.GetStrength() > 1 )
{
tempEntry.stringNum = 1061170; // strength requirement ~1_val~
Expand Down
11 changes: 11 additions & 0 deletions source/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
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.

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

Expand All @@ -6,6 +16,7 @@
-ARTIFACTRARITY=#
-Artifact Rarity is an item property that is visible on some artifacts and meant to give players an idea of how rare the item is. Items with rarity 1 are supposed to be common while rarity 12 are extremely scarce.


1/05/2024 - Dragon Slayer/Xuri
Fixed AutoUnequipAttempt function in clumsy.js, createfood.js level1target.js, will no longer fail on casting and return to hardcode.
Fixed createfood to check for reagents on cast.
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_AITYPE,
CCP_SPLIT,
CCP_SPLITCHANCE,
Expand Down Expand Up @@ -517,6 +518,7 @@ enum CI_Properties
CIP_ISCONTTYPE,
CIP_CARVESECTION,
CIP_SPEED,
CIP_SWINGSPEEDINCREASE,
CIP_MULTI,
CIP_AMMOID,
CIP_AMMOHUE,
Expand All @@ -534,7 +536,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_ARTIFACTRARITY: *vp = INT_TO_JSVAL( gPriv->GetArtifactRarity() ); break;
case CIP_NAME2:
Expand Down Expand Up @@ -1322,6 +1323,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_ARTIFACTRARITY: gPriv->SetArtifactRarity( 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;
Expand Down Expand Up @@ -1996,6 +1998,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_AITYPE: *vp = INT_TO_JSVAL( gPriv->GetNpcAiType() ); break;
case CCP_SPLIT: *vp = INT_TO_JSVAL( gPriv->GetSplit() ); break;
case CCP_SPLITCHANCE: *vp = INT_TO_JSVAL( gPriv->GetSplitChance() ); break;
Expand Down Expand Up @@ -2501,6 +2504,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_AITYPE: gPriv->SetNPCAiType( static_cast<SI16>( encaps.toInt() )); break;
case CCP_SPLIT: gPriv->SetSplit( static_cast<UI08>( encaps.toInt() )); break;
case CCP_SPLITCHANCE: gPriv->SetSplitChance( static_cast<UI08>( 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 },
{ "aitype", CCP_AITYPE, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "split", CCP_SPLIT, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "splitchance", CCP_SPLITCHANCE, JSPROP_ENUMANDPERM, nullptr, nullptr },
Expand Down Expand Up @@ -535,6 +536,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 },
{ "artifactRarity", CIP_ARTIFACTRARITY, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "multi", CIP_MULTI, JSPROP_ENUMANDPERM, nullptr, nullptr },
{ "maxRange", CIP_MAXRANGE, JSPROP_ENUMANDPERM, nullptr, nullptr },
Expand Down
43 changes: 41 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;

//o------------------------------------------------------------------------------------------------o
//| Function - CBaseObject constructor
Expand All @@ -110,7 +111,8 @@ loDamage( DEFBASE_LODAMAGE ), weight( DEFBASE_WEIGHT ),
mana( DEFBASE_MANA ), stamina( DEFBASE_STAMINA ), scriptTrig( DEFBASE_SCPTRIG ), st2( DEFBASE_STR2 ), dx2( DEFBASE_DEX2 ),
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 )
fame( DEFBASE_FAME ), karma( DEFBASE_KARMA ), kills( DEFBASE_KILLS ), subRegion( DEFBASE_SUBREGION ), nameRequestActive( DEFBASE_NAMEREQUESTACTIVE ), origin( DEFBASE_ORIGIN ),
swingSpeedIncrease( DEFBASE_SWINGSPEEDINCREASE )
{
multis = nullptr;
tempMulti = INVALIDSERIAL;
Expand Down Expand Up @@ -793,6 +795,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 @@ -1568,6 +1571,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 @@ -1661,6 +1685,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::DumpFooter()
//o------------------------------------------------------------------------------------------------o
Expand Down Expand Up @@ -2022,6 +2056,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 @@ -2544,7 +2583,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 @@ -75,6 +75,7 @@ class CBaseObject
SI32 weight;
SI16 mana;
SI16 stamina;
SI16 swingSpeedIncrease;
UI16 scriptTrig;
SI16 st2;
SI16 dx2;
Expand Down Expand Up @@ -223,6 +224,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 );

void SetDir( UI08 newDir, bool sendUpdate = true );
UI08 GetDir( void ) const;

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

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

if( toWear->IsPostLoaded() )
{
if( itemLayers[tLayer]->GetPoisoned() )
Expand Down Expand Up @@ -2979,6 +2981,9 @@ bool CChar::TakeOffItem( ItemLayers Layer )
IncStrength2( -itemLayers[Layer]->GetStrength2() );
IncDexterity2( -itemLayers[Layer]->GetDexterity2() );
IncIntelligence2( -itemLayers[Layer]->GetIntelligence2() );

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

if( itemLayers[Layer]->GetPoisoned() )
{
if( itemLayers[Layer]->GetPoisoned() > GetPoisoned() )
Expand Down
23 changes: 21 additions & 2 deletions source/cServerData.cpp
Xoduz marked this conversation as resolved.
Show resolved Hide resolved
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