Skip to content

Commit

Permalink
send cooldown to action bars when using items (#3823)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evil Puncker authored Dec 14, 2021
1 parent 7f78aff commit 5622d46
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ static void showUseHotkeyMessage(Player* player, const Item* item, uint32_t coun

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));
int32_t cooldown = g_config.getNumber(ConfigManager::ACTIONS_DELAY_INTERVAL);
player->setNextAction(OTSYS_TIME() + cooldown);
player->sendUseItemCooldown(cooldown);

if (isHotkey) {
uint16_t subType = item->getSubType();
Expand Down Expand Up @@ -454,7 +456,9 @@ bool Actions::useItem(Player* player, const Position& pos, uint8_t index, Item*
bool Actions::useItemEx(Player* player, const Position& fromPos, const Position& toPos,
uint8_t toStackPos, Item* item, bool isHotkey, Creature* creature/* = nullptr*/)
{
player->setNextAction(OTSYS_TIME() + g_config.getNumber(ConfigManager::EX_ACTIONS_DELAY_INTERVAL));
int32_t cooldown = g_config.getNumber(ConfigManager::EX_ACTIONS_DELAY_INTERVAL);
player->setNextAction(OTSYS_TIME() + cooldown);
player->sendUseItemCooldown(cooldown);

Action* action = getAction(item);
if (!action) {
Expand Down
5 changes: 5 additions & 0 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,11 @@ class Player final : public Creature, public Cylinder
client->sendSpellGroupCooldown(groupId, time);
}
}
void sendUseItemCooldown(uint32_t time) {
if (client) {
client->sendUseItemCooldown(time);
}
}
void sendModalWindow(const ModalWindow& modalWindow);

//container
Expand Down
8 changes: 8 additions & 0 deletions src/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3234,6 +3234,14 @@ void ProtocolGame::sendSpellGroupCooldown(SpellGroup_t groupId, uint32_t time)
writeToOutputBuffer(msg);
}

void ProtocolGame::sendUseItemCooldown(uint32_t time)
{
NetworkMessage msg;
msg.addByte(0xA6);
msg.add<uint32_t>(time);
writeToOutputBuffer(msg);
}

void ProtocolGame::sendModalWindow(const ModalWindow& modalWindow)
{
NetworkMessage msg;
Expand Down
1 change: 1 addition & 0 deletions src/protocolgame.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class ProtocolGame final : public Protocol

void sendSpellCooldown(uint8_t spellId, uint32_t time);
void sendSpellGroupCooldown(SpellGroup_t groupId, uint32_t time);
void sendUseItemCooldown(uint32_t time);

//tiles
void sendMapDescription(const Position& pos);
Expand Down

0 comments on commit 5622d46

Please sign in to comment.