Skip to content

Commit

Permalink
enchant template, use consumables
Browse files Browse the repository at this point in the history
  • Loading branch information
Lidocian committed Jan 22, 2019
1 parent e9b2b8f commit c87e382
Show file tree
Hide file tree
Showing 9 changed files with 645 additions and 75 deletions.
109 changes: 108 additions & 1 deletion playerbot/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,25 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, uint8 effectMask, b
}
}

uint8 PlayerbotAI::GetHealthPercent(const Unit& target) const
{
return (static_cast<float>(target.GetHealth()) / target.GetMaxHealth()) * 100;
}

uint8 PlayerbotAI::GetHealthPercent() const
{
return GetHealthPercent(*bot);
}

uint8 PlayerbotAI::GetManaPercent(const Unit& target) const
{
return (static_cast<float>(target.GetPower(POWER_MANA)) / target.GetMaxPower(POWER_MANA)) * 100;
}

uint8 PlayerbotAI::GetManaPercent() const
{
return GetManaPercent(*bot);
}

bool PlayerbotAI::CastSpell(string name, Unit* target, Item* itemTarget)
{
Expand Down Expand Up @@ -1624,6 +1643,46 @@ Item* PlayerbotAI::FindConsumable(uint32 displayId) const
return NULL;
}

Item* PlayerbotAI::FindBandage() const
{
// list out items in main backpack
for (uint8 slot = INVENTORY_SLOT_ITEM_START; slot < INVENTORY_SLOT_ITEM_END; slot++)
{
Item* const pItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
if (pItem)
{
const ItemPrototype* const pItemProto = pItem->GetProto();

if (!pItemProto || bot->CanUseItem(pItemProto) != EQUIP_ERR_OK)
continue;

if (pItemProto->Class == ITEM_CLASS_CONSUMABLE && pItemProto->SubClass == ITEM_SUBCLASS_BANDAGE)
return pItem;
}
}
// list out items in other removable backpacks
for (uint8 bag = INVENTORY_SLOT_BAG_START; bag < INVENTORY_SLOT_BAG_END; ++bag)
{
const Bag* const pBag = (Bag *)bot->GetItemByPos(INVENTORY_SLOT_BAG_0, bag);
if (pBag)
for (uint8 slot = 0; slot < pBag->GetBagSize(); ++slot)
{
Item* const pItem = bot->GetItemByPos(bag, slot);
if (pItem)
{
const ItemPrototype* const pItemProto = pItem->GetProto();

if (!pItemProto || bot->CanUseItem(pItemProto) != EQUIP_ERR_OK)
continue;

if (pItemProto->Class == ITEM_CLASS_CONSUMABLE && pItemProto->SubClass == ITEM_SUBCLASS_BANDAGE)
return pItem;
}
}
}
return nullptr;
}

static const uint32 uPriorizedSharpStoneIds[8] =
{
ADAMANTITE_SHARPENING_DISPLAYID, FEL_SHARPENING_DISPLAYID, ELEMENTAL_SHARPENING_DISPLAYID, DENSE_SHARPENING_DISPLAYID,
Expand Down Expand Up @@ -1713,7 +1772,22 @@ Item* PlayerbotAI::FindOilFor(Item* weapon) const
return nullptr;
}

// use item on equipped item
// on self
void PlayerbotAI::ImbueItem(Item* item)
{
ImbueItem(item, TARGET_FLAG_SELF, ObjectGuid());
}

// item on unit
void PlayerbotAI::ImbueItem(Item* item, Unit* target)
{
if (!target)
return;

ImbueItem(item, TARGET_FLAG_UNIT, target->GetObjectGuid());
}

// item on equipped item
void PlayerbotAI::ImbueItem(Item* item, uint8 targetInventorySlot)
{
if (targetInventorySlot >= EQUIPMENT_SLOT_END)
Expand Down Expand Up @@ -1762,3 +1836,36 @@ void PlayerbotAI::ImbueItem(Item* item, uint32 targetFlag, ObjectGuid targetGUID

bot->GetSession()->QueuePacket(std::move(packet));
}

void PlayerbotAI::EnchantItemT(uint32 spellid, uint8 slot)
{
Item* pItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
if (!pItem)
return;

SpellEntry const* spellInfo = sSpellTemplate.LookupEntry<SpellEntry>(spellid);
if (!spellInfo)
return;

uint32 enchantid = spellInfo->EffectMiscValue[0];
if (!enchantid)
{
sLog.outError("%s: Invalid enchantid " , enchantid , " report to devs", bot->GetName());
return;
}

if (!((1 << pItem->GetProto()->SubClass) & spellInfo->EquippedItemSubClassMask) &&
!((1 << pItem->GetProto()->InventoryType) & spellInfo->EquippedItemInventoryTypeMask))
{

sLog.outError("%s: items could not be enchanted, wrong item type equipped", bot->GetName());

return;
}

bot->ApplyEnchantment(pItem, PERM_ENCHANTMENT_SLOT, false);
pItem->SetEnchantment(PERM_ENCHANTMENT_SLOT, enchantid, 0, 0);
bot->ApplyEnchantment(pItem, PERM_ENCHANTMENT_SLOT, true);

sLog.outDetail("%s: items was enchanted successfully!", bot->GetName());
}
36 changes: 33 additions & 3 deletions playerbot/PlayerbotAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ namespace ai
};
};

enum HealingItemDisplayId
{
HEALTHSTONE_DISPLAYID = 8026,
MAJOR_HEALING_POTION = 24152,
WHIPPER_ROOT_TUBER = 21974,
NIGHT_DRAGON_BREATH = 21975,
LIMITED_INVULNERABILITY_POTION = 24213,
GREATER_DREAMLESS_SLEEP_POTION = 17403,
SUPERIOR_HEALING_POTION = 15714,
CRYSTAL_RESTORE = 2516,
DREAMLESS_SLEEP_POTION = 17403,
GREATER_HEALING_POTION = 15713,
HEALING_POTION = 15712,
LESSER_HEALING_POTION = 15711,
DISCOLORED_HEALING_POTION = 15736,
MINOR_HEALING_POTION = 15710,
VOLATILE_HEALING_POTION = 24212,
SUPER_HEALING_POTION = 37807,
CRYSTAL_HEALING_POTION = 47132,
FEL_REGENERATION_POTION = 37864,
MAJOR_DREAMLESS_SLEEP_POTION = 37845,
};

enum BotState
{
BOT_STATE_COMBAT = 0,
Expand Down Expand Up @@ -197,17 +220,24 @@ class PlayerbotAI : public PlayerbotAIBase
bool PlaySound(uint32 emote);
Item * FindPoison() const;
Item * FindConsumable(uint32 displayId) const;
Item * FindBandage() const;
Item* FindStoneFor(Item* weapon) const;
Item* FindOilFor(Item* weapon) const;
void ImbueItem(Item* item, uint32 targetFlag, ObjectGuid targetGUID);
void ImbueItem(Item* item, uint8 targetInventorySlot);
//void UseItem(Item* item, Unit* target);
//void UseItem(Item* item);
void ImbueItem(Item* item, Unit* target);
void ImbueItem(Item* item);
void EnchantItemT(uint32 spellid, uint8 slot);


virtual bool CanCastSpell(string name, Unit* target, uint8 effectMask, Item* itemTarget = NULL);
virtual bool CastSpell(string name, Unit* target, Item* itemTarget = NULL);
virtual bool HasAura(string spellName, Unit* player);
virtual bool HasAnyAuraOf(Unit* player, ...);
uint8 GetHealthPercent(const Unit& target) const;
uint8 GetHealthPercent() const;
uint8 GetManaPercent(const Unit& target) const;
uint8 GetManaPercent() const;

virtual bool IsInterruptableSpellCasting(Unit* player, string spell, uint8 effectMask);
virtual bool HasAuraToDispel(Unit* player, uint32 dispelType);
Expand All @@ -223,7 +253,7 @@ class PlayerbotAI : public PlayerbotAIBase

private:
void _fillGearScoreData(Player *player, Item* item, std::vector<uint32>* gearScore, uint32& twoHandScore);

public:
Player* GetBot() { return bot; }
Player* GetMaster() { return master; }
Expand Down
Loading

0 comments on commit c87e382

Please sign in to comment.