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

📄 dungeon.cpp

📁 国内著名网络游戏dragon的服务端完整源码 内附完整数据库结构
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	// 030211 YGI
	if( p->u.kein.scenario_message.type == 1 )
	{
		MyLog( 0, "################### [%d]DUNGEON_CLOSE #####################", p->u.kein.scenario_message.port );
	}
	else if( p->u.kein.scenario_message.type == 2 )
	{
		MyLog( 0, "################### [%d]DUNGEON_OPEN #####################", p->u.kein.scenario_message.port );
	}
}

void RecvScenarioDetailInfo( t_packet *p, short int cn )
{
	CHARLIST *ch = CheckServerId( cn ); 
	if( !ch ) return;
	
	//int event_no = p->u.kein.default_char;
	if( !g_pDungeonMap ) return;
	
	int count, active_count, active_time;
	g_pDungeonMap->GetTrapCount( count, active_count, active_time );
	
	t_packet packet;
	if( !count )
	{
		packet.h.header.type = p->h.header.type;
		packet.u.kein.scenario_detail_info.type = 0;
		packet.h.header.size = 1;
		QueuePacket( connections, cn, &packet, 1 );
		return;
	}
	
	packet.h.header.type = p->h.header.type;
	packet.u.kein.scenario_detail_info.type = 1;
	packet.u.kein.scenario_detail_info.total_trap = count;
	packet.u.kein.scenario_detail_info.active_trap = active_count;
	packet.u.kein.scenario_detail_info.time = active_time;
	packet.h.header.size = sizeof( k_scenario_detail_info );
	QueuePacket( connections, cn, &packet, 1 );
	
	packet.h.header.type = CMD_TRAP_INFO_MAP;
	packet.u.kein.direct_map_req.server_id = cn;
	packet.u.kein.direct_map_req.port = GetOwnPort();
	packet.h.header.size = sizeof( k_direct_map_req );
	if( CheckMapPort(MN_SCENARIO_MAP) )
	{
		RecvScenarioDetailInfoMap( &packet, -1 );
	}
	else
	{
		SendPacket2Map( &packet, MN_SCENARIO_MAP );
	}
}

void RecvScenarioDetailInfoMap( t_packet *p, short int cn )
{
	if( !g_pDungeonMgr ) return;
	int server_id = p->u.kein.direct_map_req.server_id;
	int port = p->u.kein.direct_map_req.port;
	CDungeonBasic *pDungeon = g_pDungeonMgr->GetDungeonByPort( port );
	if( !pDungeon ) return;
	if( !pDungeon->m_nActive ) return;
	
	k_scenario_detail_info scenario_detail_info;
	scenario_detail_info.type = 2;
	scenario_detail_info.time = pDungeon->GetRemainTime();//pDungeon->m_nContinueTime - pDungeon->m_nStartTime;	// 031110 YGI
	int size = size = sizeof(char) + sizeof(int);
	if( CheckMapPort(port) )
	{
		t_packet packet;
		packet.h.header.type = CMD_TRAP_INFO;
		packet.h.header.size = size;
		memcpy( packet.u.data, &scenario_detail_info, size );
		QueuePacket( connections, server_id, &packet, 1 ); 
	}
	else
	{
		SendDirectClientOtherMap( CMD_TRAP_INFO, server_id, port, &scenario_detail_info, size );
	}
}

// 甘辑滚啊 谗绢 脸菌阑 锭, 弊 甘捞 泅犁 咀萍宏 登绢 乐带 惑炔捞搁
void ScenarioServerNewStart( WORD port )
{
	if( !g_pDungeonMgr ) {return;}
	
	CDungeonBasic *pDungeon = g_pDungeonMgr->GetDungeonByPort( port );
	if( !pDungeon ) {return;}
	//if( !pDungeon->m_nActive ) return;
	
	int temp[MAX_CDUNGEONBASIC_INT]; // CSD-030723
	LoadDungeonMapEach( port, temp );
	pDungeon->SetActiveFlag( 0 );
	pDungeon->SetInt( temp );
}

void ScenarioServerClear( WORD port )
{
	if( !g_pDungeonMgr ) return;
	
	CDungeonBasic *pDungeon = g_pDungeonMgr->GetDungeonByPort( port );
	if( !pDungeon ) return;
	if( !pDungeon->m_nActive ) return;
	
	pDungeon->m_nStartTime = pDungeon->m_nWaitTime - 60;
	pDungeon->SetActiveFlag( 0 );
	pDungeon->SaveDungeonStatus();
}

void ScenarioServerReset( WORD port )		// 带傈 甘捞 货肺 坷锹 登搁 弊 甘狼 咀萍宏甫 官层霖促.
{
	if( !g_pDungeonMgr ) return;
	CDungeonBasic *pDungeon = g_pDungeonMgr->GetDungeonByPort( port );
	if( !pDungeon ) return;
	if( !pDungeon->m_nActive ) return;
	
	pDungeon->m_nStartTime = pDungeon->m_nWaitTime - 2;
	pDungeon->SetActiveFlag( 0 );
}

void RecvScenarioTrapKeyInfo( t_packet *p, short int cn )
{
	CHARLIST *ch = CheckServerId( cn );
	if( !ch ) return;
	
	if( !g_pDungeonMap ) return;
	
	CDungeonMap* pDM = g_pDungeonMap->GetActiveDungeonMap();
	if( !pDM ) return;
	t_packet packet;
	packet.h.header.type = p->h.header.type;
	packet.u.kein.scenario_trap_key.sum = pDM->m_nTrapCount;
	for( int i=0; i<7; i++ )
	{
		packet.u.kein.scenario_trap_key.qube[i] = pDM->m_pKey[i];
	}
	packet.h.header.size = sizeof( k_scenario_trap_key );
	QueuePacket( connections, cn, &packet, 1 );
}

void SendScenarioMessage( short int cn, int type, void *data, int size )
{
	t_packet packet;
	packet.h.header.type = CMD_SCENARIO_MESSAGE;
	packet.u.kein.data[0] = type;		// 
	if( data )
	{
		memcpy( &packet.u.kein.data[1], data, size );
	}
	packet.h.header.size = size+1;
	if( cn == SEND_ALL )
	{
		g_pUserManager->SendPacket(&packet); // CSD-CN-031213
	}
	else
	{
		QueuePacket( connections, cn, &packet, 1 );
	}
}

// 矫唱府坷 侩 酒捞袍 傈何 瘤快扁
void DeleteScenarioItem( CHARLIST *ch )
{
	//	return ;		// test
	for( int a=0; a<3; a++ ) 
	{	for( int b=0; b<3; b++ ) 
	{	for( int c=0; c<8; c++ )
	{
		ItemAttr *item = &ch->inv[a][b][c];
		if( !item->item_no ) continue;
		CItem *t = ItemUnit( item->item_no );
		if( !t ) continue;
		if( ( t->GetItemKind() == IK_ABYSS_MAZE )
			|| ( t->GetItemKind() == IK_UNDEAD_DUNGEON )
			|| ( t->GetItemKind() == IK_GREAT_MAZE ) )
		{
			POS pos;
			SetItemPos( INV, a, b, c, &pos );
			SendDeleteItem( item, &pos, ch );
		}
	}
	}
	}
	
	ItemAttr *item = &ch->handheld;
	if( item->item_no )
	{
		CItem *t = ItemUnit( item->item_no );
		if( t )
		{
			if( ( t->GetItemKind() == IK_ABYSS_MAZE )
				|| ( t->GetItemKind() == IK_UNDEAD_DUNGEON )
				|| ( t->GetItemKind() == IK_GREAT_MAZE ) )
			{
				POS pos;
				SetItemPos( HAND, &pos );
				SendDeleteItem( item, &pos, ch );
			}
		}
	}
}



//////////////////////////////////////////////////////
// class CScenarioBoss member functions
//021030 YGI
int CScenarioBoss::DeleteBoss()
{
	int ret = 0;
	if( m_nNpcIndex ) 
	{
		CHARLIST *npc = &NPCList[m_nNpcIndex];
		if( npc->npc_index == m_nSprNum )
		{
			if( npc->bAlive == ALIVE_ )
			{
				::DeleteNpc( m_nNpcIndex );
				ret = 1;
			}
			
			if ( g_pDungeonMap )
				if( m_nBossType == BT_DARAGON ) g_pDungeonMap->DropDragonItem();
		}
	}
	Clear();
	return ret;
	
}
int CScenarioBoss::CreateBoss( int npc_type, int npc_num, int x, int y )
{
	const int id = ::GetDeleteAbleNPC();//030211 lsw
	if( id >= 0 )
	{
		::DeleteNpc( id );
	}
	else
	{//瘤匡 荐 乐绰 阁胶磐啊 绝促搁
		::MyLog(0,"Critical Error Can't Get Normal Monster(CreateBoss())");
		return 0;
	}
	
	int spr = 0;
	switch( npc_type )
	{
	default : return 0;
	case NT_DRAGON_LOAD :
		{
			m_nSprNum = DRAGON_LORD_INDEX_NO;
			NPC_Create( id, m_nSprNum, x, y, 0, 0, GT_SCENARIO_MONSTER );
			m_nBossType = BT_DARAGON;
			break;
		}
	case NT_NORMAL_DRAGON : 
		{
			m_nSprNum = DRAGON_INDEX_NO;
			NPC_Create( id, m_nSprNum, x, y, 0, 0, GT_SCENARIO_MONSTER );
			m_nBossType = BT_DARAGON;
			break;
		}
	case NT_DRAGON_HEART :
		{
			m_nSprNum = DRAGON_HEART_INDEX_NO;
			NPC_Create( id, m_nSprNum, x, y, 0, 0, GT_SCENARIO_MONSTER );
			m_nBossType = BT_DARAGON_HEART;
			break;
		}
	case NT_NORMAL_BOSS :
		{
			m_nSprNum = npc_num;
			NPC_Create( id, m_nSprNum, x, y, 0, 0, GT_SCENARIO_MONSTER );
			break;
		}
	case NT_FOLLOWER:
		{
			if( TileMap[x][ y].attr_dont )
			{
				for( int i=x-5; i<x+5; i++ )
				{
					for( int j=y-5; j<y+5; y++ )
					{
						if( !TileMap[x][ y].attr_dont ) 
						{
							x=i, y =j;
							break;
						}
					}
				}
			}
			if( TileMap[x][ y].attr_dont ) return 0;
			m_nSprNum = npc_num;
			NPC_Create( id, m_nSprNum, x, y, 0, 0, GT_SCENARIO_MONSTER );
			break;
		}
	}
	m_nNpcType = npc_type;
	m_nNpcIndex = id;
	
	return 1;
}

//////////////////////////////////////////////////////

int KilledScenarioBoss( CHARLIST *user, CHARLIST *npc )		// 矫唱扼府坷 阁胶磐啊 磷菌促.
{
	if( !g_pDungeonMap ) return 0;
	return g_pDungeonMap->KilledScenarioBoss( user, npc );
}

void RecvDragonVote( t_packet *p, short int cn )
{
	CHARLIST *ch = CheckServerId( cn );
	if( !ch ) return;
	if( !g_pDungeonMap ) return;
	
	int true_false = p->u.data[0];		// 蛮己 馆措
	if( !g_pDungeonMap->pVoteTrue ) return;
	int *pData;
	pData = new int;
	*pData = cn;
	if( true_false ) g_pDungeonMap->pVoteTrue->AddNode( pData );
	else g_pDungeonMap->pVoteFalse->AddNode( pData );
} 

// 蛮馆 搬捧
void ScenarioDragonEndWar()
{
	g_pDungeonMap->EndUserFightByDragon();
}
void ScenarioDragonMsgFunc()
{
	//MyLog( 0, "message " );
}

CScenarioDragonItem	*g_pDragonItem = NULL;
int CScenarioDragonItem::MakeDragonItem( int total )
{
	SAFE_DELETE_ARRAY(m_pTotalItem);
	
	m_pTotalItem = new ItemAttr[total];
	m_nTotalCount = total;
	
	ItemAttr *pItem;
	for( int i=0; i<m_nTotalCount; i++ )
	{
		pItem = &m_pTotalItem[i];
		SkillMgr.MakeItemByItemControl( pItem, DRAGON_ITEMCONTROL_NUMBER );
	}
	return 1;
}
/////////////////////////////////////////////
// 靛贰帮捞 磷阑 锭 龋免
// 蛮己茄 某腐磐 府胶飘客 馆措茄 某腐磐 府胶飘甫 牢磊肺 罐绰促.
//
// 曼咯 蜡历 荐 * 2 + 2甫 茄 荐 父怒 酒捞袍阑 父电促.
int CScenarioDragonItem::DropDragonItem( TKeinList<int> *pLink1, TKeinList<int> *pLink2 )
{
	int max_ch = 0;
	max_ch += pLink1?pLink1->GetCount():0;
	max_ch += pLink2?pLink2->GetCount():0;
	
	if( !max_ch ) return 0;
	
	int item_count_max =  max_ch*2 + 2;
	MakeDragonItem( item_count_max );
	short int *pServerIDBuf;
	pServerIDBuf = new short int[max_ch];
	
	
	int man_count = 0;		// 荤恩 墨款飘 茄促.( 酒捞叼 滚欺俊 淬扁 困秦 )
	int item_count = 0;		// 冻绢柳 酒捞袍 荐甫 墨款飘茄促.
	CHARLIST *ch;
	
	// 茄荤恩 菊俊 窍唱俊辑 笛 沥档狼 酒捞袍阑 冻绢 哆赴促.
	TKeinList<int> *pTarget;
	for( int i=0; i<2; i++ )
	{
		if( i == 0 )
		{
			pTarget = pLink1;
		}
		else
		{
			pTarget = pLink2;
		}
		pTarget ->SetFind();
		while( pTarget->FindNext() )
		{
			pServerIDBuf[man_count] = pTarget->GetFind();
			ch = CheckServerId( pServerIDBuf[man_count] );
			if( !ch ) continue;
			
			int rand_item_count = rand()%2+1;
			for( int i=0; i<rand_item_count; i++ )
			{
				DropItem( ch->X + (rand()%40) - 40, ch->Y + (rand()%40) - 40, &m_pTotalItem[item_count++] );
			}
			man_count++;
		}
	}
	
	// 巢绰 酒捞袍阑 罚待栏肺 荤恩阑 惶酒辑 谎赴促.
	for( ; item_count<item_count_max; item_count++ )
	{
		ch = CheckServerId( pServerIDBuf[rand()%man_count] );
		if( !ch ) continue;
		DropItem( ch->X + (rand()%40) - 40, ch->Y + (rand()%40) - 40, &m_pTotalItem[item_count] );
	}
	
	SAFE_DELETE_ARRAY(pServerIDBuf);
	return 1;
}

//DropItem(	ch->X + (rand()%40) - 40, ch->Y + (rand()%40) - 40, &item);

void SendGetScenarioTime(int port, int cn, k_client_scenario_time_info* pPacket)
{	//< CSD-030723
	if( !g_pDungeonMgr ) return ;
	
	CDungeonBasic *pTemp = g_pDungeonMgr->GetDungeon(pPacket->idDungeon);
		
	if (pTemp == NULL)
	{
		return;
	}

	t_packet packet;
	packet.h.header.type = CMD_SCENARIO_TIME_INFO;
	packet.h.header.size = sizeof(k_server_scenario_time_info);

	CDungeonBasic::VECTOR_START_UP& rList = pTemp->GetStartUpList();

	for (CDungeonBasic::ITOR_START_UP i = rList.begin(); i != rList.end(); ++i)
	{	
		packet.u.kein.server_scenario_time_info.idStartUp = i->idIndex;
		packet.u.kein.server_scenario_time_info.idDungeon = pPacket->idDungeon;
		packet.u.kein.server_scenario_time_info.nApplyDay = i->nApplyDay;
		packet.u.kein.server_scenario_time_info.nStartHour = i->nStartHour;
		packet.u.kein.server_scenario_time_info.nStartMinute = i->nStartMinute;
		packet.u.kein.server_scenario_time_info.nEndHour = i->nEndHour;
		packet.u.kein.server_scenario_time_info.nEndMinute = i->nEndMinute;
	
		if( port == GetOwnPort() )
		{
			QueuePacket( connections, cn, &packet, 1 );
		}
		else
		{
			SendDirectClientOtherMap(CMD_SCENARIO_TIME_INFO, cn, port, 
				                     &packet.u.kein.server_scenario_time_info, 
									 sizeof(k_server_scenario_time_info));
		}
	}
}	//> CSD-030723

void RecvGetScenarioTime( t_packet *p, short int cn )
{	//< CSD-030306
	if( cn == CN_FROM_OTHER_MAPSERVER_MSG )
	{
		int port = p->u.kein.client_scenario_time_info.nPort;
		int server_id = p->u.kein.client_scenario_time_info.nServer_Id;
		SendGetScenarioTime(port, server_id, &p->u.kein.client_scenario_time_info);	// 秦寸甘阑 烹秦辑 焊郴霖促.
	}
	else
	{
		if( g_pDungeonMgr )
		{
			SendGetScenarioTime(GetOwnPort(), cn, &p->u.kein.client_scenario_time_info); // 官肺 焊郴霖促.
		}
		else
		{
			// 咯扁辑 夸没窍绰 辑滚客 蜡历甫 淬酒辑 焊郴 霖促.
			p->u.kein.client_scenario_time_info.nPort = GetOwnPort();
			p->u.kein.client_scenario_time_info.nServer_Id = cn;

			SendPacket2Map(p, MN_SCENARIO_MAP);
		}
	}
}	//> CSD-030306

void RecvChangeScenarioTime( t_packet *p, short int cn )
{	//< CSD-030306
	if( cn == CN_FROM_OTHER_MAPSERVER_MSG )
	{
		if (!g_pDungeonMgr) 
		{
			return;
		}

		CDungeonBasic* pTemp = g_pDungeonMgr->GetDungeon(p->u.kein.scenario_time_change.idDungeon);

		if (pTemp == NULL)
		{
			return;
		}

		pTemp->SetStartUpInfo(p->u.kein.scenario_time_change.idStartUp,
							  p->u.kein.scenario_time_change.nApplyDay,
							  p->u.kein.scenario_time_change.nStartHour,
							  p->u.kein.scenario_time_change.nStartMinute,
							  p->u.kein.scenario_time_change.nEndHour,
							  p->u.kein.scenario_time_change.nEndMinute);
	}
	else
	{
		if( g_pDungeonMgr )
		{
			RecvChangeScenarioTime( p, CN_FROM_OTHER_MAPSERVER_MSG );
		}
		else
		{
			SendPacket2Map( p, MN_SCENARIO_MAP);
		}
	}
}	//> CSD-030306

bool IsActiveDugeon()
{	//< CSD-030428
	if( !g_pDungeonMap ) return false;
	if( g_pDungeonMap->GetActiveDungeonMap() ) return true;
	
	return false;
}	//> CSD-030428

⌨️ 快捷键说明

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