Exemple #1
0
/*==========================================
 * Adds an item/qty to the trade window
 *------------------------------------------*/
void trade_tradeadditem (struct map_session_data *sd, short index, short amount)
{
	struct map_session_data *target_sd;
	struct item *item;
	int trade_i, trade_weight;
	int src_lv, dst_lv;
	nullpo_retv (sd);

	if (!sd->state.trading || sd->state.deal_locked > 0)
		return; //Can't add stuff.

	if ( (target_sd = map_id2sd (sd->trade_partner)) == NULL) {
		trade_tradecancel (sd);
		return;
	}

	if (amount == 0) {
		//Why do this.. ~.~ just send an ack, the item won't display on the trade window.
		clif_tradeitemok (sd, index, 0);
		return;
	}

	index -= 2; // 0 is for zeny, 1 is unknown. Gravity, go figure...

	//Item checks...
	if (index < 0 || index >= MAX_INVENTORY)
		return;

	if (amount < 0 || amount > sd->status.inventory[index].amount)
		return;

	item = &sd->status.inventory[index];
	src_lv = pc_get_group_level (sd);
	dst_lv = pc_get_group_level (target_sd);

	if (!itemdb_cantrade (item, src_lv, dst_lv) && //Can't trade
			(pc_get_partner (sd) != target_sd || !itemdb_canpartnertrade (item, src_lv, dst_lv))) { //Can't partner-trade
		clif_displaymessage (sd->fd, msg_txt (260));
		clif_tradeitemok (sd, index + 2, 1);
		return;
	}

	if (item->expire_time) {
		// Rental System
		clif_displaymessage (sd->fd, msg_txt (260));
		clif_tradeitemok (sd, index + 2, 1);
		return;
	}

	//Locate a trade position
	ARR_FIND (0, 10, trade_i, sd->deal.item[trade_i].index == index || sd->deal.item[trade_i].amount == 0);

	if (trade_i == 10) { //No space left
		clif_tradeitemok (sd, index + 2, 1);
		return;
	}

	trade_weight = sd->inventory_data[index]->weight * amount;

	if (target_sd->weight + sd->deal.weight + trade_weight > target_sd->max_weight) {
		//fail to add item -- the player was over weighted.
		clif_tradeitemok (sd, index + 2, 1);
		return;
	}

	if (sd->deal.item[trade_i].index == index) {
		//The same item as before is being readjusted.
		if (sd->deal.item[trade_i].amount + amount > sd->status.inventory[index].amount) {
			//packet deal exploit check
			amount = sd->status.inventory[index].amount - sd->deal.item[trade_i].amount;
			trade_weight = sd->inventory_data[index]->weight * amount;
		}

		sd->deal.item[trade_i].amount += amount;
	} else {
		//New deal item
		sd->deal.item[trade_i].index = index;
		sd->deal.item[trade_i].amount = amount;
	}

	sd->deal.weight += trade_weight;
	clif_tradeitemok (sd, index + 2, 0); // Return the index as it was received
	clif_tradeadditem (sd, target_sd, index + 2, amount);
}
Exemple #2
0
/*==========================================
 * Adds an item/qty to the trade window
 *------------------------------------------*/
void trade_tradeadditem(struct map_session_data *sd, short index, short amount)
{
	struct map_session_data *target_sd;
	struct item *item;
	struct homun_data *hd;
	char atcmd_output[CHAT_SIZE_MAX];
	int trade_i, trade_weight;
	int src_lv, dst_lv;
	int i, p, tid, amttsd = 0, amtt = 0;

	hd = sd->hd;
	
	nullpo_retv(sd);
	if( !sd->state.trading || sd->state.deal_locked > 0 )
		return; //Can't add stuff.

	if( (target_sd = map_id2sd(sd->trade_partner)) == NULL )
	{
		trade_tradecancel(sd);
		return;
	}

	if( amount == 0 )
	{	//Why do this.. ~.~ just send an ack, the item won't display on the trade window.
		clif_tradeitemok(sd, index, 0);
		return;
	}

	index -= 2; // 0 is for zeny, 1 is unknown. Gravity, go figure...

	//Item checks...
	if( index < 0 || index >= MAX_INVENTORY )
		return;
	if( amount < 0 || amount > sd->status.inventory[index].amount )
		return;

	item = &sd->status.inventory[index];
	src_lv = pc_isGM(sd);
	dst_lv = pc_isGM(target_sd);
	if( !itemdb_cantrade(item, src_lv, dst_lv) && //Can't trade
		(pc_get_partner(sd) != target_sd || !itemdb_canpartnertrade(item, src_lv, dst_lv)) ) //Can't partner-trade
	{
		clif_displaymessage (sd->fd, msg_txt(260));
		clif_tradeitemok(sd, index+2, 1);
		return;
	}

	if( item->expire_time )
	{ // Rental System
		clif_displaymessage (sd->fd, msg_txt(260));
		clif_tradeitemok(sd, index+2, 1);
		return;
	}

	//Locate a trade position
	ARR_FIND( 0, 10, trade_i, sd->deal.item[trade_i].index == index || sd->deal.item[trade_i].amount == 0 );
	if( trade_i == 10 ) //No space left
	{
		clif_tradeitemok(sd, index+2, 1);
		return;
	}

	
	
	//-------------| Bloquear Donates dias de semana |-------------//                     by: [Brunno Thadeu]
			
	//Abaixo, defini-se os dias (Falta testar isso, creio eu que 1 seja domingo, 2 segunda etc..)
//	if(t->tm_wday != 1 && t->tm_wday != 7){
	
		//Abaixo, defini-se o range de ID's dos Donates.
//		if(sd->status.inventory[index].nameid >= 5000 && sd->status.inventory[index].nameid <= 5500) {

//			clif_tradeitemok(sd, index+2, 1);
//			return;
//		}
//	}																
	//--------------------------------------------------------------//
	
	if(sd->status.inventory[index].nameid == 690)
		return ;	
	
	
	if(sd->status.inventory[index].nameid >= 8031 && sd->status.inventory[index].nameid <= 8181) {

		for(i = 8031; i <= 8181; i++)
			amttsd += pc_countitem(target_sd, i);

		for(i = 0; i < 10; i++) {
			tid = sd->status.inventory[sd->deal.item[i].index].nameid;
			if(tid >= 8031 && tid <= 8181)
				amtt += sd->deal.item[i].amount;
		}

		p = 6;
		if((hd = target_sd->hd) == NULL ){
			p = 7;
			}

		if((amttsd + amount + amtt) >= p) {
			clif_tradeitemok(sd, index+2, 1);
			return;
		}
	}


	if(sd->status.inventory[index].nameid >= 8031 && sd->status.inventory[index].nameid <= 8181){
		snprintf(atcmd_output, sizeof(atcmd_output) ,"Pokemon ID: %d ", MakeDWord(sd->status.inventory[index].card[1], sd->status.inventory[index].card[2]));
		clif_displaymessage(target_sd->fd, atcmd_output);
	}
	
	
	trade_weight = sd->inventory_data[index]->weight * amount;
	if( target_sd->weight + sd->deal.weight + trade_weight > target_sd->max_weight )
	{	//fail to add item -- the player was over weighted.
		clif_tradeitemok(sd, index+2, 1);
		return;
	}

	if( sd->deal.item[trade_i].index == index )
	{	//The same item as before is being readjusted.
		if( sd->deal.item[trade_i].amount + amount > sd->status.inventory[index].amount )
		{	//packet deal exploit check
			amount = sd->status.inventory[index].amount - sd->deal.item[trade_i].amount;
			trade_weight = sd->inventory_data[index]->weight * amount;
		}
		sd->deal.item[trade_i].amount += amount;
	}
	else
	{	//New deal item
		sd->deal.item[trade_i].index = index;
		sd->deal.item[trade_i].amount = amount;
	}
	sd->deal.weight += trade_weight;

	clif_tradeitemok(sd, index+2, 0); // Return the index as it was received
	clif_tradeadditem(sd, target_sd, index+2, amount);
}
Exemple #3
0
/*==========================================
 * Adds an item/qty to the trade window [rewrite by Skotlex] 
 *------------------------------------------
 */
void trade_tradeadditem(struct map_session_data *sd, int index, int amount) {
	struct map_session_data *target_sd;
	struct item *item;
	int trade_i, trade_weight;

	nullpo_retv(sd);
	if (!sd->state.trading || sd->state.deal_locked > 0)
		return; //Can't add stuff.

	if ((target_sd = map_id2sd(sd->trade_partner)) == NULL) {
		trade_tradecancel(sd);
		return;
	}

	if (amount == 0)
	{	//Why do this.. ~.~ just send an ack, the item won't display on the trade window.
		clif_tradeitemok(sd, index, 0);
		return;
	}

	if (index == 0)
	{	//Adding Zeny
		if (amount >= 0 && amount <= sd->status.zeny && // check amount
			(amount <= MAX_ZENY - target_sd->status.zeny)) // fix positiv overflow
		{	//Check Ok
			sd->deal.zeny = amount;
			clif_tradeadditem(sd, target_sd, 0, amount);
		} else //Send overweight when trying to add too much zeny? Hope they get the idea...
			clif_tradeitemok(sd, 0, 1);
		return;
	}

	index = index -2; //Why the actual index used is -2?
	//Item checks...
	if (index < 0 || index >= MAX_INVENTORY)
		return;
	if (amount < 0 || amount > sd->status.inventory[index].amount)
		return;

	item = &sd->status.inventory[index];
	trade_i = pc_isGM(sd); //Recycling the variables to check for trad restrict.
	trade_weight = pc_isGM(target_sd);
	if (!itemdb_cantrade(item, trade_i, trade_weight) &&	//Can't trade
		(pc_get_partner(sd) != target_sd ||
		!itemdb_canpartnertrade(item, trade_i, trade_weight))) //Can't partner-trade
	{
		clif_displaymessage (sd->fd, msg_txt(260));
		return;
	}

	for(trade_i = 0; trade_i < 10; trade_i++)
	{	//Locate a trade position
		if (sd->deal.item[trade_i].index == index ||
			sd->deal.item[trade_i].amount == 0)
			break;
	}
	if (trade_i >= 10)	//No space left
	{
		clif_tradeitemok(sd, index+2, 1);
		return;
	}

	trade_weight = sd->inventory_data[index]->weight * amount;
	if (target_sd->weight + sd->deal.weight + trade_weight > target_sd->max_weight)
	{	//fail to add item -- the player was over weighted.
		clif_tradeitemok(sd, index+2, 1);
		return;
	}

	if (sd->deal.item[trade_i].index == index)
	{	//The same item as before is being readjusted.
		if (sd->deal.item[trade_i].amount + amount > sd->status.inventory[index].amount)
		{	//packet deal exploit check
			amount = sd->status.inventory[index].amount - sd->deal.item[trade_i].amount;
			trade_weight = sd->inventory_data[index]->weight * amount;
		}
		sd->deal.item[trade_i].amount += amount;
	} else {	//New deal item
		sd->deal.item[trade_i].index = index;
		sd->deal.item[trade_i].amount = amount;
	}
	sd->deal.weight += trade_weight;

	clif_tradeitemok(sd, index+2, 0); // Return the index as it was received
	clif_tradeadditem(sd, target_sd, index+2, amount); //index fix
}
Exemple #4
0
/*==========================================
 * Adds an item/qty to the trade window [rewrite by Skotlex] 
 *------------------------------------------
 */
void trade_tradeadditem(struct map_session_data *sd, int index, int amount) {
	struct map_session_data *target_sd;
	int trade_i, trade_weight, nameid;

	nullpo_retv(sd);
	if (!sd->state.trading || (target_sd = map_id2sd(sd->trade_partner)) == NULL || sd->state.deal_locked > 0)
		return; //Can't add stuff.

	if (index == 0)
	{	//Adding Zeny
		if (amount >= 0 && amount <= MAX_ZENY && amount <= sd->status.zeny && // check amount
			(target_sd->status.zeny + amount) <= MAX_ZENY) // fix positiv overflow
		{	//Check Ok
			sd->deal.zeny = amount;
			clif_tradeadditem(sd, target_sd, 0, amount);
		} else //Cancel Transaction
			trade_tradecancel(sd);
		return;
	}
	//Add an Item
	index = index -2; //Why the actual index used is -2?
	//Item checks...
	if (index < 0 || index > MAX_INVENTORY)
		return;
	if (amount < 0 || amount > sd->status.inventory[index].amount)
		return;

	nameid = sd->inventory_data[index]->nameid;

	if (!itemdb_cantrade(nameid, pc_isGM(sd), pc_isGM(target_sd)) &&	//Can't trade
		(pc_get_partner(sd) != target_sd || !itemdb_canpartnertrade(nameid, pc_isGM(sd), pc_isGM(target_sd))))	//Can't partner-trade
	{
		clif_displaymessage (sd->fd, msg_txt(260));
		return;
	}

	for(trade_i = 0; trade_i < 10; trade_i++)
	{	//Locate a trade position
		if (sd->deal.item[trade_i].index == index ||
			sd->deal.item[trade_i].amount == 0)
			break;
	}
	if (trade_i >= 10)	//No space left
		return;

	trade_weight = sd->inventory_data[index]->weight * amount;
	if (target_sd->weight + sd->deal.weight + trade_weight > target_sd->max_weight)
	{	//fail to add item -- the player was over weighted.
		clif_tradeitemok(sd, index, 1);
		return;
	}

	if (sd->deal.item[trade_i].index == index)
	{	//The same item as before is being readjusted.
		if (sd->deal.item[trade_i].amount + amount > sd->status.inventory[index].amount)
		{	//packet deal exploit check
			amount = sd->status.inventory[index].amount - sd->deal.item[trade_i].amount;
			trade_weight = sd->inventory_data[index]->weight * amount;
		}
		sd->deal.item[trade_i].amount += amount;
	} else {	//New deal item
		sd->deal.item[trade_i].index = index;
		sd->deal.item[trade_i].amount = amount;
	}
	sd->deal.weight += trade_weight;

	if (impossible_trade_check(sd))
	{ // check exploit (trade more items that you have)
		trade_tradecancel(sd);
		return;
	}

	clif_tradeitemok(sd, index+2, 0); // Return the index as it was received
	clif_tradeadditem(sd, target_sd, index+2, amount); //index fix
}