コード例 #1
0
ファイル: trade.c プロジェクト: AurigaProject/root
/*==========================================
 * アイテム追加
 *------------------------------------------
 */
void trade_tradeadditem(struct map_session_data *sd, int idx, int amount)
{
	struct map_session_data *target_sd;

	nullpo_retv(sd);

	target_sd = map_id2sd(sd->trade.partner);
	if (target_sd && target_sd->bl.prev && sd->state.deal_locked < 1) {
		if (idx < 2 || idx >= MAX_INVENTORY + 2) {
			if (idx == 0 && amount > 0 && amount <= sd->status.zeny) {
				if(
					target_sd->status.zeny - target_sd->trade.zeny + amount <= MAX_ZENY &&
					target_sd->status.zeny - target_sd->trade.zeny + amount >= 0 // overflow 対策
				) {
					sd->trade.zeny=amount;
					clif_tradeadditem(sd,target_sd,0,amount);
				} else {
					clif_tradeitemok(sd, idx, 1); //fail to add item
				}
			}
		} else if (amount <= sd->status.inventory[idx-2].amount && amount > 0 && itemdb_isdropable(sd->status.inventory[idx-2].nameid)) {
			int trade_i;
			int trade_weight = 0;

			for(trade_i = 0; trade_i < MAX_DEAL_ITEMS; trade_i++) {
				if(sd->trade.item_amount[trade_i] == 0){
					trade_weight += sd->inventory_data[idx-2]->weight * amount;
					if(target_sd->weight + trade_weight > target_sd->max_weight){
						clif_tradeitemok(sd, idx, 1); //fail to add item -- the player was over weighted.
					}else{
						// re-deal is check when trade is commited.
						sd->trade.item_index[trade_i]  = idx;
						sd->trade.item_amount[trade_i] = amount;
						clif_tradeitemok(sd, idx, 0); //success to add item
						clif_tradeadditem(sd, target_sd, idx, amount);
					}
					break;
				}else{
					trade_weight+=sd->inventory_data[sd->trade.item_index[trade_i]-2]->weight*sd->trade.item_amount[trade_i];
				}
			}
		} else {
			clif_tradeitemok(sd, idx, 1); //fail to add item
		}
	}

	return;
}
コード例 #2
0
ファイル: trade.c プロジェクト: Celso1415/Fusion
/*==========================================
 * 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);
}
コード例 #3
0
ファイル: trade.c プロジェクト: Celso1415/Fusion
/*==========================================
 * 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);
}
コード例 #4
0
ファイル: trade.cpp プロジェクト: 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_--;
            }
        }
    }
}
コード例 #5
0
ファイル: trade.c プロジェクト: AxlSckay/Ragnarok-OldTimes
/*==========================================
 * 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
}
コード例 #6
0
ファイル: trade.c プロジェクト: Aeromesi/PkRO_Translation
/*==========================================
 * 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);
}
コード例 #7
0
ファイル: trade.c プロジェクト: AxlSckay/Ragnarok-OldTimes
/*==========================================
 * 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
}