mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-02-21 02:20:00 +01:00
Update EquipAction.cpp
This commit is contained in:
parent
f8da773ce1
commit
34c0759c90
@ -89,6 +89,8 @@ void EquipAction::EquipItem(Item* item)
|
|||||||
if (!equippedBag)
|
if (!equippedBag)
|
||||||
{
|
{
|
||||||
uint8 dstSlot = botAI->FindEquipSlot(itemProto, NULL_SLOT, true);
|
uint8 dstSlot = botAI->FindEquipSlot(itemProto, NULL_SLOT, true);
|
||||||
|
|
||||||
|
bool isWeapon = (itemProto->Class == ITEM_CLASS_WEAPON);
|
||||||
bool have2HWeapon = false;
|
bool have2HWeapon = false;
|
||||||
bool isValidTGWeapon = false;
|
bool isValidTGWeapon = false;
|
||||||
|
|
||||||
@ -105,15 +107,13 @@ void EquipAction::EquipItem(Item* item)
|
|||||||
have2HWeapon = currentWeapon && currentWeapon->GetTemplate()->InventoryType == INVTYPE_2HWEAPON;
|
have2HWeapon = currentWeapon && currentWeapon->GetTemplate()->InventoryType == INVTYPE_2HWEAPON;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isWeapon = (itemProto->Class == ITEM_CLASS_WEAPON);
|
|
||||||
bool canDualWieldOrTG = (bot->CanDualWield() || (bot->CanTitanGrip() && itemProto->InventoryType == INVTYPE_2HWEAPON));
|
bool canDualWieldOrTG = (bot->CanDualWield() || (bot->CanTitanGrip() && itemProto->InventoryType == INVTYPE_2HWEAPON));
|
||||||
|
|
||||||
// Perform best-weapon logic if this is a weapon and the bot can dual wield or Titan Grip
|
// Run best-weapon logic only if it's a weapon and can dual wield or Titan Grip.
|
||||||
if (isWeapon && canDualWieldOrTG &&
|
// Remove conditions that previously restricted running this logic based on dstSlot.
|
||||||
((itemProto->InventoryType != INVTYPE_2HWEAPON && !have2HWeapon) ||
|
// We'll always check if this new weapon is better, and then decide final slot.
|
||||||
(bot->CanTitanGrip() && isValidTGWeapon)))
|
if (isWeapon && canDualWieldOrTG)
|
||||||
{
|
{
|
||||||
// Compare new item to mainhand and offhand regardless of initial dstSlot
|
|
||||||
Item* mainHandItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND);
|
Item* mainHandItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND);
|
||||||
Item* offHandItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND);
|
Item* offHandItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND);
|
||||||
|
|
||||||
@ -125,9 +125,6 @@ void EquipAction::EquipItem(Item* item)
|
|||||||
float mainHandScore = mainHandItem ? calculator.CalculateItem(mainHandItem->GetTemplate()->ItemId) : 0.0f;
|
float mainHandScore = mainHandItem ? calculator.CalculateItem(mainHandItem->GetTemplate()->ItemId) : 0.0f;
|
||||||
float offHandScore = offHandItem ? calculator.CalculateItem(offHandItem->GetTemplate()->ItemId) : 0.0f;
|
float offHandScore = offHandItem ? calculator.CalculateItem(offHandItem->GetTemplate()->ItemId) : 0.0f;
|
||||||
|
|
||||||
bool newIsBest = (newItemScore > mainHandScore && newItemScore > offHandScore);
|
|
||||||
bool betterThanOff = (newItemScore > offHandScore) && !newIsBest;
|
|
||||||
|
|
||||||
bool canGoMain = (itemProto->InventoryType == INVTYPE_WEAPON ||
|
bool canGoMain = (itemProto->InventoryType == INVTYPE_WEAPON ||
|
||||||
itemProto->InventoryType == INVTYPE_WEAPONMAINHAND ||
|
itemProto->InventoryType == INVTYPE_WEAPONMAINHAND ||
|
||||||
(bot->CanTitanGrip() && itemProto->InventoryType == INVTYPE_2HWEAPON));
|
(bot->CanTitanGrip() && itemProto->InventoryType == INVTYPE_2HWEAPON));
|
||||||
@ -135,7 +132,6 @@ void EquipAction::EquipItem(Item* item)
|
|||||||
bool canTGOff = false;
|
bool canTGOff = false;
|
||||||
if (bot->CanTitanGrip() && itemProto->InventoryType == INVTYPE_2HWEAPON)
|
if (bot->CanTitanGrip() && itemProto->InventoryType == INVTYPE_2HWEAPON)
|
||||||
{
|
{
|
||||||
// Titan Grip allows certain 2H weapons in offhand
|
|
||||||
canTGOff = isValidTGWeapon;
|
canTGOff = isValidTGWeapon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,12 +153,11 @@ void EquipAction::EquipItem(Item* item)
|
|||||||
(mhProto->InventoryType == INVTYPE_2HWEAPON && mhIsValidTG));
|
(mhProto->InventoryType == INVTYPE_2HWEAPON && mhIsValidTG));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decide final equip slot based on comparison
|
// First priority: If new weapon is better than main hand and can be equipped in main hand,
|
||||||
if (newIsBest && canGoMain)
|
// do that.
|
||||||
|
if (canGoMain && newItemScore > mainHandScore &&
|
||||||
|
((itemProto->InventoryType != INVTYPE_2HWEAPON && !have2HWeapon) || (bot->CanTitanGrip() && isValidTGWeapon)))
|
||||||
{
|
{
|
||||||
// Equip in main hand
|
|
||||||
dstSlot = EQUIPMENT_SLOT_MAINHAND;
|
|
||||||
|
|
||||||
// Equip new weapon in main hand
|
// Equip new weapon in main hand
|
||||||
{
|
{
|
||||||
WorldPacket eqPacket(CMSG_AUTOEQUIP_ITEM_SLOT, 2);
|
WorldPacket eqPacket(CMSG_AUTOEQUIP_ITEM_SLOT, 2);
|
||||||
@ -171,48 +166,43 @@ void EquipAction::EquipItem(Item* item)
|
|||||||
bot->GetSession()->HandleAutoEquipItemSlotOpcode(eqPacket);
|
bot->GetSession()->HandleAutoEquipItemSlotOpcode(eqPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there was a main hand item, try to move it to offhand if it improves offhand
|
// If we had a main hand item, consider moving it to offhand if beneficial
|
||||||
if (mainHandItem && mainHandCanGoOff)
|
if (mainHandItem && mainHandCanGoOff &&
|
||||||
|
(!offHandItem || mainHandScore > offHandScore))
|
||||||
{
|
{
|
||||||
if (!offHandItem || mainHandScore > offHandScore)
|
WorldPacket offhandPacket(CMSG_AUTOEQUIP_ITEM_SLOT, 2);
|
||||||
{
|
ObjectGuid oldMHGuid = mainHandItem->GetGUID();
|
||||||
WorldPacket offhandPacket(CMSG_AUTOEQUIP_ITEM_SLOT, 2);
|
offhandPacket << oldMHGuid << uint8(EQUIPMENT_SLOT_OFFHAND);
|
||||||
ObjectGuid oldMHGuid = mainHandItem->GetGUID();
|
bot->GetSession()->HandleAutoEquipItemSlotOpcode(offhandPacket);
|
||||||
offhandPacket << oldMHGuid << uint8(EQUIPMENT_SLOT_OFFHAND);
|
|
||||||
bot->GetSession()->HandleAutoEquipItemSlotOpcode(offhandPacket);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << "equipping " << chat->FormatItem(itemProto) << " as the best weapon in main hand";
|
out << "equipping " << chat->FormatItem(itemProto) << " in main hand as an upgrade";
|
||||||
botAI->TellMaster(out);
|
botAI->TellMaster(out);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (betterThanOff && canGoOff)
|
// If not better than main hand, check if it's better than offhand
|
||||||
|
else if (canGoOff && newItemScore > offHandScore)
|
||||||
{
|
{
|
||||||
// Equip in offhand
|
// Equip in offhand
|
||||||
dstSlot = EQUIPMENT_SLOT_OFFHAND;
|
|
||||||
|
|
||||||
WorldPacket eqPacket(CMSG_AUTOEQUIP_ITEM_SLOT, 2);
|
WorldPacket eqPacket(CMSG_AUTOEQUIP_ITEM_SLOT, 2);
|
||||||
ObjectGuid newItemGuid = item->GetGUID();
|
ObjectGuid newItemGuid = item->GetGUID();
|
||||||
eqPacket << newItemGuid << uint8(EQUIPMENT_SLOT_OFFHAND);
|
eqPacket << newItemGuid << uint8(EQUIPMENT_SLOT_OFFHAND);
|
||||||
bot->GetSession()->HandleAutoEquipItemSlotOpcode(eqPacket);
|
bot->GetSession()->HandleAutoEquipItemSlotOpcode(eqPacket);
|
||||||
|
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << "equipping " << chat->FormatItem(itemProto) << " in offhand";
|
out << "equipping " << chat->FormatItem(itemProto) << " in offhand as an upgrade";
|
||||||
botAI->TellMaster(out);
|
botAI->TellMaster(out);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Not an improvement, do nothing and return
|
// No improvement, do nothing
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we reach here, either not a dual-wield scenario, not a better weapon scenario,
|
// If not a special dual-wield/TG scenario or no improvement found, fall back to original logic
|
||||||
// or the item isn't a weapon. Fall back to existing logic.
|
|
||||||
|
|
||||||
if (dstSlot == EQUIPMENT_SLOT_FINGER1 ||
|
if (dstSlot == EQUIPMENT_SLOT_FINGER1 ||
|
||||||
dstSlot == EQUIPMENT_SLOT_TRINKET1 ||
|
dstSlot == EQUIPMENT_SLOT_TRINKET1 ||
|
||||||
(dstSlot == EQUIPMENT_SLOT_MAINHAND && bot->CanDualWield() &&
|
(dstSlot == EQUIPMENT_SLOT_MAINHAND && bot->CanDualWield() &&
|
||||||
@ -233,8 +223,8 @@ void EquipAction::EquipItem(Item* item)
|
|||||||
calculator.SetOverflowPenalty(false);
|
calculator.SetOverflowPenalty(false);
|
||||||
|
|
||||||
float equippedItemScore[2] = {
|
float equippedItemScore[2] = {
|
||||||
equippedItemScore[0] = calculator.CalculateItem(equippedItems[0]->GetTemplate()->ItemId),
|
calculator.CalculateItem(equippedItems[0]->GetTemplate()->ItemId),
|
||||||
equippedItemScore[1] = calculator.CalculateItem(equippedItems[1]->GetTemplate()->ItemId)
|
calculator.CalculateItem(equippedItems[1]->GetTemplate()->ItemId)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Second item is worse than first, equip candidate item in second slot
|
// Second item is worse than first, equip candidate item in second slot
|
||||||
@ -243,14 +233,14 @@ void EquipAction::EquipItem(Item* item)
|
|||||||
dstSlot++;
|
dstSlot++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // No item equipped in slot 2, equip in that slot
|
else
|
||||||
{
|
{
|
||||||
|
// No item in second slot, equip there
|
||||||
dstSlot++;
|
dstSlot++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the final equip if no special logic applied
|
|
||||||
WorldPacket packet(CMSG_AUTOEQUIP_ITEM_SLOT, 2);
|
WorldPacket packet(CMSG_AUTOEQUIP_ITEM_SLOT, 2);
|
||||||
ObjectGuid itemguid = item->GetGUID();
|
ObjectGuid itemguid = item->GetGUID();
|
||||||
packet << itemguid << dstSlot;
|
packet << itemguid << dstSlot;
|
||||||
@ -263,7 +253,6 @@ void EquipAction::EquipItem(Item* item)
|
|||||||
botAI->TellMaster(out);
|
botAI->TellMaster(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EquipUpgradesAction::Execute(Event event)
|
bool EquipUpgradesAction::Execute(Event event)
|
||||||
{
|
{
|
||||||
if (!sPlayerbotAIConfig->autoEquipUpgradeLoot && !sRandomPlayerbotMgr->IsRandomBot(bot))
|
if (!sPlayerbotAIConfig->autoEquipUpgradeLoot && !sRandomPlayerbotMgr->IsRandomBot(bot))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user