Skip to content

Commit

Permalink
Merge pull request liyunfan1223#618 from avirar/armor_token_usage
Browse files Browse the repository at this point in the history
Armor token usage
  • Loading branch information
liyunfan1223 authored Oct 21, 2024
2 parents 0596154 + a3101cc commit 47544bf
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
67 changes: 49 additions & 18 deletions src/strategy/actions/LootRollAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,39 @@ bool LootRollAction::Execute(Event event)
if (!proto)
continue;
ItemUsage usage = AI_VALUE2(ItemUsage, "item usage", itemId);
switch (proto->Class)

// Armor Tokens are classed as MISC JUNK (Class 15, Subclass 0), luckily no other items I found have class bits and epic quality.
if (proto->Class == ITEM_CLASS_MISC && proto->SubClass == ITEM_SUBCLASS_JUNK && proto->Quality == ITEM_QUALITY_EPIC)
{
case ITEM_CLASS_WEAPON:
case ITEM_CLASS_ARMOR:
if (usage == ITEM_USAGE_EQUIP || usage == ITEM_USAGE_REPLACE || usage == ITEM_USAGE_BAD_EQUIP)
{
vote = NEED;
}
else if (usage != ITEM_USAGE_NONE)
{
vote = GREED;
}
break;
default:
if (StoreLootAction::IsLootAllowed(itemId, botAI))
vote = NEED;
break;
if (CanBotUseToken(proto, bot))
{
vote = NEED; // Eligible for "Need"
}
else
{
vote = GREED; // Not eligible, so "Greed"
}
}
else
{
switch (proto->Class)
{
case ITEM_CLASS_WEAPON:
case ITEM_CLASS_ARMOR:
if (usage == ITEM_USAGE_EQUIP || usage == ITEM_USAGE_REPLACE || usage == ITEM_USAGE_BAD_EQUIP)
{
vote = NEED;
}
else if (usage != ITEM_USAGE_NONE)
{
vote = GREED;
}
break;
default:
if (StoreLootAction::IsLootAllowed(itemId, botAI))
vote = NEED;
break;
}
}
if (sPlayerbotAIConfig->lootRollLevel == 0)
{
Expand Down Expand Up @@ -80,6 +96,7 @@ bool LootRollAction::Execute(Event event)
break;
}
}

// WorldPacket p(event.getPacket()); //WorldPacket packet for CMSG_LOOT_ROLL, (8+4+1)
// p.rpos(0); //reset packet pointer
// p >> guid; //guid of the item rolled
Expand Down Expand Up @@ -132,10 +149,10 @@ bool LootRollAction::Execute(Event event)
// break;
// }
// }

return true;
}


RollVote LootRollAction::CalculateRollVote(ItemTemplate const* proto)
{
std::ostringstream out;
Expand Down Expand Up @@ -165,7 +182,7 @@ RollVote LootRollAction::CalculateRollVote(ItemTemplate const* proto)
return StoreLootAction::IsLootAllowed(proto->ItemId, GET_PLAYERBOT_AI(bot)) ? needVote : PASS;
}

bool MasterLootRollAction::isUseful() { return !botAI->HasActivePlayerMaster(); };
bool MasterLootRollAction::isUseful() { return !botAI->HasActivePlayerMaster(); }

bool MasterLootRollAction::Execute(Event event)
{
Expand Down Expand Up @@ -204,3 +221,17 @@ bool MasterLootRollAction::Execute(Event event)

return true;
}

bool CanBotUseToken(ItemTemplate const* proto, Player* bot)
{
// Get the bitmask for the bot's class
uint32 botClassMask = (1 << (bot->getClass() - 1));

// Check if the bot's class is allowed to use the token
if (proto->AllowableClass & botClassMask)
{
return true; // Bot's class is eligible to use this token
}

return false; // Bot's class cannot use this token
}
2 changes: 2 additions & 0 deletions src/strategy/actions/LootRollAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class LootRollAction : public QueryItemUsageAction
RollVote CalculateRollVote(ItemTemplate const* proto);
};

bool CanBotUseToken(ItemTemplate const* proto, Player* bot);

class MasterLootRollAction : public LootRollAction
{
public:
Expand Down

0 comments on commit 47544bf

Please sign in to comment.