int KScene::LuaGetAllHero(Lua_State* L) { KHero* pResult = NULL; KHero* pHero = NULL; int nIndex = 1; lua_newtable(L); for (KObjEnumerator it = m_pSceneObjMgr->GetEnumerator(); it.HasElement(); it.MoveToNext()) { KSceneObject* pObj = it.GetValue(); if (pObj->GetType() != sotHero) continue; pHero = (KHero*)pObj; lua_pushinteger(L, nIndex); pHero->LuaGetObj(L); lua_settable(L, -3); ++nIndex; } Exit0: return 1; }
int KScene::LuaActiveLandMine(Lua_State* L) { int nResult = 0; BOOL bRetCode = false; int nTopIndex = 0; DWORD dwLandMineID = 0; KLandMine* pLandMine = NULL; KSceneObject* pObj = NULL; nTopIndex = Lua_GetTopIndex(L); KGLOG_PROCESS_ERROR(nTopIndex == 1); dwLandMineID = (DWORD)Lua_ValueToNumber(L, 1); pObj = GetSceneObjByID(dwLandMineID); KGLOG_PROCESS_ERROR(pObj); KGLOG_PROCESS_ERROR(pObj->GetType() == sotLandMine); pLandMine = (KLandMine*)pObj; pLandMine->ActiveState(); Exit0: return nResult; }
int KScene::LuaGetSceneObjCountByType(Lua_State* L) { int nResult = 0; int nTopIndex = 0; KSceneObjectType eType = sotInvalid; int nCount = 0; nTopIndex = Lua_GetTopIndex(L); KGLOG_PROCESS_ERROR(nTopIndex == 1); eType = (KSceneObjectType)(int)Lua_ValueToNumber(L, 1); for (KObjEnumerator it = m_pSceneObjMgr->GetEnumerator(); it.HasElement(); it.MoveToNext()) { KSceneObject* pObj = it.GetValue(); assert(pObj); if (pObj->GetType() == eType) ++nCount; } lua_pushinteger(L, nCount); nResult = 1; Exit0: return nResult; }
int KScene::LuaGetPlayerHero(Lua_State* L) { KHero* pResult = NULL; int nTopIndex = 0; DWORD dwTemplateID = ERROR_ID; KHero* pHero = NULL; nTopIndex = Lua_GetTopIndex(L); KGLOG_PROCESS_ERROR(nTopIndex == 1); dwTemplateID = (DWORD)Lua_ValueToNumber(L, 1); for (KObjEnumerator it = m_pSceneObjMgr->GetEnumerator(); it.HasElement(); it.MoveToNext()) { KSceneObject* pObj = it.GetValue(); if (pObj->GetType() != sotHero) continue; pHero = (KHero*)pObj; if (pHero->IsNpc()) continue; if (pHero->m_dwTemplateID == dwTemplateID) { pResult = pHero; break; } } KG_PROCESS_ERROR(pResult); return pResult->LuaGetObj(L); Exit0: return 0; }
KMovableObject* KMovableObject::GetFirstFollowerWithType(KSceneObjectType eType) const { KMovableObject* pResult = NULL; KSceneObject* pObj = NULL; for (std::vector<DWORD>::const_iterator constIt = m_vecFollower.begin(); constIt != m_vecFollower.end(); ++constIt) { pObj = m_pScene->GetSceneObjByID(*constIt); if (pObj == NULL) continue; if (pObj->GetType() == eType) { pResult = dynamic_cast<KMovableObject*>(pObj); break; } } return pResult; }
int KScene::LuaGetObjType(Lua_State* L) { int nResult = 0; int nTopIndex = 0; uint32_t dwObjID = 0; KSceneObject* pObj = NULL; nTopIndex = Lua_GetTopIndex(L); KGLOG_PROCESS_ERROR(nTopIndex == 1); dwObjID = (uint32_t)Lua_ValueToNumber(L, 1); pObj = m_pSceneObjMgr->Get(dwObjID); KGLOG_PROCESS_ERROR(pObj); lua_pushinteger(L, pObj->GetType()); nResult = 1; Exit0: return nResult; }
int KScene::LuaSetBasketNotCostHP(Lua_State* L) { int nTopIndex = 0; BOOL bCanCostHP = false; nTopIndex = Lua_GetTopIndex(L); KGLOG_PROCESS_ERROR(nTopIndex == 1); bCanCostHP = (BOOL)Lua_ValueToBoolean(L, 1); for (KObjEnumerator it = m_pSceneObjMgr->GetEnumerator(); it.HasElement(); it.MoveToNext()) { KSceneObject* pObj = it.GetValue(); if (pObj->GetType() == sotBasket) { KBasket* pBasket = (KBasket*)pObj; pBasket->m_bNotCostHP = bCanCostHP; } } Exit0: return 0; }
int KScene::LuaResetBattle(Lua_State* L) { m_nShouldStartFrame = g_pSO3World->m_nGameLoop + BATTLE_START_COUNT_DOWN; m_eSceneState = ssCountDown; for (KObjEnumerator it = m_pSceneObjMgr->GetEnumerator(); it.HasElement(); it.MoveToNext()) { KSceneObject* pObj = it.GetValue(); if (pObj->GetType() != sotHero) continue; KHero* pHero = (KHero*)pObj; if (pHero->IsMainHero()) { KPlayer* pPlayer = pHero->GetOwner(); KGLOG_PROCESS_ERROR(pPlayer); g_PlayerServer.DoRemoteCall(pPlayer->m_nConnIndex, "onResetBattle", BATTLE_START_COUNT_DOWN, m_Battle.m_nFramePerBattle); } } Exit0: return 0; }
void KMovableObject::Activate(int nCurLoop) { m_nGameLoop = nCurLoop; m_moveOffset.nX = m_nX; m_moveOffset.nY = m_nY; m_moveOffset.nZ = m_nZ; if (m_dwObstacleID) { KMovableObstacle* pObstacle = NULL; KSceneObject* pSceneObj = m_pScene->GetSceneObjByID(m_dwObstacleID); if (pSceneObj) { assert(g_IsObstacle(pSceneObj->GetType())); pObstacle = (KMovableObstacle*)pSceneObj; KPOSITION cPos = GetPosition(); if (pObstacle->GetType() == sotHoist) { cPos = GetPosition(); cPos.nZ = pObstacle->m_nZ + pObstacle->m_nHeight; SetPosition(cPos); } } } switch (m_eMoveType) { case mosFree: OnFree(nCurLoop); break; case mosIdle: OnIdle(nCurLoop); break; case mosTrackMove: OnTrackMove(nCurLoop); break; default: break; } if (m_dwObstacleID) { KPOSITION cPos; KMovableObstacle* pObstacle = NULL; KSceneObject* pSceneObj = m_pScene->GetSceneObjByID(m_dwObstacleID); if (pSceneObj) { int nZ = 0; assert(g_IsObstacle(pSceneObj->GetType())); pObstacle = (KMovableObstacle*)pSceneObj; cPos = GetPosition(); nZ = cPos.nZ + pObstacle->m_moveOffset.nZ; if (pObstacle->m_nZ + pObstacle->m_nHeight > nZ) nZ = pObstacle->m_nZ + pObstacle->m_nHeight; SetPosition(cPos.nX + pObstacle->m_moveOffset.nX, cPos.nY + pObstacle->m_moveOffset.nY, nZ); } } m_moveOffset.nX = m_nX - m_moveOffset.nX; m_moveOffset.nY = m_nY - m_moveOffset.nY; m_moveOffset.nZ = m_nZ - m_moveOffset.nZ; }
BOOL KMovableObject::IsStandOn(KSceneObjectType eType) { KSceneObject* pObj = m_pScene->GetSceneObjByID(m_dwGuide); return (pObj && pObj->GetType() == eType && m_eMoveType == mosStandOn); }