chuyiwen_gmsv/mylua/itembase.c

361 lines
9.1 KiB
C
Raw Normal View History

2016-12-24 08:45:52 +08:00
#include <string.h>
#include "common.h"
#include "char_base.h"
#include "mylua/base.h"
#include "char.h"
#include "item.h"
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "lssproto_serv.h"
#ifdef _ALLBLUES_LUA_1_2
#include "mylua/mylua.h"
extern MY_Lua MYLua;
static CharBase ItemBaseInt[] = {
{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_ID}
,{{"ͼ<EFBFBD><EFBFBD>"}, ITEM_BASEIMAGENUMBER}
,{{"<EFBFBD><EFBFBD>ֵ"}, ITEM_COST}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_TYPE}
,{{"ʹ<EFBFBD><EFBFBD>"}, ITEM_ABLEUSEFIELD}
,{{"Ŀ<EFBFBD><EFBFBD>"}, ITEM_TARGET}
,{{"<EFBFBD>ȼ<EFBFBD>"}, ITEM_LEVEL}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_DAMAGEBREAK}
,{{"<EFBFBD>ѵ<EFBFBD>"}, ITEM_USEPILENUMS}
,{{"<EFBFBD>ص<EFBFBD>"}, ITEM_CANBEPILE}
,{{"<EFBFBD>"}, ITEM_NEEDSTR}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_NEEDDEX}
,{{"<EFBFBD><EFBFBD>ת"}, ITEM_NEEDTRANS}
,{{"<EFBFBD><EFBFBD>ְҵ"}, ITEM_NEEDPROFESSION}
#ifdef _TAKE_ITEMDAMAGE
,{{"<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD>"}, ITEM_DAMAGECRUSHE}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_MAXDAMAGECRUSHE}
#endif
,{{"<EFBFBD><EFBFBD>"}, ITEM_OTHERDAMAGE}
,{{"<EFBFBD><EFBFBD>"}, ITEM_OTHERDEFC}
,{{"<EFBFBD><EFBFBD>װ"}, ITEM_SUITCODE}
,{{"<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_ATTACKNUM_MIN}
,{{"<EFBFBD><EFBFBD><EFBFBD>󹥻<EFBFBD>"}, ITEM_ATTACKNUM_MAX}
,{{"<EFBFBD><EFBFBD>"}, ITEM_MODIFYATTACK}
,{{"<EFBFBD><EFBFBD>"}, ITEM_MODIFYDEFENCE}
,{{"<EFBFBD><EFBFBD>"}, ITEM_MODIFYQUICK}
,{{"HP"}, ITEM_MODIFYHP}
,{{"MP"}, ITEM_MODIFYMP}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_MODIFYLUCK}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_MODIFYCHARM}
,{{"<EFBFBD>ر<EFBFBD>"}, ITEM_MODIFYAVOID}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_MODIFYATTRIB}
,{{"<EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD>"}, ITEM_MODIFYATTRIBVALUE}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_MAGICID}
,{{"<EFBFBD>о<EFBFBD><EFBFBD><EFBFBD>"}, ITEM_MAGICPROB}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>MP"}, ITEM_MAGICUSEMP}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_MODIFYARRANGE}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_MODIFYSEQUENCE}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_ATTACHPILE}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_HITRIGHT}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"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}
};
static CharBase ItemBaseChar[] = {
{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_NAME}
,{{"<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>"}, ITEM_SECRETNAME}
,{{"˵<EFBFBD><EFBFBD>"}, ITEM_EFFECTSTRING}
,{{"<EFBFBD>ֶ<EFBFBD>"}, ITEM_ARGUMENT}
,{{"<EFBFBD>ɷ<EFBFBD><EFBFBD><EFBFBD>0"}, ITEM_INGNAME0}
,{{"<EFBFBD>ɷ<EFBFBD><EFBFBD><EFBFBD>1"}, ITEM_INGNAME1}
,{{"<EFBFBD>ɷ<EFBFBD><EFBFBD><EFBFBD>2"}, ITEM_INGNAME2}
,{{"<EFBFBD>ɷ<EFBFBD><EFBFBD><EFBFBD>3"}, ITEM_INGNAME3}
,{{"<EFBFBD>ɷ<EFBFBD><EFBFBD><EFBFBD>4"}, ITEM_INGNAME4}
#ifdef _ANGEL_SUMMON
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_ANGELMISSION}
,{{"<EFBFBD><EFBFBD>ʹ"}, ITEM_ANGELINFO}
,{{"Ӣ<EFBFBD><EFBFBD>"}, ITEM_HEROINFO}
#endif
};
static CharBase ItemBaseValue[] = {
{{"צ"}, ITEM_FIST}
,{{"<EFBFBD><EFBFBD>"}, ITEM_AXE}
,{{"<EFBFBD><EFBFBD>"}, ITEM_CLUB}
,{{"ǹ"}, ITEM_SPEAR}
,{{"<EFBFBD><EFBFBD>"}, ITEM_BOW}
,{{"<EFBFBD><EFBFBD>"}, ITEM_SHIELD}
,{{"<EFBFBD><EFBFBD>"}, ITEM_HELM}
,{{"<EFBFBD><EFBFBD>"}, ITEM_ARMOUR}
,{{"<EFBFBD><EFBFBD>"}, ITEM_BRACELET}
,{{"<EFBFBD><EFBFBD>"}, ITEM_MUSIC}
,{{"<EFBFBD><EFBFBD>"}, ITEM_NECKLACE}
,{{"<EFBFBD><EFBFBD>"}, ITEM_RING}
,{{"<EFBFBD><EFBFBD>"}, ITEM_BELT}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_EARRING}
,{{"<EFBFBD>ǻ<EFBFBD>"}, ITEM_NOSERING}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_AMULET}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_OTHER}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_BOOMERANG}
,{{"Ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_BOUNDTHROW}
,{{"Ͷ<EFBFBD><EFBFBD>ʯ"}, ITEM_BREAKTHROW}
,{{"<EFBFBD><EFBFBD>"}, ITEM_DISH}
#ifdef _ITEM_INSLAY
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_METAL}
,{{"<EFBFBD><EFBFBD>ʯ"}, ITEM_JEWEL}
#endif
#ifdef _ITEM_CHECKWARES
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_WARES}
#endif
#ifdef _ITEM_EQUITSPACE
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_WBELT}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_WSHIELD}
,{{"Ь<EFBFBD><EFBFBD>"}, ITEM_WSHOES}
#endif
#ifdef _EQUIT_NEWGLOVE
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_WGLOVE}
#endif
#ifdef _ALCHEMIST
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_ALCHEMIST}
#endif
#ifdef _PET_ITEM
,{{"<EFBFBD><EFBFBD>ͷ"}, ITEM_PET_HEAD}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_PET_TOOTH}
,{{"<EFBFBD><EFBFBD>צ"}, ITEM_PET_CLAW}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_PET_BREAST}
,{{"<EFBFBD>"}, ITEM_PET_BACK}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_PET_WING}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_PET_FEET}
#endif
};
static CharBase ItemBaseWorkInt[] = {
{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_WORKOBJINDEX}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"}, ITEM_WORKCHARAINDEX}
};
static CharBase ItemBaseEvent[] = {
{{"δ֪<EFBFBD>¼<EFBFBD>"}, ITEM_PREOVERFUNC}
,{{"<EFBFBD>ʼ<EFBFBD><EFBFBD>¼<EFBFBD>"}, ITEM_POSTOVERFUNC}
,{{"ʹ<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>"}, ITEM_USEFUNC}
,{{"װ<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>"}, ITEM_ATTACHFUNC}
,{{"ж<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>"}, ITEM_DETACHFUNC}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>"}, ITEM_DROPFUNC}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>"}, ITEM_PICKUPFUNC}
,{{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>"}, ITEM_DIERELIFEFUNC}
};
static int getInt(lua_State *L)
{
const int index = luaL_checkint(L, 1);
const int element = getCharBaseValue(L, 2, ItemBaseInt, arraysizeof(ItemBaseInt));
lua_pushinteger(L, ITEM_getInt(index, element));
return 1;
}
static int setInt(lua_State *L)
{
const int index = luaL_checkint(L, 1);
const int element = getCharBaseValue(L, 2, ItemBaseInt, arraysizeof(ItemBaseInt));
const int data = luaL_checkint(L, 3);
if(ITEM_setInt(index, element, data) == -1){
return 0;
}else{
return 1;
}
}
static int getChar(lua_State *L)
{
const int index = luaL_checkint(L, 1);
const int element = getCharBaseValue(L, 2, ItemBaseChar, arraysizeof(ItemBaseChar));
lua_pushstring(L, ITEM_getChar(index, element));
return 1;
}
static int setChar(lua_State *L)
{
size_t l;
const int index = luaL_checkint(L, 1);
const int element = getCharBaseValue(L, 2, ItemBaseChar, arraysizeof(ItemBaseChar));
char *data = luaL_checklstring(L, 3, &l);
if(ITEM_setChar(index, element, data) == -1){
return 0;
}else{
return 1;
}
}
static int getWorkInt(lua_State *L)
{
const int index = luaL_checkint(L, 1);
const int element = getCharBaseValue(L, 2, ItemBaseWorkInt, arraysizeof(ItemBaseWorkInt));
lua_pushinteger(L, ITEM_getWorkInt(index, element));
return 1;
}
static int setWorkInt(lua_State *L)
{
const int index = luaL_checkint(L, 1);
const int element = getCharBaseValue(L, 2, ItemBaseWorkInt, arraysizeof(ItemBaseWorkInt));
const int data = luaL_checkint(L, 3);
if(ITEM_setWorkInt(index, element, data) == -1){
return 0;
}else{
return 1;
}
}
static int getNameFromNumber(lua_State *L)
{
const int id = luaL_checkint(L, 1);
lua_pushstring(L, ITEM_getNameFromNumber(id));
return 1;
}
static int getcostFromITEMtabl(lua_State *L)
{
const int id = luaL_checkint(L, 1);
lua_pushinteger(L, ITEM_getcostFromITEMtabl(id));
return 1;
}
static int getlevelFromITEMtabl(lua_State *L)
{
const int id = luaL_checkint(L, 1);
lua_pushinteger(L, ITEM_getlevelFromITEMtabl(id));
return 1;
}
static int getgraNoFromITEMtabl(lua_State *L)
{
const int id = luaL_checkint(L, 1);
lua_pushinteger(L, ITEM_getgraNoFromITEMtabl(id));
return 1;
}
static int getItemInfoFromNumber(lua_State *L)
{
const int id = luaL_checkint(L, 1);
lua_pushstring(L, ITEM_getItemInfoFromNumber(id));
return 1;
}
static int setFunctionPointer(lua_State *L)
{
size_t l;
const int index = luaL_checkint(L, 1);
const int functype = getCharBaseValue(L, 2, ItemBaseEvent, arraysizeof(ItemBaseEvent));
char *luafuncname=luaL_checklstring(L, 3, &l);
return ITEM_setLUAFunction( index, functype, luafuncname );
}
static int addLUAListFunction(lua_State *L)
{
size_t l;
char *luafuncname=luaL_checklstring(L, 1, &l);
char *luafunctable=luaL_checklstring(L, 2, &l);
char *luafunctablepath=luaL_checklstring(L, 3, &l);
if(strlen(luafunctablepath) > 0){
MY_Lua *mylua = &MYLua;
while(mylua->next != NULL){
if(strcmp(mylua->luapath, luafunctablepath) == 0){
return ITEM_addLUAListFunction( mylua->lua, luafuncname, luafunctable);
}
mylua = mylua->next;
}
}else{
return ITEM_addLUAListFunction( L, luafuncname, luafunctable );
}
return 1;
}
static int UpdataItemOne(lua_State *L)
{
const int charaindex = luaL_checkint(L, 1);
const int itemindex = luaL_checkint(L, 2);
int i;
for( i = 0; i < CHAR_MAXITEMHAVE ; i++ ){
if(itemindex == CHAR_getItemIndex( charaindex , i )){
CHAR_sendItemDataOne( charaindex, i);
break;
}
}
return 1;
}
static int UpdataHaveItemOne(lua_State *L)
{
const int charaindex = luaL_checkint(L, 1);
const int haveitemindex = luaL_checkint(L, 2);
CHAR_sendItemDataOne( charaindex, haveitemindex);
return 1;
}
static const luaL_Reg itemlib[] = {
{"getInt", getInt},
{"setInt", setInt},
{"getChar", getChar},
{"setChar", setChar},
{"getWorkInt", getWorkInt},
{"setWorkInt", setWorkInt},
{"setFunctionPointer", setFunctionPointer},
{"addLUAListFunction", addLUAListFunction},
{"getNameFromNumber", getNameFromNumber},
{"getcostFromITEMtabl", getcostFromITEMtabl},
{"getlevelFromITEMtabl", getlevelFromITEMtabl},
{"getgraNoFromITEMtabl", getgraNoFromITEMtabl},
{"getItemInfoFromNumber", getItemInfoFromNumber},
{"UpdataItemOne", UpdataItemOne},
{"UpdataHaveItemOne", UpdataHaveItemOne},
{NULL, NULL}
};
LUALIB_API int luaopen_Item (lua_State *L) {
luaL_register(L, "item", itemlib);
return 1;
}
#endif