Skip to content

Commit

Permalink
Move durability loss logic into bot method
Browse files Browse the repository at this point in the history
  • Loading branch information
davidonete committed Apr 8, 2024
1 parent 0e83bda commit 11e4915
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
33 changes: 27 additions & 6 deletions playerbot/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 ||
Expand Down
1 change: 1 addition & 0 deletions playerbot/PlayerbotAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ class PlayerbotAI : public PlayerbotAIBase
std::vector<Aura*> 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);
Expand Down
5 changes: 1 addition & 4 deletions playerbot/strategy/actions/ReleaseSpiritAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 1 addition & 4 deletions playerbot/strategy/actions/ReviveFromCorpseAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 11e4915

Please sign in to comment.