Пример #1
0
bool CShop::MergeIntoStartingEquipment( const idStr &itemName, int quantity, bool isWeapon, bool isMeleeWeapon ) {
	CShopItemPtr startingItem = FindStartingItemByID( itemName );
	if( !startingItem ) {
		return false; // item not found
	}
	int oldQuantity = startingItem->GetCount();
	int newQuantity = oldQuantity + quantity;
	// Weapons have ammo limits. Even though you might have
	// adjusted that already in the incoming item,
	// you have to check again when it's added to
	// the existing amount already in the starting items.
	if( isWeapon ) {
		if( isMeleeWeapon ) {
			// Don't stack anything for melee weapons, otherwise we end up with 2 shortswords
			newQuantity = oldQuantity;
		} else {
			// Arrow-based weapons need ammo
			int maxAmmo = GetMaxAmmo( itemName );
			if( newQuantity > maxAmmo ) {
				newQuantity = maxAmmo;
			}
		}
		quantity = newQuantity - oldQuantity; // amount to give
	} else if( !startingItem->GetStackable() ) {
		quantity = 0; // don't adjust item's quantity
	}
	if( quantity > 0 ) {
		startingItem->ChangeCount( quantity ); // add quantity to count
	}
	return true; // item found
}
Пример #2
0
void CShop::SellItem(int index)
{
	CShopItemPtr boughtItem = _itemsPurchased[_purchasedTop + index];
	CShopItemPtr forSaleItem = FindForSaleByID(boughtItem->GetID());
	boughtItem->ChangeCount(-1);

	// If last in the purchased items list, remove it from the list
	if (boughtItem->GetCount() == 0)
	{
		_itemsPurchased.RemoveIndex(_purchasedTop + index);
		// scroll so appropriate items visible
		if ((_purchasedTop >= _itemsPurchased.Num()) || (_purchasedTop % LIST_SIZE_PURCHASED != 0)) {
			_purchasedTop = _itemsPurchased.Num() - LIST_SIZE_PURCHASED;
			if (_purchasedTop < 0) _purchasedTop = 0;
		}
	}

	ChangeGold(boughtItem->GetCost());

	// If the weapon class wasn't in the for sale list (it should be), add it
	if (forSaleItem == NULL)
	{
		forSaleItem = CShopItemPtr(new CShopItem(*boughtItem, 0, boughtItem->GetCost(), boughtItem->GetPersistent()));

		_itemsForSale.Append(forSaleItem);
	}

	forSaleItem->ChangeCount(1);
}
Пример #3
0
void CShop::CopyPurchasedIntoStartingEquipment() {
	for( int i = 0; i < _itemsPurchased.Num(); i++ ) {
		CShopItemPtr item = FindStartingItemByID( _itemsPurchased[i]->GetID() );
		if( item == NULL ) {
			_startingItems.Append( _itemsPurchased[i] );
		} else {
			// Starting item exists, just change the count
			item->ChangeCount( _itemsPurchased[i]->GetCount() );
		}
	}
}
Пример #4
0
void CShop::BuyItem(int index)
{
	CShopItemPtr forSaleItem = _itemsForSale[_forSaleTop + index];
	CShopItemPtr boughtItem = FindPurchasedByID(forSaleItem->GetID());

	forSaleItem->ChangeCount(-1);
	ChangeGold(-(forSaleItem->GetCost()));

	// if the weapon class wasn't in the purchased item list, add it
	if (boughtItem == NULL)
	{
		boughtItem = CShopItemPtr(new CShopItem(
			*forSaleItem, 0, forSaleItem->GetCost(), forSaleItem->GetPersistent())
		);

		_itemsPurchased.Append(boughtItem);

		// scroll so new item is visible in purchased list
		if (_itemsPurchased.Num() > _purchasedTop + LIST_SIZE_PURCHASED)
		{
			_purchasedTop = _itemsPurchased.Num() - LIST_SIZE_PURCHASED;
		}
	}

	boughtItem->ChangeCount(1);
}