From f50096b501b896e6c38dd8f26a6ab7efcd8b0307 Mon Sep 17 00:00:00 2001 From: Anderson Faria Date: Sun, 17 Apr 2022 15:07:55 +0200 Subject: [PATCH] Quiver checking for ammunition level (#297) Description Added check for minReqLevel of ammunitions in quiver both for total count of arrow as well as to select which ammunition to use Actual behaviour Quiver ignore level requirement as stated in #77 Expected behaviour Quiver actually doesn't throw ammunitions which has higher level requirement than player level --- src/creatures/players/player.cpp | 8 +++++--- src/server/network/protocol/protocolgame.cpp | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 7cdc7974588..0e63baa92d5 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -242,9 +242,11 @@ Item* Player::getWeapon(Slots_t slot, bool ignoreAmmo) const bool found = false; for (Item* ammoItem : container->getItemList()) { if (ammoItem->getAmmoType() == it.ammoType) { - item = ammoItem; - found = true; - break; + if (level >= Item::items[ammoItem->getID()].minReqLevel) { + item = ammoItem; + found = true; + break; + } } } if (!found) diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 665b634555d..a475219b413 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -143,7 +143,9 @@ void ProtocolGame::AddItem(NetworkMessage &msg, const Item *item) if (container && item->getWeaponType() == WEAPON_QUIVER && player->getThing(CONST_SLOT_RIGHT) == item) { uint16_t ammoTotal = 0; for (Item* listItem : container->getItemList()) { - ammoTotal += listItem->getItemCount(); + if (player->getLevel() >= Item::items[listItem->getID()].minReqLevel) { + ammoTotal += listItem->getItemCount(); + } } msg.addByte(0x01); msg.add(ammoTotal);