Esempio n. 1
0
/*==========================================
 * アイテム追加完了(ok押し)
 *------------------------------------------
 */
void trade_tradeok(struct map_session_data *sd) {
	struct map_session_data *target_sd;
	int trade_i;

	nullpo_retv(sd);

	// check items
	for(trade_i = 0; trade_i < 10; trade_i++) {
		if ((((sd->deal.item[trade_i].index) >= 0) &&
		    (sd->deal.item[trade_i].amount > sd->status.inventory[sd->deal.item[trade_i].index].amount)) ||
		    (sd->deal.item[trade_i].amount < 0)) {
			trade_tradecancel(sd);
			return;
		}
	}

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

	// check zeny
	if (sd->deal.zeny < 0 || sd->deal.zeny > MAX_ZENY || sd->deal.zeny > sd->status.zeny) { // check amount
		trade_tradecancel(sd);
		return;
	}

	if ((target_sd = map_id2sd(sd->trade_partner)) != NULL) {
		sd->state.deal_locked = 1;
		clif_tradeitemok(sd, 0, 0);
		clif_tradedeal_lock(sd, 0);
		clif_tradedeal_lock(target_sd, 1);
	}
}
Esempio n. 2
0
/*==========================================
 * アイテム追加完了(ok押し)
 *------------------------------------------
 */
void trade_tradeok(dumb_ptr<map_session_data> sd)
{
    dumb_ptr<map_session_data> target_sd;
    int trade_i;

    nullpo_retv(sd);

    for (trade_i = 0; trade_i < 10; trade_i++)
    {
        if (sd->deal_item_amount[trade_i] >
            sd->status.inventory[sd->deal_item_index[trade_i] - 2].amount
            || sd->deal_item_amount[trade_i] < 0)
        {
            trade_tradecancel(sd);
            return;
        }

    }

    if ((target_sd = map_id2sd(sd->trade_partner)) != NULL)
    {
        sd->deal_locked = 1;
        clif_tradeitemok(sd, 0, 0, 0);
        clif_tradedeal_lock(sd, 0);
        clif_tradedeal_lock(target_sd, 1);
    }
}
Esempio n. 3
0
File: trade.cpp Progetto: mrktj/tmwa
/*==========================================
 * アイテム追加完了(ok押し)
 *------------------------------------------
 */
void trade_tradeok(dumb_ptr<map_session_data> sd)
{
    dumb_ptr<map_session_data> target_sd;
    int trade_i;

    nullpo_retv(sd);

    for (trade_i = 0; trade_i < TRADE_MAX; trade_i++)
    {
        IOff2 index = sd->deal_item_index[trade_i];
        if (!index.ok())
            continue;
        if (sd->deal_item_amount[trade_i] >
            sd->status.inventory[index.unshift()].amount
            || sd->deal_item_amount[trade_i] < 0)
        {
            trade_tradecancel(sd);
            return;
        }

    }

    if ((target_sd = map_id2sd(account_to_block(sd->trade_partner))) != nullptr)
    {
        sd->deal_locked = 1;
        clif_tradeitemok(sd, IOff2::from(0), 0, 0);
        clif_tradedeal_lock(sd, 0);
        clif_tradedeal_lock(target_sd, 1);
    }
}
Esempio n. 4
0
/*==========================================
 * Initiates a trade request.
 *------------------------------------------
 */
void trade_traderequest(struct map_session_data *sd, struct map_session_data *target_sd) {
	int level;

	nullpo_retv(sd);

	if (map[sd->bl.m].flag.notrade) {
		clif_displaymessage (sd->fd, msg_txt(272));
		return; //Can't trade in notrade mapflag maps.
	}

	if (target_sd == NULL || sd == target_sd) {
		clif_tradestart(sd, 1); // character does not exist
		return;
	}
	
	if (!battle_config.invite_request_check) {
		if (target_sd->guild_invite > 0 || target_sd->party_invite > 0) {
			clif_tradestart(sd, 2);
			return;
		}
	}

	if ((target_sd->trade_partner != 0) || (sd->trade_partner != 0)) {
		trade_tradecancel(sd); // person is in another trade
		return;
	}

	level = pc_isGM(sd);
	if ( pc_can_give_items(level) || pc_can_give_items(pc_isGM(target_sd)) ) //check if both GMs are allowed to trade
	{
		clif_displaymessage(sd->fd, msg_txt(246));
		trade_tradecancel(sd); // GM is not allowed to trade
		return;
	} 
	
	//Fixed. Only real GMs can request trade from far away! [Lupus] 
	if (level < lowest_gm_level && (sd->bl.m != target_sd->bl.m ||
		!check_distance_bl(&sd->bl, &target_sd->bl, TRADE_DISTANCE)
	)) {
		clif_tradestart(sd, 0); // too far
		return ;
	}
	
	target_sd->trade_partner = sd->status.account_id;
	sd->trade_partner = target_sd->status.account_id;
	clif_traderequest(target_sd, sd->status.name);
}
Esempio n. 5
0
/**
 * Close trade window if party member is kicked when trade a party bound item
 * @param sd
 **/
static void party_trade_bound_cancel(struct map_session_data *sd) {
#ifdef BOUND_ITEMS
	nullpo_retv(sd);
	if (sd->state.isBoundTrading&(1<<BOUND_PARTY))
		trade_tradecancel(sd);
#else
	;
#endif
}
Esempio n. 6
0
/*==========================================
 * 取引要請を相手に送る
 *------------------------------------------
 */
void trade_traderequest(struct map_session_data *sd, int target_id) {
	struct map_session_data *target_sd;
	int level;

	nullpo_retv(sd);

	if (map[sd->bl.m].flag.notrade) {
		clif_displaymessage (sd->fd, msg_txt(272));
		return; //Can't trade in notrade mapflag maps.
	}

	if ((target_sd = map_id2sd(target_id)) != NULL) {
		if (!battle_config.invite_request_check) {
			if (target_sd->guild_invite > 0 || target_sd->party_invite > 0) {
				clif_tradestart(sd, 2); // 相手はPT要請中かGuild要請中
				return;
			}
		}
		level = pc_isGM(sd);
		if ( pc_can_give_items(level) || pc_can_give_items(pc_isGM(target_sd)) ) //check if both GMs are allowed to trade
		{
			clif_displaymessage(sd->fd, msg_txt(246));
			trade_tradecancel(sd); // GM is not allowed to trade
		} else if ((target_sd->trade_partner != 0) || (sd->trade_partner != 0)) {
			trade_tradecancel(sd); // person is in another trade
		} else {
			//Fixed. Only real GMs can request trade from far away! [Lupus] 
			if (level < lowest_gm_level && (sd->bl.m != target_sd->bl.m ||
			    (sd->bl.x - target_sd->bl.x <= -5 || sd->bl.x - target_sd->bl.x >= 5) ||
			    (sd->bl.y - target_sd->bl.y <= -5 || sd->bl.y - target_sd->bl.y >= 5))) {
				clif_tradestart(sd, 0); // too far
			} else if (sd != target_sd) {
				target_sd->trade_partner = sd->status.account_id;
				sd->trade_partner = target_sd->status.account_id;
				clif_traderequest(target_sd, sd->status.name);
			}
		}
	} else {
		clif_tradestart(sd, 1); // character does not exist
	}
}
Esempio n. 7
0
/*==========================================
 * 取引要請
 *------------------------------------------
 */
void trade_tradeack(struct map_session_data *sd, unsigned char type)
{
	struct map_session_data *target_sd;

	nullpo_retv(sd);

	// possible types: 3: trade ok., 4: trade canceled.
	if (type != 3 && type != 4)
		return;

	if(sd->npc_id != 0)
		npc_event_dequeue(sd);

	target_sd = map_id2sd(sd->trade.partner);
	if(target_sd && target_sd->bl.prev) {
		if(sd->bl.m != target_sd->bl.m || unit_distance(&sd->bl, &target_sd->bl) > 2) {
			trade_tradecancel(sd);
			return;
		}
		if(sd->state.storage_flag || target_sd->state.storage_flag) {
			trade_tradecancel(target_sd);
			trade_tradecancel(sd);
			return;
		}
		clif_tradestart(target_sd,type);
		clif_tradestart(sd,type);
		if(type == 4) {	// Cancel
			sd->state.deal_locked = 0;
			sd->state.deal_mode   = 0;
			sd->trade.partner     = 0;
			target_sd->state.deal_locked = 0;
			target_sd->state.deal_mode   = 0;
			target_sd->trade.partner     = 0;
		} else {
			sd->state.deal_mode        = 1;
			target_sd->state.deal_mode = 1;
		}
	}

	return;
}
Esempio n. 8
0
/*==========================================
 * Adds the specified amount of zeny to the trade window
 *------------------------------------------*/
void trade_tradeaddzeny (struct map_session_data *sd, int amount)
{
	struct map_session_data *target_sd;
	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 || amount > sd->status.zeny || amount > MAX_ZENY - target_sd->status.zeny) {
		// invalid values, no appropriate packet for it => abort
		trade_tradecancel (sd);
		return;
	}

	sd->deal.zeny = amount;
	clif_tradeadditem (sd, target_sd, 0, amount);
}
Esempio n. 9
0
/*==========================================
 * アイテム追加完了(ok押し)
 *------------------------------------------
 */
void trade_tradeok(struct map_session_data *sd)
{
	struct map_session_data *target_sd;

	nullpo_retv(sd);

	target_sd = map_id2sd(sd->trade.partner);
	if(target_sd && target_sd->bl.prev) {
		if (sd->bl.m != target_sd->bl.m || unit_distance(&sd->bl, &target_sd->bl) > 2) {
			trade_tradecancel(sd);
			return;
		}
		sd->state.deal_locked = 1;
		clif_tradeitemok(sd,0,0);
		clif_tradedeal_lock(sd,0);
		clif_tradedeal_lock(target_sd,1);
	} else {
		trade_tradecancel(sd);
	}

	return;
}
Esempio n. 10
0
File: trade.cpp Progetto: mrktj/tmwa
/*==========================================
 * 取引要請を相手に送る
 *------------------------------------------
 */
void trade_traderequest(dumb_ptr<map_session_data> sd, BlockId target_id)
{
    dumb_ptr<map_session_data> target_sd;

    nullpo_retv(sd);

    if ((target_sd = map_id2sd(target_id)) != nullptr)
    {
        if (!battle_config.invite_request_check)
        {
            if (target_sd->party_invite)
            {
                clif_tradestart(sd, 2);    // 相手はPT要請中かGuild要請中
                return;
            }
        }
        if (target_sd->npc_id)
        {
            //Trade fails if you are using an NPC.
            clif_tradestart(sd, 2);
            return;
        }
        if ((target_sd->trade_partner) || (sd->trade_partner))
        {
            trade_tradecancel(sd); //person is in another trade
        }
        else
        {
            if (sd->bl_m != target_sd->bl_m
                || (sd->bl_x - target_sd->bl_x <= -5
                    || sd->bl_x - target_sd->bl_x >= 5)
                || (sd->bl_y - target_sd->bl_y <= -5
                    || sd->bl_y - target_sd->bl_y >= 5))
            {
                clif_tradestart(sd, 0);    //too far
            }
            else if (sd != target_sd)
            {
                target_sd->trade_partner = sd->status_key.account_id;
                sd->trade_partner = target_sd->status_key.account_id;
                clif_traderequest(target_sd, sd->status_key.name);
            }
        }
    }
    else
    {
        clif_tradestart(sd, 1);    //character does not exist
    }
}
Esempio n. 11
0
/*==========================================
 * 'Ok' button on the trade window is pressed.
 *------------------------------------------
 */
void trade_tradeok(struct map_session_data *sd) {
	struct map_session_data *target_sd;

	if(sd->state.deal_locked || !sd->state.trading)
		return;
	
	if ((target_sd = map_id2sd(sd->trade_partner)) == NULL) {
		trade_tradecancel(sd);
		return;
	}
	sd->state.deal_locked = 1;
	clif_tradeitemok(sd, 0, 0);
	clif_tradedeal_lock(sd, 0);
	clif_tradedeal_lock(target_sd, 1);
}
Esempio n. 12
0
File: trade.cpp Progetto: mrktj/tmwa
// This is called when a char's zeny is changed
// This helps prevent money duplication and other problems
// [Jaxad0127]
void trade_verifyzeny(dumb_ptr<map_session_data> sd)
{
    dumb_ptr<map_session_data> target_sd;

    nullpo_retv(sd);

    if ((target_sd = map_id2sd(account_to_block(sd->trade_partner))) != nullptr)
    {
        if (sd->deal_zeny > sd->status.zeny)
        {
            if (sd->deal_locked < 1)
                trade_tradeadditem(sd, IOff2::from(0), sd->status.zeny);    // Fix money ammount
            else
                trade_tradecancel(sd); // Or cancel the trade if we can't fix it
        }
    }
}
Esempio n. 13
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);
}
Esempio n. 14
0
/*==========================================
 * Initiates a trade request.
 *------------------------------------------*/
void trade_traderequest (struct map_session_data *sd, struct map_session_data *target_sd)
{
	nullpo_retv (sd);

	if (map[sd->bl.m].flag.notrade) {
		clif_displaymessage (sd->fd, msg_txt (272));
		return; //Can't trade in notrade mapflag maps.
	}

	if (target_sd == NULL || sd == target_sd) {
		clif_tradestart (sd, 1); // character does not exist
		return;
	}

	if (target_sd->npc_id) {
		//Trade fails if you are using an NPC.
		clif_tradestart (sd, 2);
		return;
	}

	if (!battle_config.invite_request_check) {
		if (target_sd->guild_invite > 0 || target_sd->party_invite > 0 || target_sd->adopt_invite) {
			clif_tradestart (sd, 2);
			return;
		}
	}

	if (sd->trade_partner != 0) {   // If a character tries to trade to another one then cancel the previous one
		struct map_session_data *previous_sd = map_id2sd (sd->trade_partner);

		if (previous_sd) {
			previous_sd->trade_partner = 0;
			clif_tradecancelled (previous_sd);
		} // Once cancelled then continue to the new one.

		sd->trade_partner = 0;
		clif_tradecancelled (sd);
	}

	if (target_sd->trade_partner != 0) {
		clif_tradestart (sd, 2); // person is in another trade
		return;
	}

	if (!pc_can_give_items (sd) || !pc_can_give_items (target_sd)) { //check if both GMs are allowed to trade
		clif_displaymessage (sd->fd, msg_txt (246));
		clif_tradestart (sd, 2); // GM is not allowed to trade
		return;
	}

	// Players can not request trade from far away, unless they are allowed to use @trade.
	if (!pc_can_use_command (sd, "trade", COMMAND_ATCOMMAND) &&
			(sd->bl.m != target_sd->bl.m || !check_distance_bl (&sd->bl, &target_sd->bl, TRADE_DISTANCE))) {
		clif_tradestart (sd, 0); // too far
		return ;
	}

	if (target_sd->weight > target_sd->max_weight || sd->weight > sd->max_weight) {
		clif_tradestart (sd, 2); // trade failed (overweight)
		return;
	}

	if (sd->trade_partner != 0)
		trade_tradecancel (sd);

	if (sd->state.vending || target_sd->state.vending)
		return; // ignore request at the last minute (official)

	target_sd->state.can_tradeack = 1;
	target_sd->trade_partner = sd->status.account_id;
	sd->trade_partner = target_sd->status.account_id;
	clif_traderequest (target_sd, sd->status.name);
}
Esempio n. 15
0
/*==========================================
 * 取引許諾(trade押し)
 *------------------------------------------
 */
void trade_tradecommit(struct map_session_data *sd) {
	struct map_session_data *target_sd;
	int trade_i;
	int flag;

	nullpo_retv(sd);

	if (sd->state.trading && (target_sd = map_id2sd(sd->trade_partner)) != NULL) {
		if ((sd->state.deal_locked >= 1) && (target_sd->state.deal_locked >= 1)) { // both have pressed 'ok'
			if (sd->state.deal_locked < 2) { // set locked to 2
				sd->state.deal_locked = 2;
			}
			if (target_sd->state.deal_locked == 2) { // the other one pressed 'trade' too
				// check exploit (trade more items that you have)
				if (impossible_trade_check(sd)) {
					trade_tradecancel(sd);
					return;
				}
				// check exploit (trade more items that you have)
				if (impossible_trade_check(target_sd)) {
					trade_tradecancel(target_sd);
					return;
				}
				// check zenys value against hackers
				if (sd->deal.zeny >= 0 && sd->deal.zeny <= MAX_ZENY && sd->deal.zeny <= sd->status.zeny && // check amount
				    (target_sd->status.zeny + sd->deal.zeny) <= MAX_ZENY && // fix positiv overflow
				    target_sd->deal.zeny >= 0 && target_sd->deal.zeny <= MAX_ZENY && target_sd->deal.zeny <= target_sd->status.zeny && // check amount
				    (sd->status.zeny + target_sd->deal.zeny) <= MAX_ZENY) { // fix positiv overflow

					// check for full inventory (can not add traded items)
					if (!trade_check(sd)) { // check the both players
						trade_tradecancel(sd);
						return;
					}

					// trade is accepted
					for(trade_i = 0; trade_i < 10; trade_i++) {
						if (sd->deal.item[trade_i].amount != 0) {
							int n = sd->deal.item[trade_i].index;

							if (sd->status.inventory[n].amount < sd->deal.item[trade_i].amount)
								sd->deal.item[trade_i].amount = sd->status.inventory[n].amount;
                                                        log_trade(sd, target_sd, n, sd->deal.item[trade_i].amount);

							flag = pc_additem(target_sd, &sd->status.inventory[n], sd->deal.item[trade_i].amount);
							if (flag == 0) {
								//Logs (T)rade [Lupus]
								if(log_config.pick > 0 )
									log_pick(sd, "T", 0, sd->status.inventory[n].nameid, -(sd->deal.item[trade_i].amount), &sd->status.inventory[n]);
									log_pick(target_sd, "T", 0, sd->status.inventory[n].nameid, sd->deal.item[trade_i].amount, &sd->status.inventory[n]);
								//Logs
								pc_delitem(sd, n, sd->deal.item[trade_i].amount, 1);
							} else {
								clif_additem(sd, n, sd->deal.item[trade_i].amount, 0);
							}
							sd->deal.item[trade_i].index = 0;
							sd->deal.item[trade_i].amount = 0;
                                                        
						}
						if (target_sd->deal.item[trade_i].amount != 0) {
							int n = target_sd->deal.item[trade_i].index;

							if (target_sd->status.inventory[n].amount < target_sd->deal.item[trade_i].amount)
								target_sd->deal.item[trade_i].amount = target_sd->status.inventory[n].amount;

							log_trade(target_sd, sd, n, target_sd->deal.item[trade_i].amount);

							flag = pc_additem(sd, &target_sd->status.inventory[n], target_sd->deal.item[trade_i].amount);
							if (flag == 0) {
								//Logs (T)rade [Lupus]
								if(log_config.pick > 0 )
									log_pick(target_sd, "T", 0, target_sd->status.inventory[n].nameid, -(target_sd->deal.item[trade_i].amount), &target_sd->status.inventory[n]);
									log_pick(sd, "T", 0, target_sd->status.inventory[n].nameid, target_sd->deal.item[trade_i].amount, &target_sd->status.inventory[n]);
								//Logs
								pc_delitem(target_sd, n, target_sd->deal.item[trade_i].amount, 1);
							} else {
								clif_additem(target_sd, n, target_sd->deal.item[trade_i].amount, 0);
							}
							target_sd->deal.item[trade_i].index = 0;
							target_sd->deal.item[trade_i].amount = 0;
						}
					}
					if (sd->deal.zeny) {
						//Logs Zeny (T)rade [Lupus]
						if(log_config.zeny > 0 )
							log_zeny(target_sd, "T", sd, sd->deal.zeny);
						//Logs
						sd->status.zeny -= sd->deal.zeny;
						target_sd->status.zeny += sd->deal.zeny;
					}
					if (target_sd->deal.zeny) {
						//Logs Zeny (T)rade [Lupus]
						if(log_config.zeny > 0 )
							log_zeny(sd, "T", target_sd, target_sd->deal.zeny);
						//Logs
						target_sd->status.zeny -= target_sd->deal.zeny;
						sd->status.zeny += target_sd->deal.zeny;
					}
					if (sd->deal.zeny || target_sd->deal.zeny) {
						clif_updatestatus(sd, SP_ZENY);
						sd->deal.zeny = 0;
						clif_updatestatus(target_sd, SP_ZENY);
						target_sd->deal.zeny = 0;
					}
					sd->state.deal_locked = 0;
					sd->trade_partner = 0;
					sd->state.trading = 0;
					target_sd->state.deal_locked = 0;
					target_sd->trade_partner = 0;
					target_sd->state.trading = 0;
					clif_tradecompleted(sd, 0);
					clif_tradecompleted(target_sd, 0);
					// save both player to avoid crash: they always have no advantage/disadvantage between the 2 players
					chrif_save(sd,0); // do pc_makesavestatus and save storage too
					chrif_save(target_sd,0); // do pc_makesavestatus and save storage too
				// zeny value was modified!!!! hacker with packet modified
				} else {
					trade_tradecancel(sd);
				}
			}
		}
	}
}
Esempio n. 16
0
/*==========================================
 * 取引許諾(trade押し)
 *------------------------------------------
 */
void trade_tradecommit(struct map_session_data *sd)
{
	struct map_session_data *target_sd;

	nullpo_retv(sd);

	target_sd = map_id2sd(sd->trade.partner);
	if(target_sd && target_sd->bl.prev) {
		if (sd->state.deal_locked >= 1 && target_sd->state.deal_locked >= 1) { // both have pressed 'ok'
			if (sd->state.deal_locked < 2) // set locked to 2
				sd->state.deal_locked = 2;
			if(target_sd->state.deal_locked == 2) { // the other one pressed 'trade' too
				int trade_i, idx, flag;

				// checks quantity of items
				if (!trade_check(sd, target_sd)) { // this function do like the real trade, but with virtual inventories
					trade_tradecancel(sd);
					return;
				}
				// check zenys
				if (sd->trade.zeny > sd->status.zeny ||
				    target_sd->trade.zeny > target_sd->status.zeny ||
				    sd->status.zeny - sd->trade.zeny + target_sd->trade.zeny > MAX_ZENY ||
				    target_sd->status.zeny - target_sd->trade.zeny + sd->trade.zeny > MAX_ZENY) {
					trade_tradecancel(sd);
					return;
				}
				// do trade
				// ---- of items
				for(trade_i = 0; trade_i < MAX_DEAL_ITEMS; trade_i++) {
					if(sd->trade.item_amount[trade_i] != 0) {
						idx = sd->trade.item_index[trade_i] - 2;
						if (itemdb_isdropable(sd->status.inventory[idx].nameid)) {
							flag = pc_additem(target_sd, &sd->status.inventory[idx], sd->trade.item_amount[trade_i]);
							if(flag==0)
								pc_delitem(sd, idx, sd->trade.item_amount[trade_i], 1, 0);
							else
								clif_additem(sd, idx, sd->trade.item_amount[trade_i], 0);
						}
						sd->trade.item_amount[trade_i] = 0;
					}
					sd->trade.item_index[trade_i] = 0;
					if(target_sd->trade.item_amount[trade_i] != 0) {
						idx = target_sd->trade.item_index[trade_i] - 2;
						if (itemdb_isdropable(target_sd->status.inventory[idx].nameid)) {
							flag = pc_additem(sd, &target_sd->status.inventory[idx], target_sd->trade.item_amount[trade_i]);
							if(flag==0)
								pc_delitem(target_sd, idx, target_sd->trade.item_amount[trade_i], 1, 0);
							else
								clif_additem(target_sd, idx, target_sd->trade.item_amount[trade_i], 0);
						}
						target_sd->trade.item_amount[trade_i] = 0;
					}
					target_sd->trade.item_index[trade_i] = 0;
				}
				// ---- of zenys
				if(sd->trade.zeny || target_sd->trade.zeny) {
					sd->status.zeny = sd->status.zeny - sd->trade.zeny + target_sd->trade.zeny;
					target_sd->status.zeny = target_sd->status.zeny - target_sd->trade.zeny + sd->trade.zeny;
					clif_updatestatus(sd, SP_ZENY);
					clif_updatestatus(target_sd, SP_ZENY);
				}
				sd->trade.zeny = 0;
				target_sd->trade.zeny = 0;
				// clean up variables
				sd->state.deal_locked = 0;
				sd->state.deal_mode   = 0;
				sd->trade.partner     = 0;
				target_sd->state.deal_locked = 0;
				target_sd->state.deal_mode   = 0;
				target_sd->trade.partner     = 0;
				clif_tradecompleted(sd,0);
				clif_tradecompleted(target_sd,0);
				// save both player to avoid crash: they always have no advantage/disadvantage between the 2 players
				chrif_save(sd,0);
				chrif_save(target_sd,0);
			}
		}
	} else {
		trade_tradecancel(sd);
	}

	return;
}
Esempio n. 17
0
/*==========================================
 * PCのquit処理 map.c内分
 *
 * quit処理の主体が違うような気もしてきた
 *------------------------------------------
 */
int map_quit(struct map_session_data *sd)
{
	if(sd->chatID)	// チャットから出る
		chat_leavechat(sd);
		
	if(sd->trade_partner)	// 取引を中断する
		trade_tradecancel(sd);

	if(sd->party_invite>0)	// パーティ勧誘を拒否する
		party_reply_invite(sd,sd->party_invite_account,0);

	if(sd->guild_invite>0)	// ギルド勧誘を拒否する
		guild_reply_invite(sd,sd->guild_invite,0);
	if(sd->guild_alliance>0)	// ギルド同盟勧誘を拒否する
		guild_reply_reqalliance(sd,sd->guild_alliance_account,0);

	party_send_logout(sd);	// パーティのログアウトメッセージ送信

	guild_send_memberinfoshort(sd,0);	// ギルドのログアウトメッセージ送信

	pc_cleareventtimer(sd);	// イベントタイマを破棄する

	storage_storage_quit(sd);	// 倉庫を開いてるなら保存する

	skill_castcancel(&sd->bl,0);	// 詠唱を中断する
	skill_status_change_clear(&sd->bl);	// ステータス異常を解除する
	skill_clear_unitgroup(&sd->bl);	// スキルユニットグループの削除
	skill_cleartimerskill(&sd->bl);
	pc_stop_walking(sd,0);
	pc_stopattack(sd);
	pc_delinvincibletimer(sd);
	pc_delspiritball(sd,sd->spiritball,1);
	skill_gangsterparadise(sd,0);

	pc_calcstatus(sd,4);

	clif_clearchar_area(&sd->bl,2);

	if(sd->status.pet_id && sd->pd) {
		pet_remove_map(sd);
		if(sd->pet.intimate <= 0) {
			intif_delete_petdata(sd->status.pet_id);
			sd->status.pet_id = 0;
			sd->pd = NULL;
			sd->petDB = NULL;
		}
		else
			intif_save_petdata(sd->status.account_id,&sd->pet);
	}

	if(pc_isdead(sd))
		pc_setrestartvalue(sd,2);
	pc_makesavestatus(sd);
	chrif_save(sd);
	storage_storage_save(sd);

	map_delblock(&sd->bl);

	numdb_erase(id_db,sd->bl.id);
	strdb_erase(nick_db,sd->status.name);

	return 0;
}
Esempio n. 18
0
File: trade.cpp Progetto: mrktj/tmwa
/*==========================================
 * 取引許諾(trade押し)
 *------------------------------------------
 */
void trade_tradecommit(dumb_ptr<map_session_data> sd)
{
    dumb_ptr<map_session_data> target_sd;
    int trade_i;

    nullpo_retv(sd);

    if ((target_sd = map_id2sd(account_to_block(sd->trade_partner))) != nullptr)
    {
        MAP_LOG_PC(sd, " TRADECOMMIT WITH %d GIVE %d GET %d"_fmt,
                target_sd->status_key.char_id, sd->deal_zeny,
                target_sd->deal_zeny);
        if ((sd->deal_locked >= 1) && (target_sd->deal_locked >= 1))
        {                       // both have pressed 'ok'
            if (sd->deal_locked < 2)
            {
                sd->deal_locked = 2;
            }                   // set locked to 2
            if (target_sd->deal_locked == 2)
            {                   // the other one pressed 'trade' too
                if (sd->deal_zeny > sd->status.zeny)
                {
                    sd->deal_zeny = 0;
                    trade_tradecancel(sd);
                    MAP_LOG_PC(sd, " TRADECANCEL"_fmt);
                    return;
                }
                if (target_sd->deal_zeny > target_sd->status.zeny)
                {
                    target_sd->deal_zeny = 0;
                    trade_tradecancel(sd);
                    MAP_LOG_PC(sd, " TRADECANCEL"_fmt);
                    return;
                }
                sd->trade_partner = AccountId();
                target_sd->trade_partner = AccountId();
                for (trade_i = 0; trade_i < TRADE_MAX; trade_i++)
                {
                    if (sd->deal_item_amount[trade_i] != 0)
                    {
                        assert (sd->deal_item_index[trade_i].ok());
                        IOff0 n = sd->deal_item_index[trade_i].unshift();
                        PickupFail flag = pc_additem(target_sd,
                                &sd->status.inventory[n],
                                sd->deal_item_amount[trade_i]);
                        if (flag == PickupFail::OKAY)
                            pc_delitem(sd, n, sd->deal_item_amount[trade_i],
                                        1);
                        else
                            clif_additem(sd, n,
                                    sd->deal_item_amount[trade_i],
                                    PickupFail::OKAY);
                        sd->deal_item_index[trade_i] = IOff2::from(0);
                        sd->deal_item_amount[trade_i] = 0;
                    }
                    if (target_sd->deal_item_amount[trade_i] != 0)
                    {
                        assert (target_sd->deal_item_index[trade_i].ok());
                        IOff0 n = target_sd->deal_item_index[trade_i].unshift();
                        PickupFail flag = pc_additem(sd,
                                &target_sd->status.inventory[n],
                                target_sd->deal_item_amount[trade_i]);
                        if (flag == PickupFail::OKAY)
                            pc_delitem(target_sd, n,
                                        target_sd->deal_item_amount[trade_i],
                                        1);
                        else
                            clif_additem(target_sd, n,
                                    target_sd->deal_item_amount[trade_i],
                                    PickupFail::OKAY);
                        target_sd->deal_item_index[trade_i] = IOff2::from(0);
                        target_sd->deal_item_amount[trade_i] = 0;
                    }
                }
                if (sd->deal_zeny)
                {
                    int deal = sd->deal_zeny;
                    sd->deal_zeny = 0;
                    sd->status.zeny -= deal;
                    clif_updatestatus(sd, SP::ZENY);
                    target_sd->status.zeny += deal;
                    clif_updatestatus(target_sd, SP::ZENY);
                }
                if (target_sd->deal_zeny)
                {
                    int deal = target_sd->deal_zeny;
                    target_sd->deal_zeny = 0;
                    target_sd->status.zeny -= deal;
                    clif_updatestatus(target_sd, SP::ZENY);
                    sd->status.zeny += deal;
                    clif_updatestatus(sd, SP::ZENY);
                }
                sd->deal_locked = 0;
                target_sd->deal_locked = 0;
                clif_tradecompleted(sd, 0);
                clif_tradecompleted(target_sd, 0);
                MAP_LOG_PC(sd, " TRADEOK"_fmt);
            }
        }
    }
}
Esempio n. 19
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
}
Esempio n. 20
0
File: trade.cpp Progetto: mrktj/tmwa
/*==========================================
 * アイテム追加
 *------------------------------------------
 */
void trade_tradeadditem(dumb_ptr<map_session_data> sd, IOff2 index, int amount)
{
    dumb_ptr<map_session_data> target_sd;
    struct item_data *id;
    int trade_i;
    int trade_weight = 0;
    int free_ = 0;
    int c;

    nullpo_retv(sd);

    if (((target_sd = map_id2sd(account_to_block(sd->trade_partner))) != nullptr)
        && (sd->deal_locked < 1))
    {
        if (!index.ok())
        {
            if (index.index == 0 && amount > 0 && amount <= sd->status.zeny)
            {
                sd->deal_zeny = amount;
                clif_tradeadditem(sd, target_sd, index, amount);
            }
        }
        // note: amount is overridden below!
        else if (amount <= sd->status.inventory[index.unshift()].amount
                 && amount > 0)
        {
            // determine free slots of receiver
            for (IOff0 i : IOff0::iter())
            {
                if (!target_sd->status.inventory[i].nameid
                    && target_sd->inventory_data[i] == nullptr)
                    free_++;
            }
            for (trade_i = 0; trade_i < TRADE_MAX; trade_i++)
            {
                if (sd->deal_item_amount[trade_i] == 0)
                {
                    // calculate trade weight
                    trade_weight +=
                        sd->inventory_data[index.unshift()]->weight * amount;

                    // determine if item is a stackable already in receivers inventory, and up free count
                    for (IOff0 i : IOff0::iter())
                    {
                        if (target_sd->status.inventory[i].nameid ==
                            sd->status.inventory[index.unshift()].nameid
                            && target_sd->inventory_data[i] != nullptr)
                        {
                            id = target_sd->inventory_data[i];
                            if (id->type != ItemType::WEAPON
                                && id->type != ItemType::ARMOR
                                && id->type != ItemType::_7
                                && id->type != ItemType::_8)
                            {
                                free_++;
                                break;
                            }
                        }
                    }

                    if (target_sd->weight + trade_weight >
                        target_sd->max_weight)
                    {
                        clif_tradeitemok(sd, index, 0, 1); //fail to add item -- the player was over weighted.
                        amount = 0; // [MouseJstr]
                    }
                    else if (free_ <= 0)
                    {
                        clif_tradeitemok(sd, index, 0, 2); //fail to add item -- no free slots at receiver
                        amount = 0; // peavey
                    }
                    else
                    {
                        for (c = 0; c == trade_i - 1; c++)
                        {       // re-deal exploit protection [Valaris]
                            if (sd->deal_item_index[c] == index)
                            {
                                trade_tradecancel(sd);
                                return;
                            }
                        }
                        pc_unequipinvyitem(sd, index.unshift(), CalcStatus::NOW);
                        sd->deal_item_index[trade_i] = index;
                        sd->deal_item_amount[trade_i] += amount;
                        clif_tradeitemok(sd, index, amount, 0);    //success to add item
                        clif_tradeadditem(sd, target_sd, index, amount);
                    }
                    break;
                }
                else
                {
                    // calculate weight for stored deal
                    trade_weight +=
                        sd->inventory_data[sd->deal_item_index[trade_i].unshift()
                                           ]->weight *
                        sd->deal_item_amount[trade_i];
                    // count free stackables in stored deal
                    for (IOff0 i : IOff0::iter())
                    {
                        if (target_sd->status.inventory[i].nameid ==
                            sd->status.
                            inventory[sd->deal_item_index[trade_i].unshift()].nameid
                            && target_sd->inventory_data[i] != nullptr)
                        {
                            id = target_sd->inventory_data[i];
                            if (id->type != ItemType::WEAPON
                                && id->type != ItemType::ARMOR
                                && id->type != ItemType::_7
                                && id->type != ItemType::_8)
                            {
                                free_++;
                                break;
                            }
                        }
                    }
                }
                // used a slot, but might be cancelled out by stackable checks above
                free_--;
            }
        }
    }
}
Esempio n. 21
0
/*==========================================
 * Žæˆø‹–‘ø(trade‰Ÿ‚µ)
 *------------------------------------------*/
void trade_tradecommit(struct map_session_data *sd)
{
	struct map_session_data *tsd;
	int trade_i;
	int flag;

	if (!sd->state.trading || !sd->state.deal_locked) //Locked should be 1 (pressed ok) before you can press trade.
		return;

	if ((tsd = map_id2sd(sd->trade_partner)) == NULL) {
		trade_tradecancel(sd);
		return;
	}
	
	sd->state.deal_locked = 2;
	
	if (tsd->state.deal_locked < 2)
		return; //Not yet time for trading.

	//Now is a good time (to save on resources) to check that the trade can indeed be made and it's not exploitable.
	// check exploit (trade more items that you have)
	if (impossible_trade_check(sd)) {
		trade_tradecancel(sd);
		return;
	}
	// check exploit (trade more items that you have)
	if (impossible_trade_check(tsd)) {
		trade_tradecancel(tsd);
		return;
	}
	// check for full inventory (can not add traded items)
	if (!trade_check(sd,tsd)) { // check the both players
		trade_tradecancel(sd);
		return;
	}
	
	// trade is accepted and correct.
	for( trade_i = 0; trade_i < 10; trade_i++ )
	{
		int n;
		if (sd->deal.item[trade_i].amount)
		{
			n = sd->deal.item[trade_i].index;

			flag = pc_additem(tsd, &sd->status.inventory[n], sd->deal.item[trade_i].amount);
			if (flag == 0)
			{
				//Logs (T)rade [Lupus]
				if(log_config.enable_logs&0x2)
				{
					log_pick_pc(sd, "T", sd->status.inventory[n].nameid, -(sd->deal.item[trade_i].amount), &sd->status.inventory[n]);
					log_pick_pc(tsd, "T", sd->status.inventory[n].nameid, sd->deal.item[trade_i].amount, &sd->status.inventory[n]);
				}
				pc_delitem(sd, n, sd->deal.item[trade_i].amount, 1);
			} else
				clif_additem(sd, n, sd->deal.item[trade_i].amount, 0);
			sd->deal.item[trade_i].index = 0;
			sd->deal.item[trade_i].amount = 0;
		}
		if (tsd->deal.item[trade_i].amount)
		{
			n = tsd->deal.item[trade_i].index;

			flag = pc_additem(sd, &tsd->status.inventory[n], tsd->deal.item[trade_i].amount);
			if (flag == 0)
			{
				//Logs (T)rade [Lupus]
				if(log_config.enable_logs&0x2)
				{
					log_pick_pc(tsd, "T", tsd->status.inventory[n].nameid, -(tsd->deal.item[trade_i].amount), &tsd->status.inventory[n]);
					log_pick_pc(sd, "T", tsd->status.inventory[n].nameid, tsd->deal.item[trade_i].amount, &tsd->status.inventory[n]);
				}
				pc_delitem(tsd, n, tsd->deal.item[trade_i].amount, 1);
			} else
				clif_additem(tsd, n, tsd->deal.item[trade_i].amount, 0);
			tsd->deal.item[trade_i].index = 0;
			tsd->deal.item[trade_i].amount = 0;
		}
	}

	if( sd->deal.zeny || tsd->deal.zeny )
	{
		sd->status.zeny += tsd->deal.zeny - sd->deal.zeny;
		tsd->status.zeny += sd->deal.zeny - tsd->deal.zeny;

		//Logs Zeny (T)rade [Lupus]
		if( sd->deal.zeny && log_config.zeny )
			log_zeny(tsd, "T", sd, sd->deal.zeny);
		if( tsd->deal.zeny && log_config.zeny )
			log_zeny(sd, "T", tsd, tsd->deal.zeny);

		sd->deal.zeny = 0;
		tsd->deal.zeny = 0;

		clif_updatestatus(sd, SP_ZENY);
		clif_updatestatus(tsd, SP_ZENY);
	}
	
	sd->state.deal_locked = 0;
	sd->trade_partner = 0;
	sd->state.trading = 0;
	
	tsd->state.deal_locked = 0;
	tsd->trade_partner = 0;
	tsd->state.trading = 0;
	
	clif_tradecompleted(sd, 0);
	clif_tradecompleted(tsd, 0);

	// save both player to avoid crash: they always have no advantage/disadvantage between the 2 players
	if (save_settings&1)
  	{
		chrif_save(sd,0); 
		chrif_save(tsd,0);
	}
}
Esempio n. 22
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
}
Esempio n. 23
0
/*==========================================
 * Žæˆø‹–‘ø(trade‰Ÿ‚µ)
 *------------------------------------------*/
void trade_tradecommit (struct map_session_data *sd)
{
	struct map_session_data *tsd;
	int trade_i;
	int flag;

	if (!sd->state.trading || !sd->state.deal_locked) //Locked should be 1 (pressed ok) before you can press trade.
		return;

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

	sd->state.deal_locked = 2;

	if (tsd->state.deal_locked < 2)
		return; //Not yet time for trading.

	//Now is a good time (to save on resources) to check that the trade can indeed be made and it's not exploitable.
	// check exploit (trade more items that you have)
	if (impossible_trade_check (sd)) {
		trade_tradecancel (sd);
		return;
	}

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

	// check for full inventory (can not add traded items)
	if (!trade_check (sd, tsd)) { // check the both players
		trade_tradecancel (sd);
		return;
	}

	// trade is accepted and correct.
	for (trade_i = 0; trade_i < 10; trade_i++) {
		int n;

		if (sd->deal.item[trade_i].amount) {
			n = sd->deal.item[trade_i].index;
			flag = pc_additem (tsd, &sd->status.inventory[n], sd->deal.item[trade_i].amount, LOG_TYPE_TRADE);

			if (flag == 0)
				pc_delitem (sd, n, sd->deal.item[trade_i].amount, 1, 6, LOG_TYPE_TRADE);
			else
				clif_additem (sd, n, sd->deal.item[trade_i].amount, 0);

			sd->deal.item[trade_i].index = 0;
			sd->deal.item[trade_i].amount = 0;
		}

		if (tsd->deal.item[trade_i].amount) {
			n = tsd->deal.item[trade_i].index;
			flag = pc_additem (sd, &tsd->status.inventory[n], tsd->deal.item[trade_i].amount, LOG_TYPE_TRADE);

			if (flag == 0)
				pc_delitem (tsd, n, tsd->deal.item[trade_i].amount, 1, 6, LOG_TYPE_TRADE);
			else
				clif_additem (tsd, n, tsd->deal.item[trade_i].amount, 0);

			tsd->deal.item[trade_i].index = 0;
			tsd->deal.item[trade_i].amount = 0;
		}
	}

	if (sd->deal.zeny) {
		pc_payzeny (sd , sd->deal.zeny, LOG_TYPE_TRADE, tsd);
		pc_getzeny (tsd, sd->deal.zeny, LOG_TYPE_TRADE, sd);
		sd->deal.zeny = 0;
		sd->deal.zeny = 0;
	}

	if (tsd->deal.zeny) {
		pc_payzeny (tsd, tsd->deal.zeny, LOG_TYPE_TRADE, sd);
		pc_getzeny (sd , tsd->deal.zeny, LOG_TYPE_TRADE, tsd);
		tsd->deal.zeny = 0;
	}

	sd->state.deal_locked = 0;
	sd->trade_partner = 0;
	sd->state.trading = 0;
	tsd->state.deal_locked = 0;
	tsd->trade_partner = 0;
	tsd->state.trading = 0;
	clif_tradecompleted (sd, 0);
	clif_tradecompleted (tsd, 0);

	// save both player to avoid crash: they always have no advantage/disadvantage between the 2 players
	if (save_settings & 1) {
		chrif_save (sd, 0);
		chrif_save (tsd, 0);
	}
}
Esempio n. 24
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);
}