mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Item usage and equip initialization
This commit is contained in:
@@ -845,6 +845,22 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
|
||||
|
||||
if (!strncmp(cmd, "initself=", 9))
|
||||
{
|
||||
if (!strcmp(cmd, "initself=uncommon"))
|
||||
{
|
||||
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
|
||||
{
|
||||
// OnBotLogin(master);
|
||||
PlayerbotFactory factory(master, master->GetLevel(), ITEM_QUALITY_UNCOMMON);
|
||||
factory.Randomize(false);
|
||||
messages.push_back("initself ok");
|
||||
return messages;
|
||||
}
|
||||
else
|
||||
{
|
||||
messages.push_back("ERROR: Only GM can use this command.");
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
if (!strcmp(cmd, "initself=rare"))
|
||||
{
|
||||
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
|
||||
@@ -877,6 +893,22 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
if (!strcmp(cmd, "initself=legendary"))
|
||||
{
|
||||
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
|
||||
{
|
||||
// OnBotLogin(master);
|
||||
PlayerbotFactory factory(master, master->GetLevel(), ITEM_QUALITY_LEGENDARY);
|
||||
factory.Randomize(false);
|
||||
messages.push_back("initself ok");
|
||||
return messages;
|
||||
}
|
||||
else
|
||||
{
|
||||
messages.push_back("ERROR: Only GM can use this command.");
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
int32 gs;
|
||||
if (sscanf(cmd, "initself=%d", &gs) != -1)
|
||||
{
|
||||
|
||||
@@ -614,7 +614,6 @@ void PlayerbotFactory::InitPetTalents()
|
||||
}
|
||||
std::unordered_map<uint32, std::vector<TalentEntry const*>> spells;
|
||||
bool diveTypePet = (1LL << ci->family) & diveMask;
|
||||
LOG_INFO("playerbots", "DIVEMASK:{}", diveMask);
|
||||
|
||||
for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
|
||||
{
|
||||
@@ -1513,7 +1512,7 @@ void Shuffle(std::vector<uint32>& items)
|
||||
// }
|
||||
// }
|
||||
|
||||
void PlayerbotFactory::InitEquipment(bool incremental)
|
||||
void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance)
|
||||
{
|
||||
std::unordered_map<uint8, std::vector<uint32>> items;
|
||||
// int tab = AiFactory::GetPlayerSpecTab(bot);
|
||||
@@ -1553,16 +1552,13 @@ void PlayerbotFactory::InitEquipment(bool incremental)
|
||||
|
||||
Item* oldItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
|
||||
|
||||
if (!incremental && oldItem)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (oldItem)
|
||||
if (second_chance && oldItem)
|
||||
{
|
||||
bot->DestroyItem(INVENTORY_SLOT_BAG_0, slot, true);
|
||||
}
|
||||
|
||||
oldItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
|
||||
|
||||
uint32 desiredQuality = itemQuality;
|
||||
if (urand(0, 100) < 100 * sPlayerbotAIConfig->randomGearLoweringChance && desiredQuality > ITEM_QUALITY_NORMAL)
|
||||
{
|
||||
@@ -1668,17 +1664,38 @@ void PlayerbotFactory::InitEquipment(bool incremental)
|
||||
bestItemForSlot = newItemId;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestItemForSlot == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
uint16 dest;
|
||||
if (!CanEquipUnseenItem(slot, dest, bestItemForSlot))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (incremental && oldItem)
|
||||
{
|
||||
float old_score = calculator.CalculateItem(oldItem->GetEntry());
|
||||
if (bestScoreForSlot < 1.2f * old_score)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (oldItem)
|
||||
{
|
||||
uint8 bagIndex = oldItem->GetBagSlot();
|
||||
uint8 slot = oldItem->GetSlot();
|
||||
uint8 dstBag = NULL_BAG;
|
||||
|
||||
WorldPacket packet(CMSG_AUTOSTORE_BAG_ITEM, 3);
|
||||
packet << bagIndex << slot << dstBag;
|
||||
bot->GetSession()->HandleAutoStoreBagItemOpcode(packet);
|
||||
}
|
||||
|
||||
Item* newItem = bot->EquipNewItem(dest, bestItemForSlot, true);
|
||||
bot->AutoUnequipOffhandIfNeed();
|
||||
// bot->AutoUnequipOffhandIfNeed();
|
||||
if (newItem)
|
||||
{
|
||||
newItem->AddToWorld();
|
||||
@@ -1686,25 +1703,10 @@ void PlayerbotFactory::InitEquipment(bool incremental)
|
||||
}
|
||||
}
|
||||
// secondary init for better equips
|
||||
if (!incremental)
|
||||
InitEquipment(true);
|
||||
|
||||
// for (uint8 slot = 0; slot < EQUIPMENT_SLOT_END; ++slot)
|
||||
// {
|
||||
// if (slot == EQUIPMENT_SLOT_TABARD || slot == EQUIPMENT_SLOT_BODY)
|
||||
// continue;
|
||||
|
||||
// if (level < 40 && (slot == EQUIPMENT_SLOT_TRINKET1 || slot == EQUIPMENT_SLOT_TRINKET2))
|
||||
// continue;
|
||||
|
||||
// if (level < 25 && slot == EQUIPMENT_SLOT_NECK)
|
||||
// continue;
|
||||
|
||||
// if (level < 25 && slot == EQUIPMENT_SLOT_HEAD)
|
||||
// continue;
|
||||
if (!incremental && !second_chance)
|
||||
InitEquipment(incremental, true);
|
||||
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
bool PlayerbotFactory::IsDesiredReplacement(Item* item)
|
||||
@@ -1978,7 +1980,7 @@ bool PlayerbotFactory::CanEquipUnseenItem(uint8 slot, uint16& dest, uint32 item)
|
||||
|
||||
if (Item* pItem = Item::CreateItem(item, 1, bot, false, 0, true))
|
||||
{
|
||||
InventoryResult result = bot->CanEquipItem(slot, dest, pItem, true, false);
|
||||
InventoryResult result = botAI->CanEquipItem(slot, dest, pItem, true, true);
|
||||
pItem->RemoveFromUpdateQueueOf(bot);
|
||||
delete pItem;
|
||||
return result == EQUIP_ERR_OK;
|
||||
|
||||
@@ -122,7 +122,7 @@ public:
|
||||
static void InitTalentsByParsedSpecLink(Player* bot, std::vector<std::vector<uint32>> parsedSpecLink, bool reset);
|
||||
void InitAvailableSpells();
|
||||
void InitClassSpells();
|
||||
void InitEquipment(bool incremental);
|
||||
void InitEquipment(bool incremental, bool second_chance = false);
|
||||
void InitPet();
|
||||
void InitAmmo();
|
||||
static uint32 CalcMixedGearScore(uint32 gs, uint32 quality);
|
||||
|
||||
@@ -166,7 +166,7 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto)
|
||||
return ITEM_USAGE_NONE;
|
||||
|
||||
uint16 dest;
|
||||
InventoryResult result = botAI->CanEquipItem(NULL_SLOT, dest, pItem, true, false);
|
||||
InventoryResult result = botAI->CanEquipItem(NULL_SLOT, dest, pItem, true, true);
|
||||
pItem->RemoveFromUpdateQueueOf(bot);
|
||||
delete pItem;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user