Skip to content

Commit

Permalink
fix: necklace/ring slots exhaustion (#3272)
Browse files Browse the repository at this point in the history
This extends #3165 in the following manner:
I've separated necklace and ring slots in different groups, so the `ACTIONS_DELAY_INTERVAL` delay flag works on the groups separately. 
This means the exhaustion delay continues to be applied on equip items, but considering groups separately. In other words, the players are now able to equip necklaces and rings at the same time, but when trying to equip different necklaces (or rings) they are subject to `ACTIONS_DELAY_INTERVAL`.
samuelbfg authored Jan 26, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent ac4d9c8 commit 7b8a234
Showing 3 changed files with 48 additions and 6 deletions.
20 changes: 20 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 8 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
@@ -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;
26 changes: 20 additions & 6 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
@@ -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) {

0 comments on commit 7b8a234

Please sign in to comment.