int WGMapManager::initMapData()
{
	for (UINT i = 0; i < m_mapNodeCount; i++)
	{
		m_mapInfo[i].m_position.x = g_Random(MAP_X_MAX);
		m_mapInfo[i].m_position.y = g_Random(MAP_Y_MAX);
		m_mapInfo[i].m_position.z = g_Random(MAP_Z_MAX);
		m_mapNodes[i].createNode(&(m_mapInfo[i]));
	}

	return 0;
}
Beispiel #2
0
void KGold::ApplyTemplateCustomParam(KSceneObjectTemplate* pTemplate)
{
    assert(pTemplate);
    
    m_nVelocityX = pTemplate->m_nVXOnThrow - g_Random(pTemplate->m_nVXOnThrow/2);
    m_nVelocityY = pTemplate->m_nVYOnThrow - g_Random(pTemplate->m_nVYOnThrow/2);
    m_nVelocityZ = pTemplate->m_nVZOnThrow - g_Random(pTemplate->m_nVZOnThrow/2);
    if (g_Random(2) > 0)
        m_nVelocityX = -m_nVelocityX;
    if (g_Random(2) > 0)
        m_nVelocityY = -m_nVelocityY;
}
BOOL KChallengeMissionNpc::GetTwoRandomNpc(int nType, int nStep, int& nNPCID1, int& nNPCID2)
{
    BOOL    bResult = false;
    int     nRandomNum = 0;
    int     nValidNpcCount = 0;
    KChallengeMissionNpcData* pData = NULL;

    if (nType == emitPVE1ContinuousChallenge)
    {
        pData = m_Data1.GetByID(nStep);
        KGLOG_PROCESS_ERROR(pData);
    }
    else if (nType == emitPVE2ContinuousChallenge)
    {
        pData = m_Data2.GetByID(nStep);
        KGLOG_PROCESS_ERROR(pData);
    }
    else
    {
        pData = m_Data1.GetByID(nStep);
        KGLOG_PROCESS_ERROR(pData);
    }
    
    nValidNpcCount = pData->vecValidNpc.size();
    if (nValidNpcCount == 0)
    {
        nNPCID1 = 0;
        nNPCID2 = 0;
    }
    else if (nValidNpcCount == 1)
    {
        nNPCID1 = pData->vecValidNpc[0];
        nNPCID2 = 0;
    }
    else if (nValidNpcCount == 2)
    {
        nNPCID1 = pData->vecValidNpc[0];
        nNPCID2 = pData->vecValidNpc[1];
    }
    else
    {
        nRandomNum = g_Random(MILLION_NUM) % nValidNpcCount;
        nNPCID1 = pData->vecValidNpc[nRandomNum];

        nRandomNum = g_Random(MILLION_NUM) % nValidNpcCount;
        nNPCID2 = pData->vecValidNpc[nRandomNum];
    }
    
    bResult = true;
Exit0:
    return bResult;
}
/******************************************************************************
	功能:	生成随机装备
	入口:	nSeriesReq: 五行属性
			nLevel: 等级
			nLucky: 运气值
			nVersion: 版本号
	出口:	成功时返回非零, 相关数据在 pItem 所指对象中给出
			失败时返回零
******************************************************************************/
BOOL KItemGenerator::Gen_Item(IN int nItemGenre,
							  IN int nSeriesReq,
							  IN int nLevel,
							  IN int nLucky,
							  IN OUT KItem* pItem)
{
	_ASSERT(this != NULL);
	_ASSERT(pItem != NULL);

	switch (nItemGenre)
	{
	case item_equip:
		{
			int nDetailType, nParticularType, i;
			nDetailType = g_Random(equip_detailnum);
			nParticularType = g_Random(m_EquipNumOfEntries[nDetailType] + 1);
			int naryMALevel[6];
			ZeroMemory(naryMALevel, 6 * sizeof(int));
			for (i = 0; i < 6; i++)
			{
				naryMALevel[i] = g_Random(nLevel / 10 + 1);
				if (!naryMALevel[i])
					break;
			}
			Gen_Equipment(nDetailType, nParticularType, nSeriesReq, nLevel, naryMALevel, nLucky, g_SubWorldSet.GetGameVersion(), pItem);
		}
		break;
	case item_medicine:
		{
			int nDetailType;
			nDetailType = g_Random(medicine_detailnum);
			Gen_Medicine(nDetailType, nLevel, g_SubWorldSet.GetGameVersion(), pItem);
		}
		break;
	case item_task:
		{
			Gen_Quest(nSeriesReq, pItem);			
		}
		break;
	case item_townportal:
		{
			Gen_TownPortal(pItem);
		}
		break;
	default:
		break;
	}
	
	return TRUE;
}
WGMapManager::WGMapManager()
{
	m_mapNodeCount = MAP_NODE_MIN_COUNT + g_Random(MAP_NODE_MAX_COUNT - MAP_NODE_MIN_COUNT);
	m_mapNodes = new WGMapNodeBase[m_mapNodeCount];
	m_mapInfo = new MapNodeInfo[m_mapNodeCount];
 
}
Beispiel #6
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;
}
Beispiel #7
0
BOOL KAwardMgr::GetAwardItemValuePoint(KAWARD_ITEM* pAwardItem, int& nValuePoint)
{
	BOOL bResult  = false;
	BOOL bRetCode = false;
    KGItemInfo* pItemInfo = NULL;

	KGLOG_PROCESS_ERROR(pAwardItem);

    nValuePoint = 0;

    KG_PROCESS_SUCCESS(pAwardItem->dwTabType != ittEquip);

    if (pAwardItem->nQualityLevel != -1)
    {
        pItemInfo = g_pSO3World->m_ItemHouse.GetItemInfo(pAwardItem->dwTabType, pAwardItem->dwIndex);
        KGLOG_PROCESS_ERROR(pItemInfo);

        nValuePoint = g_pSO3World->m_ItemHouse.GetRandomValuePoint(pItemInfo->nLevel, pAwardItem->nQualityLevel);
    }
    else
    {
        int nDeltaValuePoint = pAwardItem->nMaxValuePoint - pAwardItem->nMinValuePoint;
        KGLOG_PROCESS_ERROR(nDeltaValuePoint >= 0);

        nValuePoint = pAwardItem->nMinValuePoint;
        if (nDeltaValuePoint > 0)
            nValuePoint += (int)g_Random(nDeltaValuePoint);
    }

Exit1:
	bResult = true;
Exit0:
	return bResult;
}
Beispiel #8
0
KAWARD_ITEM* KAwardTable::GetOneAwardItemByEqualRate()
{
    KAWARD_ITEM*    pResult = NULL;
    unsigned        uCount  = 0U;
    unsigned        uIndex  = 0U;
    unsigned        i       = 0U;
    std::vector<DWORD> vecCanRandomItem;
    KAWARD_ITEM_MAP::iterator it;

    for (it = m_mapAwardItem.begin(); it != m_mapAwardItem.end(); ++it)
    {
        vecCanRandomItem.push_back(it->first);
    }

    uCount = vecCanRandomItem.size();
    KG_PROCESS_ERROR(uCount > 0);

    uIndex = g_Random(KILO_NUM) % uCount;
    it = m_mapAwardItem.find(vecCanRandomItem[uIndex]);
    KGLOG_PROCESS_ERROR(it != m_mapAwardItem.end());

    pResult = &it->second;
Exit0:
    return pResult;
}
BOOL KAIManager::GetRandomAIType(DWORD dwAIGroupID, int nAILevel, int& nAIType)
{
	BOOL    bResult     = false;
	BOOL    bRetCode    = false;	
    size_t  uIndex      = 0;
    int     nMaxAILevel = 0;
    uint64_t uKey       = 0;
    KAI_LEVEL_TABLE::iterator it;

    nMaxAILevel = GetMaxAILevel();
    KGLOG_PROCESS_ERROR(nMaxAILevel > 0);

    MakeInRange(nAILevel, 1, nMaxAILevel);

    uKey = MAKE_INT64(dwAIGroupID, nAILevel);

    it = m_AILevelTable.find(uKey);
    if (it == m_AILevelTable.end())
    {
        uKey = MAKE_INT64(DEFAULT_AI_GROUP_ID, nAILevel);
        it = m_AILevelTable.find(uKey);   
    }   
    KGLOG_PROCESS_ERROR(it != m_AILevelTable.end());

    KGLOG_PROCESS_ERROR(it->second.size());

    uIndex = g_Random(it->second.size());
    nAIType = it->second[uIndex];

	bResult = true;
Exit0:
	return bResult;
}
int KMovableObject::CalcProcessTrackMoveZmax(int nRandomSeed, const KPOSITION& StartPos, const KPOSITION& FinalPos) const
{
    int nDistanceXY         = 0;
    int nDistanceZ          = 0;
    int nOffsetX            = 0;
    int nOffsetY            = 0;
    int nTempRandomNum      = 0;
    int nSaveRandomSeed     = 0;
    int nZmax               = 0;

    nOffsetX = abs(StartPos.nX - FinalPos.nX);
    nOffsetY = abs(StartPos.nY - FinalPos.nY);
    nDistanceXY = (int)sqrt((double)(nOffsetX * nOffsetX + nOffsetY * nOffsetY));

    nDistanceZ  = abs(StartPos.nZ - FinalPos.nZ);

    nSaveRandomSeed = g_GetRandomSeed();
    g_RandomSeed(nRandomSeed);
    //KGLogPrintf(KGLOG_INFO, "seed = %d  DistanceXY = %d DistanceZ = %d OffsetX = %d OffsetY = %d\n", nRandomSeed, nDistanceXY, nDistanceZ, nOffsetX, nOffsetY);
    nTempRandomNum = g_Random(160) + 160;
    g_RandomSeed(nSaveRandomSeed);

    nZmax = nDistanceXY / 640 + nDistanceZ / 320 + nTempRandomNum;

    MakeInRange<int>(nZmax, 240, 600);

    nZmax += MAX(StartPos.nZ, FinalPos.nZ);

    //KGLogPrintf(KGLOG_INFO, "nZmax = %d, temprandom:%d\n", nZmax, nTempRandomNum);
Exit0:
    return nZmax;
}
Beispiel #11
0
DWORD KMoneyDropList::GetRandomMoney()
{
	int nResult = 0;

	int nMoneyRate = m_dwMaxMoney - m_dwMinMoney + 1;

	nResult = g_Random(nMoneyRate);
	nResult += m_dwMinMoney;
	
	return nResult;
}
Beispiel #12
0
BOOL KMoneyDropList::IsDropInRandom()
{
	BOOL bResult = false;

	int nRate = g_Random(MILLION_NUM);

	if (nRate <= (int)m_dwMoneyDropRate)
	{
		bResult = true;
	}

	return bResult;
}
Beispiel #13
0
KAWARD_ITEM* KAwardTable::GetRandomAward()
{
    KAWARD_ITEM* pResult = NULL;
    int nRandomNum = g_Random(1000000);
    KAWARD_ITEM_RATE_MAP::iterator itUpper;
    KAWARD_ITEM_MAP::iterator it;

    itUpper = m_mapAwardItemRate.upper_bound(nRandomNum);
    KG_PROCESS_ERROR(itUpper != m_mapAwardItemRate.end());

    it = m_mapAwardItem.find(itUpper->second);
    KGLOG_PROCESS_ERROR(it != m_mapAwardItem.end());

    pResult = &it->second;
Exit0:
    return pResult;
}
Beispiel #14
0
//-------------------------------------------------------------------------
//	功能:	播放随机音效
//-------------------------------------------------------------------------
void	KObj::PlayRandSound()
{
	if (!m_szSoundName[0])
		return;

	if (g_Random(500) != 0)
		return;

	m_pSoundNode = (KCacheNode*) g_SoundCache.GetNode(m_szSoundName, (KCacheNode * )m_pSoundNode);
	m_pWave = (KWavSound*)m_pSoundNode->m_lpData;
	if (m_pWave)
	{
		if (m_pWave->IsPlaying())
			return;
		m_pWave->Play(GetSoundPan(), GetSoundVolume(), 0);
	}
}
Beispiel #15
0
BOOL KSkillList::AddSkillExp(DWORD dwSkillID, DWORD dwExp)
{
    BOOL                bResult         = false;
    BOOL                bRetCode        = false;
    int                 nOdds           = 0;
    DWORD               dwSkillExp      = 0;
	KSkill*             pSkill          = NULL;
    const KPlayerSkill* cpPlayerSkill   = NULL;
    PLAYER_SKILL_LIST::const_iterator cit;
    
    cit = m_PlayerSkillList.find(dwSkillID);
	KG_PROCESS_ERROR(cit != m_PlayerSkillList.end());
    cpPlayerSkill = &cit->second;

	pSkill = g_pSO3World->m_SkillManager.GetSkill_RAW(dwSkillID, cit->second.dwLevel);
	KG_PROCESS_ERROR(pSkill);
	KG_PROCESS_ERROR(pSkill->m_dwLevelUpExp);

    nOdds = (int)g_Random(KILO_NUM);
    KG_PROCESS_SUCCESS(nOdds + pSkill->m_nExpAddOdds < KILO_NUM);

    dwSkillExp = cpPlayerSkill->dwExp + dwExp;

    MAKE_IN_RANGE(dwSkillExp, 0, pSkill->m_dwLevelUpExp);

    bRetCode = UpdateSkill(dwSkillID, cpPlayerSkill->dwLevel, dwSkillExp);

    if (CanRealizeSkill(dwSkillID))
    {
        LearnSkill(dwSkillID, true);
    }

Exit1:
    bResult = true;
Exit0:
	return bResult;
}
DWORD KQuestInfoList::GetRandomQuest(int nHeroLevel, int nRandomQuestIndex)
{
    DWORD dwResult = 0;
    KMAP_LEVEL2QUESTGROUP::iterator it;
    KQUEST_GROUP* pQuestGroup = NULL;
    int nLevel = (nHeroLevel - 1) / RANDOM_QUEST_LEVEL + 1;
    unsigned int nOldSeed = g_GetRandomSeed();
    unsigned int nRandSeed = nRandomQuestIndex + g_pSO3World->m_nBaseTime;
    unsigned int nRandomQuest = 0;

    it = m_RandomQuestGroup.find(nLevel);
    KG_PROCESS_ERROR(it != m_RandomQuestGroup.end());

    pQuestGroup = &it->second;
    KGLOG_PROCESS_ERROR(pQuestGroup->size() > 0);

    g_RandomSeed(nRandSeed);
    nRandomQuest = g_Random(pQuestGroup->size());
    g_RandomSeed(nOldSeed);

    dwResult = pQuestGroup->at(nRandomQuest);
Exit0:
    return dwResult;
}
Beispiel #17
0
BOOL KItemLib::GenerateItem(KItem* pItem,
                            DWORD dwTabType,
                            DWORD dwIndex,
                            DWORD dwId/* = 0*/,
                            DWORD dwRandSeed/* = 0 */,
                            int nMagicNum/* = 0 */,
                            int nQuality/* = 0 */,
                            int nMagic[]/* = NULL */,
                            time_t nGenTime/* = 0*/)
{
    BOOL bResult = FALSE;
    BOOL bRetCode = FALSE;
    DWORD dwOldRandSeed = 0;
    KGLOG_PROCESS_ERROR(dwTabType > ittInvalid && dwTabType < ittTotal);

    if (!nQuality)
    {
        nQuality = GenerateQuality(dwTabType, dwIndex);
    }

    if (!nGenTime)
    {
        nGenTime = time(NULL);
    }

    pItem->m_GenParam.nVersion = m_nVerion;
    pItem->m_GenParam.dwTabType = dwTabType;
    pItem->m_GenParam.dwIndex = dwIndex;

    pItem->m_GenParam.nGenTime = nGenTime;

    if (dwRandSeed)
    {
        dwOldRandSeed = g_GetRandomSeed();
    }
    else
    {
        // 改变随机种子,保证反复调用生成道具具有不一致性
        g_Random(128);
    }

    switch (dwTabType)
    {
    case ittWeapon:
        bRetCode = GenerateRandItem(
                       pItem, m_Weapon.GetItemInfo(dwIndex), nMagicNum, nQuality,
                       dwRandSeed, nMagic);
        KG_PROCESS_ERROR(bRetCode);
        break;
    case ittArmor:
        bRetCode = GenerateRandItem(
                       pItem, m_Armor.GetItemInfo(dwIndex), nMagicNum, nQuality,
                       dwRandSeed, nMagic);
        KG_PROCESS_ERROR(bRetCode);
    case ittTrinket:
        bRetCode = GenerateRandItem(
                       pItem, m_Trinket.GetItemInfo(dwIndex), nMagicNum, nQuality,
                       dwRandSeed, nMagic);
        KG_PROCESS_ERROR(bRetCode);
        break;
    case ittOther:
        bRetCode = GenerateCommonItem(
                       pItem, m_Other.GetItemInfo(dwIndex), dwRandSeed);
        KG_PROCESS_ERROR(bRetCode);
        break;
    case ittCustWeapon:
        bRetCode = GenerateCustomItem(
                       pItem, m_CustomWeapon.GetItemInfo(dwIndex), dwRandSeed);
        KG_PROCESS_ERROR(bRetCode);
        break;
    case ittCustArmor:
        bRetCode = GenerateCustomItem(
                       pItem, m_CustomArmor.GetItemInfo(dwIndex), dwRandSeed);
        KG_PROCESS_ERROR(bRetCode);
        break;
    case ittCustTrinket:
        bRetCode = GenerateCustomItem(
                       pItem, m_CustomTrinket.GetItemInfo(dwIndex), dwRandSeed);
        KG_PROCESS_ERROR(bRetCode);
        break;
    default:
        KG_PROCESS_ERROR(0);
        break;
    }
    bResult = TRUE;

    if (!pItem->m_dwScriptID && !pItem->m_dwSkillID)
    {
        pItem->m_eUseType = uistCannotUse;
    }
    else
    {
        if (pItem->m_Common.nGenre == igEquipment)
            pItem->m_eUseType = uistUseWhenEquipped;
        else
            pItem->m_eUseType = uistUseInPackage;
    }
Exit0:
    if (dwOldRandSeed)
    {
        g_RandomSeed(dwOldRandSeed);
    }
    return bResult;
}
Beispiel #18
0
//-------------------------------------------------------------------------
//	功能:	各种物件的处理
//-------------------------------------------------------------------------
void	KObj::Activate()
{
	if ( m_nIndex <= 0 )
		return;

#ifdef _SERVER
	int		nEnemyIndex, x, y;
#else
	int		nMask = IPOT_RL_OBJECT | IPOT_RL_INFRONTOF_ALL;
#endif

	switch(m_nKind)
	{
#ifndef _SERVER
	case Obj_Kind_MapObj:					// 地图物件动画
		if (m_nState == 0)					// 地图物件动画循环播放
			m_cImage.GetNextFrame();
		nMask = IPOT_RL_OBJECT | IPOT_RL_INFRONTOF_ALL;
		break;
	case Obj_Kind_Light:					// 光源
		if (m_nState == 0)
			m_cImage.GetNextFrame();
		nMask = IPOT_RL_OBJECT | IPOT_RL_INFRONTOF_ALL;
		break;
	case Obj_Kind_LoopSound:				// 循环音效
		PlayLoopSound();
		break;
	case Obj_Kind_RandSound:				// 随机音效
		PlayRandSound();
		break;
	case Obj_Kind_Body:						// 尸体逐渐消失
		m_cImage.GetNextFrame(FALSE);		// 尸体动画单方向播放
		m_nLifeTime--;
		if (m_nLifeTime <= 0)
			Remove(FALSE);
		nMask = IPOT_RL_COVER_GROUND | IPOT_RL_INFRONTOF_ALL;
		break;
#endif
	case Obj_Kind_Box:						// 宝箱
#ifdef _SERVER
		if (m_nState == OBJ_BOX_STATE_OPEN)	// 宝箱关闭重生
		{
			m_nBornTime--;
			if (m_nBornTime <= 0)
				SetState(OBJ_BOX_STATE_CLOSE);
		}
#else
		if (m_nState == OBJ_BOX_STATE_CLOSE)// 宝箱关闭状态
			m_cImage.GetPrevFrame(FALSE);
		else// if (m_nState == OBJ_BOX_STATE_OPEN)// 宝箱打开状态
			m_cImage.GetNextFrame(FALSE);
		nMask = IPOT_RL_OBJECT | IPOT_RL_INFRONTOF_ALL;
#endif
		break;
	case Obj_Kind_Door:						// 门
#ifdef _SERVER
#else
		if (m_nState == OBJ_DOOR_STATE_CLOSE)// 门关闭状态
			m_cImage.GetPrevFrame(FALSE);
		else// if (m_nState == OBJ_DOOR_STATE_OPEN)// 门打开状态
			m_cImage.GetNextFrame(FALSE);
		nMask = IPOT_RL_OBJECT | IPOT_RL_INFRONTOF_ALL;
#endif
		break;
	case Obj_Kind_Item:						// 装备动画循环播放
#ifdef _SERVER
		if (m_nBelong >= 0)
		{
			m_nBelongTime--;
			if (m_nBelongTime <= 0)
			{
				m_nBelongTime = 0;
				m_nBelong = -1;
			}
		}
		m_nLifeTime--;
		if (m_nLifeTime <= 0)
			Remove(FALSE);
#else
		if (this->m_nDropState == 1)		// 物品掉出动画
		{
			if (m_cImageDrop.GetNextFrame(FALSE))
			{
				if (m_cImageDrop.CheckEnd())
				{
					m_nDropState = 0;			// 物品掉出动画播放完了,改为放置循环动画
					m_Image.uImage = 0;
				}
			}
			nMask = IPOT_RL_OBJECT | IPOT_RL_INFRONTOF_ALL;
		}
		else
		{
			if (this->m_nDropState == 2)
			{
				if (m_cImage.GetNextFrame(FALSE))
				{
					if (m_cImage.CheckEnd())
						this->m_nDropState = 0;
				}
			}
			else
			{
				if (g_Random(40) == 0)
				{
					m_nDropState = 2;
				}
				else
				{
					m_cImage.SetDirStart();
				}
			}
			nMask = IPOT_RL_COVER_GROUND | IPOT_RL_INFRONTOF_ALL;
		}
		m_nLifeTime--;
		if (m_nLifeTime <= -100)
			Remove(FALSE);
#endif
		break;
	case Obj_Kind_Money:
#ifdef _SERVER
		if (m_nBelong >= 0)
		{
			m_nBelongTime--;
			if (m_nBelongTime <= 0)
			{
				m_nBelongTime = 0;
				m_nBelong = -1;
			}
		}
		m_nLifeTime--;
		if (m_nLifeTime <= 0)
			Remove(FALSE);
#else
		m_cImage.GetNextFrame();
		nMask = IPOT_RL_COVER_GROUND | IPOT_RL_INFRONTOF_ALL;
		m_nLifeTime--;
		if (m_nLifeTime <= -100)
			Remove(FALSE);
#endif
		break;
	case Obj_Kind_Prop:
#ifdef _SERVER
		if (m_nState == OBJ_PROP_STATE_HIDE)	// 道具隐藏状态
		{
			m_nBornTime--;
			if (m_nBornTime <= 0)
				SetState(OBJ_PROP_STATE_DISPLAY);// 道具重生
		}
#else
		if (m_nState == OBJ_PROP_STATE_DISPLAY)
		{
			m_cImage.GetNextFrame();
			nMask = IPOT_RL_OBJECT | IPOT_RL_INFRONTOF_ALL;
		}
#endif
		break;
/*
	case Obj_Kind_Trap:
		switch (m_cSkill.m_nKind)
		{
		case ObjTrap_Kind_Cycle_Image_Static:
			if (m_nState == OBJ_TRAP_STATE_STOP)
			{
				if (m_nWaitTime > 0)
				{
					m_nWaitTime--;
					if (m_nWaitTime <= 0)
					{
						m_nWaitTime = 0;
						SetState(OBJ_TRAP_STATE_ACTIVE);
					}
				}
#ifdef _SERVER
				m_cImage.SetDirStart();
#else
				m_cImage.SetDirStart();
#endif
			}
			else// if (m_nState == OBJ_TRAP_STATE_ACTIVE)
			{
#ifdef _SERVER
				// 朝自身位置发射技能
//				if (m_cImage.GetCurDirFrameNo() == m_cSkill.m_nCastTime)
//					Skill[][].cast()
				m_cImage.GetNextFrame();
#else
				// 朝自身位置发射技能
//				if (m_cImage.GetCurDirFrameNo() == m_cSkill.m_nCastTime)
//					Skill[][].cast()
				m_cImage.GetNextFrame();
#endif
			}
			break;
		case ObjTrap_Kind_Cycle_Image_Dir:
			if (m_nState == OBJ_TRAP_STATE_STOP)
			{
				if (m_nWaitTime > 0)
				{
					m_nWaitTime--;
					if (m_nWaitTime <= 0)
					{
						m_nWaitTime = 0;
						SetState(OBJ_TRAP_STATE_ACTIVE);
					}
				}
#ifdef _SERVER
				m_cImage.SetDirStart();
#else
				m_cImage.SetDirStart();
#endif
			}
			else// if (m_nState == OBJ_TRAP_STATE_ACTIVE)
			{
#ifdef _SERVER
				// 朝固定方向发射技能
//				if (m_cImage.GetCurDirFrameNo() == m_cSkill.m_nCastTime)
//					Skill[][].cast()
				m_cImage.GetNextFrame();
#else
				// 朝固定方向发射技能
//				if (m_cImage.GetCurDirFrameNo() == m_cSkill.m_nCastTime)
//					Skill[][].cast()
				m_cImage.GetNextFrame();
#endif
			}
			break;
		case ObjTrap_Kind_Auto_Image_Static:
			if (m_nState == OBJ_TRAP_STATE_STOP)
				break;
#ifdef _SERVER
			if (m_nState == OBJ_TRAP_STATE_ACTIVE)
			{
				nEnemyIndex = FindEnemy();
				if (nEnemyIndex > 0)
				{
					Npc[nEnemyIndex].GetMpsPos(&x, &y);
					m_cSkill.m_nTarX = x;
					m_cSkill.m_nTarY = y;
					m_nState = OBJ_TRAP_STATE_ACTING;
					m_cImage.SetDirStart();
					// 通知客户端
					TrapAct();
				}
			}
			else if (m_nState == OBJ_TRAP_STATE_ACTING)
			{
				// 朝固定位置发射技能
//				if (m_cImage.m_nCurFrame == m_cSkill.m_nCastTime)
//					Skill[][].cast
				m_cImage.GetNextFrame(FALSE);
				if (m_cImage.CheckEnd())
				{
					m_nState = OBJ_TRAP_STATE_ACTIVE;
					m_cImage.SetDirStart();
				}
			}
#else
			if (m_nState == OBJ_TRAP_STATE_ACTING)
			{
				// 朝自身位置发射技能
//				if (m_cImage.GetCurDirFrameNo() == m_cSkill.m_nCastTime)
//					Skill[][].cast()
				m_cImage.GetNextFrame(FALSE);
				if (m_cImage.CheckEnd())
				{
					m_nState = OBJ_TRAP_STATE_ACTIVE;
					m_cImage.SetDirStart();
				}
			}
#endif
			break;
		case ObjTrap_Kind_Auto_Image_Dir:
			if (m_nState == OBJ_TRAP_STATE_STOP)
				break;
#ifdef _SERVER
			if (m_nState == OBJ_TRAP_STATE_ACTIVE)
			{
				nEnemyIndex = FindEnemy();
				if (nEnemyIndex > 0)
				{
					Npc[nEnemyIndex].GetMpsPos(&x, &y);
					m_cSkill.m_nTarX = x;
					m_cSkill.m_nTarY = y;
					m_nState = OBJ_TRAP_STATE_ACTING;
					m_cImage.SetDirStart();
					// 通知客户端
					TrapAct();
				}
			}
			else if (m_nState == OBJ_TRAP_STATE_ACTING)
			{
				// 朝固定方向发射技能
//				if (m_cImage.m_nCurFrame == m_cSkill.m_nCastTime)
//					Skill[][].cast
				m_cImage.GetNextFrame(FALSE);
				if (m_cImage.CheckEnd())
				{
					m_nState = OBJ_TRAP_STATE_ACTIVE;
					m_cImage.SetDirStart();
				}
			}
#else
			if (m_nState == OBJ_TRAP_STATE_ACTING)
			{
				// 朝固定方向发射技能
//				if (m_cImage.GetCurDirFrameNo() == m_cSkill.m_nCastTime)
//					Skill[][].cast()
				m_cImage.GetNextFrame(FALSE);
				if (m_cImage.CheckEnd())
				{
					m_nState = OBJ_TRAP_STATE_ACTIVE;
					m_cImage.SetDirStart();
				}
			}
#endif
			break;
		case ObjTrap_Kind_Auto_Image_Target:
			if (m_nState == OBJ_TRAP_STATE_STOP)
				break;
#ifdef _SERVER
			if (m_nState == OBJ_TRAP_STATE_ACTIVE)
			{
				nEnemyIndex = FindEnemy();
				if (nEnemyIndex > 0)
				{
					Npc[nEnemyIndex].GetMpsPos(&x, &y);
					m_cSkill.m_nTarX = x;
					m_cSkill.m_nTarY = y;
					m_nState = OBJ_TRAP_STATE_ACTING;
					m_cImage.SetDirStart();
					// 通知客户端
					TrapAct();
				}
			}
			else if (m_nState == OBJ_TRAP_STATE_ACTING)
			{
				// 朝目标点发射技能
//				if (m_cImage.m_nCurFrame == m_cSkill.m_nCastTime)
//					Skill[][].cast
				m_cImage.GetNextFrame(FALSE);
				if (m_cImage.CheckEnd())
				{
					m_nState = OBJ_TRAP_STATE_ACTIVE;
					m_cImage.SetDirStart();
				}
			}
#else
			if (m_nState == OBJ_TRAP_STATE_ACTING)
			{
				// 朝目标点发射技能
//				if (m_cImage.GetCurDirFrameNo() == m_cSkill.m_nCastTime)
//					Skill[][].cast()
				m_cImage.GetNextFrame(FALSE);
				if (m_cImage.CheckEnd())
				{
					m_nState = OBJ_TRAP_STATE_ACTIVE;
					m_cImage.SetDirStart();
				}
			}
#endif
			break;
		case ObjTrap_Kind_Auto_Delay_Static:
			if (m_nState == OBJ_TRAP_STATE_STOP)
				break;
#ifdef _SERVER
			if (m_nState == OBJ_TRAP_STATE_ACTIVE)
			{
				if (m_nWaitTime > 0)
				{
					m_nWaitTime--;
				}
				else
				{
					nEnemyIndex = FindEnemy();
					if (nEnemyIndex > 0)
					{
						Npc[nEnemyIndex].GetMpsPos(&x, &y);
						m_cSkill.m_nTarX = x;
						m_cSkill.m_nTarY = y;
						m_nState = OBJ_TRAP_STATE_ACTING;
						// 通知客户端
						TrapAct();
						// 朝自身位置发射技能
						//Skill[][].cast();
						m_nState = OBJ_TRAP_STATE_ACTIVE;
						m_nWaitTime = m_cSkill.m_nCastTime;
					}
				}
			}
#else
			if (m_nState == OBJ_TRAP_STATE_ACTING)
			{
				// 朝自身位置发射技能
//				Skill[][].cast()
				m_nState = OBJ_TRAP_STATE_ACTIVE;
			}
			m_cImage.GetNextFrame();
#endif
			break;
		case ObjTrap_Kind_Auto_Delay_Dir:
			if (m_nState == OBJ_TRAP_STATE_STOP)
				break;
#ifdef _SERVER
			if (m_nState == OBJ_TRAP_STATE_ACTIVE)
			{
				if (m_nWaitTime > 0)
				{
					m_nWaitTime--;
				}
				else
				{
					nEnemyIndex = FindEnemy();
					if (nEnemyIndex > 0)
					{
						Npc[nEnemyIndex].GetMpsPos(&x, &y);
						m_cSkill.m_nTarX = x;
						m_cSkill.m_nTarY = y;
						m_nState = OBJ_TRAP_STATE_ACTING;
						// 通知客户端
						TrapAct();
						// 朝固定方向发射技能
						//Skill[][].cast();
						m_nState = OBJ_TRAP_STATE_ACTIVE;
						m_nWaitTime = m_cSkill.m_nCastTime;
					}
				}
			}
#else
			if (m_nState == OBJ_TRAP_STATE_ACTING)
			{
				// 朝固定方向发射技能
//				Skill[][].cast()
				m_nState = OBJ_TRAP_STATE_ACTIVE;
			}
			m_cImage.GetNextFrame();
#endif
			break;
		case ObjTrap_Kind_Auto_Delay_Target:
			if (m_nState == OBJ_TRAP_STATE_STOP)
				break;
#ifdef _SERVER
			if (m_nState == OBJ_TRAP_STATE_ACTIVE)
			{
				if (m_nWaitTime > 0)
				{
					m_nWaitTime--;
				}
				else
				{
					nEnemyIndex = FindEnemy();
					if (nEnemyIndex > 0)
					{
						Npc[nEnemyIndex].GetMpsPos(&x, &y);
						m_cSkill.m_nTarX = x;
						m_cSkill.m_nTarY = y;
						m_nState = OBJ_TRAP_STATE_ACTING;
						// 通知客户端
						TrapAct();
						// 朝目标点发射技能
						//Skill[][].cast();
						m_nState = OBJ_TRAP_STATE_ACTIVE;
						m_nWaitTime = m_cSkill.m_nCastTime;
					}
				}
			}
#else
			if (m_nState == OBJ_TRAP_STATE_ACTING)
			{
				// 朝目标点发射技能
//				Skill[][].cast()
				m_nState = OBJ_TRAP_STATE_ACTIVE;
			}
			m_cImage.GetNextFrame();
#endif
			break;
		}
		break;
*/
	}
#ifndef _SERVER
	int nMpsX, nMpsY;
	SubWorld[m_nSubWorldID].Map2Mps(m_nRegionIdx, m_nMapX, m_nMapY, m_nOffX, m_nOffY, &nMpsX, &nMpsY);
	g_ScenePlace.MoveObject(CGOG_OBJECT, m_nIndex, nMpsX, nMpsY, 0, m_SceneID, nMask);
#endif
}
Beispiel #19
0
SKILL_RESULT_CODE KLootList::LootOrRollItem(KPlayer* pLooter, DWORD dwDoodadID, DWORD dwItemID, BOOL bCancel)
{
    SKILL_RESULT_CODE nResult = srcFailed;
    BOOL bRetCode = FALSE;
    BOOL bResult = FALSE;
    int nRandom = -1;

    KGLOG_PROCESS_ERROR(pLooter);

    KDoodad *pDoodad = g_ObjectManager.m_DoodadSet.GetObj(dwDoodadID);
    KGLOG_PROCESS_ERROR(pDoodad);

    //在表中找到指定的物品
    int nItemIndex = 0;
    for (; nItemIndex < MAX_LOOT_SIZE; nItemIndex++)
    {
        if (m_LootList[nItemIndex].pItem == NULL)
            continue;
        if (m_LootList[nItemIndex].pItem->m_dwID == dwItemID)
            break;
    }
    KG_PROCESS_ERROR_RET_CODE(nItemIndex < MAX_LOOT_SIZE, srcNotExistLootItem);

    bResult = CanLoot(nItemIndex, pLooter);
    if (bResult)
    {
        //拾取
        bRetCode = pLooter->m_ItemList.AddItem(m_LootList[nItemIndex].pItem);
        KG_PROCESS_ERROR_RET_CODE(bRetCode, srcAddLootItemFailed);

        m_LootList[nItemIndex].pItem = NULL;
        m_nLootedCount++;

        bRetCode = g_PlayerServer.DoRollItemMessage(pLooter, dwDoodadID, dwItemID, TRUE, nRandom);
        KGLOG_CHECK_ERROR(bRetCode);

        return srcSuccess;
    }

    bResult = CanRoll(nItemIndex, pLooter, TRUE);
    if (bResult)
    {
        for (int nOwnerIndex = 0; nOwnerIndex < m_nLooterCount; nOwnerIndex++)
        {
            if (m_pLooterList[nOwnerIndex] != pLooter)
                continue;

            //投一个100面的骰子
            if (!bCancel)
            {
                nRandom = g_Random(ROLL_ITEM_NUMBER) + 1;
                if (nRandom > m_LootList[nItemIndex].nRandom)
                {
                    //掷赢了,则更改胜利者
                    m_LootList[nItemIndex].pWinner = m_pLooterList[nOwnerIndex];
                    m_LootList[nItemIndex].nRandom = nRandom;
                }
                else if (nRandom == m_LootList[nItemIndex].nRandom)
                {
                    //平局,自动再掷一次
                    int nRoll = g_Random(2);
                    if (nRoll == 0)
                    {
                        m_LootList[nItemIndex].pWinner = m_pLooterList[nOwnerIndex];
                        m_LootList[nItemIndex].nRandom = nRandom;
                    }
                }
            }

            //取消掷骰子的权利
            m_LootList[nItemIndex].dwFlag[nOwnerIndex] = 1;
            m_LootList[nItemIndex].nRollCount--;

            //如果所有人都掷过了,那么自动放到胜利者的背包中
            KPlayer* pWinner = m_LootList[nItemIndex].pWinner;


            //同步LootList
            for (int nOwnIndex = 0; nOwnIndex < m_nLooterCount; nOwnIndex++)
            {
                bRetCode = g_PlayerServer.DoSyncLootList(m_pLooterList[nOwnIndex], m_pDoodad);
                KGLOG_CHECK_ERROR(bRetCode);
            }

            if (m_LootList[nItemIndex].nRollCount == 0 && pWinner)
            {
                bRetCode = pWinner->m_ItemList.AddItem(m_LootList[nItemIndex].pItem);
                KG_PROCESS_ERROR_RET_CODE(bRetCode, srcAddLootItemFailed);

                m_LootList[nItemIndex].pItem = NULL;
                m_nLootedCount++;

                bRetCode = g_PlayerServer.DoRollItemMessage(pWinner, dwDoodadID, dwItemID,
                           TRUE, nRandom);
                KGLOG_CHECK_ERROR(bRetCode);
            }
            else
            {
                bRetCode = g_PlayerServer.DoRollItemMessage(pLooter, dwDoodadID, dwItemID,
                           FALSE, nRandom);
                KGLOG_CHECK_ERROR(bRetCode);
            }
        }
        return srcSuccess;
    }
Exit0:
    //这里同步是因为有可能有玩家部分拾取了某个可叠加的物品
    bRetCode = g_PlayerServer.DoRollItemMessage(pLooter, dwDoodadID, dwItemID, FALSE, -2);
    KGLOG_CHECK_ERROR(bRetCode);

    return nResult;
}
Beispiel #20
0
KItem* KDropList::GetRandomItem(DROP_DATA& DropData)
{
	int		nHead		= 0;
	int		nRear		= m_dwSize;
	int		nMid		= 0;
	BOOL	bFound		= false;
	int		nDropRate	= 0;
	DWORD	dwItemTab	= 0;
	DWORD	dwItemIndex = 0;
	int		nCount		= 0;
	KItem*	pItem		= NULL;

	nDropRate = g_Random(MILLION_NUM);
	KG_PROCESS_ERROR(nDropRate <= m_ItemList[nRear].nDropRate);
	
	while (!bFound)
	{
		if (nHead + 1 == nRear)
			bFound = true;
		else
		{
			nMid = (nHead + nRear) / 2;
			if (m_ItemList[nMid].nDropRate < nDropRate)
			{
				nHead = nMid;
			}
			else if (m_ItemList[nMid].nDropRate > nDropRate)
			{
				nRear = nMid;
			}
			else
			{
				nRear = nMid;
				bFound = true;
			}
		}
	}

	dwItemTab = m_ItemList[nRear].dwTabType;
	dwItemIndex = m_ItemList[nRear].dwItemIndex;
	DropData = m_ItemList[nRear];

	if (m_ItemList[nRear].dwMin == 0 && m_ItemList[nRear].dwMax == 0)
	{
		//不能叠加的物品
		nCount = 0;
	}
	else
	{
		DWORD dwMin = m_ItemList[nRear].dwMin;
		DWORD dwMax = m_ItemList[nRear].dwMax;

		nCount = g_Random(dwMax - dwMin + 1);
		nCount += dwMin;
	}

	pItem = g_pSO3World->GenerateItem(dwItemTab, dwItemIndex);
	KGLOG_PROCESS_ERROR(pItem);

	if (pItem->m_Common.nGenre == igBook)
	{
		pItem->m_nCurrentDurability = nCount;
	}
	else if (nCount > 0)
	{
		if (pItem->IsStackable())
		{
			pItem->SetStackNum(nCount);
		}
	}

	return pItem;
Exit0:
	if (pItem)
	{
		g_pSO3World->m_ItemManager.FreeItem(pItem);
		pItem = NULL;
	}
	return NULL;
}
Beispiel #21
0
// 填好装备的生成参数,生成装备
BOOL KItemLib::ExpandCustomItemAttrib(KItem* pItem, KCustomEquipInfo* pInfo)
{
    BOOL bResult = FALSE;
    KAttribInfo* pAttr = NULL;

    KGLOG_PROCESS_ERROR(pItem);
    KGLOG_PROCESS_ERROR(pInfo);

    pItem->m_Common.nBindType = pInfo->nBindType;

    pItem->m_Common.nGenre = pInfo->nGenre;
    pItem->m_Common.nSub = pInfo->nSub;
    pItem->m_Common.nDetail = pInfo->nDetail;
    pItem->m_Common.nLevel = pInfo->nLevel;
    pItem->m_Common.nPrice = pInfo->nPrice;
    pItem->m_nRepresentId = pInfo->nRepresentId;
    pItem->m_nMaxDurability = pInfo->nMaxDurability;
    pItem->m_nCurrentDurability = pInfo->nMaxDurability;
    pItem->m_Common.bCanTrade = pInfo->bCanTrade;
    pItem->m_Common.bCanDestory = pInfo->bCanDestory;
    pItem->m_Common.nAbradeRate = pInfo->nAbradeRate;
    if (pInfo->nSub != estArrow)	//暗器可叠加
        pItem->m_Common.bStack = FALSE;
    else
        pItem->m_Common.bStack = TRUE;
    pItem->m_Common.bConsumeDurabiltity = FALSE;
    pItem->m_dwScriptID = pInfo->dwScriptID;
    strcpy(pItem->m_Common.szItemName, pInfo->szName);
#ifdef _CLIENT
    pItem->m_nUiId = pInfo->nUiId;
#endif


    // 展开道具基本属性
    KAttribute* pTailAttr = NULL;

    for (int i = 0; i < MAX_ITEM_BASE_COUNT; i++)
    {
        if (pInfo->BaseAttrib[i].nAttribID > 0)
        {
            KAttribute* pAttrib = g_ObjectManager.m_AttributeSet.New();
            KGLOG_PROCESS_ERROR(pAttrib);
            pAttrib->pNext = NULL;

            if (pTailAttr)
            {
                pTailAttr->pNext = pAttrib;
                pTailAttr = pAttrib;
            }
            else
            {
                ASSERT(NULL == pItem->m_pBaseAttr);
                pItem->m_pBaseAttr = pAttrib;
                pTailAttr = pAttrib;
            }

            pAttrib->nKey = pInfo->BaseAttrib[i].nAttribID;
            pAttrib->nValue1 = pInfo->BaseAttrib[i].nMin +
                               g_Random(pInfo->BaseAttrib[i].nMax - pInfo->BaseAttrib[i].nMin);
            // 道具基本属性第二参数无效。
            pAttrib->nValue2 = 0;
        }
        else
        {
            break;
        }
    }

    pTailAttr = NULL;

    for (int i = 0; i < MAX_ITEM_REQUIRE_COUNT; i++)
    {
        if (pInfo->RequireAttrib[i].nAttribID > 0)
        {
            KAttribute* pAttrib = g_ObjectManager.m_AttributeSet.New();
            KGLOG_PROCESS_ERROR(pAttrib);
            pAttrib->pNext = NULL;

            if (pTailAttr)
            {
                pTailAttr->pNext = pAttrib;
                pTailAttr = pAttrib;
            }
            else
            {
                ASSERT(NULL == pItem->m_pRequireAttr);
                pItem->m_pRequireAttr = pAttrib;
                pTailAttr = pAttrib;
            }
            pAttrib->nKey = pInfo->RequireAttrib[i].nAttribID;
            pAttrib->nValue1 = pInfo->RequireAttrib[i].nValue;
            pAttrib->nValue2 = 0;
        }
        else
        {
            break;
        }
    }

    pTailAttr = NULL;

    for (int i = 0; i < MAX_ITEM_MAGIC_COUNT; i++)
    {
        if (pItem->m_GenParam.nMagicIndex[i] > 0)
        {
            pAttr =	m_Attrib.GetItemInfo(pItem->m_GenParam.nMagicIndex[i]);
            KGLOG_PROCESS_ERROR(pAttr);

            KAttribute* pAttrib = g_ObjectManager.m_AttributeSet.New();
            KGLOG_PROCESS_ERROR(pAttrib);
            pAttrib->pNext = NULL;

            if (pTailAttr)
            {
                pTailAttr->pNext = pAttrib;
                pTailAttr = pAttrib;
            }
            else
            {
                ASSERT(NULL == pItem->m_pMagicAttr);
                pItem->m_pMagicAttr = pAttrib;
                pTailAttr = pAttrib;
            }

            pAttrib->nKey = pAttr->nAttribID;
            pAttrib->nValue1 = pAttr->Param[0].nMin +
                               g_Random(pAttr->Param[0].nMax - pAttr->Param[0].nMin);
            pAttrib->nValue2 = pAttr->Param[1].nMin +
                               g_Random(pAttr->Param[1].nMax - pAttr->Param[1].nMin);
        }
        else
        {
            break;
        }
    }

    bResult = TRUE;

Exit0:
    return bResult;
}
Beispiel #22
0
// 填好装备的生成参数,生成装备
BOOL KItemLib::ExpandItemAttrib(KItem* pItem, KEquipInfo* pInfo)
{
    BOOL bResult = FALSE;
    KAttribInfo* pAttr = NULL;

    KGLOG_PROCESS_ERROR(pItem);
    KGLOG_PROCESS_ERROR(pInfo);

    pItem->m_Common.nGenre = pInfo->nGenre;
    pItem->m_Common.nSub = pInfo->nSub;
    pItem->m_Common.nDetail = pInfo->nDetail;
    pItem->m_Common.nLevel = pInfo->nLevel;
    pItem->m_Common.nPrice = pInfo->nPrice;
    pItem->m_Common.nAbradeRate = 0;// pInfo->nAbradeRate;// TODO:磨损机率,等具体随机装备制作时再搞吧
    strcpy(pItem->m_Common.szItemName, pInfo->szName);
#ifdef _CLIENT
    pItem->m_nUiId = pInfo->nUiId;
#endif
    pItem->m_nRepresentId = pInfo->nRepresentId;
    pItem->m_Common.nBindType = ibtBindOnEquipped;	// 随机装备都是装备绑定
    pItem->m_Common.bStack = FALSE;					// 随机装备都是不能叠放的

    // 展开道具基本属性
    KAttribute* pTailAttr = NULL;

    for (int i = 0; i < MAX_ITEM_BASE_COUNT; i++)
    {
        if (pInfo->BaseAttrib[i].nAttribID > 0)
        {
            KAttribute* pAttrib = g_ObjectManager.m_AttributeSet.New();
            KGLOG_PROCESS_ERROR(pAttrib);
            pAttrib->pNext = NULL;

            if (pTailAttr)
            {
                pTailAttr->pNext = pAttrib;
                pTailAttr = pAttrib;
            }
            else
            {
                ASSERT(NULL == pItem->m_pBaseAttr);
                pItem->m_pBaseAttr = pAttrib;
                pTailAttr = pAttrib;
            }
            pAttrib->nKey = pInfo->BaseAttrib[i].nAttribID;
            pAttrib->nValue1 = pInfo->BaseAttrib[i].nMin +
                               g_Random(pInfo->BaseAttrib[i].nMax - pInfo->BaseAttrib[i].nMin);
            // 道具基本属性第二参数无效。
            pAttrib->nValue2 = 0;
        }
        else
        {
            break;
        }
    }

    pTailAttr = NULL;

    for (int i = 0; i < MAX_ITEM_REQUIRE_COUNT; i++)
    {
        if (pInfo->RequireAttrib[i].nAttribID > 0)
        {
            KAttribute* pAttrib = g_ObjectManager.m_AttributeSet.New();
            KGLOG_PROCESS_ERROR(pAttrib);
            pAttrib->pNext = NULL;

            if (pTailAttr)
            {
                pTailAttr->pNext = pAttrib;
                pTailAttr = pAttrib;
            }
            else
            {
                ASSERT(NULL == pItem->m_pRequireAttr);
                pItem->m_pRequireAttr = pAttrib;
                pTailAttr = pAttrib;
            }
            pAttrib->nKey = pInfo->RequireAttrib[i].nAttribID;
            pAttrib->nValue1 = pInfo->RequireAttrib[i].nValue;
            pAttrib->nValue2 = 0;
        }
        else
        {
            break;
        }
    }

    pTailAttr = NULL;

    for (int i = 0; i < MAX_ITEM_MAGIC_COUNT; i++)
    {
        if (pItem->m_GenParam.nMagicIndex[i] > 0)
        {
            pAttr =	m_Attrib.GetItemInfo(pItem->m_GenParam.nMagicIndex[i]);
            KGLOG_PROCESS_ERROR(pAttr);

            KAttribute* pAttrib = g_ObjectManager.m_AttributeSet.New();
            KGLOG_PROCESS_ERROR(pAttrib);
            pAttrib->pNext = NULL;

            if (pTailAttr)
            {
                pTailAttr->pNext = pAttrib;
                pTailAttr = pAttrib;
            }
            else
            {
                ASSERT(NULL == pItem->m_pMagicAttr);
                pItem->m_pMagicAttr = pAttrib;
                pTailAttr = pAttrib;
            }

            pAttrib->nKey = pAttr->nAttribID;
            pAttrib->nValue1 = pAttr->Param[0].nMin +
                               g_Random(pAttr->Param[0].nMax - pAttr->Param[0].nMin);
            pAttrib->nValue2 = pAttr->Param[1].nMin +
                               g_Random(pAttr->Param[1].nMax - pAttr->Param[1].nMin);
        }
        else
        {
            break;
        }
    }

    bResult = TRUE;

Exit0:
    return bResult;
}
Beispiel #23
0
BOOL KItemGenerator::Gen_Item(KItem*					pItem,
							  INT						nItemGenre,
							  INT						nDetailType,
							  INT						nParticular,
							  INT						nLevel,
							  INT						nEnhTimes,
							  CONST KItem::KSTONE_INFO* pStoneInfo,
							  CONST KMagicAttrib*		pAppendAttr,
							  CONST KItem::KREFINE_LOCK* pRefineLock,
							  UINT						uRandSeed,
							  UINT						uRandSeedEx,
							  BOOL						bNew,
							  BOOL						bTemporary,		// = FALSE
							  CONST GUID*				pGuid			// = NULL
							  )
{
	BYTE pBuf[emITEM_COUNT_RANDOM] = {0};
	if (!pItem)
		return	FALSE;
	if (nItemGenre <= ITEM_INVALID_TYPE)
		return	FALSE;
	if (nDetailType <= ITEM_INVALID_TYPE)
		return	FALSE;
	if (nParticular <= ITEM_INVALID_TYPE)
		return	FALSE;

	BOOL bRet = FALSE;

#ifdef GAME_SERVER
	if (!uRandSeed)
	{	// 打散随机种子
		g_Random(-1);
		uRandSeed = g_GetRandomSeed();
	}
	if (!uRandSeedEx)
	{	// 打散随机种子
		g_Random(-1);
		uRandSeedEx = g_GetRandomSeed();
	}
	// 设置物品唯一ID
	if (pGuid)
	{
		pItem->SetGuid(pGuid);
	}
	else
	{
		GUID sGuid;
		QGenerateGUID(&sGuid);
		pItem->SetGuid(&sGuid);
	}

#endif

	if(bNew)
	{
		memset(pItem->m_aryStoneInfo, emSTONE_LOCKED_ID, sizeof(pItem->m_aryStoneInfo));
	}

	m_cRandom.SetSeed(uRandSeed);	// 使用随机种子
	m_cRandomEx.SetSeed(uRandSeedEx);

	pItem->SetRandSeed(uRandSeed);	// 设置随机种子
	pItem->SetRandSeedEx(uRandSeedEx);

	g_cScriptManager.SetIt((QLunaBase*)pItem->m_pLuna);

	switch (nItemGenre)
	{
	case item_equip_general:		// 普通装备类
		if(nDetailType <= equip_foot)
		{
			bRet = Gen_GeneralEquip(pItem, nDetailType, nParticular, nLevel, nEnhTimes, pStoneInfo, pAppendAttr, pRefineLock, bNew);
		}
		else
		{
			// 套装
			bRet = Gen_GeneralSuit(pItem, nDetailType, nParticular, nLevel, bNew);
		}
		
		break;
	case item_medicine:				// 药品类
		bRet = Gen_Medicine(pItem, nDetailType, nParticular);
		break;
	case item_script:				// 脚本道具类
		switch(nDetailType)
		{
		case item_script_stone:
			bRet = Gen_Stone(pItem, nDetailType, nParticular, nLevel);
			break;
		case item_script_ride:
			bRet = Gen_Ride(pItem, nDetailType, nParticular, nLevel);
			break;
		default:
			bRet = Gen_ScriptItem(pItem, nDetailType, nParticular);
			break;
		}
		break;
	case item_pet:					// 宠物道具类
		bRet = Gen_PetItem(pItem, nDetailType, nParticular);
		break;
	case item_skill:				// 技能道具类
		bRet = Gen_SkillItem(pItem, nDetailType, nParticular);
		break;
	case item_quest:				// 任务道具类
		bRet = Gen_TaskQuest(pItem, nDetailType, nParticular);
		break;
	case item_extbag:				// 扩展背包类
		bRet = Gen_ExtendBag(pItem, nDetailType, nParticular);
		break;
	case item_stuff:
		bRet = Gen_StuffItem(pItem, nDetailType, nParticular);
		break;
	case item_plan:
		bRet = Gen_PlanItem(pItem, nDetailType, nParticular);
		break;
	default:
		bRet = FALSE;
	}

	if (bRet)
	{
#ifdef GAME_SERVER
		if (bNew)
			pItem->SetGenTime(KSysService::Time(NULL));
#endif
		/*
		if (nStrengthen > 0)
		{
			pItem->SetStrengthen(nStrengthen); // 设置改造属性
		}
		*/

		pItem->SetTemporary(bTemporary);
		//VERIFY(pItem->EndGenerate());
	}

	return	bRet;
}
Beispiel #24
0
int LuaSelectOnlineRole(Lua_State* L)
{
    int     nResult         = 0;
    int     nRetCode        = 0;
    int     nTopIndex       = 0;
    int     nRequireCount   = 0;
    int     nRandIndex      = 0;
    int     nOnlineTotal    = 0;
    KRole*  pRole           = NULL;
    KFuncGetOnlineRoleTable Func;

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

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

    Func.m_nLevelLow  = (int)Lua_ValueToNumber(L, 2);
    Func.m_nLevelHigh = (int)Lua_ValueToNumber(L, 3);

    Func.m_vRoleTable.reserve(20000);
    g_pSO3GameCenter->m_RoleManager.Traverse(Func);

    nOnlineTotal = (int)Func.m_vRoleTable.size();

    Lua_NewTable(L);

    if (nRequireCount >= nOnlineTotal)
    {
        for (int i = 0; i < nOnlineTotal; i++)
        {
            pRole = Func.m_vRoleTable[i];
            assert(pRole);

            Lua_PushNumber(L, i + 1);
            pRole->LuaGetObj(L);
            
            Lua_SetTable(L, -3);
        }
    }
    else
    {
        for (int i = 0; i < nRequireCount; i++)
        {
            nRandIndex = g_Random(nOnlineTotal - i);
            
            pRole = Func.m_vRoleTable[nRandIndex];
            assert(pRole);

            Func.m_vRoleTable[nRandIndex] = Func.m_vRoleTable[nOnlineTotal - i - 1];

            Lua_PushNumber(L, i + 1);
            pRole->LuaGetObj(L);

            Lua_SetTable(L, -3);
        }
    }

    nResult = 1;
Exit0:
    return nResult;
}
Beispiel #25
0
BOOL KBuff::ApplyAttributeNotRollBack(KCharacter* pCharacter, KBUFF_LIST_NODE& rBuffListNode, KAttribute* pAttribute)
{
    BOOL                                bResult                 = false;
    BOOL                                bRetCode                = false;
    int                                 nDamageValue            = 0;
    int                                 nDenominator            = 0;
    int                                 nCriticalStrikeValue    = 0;
    int                                 nDefCriticalStrikeValue = 0;
    int                                 nRandomValue            = 0;
    BOOL                                bShield                 = false;
    BOOL                                bForceSync              = false;
    KCharacter*                         pCharacterSrc           = NULL;
    KBuff*                              pBuff                   = NULL;

    KCharacter::KSKILL_ATTRIBUTE_PARAM* pOldDstAttributeParam   = NULL;
    KCharacter::KSKILL_ATTRIBUTE_PARAM  AttributeParam;

    KSKILL_CALCULATE_RESULT*            pOldSrcResult           = NULL;
    KSKILL_CALCULATE_RESULT*            pOldDstResult           = NULL;
    KSKILL_CALCULATE_RESULT             SrcResult;
    KSKILL_CALCULATE_RESULT             DstResult;

    assert(pCharacter);
    assert(pAttribute);

    memset(&AttributeParam, 0, sizeof(AttributeParam));
    memset(&SrcResult, 0, sizeof(SrcResult));
    memset(&DstResult, 0, sizeof(DstResult));

    pOldDstAttributeParam = pCharacter->m_pSkillAttributeParam;
    pCharacter->m_pSkillAttributeParam = &AttributeParam;

    pOldSrcResult = pCharacter->m_pSrcSkillCalculateResult;
    pOldDstResult = pCharacter->m_pDstSkillCalculateResult;

    pCharacter->m_pDstSkillCalculateResult = &DstResult;
    pCharacter->m_pSrcSkillCalculateResult = &SrcResult;

    pBuff = rBuffListNode.BuffRecipePointer.GetPointer();
    KGLOG_PROCESS_ERROR(pBuff);

    SrcResult.EffectSrc.eType   = setBuff;
    SrcResult.EffectSrc.dwID    = pBuff->m_dwID;
    SrcResult.EffectSrc.nLevel  = pBuff->m_nLevel;

    DstResult.EffectSrc.eType   = setBuff;
    DstResult.EffectSrc.dwID    = pBuff->m_dwID;
    DstResult.EffectSrc.nLevel  = pBuff->m_nLevel;

    AttributeParam.SkillRecipePointer = rBuffListNode.SkillRecipePointer;

    bRetCode = IS_PLAYER(rBuffListNode.dwSkillSrcID);
    if (bRetCode)
    {
        pCharacterSrc = g_pSO3World->m_PlayerSet.GetObj(rBuffListNode.dwSkillSrcID);
    }
    else
    {
        pCharacterSrc = g_pSO3World->m_NpcSet.GetObj(rBuffListNode.dwSkillSrcID);
    }

    AttributeParam.dwSkillSrcID             = rBuffListNode.dwSkillSrcID;
    AttributeParam.nSkillSrcLevel           = rBuffListNode.nSkillSrcLevel;
    AttributeParam.pSkillDst                = pCharacter;
    AttributeParam.pSkillSrc                = pCharacterSrc;

    AttributeParam.nPhysicsDamage           = rBuffListNode.nPhysicsDamage;
    AttributeParam.nSolarDamage             = rBuffListNode.nSolarDamage;
    AttributeParam.nNeutralDamage           = rBuffListNode.nNeutralDamage;
    AttributeParam.nLunarDamage             = rBuffListNode.nLunarDamage;
    AttributeParam.nPoisonDamage            = rBuffListNode.nPoisonDamage;
    AttributeParam.nTherapy                 = rBuffListNode.nTherapy;
    AttributeParam.nDamageAddPercent        = pBuff->m_nDamageAddPercent;

    if (pCharacter->m_bSystemShield)
    {
        DstResult.bShield   = true;
        bForceSync          = true;

        goto Exit1;
    }

    // 计算暴击
    nCriticalStrikeValue                    = rBuffListNode.nCriticalStrike;

    if (!pBuff->m_bCanCancel)   // debuff和dot要计算自身韧性
    {
        nDenominator = pCharacter->m_nToughness + 74 * pCharacter->m_nLevel + 320;
        KGLOG_PROCESS_ERROR(nDenominator > 0);
        nDefCriticalStrikeValue = pCharacter->m_nToughnessBaseRate + MAX_HIT_VALUE * pCharacter->m_nToughness / nDenominator;
    }

    nCriticalStrikeValue = max((nCriticalStrikeValue - nDefCriticalStrikeValue), 0);
    
    AttributeParam.bCriticalStrike          = false;

    nRandomValue = g_Random(MAX_HIT_VALUE);
    if (nRandomValue <= nCriticalStrikeValue)
    {
        AttributeParam.bCriticalStrike      = true;
    }
    
    AttributeParam.nStackNum                = rBuffListNode.nStackNum;

    AttributeParam.nBaseThreatCoefficient       = rBuffListNode.nBaseThreatCoefficient;
    AttributeParam.nDamageThreatCoefficient     = rBuffListNode.nDamageThreatCoefficient;
    AttributeParam.nTherapyThreatCoefficient    = rBuffListNode.nTherapyThreatCoefficient;

    AttributeParam.nDamgeToLifeForSelf      = rBuffListNode.nStealLifePercent;
    AttributeParam.nDamgeToManaForSelf      = rBuffListNode.nStealManaPercent;

    pCharacter->m_pDstSkillCalculateResult->bHitTarget = true;
    pCharacter->m_pSrcSkillCalculateResult->bHitTarget = true;
    
    pCharacter->m_pDstSkillCalculateResult->bCriticalStrike = AttributeParam.bCriticalStrike;
    pCharacter->m_pSrcSkillCalculateResult->bCriticalStrike = AttributeParam.bCriticalStrike;

    pCharacter->ApplyAttribute(pAttribute);

    pCharacter->ConcludeResult(0, AttributeParam.bCriticalStrike, &nDamageValue);


Exit1:
    if (nDamageValue || bForceSync)
    {
        g_PlayerServer.DoSkillEffectResult(pCharacterSrc, pCharacter, pCharacter, pCharacter->m_pDstSkillCalculateResult, 0);
        g_PlayerServer.DoSyncBehitRepresent(pCharacterSrc, pCharacter, pCharacter, pCharacter->m_pDstSkillCalculateResult, 0);
    }

    bResult = true;
Exit0:
    pCharacter->m_pSkillAttributeParam      = pOldDstAttributeParam;
    pCharacter->m_pDstSkillCalculateResult  = pOldDstResult;
    pCharacter->m_pSrcSkillCalculateResult  = pOldSrcResult;

    return bResult;
}