chuyiwen_gmsv/npc/npc_welfare.c

391 lines
10 KiB
C
Raw Normal View History

2016-12-24 08:45:52 +08:00
#include "version.h"
#ifdef _NPC_WELFARE
#ifdef _PROFESSION_SKILL // WON ADD <20><><EFBFBD><EFBFBD>ְҵ<D6B0><D2B5><EFBFBD><EFBFBD>
#include <string.h>
#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 "profession_skill.h"
#include "chatmagic.h"
#include "npc_welfare.h"
#include "npc_exchangeman.h"
static void NPC_Welfare_selectWindow(int meindex, int toindex, int num, int select);
//<2F><><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD>NPC<50>ij<EFBFBD>ʼ<EFBFBD><CABC>
BOOL NPC_WelfareInit( int meindex )
{
CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEWELFARE);
//print("<22><><EFBFBD><EFBFBD>:%s\n",CHAR_getChar( meindex, CHAR_NAME));
return TRUE;
}
//<2F>Ի<EFBFBD>ʱ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
void NPC_WelfareTalked( 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;
}
NPC_Welfare_selectWindow( meindex, talkerindex,0,-1);
}
static void NPC_Welfare_selectWindow( int meindex, int toindex, int num,int select)
{
switch(num){
case 0:
//free
NPC_WelfareMakeStr(meindex, toindex, select);
break;
case 1:
break;
}
}
void NPC_WelfareWindowTalked( int meindex, int talkerindex,
int seqno, int select, char *data)
{
int skill, i, j;
int cost;
int skillID=0;
char buf[64];
char argstr[NPC_UTIL_GETARGSTR_BUFSIZE];
char msg[512];
char message[64];
int fd = getfdFromCharaIndex( talkerindex );
double rate= 1.0;
int skillarray;
int p_class=0, need_class=0;
int profession_skill_point;
memset( message, -1, sizeof(message) );
if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) {
return;
}
if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){
print("GetArgStrErr");
return;
}
makeStringFromEscaped( data);
getStringFromIndexWithDelim(data,"|",1,buf,sizeof(buf));
skill=atoi(buf);
getStringFromIndexWithDelim(data,"|",2,buf,sizeof(buf));
cost=atoi(buf);
if( NPC_Util_GetStrFromStrWithDelim( argstr, "profession_skill", msg, sizeof( msg)) != NULL){
getStringFromIndexWithDelim(msg,",",skill,buf,sizeof(buf));
skillID=atoi(buf);
}
if(skillID < 0) return ;
if( CHAR_getWorkInt( CONNECT_getCharaindex(fd), CHAR_WORKBATTLEMODE) != BATTLE_CHARMODE_NONE) return ;
if( NPC_Util_GetStrFromStrWithDelim( argstr, "skill_rate", msg, sizeof( msg)) != NULL){
rate = atof( msg);
}
skillarray = PROFESSION_SKILL_getskillArray( skillID );
if(skillarray == -1){
CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);
return ;
}
// <20>ж<EFBFBD>ְҵ
{
if( NPC_Util_GetStrFromStrWithDelim( argstr, "profession_class", msg, sizeof(msg) ) == NULL){
return ;
}else{
p_class = atoi(msg);
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְҵ
need_class = PROFESSION_SKILL_getInt( skillarray, PROFESSION_SKILL_PROFESSION_CLASS );
if( CHAR_getInt( talkerindex, PROFESSION_CLASS ) == 0 ){
char token[256];
memset(token, -1, sizeof(token) );
sprintf( token, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD>ְ!" );
CHAR_talkToCli( talkerindex, meindex, token, CHAR_COLORYELLOW);
CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);
return;
}
if( CHAR_getInt( talkerindex, PROFESSION_CLASS ) != need_class && need_class != 4 ){
char token[256];
memset(token, -1, sizeof(token) );
sprintf( token, "<EFBFBD>˼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>!" );
CHAR_talkToCli( talkerindex, meindex, token, CHAR_COLORYELLOW);
CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);
return;
}
}
// <20>ж<EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
profession_skill_point = CHAR_getInt( talkerindex, PROFESSION_SKILL_POINT );
if( profession_skill_point <= 0 ){
char token[256];
memset(token, -1, sizeof(token) );
sprintf( token, "<EFBFBD><EFBFBD>Ŀǰû<EFBFBD><EFBFBD>ѧϰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>!" );
CHAR_talkToCli( talkerindex, meindex, token, CHAR_COLORYELLOW);
CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);
return;
}
}
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ѧϰ<D1A7><CFB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
int temp[4] = {0}, count = 0, flag = -1 , need_percent = -1, need_count = 0;
for( i=0; i<4; i++){
int limit = -1;
flag = -1;
limit = PROFESSION_SKILL_getInt( skillarray, PROFESSION_SKILL_LIMIT1+i*2 );
need_percent = PROFESSION_SKILL_getInt( skillarray, PROFESSION_SKILL_LIMIT1+i*2 + 1 );
if( limit!= 0 && need_percent == 0 ) need_count++;
if( limit == 0 ){
continue;
}else if( limit == -1 ){
for( j=0; j<PROFESSION_MAX_LEVEL; j++ ){
if( CHAR_getCharSkill( talkerindex, j) > 0 ) break;
}
if( j >= PROFESSION_MAX_LEVEL ){
char token[256];
sprintf( token, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD>ս<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><EFBFBD><EFBFBD>ѧϰ<EFBFBD><EFBFBD>");
CHAR_talkToCli( talkerindex, meindex, token, CHAR_COLORYELLOW);
CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);
return;
}
}else{
flag = -1;
for( j=0; j<PROFESSION_MAX_LEVEL; j++ ){
// <20>жϼ<D0B6><CFBC><EFBFBD>
if( CHAR_getCharSkill( talkerindex, j) == limit ){
int skill_level = -1;
CHAR_HaveSkill* hskill;
flag = -2;
hskill = CHAR_getCharHaveSkill( talkerindex, j );
skill_level = SKILL_getInt( &hskill->skill, SKILL_LEVEL);
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( skill_level >= need_percent ){
flag = 1; break;
}
}
}
// δ<><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( flag == -1 && need_percent == 0 ){
temp[count] = limit;
count ++;
}else if( flag == -1 ){
char token[256];
memset(token, -1, sizeof(token) );
sprintf( token, "<EFBFBD><EFBFBD>δѧ<EFBFBD><EFBFBD>%s!", PROFESSION_SKILL_getChar( limit, PROFESSION_SKILL_NAME) );
CHAR_talkToCli( talkerindex, -1, token, CHAR_COLORYELLOW);
CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);
return;
}else if( flag == -2 ){
char token[256];
memset(token, -1, sizeof(token) );
sprintf( token, "%s<><73><EFBFBD><EFBFBD><EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD>%d!", PROFESSION_SKILL_getChar( limit, PROFESSION_SKILL_NAME), need_percent );
CHAR_talkToCli( talkerindex, -1, token, CHAR_COLORYELLOW);
CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);
return;
}
}
}
if( count == need_count && need_count != 0 ){
char msg[256] = {0};
sprintf( msg, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD> " );
for( i = 0; i< count; i++ ){
if( temp[i] != 0 ){
char token[50] = {0};
sprintf( token, "%s ", PROFESSION_SKILL_getChar( temp[i], PROFESSION_SKILL_NAME) );
strcat( msg, token );
}
}
sprintf( msg, "%s <20><>һ<EFBFBD>ּ<EFBFBD><D6BC><EFBFBD>", msg );
CHAR_talkToCli( talkerindex, -1, msg, CHAR_COLORYELLOW);
CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);
return;
}
}
// <20>жϽ<D0B6>Ǯ
{
cost = PROFESSION_SKILL_getInt( skillarray, PROFESSION_SKILL_COST );
cost = cost * rate;
if(CHAR_getInt(talkerindex,CHAR_GOLD) < cost){
CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);
return;
}
}
#ifdef _NPC_ProfessionTrans
//<2F>ж<EFBFBD>ת<EFBFBD><D7AA>
{
if( NPC_Util_GetStrFromStrWithDelim( argstr, "trans", msg, sizeof(msg) ) != NULL){
int trans = atoi(msg);
print("\nת<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>:%d,%d",CHAR_getInt( talkerindex, CHAR_TRANSMIGRATION),trans);
if( CHAR_getInt( talkerindex, CHAR_TRANSMIGRATION) < trans){
if( NPC_Util_GetStrFromStrWithDelim( argstr, "trans_msg", msg, sizeof(msg) ) != NULL){
CHAR_talkToCli( talkerindex, meindex, msg, CHAR_COLORYELLOW);
return;
}
else{
CHAR_talkToCli( talkerindex, meindex, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD><EFBFBD>", CHAR_COLORYELLOW);
return;
}
}
}
}
#endif
// <20><><EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD>
{
int skill_level = 0;
// <20><>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȸ<EFBFBD>50<35><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>10
if( (skillID == 63) || (skillID == 64) || (skillID == 65) ){
int Pskillid = -1;
skill_level = 50;
Pskillid = PROFESSION_SKILL_getskillArray( skillID );
}else{
skill_level = 10;
}
if( PROFESSION_SKILL_ADDSK( talkerindex, skillID, skill_level ) == -1 ) return;
CHAR_DelGold( talkerindex, cost );
CHAR_sendStatusString( talkerindex , "S");
NPC_Welfare_selectWindow( meindex, talkerindex,0,-1);
}
// <20><><EFBFBD><EFBFBD>ѶϢ
{
char token[256];
int next_profession_skill_point = profession_skill_point-1;
CHAR_setInt( talkerindex, PROFESSION_SKILL_POINT, next_profession_skill_point );
memset(token, -1, sizeof(token) );
sprintf( token, "<EFBFBD><EFBFBD>ѧϰ<EFBFBD><EFBFBD> %s<><73>ʣ<EFBFBD><CAA3>ѧϰ<D1A7><CFB0><EFBFBD><EFBFBD> %d"
,PROFESSION_SKILL_getChar( skillarray, PROFESSION_SKILL_NAME )
,next_profession_skill_point );
CHAR_talkToCli( talkerindex, -1, token, CHAR_COLORYELLOW);
CHAR_sendCToArroundCharacter( CHAR_getWorkInt( talkerindex , CHAR_WORKOBJINDEX ));
}
}
void NPC_WelfareMakeStr(int meindex,int toindex,int select)
{
char argstr[NPC_UTIL_GETARGSTR_BUFSIZE];
char msg[256];
double rate=1.0;
int i=0;
char token[65530];
int fd = getfdFromCharaIndex( toindex);
if(select==0){
sprintf(token,"0|0");
lssproto_WN_send( fd, WINDOW_MESSAGETYPE_PETSKILLSHOP,
WINDOW_BUTTONTYPE_NONE,
CHAR_WINDOWTYPE_WINDOWPETSKILLSHOP,
CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX),
token);
}
if(NPC_Util_GetArgStr( meindex, argstr, sizeof(argstr))==NULL){
print("GetArgStrErr");
return;
}
if( NPC_Util_GetStrFromStrWithDelim( argstr, "main_msg", msg, sizeof( msg)) == NULL){
print("mainERR");
return ;
}
sprintf(token,"1|%s|%s", CHAR_getChar(meindex,CHAR_NAME), msg);
if( NPC_Util_GetStrFromStrWithDelim( argstr, "skill_rate", msg, sizeof( msg)) != NULL){
rate=atof(msg);
}
if( NPC_Util_GetStrFromStrWithDelim( argstr, "profession_skill", msg, sizeof( msg) ) != NULL){
int skillarray;
int skillID;
int cost;
char token2[265];
char buf[64];
i=1;
while( getStringFromIndexWithDelim(msg,",",i,buf,sizeof(buf)) !=FALSE ){
i++;
skillID=atoi(buf);
skillarray = PROFESSION_SKILL_getskillArray( skillID );
if( PROFESSION_SKILL_CHECKINDEX( skillarray ) == FALSE ) continue;
cost = PROFESSION_SKILL_getInt( skillarray, PROFESSION_SKILL_COST );
cost = (int)cost*rate;
sprintf(token2,"|%s|%d|%s|%d",
PROFESSION_SKILL_getChar( skillarray, PROFESSION_SKILL_NAME ), // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cost, // <20><><EFBFBD><EFBFBD>
PROFESSION_SKILL_getChar( skillarray, PROFESSION_SKILL_TXT ), // ˵<><CBB5>
PROFESSION_SKILL_getInt( skillarray, PROFESSION_SKILL_ICON ) // ͼʾ
);
strcat(token,token2);
}
}
lssproto_WN_send( fd, WINDOW_MESSAGETYPE_PROFESSIONSHOP,
WINDOW_BUTTONTYPE_NONE,
WINDOW_MESSAGETYPE_PROFESSIONSHOP,
CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX),
token);
return;
}
#endif
#endif