示例#1
0
int KScene::LuaSetObjPosition(Lua_State* L)
{
    int             nResult     = 0;
    int             nTopIndex   = 0;
    uint32_t        dwObjID     = 0;
    KSceneObject*   pObj        = NULL;
    int             nX          = 0;
    int             nY          = 0;
    int             nZ          = 0;

    nTopIndex = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nTopIndex == 4);

    dwObjID = (uint32_t)Lua_ValueToNumber(L, 1);
    nX      = (int)Lua_ValueToNumber(L, 2);
    nY      = (int)Lua_ValueToNumber(L, 3);
    nZ      = (int)Lua_ValueToNumber(L, 4);

    pObj = m_pSceneObjMgr->Get(dwObjID);
    KGLOG_PROCESS_ERROR(pObj);

    pObj->SetPosition(nX, nY, nZ);

    g_PlayerServer.DoSyncSceneObjPosition(pObj);
    
Exit0:
    return 0;
}
BOOL KPlayerBaseProcess::OnSyncTeleport( LPCBYTE pData, UINT uDataLen )
{
	KS2C_SYNC_TELEPORT* pReceived = (KS2C_SYNC_TELEPORT*)pData;
	KSceneObject* pSceneObj = NULL;

	if (IS_PLAYER(pReceived->dwId))
	{
		pSceneObj = g_cPlayerMgr.GetById(pReceived->dwId);
	}
	else if (IS_NPC(pReceived->dwId))
	{
		pSceneObj = g_cNpcMgr.GetById(pReceived->dwId);
	}
	else if (IS_DOODAD(pReceived->dwId))
	{
		pSceneObj = g_cDoodadMgr.GetById(pReceived->dwId);
	}
	else
	{
		Q_Printl("Unknown SceneObject " << pReceived->dwId);
	}
	QCONFIRM_RET_FALSE(pSceneObj);

	pSceneObj->SetPosition(pReceived->nX, pReceived->nY, pReceived->nZ);
	pSceneObj->StopMoving();

	return TRUE;
}
示例#3
0
int KScene::LuaAddSceneObj(Lua_State* L )
{
	DWORD                   dwObjID             = 0;
	BOOL                    bRetCode            = false;
	int                     nTopIndex           = 0;
	DWORD                   dwTemplateID        = ERROR_ID;
	int                     nX					= 0;
	int                     nY					= 0;
	int						nZ					= 0;
	int						nVelocityX			= 0;
	int						nVelocityY			= 0;
	int						nVelocityZ			= 0;
	KSceneObjectTemplate*   pTemplate           = NULL;
	KSceneObject*           pObj                = NULL;
	KMovableObject*			pMovableObj			= NULL;

	nTopIndex = Lua_GetTopIndex(L);
	KGLOG_PROCESS_ERROR(nTopIndex == 4 || nTopIndex == 7);

	dwTemplateID        = (DWORD)Lua_ValueToNumber(L, 1);
	nX					= (int)Lua_ValueToNumber(L, 2);
	nY					= (int)Lua_ValueToNumber(L, 3);
	nZ					= (int)Lua_ValueToNumber(L, 4);

    if (nTopIndex == 7)
    {
        nVelocityX			= (int)Lua_ValueToNumber(L, 5);
        nVelocityY			= (int)Lua_ValueToNumber(L, 6);
        nVelocityZ			= (int)Lua_ValueToNumber(L, 7);
    }

	KGLOG_PROCESS_ERROR(nX >= 0 && nX < GetLength() && nY >= 0 && nY < GetWidth() && nZ >= 0);

	pTemplate = g_pSO3World->m_Settings.m_ObjTemplate.GetTemplate(dwTemplateID);
	KGLOG_PROCESS_ERROR(pTemplate);

	pObj = m_pSceneObjMgr->AddByTemplate(dwTemplateID);
	KGLOG_PROCESS_ERROR(pObj);

    pObj->SetPosition(nX, nY, nZ);

    if (pObj->m_pTemplate && pObj->m_pTemplate->m_Obstacle)
    {
        ApplyObstacle(pObj, true); 
    }

	pMovableObj = dynamic_cast<KMovableObject*>(pObj);
    if (pMovableObj)
    {
        pMovableObj->m_nVelocityX = nVelocityX;
        pMovableObj->m_nVelocityY = nVelocityY;
        pMovableObj->m_nVelocityZ = nVelocityZ;
    }

	g_PlayerServer.DoSyncSceneObject(pObj);

	dwObjID = pObj->m_dwID;
Exit0:
	if (dwObjID == 0)
	{
		if (pObj)
		{
			pObj->SetDeleteFlag();
			pObj = NULL;
		}
	}

	Lua_PushNumber(L, dwObjID);
	return 1;
}