From 9034441cef861cea162d29dba20a0b585ee68467 Mon Sep 17 00:00:00 2001 From: Dragon Slayer <85514184+DragonSlayer62@users.noreply.github.com> Date: Wed, 29 Jan 2025 10:13:52 -0600 Subject: [PATCH] updated ResourceCount --- source/UOXJSMethods.cpp | 24 ++++++++++++++++++------ source/UOXJSMethods.h | 4 ++-- source/funcdecl.h | 1 + source/quantityfuncs.cpp | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/source/UOXJSMethods.cpp b/source/UOXJSMethods.cpp index 5ae378ae1..97e2cf49e 100644 --- a/source/UOXJSMethods.cpp +++ b/source/UOXJSMethods.cpp @@ -3997,18 +3997,19 @@ JSBool CGuild_IsAtPeace( JSContext *cx, JSObject *obj, uintN argc, [[maybe_unuse } //o------------------------------------------------------------------------------------------------o -//| Function - CChar_ResourceCount() +//| Function - CBase_ResourceCount() //| Prototype - int ResourceCount( realId, colour ) //| int ResourceCount( realId, colour, moreVal ) //| int ResourceCount( realId, colour, moreVal, sectionId ) //o------------------------------------------------------------------------------------------------o //| Purpose - Returns the amount of the items of given ID, colour and moreVal character has in packs //o------------------------------------------------------------------------------------------------o -JSBool CChar_ResourceCount( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval ) +JSBool CBase_ResourceCount( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval ) { - CChar *myChar = static_cast( JS_GetPrivate( cx, obj )); + JSEncapsulate myClass( cx, obj ); + CBaseObject* myObj = static_cast( myClass.toObject() ); - if( !ValidateObject( myChar )) + if( !ValidateObject( myObj )) { ScriptError( cx, "(ResourceCount) Invalid Object assigned" ); return JS_FALSE; @@ -4035,13 +4036,24 @@ JSBool CChar_ResourceCount( JSContext *cx, JSObject *obj, uintN argc, jsval *arg } if( argc >= 4 ) { - sectionId = JS_GetStringBytes( JS_ValueToString( cx, argv[3] )); + sectionId = JS_GetStringBytes(JS_ValueToString( cx, argv[3] )); } bool colorCheck = ( itemColour != -1 ? true : false ); bool moreCheck = ( moreVal != -1 ? true : false ); - *rval = INT_TO_JSVAL( GetItemAmount( myChar, realId, static_cast( itemColour ), static_cast( moreVal ), colorCheck, moreCheck, sectionId )); + UI32 retVal = 0; + if( myClass.ClassName() == "UOXChar" ) + { + CChar* myChar = static_cast( myObj ); + retVal = GetItemAmount( myChar, realId, static_cast(itemColour), static_cast(moreVal), colorCheck, moreCheck, sectionId ); + } + else + { + CItem* myItem = static_cast( myObj ); + retVal = GetSubItemAmount( myItem, realId, static_cast(itemColour), static_cast(moreVal), colorCheck, moreCheck, sectionId ); + } + *rval = INT_TO_JSVAL( retVal ); return JS_TRUE; } diff --git a/source/UOXJSMethods.h b/source/UOXJSMethods.h index 447dd5c12..2cb8d908d 100644 --- a/source/UOXJSMethods.h +++ b/source/UOXJSMethods.h @@ -78,7 +78,6 @@ JSMethodFunc CChar_EmoteMessage; JSMethodFunc CChar_OpenBank; JSMethodFunc CChar_DirectionTo; JSMethodFunc CChar_TurnToward; -JSMethodFunc CChar_ResourceCount; JSMethodFunc CChar_CheckSkill; JSMethodFunc CChar_FindItemLayer; JSMethodFunc CChar_SpeechInput; @@ -187,6 +186,7 @@ JSMethodFunc CBase_UpdateStats; JSMethodFunc CBase_Resist; JSMethodFunc CBase_IsBoat; JSMethodFunc CBase_CanSee; +JSMethodFunc CBase_ResourceCount; JSMethodFunc CBase_UseResource; JSMethodFunc CBase_AddScriptTrigger; JSMethodFunc CBase_HasScriptTrigger; @@ -394,7 +394,7 @@ inline JSFunctionSpec CChar_Methods[] = { "OpenBank", CChar_OpenBank, 1, 0, 0 }, { "DirectionTo", CChar_DirectionTo, 1, 0, 0 }, { "TurnToward", CChar_TurnToward, 1, 0, 0 }, - { "ResourceCount", CChar_ResourceCount, 2, 0, 0 }, + { "ResourceCount", CBase_ResourceCount, 2, 0, 0 }, { "UseResource", CBase_UseResource, 3, 0, 0 }, { "CustomTarget", CMisc_CustomTarget, 1, 0, 0 }, { "PopUpTarget", CMisc_PopUpTarget, 1, 0, 0 }, diff --git a/source/funcdecl.h b/source/funcdecl.h index 7324d4c18..768adb7e4 100644 --- a/source/funcdecl.h +++ b/source/funcdecl.h @@ -98,6 +98,7 @@ TIMERVAL GetPoisonTickTime( UI08 poisonStrength ); // Amount related //o------------------------------------------------------------------------------------------------o UI32 GetItemAmount( CChar *s, UI16 realId, UI16 realColour = 0x0000, UI32 realMoreVal = 0x0, bool colorCheck = false, bool moreCheck = false, std::string sectionId = "" ); +UI32 GetSubItemAmount( CItem* p, UI16 realId, UI16 realColour = 0x0000, UI32 realMoreVal = 0x0, bool colorCheck = false, bool moreCheck = false, std::string sectionId = "" ); UI32 GetTotalItemCount( CItem *objCont ); UI32 DeleteItemAmount( CChar *s, UI32 amount, UI16 realId, UI16 realColour = 0x0000, UI32 realMoreVal = 0x0, bool colorCheck = false, bool moreCheck = false, std::string sectionId = "" ); UI32 DeleteSubItemAmount( CItem *p, UI32 amount, UI16 realId, UI16 realColour = 0x0000, UI32 realMoreVal = 0x0, bool colorCheck = false, bool moreCheck = false, std::string sectionId = "" ); diff --git a/source/quantityfuncs.cpp b/source/quantityfuncs.cpp index dfd357908..46c79edb6 100644 --- a/source/quantityfuncs.cpp +++ b/source/quantityfuncs.cpp @@ -49,7 +49,7 @@ UI32 GetTotalItemCount( CItem *objCont ) //o------------------------------------------------------------------------------------------------o //| Purpose - Get the total amount of an item in a pack //o------------------------------------------------------------------------------------------------o -auto GetSubItemAmount( CItem *p, UI16 realId, UI16 realColour, UI32 realMoreVal, bool colorCheck = false, bool moreCheck = false, std::string sectionId = "" ) -> UI32 +auto GetSubItemAmount( CItem* p, UI16 realId, UI16 realColour, UI32 realMoreVal, bool colorCheck, bool moreCheck, std::string sectionId ) -> UI32 { UI32 total = 0; auto pCont = p->GetContainsList();