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

📄 npc_pattern.cpp

📁 网络游戏龙族 完整的登陆器 C++ 源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
#include "StdAfx.h"

#include <Stdio.h>
#include "Dragon.h"	

#include "Path.h"
#include "CharDataTable.h"
#include "Hong_Sub.h"
#include "CounSeler.h"
#include "Item.h"

#define __NPC_PATTERN_H__
#include "NPC_Pattern.h"

#include "NetWork.h"
#include "Map.h"
#include "Hong_Sprite.h"

extern NPC_INFO g_infNpc[MAX_CHARACTER_SPRITE_]; // CSD-030419
extern struct CItem_List Item_Ref ;
extern void SendNPCAttack( t_connection c[], int npc );
extern void calcNewAbility(CHARACTER *) ;
extern int  getMaxHungry(CHARACTER *chr) ;
extern void SetDamageOfHero( CHARACTER *ch ); // OP_Chr_Status.cpp
extern ItemAttr GenerateItem( int type, int item_no, DWORD intattr2, int success_rate );
/////////////// 0124 捞痹绕 //////////////////
extern int  calcAC( CHARACTER *ch );
extern int  calcDefenceRate( CHARACTER *ch );
extern void SendViewTypeChange( int cn, int viewtype );


extern void NPC_Pattern_Tammed( CHARACTER *n );
extern void NPC_Pattern_GUARD( LPCHARACTER n);
extern void NPC_Pattern_MAUL( LPCHARACTER n);
extern void NPC_Pattern_8( CHARACTER *n );
extern void NPC_Pattern_SealStone( LPCHARACTER n );

//extern NPCName_by_Gender	NPC_Name_Ref[Num_Of_NPC_Name];
//extern NPC_Info				NPC_Info_Ref[Num_Of_NPC_Type];
//extern NPCLev_to_Exp		NPC_Lev_Ref[Num_Of_NPC_Lev] ;
//extern NPC_Generation		NPC_Gen_Ref[Num_Of_NPC_Generation] ;

extern int writedebug;
extern int g_DontPlayNPC;

/*
#define NPC_PATTERN_NO_MOVE_			  0		// 啊父洒 乐绰促.
#define NPC_PATTERN_HOSTILE_			 10		// 利措利栏肺 官诧促. 
#define NPC_PATTERN_PEACE_				 20		// 乞拳利栏肺 官诧促.
#define NPC_PATTERN_FIND_CLOSE_PC_		 30		// 啊鳖款 pc甫 茫绰促.(弊率阑 官扼夯促. )
#define NPC_PATTERN_FIND_WEAK_PC_		 40		// 距茄  pc甫 茫绰促.(弊率阑 官扼夯促. )
#define NPC_PATTERN_FIND_STRONG_PC_		 50		// 碍茄  pc甫 茫绰促.(弊率阑 官扼夯促. )
#define NPC_PATTERN_ACCESS_PC_			 60		// 茫篮 PC俊 利辟茄促. ( Hostile老版快 傍拜裹困俊 乐栏搁 傍拜茄促. peace老版快 立辟秦档 啊父洒 立辟窍绰仇阑 官扼夯促.  
#define NPC_PATTERN_ACCESS_PC_ATTACKED_	 70		// 唱甫 傍拜茄 Pc俊 立辟茄促. 
#define NPC_PATTERN_WANDER_RANGE_1_		 80		// 硅雀茄促. ( 1锅 硅雀裹困啊 1捞促. )
#define NPC_PATTERN_WANDER_RANGE_2_		 90		// 硅拳茄促. ( 1锅 硅雀裹困啊 2捞促. )
#define NPC_PATTERN_WANDER_RANGE_3_		100  	// 硅拳茄促. ( 1锅 硅雀裹困啊 3捞促. )
#define NPC_PATTERN_ESCAPE_PC_			110		// 茫篮 PC肺 何磐 档噶埃促. 
#define NPC_PATTERN_ESCAPE_BATTLE_PC_	120		// 辟贸俊 傍拜 PC啊 乐栏搁 钢府 档噶埃促. 
*/


////////////////////////////////////////////////////////////////////////////////////////////
///////////   Variables..

int NpcPatternTable[20] = { NPC_PATTERN_HOSTILE_,
							NPC_PATTERN_FIND_CLOSE_PC_,
							NPC_PATTERN_ACCESS_PC_,
							NPC_PATTERN_ATTACK_PC_,
							NPC_PATTERN_BACKDRAW_,
							NPC_PATTERN_RETURN_,		
};


// 0811 NPC KHS
short NPCAccessTable[400][4];



static int movep;





///////////////////////////////////////////////////////////////////////////////////////////////////
///
///				User Function Declarations..
///
void InitMoveDelayTable( void );
int Get_MoveDelayTime( CHARACTER *ch );
int InDistance( CHARACTER *s, CHARACTER *d, int dis );
int NPC_NearRoundCh( CHARACTER *n, CHARACTER *ch, int *x, int *y );
int NPC_NearCh( CHARACTER *n, CHARACTER *ch, int *x, int *y );
int NPC_NearPosition( CHARACTER *n, CHARACTER *c, int *x, int *y );
int NPC_NearBackCh( CHARACTER *n, CHARACTER *ch, int *x, int *y, int dist );
int NPC_GetAttackRange( CHARACTER *n );
int NPC_GetPatternTable( CHARACTER *n );
int NPC_GetDir( int sx, int sy, int ex, int ey );
int NPC_MakePath( CHARACTER *n, int tx, int ty, int how );
int NPC_MakePathBumn( CHARACTER *n, int tx, int ty, int how );
inline bool NPC_IsMoving(CHARACTER *n); // CSD-040107
int NPC_Hostile( CHARACTER *n );
int NPC_StillAttack( CHARACTER *n);
int NPC_IsAttackableRange( CHARACTER *n );
int NPC_IsInBossRange( CHARACTER *n );
int NPC_IsInHostRange( CHARACTER *n );
int NPC_IsWhoNearRedPC( CHARACTER *npc, int tilerange  );
int NPC_IsWhoNearPC( CHARACTER *npc, int tilerange );
int NPC_WhoIsAttackMyBaby( CHARACTER *n );
int NPC_WhoIsBoss( CHARACTER *npc );
int NPC_WhoIsBlocking( int sx, int sy );
CHARACTER *NPC_ReturnCharListPoint( int id );
CHARACTER *ReturnCharListPoint( char *name );
void RecvTameCommand( int cn, t_tame_command *p );
void SendTameResult( int cn, int result  );
void SendHostName( int cn, CHARACTER *n );
void CheckNPCTammingTimeElapsed( CHARACTER *n );
	
	
////////////////////////////////////////////////////////////////////////////////////////////////
////
////			   User Function
////
		

void SendNPC_parameter( int id, int type, int data )
{
	t_packet p;

	p.h.header.type = CMD_SEND_NPC_PARAMETER;

	p.u.send_npc_parameter.id	= id;
	p.u.send_npc_parameter.type	= type;
	p.u.send_npc_parameter.data = data;

	p.h.header.size = sizeof( t_send_npc_parameter );
	
	QueuePacket( &p, 1 );
}

void RecvNPC_parameter(int id, int type, int data)
{	//< CSD-031106
	LPCHARACTER ch = ReturnCharacterPoint(id);
	if (ch == NULL) return;

	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;
		}
	case NPC_PARAMETER_PATTERNTYPE:
		{
			ch->patterntype	= data;
			break;
		}
	case NPC_PARAMETER_OLDPATTERNTYPE:
		{
			ch->oldpatterntype	= data;
			break;
		}
	case NPC_PARAMETER_ATTRIBUTE:
		{
			ch->nAttr = data;
			break;
		}
	}
}	//> CSD-031106

void RecvNPC_stringparameter( int id, int type, char *data )
{
	LPCHARACTER ch = ReturnCharacterPoint( id );
	if( ch == NULL ) return;

	switch( type )
	{
	case NPC_PARAMETER_TARGETNAME	:	strcpy( ch->TargetName, data );
		break;

	default : break;
	}
}	
	
	
	
	
	
int InDistance( CHARACTER *s, CHARACTER *d, int dis )
{	
	if( s == NULL ) return 0;
	if( d == NULL ) return 0;
	
 	if( IsDead( s ) ) return 0;
	if( IsDead( d ) ) return 0;
	
	int sx = s->x;
	int sy = s->y;
	int dx = d->x;
	int dy = d->y;

	if( dis * dis > (dx-sx)*(dx-sx)+(dy-sy)*(dy-sy) ) return 1;
	
	return 0;
}	



void SendModifyPositionNPC( int id )
{
	LPCHARACTER ch = ReturnCharacterPoint( id );

	t_packet p;

	if( ch->patterntype == 0 && ch->HostName[0] == 0 ) return;

	p.h.header.type = CMD_NPC_MODIFY_POS;

		p.u.npc_modify_pos.id = id;
		p.u.npc_modify_pos.mx = ch->x / TILE_SIZE;
		p.u.npc_modify_pos.my = ch->y / TILE_SIZE;

	p.h.header.size = sizeof( t_npc_modify_pos );

	QueuePacket( &p, 1 );
}




void SendNPCChatArea( int id, char *data )
{
	t_packet p;
	int Len;

	if( data == NULL ) return;

	Len = strlen( data );
	if( Len <= 0 ) return;

	p.h.header.type = CMD_NPC_CHAT_DATA;
		p.u.npc_chat_data.id = id;
		strcpy(p.u.npc_chat_data.data, data);
	p.h.header.size = sizeof( t_npc_chat_data ) - TEXT_LENGTH + Len;

	
	QueuePacket( &p, 1 );
}

void SendNPCAttack( int attacker_npc_id )
{
	t_packet	p;
	int			magic_no=0;			//老馆利栏肺 付过阑 备荤窍绰 阁胶磐父 付过 锅龋 何咯


	LPCHARACTER attacker_npc_ch = ReturnCharacterPoint( attacker_npc_id );
	if( attacker_npc_ch == NULL ) return;
	if( attacker_npc_ch->targetid == -1 ) return;
	LPCHARACTER diffender_npc_ch = ReturnCharacterPoint( attacker_npc_ch->targetid );

	
	if( diffender_npc_ch == NULL ) return;

	if( attacker_npc_ch->viewtype == VIEWTYPE_STONE_ ) return;	//001215 KHS
	if( diffender_npc_ch->viewtype == VIEWTYPE_STONE_ ) return;	//001215 KHS
	if( diffender_npc_ch->accessory[0] == 114 )  return;

	//switch(attacker_npc_ch->sprno)
	//{
	//case 40:						//盖胶妮乔攫->拳混幅 惯荤
		//magic_no = 30+rand()%3;
		//break;
	//}

	if( magic_no )							//漂沥 付过阑 备荤绰 NPC牢 版快
	{
		LPCHARACTER		target_ch = ReturnCharacterPoint( attacker_npc_ch->targetid );
		if(target_ch==NULL)		return;
		return;
	}
	
	
	DIRECTION dir;	
	int x, y;		
	int	t_X, t_Y;	
	x = diffender_npc_ch->x;
	y = diffender_npc_ch->y;
	int how;
	
	switch(rand()%6)
	{
	case 0:
	case 1:
	case 2:
		how = 0;
		break;
	case 3:
		how	= 12;
		break;
	case 4:
		how = 18;
		break;
	case 5:
		how = 24;
		break;
	}
	
	ChangeDirection( &dir, attacker_npc_ch->x, attacker_npc_ch->y, x, y );

	switch( dir )
	{
		case DIRECTION_DOWN		:	t_X= 0;		t_Y=how;		break;
		case DIRECTION_LEFTDOWN	:	t_X=-how;	t_Y=how;		break;
		case DIRECTION_LEFT		:	t_X=-how;	t_Y=0;			break;
		case DIRECTION_LEFTUP	:	t_X=-how;	t_Y=-how;		break;
		case DIRECTION_UP		:	t_X= 0;		t_Y=-how;		break;
		case DIRECTION_RIGHTUP	:	t_X=how;	t_Y=-how;		break;
		case DIRECTION_RIGHT	:	t_X=how; 	t_Y=0;			break;
		case DIRECTION_RIGHTDOWN:	t_X=how;	t_Y=how;		break;
		default					:	dir = DIRECTION_SAME; t_X=0;	t_Y=0;		break;
	}

	if( t_X || t_Y )	{	x += t_X;	y += t_Y;	}
	else				{	x =0;		y = 0;		}						//第肺 剐府绰 楷免 老绢唱瘤 臼档废
	{
    p.h.header.type = CMD_NPC_ATTACK;
		p.u.strike.npc_attack.idCaster = WORD(attacker_npc_id);
		p.u.strike.npc_attack.idTarget = WORD(attacker_npc_ch->targetid);
		
		if (FreeTile(diffender_npc_ch, x>>5, y>>5, x>>5, y>>5))			//角力 哎荐 乐绰 瘤痢牢啊?
		{
			p.u.strike.npc_attack.nX = x;
			p.u.strike.npc_attack.nY = y;
		}
		else
		{
			p.u.strike.npc_attack.nX = 0;
			p.u.strike.npc_attack.nY = 0;
		}
		
		p.h.header.size = sizeof( t_npc_attack );
		QueuePacket( &p, 1 );    
  }
}

int NPC_NearPosition( CHARACTER *n, CHARACTER *c, int *x, int *y )
{	
	int dirt[ 5] = { 0,1,-1,-2,2 };
	int d, i, j, tempdir;
	int tx, ty;
	int ttx, tty;
	
	if( IsDead( c ) ) return 0;
	
	// 傍拜 措惑捞 绝绢..
	
	tx = c->x / TILE_SIZE;
	ty = c->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;
}

int NPC_NearRoundCh( 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;
}	

	
// 傍拜措惑俊 措秦 立辟且锭 荤侩等促. 
/*int NPC_NearCh( 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;
	}

	// 傍拜 措惑捞 绝绢..
	if( !connections[n->targetid].socket || connections[n->targetid].state < CONNECT_JOIN ) return 0;
	if( connections[n->targetid].chrlst.bAlive >= DEAD_ ) return 0;

	tx = connections[ n->targetid].chrlst.x / TILE_SIZE;
	ty = connections[ n->targetid].chrlst.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 = 2 ; 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;
}*/
// 父距 格钎某腐捞 捞悼吝捞搁 档崔格钎痢阑 府畔秦霖促. 
// 窜瘤 弊镑狼 辟贸俊 埃促. ( Tamming俊 荤侩等促. )









#define HOME_DIST_1AREA		245
#define HOME_DIST_2AREA		625



int NPC_NearCh( 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( ch == NULL )			return 0;

⌨️ 快捷键说明

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