Exemplo n.º 1
0
int LuaRenameConflictTong(Lua_State* L)
{
    BOOL        bRetCode        = false;
    int         nTopIndex       = 0;
    int         nConnIndex      = 0;
    DWORD       dwPlayerID      = ERROR_ID;
    DWORD       dwTongID        = ERROR_ID;
    const char* pszNewName      = NULL;
    size_t      uNewNameLen     = 0;

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

    nConnIndex = (int)Lua_ValueToNumber(L, 1);
    KGLOG_PROCESS_ERROR(nConnIndex);

    dwPlayerID = (DWORD)Lua_ValueToNumber(L, 2);
    KGLOG_PROCESS_ERROR(dwPlayerID != ERROR_ID);

    dwTongID = (DWORD)Lua_ValueToNumber(L, 3);
    KGLOG_PROCESS_ERROR(dwTongID != ERROR_ID);

    pszNewName = (const char*)Lua_ValueToString(L, 4);
    KGLOG_PROCESS_ERROR(pszNewName);

    uNewNameLen = strlen(pszNewName);
    KGLOG_PROCESS_ERROR(uNewNameLen < _NAME_LEN);

    g_pSO3GameCenter->m_TongManager.ProcessRenameConflictTong(nConnIndex, dwPlayerID, dwTongID, pszNewName);

Exit0:
    return 0;
}
Exemplo n.º 2
0
int LuaSendPrizeInfo(Lua_State* L)
{
    int         nRetCode        = 0;
    int         nTopIndex       = 0;
    DWORD       dwPlayerID      = ERROR_ID;
    KRole*      pRole           = NULL;
    const char* pszType         = NULL;
    int         nValue          = 0;

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

    dwPlayerID = (DWORD)Lua_ValueToNumber(L, 1);
    KGLOG_PROCESS_ERROR(dwPlayerID);

    pszType = (const char*)Lua_ValueToString(L, 2);
    KGLOG_PROCESS_ERROR(pszType);

    nValue = (int)Lua_ValueToNumber(L, 3);

    assert(g_pSO3GameCenter);
    pRole = g_pSO3GameCenter->m_RoleManager.GetRole(dwPlayerID);
    KGLOG_PROCESS_ERROR(pRole);

    g_pSO3GameCenter->m_Eyes.DoSendPrizeInfo(pRole->m_pszAccount, pRole->m_szName, dwPlayerID, pszType, nValue);   
Exit0:
    return 0;
}
Exemplo n.º 3
0
int KHero::LuaCheckAISelfDefData(Lua_State* L)
{
    int nRetCode = KAI_BRANCH_ERROR;
    BOOL bRetCode	= false;
    int	 nTopIndex	= 0;
    const char* pszKey = NULL;
    int nMinValue = 0;
    int nMaxValue = 0;
    int nCurValue = 0;

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

    pszKey = Lua_ValueToString(L, 1);
    KGLOG_PROCESS_ERROR(pszKey);

    nMinValue = (int)Lua_ValueToNumber(L, 1);
    nMaxValue = (int)Lua_ValueToNumber(L, 2);

    if (m_dictAISelfDefData.find(pszKey) == m_dictAISelfDefData.end())
        goto Exit0;

    nCurValue = m_dictAISelfDefData[pszKey];
    if (nCurValue < nMinValue || nCurValue > nMaxValue)
    {
        nRetCode = KAI_BRANCH_FAILED;
        goto Exit0;
    }

    nRetCode = KAI_BRANCH_SUCCESS;
Exit0:
    Lua_PushNumber(L, nRetCode);
    return 1;
}
Exemplo n.º 4
0
int KTeamClient::LuaChangeMemberGroup(Lua_State* L)
{
    int      nTopIndex      = 0;
    DWORD    dwMemberID     = ERROR_ID;
    DWORD    dwDstMemberID  = ERROR_ID;
    int      nDstGroup      = -1;
    KPlayer* pPlayer        = NULL;

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

    dwMemberID = (DWORD)Lua_ValueToNumber(L, 1);
    nDstGroup  = (int)Lua_ValueToNumber(L, 2);

    if (nTopIndex == 3)
    {
        dwDstMemberID = (DWORD)Lua_ValueToNumber(L, 3);
    }

    pPlayer = g_pSO3World->m_PlayerSet.GetObj(g_pSO3World->m_dwClientPlayerID);
    KGLOG_PROCESS_ERROR(pPlayer);

    KGLOG_PROCESS_ERROR(nDstGroup >= 0 && nDstGroup < m_nGroupNum);
    KGLOG_PROCESS_ERROR(pPlayer->m_dwID == m_dwAuthority[tatLeader]);

    g_PlayerClient.DoTeamChangeMemberGroupRequest(dwMemberID, nDstGroup, dwDstMemberID);

Exit0:
    return 0;
}
Exemplo n.º 5
0
int KScene::LuaSetTimer(Lua_State* L)
{
    int         nParamCount     = 0;
    DWORD       dwID            = 0;
    int         nTime           = 0;
    const char* pszScriptName   = NULL;
    int         nParam1         = 0;
    int         nParam2         = 0;

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

    nTime           =   (int)Lua_ValueToNumber(L, 1);
    pszScriptName   =   Lua_ValueToString(L, 2);
    nParam1         =   (int)Lua_ValueToNumber(L, 3);
    nParam2         =   (int)Lua_ValueToNumber(L, 4);

    KGLOG_PROCESS_ERROR(pszScriptName);

    dwID = m_ScriptTimerList.SetTimer(nTime, pszScriptName, nParam1, nParam2);
    KGLOG_PROCESS_ERROR(dwID);

Exit0:
    lua_pushinteger(L, dwID);
    return 1;
}
Exemplo n.º 6
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.º 7
0
int KTeamClient::LuaSetTeamFormationLeader(Lua_State* L)
{
    int         nResult              = 0;
    KPlayer*    pClientPlayer        = NULL;
    int         nTopIndex            = 0;
    DWORD       dwNewFormationLeader = ERROR_ID;
    int         nGroupIndex          = 0;

    nTopIndex = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nTopIndex == 1 || nTopIndex == 2);

    dwNewFormationLeader = (DWORD)Lua_ValueToNumber(L, 1);
    if (nTopIndex == 2)
    {
        nGroupIndex      = (int)Lua_ValueToNumber(L, 2);
    }

    pClientPlayer = g_pSO3World->m_PlayerSet.GetObj(g_pSO3World->m_dwClientPlayerID);
    KG_PROCESS_ERROR(pClientPlayer);

    KG_PROCESS_ERROR(m_dwTeamID != ERROR_ID);

    KG_PROCESS_ERROR(m_TeamGroup[nGroupIndex].dwFormationLeader != dwNewFormationLeader);

    g_PlayerClient.DoTeamSetFormationLeader(dwNewFormationLeader, nGroupIndex, pClientPlayer);

    nResult = 0;
Exit0:
    return nResult;
}
Exemplo n.º 8
0
int KHero::LuaSetAISelfDefData(Lua_State* L)
{
    BOOL bResult 	    = false;
    BOOL bRetCode	    = false;
    int	 nTopIndex	    = 0;
    const char* pszKey  = NULL;
    int nNewValue       = 0;
    BOOL bDirectlySet   = false;
    int nDefaultValue   = 0;
    int nCurValue 		= 0;

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

    pszKey        = Lua_ValueToString(L, 1);
    KGLOG_PROCESS_ERROR(pszKey);

    nNewValue     = (int)Lua_ValueToNumber(L, 2);
    bDirectlySet  = (BOOL)Lua_ValueToBoolean(L, 3);
    nDefaultValue = (int)Lua_ValueToNumber(L, 4);

    if (bDirectlySet)
        m_dictAISelfDefData[pszKey] = nNewValue;
    else if (m_dictAISelfDefData.find(pszKey) == m_dictAISelfDefData.end())
        m_dictAISelfDefData[pszKey] = nDefaultValue + nNewValue;
    else
        m_dictAISelfDefData[pszKey] += nNewValue;
    
Exit0:
    return 0;
}
Exemplo n.º 9
0
int LuaGetSceneConnIndex(Lua_State* L)
{
    int         nResult         = 0;
    int         nTopIndex       = 0;
    DWORD       dwMapID         = 0;
    int         nMapCopyIndex   = 0;
    KMapCopy*   pMapCopy        = NULL;

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

    dwMapID         = (DWORD)Lua_ValueToNumber(L, 1);
    nMapCopyIndex   = (int)Lua_ValueToNumber(L, 2);

    pMapCopy = g_pSO3GameCenter->m_MapManager.GetMapCopy(dwMapID, nMapCopyIndex);
    KG_PROCESS_ERROR(pMapCopy);
    
    nResult = pMapCopy->m_nConnIndex;
Exit0:
    if (nResult)
        Lua_PushNumber(L, nResult);
    else
        Lua_PushNil(L);

    return 1;
}
Exemplo n.º 10
0
int KScene::LuaFixObj(Lua_State* L)
{
    BOOL bResult 	= false;
    BOOL bRetCode	= false;
    int	 nTopIndex	= 0;
    int  nObjID     = 0;
    KSceneObject* pSceneObj = NULL;
    KMovableObject* pMoveObj = NULL;
    KPOSITION pos;

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

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

    pSceneObj = GetSceneObjByID(nObjID);
    KGLOG_PROCESS_ERROR(pSceneObj);
    
    pMoveObj = dynamic_cast<KMovableObject*>(pSceneObj);
    KGLOG_PROCESS_ERROR(pMoveObj);

    pMoveObj->FixTo(pos);
    g_PlayerServer.DoSyncSceneObject(pMoveObj, -1);

    bResult = true;
Exit0:
    Lua_PushBoolean(L, bResult);
    return 1;
}
Exemplo n.º 11
0
int KHero::LuaSetMoveTarget(Lua_State* L)
{
    BOOL        bRetCode        = false;
    int         nTopIndex       = 0;
    BOOL        bMove           = false;
    int         nDirection      = 0;

    nTopIndex = Lua_GetTopIndex(L);
    if (nTopIndex == 1)
    {
        m_AIData.eTargetType = KTARGET_OBJ;
        m_AIData.dwTargetObjID = (DWORD)Lua_ValueToNumber(L, 1);
    }
    else if(nTopIndex == 3)
    {
        m_AIData.eTargetType = KTARGET_POSITION;
        m_AIData.nTargetX = (DWORD)Lua_ValueToNumber(L, 1);
        m_AIData.nTargetY = (DWORD)Lua_ValueToNumber(L, 2);
        m_AIData.nTargetZ = (DWORD)Lua_ValueToNumber(L, 3);

        MAKE_IN_RANGE(m_AIData.nTargetX, 0, m_pScene->GetLength());
        MAKE_IN_RANGE(m_AIData.nTargetY, 0, m_pScene->GetWidth());
    }

    return 0;
}
Exemplo n.º 12
0
int LuaCreateTong(Lua_State* L)
{
    int         nResult     = 0;
    BOOL        bRetCode    = false;
    int         nTopIndex   = 0;
    DWORD       dwPlayerID  = 0;
    const char* pszTongName = 0;
    int         nTemplateID = 0;

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

    dwPlayerID  = (DWORD)Lua_ValueToNumber(L, 1);

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

    nTemplateID = (int)Lua_ValueToNumber(L, 3);

    bRetCode = g_pSO3GameCenter->m_TongManager.CreateTong(dwPlayerID, pszTongName, nTemplateID);
    
    Lua_PushBoolean(L, bRetCode);
    nResult = 1;
Exit0:
    return nResult;
}
Exemplo n.º 13
0
int LuaGetPlayerEnterNewCopyTimesInfo(Lua_State* L)
{
    int         nResult             = 0;
    KMapInfo*   pMapInfo            = NULL;
    int         nTopIndex           = 0;
    DWORD       dwMapID             = 0;
    DWORD       dwPlayerID          = 0;
    int         nAlreadyEnterTimes  = 0;
    KNEW_MAP_LIMIT_TABLE::iterator it;

    nTopIndex = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nTopIndex == 2);
    
    dwMapID     = (DWORD)Lua_ValueToNumber(L, 1);
    dwPlayerID  = (DWORD)Lua_ValueToNumber(L, 2);

    pMapInfo = g_pSO3GameCenter->m_MapManager.GetMapInfo(dwMapID);
    KGLOG_PROCESS_ERROR(pMapInfo);
    
    KG_PROCESS_ERROR(pMapInfo->m_nType == emtDungeon || pMapInfo->m_nType == emtBattleField);

    it = pMapInfo->m_PlayerEnterNewCopyTimes.find(dwPlayerID);
    if (it != pMapInfo->m_PlayerEnterNewCopyTimes.end())
    {
        nAlreadyEnterTimes = it->second.nTimes;
    }   
    
    Lua_PushNumber(L, nAlreadyEnterTimes);

    nResult = 1;
Exit0:
    return nResult;
}
Exemplo n.º 14
0
int LuaRefreshMapCopy(Lua_State* L)
{
    BOOL        bResult         = false;
    BOOL        bRetCode        = false;
    int         nTopIndex       = 0;
    DWORD       dwMapID         = 0;
    int         nMapCopyIndex   = 0;
    KMapCopy*   pMapCopy        = NULL;

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

    dwMapID       = (DWORD)Lua_ValueToNumber(L, 1);
    nMapCopyIndex = (int)Lua_ValueToNumber(L, 2);

    pMapCopy = g_pSO3GameCenter->m_MapManager.GetMapCopy(dwMapID, nMapCopyIndex);
    KGLOG_PROCESS_ERROR(pMapCopy);
    KGLOG_PROCESS_ERROR(pMapCopy->m_nConnIndex);

    bRetCode = g_pSO3GameCenter->m_GameServer.DoMapCopyDoClearPlayerPrepare(
        pMapCopy->m_nConnIndex, dwMapID, nMapCopyIndex, bpcMapRefresh, BANISH_PLAYER_WAIT_SECONDS
    );
    KGLOG_PROCESS_ERROR(bRetCode);

    pMapCopy->m_eState       = eMapStateRefreshing;
    pMapCopy->m_nRefreshTime = g_pSO3GameCenter->m_nTimeNow + BANISH_PLAYER_WAIT_SECONDS;

Exit0:
    Lua_PushBoolean(L, bResult);
    return 1;
}
Exemplo n.º 15
0
int LuaRandom(Lua_State* L)
{
    int nResult = 0;
    int nRetCode = 0;
    int nX = 0;
    int nY = 0;

    nRetCode = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nRetCode == 1 || nRetCode == 2);

    if (nRetCode == 1)
    {
        nX = 1;
        nY = (int)Lua_ValueToNumber(L, 1);
    }
    else if (nRetCode == 2)
    {
        nX = (int)Lua_ValueToNumber(L, 1);
        nY = (int)Lua_ValueToNumber(L, 2);
    }
    else
    {
        KGLOG_PROCESS_ERROR(false);
    }

    KGLOG_PROCESS_ERROR(nX >= 1 && nY >= nX);

    nResult = g_Random(nY - nX + 1) + nX;
Exit0:
    lua_pushinteger(L, nResult);
    return 1;
}
Exemplo n.º 16
0
int LuaCreatePQ(Lua_State* L)
{
    int     nResult         = 0;
    int     nTopIndex       = 0;
    DWORD   dwPQTemplateID  = 0;
    int     nOwnerType      = pqotInvalid;
    DWORD   dwOwnerID1      = 0;
    DWORD   dwOwnerID2      = 0;
    DWORD   dwOwnerID3      = 0;
    DWORD   dwPQID          = 0;

    nTopIndex = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nTopIndex == 1 || nTopIndex == 5);

    dwPQTemplateID = (DWORD)Lua_ValueToNumber(L, 1);

    if (nTopIndex == 5)
    {
        nOwnerType = (int)Lua_ValueToNumber(L, 2);
        dwOwnerID1 = (DWORD)Lua_ValueToNumber(L, 3);
        dwOwnerID2 = (DWORD)Lua_ValueToNumber(L, 4);
        dwOwnerID3 = (DWORD)Lua_ValueToNumber(L, 5);
    }

    dwPQID = g_pSO3GameCenter->m_PQCenter.CreatePQ(dwPQTemplateID, (KGPQ_OWNER_TYPE)nOwnerType, dwOwnerID1, dwOwnerID2, dwOwnerID3);

Exit0:
    Lua_PushNumber(L, dwPQID);
    return 1;
}
Exemplo n.º 17
0
int KScene::LuaUpdateSceneObjectObstacle(Lua_State* L)
{
	BOOL bResult 	= false;
	BOOL bRetCode	= false;
	int	 nTopIndex	= 0;
    DWORD dwSceneObjectID = ERROR_ID;
    BOOL bApply = false;
    KSceneObject* pSceneObject = NULL;
	
	nTopIndex = Lua_GetTopIndex(L);
	KGLOG_PROCESS_ERROR(nTopIndex == 2);

    dwSceneObjectID = (DWORD)Lua_ValueToNumber(L, 1);
    bApply = (BOOL)Lua_ValueToNumber(L, 2);

    pSceneObject = GetSceneObjByID(dwSceneObjectID);
    KGLOG_PROCESS_ERROR(pSceneObject);

    ApplyObstacle(pSceneObject, bApply);

	bResult = true;
Exit0:
	Lua_PushBoolean(L, bResult);
	return 1;
}
Exemplo n.º 18
0
int KHero::LuaAimAt(Lua_State* L)
{
    BOOL bResult    = false;
    BOOL bRetCode   = false;
    int  nTopIndex  = 0;
    BOOL bAimAt     = false;
    int  nDirection = 0;
    KDoodad* pDoodad = NULL;

    nTopIndex = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nTopIndex == 2);
    
    bAimAt = (BOOL)Lua_ValueToNumber(L, 1);
    nDirection = (int)Lua_ValueToNumber(L, 2);

    pDoodad = GetHoldingDoodad();
    KGLOG_PROCESS_ERROR(pDoodad);

    bRetCode = AimAt(bAimAt, nDirection, pDoodad->m_dwID, true);
    KGLOG_PROCESS_ERROR(bRetCode);

    bResult = true;
Exit0:
    Lua_PushBoolean(L, bResult);
    return 1;
}
Exemplo n.º 19
0
int KAILogic::LuaNewAction(Lua_State* L)
{
    int         nResult     = 0;
    int         nRetCode    = 0;
    int         nActionID   = KAI_ACTION_ID_NONE;
    int         nActionKey  = eakInvalid;
    KAIAction*  pActionData = NULL;
    std::pair<KAI_ACTION_TABLE::iterator, bool> RetPair;

    nRetCode = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nRetCode == 2);

    nActionID = (int)Lua_ValueToNumber(L, 1);
    KGLOG_PROCESS_ERROR(nActionID > KAI_ACTION_ID_NONE);

    nActionKey = (int)Lua_ValueToNumber(L, 2);
    KGLOG_PROCESS_ERROR(nActionKey > eakInvalid);

    if (nActionKey < KAI_USER_ACTION)
    {
        KAI_ACTION_FUNC PAction  = NULL;

        PAction = g_pSO3World->m_AIManager.GetActionFunction(nActionKey);
        if (PAction == NULL)
        {
            KGLogPrintf(KGLOG_ERR, "[AI] Unregistered sys action(ID: %d, Key: %d) in ai %d\n", nActionID, nActionKey, m_nAIType);
            goto Exit0;
        }
    }
    else
    {
        KUSER_ACTION_TABLE::iterator it = m_UserActionTable.find(nActionKey);

        if (it == m_UserActionTable.end())
        {
            KGLogPrintf(KGLOG_ERR, "[AI] Unregistered lua actionID: %d, Key: %d) in ai %d\n", nActionID, nActionKey, m_nAIType);
            goto Exit0;
        }
    }

    RetPair = m_ActionTable.insert(std::make_pair(nActionID, KAIAction()));
    if (!RetPair.second)
    {
        KGLogPrintf(KGLOG_ERR, "[AI] Duplicated AI action(%d) in ai %d\n", nActionID, m_nAIType);
        goto Exit0;
    }

    pActionData = &(RetPair.first->second);

    pActionData->m_nKey = nActionKey;

    nResult = pActionData->LuaGetObj(L);
Exit0:
    return nResult;
}
Exemplo n.º 20
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.º 21
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.º 22
0
int KAILogic::LuaNewState(Lua_State* L)
{
    int                     nResult     = 0;
    int                     nRetCode    = 0;
    int                     nState      = 0;
    KAIState*               pState      = NULL;
    std::pair<KAI_STATE_TABLE::iterator, bool> RetPair;

    nRetCode = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nRetCode == 1);

    nState = (int)Lua_ValueToNumber(L, 1);
    KGLOG_PROCESS_ERROR(nState > 0);

    
    RetPair = m_StateTable.insert(std::make_pair(nState, KAIState(this, nState)));
    if (!RetPair.second)
    {
        KGLogPrintf(KGLOG_ERR, "[AI] Duplicated AI state(%d) in ai type %d\n", nState, m_nAIType);
        goto Exit0;
    }

    pState = &(RetPair.first->second);

    nResult = pState->LuaGetObj(L);
Exit0:
    return nResult;
}
Exemplo n.º 23
0
int LuaSetStatData(Lua_State* L)
{
    int         nTopIndex    = 0;
    int         nValue       = 0;
    size_t      uNameLen     = 0;
    const char* pszName      = NULL;
    const char* pszLuaPrefix = "lua_";
    char        szName[STAT_DATA_NAME_LEN];

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

    pszName = Lua_ValueToString(L, 1);
    KGLOG_PROCESS_ERROR(pszName);

    uNameLen = strlen(pszName) + strlen(pszLuaPrefix) + 1;
    KGLOG_PROCESS_ERROR(uNameLen <= sizeof(szName));

    nValue = (int)Lua_ValueToNumber(L, 2);

    snprintf(szName, sizeof(szName), "%s%s", pszLuaPrefix, pszName);
    szName[sizeof(szName) - 1] = '\0';

    g_pSO3GameCenter->m_StatDataManager.SetDataValue(szName, nValue);

Exit0:
    return 0;
}
Exemplo n.º 24
0
int KScene::LuaSetBattleTotalFrame(Lua_State* L)
{
    BOOL bResult = false;
    BOOL bRetCode = false;
    int nTopIndex = 0;
    int nTotalFrame = 0;
    BOOL bReTiming = false;

    nTopIndex = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nTopIndex == 1 || nTopIndex == 2);

    nTotalFrame = (int)Lua_ValueToNumber(L, 1);
    KGLOG_PROCESS_ERROR(nTotalFrame > 0);

    if (nTopIndex == 2)
        bReTiming = (BOOL)Lua_ValueToBoolean(L, 2);

    bRetCode = m_Battle.SetBattleTotalFrame(nTotalFrame, bReTiming);
    KGLOG_PROCESS_ERROR(bRetCode);

    bResult = true;
Exit0:
    Lua_PushBoolean(L, bResult);
    return 1;
}
Exemplo n.º 25
0
int KSchemeScriptTable::LuaInteraction_Request(Lua_State *L)
{
    int nRetCode = false;
    const char * pcszName = NULL;
    const char * pcszAddress = NULL;
    const char * pcszObjectName = NULL;
    const char * pcszVerb = NULL;
    int nPort = 0;
    int nParamCount = Lua_GetTopIndex(L);

    KGLOG_PROCESS_ERROR(nParamCount == 5);

    pcszName = Lua_ValueToString(L, 1);
    KGLOG_PROCESS_ERROR(pcszName);

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

    pcszObjectName = Lua_ValueToString(L, 3);
    KGLOG_PROCESS_ERROR(pcszObjectName);

    pcszVerb = Lua_ValueToString(L, 4);
    KGLOG_PROCESS_ERROR(pcszVerb);

    nPort = (int)Lua_ValueToNumber(L, 5);

    nRetCode = g_pSO3UI->m_pInteraction->Request(pcszName, pcszAddress, pcszObjectName, pcszVerb, nPort, &Interaction_RequestResult);
    KGLOG_PROCESS_ERROR(nRetCode);

    lua_pushboolean(L, TRUE);
    return 1;
Exit0:
    lua_pushboolean(L, FALSE);
    return 1;
}
Exemplo n.º 26
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.º 27
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.º 28
0
int LuaFreezeRole(Lua_State* L)
{
    int         nRetCode        = false;
    const char* pszRoleName     = NULL;
    int         nFreezeSecond   = 0;
    time_t      nFreezeEndTime  = 0;
    KRole*      pRole           = NULL;

    nRetCode = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nRetCode == 2);

    pszRoleName = Lua_ValueToString(L, 1);
    KGLOG_PROCESS_ERROR(pszRoleName);

    nFreezeSecond = (int)Lua_ValueToNumber(L, 2);

    nFreezeEndTime = g_pSO3GameCenter->m_nTimeNow + nFreezeSecond;

    pRole = g_pSO3GameCenter->m_RoleManager.GetRole(pszRoleName);
    KGLOG_PROCESS_ERROR(pRole);

    nRetCode = g_pSO3GameCenter->m_RoleManager.FreezeRole(pRole->m_dwPlayerID, nFreezeEndTime);
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = g_pSO3GameCenter->m_MiscDB.DoUpdateRoleBlackList(pRole->m_dwPlayerID, nFreezeEndTime);
    KGLOG_PROCESS_ERROR(nRetCode);

Exit0:
    return 0;
}
Exemplo n.º 29
0
int KScene::LuaGetDoodadCount(Lua_State* L)
{
    int     nResult         = 0;
    int     nTopIndex       = 0;
    DWORD   dwTemplateID    = ERROR_ID;
    int     nCount          = 0;

    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 (!g_IsDoodad(pObj))
            continue;

        assert(pObj->m_pTemplate);
        if (pObj->m_pTemplate->m_dwID != dwTemplateID)
            continue;
            
        ++nCount;
    }

    lua_pushinteger(L, nCount);

    nResult = 1;
Exit0:
    return nResult;
}
Exemplo n.º 30
0
int LuaGetMapInfo(Lua_State* L)
{
    int         nTopIndex   = 0;
    DWORD       dwMapID     = ERROR_ID;
    KMapInfo*   pMapInfo    = NULL;

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

    dwMapID = (DWORD)Lua_ValueToNumber(L, 1);

    pMapInfo = g_pSO3GameCenter->m_MapManager.GetMapInfo(dwMapID);
    KG_PROCESS_ERROR(pMapInfo);

Exit0:
    if (pMapInfo)
    {
        pMapInfo->LuaGetObj(L);
    }
    else
    {
        Lua_PushNil(L);
    }
    return 1;
}