npc_quiz.c
来自「石器时代6.0源代码 2008.08.27最新版 完全可编译开服!」· C语言 代码 · 共 1,326 行 · 第 1/3 页
C
1,326 行
CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER1 + j,-1); }else{ okflg = TRUE; } break; } } } if(okflg == TRUE) break; } if(okflg ==FALSE){// print("\n %s %d开放",CHAR_getChar(talker,CHAR_NAME),(int)PLAYER.ptr); free(PLAYER.ptr); CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER1 + j,-1); } } return -1;}BOOL QUIZ_initQuiz( char *filename){ FILE* f; char line[512]; char buf2[512], buf3[128]; char buf[512]; int i, linenum=0; f = fopen(filename,"r"); if( f == NULL ){ print( "file open error\n"); return FALSE; } while( fgets( line, sizeof( line ), f ) ){ if( line[0] == '#' )continue; if( line[0] == '\n' )continue; chomp( line ); linenum ++; quizcnt++; } if( fseek( f, 0, SEEK_SET ) == -1 ){ fprint( "Seek Error\n" ); fclose(f); return FALSE; } Quiz = allocateMemory( sizeof(NPC_QUIZ) * (quizcnt+1) ); if( Quiz == NULL ){ fprint( "Can't allocate Memory %d\n", sizeof(Quiz) * (quizcnt+1)); fclose( f ); return FALSE; } linenum = 0; memset( buf3, 0, sizeof(buf3)); while( fgets( line, sizeof( line ), f ) ){ if( line[0] == '#' )continue; if( line[0] == '\n' )continue; chomp( line ); replaceString( line, '\t' , ' ' ); for( i = 0; i < strlen( line); i ++) { if( line[i] != ' ' ) { break; } strcpy( buf, &line[i]); } if( i != 0 ) { strcpy( line, buf); } if( getStringFromIndexWithDelim( line, ",", 1, buf2, sizeof(buf2)) == FALSE ) continue; Quiz[linenum].no = atoi(buf2); if( getStringFromIndexWithDelim( line, ",", 2, buf2, sizeof(buf2)) == FALSE ) continue; Quiz[linenum].type = atoi(buf2); if( getStringFromIndexWithDelim( line, ",", 3, buf2, sizeof(buf2)) == FALSE ) continue; Quiz[linenum].level = atoi(buf2); if( getStringFromIndexWithDelim( line, ",", 4, buf2, sizeof(buf2)) == FALSE ) continue; Quiz[linenum].answertype = atoi(buf2); if( getStringFromIndexWithDelim( line, ",", 5, buf2, sizeof(buf2)) == FALSE ) continue; Quiz[linenum].answerNo = atoi(buf2); if( getStringFromIndexWithDelim( line, ",", 6, buf2, sizeof(buf2)) == FALSE ) continue; memcpy( Quiz[linenum].question, buf2, sizeof( Quiz[linenum].question)); if( getStringFromIndexWithDelim( line, ",", 7, buf3, sizeof(buf3)) == FALSE ) continue; memcpy( Quiz[linenum].select1, buf3, sizeof( Quiz[linenum].select1)); if( getStringFromIndexWithDelim( line, ",", 8, buf3, sizeof(buf3)) == FALSE ) continue; memcpy( Quiz[linenum].select2, buf3, sizeof( Quiz[linenum].select2)); if( getStringFromIndexWithDelim( line, ",", 9, buf3, sizeof(buf3)) == FALSE ) continue; memcpy( Quiz[linenum].select3, buf3, sizeof( Quiz[linenum].select3)); if(Quiz[linenum].answertype == 1){ if(Quiz[linenum].answerNo == 3){ return FALSE; } } if(Quiz[linenum].answertype == 4){ if(Quiz[linenum].answerNo != 1){ return FALSE; } } linenum ++;// quizcnt++; } if( quizcnt < linenum ){ print("ERR linenum:%d >= quizcnt:%d\n", linenum, quizcnt); return FALSE; } quizcnt = linenum; fclose( f); return TRUE;}int *NPC_GetQuestion(int meindex){ char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; int i,j; int type=0; int answer=0; int level=0; int *tbl; char buf[16]; NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)); if(NPC_Util_GetStrFromStrWithDelim(argstr,"Type",buf, sizeof( buf)) != NULL ){ type = atoi(buf); } if( type <= 0){ type = 0xffff; } if(NPC_Util_GetStrFromStrWithDelim( argstr, "Answer", buf, sizeof( buf)) != NULL){ answer = atoi(buf); } if(answer <= 0){ answer = 0xffff; } if(NPC_Util_GetStrFromStrWithDelim( argstr, "Level", buf, sizeof( buf)) != NULL ){ level = atoi(buf); } if(level <= 0){ level = 0xffff; } for(j=0,i=0; i < quizcnt ;i++){ if( (type & (1 << (Quiz[i].type-1))) != (1 << (Quiz[i].type-1))){ continue; } if((answer & (Quiz[i].answertype)) != Quiz[i].answertype){ continue; } if((level & (Quiz[i].level)) != Quiz[i].level){ continue; } j++; } { int tmp_tbl[j+1]; tmp_tbl[0] = j+1; for(j=1,i=0; i < quizcnt ;i++){ if( (type & (1 << (Quiz[i].type-1))) != (1 << (Quiz[i].type-1))){ continue; } if((answer & (Quiz[i].answertype)) != Quiz[i].answertype){ continue; } if((level & (Quiz[i].level)) != Quiz[i].level){ continue; } tmp_tbl[j] = i; j++; } tbl = tmp_tbl; return tbl; }}BOOL NPC_QuizItemFullCheck(int meindex,int talker){ int i; int itemindex; char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; char buf2[32]; for( i = CHAR_STARTITEMARRAY ; i < CHAR_MAXITEMHAVE ; i++ ) { itemindex = CHAR_getItemIndex( talker , i ); if( !ITEM_CHECKINDEX( itemindex) ) { return TRUE; } } if(NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL) { print("GetArgstrErr:Quiz %s",CHAR_getChar( meindex, CHAR_NAME)); } if(NPC_Util_GetStrFromStrWithDelim( argstr,"EntryItem", buf2, sizeof( buf2)) != NULL) { if(NPC_EntryItemCheck( talker, buf2) == FALSE){ NPC_Quiz_selectWindow( meindex, talker, 3); return FALSE; }else{ return TRUE; } } return FALSE;}/* *云嗯及民尼永弁 */BOOL NPC_EntryStoneCheck(int talker,char *buf){ int stone; int cost; cost= atoi( buf); stone = CHAR_getInt( talker, CHAR_GOLD); if(cost > stone){ return FALSE; } return TRUE;}/* *云嗯及绰轮 */BOOL NPC_EntryStoneDel(int talker,char *buf){ int stone; int cost; char token[256]; cost= atoi( buf); stone = CHAR_getInt( talker, CHAR_GOLD); if((stone-cost) < 0){ CHAR_setInt( talker, CHAR_GOLD, 0); }else{ CHAR_DelGold( talker, cost ); } sprintf( token, "%d 交出stone。", cost); CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE); CHAR_send_P_StatusString( talker, CHAR_P_STRING_GOLD); return TRUE;}/* */BOOL NPC_EntryItemDel(int talker,char *buf){ int i = 1, j = 1,k = 1; char buff3[128]; char buf2[32]; int itemindex; while(getStringFromIndexWithDelim(buf , "," , k, buff3, sizeof(buff3)) !=FALSE ){ k++; if(strstr(buff3, "*") !=NULL){ int itemno; int kosuu; int id; int cnt=0; getStringFromIndexWithDelim(buff3,"*",1,buf2,sizeof(buf2)); itemno = atoi(buf2); getStringFromIndexWithDelim(buff3,"*",2,buf2,sizeof(buf2)); kosuu = atoi(buf2); for( i =0 ; i < CHAR_MAXITEMHAVE ; i++ ){ itemindex = CHAR_getItemIndex( talker , i ); if( ITEM_CHECKINDEX(itemindex) ){ id=ITEM_getInt(itemindex ,ITEM_ID ); if(itemno==id){ cnt++; LogItem( CHAR_getChar( talker, CHAR_NAME ), /* 平乓仿抩 */ CHAR_getChar( talker, CHAR_CDKEY ),#ifdef _add_item_log_name // WON ADD 在item的log中增加item名称 itemindex,#else ITEM_getInt( itemindex, ITEM_ID), /* 失奶泛丞?寞 */#endif "QuizDelItem(猜谜->交出的道具)", CHAR_getInt( talker, CHAR_FLOOR), CHAR_getInt( talker, CHAR_X ), CHAR_getInt( talker, CHAR_Y ), ITEM_getChar( itemindex, ITEM_UNIQUECODE), ITEM_getChar( itemindex, ITEM_NAME), ITEM_getInt( itemindex, ITEM_ID) ); CHAR_DelItem( talker, i); if(cnt == kosuu){ break; } } } } }else{ for( j = 0 ; j < CHAR_MAXITEMHAVE ; j++){ itemindex = CHAR_getItemIndex( talker ,j); if( ITEM_CHECKINDEX(itemindex) ){ if( atoi( buff3) == ITEM_getInt(itemindex,ITEM_ID)){ LogItem( CHAR_getChar( talker, CHAR_NAME ), /* 平乓仿抩 */ CHAR_getChar( talker, CHAR_CDKEY ),#ifdef _add_item_log_name // WON ADD 在item的log中增加item名称 itemindex,#else ITEM_getInt( itemindex, ITEM_ID), /* 失奶泛丞?寞 */#endif "QuizDelItem(猜谜->领到的道具)", CHAR_getInt( talker,CHAR_FLOOR), CHAR_getInt( talker,CHAR_X ), CHAR_getInt( talker,CHAR_Y ), ITEM_getChar( itemindex, ITEM_UNIQUECODE), ITEM_getChar( itemindex, ITEM_NAME), ITEM_getInt( itemindex, ITEM_ID) ); CHAR_DelItem( talker, j); } } } } } return TRUE;}/* */BOOL NPC_EntryItemCheck(int talker,char *buf){ char buf2[512]; char buf3[256]; int id=0; BOOL flg = FALSE; int i; int itemindex; int itemno; int kosuu; int cnt=0; int k=1; while(getStringFromIndexWithDelim(buf , "," , k, buf2, sizeof(buf2)) !=FALSE ) { flg = FALSE; k++; if(strstr(buf2,"*") != NULL){ cnt = 0; getStringFromIndexWithDelim(buf2,"*",1,buf3,sizeof(buf3)); itemno = atoi(buf3); getStringFromIndexWithDelim(buf2,"*",2,buf3,sizeof(buf3)); kosuu = atoi(buf3); for( i=0 ; i < CHAR_MAXITEMHAVE;i++ ){ itemindex = CHAR_getItemIndex( talker , i ); if( ITEM_CHECKINDEX(itemindex) ){ id = ITEM_getInt(itemindex ,ITEM_ID ); if(itemno == id){ cnt++; if(cnt == kosuu){ flg = TRUE; break; } } } } if(flg == FALSE) { return FALSE; } }else{ itemno = atoi(buf2); for( i=0 ; i < CHAR_MAXITEMHAVE;i++ ){ itemindex = CHAR_getItemIndex( talker , i ); if( ITEM_CHECKINDEX(itemindex) ){ id = ITEM_getInt(itemindex ,ITEM_ID ); if(itemno == id){ flg = TRUE; break; } } } if(flg == FALSE) { return FALSE; } } } return TRUE;}/* */BOOL NPC_QUIZPARTY_CHAECK(int meindex,int talker){ if(CHAR_getWorkInt(talker,CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE){ return FALSE; } return TRUE;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?