int KCustomEquipInfo::LuaGetMagicAttrib(Lua_State* L) { int nResult = false; int nRelIndex = 0; int nTable = 0; Lua_NewTable(L); nTable = Lua_GetTopIndex(L); for(int i = 0; i < MAX_ITEM_MAGIC_COUNT; ++i) { KAttribInfo* pInfo = g_pSO3World->m_ItemManager.m_ItemLib.GetAttribInfo(nAttribIndex[i]); if (pInfo && pInfo->nAttribID != atInvalid) { ++nRelIndex; Lua_PushNumber(L, nRelIndex); Lua_NewTable(L); int nAttrib = Lua_GetTopIndex(L); Lua_PushString(L, "nID"); Lua_PushNumber(L, pInfo->nAttribID); Lua_SetTable(L, nAttrib); Lua_PushString(L, "nImportance"); Lua_PushNumber(L, pInfo->nImportance); Lua_SetTable(L, nAttrib); for (int j = 0; j < MAX_ATTRIB_PARAM_NUM; ++j) { char szKey[16]; sprintf(szKey, "%s%d", "Param", (j * 2)); Lua_PushString(L, szKey); Lua_PushNumber(L, pInfo->Param[j].nMin); Lua_SetTable(L, nAttrib); sprintf(szKey, "%s%d", "Param", (j * 2 + 1)); Lua_PushString(L, szKey); Lua_PushNumber(L, pInfo->Param[j].nMax); Lua_SetTable(L, nAttrib); } Lua_SetTable(L, nTable); } } nResult = true; Exit0: if (!nResult) Lua_PushNil(L); return 1; }
//--------------------------------------------------------------------------- // 函数: Lua_SetTable_StringFromName // 功能: // 参数: Lua_State * L // 参数: int nIndex // 参数: const char * szMemberName // 参数: char * szString // 返回: int //--------------------------------------------------------------------------- int Lua_SetTable_StringFromName(Lua_State * L ,int nIndex, const char * szMemberName, char * szString) { if (! Lua_IsTable(L, nIndex)) return 0; Lua_PushString(L, szMemberName); Lua_PushString(L, szString); Lua_SetTable(L, nIndex); return 1; }
int KSystemScriptTable::LuaGetOpenFileName(Lua_State* L) { int nRetCode = false; OPENFILENAME OpenFileName; char szFile[MAX_PATH]; szFile[0] = '\0'; const char * pcszTitle = "Please select a file!"; int nParamCount = lua_gettop(L); if (nParamCount > 0) pcszTitle = Lua_ValueToString(L, 1); memset(&OpenFileName, 0, sizeof(OPENFILENAME)); OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.hwndOwner = g_pUI->m_hWnd; OpenFileName.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_EXPLORER | OFN_EXTENSIONDIFFERENT; OpenFileName.lpstrTitle = pcszTitle; OpenFileName.nMaxFile = sizeof(szFile); OpenFileName.lpstrFile = szFile; nRetCode = ::GetOpenFileNameA(&OpenFileName); KG_PROCESS_ERROR(nRetCode); Exit0: Lua_PushString(L, szFile); return 1; }
int KSystemScriptTable::LuaFormatTime(Lua_State* L) { size_t nRetCode = 0; char szDest[128]; time_t nTime = 0; LPCSTR pcszFormat = NULL; struct tm *ptmTime = NULL; KGLOG_PROCESS_ERROR(Lua_GetTopIndex(L) == 2); pcszFormat = lua_tostring(L, 1); KGLOG_PROCESS_ERROR(pcszFormat); KGLOG_PROCESS_ERROR(pcszFormat[0]); nTime = (time_t)lua_tonumber(L, 2); ptmTime = localtime(&nTime); KGLOG_PROCESS_ERROR(ptmTime); nRetCode = strftime(szDest, sizeof(szDest), pcszFormat, ptmTime); KGLOG_PROCESS_ERROR(nRetCode > 0); Lua_PushString(L, szDest); return 1; Exit0: return 0; }
int KTeamClient::LuaGetGroupInfo(Lua_State* L) { int nResult = 0; int nTopIndex = 0; int nTable = 0; int nSubTable = 0; int nTeamGroup = 0; int nIndex = 0; nTopIndex = Lua_GetTopIndex(L); KGLOG_PROCESS_ERROR(nTopIndex == 1); KGLOG_PROCESS_ERROR(m_dwTeamID != ERROR_ID); nTeamGroup = (int)Lua_ValueToNumber(L, 1); KGLOG_PROCESS_ERROR(nTeamGroup >= 0 && nTeamGroup < m_nGroupNum); Lua_NewTable(L); nTable = Lua_GetTopIndex(L); Lua_PushString(L, "dwFormationLeader"); Lua_PushNumber(L, m_TeamGroup[nTeamGroup].dwFormationLeader); Lua_SetTable(L, nTable); Lua_PushString(L, "MemberList"); Lua_NewTable(L); nSubTable = Lua_GetTopIndex(L); for ( KTEAM_MEMBER_LIST::iterator it = m_TeamGroup[nTeamGroup].MemberList.begin(); it != m_TeamGroup[nTeamGroup].MemberList.end(); ++it ) { Lua_PushNumber(L, ++nIndex); Lua_PushNumber(L, it->dwMemberID); Lua_SetTable(L, nSubTable); } Lua_SetTable(L, nTable); nResult = 1; Exit0: return nResult; }
//--------------------------------------------------------------------------- // 函数: Lua_SetTable_CFunFromName // 功能: // 参数: Lua_State * L // 参数: int nIndex // 参数: const char * szMemberName // 参数: Lua_CFunction CFun // 返回: int //--------------------------------------------------------------------------- int Lua_SetTable_CFunFromName(Lua_State * L, int nIndex, const char * szMemberName, Lua_CFunction CFun) { if (! Lua_IsTable(L, nIndex)) return 0; Lua_PushString(L, szMemberName); Lua_PushCFunction(L, CFun); Lua_SetTable(L, nIndex); return 1; }
//--------------------------------------------------------------------------- // 函数: Lua_SetTable_StringFromId // 功能: // 参数: Lua_State * L // 参数: int nIndex // 参数: int Id // 参数: const char * szString // 返回: int //--------------------------------------------------------------------------- int Lua_SetTable_StringFromId(Lua_State * L, int nIndex, int Id, const char * szString) { if (! Lua_IsTable(L, nIndex)) return 0; Lua_PushNumber(L, (double)Id); Lua_PushString(L, szString); Lua_SetTable(L, nIndex); return 1; }
int KItem::LuaGetTemporaryEnchantAttrib(Lua_State* L) { int nFirst = true; int nResult = 0; int nIndex = 1; KGLOG_PROCESS_ERROR(Lua_GetTopIndex(L) == 0); KG_PROCESS_ERROR(m_pTemporaryEnchant); KG_PROCESS_ERROR(m_pTemporaryEnchant->pAttribute); for (KAttribute* pAttribute = m_pTemporaryEnchant->pAttribute; pAttribute; pAttribute = pAttribute->pNext) { if (pAttribute->nKey != atInvalid) { if (nFirst) { Lua_NewTable(L); nFirst = false; } Lua_PushNumber(L, nIndex); nIndex++; Lua_NewTable(L); Lua_PushString(L, "nID"); Lua_PushNumber(L, pAttribute->nKey); Lua_SetTable(L, -3); Lua_PushString(L, "nValue1"); Lua_PushNumber(L, pAttribute->nValue1); Lua_SetTable(L, -3); Lua_PushString(L, "nValue2"); Lua_PushNumber(L, pAttribute->nValue2); Lua_SetTable(L, -3); Lua_SetTable(L, -3); } } if (!nFirst) nResult = 1; Exit0: return nResult; }
//--------------------------------------------------------------------------- // 函数: Lua_SetTable_IntFromName // 功能: // 参数: Lua_State * L // 参数: int nIndex // 参数: const char * szMemberName // 参数: int Number // 返回: int //--------------------------------------------------------------------------- int Lua_SetTable_IntFromName(Lua_State * L, int nIndex, const char * szMemberName, int Number) { if (! Lua_IsTable(L, nIndex)) return 0; Lua_PushString(L, szMemberName); Lua_PushNumber(L, (double)Number); Lua_SetTable(L, nIndex); return 1; }
int KItem::LuaGetRequireAttrib(Lua_State* L) { int nRelIndex = 0; assert(L); Lua_NewTable(L); int nTable = Lua_GetTopIndex(L); for (KAttribute* pAttribute = m_pRequireAttr; pAttribute; pAttribute = pAttribute->pNext) { if (pAttribute->nKey != atInvalid) { ++nRelIndex; Lua_PushNumber(L, nRelIndex); Lua_NewTable(L); int nAttrib = Lua_GetTopIndex(L); Lua_PushString(L, "nID"); Lua_PushNumber(L, pAttribute->nKey); Lua_SetTable(L, nAttrib); Lua_PushString(L, "nValue1"); Lua_PushNumber(L, pAttribute->nValue1); Lua_SetTable(L, nAttrib); Lua_PushString(L, "nValue2"); Lua_PushNumber(L, pAttribute->nValue2); Lua_SetTable(L, nAttrib); Lua_SetTable(L, nTable); } } return 1; }
int KCustomEquipInfo::LuaGetRequireAttrib(Lua_State* L) { int nRelIndex = 0; int nTable = 0; assert(L); Lua_NewTable(L); nTable = Lua_GetTopIndex(L); for(int i = 0; i < MAX_ITEM_REQUIRE_COUNT; ++i) { if (RequireAttrib[i].nAttribID != atInvalid) { ++nRelIndex; Lua_PushNumber(L, nRelIndex); Lua_NewTable(L); int nAttrib = Lua_GetTopIndex(L); Lua_PushString(L, "nID"); Lua_PushNumber(L, RequireAttrib[i].nAttribID); Lua_SetTable(L, nAttrib); Lua_PushString(L, "nValue"); Lua_PushNumber(L, RequireAttrib[i].nValue); Lua_SetTable(L, nAttrib); Lua_SetTable(L, nTable); } } return 1; }
int LuaGetAccount(Lua_State* L) { int nResult = 0; const char* cszAccountName = NULL; KGLOG_PROCESS_ERROR(Lua_GetTopIndex(L) == 0); cszAccountName = g_GatewayClient.GetAccountName(); KGLOG_PROCESS_ERROR(cszAccountName); Lua_PushString(L, cszAccountName); nResult = 1; Exit0: return nResult; }
int KSystemScriptTable::LuaGetUserDataPath(Lua_State* L) { BOOL bRetCode = FALSE; char szFilePath[MAX_PATH]; szFilePath[0] = '\0'; LPCSTR pcszRole = NULL; if (Lua_GetTopIndex(L) > 0) pcszRole = Lua_ValueToString(L, 1); bRetCode = KUiConfig::GetSelf().GetUserDataPath(szFilePath, pcszRole); KGLOG_PROCESS_ERROR(bRetCode); Exit0: Lua_PushString(L, szFilePath); return 1; }
int LuaTimeToDate(Lua_State* L) { int nTopIndex = 0; time_t nTime = 0; struct tm* ptmTime = NULL; nTopIndex = Lua_GetTopIndex(L); KGLOG_PROCESS_ERROR(nTopIndex == 1); nTime = (time_t)Lua_ValueToNumber(L, 1); ptmTime = localtime(&nTime); KGLOG_PROCESS_ERROR(ptmTime); Lua_NewTable(L); Lua_PushString(L, "year"); Lua_PushNumber(L, ptmTime->tm_year + 1900); Lua_SetTable(L, -3); Lua_PushString(L, "month"); Lua_PushNumber(L, ptmTime->tm_mon + 1); Lua_SetTable(L, -3); Lua_PushString(L, "day"); Lua_PushNumber(L, ptmTime->tm_mday); Lua_SetTable(L, -3); Lua_PushString(L, "hour"); Lua_PushNumber(L, ptmTime->tm_hour); Lua_SetTable(L, -3); Lua_PushString(L, "minute"); Lua_PushNumber(L, ptmTime->tm_min); Lua_SetTable(L, -3); Lua_PushString(L, "second"); Lua_PushNumber(L, ptmTime->tm_sec); Lua_SetTable(L, -3); Lua_PushString(L, "weekday"); Lua_PushNumber(L, ptmTime->tm_wday); Lua_SetTable(L, -3); return 1; Exit0: return 0; }
int LuaGetLastLoginIP(Lua_State* L) { int nResult = 0; DWORD dwIP = 0; char* pszIP = NULL; struct in_addr InAddr; KGLOG_PROCESS_ERROR(Lua_GetTopIndex(L) == 0); dwIP = g_GatewayClient.GetLastLoginIP(); InAddr.s_addr = dwIP; pszIP = inet_ntoa(InAddr); KGLOG_PROCESS_ERROR(pszIP); Lua_PushString(L, pszIP); nResult = 1; Exit0: return nResult; }
int KTeamClient::LuaGetClientTeamMemberName(Lua_State* L) { int nResult = 0; int nRetCode = 0; DWORD dwMemberID = 0; KTEAM_MEMBER_INFO* pMemberInfo = NULL; nRetCode = Lua_GetTopIndex(L); KGLOG_PROCESS_ERROR(nRetCode == 1); dwMemberID = (DWORD)Lua_ValueToNumber(L, 1); KG_PROCESS_ERROR(m_dwTeamID != ERROR_ID); pMemberInfo = GetMemberInfo(dwMemberID); KGLOG_PROCESS_ERROR(pMemberInfo); Lua_PushString(L, pMemberInfo->szRoleName); nResult = 1; Exit0: return nResult; }
int KSystemScriptTable::LuaGetUserDataFloder(Lua_State* L) { Lua_PushString(L, F_UI_USER_DATA_FOLDER); return 1; }
int KCustomEquipInfo::LuaGetSetAttrib(Lua_State* L) { int nResult = 0; int nSetEquipCount = 0; int nIndex = 0; int nEquipedNum = 0; KSetInfo* pSetInfo = NULL; KPlayer* pPlayer = NULL; int nTable = 0; KG_PROCESS_ERROR(nSetID > 0); pSetInfo = g_pSO3World->m_ItemManager.m_ItemLib.GetSetInfo(nSetID); KGLOG_PROCESS_ERROR(pSetInfo); pPlayer = g_pSO3World->m_PlayerSet.GetObj(g_pSO3World->m_dwClientPlayerID); KGLOG_PROCESS_ERROR(pPlayer); Lua_PushNumber(L, pSetInfo->dwUiID); Lua_NewTable(L); nTable = Lua_GetTopIndex(L); for (int i = 0; i < MAX_SET_PART_NUM; ++i) { KCustomEquipInfo *pInfo = pSetInfo->pEquipList[i]; if (pInfo) { ++nSetEquipCount; Lua_PushNumber(L, nSetEquipCount); Lua_NewTable(L); int nAttrib = Lua_GetTopIndex(L); Lua_PushString(L, "nUiId"); Lua_PushNumber(L, pInfo->nUiId); Lua_SetTable(L, nAttrib); Lua_PushString(L, "bEquiped"); int nEquiped = pPlayer->IsEquiped(pInfo); if (nEquiped) ++nEquipedNum; Lua_PushBoolean(L, nEquiped); Lua_SetTable(L, nAttrib); Lua_SetTable(L, nTable); } } Lua_PushNumber(L, nSetEquipCount); Lua_PushNumber(L, nEquipedNum); Lua_NewTable(L); nTable = Lua_GetTopIndex(L); nIndex = 0; for (int i = 1; i <= nSetEquipCount; ++i) { KAttribute Attribute; if (g_pSO3World->m_ItemManager.GetSetAttrib(Attribute, nUiId, i)) { if (Attribute.nKey != atInvalid) { ++nIndex; Lua_PushNumber(L, nIndex); Lua_NewTable(L); int nAttrib = Lua_GetTopIndex(L); Lua_PushString(L, "nID"); Lua_PushNumber(L, Attribute.nKey); Lua_SetTable(L, nAttrib); Lua_PushString(L, "nCount"); Lua_PushNumber(L, i); Lua_SetTable(L, nAttrib); Lua_PushString(L, "nValue1"); Lua_PushNumber(L, Attribute.nValue1); Lua_SetTable(L, nAttrib); Lua_PushString(L, "nValue2"); Lua_PushNumber(L, Attribute.nValue2); Lua_SetTable(L, nAttrib); Lua_PushString(L, "bEquiped"); int nHave = false; if (nEquipedNum >= i) nHave = true; Lua_PushBoolean(L, nHave); Lua_SetTable(L, nAttrib); Lua_SetTable(L, nTable); } } } nResult = 5; Exit0: return nResult; }
int KItem::LuaGetBaseAttrib(Lua_State* L) { int nRelIndex = 0; assert(L); Lua_NewTable(L); int nTable = Lua_GetTopIndex(L); for (KAttribute* pAttribute = m_pBaseAttr; pAttribute; pAttribute = pAttribute->pNext) { if (pAttribute->nKey != atInvalid) { if (pAttribute->nKey == atMeleeWeaponDamageRand || pAttribute->nKey == atRangeWeaponDamageRand) continue; ++nRelIndex; Lua_PushNumber(L, nRelIndex); Lua_NewTable(L); int nAttrib = Lua_GetTopIndex(L); Lua_PushString(L, "nID"); Lua_PushNumber(L, pAttribute->nKey); Lua_SetTable(L, nAttrib); Lua_PushString(L, "nValue1"); Lua_PushNumber(L, pAttribute->nValue1); Lua_SetTable(L, nAttrib); int nValue2 = pAttribute->nValue2; if (pAttribute->nKey == atMeleeWeaponDamageBase) { nValue2 = pAttribute->nValue1; for (KAttribute* pAttributeRand = m_pBaseAttr; pAttributeRand; pAttributeRand = pAttributeRand->pNext) { if (pAttributeRand->nKey == atMeleeWeaponDamageRand) { nValue2 += pAttributeRand->nValue1; } } } if (pAttribute->nKey == atRangeWeaponDamageBase) { nValue2 = pAttribute->nValue1; for (KAttribute* pAttributeRand = m_pBaseAttr; pAttributeRand; pAttributeRand = pAttributeRand->pNext) { if (pAttributeRand->nKey == atRangeWeaponDamageRand) { nValue2 += pAttributeRand->nValue1; } } } Lua_PushString(L, "nValue2"); Lua_PushNumber(L, nValue2 ); Lua_SetTable(L, nAttrib); Lua_SetTable(L, nTable); } } return 1; }
int KTeamClient::LuaGetMemberInfo(Lua_State* L) { int nResult = 0; int nTopIndex = 0; int nTable = 0; int nCurrentLife = 0; int nCurrentMana = 0; DWORD dwMemberID = 0; KTEAM_MEMBER_INFO* pMemberInfo = NULL; nTopIndex = Lua_GetTopIndex(L); KGLOG_PROCESS_ERROR(nTopIndex == 1); KGLOG_PROCESS_ERROR(m_dwTeamID != ERROR_ID); dwMemberID = (DWORD)Lua_ValueToNumber(L, 1); pMemberInfo = GetMemberInfo(dwMemberID); KGLOG_PROCESS_ERROR(pMemberInfo); Lua_NewTable(L); nTable = Lua_GetTopIndex(L); Lua_PushString(L, "szName"); Lua_PushString(L, pMemberInfo->szRoleName); Lua_SetTable(L, nTable); Lua_PushString(L, "nLevel"); Lua_PushNumber(L, pMemberInfo->nLevel); Lua_SetTable(L, nTable); Lua_PushString(L, "bIsOnLine"); Lua_PushBoolean(L, pMemberInfo->bOnlineFlag); Lua_SetTable(L, nTable); Lua_PushString(L, "bDeathFlag"); Lua_PushBoolean(L, pMemberInfo->bDeathFlag); Lua_SetTable(L, nTable); Lua_PushString(L, "nCamp"); Lua_PushNumber(L, pMemberInfo->eCamp); Lua_SetTable(L, nTable); Lua_PushString(L, "dwForceID"); Lua_PushNumber(L, pMemberInfo->dwForceID); Lua_SetTable(L, nTable); Lua_PushString(L, "nMaxLife"); Lua_PushNumber(L, pMemberInfo->nMaxLife); Lua_SetTable(L, nTable); nCurrentLife = pMemberInfo->nMaxLife * pMemberInfo->nLifePercent / UCHAR_MAX; Lua_PushString(L, "nCurrentLife"); Lua_PushNumber(L, nCurrentLife); Lua_SetTable(L, nTable); Lua_PushString(L, "nMaxMana"); Lua_PushNumber(L, pMemberInfo->nMaxMana); Lua_SetTable(L, nTable); nCurrentMana = pMemberInfo->nMaxMana * pMemberInfo->nManaPercent / UCHAR_MAX; Lua_PushString(L, "nCurrentMana"); Lua_PushNumber(L, nCurrentMana); Lua_SetTable(L, nTable); Lua_PushString(L, "dwMapID"); Lua_PushNumber(L, pMemberInfo->dwMapID); Lua_SetTable(L, nTable); Lua_PushString(L, "nMapCopyIndex"); Lua_PushNumber(L, pMemberInfo->nMapCopyIndex); Lua_SetTable(L, nTable); Lua_PushString(L, "nPosX"); Lua_PushNumber(L, pMemberInfo->nPosX); Lua_SetTable(L, nTable); Lua_PushString(L, "nPosY"); Lua_PushNumber(L, pMemberInfo->nPosY); Lua_SetTable(L, nTable); Lua_PushString(L, "nRoleType"); Lua_PushNumber(L, pMemberInfo->nRoleType); Lua_SetTable(L, nTable); Lua_PushString(L, "nFormationCoefficient"); Lua_PushNumber(L, pMemberInfo->nFormationCoefficient); Lua_SetTable(L, nTable); nResult = 1; Exit0: return nResult; }
int KSchemeScriptTable::LuaGWTextEncoder_Encode(Lua_State* L) { BOOL bRetCode = FALSE; LPCSTR szStream = NULL; size_t nEncodedLength = 0; int nIndex = 1; KGWTextEncoder::KGWTextAtomList aEncodedAtom; std::string szEncode; unsigned int uCodePage = 0; ASSERT(L); ASSERT(g_pSO3UI && g_pSO3UI->m_pUI); uCodePage = g_pSO3UI->m_pUI->GetCodePage(); bRetCode = Lua_GetTopIndex(L) == 1; KGLOG_PROCESS_ERROR(bRetCode); szStream = Lua_ValueToString(L, 1); KGLOG_PROCESS_ERROR(szStream); szEncode = szStream; TripSlashes(&szEncode[0]); { ATL::CA2W wszStream(szEncode.c_str(), uCodePage); size_t nStreamLength = wcslen(wszStream); bRetCode = KGWTextEncoder::GetSelf().Encode(wszStream, nStreamLength, aEncodedAtom, nEncodedLength); KGLOG_PROCESS_ERROR(bRetCode); } Lua_PushNumber(L, nEncodedLength); if (aEncodedAtom.size() > 0) { Lua_NewTable(L); KGWTextEncoder::KGWTextAtomList::const_iterator it = aEncodedAtom.begin(); KGWTextEncoder::KGWTextAtomList::const_iterator ie = aEncodedAtom.end(); for (; it != ie; ++it) { KGWTextAtom const& item = *it; LPCWSTR wszName = item.GetName(); LPCWSTR wszContext = item.GetContext(); Lua_PushNumber(L, nIndex); Lua_NewTable(L); if (wszName) { Lua_PushString(L, "name"); Lua_PushString(L, ATL::CW2A(wszName, uCodePage)); Lua_SetTable(L, -3); } if (wszContext) { Lua_PushString(L, "context"); Lua_PushString(L, ATL::CW2A(wszContext, uCodePage)); Lua_SetTable(L, -3); } size_t const nCount = item.GetAttributeCount(); if (nCount > 0) { Lua_PushString(L, "attribute"); Lua_NewTable(L); for (size_t nIndex = 0; nIndex < nCount; ++nIndex) { LPCWSTR wszKey = item.GetAttributeKey(nIndex); LPCWSTR wszValue = item.GetAttributeValue(nIndex); ASSERT(wszKey && wszKey[0] != L'\0'); Lua_PushString(L, ATL::CW2A(wszKey, uCodePage)); Lua_PushString(L, wszValue ? ATL::CW2A(wszValue, uCodePage) : ""); Lua_SetTable(L, -3); } Lua_SetTable(L, -3); } Lua_SetTable(L, -3); ++nIndex; } } else { Lua_PushNil(L); } return 2; Exit0: return 0; }
int KQuestInfo::LuaGetHortation(Lua_State* L) { int nHave = false; int nTopIndex = Lua_GetTopIndex(L); Lua_NewTable(L); int nTable = Lua_GetTopIndex(L); if (nPresentMoney) { Lua_PushString(L, "money"); Lua_PushNumber(L, nPresentMoney); Lua_SetTable(L, nTable); nHave = true; } if (wPresentSkill) { Lua_PushString(L, "skill"); Lua_PushNumber(L, wPresentSkill); Lua_SetTable(L, nTable); nHave = true; } if (nPresentPrestige) { Lua_PushString(L, "prestige"); Lua_PushNumber(L, nPresentPrestige); Lua_SetTable(L, nTable); nHave = true; } if (nPresentContribution) { Lua_PushString(L, "contribution"); Lua_PushNumber(L, nPresentContribution); Lua_SetTable(L, nTable); nHave = true; } if (nPresentTrain) { Lua_PushString(L, "presenttrain"); Lua_PushNumber(L, nPresentTrain); Lua_SetTable(L, nTable); nHave = true; } int nNotSet = true; int nRelIndex = 1; for (int i = 0; i < QUEST_PARAM_COUNT; ++i) { if (byAffectForceID[i] != 0 && nAffectForceValue[i] != 0) { if (nNotSet) { Lua_PushString(L, "reputation"); Lua_NewTable(L); nHave = true; nNotSet = false; } Lua_PushNumber(L, nRelIndex); Lua_NewTable(L); ++nRelIndex; Lua_PushString(L, "force"); Lua_PushNumber(L, byAffectForceID[i]); Lua_SetTable(L, -3); Lua_PushString(L, "value"); Lua_PushNumber(L, nAffectForceValue[i]); Lua_SetTable(L, -3); Lua_SetTable(L, -3); } } if (!nNotSet) { Lua_SetTable(L, nTable); } nNotSet = true; nRelIndex = 1; if (bHidePresent) { // 隐藏显示,为制定的道具图标暂时定为Type5,Index2931,Count1 if (nNotSet) { Lua_PushString(L, "itemgroup1"); Lua_NewTable(L); Lua_PushString(L, "all"); Lua_PushBoolean(L, bPresentAll[0]); Lua_SetTable(L, -3); nHave = true; nNotSet = false; } Lua_PushNumber(L, nRelIndex); Lua_NewTable(L); ++nRelIndex; Lua_PushString(L, "selectindex"); Lua_PushNumber(L, 0); Lua_SetTable(L, -3); Lua_PushString(L, "count"); Lua_PushNumber(L, 1); Lua_SetTable(L, -3); Lua_PushString(L, "version"); Lua_PushNumber(L, 0); Lua_SetTable(L, -3); Lua_PushString(L, "type"); Lua_PushNumber(L, 5); Lua_SetTable(L, -3); Lua_PushString(L, "index"); Lua_PushNumber(L, 2931); Lua_SetTable(L, -3); Lua_SetTable(L, -3); } else { for (int i = 0; i < QUEST_PARAM_COUNT; ++i) { if (wPresentItemAmount[i]) { if (nNotSet) { Lua_PushString(L, "itemgroup1"); Lua_NewTable(L); Lua_PushString(L, "all"); Lua_PushBoolean(L, bPresentAll[0]); Lua_SetTable(L, -3); nHave = true; nNotSet = false; } Lua_PushNumber(L, nRelIndex); Lua_NewTable(L); ++nRelIndex; Lua_PushString(L, "selectindex"); Lua_PushNumber(L, i); Lua_SetTable(L, -3); Lua_PushString(L, "count"); Lua_PushNumber(L, wPresentItemAmount[i]); Lua_SetTable(L, -3); Lua_PushString(L, "version"); Lua_PushNumber(L, 0); Lua_SetTable(L, -3); Lua_PushString(L, "type"); Lua_PushNumber(L, byPresentItemType[i]); Lua_SetTable(L, -3); Lua_PushString(L, "index"); Lua_PushNumber(L, wPresentItemIndex[i]); Lua_SetTable(L, -3); Lua_SetTable(L, -3); } } } if (!nNotSet) { Lua_SetTable(L, nTable); } nNotSet = true; nRelIndex = 1; for (int i = QUEST_PARAM_COUNT; i < QUEST_PARAM_COUNT * 2; ++i) { if (wPresentItemAmount[i]) { if (nNotSet) { Lua_PushString(L, "itemgroup2"); Lua_NewTable(L); Lua_PushString(L, "all"); Lua_PushBoolean(L, bPresentAll[1]); Lua_SetTable(L, -3); nHave = true; nNotSet = false; } Lua_PushNumber(L, nRelIndex); Lua_NewTable(L); ++nRelIndex; Lua_PushString(L, "selectindex"); Lua_PushNumber(L, i); Lua_SetTable(L, -3); Lua_PushString(L, "count"); Lua_PushNumber(L, wPresentItemAmount[i]); Lua_SetTable(L, -3); Lua_PushString(L, "version"); Lua_PushNumber(L, 0); Lua_SetTable(L, -3); Lua_PushString(L, "type"); Lua_PushNumber(L, byPresentItemType[i]); Lua_SetTable(L, -3); Lua_PushString(L, "index"); Lua_PushNumber(L, wPresentItemIndex[i]); Lua_SetTable(L, -3); Lua_SetTable(L, -3); } } if (!nNotSet) { Lua_SetTable(L, nTable); } if (nHave) { assert(nTopIndex + 1 == Lua_GetTopIndex(L)); return 1; } else { Lua_SetTopIndex(L, nTopIndex); return 0; } }
int KSystemScriptTable::LuaGetUserServer(Lua_State* L) { Lua_PushString(L, KUiConfig::GetSelf().GetUserRegion()); Lua_PushString(L, KUiConfig::GetSelf().GetUserServer()); return 2; }
int KSystemScriptTable::LuaGetAllowableAdapterModes(Lua_State* L) { struct KADAPTERMODE { UINT Width; UINT Height; UINT RefreshRates[32]; // ³¬³öºöÂÔºóÃæµÄ }; HRESULT hr = E_FAIL; UINT uCount = 0; std::vector<KADAPTERMODE> AdapterModes; std::vector<D3DDISPLAYMODE> DisplayModes; ASSERT(L); uCount = g_pUI->m_p3DUI->GetAllowableAdapterModeCount(); KGLOG_PROCESS_ERROR(uCount != 0); DisplayModes.resize(uCount); hr = g_pUI->m_p3DUI->GetAllowableAdapterMode(&DisplayModes[0], &uCount); KGLOG_COM_PROCESS_ERROR(hr); for (UINT uIndex = 0; uIndex < uCount; ++uIndex) { int nFind = false; D3DDISPLAYMODE& dm = DisplayModes[uIndex]; for (UINT uAdapter = 0; uAdapter != AdapterModes.size(); ++uAdapter) { KADAPTERMODE& am = AdapterModes[uAdapter]; if (dm.Width == am.Width && dm.Height == am.Height) { for (UINT uRefreshRateIndex = 0; uRefreshRateIndex != _countof(am.RefreshRates); ++uRefreshRateIndex) { if (am.RefreshRates[uRefreshRateIndex] == 0) { am.RefreshRates[uRefreshRateIndex] = dm.RefreshRate; break; } } nFind = true; break; } } if (!nFind) { KADAPTERMODE Mode; memset(&Mode, 0, sizeof(Mode)); Mode.Width = dm.Width; Mode.Height = dm.Height; Mode.RefreshRates[0] = dm.RefreshRate; AdapterModes.push_back(Mode); } } Lua_NewTable(L); for (size_t nIndex = 0; nIndex < AdapterModes.size(); ++nIndex) { KADAPTERMODE& am = AdapterModes[nIndex]; Lua_PushNumber(L, nIndex + 1); Lua_NewTable(L); Lua_PushString(L, "nWidth"); Lua_PushNumber(L, am.Width); Lua_SetTable(L, -3); Lua_PushString(L, "nHeight"); Lua_PushNumber(L, am.Height); Lua_SetTable(L, -3); Lua_PushString(L, "aRefreshRate"); Lua_NewTable(L); int nUsedRefreshRateIndex = 1; for (size_t nRefreshRateIndex = 0; nRefreshRateIndex < _countof(am.RefreshRates); ++nRefreshRateIndex) { UINT nRefreshRate = am.RefreshRates[nRefreshRateIndex]; if (nRefreshRate != 0) { Lua_PushNumber(L, nUsedRefreshRateIndex++); Lua_PushNumber(L, nRefreshRate); Lua_SetTable(L, -3); } } Lua_SetTable(L, -3); Lua_SetTable(L, -3); } return 1; Exit0: return 0; }
int KCustomEquipInfo::LuaGetBaseAttrib(Lua_State* L) { int nRelIndex = 0; int nTable = 0; assert(L); Lua_NewTable(L); nTable = Lua_GetTopIndex(L); for(int i = 0; i < MAX_ITEM_BASE_COUNT; ++i) { if (BaseAttrib[i].nAttribID != atInvalid && BaseAttrib[i].nAttribID != atMeleeWeaponDamageRand && BaseAttrib[i].nAttribID != atRangeWeaponDamageRand ) { ++nRelIndex; Lua_PushNumber(L, nRelIndex); Lua_NewTable(L); int nAttrib = Lua_GetTopIndex(L); Lua_PushString(L, "nID"); Lua_PushNumber(L, BaseAttrib[i].nAttribID); Lua_SetTable(L, nAttrib); Lua_PushString(L, "nMin"); Lua_PushNumber(L, BaseAttrib[i].nMin); Lua_SetTable(L, nAttrib); Lua_PushString(L, "nMax"); Lua_PushNumber(L, BaseAttrib[i].nMax); Lua_SetTable(L, nAttrib); if (BaseAttrib[i].nAttribID == atMeleeWeaponDamageBase) { for(int j = 0; j < MAX_ITEM_BASE_COUNT; ++j) { if (BaseAttrib[j].nAttribID == atMeleeWeaponDamageRand) { Lua_PushString(L, "nMin1"); Lua_PushNumber(L, BaseAttrib[j].nMin); Lua_SetTable(L, nAttrib); Lua_PushString(L, "nMax1"); Lua_PushNumber(L, BaseAttrib[j].nMax); Lua_SetTable(L, nAttrib); } } } if (BaseAttrib[i].nAttribID == atRangeWeaponDamageBase) { for(int j = 0; j < MAX_ITEM_BASE_COUNT; ++j) { if (BaseAttrib[j].nAttribID == atRangeWeaponDamageRand) { Lua_PushString(L, "nMin1"); Lua_PushNumber(L, BaseAttrib[j].nMin); Lua_SetTable(L, nAttrib); Lua_PushString(L, "nMax1"); Lua_PushNumber(L, BaseAttrib[j].nMax); Lua_SetTable(L, nAttrib); } } } Lua_SetTable(L, nTable); } } return 1; }
int KSystemScriptTable::LuaGetUserRoleName(Lua_State* L) { Lua_PushString(L, KUiConfig::GetSelf().GetUserRoleName()); return 1; }