l2c_getUserItems() done

This commit is contained in:
alexey.min 2012-05-12 19:39:01 +00:00
parent 3f7769292c
commit 0506593508
5 changed files with 71 additions and 4 deletions

View File

@ -5,6 +5,20 @@
extern class CConfig g_cfg; extern class CConfig g_cfg;
void UserInventoryItem::getItemName( char *out, size_t maxCount )
{
out[0] = 0;
char *aname = (char *)malloc( 1024 );
if( aname )
{
L2Data_DB_GetItemNamePicByID( itemID, aname, NULL );
strncpy( out, aname, maxCount );
free( aname );
}
}
UserInventory::UserInventory() UserInventory::UserInventory()
{ {
clear(); clear();
@ -34,7 +48,7 @@ int UserInventory::addItem( UserInventoryItem& it )
int i; int i;
for( i=0; i<USERINV_MAX_ITEMS; i++ ) for( i=0; i<USERINV_MAX_ITEMS; i++ )
{ {
if( item[i].objectID == 0 ) if( item[i].isUnused() )
{ {
add_idx = i; add_idx = i;
break; break;

View File

@ -1,8 +1,6 @@
#ifndef H_USER_INVENTORY #ifndef H_USER_INVENTORY
#define H_USER_INVENTORY #define H_USER_INVENTORY
#define USERINV_MAX_ITEMS 256
// =========================================== // ===========================================
class UserInventoryItem class UserInventoryItem
@ -11,6 +9,8 @@ public:
UserInventoryItem(): itemID(0), objectID(0), count(0) {} UserInventoryItem(): itemID(0), objectID(0), count(0) {}
UserInventoryItem( unsigned int ItemID, unsigned int ObjectID, unsigned int Count ): UserInventoryItem( unsigned int ItemID, unsigned int ObjectID, unsigned int Count ):
itemID(ItemID), objectID(ObjectID), count(Count) {} itemID(ItemID), objectID(ObjectID), count(Count) {}
bool isUnused() const { return (itemID==0) || (objectID==0); }
void getItemName( char *out, size_t maxCount );
public: public:
unsigned int itemID; unsigned int itemID;
unsigned int objectID; unsigned int objectID;
@ -23,21 +23,27 @@ public:
class UserInventory class UserInventory
{ {
public: public:
static const unsigned int USERINV_MAX_ITEMS = 512;
UserInventory(); UserInventory();
~UserInventory(); ~UserInventory();
void clear(); void clear();
public: public:
//int addItem( unsigned int itemID, unsigned int objectID, unsigned long long int count ); //int addItem( unsigned int itemID, unsigned int objectID, unsigned long long int count );
int addItem( UserInventoryItem& it ); int addItem( UserInventoryItem& it );
int delItem( unsigned int itemID, unsigned int objectID ); int delItem( unsigned int itemID, unsigned int objectID );
//int updateItem( unsigned int itemID, unsigned int objectID, unsigned long long int count ); //int updateItem( unsigned int itemID, unsigned int objectID, unsigned long long int count );
int updateItem( UserInventoryItem& it ); int updateItem( UserInventoryItem& it );
public: public:
int getItemInfoByItemId( unsigned int itemID, UserInventoryItem& it ); int getItemInfoByItemId( unsigned int itemID, UserInventoryItem& it );
public: public:
void parse_ItemList( void *l2_game_packet ); void parse_ItemList( void *l2_game_packet );
void parse_InventoryUpdate( void *l2_game_packet ); void parse_InventoryUpdate( void *l2_game_packet );
protected:
public:
int itemCount; int itemCount;
UserInventoryItem item[USERINV_MAX_ITEMS]; UserInventoryItem item[USERINV_MAX_ITEMS];
}; };

View File

@ -45,6 +45,7 @@ void SE_funcs_register( lua_State *L )
lua_register( L, "l2c_useItem", l2c_useItem ); lua_register( L, "l2c_useItem", l2c_useItem );
lua_register( L, "l2c_useItemByObjectId", l2c_useItemByObjectId ); lua_register( L, "l2c_useItemByObjectId", l2c_useItemByObjectId );
lua_register( L, "l2c_getPaperdollItem", l2c_getPaperdollItem ); lua_register( L, "l2c_getPaperdollItem", l2c_getPaperdollItem );
lua_register( L, "l2c_getUserItems", l2c_getUserItems );
// Skills // Skills
lua_register( L, "l2c_useSkill", l2c_useSkill ); lua_register( L, "l2c_useSkill", l2c_useSkill );
lua_register( L, "l2c_getSkillLevel", l2c_getSkillLevel ); lua_register( L, "l2c_getSkillLevel", l2c_getSkillLevel );

View File

@ -43,6 +43,7 @@ int l2c_getItemCount( lua_State *L );
int l2c_useItem( lua_State *L ); int l2c_useItem( lua_State *L );
int l2c_useItemByObjectId( lua_State *L ); int l2c_useItemByObjectId( lua_State *L );
int l2c_getPaperdollItem( lua_State *L ); int l2c_getPaperdollItem( lua_State *L );
int l2c_getUserItems( lua_State *L );
// Skills // Skills
int l2c_useSkill( lua_State *L ); int l2c_useSkill( lua_State *L );
int l2c_getSkillLevel( lua_State *L ); int l2c_getSkillLevel( lua_State *L );

View File

@ -71,3 +71,48 @@ int l2c_getPaperdollItem( lua_State *L )
lua_pushnumber( L, pusr->paperdoll_oid[ slot ] ); lua_pushnumber( L, pusr->paperdoll_oid[ slot ] );
return 2; return 2;
} }
// table l2c_getUserItems()
int l2c_getUserItems( lua_State *L )
{
if( !g_game_client ) { lua_pushboolean( L, 0 ); return 1; }
UserInventory *inv = &(g_game_client->ai.inv);
//
int tableIndex = 1;
lua_createtable( L, 0, 0 );
int i = 0;
char itemName[255] = {0};
for( i=0; i<UserInventory::USERINV_MAX_ITEMS; i++ )
{
if( inv->item[i].isUnused() ) continue;
inv->item[i].getItemName( itemName, sizeof(itemName)-1 );
lua_pushnumber( L, tableIndex );
lua_createtable( L, 0, 0 );
//
lua_pushstring( L, "itemId" );
lua_pushinteger( L, inv->item[i].itemID );
lua_settable( L, -3 );
//
lua_pushstring( L, "itemName" );
lua_pushstring( L, itemName );
lua_settable( L, -3 );
//
lua_pushstring( L, "objectId" );
lua_pushinteger( L, inv->item[i].objectID );
lua_settable( L, -3 );
//
lua_pushstring( L, "isEquipped" );
lua_pushboolean( L, inv->item[i].isEquipped );
lua_settable( L, -3 );
//
lua_pushstring( L, "count" );
lua_pushnumber( L, (lua_Number)inv->item[i].count );
lua_settable( L, -3 );
//
lua_settable( L, -3 );
tableIndex++;
}
//
return 1;
}