diff --git a/playerbot/PlayerbotAI.cpp b/playerbot/PlayerbotAI.cpp index 8d856731..aa138acd 100644 --- a/playerbot/PlayerbotAI.cpp +++ b/playerbot/PlayerbotAI.cpp @@ -399,12 +399,6 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal) bot->SetPower(POWER_MANA, bot->GetMaxPower(POWER_MANA)); if (HasCheat(BotCheatMask::power) && bot->GetPowerType() != POWER_MANA) bot->SetPower(bot->GetPowerType(), bot->GetMaxPower(bot->GetPowerType())); - if (HasCheat(BotCheatMask::repair)) -#ifdef MANGOSBOT_ZERO - bot->DurabilityRepairAll(false, 0); -#else - bot->DurabilityRepairAll(false, 0, false); -#endif if (HasCheat(BotCheatMask::cooldown)) bot->RemoveAllCooldowns(); if (HasCheat(BotCheatMask::movespeed)) @@ -4299,6 +4293,33 @@ bool PlayerbotAI::HasSpellItems(uint32 spellId, const Item* castItem) const return false; } +void PlayerbotAI::DurabilityLoss(Item* item, double percent) +{ + if (item) + { + const uint32 pCurrDurability = item->GetUInt32Value(ITEM_FIELD_DURABILITY); + const uint32 pMaxDurability = item->GetUInt32Value(ITEM_FIELD_MAXDURABILITY); + if (pMaxDurability) + { + if (!HasCheat(BotCheatMask::repair)) + { + // Break item + uint32 pDurabilityLoss = std::max(uint32(pMaxDurability * percent), 1U); + bot->DurabilityPointsLoss(item, pDurabilityLoss); + } + else if (pCurrDurability < pMaxDurability) + { + // Repair if broken +#ifdef MANGOSBOT_ZERO + bot->DurabilityRepair(item->GetPos(), false, 0.0f); +#else + bot->DurabilityRepair(item->GetPos(), false, 0.0f, false); +#endif + } + } + } +} + bool IsAlliance(uint8 race) { return race == RACE_HUMAN || race == RACE_DWARF || race == RACE_NIGHTELF || diff --git a/playerbot/PlayerbotAI.h b/playerbot/PlayerbotAI.h index d952f346..fd98b2aa 100644 --- a/playerbot/PlayerbotAI.h +++ b/playerbot/PlayerbotAI.h @@ -392,6 +392,7 @@ class PlayerbotAI : public PlayerbotAIBase std::vector GetAuras(Unit* player, bool allAuras = true, bool positive = false); bool HasSpellItems(uint32 spellId, const Item* castItem) const; + void DurabilityLoss(Item* item, double percent); virtual bool CanCastSpell(std::string name, Unit* target, uint8 effectMask, Item* itemTarget = nullptr, bool ignoreRange = false, bool ignoreInCombat = false, bool ignoreMount = false); bool CanCastSpell(uint32 spellid, Unit* target, uint8 effectMask, bool checkHasSpell = true, Item* itemTarget = nullptr, bool ignoreRange = false, bool ignoreInCombat = false, bool ignoreMount = false); diff --git a/playerbot/strategy/actions/ReleaseSpiritAction.h b/playerbot/strategy/actions/ReleaseSpiritAction.h index ff7f6e48..312ba835 100644 --- a/playerbot/strategy/actions/ReleaseSpiritAction.h +++ b/playerbot/strategy/actions/ReleaseSpiritAction.h @@ -141,10 +141,7 @@ namespace ai sLog.outBasic("Bot #%d %s:%d <%s> repops at spirit healer", bot->GetGUIDLow(), bot->GetTeam() == ALLIANCE ? "A" : "H", bot->GetLevel(), bot->GetName()); PlayerbotChatHandler ch(bot); bot->ResurrectPlayer(0.5f, !ai->HasCheat(BotCheatMask::repair)); - if (!ai->HasCheat(BotCheatMask::repair)) - { - bot->DurabilityLossAll(0.25f, true); - } + bot->DurabilityLossAll(0.25f, true); bot->SpawnCorpseBones(); bot->SaveToDB(); diff --git a/playerbot/strategy/actions/ReviveFromCorpseAction.cpp b/playerbot/strategy/actions/ReviveFromCorpseAction.cpp index a66a4a74..b76a79fc 100644 --- a/playerbot/strategy/actions/ReviveFromCorpseAction.cpp +++ b/playerbot/strategy/actions/ReviveFromCorpseAction.cpp @@ -226,10 +226,7 @@ bool SpiritHealerAction::Execute(Event& event) sLog.outBasic("Bot #%d %s:%d <%s> revives at spirit healer", bot->GetGUIDLow(), bot->GetTeam() == ALLIANCE ? "A" : "H", bot->GetLevel(), bot->GetName()); PlayerbotChatHandler ch(bot); bot->ResurrectPlayer(0.5f, !ai->HasCheat(BotCheatMask::repair)); - if (!ai->HasCheat(BotCheatMask::repair)) - { - bot->DurabilityLossAll(0.25f, true); - } + bot->DurabilityLossAll(0.25f, true); bot->SpawnCorpseBones(); bot->SaveToDB();