Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: necklace/ring slots exhaustion #3272

Merged
merged 2 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 20 additions & 6 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Loading