⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regenmanager.cpp

📁 奇迹世界 部分源代码奇迹世界 部分源代码奇迹世界 部分源代码
💻 CPP
字号:
#include "stdafx.h"
#include "RegenManager.h"
#include "Field.h"
#include "FieldInfo.h"
#include "RegenParser.h"
#include "RegenLocation.h"
#include "ObjectFactory.h"
#include "NPCInfoParser.h"
#include "ObjectGroupManager.h"
#include <Struct.h>
#include <Const.h>
#include <3DEngine/3DTerrain/WorldBase.h>
#include <vector>
#include <algorithm>
#include <battle.h>
#include "Monster.h"
#include "AIParamParser.h"

RegenManager::RegenManager( Field *pField )
{
	m_pField = pField;							// 傍蜡 器牢磐
}


RegenManager::~RegenManager()
{
}


VOID RegenManager::Release()
{
	LOCATION_VECTOR_ITER it;

	for( it = m_vecRegenLocations.begin(); it != m_vecRegenLocations.end(); ++it )
	{
		(*it)->Release();

		// TODO: 钱 父甸绢辑 芭扁促 馆券且 巴
		SAFE_DELETE( *it );
	}
	m_vecRegenLocations.clear();
}

class RegenInit
{
	DWORD m_dwMapCode;
	DWORD m_dwFieldIndex;
	WORD m_wMonType;
	RegenManager * m_pMGR;

public:
	RegenInit( RegenManager * pMGR, DWORD dwMapCode, DWORD dwFieldIndex, WORD wMonType ):
	  m_pMGR(pMGR),m_dwMapCode(dwMapCode),m_dwFieldIndex(dwFieldIndex),m_wMonType(wMonType) {}

	~RegenInit(){}
	VOID operator()( WzSpecialArea *pArea )
	{
		REGEN_INFO *pRegenInfo = RegenParser::Instance()->GetRegenInfo( m_dwMapCode, m_dwFieldIndex, pArea->m_wiIdentity, m_wMonType );
		if( !pRegenInfo )	return;

		// TODO: 钱 父甸 巴
		RegenLocation *pRegenLocation = new RegenLocation;

		// 康开俊 府哩 沥焊 悸泼
		pRegenLocation->Init( pRegenInfo, pArea->m_wiIdentity );

		// 氦磐俊 眠啊
		m_pMGR->AddRegenLocation( pRegenLocation );
	}
};

class RandomRegenInit
{
	DWORD m_dwMapCode;
	DWORD m_dwFieldIndex;
	WORD m_wMonType;
	RegenManager * m_pMGR;
	FieldInfo *m_pFieldInfo;	

	class AddAreaKey
	{
		RegenLocation*	m_pRegenLocation;

	public:
		AddAreaKey( RegenLocation *pRegenLocation ) : m_pRegenLocation(pRegenLocation) {}

		VOID operator()( WzSpecialArea *pArea )
		{
			if( pArea ->m_wbvRegion.m_eBvType != BVT_PATH_TILE_INDEX )	
				return;

			m_pRegenLocation->AddRandomAreaKey( pArea->m_wiIdentity );
		}
	};

public:
	RandomRegenInit( RegenManager * pMGR, DWORD dwMapCode, DWORD dwFieldIndex, WORD wMonType, FieldInfo *pFieldInfo ):
	  m_pMGR(pMGR),m_dwMapCode(dwMapCode),m_dwFieldIndex(dwFieldIndex),m_wMonType(wMonType),m_pFieldInfo(pFieldInfo) {}
	  ~RandomRegenInit(){}

	  VOID operator()( REGEN_INFO *pRegenInfo )
	  {
		  // 甘内靛, 鞘靛牢郸胶, 阁胶磐鸥涝捞 老摹窍绰 府哩沥焊父 茫绰促.
		  if( pRegenInfo->dwMapCode != m_dwMapCode || pRegenInfo->dwFieldIndex != m_dwFieldIndex || pRegenInfo->wMonsterType != m_wMonType )
			  return;

		  // TODO: 钱 父甸 巴
		  RegenLocation *pRegenLocation = new RegenLocation;

		  // 康开俊 府哩 沥焊 悸泼
		  pRegenLocation->Init( pRegenInfo );

		  // 秦寸 甘狼 葛电 AreaKey甸阑 眠啊茄促.
		  AddAreaKey AddAreaKeyOpr(pRegenLocation);
		  m_pFieldInfo->ForeachArea(AddAreaKeyOpr);

		  // 氦磐俊 眠啊
		  m_pMGR->AddRegenLocation( pRegenLocation );
	  }
};


// FieldInfo俊 历厘等 府哩 康开 府胶飘甫 掘绢辑 府哩 沥焊 器牢磐甫 秦浆甘栏肺 包府且 荐 乐霸 茄促.
VOID RegenManager::Init( DWORD dwMapCode, DWORD dwFieldIndex, WORD wMonType )
{
	// 茄 康开俊辑 积己登绰 阁胶磐甸阑 悸泼茄促.
	RegenInit RegenOpr( this, dwMapCode, dwFieldIndex, wMonType );
	m_pField->GetFieldInfo()->ForeachArea(RegenOpr);

	// 罚待茄 康开俊辑 积己登绰 阁胶磐甸阑 悸泼茄促.
	RandomRegenInit RandomRegenOpr( this, dwMapCode, dwFieldIndex, wMonType, m_pField->GetFieldInfo() );
	RegenParser::Instance()->ForeachRandomRegen(RandomRegenOpr);

	AIParamInfo& stAIParamInfo = AIParamParser::Instance()->GetInfo();
	m_RegenTimer.SetTimer( stAIParamInfo.m_dwREGEN_CYCLE );

	// 贸澜浚 傈眉 阁胶磐甫 谎赴促.
	ExecuteRegen( TRUE );
}

VOID RegenManager::Update()
{
	if( !m_RegenTimer.IsExpired() ) return;

	// 康开甸阑 逻 倒搁辑 府哩 贸府
	ExecuteRegen();
}

VOID RegenManager::CreateNPC( DWORD dwCode, DWORD dwNumberOfNPCs, WzVector *pwvPos, RegenLocation *pHomeLocation, DWORD dwGroupID )
{
	BASE_NPCINFO* pBaseNPCInfo = NPCInfoParser::Instance()->GetMonsterInfo( dwCode );
	if( !pBaseNPCInfo )
	{
		SUNLOG( eFULL_LOG,  "[RegenManager::CreateNPC] 积己窍绊磊 窍绰 阁胶磐 内靛啊 胶农赋飘俊 绝嚼聪促.(%d)", dwCode );
		return;
	}

	// 秦寸窍绰 弊缝阑 茫芭唱 绝栏搁 货肺 弊缝阑 且寸
	ObjectGroup *pObjectGroup = NULL;
	if( dwGroupID )
	{
		pObjectGroup = m_pField->AllocGroup( pHomeLocation->GetRegenInfo()->dwLocationID, dwGroupID );
	}

	// 阁胶磐 积己
	Monster *pMonster;
	for( DWORD i = 0; i < dwNumberOfNPCs; ++i )
	{
		pMonster = (Monster*)ObjectFactory::Instance()->AllocObject( MONSTER_OBJECT );

		pMonster->SetBaseInfo( pBaseNPCInfo );

		m_pField->EnterField( pMonster, pwvPos );

		// 权 康开 悸泼
		pMonster->SetRegenLocation( pHomeLocation );

		// 积己等 NPC甫 Group俊 殿废茄促.
		if( pObjectGroup )
		{
			pObjectGroup->AddObject( MONSTER_OBJECT, pMonster, dwCode );
			pMonster->JoinGroup( pObjectGroup );
		}
		else
		{
			// 权 康开狼 阁胶磐 荐 刘啊
			pHomeLocation->IncreaseNPC( pMonster->GetBaseInfo()->m_MonsterCode );
		}
	}
}

DWORD RegenManager::DecisionNumberOfRegen( RegenLocation *pLocation, DWORD dwNPCCode, DWORD dwMaxNum )
{
	// 秦寸 NPC内靛狼 混酒乐绰 NPC荐
	DWORD dwNumberOfAliveNPCs = pLocation->GetNumberOfAliveNPCs( dwNPCCode );

	// 混酒乐绰 NPC荐啊 弥措摹尔 鞍栏搁 歹捞惑 积己 救茄促.
	if( dwNumberOfAliveNPCs >= dwMaxNum )		return 0;

	// 府哩矫懦 荐甫 0~max吝 罚待窍霸 积己
	DWORD dwNumberOfRegen = rand() % ( dwMaxNum + 1 );
//	DWORD dwNumberOfRegen = dwMaxNum;

	// 混酒乐绰 荐 + 府哩 荐啊 弥措摹焊促 农搁 府哩 荐 炼沥
	if( dwNumberOfAliveNPCs + dwNumberOfRegen > dwMaxNum )
	{
		dwNumberOfRegen = dwMaxNum - dwNumberOfAliveNPCs;
	}
	return dwNumberOfRegen;
}

VOID RegenManager::ExecuteRegen( BOOL bSpawnAll )
{
	for( LOCATION_VECTOR_ITER it = m_vecRegenLocations.begin(); it != m_vecRegenLocations.end(); ++it )
	{		
		m_pLocalLocation = *it;
		m_pLocalRegenInfo = m_pLocalLocation->GetRegenInfo();

		// 阿 康开狼 鸥老 牢郸胶甸阑 掘绰促.
		BOOL bBossRegen = FALSE;
		WzSpecialArea *pBaseAreaInfo = m_pField->GetFieldInfo()->GetAreaInfo( m_pLocalLocation->GetAreaKey() );
		if( !pBaseAreaInfo )
		{
			bBossRegen = TRUE;
			pBaseAreaInfo = m_pField->GetFieldInfo()->GetAreaInfo( m_pLocalLocation->GetRandomAreaKey() );
			if( !pBaseAreaInfo )
			{
				SUNLOG( eFULL_LOG,  "[RegenManager::ExecuteRegen] Regen.txt甫 曼炼窍咯 府哩阑 贸府窍妨 沁瘤父 甘沥焊俊 秦寸 康开捞 绝嚼聪促." );
				continue;
			}
		}

		if( pBaseAreaInfo ->m_wbvRegion.m_eBvType != BVT_PATH_TILE_INDEX )
		{
			SUNLOG( eFULL_LOG,  "[RegenManager::ExecuteRegen] Regen AreaType is not Tile! " );
			continue;
		}

		//康开 沥焊
		DWORD dwAreaTileCnt = pBaseAreaInfo->m_wbvRegion.m_BvPathTileIndex.m_nCount;
		if( dwAreaTileCnt )
		{
			DWORD *pdwTileIndex = pBaseAreaInfo->m_wbvRegion.m_BvPathTileIndex.m_pdwData;

			// 弊缝 NPC 积己
			ExecuteGroupRegen( bBossRegen, dwAreaTileCnt, pdwTileIndex );

			// 俺喊 NPC 积己
			ExecuteSingleRegen( bSpawnAll, dwAreaTileCnt, pdwTileIndex );
		}
	}
}

VOID RegenManager::ExecuteGroupRegen( BOOL bBossRegen, DWORD dwAreaTileCnt, DWORD *pdwTileIndex )
{
	WzVector vLeaderRegenPos, vFollowerRegenPos;
	DWORD dwSelectedTile;

	// 弊缝 NPC 积己!
	for( int iGroup = 0; iGroup < MAX_GROUP; ++iGroup )
	{	
		// 犬伏 利侩
		if( !DrawLots( (BYTE)( m_pLocalRegenInfo->fRegenRate * 100 ) ) ) continue;

		// 捞固 弊缝捞 劝己拳登绢 乐栏搁 胶诺
		ObjectGroup *pGroup = m_pField->FindGroup( m_pLocalRegenInfo->dwLocationID, m_pLocalRegenInfo->dwGroupID[iGroup] );
		if( pGroup ) continue;

		BASE_GROUPINFO *pGroupInfo = GroupParser::Instance()->GetGroupInfo( m_pLocalRegenInfo->dwGroupID[iGroup] );
		if( !pGroupInfo ) continue;

		// 捞 康开狼 鸥老 府胶飘 吝 窍唱甫 急琶
		dwSelectedTile = (WORD)(rand() % dwAreaTileCnt);

		// 府歹 积己
		if( pGroupInfo->dwLeaderCode != 0 )
		{
			// 急琶等 鸥老 救俊辑 罚待 谅钎甫 掘绢柯促.
			vLeaderRegenPos = m_pField->GetFieldInfo()->GetWorldBase()->GetRandomPosInTile( pdwTileIndex[dwSelectedTile] );

			CreateNPC( pGroupInfo->dwLeaderCode, 1, &vLeaderRegenPos, m_pLocalLocation, pGroupInfo->dwGroupID );
		}

		// 绿蝶备(甸) 积己
		for( int iFollower = 0; iFollower < MAX_FOLLOWER_NUM; ++iFollower )
		{
			FOLLOWERINFO &rFollowerInfo = pGroupInfo->FollowerInfo[iFollower];

			if( rFollowerInfo.dwMonCode == 0 ) break;

			// 急琶等 鸥老 救俊辑 罚待 谅钎甫 掘绢柯促.
			vFollowerRegenPos = m_pField->GetFieldInfo()->GetWorldBase()->GetRandomPosInTile( pdwTileIndex[dwSelectedTile] );

			CreateNPC( rFollowerInfo.dwMonCode, rFollowerInfo.wNum, &vFollowerRegenPos, m_pLocalLocation, pGroupInfo->dwGroupID );
		}

		// 焊胶啊 府哩登菌澜阑 林函俊 舅赴促.
		if( bBossRegen )
		{
			MSG_CG_SYNC_BOSS_MONSTER_ENTER_BRD brdMsg;
			brdMsg.m_dwBossCode = pGroupInfo->dwLeaderCode;
			brdMsg.m_vCurPos = vLeaderRegenPos;
			m_pField->SendPacketToAll( &brdMsg, sizeof(brdMsg) );
		}
	}
}

VOID RegenManager::ExecuteSingleRegen( BOOL bSpawnAll, DWORD dwAreaTileCnt, DWORD *pdwTileIndex )
{
	WzVector wvRegenPos;
	DWORD dwSelectedTile;

	// 登档废 辑肺 促弗 鸥老俊 瑞绢辑 积己窍扁 困秦 罚待窍霸 鸥老 锅龋甫 集篮 饶 菊俊辑何磐 窍唱究 急琶
	vector<DWORD> vecTiles;
	for( DWORD iTile = 0; iTile < dwAreaTileCnt; ++iTile )
	{
		vecTiles.push_back( iTile );
	}
	random_shuffle( vecTiles.begin(), vecTiles.end() );

	DWORD dwSelectTileCnt = 0;

	// 俺喊 NPC 积己!
	for( int i = 0; i < MAX_REGEN_MONSTER_KIND; ++i )
	{
		if( m_pLocalRegenInfo->dwMonCode[i] == 0 || m_pLocalRegenInfo->dwMaxNum[i] == 0 ) continue;

		// 犬伏 利侩
		if( !bSpawnAll )
		{
			if( !DrawLots( (BYTE)( m_pLocalRegenInfo->fRegenRate * 100 ) ) ) continue;
		}

		DWORD dwNumberOfRegen = DecisionNumberOfRegen( m_pLocalLocation, m_pLocalRegenInfo->dwMonCode[i], m_pLocalRegenInfo->dwMaxNum[i] );
		if( dwNumberOfRegen == 0 ) continue;

		for( DWORD dwRegenCnt = 0; dwRegenCnt < dwNumberOfRegen; ++dwRegenCnt )
		{
			// 寂敲等 鸥老 氦磐狼 菊俊辑何磐 瞒肥肺 鉴雀窍哥 急琶
			dwSelectedTile = vecTiles[dwSelectTileCnt++ % dwAreaTileCnt];

			// 急琶等 鸥老 救俊辑 罚待 谅钎甫 掘绢柯促.
			wvRegenPos = m_pField->GetFieldInfo()->GetWorldBase()->GetRandomPosInTile( pdwTileIndex[dwSelectedTile] );

			// TODO: 冀磐付促 弓绢辑 菩哦 焊郴绰霸 鞘夸且 淀
			CreateNPC( m_pLocalRegenInfo->dwMonCode[i], 1, &wvRegenPos, m_pLocalLocation, 0 );
		}
	}

	vecTiles.clear();
}





















⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -