?? deathcontend.c
字號:
#include "version.h"
#include <string.h>
#include <math.h>
#include "util.h"
#include "char.h"
#include "char_data.h"
#include "char_base.h"
#include "battle.h"
#include "configfile.h"
#include "saacproto_cli.h"
#include "buf.h"
#include "log.h"
#ifdef _DEATH_CONTEND
#include "deathcontend.h"
PkTeamLists *PkTeamList=NULL;
PKProcedures PKProcedure[MAXJOINTEAM];
static char chartslist[65536*3];
static char ABattlelist[65536*2];
static char ABLevelup[65536*2];
static int maxteam = 0;
static int PKListSort[550];
//正式賽
ArrangeBattleC *NowABattle[MAXBAHEAD][MAXBAFLOOR][MAXNOWBATTLE];
ArrangeBattleC *headABattle[MAXBAHEAD];
ArrangeBattleC *InBattle[MAXBATTLEPAGE];
static int maxfloor=0;
static int maxbati=0;
int ABFloor[MAXBAHEAD];
/*
struct {
int floor;
int x;
int y;
int use;
}PK_WATCHMAP[MAXJOINTEAM][MAXWATCHMAP]={
{},
};
*/
struct {
int floor;
int x;
int y;
int use;
}PK_BATTLEMAP[MAXJOINTEAM]={
// { 8240, 13, 14, 0}, { 8240, 13, 27, 0}, { 8240, 26, 14, 0}, { 8240, 26, 27, 0},
{ 8240, 13, 14, 0}, { 8240, 13, 27, 0}, { 8240, 26, 14, 0}, { 8240, 26, 27, 0},
{ 8241, 13, 14, 0}, { 8241, 13, 27, 0}, { 8241, 26, 14, 0}, { 8241, 26, 27, 0},
{ 8242, 13, 14, 0}, { 8242, 13, 27, 0}, { 8242, 26, 14, 0}, { 8242, 26, 27, 0},
{ 8243, 13, 14, 0}, { 8243, 13, 27, 0}, { 8243, 26, 14, 0}, { 8243, 26, 27, 0},
{ 8244, 13, 14, 0}, { 8244, 13, 27, 0}, { 8244, 26, 14, 0}, { 8244, 26, 27, 0},
{ 8245, 13, 14, 0}, { 8245, 13, 27, 0}, { 8245, 26, 14, 0}, { 8245, 26, 27, 0},
{ 8246, 13, 14, 0}, { 8246, 13, 27, 0}, { 8246, 26, 14, 0}, { 8246, 26, 27, 0},
{ 8247, 13, 14, 0}, { 8247, 13, 27, 0}, { 8247, 26, 14, 0}, { 8247, 26, 27, 0},
{ 8248, 13, 14, 0}, { 8248, 13, 27, 0}, { 8248, 26, 14, 0}, { 8248, 26, 27, 0},
{ 8249, 13, 14, 0}, { 8249, 13, 27, 0}, { 8249, 26, 14, 0}, { 8249, 26, 27, 0},
};
void PKLIST_shoutToAll( char *token, int teamnum, int floor)
{
int i;
int playernum = CHAR_getPlayerMaxNum();
LogPkContend( token, "shoutToAll", 0, 0, 0, 1);
for( i=0 ; i<playernum ; i++) {
if( CHAR_getCharUse(i) == FALSE ) continue;
//if( floor == -1 || floor == CHAR_getInt( i, CHAR_FLOOR) )
//if( teamnum == -1 || teamnum == CHAR_getInt( i, CHAR_PKLISTTEAMNUM) )
CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW);
}
}
void del_rn( char *s )
{
int i;
for(i=0;;i++){
if( s[i] == '\r' || s[i] == '\n' ) s[i] = 0;
if( s[i] == 0 )break;
}
}
//勿動-------------------------------------------------------
void PKLIST_ResetOneTeamMan( int ti )
{
int k;
if( ti < 0 || ti >= maxteam ) return;
for( k=0;k<MAXTEAMMANNUM;k++){
PkTeamList[ti].MyTeamMans[k].use = 0;
memset( PkTeamList[ti].MyTeamMans[k].cdkey, 0,
sizeof( PkTeamList[ti].MyTeamMans[k].cdkey) );
memset( PkTeamList[ti].MyTeamMans[k].name, 0,
sizeof( PkTeamList[ti].MyTeamMans[k].name) );
}
}
void PKLIST_ResetOneBHistory( int ti )
{
int k;
for( k=0; k<MAXBATTLENUM; k++){
PkTeamList[ti].BHistory[k].use = 0;
PkTeamList[ti].BHistory[k].teamnum = -1;
PkTeamList[ti].BHistory[k].flg = 1;
}
}
void PKLIST_ResetOnePkTeamList( int ti )
{
if( ti < 0 || ti >= maxteam ) return;
PkTeamList[ti].use = 0;
PkTeamList[ti].teamnum = -1;
memset( PkTeamList[ti].teamname, 0, sizeof( PkTeamList[ti].teamname ) );
memset( PkTeamList[ti].pathdir, 0, sizeof( PkTeamList[ti].pathdir) );
memset( PkTeamList[ti].leadercdkey, 0, sizeof( PkTeamList[ti].leadercdkey ) );
PkTeamList[ti].win = 0;
PkTeamList[ti].lost = 0;
PkTeamList[ti].battleplay = 0;
PkTeamList[ti].score = 0;
PkTeamList[ti].inside = 1;
PkTeamList[ti].read = 1;
}
//-----------------------------------------------------------
int PKLIST_InitPkTeamList( int teamnum )
{
int i;
if( PkTeamList != NULL || teamnum <= 0 ) return -1;
maxteam = teamnum;
PkTeamList = (PkTeamLists *)calloc( 1, sizeof( struct _tagPkTeamLists) * maxteam );
if( PkTeamList == NULL ){
print( "ANDY err Can't calloc PkTeamList :%d !!\n",
sizeof( struct _tagPkTeamLists) * maxteam );
return -1;
}
print( "PkTeamList calloc size :%d ..\n",
sizeof( struct _tagPkTeamLists) * maxteam );
for( i=0; i<maxteam; i++ ){
PKLIST_ResetOnePkTeamList( i );
PKLIST_ResetOneTeamMan( i);
PKLIST_ResetOneBHistory( i);
}
PKLIST_LoadInitPkTeamListData();
memset( PKListSort, -1, sizeof(PKListSort));
memset( chartslist, 0, sizeof(chartslist));
//saacproto_LoadPkTeamListData_send( acfd , 0, 1000);
for( i=0; i<MAXJOINTEAM; i++ ){
PKProcedure[i].use = 0;
PKProcedure[i].type = PKTYPE_NONE;
PKProcedure[i].time = 0;
PKProcedure[i].Team[0].use = 0;
PKProcedure[i].Team[0].fd = -1;
PKProcedure[i].Team[0].teamnum = -1;
PKProcedure[i].Team[1].use = 0;
PKProcedure[i].Team[1].teamnum = -1;
PKProcedure[i].Team[1].fd = -1;
}
#ifdef _DEATH_CONTENDAB
ABATTLE_InitABattle(19);
#endif
PKLIST_LoadPkTeamListData(); // 本來向ac要,改為直接讀檔
PKLIST_Sort_PKListSort();
return 1;
}
int PKLIST_GetPkTeamListArrayFromNum( int teamnum)
{
int i;
for( i=0; i<maxteam; i++ ){
if( PkTeamList[i].use != 1 ) continue;
if( PkTeamList[i].teamnum == teamnum )return i;
}
return -1;
}
int PKLIST_GetPkTeamListArray( int teamnum, char *cdkey)
{
int i;
for( i=0; i<maxteam; i++ ){
if( PkTeamList[i].use != 1 ) continue;
if( PkTeamList[i].teamnum != teamnum ) continue;
if( !strcmp( PkTeamList[i].leadercdkey, cdkey) ) return i;
}
return -1;
}
//確認約戰
BOOL PKLIST_CHECKPkTeamSame( int teamnum, int charaindex, char *cdkey, int toteamnum )
{
int k;
int array;
if( !CHAR_CHECKINDEX( charaindex ) ) return FALSE;
array = PKLIST_GetPkTeamListArray( teamnum, cdkey);
if( array == -1 ) return FALSE;
for( k=0; k<MAXBATTLENUM; k++){
if( k >= DEFMAXBATTLENUM ){
CHAR_talkToCli( charaindex, -1, "對戰場次已滿!", CHAR_COLORYELLOW);
return FALSE;
}
if( PkTeamList[array].BHistory[k].use == 0 ) continue;
if( PkTeamList[array].BHistory[k].teamnum == toteamnum ) return FALSE;
}
return TRUE;
}
int PKLIST_CHECKPkTeamNew( int teamnum, int charaindex, char *cdkey )
{
int k;
int array;
array = PKLIST_GetPkTeamListArray( teamnum, cdkey);
if( array == -1 ){
CHAR_talkToCli( charaindex, -1, "無法取得隊伍資料!", CHAR_COLORYELLOW);
return -1;
}
for( k=0; k<MAXBATTLENUM; k++){
if( PkTeamList[array].BHistory[k].use == 1 ) continue;
break;
}
if( k>= DEFMAXBATTLENUM ){
CHAR_talkToCli( charaindex, -1, "對戰場次已滿!", CHAR_COLORYELLOW);
return -1;
}
return k;
}
BOOL PKLIST_LoadPkTeamListDataSub( int ti, char *data)
{
int oldinside = -1;
char buf[512];
if( getStringFromIndexWithDelim( data, "|", 1, buf, sizeof( buf)) == FALSE ) return FALSE;
PkTeamList[ti].teamnum = atoi( buf);
if( getStringFromIndexWithDelim( data, "|", 2, buf, sizeof( buf)) == FALSE ) return FALSE;
sprintf( PkTeamList[ti].pathdir, "%s", buf);
if( getStringFromIndexWithDelim( data, "|", 3, buf, sizeof( buf)) == FALSE ) return FALSE;
sprintf( PkTeamList[ti].teamname, "%s", buf);
if( getStringFromIndexWithDelim( data, "|", 4, buf, sizeof( buf)) == FALSE ) return FALSE;
sprintf( PkTeamList[ti].leadercdkey, "%s", buf);
if( getStringFromIndexWithDelim( data, "|", 5, buf, sizeof( buf)) == FALSE ) return FALSE;
PkTeamList[ti].win = atoi( buf);
if( getStringFromIndexWithDelim( data, "|", 6, buf, sizeof( buf)) == FALSE ) return FALSE;
PkTeamList[ti].lost = atoi( buf);
if( getStringFromIndexWithDelim( data, "|", 7, buf, sizeof( buf)) == FALSE ) return FALSE;
PkTeamList[ti].battleplay = atoi( buf);
if( getStringFromIndexWithDelim( data, "|", 8, buf, sizeof( buf)) == FALSE ) return FALSE;
PkTeamList[ti].score = atoi( buf);
oldinside = PkTeamList[ti].inside;
if( getStringFromIndexWithDelim( data, "|", 9, buf, sizeof( buf)) == FALSE ) return FALSE;
PkTeamList[ti].inside = atoi( buf);
if( PkTeamList[ti].inside == 2 && PkTeamList[ti].inside != oldinside ){//廣播
char token[256];
int i;
int playernum = CHAR_getPlayerMaxNum();
sprintf( token, "%s 隊,達成比賽規定積分,積分:%d。",
PkTeamList[ti].teamname, PkTeamList[ti].score );
for( i=0; i<playernum; i++){
if( CHAR_getCharUse(i) &&
CHAR_getInt( i , CHAR_WHICHTYPE) == CHAR_TYPEPLAYER &&
CHAR_getInt( i , CHAR_FLOOR ) == 8250 ){
CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW );
}
}
}
PKLIST_UNLOCKTeam( PkTeamList[ti].teamnum);
PkTeamList[ti].use = 1;
return TRUE;
}
BOOL PKLIST_LoadPkTeamListDataMyTeamMans( int ti, char *data)
{
int k=1, count=0;
char buf[256], buf1[64];
while( getStringFromIndexWithDelim( data, "|", k, buf, sizeof( buf)) !=FALSE ) {
k++;
if( getStringFromIndexWithDelim( buf, ",", 1, buf1, sizeof( buf1)) == FALSE ) continue;
sprintf( PkTeamList[ti].MyTeamMans[count].cdkey, "%s", buf1);
if( getStringFromIndexWithDelim( buf, ",", 2, buf1, sizeof( buf1)) == FALSE ) continue;
sprintf( PkTeamList[ti].MyTeamMans[count].name, "%s", buf1);
PkTeamList[ti].MyTeamMans[count].use = 1;
count++;
if( count >= MAXTEAMMANNUM ) break;
}
if( count <= 0 ) return FALSE;
return TRUE;
}
BOOL PKLIST_LoadPkTeamListDataBHistory( int ti, char *data)
{
int k=1, count=0;
char buf[256], buf1[64];
while( getStringFromIndexWithDelim( data, "|", k, buf, sizeof( buf)) !=FALSE ) {
k++;
if( getStringFromIndexWithDelim( buf, ",", 1, buf1, sizeof( buf1)) == FALSE ) continue;
PkTeamList[ti].BHistory[count].teamnum = atoi( buf1);
if( getStringFromIndexWithDelim( buf, ",", 2, buf1, sizeof( buf1)) == FALSE ) continue;
PkTeamList[ti].BHistory[count].flg = atoi( buf1);
PkTeamList[ti].BHistory[count].use = 1;
count++;
if( count >= MAXBATTLENUM ) break;
}
return TRUE;
}
// teamlist.ini 內容
// teamnum|teamname|leadercdkeky|leadername|cdkey|name|cdkey|name|cdkey|name|cdkey|name
void PKLIST_LoadInitPkTeamListData(void)
{
FILE *fp = NULL;
int count = 0,i;
char szReadData[1024],buf[1024],buf1[1024];
if((fp = fopen("data//pkdata//teamlist.txt","r")) != NULL){
fclose(fp);
return;
}
if((fp = fopen("data//pkdata//teamlist.ini","r")) == NULL){
print("can't find data/pkdata/teamlist.ini\n");
return;
}
while(1){
memset(szReadData,0,sizeof(szReadData));
memset(buf,0,sizeof(buf));
if(fgets(szReadData,1024,fp) == NULL) break;
if(getStringFromIndexWithDelim(szReadData,"|",1,buf,sizeof(buf)) == FALSE){
print("err get teamindex data:%s\n",szReadData);
continue;
}
PkTeamList[count].teamnum = atoi(buf);
sprintf(PkTeamList[count].pathdir,"NOUSE");
if(getStringFromIndexWithDelim(szReadData,"|",2,buf,sizeof(buf)) == FALSE){
print("err get teamindex data:%s\n",szReadData);
continue;
}
sprintf(PkTeamList[count].teamname,"%s",buf);
if(getStringFromIndexWithDelim(szReadData,"|",3,buf,sizeof(buf)) == FALSE){
print("err get leadercdkey data:%s\n",szReadData);
continue;
}
sprintf(PkTeamList[count].leadercdkey,"%s",buf);
for(i=0;i<MAXTEAMMANNUM;i++){
if(getStringFromIndexWithDelim(szReadData,"|",3+i*2,buf,sizeof(buf)) == FALSE){
if(i == 0) print("err team has no leader data:%s\n",szReadData);
break;
}
if(getStringFromIndexWithDelim(szReadData,"|",4+i*2,buf1,sizeof(buf1)) == FALSE) break;
sprintf(PkTeamList[count].MyTeamMans[i].cdkey,"%s",buf);
sprintf(PkTeamList[count].MyTeamMans[i].name,"%s",buf1);
PkTeamList[count].MyTeamMans[i].use = 1;
}
PKLIST_UNLOCKTeam(PkTeamList[count].teamnum);
PkTeamList[count].use = 1;
count++;
}
fclose(fp);
printf("get %d teamlist.ini data\n",count);
PKLIST_SavePkTeamListData();
}
// teamlist.txt 內容
// teamindex_teamnum|pathdir|teamname|leadercdkeky|win|lost|battleplay|score|inside_cdkey,name|...|cdkey,name|_teamnum,flg|...|teamnum,flg
// |--------最多五筆--------| |--------最多一百筆-------|
BOOL PKLIST_LoadPkTeamListData(void) // 改成讀檔
{
FILE *fp = NULL;
int array = -1,count = 0;
char szReadData[10240],buf[10240];
char teamindex[8];
if((fp = fopen("data//pkdata//teamlist.txt","r")) == NULL){
print("can't find data/pkdata/teamlist.txt\n");
return FALSE;
}
while(1){
memset(szReadData,0,sizeof(szReadData));
memset(buf,0,sizeof(buf));
if(fgets(szReadData,10240,fp) == NULL) break;
if(getStringFromIndexWithDelim(szReadData,"_",1,teamindex,sizeof(teamindex)) == FALSE){
print("err get teamindex data:%s line:%d\n",szReadData,count++);
continue;
}
array = atoi(teamindex);
getStringFromIndexWithDelim(szReadData,"_",2,buf,sizeof(buf));
if(PKLIST_LoadPkTeamListDataSub(array,buf) == FALSE){
print("err set PkTeamList data:%s line:%d\n",szReadData,count++);
continue;
}
getStringFromIndexWithDelim(szReadData,"_",3,buf,sizeof(buf));
if( PKLIST_LoadPkTeamListDataMyTeamMans(array,buf) == FALSE){
print("err set PkTeamList.MyTeamMans data:%s line:%d\n",szReadData,count++);
continue;
}
if(getStringFromIndexWithDelim(szReadData,"_",4,buf,sizeof(buf)) != FALSE){
if(PKLIST_LoadPkTeamListDataBHistory(array,buf) == FALSE){
print("err set PkTeamList.BHistory data:%s line:%d\n",szReadData,count++);
continue;
}
}
count++;
}
fclose(fp);
printf("get %d teamlist data\n",count);
return TRUE;
}
void PKLIST_SavePkTeamListData(void)
{
FILE *fp = NULL;
int i,j;
char szWriteData[1024],szWriteData2[2048],szTemp[128];
if((fp = fopen("data//pkdata//teamlist.txt","w")) == NULL){
print("can't open data/pkdata/teamlist.txt\n");
return;
}
for(i=0;i<MAXTEAMNUM;i++){
if(PkTeamList[i].use != 0){
memset(szWriteData,0,sizeof(szWriteData));
for(j=0;j<MAXTEAMMANNUM;j++){
if(PkTeamList[i].MyTeamMans[j].use != 0){
strcat(szWriteData,PkTeamList[i].MyTeamMans[j].cdkey);
strcat(szWriteData,",");
strcat(szWriteData,PkTeamList[i].MyTeamMans[j].name);
strcat(szWriteData,"|");
}
}
szWriteData[strlen(szWriteData)-1] = 0;
memset(szWriteData2,0,sizeof(szWriteData2));
memset(szTemp,0,sizeof(szTemp));
for(j=0;j<MAXBATTLENUM;j++){
if(PkTeamList[i].BHistory[j].use != 0){
sprintf(szTemp,"%d,%d|",PkTeamList[i].BHistory[j].teamnum,PkTeamList[i].BHistory[j].flg);
strcat(szWriteData2,szTemp);
}
}
fprintf(fp,"%d_%d|%s|%s|%s|%d|%d|%d|%d|%d|_%s_%s\n",
i,PkTeamList[i].teamnum,"NOUSE",PkTeamList[i].teamname,PkTeamList[i].leadercdkey,
PkTeamList[i].win,PkTeamList[i].lost,PkTeamList[i].battleplay,PkTeamList[i].score,
PkTeamList[i].inside,szWriteData,szWriteData2);
}
}
fclose(fp);
}
/*BOOL PKLIST_LoadPkTeamListData( char *data)
{
int k=1, array=-1, teamcount=0;
char buf[10240], buf1[512];
if( PkTeamList == NULL || data == NULL ){
//andy_log
print(" ANDY PkTeamList=NULL || data = NULL \n");
return FALSE;
}
while( getStringFromIndexWithDelim( data, " ", k, buf, sizeof( buf)) !=FALSE ) {
k++;
print("\n read buf:%s\n", buf);
if( getStringFromIndexWithDelim( buf, "_", 1, buf1, sizeof( buf1)) == FALSE ) continue;
array = atoi( buf1);
if( array<0 || array>=maxteam ){
print("err 1 buf:%s\n", buf);
continue;
}
if( getStringFromIndexWithDelim( buf, "_", 2, buf1, sizeof( buf1)) == FALSE ){
print("err 2 buf:%s\n", buf);
continue;
}
if( PKLIST_LoadPkTeamListDataSub( array, buf1 ) == FALSE ){
print("err 3 buf:%s\n", buf);
continue;
}
if( getStringFromIndexWithDelim( buf, "_", 3, buf1, sizeof( buf1)) == FALSE ){
print("err 4 buf:%s\n", buf);
continue;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -