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

📄 npc_pattern.cpp

📁 网络游戏龙族 完整的登陆器 C++ 源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		
		
	tx = ch->x / TILE_SIZE;
	ty = ch->y / TILE_SIZE;
		
	if( ch->sprno == 0 || ch->sprno == 1 ) // PC扼搁 
	{	
		if( (rand()%100) < 70 )
		{
			tx = ch->gox / TILE_SIZE;
			ty = ch->goy / TILE_SIZE;
		}
	}	


	DWORD area1, area2;

	switch( n->patterntype )
	{
//------------------------------------------------------------------------------------------------------------

	case  NPC_PATTERN_ACCESS_PC_38_		:
	case  NPC_PATTERN_ATTACK_PC_38_		:
	case  NPC_PATTERN_WANDER_38_		:
	case  NPC_PATTERN_MURI_38_			:
	case  NPC_PATTERN_BACKDRAW_PC_38_	:	area1 = (n->x/TILE_SIZE - n->homex)*(n->x/TILE_SIZE - n->homex) + (n->y/TILE_SIZE - n->homey)*(n->y/TILE_SIZE - n->homey);
											area2 = (tx - n->homex)*(tx - n->homex) + (ty - n->homey)*(ty - n->homey);
											if( area1 > HOME_DIST_1AREA )
											{	
												if( area2 > HOME_DIST_2AREA )
												{
													tx = n->homex;
													ty = n->homey;
												}
											}	
								break;
/*
	case NPC_PATTERN_WANDER_8_			:
	case NPC_PATTERN_IAM_BOSS_8_		:
	case NPC_PATTERN_TOBOSS_8_			:
	case NPC_PATTERN_MURI_8_			:`
	case NPC_PATTERN_ACCESS_PC_8_		:
	case NPC_PATTERN_ATTACK_PC_8_		:
	case NPC_PATTERN_BACKDRAW_8_		:	

	case NPC_PATTERN_IAM_BOSS_28_		:
	case NPC_PATTERN_TOBOSS_28_			:
	case NPC_PATTERN_WANDER_28_			:
	case NPC_PATTERN_MURI_28_			:
	case NPC_PATTERN_BACKDRAW_PC_28_	:	

	case  NPC_PATTERN_IAM_BOSS_GUARD_	:
	case  NPC_PATTERN_TOBOSS_GUARD_		:
	case  NPC_PATTERN_WANDER_GUARD_		:
	case  NPC_PATTERN_MURI_GUARD_		:
	case  NPC_PATTERN_ACCESS_PC_GUARD_	:
	case  NPC_PATTERN_ATTACK_PC_GUARD_	:
	case  NPC_PATTERN_BACKDRAW_PC_GUARD_:	

	case NPC_PATTERN_TAME_				:	
	case NPC_PATTERN_EVENTING_MAUL_		:
	case NPC_PATTERN_WANDER_MAUL_		:
		break;
		*/
	}

	*x = n->x / TILE_SIZE;  *y = n->y / TILE_SIZE;
	tempdir = NPC_GetDir( tx, ty, n->x / TILE_SIZE, n->y / TILE_SIZE );
	
	for( j = 1 ; j < 10 ; j ++)
	{		
		for( i = 0 ;  i < 5 ; i ++)
		{	
			ttx = tx;	tty = ty;
			d = ( tempdir + 8 + dirt[i] ) %8;
			switch( d )
			{
				case 0 :			tty +=j; break;
				case 1 : ttx -=j;	tty +=j; break;
				case 2 : ttx -=j;			 break;
				case 3 : ttx -=j;	tty -=j; break;
				case 4 :			tty -=j; break;
				case 5 : ttx +=j;	tty -=j; break;
				case 6 : ttx +=j;			 break;
				case 7 : ttx +=j;	tty +=j; break;
			}
			if( FreeTile( n, n->x / TILE_SIZE, n->y / TILE_SIZE, ttx, tty ) )  
			{
				*x = ttx;  *y = tty;
				return 1;
			}
		}	
	}		
			
	return 0;
}







#define TILE_BLOCK_SIZE  11


BYTE TileBlock[ TILE_BLOCK_SIZE][ TILE_BLOCK_SIZE] = {
	{ 0,0,0,0,1,1,1,0,0,0,0 },
	{ 0,0,1,1,1,1,1,1,1,0,0 },
	{ 0,1,1,1,1,1,1,1,1,1,0 },
	{ 0,1,1,1,1,1,1,1,1,1,0 },
	{ 1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,1,1,1,1,1,1,1,1,1,1 },
	{ 0,1,1,1,1,1,1,1,1,1,0 },
	{ 0,1,1,1,1,1,1,1,1,1,0 },
	{ 0,0,1,1,1,1,1,1,1,0,0 },
	{ 0,0,0,0,1,1,1,0,0,0,0 }};

BYTE TileBlockBuf[ TILE_BLOCK_SIZE][ TILE_BLOCK_SIZE];

void GetTileBlock( int x, int y )
{

	int sx, sy, ex, ey;

	sx = x - (TILE_BLOCK_SIZE / 2 );
	sy = y - (TILE_BLOCK_SIZE / 2 );
	ex = x + (TILE_BLOCK_SIZE / 2 );
	ey = y + (TILE_BLOCK_SIZE / 2 );

	
	for( ; sx <= ex ; sx ++ )
	{
		for( ; sy <= ey ; sy ++ )
		{

		}
	}
}


void PutTileBlock( int x, int y, int xl, int yl )
{
}



// 林狼俊 欺柳 困摹甫 茫绰促. 
int NPC_NearChPart( CHARACTER *n, CHARACTER *ch, int *x, int *y )
{
	int dirt[ 5] = { 0,1,-1,-2,2 };
	int d, i, j, tempdir;
	int tx, ty;
	int ttx, tty;

	if( n->targetid == -1 ) 
	{
		n->targetid = NPC_IsWhoNearPC( n, 10 );
		if( n->targetid == -1 )  return 0;
	}

	// 傍拜 措惑捞 绝绢..
	LPCHARACTER tch = ReturnCharacterPoint( n->targetid );
	if( IsDead( tch ) ) return 0;

	tx = tch->x / TILE_SIZE;
	ty = tch->y / TILE_SIZE;
	*x = n->x / TILE_SIZE;  *y = n->y / TILE_SIZE;
	tempdir = NPC_GetDir( tx, ty, n->x / TILE_SIZE, n->y / TILE_SIZE );
	
	for( j = 1 ; j < 10 ; j ++)
	{
		for( i = 0 ;  i < 5 ; i ++)
		{
			ttx = tx;	tty = ty;
			d = ( tempdir + 8 + dirt[i] ) %8;
			switch( d )
			{
			case 0 :			tty +=j; break;
			case 1 : ttx -=j;	tty +=j; break;
			case 2 : ttx -=j;			 break;
			case 3 : ttx -=j;	tty -=j; break;
			case 4 :			tty -=j; break;
			case 5 : ttx +=j;	tty -=j; break;
			case 6 : ttx +=j;			 break;
			case 7 : ttx +=j;	tty +=j; break;
			}
			if( FreeTile( n, n->x / TILE_SIZE, n->y / TILE_SIZE, ttx, tty ) )  
			{
				*x = ttx;  *y = tty;
				return 1;
			}
		}
	}
	return 0;
}	
	
	
// 泅犁困摹俊辑 dist鸥老父怒  第肺 狐柳促. 
int NPC_NearBackCh( CHARACTER *n, CHARACTER *ch, int *x, int *y, int dist )
{	
	int dirt[ 5] = { 0,1,-1,-2,2 };
	int d, i, j, tempdir;
	int tx, ty;
	int ttx, tty;
	
	if( n->targetid == -1 ) 
	{
//		n->targetid = NPC_IsWhoNearPC( n, 10  );
//		if( n->targetid == -1 )  
		return 0;
	}
	
	// 傍拜 措惑捞 绝绢..
	LPCHARACTER tch = ReturnCharacterPoint( n->targetid );
	if( IsDead( tch ) ) return 0;

	tx = tch->x / TILE_SIZE;
	ty = tch->y / TILE_SIZE;
	*x = n->x / TILE_SIZE;  *y = n->y / TILE_SIZE;
	tempdir = NPC_GetDir( tx, ty, n->x / TILE_SIZE, n->y / TILE_SIZE );
	
 	switch( tempdir )
	{
		case 0 :			ty +=dist;	break;
		case 1 : tx -=dist;	ty +=dist;	break;
		case 2 : tx -=dist;				break;
		case 3 : tx -=dist;	ty -=dist;	break;
		case 4 :			ty -=dist;	break;
		case 5 : tx +=dist;	ty -=dist;	break;
		case 6 : tx +=dist;				break;
		case 7 : tx +=dist;	ty +=dist;	break;
	}
	
	for( j = 0 ; j < 10 ; j ++)
	{
		for( i = 0 ;  i < 5 ; i ++)
		{
			ttx = tx;	tty = ty;
			d = ( tempdir + 8 + dirt[i] ) %8;
			switch( d )
			{
			case 0 :			tty +=j; break;
			case 1 : ttx -=j;	tty +=j; break;
			case 2 : ttx -=j;			 break;
			case 3 : ttx -=j;	tty -=j; break;
			case 4 :			tty -=j; break;
			case 5 : ttx +=j;	tty -=j; break;
			case 6 : ttx +=j;			 break;
			case 7 : ttx +=j;	tty +=j; break;
			}

			if( FreeTile( n, n->x / TILE_SIZE, n->y / TILE_SIZE, ttx, tty ) )  
			{
				*x = ttx;  *y = tty;
				return 1;
			}
		}
	}
	
	return 0;
}	
	
	
	
	
//	立辟 芭府 
int NPC_GetAttackRange( CHARACTER *n )
{	
	// 唱吝俊 Table蔼栏肺 措摹......
	switch( n->sprno )
	{
	case 8 :	return 50 * 50 * 2;
	case 38 :	return 80 * 80 * 2;
	default : 	return 80 * 80 * 2; 
	}
}	
	
	
	
int NPC_GetPatternTable( CHARACTER *n )
{	
	if( n->patterntype >= 20 ) n->patterntype = 0;
	return NpcPatternTable[n->patterntype];
}	
/********************
      3  4  5 
       \ | /
    2- sx,sy -6
       / | \ 
	  1  0  7   
*********************/		 
int NPC_GetDir( int sx, int sy, int ex, int ey )
{	
	if( sx > ex )  // 1/2/3
	{
		if( sy > ey )		return 3;
		else if( sy < ey )	return 1; 
		else				return 2;
	}
	else if( sx < ex ) // 5/6/7
	{
		if( sy > ey )		return 5;
		else if( sy < ey )	return 7; 
		else				return 6;
	}
	else 
	{
		if( sy > ey )		return 4;
		else if( sy < ey )	return 0;
	}
		
	return -1;
}		
			
	
	
	
	
/*	
	
int NPC_MakePath( CHARACTER *n, int tx, int ty, int how = 0 )
{		
	int dir;
	int c, i;
	int nx, ny, px, py;
		
	n->tx = tx;
	n->ty = ty;
	n->how = how;
	
	if( n->pathcount < 2 )
	{
		if( PathBuild( n, tx, ty ) == false ) { return 0; }
	
		int bOdd = 0;
	
		if( n->pathcount )
		{
			px = n->path[ n->pathcount -1][0];
			py = n->path[ n->pathcount -1][1];
	
			c = 0;
			for( i = n->pathcount -2 ; i >= 0 ; i -- )
			{		
				nx = n->path[i][0];
				ny = n->path[i][1];
					
				if( nx > px ) 
				{	
					if( ny > py )		{ dir = 7; }
					else if( ny < py )	{ dir = 5; }
					else				{ dir = 6; }
				}	
				else if( nx < px )
				{	
					if( ny > py )		{ dir = 1; }
					else if( ny < py )	{ dir = 3; }
					else				{ dir = 2; }
				}	
				else 
				{	
					if( ny > py )		{ dir = 0; }
					else				{ dir = 4; }
				}	
	
	
				if (  bOdd == 0){	n->MoveDirTbl[ (c/2) ] = dir << 4;	}
				else			{	n->MoveDirTbl[ (c/2) ] += dir;		}
				c++;
				bOdd = !bOdd;
				px = nx;
				py = ny;
			}
	
			n->MoveLength		= c;
			n->pathcount	= 0;
			n->MoveGox			= tx * TILE_SIZE + 16 -5 + Random(10);
			n->goy			= ty * TILE_SIZE + 16 -5 + Random(10);
			n->WalkTime			= g_ClientTime; // ::timeGetTime();
			n->MoveType			= 0;
	
			
			return 1;
		}
	
		return 0;
	}		
	
	
	return 0;
}				
	
	
*/	
	

					
						
// 格利瘤啊 利寸茄镑牢磊 酒囱瘤甫 Check茄促. 
// NPC绰 巩辟贸俊 汲荐 绝促. 

// 哎荐 绝绰镑捞搁 0阑 府畔茄促. 
bool CheckDestinationOk( int tx, int ty )
{					
	LPITEMGROUND  i = g_Item;

	return 1;
					
	while( i != NULL )
	{				
		switch( i->type )
		{			
		case ITEMTYPE_DOOR : 
			{		
				if( Distance( i->x, i->y, tx, ty ) < 18432 ) //鸥老 3俺 瞒捞...
				{	
//					return 0;
				}	
			}		

		}			
		i = i->next;
	}	

	return 1;

}		
					
int NPC_MakePath( CHARACTER *n, int tx, int ty, int how = 0 )
{					
	CHARACTER t;
	// 酒贰 惑怕俊辑绰 捞悼捞 阂啊瓷
  if (n->condition&CON_STONE)   return 0;
	if (n->eventnpc)              return 0;

	if( CheckDestinationOk( tx * TILE_SIZE, ty * TILE_SIZE ) == 0 ) return 0;

	static DWORD time;
	static int   count;
	static DWORD addtime;
	static DWORD temptime;

	time = ::timeGetTime();


			
	memcpy( &t, n , sizeof( CHARACTER ) );
	t.moveFlag = TRUE;
	t.movetype = 0;
	t.gox = tx * TILE_SIZE + 16;
	t.goy = ty * TILE_SIZE + 16;
	t.destx = tx, t.desty = ty;

	n->MoveP	= 0;

	if ( PathBuild( &t ) )
	{	
			t.moveFlag = FALSE;
			t.movetype += 100;
			SendMoveData( &t );	
			t.movetype -= 100;

			temptime =  ::timeGetTime() - time;
			addtime += temptime;
			count ++;

			// 010414 KHS deletion for "temptime.txt" file generation...
			//fp = Fopen( "temptime.txt", "at+" );
			//fprintf( fp, "%3d  : %5d    %d \n", count, addtime, addtime / count );
			//fclose(fp);
		
			return 1;
	}		
	
	n->MoveP	= 0;

			temptime =  ::timeGetTime() - time;
			addtime += temptime;
			count ++;

			// 010414 KHS deletion for "temptime.txt" file generation...
			//fp = Fopen( "temptime.txt", "at+" );
			//fprintf( fp, "%3d  : %5d    %d \n", count, addtime, addtime / count );
			//fclose(fp);

	return 0;
}
	
	
	
/*	
int NPC_MakePath( CHARACTER *n, int tx, int ty, int how = 0 )
{		
	int dir;
	int c, i;
	int nx, ny, px, py;


	if( g_block_move )
	{
		return 0;
	}

	n->destx = tx;
	n->desty = ty;
	n->how = how;
	if( n->pathcount < 2 )
	{
		if( PathBuild( n, tx, ty ) == false ) { return 0; }
	
		int bOdd = 0;
	
		if( n->pathcount )
		{
			px = n->path[ n->pathcount -1][0];
			py = n->path[ n->pathcount -1][1];
	
			c = 0;
			for( i = n->pathcount -2 ; i >= 0 ; i -- )
			{		
				nx = n->path[i][0];
				ny = n->path[i][1];
					
				if( nx > px ) 
				{	
					if( ny > py )		{ dir = 7; }
					else if( ny < py )	{ dir = 5; }
					else				{ dir = 6; }

⌨️ 快捷键说明

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