void Game::rotate(const ThingPtr& thing) { if(!canPerformGameAction() || !thing) return; m_protocolGame->sendRotateItem(thing->getPosition(), thing->getId(), thing->getStackpos()); }
void Game::move(const ThingPtr& thing, const Position& toPos, int count) { if(count <= 0) count = 1; if(!canPerformGameAction() || !thing || thing->getPosition() == toPos) return; uint id = thing->getId(); if(thing->isCreature()) { CreaturePtr creature = thing->static_self_cast<Creature>(); id = Proto::Creature; } m_protocolGame->sendMove(thing->getPosition(), id, thing->getStackpos(), toPos, count); }
bool Map::removeThing(const ThingPtr& thing) { if(!thing) return false; bool ret = false; if(thing->isMissile()) { MissilePtr missile = thing->static_self_cast<Missile>(); int z = missile->getPosition().z; auto it = std::find(m_floorMissiles[z].begin(), m_floorMissiles[z].end(), missile); if(it != m_floorMissiles[z].end()) { m_floorMissiles[z].erase(it); ret = true; } } else if(thing->isAnimatedText()) { AnimatedTextPtr animatedText = thing->static_self_cast<AnimatedText>(); auto it = std::find(m_animatedTexts.begin(), m_animatedTexts.end(), animatedText); if(it != m_animatedTexts.end()) { m_animatedTexts.erase(it); ret = true; } } else if(thing->isStaticText()) { StaticTextPtr staticText = thing->static_self_cast<StaticText>(); auto it = std::find(m_staticTexts.begin(), m_staticTexts.end(), staticText); if(it != m_staticTexts.end()) { m_staticTexts.erase(it); ret = true; } } else if(const TilePtr& tile = thing->getTile()) ret = tile->removeThing(thing); notificateTileUpdate(thing->getPosition()); return ret; }
void Game::moveToParentContainer(const ThingPtr& thing, int count) { if(!canPerformGameAction() || !thing || count <= 0) return; Position position = thing->getPosition(); move(thing, Position(position.x, position.y, 254), count); }
void Game::look(const ThingPtr& thing) { if(!canPerformGameAction() || !thing) return; if(thing->isCreature() && m_protocolVersion >= 961) m_protocolGame->sendLookCreature(thing->getId()); else m_protocolGame->sendLook(thing->getPosition(), thing->getId(), thing->getStackPos()); }
void Game::use(const ThingPtr& thing) { if(!canPerformGameAction() || !thing) return; Position pos = thing->getPosition(); if(!pos.isValid()) // virtual item pos = Position(0xFFFF, 0, 0); // means that is a item in inventory m_protocolGame->sendUseItem(pos, thing->getId(), thing->getStackpos(), 0); }
void Game::useWith(const ItemPtr& item, const ThingPtr& toThing) { if(!canPerformGameAction() || !item || !toThing) return; Position pos = item->getPosition(); if(!pos.isValid()) // virtual item pos = Position(0xFFFF, 0, 0); // means that is a item in inventory m_protocolGame->sendUseItemWith(pos, item->getId(), item->getStackPos(), toThing->getPosition(), toThing->getId(), toThing->getStackPos()); }
void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing) { if(!canPerformGameAction() || !toThing) return; Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory if(toThing->isCreature()) m_protocolGame->sendUseOnCreature(pos, itemId, 0, toThing->getId()); else m_protocolGame->sendUseItemWith(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackpos()); }
void Game::use(const ThingPtr& thing) { if(!canPerformGameAction() || !thing) return; Position pos = thing->getPosition(); if(!pos.isValid()) // virtual item pos = Position(0xFFFF, 0, 0); // inventory item // some items, e.g. parcel, are not set as containers but they are. // always try to use these items in free container slots. m_protocolGame->sendUseItem(pos, thing->getId(), thing->getStackPos(), findEmptyContainerId()); }
void Map::removeThing(const ThingPtr& thing) { if(!thing) return; if(MissilePtr shot = thing->asMissile()) { auto it = std::find(m_missilesAtFloor[shot->getPosition().z].begin(), m_missilesAtFloor[shot->getPosition().z].end(), shot); if(it != m_missilesAtFloor[shot->getPosition().z].end()) { m_missilesAtFloor[shot->getPosition().z].erase(it); } return; } if(TilePtr& tile = m_tiles[thing->getPosition()]) tile->removeThing(thing); }