?? word.cpp
字號:
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(¤tPosition); //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 + -