bool Actions::useItemEx(Player* player, const Position& fromPos, const Position& toPos, uint8_t toStackPos, Item* item, bool isHotkey, Creature* creature/* = nullptr*/) { if (!player->canDoAction()) { return false; } player->setNextActionTask(nullptr); player->setNextAction(OTSYS_TIME() + g_config.getNumber(ConfigManager::EX_ACTIONS_DELAY_INTERVAL)); player->stopWalk(); Action* action = getAction(item); if (!action) { player->sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT); return false; } ReturnValue ret = action->canExecuteAction(player, toPos); if (ret != RETURNVALUE_NOERROR) { player->sendCancelMessage(ret); return false; } if (isHotkey) { showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), -1)); } if (!action->executeUse(player, item, fromPos, action->getTarget(player, creature, toPos, toStackPos), toPos, isHotkey)) { if (!action->hasOwnErrorHandler()) { player->sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT); } return false; } return true; }
bool Actions::useItem(Player* player, const Position& pos, uint8_t index, Item* item, bool isHotkey) { player->setNextAction(OTSYS_TIME() + g_config.getNumber(ConfigManager::ACTIONS_DELAY_INTERVAL)); player->stopWalk(); if (isHotkey) { showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), -1)); } ReturnValue ret = internalUseItem(player, pos, index, item, isHotkey); if (ret != RETURNVALUE_NOERROR) { player->sendCancelMessage(ret); return false; } return true; }
bool Actions::useItemEx(Player* player, const Position& fromPos, const Position& toPos, uint8_t toStackPos, Item* item, bool isHotkey, uint32_t creatureId/* = 0*/) { if (!player->canDoAction()) { return false; } player->setNextActionTask(nullptr); player->setNextAction(OTSYS_TIME() + g_config.getNumber(ConfigManager::EX_ACTIONS_DELAY_INTERVAL)); player->stopWalk(); Action* action = getAction(item); if (!action) { player->sendCancelMessage(RET_CANNOTUSETHISOBJECT); return false; } ReturnValue ret = action->canExecuteAction(player, toPos); if (ret != RET_NOERROR) { player->sendCancelMessage(ret); return false; } if (isHotkey) { showUseHotkeyMessage(player, item->getID(), player->__getItemTypeCount(item->getID(), -1)); } int32_t fromStackPos = item->getParent()->__getIndexOfThing(item); PositionEx fromPosEx(fromPos, fromStackPos); PositionEx toPosEx(toPos, toStackPos); if (!action->executeUse(player, item, fromPosEx, toPosEx, true, creatureId)) { if (!action->hasOwnErrorHandler()) { player->sendCancelMessage(RET_CANNOTUSETHISOBJECT); } return false; } return true; }