feat: apply out-of-range red tint to ranged items on action bar

Extend the existing out-of-range check to cover ITEM slots whose
inventory type is Ranged (bow/gun/crossbow, 40 yd), RangedRight
(wand, 40 yd), or Thrown (30 yd). The check runs after barItemDef
is resolved so the inventory type is available.
This commit is contained in:
Kelsi 2026-03-17 13:59:42 -07:00
parent 5031351736
commit b23dbc9ab7

View file

@ -6713,6 +6713,7 @@ void GameScreen::renderActionBar(game::GameHandler& gameHandler) {
// Out-of-range check: red tint when a targeted spell cannot reach the current target. // Out-of-range check: red tint when a targeted spell cannot reach the current target.
// Only applies to SPELL slots with a known max range (>5 yd) and an active target. // Only applies to SPELL slots with a known max range (>5 yd) and an active target.
// Item range is checked below after barItemDef is populated.
bool outOfRange = false; bool outOfRange = false;
if (!slot.isEmpty() && slot.type == game::ActionBarSlot::SPELL && slot.id != 0 if (!slot.isEmpty() && slot.type == game::ActionBarSlot::SPELL && slot.id != 0
&& !onCooldown && gameHandler.hasTarget()) { && !onCooldown && gameHandler.hasTarget()) {
@ -6802,6 +6803,33 @@ void GameScreen::renderActionBar(game::GameHandler& gameHandler) {
const bool itemMissing = (slot.type == game::ActionBarSlot::ITEM && slot.id != 0 const bool itemMissing = (slot.type == game::ActionBarSlot::ITEM && slot.id != 0
&& barItemDef == nullptr && !onCooldown); && barItemDef == nullptr && !onCooldown);
// Ranged item out-of-range check (runs after barItemDef is populated above).
// invType 15=Ranged (bow/gun/crossbow), 26=Thrown, 28=RangedRight (wand/crossbow).
if (!outOfRange && slot.type == game::ActionBarSlot::ITEM && barItemDef
&& !onCooldown && gameHandler.hasTarget()) {
constexpr uint8_t INVTYPE_RANGED = 15;
constexpr uint8_t INVTYPE_THROWN = 26;
constexpr uint8_t INVTYPE_RANGEDRIGHT = 28;
uint32_t itemMaxRange = 0;
if (barItemDef->inventoryType == INVTYPE_RANGED ||
barItemDef->inventoryType == INVTYPE_RANGEDRIGHT)
itemMaxRange = 40;
else if (barItemDef->inventoryType == INVTYPE_THROWN)
itemMaxRange = 30;
if (itemMaxRange > 0) {
auto& em = gameHandler.getEntityManager();
auto playerEnt = em.getEntity(gameHandler.getPlayerGuid());
auto targetEnt = em.getEntity(gameHandler.getTargetGuid());
if (playerEnt && targetEnt) {
float dx = playerEnt->getX() - targetEnt->getX();
float dy = playerEnt->getY() - targetEnt->getY();
float dz = playerEnt->getZ() - targetEnt->getZ();
if (std::sqrt(dx*dx + dy*dy + dz*dz) > static_cast<float>(itemMaxRange))
outOfRange = true;
}
}
}
bool clicked = false; bool clicked = false;
if (iconTex) { if (iconTex) {
ImVec4 tintColor(1, 1, 1, 1); ImVec4 tintColor(1, 1, 1, 1);