Skip to content

Commit

Permalink
updated ResourceCount
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonSlayer62 committed Jan 29, 2025
1 parent c2be164 commit 9034441
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
24 changes: 18 additions & 6 deletions source/UOXJSMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CChar*>( JS_GetPrivate( cx, obj ));
JSEncapsulate myClass( cx, obj );
CBaseObject* myObj = static_cast<CBaseObject*>( myClass.toObject() );

if( !ValidateObject( myChar ))
if( !ValidateObject( myObj ))
{
ScriptError( cx, "(ResourceCount) Invalid Object assigned" );
return JS_FALSE;
Expand All @@ -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<UI16>( itemColour ), static_cast<UI32>( moreVal ), colorCheck, moreCheck, sectionId ));
UI32 retVal = 0;
if( myClass.ClassName() == "UOXChar" )
{
CChar* myChar = static_cast<CChar*>( myObj );
retVal = GetItemAmount( myChar, realId, static_cast<UI16>(itemColour), static_cast<UI32>(moreVal), colorCheck, moreCheck, sectionId );
}
else
{
CItem* myItem = static_cast<CItem*>( myObj );
retVal = GetSubItemAmount( myItem, realId, static_cast<UI16>(itemColour), static_cast<UI32>(moreVal), colorCheck, moreCheck, sectionId );
}
*rval = INT_TO_JSVAL( retVal );
return JS_TRUE;
}

Expand Down
4 changes: 2 additions & 2 deletions source/UOXJSMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 },
Expand Down
1 change: 1 addition & 0 deletions source/funcdecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "" );
Expand Down
2 changes: 1 addition & 1 deletion source/quantityfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9034441

Please sign in to comment.