ScriptFuns.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:129k
- /*******************************************************************************
- // FileName : ScriptFuns.cpp
- // FileAuthor : RomanDou
- // FileCreateDate : 2002-11-19 15:58:20
- // FileDescription : 脚本指令集
- // Revision Count :
- *******************************************************************************/
- #ifndef WIN32
- #include <string>
- #endif
- #include "KWin32.h"
- #include "KEngine.h"
- #include "KDebug.h"
- #include "KStepLuaScript.h"
- #include "LuaLib.h"
- #include "KScriptList.h"
- #include <string.h>
- #include "LuaFuns.h"
- #include "KCore.h"
- #include "KNpc.h"
- #include "KSubWorld.h"
- #include "KObjSet.h"
- #include "KItemSet.h"
- //#include "KNetClient.h"
- #include "KScriptValueSet.h"
- #include "KNpcSet.h"
- #include "KPlayerSet.h"
- #include "KPlayer.h"
- #include "KSubWorldSet.h"
- #include "KProtocolProcess.h"
- #include "KBuySell.h"
- #include "KTaskFuns.h"
- #include "KPlayerDef.h"
- #include "TaskDef.h"
- #ifdef _SERVER
- //#include "KNetServer.h"
- //#include "../MultiServer/Heaven/interface/iServer.h"
- #include "KNewProtocolProcess.h"
- #endif
- #include "KSortScript.h"
- #ifndef __linux
- #include "Shlwapi.h"
- #include "windows.h"
- #include "winbase.h"
- #include <direct.h>
- #else
- #include "unistd.h"
- #endif
- #ifdef _STANDALONE
- #include "KSG_StringProcess.h"
- #else
- #include "../../Engine/Src/KSG_StringProcess.h"
- #endif
- #ifndef WIN32
- typedef struct _SYSTEMTIME
- {
- WORD wYear;
- WORD wMonth;
- WORD wDayOfWeek;
- WORD wDay;
- WORD wHour;
- WORD wMinute;
- WORD wSecond;
- WORD wMilliseconds;
- } SYSTEMTIME;
- typedef struct _FILETIME
- {
- DWORD dwLowDateTime;
- DWORD dwHighDateTime;
- } FILETIME;
- #endif
- inline const char* _ip2a(DWORD ip) { in_addr ia; ia.s_addr = ip; return inet_ntoa(ia); }
- inline DWORD _a2ip(const char* cp) { return inet_addr(cp); }
- KScriptList g_StoryScriptList;
- KStepLuaScript * LuaGetScript(Lua_State * L);
- int GetPlayerIndex(Lua_State * L);
- extern int g_GetPriceToStation(int,int);
- extern int g_GetPriceToWayPoint(int,int);
- extern int g_GetPriceToDock(int ,int );
- //BitValue = GetBit(Value, BitNo)
- int LuaGetBit(Lua_State * L)
- {
- int nBitValue = 0;
- int nIntValue = (int)Lua_ValueToNumber(L, 1);
- int nBitNumber = (int)Lua_ValueToNumber(L, 2);
-
- if (nBitNumber >= 32 || nBitNumber <= 0)
- goto lab_getbit;
- nBitValue = (nIntValue & (1 << (nBitNumber - 1))) != 0;
- lab_getbit:
- Lua_PushNumber(L, nBitValue);
- return 1;
- }
- //NewBit = SetBit(Value, BitNo, BitValue)
- int LuaSetBit(Lua_State * L)
- {
- int nIntValue = (int)Lua_ValueToNumber(L, 1);
- int nBitNumber = (int)Lua_ValueToNumber(L, 2);
- int nBitValue = (int)Lua_ValueToNumber(L,3);
- nBitValue = (nBitValue == 1);
-
- if (nBitNumber > 32 || nBitNumber <= 0)
- goto lab_setbit;
-
- nIntValue = (nIntValue | (1 << (nBitNumber - 1)));
- lab_setbit:
- Lua_PushNumber(L, nIntValue);
- return 1;
- }
- //ByteValue = GetByte(Value, ByteNo)
- int LuaGetByte(Lua_State * L)
- {
- int nByteValue = 0;
- int nIntValue = (int)Lua_ValueToNumber(L, 1);
- int nByteNumber = (int)Lua_ValueToNumber(L, 2);
-
- if (nByteNumber > 4 || nByteNumber <= 0)
- goto lab_getByte;
- nByteValue = (nIntValue & (0xff << ((nByteNumber - 1) * 8) )) >> ((nByteNumber - 1) * 8);
-
- lab_getByte:
- Lua_PushNumber(L, nByteValue);
- return 1;
- }
- //NewByte = SetByte(Value, ByteNo, ByteValue)
- int LuaSetByte(Lua_State * L)
- {
- BYTE * pByte = NULL;
- int nIntValue = (int)Lua_ValueToNumber(L, 1);
- int nByteNumber = (int)Lua_ValueToNumber(L, 2);
- int nByteValue = (int)Lua_ValueToNumber(L,3);
- nByteValue = (nByteValue & 0xff);
-
- if (nByteNumber > 4 || nByteNumber <= 0)
- goto lab_setByte;
-
- pByte = (BYTE*)&nIntValue;
- *(pByte + (nByteNumber -1)) = (BYTE)nByteValue;
- //nIntValue = (nIntValue | (0xff << ((nByteNumber - 1) * 8) )) ;
- lab_setByte:
- Lua_PushNumber(L, nIntValue);
- return 1;
- }
- #ifdef _SERVER
- int LuaModifyRepute(Lua_State *L)
- {
- if (Lua_GetTopIndex(L) <1)
- return 0;
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0)
- return 0;
- int nValue = (int)Lua_ValueToNumber(L,1);
-
- Player[nPlayerIndex].m_cTask.SetSaveVal(TASKVALUE_REPUTE, Player[nPlayerIndex].m_cTask.GetSaveVal(TASKVALUE_REPUTE) + nValue);
- if (nValue < 0)
- {
- char szMsg[100];
- sprintf(szMsg, "您的声望减少了%d点!", -nValue);
- // KPlayerChat::SendSystemInfo(1, nPlayerIndex, MESSAGE_SYSTEM_ANNOUCE_HEAD, (char *) szMsg, strlen(szMsg) );
- }
- else
- {
- char szMsg[100];
- sprintf(szMsg, "您的声望增加了%d点!", nValue);
- // KPlayerChat::SendSystemInfo(1, nPlayerIndex, MESSAGE_SYSTEM_ANNOUCE_HEAD, (char *) szMsg, strlen(szMsg) );
- }
-
-
- return 0;
- }
- int LuaGetRepute(Lua_State *L)
- {
- int nValue = 0;
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0)
- goto lab_getrepute;
- nValue = Player[nPlayerIndex].m_cTask.GetSaveVal(TASKVALUE_REPUTE);
- lab_getrepute:
- Lua_PushNumber(L, nValue);
- return 1;
- }
- #endif
- int GetSubWorldIndex(Lua_State * L)
- {
- Lua_GetGlobal(L, SCRIPT_SUBWORLDINDEX);
- if (lua_isnil(L,Lua_GetTopIndex(L)))
- return -1;
- int nIndex = (int)Lua_ValueToNumber(L, Lua_GetTopIndex(L));
- if (nIndex >= MAX_SUBWORLD || nIndex <= 0)
- {
- _ASSERT(0);
- return -1;
- }
- if (SubWorld[nIndex].m_nIndex >= MAX_SUBWORLD || SubWorld[nIndex].m_nIndex < 0)
- {
- _ASSERT(0);
- return -1;
- }
- return nIndex;
- }
- //Idx = SubWorldID2Idx(dwID)
- int LuaSubWorldIDToIndex(Lua_State * L)
- {
- int nTargetSubWorld = -1;
- int nSubWorldID = 0;
- if (Lua_GetTopIndex(L) < 1)
- goto lab_subworldid2idx;
-
- nSubWorldID = (int)Lua_ValueToNumber(L, 1);
- nTargetSubWorld = g_SubWorldSet.SearchWorld(nSubWorldID);
-
- lab_subworldid2idx:
- Lua_PushNumber(L, nTargetSubWorld);
- return 1;
- }
- /*
- Say(sMainInfo, nSelCount, sSel1, sSel2, sSel3, .....,sSeln)
- Say(nMainInfo, nSelCount, sSel1, sSel2, sSel3, .....,sSeln)
- Say(nMainInfo, nSelCount, SelTab)
- 如果是客户端的则不会向服务器端发送任何操作
- Say(100, 3, 10, 23,43)
- Say("选择什么?", 2, "是/yes", "否/no");
- Say("选什么呀", 2, SelTab);
- */
- //**************************************************************************************************************************************************************
- // 界面脚本
- //**************************************************************************************************************************************************************
- int LuaSelectUI(Lua_State * L)
- {
- char * strMain = NULL;
- int nMainInfo = 0;
- int nDataType = 0;
- int nOptionNum = 0;
- char * pContent = NULL;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0) return 0;
- Player[nPlayerIndex].m_bWaitingPlayerFeedBack = false;
-
- int nParamNum = Lua_GetTopIndex(L);
- if (nParamNum < 2) return 0;
-
- if (Lua_IsNumber(L,2))
- {
- nOptionNum = (int)Lua_ValueToNumber(L,2);
- }
- else
- {
- _ASSERT(0);
- return 0;
- }
-
- if (Lua_IsNumber(L,1))
- {
- nMainInfo = (int)Lua_ValueToNumber(L,1);
- nDataType = 1 ;
- }
- else if (Lua_IsString(L, 1)) //检查主信息是字符串还是字符串标识号
- {
- strMain = (char *)Lua_ValueToString(L, 1);
- nDataType = 0 ;
- }
- else
- return 0;
-
- BOOL bStringTab = FALSE;//标识传进来的选项数据存放在一个数组中,还是许多字符串里
-
- if (Lua_IsString(L,3))
- bStringTab = FALSE;
- else if (Lua_IsTable(L, 3))
- {
- bStringTab = TRUE;
- }
- else
- {if (nOptionNum > 0) return 0;
- }
-
- if (bStringTab == FALSE)
- {
- //获得实际传入的选项的个数
- if (nOptionNum > nParamNum - 2) nOptionNum = nParamNum - 2;
- }
-
- if (nOptionNum > MAX_ANSWERNUM) nOptionNum = MAX_ANSWERNUM;
-
- PLAYER_SCRIPTACTION_SYNC UiInfo;
- UiInfo.m_bUIId = UI_SELECTDIALOG;
- UiInfo.m_bParam1 = nDataType;//主信息的类型,字符串(0)或数字(1)
- UiInfo.m_bOptionNum = nOptionNum;
- UiInfo.m_nOperateType = SCRIPTACTION_UISHOW;
-
- //主信息为字符串
- if (nDataType == 0)
- {
- if (strMain)
- sprintf(UiInfo.m_pContent, "%s", strMain);
- pContent = UiInfo.m_pContent;
- }
- else if (nDataType == 1) //主信息为数字标识
- {
- *(int *)UiInfo.m_pContent = nMainInfo;
- pContent = UiInfo.m_pContent + sizeof(int);
- *pContent = 0;
- }
-
- if (nOptionNum > MAX_ANSWERNUM)
- nOptionNum = MAX_ANSWERNUM;
-
- Player[nPlayerIndex].m_nAvailableAnswerNum = nOptionNum;
-
- for (int i = 0; i < nOptionNum; i ++)
- {
- char pAnswer[100];
- pAnswer[0] = 0;
-
- if (bStringTab)
- {
- Lua_PushNumber(L, i + 1);
- Lua_RawGet(L, 3);
- char * pszString = (char *)Lua_ValueToString(L, Lua_GetTopIndex(L));
- if (pszString)
- {
- g_StrCpyLen(pAnswer, pszString, 100);
- }
- }
- else
- {
- char * pszString = (char *)Lua_ValueToString(L, i + 3);
- if (pszString)
- g_StrCpyLen(pAnswer, pszString, 100);
- }
-
- char * pFunName = strstr(pAnswer, "/");
-
- if (pFunName)
- {
- g_StrCpyLen(Player[nPlayerIndex].m_szTaskAnswerFun[i], pFunName + 1, sizeof(Player[nPlayerIndex].m_szTaskAnswerFun[0]));
- *pFunName = 0;
- sprintf(pContent, "%s|%s", pContent, pAnswer);
- }
- else
- {
- strcpy(Player[nPlayerIndex].m_szTaskAnswerFun[i], "main");
- sprintf(pContent, "%s|%s", pContent, pAnswer);
- }
- }
-
- if (nDataType == 0)
- UiInfo.m_nBufferLen = strlen(pContent);
- else
- UiInfo.m_nBufferLen = strlen(pContent) + sizeof(int);
-
- #ifndef _SERVER
- UiInfo.m_bParam2 = 0;
- #else
- UiInfo.m_bParam2 = 1;
- #endif
-
- if (nOptionNum == 0)
- {
- Player[nPlayerIndex].m_bWaitingPlayerFeedBack = false;
- }
- else
- {
- Player[nPlayerIndex].m_bWaitingPlayerFeedBack = true;
- }
-
- Player[nPlayerIndex].DoScriptAction(&UiInfo);
- return 0;
- }
- //PutMsg(szMsg/MsgId)
- int LuaSendMessageInfo(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0) return 0;
-
- PLAYER_SCRIPTACTION_SYNC UiInfo;
- UiInfo.m_bUIId = UI_MSGINFO;
- UiInfo.m_bOptionNum = 1;
- UiInfo.m_nOperateType = SCRIPTACTION_UISHOW;
-
- int nMsgId = 0;
-
- if (Lua_IsNumber(L,1))
- {
- nMsgId = (int)Lua_ValueToNumber(L,1);
- *((int *)(UiInfo.m_pContent)) = nMsgId;
- UiInfo.m_bParam1 = 1;
- UiInfo.m_nBufferLen = sizeof(int);
- }
- else
- {
-
- g_StrCpyLen(UiInfo.m_pContent, Lua_ValueToString(L,1), 64);
- UiInfo.m_nBufferLen = strlen(((char *)UiInfo.m_pContent));
- UiInfo.m_bParam1 = 0;
- }
-
- #ifndef _SERVER
- UiInfo.m_bParam2 = 0;
- #else
- UiInfo.m_bParam2 = 1;
- #endif
- Player[nPlayerIndex].DoScriptAction(&UiInfo);
- return 0;
- }
- //AddGlobalNews(Newsstr)
- int LuaAddGlobalNews(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
-
- PLAYER_SCRIPTACTION_SYNC UiInfo;
- UiInfo.m_bUIId = UI_NEWSINFO;
- UiInfo.m_bOptionNum = NEWSMESSAGE_NORMAL;
- UiInfo.m_nOperateType = SCRIPTACTION_UISHOW;
-
- int nMsgId = 0;
-
- if (Lua_IsNumber(L,1))
- {
- nMsgId = (int)Lua_ValueToNumber(L,1);
- *((int *)(UiInfo.m_pContent)) = nMsgId;
- UiInfo.m_bParam1 = 1;
- UiInfo.m_nBufferLen = sizeof(int);
- }
- else
- {
- g_StrCpyLen(UiInfo.m_pContent, Lua_ValueToString(L,1), 64);
- UiInfo.m_nBufferLen = strlen(((char *)UiInfo.m_pContent));
- UiInfo.m_bParam1 = 0;
- }
-
- #ifndef _SERVER
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0) return 0;
- UiInfo.m_bParam2 = 0;
- Player[nPlayerIndex].DoScriptAction(&UiInfo);
- #else
- UiInfo.m_bParam2 = 1;
- UiInfo.ProtocolType = (BYTE)s2c_scriptaction;
- UiInfo.m_wProtocolLong = sizeof(PLAYER_SCRIPTACTION_SYNC) - MAX_SCIRPTACTION_BUFFERNUM + UiInfo.m_nBufferLen - 1;
- g_NewProtocolProcess.BroadcastGlobal(&UiInfo, UiInfo.m_wProtocolLong + 1);
- #endif
- return 0;
- }
- //AddLocalNews(Newsstr)
- int LuaAddLocalNews(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
-
- PLAYER_SCRIPTACTION_SYNC UiInfo;
- UiInfo.m_bUIId = UI_NEWSINFO;
- UiInfo.m_bOptionNum = NEWSMESSAGE_NORMAL;
- UiInfo.m_nOperateType = SCRIPTACTION_UISHOW;
-
- int nMsgId = 0;
-
- if (Lua_IsNumber(L,1))
- {
- nMsgId = (int)Lua_ValueToNumber(L,1);
- *((int *)(UiInfo.m_pContent)) = nMsgId;
- UiInfo.m_bParam1 = 1;
- UiInfo.m_nBufferLen = sizeof(int);
- }
- else
- {
- g_StrCpyLen(UiInfo.m_pContent, Lua_ValueToString(L,1), 64);
- UiInfo.m_nBufferLen = strlen(((char *)UiInfo.m_pContent));
- UiInfo.m_bParam1 = 0;
- }
-
- #ifndef _SERVER
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0) return 0;
- UiInfo.m_bParam2 = 0;
- Player[nPlayerIndex].DoScriptAction(&UiInfo);
- #else
- UiInfo.m_bParam2 = 1;
- UiInfo.ProtocolType = (BYTE)s2c_scriptaction;
- UiInfo.m_wProtocolLong = sizeof(PLAYER_SCRIPTACTION_SYNC) - MAX_SCIRPTACTION_BUFFERNUM + UiInfo.m_nBufferLen - 1;
- g_NewProtocolProcess.BroadcastLocalServer(&UiInfo, UiInfo.m_wProtocolLong + 1);
- #endif
- return 0;
- }
- //AddGlobalCountNews(strNew/newid, time)
- int LuaAddGlobalCountNews(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 2)
- return 0;
-
- PLAYER_SCRIPTACTION_SYNC UiInfo;
- UiInfo.m_bUIId = UI_NEWSINFO;
- UiInfo.m_bOptionNum = NEWSMESSAGE_COUNTING;
- UiInfo.m_nOperateType = SCRIPTACTION_UISHOW;
-
- int nMsgId = 0;
-
- int nTime = (int)Lua_ValueToNumber(L,2);
-
- if (nTime <= 0)
- nTime = 1;
-
- if (Lua_IsNumber(L,1))
- {
- nMsgId = (int)Lua_ValueToNumber(L,1);
- *((int *)(UiInfo.m_pContent)) = nMsgId;
- UiInfo.m_bParam1 = 1;
- *(int *)((char *)UiInfo.m_pContent + sizeof(int)) = nTime;
- UiInfo.m_nBufferLen = sizeof(int) * 2;
- }
- else
- {
- g_StrCpyLen(UiInfo.m_pContent, Lua_ValueToString(L,1), 64);
- UiInfo.m_nBufferLen = strlen(((char *)UiInfo.m_pContent));
- *(int *)((char *)UiInfo.m_pContent + UiInfo.m_nBufferLen) = nTime;
- UiInfo.m_nBufferLen += sizeof(int);
- UiInfo.m_bParam1 = 0;
- }
-
- #ifndef _SERVER
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0) return 0;
- UiInfo.m_bParam2 = 0;
- Player[nPlayerIndex].DoScriptAction(&UiInfo);
- #else
- UiInfo.m_bParam2 = 1;
- UiInfo.ProtocolType = (BYTE)s2c_scriptaction;
- UiInfo.m_wProtocolLong = sizeof(PLAYER_SCRIPTACTION_SYNC) - MAX_SCIRPTACTION_BUFFERNUM + UiInfo.m_nBufferLen - 1;
- g_NewProtocolProcess.BroadcastGlobal(&UiInfo, UiInfo.m_wProtocolLong + 1);
- #endif
- return 0;
- }
- //AddLocalCountNews(strNew/newid, time)
- int LuaAddLocalCountNews(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 2)
- return 0;
-
- PLAYER_SCRIPTACTION_SYNC UiInfo;
- UiInfo.m_bUIId = UI_NEWSINFO;
- UiInfo.m_bOptionNum = NEWSMESSAGE_COUNTING;
- UiInfo.m_nOperateType = SCRIPTACTION_UISHOW;
-
- int nMsgId = 0;
-
- int nTime = (int)Lua_ValueToNumber(L,2);
-
- if (nTime <= 0)
- nTime = 1;
-
- if (Lua_IsNumber(L,1))
- {
- nMsgId = (int)Lua_ValueToNumber(L,1);
- *((int *)(UiInfo.m_pContent)) = nMsgId;
- UiInfo.m_bParam1 = 1;
- *(int *)((char *)UiInfo.m_pContent + sizeof(int)) = nTime;
- UiInfo.m_nBufferLen = sizeof(int) * 2;
- }
- else
- {
- g_StrCpyLen(UiInfo.m_pContent, Lua_ValueToString(L,1), 64);
- UiInfo.m_nBufferLen = strlen(((char *)UiInfo.m_pContent));
- *(int *)((char *)UiInfo.m_pContent + UiInfo.m_nBufferLen) = nTime;
- UiInfo.m_nBufferLen += sizeof(int);
- UiInfo.m_bParam1 = 0;
- }
-
- #ifndef _SERVER
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0) return 0;
- UiInfo.m_bParam2 = 0;
- Player[nPlayerIndex].DoScriptAction(&UiInfo);
- #else
- UiInfo.m_bParam2 = 1;
- UiInfo.ProtocolType = (BYTE)s2c_scriptaction;
- UiInfo.m_wProtocolLong = sizeof(PLAYER_SCRIPTACTION_SYNC) - MAX_SCIRPTACTION_BUFFERNUM + UiInfo.m_nBufferLen - 1;
- g_NewProtocolProcess.BroadcastLocalServer(&UiInfo, UiInfo.m_wProtocolLong + 1);
- #endif
- return 0;
- }
- //AddGlobalTimeNews(strNew/newid, year,month,day,hour,mins)
- int LuaAddGlobalTimeNews(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 6)
- return 0;
-
- PLAYER_SCRIPTACTION_SYNC UiInfo;
- UiInfo.m_bUIId = UI_NEWSINFO;
- UiInfo.m_bOptionNum = NEWSMESSAGE_TIMEEND;
- UiInfo.m_nOperateType = SCRIPTACTION_UISHOW;
-
- int nMsgId = 0;
-
- if (Lua_IsNumber(L,1))
- {
- nMsgId = (int)Lua_ValueToNumber(L,1);
- *((int *)(UiInfo.m_pContent)) = nMsgId;
- UiInfo.m_bParam1 = 1;
- UiInfo.m_nBufferLen = sizeof(int) + sizeof(SYSTEMTIME);
- }
- else
- {
- g_StrCpyLen(UiInfo.m_pContent, Lua_ValueToString(L,1), 64);
- UiInfo.m_nBufferLen = strlen(((char *)UiInfo.m_pContent)) + sizeof(SYSTEMTIME);
- UiInfo.m_bParam1 = 0;
- }
-
- SYSTEMTIME *pSystemTime = (SYSTEMTIME *)((char *)UiInfo.m_pContent + UiInfo.m_nBufferLen - sizeof(SYSTEMTIME));
- memset(pSystemTime, 0, sizeof(SYSTEMTIME));
-
- SYSTEMTIME LocalTime ;
- memset(&LocalTime, 0, sizeof(SYSTEMTIME));
-
- LocalTime.wYear = (WORD)Lua_ValueToNumber(L,2);
- LocalTime.wMonth =(WORD)Lua_ValueToNumber(L,3);
- LocalTime.wDay = (WORD)Lua_ValueToNumber(L, 4);
- LocalTime.wHour = (WORD)Lua_ValueToNumber(L,5);
- LocalTime.wMinute = (WORD)Lua_ValueToNumber(L,6);
- FILETIME ft;
- FILETIME sysft;
- #ifdef WIN32
- SystemTimeToFileTime(&LocalTime, &ft);
- LocalFileTimeToFileTime(&ft, &sysft);
- FileTimeToSystemTime(&sysft, pSystemTime);
- #else
- memcpy(pSystemTime, &LocalTime, sizeof(LocalTime));
- #endif
-
- #ifndef _SERVER
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0) return 0;
- UiInfo.m_bParam2 = 0;
- Player[nPlayerIndex].DoScriptAction(&UiInfo);
- #else
- UiInfo.m_bParam2 = 1;
- UiInfo.ProtocolType = (BYTE)s2c_scriptaction;
- UiInfo.m_wProtocolLong = sizeof(PLAYER_SCRIPTACTION_SYNC) - MAX_SCIRPTACTION_BUFFERNUM + UiInfo.m_nBufferLen - 1;
- g_NewProtocolProcess.BroadcastGlobal(&UiInfo, UiInfo.m_wProtocolLong + 1);
- #endif
- return 0;
- }
- //AddLocalTimeNews(strNew/newid, year,month,day,hour,mins)
- int LuaAddLocalTimeNews(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 6)
- return 0;
-
- PLAYER_SCRIPTACTION_SYNC UiInfo;
- UiInfo.m_bUIId = UI_NEWSINFO;
- UiInfo.m_bOptionNum = NEWSMESSAGE_TIMEEND;
- UiInfo.m_nOperateType = SCRIPTACTION_UISHOW;
-
- int nMsgId = 0;
-
- if (Lua_IsNumber(L,1))
- {
- nMsgId = (int)Lua_ValueToNumber(L,1);
- *((int *)(UiInfo.m_pContent)) = nMsgId;
- UiInfo.m_bParam1 = 1;
- UiInfo.m_nBufferLen = sizeof(int) + sizeof(SYSTEMTIME);
- }
- else
- {
- g_StrCpyLen(UiInfo.m_pContent, Lua_ValueToString(L,1), 64);
- UiInfo.m_nBufferLen = strlen(((char *)UiInfo.m_pContent)) + sizeof(SYSTEMTIME);
- UiInfo.m_bParam1 = 0;
- }
-
- SYSTEMTIME *pSystemTime = (SYSTEMTIME *)((char *)UiInfo.m_pContent + UiInfo.m_nBufferLen - sizeof(SYSTEMTIME));
- memset(pSystemTime, 0, sizeof(SYSTEMTIME));
-
- SYSTEMTIME LocalTime ;
- memset(&LocalTime, 0, sizeof(SYSTEMTIME));
-
- LocalTime.wYear = (WORD)Lua_ValueToNumber(L,2);
- LocalTime.wMonth =(WORD)Lua_ValueToNumber(L,3);
- LocalTime.wDay = (WORD)Lua_ValueToNumber(L, 4);
- LocalTime.wHour = (WORD)Lua_ValueToNumber(L,5);
- LocalTime.wMinute = (WORD)Lua_ValueToNumber(L,6);
- FILETIME ft;
- FILETIME sysft;
- #ifdef WIN32
- SystemTimeToFileTime(&LocalTime, &ft);
- LocalFileTimeToFileTime(&ft, &sysft);
- FileTimeToSystemTime(&sysft, pSystemTime);
- #else
- memcpy(pSystemTime, &LocalTime, sizeof(LocalTime));
- #endif
-
- #ifndef _SERVER
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0) return 0;
- UiInfo.m_bParam2 = 0;
- Player[nPlayerIndex].DoScriptAction(&UiInfo);
- #else
- UiInfo.m_bParam2 = 1;
- UiInfo.ProtocolType = (BYTE)s2c_scriptaction;
- UiInfo.m_wProtocolLong = sizeof(PLAYER_SCRIPTACTION_SYNC) - MAX_SCIRPTACTION_BUFFERNUM + UiInfo.m_nBufferLen - 1;
- g_NewProtocolProcess.BroadcastLocalServer(&UiInfo, UiInfo.m_wProtocolLong + 1);
- #endif
- return 0;
- }
- //AddNote(str/strid)
- int LuaAddNote(Lua_State * L)
- {
- char * strMain = NULL;
- int nMainInfo = 0;
- int nDataType = 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0)
- return 0;
-
- int nParamNum = Lua_GetTopIndex(L);
- if (nParamNum < 1)
- return 0;
-
- int nParam2 = 0;
-
-
- if (Lua_IsNumber(L,1))
- {
- nMainInfo = (int)Lua_ValueToNumber(L,1);
- nDataType = 1 ;
- }
- else if (Lua_IsString(L, 1)) //检查主信息是字符串还是字符串标识号
- {
- strMain = (char *)Lua_ValueToString(L, 1);
- nDataType = 0 ;
- }
- else
- return 0;
-
- if (nParamNum > 1)
- {
- nParam2 = (int)Lua_ValueToNumber(L, 2);
- }
-
- PLAYER_SCRIPTACTION_SYNC UiInfo;
- UiInfo.m_bUIId = UI_NOTEINFO;
- UiInfo.m_bParam1 = nDataType;//主信息的类型,字符串(0)或数字(1)
- #ifndef _SERVER
- UiInfo.m_bParam2 = 0;
- #else
- UiInfo.m_bParam2 = 1;
- #endif
-
- UiInfo.m_bOptionNum = 0;
- UiInfo.m_nOperateType = SCRIPTACTION_UISHOW;
-
- //主信息为字符串
- if (nDataType == 0)
- {
- if (strMain)
- sprintf(UiInfo.m_pContent, "%s", strMain);
- int nLen = strlen(strMain);
- *(int*)(UiInfo.m_pContent + nLen) = nParam2;
- UiInfo.m_nBufferLen = nLen + sizeof(int);
- }
- else if (nDataType == 1) //主信息为数字标识
- {
- *(int *)UiInfo.m_pContent = nMainInfo;
- *(int *)(UiInfo.m_pContent + sizeof(int)) = nParam2;
- UiInfo.m_nBufferLen = sizeof(int) + sizeof(int);
- }
-
- Player[nPlayerIndex].DoScriptAction(&UiInfo);
- return 0;
- }
- /*
- **
- **格式1:Talk(SentenceNum, CallBack-Fun(结束后的回调函数), sTalk1, sTalk2, sTalk3, sTalk4,...sTalkN);
- Talk(SentenceNum, CallBack-Fun(结束后的回调函数), nTalk1, nTalk2,nTalk3,nTalk4,...nTalkN);
- **格式2:Talk(SentenceNum, CallBack-Fun, SentenceTab);
- **例子:Talk(3,"EndTalk", "玩家:请问现在几点钟了?", "雇员:现在5点钟了","太谢谢你了!");
- **
- */
- int LuaTalkUI(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- return 0;
- Player[nPlayerIndex].m_bWaitingPlayerFeedBack = false;
- int nMainInfo = 0;
- int nDataType = 0;
- int nOptionNum = 0;
- char * pContent = NULL;
-
- int nParamNum = Lua_GetTopIndex(L);
- if (nParamNum < 3)
- return 0;
-
- if (Lua_IsNumber(L,1))
- {
- nOptionNum = (int)Lua_ValueToNumber(L,1);
- }
- else
- {
- _ASSERT(0);
- return 0;
- }
-
- const char * pCallBackFun = Lua_ValueToString(L,2);
-
- //检查主信息是字符串还是字符串标识号
-
- if (Lua_IsNumber(L,3))
- {
- nDataType = 1 ;
- }
- else if (Lua_IsString(L, 3))
- {
- nDataType = 0 ;
- }
- else
- return 0;
-
-
- //获得实际传入的选项的个数
- if (nOptionNum > nParamNum - 2)
- nOptionNum = nParamNum - 2;
-
- PLAYER_SCRIPTACTION_SYNC UiInfo;
- UiInfo.m_bUIId = UI_TALKDIALOG;
- UiInfo.m_bParam1 = nDataType;//主信息的类型,字符串(0)或数字(1)
- UiInfo.m_bOptionNum = nOptionNum;
- UiInfo.m_nOperateType = SCRIPTACTION_UISHOW;
- pContent = UiInfo.m_pContent;
- pContent[0] = 0;
- size_t nContentLen = 0;
- for (int i = 0; i < nOptionNum; i ++)
- {
- const char * pString = NULL;
- if (!nDataType)//StringInfo
- {
- pString = Lua_ValueToString(L, i + 3);
- if (nContentLen + strlen(pString) >= MAX_SCIRPTACTION_BUFFERNUM)
- {
- nOptionNum = i;
- UiInfo.m_bOptionNum = nOptionNum;
- break;
- }
- nContentLen += strlen(pString);
- sprintf(pContent, "%s%s|", pContent, pString);
- }
- else
- {
- int j = (int)Lua_ValueToNumber(L, i + 3);
- sprintf(pContent, "%s%d|", pContent, j);
- }
- }
- UiInfo.m_nBufferLen = strlen(pContent);
-
- if (!pCallBackFun || strlen(pCallBackFun) <= 0)
- {
- UiInfo.m_nParam = 0;
- Player[nPlayerIndex].m_nAvailableAnswerNum = 0;
- Player[nPlayerIndex].m_bWaitingPlayerFeedBack = false;
- }
- else
- {
- UiInfo.m_nParam = 1;
- Player[nPlayerIndex].m_nAvailableAnswerNum = 1;
- g_StrCpyLen(Player[nPlayerIndex].m_szTaskAnswerFun[0], pCallBackFun, sizeof(Player[nPlayerIndex].m_szTaskAnswerFun[0]));
- Player[nPlayerIndex].m_bWaitingPlayerFeedBack = true;
- }
-
- #ifndef _SERVER
- UiInfo.m_bParam2 = 0;
- #else
- UiInfo.m_bParam2 = 1;
- #endif
-
- Player[nPlayerIndex].DoScriptAction(&UiInfo);
- return 0;
-
- }
- int LuaIncludeFile(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) <= 0) return 0;
-
- if (Lua_IsString(L,1))
- {
- const char * pFileName = lua_tostring(L,1);
- char lszCurrentDirectory[MAX_PATH];
- int nLen = 0;
- if (pFileName[0] != '\' && pFileName[0] != '/')
- {
- getcwd(lszCurrentDirectory, MAX_PATH);
- nLen = strlen(lszCurrentDirectory);
- if (lszCurrentDirectory[nLen - 1] == '\' || lszCurrentDirectory[nLen - 1] == '/')
- lszCurrentDirectory[nLen - 1] = 0;
- #ifdef WIN32
- g_StrCat(lszCurrentDirectory, "\");
- g_StrCat(lszCurrentDirectory, (char*)pFileName);
- #else
- g_StrCat(lszCurrentDirectory, "/");
- g_StrCat(lszCurrentDirectory, (char*)pFileName);
- for (int i = 0; lszCurrentDirectory[i]; i++)
- {
- if (lszCurrentDirectory[i] == '\')
- lszCurrentDirectory[i] = '/';
- }
- #endif
- }
- else
- {
- g_GetRootPath(lszCurrentDirectory);
- nLen = strlen(lszCurrentDirectory);
- if (lszCurrentDirectory[nLen - 1] == '\' || lszCurrentDirectory[nLen - 1] == '/')
- lszCurrentDirectory[nLen - 1] = 0;
- #ifdef WIN32
- g_StrCat(lszCurrentDirectory, "\");
- g_StrCat(lszCurrentDirectory, (char*)pFileName + 1);
- #else
- g_StrCat(lszCurrentDirectory, "/");
- g_StrCat(lszCurrentDirectory, (char*)pFileName + 1);
- for (int i = 0; lszCurrentDirectory[i]; i++)
- {
- if (lszCurrentDirectory[i] == '\')
- lszCurrentDirectory[i] = '/';
- }
- #endif
- }
- strlwr(lszCurrentDirectory + nLen);
- lua_dofile(L, lszCurrentDirectory);
- return 0;
- }
- else
- return 0;
- }
- //**************************************************************************************************************************************************************
- // 任务脚本
- //**************************************************************************************************************************************************************
- int LuaGetTaskValue(Lua_State * L)
- {
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nValue = (int)Player[nPlayerIndex].m_cTask.GetSaveVal((int)Lua_ValueToNumber(L,1));
- Lua_PushNumber(L, nValue);
- }
- else
- Lua_PushNil(L);
-
- return 1;
- }
- int LuaSetTaskValue(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- int nValueIndex = (int)Lua_ValueToNumber(L, 1);
- int nValue = (int)Lua_ValueToNumber(L, 2);
-
- if (nPlayerIndex <= 0) return 0;
- Player[nPlayerIndex].m_cTask.SetSaveVal(nValueIndex, nValue);
- return 0;
- }
- #ifndef _SERVER
- #define MAX_TEMPVALUENUM_INCLIENT 500
- int g_TempValue[MAX_TEMPVALUENUM_INCLIENT];
- #endif
- int LuaGetTempTaskValue(Lua_State * L)
- {
- int nTempIndex = (int)Lua_ValueToNumber(L, Lua_GetTopIndex(L));
-
- #ifdef _SERVER
- if(nTempIndex >= MAX_TEMP_TASK)
- {
- Lua_PushNil(L) ;
- return 1;
- }
- int nPlayerIndex = GetPlayerIndex(L);
-
- if (nPlayerIndex <= 0)
- {
- Lua_PushNil(L);
- return 1;
- }
-
- int nValue = Player[nPlayerIndex].m_cTask.GetClearVal(nTempIndex);
- Lua_PushNumber(L, nValue);
- #else
-
- if (nTempIndex >= 0 && nTempIndex < MAX_TEMPVALUENUM_INCLIENT)
- Lua_PushNumber(L, g_TempValue[nTempIndex]);
- else
- Lua_PushNil(L);
- #endif
- return 1;
- }
- int LuaSetTempTaskValue(Lua_State * L)
- {
- int nTempIndex = (int)Lua_ValueToNumber(L, Lua_GetTopIndex(L) - 1);
- int nValue = (int)Lua_ValueToNumber(L, Lua_GetTopIndex(L));
- #ifdef _SERVER
- Lua_GetGlobal(L, SCRIPT_PLAYERINDEX);
- int nPlayerIndex = (int)Lua_ValueToNumber(L, Lua_GetTopIndex(L));
- if (nPlayerIndex <= 0) return 0;
- Player[nPlayerIndex].m_cTask.SetClearVal(nTempIndex, nValue);
- #else
- g_TempValue[nTempIndex] = nValue;
- #endif
- return 0;
- }
- #ifdef _SERVER
- //---------------------------------交易、买卖、打开储藏箱-----------------------
- //Sale(id)
- //------------------------------------------------------------------------------
- int LuaSale(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) <= 0) return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nShopId = (int)Lua_ValueToNumber(L,1);
- //----在以下加入买卖的实际代码!
- BuySell.OpenSale(nPlayerIndex, nShopId - 1);
- }
- return 0;
- }
- int LuaTrade(Lua_State * L)
- {
- //Question 未写
- return 0;
- }
- int LuaOpenBox(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
-
- BYTE NetCommand = (BYTE)s2c_openstorebox;
- g_pServer->PackDataToClient(Player[nPlayerIndex].m_nNetConnectIdx, &NetCommand, sizeof(BYTE));
- return 0;
- }
- //---------------------------------时间任务-------------------------------------
- //SetTimer(Time, TimerTaskId)
- int LuaSetTimer(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- if (nParamCount < 2 ) return 0;
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- Player[nPlayerIndex].SetTimer((DWORD) (int)Lua_ValueToNumber(L, 1), (int)Lua_ValueToNumber(L,2));
- return 0;
- }
- int LuaStopTimer(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- Player[nPlayerIndex].CloseTimer();
- return 0;
- }
- int LuaGetCurTimerId(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- {
- Lua_PushNumber(L,0);
- return 1;
- }
- int nTimerId = Player[nPlayerIndex].m_TimerTask.GetTaskId();
- Lua_PushNumber(L, nTimerId);
- return 1;
- }
- int LuaGetRestTime(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- {
- Lua_PushNil(L);
- return 1;
- }
- int nRestTime = Player[nPlayerIndex].m_TimerTask.GetRestTime();//m_dwTimeTaskTime - g_SubWorldSet.GetGameTime();
-
- if (nRestTime > 0)
- Lua_PushNumber(L, nRestTime);
- else
- Lua_PushNumber(L, 0);
-
- return 1;
- }
- int LuaGetMissionRestTime(Lua_State * L)
- {
- int RestTime = 0;
- if (Lua_GetTopIndex(L) >= 2)
- {
- int nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex >= 0)
- {
- int nMissionId = (int)Lua_ValueToNumber(L, 1);
- int nTimerId = (int)Lua_ValueToNumber(L, 2);
-
- if (nMissionId < 0 || nTimerId < 0 )
- goto lab_getmissionresttime;
-
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- RestTime = (int)pMission->GetTimerRestTimer(nTimerId);
- }
- }
- }
-
- lab_getmissionresttime:
- Lua_PushNumber(L, RestTime);
- return 1;
- }
- //**************************************************************************************************************************************************************
- // 组队脚本
- //**************************************************************************************************************************************************************
- int LuaIsLeader(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0 )
- {
- if (Player[nPlayerIndex].m_cTeam.m_nFlag && Player[nPlayerIndex].m_cTeam.m_nFigure == TEAM_CAPTAIN)
- Lua_PushNumber(L,1);
- else
- Lua_PushNumber(L,0);
-
- }
- else
- Lua_PushNumber(L, 0);
- return 1;
- }
- int LuaGetTeamId(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- if (Player[nPlayerIndex].m_cTeam.m_nFlag)
- Lua_PushNumber(L, Player[nPlayerIndex].m_cTeam.m_nID);
- else Lua_PushNil(L);
- }
- else
- Lua_PushNil(L);
- return 1;
- }
- int LuaGetTeamSize(Lua_State * L)
- {
- int nTeamSize = 0;
- int nTeamId = -1;
- if (Lua_GetTopIndex(L) >= 1)
- {
- nTeamId = Lua_ValueToNumber(L, 1);
- }
- else
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- if (Player[nPlayerIndex].m_cTeam.m_nFlag)
- nTeamId = Player[nPlayerIndex].m_cTeam.m_nID;
- else
- nTeamId = -1;
- }
- }
-
- if (nTeamId < 0)
- nTeamSize = 0;
- else
- nTeamSize = g_Team[nTeamId].m_nMemNum + 1;
- Lua_PushNumber(L, nTeamSize);
- return 1;
- }
- int LuaLeaveTeam(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- if (Player[nPlayerIndex].m_cTeam.m_nFlag)
- {
- PLAYER_APPLY_LEAVE_TEAM sLeaveTeam;
- sLeaveTeam.ProtocolType = c2s_teamapplyleave;
- Player[nPlayerIndex].LeaveTeam((BYTE*)&sLeaveTeam);
- }
- }
- return 0;
- }
- int LuaSetCreateTeamOption(Lua_State * L)
- {
- int nState = (int)Lua_ValueToNumber(L, 1);
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- if (nState)
- Player[nPlayerIndex].m_cTeam.SetCanTeamFlag(nPlayerIndex, TRUE);
- else
- Player[nPlayerIndex].m_cTeam.SetCanTeamFlag(nPlayerIndex, FALSE);
- }
- return 0;
- }
- //**************************************************************************************************************************************************************
- // 聊天消息脚本
- //**************************************************************************************************************************************************************
- int LuaMsgToPlayer(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) <= 0) return 0;
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- const char * szMsg = Lua_ValueToString(L,1);
- if (szMsg)
- KPlayerChat::SendSystemInfo(1, nPlayerIndex, MESSAGE_SYSTEM_ANNOUCE_HEAD, (char *) szMsg, strlen(szMsg) );
- }
-
- return 0;
- }
- int LuaMsgToTeam(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) <= 0 ) return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- if (Player[nPlayerIndex].m_cTeam.m_nID >= 0)
- {
- const char * szMsg = Lua_ValueToString(L,1);
- int nTeamLeaderId = g_Team[Player[nPlayerIndex].m_cTeam.m_nID].m_nCaptain;
- if (nTeamLeaderId > 0)
- KPlayerChat::SendSystemInfo(1, nTeamLeaderId, "组队消息",(char *) szMsg, strlen(szMsg) );
-
- for (int i = 0; i < MAX_TEAM_MEMBER; i ++)
- {
- int nMemberId = g_Team[Player[nPlayerIndex].m_cTeam.m_nID].m_nMember[i] ;
- if (nMemberId > 0)
- {
- if (szMsg)
- KPlayerChat::SendSystemInfo(1, nMemberId, "组队消息", (char *)szMsg, strlen(szMsg) );
- }
- }
- }
- }
- return 0;
- }
- int LuaMsgToSubWorld(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) <= 0 ) return 0;
-
- const char * szMsg = Lua_ValueToString(L,1);
- if (szMsg)
- KPlayerChat::SendSystemInfo(0, 0, MESSAGE_SYSTEM_ANNOUCE_HEAD, (char *)szMsg, strlen(szMsg) );
- return 0;
- }
- int LuaMsgToAroundRegion(Lua_State * L)
- {
-
- return 0;
- }
- //**************************************************************************************************************************************************************
- // 主角脚本
- //**************************************************************************************************************************************************************
- //**************************************************************************************************************************************************************
- // 主角脚本
- //**************************************************************************************************************************************************************
- /*功能:让玩家进入新的一个游戏世界
- nPlayerIndex:主角的Index
- nSubWorldIndex:游戏世界id
- nPosX:
- nPosY:
- */
- //NewWorld(WorldId, X,Y)
- int LuaEnterNewWorld(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0)
- return 0;
-
- int nResult = 0;
- if (Lua_GetTopIndex(L) >= 3)
- {
- DWORD dwWorldId = (DWORD)Lua_ValueToNumber(L, 1);
- nResult = Npc[Player[nPlayerIndex].m_nIndex].ChangeWorld(dwWorldId, (int)Lua_ValueToNumber(L,2) * 32, (int)Lua_ValueToNumber(L,3) * 32);
- }
- Lua_PushNumber(L, nResult);
- return 1;
- }
- //SetPos(X,Y)
- int LuaSetPos(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- if (nParamCount != 2) return 0;
- int nPlayerIndex = GetPlayerIndex(L);
-
- int nX = (int) Lua_ValueToNumber(L,1);
- int nY = (int) Lua_ValueToNumber(L,2);
-
- if (nPlayerIndex > 0)
- {
- Npc[Player[nPlayerIndex].m_nIndex].SetPos(nX * 32, nY * 32);
- }
- return 0;
- }
- int LuaGetPos(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
-
- if (nPlayerIndex > 0)
- {
- int nPosX = 0;
- int nPosY = 0;
- Npc[Player[nPlayerIndex].m_nIndex].GetMpsPos(&nPosX, &nPosY);
- Lua_PushNumber(L, nPosX);
- Lua_PushNumber(L, nPosY);
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_SubWorldIndex);
- }
- else
- return 0;
- return 3;
- }
- //W,X,Y = GetWorldPos()
- int LuaGetNewWorldPos(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
-
- if (nPlayerIndex > 0)
- {
- int nPosX = 0;
- int nPosY = 0;
- Npc[Player[nPlayerIndex].m_nIndex].GetMpsPos(&nPosX, &nPosY);
- int nSubWorldIndex = Npc[Player[nPlayerIndex].m_nIndex].m_SubWorldIndex;
- int nSubWorldID = 0;
- if (nSubWorldIndex >= 0 && nSubWorldIndex < MAX_SUBWORLD)
- {
- nSubWorldID = SubWorld[nSubWorldIndex].m_SubWorldID;
- }
- Lua_PushNumber(L, nSubWorldID);
- Lua_PushNumber(L, ((int)(nPosX / 32)));
- Lua_PushNumber(L, ((int)(nPosY / 32)));
- }
- else
- {
- Lua_PushNumber(L, 0);
- Lua_PushNumber(L, 0);
- Lua_PushNumber(L, 0);
- return 3;
- }
- return 3;
- }
- int LuaDropItem(Lua_State *L)
- {
- return 0;
- }
- /*AddEventItem(id)*/
- KTabFile g_EventItemTab;
- int LuaAddEventItem(Lua_State *L)
- {
- // modify by spe 03/06/13
- if (Lua_GetTopIndex(L) < 1)
- return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
-
- if (nPlayerIndex <= 0)
- {
- Lua_PushNumber(L,0);
- return 1;
- }
- int nEventId = 0;
- if (Lua_IsNumber(L, 1))
- {
- nEventId = (int)Lua_ValueToNumber(L,1);
- }
- else
- {
- char * szEventItm = (char *)Lua_ValueToString(L,1);
-
- if (!g_EventItemTab.GetInteger(szEventItm, "具体类别", 0, &nEventId))
- {
- Lua_PushNumber(L,0);
- return 1;
- }
- }
-
- int nIndex = ItemSet.Add(item_task, 0, 0, 0, nEventId, 0, 0, 1, 0);
-
- if (nIndex <= 0)
- {
- Lua_PushNumber(L,0);
- return 1;
- }
-
- int x, y;
- if (Player[nPlayerIndex].m_ItemList.CheckCanPlaceInEquipment(Item[nIndex].GetWidth(), Item[nIndex].GetHeight(), &x, &y))
- {
- Player[nPlayerIndex].m_ItemList.Add(nIndex, pos_equiproom, x, y);
- }
- else
- {
- int nIdx = Player[nPlayerIndex].m_ItemList.Hand();
- if (nIdx)
- {
- Player[nPlayerIndex].m_ItemList.Remove(nIdx);
-
- KMapPos sMapPos;
- KObjItemInfo sInfo;
-
- Player[nPlayerIndex].GetAboutPos(&sMapPos);
-
- sInfo.m_nItemID = nIdx;
- sInfo.m_nItemWidth = Item[nIdx].GetWidth();
- sInfo.m_nItemHeight = Item[nIdx].GetHeight();
- sInfo.m_nMoneyNum = 0;
- strcpy(sInfo.m_szName, Item[nIdx].GetName());
- sInfo.m_nColorID = 0;
- sInfo.m_nMovieFlag = 1;
- sInfo.m_nSoundFlag = 1;
-
- int nObj = ObjSet.Add(Item[nIdx].GetObjIdx(), sMapPos, sInfo);
- if (nObj >= 0)
- {
- if (Item[nIdx].GetGenre() == item_task)
- {
- Object[nObj].SetEntireBelong(nPlayerIndex);
- }
- else
- {
- Object[nObj].SetItemBelong(nPlayerIndex);
- }
- }
- }
- Player[nPlayerIndex].m_ItemList.Add(nIndex, pos_hand, 0 ,0);
- }
- Lua_PushNumber(L, 1);
- return 1;
- }
- /*AddItem(nItemClass, nDetailType, nParticualrType, nLevel, nSeries, nLuck, nItemLevel..6)*/
- int LuaAddItem(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
-
- if (nPlayerIndex <= 0)
- {
- Lua_PushNumber(L,0);
- return 1;
- }
-
- int nParamNum = Lua_GetTopIndex(L);
- if (nParamNum < 7)
- {
- g_DebugLog("[Script]使用AddItem参数数量不符!");
- Lua_PushNumber(L,0);
- return 1;
- }
-
- int nItemClass = (int)Lua_ValueToNumber(L, 1);
- int nDetailType = (int)Lua_ValueToNumber(L, 2);
- int nParticularType = (int)Lua_ValueToNumber(L, 3);
- int nLevel = (int)Lua_ValueToNumber(L, 4);
- int nSeries = (int)Lua_ValueToNumber(L, 5);
- int nLuck = (int)Lua_ValueToNumber(L, 6);
- int nItemLevel[6];
-
- ZeroMemory(nItemLevel, sizeof(nItemLevel));
- nItemLevel[0] = (int)Lua_ValueToNumber(L, 7);
-
- if (nParamNum >= 12)
- {
- nItemLevel[1] = (int)Lua_ValueToNumber(L, 8);
- nItemLevel[2] = (int)Lua_ValueToNumber(L, 9);
- nItemLevel[3] = (int)Lua_ValueToNumber(L, 10);
- nItemLevel[4] = (int)Lua_ValueToNumber(L, 11);
- nItemLevel[5] = (int)Lua_ValueToNumber(L, 12);
- }
- else
- {
- for (int i = 0; i < 5; i ++)
- nItemLevel[i + 1] = nItemLevel[0];
- }
-
- int nIndex = ItemSet.Add(nItemClass, nSeries, nLevel, nLuck, nDetailType, nParticularType, nItemLevel, g_SubWorldSet.GetGameVersion());
- if (nIndex <= 0)
- {
- Lua_PushNumber(L, 0);
- return 1;
- }
-
- int x, y;
- if (Player[nPlayerIndex].m_ItemList.CheckCanPlaceInEquipment(Item[nIndex].GetWidth(), Item[nIndex].GetHeight(), &x, &y))
- {
- Player[nPlayerIndex].m_ItemList.Add(nIndex, pos_equiproom, x, y);
- }
- else
- {
- int nIdx = Player[nPlayerIndex].m_ItemList.Hand();
- if (nIdx)
- {
- Player[nPlayerIndex].m_ItemList.Remove(nIdx);
-
- KMapPos sMapPos;
- KObjItemInfo sInfo;
-
- Player[nPlayerIndex].GetAboutPos(&sMapPos);
-
- sInfo.m_nItemID = nIdx;
- sInfo.m_nItemWidth = Item[nIdx].GetWidth();
- sInfo.m_nItemHeight = Item[nIdx].GetHeight();
- sInfo.m_nMoneyNum = 0;
- strcpy(sInfo.m_szName, Item[nIdx].GetName());
- sInfo.m_nColorID = 0;
- sInfo.m_nMovieFlag = 1;
- sInfo.m_nSoundFlag = 1;
-
- int nObj = ObjSet.Add(Item[nIdx].GetObjIdx(), sMapPos, sInfo);
- if (nObj >= 0)
- {
- if (Item[nIdx].GetGenre() == item_task)
- {
- Object[nObj].SetEntireBelong(nPlayerIndex);
- }
- else
- {
- Object[nObj].SetItemBelong(nPlayerIndex);
- }
- }
- }
- Player[nPlayerIndex].m_ItemList.Add(nIndex, pos_hand, 0 ,0);
- }
-
- Lua_PushNumber(L,1);
-
- return 1;
-
- }
- int LuaGetTaskItemCount(Lua_State * L)
- {
-
- if (Lua_GetTopIndex(L) > 0)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nEventId = 0;
- if (Lua_IsNumber(L, 1))
- {
- nEventId = (int)Lua_ValueToNumber(L,1);
- }
- else
- {
- char * szEventItm = (char *)Lua_ValueToString(L,1);
-
- if (!g_EventItemTab.GetInteger(szEventItm, "具体类别", 0, &nEventId))
- {
- Lua_PushNumber(L,0);
- return 1;
- }
- }
-
- int nCount = Player[nPlayerIndex].m_ItemList.GetTaskItemNum(nEventId);
- Lua_PushNumber(L, nCount);
- }
- else
- {
- g_DebugLog("GetItemCount nPlayerIndex <= 0");
- Lua_PushNumber(L,0);
- }
- }
- else
- {
- g_DebugLog("GetItem 参数不够!");
- Lua_PushNumber(L , 0);
- }
-
- return 1;
- }
- /*nPlayerIndex, nItemTemplateId
- 功能:给玩家某个物品
- */
- /*
- DelItem (nPlayerIndex, nItemTemplateId)
- 功能:删除玩家身上某个物品
- */
- int LuaDelItem(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) > 0)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nEventId = 0;
- if (Lua_IsNumber(L, 1))
- {
- nEventId = (int)Lua_ValueToNumber(L,1);
- }
- else
- {
- char * szEventItm = (char *)Lua_ValueToString(L,1);
- if (!g_EventItemTab.GetInteger(szEventItm, "具体类别", 0, &nEventId))
- {
- return 0;
- }
- }
-
- int nResult = Player[nPlayerIndex].m_ItemList.RemoveTaskItem(nEventId);
-
- }
- else
- {
- g_DebugLog("[TASK] Can Not Del Item ");
- }
- }
- else
- {
- g_DebugLog("HaveItem 参数不够!");
- }
-
- return 0;
- }
- /*HaveItem(nItemTemplateId);
- 功能:检查玩家是否有某个物品
- */
- int LuaHaveItem(Lua_State *L)
- {
- if (Lua_GetTopIndex(L) > 0)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nEventId = 0;
- if (Lua_IsNumber(L, 1))
- {
- nEventId = (int)Lua_ValueToNumber(L,1);
- }
- else
- {
- char * szEventItm = (char *)Lua_ValueToString(L,1);
-
- if (!g_EventItemTab.GetInteger(szEventItm, "具体类别", 0, &nEventId))
- {
- Lua_PushNumber(L,0);
- return 1;
- }
- }
-
- int nResult = Player[nPlayerIndex].m_ItemList.IsTaskItemExist(nEventId);
- Lua_PushNumber(L, (nResult != 0));
- }
- else
- {
- g_DebugLog("HaveItem nPlayerIndex <= 0");
- Lua_PushNumber(L,0);
- }
- }
- else
- {
- g_DebugLog("HaveItem 参数不够!");
- Lua_PushNumber(L , 0);
- }
-
- return 1;
- }
- /*
- AddMagic(nPlayerIndex, nMagicID, nLevel)
- DelMagic(nPlayerIndex, nMagicId)
- HaveMagic(nPlayerIndex, nMagicId)
- GetMagicLevel(nPlayerIndex, nMagicId)
- SetMagicLevel(nPlayerIndex, nMagicId, nLevel)
- ModifyMagicLevel(nPlayerIndex ,nMagicId, nDLevel)
- */
- int LuaAddMagic(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- int nPlayerIndex = 0;
- if (nParamCount < 1) return 0;
- nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- int nSkillId = 0;
- if (Lua_IsNumber(L, 1))
- {
- nSkillId = (int)Lua_ValueToNumber (L, 1);
- }
- else
- {
- const char * sSkillName = Lua_ValueToString(L, 1);
- g_OrdinSkillsSetting.GetInteger((char*)sSkillName, "SkillId", 0, &nSkillId);
- if (nSkillId <= 0 ) return 0;
- }
- Player[nPlayerIndex].m_nIndex;
- int nLevel = 0;
- if (nParamCount >=2)
- nLevel = (int)Lua_ValueToNumber(L,2);
- else
- nLevel = 0;
-
- int nRet = Npc[Player[nPlayerIndex].m_nIndex].m_SkillList.Add(nSkillId, nLevel);
- if (nRet)
- {
- PLAYER_SKILL_LEVEL_SYNC NewSkill;
- NewSkill.ProtocolType = s2c_playerskilllevel;
- NewSkill.m_nSkillID = nSkillId;
- NewSkill.m_nSkillLevel = Npc[Player[nPlayerIndex].m_nIndex].m_SkillList.GetCurrentLevel(nSkillId);
- NewSkill.m_nLeavePoint = Player[nPlayerIndex].m_nSkillPoint;
- g_pServer->PackDataToClient(Player[nPlayerIndex].m_nNetConnectIdx, (BYTE*)&NewSkill, sizeof(PLAYER_SKILL_LEVEL_SYNC));
- }
-
- return 0;
- }
- int LuaDelMagic(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- int nPlayerIndex = 0;
- if (nParamCount < 1) return 0;
-
- nPlayerIndex = GetPlayerIndex(L);
-
- if (nPlayerIndex <= 0) return 0;
-
- int nSkillId = 0;
- if (Lua_IsNumber(L, 1))
- {
- nSkillId = (int)Lua_ValueToNumber (L, 1);
- }
- else
- {
- const char * sSkillName = Lua_ValueToString(L, 1);
- g_OrdinSkillsSetting.GetInteger((char*)sSkillName, "SkillId", 0, &nSkillId);
- if (nSkillId <= 0 ) return 0;
- }
- Npc[Player[nPlayerIndex].m_nIndex].m_SkillList.Remove(nSkillId);
- return 0;
-
- }
- int LuaHaveMagic(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- int nPlayerIndex = 0;
- if (nParamCount < 1) return 0;
-
- nPlayerIndex = GetPlayerIndex(L);
-
- if (nPlayerIndex <= 0) return 0;
-
- int nSkillId = 0;
- if (Lua_IsNumber(L, 1))
- {
- nSkillId = (int)Lua_ValueToNumber (L, 1);
- }
- else
- {
- const char * sSkillName = Lua_ValueToString(L, 1);
- g_OrdinSkillsSetting.GetInteger((char *)sSkillName, "SkillId", 0, &nSkillId);
- if (nSkillId <= 0 )
- {
- Lua_PushNumber(L, -1);
- }
- return 1;
- }
-
- if (Npc[Player[nPlayerIndex].m_nIndex].m_SkillList.FindSame(nSkillId))
- {
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_SkillList.GetLevel(nSkillId));
- }
- else
- {
- Lua_PushNumber(L, -1);
- }
-
- return 1;
- }
- int LuaGetSkillIdInSkillList(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- return 0;
- int nSkillIndex = (int)Lua_ValueToNumber (L, 1);
- int nSkillId = 0;
- if (nSkillIndex > 0)
- {
- nSkillId = Npc[Player[nPlayerIndex].m_nIndex].m_SkillList.GetSkillId(nSkillIndex);
- }
- Lua_PushNumber(L, nSkillId);
- return 1;
- }
- int LuaSetSkillLevel(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 2)
- return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- return 0;
- int nSkillId = 0;
-
- if (Lua_IsNumber(L, 1))
- {
- nSkillId = (int)Lua_ValueToNumber (L, 1);
- }
- else
- {
- const char * sSkillName = Lua_ValueToString(L, 1);
- g_OrdinSkillsSetting.GetInteger((char *)sSkillName, "SkillId", 0, &nSkillId);
- if (nSkillId <= 0 ) return 0;
- }
- int nLevel = (int)Lua_ValueToNumber(L, 2);
- if (nLevel >= 0)
- Npc[Player[nPlayerIndex].m_nIndex].m_SkillList.SetSkillLevelDirectlyUsingId(nSkillId, nLevel);
- return 0;
- }
- int LuaRollBackSkills(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- return 0;
- int nSkillId = 0;
- int nTotalSkill = Npc[Player[nPlayerIndex].m_nIndex].m_SkillList.ClearSkillLevel(true);
- Lua_PushNumber(L, nTotalSkill);
- return 1;
- }
- int LuaUpdateSkillList(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- return 0;
- Player[nPlayerIndex].SendSyncData_Skill();
- return 0;
- }
- int LuaGetMagicLevel(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- int nPlayerIndex = 0;
-
- if (nParamCount < 1) return 0;
- nPlayerIndex = GetPlayerIndex(L);
-
- if (nPlayerIndex <= 0) return 0;
-
- int nSkillId = 0;
- if (Lua_IsNumber(L, 1))
- {
- nSkillId = (int)Lua_ValueToNumber (L, 1);
- }
- else
- {
- const char * sSkillName = Lua_ValueToString(L, 1);
- g_OrdinSkillsSetting.GetInteger((char *)sSkillName, "SkillId", 0, &nSkillId);
- if (nSkillId <= 0 ) return 0;
- }
- Lua_PushNumber(L,Npc[Player[nPlayerIndex].m_nIndex].m_SkillList.GetLevel(nSkillId));
- return 1;
-
- }
- /*
- int LuaSetMagicLevel(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- int nPlayerIndex = 0;
- int nTemp = 0;
- if (nParamCount < 1) return 0;
- nPlayerIndex = GetPlayerIndex(L);
-
- if (nPlayerIndex <= 0) return 0;
-
- int nSkillId = 0;
- if (Lua_IsNumber(L, nTemp))
- {
- nSkillId = (int)Lua_ValueToNumber (L, 1);
- }
- else
- {
- const char * sSkillName = Lua_ValueToString(L, 1);
- nSkillId = g_OrdinSkillsSetting.FindRow((char *)sSkillName) - 2;
- if (nSkillId <= 0 ) return 0;
- }
- int nNpcIndex = Player[nPlayerIndex].m_nIndex;
- if (nNpcIndex > 0)
- Lua_PushNumber(L,Npc[nNpcIndex].m_SkillList.SetSkillLevel(nSkillId, (int)Lua_ValueToNumber(L, 2)));
- return 0;
- }
- */
- //**************************************************************************************************************************************************************
- // NPC操作脚本
- //**************************************************************************************************************************************************************
- /*nNpcTemplateId GetNpcTmpId(sName)
- 功能从Npc模板中获得名称为sName的Npc在模板中的Id
- sName:Npc名称
- nNpcTemplateID:模板中Id
- */
- int LuaGetNpcTemplateID(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) > 0)
- {
- if (Lua_IsString(L,1))
- {
- const char * pName = lua_tostring(L,1);
- int nId = g_NpcSetting.FindRow((char*)pName) - 2;
- Lua_PushNumber(L, nId);
- }
- else
- return 0;
- }
- else
- return 0;
- return 1;
- }
- /*
- nNpcIndex AddNpc(nNpcTemplateId,nLevel, nSubWorldIndex, nPosX, nPosY )
- 功能:增加一个特定的NPC
- 参数:
- nNpcTemplateId: NPC在NPC模板中的id
- nLevel:Npc的等级
- nSubWorldIndex:所处的世界id
- nPosX:X (点坐标)
- nPosY:Y (点坐标)
- nNpcIndex:增加后,将返回该Npc在游戏世界的Index,如果不成功返回nil
- */
- int LuaAddNpc(Lua_State * L)
- {
- char * pName = NULL;
- int nId = 0;
- if (Lua_GetTopIndex(L) < 5) return 0;
-
- if (Lua_IsNumber(L,1))
- {
- nId = (int)Lua_ValueToNumber(L,1);
- }
- else if (Lua_IsString(L,1))
- {
- pName = (char *)lua_tostring(L,1);
- nId = g_NpcSetting.FindRow((char*)pName) - 2;
- }
- else return 0;
-
- if (nId < 0) nId = 0;
-
- int nLevel = (int)lua_tonumber(L,2);
- //if (nLevel >= 128) nLevel = 127;
- if (nLevel < 0 ) nLevel = 1;
-
- int nNpcIdxInfo = MAKELONG(nLevel, nId);//(nId << 7) + nLevel;
- //question
- int nNpcIdx = NpcSet.Add(nNpcIdxInfo, (int)lua_tonumber(L, 3), (int)lua_tonumber(L,4), (int)lua_tonumber(L,5));
- // g_StrCpy(Npc[nNpcIdx].Name, (char*)pName);
- Lua_PushNumber(L, nNpcIdx);
- return 1;
- }
- /*nResult DelNpc (nNpcIndex)
- 功能:删除一个特定的NPC
- nResult:返回成功与否,1为成功,0为失败
- */
- int LuaDelNpc(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) <= 0 ) return 0 ;
- int nNpcIndex = (int)Lua_ValueToNumber(L, 1);
- if (nNpcIndex > 0)
- {
- if (Npc[nNpcIndex].m_RegionIndex >= 0)
- {
- SubWorld[Npc[nNpcIndex].m_SubWorldIndex].m_Region[Npc[nNpcIndex].m_RegionIndex].RemoveNpc(nNpcIndex);
- SubWorld[Npc[nNpcIndex].m_SubWorldIndex].m_Region[Npc[nNpcIndex].m_RegionIndex].DecRef(Npc[nNpcIndex].m_MapX, Npc[nNpcIndex].m_MapY, obj_npc);
- }
- NpcSet.Remove(nNpcIndex);
- }
- return 0;
- }
- /*
- nDelCount DelNpcsInRgn(nSubWorld,nRegionId, nKind)
- 功能:删除某个游戏世界中某个Region内的所有某类的NPC
- 返回:删除的Npc个数
- */
- int LuaDelNpcsInRgn(Lua_State * L)
- {
- //Question
- return 0;
- }
- /*
- nDelCount DelNpcsInWld(nSubWorldId, nKind)
- 功能:删除某个游戏世界中的所有Npc
- */
- int LuaDelNpcsInWld(Lua_State * L)
- {
- return 0;
- }
- /*
- SetNpcPos (nNpcIndex, x, y)
- 功能:设置/修改一个NPC的位置
- 参数:
- nNpcIndex:Npc的id
- x:X坐标
- y:Y坐标
- */
- int LuaSetNpcPos(Lua_State * L)
- {
- int nParamCount = 0;
- if ((nParamCount = Lua_GetTopIndex(L)) < 3) return 0;
- int nNpcIndex = (int)Lua_ValueToNumber(L, 1);
- if (nNpcIndex <= 0) return 0;
- Npc[nNpcIndex].m_MapX = (int)Lua_ValueToNumber(L, 2);
- Npc[nNpcIndex].m_MapY = (int)Lua_ValueToNumber(L, 3);
-
- return 0;
- }
- /*SetNpcDthSct (nNpcIndex, map, “*.txt” )
- 功能:设置NPC死亡脚本
- 参数:
- nNpcIndex:NPCIndex
- *.txt:脚本文件名
- */
- int LuaSetNpcActionScript(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 2 ) return 0;
- int nNpcIndex = (int)Lua_ValueToNumber(L, 1);
- if (nNpcIndex <= 0 || nNpcIndex >= MAX_NPC) return 0;
- strcpy(Npc[nNpcIndex].ActionScript, Lua_ValueToString(L,2));
- Npc[nNpcIndex].m_ActionScriptID = g_FileName2Id((char *)Lua_ValueToString(L,2));
- return 0;
- }
- /*
- SetRevivalPos(subworldid = -1, revid )
- 功能:设置Npc重生点
- */
- int LuaSetPlayerRevivalPos(Lua_State * L)
- {
- //Question
- int nParamCount = Lua_GetTopIndex(L);
- int nPlayerIndex = 0;
- int nBeginIndex = 2;
- nPlayerIndex = GetPlayerIndex(L);
- int nSubWorldId = 0;
- int nRevId = 0;
- if (nPlayerIndex < 0)
- {
- return 0;
- }
-
- if (nParamCount >= 2)
- {
- nSubWorldId = (int) Lua_ValueToNumber(L, 1);
- nRevId = (int) Lua_ValueToNumber(L, 2);
- }
- else if (nParamCount == 1)
- {
- nSubWorldId = -1;
- nRevId = (int) Lua_ValueToNumber(L, 1);
- }
- else
- {
- return 0;
- }
-
- Player[nPlayerIndex].SetRevivalPos(nSubWorldId, nRevId);
- return 0;
- }
- //**************************************************************************************************************************************************************
- // 聊天消息脚本
- //**************************************************************************************************************************************************************
- //**********************************************************************************************
- // 主角属性获得
- //**********************************************************************************************
- #define MacroFun_GetPlayerInfoInt(L, MemberName) { int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0){ int nNpcIndex = Player[nPlayerIndex].m_nIndex; if (nNpcIndex > 0)Lua_PushNumber(L, Npc[nNpcIndex].MemberName);
- else Lua_PushNil(L);}
- else Lua_PushNil(L);
- return 1;}
- //阵营
- int LuaGetPlayerCurrentCamp(Lua_State * L)
- {
- MacroFun_GetPlayerInfoInt(L, m_CurrentCamp);
- }
- int LuaGetPlayerCamp(Lua_State * L)
- {
- MacroFun_GetPlayerInfoInt(L, m_Camp);
- }
- int LuaSetPlayerCamp(Lua_State * L)
- {
- int nValue = (int)Lua_ValueToNumber(L,1);
- if (nValue < 0 ) return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- Npc[Player[nPlayerIndex].m_nIndex].SetCamp(nValue);
- }
- return 0;
- }
- int LuaSetPlayerCurrentCamp(Lua_State * L)
- {
- int nValue = (int)Lua_ValueToNumber(L,1);
- if (nValue < 0 ) return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- Npc[Player[nPlayerIndex].m_nIndex].SetCurrentCamp(nValue);
- }
- return 0;
- }
- int LuaSetNpcCurCamp(Lua_State * L)
- {
- int nNpcIndex = (int)Lua_ValueToNumber(L,1);
- if (nNpcIndex <= 0 && nNpcIndex > MAX_NPC) return 0;
- int nValue = (int )Lua_ValueToNumber(L,2);
- if (nValue >= camp_num) return 0;
- Npc[nNpcIndex].SetCurrentCamp(nValue);
- return 0;
- }
- int LuaRestorePlayerCamp(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- Npc[Player[nPlayerIndex].m_nIndex].RestoreCurrentCamp();
- }
- return 0;
- }
- int LuaOpenTong(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0) return 0;
-
- PLAYER_SCRIPTACTION_SYNC UiInfo;
- UiInfo.m_bUIId = UI_OPENTONGUI;
- UiInfo.m_bOptionNum = 0;
- UiInfo.m_nOperateType = SCRIPTACTION_UISHOW;
-
- int nMsgId = 0;
- UiInfo.m_bParam1 = 0;
- UiInfo.m_nBufferLen = sizeof(int);
-
- #ifndef _SERVER
- UiInfo.m_bParam2 = 0;
- Player[nPlayerIndex].DoScriptAction(&UiInfo);
- #else
- UiInfo.m_bParam2 = 1;
- UiInfo.ProtocolType = (BYTE)s2c_scriptaction;
- UiInfo.m_wProtocolLong = sizeof(PLAYER_SCRIPTACTION_SYNC) - MAX_SCIRPTACTION_BUFFERNUM + UiInfo.m_nBufferLen - 1;
- g_NewProtocolProcess.BroadcastGlobal(&UiInfo, UiInfo.m_wProtocolLong + 1);
- #endif
- return 0;
- }
- //门派
- int LuaGetPlayerFaction(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- char FactionName[100];
- Player[nPlayerIndex].GetFactionName(FactionName, 100);
- Lua_PushString(L, FactionName);
- }
- else
- {
- Lua_PushString(L,"");
- }
- return 1;
- }
- int LuaChangePlayerFaction(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- int nResult = 0;
- if (nPlayerIndex > 0)
- {
- const char * szFactionName = Lua_ValueToString(L,1);
- Player[nPlayerIndex].LeaveCurFaction();
- if (strlen(szFactionName) == 0)
- {
- nResult = 1;
- }
- else
- {
- nResult = Player[nPlayerIndex].AddFaction((char *)szFactionName);
- }
- }
- Lua_PushNumber(L, nResult);
- return 1;
- }
- //抗性 *************************************************************************************
- //0表示当前,1表示原始的,2表示最大的
- int LuaGetPlayerColdResist(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nType = (int)Lua_ValueToNumber(L,1);
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_CurrentColdResist);break;
- case 1:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_ColdResist); break;
- case 2:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_ColdResistMax);break;
- default:
- Lua_PushNil(L);
- }
- }
- else
- Lua_PushNil(L);
- return 1;
- }
- int LuaSetPlayerColdResist(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nValue = (int)Lua_ValueToNumber(L,2);
- if (nValue < 0) nValue = 0;
- if (nValue > Npc[Player[nPlayerIndex].m_nIndex].m_ColdResistMax) nValue = Npc[Player[nPlayerIndex].m_nIndex].m_ColdResistMax;
-
- int nType = (int)Lua_ValueToNumber(L,1);
-
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Npc[Player[nPlayerIndex].m_nIndex].m_CurrentColdResist = nValue;
- break;
-
- case 1:
- Npc[Player[nPlayerIndex].m_nIndex].m_ColdResist = nValue;
- break;
- case 2:
- Npc[Player[nPlayerIndex].m_nIndex].m_ColdResistMax = nValue;
- break;
- }
-
-
- }
- return 0;
-
- }
- int LuaGetPlayerFireResist(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
-
- int nType = (int)Lua_ValueToNumber(L,1);
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_CurrentFireResist);break;
- case 1:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_FireResist); break;
- case 2:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_FireResistMax);break;
- default:
- Lua_PushNil(L);
- }
- }
- else
- Lua_PushNil(L);
- return 1;
- }
- int LuaSetPlayerFireResist(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
-
-
- int nValue = (int)Lua_ValueToNumber(L,2);
- if (nValue < 0) nValue = 0;
- if (nValue > Npc[Player[nPlayerIndex].m_nIndex].m_FireResistMax) nValue = Npc[Player[nPlayerIndex].m_nIndex].m_FireResistMax;
-
- int nType = (int)Lua_ValueToNumber(L,1);
-
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Npc[Player[nPlayerIndex].m_nIndex].m_CurrentFireResist = nValue;
- break;
-
- case 1:
- Npc[Player[nPlayerIndex].m_nIndex].m_FireResist = nValue;
- break;
- case 2:
- Npc[Player[nPlayerIndex].m_nIndex].m_FireResistMax = nValue;
- break;
- }
-
-
- }
- return 0;
-
- }
- int LuaGetPlayerLightResist(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nType = (int)Lua_ValueToNumber(L,1);
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_CurrentLightResist);break;
- case 1:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_LightResist); break;
- case 2:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_LightResistMax);break;
- default:
- Lua_PushNil(L);
- }
- }
- else
- Lua_PushNil(L);
- return 1;
- }
- int LuaSetPlayerLightResist(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
-
- int nValue = (int)Lua_ValueToNumber(L,2);
- if (nValue < 0) nValue = 0;
- if (nValue > Npc[Player[nPlayerIndex].m_nIndex].m_LightResistMax) nValue = Npc[Player[nPlayerIndex].m_nIndex].m_LightResistMax;
-
- int nType = (int)Lua_ValueToNumber(L,1);
-
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Npc[Player[nPlayerIndex].m_nIndex].m_CurrentLightResist = nValue;
- break;
-
- case 1:
- Npc[Player[nPlayerIndex].m_nIndex].m_LightResist = nValue;
- break;
- case 2:
- Npc[Player[nPlayerIndex].m_nIndex].m_LightResistMax = nValue;
- break;
- }
- }
- else
- Lua_PushNil(L);
- return 0;
- }
- int LuaGetPlayerPoisonResist(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nType = (int)Lua_ValueToNumber(L,1);
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_CurrentPoisonResist);break;
- case 1:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_PoisonResist); break;
- case 2:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_PoisonResistMax);break;
- default:
- Lua_PushNil(L);
- }
- }
- else
- Lua_PushNil(L);
- return 1;
- }
- int LuaSetPlayerPoisonResist(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- {
- int nValue = (int)Lua_ValueToNumber(L,2);
- if (nValue < 0) nValue = 0;
- if (nValue > Npc[Player[nPlayerIndex].m_nIndex].m_PoisonResistMax) nValue = Npc[Player[nPlayerIndex].m_nIndex].m_PoisonResistMax;
-
- int nType = (int)Lua_ValueToNumber(L,1);
-
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Npc[Player[nPlayerIndex].m_nIndex].m_CurrentPoisonResist = nValue;
- break;
-
- case 1:
- Npc[Player[nPlayerIndex].m_nIndex].m_PoisonResist = nValue;
- break;
- case 2:
- Npc[Player[nPlayerIndex].m_nIndex].m_PoisonResistMax = nValue;
- break;
- }
- }
-
- }
-
-
- return 0;
-
- }
- int LuaGetPlayerPhysicsResist(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
-
- {
- int nType = (int)Lua_ValueToNumber(L,1);
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_CurrentPhysicsResist);break;
- case 1:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_PhysicsResist); break;
- case 2:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_PhysicsResistMax);break;
- default:
- Lua_PushNil(L);
- }
- }
-
- }
- else
- Lua_PushNil(L);
- return 1;
- }
- int LuaSetPlayerPhysicsResist(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
-
- {
- int nValue = (int)Lua_ValueToNumber(L,2);
- if (nValue < 0) nValue = 0;
- if (nValue > Npc[Player[nPlayerIndex].m_nIndex].m_PhysicsResistMax) nValue = Npc[Player[nPlayerIndex].m_nIndex].m_PhysicsResistMax;
-
- int nType = (int)Lua_ValueToNumber(L,1);
-
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Npc[Player[nPlayerIndex].m_nIndex].m_CurrentPhysicsResist = nValue;
- break;
-
- case 1:
- Npc[Player[nPlayerIndex].m_nIndex].m_PhysicsResist = nValue;
- break;
- case 2:
- Npc[Player[nPlayerIndex].m_nIndex].m_PhysicsResistMax = nValue;
- break;
- }
- }
-
- }
- return 0;
-
- }
- //经验值*********************************************************************
- int LuaGetPlayerExp(Lua_State *L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- Lua_PushNumber(L, Player[nPlayerIndex].m_nExp);
- }
- else
- Lua_PushNil(L);
- return 1;
- }
- //AddExp(200,10,0)
- int LuaModifyPlayerExp(Lua_State * L)
- {
- int bAllTeamGet = 0;
- if(Lua_GetTopIndex(L) >= 3) bAllTeamGet = (int)Lua_ValueToNumber(L,3);
-
- int nDValue = (int)Lua_ValueToNumber(L,1);
- int nTarLevel = (int)Lua_ValueToNumber(L,2);
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- if (bAllTeamGet)
- Player[nPlayerIndex].AddExp(nDValue, nTarLevel);
- else
- Player[nPlayerIndex].AddSelfExp(nDValue, nTarLevel);
- }
- return 0;
- }
- int LuaAddOwnExp(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) <=0 ) return 0;
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nExp = (int)Lua_ValueToNumber(L,1);
- if (nExp >= 0)
- Player[nPlayerIndex].DirectAddExp((int)Lua_ValueToNumber(L,1));
- }
- return 0;
- }
- int LuaGetPlayerLevel(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);