void CUIMpTradeWnd::SellAll()
{
	SBuyItemInfo*	iinfo		= NULL;
	SBuyItemInfo*	tmp_iinfo	= NULL;
	bool			b_ok		= true;

	do{
		iinfo						= FindItem(SBuyItemInfo::e_bought);
		if(iinfo)
			b_ok					= TryToSellItem(iinfo, true, tmp_iinfo);

		R_ASSERT					(b_ok);
	}while(iinfo);

	do{
		iinfo						= FindItem(SBuyItemInfo::e_own);
		if(iinfo)
		{
			VERIFY					(iinfo->m_cell_item->OwnerList());
			CUICellItem* citem		= iinfo->m_cell_item->OwnerList()->RemoveItem(iinfo->m_cell_item, false );
			SBuyItemInfo* iinfo_int = FindItem(citem);
			R_ASSERT				( TryToSellItem(iinfo_int, true, tmp_iinfo) );
		}
	}while(iinfo);
}
Example #2
0
bool CUIMpTradeWnd::OnItemDbClick(CUICellItem* itm)
{
	CUIDragDropListEx*	owner_list		=	itm->OwnerList();
	dd_list_type		owner_type		=	GetListType	(owner_list);

	SBuyItemInfo*		iinfo 			=	FindItem(itm);

	switch(owner_type)
	{
		case dd_shop:
		{
			BuyItemAction					(iinfo);

		} break;

		case dd_own_bag:
		case dd_own_slot:
		{
			if ( !CanBuyOrSellInList(owner_list) )
			{
				SBuyItemInfo* tmp_iinfo =	NULL;
				TryToSellItem				(iinfo, true, tmp_iinfo);
			}
			else
			{
				OnItemLButtonClick			(itm);
			}

		} break;

		default:							NODEFAULT;
	};

	return							true;
}
void CUIMpTradeWnd::ResetToOrigin()
{
	// 1-sell all bought items
	// 2-buy all sold items
	
	SBuyItemInfo*	iinfo		= NULL;
	SBuyItemInfo*	tmp_iinfo	= NULL;
	bool			b_ok		= true;

	DeleteHelperItems	();

	do{
		iinfo			= FindItem(SBuyItemInfo::e_bought);
		if(iinfo)
			b_ok		= TryToSellItem(iinfo, true, tmp_iinfo);

		R_ASSERT		(b_ok);
	}while(iinfo);
	
	do{
		iinfo			= FindItem(SBuyItemInfo::e_sold);
		if(iinfo)
			b_ok		= TryToBuyItem(iinfo, bf_normal, NULL);

		R_ASSERT		(b_ok);
	}while(iinfo);
}
Example #4
0
void CUIMpTradeWnd::ResetToOrigin()
{
	Msg("--ResetToOrigin");
	// 1-sell all bought items
	// 2-buy all sold items
	
	ITEMS_vec_cit it;

	SBuyItemInfo*	iinfo		= NULL;
	SBuyItemInfo*	tmp_iinfo	= NULL;
	bool			b_ok		= true;

	do{
		iinfo			= FindItem(SBuyItemInfo::e_bought);
		if(iinfo)
			b_ok		= TryToSellItem(iinfo, true, tmp_iinfo);

		R_ASSERT		(b_ok);
	}while(iinfo);
	
	do{
		iinfo			= FindItem(SBuyItemInfo::e_sold);
		if(iinfo)
			b_ok		= TryToBuyItem(iinfo, bf_normal, NULL);

		R_ASSERT		(b_ok);
	}while(iinfo);
}
Example #5
0
void CUIMpTradeWnd::SellItemAddons(SBuyItemInfo* sell_itm, item_addon_type addon_type)
{
	CInventoryItem* item_	= (CInventoryItem*)sell_itm->m_cell_item->m_pData;
	CWeapon* w				= smart_cast<CWeapon*>(item_);
	if(!w)					return; //ammo,medkit etc.

	if(IsAddonAttached(sell_itm, addon_type))
	{
		SBuyItemInfo* detached_addon	= DetachAddon(sell_itm, addon_type);
		u32 _item_cost					= m_item_mngr->GetItemCost(detached_addon->m_name_sect, GetRank() );
		SetMoneyAmount					(GetMoneyAmount() + _item_cost);
		DestroyItem						(detached_addon);

		if ( addon_type == at_glauncher )
		{
			CWeaponMagazinedWGrenade* wpn2 = smart_cast<CWeaponMagazinedWGrenade*>(item_);
			VERIFY(wpn2);

			for ( u32 ammo_idx							=	0;
					  ammo_idx							<	wpn2->m_ammoTypes2.size();
					++ammo_idx )
			{
				const shared_str&	ammo_name			=	wpn2->m_ammoTypes2[ammo_idx];
				SBuyItemInfo*		ammo				=	NULL;

				while ( (ammo = FindItem(ammo_name, SBuyItemInfo::e_bought)) != NULL )
				{
					SBuyItemInfo*   tempo				=	NULL;
					TryToSellItem(ammo, true, tempo);
				}
			}
		}
	}
}
void CUIMpTradeWnd::OnBtnSellClicked(CUIWindow* w, void* d)
{
	CheckDragItemToDestroy				();
	CUIDragDropListEx*	pList			= m_list[e_player_bag];

	SBuyItemInfo*	iinfo	= NULL;
	while( pList->ItemsCount() )
	{
		CUICellItem* ci = pList->GetItemIdx(0);
		iinfo			= FindItem(ci);
		bool	b_ok	= true;
		SBuyItemInfo*	tmp_iinfo	= NULL;
		b_ok			= TryToSellItem(iinfo, true, tmp_iinfo);
		R_ASSERT		(b_ok);
	}
}
Example #7
0
bool CUIMpTradeWnd::OnItemDrop(CUICellItem* itm)
{
	CUIDragDropListEx*	_owner_list		= itm->OwnerList();
	dd_list_type		_owner_type		= GetListType	(_owner_list);

	CUIDragDropListEx*	_new_owner		= CUIDragDropListEx::m_drag_item->BackList();
	
	if(!_new_owner || _new_owner==_owner_list)		
		return			true;

	dd_list_type		_new_owner_type	= GetListType	(_new_owner);

	SBuyItemInfo*		iinfo 		= FindItem(itm);

	if(_owner_type==dd_shop)
	{
		BuyItemAction	(iinfo);
		return			true;
	}

	if(_new_owner_type==dd_shop)
	{
		SBuyItemInfo*	tmp_iinfo = NULL;
		bool res		= TryToSellItem			(iinfo, true, tmp_iinfo);
		VERIFY			(res);
		return			true;
	}
	
	if(_new_owner_type==dd_own_bag)
	{
		CUICellItem* citm				= _owner_list->RemoveItem(itm, false);
		_new_owner->SetItem				(citm);
		UpdateCorrespondingItemsForList	(_owner_list);
	}else
	{
		VERIFY(_new_owner_type==dd_own_slot);
		if( _new_owner==GetMatchedListForItem(iinfo->m_name_sect) )
		{
			CUICellItem* citm				= _owner_list->RemoveItem(itm, false);
			_new_owner->SetItem				(citm);
			UpdateCorrespondingItemsForList	(_new_owner);
		}
	}	
	return							true;
}
Example #8
0
bool CUIMpTradeWnd::OnItemRButtonClick(CUICellItem* itm)
{	
	CUIDragDropListEx*	owner_list		=	itm->OwnerList();

	SetCurrentItem							(itm);

 	SBuyItemInfo*		iinfo			=	FindItem(itm);
	SBuyItemInfo*		tmp_iinfo		=	NULL;

	if ( !CanBuyOrSellInList				(owner_list) )
	{
		return								false;
	}	

	shared_str			section			=	iinfo->m_name_sect;
	DeleteHelperItems						(owner_list);
	iinfo								=	FindItem(section, SBuyItemInfo::e_bought);
	if ( !iinfo ) iinfo					=	FindItem(section, SBuyItemInfo::e_own);

	if ( iinfo )
	{
		TryToSellItem						(iinfo, true, tmp_iinfo);
	}

	if ( owner_list						==	m_list[e_pistol_ammo] )
	{
		UpdateCorrespondingItemsForList		(m_list[e_pistol]);
	}
	else if ( owner_list				==	m_list[e_rifle_ammo] )
	{
		UpdateCorrespondingItemsForList		(m_list[e_rifle]);
	}
	else
	{
		CreateHelperItems					(owner_list);
	}

	return									false;
}
void CUIMpTradeWnd::DeleteHelperItems (CUIDragDropListEx* list)
{
	ITEMS_vec to_sell;

	for ( ITEMS_vec::iterator it	=	m_all_items.begin();
							  it	!=	m_all_items.end();
							  ++it )
	{
		SBuyItemInfo*		  item			=	*it;

		if ( item->m_cell_item->OwnerList() != list )
		{
			continue;
		}

		if ( item->GetState() != SBuyItemInfo::e_bought && item->GetState() != SBuyItemInfo::e_own )
		{
			continue;
		}

		if ( item->m_cell_item->IsHelper() )
		{
			if ( std::find(to_sell.begin(), to_sell.end(), item) == to_sell.end() )
			{
				to_sell.push_back(item);
			}
		}
	}

	for ( ITEMS_vec::iterator it	=	to_sell.begin();
							  it	!=	to_sell.end();
							  ++it )
	{
		SBuyItemInfo* tempo = NULL;
		TryToSellItem(*it, true, tempo);
	}
}
void CUIMpTradeWnd::UpdateCorrespondingItemsForList(CUIDragDropListEx* _list)
{
	CUIDragDropListEx* dependent_list	= NULL;
	CUIDragDropListEx* bag_list			= m_list[e_player_bag];

	if(_list==m_list[e_pistol])
		dependent_list	= m_list[e_pistol_ammo];
	else
	if(_list==m_list[e_rifle])
		dependent_list	= m_list[e_rifle_ammo];

	if(!dependent_list)	return;

	DeleteHelperItems(dependent_list);

	xr_list<SBuyItemInfo*>	_tmp_list;
	while(dependent_list->ItemsCount()!=0)
	{
		CUICellItem* ci			= dependent_list->GetItemIdx(0);
		CUICellItem* ci2		= dependent_list->RemoveItem(ci, false);
		SBuyItemInfo* bi		= FindItem(ci2);		
		_tmp_list.push_back		( bi );
		bag_list->SetItem		( ci2 );
	};

	CreateHelperItems(dependent_list);

	if(_list->ItemsCount()!=0)
	{
		R_ASSERT(_list->ItemsCount()==1);

		CInventoryItem* main_item	= (CInventoryItem*)_list->GetItemIdx(0)->m_pData;

		while( bag_list->ItemsCount() )
		{
			u32 cnt = bag_list->ItemsCount();
			for(u32 idx=0; idx<cnt; ++idx)
			{
				CUICellItem* ci					= bag_list->GetItemIdx(idx);
				SBuyItemInfo* iinfo				= FindItem(ci);

				if(main_item->IsNecessaryItem	(iinfo->m_name_sect))
				{
					CUICellItem* ci2			= bag_list->RemoveItem(ci, false);
					dependent_list->SetItem		(ci2);
					goto _l1;
				}
			}
			break;
			_l1:
			;
		}
	}

	while( !_tmp_list.empty() )
	{
		xr_list<SBuyItemInfo*>::iterator _curr = _tmp_list.begin();
		SBuyItemInfo* bi	= *(_curr);

		CUIDragDropListEx*	_owner_list		= bi->m_cell_item->OwnerList();
		if(_owner_list!=bag_list){
			_tmp_list.erase	( _curr );
			continue;
		}

		u32 _bag_cnt = bag_list->ItemsCount();

		bool bNecessary = false;

		for(u32 _i=0; _i<_bag_cnt; ++_i)
		{
			CUICellItem*	_ci					= bag_list->GetItemIdx(_i);
			CInventoryItem* _ii					= (CInventoryItem*)_ci->m_pData;
			
			bNecessary							= _ii->IsNecessaryItem(bi->m_name_sect);

			if(bNecessary)
			{
				_tmp_list.erase	( _curr );
				break;
			}
		}
		if(!bNecessary)
		{
			//sell 
			SBuyItemInfo*			res_info	= NULL;
			TryToSellItem			(bi, true, res_info);
			xr_list<SBuyItemInfo*>::iterator tmp_it = find(_tmp_list.begin(), _tmp_list.end(), res_info);
			VERIFY					(tmp_it!=_tmp_list.end());
			_tmp_list.erase			( tmp_it );
		}
	}
}