예제 #1
0
BOOL KDoodadMgr::DestroyDoodad( DWORD dwId )
{
	BOOL bResult = FALSE;
	KDoodad* pstDoodad = NULL;

	PROCESS_ERROR(pstDoodad = m_cObjPool.GetById(dwId));

	pstDoodad->Uninit();
	m_cObjPool.Remove(dwId);

	bResult = TRUE;
EXIT0:
	return bResult;
}
예제 #2
0
BOOL KDoodadMgr::RemoveFromScene( DWORD dwId )
{
	BOOL bResult = FALSE;
	KDoodad* pstDoodad = NULL;
	IKScene* pScene = NULL;

	PROCESS_ERROR(pstDoodad = m_cObjPool.GetById(dwId));
	PROCESS_ERROR(pScene = pstDoodad->GetScene());
	PROCESS_ERROR(pScene->RemoveDoodad(pstDoodad));

	g_cScriptManager.GetSafeScript()->CallTableFunction("Doodad", "OnLeaveScene", 1, "os",
		pstDoodad->GetScriptInterface(), pstDoodad->m_strClass.c_str());

	bResult = TRUE;
EXIT0:
	return bResult;
}
예제 #3
0
파일: KSO3World.cpp 프로젝트: 1suming/pap2
KDoodad* KSO3World::NewDoodad(DWORD dwDoodadID)
{
    KDoodad*        pResult         = NULL;
	BOOL            bRetCode        = false;
	KDoodad*        pDoodad         = NULL;
	BOOL            bDoodadRegFlag  = false;
    BOOL            bDoodadInitFlag = false;

    pDoodad = KMemory::New<KDoodad>();
    KGLOG_PROCESS_ERROR(pDoodad);

	bRetCode = g_pSO3World->m_DoodadSet.Register(pDoodad, dwDoodadID);
	KGLOG_PROCESS_ERROR(bRetCode);
	bDoodadRegFlag = true;

    bRetCode = pDoodad->Init();
    KGLOG_PROCESS_ERROR(bRetCode);
    bDoodadInitFlag = true;
	
	pResult = pDoodad;
Exit0:
    if (pResult == NULL)
    {
        if (bDoodadInitFlag)
        {
            pDoodad->UnInit();
            bDoodadInitFlag = false;
        }

		if (bDoodadRegFlag)
		{
			g_pSO3World->m_DoodadSet.Unregister(pDoodad);
			bDoodadRegFlag = false;
		}

        if (pDoodad)
        {
            KMemory::Delete(pDoodad);
            pDoodad = NULL;
        }
    }
	return pResult;
}
예제 #4
0
BOOL KDoodadMgr::NotifyRemoveFromScene( DWORD dwId )
{
	BOOL bResult = FALSE;
	KDoodad* pstDoodad = NULL;

#ifdef GAME_SERVER
	PROCESS_ERROR(pstDoodad = GetById(dwId));
	if (pstDoodad->m_eState == emKDOODADSTATE_OPING)
	{
		pstDoodad->CancelDialog(pstDoodad->m_pCurrPlayer);
	}
	// 同步需要取场景,必须放在Uninit之前
	g_cPlayerBaseProcess.DoSyncLeave(*pstDoodad, TRUE);
#endif

	bResult = TRUE;
#ifdef GAME_SERVER
EXIT0:
#endif
	return bResult;
}
예제 #5
0
BOOL KPlayerBaseProcess::OnSyncDoodadState( LPCBYTE pData, UINT uDataLen )
{
	KS2C_SYNC_DOODAD_STATE* pReceived = (KS2C_SYNC_DOODAD_STATE*)pData;

	KDoodad* pDoodad = g_cDoodadMgr.GetById(pReceived->dwId);
	QCONFIRM_RET_FALSE(pDoodad);

	if (pReceived->nDoodadState != (INT)pDoodad->GetState())
	{
		pDoodad->SetState((KEDOODAD_STATE)pReceived->nDoodadState);

		pDoodad->FireEvent(emKOBJEVENTTYPE_DOODAD_STATE_CHANGED,
			pReceived->dwPlayerId,
			pDoodad->GetId(),
			pReceived->nDoodadState);

		// 因为要传递四个参数,现有机制不支持,使用CallFunction来告之脚本这个事情
		//pReceived->dwPlayerId
		//CallTableFunction();
	}
	return TRUE;
}
예제 #6
0
BOOL KPlayerBaseProcess::OnSyncDoodad( LPCBYTE pData, UINT uDataLen )
{
	KS2C_SYNC_DOODAD* pReceived = (KS2C_SYNC_DOODAD*)pData;
	KDoodad* pDoodad = NULL;

	// TODO: improve
	if (g_cDoodadMgr.GetById(pReceived->dwId))
		return FALSE;	

	//pDoodad = g_cOrpgWorld.AddDoodadToScene(pReceived->dwTemplateId, g_cOrpgWorld.m_dwClientSceneId, pReceived->nX, pReceived->nY, pReceived->nZ, pReceived->nDirectionXY, pReceived->dwId);
	pDoodad = g_cDoodadMgr.CreateDoodad(pReceived->dwTemplateId, pReceived->dwId);
	QCONFIRM_RET_FALSE(pDoodad);

	pDoodad->SetMoveState((KE_MOVE_STATE)pReceived->nMoveState);
	pDoodad->m_nVelocityXY = pReceived->nVelocityXY;
	pDoodad->m_nDestX = pReceived->nDestX;
	pDoodad->m_nDestY = pReceived->nDestY;
	pDoodad->m_nDestZ = pReceived->nDestZ;
	pDoodad->m_nFaceDirection = pReceived->nDirectionXY; // 暂时用速度方向代替
	pDoodad->SetState((KEDOODAD_STATE)pReceived->nDoodadState);
	g_cDoodadMgr.AddToScene(pDoodad, g_cOrpgWorld.m_dwClientSceneId, pReceived->nX, pReceived->nY, pReceived->nZ, pReceived->nDirectionXY);
	pDoodad->FireEvent(emKOBJEVENTTYPE_DOODAD_STATE_CHANGED, pReceived->dwPlayerId, pDoodad->GetId(), pReceived->nDoodadState);
	return TRUE;
}
예제 #7
0
KDoodad* KDoodadMgr::CreateDoodad(DWORD dwTemplateId, DWORD dwId /*= KD_BAD_ID*/ )
{
	BOOL bResult = FALSE;
	INT nIndex = 0;
	KDoodad* pDoodad = NULL;

	pDoodad = m_cObjPool.GetById(dwId);
	if (pDoodad)
	{
		nIndex = pDoodad->m_nIndex;
		IKScene* pScene = pDoodad->GetScene();
		if (pScene)
			pScene->RemoveDoodad(pDoodad);
	}
	else
	{
		KDoodadTemplateMapIt stIt = m_mapDoodadTemplate.find(dwTemplateId);
		LOG_PROCESS_ERROR(stIt != m_mapDoodadTemplate.end());

		nIndex = m_cObjPool.Add(dwId);
		LOG_PROCESS_ERROR(pDoodad = m_cObjPool.GetByIndex(nIndex));
		LOG_PROCESS_ERROR(pDoodad->Init(nIndex, &stIt->second));
	}

	bResult = TRUE;
EXIT0:
	if (FALSE == bResult)
	{
		if (pDoodad)
		{
			DestroyDoodad(pDoodad->m_dwId);
			pDoodad = NULL;
		}
	}
	return pDoodad;
}
예제 #8
0
BOOL KPlayerBaseProcess::OnSyncDoodadExtra( LPCBYTE pData, UINT uDataLen )
{
	BOOL bResult = FALSE;
	KDoodad* pDoodad = NULL;
	KS2C_SYNC_DOODAD_EXTRA* pReceived = NULL;
	BOOL bBegin = FALSE;
	DWORD* pdwExtraHeader = NULL;
	BYTE* pstExtraData = NULL;
	
	PROCESS_ERROR(pReceived = (KS2C_SYNC_DOODAD_EXTRA*)pData);
	PROCESS_ERROR(pDoodad = g_cDoodadMgr.GetById(pReceived->dwDoodadId));

	PROCESS_ERROR(pDoodad->BeginSetExtra());
	bBegin = TRUE;

	//PROCESS_ERROR(pDoodad->ClearExtra());
	pdwExtraHeader = (DWORD*)pReceived->acData;
	pstExtraData = (BYTE*)(pReceived->acData + pReceived->dwExtraCount * sizeof(DWORD));
	for (DWORD dwI = 0; dwI < pReceived->dwExtraCount; dwI++)
	{
		KDoodadExtraField* pstExtraField = NULL;

		pstExtraField = (KDoodadExtraField*)pstExtraData;
		if (0 == pstExtraField->dwType)
		{
			PROCESS_ERROR(pDoodad->SetExtraNumber(pstExtraField->dwId, pstExtraField->adwData[0], FALSE));
		}
		else if (1 == pstExtraField->dwType)
		{
			PROCESS_ERROR(pDoodad->SetExtraString(pstExtraField->dwId, (CONST CHAR*)pstExtraField->adwData, FALSE));
		}

		pstExtraData += pdwExtraHeader[dwI];
	}

	PROCESS_ERROR(pDoodad->EndSetExtra(FALSE));
	bBegin = FALSE;
	/*事件*/

	bResult = TRUE;
EXIT0:
	if (bBegin)
	{
		if (pDoodad)
		{
			pDoodad->EndSetExtra(FALSE);
		}
	}
	return bResult;
}