www.pudn.com > gamedata.rar > warehouse.c


#include "stdafx.h" 
 
extern struct OBJECT_INFO       object_info[MAX_NUM_OBJ]; 
extern struct optiondata        option; 
 
 
int showprivatewarehousemoneyinfo(SOCKET s, BYTE mode, long money1, long money2) 
{ 
	// 00 01 02 03 04 05 06 07 08 09 10 11 12 13 
	// C2 02 00 00 91 03 64 00 00 00 86 CE C0 00  
	int ret; 
	BYTE lpSource[14]; 
	 
	BYTE buf[4]; 
 
	memset(lpSource, 0x00, sizeof(lpSource)); 
 
	lpSource[0]  = 0x00; 
	lpSource[1]  = 0x00; 
	lpSource[2]  = 0x00; 
	lpSource[3]  = 0x00; 
	lpSource[4]  = 0x91; 
	lpSource[5]  = mode; 
 
	Encode4(buf, money1); 
 
	lpSource[6]  = buf[3]; 
	lpSource[7]  = buf[2]; 
	lpSource[8]  = buf[1]; 
	lpSource[9]  = buf[0]; 
 
	Encode4(buf, money2); 
 
	lpSource[10] = buf[3]; 
	lpSource[11] = buf[2]; 
	lpSource[12] = buf[1]; 
	lpSource[13] = buf[0]; 
 
	ret = add_pack_chain(s, lpSource, 14, 0, FALSE); 
 
	return ret; 
} 
 
// 得到当前私人仓库是否有空位置 
int getprivatewarehouseblank(int n) 
{ 
	int i; 
	for(i=0;i novelity.number) 
				{ 
					return -1; 
				} // 如果数量小于 0或等于 0 
				else if (novelity.number <= 0) 
				{ 
					return -1; 
				} 
				else if (give_number <= novelity.number) 
				{ 
					/* 
	消耗品       0 
	帽子         1 
	耳环         2 
	项链         3 
	衣服         4 
	武器         5 
	戒指         6 
	裤子         7 
	鞋子         8 
	机械帽子     9 
	机械衣服     10 
	机械裤子     11 
	机械特殊属性 12 
	守护者       13 
	普通物品     14 
	矿石         15 
	宝石         16 
	*/ 
					// 消耗品的问题 
					if((novelity_info.reside2 == 0) || (novelity_info.reside2 == 15)) 
					{ 
						// 该物品位置已经满了		 
						index = getprivatewarehousesame(n, me_code1, me_code2); 
						if (index == PRIVATE_WAREHOUSE_NUM) 
						{ 
							index = getprivatewarehouseblank(n); 
 
							if (index == PRIVATE_WAREHOUSE_NUM) return -1; 
 
							if (give_number <= MAX_PRIVATE_WAREHOUSE) 
							{ 
								for(i=0;i<17;i++) 
								{ 
									object_info[n].privatewarehouse[index].code[i] = object_info[n].Novelity[lpTarget[6]][i]; 
								} 
 
								novelity.number = novelity.number - give_number; 
							 
								setuserNovelityinfo(n, lpTarget[6], novelity); 
 
								Encode2(buf, give_number); 
 
								object_info[n].privatewarehouse[index].code[8] = buf[1]; 
								object_info[n].privatewarehouse[index].code[9] = buf[0]; 
							} 
						} 
						else 
						{ 
							warehouse_number = object_info[n].privatewarehouse[index].code[8], 
									object_info[n].privatewarehouse[index].code[9] * 256; 
							if (give_number + warehouse_number <= MAX_PRIVATE_WAREHOUSE)			 
							{ 
								 
								for(i=0;i<17;i++)		 
								{ 
									object_info[n].privatewarehouse[index].code[i] = object_info[n].Novelity[lpTarget[6]][i];	 
								} 
			 
								novelity.number = novelity.number - give_number; 
						 
								setuserNovelityinfo(n, lpTarget[6], novelity);					 
								Encode2(buf, give_number + warehouse_number); 
							 
								object_info[n].privatewarehouse[index].code[8] = buf[1];						 
								object_info[n].privatewarehouse[index].code[9] = buf[0]; 
							} 
 
						} 
 
						novelitytoprivatewarehouse(s, 0x01, n, (BYTE)index, lpTarget[6]); 
 
					} 
					else 
					{ 
						index = getprivatewarehouseblank(n); 
 
						if (index == PRIVATE_WAREHOUSE_NUM) return -1; 
 
						if (give_number <= MAX_PRIVATE_WAREHOUSE) 
						{ 
							for(i=0;i<17;i++) 
							{ 
								object_info[n].privatewarehouse[index].code[i] = object_info[n].Novelity[lpTarget[6]][i]; 
							} 
 
							novelity.number = novelity.number - give_number; 
						 
							setuserNovelityinfo(n, lpTarget[6], novelity); 
 
							Encode2(buf, give_number); 
 
							object_info[n].privatewarehouse[index].code[8] = buf[1]; 
							object_info[n].privatewarehouse[index].code[9] = buf[0]; 
 
							novelitytoprivatewarehouse(s, 0x01, n, (BYTE)index, lpTarget[6]); 
						} 
					}	 
				} 
			} 
		} 
	} 
	else if (lpTarget[5] == 0x02) // 取物品 
	{ 
		// 00 01 02 03 04 05 06 07 08 
		// 48 00 00 00 90 02 03 01 00 
		warehouse_code1 = object_info[n].privatewarehouse[lpTarget[6]].code[2]; 
		warehouse_code2 = object_info[n].privatewarehouse[lpTarget[6]].code[3]; 
//		me_number   = object_info[n].Novelity[lpTarget[6]][8] * object_info[n].Novelity[lpTarget[6]][9] *256; 
		give_number = lpTarget[7] + lpTarget[8] * 256; 
 
		if ((warehouse_code1 == 0xFF) && (warehouse_code2 == 0xFF)) return -1; 
 
		novelity_info = getNovelity_info(warehouse_code1, warehouse_code2); 
 
		if (novelity_info.have) 
		{ 
			// 检查私人银行数据正确性 
			novelity =  getprivatewarehouseNovelityinfo(n, lpTarget[6]); 
			if (novelity.have) 
			{ 
				// 如果存入的数量大于拥有的数量 
				if (give_number > novelity.number) 
				{ 
					return -1; 
				} // 如果数量小于 0或等于 0 
				else if (novelity.number <= 0) 
				{ 
					return -1; 
				} 
				else if (give_number <= novelity.number) 
				{ 
					// 消耗品的问题 
					if((novelity_info.reside2 == 0) || (novelity_info.reside2 == 15)) 
					{ 
						// 该物品位置已经满了	 
						 
//						int getusernovelitysiteblank(int id); 
//int getusernovelitysitesame(int id, BYTE code1, BYTE code2); 
						index = getusernovelitysitesame(n, warehouse_code1, warehouse_code2); 
						if (index == 34) 
						{ 
							index = getusernovelitysiteblank(n); 
 
							if (index == 34) return -1; 
 
							if (give_number <= MAX_ME_NOVELITY) 
							{ 
								for(i=0;i<17;i++) 
								{ 
									object_info[n].Novelity[index][i] = object_info[n].privatewarehouse[lpTarget[6]].code[i]; 
								} 
 
								novelity.number = novelity.number - give_number; 
							 
								setprivatewarehouseNovelityinfo(n, lpTarget[6], novelity); 
 
								Encode2(buf, give_number); 
								object_info[n].Novelity[index][8] = buf[1];						 
								object_info[n].Novelity[index][9] = buf[0]; 
							} 
						} 
						else 
						{ 
							me_number = object_info[n].Novelity[index][8], 
									object_info[n].Novelity[index][9] * 256; 
							if (give_number + me_number <= MAX_ME_NOVELITY)			 
							{ 
								 
								for(i=0;i<17;i++)		 
								{ 
									object_info[n].Novelity[index][i] = object_info[n].privatewarehouse[lpTarget[6]].code[i];	 
								} 
			 
								novelity.number = novelity.number - give_number; 
						 
								setprivatewarehouseNovelityinfo(n, lpTarget[6], novelity);					 
		 
								Encode2(buf, give_number + me_number);			 
								object_info[n].Novelity[index][8] = buf[1];						 
								object_info[n].Novelity[index][9] = buf[0]; 
							} 
 
						} 
 
						novelitytoprivatewarehouse(s, 0x02, n, lpTarget[6], (BYTE)index); 
 
					} 
					else 
					{ 
						index = getusernovelitysiteblank(n); 
 
						if (index == 34) return -1; 
 
						if (give_number <= MAX_ME_NOVELITY) 
						{ 
							for(i=0;i<17;i++) 
							{ 
								object_info[n].Novelity[index][i] = object_info[n].privatewarehouse[lpTarget[6]].code[i]; 
							} 
 
							novelity.number = novelity.number - give_number; 
							 
							setprivatewarehouseNovelityinfo(n, lpTarget[6], novelity); 
 
							Encode2(buf, give_number); 
							object_info[n].Novelity[index][8] = buf[1];						 
							object_info[n].Novelity[index][9] = buf[0]; 
 
							novelitytoprivatewarehouse(s, 0x02, n, lpTarget[6], (BYTE)index); 
						} 
					}	 
				} 
			} 
		} 
	} 
	else if (lpTarget[5] == 0x03) // 存钱 
	{ 
		// 00 01 02 03 04 05 06 07 08 09 
		// 63 00 00 00 90 03 64 00 00 00  
 
		buf[3] = lpTarget[6]; 
		buf[2] = lpTarget[7]; 
		buf[1] = lpTarget[8]; 
		buf[0] = lpTarget[9]; 
 
		if (object_info[n].money == 0) return -1; 
 
		money = Decode4(buf); 
 
		if (object_info[n].money >= money) 
		{ 
			if (object_info[n].privatewarehousemoney + money >= MAX_MONEY) 
			{ 
				object_info[n].privatewarehousemoney = MAX_MONEY; 
				object_info[n].money = money - (MAX_MONEY - object_info[n].privatewarehousemoney); 
			} 
			else 
			{ 
				object_info[n].privatewarehousemoney += money; 
				object_info[n].money -= money; 
			} 
 
			showprivatewarehousemoneyinfo(s, 0x03, object_info[n].privatewarehousemoney, object_info[n].money); 
		} 
	} 
	else if (lpTarget[5] == 0x04) // 取钱 
	{ 
		// 00 01 02 03 04 05 06 07 08 09 
		// 6A 00 00 00 90 04 32 00 00 00 
		buf[3] = lpTarget[6]; 
		buf[2] = lpTarget[7]; 
		buf[1] = lpTarget[8]; 
		buf[0] = lpTarget[9]; 
 
 
		if (object_info[n].privatewarehousemoney == 0) return -1; 
 
		money = Decode4(buf); 
 
		if (object_info[n].privatewarehousemoney >= money) 
		{ 
			if (object_info[n].money + money >= MAX_MONEY) 
			{ 
				object_info[n].money = MAX_MONEY; 
				object_info[n].privatewarehousemoney = money - (MAX_MONEY - object_info[n].money); 
			} 
			else 
			{ 
				object_info[n].money += money; 
				object_info[n].privatewarehousemoney -= money; 
			} 
 
			showprivatewarehousemoneyinfo(s, 0x04, object_info[n].privatewarehousemoney, object_info[n].money); 
		} 
	} 
 
	return 0; 
} 
 
int openprivatewarehouse(SOCKET s) 
{ 
	BYTE lpSource[2048]; 
 
	BYTE buf[4]; 
 
	int i, j, a, n, len, number, ret; 
 
	n = find_obj(s); 
 
	if (n == MAX_NUM_USER) return -1; 
 
	len = 10; 
 
	j = 0; 
 
	number = 0; 
 
	for(i=0;i<48;i++) 
	{ 
		len = len + 18; 
		number++; 
	} 
 
	memset(lpSource, 0x00, sizeof(lpSource)); 
 
	// DA 00 00 00 8F 00 00 00 00 0C 
	lpSource[0] = 0x00; 
	lpSource[1] = 0x00; 
	lpSource[2] = 0x00; 
	lpSource[3] = 0x00; 
	lpSource[4] = 0x8F; 
	Encode4(buf, object_info[n].privatewarehousemoney); 
	lpSource[5] = buf[3]; 
	lpSource[6] = buf[2]; 
	lpSource[7] = buf[1]; 
	lpSource[8] = buf[0]; 
	lpSource[9] = number; 
	a = 0; 
 
	for(i=0;i<48;i++) 
	{		 
		a++; 
		lpSource[9 + a] = i; 
		for (j=0;j<17;j++) 
		{ 
			a++; 
			lpSource[9 + a] = object_info[n].privatewarehouse[i].code[j]; 
		} 
	} 
 
	ret = add_pack_chain(s, lpSource, len, 0, FALSE); 
 
	return ret; 
} 
 
int openpublicwarehouse(SOCKET s) 
{ 
	BYTE lpSource[2048]; 
 
	BYTE buf[4]; 
 
	int i, j, a, n, len, number, ret; 
 
	n = find_obj(s); 
 
	if (n == MAX_NUM_USER) return -1; 
 
	memset(lpSource, 0x00, sizeof(lpSource)); 
 
	// 00 01 02 03 04 05 06 07 08 09 10 11 
	// 4F 02 00 00 CE 09 00 BC A9 44 00 86  
	len = 12; 
 
	j = 0; 
 
	number = 0; 
 
	for(i=0;i<50;i++) 
	{ 
		if (object_info[n].publicwarehouse[i].code[2] != 0xFF || 
			object_info[n].publicwarehouse[i].code[3] != 0xFF) 
		{ 
			len = len + 22; 
			number++; 
		} 
	} 
 
	// DA 00 00 00 CE 00 00 00 00 0C 
	lpSource[0] = 0x00; 
	lpSource[1] = 0x00; 
	lpSource[2] = 0x00; 
	lpSource[3] = 0x00; 
	lpSource[4] = 0xCE; 
	 
	lpSource[5] = 0x09; 
	lpSource[6] = 0x00; 
 
	Encode4(buf, object_info[n].publicwarehousemoney); 
 
	lpSource[7] = buf[3]; 
	lpSource[8] = buf[2]; 
	lpSource[9] = buf[1]; 
	lpSource[10] = buf[0]; 
	lpSource[11] = number; 
 
 
	a = 0; 
 
	for(i=0;i<50;i++) 
	{ 
		if (object_info[n].publicwarehouse[i].code[2] != 0xFF || 
			object_info[n].publicwarehouse[i].code[3] != 0xFF) 
		{		 
			a++;	 
			lpSource[11 + a] = i;	 
			for (j=0;j<17;j++)	 
			{		 
				a ++; 
				lpSource[11 + a] = object_info[n].publicwarehouse[i].code[j]; 
			}		 
			a++; 
			lpSource[11 + a] = 0x96;	 
			a++;	 
			lpSource[11 + a] = 0x00; 
			a++; 
			lpSource[11 + a] = 0x00; 
			a++;	 
			lpSource[11 + a] = 0x00; 
		} 
	} 
 
	ret = add_pack_chain(s, lpSource, len, 0, FALSE); 
 
	return ret; 
}