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

📄 npc_pattern.cpp

📁 国内著名网络游戏dragon的服务端完整源码 内附完整数据库结构
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		{		
			n->TargetName[0] = 0;
			SendTameResult( cn, TAME_NO_NAME_CHAR ); return;
		}		
		else	
		{		
			ch = ReturnCharListPoint( p->toname );	// 傍拜 措惑阑 茫绰促. 

			if (ch == n)
			{	//< CSD-031106
				return;
			}	//> CSD-031106

			if( ch == NULL )	// 傍拜措惑捞 绝栏搁.
			{	
				n->TargetName[0] = 0;
				SendTameResult( cn, TAME_NO_CHAR ); return;
			}	
			else	// 傍拜措惑阑 茫疽促 !
			{	
				if( ch->SprType == SPRITETYPE_NPC ) 
				{
					n->targetid = ch->GetServerID() + 10000;
					SendNPC_Parameter( n->GetServerID(), NPC_PARAMETER_TARGETID, n->targetid );
				}
				else 
				{
					n->targetid = ch->GetServerID();
					SendNPC_Parameter( n->GetServerID(), NPC_PARAMETER_TARGETID, n->targetid );
				}
				
				n->tame_cmd = LC_TAME_ATTACK;
				SendNPC_Parameter( n->GetServerID(), NPC_PARAMETER_TAME_CMD, LC_TAME_ATTACK );
				strcpy( n->TargetName, p->toname );
				SendTameResult( cn, TAME_ATTACK	); 
				SendNPC_StringParameter( n->GetServerID(), NPC_PARAMETER_TARGETNAME, n->TargetName );
				
				return;
			}
		}		
		break;						
	case LC_TAME_FOLLOWME :		ch = ReturnCharListPoint( n->HostName );
		if( ch )
		{
			n->HostId = ch->GetServerID();
			n->tame_cmd = LC_TAME_FOLLOWME;
			SendNPC_Parameter( n->GetServerID(), NPC_PARAMETER_HOSTID, n->HostId );
			SendNPC_Parameter( n->GetServerID(), NPC_PARAMETER_TAME_CMD, LC_TAME_FOLLOWME );
			
			if( n->patterntype != NPC_PATTERN_TAME_ )
			{
				n->oldpatterntype = n->patterntype;
				n->patterntype = NPC_PATTERN_TAME_;
				SendNPC_Parameter( n->GetServerID(), NPC_PARAMETER_OLDPATTERNTYPE,	n->oldpatterntype );
				SendNPC_Parameter( n->GetServerID(), NPC_PARAMETER_PATTERNTYPE,		n->patterntype );
			}
			SendTameResult( cn, TAME_FOLLOW );
			return;
		}
		else
		{
			return;
		}
		break;
		
	case LC_TAME_STOP :			n->tame_cmd = LC_TAME_STOP;
		//2001/02/18 zhh
		if( n->patterntype != NPC_PATTERN_TAME_ )
		{
			n->oldpatterntype = n->patterntype;
			n->patterntype = NPC_PATTERN_TAME_;
			SendNPC_Parameter( n->GetServerID(), NPC_PARAMETER_OLDPATTERNTYPE,	n->oldpatterntype );
			SendNPC_Parameter( n->GetServerID(), NPC_PARAMETER_PATTERNTYPE,		n->patterntype );
			SendNPC_Parameter( n->GetServerID(), NPC_PARAMETER_TAME_CMD, LC_TAME_STOP );
		}
		else 
		{
			SendNPC_Parameter( n->GetServerID(), NPC_PARAMETER_TAME_CMD, LC_TAME_STOP );
		}
		SendTameResult( cn, TAME_STOP );	return;
		break;
	}	
}

void SendTameResult( int cn, int result  )
{	
	t_packet p;
	
	p.h.header.type = CMD_TAME_COMMAND_RESULT;
	p.u.tame_command_result.result = result;
	p.h.header.size = sizeof( t_tame_command_result );
	
	QueuePacket( connections, cn, &p, 1 );
}	

void SendHostName( int cn, CHARLIST *n )
{
	t_packet p;
	
	p.h.header.type= CMD_TAME_HOST_NAME;
	p.u.tame_host_name.id = n->GetServerID() + 10000;
	strcpy( p.u.tame_host_name.hostname, n->HostName );
	p.h.header.size = sizeof( t_tame_host_name );
	
	QueuePacket( connections, cn, &p, 1 );
}
void SendToAllHostName( int cn, CHARLIST *n )
{
	t_packet p;
	
	p.h.header.type= CMD_TAME_HOST_NAME;
	p.u.tame_host_name.id = n->GetServerID() + 10000;
	strcpy( p.u.tame_host_name.hostname, n->HostName );
	p.h.header.size = sizeof( t_tame_host_name );
	
	QueuePacket( connections, cn, &p, 1 );
	CastMe2Other( cn, &p );
}


void SendHostEnd( int npc_id )
{
	t_packet p;
	
	p.h.header.type= CMD_TAME_END;
	p.u.tame_end.id = npc_id + 10000;
	p.h.header.size = sizeof( t_tame_host_name );
	CastNPC2Other( npc_id, &p );
}

void CheckNPCTammingTimeElapsed( CHARLIST *ch )
{		
	//	矫埃瘤巢俊 蝶扼 Tamming憋捞绰 何盒..
	
	if( ch->tame > 0 ) 
	{	
		ch->tamingcountdown --;
		if( ch->tamingcountdown <= 0 ) 
		{
			ch->tame --;
			if( ch->tame <= NPC_Gen_Ref[ch->SprNo].Taming_min )
			{
				ch->SetTamed(false);
				ch->HostName[0] = 0;
				ch->tame_cmd = LC_TAME_STOP;
				ch->patterntype = ch->oldpatterntype;
				SendHostEnd( ch->GetServerID());
				SendNPC_Parameter( ch->GetServerID(), NPC_PARAMETER_TAME_CMD,		ch->tame_cmd );
				SendNPC_Parameter( ch->GetServerID(), NPC_PARAMETER_PATTERNTYPE,	ch->patterntype );
			}
			ch->tamingcountdown = 15;
		}
	}	
}		





//-----------------  Smile Face...

void RecvSmileFace( int cn, int smileno )
{		
	t_packet p;
	
	if(	connections[cn].chrlst.viewtype == VIEWTYPE_GHOST_ ) return;
	
	p.h.header.type = CMD_SMILE_FACE;
	p.u.server_smile_face.id		= cn;
	p.u.server_smile_face.smileno	= smileno;
	p.h.header.size = sizeof( t_server_smile_face );
	
	
	//	QueuePacket( connections, cn, &p, 1 );
	CastMe2Other( cn, &p );
}	

/*//////////////////////////////////////////////////////////////////////

  2000.2.5
  
	1. NPC啊 瘤贺俊 啊妨咙.
	42锅 拳捞锅.
	54锅 刀荐府.
	
//////////////////////////////////////////////////////////////////////// */

///	  	NPC甫 PC俊辑 包府茄促. 
void SendNPCControlData( int cn, int npc )
{															
	t_packet p;	
	int type, size;
	LPCHARLIST n;									
	
	
	//	return;
	
	n = &NPCList[ npc];							
	
	switch( NPCList[ npc].patterntype )		
	{										
	case NPC_PATTERN_MURI_8_		:	type = CMD_NPCCTRL_MURI_8;	
		p.u.npcctrl_muri_8.id				= npc + 10000;
		p.u.npcctrl_muri_8.bossid			= n->bossid;
		p.u.npcctrl_muri_8.Exp				= n->Exp;
		p.u.npcctrl_muri_8.oldpatterntype	= n->oldpatterntype;
		p.u.npcctrl_muri_8.patterntype	= n->patterntype;
		size = sizeof( t_npcctrl_muri_8 );
		break;
		
	case NPC_PATTERN_MURI_28_		:	type = CMD_NPCCTRL_MURI_28;		
		p.u.npcctrl_muri_28.id				= npc + 10000;
		p.u.npcctrl_muri_28.bossid			= n->bossid;
		p.u.npcctrl_muri_28.Exp				= n->Exp;
		p.u.npcctrl_muri_28.oldpatterntype	= n->oldpatterntype;
		p.u.npcctrl_muri_28.patterntype	= n->patterntype;
		size = sizeof( t_npcctrl_muri_28 );	 
		break;
		
	case NPC_PATTERN_WANDER_MAUL_	:	type = CMD_NPCCTRL_WANDER_MAUL;				
		p.u.npcctrl_wander_maul.id				= npc + 10000;			
		p.u.npcctrl_wander_maul.oldpatterntype	= n->oldpatterntype;
		p.u.npcctrl_wander_maul.patterntype	= n->patterntype;
		size = sizeof( t_npcctrl_wander_maul );	 
		break;
		
	case NPC_PATTERN_NO_MOVE_		:	type = CMD_NPCCTRL_NO_MOVE;		
		p.u.npcctrl_no_move.id					= npc + 10000;
		p.u.npcctrl_no_move.oldpatterntype		= n->oldpatterntype;
		p.u.npcctrl_no_move.patterntype			= n->patterntype;
		size = sizeof( t_npcctrl_no_move );	 
		break;
		
		
	case NPC_PATTERN_WANDER_GUARD_	:	type = CMD_NPCCTRL_WANDER_GUARD;	
		p.u.npcctrl_wander_guard.id				= npc + 10000;
		p.u.npcctrl_wander_guard.oldpatterntype= n->oldpatterntype;
		p.u.npcctrl_wander_guard.patterntype	= n->patterntype;
		size = sizeof( t_npcctrl_wander_guard );	 
		break;
		
	case NPC_PATTERN_WANDER_38_		:	type = CMD_NPCCTRL_WANDER_38;				 
		p.u.npcctrl_wander_38.id				= npc + 10000;
		p.u.npcctrl_wander_38.oldpatterntype	= n->oldpatterntype;
		p.u.npcctrl_wander_38.patterntype		= n->patterntype;
		p.u.npcctrl_wander_38.bossid			= n->bossid;
		
		size = sizeof( t_npcctrl_wander_38 );
		break;
		
	case NPC_PATTERN_TAME_			:	type = CMD_NPCCTRL_TAME;
		p.u.npcctrl_tame.id						= npc + 10000;
		p.u.npcctrl_tame.oldpatterntype			= n->oldpatterntype;
		p.u.npcctrl_tame.patterntype			= n->patterntype;		
		p.u.npcctrl_tame.HostId					= n->tame_cmd;
		p.u.npcctrl_tame.tame					= n->tame;
		p.u.npcctrl_tame.tame_cmd				= n->tame_cmd;
		
		strcpy( (char *)(p.u.npcctrl_tame.TargetName),	n->TargetName );
		size = sizeof( t_npcctrl_wander_38 );
		break;
		
	case NPC_PATTERN_SEALSTONE_NO_OPERATE_	:	
		type = CMD_NPCCTRL_SEALSTONE_;	
		p.u.npcctrl_sealstone.id				= npc + 10000;
		p.u.npcctrl_sealstone.patterntype		= n->patterntype;
		size = sizeof( t_npcctrl_sealstone );	 
		break;
		
	default : return;
	}
	
	p.h.header.type = type;
	p.h.header.size = size;
	QueuePacket( connections, cn, &p, 1 );
	
}	

int ManageNPC(  int i )
{			
	int mx,my;
	int sx, sy;
	int ex, ey;
	int range = 18;
	int id;
	int ctrlpc;					
	
	
	//	return 0;
	
	//	for( i = 0 ; i < MAX_NPC_LIST; i ++)
	{							
		ctrlpc = 0;				
		if( NPCList[i].bAlive != ALIVE_ ) return 0;
		
		mx = NPCList[i].MoveSx;	
		my = NPCList[i].MoveSy;	
		sx = mx - range;	if( sx < 0 ) sx = 0;
		ex = mx + range;	if( ex >= g_Map.file.wWidth ) ex = g_Map.file.wWidth-1;
		sy = my - range;	if( sy < 0 ) sy = 0;
		ey = my + range;	if( ey >= g_Map.file.wHeight) ey = g_Map.file.wHeight-1;
		
		if( NPCList[i].ctrlpc )	
		{						
			id = NPCList[i].ctrlpc;
			if( connections[id].dwAgentConnectionIndex && connections[id].state >= CONNECT_JOIN)
			{					
				if( BoxAndDotCrash( sx, sy, range+range, range+range, connections[id].chrlst.MoveSx,  connections[id].chrlst.MoveSy ) )
				{				
					ctrlpc = 1;	
				}				
			}					
		}
		
		if( ctrlpc )		
		{	
			
		}	
		else		// 磊脚	阑 Control窍绰 PC啊 绝促. 
		{	
		/*			NPCList[i].ctrlpc = -1;	
		for( ; sx <= ex ; sx ++ )
		{
		for( tsy = sy ; tsy < ey ; tsy ++)
		{
		t = Floor[ sx][ tsy];
		while( t )
		{
		if( t->Type == SPRITETYPE_NONE )
		{			
		tempctrlnpc = connections[ t->ID].chrlst.ctrlnpc;
		
		  for( j = 0 ; j < 3 ; j ++)
		  {		
		  if( *( tempctrlnpc + j ) == -1 ) 
		  {	
		  SendNPCControlData( t->ID, i );
		  *( tempctrlnpc + j ) = i;
		  NPCList[i].ctrlpc = t->ID;
		  return TRUE;
		  }	
		  }		
		  }			
		  t = t->next;
		  }				
		  }					
		  }						
			*/
		}							
	}									
	
	return FALSE;
}

// 0 <= id < MAX_NPC_LIST
void SendNPC_Parameter( int id, int type, int data )
{
	t_packet p;
	int ctrlpc = NPCList[ id].ctrlpc;
	
	if( ctrlpc == -1 )	return;
	p.h.header.type = CMD_SEND_NPC_PARAMETER;
	p.u.send_npc_parameter.id = id + 10000;
	p.u.send_npc_parameter.type = type;
	p.u.send_npc_parameter.data	= data;
	p.h.header.size = sizeof( t_send_npc_parameter );
	
	QueuePacket( connections,  ctrlpc, &p, 1 );
}		


void SendNPC_StringParameter( int id, int type, char *data )
{	
	t_packet p;
	
	int ctrlpc = NPCList[ id].ctrlpc;
	if( ctrlpc == -1 )	return;
	
	if( data == NULL ) return;
	if( *data == 0 ) return;
	if( strlen( data ) == 0 ) return;
	
	p.h.header.type		= CMD_SEND_NPC_STRING_PARAMETER;
	p.u.send_npc_string_parameter.id		= id + 10000;
	p.u.send_npc_string_parameter.type		= type;
	strcpy( p.u.send_npc_string_parameter.data, data );
	p.h.header.size = sizeof( t_send_npc_string_parameter) - 31 + strlen( data );
	
	QueuePacket( connections,  ctrlpc, &p, 1 );
}	


void RecvNPC_Parameter( int id, int type, int data )
{
	if( id < 10000 )	return;
	
	LPCHARLIST ch = &NPCList[ id-10000];
	
	switch( type )
	{
	case NPC_PARAMETER_TARGETID	:	ch->targetid= data;	break;
	case NPC_PARAMETER_BOSSID	:	ch->bossid	= data;	break;
	case NPC_PARAMETER_HOSTID	:	ch->HostId	= data;	break;
	case NPC_PARAMETER_TAME_CMD	:	ch->tame_cmd= data;	break;
	}
}	

void RecvNPC_StringParameter( int id, int type, char *data )
{
	if( id < 10000 )	return;
	LPCHARLIST ch = &NPCList[ id-10000];
	
	switch( type )
	{
	case NPC_PARAMETER_TARGETNAME	:	strcpy( ch->TargetName, data );
	default : break;
	}	
}		


void RecvMoveNear( int cn, int gox, int goy )
{		
	
}	

///////////////////////////////////////////////////////////////////////
// 瘤陛	鳖瘤 葛电巴篮 Client俊辑 贸府秦辑 家胶甫 眠啊且老捞 绝菌促.
void Recv_JustAni( t_packet *p )
{		
	if( p->u.just_ani.id >= 10000 )
	{	
		CastNPC2Other( p->u.just_ani.id - 10000, p );
	}	
	else 
	{	
		QueuePacket( connections, p->u.just_ani.id, p, 1 );
		CastMe2Other( p->u.just_ani.id, p );
	}	
}		

void RecvCMD_MOVE(const int cn,t_packet *packet)
{	
	if( g_block_move ){return;}
	
	const int dummysize = sizeof(t_client_move);
	t_client_move * p = &packet->u.client_move;
	
	if( p->movetype >= 100 )	// 碍力肺 捞悼茄促. ( 款康磊侩 )
	{
		p->movetype -=100;
	}
	
	const int id = p->server_id;
	LPCHARLIST ch = NULL;
	if( id >= 10000 )	
	{
		if( id-10000 < MAX_NPC_LIST ) 
		{
			ch = ::CheckNpcId(id - 10000);
			if(!ch){return;}
			
			if( ch->eventno > 0 )
			{
				::MyLog( LOG_NORMAL, "####  Cracking : Event Char Move  ID:%s ", connections[cn].id );
				return;
			}
		}
		else
		{
			::MyLog( LOG_NORMAL, "####  Cracking : Event Char Move  ID:%s NPCList[%d] ", connections[cn].id, id - 10000 );
			return;
		}
	}
	else			
	{
		ch = ::CheckServerId(cn);
		if(!ch){return;}
		ch->attackedblock = 0; 
	}
	
	if( p->sx < 0 || p->sx >= g_Map.file.wWidth ||
		p->sy < 0 || p->sy >= g_Map.file.wHeight )
	{	
		MyLog( LOG_NORMAL, "####  Cracking : RecvCMD_MOVE"
			"\nip:%s ID:%s(%s) MapSize(%d:%d) Packet(%d:%d)", 
			connections[cn].ip_address, connections[cn].id, ch->Name,
			g_Map.file.wWidth, g_Map.file.wHeight, p->sx, p->sy);
		return;
	}
	
	if (ch->CalcMovePower() <= 0){return;}
	
	ch->MoveLength				= (short int)p->length;
	ch->MoveType				=  p->movetype;		
	
	::SetTileOccupied(ch->MoveSx,ch->MoveSy,false);
	
	ch->OldMoveSx	= ch->MoveSx;
	ch->OldMoveSy	= ch->MoveSy;					
	
	short iNewMoveSX =(short int)p->sx;
	short iNewMoveSY =(short int)p->sy;
	ch->MoveSx		= iNewMoveSX;	
	ch->MoveSy		= iNewMoveSY;
	
	::SetTileOccupied(iNewMoveSX,iNewMoveSY,true);
	
	memcpy(ch->MoveDirTbl, p->dir_tbl, ch->MoveLength);
	
	ch->MoveGox					= (short int)p->gox;
	ch->MoveGoy					= (short int)p->goy;
	ch->MovePathCount			= 0;				
	
	ch->X = ch->MoveSx * TILE_SIZE + 16;			
	ch->Y = ch->MoveSy * TILE_SIZE + 16;			
	ch->WalkTime = timeGetTime();					
	
	packet->h.header.type = CMD_MOVE;
	
	if( id >= 10000 )
	{	
		SettingMoveData_( id, ch, packet );
		CastNPC2Other( id-10000,  packet);
	}	
	else 
	{	
		::SettingMoveData_( cn, ch, packet );
		::QueuePacket(connections, cn, packet, 1);
		::CastMe2Other( cn, packet);
		
		if( ch->Status )	// 0405 YGI	// 泪磊绊 乐绰 惑怕促...
		{
			::SendServerWeakUp( cn );		// 柄绢唱具窃
		}
	}
}

⌨️ 快捷键说明

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