From 01eb0e64345c4c2e499bc0b9b7b5dec3f6cb5947 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sat, 22 Jun 2024 18:12:06 +0800 Subject: [PATCH 01/17] [Random bots] Miscs --- src/PlayerbotFactory.cpp | 2 +- src/RandomPlayerbotMgr.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index b32fa397..84642bc5 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -2617,7 +2617,7 @@ void PlayerbotFactory::InitPotions() uint32 itemId = sRandomItemMgr->GetRandomPotion(level, effect); if (!itemId) { - LOG_INFO("playerbots", "No potions (type {}) available for bot {} ({} level)", effect, bot->GetName().c_str(), bot->getLevel()); + // LOG_INFO("playerbots", "No potions (type {}) available for bot {} ({} level)", effect, bot->GetName().c_str(), bot->getLevel()); continue; } diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index 14a11e32..f7ff76cc 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -1524,7 +1524,7 @@ void RandomPlayerbotMgr::RandomizeFirst(Player* bot) uint32 level; - if (sPlayerbotAIConfig->downgradeMaxLevelBot && bot->GetLevel() == sPlayerbotAIConfig->randomBotMaxLevel) { + if (sPlayerbotAIConfig->downgradeMaxLevelBot && bot->GetLevel() >= sPlayerbotAIConfig->randomBotMaxLevel) { if (bot->getClass() == CLASS_DEATH_KNIGHT) { level = sWorld->getIntConfig(CONFIG_START_HEROIC_PLAYER_LEVEL); } else { @@ -1532,7 +1532,7 @@ void RandomPlayerbotMgr::RandomizeFirst(Player* bot) } } else { level = urand(sPlayerbotAIConfig->randomBotMinLevel, maxLevel); - if (urand(0, 100) < 100 * sPlayerbotAIConfig->randomBotMaxLevelChance) + if (urand(1, 100) < 100 * sPlayerbotAIConfig->randomBotMaxLevelChance) level = maxLevel; if (bot->getClass() == CLASS_DEATH_KNIGHT) From 5318e4b49d85257feac35b9fe20d07bd13b4358e Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sat, 22 Jun 2024 18:37:48 +0800 Subject: [PATCH 02/17] [Bot behaviour] accept invitation teleport distance check --- src/strategy/actions/AcceptInvitationAction.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/strategy/actions/AcceptInvitationAction.cpp b/src/strategy/actions/AcceptInvitationAction.cpp index c7a8563c..ce2ea360 100644 --- a/src/strategy/actions/AcceptInvitationAction.cpp +++ b/src/strategy/actions/AcceptInvitationAction.cpp @@ -4,6 +4,7 @@ #include "AcceptInvitationAction.h" #include "Event.h" +#include "PlayerbotAIConfig.h" #include "Playerbots.h" #include "PlayerbotSecurity.h" @@ -42,7 +43,7 @@ bool AcceptInvitationAction::Execute(Event event) botAI->TellMaster("Hello"); - if (sPlayerbotAIConfig->summonWhenGroup) { + if (sPlayerbotAIConfig->summonWhenGroup && bot->GetDistance(inviter) > sPlayerbotAIConfig->sightDistance) { Teleport(inviter, bot); } return true; From ab9339dffaedc298bfb7856d681143a9a506a885 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sat, 22 Jun 2024 18:47:00 +0800 Subject: [PATCH 03/17] [Warnings] Fix warnings --- src/PlayerbotAI.cpp | 4 +++- src/RandomPlayerbotMgr.cpp | 2 +- src/strategy/values/ItemUsageValue.cpp | 6 ++++-- src/strategy/values/PartyMemberValue.h | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index e7d9552b..5ff7fd7d 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -3123,7 +3123,7 @@ bool PlayerbotAI::HasAuraToDispel(Unit* target, uint32 dispelType) #ifndef WIN32 inline int strcmpi(char const* s1, char const* s2) { - for (; *s1 && *s2 && (toupper(*s1) == toupper(*s2)); ++s1, ++s2); + for (; *s1 && *s2 && (toupper(*s1) == toupper(*s2)); ++s1, ++s2) {} return *s1 - *s2; } #endif @@ -3951,6 +3951,8 @@ std::string const PlayerbotAI::HandleRemoteCommand(std::string const command) case NeedMoneyFor::guild: out << "guild"; break; + default: + break; } out << " | " << ChatHelper::formatMoney(AI_VALUE2(uint32, "free money for", i)) << " / " << ChatHelper::formatMoney(AI_VALUE2(uint32, "money needed for", i)) << "\n"; diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index f7ff76cc..a2c96a62 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -1285,7 +1285,7 @@ void RandomPlayerbotMgr::PrepareTeleportCache() "ROUND( position_z / 50), " "t.entry " "HAVING " - "count(*) > 10) AS g " + "count(*) > 7) AS g " "INNER JOIN creature c ON g.guid = c.guid " "INNER JOIN creature_template t on c.id1 = t.entry " "ORDER BY " diff --git a/src/strategy/values/ItemUsageValue.cpp b/src/strategy/values/ItemUsageValue.cpp index 8c05803a..ad4deb03 100644 --- a/src/strategy/values/ItemUsageValue.cpp +++ b/src/strategy/values/ItemUsageValue.cpp @@ -199,8 +199,9 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto) if (!oldItem) if (shouldEquip) return ITEM_USAGE_EQUIP; - else + else { return ITEM_USAGE_BAD_EQUIP; + } ItemTemplate const* oldItemProto = oldItem->GetTemplate(); float oldScore = PlayerbotFactory::CalculateItemScore(oldItemProto->ItemId, bot); @@ -217,8 +218,9 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto) if (itemProto->Class == ITEM_CLASS_QUIVER) if (!oldItem || oldItemProto->ContainerSlots < itemProto->ContainerSlots) return ITEM_USAGE_EQUIP; - else + else { return ITEM_USAGE_NONE; + } bool existingShouldEquip = true; if (oldItemProto->Class == ITEM_CLASS_WEAPON && !sRandomItemMgr->CanEquipWeapon(bot->getClass(), oldItemProto)) diff --git a/src/strategy/values/PartyMemberValue.h b/src/strategy/values/PartyMemberValue.h index ab9c97ef..2924c99b 100644 --- a/src/strategy/values/PartyMemberValue.h +++ b/src/strategy/values/PartyMemberValue.h @@ -13,6 +13,7 @@ class PlayerbotAI; class FindPlayerPredicate { public: + virtual ~FindPlayerPredicate() = default; virtual bool Check(Unit* /*unit*/) = 0; }; From 4636b6e5b6325ec113c9b2e060009cd61286d21a Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sat, 22 Jun 2024 18:48:20 +0800 Subject: [PATCH 04/17] [Warnings] Fix warnings --- src/PlayerbotAI.cpp | 2 ++ src/strategy/values/ItemUsageValue.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 5ff7fd7d..310cc3ad 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -960,6 +960,8 @@ void PlayerbotAI::ChangeEngine(BotState type) case BOT_STATE_DEAD: // LOG_DEBUG("playerbots", "=== {} DEAD ===", bot->GetName().c_str()); break; + default: + break; } } } diff --git a/src/strategy/values/ItemUsageValue.cpp b/src/strategy/values/ItemUsageValue.cpp index ad4deb03..88d7e007 100644 --- a/src/strategy/values/ItemUsageValue.cpp +++ b/src/strategy/values/ItemUsageValue.cpp @@ -196,12 +196,13 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto) Item* oldItem = bot->GetItemByPos(dest); //No item equiped - if (!oldItem) + if (!oldItem) { if (shouldEquip) return ITEM_USAGE_EQUIP; else { return ITEM_USAGE_BAD_EQUIP; } + } ItemTemplate const* oldItemProto = oldItem->GetTemplate(); float oldScore = PlayerbotFactory::CalculateItemScore(oldItemProto->ItemId, bot); @@ -215,12 +216,13 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto) } // Bigger quiver - if (itemProto->Class == ITEM_CLASS_QUIVER) - if (!oldItem || oldItemProto->ContainerSlots < itemProto->ContainerSlots) + if (itemProto->Class == ITEM_CLASS_QUIVER) { + if (!oldItem || oldItemProto->ContainerSlots < itemProto->ContainerSlots) { return ITEM_USAGE_EQUIP; - else { + } else { return ITEM_USAGE_NONE; } + } bool existingShouldEquip = true; if (oldItemProto->Class == ITEM_CLASS_WEAPON && !sRandomItemMgr->CanEquipWeapon(bot->getClass(), oldItemProto)) From 7ecd1613104c730e230839d1ca760b7e624ed0cc Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 23 Jun 2024 11:04:38 +0800 Subject: [PATCH 05/17] [Bot initialization] Neck level check --- src/PlayerbotFactory.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index 84642bc5..fbd3bede 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -1485,6 +1485,9 @@ void PlayerbotFactory::InitEquipment(bool incremental) { if (slot == EQUIPMENT_SLOT_TABARD || slot == EQUIPMENT_SLOT_BODY) continue; + + if (slot == EQUIPMENT_SLOT_NECK && level < 40) + continue; std::vector& ids = items[slot]; if (ids.empty()) From 1428436b6a30bddf3c80cf48b551d7b23989a60c Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 23 Jun 2024 11:15:58 +0800 Subject: [PATCH 06/17] [Bot initialization] Slot level check --- src/PlayerbotFactory.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index fbd3bede..9b1f2339 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -1486,7 +1486,13 @@ void PlayerbotFactory::InitEquipment(bool incremental) if (slot == EQUIPMENT_SLOT_TABARD || slot == EQUIPMENT_SLOT_BODY) continue; - if (slot == EQUIPMENT_SLOT_NECK && level < 40) + 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; std::vector& ids = items[slot]; From 036638e110b3081fa2d16f3e226f259e8c9e1202 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 23 Jun 2024 12:31:40 +0800 Subject: [PATCH 07/17] [Random bots] Fix banker position out-of-bounds --- src/RandomPlayerbotMgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index a2c96a62..fd30576a 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -1347,7 +1347,7 @@ void RandomPlayerbotMgr::PrepareTeleportCache() float z = fields[3].Get(); float orient = fields[4].Get(); uint32 level = fields[5].Get(); - WorldLocation loc(mapId, x + cos(orient) * 10.0f, y + sin(orient) * 10.0f, z, orient + M_PI); + WorldLocation loc(mapId, x + cos(orient) * 6.0f, y + sin(orient) * 6.0f, z + 2.0f, orient + M_PI); collected_locs++; for (int32 l = 1; l <= maxLevel; l++) { if (l <= 60 && level >= 60) { From 34bec1285119a57530877325b7e06cf78debfc2e Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 23 Jun 2024 12:57:57 +0800 Subject: [PATCH 08/17] [Initialization] Fix pet_spell sql --- src/PlayerbotFactory.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index 9b1f2339..89782f68 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -188,7 +188,7 @@ void PlayerbotFactory::Randomize(bool incremental) ClearSkills(); // bot->SaveToDB(false, false); ClearSpells(); - bot->SaveToDB(false, false); + // bot->SaveToDB(false, false); if (!incremental) { ResetQuests(); @@ -196,12 +196,12 @@ void PlayerbotFactory::Randomize(bool incremental) if (!sPlayerbotAIConfig->equipmentPersistence || level < sPlayerbotAIConfig->equipmentPersistenceLevel) { ClearAllItems(); } - bot->SaveToDB(false, false); + // bot->SaveToDB(false, false); bot->GiveLevel(level); bot->InitStatsForLevel(); CancelAuras(); - bot->SaveToDB(false, false); + // bot->SaveToDB(false, false); if (pmo) pmo->finish(); @@ -260,7 +260,7 @@ void PlayerbotFactory::Randomize(bool incremental) pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Mounts"); LOG_DEBUG("playerbots", "Initializing mounts..."); InitMounts(); - bot->SaveToDB(false, false); + // bot->SaveToDB(false, false); if (pmo) pmo->finish(); @@ -349,8 +349,8 @@ void PlayerbotFactory::Randomize(bool incremental) pmo->finish(); LOG_DEBUG("playerbots", "Initializing glyphs..."); - bot->SaveToDB(false, false); InitGlyphs(); + // bot->SaveToDB(false, false); // pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Guilds"); // LOG_INFO("playerbots", "Initializing guilds..."); @@ -372,13 +372,14 @@ void PlayerbotFactory::Randomize(bool incremental) if (!incremental) { bot->RemovePet(nullptr, PET_SAVE_AS_CURRENT, true); bot->RemovePet(nullptr, PET_SAVE_NOT_IN_SLOT, true); + // bot->SaveToDB(false, false); } if (bot->getLevel() >= 10) { pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Pet"); LOG_DEBUG("playerbots", "Initializing pet..."); InitPet(); - bot->SaveToDB(false, false); + // bot->SaveToDB(false, false); InitPetTalents(); if (pmo) pmo->finish(); @@ -1422,10 +1423,19 @@ void PlayerbotFactory::InitEquipment(bool incremental) else if (blevel == 80) delta = 9; - for(uint8 slot = 0; slot < EQUIPMENT_SLOT_END; ++slot) + 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; uint32 desiredQuality = itemQuality; if (urand(0, 100) < 100 * sPlayerbotAIConfig->randomGearLoweringChance && desiredQuality > ITEM_QUALITY_NORMAL) { From 8972d8fd24797de1d95dbc60a083424130ecd025 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 23 Jun 2024 12:58:10 +0800 Subject: [PATCH 09/17] [Random bots] Banker pos --- src/RandomPlayerbotMgr.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index fd30576a..1c320ebd 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -1332,6 +1332,9 @@ void RandomPlayerbotMgr::PrepareTeleportCache() "AND t.faction != 35 " "AND t.faction != 474 " "AND t.faction != 69 " + "AND t.entry != 30606 " + "AND t.entry != 30608 " + "AND t.faction != 69 " "AND map IN ({}) " "ORDER BY " "t.minlevel;", sPlayerbotAIConfig->randomBotMapsAsString.c_str()); From d4c0390a2e8ba2b1b9d988361c3fad3b2394af1c Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 23 Jun 2024 15:53:33 +0800 Subject: [PATCH 10/17] [Class spell] Fix attack action for ranged --- src/strategy/actions/AttackAction.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/strategy/actions/AttackAction.cpp b/src/strategy/actions/AttackAction.cpp index 978eb1d9..f0d85a8c 100644 --- a/src/strategy/actions/AttackAction.cpp +++ b/src/strategy/actions/AttackAction.cpp @@ -110,7 +110,8 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/) context->GetValue("current target")->Set(target); context->GetValue("available loot")->Get()->Add(guid); - bool attacked = bot->Attack(target, true); + bool melee = bot->IsWithinMeleeRange(target) || botAI->IsMelee(bot); + bot->Attack(target, melee); if (IsMovingAllowed() && !bot->HasInArc(CAST_ANGLE_IN_FRONT, target)) { sServerFacade->SetFacingTo(bot, target); From 51a88063f895481e672877be375bdf8b725f6110 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 23 Jun 2024 16:29:46 +0800 Subject: [PATCH 11/17] [Class spell] Hunter auto shot --- src/strategy/hunter/GenericHunterStrategy.cpp | 4 +- src/strategy/triggers/RangeTriggers.cpp | 44 +++++++++++-------- src/strategy/triggers/RangeTriggers.h | 8 ++++ src/strategy/triggers/TriggerContext.h | 2 + 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/strategy/hunter/GenericHunterStrategy.cpp b/src/strategy/hunter/GenericHunterStrategy.cpp index 914ef210..f59db30e 100644 --- a/src/strategy/hunter/GenericHunterStrategy.cpp +++ b/src/strategy/hunter/GenericHunterStrategy.cpp @@ -79,7 +79,7 @@ void GenericHunterStrategy::InitTriggers(std::vector& triggers) { CombatStrategy::InitTriggers(triggers); - triggers.push_back(new TriggerNode("enemy is close", + triggers.push_back(new TriggerNode("enemy within melee", NextAction::array(0, new NextAction("wing clip", ACTION_HIGH + 1), new NextAction("mongoose bite", ACTION_HIGH), @@ -88,7 +88,7 @@ void GenericHunterStrategy::InitTriggers(std::vector& triggers) triggers.push_back(new TriggerNode("hunters pet medium health", NextAction::array(0, new NextAction("mend pet", ACTION_HIGH + 2), nullptr))); // triggers.push_back(new TriggerNode("no ammo", NextAction::array(0, new NextAction("switch to melee", ACTION_HIGH + 1), new NextAction("say::no ammo", ACTION_HIGH), nullptr))); triggers.push_back(new TriggerNode("aspect of the viper", NextAction::array(0, new NextAction("aspect of the viper", ACTION_HIGH), NULL))); - triggers.push_back(new TriggerNode("enemy too close for shoot", NextAction::array(0, new NextAction("flee", ACTION_MOVE + 9), nullptr))); + triggers.push_back(new TriggerNode("enemy too close for auto shot", NextAction::array(0, new NextAction("flee", ACTION_MOVE + 9), nullptr))); triggers.push_back(new TriggerNode("misdirection on main tank", NextAction::array(0, new NextAction("misdirection on main tank", ACTION_HIGH + 7), NULL))); triggers.push_back(new TriggerNode("tranquilizing shot", NextAction::array(0, new NextAction("tranquilizing shot", 61.0f), NULL))); diff --git a/src/strategy/triggers/RangeTriggers.cpp b/src/strategy/triggers/RangeTriggers.cpp index 55b095dd..6431e779 100644 --- a/src/strategy/triggers/RangeTriggers.cpp +++ b/src/strategy/triggers/RangeTriggers.cpp @@ -52,29 +52,29 @@ bool EnemyTooCloseForSpellTrigger::IsActive() bool EnemyTooCloseForAutoShotTrigger::IsActive() { Unit* target = AI_VALUE(Unit*, "current target"); - if (!target) - return false; + + return target && (target->GetVictim() != bot || target->isFrozen() || !target->CanFreeMove()) && bot->IsWithinMeleeRange(target); - if (target->GetTarget() == bot->GetGUID() && !bot->GetGroup() && !target->HasUnitState(UNIT_STATE_ROOT) && GetSpeedInMotion(target) > GetSpeedInMotion(bot) * 0.65f) - return false; + // if (target->GetTarget() == bot->GetGUID() && !bot->GetGroup() && !target->HasUnitState(UNIT_STATE_ROOT) && GetSpeedInMotion(target) > GetSpeedInMotion(bot) * 0.65f) + // return false; - bool isBoss = false; - bool isRaid = false; - float combatReach = bot->GetCombatReach() + target->GetCombatReach(); - float targetDistance = sServerFacade->GetDistance2d(bot, target) + combatReach; - if (target->GetTypeId() == TYPEID_UNIT) - { - Creature* creature = botAI->GetCreature(target->GetGUID()); - if (creature) - { - isBoss = creature->isWorldBoss(); - } - } + // bool isBoss = false; + // bool isRaid = false; + // float combatReach = bot->GetCombatReach() + target->GetCombatReach(); + // float targetDistance = sServerFacade->GetDistance2d(bot, target) + combatReach; + // if (target->GetTypeId() == TYPEID_UNIT) + // { + // Creature* creature = botAI->GetCreature(target->GetGUID()); + // if (creature) + // { + // isBoss = creature->isWorldBoss(); + // } + // } - if (bot->GetMap() && bot->GetMap()->IsRaid()) - isRaid = true; + // if (bot->GetMap() && bot->GetMap()->IsRaid()) + // isRaid = true; - return sServerFacade->IsDistanceLessOrEqualThan(targetDistance, 5.0f); + // return sServerFacade->IsDistanceLessOrEqualThan(targetDistance, 5.0f); } bool EnemyTooCloseForShootTrigger::IsActive() @@ -128,6 +128,12 @@ bool EnemyIsCloseTrigger::IsActive() return target && sServerFacade->IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", "current target"), sPlayerbotAIConfig->tooCloseDistance); } +bool EnemyWithinMeleeTrigger::IsActive() +{ + Unit* target = AI_VALUE(Unit*, "current target"); + return target && bot->IsWithinMeleeRange(target); +} + bool OutOfRangeTrigger::IsActive() { Unit* target = AI_VALUE(Unit*, GetTargetName()); diff --git a/src/strategy/triggers/RangeTriggers.h b/src/strategy/triggers/RangeTriggers.h index ce33b3be..470b5a8f 100644 --- a/src/strategy/triggers/RangeTriggers.h +++ b/src/strategy/triggers/RangeTriggers.h @@ -50,6 +50,14 @@ class EnemyIsCloseTrigger : public Trigger bool IsActive() override; }; +class EnemyWithinMeleeTrigger : public Trigger +{ + public: + EnemyWithinMeleeTrigger(PlayerbotAI* botAI) : Trigger(botAI, "enemy within melee") { } + + bool IsActive() override; +}; + class OutOfRangeTrigger : public Trigger { public: diff --git a/src/strategy/triggers/TriggerContext.h b/src/strategy/triggers/TriggerContext.h index 92fb96a2..34ef3480 100644 --- a/src/strategy/triggers/TriggerContext.h +++ b/src/strategy/triggers/TriggerContext.h @@ -87,6 +87,7 @@ class TriggerContext : public NamedObjectContext creators["enemy too close for auto shot"] = &TriggerContext::enemy_too_close_for_auto_shot; creators["enemy too close for melee"] = &TriggerContext::enemy_too_close_for_melee; creators["enemy is close"] = &TriggerContext::enemy_is_close; + creators["enemy within melee"] = &TriggerContext::enemy_within_melee; creators["party member to heal out of spell range"] = &TriggerContext::party_member_to_heal_out_of_spell_range; creators["combo points available"] = &TriggerContext::ComboPointsAvailable; @@ -278,6 +279,7 @@ class TriggerContext : public NamedObjectContext static Trigger* enemy_too_close_for_shoot(PlayerbotAI* botAI) { return new EnemyTooCloseForShootTrigger(botAI); } static Trigger* enemy_too_close_for_melee(PlayerbotAI* botAI) { return new EnemyTooCloseForMeleeTrigger(botAI); } static Trigger* enemy_is_close(PlayerbotAI* botAI) { return new EnemyIsCloseTrigger(botAI); } + static Trigger* enemy_within_melee(PlayerbotAI* botAI) { return new EnemyWithinMeleeTrigger(botAI); } static Trigger* party_member_to_heal_out_of_spell_range(PlayerbotAI* botAI) { return new PartyMemberToHealOutOfSpellRangeTrigger(botAI); } static Trigger* ComboPointsAvailable(PlayerbotAI* botAI) { return new ComboPointsAvailableTrigger(botAI); } static Trigger* ComboPoints3Available(PlayerbotAI* botAI) { return new ComboPointsAvailableTrigger(botAI, 3); } From 73be6fe119d7cb0993d4db3fc8b39dcb0bd7fd0c Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 23 Jun 2024 17:44:30 +0800 Subject: [PATCH 12/17] [MIscs] Equips, avoid aoe tell --- src/PlayerbotFactory.cpp | 5 ++++- src/strategy/actions/MovementActions.cpp | 16 ++++++++-------- src/strategy/actions/MovementActions.h | 5 ++++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index 89782f68..b5fa94a0 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -1431,11 +1431,14 @@ void PlayerbotFactory::InitEquipment(bool incremental) if (level < 40 && (slot == EQUIPMENT_SLOT_TRINKET1 || slot == EQUIPMENT_SLOT_TRINKET2)) continue; - if (level < 25 && slot == EQUIPMENT_SLOT_NECK) + if (level < 30 && slot == EQUIPMENT_SLOT_NECK) continue; if (level < 25 && slot == EQUIPMENT_SLOT_HEAD) continue; + + if (level < 20 && (slot == EQUIPMENT_SLOT_FINGER1 || slot == EQUIPMENT_SLOT_FINGER2)) + continue; uint32 desiredQuality = itemQuality; if (urand(0, 100) < 100 * sPlayerbotAIConfig->randomGearLoweringChance && desiredQuality > ITEM_QUALITY_NORMAL) { diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index c0de3249..c5024d58 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -1540,8 +1540,8 @@ bool AvoidAoeAction::AvoidAuraWithDynamicObj() return false; } std::ostringstream name; - name << "[" << spellInfo->SpellName[0] << "] (aura)"; - if (FleePostion(dynOwner->GetPosition(), radius, name.str())) { + name << spellInfo->SpellName[0]; // << "] (aura)"; + if (FleePosition(dynOwner->GetPosition(), radius, name.str())) { return true; } return false; @@ -1591,8 +1591,8 @@ bool AvoidAoeAction::AvoidGameObjectWithDamage() continue; } std::ostringstream name; - name << "[" << spellInfo->SpellName[0] << "] (object)"; - if (FleePostion(go->GetPosition(), radius, name.str())) { + name << spellInfo->SpellName[0]; // << "] (object)"; + if (FleePosition(go->GetPosition(), radius, name.str())) { return true; } @@ -1633,8 +1633,8 @@ bool AvoidAoeAction::AvoidUnitWithDamageAura() break; } std::ostringstream name; - name << "[" << triggerSpellInfo->SpellName[0] << "] (unit)"; - if (FleePostion(unit->GetPosition(), radius, name.str())) { + name << triggerSpellInfo->SpellName[0]; //<< "] (unit)"; + if (FleePosition(unit->GetPosition(), radius, name.str())) { return true; } } @@ -1645,7 +1645,7 @@ bool AvoidAoeAction::AvoidUnitWithDamageAura() return false; } -bool AvoidAoeAction::FleePostion(Position pos, float radius, std::string name) +bool AvoidAoeAction::FleePosition(Position pos, float radius, std::string name) { Unit* currentTarget = AI_VALUE(Unit*, "current target"); std::vector possibleAngles; @@ -1676,7 +1676,7 @@ bool AvoidAoeAction::FleePostion(Position pos, float radius, std::string name) if (MoveTo(bot->GetMapId(), bestPos.GetPositionX(), bestPos.GetPositionY(), bestPos.GetPositionZ(), false, false, true)) { if (sPlayerbotAIConfig->tellWhenAvoidAoe) { std::ostringstream out; - out << "Avoiding spell " << name << "..."; + out << "I'm avoiding " << name << "..."; bot->Say(out.str(), LANG_UNIVERSAL); } return true; diff --git a/src/strategy/actions/MovementActions.h b/src/strategy/actions/MovementActions.h index befb1b43..1f6ee401 100644 --- a/src/strategy/actions/MovementActions.h +++ b/src/strategy/actions/MovementActions.h @@ -78,7 +78,10 @@ class AvoidAoeAction : public MovementAction bool AvoidAuraWithDynamicObj(); bool AvoidGameObjectWithDamage(); bool AvoidUnitWithDamageAura(); - bool FleePostion(Position pos, float radius, std::string name); + // Position PositionForTank(Position pos, float radius); + // Position PositionForMelee(Position pos, float radius); + // Position PositionForRanged(Position pos, float radius); + bool FleePosition(Position pos, float radius, std::string name); }; class RunAwayAction : public MovementAction From 82114fdfff51110ec68ee531d245a8cc900767e8 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 23 Jun 2024 23:55:29 +0800 Subject: [PATCH 13/17] [Warnings] Fix. --- src/PlayerbotFactory.cpp | 2 +- src/strategy/actions/SetHomeAction.cpp | 3 ++- src/strategy/actions/TravelAction.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index b5fa94a0..1512046d 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -178,7 +178,7 @@ void PlayerbotFactory::Randomize(bool incremental) // { // return; // } - LOG_INFO("playerbots", "{} randomizing {} (level {} class = {})...", (incremental ? "Incremental" : "Full"), bot->GetName().c_str(), bot->GetLevel(), bot->getClass()); + LOG_INFO("playerbots", "{} randomizing {} (level {} class = {})...", (incremental ? "Incremental" : "Full"), bot->GetName().c_str(), level, bot->getClass()); // LOG_DEBUG("playerbots", "Preparing to {} randomize...", (incremental ? "incremental" : "full")); Prepare(); LOG_DEBUG("playerbots", "Resetting player..."); diff --git a/src/strategy/actions/SetHomeAction.cpp b/src/strategy/actions/SetHomeAction.cpp index 6bf39c60..6bcb417a 100644 --- a/src/strategy/actions/SetHomeAction.cpp +++ b/src/strategy/actions/SetHomeAction.cpp @@ -13,11 +13,12 @@ bool SetHomeAction::Execute(Event event) ObjectGuid selection = bot->GetTarget(); bool isRpgAction = AI_VALUE(GuidPosition, "rpg target") == selection; - if (!isRpgAction) + if (!isRpgAction) { if (master) selection = master->GetTarget(); else return false; + } if (Unit* unit = botAI->GetUnit(selection)) if (unit->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_INNKEEPER)) diff --git a/src/strategy/actions/TravelAction.cpp b/src/strategy/actions/TravelAction.cpp index 3eb1211a..8e3e4524 100644 --- a/src/strategy/actions/TravelAction.cpp +++ b/src/strategy/actions/TravelAction.cpp @@ -35,7 +35,7 @@ bool TravelAction::Execute(Event event) if (!newTarget->IsAlive()) continue; - if (!newTarget->GetEntry() != target->getDestination()->getEntry()) + if (newTarget->GetEntry() == target->getDestination()->getEntry()) continue; if (newTarget->IsInCombat()) From 3abce62bbaff73802ab28eee17cebcf10a599d43 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Mon, 24 Jun 2024 00:21:59 +0800 Subject: [PATCH 14/17] [Performance] Look object stack --- src/LootObjectStack.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/LootObjectStack.cpp b/src/LootObjectStack.cpp index 4a047a16..23324da8 100644 --- a/src/LootObjectStack.cpp +++ b/src/LootObjectStack.cpp @@ -249,16 +249,17 @@ bool LootObject::IsLootPossible(Player* bot) bool LootObjectStack::Add(ObjectGuid guid) { + if (availableLoot.size() >= MAX_LOOT_OBJECT_COUNT) { + availableLoot.shrink(time(nullptr) - 30); + } + + if (availableLoot.size() >= MAX_LOOT_OBJECT_COUNT) { + availableLoot.clear(); + } + if (!availableLoot.insert(guid).second) return false; - if (availableLoot.size() < MAX_LOOT_OBJECT_COUNT) - return true; - - std::vector ordered = OrderByDistance(); - for (size_t i = MAX_LOOT_OBJECT_COUNT; i < ordered.size(); i++) - Remove(ordered[i].guid); - return true; } From 405c20fdd2ef46bb1a938b910884c50eaa48d746 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Mon, 24 Jun 2024 10:36:01 +0800 Subject: [PATCH 15/17] [Attack target] Skull mark icon index fix --- src/strategy/values/AttackersValue.cpp | 2 +- src/strategy/values/TargetValue.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/strategy/values/AttackersValue.cpp b/src/strategy/values/AttackersValue.cpp index fcfd1d9a..41ff417e 100644 --- a/src/strategy/values/AttackersValue.cpp +++ b/src/strategy/values/AttackersValue.cpp @@ -35,7 +35,7 @@ GuidVector AttackersValue::Calculate() } } if (Group* group = bot->GetGroup()) { - ObjectGuid skullGuid = group->GetTargetIcon(4); + ObjectGuid skullGuid = group->GetTargetIcon(7); Unit* skullTarget = botAI->GetUnit(skullGuid); if (skullTarget && IsValidTarget(skullTarget, bot)) { targets.insert(skullTarget); diff --git a/src/strategy/values/TargetValue.cpp b/src/strategy/values/TargetValue.cpp index ad709394..7c515a8a 100644 --- a/src/strategy/values/TargetValue.cpp +++ b/src/strategy/values/TargetValue.cpp @@ -104,7 +104,7 @@ bool FindTargetStrategy::IsHighPriority(Unit* attacker) { if (Group* group = botAI->GetBot()->GetGroup()) { - ObjectGuid guid = group->GetTargetIcon(4); + ObjectGuid guid = group->GetTargetIcon(7); if (guid && attacker->GetGUID() == guid) { return true; } From 38ff51c9caae41f58d361be57d7e166007c3565b Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Mon, 24 Jun 2024 10:36:13 +0800 Subject: [PATCH 16/17] [Avoid aoe] Aura detection --- src/strategy/values/AoeValues.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/strategy/values/AoeValues.cpp b/src/strategy/values/AoeValues.cpp index e6295349..b27fc307 100644 --- a/src/strategy/values/AoeValues.cpp +++ b/src/strategy/values/AoeValues.cpp @@ -122,9 +122,10 @@ Aura* AreaDebuffValue::Calculate() { // Unit::AuraApplicationMap& map = bot->GetAppliedAuras(); Unit::AuraEffectList const& aurasPeriodicDamage = bot->GetAuraEffectsByType(SPELL_AURA_PERIODIC_DAMAGE); + Unit::AuraEffectList const& aurasPeriodicDamagePercent = bot->GetAuraEffectsByType(SPELL_AURA_PERIODIC_DAMAGE_PERCENT); Unit::AuraEffectList const& aurasPeriodicTriggerSpell = bot->GetAuraEffectsByType(SPELL_AURA_PERIODIC_TRIGGER_SPELL); Unit::AuraEffectList const& aurasPeriodicTriggerWithValueSpell = bot->GetAuraEffectsByType(SPELL_AURA_PERIODIC_TRIGGER_SPELL_WITH_VALUE); - for (const Unit::AuraEffectList& list : {aurasPeriodicDamage, aurasPeriodicTriggerSpell, aurasPeriodicTriggerWithValueSpell}) { + for (const Unit::AuraEffectList& list : {aurasPeriodicDamage, aurasPeriodicDamagePercent, aurasPeriodicTriggerSpell, aurasPeriodicTriggerWithValueSpell}) { for (auto i = list.begin(); i != list.end(); ++i) { AuraEffect* aurEff = *i; From c63fd39b9211b36367ef1241936fd4010a8e76ac Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Mon, 24 Jun 2024 10:43:17 +0800 Subject: [PATCH 17/17] [Avoid aoe] Tell avoiding timer --- src/strategy/actions/MovementActions.cpp | 3 ++- src/strategy/actions/MovementActions.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index c5024d58..7ab12027 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -1674,7 +1674,8 @@ bool AvoidAoeAction::FleePosition(Position pos, float radius, std::string name) } if (farestDis > 0.0f) { if (MoveTo(bot->GetMapId(), bestPos.GetPositionX(), bestPos.GetPositionY(), bestPos.GetPositionZ(), false, false, true)) { - if (sPlayerbotAIConfig->tellWhenAvoidAoe) { + if (sPlayerbotAIConfig->tellWhenAvoidAoe && lastTellTimer < time(NULL) - 10) { + lastTellTimer = time(NULL); std::ostringstream out; out << "I'm avoiding " << name << "..."; bot->Say(out.str(), LANG_UNIVERSAL); diff --git a/src/strategy/actions/MovementActions.h b/src/strategy/actions/MovementActions.h index 1f6ee401..c53bf25e 100644 --- a/src/strategy/actions/MovementActions.h +++ b/src/strategy/actions/MovementActions.h @@ -82,6 +82,7 @@ class AvoidAoeAction : public MovementAction // Position PositionForMelee(Position pos, float radius); // Position PositionForRanged(Position pos, float radius); bool FleePosition(Position pos, float radius, std::string name); + time_t lastTellTimer = 0; }; class RunAwayAction : public MovementAction