Exemple #1
0
void Container::__replaceThing(uint32_t index, Thing* thing)
{
	Item* item = thing->getItem();
	if (!item) {
		return /*RET_NOTPOSSIBLE*/;
	}

	Item* replacedItem = getItemByIndex(index);
	if (!replacedItem) {
		return /*RET_NOTPOSSIBLE*/;
	}

	totalWeight -= replacedItem->getWeight();
	totalWeight += item->getWeight();

	if (Container* parentContainer = getParentContainer()) {
		parentContainer->updateItemWeight(-replacedItem->getWeight() + item->getWeight());
	}

	itemlist[index] = item;
	item->setParent(this);

	//send change to client
	if (getParent()) {
		const ItemType& oldType = Item::items[replacedItem->getID()];
		const ItemType& newType = Item::items[item->getID()];
		onUpdateContainerItem(index, replacedItem, oldType, item, newType);
	}

	replacedItem->setParent(NULL);
}
Exemple #2
0
void Container::removeThing(Thing* thing, uint32_t count)
{
	Item* item = thing->getItem();
	if (item == nullptr) {
		return /*RETURNVALUE_NOTPOSSIBLE*/;
	}

	int32_t index = getThingIndex(thing);
	if (index == -1) {
		return /*RETURNVALUE_NOTPOSSIBLE*/;
	}

	if (item->isStackable() && count != item->getItemCount()) {
		uint8_t newCount = static_cast<uint8_t>(std::max<int32_t>(0, item->getItemCount() - count));
		const int32_t oldWeight = item->getWeight();
		item->setItemCount(newCount);
		updateItemWeight(-oldWeight + item->getWeight());

		//send change to client
		if (getParent()) {
			onUpdateContainerItem(index, item, item);
		}
	} else {
		updateItemWeight(-static_cast<int32_t>(item->getWeight()));

		//send change to client
		if (getParent()) {
			onRemoveContainerItem(index, item);
		}

		item->setParent(nullptr);
		itemlist.erase(itemlist.begin() + index);
	}
}
Exemple #3
0
void Container::__updateThing(Thing* thing, uint16_t itemId, uint32_t count)
{
	int32_t index = __getIndexOfThing(thing);
	if (index == -1) {
		return /*RET_NOTPOSSIBLE*/;
	}

	Item* item = thing->getItem();
	if (item == NULL) {
		return /*RET_NOTPOSSIBLE*/;
	}

	const ItemType& oldType = Item::items[item->getID()];
	const ItemType& newType = Item::items[itemId];

	const double oldWeight = item->getWeight();

	item->setID(itemId);
	item->setSubType(count);

	const double diffWeight = -oldWeight + item->getWeight();

	totalWeight += diffWeight;

	if (Container* parentContainer = getParentContainer()) {
		parentContainer->updateItemWeight(diffWeight);
	}

	//send change to client
	if (getParent()) {
		onUpdateContainerItem(index, item, oldType, item, newType);
	}
}
void Container::__replaceThing(uint32_t index, Thing* thing)
{
	Item* item = thing->getItem();
	if (!item) {
		return /*RET_NOTPOSSIBLE*/;
	}

	Item* replacedItem = getItemByIndex(index);
	if (!replacedItem) {
		return /*RET_NOTPOSSIBLE*/;
	}

	totalWeight -= replacedItem->getWeight();
	totalWeight += item->getWeight();

	if (Container* parentContainer = getParentContainer()) {
		parentContainer->updateItemWeight(-replacedItem->getWeight() + item->getWeight());
	}

	itemlist[index] = item;
	item->setParent(this);

	//send change to client
	if (getParent()) {
		onUpdateContainerItem(index, replacedItem, item);
	}

	replacedItem->setParent(nullptr);
}
Exemple #5
0
void Container::__replaceThing(uint32_t index, Thing* thing)
{
    Item* item = thing->getItem();
    if(!item)
    {
#ifdef __DEBUG_MOVESYS__
        std::clog << "Failure: [Container::__replaceThing] item == NULL" << std::endl;
#endif
        return /*RET_NOTPOSSIBLE*/;
    }

    uint32_t count = 0;
    ItemList::iterator cit = itemlist.end();
    for(cit = itemlist.begin(); cit != itemlist.end(); ++cit)
    {
        if(count == index)
            break;

        ++count;
    }

    if(cit == itemlist.end())
    {
#ifdef __DEBUG_MOVESYS__
        std::clog << "Failure: [Container::__updateThing] item not found" << std::endl;
#endif
        return /*RET_NOTPOSSIBLE*/;
    }

    totalWeight -= (*cit)->getWeight();
    totalWeight += item->getWeight();
    if(Container* parentContainer = getParentContainer())
        parentContainer->updateItemWeight(-(*cit)->getWeight() + item->getWeight());

    itemlist.insert(cit, item);
    item->setParent(this);
    //send change to client
    if(getParent())
    {
        const ItemType& oldType = Item::items[(*cit)->getID()];
        const ItemType& newType = Item::items[item->getID()];
        onUpdateContainerItem(index, *cit, oldType, item, newType);
    }

    (*cit)->setParent(NULL);
    itemlist.erase(cit);
}
Exemple #6
0
void Container::__removeThing(Thing* thing, uint32_t count)
{
	Item* item = thing->getItem();
	if (item == NULL) {
		return /*RET_NOTPOSSIBLE*/;
	}

	int32_t index = __getIndexOfThing(thing);
	if (index == -1) {
		return /*RET_NOTPOSSIBLE*/;
	}

	if (item->isStackable() && count != item->getItemCount()) {
		uint8_t newCount = (uint8_t)std::max<int32_t>(0, item->getItemCount() - count);
		const double oldWeight = -item->getWeight();
		item->setItemCount(newCount);
		const double diffWeight = oldWeight + item->getWeight();
		totalWeight += diffWeight;

		//send change to client
		if (getParent()) {
			if (Container* parentContainer = getParentContainer()) {
				parentContainer->updateItemWeight(diffWeight);
			}

			const ItemType& it = Item::items[item->getID()];
			onUpdateContainerItem(index, item, it, item, it);
		}
	} else {
		//send change to client
		if (getParent()) {
			if (Container* parentContainer = getParentContainer()) {
				parentContainer->updateItemWeight(-item->getWeight());
			}

			onRemoveContainerItem(index, item);
		}

		totalWeight -= item->getWeight();
		item->setParent(NULL);
		itemlist.erase(itemlist.begin() + index);
	}
}
Exemple #7
0
void Container::updateThing(Thing* thing, uint16_t itemId, uint32_t count)
{
	int32_t index = getThingIndex(thing);
	if (index == -1) {
		return /*RETURNVALUE_NOTPOSSIBLE*/;
	}

	Item* item = thing->getItem();
	if (item == nullptr) {
		return /*RETURNVALUE_NOTPOSSIBLE*/;
	}

	const int32_t oldWeight = item->getWeight();
	item->setID(itemId);
	item->setSubType(count);
	updateItemWeight(-oldWeight + item->getWeight());

	//send change to client
	if (getParent()) {
		onUpdateContainerItem(index, item, item);
	}
}
Exemple #8
0
void Container::replaceThing(uint32_t index, Thing* thing)
{
	Item* item = thing->getItem();
	if (!item) {
		return /*RETURNVALUE_NOTPOSSIBLE*/;
	}

	Item* replacedItem = getItemByIndex(index);
	if (!replacedItem) {
		return /*RETURNVALUE_NOTPOSSIBLE*/;
	}

	itemlist[index] = item;
	item->setParent(this);
	updateItemWeight(-static_cast<int32_t>(replacedItem->getWeight()) + item->getWeight());

	//send change to client
	if (getParent()) {
		onUpdateContainerItem(index, replacedItem, item);
	}

	replacedItem->setParent(nullptr);
}
Exemple #9
0
void Container::__updateThing(Thing* thing, uint16_t itemId, uint32_t count)
{
    int32_t index = __getIndexOfThing(thing);
    if(index == -1)
    {
#ifdef __DEBUG_MOVESYS__
        std::clog << "Failure: [Container::__updateThing] index == -1" << std::endl;
#endif
        return /*RET_NOTPOSSIBLE*/;
    }

    Item* item = thing->getItem();
    if(!item)
    {
#ifdef __DEBUG_MOVESYS__
        std::clog << "Failure: [Container::__updateThing] item == NULL" << std::endl;
#endif
        return /*RET_NOTPOSSIBLE*/;
    }

    const ItemType& oldType = Item::items[item->getID()];
    const ItemType& newType = Item::items[itemId];

    const double oldWeight = item->getWeight();
    item->setID(itemId);
    item->setSubType(count);

    const double diffWeight = -oldWeight + item->getWeight();
    totalWeight += diffWeight;
    if(Container* parentContainer = getParentContainer())
        parentContainer->updateItemWeight(diffWeight);

    //send change to client
    if(getParent())
        onUpdateContainerItem(index, item, oldType, item, newType);
}
Exemple #10
0
void Container::__removeThing(Thing* thing, uint32_t count)
{
    Item* item = thing->getItem();
    if(!item)
    {
#ifdef __DEBUG_MOVESYS__
        std::clog << "Failure: [Container::__removeThing] item == NULL" << std::endl;
#endif
        return /*RET_NOTPOSSIBLE*/;
    }

    int32_t index = __getIndexOfThing(thing);
    if(index == -1)
    {
#ifdef __DEBUG_MOVESYS__
        std::clog << "Failure: [Container::__removeThing] index == -1" << std::endl;
#endif
        return /*RET_NOTPOSSIBLE*/;
    }

    ItemList::iterator cit = std::find(itemlist.begin(), itemlist.end(), thing);
    if(cit == itemlist.end())
    {
#ifdef __DEBUG_MOVESYS__
        std::clog << "Failure: [Container::__removeThing] item not found" << std::endl;
#endif
        return /*RET_NOTPOSSIBLE*/;
    }

    if(item->isStackable() && count != item->getItemCount())
    {
        const double oldWeight = -item->getWeight();
        item->setItemCount(std::max(0, (int32_t)(item->getItemCount() - count)));

        const double diffWeight = oldWeight + item->getWeight();
        totalWeight += diffWeight;
        //send change to client
        if(getParent())
        {
            if(Container* parentContainer = getParentContainer())
                parentContainer->updateItemWeight(diffWeight);

            const ItemType& it = Item::items[item->getID()];
            onUpdateContainerItem(index, item, it, item, it);
        }
    }
    else
    {
        //send change to client
        if(getParent())
        {
            if(Container* parentContainer = getParentContainer())
                parentContainer->updateItemWeight(-item->getWeight());

            onRemoveContainerItem(index, item);
        }

        totalWeight -= item->getWeight();
        item->setParent(NULL);
        itemlist.erase(cit);
    }
}