npc_poolitemshop.c

来自「石器时代8.0服务端完整源代码。可以直接编译」· C语言 代码 · 共 883 行 · 第 1/2 页

C
883
字号
			ITEM_getInt( itemindex, ITEM_ID) );

	CHAR_setDepotItemIndex( charaindex, ti, -1);
	ITEM_endExistItemsOne( itemindex);
}

void NPC_DepotItem_CheckRepeat( int talkerindex)
{
	int i, j, cnt=0, itemindex, itemindex1;

	for( i=0; i<(CHAR_MAXDEPOTITEMHAVE-1); i++){
		itemindex = CHAR_getDepotItemIndex( talkerindex, i);
		if( !ITEM_CHECKINDEX( itemindex)) continue;
		cnt=0;
		for( j=(i+1); j<CHAR_MAXDEPOTITEMHAVE; j++ ){
			itemindex1 = CHAR_getDepotItemIndex( talkerindex, j);
			if( itemindex==itemindex1) continue;
			if( !ITEM_CHECKINDEX( itemindex1)) continue;
			if( !strcmp( ITEM_getChar( itemindex, ITEM_UNIQUECODE),
				ITEM_getChar( itemindex1, ITEM_UNIQUECODE) ) ){
				NPC_DepotItem_CheckRepeat_Del( talkerindex, j, itemindex1);
				cnt++;
			}
		}
		if( cnt != 0 ){
			NPC_DepotItem_CheckRepeat_Del( talkerindex, i, itemindex);
		}
	}
}

BOOL NPC_DepotItem_InsertItem( int meindex, int talkerindex, int num)
{
	int emptyindex;
	int itemindex;
	int cost = CHAR_getWorkInt( meindex, NPC_WORK_COST);

	if( !CHAR_CheckDepotItem( talkerindex) ) return FALSE;
	if( (emptyindex=CHAR_findEmptyDepotItem( talkerindex) ) == -1 ) return FALSE;
	itemindex = CHAR_getItemIndex( talkerindex, num);
	if( !ITEM_CHECKINDEX( itemindex) )return FALSE;
#if 1 // 共同仓库不可存的物品
	if( ITEM_getInt( itemindex, ITEM_DROPATLOGOUT) || // 登出後消失
			ITEM_getInt( itemindex, ITEM_VANISHATDROP) || // 丢弃後消失
			!ITEM_getInt( itemindex, ITEM_CANPETMAIL)) { // 不可宠邮寄
		print("\n 改封包!!非法存放道具:%s ", CHAR_getChar( talkerindex, CHAR_CDKEY) );
		return FALSE;
	}
#endif
	if( CHAR_DelGold( talkerindex, cost ) == 0 ) return FALSE;

	CHAR_setItemIndex( talkerindex, num, -1);
	CHAR_sendItemDataOne( talkerindex, num);
	CHAR_setDepotItemIndex( talkerindex, emptyindex, itemindex);

//	CHAR_DelGold( talkerindex, cost );
	CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);

	LogItem(
		CHAR_getChar( talkerindex, CHAR_NAME ),
		CHAR_getChar( talkerindex, CHAR_CDKEY ),
#ifdef _add_item_log_name
		itemindex,
#else
		ITEM_getInt( itemindex, ITEM_ID),
#endif
		"Depot(存放道具)",
		CHAR_getInt( talkerindex,CHAR_FLOOR),
		CHAR_getInt( talkerindex,CHAR_X ),
 		CHAR_getInt( talkerindex,CHAR_Y ),
		ITEM_getChar( itemindex, ITEM_UNIQUECODE),
		ITEM_getChar( itemindex, ITEM_NAME),
		ITEM_getInt( itemindex, ITEM_ID) );

	NPC_DepotItem_CheckRepeat( talkerindex);

	return TRUE;
}

BOOL NPC_DepotItem_gettItem( int meindex, int talkerindex, int num)
{
	int emptyindex;
	int itemindex;

	if( !CHAR_CheckDepotItem( talkerindex) ) return FALSE;

	if( (emptyindex=CHAR_findEmptyItemBox( talkerindex)) == -1 ) return FALSE;
	itemindex = CHAR_getDepotItemIndex( talkerindex, num);
	if( !ITEM_CHECKINDEX( itemindex) )return FALSE;

	CHAR_setDepotItemIndex( talkerindex, num, -1);
	CHAR_setItemIndex( talkerindex, emptyindex, itemindex);
	CHAR_sendItemDataOne( talkerindex, emptyindex);
	
	CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);

	LogItem(
		CHAR_getChar( talkerindex, CHAR_NAME ),
		CHAR_getChar( talkerindex, CHAR_CDKEY ),
#ifdef _add_item_log_name
		itemindex,
#else
		ITEM_getInt( itemindex, ITEM_ID),
#endif
		"Depot(取出道具)",
		CHAR_getInt( talkerindex,CHAR_FLOOR),
		CHAR_getInt( talkerindex,CHAR_X ),
 		CHAR_getInt( talkerindex,CHAR_Y ),
		ITEM_getChar( itemindex, ITEM_UNIQUECODE),
		ITEM_getChar( itemindex, ITEM_NAME),
		ITEM_getInt( itemindex, ITEM_ID) );

	{
		int i, cnt=0;
		int work[CHAR_MAXDEPOTITEMHAVE];
		for( i = 0; i < CHAR_MAXDEPOTITEMHAVE; i ++ ) {
			work[i] = -1;
		}
		for( i = 0; i < CHAR_MAXDEPOTITEMHAVE; i ++ ) {
			itemindex = CHAR_getDepotItemIndex( talkerindex, i);
			if( !ITEM_CHECKINDEX( itemindex)) continue;
			work[ cnt++] = itemindex;
		}
		for( i = 0; i < CHAR_MAXDEPOTITEMHAVE; i ++ ) {
			CHAR_setDepotItemIndex( talkerindex, i, work[i]);
		}
	}


	return TRUE;
}
#endif

static void NPC_PoolItemShop_printWindow_Full( int meindex, int talkerindex)
{
	int fd;
	
	fd = getfdFromCharaIndex( talkerindex);
	if( fd != -1 ) {
		char	message[1024];
		char	buf[2048];
		
		strcpy( message, 
			"\n\n    超过的无法处理喔"
				);
		lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, 
						WINDOW_BUTTONTYPE_OK,
						CHAR_WINDOWTYPE_POOLITEMSHOP_FULL_MSG,
						CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX),
						makeEscapeString( message, buf, sizeof(buf)));
	}
	
}

static void NPC_PoolItemShop_printWindow_HaveItemFull( int meindex, int talkerindex)
{
	int fd;
	
	fd = getfdFromCharaIndex( talkerindex);
	if( fd != -1 ) {
		char	message[1024];
		char	buf[2048];
		
		strcpy( message, 
			"\n\n    道具不是已经满了吗"
				);
		lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, 
						WINDOW_BUTTONTYPE_OK,
						CHAR_WINDOWTYPE_POOLITEMSHOP_HAVEITEMFULL_MSG,
						CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX),
						makeEscapeString( message, buf, sizeof(buf)));
	}
}

static void NPC_PoolItemShop_printWindow_Pool( int meindex, int talkerindex)
{
	char	itemstring[65536-1024];
	char	sendstring[65536];
	char	argstr[NPC_UTIL_GETARGSTR_BUFSIZE];
	char	buff2[1024];
	char	buff3[1024];
	char	buff4[1024];
	int fd;
	
	fd = getfdFromCharaIndex( talkerindex);
	if( fd == -1 ) {
		fprint( "err\n");
		return;
	}

	NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr));
	
	snprintf( sendstring, sizeof( sendstring), "0|%d|%s|%s|%s|%s|",
			CHAR_getEmptyCharPoolItemIndexNum( talkerindex),
			CHAR_getChar( meindex, CHAR_NAME),
			NPC_PoolItemShop_getMsg_noarg( NPC_POOLITEMSHOP_MSG_POOL, 
										argstr, buff2, sizeof( buff2)),
			NPC_PoolItemShop_getMsg_noarg( NPC_POOLITEMSHOP_MSG_POOLFULL, 
										argstr, buff3, sizeof( buff3)),
			NPC_PoolItemShop_getMsg_noarg( NPC_POOLITEMSHOP_MSG_REALY, 
										argstr, buff4, sizeof( buff4))
			);
	
	NPC_PoolItemShop_MakeItemString_Pool( meindex, talkerindex, itemstring, sizeof( itemstring));
	strcat( sendstring, itemstring);
	lssproto_WN_send( fd, WINDOW_MESSAGETYPE_POOLITEMSHOPMAIN,
				WINDOW_BUTTONTYPE_NONE, 
				CHAR_WINDOWTYPE_POOLITEMSHOP_POOL_MSG,
				CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX),
				sendstring);
	
}

static void NPC_PoolItemShop_printWindow_Draw( int meindex, int talkerindex)
{
	char	itemstring[65536-1024];
	char	sendstring[65536];
	char	argstr[NPC_UTIL_GETARGSTR_BUFSIZE];
	char	buff[1024];
	char	buff2[1024];
	char	buff3[1024];
	int fd;
	
	fd = getfdFromCharaIndex( talkerindex);
	if( fd == -1 ) {
		fprint( "err\n");
		return;
	}

	NPC_Util_GetArgStr( meindex, argstr, sizeof( argstr));
	
	snprintf( sendstring, sizeof( sendstring), "1|%s|%s|%s|%s|",
			CHAR_getChar( meindex, CHAR_NAME),
			NPC_PoolItemShop_getMsg_noarg( NPC_POOLITEMSHOP_MSG_DRAW, 
										argstr, buff2, sizeof( buff2)),
			NPC_PoolItemShop_getMsg_noarg( NPC_POOLITEMSHOP_MSG_ITEMFULL, 
										argstr, buff, sizeof( buff)),
			NPC_PoolItemShop_getMsg_noarg( NPC_POOLITEMSHOP_MSG_REALY, 
										argstr, buff3, sizeof( buff3))
			);
	NPC_PoolItemShop_MakeItemString_Draw( meindex, talkerindex, 
									itemstring, sizeof( itemstring));
	strcat( sendstring, itemstring);
	lssproto_WN_send( fd, WINDOW_MESSAGETYPE_POOLITEMSHOPMAIN,
				WINDOW_BUTTONTYPE_NONE, 
				CHAR_WINDOWTYPE_POOLITEMSHOP_DRAW_MSG,
				CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX),
				sendstring);
	
}

static char *NPC_PoolItemShop_getMsg_noarg( int tablenum, 
								char *argstr, char *retstring, int retstringlen)
{
	char	buf[1024];
	if( tablenum < 0 || tablenum >= arraysizeof( poolshopmsg)) return NULL;
	
	if( NPC_Util_GetStrFromStrWithDelim( argstr, poolshopmsg[tablenum].option, buf, sizeof( buf)) != NULL ) {
		strcpysafe( retstring, retstringlen, buf);
	}else {
		strcpysafe( retstring, retstringlen, poolshopmsg[tablenum].defaultmsg);
	}
	return retstring;
}

static void NPC_PoolItemShop_MakeItemString_Pool( int meindex, int talkerindex, 
								char *retstring,int retstringlen)
{
	int		i;
	int		itemindex;
	int		pos = 0;
	char	buff[1024];
		
	retstring[0] = '\0';
	for( i = CHAR_STARTITEMARRAY; i < CHAR_MAXITEMHAVE; i ++ ) {
		itemindex = CHAR_getItemIndex( talkerindex, i);
		if( ITEM_CHECKINDEX( itemindex)) {
			int poolflg = FALSE;
			if( ITEM_getInt( itemindex, ITEM_DROPATLOGOUT) || 
				ITEM_getInt( itemindex, ITEM_VANISHATDROP) ||
				!ITEM_getInt( itemindex, ITEM_CANPETMAIL)){
				poolflg = TRUE;
			}
			snprintf( buff, sizeof( buff), 
#ifdef _ITEM_PILENUMS
				"%s|%d|%d|%d|%s|%d|%d|",
#else
						"%s|%d|%d|%d|%s|%d|",
#endif
						ITEM_getChar( itemindex, ITEM_SECRETNAME),
						poolflg,CHAR_getWorkInt( meindex, NPC_WORK_COST),
						ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER),
						ITEM_getChar( itemindex, ITEM_EFFECTSTRING),
#ifdef _ITEM_PILENUMS
						ITEM_getInt( itemindex, ITEM_USEPILENUMS),
#endif
						i + 1 );
			if( pos +strlen( buff)>= retstringlen) {
				fprint( "buffer over err\n");
				break;
			}
			strcpy( &retstring[pos], buff);
			pos += strlen( buff);
		}
	}
}

static void NPC_PoolItemShop_MakeItemString_Draw( int meindex, int talkerindex, 
								char *retstring,int retstringlen)
{
	int		i;
	int		itemindex;
	int		pos = 0;
	char	buff[1024];
		
	retstring[0] = '\0';
	for( i = 0; i < CHAR_MAXPOOLITEMHAVE; i ++ ) {
		itemindex = CHAR_getPoolItemIndex( talkerindex, i);
		if( ITEM_CHECKINDEX( itemindex)) {
			int poolflg = FALSE;
			snprintf( buff, sizeof( buff),
#ifdef _ITEM_PILENUMS
				"%s|%d|%d|%d|%d|%s|%d|",

#else
						"%s|%d|%d|%d|%d|%s|",
#endif
						ITEM_getChar( itemindex, ITEM_SECRETNAME),
						poolflg,
						ITEM_getInt( itemindex, ITEM_LEVEL),
						ITEM_getInt( itemindex, ITEM_COST),
						ITEM_getInt( itemindex, ITEM_BASEIMAGENUMBER),
						ITEM_getChar( itemindex, ITEM_EFFECTSTRING)
#ifdef _ITEM_PILENUMS
						,ITEM_getInt( itemindex, ITEM_USEPILENUMS)
#endif
						);
			if( pos +strlen( buff)>= retstringlen) {
				fprint( "buffer over err\n");
				break;
			}
			strcpy( &retstring[pos], buff);
			pos += strlen( buff);
		}
	}
}

static BOOL NPC_PoolItemShop_PoolItem( int meindex, int talkerindex, int num)
{
	int emptyindex;
	int itemindex;
	int cost = CHAR_getWorkInt( meindex, NPC_WORK_COST);

	emptyindex = CHAR_getCharPoolItemIndexElement( talkerindex);
	if( emptyindex == -1 ) {
		return FALSE;
	}
	                                                                                                  
	itemindex = CHAR_getItemIndex( talkerindex, num);
	if( !ITEM_CHECKINDEX( itemindex)) {
		fprint( "err");
		return FALSE;
	}
	CHAR_DelGold( talkerindex, cost );

	CHAR_setPoolItemIndex( talkerindex, emptyindex, itemindex);

	CHAR_setItemIndex( talkerindex, num, -1);
	CHAR_sendItemDataOne( talkerindex, num);

	CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);
	LogItem(
		CHAR_getChar( talkerindex, CHAR_NAME ), /* 平乓仿   */
		CHAR_getChar( talkerindex, CHAR_CDKEY ),
#ifdef _add_item_log_name  // WON ADD 在item的log中增加item名称
		itemindex,
#else
		ITEM_getInt( itemindex, ITEM_ID),  /* 失奶  丞  寞 */
#endif
		"pool(寄放道具)",
		CHAR_getInt( talkerindex,CHAR_FLOOR),
		CHAR_getInt( talkerindex,CHAR_X ),
 		CHAR_getInt( talkerindex,CHAR_Y ),
		ITEM_getChar( itemindex, ITEM_UNIQUECODE),
				ITEM_getChar( itemindex, ITEM_NAME),
				ITEM_getInt( itemindex, ITEM_ID)

	);
	return TRUE;
}

static BOOL NPC_PoolItemShop_DrawItem( int meindex, int talkerindex, int num)
{
	int emptyindex;
	int itemindex;
	int i;
	int cnt;
	int work[CHAR_MAXPOOLITEMHAVE];

	emptyindex = CHAR_findEmptyItemBox( talkerindex);
	if( emptyindex == -1 ) return FALSE;
	
	itemindex = CHAR_getPoolItemIndex( talkerindex, num);
	if( !ITEM_CHECKINDEX( itemindex)) {
		fprint( "err\n");
		return FALSE;
	}
	CHAR_setItemIndex( talkerindex, emptyindex, itemindex);
	CHAR_setPoolItemIndex( talkerindex, num, -1);
	CHAR_sendItemDataOne( talkerindex, emptyindex);
	for( i = 0; i < CHAR_MAXPOOLITEMHAVE; i ++ ) {
		work[i] = -1;
	}
	cnt = 0;
	for( i = 0; i < CHAR_MAXPOOLITEMHAVE; i ++ ) {
		itemindex = CHAR_getPoolItemIndex( talkerindex, i);
		if( ITEM_CHECKINDEX( itemindex)) {
			work[ cnt++] = itemindex;
		}
	}
	for( i = 0; i < CHAR_MAXPOOLITEMHAVE; i ++ ) {
		CHAR_setPoolItemIndex( talkerindex, i, work[i]);
	}
	LogItem(
		CHAR_getChar( talkerindex, CHAR_NAME ),
		CHAR_getChar( talkerindex, CHAR_CDKEY ),
#ifdef _add_item_log_name  // WON ADD 在item的log中增加item名称
		itemindex,
#else
		ITEM_getInt( itemindex, ITEM_ID),
#endif
		"draw(领取道具)",
		CHAR_getInt( talkerindex,CHAR_FLOOR),
		CHAR_getInt( talkerindex,CHAR_X ),
 		CHAR_getInt( talkerindex,CHAR_Y ),
		ITEM_getChar( itemindex, ITEM_UNIQUECODE),
		ITEM_getChar( itemindex, ITEM_NAME),
		ITEM_getInt( itemindex, ITEM_ID)
	);
	return TRUE;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?