From eece7e5388d25a2b4b2f674e7768302db8f710f5 Mon Sep 17 00:00:00 2001 From: SamuelBFG Date: Thu, 23 Jan 2025 12:16:41 -0300 Subject: [PATCH] feat: necklage/rings with differente exhaustion times --- src/creatures/players/player.cpp | 20 ++++++++++++++++++++ src/creatures/players/player.hpp | 8 ++++++++ src/game/game.cpp | 26 ++++++++++++++++++++------ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 4f388e6ee90..e5b2f37342a 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -2924,6 +2924,26 @@ bool Player::canDoAction() const { return nextAction <= OTSYS_TIME(); } +void Player::setNextNecklaceAction(int64_t time) { + if (time > nextNecklaceAction) { + nextNecklaceAction = time; + } +} + +void Player::setNextRingAction(int64_t time) { + if (time > nextRingAction) { + nextRingAction = time; + } +} + +bool Player::canEquipNecklace() const { + return OTSYS_TIME() >= nextNecklaceAction; +} + +bool Player::canEquipRing() const { + return OTSYS_TIME() >= nextRingAction; +} + void Player::setNextPotionAction(int64_t time) { if (time > nextPotionAction) { nextPotionAction = time; diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 371048fbe9a..8f99f9d1821 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -945,6 +945,12 @@ class Player final : public Creature, public Cylinder, public Bankable { void setNextPotionAction(int64_t time); bool canDoPotionAction() const; + void setNextNecklaceAction(int64_t time); + bool canEquipNecklace() const; + + void setNextRingAction(int64_t time); + bool canEquipRing() const; + void setLoginProtection(int64_t time); bool isLoginProtected() const; void resetLoginProtection(); @@ -1426,6 +1432,8 @@ class Player final : public Creature, public Cylinder, public Bankable { int64_t lastPong; int64_t nextAction = 0; int64_t nextPotionAction = 0; + int64_t nextNecklaceAction = 0; + int64_t nextRingAction = 0; int64_t lastQuickLootNotification = 0; int64_t lastWalking = 0; int64_t loginProtectionTime = 0; diff --git a/src/game/game.cpp b/src/game/game.cpp index ee272442085..09fa4346773 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -3383,7 +3383,18 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = return; } - if (!player->canDoAction()) { + const ItemType &it = Item::items[itemId]; + Slots_t slot = getSlotType(it); + + if (slot == CONST_SLOT_NECKLACE) { + if (!player->canEquipNecklace()) { + return; + } + } else if (slot == CONST_SLOT_RING) { + if (!player->canEquipRing()) { + return; + } + } else if (!player->canDoAction()) { uint32_t delay = player->getNextActionTime() - OTSYS_TIME(); if (delay > 0) { const auto &task = createPlayerTask( @@ -3421,9 +3432,6 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = return; } - const ItemType &it = Item::items[itemId]; - Slots_t slot = getSlotType(it); - const auto &slotItem = player->getInventoryItem(slot); const auto &equipItem = searchForItem(backpack, it.id, hasTier, tier); ReturnValue ret = RETURNVALUE_NOERROR; @@ -3494,9 +3502,15 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = if (ret != RETURNVALUE_NOERROR) { player->sendCancelMessage(ret); + return; + } + if (slot == CONST_SLOT_NECKLACE) { + player->setNextNecklaceAction(OTSYS_TIME() + g_configManager().getNumber(ACTIONS_DELAY_INTERVAL)); + } else if (slot == CONST_SLOT_RING) { + player->setNextRingAction(OTSYS_TIME() + g_configManager().getNumber(ACTIONS_DELAY_INTERVAL)); + } else { + player->setNextAction(OTSYS_TIME() + g_configManager().getNumber(ACTIONS_DELAY_INTERVAL)); } - - player->setNextAction(OTSYS_TIME() + g_configManager().getNumber(ACTIONS_DELAY_INTERVAL)); } void Game::playerMove(uint32_t playerId, Direction direction) {