npc_quiz.c

来自「石器时代3.0源代码 2008.08.27最新版 完全可编译开服!」· C语言 代码 · 共 1,326 行 · 第 1/3 页

C
1,326 行
字号
				);			}			buttontype = WINDOW_BUTTONTYPE_CANCEL;		  	messagetype = WINDOW_MESSAGETYPE_SELECT;			windowno = CHAR_WINDOWTYPE_QUIZ_MAIN;			memcpy(pl_ptr,&PLAYER,sizeof(struct pl));		}		break;			  case 4:		if(NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr)) == NULL)		{			print("GetArgstrErr:Quiz %s",CHAR_getChar( meindex, CHAR_NAME));		}		if(NPC_Util_GetStrFromStrWithDelim( argstr,"Party",	token, sizeof( token)) != NULL) 		{			buttontype = WINDOW_BUTTONTYPE_OK;			messagetype = WINDOW_MESSAGETYPE_MESSAGE;			windowno = CHAR_WINDOWTYPE_QUIZ_START;		}		break;	}	 	/*-仇仇匹霜耨允月--*/	lssproto_WN_send( fd, messagetype, 					buttontype, 					windowno,					CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX),					token);}void NPC_QuizWindowTalked( int meindex, int talkerindex, 								int seqno, int select, char *data){	int i=0;	int old_no;	if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) {		return;	}	switch( seqno){	  case CHAR_WINDOWTYPE_QUIZ_START:		if( select == WINDOW_BUTTONTYPE_YES) {			NPC_Quiz_selectWindow(meindex, talkerindex, 1);		}				if(select == WINDOW_BUTTONTYPE_OK){		}				break;	  case CHAR_WINDOWTYPE_QUIZ_MAIN:	  {	  	int point;		int *pl_ptr;		int p_no;		struct pl PLAYER;					p_no = CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT);			point = CHAR_getWorkInt( meindex, CHAR_WORK_PLAYER1 + p_no);			pl_ptr = (int *)point;					memcpy(&PLAYER,pl_ptr,sizeof(struct pl));			p_no = CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT);			old_no = CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANTSEC)-1;			i=	PLAYER.oldno[old_no];			if(select == WINDOW_BUTTONTYPE_OK){				if( i >= quizcnt || i < 0 ) return;				if( Quiz == NULL || strlen( Quiz[i].select1) >= 128 ) return;				if( strstr( data, Quiz[i].select1) != NULL) {					PLAYER.answer++;				}				memcpy(pl_ptr,&PLAYER,sizeof(struct pl));				NPC_Quiz_selectWindow(meindex, talkerindex, 2);			}else if(select == WINDOW_BUTTONTYPE_CANCEL){				CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER1 + 							CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT) ,-1);				free(PLAYER.ptr);			}else if( atoi( data) == 0){			}else{				if(atoi(data) == PLAYER.ansno){					PLAYER.answer++;				}				memcpy(pl_ptr,&PLAYER,sizeof(struct pl));				NPC_Quiz_selectWindow(meindex, talkerindex, 2);			}	  }	  break;		}}/* *示□母□仿奶件及民尼永弁 */int NPC_QuizBorderLine(int ans ,char *buf){	char buf2[32];	int j = 1;	int border;			while(getStringFromIndexWithDelim(buf , "," , j, buf2, sizeof( buf2))	 !=FALSE )	{		border = atoi(buf2);			if(ans >= border) {			return j;		}			j += 2;	}	return -1;}/* *示□母□仿奶件及民尼永弁 */int NPC_QuizWarpBorderLine(int ans ,char *buf){	char buf2[32];	int j = 1;	int border;			while(getStringFromIndexWithDelim(buf , "," , j, buf2, sizeof( buf2))	 != FALSE )	{		border = atoi(buf2);			if(ans >= border) {			return j;		}			j += 2;	}	return -1;}/* */BOOL NPC_QuizAddItem(int talker,char *buf){	int i=1;	int ret;	char buf2[16];	int itemindex;	char token[512];		while(getStringFromIndexWithDelim(buf , "." , i, buf2, sizeof(buf2))	!= FALSE )	{		i++;	}	i--;	if(i == 1){		getStringFromIndexWithDelim(buf , "." , i, buf2, sizeof(buf2));	}else{		/*--仿件母丞--*/		i = (rand() % i)+1;		getStringFromIndexWithDelim(buf , "." , i, buf2, sizeof(buf2));	}	itemindex = ITEM_makeItemAndRegist(atoi(buf2));	if(itemindex == -1) return FALSE;	ret = CHAR_addItemSpecificItemIndex( talker, itemindex);	if( !CHAR_CHECKITEMINDEX( talker, ret) ){		print( "npc_quiz.c: additem error itemindex[%d]\n", itemindex);		ITEM_endExistItemsOne( itemindex);			CHAR_talkToCli( talker, -1, "道具栏已满", CHAR_COLORWHITE);					return FALSE;	}	if(itemindex != -1) {		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			"QuizAddItem(猜谜->领到的道具)",			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)		);	}		sprintf(token,"拿到%s。", ITEM_getChar( itemindex, ITEM_NAME));	CHAR_talkToCli( talker, -1, token, CHAR_COLORWHITE);	CHAR_sendItemDataOne( talker, ret);	return TRUE;}int  NPC_QuizRandAnswer(int p_no,int q_no, int mode,						char *work1,char *work2,char *work3){	int ans;	int ra;	ans = (rand() % mode) + 1;	if(ans == 1) {		if( Quiz[q_no].answerNo == 1) {			strcpy( work1, Quiz[q_no].select1);			if(mode == 2) {				strcpy( work2, Quiz[q_no].select2);				return ans;			}			ra = rand()%2;			if(ra == 0) {				strcpy( work2, Quiz[q_no].select2);				strcpy( work3, Quiz[q_no].select3);			}else{				strcpy( work2, Quiz[q_no].select3);				strcpy( work3, Quiz[q_no].select2);			}		}else if( Quiz[q_no].answerNo == 2) {			strcpy( work1, Quiz[q_no].select2);			if(mode == 2) {				strcpy( work2, Quiz[q_no].select1);				return ans;			}			ra = rand()%2;			if(ra == 0) {				strcpy( work2, Quiz[q_no].select1);				strcpy( work3, Quiz[q_no].select3);			}else{				strcpy( work2, Quiz[q_no].select3);				strcpy( work3, Quiz[q_no].select1);			}		}else{			strcpy( work1, Quiz[q_no].select3);			ra = rand()%2;			if(ra == 0) {				strcpy( work2, Quiz[q_no].select1);				strcpy( work3, Quiz[q_no].select2);			}else{				strcpy( work2, Quiz[q_no].select1);				strcpy( work3, Quiz[q_no].select2);			}		}	}else if(ans == 2) {		if(Quiz[q_no].answerNo == 1) {			strcpy( work2, Quiz[q_no].select1);			if(mode == 2) {				strcpy( work1, Quiz[q_no].select2);				return ans;			}			ra=rand()%2;			if(ra == 0) {				strcpy( work1, Quiz[q_no].select2);				strcpy( work3, Quiz[q_no].select3);			}else {				strcpy( work1, Quiz[q_no].select3);				strcpy( work3, Quiz[q_no].select2);			}		}else if( Quiz[q_no].answerNo == 2) {			strcpy( work2, Quiz[q_no].select2);			if(mode == 2){				strcpy( work1, Quiz[q_no].select1);				return ans;			}			ra = rand()%2;			if(ra == 0) {				strcpy( work1, Quiz[q_no].select1);				strcpy( work3, Quiz[q_no].select3);			}else {				strcpy( work1, Quiz[q_no].select3);				strcpy( work3, Quiz[q_no].select1);			}		}else {			strcpy( work2, Quiz[q_no].select3);			ra = rand()%2;			if(ra == 0) {				strcpy( work1, Quiz[q_no].select1);				strcpy( work3, Quiz[q_no].select2);			}else {				strcpy( work1, Quiz[q_no].select2);				strcpy( work3, Quiz[q_no].select1);			}		}	}else if(ans == 3) {		if( Quiz[q_no].answerNo == 1) {			strcpy( work3, Quiz[q_no].select1);			ra = rand()%2;			if(ra == 0) {				strcpy( work1, Quiz[q_no].select2);				strcpy( work2, Quiz[q_no].select3);			}else {				strcpy( work1, Quiz[q_no].select3);				strcpy( work2, Quiz[q_no].select2);			}		}else if( Quiz[q_no].answerNo == 2) {			strcpy( work3, Quiz[q_no].select2);			ra = rand()%2;			if(ra == 0) {				strcpy( work1, Quiz[q_no].select1);				strcpy( work2, Quiz[q_no].select3);			}else {				strcpy( work1, Quiz[q_no].select3);				strcpy( work2, Quiz[q_no].select1);			}		}else{			strcpy( work3, Quiz[q_no].select3);			ra = rand()%2;			if(ra == 0) {				strcpy( work1, Quiz[q_no].select1);				strcpy( work2, Quiz[q_no].select2);			}else {				strcpy( work1, Quiz[q_no].select2);				strcpy( work2, Quiz[q_no].select1);			}		}	}	return ans;}BOOL NPC_PlayerCheck(int meindex,int talker)	{	int i;	int k=0;	int *ptr;	struct pl Player;	NPC_RealyCheack( meindex, talker);		for(i = 0 ; i < MEPLAYER ; i++){		if( (CHAR_getWorkInt( meindex, CHAR_WORK_PLAYER1 +i ) == -1))		{			break;		}	}	if(i == MEPLAYER) return FALSE;	/*-- 丢乒伉割忡 --*/	if((ptr =(int *) calloc( 1,sizeof(struct pl)))  == NULL){        print("记忆体无法确保%s",CHAR_getChar(meindex,CHAR_NAME));    	return FALSE;	}    /*-- 禾奶件正及桦赭毛创尹化云仁??-*/    Player.ptr = ptr;    Player.talkerindex = talker;	//npc及奶件犯永弁旦???	Player.quizno = 0;		//蜇箕及  锁醒	Player.answer = 0;		//恳荸醒	Player.ansno = 0;		//蚕尹及  寞毛创尹化云仁  蚕尹毛田仿田仿卞请仄凶端卞银迕)    for(k=0 ; k < OLDNO; k++) {		Player.oldno[k] = -1;	}	/*--丢乒伉毛戊疋□--*/	memcpy(ptr,&Player,sizeof(struct pl));	CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTSEC,0);	CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANT,0);	CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANTTRD,0);	CHAR_setWorkInt( talker, CHAR_WORKSHOPRELEVANT, i);	k= (int)ptr;	CHAR_setWorkInt( meindex, CHAR_WORK_PLAYER1 + i, k );	return TRUE;}int NPC_RealyCheack(int meindex,int talker){	int fl, x, y;	int i, j;	int px[10] = {0, 1, 0,-1, 1,-1, 1, 0,-1};	int py[10] = {0,-1,-1,-1, 0, 0, 1, 1, 1};	int objindex;		OBJECT object;	int talkerindex;	BOOL okflg = FALSE;	struct pl PLAYER;	int *pl_ptr;	int point;		fl = CHAR_getInt( meindex, CHAR_FLOOR);	for(j = 0 ; j < MEPLAYER ; j++) {		point = CHAR_getWorkInt( meindex, CHAR_WORK_PLAYER1 + j);		okflg = FALSE;		if(point == -1) continue;		pl_ptr = (int *)point;					memcpy(&PLAYER, pl_ptr, sizeof(struct pl));		talkerindex = PLAYER.talkerindex;				for(i=0 ; i < 10 ; i++) {			x = px[i] + CHAR_getInt( meindex, CHAR_X);			y = py[i] + CHAR_getInt( meindex, CHAR_Y);						for(object = MAP_getTopObj(fl,x,y) ; object;						object = NEXT_OBJECT( object))			{				objindex = GET_OBJINDEX( object);				if( OBJECT_getType( objindex)    == OBJTYPE_CHARA ){					if( OBJECT_getIndex( objindex) == talkerindex) {						if(talkerindex == talker) {							okflg = TRUE;//							print("\n %s %d开放",CHAR_getChar(talker,CHAR_NAME),(int)PLAYER.ptr);							free(PLAYER.ptr);

⌨️ 快捷键说明

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