diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 149f41380ec..6ee9abfb137 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -2150,6 +2150,20 @@ void Player::setNextPotionActionTask(std::shared_ptr task) { } } +void Player::setNextRuneActionTask(std::shared_ptr task) { + if (actionRuneTaskEvent != 0) { + g_dispatcher().stopEvent(actionRuneTaskEvent); + actionRuneTaskEvent = 0; + } + + cancelPush(); + + if (task) { + actionRuneTaskEvent = g_dispatcher().scheduleEvent(task); + // resetIdleTime(); + } +} + uint32_t Player::getNextActionTime() const { return std::max(SCHEDULER_MINTICKS, nextAction - OTSYS_TIME()); } @@ -2158,6 +2172,10 @@ uint32_t Player::getNextPotionActionTime() const { return std::max(SCHEDULER_MINTICKS, nextPotionAction - OTSYS_TIME()); } +uint32_t Player::getNextRuneActionTime() const { + return std::max(SCHEDULER_MINTICKS, nextRuneAction - OTSYS_TIME()); +} + void Player::cancelPush() { if (actionTaskEventPush != 0) { g_dispatcher().stopEvent(actionTaskEventPush); diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index c2a9f29831a..e52fc643b13 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -1729,6 +1729,15 @@ class Player final : public Creature, public Cylinder, public Bankable { return nextPotionAction <= OTSYS_TIME(); } + void setNextRuneAction(int64_t time) { + if (time > nextRuneAction) { + nextRuneAction = time; + } + } + bool canDoRuneAction() const { + return nextRuneAction <= OTSYS_TIME(); + } + void cancelPush(); void setModuleDelay(uint8_t byteortype, int16_t delay) { @@ -1744,6 +1753,7 @@ class Player final : public Creature, public Cylinder, public Bankable { uint32_t getNextActionTime() const; uint32_t getNextPotionActionTime() const; + uint32_t getNextRuneActionTime() const; std::shared_ptr getWriteItem(uint32_t &windowTextId, uint16_t &maxWriteLen); void setWriteItem(std::shared_ptr item, uint16_t maxWriteLen = 0); @@ -2632,6 +2642,7 @@ class Player final : public Creature, public Cylinder, public Bankable { void setNextActionTask(std::shared_ptr task, bool resetIdleTime = true); void setNextActionPushTask(std::shared_ptr task); void setNextPotionActionTask(std::shared_ptr task); + void setNextRuneActionTask(std::shared_ptr task); void death(std::shared_ptr lastHitCreature) override; bool spawn(); @@ -2751,6 +2762,7 @@ class Player final : public Creature, public Cylinder, public Bankable { int64_t lastPong; int64_t nextAction = 0; int64_t nextPotionAction = 0; + int64_t nextRuneAction = 0; int64_t lastQuickLootNotification = 0; int64_t lastWalking = 0; uint64_t asyncOngoingTasks = 0; @@ -2789,6 +2801,7 @@ class Player final : public Creature, public Cylinder, public Bankable { uint32_t actionTaskEvent = 0; uint32_t actionTaskEventPush = 0; uint32_t actionPotionTaskEvent = 0; + uint32_t actionRuneTaskEvent = 0; uint32_t nextStepEvent = 0; uint32_t walkTaskEvent = 0; uint32_t MessageBufferTicks = 0; diff --git a/src/game/game.cpp b/src/game/game.cpp index b1d76f9f760..cac1f29ca97 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -3526,8 +3526,10 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f std::shared_ptr task = createPlayerTask( 400, [this, playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId] { playerUseItemEx(playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId); }, "Game::playerUseItemEx" ); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); + } else if (it.isRune()) { + player->setNextRuneActionTask(task); } else { player->setNextWalkActionTask(task); } @@ -3542,20 +3544,26 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f } bool canDoAction = player->canDoAction(); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { canDoAction = player->canDoPotionAction(); + } else if (it.isRune()) { + canDoAction = player->canDoRuneAction(); } if (!canDoAction) { uint32_t delay = player->getNextActionTime(); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { delay = player->getNextPotionActionTime(); + } else if (it.isRune()) { + delay = player->getNextRuneActionTime(); } std::shared_ptr task = createPlayerTask( delay, [this, playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId] { playerUseItemEx(playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId); }, "Game::playerUseItemEx" ); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); + } else if (it.isRune()) { + player->setNextRuneActionTask(task); } else { player->setNextActionTask(task); } @@ -3563,8 +3571,10 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f } player->resetIdleTime(); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(nullptr); + } else if (it.isRune()) { + player->setNextRuneActionTask(nullptr); } else { player->setNextActionTask(nullptr); } @@ -3640,8 +3650,10 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo std::shared_ptr task = createPlayerTask( 400, [this, playerId, pos, stackPos, index, itemId] { playerUseItem(playerId, pos, stackPos, index, itemId); }, "Game::playerUseItem" ); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); + } else if (it.isRune()) { + player->setNextRuneActionTask(task); } else { player->setNextWalkActionTask(task); } @@ -3656,20 +3668,26 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo } bool canDoAction = player->canDoAction(); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { canDoAction = player->canDoPotionAction(); + } else if (it.isRune()) { + canDoAction = player->canDoRuneAction(); } if (!canDoAction) { uint32_t delay = player->getNextActionTime(); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { delay = player->getNextPotionActionTime(); + } else if (it.isRune()) { + delay = player->getNextRuneActionTime(); } std::shared_ptr task = createPlayerTask( delay, [this, playerId, pos, stackPos, index, itemId] { playerUseItem(playerId, pos, stackPos, index, itemId); }, "Game::playerUseItem" ); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); + } else if (it.isRune()) { + player->setNextRuneActionTask(task); } else { player->setNextActionTask(task); } @@ -3800,8 +3818,10 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin }, "Game::playerUseWithCreature" ); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); + } else if (it.isRune()) { + player->setNextRuneActionTask(task); } else { player->setNextWalkActionTask(task); } @@ -3816,21 +3836,27 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin } bool canDoAction = player->canDoAction(); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { canDoAction = player->canDoPotionAction(); + } else if (it.isRune()) { + canDoAction = player->canDoRuneAction(); } if (!canDoAction) { uint32_t delay = player->getNextActionTime(); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { delay = player->getNextPotionActionTime(); + } else if (it.isRune()) { + delay = player->getNextRuneActionTime(); } std::shared_ptr task = createPlayerTask( delay, [this, playerId, fromPos, fromStackPos, creatureId, itemId] { playerUseWithCreature(playerId, fromPos, fromStackPos, creatureId, itemId); }, "Game::playerUseWithCreature" ); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); + } else if (it.isRune()) { + player->setNextRuneActionTask(task); } else { player->setNextActionTask(task); } @@ -3838,8 +3864,10 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin } player->resetIdleTime(); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(nullptr); + } else if (it.isRune()) { + player->setNextRuneActionTask(nullptr); } else { player->setNextActionTask(nullptr); } diff --git a/src/lua/creature/actions.cpp b/src/lua/creature/actions.cpp index 42f3e12c865..52fc7627aa1 100644 --- a/src/lua/creature/actions.cpp +++ b/src/lua/creature/actions.cpp @@ -407,8 +407,10 @@ bool Actions::useItem(std::shared_ptr player, const Position &pos, uint8 return false; } - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { player->setNextPotionAction(OTSYS_TIME() + g_configManager().getNumber(ACTIONS_DELAY_INTERVAL, __FUNCTION__)); + } else if (it.isRune()) { + player->setNextRuneAction(OTSYS_TIME() + g_configManager().getNumber(ACTIONS_DELAY_INTERVAL, __FUNCTION__)); } else { player->setNextAction(OTSYS_TIME() + g_configManager().getNumber(ACTIONS_DELAY_INTERVAL, __FUNCTION__)); } @@ -460,8 +462,10 @@ bool Actions::useItemEx(std::shared_ptr player, const Position &fromPos, return false; } - if (it.isRune() || it.type == ITEM_TYPE_POTION) { + if (it.type == ITEM_TYPE_POTION) { player->setNextPotionAction(OTSYS_TIME() + g_configManager().getNumber(EX_ACTIONS_DELAY_INTERVAL, __FUNCTION__)); + } else if (it.isRune()) { + player->setNextRuneAction(OTSYS_TIME() + g_configManager().getNumber(EX_ACTIONS_DELAY_INTERVAL, __FUNCTION__)); } else { player->setNextAction(OTSYS_TIME() + g_configManager().getNumber(EX_ACTIONS_DELAY_INTERVAL, __FUNCTION__)); }