#include "version.h" #include #include "char.h" #include "object.h" #include "char_base.h" #include "npcutil.h" #include "net.h" #include "lssproto_serv.h" #include "saacproto_cli.h" #include "npc_duelranking.h" #include "handletime.h" #ifdef _DEATH_CONTEND #include "deathcontend.h" #endif #ifdef _DEATH_FAMILY_GM_COMMAND // WON ADD 家族战GM指令 #include "family.h" #endif static void NPC_Duelranking_selectWindow( int meindex, int toindex, int num, int select ); #define NPC_DUELRANKING_WINDOWLINENUM 10 #ifdef _DEATH_FAMILYCONTEND BOOL NPC_ReadFamilyPK_List( void); BOOL NPC_BackupFamilyPK_List( void); BOOL NPC_getFamilyPK_List( int ti, char *buf, int sizes); BOOL NPC_CheckJoin_FamilyPK_List( int meindex, int toindex); #endif enum{ WINDOWTYPE_PKLIST_START=10, WINDOWTYPE_PKLIST_SELECT, WINDOWTYPE_PKLIST_SELECT1, WINDOWTYPE_PKLIST_SELECT2, WINDOWTYPE_FAMILYCONTENDSTART, WINDOWTYPE_FAMILYCONTENDSELECT, WINDOWTYPE_FAMILYCONTENDLIST, WINDOWTYPE_FAMILYCONTENDJOIN, NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT1, NPC_WORK_BATTLELOOP = CHAR_NPCWORKINT2, }; BOOL NPC_DuelrankingInit( int meindex ) { #ifdef _DEATH_CONTEND char buf1[256]; char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; CHAR_setWorkInt( meindex, NPC_WORK_BATTLELOOP, 0); CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); if( NPC_Util_GetArgStr( meindex, npcarg, sizeof( npcarg) ) != NULL && NPC_Util_GetStrFromStrWithDelim( npcarg, "PKLoop", buf1, sizeof( buf1)) != NULL ){ CHAR_setInt( meindex, CHAR_LOOPINTERVAL, atoi(buf1)); if( NPC_Util_GetStrFromStrWithDelim( npcarg, "PKLType", buf1, sizeof( buf1)) != NULL ){ CHAR_setWorkInt( meindex, NPC_WORK_BATTLELOOP, atoi( buf1)); } if( NPC_Util_GetStrFromStrWithDelim( npcarg, "PKLDelay", buf1, sizeof( buf1)) != NULL ){ CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec + (atoi( buf1)*60) ); } } #endif #ifdef _DEATH_FAMILYCONTEND { char buf1[256]; char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; CHAR_setWorkInt( meindex, NPC_WORK_BATTLELOOP, 0); CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); if( NPC_Util_GetArgStr( meindex, npcarg, sizeof( npcarg) ) != NULL && NPC_Util_GetStrFromStrWithDelim( npcarg, "LoadFMList", buf1, sizeof( buf1)) != NULL ){ if( strstr( buf1, "ON") != NULL ) NPC_ReadFamilyPK_List(); } } #endif CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEDUELRANKING ); return TRUE; } void NPC_DuelrankingLooked( int meindex , int lookedindex) { #ifdef _DEATH_FAMILYCONTEND char buf1[256]; char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; if( NPC_Util_GetArgStr( meindex, npcarg, sizeof( npcarg) ) != NULL && NPC_Util_GetStrFromStrWithDelim( npcarg, "FmPkJoin", buf1, sizeof( buf1)) != NULL ){ if( strstr( buf1, "ON") !=NULL ){ CHAR_setWorkInt( lookedindex, CHAR_WORKSHOPRELEVANT, 0); NPC_Duelranking_selectWindow( meindex, lookedindex, 2, -1); return; }else{ return; } } #endif #ifdef _DEATH_CONTEND char buf1[256]; char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; //static int first = 1; if( NPC_Util_GetArgStr( meindex, npcarg, sizeof( npcarg) ) != NULL && NPC_Util_GetStrFromStrWithDelim( npcarg, "PKCharts", buf1, sizeof( buf1)) != NULL ){ if( strstr( buf1, "ON") !=NULL ){ CHAR_setWorkInt( lookedindex, CHAR_WORKSHOPRELEVANT, 0); NPC_Duelranking_selectWindow( meindex, lookedindex, 2, -1); //if( first == 1 ) saacproto_PKLISTCHARTS_send( acfd, 2, 1); //first = 0; return; }else{ return; } } #endif #ifdef _DEATH_FAMILY_GM_COMMAND // WON ADD 家族战GM指令 NPC_Duelranking_selectWindow( meindex, lookedindex, 2, -1); #endif NPC_Duelranking_selectWindow( meindex, lookedindex, 1, -1); } static void NPC_Duelranking_selectWindow( int meindex, int toindex, int num, int select) { int fd; int button; if( CHAR_getInt( toindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { return; } if( NPC_Util_CharDistance( toindex, meindex ) > 1) return; if( (fd = getfdFromCharaIndex( toindex)) == -1 ) return; switch( num){ case 1: { char message[1024]; char buf[2048]; strcpy( message, "1\n" " 要看哪一个? \n\n\n" " <强者们> \n\n" " < 自己 > \n\n" " <都不看> \n\n" ); lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, WINDOW_BUTTONTYPE_NONE, CHAR_WINDOWTYPE_DUELRANKING_START, CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), makeEscapeString( message, buf, sizeof(buf))); } break; #ifdef _DEATH_CONTEND case 2: { char message[1024]; char buf[2048]; strcpy( message, "1\n" " 要看哪一个? \n\n" // " <资格赛排行> \n" " < 正式赛程表 > \n" " < 队伍资料 > \n" // " < 参加赛程 > \n" " < 赛程纪录 > \n" ); lssproto_WN_send( fd, WINDOW_MESSAGETYPE_SELECT, WINDOW_BUTTONTYPE_CANCEL, WINDOWTYPE_PKLIST_START, CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), makeEscapeString( message, buf, sizeof(buf))); } break; /* case 3: { char token[4096], buf[256], buf1[256],buf2[256]; char teamname[256]; int win, lose, battle, score; int page, i, pagecount=10; page = CHAR_getWorkInt( toindex, CHAR_WORKSHOPRELEVANT); button = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_PREV | WINDOW_BUTTONTYPE_NEXT; if( select == WINDOW_BUTTONTYPE_PREV || select == WINDOW_BUTTONTYPE_NEXT) { if( select == WINDOW_BUTTONTYPE_NEXT ){ if( page < 40 ) page++; }else if( select == WINDOW_BUTTONTYPE_PREV ){ if( page > 0 ) page--; } }else if( select == WINDOW_BUTTONTYPE_OK ){ CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); return; } if( page < 0 || page >= 40 ) page = 0; if( page == 0 ) button = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_NEXT; if( page == 39 ) button = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_PREV; CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, page); snprintf( token, sizeof( token), " 资格赛排行榜\n\n" "排名 队伍 胜 负 场 积分\n\n" ); for( i=0; i= 30 && score > 0 ) strcpy( buf2, "★"); sprintf( buf1, "%4dth %-18s %3d %3d %3d %3d %s\n", (page*pagecount)+1+i, teamname, win, lose, battle, score, buf2); strcat( token, buf1); } lssproto_WN_send( fd, WINDOW_MESSAGETYPE_WIDEMESSAGEANDLINEINPUT, button, WINDOWTYPE_PKLIST_SELECT, CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token ); } break; */ case 5://晋级队伍 case 3://正式赛程 { char token[4096], buf1[256]; char teamname1[256], teamname2[256], typestring[256]; int tindex, dtimes, stimes=0; int page, i, pagecount=10; int winno = WINDOWTYPE_PKLIST_SELECT; page = CHAR_getWorkInt( toindex, CHAR_WORKSHOPRELEVANT); button = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_PREV | WINDOW_BUTTONTYPE_NEXT; if( select == WINDOW_BUTTONTYPE_PREV || select == WINDOW_BUTTONTYPE_NEXT) { if( select == WINDOW_BUTTONTYPE_NEXT ){ if( page < 11 ) page++; }else if( select == WINDOW_BUTTONTYPE_PREV ){ if( page > 0 ) page--; } }else if( select == WINDOW_BUTTONTYPE_OK ){ CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); return; } if( page < 0 || page >= 11 ) page = 0; if( page == 0 ) button = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_NEXT; if( page == 10 ) button = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_PREV; CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, page); switch( num){ case 3: snprintf( token, sizeof( token), " 赛程表\n\n" "场次 队伍 剩馀时间 状态\n\n" ); break; case 5: snprintf( token, sizeof( token), " 队伍名单&赛程纪录\n\n" "纪录 \n\n" ); winno = WINDOWTYPE_PKLIST_SELECT2; break; } for( i=0; i 0 ) page--; } }else if( select == WINDOW_BUTTONTYPE_OK ){ CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); return; } if( page < 0 || page >= 4 ) page = 0; if( page == 0 ) button = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_NEXT; if( page == 3 ) button = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_PREV; CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, page); snprintf( token, sizeof( token), " 跨星系家族赛资格排行榜\n\n" "排名 家族名称 家族族长名称\n\n" ); for( i=0; i 0 ) page--; } }else if( select == WINDOW_BUTTONTYPE_OK ){ CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); return; } if( page < 0 || page >= 40 ) page = 0; if( page == 0 ) button = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_NEXT; if( page == 39 ) button = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_PREV; CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, page); snprintf( token, sizeof( token), " 跨星系家族战排行榜\n\n" ); for( i=0; i<40*10; i++){ memset( all_msg[i] , 0, sizeof( all_msg[i])); } if( (fp = fopen( "d_fm_pk_log.txt", "r" )) != NULL ){ i=0; //andy_log print( "read d_fm_pk_log.txt !!\n"); while( fgets( buf1, sizeof( buf1)-1, fp) ){ //andy_log print( "read buf1:%s !!\n", buf1); if( buf1[0] == 0 || buf1[0] == '#' ||strlen(buf1) <= 0 ) continue; buf1[ strlen(buf1) -1] = 0; snprintf( all_msg[i], sizeof( all_msg[i]), "%s", buf1); i++; } fclose( fp ); }else{ //andy_log print( "Can't read d_fm_pk_log.txt !!\n"); } for( i=0; i 1) return; switch( seqno){ case CHAR_WINDOWTYPE_DUELRANKING_START: if( atoi( data) == 3 ) { saacproto_DBGetEntryByCount_send( acfd, DB_DUELPOINT, 0, NPC_DUELRANKING_WINDOWLINENUM, fdid, CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); } if( atoi( data) == 5 ) { char dbkey[256]; CHAR_makeDBKey( talkerindex, dbkey, sizeof( dbkey)); saacproto_DBGetEntryRank_send( acfd, DB_DUELPOINT, dbkey, fdid, CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); } break; case CHAR_WINDOWTYPE_DUELRANKING_TOPRANKING: if( select == WINDOW_BUTTONTYPE_PREV || select == WINDOW_BUTTONTYPE_NEXT) { int count = CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT); if( select == WINDOW_BUTTONTYPE_NEXT ) { count += NPC_DUELRANKING_WINDOWLINENUM; }else { count -= NPC_DUELRANKING_WINDOWLINENUM; } if( count < 0) count = 0; saacproto_DBGetEntryByCount_send( acfd, DB_DUELPOINT, count, NPC_DUELRANKING_WINDOWLINENUM, fdid, CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); }else if( select == WINDOW_BUTTONTYPE_OK ) { if( strlen( data) != 0 ) { int count; count = atoi( data); if( count < 1 ) count = 1; saacproto_DBGetEntryByCount_send( acfd, DB_DUELPOINT, count-1, NPC_DUELRANKING_WINDOWLINENUM, fdid, CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX)); } } break; #ifdef _DEATH_CONTEND case WINDOWTYPE_PKLIST_START: { switch( atoi( data)){ case 2://资格赛排行 NPC_Duelranking_selectWindow( meindex, talkerindex, 3, select); break; case 3://正式赛程 NPC_Duelranking_selectWindow( meindex, talkerindex, 4, select); break; case 4://队伍资料 NPC_Duelranking_selectWindow( meindex, talkerindex, 5, select); break; case 5://加入赛程 NPC_Duelranking_selectWindow( meindex, talkerindex, 6, -1); break; case 6://晋级队伍 NPC_Duelranking_selectWindow( meindex, talkerindex, 7, select); break; } } break; case WINDOWTYPE_PKLIST_SELECT: NPC_Duelranking_selectWindow( meindex, talkerindex, 3, select); break; case WINDOWTYPE_PKLIST_SELECT1: NPC_Duelranking_selectWindow( meindex, talkerindex, 4, select); break; case WINDOWTYPE_PKLIST_SELECT2: NPC_Duelranking_selectWindow( meindex, talkerindex, 5, select); break; #endif #ifdef _DEATH_FAMILYCONTEND case WINDOWTYPE_FAMILYCONTENDSTART: { switch( atoi( data)){ case 2://资格排行 NPC_Duelranking_selectWindow( meindex, talkerindex, 3, select); break; case 3://报名 NPC_Duelranking_selectWindow( meindex, talkerindex, 4, select); break; } } break; case WINDOWTYPE_FAMILYCONTENDSELECT: NPC_Duelranking_selectWindow( meindex, talkerindex, 3, select); break; #endif #ifdef _DEATH_FAMILY_GM_COMMAND // WON ADD 家族战GM指令 case WINDOWTYPE_PKLIST_START: { switch( atoi( data ) ){ case 2: NPC_Duelranking_selectWindow( meindex, talkerindex, 3, select); break; } } break; case WINDOWTYPE_PKLIST_SELECT1: NPC_Duelranking_selectWindow( meindex, talkerindex, 3, select); break; #endif } } void NPC_Duelranking_PrintRanking( char *data, int count_start, int fdid, int msgid2) { char message[1024]; char buf[2048]; int i; int cnt = 0; int button = 0; int fd = getfdFromFdid( fdid); if( fd == -1 ) return; message[0] = '\0'; snprintf( message, sizeof( message), " 世界的强者们\n\n" " Rank DuelPoint Lv Name\n\n" ); for( i = 1; ; i ++ ) { char rankdata[256]; char cdandname[64]; char charaname[32]; char rank[16]; char score[64]; char msgbuf[512]; char cdkey[32]; char lv[16]; char hosi[6]; if( !getStringFromIndexWithDelim( data, "|", i, rankdata, sizeof( rankdata))) { break; } if( !getStringFromIndexWithDelim( rankdata, ",", 2, rank, sizeof( rank)) ){ continue; } if( !getStringFromIndexWithDelim( rankdata, ",", 3, cdandname, sizeof( cdandname)) ){ continue; } makeStringFromEscaped( cdandname); if( !getStringFromIndexWithDelim( cdandname, "_", 1, cdkey, sizeof( cdkey)) ){ continue; } if( !getStringFromIndexWithDelim( cdandname, "_", 2, charaname, sizeof( charaname)) ){ continue; } if( !getStringFromIndexWithDelim( rankdata, ",", 4, score, sizeof( score)) ){ continue; } if( !getStringFromIndexWithDelim( rankdata, ",", 5, lv, sizeof( lv)) ){ lv[0] = '\0'; } { char *mycdkey = CHAR_getChar( CONNECT_getCharaindex(fd), CHAR_CDKEY); char *myname = CHAR_getChar( CONNECT_getCharaindex(fd), CHAR_NAME); char engnum[4][3] = { "st","nd","rd","th"}; int dsprank = atoi(rank); if( dsprank > 3) dsprank = 3; if( mycdkey != NULL && myname != NULL && strcmp( cdkey, mycdkey) == 0 && strcmp( charaname, myname) == 0 ) { strcpy( hosi, "★"); }else { strcpy( hosi, " "); } snprintf( msgbuf, sizeof( msgbuf), "%s %5d%s %10s %3s %s\n", hosi, atoi(rank)+1, engnum[dsprank], score, lv, charaname ); } strcatsafe( message, sizeof( message), msgbuf); cnt ++; } if( cnt == 0 ) { strcpy( message, "\n 没有其他的资料了。"); button = WINDOW_BUTTONTYPE_PREV|WINDOW_BUTTONTYPE_OK; }else if( cnt < NPC_DUELRANKING_WINDOWLINENUM ) { if( count_start >= NPC_DUELRANKING_WINDOWLINENUM) { button = WINDOW_BUTTONTYPE_OK | WINDOW_BUTTONTYPE_PREV; }else { button = WINDOW_BUTTONTYPE_OK; } }else if( count_start == 0 ) { button = WINDOW_BUTTONTYPE_NEXT|WINDOW_BUTTONTYPE_OK; }else { button = WINDOW_BUTTONTYPE_NEXT|WINDOW_BUTTONTYPE_PREV|WINDOW_BUTTONTYPE_OK; } lssproto_WN_send( fd, WINDOW_MESSAGETYPE_WIDEMESSAGEANDLINEINPUT, button, CHAR_WINDOWTYPE_DUELRANKING_TOPRANKING, msgid2, makeEscapeString( message, buf, sizeof(buf))); if( cnt == 0 ) { CHAR_setWorkInt( CONNECT_getCharaindex(fd), CHAR_WORKSHOPRELEVANT, -1); }else { CHAR_setWorkInt( CONNECT_getCharaindex(fd), CHAR_WORKSHOPRELEVANT, count_start); } } void NPC_Duelranking_CallMyRanking( int count, int msgid, int msgid2) { count -= 5; if( count < 0 ) count = 0; saacproto_DBGetEntryByCount_send( acfd, DB_DUELPOINT, count, NPC_DUELRANKING_WINDOWLINENUM, msgid, msgid2 ); } #ifdef _DEATH_CONTEND void NPC_Duelrankingloop( int meindex) { static int side = 0; int i; if( CHAR_getWorkInt( meindex, NPC_WORK_CURRENTTIME) < NowTime.tv_sec ){ char buf1[256]; char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec); if( NPC_Util_GetArgStr( meindex, npcarg, sizeof( npcarg) ) != NULL && NPC_Util_GetStrFromStrWithDelim( npcarg, "PKLoop", buf1, sizeof( buf1)) != NULL ){ CHAR_setInt( meindex, CHAR_LOOPINTERVAL, atoi(buf1)); if( NPC_Util_GetStrFromStrWithDelim( npcarg, "PKLType", buf1, sizeof( buf1)) != NULL ){ CHAR_setWorkInt( meindex, NPC_WORK_BATTLELOOP, atoi( buf1)); } if( NPC_Util_GetStrFromStrWithDelim( npcarg, "PKLDelay", buf1, sizeof( buf1)) != NULL ){ CHAR_setWorkInt( meindex, NPC_WORK_CURRENTTIME, NowTime.tv_sec + (atoi( buf1)*60) ); } } } if( CHAR_getWorkInt( meindex, NPC_WORK_BATTLELOOP) == 0 ) return; for( i=0; i= MAXJOINFM ) break; } fclose( fp); return TRUE; } BOOL NPC_BackupFamilyPK_List( void) { FILE *fp=NULL; int i; if( (fp=fopen("fmlist.txt", "w+")) == NULL ) return FALSE; for( i=0; i MAXJOINFM ) return FALSE; if( JoinFamilyList[ti].use == 0 ) return FALSE; snprintf( buf, sizes, "%d|%s|%s|%s|%d|", JoinFamilyList[ti].fmindex, JoinFamilyList[ti].fmname, JoinFamilyList[ti].ucdkey, JoinFamilyList[ti].uname, JoinFamilyList[ti].join ); return TRUE; } BOOL NPC_CheckJoin_FamilyPK_List( int meindex, int toindex) { int i; //andy_log print( " *check: [%d,%s,%s]\n", CHAR_getInt( toindex, CHAR_FMINDEX), CHAR_getChar( toindex, CHAR_CDKEY), CHAR_getChar( toindex, CHAR_NAME) ); for( i=0; i