#include "version.h" #include #include "char.h" #include "object.h" #include "char_base.h" #include "npcutil.h" #include "lssproto_serv.h" #include "pet_skill.h" #include "readmap.h" #include "battle.h" #include "configfile.h" #include "util.h" #include "npc_eventaction.h" #include "npc_freepetskillshop.h" #ifdef _PETSKILL_SHOP_LUA #include "mylua/function.h" #endif #ifdef _CFREE_petskill enum { CHAR_WORK_SKILLSELECT = CHAR_NPCWORKINT1, }; enum { SELECTSKILL_START=10, SELECTSKILL_TEACH=23, SELECTSKILL_END=30, }; enum { START_WINDOW=0, SKILL_WINDOW, MEEND_WINDOW, }; static void NPC_FreePetSkillShop_selectWindow( int meindex, int toindex, int num,int select); BOOL NPC_FreePetSkillMakeStr(int meindex,int toindex, int select); //BOOL NPC_CHECKFREEPETSKILL( int toindex, int petindex, int skillID); BOOL NPC_SkillShopItemCheck(int meindex,int talker,int itemNo, int cou); BOOL NPC_SkillShopDelItems(int meindex,int talker, char *buf); BOOL NPC_SkillShopPetCheck( int toindex, int petindex, int skillID ); BOOL NPC_SkillShopWarp( int meindex, int talkindex); #define MAXNPCPOINT 10 BOOL NPC_FreePetSkillShopInit( int meindex ) { char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; char msg[256]; CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_FREESKILLSHOP ); CHAR_setWorkInt( meindex, CHAR_WORK_SKILLSELECT, 0); if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ print("GetArgStrErr NO arg !!"); return FALSE; } if( NPC_Util_GetStrFromStrWithDelim( npcarg, "pet_skill", msg, sizeof( msg)) != NULL){ char buf[256], filename[256]; int k=1, skillID, skillarray; while( getStringFromIndexWithDelim( msg, ",", k, buf, sizeof( buf) ) ){ k++; skillID=atoi(buf); skillarray = PETSKILL_getPetskillArray( skillID); if( PETSKILL_CHECKINDEX( skillarray) == FALSE ) continue; if( PETSKILL_getInt( skillarray, PETSKILL_ILLEGAL) == 1){ if( NPC_Util_CheckAssignArgFile( meindex, filename) != NULL ){ print("\n宠物技能不规范:[%d-%s] ->文件:%s\n", skillID, PETSKILL_getChar( skillarray, PETSKILL_NAME), filename ); } } } }else{ return FALSE; } return TRUE; } void NPC_FreePetSkillShopTalked( int meindex , int talkerindex , char *szMes ,int color ) { if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { return; } if(NPC_Util_isFaceToFace(talkerindex,meindex,2 )==FALSE){ if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; } CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 1 ); NPC_FreePetSkillShop_selectWindow( meindex, talkerindex, START_WINDOW,-1); } static void NPC_FreePetSkillShop_selectWindow( int meindex, int toindex, int num,int select) { char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; char token[1024]; int fd = getfdFromCharaIndex( toindex); int buttontype = 0, windowtype = 0, windowno = 0; char buf1[256]; if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ print("GetArgStrErr"); return ; } switch(num) { case START_WINDOW: { BOOL Evflg = TRUE; if( NPC_Util_GetStrFromStrWithDelim( npcarg, "start_msg", token, sizeof( token)) == NULL) { CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); return; } if( CHAR_getWorkInt( toindex, CHAR_WORKSHOPRELEVANT) != 1 ) { CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); return; } //玩家条件判断 if( NPC_Util_GetStrFromStrWithDelim( npcarg, "FREE", buf1, sizeof( buf1)) != NULL ) { if( NPC_ActionPassCheck( meindex, toindex, buf1) == FALSE ) { Evflg = FALSE; } } if( Evflg == FALSE) { CHAR_talkToCli( toindex, -1, "你想让宠物学特殊技能?可你的条件还不够喔!", CHAR_COLORYELLOW); CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 0); return; }else { windowtype = WINDOW_MESSAGETYPE_MESSAGE; buttontype = WINDOW_BUTTONTYPE_NEXT; windowno = SELECTSKILL_START; CHAR_setWorkInt( toindex, CHAR_WORKSHOPRELEVANT, 2); lssproto_WN_send( fd, windowtype, buttontype, windowno, CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX), token ); } } break; case SKILL_WINDOW: if( NPC_FreePetSkillMakeStr( meindex, toindex, select) == FALSE ) { print("\n npc_freepetskillshop.c 错误"); } break; case MEEND_WINDOW: break; } } void NPC_FreePetSkillShopWindowTalked( int meindex, int talkerindex, int seqno, int select, char *data) { int skill; int pet; int slot; int cost; int skillID=0; int petskillindex; char buf[64]; char argstr[NPC_UTIL_GETARGSTR_BUFSIZE]; char msg[512]; int petindex; char msgbuf[128]; double rate= 1.0; if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){ print("GetArgStrErr"); return; } if( CHAR_getInt( talkerindex , CHAR_WHICHTYPE ) != CHAR_TYPEPLAYER ) { return; } if(NPC_Util_isFaceToFace(talkerindex,meindex,2 )==FALSE){ if( NPC_Util_CharDistance( talkerindex, meindex ) > 1) return; } if( CHAR_getWorkInt( talkerindex, CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) return ; switch( seqno) { case SELECTSKILL_START: if( CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT) != 2 ) { CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); return; } NPC_FreePetSkillShop_selectWindow( meindex, talkerindex, SKILL_WINDOW, -1); break; case SELECTSKILL_TEACH: if( CHAR_getWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT) != 3 ) { CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); return; } makeStringFromEscaped( data); getStringFromIndexWithDelim(data,"|",1,buf,sizeof(buf)); skill=atoi(buf); getStringFromIndexWithDelim(data,"|",2,buf,sizeof(buf)); pet=atoi(buf); getStringFromIndexWithDelim(data,"|",3,buf,sizeof(buf)); slot=atoi(buf); getStringFromIndexWithDelim(data,"|",4,buf,sizeof(buf)); cost=atoi(buf); if( NPC_Util_GetStrFromStrWithDelim( argstr, "pet_skill", msg, sizeof( msg)) != NULL){ getStringFromIndexWithDelim(msg,",",skill,buf,sizeof(buf)); skillID=atoi(buf); } slot--; if( slot < 0 ) return; petindex = CHAR_getCharPet( talkerindex, pet-1); if( !CHAR_CHECKINDEX(petindex) ){ CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); return ; } if( NPC_Util_GetStrFromStrWithDelim( argstr, "skill_rate", msg, sizeof( msg)) != NULL){ rate = atof( msg); } petskillindex = PETSKILL_getPetskillArray( skillID ); if( !PETSKILL_CHECKINDEX( petskillindex)){ CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); return ; } cost = PETSKILL_getInt( petskillindex, PETSKILL_COST ); cost = cost * rate; //条件判断 if(CHAR_getInt(talkerindex,CHAR_GOLD) < cost){ CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); return; } #ifdef _PETSKILL_SHOP_LUA if(FreePetSkillShop(talkerindex, petindex, CHAR_getPetSkill(petindex, slot), skillID) == FALSE ) { return; } #endif if( NPC_CHECKFREEPETSKILL( talkerindex, petindex, skillID ) == TRUE ){ if( Action_RunDoEventAction( meindex, talkerindex, argstr) == FALSE ){ CHAR_talkToCli( talkerindex, -1, "所需物品不足!!", CHAR_COLORYELLOW); CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); CHAR_setWorkInt( talkerindex, CHAR_WORKSHOPRELEVANT, 0); return; } CHAR_setPetSkill( petindex, slot, skillID); CHAR_setInt( talkerindex, CHAR_GOLD, ( CHAR_getInt( talkerindex, CHAR_GOLD) - cost) ); snprintf( msgbuf, sizeof( msgbuf ), "W%d",pet-1); CHAR_sendStatusString( talkerindex, msgbuf ); CHAR_sendStatusString( talkerindex, "P"); CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); //WARP if( NPC_SkillShopWarp( meindex, talkerindex) == TRUE ) return; }else { CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD); CHAR_talkToCli( talkerindex, -1, "条件不足!!", CHAR_COLORYELLOW); } //ADD NPC_FreePetSkillShop_selectWindow( meindex, talkerindex, SKILL_WINDOW, -1); break; case SELECTSKILL_END: break; } return; } BOOL NPC_CHECKFREEPETSKILL( int toindex, int petindex, int skillID) { int skillindex=-1; char SCode[256]; char Free[256]; int i, petID; skillindex = PETSKILL_getPetskillArray( skillID ); memset( Free, 0, sizeof( Free)); if( !PETSKILL_CHECKINDEX( skillindex) ) { return FALSE; } petID = CHAR_getInt( petindex, CHAR_PETID); sprintf( SCode, "%s", PETSKILL_getChar( skillindex, PETSKILL_KINDCODE)); sprintf( Free, "%s", PETSKILL_getChar( skillindex, PETSKILL_FREE)); //CHECK CODE if( !strcmp( SCode, "\0")) { return TRUE; } for( i=0; i= cou ) return TRUE; } return FALSE; } BOOL NPC_SkillShopDelItems(int meindex,int talker, char *buf) { char buf1[256]; char item[256], cout[256]; int i=1; BOOL Evflg=TRUE; while( getStringFromIndexWithDelim( buf, ",", i,buf1, sizeof( buf1)) != FALSE ) { i++; if( strstr( buf1, "*") != NULL ) { getStringFromIndexWithDelim( buf1, "*", 1, item, sizeof( item)); getStringFromIndexWithDelim( buf1, "*", 2, cout, sizeof( cout)); }else { strcpy( item, buf1); strcpy( cout, "1"); } if( NPC_SkillShopItemCheck( meindex, talker, atoi( item), atoi( cout)) == FALSE ) { Evflg=FALSE; break; } if( Evflg == FALSE ) break; } if( Evflg == FALSE ) return FALSE; if( NPC_ActionDelItem( talker, buf) == TRUE ) { return TRUE; } return FALSE; } BOOL NPC_SkillShopPetCheck( int toindex, int petindex, int skillID ) { char Free[256]; int i; char data[256], msg[256]; int skillindex = PETSKILL_getPetskillArray( skillID ); memset( Free, 0, sizeof( Free)); sprintf( Free, "%s", PETSKILL_getChar( skillindex, PETSKILL_FREE)); if( NPC_Util_GetStrFromStrWithDelim( Free, "FREE", data, sizeof( data)) != NULL ) { BOOL EvFlg = TRUE; i=1; while( getStringFromIndexWithDelim( data, "|", i, msg, sizeof( msg)) != FALSE ) { i++; if( strstr( msg, "LV") != NULL ) { char LvStr[256]; int LV=0; if( strstr( msg, ">" ) != NULL ) { if( getStringFromIndexWithDelim( msg, ">", 2, LvStr, sizeof( LvStr)) != FALSE ) { LV = atoi( LvStr); if( CHAR_getInt( petindex, CHAR_LV) <= LV ) EvFlg = FALSE; } }else if( strstr( msg, "<")) { if( getStringFromIndexWithDelim( msg, "<", 2, LvStr, sizeof( LvStr)) != FALSE ) { LV = atoi( LvStr); if( CHAR_getInt( petindex, CHAR_LV) >= LV ) EvFlg = FALSE; } } }else if( strstr( msg, "SK") != NULL ) { int j=0, PskId=-1, ID; char strSK[256]; int petskillindex; getStringFromIndexWithDelim( msg, "=", 2, strSK, sizeof( strSK) ); ID = atoi( strSK); for( j=0; j < CHAR_MAXPETSKILLHAVE; j++) { PskId = CHAR_getPetSkill( petindex, j); petskillindex = PETSKILL_getPetskillArray( PskId ); if( !PETSKILL_CHECKINDEX( petskillindex)) continue; if( ID == PskId ) { if( strstr( msg, "!=") !=NULL ) EvFlg = FALSE; break; } } if( j == CHAR_MAXPETSKILLHAVE ) { EvFlg = FALSE; break; } } if( EvFlg == FALSE ) break; } if( EvFlg == FALSE ) { return FALSE; }else { return TRUE; } } return TRUE; } BOOL NPC_SkillShopWarp( int meindex, int talkindex) { char npcarg[NPC_UTIL_GETARGSTR_BUFSIZE]; char data[1024], buf1[256], buf2[256]; int i=1, j=1; BOOL EvFlg=FALSE; struct { int FLOOR; int X; int Y; }Points[MAXNPCPOINT]; if(NPC_Util_GetArgStr( meindex, npcarg, sizeof(npcarg))==NULL){ print("GetArgStrErr"); return FALSE; } for( i=0;i= MAXNPCPOINT ) break; } where = RAND( 0, i-1); CHAR_warpToSpecificPoint( meindex, Points[where].FLOOR, Points[where].X, Points[where].Y); EvFlg = TRUE; } if( NPC_Util_GetStrFromStrWithDelim( npcarg, "WARP", data, sizeof( data)) != NULL ) { int P_Floor,P_X,P_Y; getStringFromIndexWithDelim( data, ",", 1, buf2, sizeof( buf2)); P_Floor = atoi( buf2); getStringFromIndexWithDelim( data, ",", 2, buf2, sizeof( buf2)); P_X = atoi( buf2); getStringFromIndexWithDelim( data, ",", 3, buf2, sizeof( buf2)); P_Y = atoi( buf2); CHAR_warpToSpecificPoint( talkindex, P_Floor, P_X, P_Y); EvFlg = TRUE; } return EvFlg; } #endif