Exemplo n.º 1
0
BOOL KMovableObject::IsAncestorOf(const KMovableObject* pOther) const
{
    BOOL bResult = false;
    DWORD dwFatherID = ERROR_ID;
    KSceneObject* pFather = NULL;

    if (pOther)
        dwFatherID = pOther->m_dwID;

    while (dwFatherID != ERROR_ID)
    {
        if (dwFatherID == m_dwID)
        {
            bResult = true;
            break;
        }

        pFather = m_pScene->GetSceneObjByID(dwFatherID);
        dwFatherID = ERROR_ID;        
        if (pFather)
            dwFatherID = pFather->GetGuideID();
    }

Exit0:
    return bResult;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
0
int KScene::LuaAddCandyBagOnBasket(Lua_State* L)
{
    BOOL                    bResult             = false;
    BOOL                    bRetCode            = false;
    int                     nTopIndex           = 0;
    DWORD                   dwCandyTemplateID   = ERROR_ID;
    int                     nSide               = 0;
    int                     nBasketFloor        = 0;
    KSceneObjectTemplate*   pTemplate           = NULL;
    KSceneObject*           pObj                = NULL;
    KCandyBag*              pCandyBag           = NULL;
    KBasket*                pBasket             = NULL;

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

    dwCandyTemplateID   = (DWORD)Lua_ValueToNumber(L, 1);
    nSide               = (int)Lua_ValueToNumber(L, 2);
    nBasketFloor        = (int)Lua_ValueToNumber(L, 3);
    
    pTemplate = g_pSO3World->m_Settings.m_ObjTemplate.GetTemplate(dwCandyTemplateID);
    KGLOG_PROCESS_ERROR(pTemplate);
    KGLOG_PROCESS_ERROR(pTemplate->m_nType == sotCandyBag);

    KGLOG_PROCESS_ERROR(nSide == sidLeft || nSide == sidRight);
    KGLOG_PROCESS_ERROR(nBasketFloor >= bfFirst && nBasketFloor <= bfSixth);

    pBasket = GetBasket(nSide, nBasketFloor);
    KGLOG_PROCESS_ERROR(pBasket);

    pObj = m_pSceneObjMgr->AddByTemplate(dwCandyTemplateID);
    KGLOG_PROCESS_ERROR(pObj);
    KGLOG_PROCESS_ERROR(pObj->Is(sotCandyBag));

    pCandyBag = (KCandyBag*)pObj;
    pCandyBag->FixTo(pBasket->GetPosition());

    g_PlayerServer.DoSyncSceneObject(pCandyBag, -1);

    bResult = true;
Exit0:
    if (!bResult)
    {
        if (pCandyBag)
        {
            pCandyBag->SetDeleteFlag();
            pCandyBag = NULL;
        }
    }

    Lua_PushBoolean(L, bResult);
    return 1;
}
Exemplo n.º 9
0
int KHero::LuaAISay(Lua_State* L)
{
	BOOL bResult 	    = false;
	BOOL bRetCode	    = false;
	int	 nTopIndex	    = 0;
    int  nTalkChannel   = 0;
    int  nMsgType       = trRoom;
    const char* szMessage = NULL;
    DWORD dwTalkID      = ERROR_ID;
    char* szTalkerName  = m_szName;
	
	nTopIndex = Lua_GetTopIndex(L);
	KGLOG_PROCESS_ERROR(nTopIndex == 2);

    nTalkChannel = (int)Lua_ValueToNumber(L, 1);
    KGLOG_PROCESS_ERROR(nTalkChannel == KAI_TALK_CHANNEL_MAP || nTalkChannel == KAI_TALK_CHANNEL_TEAM);

    szMessage = Lua_ValueToString(L, 2);
    KGLOG_PROCESS_ERROR(szMessage);

    if (nTalkChannel == KAI_TALK_CHANNEL_TEAM)
        nMsgType = trTeam;

    if (m_pOwner)
    {
        dwTalkID = m_pOwner->m_dwID;
        szTalkerName = m_pOwner->m_szName;
    }

    for (KObjEnumerator it = m_pScene->GetObjEnumerator(); it.HasElement(); it.MoveToNext())
    {
        KSceneObject* pObj = it.GetValue();
        if (!pObj->Is(sotHero))
            continue;

        KHero* pHero = (KHero*)pObj;
        KPlayer* pOwner = pHero->GetOwner();
        if (!pOwner)
            continue;
        if (pOwner->m_pFightingHero != pHero)
            continue;

        if (nTalkChannel == KAI_TALK_CHANNEL_TEAM && pHero->m_nSide != m_nSide)
            continue;

        g_PlayerServer.DoTalkMessage(nMsgType, dwTalkID, szTalkerName, m_dwID,  ERROR_ID, pOwner->m_dwID, pOwner->m_szName, strlen(szMessage), szMessage);
    }

	bResult = true;
Exit0:
	Lua_PushBoolean(L, bResult);
	return 1;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
0
BOOL KPlayerBaseProcess::OnSyncFaceDirection( LPCBYTE pData, UINT uDataLen )
{
	KS2C_SYNC_FACE_DIRECTION* pReceived = (KS2C_SYNC_FACE_DIRECTION*)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);
	if (!pSceneObj)
	{
		QLogPrintf(LOG_LEVEL_WARNING, "OnSyncFaceDirection [0x%x] not found, re-syncing...", pReceived->dwId);
		g_cOrpgWorld.AddApplySyncNeighbor(pReceived->dwId);
		return TRUE;
	}

	if (pSceneObj->GetMoveState() == cmsOnStand)
	{
		pSceneObj->m_nFaceDirection = pReceived->nFaceDirection;
	} 
	else
	{
		pSceneObj->m_nStopedFaceDirection = pReceived->nFaceDirection;
	}
	
	return TRUE;
}
Exemplo n.º 13
0
int KScene::LuaRemoveDoodad(Lua_State* L)
{
    int     nResult         = 0;
    BOOL    bRetCode        = false;
    int     nTopIndex       = 0;
    int     nPosX           = 0;
    int     nPosY           = 0;
    int     nRange          = 0;

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

    nPosX       = (int)Lua_ValueToNumber(L, 1);
    nPosY       = (int)Lua_ValueToNumber(L, 2);
    nRange      = (int)Lua_ValueToNumber(L, 3);
    
    for (KObjEnumerator it = m_pSceneObjMgr->GetEnumerator(); it.HasElement(); it.MoveToNext())
    {
        KSceneObject* pObj = it.GetValue();
        if (!g_IsDoodad(pObj))
            continue;

        assert(pObj->m_pTemplate);

        if (pObj->m_pTemplate->m_bImpregnability) // ²»¿ÉÒƳý
            continue;

        if (nRange != -1) // ¼ì²é¾àÀë
        {
            KPOSITION pos = pObj->GetPosition();
            bRetCode = g_InRange(nPosX, nPosY, 0, pos.nX, pos.nY, 0, nRange);
            if (!bRetCode)
                continue;
        }
        RemoveSceneObject(pObj);
    }
    
Exit0:
    return 0;
}
Exemplo n.º 14
0
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;
}
Exemplo n.º 15
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;
}
Exemplo n.º 16
0
int KScene::LuaShowAllHeroAI(Lua_State* L)
{
    int nAILevel = 0;

    KGLogPrintf(KGLOG_INFO, "Begin ShowAllHeroAI ...");
    
    for (KObjEnumerator it = GetObjEnumerator(); it.HasElement(); it.GetValue())
    {
        KSceneObject* pObj = it.GetValue();
        if (!pObj->Is(sotHero))
            continue;

        KHero* pHero = (KHero*)pObj;

        g_pSO3World->m_AIManager.GetAILevel(pHero->m_AIData.nAIType, nAILevel);

        KGLogPrintf(KGLOG_INFO, "Hero ID:%u, Sid:%d, SeatPos:%d, IsAIMode:%d, AILevel:%d, AIType:%d", 
            pHero->m_dwID, pHero->m_nSide, pHero->m_nPos, pHero->m_bAiMode, pHero->m_AIData.nAIType, nAILevel);
    }

    KGLogPrintf(KGLOG_INFO, "End ShowAllHeroAI ...");

    return 0;
}
Exemplo n.º 17
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;
}
Exemplo n.º 18
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;
}
Exemplo n.º 19
0
BOOL KMovableObject::IsStandOn(KSceneObjectType eType)
{
    KSceneObject* pObj = m_pScene->GetSceneObjByID(m_dwGuide);
    return (pObj && pObj->GetType() == eType && m_eMoveType == mosStandOn);
}