Exemplo n.º 1
0
ReturnValue Container::__queryMaxCount(int32_t index, const Thing* thing, uint32_t count,
	uint32_t& maxQueryCount, uint32_t flags) const
{
	const Item* item = thing->getItem();
	if(item == NULL)
	{
		maxQueryCount = 0;
		return RET_NOTPOSSIBLE;
	}

	if(hasBitSet(FLAG_NOLIMIT, flags))
	{
		maxQueryCount = std::max<uint32_t>(1, count);
		return RET_NOERROR;
	}

	int32_t freeSlots = std::max<int32_t>(capacity() - size(), 0);

	if(item->isStackable())
	{
		uint32_t n = 0;

		if(index == INDEX_WHEREEVER)
		{
			//Iterate through every item and check how much free stackable slots there is.
			uint32_t slotIndex = 0;
			for(ItemDeque::const_iterator cit = itemlist.begin(); cit != itemlist.end(); ++cit, ++slotIndex)
			{
				if((*cit) != item && (*cit)->getID() == item->getID() && (*cit)->getItemCount() < 100)
				{
					uint32_t remainder = (100 - (*cit)->getItemCount());
					if(__queryAdd(slotIndex, item, remainder, flags) == RET_NOERROR)
						n += remainder;
				}
			}
		}
		else
		{
			const Item* destItem = getItem(index);
			if(destItem && destItem->getID() == item->getID() && destItem->getItemCount() < 100)
			{
				uint32_t remainder = 100 - destItem->getItemCount();
				if(__queryAdd(index, item, remainder, flags) == RET_NOERROR)
					n = remainder;
			}
		}

		maxQueryCount = freeSlots * 100 + n;
		if(maxQueryCount < count)
			return RET_CONTAINERNOTENOUGHROOM;
	}
	else
	{
		maxQueryCount = freeSlots;
		if(maxQueryCount == 0)
			return RET_CONTAINERNOTENOUGHROOM;
	}
	return RET_NOERROR;
}
Exemplo n.º 2
0
ReturnValue Container::__queryMaxCount(int32_t index, const Thing* thing, uint32_t count,
                                       uint32_t& maxQueryCount, uint32_t flags) const
{
	const Item* item = thing->getItem();
	if (item == nullptr) {
		maxQueryCount = 0;
		return RETURNVALUE_NOTPOSSIBLE;
	}

	if (hasBitSet(FLAG_NOLIMIT, flags)) {
		maxQueryCount = std::max<uint32_t>(1, count);
		return RETURNVALUE_NOERROR;
	}

	int32_t freeSlots = std::max<int32_t>(capacity() - size(), 0);

	if (item->isStackable()) {
		uint32_t n = 0;

		if (index == INDEX_WHEREEVER) {
			//Iterate through every item and check how much free stackable slots there is.
			uint32_t slotIndex = 0;
			for (Item* containerItem : itemlist) {
				if (containerItem != item && containerItem->equals(item) && containerItem->getItemCount() < 100) {
					uint32_t remainder = (100 - containerItem->getItemCount());
					if (__queryAdd(slotIndex++, item, remainder, flags) == RETURNVALUE_NOERROR) {
						n += remainder;
					}
				}
			}
		} else {
			const Item* destItem = getItemByIndex(index);
			if (item->equals(destItem) && destItem->getItemCount() < 100) {
				uint32_t remainder = 100 - destItem->getItemCount();
				if (__queryAdd(index, item, remainder, flags) == RETURNVALUE_NOERROR) {
					n = remainder;
				}
			}
		}

		maxQueryCount = freeSlots * 100 + n;
		if (maxQueryCount < count) {
			return RETURNVALUE_CONTAINERNOTENOUGHROOM;
		}
	} else {
		maxQueryCount = freeSlots;
		if (maxQueryCount == 0) {
			return RETURNVALUE_CONTAINERNOTENOUGHROOM;
		}
	}
	return RETURNVALUE_NOERROR;
}