Esempio n. 1
0
void MoveEvents::onAddTileItem(const Tile* tile, Item* item)
{
	if(m_lastCacheTile == tile){
		std::vector<Item*>::iterator it = std::find(
			m_lastCacheItemVector.begin(), m_lastCacheItemVector.end(), item);
		if(it == m_lastCacheItemVector.end()){
			if(hasTileEvent(item)){
				m_lastCacheItemVector.push_back(item);
			}
		}
	}
}
Esempio n. 2
0
uint32_t MoveEvents::onItemMove(Item* item, Tile* tile, bool isAdd)
{
	MoveEvent_t eventType1;
	MoveEvent_t eventType2;

	if (isAdd)
	{
		eventType1 = MOVE_EVENT_ADD_ITEM;
		eventType2 = MOVE_EVENT_ADD_ITEM_ITEMTILE;
	}
	else
	{
		eventType1 = MOVE_EVENT_REMOVE_ITEM;
		eventType2 = MOVE_EVENT_REMOVE_ITEM_ITEMTILE;
	}

	uint32_t ret = 1;
	MoveEvent* moveEvent = getEvent(tile, eventType1);

	if (moveEvent)
	{
		ret &= moveEvent->fireAddRemItem(item, NULL, tile->getPosition());
	}

	moveEvent = getEvent(item, eventType1);

	if (moveEvent)
	{
		ret &= moveEvent->fireAddRemItem(item, NULL, tile->getPosition());
	}

	Item* tileItem = NULL;

	if (m_lastCacheTile == tile)
	{
		if (m_lastCacheItemVector.empty())
		{
			return false;
		}

		//We can not use iterators here since the scripts can invalidate the iterator
		for (uint32_t i = 0; i < m_lastCacheItemVector.size(); ++i)
		{
			tileItem = m_lastCacheItemVector[i];

			if (tileItem && tileItem != item)
			{
				moveEvent = getEvent(tileItem, eventType2);

				if (moveEvent)
				{
					ret &= moveEvent->fireAddRemItem(item, tileItem, tile->getPosition());
				}
			}
		}

		return ret;
	}

	m_lastCacheTile = tile;
	m_lastCacheItemVector.clear();
	//We can not use iterators here since the scripts can invalidate the iterator
	int32_t j = tile->__getLastIndex();

	for (int32_t i = tile->__getFirstIndex(); i < j; ++i)
	{
		Thing* thing = tile->__getThing(i);

		if (thing && (tileItem = thing->getItem()) && (tileItem != item))
		{
			moveEvent = getEvent(tileItem, eventType2);

			if (moveEvent)
			{
				m_lastCacheItemVector.push_back(tileItem);
				ret &= moveEvent->fireAddRemItem(item, tileItem, tile->getPosition());
			}
			else if (hasTileEvent(tileItem))
			{
				m_lastCacheItemVector.push_back(tileItem);
			}
		}
	}

	return ret;
}
Esempio n. 3
0
uint32_t MoveEvents::onCreatureMove(Creature* creature, const Tile* fromTile, const Tile* toTile, bool isIn)
{
	MoveEvent_t eventType;
	const Tile* tile = NULL;

	if (isIn)
	{
		tile = toTile;
		eventType = MOVE_EVENT_STEP_IN;
	}
	else
	{
		tile = fromTile;
		eventType = MOVE_EVENT_STEP_OUT;
	}

	Position fromPos(0, 0, 0);

	if (fromTile)
	{
		fromPos = fromTile->getPosition();
	}

	Position toPos(0, 0, 0);

	if (toTile)
	{
		toPos = toTile->getPosition();
	}

	uint32_t ret = 1;
	MoveEvent* moveEvent = getEvent(tile, eventType);

	if (moveEvent)
	{
		ret = ret & moveEvent->fireStepEvent(creature, NULL, fromPos, toPos);
	}

	Item* tileItem = NULL;

	if (m_lastCacheTile == tile)
	{
		if (m_lastCacheItemVector.empty())
		{
			return ret;
		}

		//We can not use iterators here since the scripts can invalidate the iterator
		for (uint32_t i = 0; i < m_lastCacheItemVector.size(); ++i)
		{
			tileItem = m_lastCacheItemVector[i];

			if (tileItem)
			{
				moveEvent = getEvent(tileItem, eventType);

				if (moveEvent)
				{
					ret = ret & moveEvent->fireStepEvent(creature, tileItem, fromPos, toPos);
				}
			}
		}

		return ret;
	}

	m_lastCacheTile = tile;
	m_lastCacheItemVector.clear();
	//We can not use iterators here since the scripts can invalidate the iterator
	int32_t j = tile->__getLastIndex();

	for (int32_t i = tile->__getFirstIndex(); i < j; ++i)
	{
		Thing* thing = tile->__getThing(i);

		if (thing && (tileItem = thing->getItem()))
		{
			moveEvent = getEvent(tileItem, eventType);

			if (moveEvent)
			{
				m_lastCacheItemVector.push_back(tileItem);
				ret = ret & moveEvent->fireStepEvent(creature, tileItem, fromPos, toPos);
			}
			else if (hasTileEvent(tileItem))
			{
				m_lastCacheItemVector.push_back(tileItem);
			}
		}
	}

	return ret;
}