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

📄 word.cpp

📁 网络游戏龙族 完整的登陆器 C++ 源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
							return 0; // The deal is made.
						else
							return -100; // The deal wasn't good. Nah... I don't want to buy.
					}
					else 
						return -400; // user doesn't have this item. You don't have this item.					
				}
			case 2 :	// command buy.
				{
					//Need function that check inventory of NPC
					// 
					//	辑滚肺 惑痢 府胶飘 何殴~
					//	receive 窍绰 镑俊辑 npc狼 措拳甫 贸府茄促.
					//	npc狼 event_no啊 啊绊 酒捞袍捞 埃促.
					//  罐绰 巴篮 啊拜阑 罐酒柯促. ( true :惑痢俊 弊 酒捞袍捞 粮犁且版快 )
				//	else 
					return -500; // NPC doesn't have this item.
								 // Sorry NPC doesn't have this item.
				}

			case 3 :	// command repair.
				{
					/*if( isThatMyItem( word ) )
					{
						(char*)costs = strtok( text, "\n");

						if(cost <= /*function which returns the price of repair/ * dum)
						{
							return 0; // good deal!
							break;
						}
						else
						{
							return -100; // The deal was not good. You have to pay more...
							break;
						}
					}
					else return -400; //Hey you don't have this item. */ 
					return -400;
				}

			default : return -600; // this command is not availiable.
								// what do yo want?
		}
}

int max_pc_word;			// 泅犁 PC啊 措翠且荐乐绰 巩厘狼 荐
int max_npc_word;			// 泅犁 NPC啊 措翠且荐乐绰 巩厘狼 荐
int max_random_npc_word;		// 泅犁 NPC啊 random栏肺 措翠且荐 乐绰 巩厘荐

//////////////////////////////////////////////////////////////////////////////////////////////
//	傍荤吝
//	Function languageSystem(LPSTR lpStr)
//		Player啊 Non-Event NPC俊霸 富阑 吧菌阑锭, NPC 览翠. 
//////////////////////////////////////////////////////////////////////////////////////////////
void languageSystem( LPSTR lpStr )
{
	int getDistance = 0; // distance from the nearest NPC.
	LPCHARACTER ch = whoIsClose(&getDistance); // nearest NPC.
	// when the player is in certain distance from the NPC. 
	//Event begins.
	//************************************************************************************//
	if( !ch || getDistance > CLOSE_ENOUGH){return;}
	
	if (ch->nRace != HUMAN)	
	{	//< CSD-030419
		return;
	}	//> CSD-030419
	
	if( !start )
	{
		for(int ii=0;ii<5; ii++)
		{
			sprintf(cmd[ii],"%s",lan->OutputMessage(4,ii+171));//010217 lsw
		}
		start = 1;
	}

	int i=0;
	int ret = 0;
	while( *cmd[i] )
	{
		if( strstr( lpStr, cmd[i] ) )
		{
			ret = 1; break;
		}				
		i++;
	}

	if( ret )
	{
		SendEvent( EVENT_TYPE_NPC, ch->id );
	}
	else
	{	
		return;		// 泪矫 哗初澜..
	}
}//end of function languageSystem();

////////////////////////////////////////////////////////////////////////////////////////////////
//	Function CheckNpcTalk()
//	Player啊 NPC辟贸俊 啊鳖捞 吭阑锭 NPC啊 Player俊霸 富阑扒促. 
////////////////////////////////////////////////////////////////////////////////////////////////
void CheckNpcTalk( )
{
	return;
	int realNPC = 0;
	char* fileRandomNPCTalk = "./data/randomTalk.dat";
	int currentPosition;
	LPCHARACTER target = whoIsClose(&currentPosition); //returns closest NPC and the distance.
	
	if (target)
	{
		if (target->nRace != HUMAN)	
		{	//< CSD-030419
			int answerRate = (rand()%((int)(REPLY_RATE))); // Currently 5% // 0905 kkh 荐沥 
			
			if (!max_random_npc_word)
			{
				replyTable(fileRandomNPCTalk, random_npc_word, max_random_npc_word);
			}

			int whichLine = (rand()%max_random_npc_word);
			char* getReply = random_npc_word[whichLine].ReturnWords();
			
			if (getReply && answerRate ==0 && currentPosition < CLOSE_ENOUGH) 
			{
				strcpy( target->szChatMessage, getReply );
				target->ChatDelay = 70; 
			}	
		}	//> CSD-030419
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////
//	傍荤场... Ha Ha ha ^o^
//	Function replyTable()
//		This function Initialize the data into the linked list. 
//		
//////////////////////////////////////////////////////////////////////////////////////////////
void replyTable(char* getFile, CPcWord getWord[], int &max)
{	
	int whichOperation = 0;
	char *getNPCWord;
	char buf[512];
	char *token;
	char delemeter[] = "\t\n";

	FILE *fp;
	
	fp = Fopen(getFile, "rt");
	if(fp)
	{
			max = 0;
//			for(int i = 0; (i < NUM_NPCWORD && !feof(fp)); i++)
			while(fgets( buf, 511, fp ) != NULL )
			{
//				fgets( buf, 511, fp );
				//getWord[i].AddNode( getNPCWord, getOperation );
				token = strtok( buf, delemeter);
				whichOperation = atoi(token);
				token = strtok( NULL, delemeter );
				//token = strtok( buf, "\n");
				getNPCWord = token;
				getWord[max].AddNode(getNPCWord, whichOperation);
				max++;
			}
			fclose(fp);
	}
	
	
}//End of fn() replyTable
//////////////////////////////////////////////////////////////////////////////////////////////
//	Function *ReplyNpc(char)
//		I need data set, pc_word[100] and npc_word[100].
//		They are 100 nodes which include a character.
//		When player asked something NPC answers them...
//		I don't think this will work. Why? if the pc_word = "whaz"		a.com(
//////////////////////////////////////////////////////////////////////////////////////////////
char *ReplyNpc( char *str, CPcWord pc[], CPcWord npc[] )
{
	int random_cmd[100] = {0,};

	for( int i=0; i<max_pc_word; i++ )
	{
		int cmd = pc[i].CompareWord( str );
		if( cmd != -1 )
		{
			int count = 0;
			for( int j=0; j<max_npc_word; j++ )
			{
				if( npc[j].ReplyWords( cmd ) ) 
				{
					random_cmd[count++] = j;
				}
			}
			if( count )
			{
				count = rand()%count;
				return npc[random_cmd[count]].ReturnWords();
			}
		}
	}

	return NULL;
}



///////////////////////////////////////////////////////////////////////////////////////
//Class CPcWord.
///////////////////////////////////////////////////////////////////////////////////////
 
CPcWord::CPcWord()
{
	word = NULL;
	cmd = -1;
}

CPcWord::~CPcWord()
{
	DeleteNode();
}

void CPcWord::AddNode( char *str, int num ) // 眠啊且 窜绢客 疙飞 屈侥
{
	if( word ) delete word;
	int len = strlen( str );
	word = new char[len+1];
	strcpy( word, str );

	cmd = num;
}

void CPcWord::DeleteNode( )
{
	if( word ) delete word;
	cmd = -1;
}
	
int CPcWord::CompareWord( const char *target_str )
{
	if( strstr( target_str, word ) ) return cmd;
	else return -1;
}

char* CPcWord::ReplyWords( int num )
{
	if( num == cmd ) return word;
	else return NULL;
}

char* CPcWord::ReturnWords( )
{ 
	return word;
}





//////////////////////////////////////////////////////////////////////////////////////////////
//	Function whoIsclose(int*, int*)
//		啊厘啊鳖款 芭府俊乐绰 NPC客狼 芭府甫 备窍绊, 弊 NPC甫 return窃.  
//
//////////////////////////////////////////////////////////////////////////////////////////////

LPCHARACTER whoIsClose(int* getDistance)
{	
	LPCHARACTER	ch = Hero->lpNext;
	//////This is for exchanging the value of dot position to tile///////
	POINT	hero_Position;

	int mx=0, my=0;
	MouseClickPosition( &mx, &my );
	hero_Position.x = mx/TILE_SIZE;
	hero_Position.y = my/TILE_SIZE;
	
	int distance=0;
	int currentPosition = 2000000;
	// change the above line to the sum of position where player clicked.

	LPCHARACTER target= NULL;

	// This while-roof finds the closest NPC and the distance between NPC and Player.
	while( ch )
	{
		/**********  烙矫 荤侩吝 SPRITETYPE_NPC  **********************************/
//		if( ch->type == SPRITETYPE_NPC ) // make sure ch is NPC.
		if( ch->type == SPRITETYPE_MONSTER ) // make sure ch is NPC.
		/****************************************************************************/
		{
			POINT	npc_Position;
			npc_Position.x = ch->x/TILE_SIZE;
			npc_Position.y = ch->y/TILE_SIZE;
			distance = abs(hero_Position.x-npc_Position.x)+abs(hero_Position.y-npc_Position.y);//(int)sqrt(pow(hero_Position.x-npc_Position.x,2)+pow(hero_Position.y-npc_Position.y,2));
			
			if( currentPosition > distance ) 
			{
				target = ch;
				currentPosition = distance;
			}
		}
		ch = ch->lpNext;
	}
	*getDistance = currentPosition;
	return target;
}

⌨️ 快捷键说明

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