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

Added GetTempEffect and ReverseTempEffect #331

Merged
merged 2 commits into from
Feb 8, 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
4 changes: 4 additions & 0 deletions source/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
06/02/2025 - Dragon Slayer
Added .GetTempEffect js method, Get timer of specified temp effect for object, or 0 if it doesn't exist. ( Thanks Xuri )
Added .ReverseTempEffect js method, Force the reversion of a Temp Effect on item or character based on specified temp effect ID. ( Thanks Xuri )

01/02/2025 - Dragon Slayer
Fixed an issue where UOX3 would unnecessarily update a given player's status window repeatedly multiple times per server cycle (Thanks Xuri)
Fixed Young Status Not removing off characters. (Thanks Xuri)
Expand Down
85 changes: 85 additions & 0 deletions source/UOXJSMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2106,6 +2106,91 @@ JSBool CBase_KillJSTimer( JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
return JS_TRUE;
}

//o------------------------------------------------------------------------------------------------o
//| Function - CBase_GetTempEffect()
//| Prototype - UI32 CBase_GetTempEffect( tempEffectID )
//o------------------------------------------------------------------------------------------------o
//| Purpose - Get timer of specified temp effect for object, or 0 if it doesn't exist
//o------------------------------------------------------------------------------------------------o
JSBool CBase_GetTempEffect( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if( argc != 1 )
{
ScriptError( cx, "GetTempEffect: Invalid count of arguments :%d, needs 1 (tempEffectID)", argc );
return JS_FALSE;
}

auto myObj = static_cast<CBaseObject*>( JS_GetPrivate( cx, obj ));
if( myObj == nullptr )
{
ScriptError( cx, "GetTempEffect: Invalid object assigned." );
return JS_FALSE;
}

*rval = INT_TO_JSVAL( 0 ); // Return value 0 by default, to indicate no valid tempe effect
UI16 tempEffectID = static_cast<UI16>( JSVAL_TO_INT( argv[0] ));\

SERIAL myObjSerial = myObj->GetSerial();
for( const auto &Effect : cwmWorldState->tempEffects.collection() )
{
// We only want results that have same object serial and tempEffectID as specified
if( myObjSerial == Effect->Destination() && Effect->Number() == tempEffectID )
{
// Return the timestamp for when the Temp Effect timer expires
JS_NewNumberValue( cx, Effect->ExpireTime(), rval );
}
}

return JS_TRUE;
}

void ReverseEffect( CTEffect *Effect );
//o------------------------------------------------------------------------------------------------o
//| Function - CBase_ReverseEffect()
//| Prototype - void ReverseEffect()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Force the reversion of a Temp Effect on item or character based on specified temp effect ID
//o------------------------------------------------------------------------------------------------o
JSBool CBase_ReverseEffect( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if( argc != 1 )
{
ScriptError( cx, "ReverseEffect: Invalid count of arguments :%d, needs 1 (tempEffectID)", argc );
return JS_FALSE;
}
auto myObj = static_cast<CBaseObject*>( JS_GetPrivate( cx, obj ));
if( myObj == nullptr )
{
ScriptError( cx, "ReverseEffect: Invalid object assigned." );
return JS_FALSE;
}

*rval = INT_TO_JSVAL( 0 ); // Return value 0 by default, to indicate no valid temp effect found
UI16 tempEffectID = static_cast<UI16>( JSVAL_TO_INT( argv[0] ));

SERIAL myObjSerial = myObj->GetSerial();
CTEffect *removeEffect = nullptr;

for( auto &Effect : cwmWorldState->tempEffects.collection() )
{
if( myObjSerial == Effect->Destination() && Effect->Number() == tempEffectID )
{
// Found our timer! Keep track of it for removal outside loop
removeEffect = Effect;
break;
}
}

if( removeEffect != nullptr )
{
ReverseEffect( removeEffect );
cwmWorldState->tempEffects.Remove( removeEffect, true );
*rval = INT_TO_JSVAL( 1 ); // Return 1 indicating temp effect was found and removed
}

return JS_TRUE;
}

//o------------------------------------------------------------------------------------------------o
//| Function - CBase_Delete()
//| Prototype - void Delete()
Expand Down
6 changes: 6 additions & 0 deletions source/UOXJSMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ JSMethodFunc CBase_RemoveScriptTrigger;
JSMethodFunc CBase_Refresh;
JSMethodFunc CBase_SetRandomName;
JSMethodFunc CBase_SetRandomColor;
JSMethodFunc CBase_GetTempEffect;
JSMethodFunc CBase_ReverseEffect;

// Multi Methods
JSMethodFunc CMulti_GetMultiCorner;
Expand Down Expand Up @@ -480,6 +482,8 @@ inline JSFunctionSpec CChar_Methods[] =
{ "RemoveFollower", CChar_RemoveFollower, 1, 0, 0 },
{ "HasBeenOwner", CChar_HasBeenOwner, 1, 0, 0 },
{ "CalculateControlChance", CChar_CalculateControlChance, 1, 0, 0 },
{ "GetTempEffect", CBase_GetTempEffect, 1, 0, 0 },
{ "ReverseTempEffect", CBase_ReverseEffect, 1, 0, 0 },
{ nullptr, nullptr, 0, 0, 0 }
};

Expand Down Expand Up @@ -571,6 +575,8 @@ inline JSFunctionSpec CItem_Methods[] =
//{ "SetMoreSerial", CBase_SetMoreSerial, 1, 0, 0 },
{ "SetRandomName", CBase_SetRandomName, 1, 0, 0 },
{ "SetRandomColor", CBase_SetRandomColor, 1, 0, 0 },
{ "GetTempEffect", CBase_GetTempEffect, 1, 0, 0 },
{ "ReverseTempEffect", CBase_ReverseEffect, 1, 0, 0 },
{ nullptr, nullptr, 0, 0, 0 }
};

Expand Down