Rogue bots can unlock items in their bags and in the trade window (#1055)

This commit is contained in:
avirar
2025-03-18 01:10:33 +11:00
committed by GitHub
parent c93bf38463
commit c4a4d3a9e6
18 changed files with 437 additions and 57 deletions

View File

@@ -75,6 +75,8 @@
#include "WhoAction.h"
#include "WtsAction.h"
#include "OpenItemAction.h"
#include "UnlockItemAction.h"
#include "UnlockTradedItemAction.h"
class ChatActionContext : public NamedObjectContext<Action>
{
@@ -82,6 +84,8 @@ public:
ChatActionContext()
{
creators["open items"] = &ChatActionContext::open_items;
creators["unlock items"] = &ChatActionContext::unlock_items;
creators["unlock traded item"] = &ChatActionContext::unlock_traded_item;
creators["range"] = &ChatActionContext::range;
creators["stats"] = &ChatActionContext::stats;
creators["quests"] = &ChatActionContext::quests;
@@ -184,6 +188,8 @@ public:
private:
static Action* open_items(PlayerbotAI* botAI) { return new OpenItemAction(botAI); }
static Action* unlock_items(PlayerbotAI* botAI) { return new UnlockItemAction(botAI); }
static Action* unlock_traded_item(PlayerbotAI* botAI) { return new UnlockTradedItemAction(botAI); }
static Action* range(PlayerbotAI* botAI) { return new RangeAction(botAI); }
static Action* flag(PlayerbotAI* botAI) { return new FlagAction(botAI); }
static Action* craft(PlayerbotAI* botAI) { return new SetCraftAction(botAI); }

View File

@@ -4,64 +4,23 @@
#include "WorldPacket.h"
#include "Player.h"
#include "ObjectMgr.h"
bool OpenItemAction::Execute(Event event)
{
bool foundOpenable = false;
// Check main inventory slots
for (uint8 slot = EQUIPMENT_SLOT_START; slot < INVENTORY_SLOT_ITEM_END; ++slot)
Item* item = botAI->FindOpenableItem();
if (item)
{
Item* item = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
uint8 bag = item->GetBagSlot(); // Retrieves the bag slot (0 for main inventory)
uint8 slot = item->GetSlot(); // Retrieves the actual slot inside the bag
if (item && CanOpenItem(item))
{
OpenItem(item, INVENTORY_SLOT_BAG_0, slot);
foundOpenable = true;
}
}
// Check items in the bags
for (uint8 bag = INVENTORY_SLOT_BAG_START; bag < INVENTORY_SLOT_BAG_END; ++bag)
{
Bag* bagItem = bot->GetBagByPos(bag);
if (!bagItem)
continue;
for (uint32 slot = 0; slot < bagItem->GetBagSize(); ++slot)
{
Item* item = bot->GetItemByPos(bag, slot);
if (item && CanOpenItem(item))
{
OpenItem(item, bag, slot);
foundOpenable = true;
}
}
}
// If no openable items found
if (!foundOpenable)
{
botAI->TellError("No openable items in inventory.");
OpenItem(item, bag, slot);
foundOpenable = true;
}
return foundOpenable;
}
bool OpenItemAction::CanOpenItem(Item* item)
{
if (!item)
return false;
ItemTemplate const* itemTemplate = item->GetTemplate();
if (!itemTemplate)
return false;
// Check if the item has the openable flag
return itemTemplate->Flags & ITEM_FLAG_HAS_LOOT;
}
void OpenItemAction::OpenItem(Item* item, uint8 bag, uint8 slot)
{
WorldPacket packet(CMSG_OPEN_ITEM);

View File

@@ -21,9 +21,6 @@ public:
bool Execute(Event event) override;
private:
// Checks if the given item can be opened (i.e., has the openable flag)
bool CanOpenItem(Item* item);
// Performs the action of opening the item
void OpenItem(Item* item, uint8 bag, uint8 slot);
};

View File

@@ -24,12 +24,17 @@ bool TradeStatusAction::Execute(Event event)
return false;
PlayerbotAI* traderBotAI = GET_PLAYERBOT_AI(trader);
if (trader != master && !traderBotAI)
// Allow the master and group members to trade
if (trader != master && !traderBotAI && (!bot->GetGroup() || !bot->GetGroup()->IsMember(trader->GetGUID())))
{
bot->Whisper("I'm kind of busy now", LANG_UNIVERSAL, trader);
return false;
}
if ((trader != master || !botAI->GetSecurity()->CheckLevelFor(PLAYERBOT_SECURITY_ALLOW_ALL, true, master)) &&
// Allow trades from group members or bots
if ((!bot->GetGroup() || !bot->GetGroup()->IsMember(trader->GetGUID())) &&
(trader != master || !botAI->GetSecurity()->CheckLevelFor(PLAYERBOT_SECURITY_ALLOW_ALL, true, master)) &&
!traderBotAI)
{
WorldPacket p;
@@ -109,9 +114,9 @@ bool TradeStatusAction::Execute(Event event)
bot->SetFacingToObject(trader);
BeginTrade();
return true;
}
return false;
}

View File

@@ -0,0 +1,84 @@
#include "TradeStatusExtendedAction.h"
#include "Event.h"
#include "Player.h"
#include "PlayerbotAI.h"
#include "WorldPacket.h"
#include "TradeData.h"
bool TradeStatusExtendedAction::Execute(Event event)
{
Player* trader = bot->GetTrader();
if (!trader)
return false;
TradeData* tradeData = trader->GetTradeData();
if (!tradeData)
return false;
WorldPacket p(event.getPacket());
p.rpos(0);
uint8 isTraderData;
uint32 unknown1, slotCount1, slotCount2, tradeGold, spellCast;
p >> isTraderData;
p >> unknown1;
p >> slotCount1;
p >> slotCount2;
p >> tradeGold;
p >> spellCast;
for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
{
uint8 tradeSlot;
p >> tradeSlot;
if (tradeSlot >= TRADE_SLOT_COUNT)
break; // End of packet
uint32 itemId, displayId, count, wrapped, lockId;
uint64 giftCreator, creator;
uint32 permEnchant, gem1, gem2, gem3;
uint32 spellCharges, suffixFactor, randomProp, maxDurability, durability;
p >> itemId;
p >> displayId;
p >> count;
p >> wrapped;
p >> giftCreator;
p >> permEnchant;
p >> gem1;
p >> gem2;
p >> gem3;
p >> creator;
p >> spellCharges;
p >> suffixFactor;
p >> randomProp;
p >> lockId;
p >> maxDurability;
p >> durability;
// Check for locked items in "Do Not Trade" slot
if (tradeSlot == TRADE_SLOT_NONTRADED && lockId > 0)
{
// Get the actual item reference from TradeData
Item* lockbox = tradeData->GetItem(TRADE_SLOT_NONTRADED);
if (!lockbox)
{
return false;
}
if (bot->getClass() == CLASS_ROGUE && bot->HasSpell(1804) && lockbox->IsLocked()) // Pick Lock spell
{
// botAI->CastSpell(1804, bot, lockbox); // Attempt to cast Pick Lock on the lockbox
botAI->DoSpecificAction("unlock traded item");
botAI->SetNextCheckDelay(4000); // Delay before accepting trade
}
else
{
botAI->TellMaster("I can't unlock this item.");
}
}
}
return true;
}

View File

@@ -0,0 +1,17 @@
#ifndef _PLAYERBOT_TRADESTATUSEXTENDEDACTION_H
#define _PLAYERBOT_TRADESTATUSEXTENDEDACTION_H
#include "QueryItemUsageAction.h"
class Player;
class PlayerbotAI;
class TradeStatusExtendedAction : public QueryItemUsageAction
{
public:
TradeStatusExtendedAction(PlayerbotAI* botAI) : QueryItemUsageAction(botAI, "trade status extended") {}
bool Execute(Event event) override;
};
#endif

View File

@@ -0,0 +1,38 @@
#include "UnlockItemAction.h"
#include "PlayerbotAI.h"
#include "ItemTemplate.h"
#include "WorldPacket.h"
#include "Player.h"
#include "ObjectMgr.h"
#include "SpellInfo.h"
#define PICK_LOCK_SPELL_ID 1804
bool UnlockItemAction::Execute(Event event)
{
bool foundLockedItem = false;
Item* item = botAI->FindLockedItem();
if (item)
{
UnlockItem(item);
foundLockedItem = true;
}
return foundLockedItem;
}
void UnlockItemAction::UnlockItem(Item* item)
{
// Use CastSpell to unlock the item
if (botAI->CastSpell(PICK_LOCK_SPELL_ID, bot, item))
{
std::ostringstream out;
out << "Used Pick Lock on: " << item->GetTemplate()->Name1;
botAI->TellMaster(out.str());
}
else
{
botAI->TellError("Failed to cast Pick Lock.");
}
}

View File

@@ -0,0 +1,19 @@
#ifndef _PLAYERBOT_UNLOCKITEMACTION_H
#define _PLAYERBOT_UNLOCKITEMACTION_H
#include "Action.h"
class PlayerbotAI;
class UnlockItemAction : public Action
{
public:
UnlockItemAction(PlayerbotAI* botAI) : Action(botAI, "unlock item") { }
bool Execute(Event event) override;
private:
void UnlockItem(Item* item);
};
#endif

View File

@@ -0,0 +1,98 @@
#include "UnlockTradedItemAction.h"
#include "Playerbots.h"
#include "TradeData.h"
#include "SpellInfo.h"
#define PICK_LOCK_SPELL_ID 1804
bool UnlockTradedItemAction::Execute(Event event)
{
Player* trader = bot->GetTrader();
if (!trader)
return false; // No active trade session
TradeData* tradeData = trader->GetTradeData();
if (!tradeData)
return false; // No trade data available
Item* lockbox = tradeData->GetItem(TRADE_SLOT_NONTRADED);
if (!lockbox)
{
botAI->TellError("No item in the Do Not Trade slot.");
return false;
}
if (!CanUnlockItem(lockbox))
{
botAI->TellError("Cannot unlock this item.");
return false;
}
UnlockItem(lockbox);
return true;
}
bool UnlockTradedItemAction::CanUnlockItem(Item* item)
{
if (!item)
return false;
ItemTemplate const* itemTemplate = item->GetTemplate();
if (!itemTemplate)
return false;
// Ensure the bot is a rogue and has Lockpicking skill
if (bot->getClass() != CLASS_ROGUE || !botAI->HasSkill(SKILL_LOCKPICKING))
return false;
// Ensure the item is actually locked
if (itemTemplate->LockID == 0 || !item->IsLocked())
return false;
// Check if the bot's Lockpicking skill is high enough
uint32 lockId = itemTemplate->LockID;
LockEntry const* lockInfo = sLockStore.LookupEntry(lockId);
if (!lockInfo)
return false;
uint32 botSkill = bot->GetSkillValue(SKILL_LOCKPICKING);
for (uint8 j = 0; j < 8; ++j)
{
if (lockInfo->Type[j] == LOCK_KEY_SKILL && SkillByLockType(LockType(lockInfo->Index[j])) == SKILL_LOCKPICKING)
{
uint32 requiredSkill = lockInfo->Skill[j];
if (botSkill >= requiredSkill)
return true;
else
{
std::ostringstream out;
out << "Lockpicking skill too low (" << botSkill << "/" << requiredSkill << ") to unlock: "
<< item->GetTemplate()->Name1;
botAI->TellMaster(out.str());
}
}
}
return false;
}
void UnlockTradedItemAction::UnlockItem(Item* item)
{
if (!bot->HasSpell(PICK_LOCK_SPELL_ID))
{
botAI->TellError("Cannot unlock, Pick Lock spell is missing.");
return;
}
// Use CastSpell to unlock the item
if (botAI->CastSpell(PICK_LOCK_SPELL_ID, bot->GetTrader(), item)) // Unit target is trader
{
std::ostringstream out;
out << "Picking Lock on traded item: " << item->GetTemplate()->Name1;
botAI->TellMaster(out.str());
}
else
{
botAI->TellError("Failed to cast Pick Lock.");
}
}

View File

@@ -0,0 +1,20 @@
#ifndef _PLAYERBOT_UNLOCKTRADEDITEMACTION_H
#define _PLAYERBOT_UNLOCKTRADEDITEMACTION_H
#include "Action.h"
class PlayerbotAI;
class UnlockTradedItemAction : public Action
{
public:
UnlockTradedItemAction(PlayerbotAI* botAI) : Action(botAI, "unlock traded item") {}
bool Execute(Event event) override;
private:
bool CanUnlockItem(Item* item);
void UnlockItem(Item* item);
};
#endif

View File

@@ -37,6 +37,7 @@
#include "TellCastFailedAction.h"
#include "TellMasterAction.h"
#include "TradeStatusAction.h"
#include "TradeStatusExtendedAction.h"
#include "UseMeetingStoneAction.h"
#include "NamedObjectContext.h"
@@ -65,6 +66,7 @@ public:
creators["check mount state"] = &WorldPacketActionContext::check_mount_state;
creators["remember taxi"] = &WorldPacketActionContext::remember_taxi;
creators["accept trade"] = &WorldPacketActionContext::accept_trade;
creators["trade status extended"] = &WorldPacketActionContext::trade_status_extended;
creators["store loot"] = &WorldPacketActionContext::store_loot;
// quest
@@ -118,6 +120,7 @@ private:
static Action* party_command(PlayerbotAI* botAI) { return new PartyCommandAction(botAI); }
static Action* store_loot(PlayerbotAI* botAI) { return new StoreLootAction(botAI); }
static Action* accept_trade(PlayerbotAI* botAI) { return new TradeStatusAction(botAI); }
static Action* trade_status_extended(PlayerbotAI* botAI) { return new TradeStatusExtendedAction(botAI); }
static Action* remember_taxi(PlayerbotAI* botAI) { return new RememberTaxiAction(botAI); }
static Action* check_mount_state(PlayerbotAI* botAI) { return new CheckMountStateAction(botAI); }
static Action* area_trigger(PlayerbotAI* botAI) { return new AreaTriggerAction(botAI); }