New JS property for chars: .isShop

Want to discuss changes to the UOX3 source code? Got a code-snippet you'd like to post? Anything related to coding/programming goes here!
Post Reply
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

New JS property for chars: .isShop

Post by Grimson »

Currently there is no way to check if a char is a vendor or not in a script. So I added a new JS property ".isShop", it can be used to get the shop status and also to set the shop status of chars.

You can find the diff here: Download

Code: Select all

Index: UOXJSPropertyEnums.h
===================================================================
RCS file: /cvsroot/openuo/projects/uox3/source/UOXJSPropertyEnums.h,v
retrieving revision 1.17
diff -u -r1.17 UOXJSPropertyEnums.h
--- UOXJSPropertyEnums.h	6 Feb 2006 17:49:30 -0000	1.17
+++ UOXJSPropertyEnums.h	9 Feb 2006 09:18:24 -0000
@@ -222,6 +222,7 @@
 	CCP_NEUTRAL,
 	CCP_ISANIMAL,
 	CCP_ISHUMAN,
+	CCP_ISSHOP,
 	CCP_COUNT
 };
 
Index: UOXJSPropertyFuncs.cpp
===================================================================
RCS file: /cvsroot/openuo/projects/uox3/source/UOXJSPropertyFuncs.cpp,v
retrieving revision 1.32
diff -u -r1.32 UOXJSPropertyFuncs.cpp
--- UOXJSPropertyFuncs.cpp	6 Feb 2006 17:49:30 -0000	1.32
+++ UOXJSPropertyFuncs.cpp	9 Feb 2006 09:43:11 -0000
@@ -30,6 +30,7 @@
 #include "cMagic.h"
 #include "scriptc.h"
 #include "ssection.h"
+#include "classes.h"
 
 #include "jsobj.h"
 #include "jsutil.h"
@@ -485,6 +486,7 @@
 				case CCP_INNOCENT:		*vp = BOOLEAN_TO_JSVAL( gPriv->IsInnocent() );	break;
 				case CCP_MURDERCOUNT:	*vp = INT_TO_JSVAL( gPriv->GetKills() );		break;
 				case CCP_NEUTRAL:		*vp = BOOLEAN_TO_JSVAL( gPriv->IsNeutral() );	break;
+				case CCP_ISSHOP:		*vp = BOOLEAN_TO_JSVAL( gPriv->IsShop() );		break;
 				case CCP_GENDER:
 					switch( gPriv->GetID() )
 					{
@@ -800,6 +802,47 @@
 						setcharflag( gPriv );
 					}
 					break;
+				case CCP_ISSHOP:
+					if( encaps.toBool() )
+					{
+						gPriv->SetShop( true );
+						CItem *tPack = NULL;
+						for( UI08 i = IL_BUYCONTAINER; i <= IL_SELLCONTAINER; ++i )
+						{
+							tPack = gPriv->GetItemAtLayer( static_cast<ItemLayers>(i) );
+							if( !ValidateObject( tPack ) )
+							{
+								tPack = Items->CreateItem( NULL, gPriv, 0x2AF8, 1, 0, OT_ITEM );
+								if( tPack != NULL )
+								{
+									tPack->SetLayer( static_cast<ItemLayers>(i) );
+									if( !tPack->SetCont( gPriv ) )
+										tPack->Delete();
+									else
+									{
+										tPack->SetType( IT_CONTAINER );
+										tPack->SetNewbie( true );
+									}
+								}
+							}
+						}
+						gPriv->Update();
+					} 
+					else 
+					{
+						gPriv->SetShop( false );
+						CItem *tPack = NULL;
+						for( UI08 i = IL_BUYCONTAINER; i <= IL_SELLCONTAINER; ++i )
+						{
+							tPack = gPriv->GetItemAtLayer( static_cast<ItemLayers>(i) );
+							if( ValidateObject( tPack ) )
+							{
+								tPack->Delete();
+							}
+						}
+						gPriv->Update();
+					} 
+					break;
 				case CCP_GENDER:
 					switch( (SI16)encaps.toInt() )
 					{
Index: UOXJSPropertySpecs.h
===================================================================
RCS file: /cvsroot/openuo/projects/uox3/source/UOXJSPropertySpecs.h,v
retrieving revision 1.19
diff -u -r1.19 UOXJSPropertySpecs.h
--- UOXJSPropertySpecs.h	6 Feb 2006 17:49:30 -0000	1.19
+++ UOXJSPropertySpecs.h	9 Feb 2006 09:18:24 -0000
@@ -235,6 +235,7 @@
 	{ "orgSkin",		CCP_ORGSKIN,		JSPROP_ENUMANDPERM },
 	{ "isAnimal",		CCP_ISANIMAL,		JSPROP_ENUMPERMRO  },
 	{ "isHuman",		CCP_ISHUMAN,		JSPROP_ENUMPERMRO  },
+	{ "isShop",			CCP_ISSHOP,			JSPROP_ENUMANDPERM },
 
 	{ NULL,			(SI08)NULL,			(UI08)0}
 };
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Thanks Grimson, I'll incorporate this into the CVS.

As a bit of a side note, if you are interested in being added to the OpenUO Sourceforge project, I can add you (thus giving you access to the CVS changes immediately as well as the ability to commit changes such as this directly).

Send me a PM or email (jowig underscore 81 at yahoo dot com) with your SF name if you are interested.
Scott
Post Reply