uint32_t MoveEvents::onItemMove(Item* item, Tile* tile, bool isAdd) { MoveEvent_t eventType1, 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, nullptr, tile->getPosition()); } moveEvent = getEvent(item, eventType1); if (moveEvent) { ret &= moveEvent->fireAddRemItem(item, nullptr, tile->getPosition()); } for (size_t i = tile->getFirstIndex(), j = tile->getLastIndex(); i < j; ++i) { Thing* thing = tile->getThing(i); if (!thing) { continue; } Item* tileItem = thing->getItem(); if (!tileItem || tileItem == item) { continue; } moveEvent = getEvent(tileItem, eventType2); if (moveEvent) { ret &= moveEvent->fireAddRemItem(item, tileItem, tile->getPosition()); } } return ret; }
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 = ret & moveEvent->fireAddRemItem(item, NULL, tile->getPosition()); } moveEvent = getEvent(item, eventType1); if(moveEvent){ ret = ret & moveEvent->fireAddRemItem(item, NULL, tile->getPosition()); } int32_t j = tile->__getLastIndex(); Item* tileItem = NULL; 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){ ret = ret & moveEvent->fireAddRemItem(item, tileItem, tile->getPosition()); } } } return ret; }
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; }