#include "version.h" #include #include "char.h" #include "object.h" #include "char_base.h" #include "npcutil.h" #include "lssproto_serv.h" #include "saacproto_cli.h" #include "readmap.h" #include "battle.h" #include "log.h" #include "enemy.h" #include "handletime.h" #include "npc_eventaction.h" #include "npc_sellsthman.h" #include "pet_skill.h" #ifdef _NPC_SELLSTH enum { NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT1, NPC_WORK_PAGE = CHAR_NPCWORKINT2, NPC_WORK_NUM = CHAR_NPCWORKINT3, NPC_WORK_CALLPAGE = CHAR_NPCWORKINT4, NPC_WORK_CALLNUM = CHAR_NPCWORKINT5, /* NPC_WORK_ROUTETOY = CHAR_NPCWORKINT2, NPC_WORK_ROUTEPOINT = CHAR_NPCWORKINT3, NPC_WORK_ROUNDTRIP = CHAR_NPCWORKINT4, NPC_WORK_MODE = CHAR_NPCWORKINT5, NPC_WORK_CURRENTROUTE = CHAR_NPCWORKINT6, NPC_WORK_ROUTEMAX = CHAR_NPCWORKINT7, NPC_WORK_WAITTIME = CHAR_NPCWORKINT8, NPC_WORK_CURRENTTIME = CHAR_NPCWORKINT9, NPC_WORK_SEFLG = CHAR_NPCWORKINT10, */ }; #define SELLSTHMESS_LOOP 2000 enum{ WINDOW_TALK=0, WINDOW_START=10, WINDOW_MENU, WINDOW_LOOK, WINDOW_CALL, WINDOW_FIND, WINDOW_SELLON, WINDOW_SELLHANDLE, WINDOW_BUYMESS, WINDOW_BUYHANDLE, WINDOW_HELP, WINDOW_END, NPC_WINDOW_TALK=300, NPC_WINDOW_START, NPC_WINDOW_MENU, NPC_WINDOW_LOOK, NPC_WINDOW_FIND, NPC_WINDOW_NEXT, NPC_WINDOW_SELLON, NPC_WINDOW_SELLHANDLE, NPC_WINDOW_BUYMESS, NPC_WINDOW_BUYHANDLE, NPC_WINDOW_HELP, NPC_WINDOW_END, }; #define MAX_LISTPAGE 20 #define MAX_LISTNUM 12 struct _tagNSellSthList{ int use; int fd; int sellindex; int selltype; int uindex; int Iindex; char headmess[256]; char sellmess[256]; }NSellSthList[MAX_LISTPAGE][MAX_LISTNUM]; static int StructBeInit=0; static void NPC_SellsthMan_selectWindow( int meindex, int toindex, int num,int select, char *data); BOOL NPC_getSellSth_ListString( int page, int num, char *ListString, int slen ); BOOL NPC_setSellSth_ListString( int meindex, int toindex, int *page, int *num, char *data ); BOOL NPC_getSellSth_ViewString( int page, int num, char *ListString, int slen ); int NPC_getSellSth_FreeTiCount( void); void NPC_SellrePutList( int defpage, int ti) { int i; if( NSellSthList[defpage][ti].use != 0 ) return; for( i=(ti+1); i= MAX_LISTNUM ) return; if( NPC_getSellSth_ViewString( page, num, token, sizeof( token)) == FALSE ){ return; } windowtype = WINDOWS_MESSAGETYPE_SELLSTHVIEW; windowno = NPC_WINDOW_NEXT; } break; case WINDOW_CALL: { int num; int page = CHAR_getWorkInt( toindex, CHAR_WORKSHOPRELEVANT); num = atoi( data); if( num <0 || num >= MAX_LISTNUM ) return; if( NSellSthList[page][num].use == 0 )return; if( !CHAR_CHECKINDEX( NSellSthList[page][num].sellindex) || NSellSthList[page][num].fd != getfdFromCharaIndex( NSellSthList[page][num].sellindex) ) return; sprintf( token, "%s欲购买你拍卖(%d页,%d项)的物品,\n%s正在%s。", CHAR_getChar( toindex, CHAR_NAME), page, num, CHAR_getChar( toindex, CHAR_NAME), MAP_getFloorName( CHAR_getInt( toindex, CHAR_FLOOR)) ); if( CHAR_getWorkInt( NSellSthList[page][num].sellindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE ){ CHAR_talkToCli( NSellSthList[page][num].sellindex, meindex, token, CHAR_COLORYELLOW); }else{ int callfd = getfdFromCharaIndex( NSellSthList[page][num].sellindex); buttontype = WINDOW_BUTTONTYPE_OK; windowno = NPC_WINDOW_END; lssproto_WN_send( callfd, windowtype, buttontype, windowno, CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); } return; } break; case WINDOW_FIND: { int page, num; page = select >> 16; num = select & 0x0000ffff; page = (page<0||page>=MAX_LISTPAGE)?0:page; num = (num<0||num>=MAX_LISTNUM)?0:num; if( NPC_getSellSth_ListString( page, num, token, sizeof( token) ) == FALSE ) return; windowtype = WINDOWS_MESSAGETYPE_SELLSTHMENU; windowno = NPC_WINDOW_NEXT; } break; case WINDOW_SELLON: if( CHAR_getWorkInt( toindex, CHAR_WORKSELLSTHNUM) >= 3 ){ CHAR_talkToCli( toindex, meindex, "最多只能登记叁次。", CHAR_COLORRED); return; }else if( CHAR_getInt( toindex, CHAR_GOLD) < 100 ){ CHAR_talkToCli( toindex, meindex, "需付100石币才能登记。", CHAR_COLORRED); return; } if( NPC_getSellSth_FreeTiCount() < 1 ){ if( NPC_Util_GetStrFromStrWithDelim( npcarg, "FULL_MSG", token, sizeof( token) ) == NULL) { print("SellSthMan err Can't Get FULL_MSG string\n"); return; } buttontype = WINDOW_BUTTONTYPE_OK; windowno = NPC_WINDOW_END; }else{ windowtype = WINDOWS_MESSAGETYPE_SELLSTHSELL; windowno = NPC_WINDOW_SELLON; } break; case WINDOW_SELLHANDLE: { int page, num; if( NPC_setSellSth_ListString( meindex, toindex, &page, &num, data ) == FALSE ) { if( NPC_Util_GetStrFromStrWithDelim( npcarg, "ERROR_MSG", token, sizeof( token) ) == NULL) { print("SellSthMan err Can't Get ERROR_MSG string\n"); return; } }else if( NPC_Util_GetStrFromStrWithDelim( npcarg, "OK_MSG", token, sizeof( token) ) == NULL) { print("SellSthMan err Can't Get OK_MSG string\n"); return; } { int sellnum = CHAR_getWorkInt( toindex, CHAR_WORKSELLSTHNUM); CHAR_setWorkInt( toindex, CHAR_WORKSELLSTHNUM, sellnum+1); CHAR_DelGold( toindex, 100); } buttontype = WINDOW_BUTTONTYPE_OK; windowno = NPC_WINDOW_END; } break; case WINDOW_BUYMESS: break; case WINDOW_BUYHANDLE: break; case WINDOW_HELP: break; case WINDOW_END: break; } lssproto_WN_send( fd, windowtype, buttontype, windowno, CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token); } void NPC_SellsthManWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) { if(NPC_Util_isFaceToFace( meindex ,talkerindex , 2) == FALSE) { if(NPC_Util_isFaceToChara( talkerindex, meindex, 1) == FALSE) return; } if( select == WINDOW_BUTTONTYPE_CANCEL || select == WINDOW_BUTTONTYPE_NO) return; switch( seqno) { case NPC_WINDOW_START: NPC_SellsthMan_selectWindow( meindex, talkerindex, WINDOW_MENU, select, NULL); break; case NPC_WINDOW_MENU: switch( atoi( data)) { case 1://查看 CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); NPC_SellsthMan_selectWindow( meindex, talkerindex, WINDOW_FIND, 0, NULL); break; case 2://登记 NPC_SellsthMan_selectWindow( meindex, talkerindex, WINDOW_SELLON, select, NULL); break; } break; case NPC_WINDOW_LOOK: break; case NPC_WINDOW_FIND://包含买 break; case NPC_WINDOW_NEXT: { int ti; int page = CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT); if( select == WINDOW_BUTTONTYPE_PREV ){ page = ((page-1)<0)?0:page-1; }else if( select == WINDOW_BUTTONTYPE_NEXT ){ page = ((page+1)>=MAX_LISTPAGE)?(MAX_LISTPAGE-1):(page+1); }else if( select == WINDOW_BUTTONTYPE_OK ){ //买 }else if( select == WINDOW_BUTTONTYPE_YES ){ //买 NPC_SellsthMan_selectWindow( meindex, talkerindex, WINDOW_CALL, select, data); return; }else if( select == 0 ){ NPC_SellsthMan_selectWindow( meindex, talkerindex, WINDOW_LOOK, select, data); return; } ti = (page<<16); CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, page); NPC_SellsthMan_selectWindow( meindex, talkerindex, WINDOW_FIND, ti, data); } break; case NPC_WINDOW_SELLON: NPC_SellsthMan_selectWindow( meindex, talkerindex, WINDOW_SELLHANDLE, select, data); break; case NPC_WINDOW_SELLHANDLE: break; case NPC_WINDOW_BUYMESS: break; case NPC_WINDOW_BUYHANDLE: break; case NPC_WINDOW_HELP: break; case NPC_WINDOW_END: break; } } static int runType = 0; void NPC_SellsthManLoop( int meindex) { int i, j; char headmsg[256]; char token[256]; int playernum, page, num; int floor = CHAR_getInt( meindex, CHAR_FLOOR); playernum = CHAR_getPlayerMaxNum(); runType = (++runType)%100; page = CHAR_getWorkInt( meindex, NPC_WORK_CALLPAGE ); num = CHAR_getWorkInt( meindex, NPC_WORK_CALLNUM ); for( i=0; i= MAX_LISTNUM ){ num = 0; if( ++page >= MAX_LISTPAGE ){ page=0; } } } CHAR_setWorkInt( meindex, NPC_WORK_CALLPAGE, page); CHAR_setWorkInt( meindex, NPC_WORK_CALLNUM, num); if( i >= MAX_LISTNUM )return; sprintf( headmsg, "拍卖频道(%d页%d项):%s (拍卖者:%s)。", page, num, NSellSthList[page][num].headmess, CHAR_getChar( NSellSthList[page][num].sellindex, CHAR_NAME) ); if( NSellSthList[page][num].selltype==1 ){ sprintf( token, "拍卖道具:%s。", ITEM_getChar( NSellSthList[page][num].Iindex, ITEM_NAME) ); }else{ sprintf( token, "拍卖宠物:%s LV:%d %s。", CHAR_getChar( NSellSthList[page][num].Iindex, CHAR_NAME), CHAR_getInt( NSellSthList[page][num].Iindex, CHAR_LV), #ifdef _PET_2TRANS CHAR_getInt( NSellSthList[page][num].Iindex , CHAR_TRANSMIGRATION) == 2 )?"二转":(CHAR_getInt( NSellSthList[page][num].Iindex , CHAR_TRANSMIGRATION) == 1 )?"一转":"") #else ( CHAR_getInt( NSellSthList[page][num].Iindex , CHAR_TRANSMIGRATION) == 1 )?"转":"" #endif ); } for(i=0; i= MAX_LISTNUM ){ num = 0; if( ++page >= MAX_LISTPAGE ){ page=0; } } CHAR_setWorkInt( meindex, NPC_WORK_CALLPAGE, page); CHAR_setWorkInt( meindex, NPC_WORK_CALLNUM, num); if( runType%10 == 0 ){ for( i=0; i slen ) return FALSE; sprintf( ListString, "%d|%d|%s", listnum, page, buff); printf( "ANDY ListString:%s\nstrlen = %d \n", ListString, strlen( ListString) ); if( strlen( ListString) <= 0 ) return FALSE; return TRUE; } BOOL NPC_setSellSth_ListString( int meindex, int toindex, int *page, int *num, char *data ) { char buf1[256]; int i, j; int fd = getfdFromCharaIndex( toindex); for( i=0; i MAX_LISTNUM ) return FALSE; if( NSellSthList[page][num].use == 0 )return FALSE; if( !CHAR_CHECKINDEX( NSellSthList[page][num].sellindex ) )return FALSE; sellindex = NSellSthList[page][num].sellindex; if( NSellSthList[page][num].selltype == 1 ){//道具 int itemindex, crushe; ti = NSellSthList[page][num].uindex; itemindex = CHAR_getItemIndex( sellindex , ti); if( !ITEM_CHECKINDEX( itemindex) ) return FALSE; crushe = ITEM_getItemDamageCrusheED( itemindex); sprintf( buff, "1|%s|%s|0|%d|%d|%d|0|0|0|%s|||||||", makeEscapeString( ITEM_getChar( itemindex, ITEM_SECRETNAME), buf2, sizeof( buf2)), makeEscapeString( ITEM_getChar( itemindex, ITEM_NAME), buf1, sizeof( buf1)), ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER), crushe, ITEM_getInt( itemindex, ITEM_USEPILENUMS), ITEM_getChar( itemindex, ITEM_EFFECTSTRING) ); }else if( NSellSthList[page][num].selltype == 2 ){//宠物 int petindex, i; ti = NSellSthList[page][num].uindex; petindex = CHAR_getCharPet( sellindex, ti); if( !CHAR_CHECKINDEX( petindex) ) return FALSE; //TYPE|名| |图|等级|转| |攻|防|敏|技1|技2|技3|技4|技5|技6|技7 sprintf( buff, "2|%s|%s|%d|%d|%d|%d|%d|%d|%d|", makeEscapeString( CHAR_getChar( petindex, CHAR_NAME ), buf1, sizeof(buf1)), makeEscapeString( CHAR_getUseName( petindex), buf2, sizeof(buf2)), CHAR_getInt( petindex, CHAR_BASEBASEIMAGENUMBER), CHAR_getInt( petindex , CHAR_LV), CHAR_getInt( petindex , CHAR_TRANSMIGRATION), CHAR_getWorkInt(petindex , CHAR_WORKMAXHP), CHAR_getWorkInt( petindex, CHAR_WORKATTACKPOWER), CHAR_getWorkInt( petindex, CHAR_WORKDEFENCEPOWER), CHAR_getWorkInt( petindex, CHAR_WORKQUICK)); for( i=0; i<7; i++){ int skillarray, skillID; skillID = CHAR_getPetSkill( petindex, i); skillarray = PETSKILL_getPetskillArray( skillID); if( PETSKILL_CHECKINDEX( skillarray) ){ strcat( buff, PETSKILL_getChar( skillarray, PETSKILL_NAME) ); } strcat( buff, "|"); } } sprintf( ListString, "%d|%s|%s|%s|%s", num, CHAR_getChar( sellindex, CHAR_NAME), NSellSthList[page][num].headmess, NSellSthList[page][num].sellmess, buff ); if( strlen( ListString) <= 0 ){ print("err ListString:%s strlen <= %d\n", ListString, strlen( ListString)); return FALSE; } return TRUE; } int NPC_getSellSth_FreeTiCount( void) { int counts = 0, i, j; for( i=0; i