From 4b62d99c92257be9a24e642b3d553f769003bfde Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 25 Aug 2024 11:19:00 +0800 Subject: [PATCH 1/6] [Crash fix] Circle formation --- src/strategy/values/Formations.cpp | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/strategy/values/Formations.cpp b/src/strategy/values/Formations.cpp index 61ec1b3d..9854b420 100644 --- a/src/strategy/values/Formations.cpp +++ b/src/strategy/values/Formations.cpp @@ -90,7 +90,7 @@ public: float y = master->GetPositionY() + sin(angle) * range; float z = master->GetPositionZ(); if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z)) + master->GetPositionZ(), x, y, z)) { x = master->GetPositionX() + cos(angle) * range; y = master->GetPositionY() + sin(angle) * range; @@ -140,8 +140,8 @@ public: float y = master->GetPositionY() + sin(angle) * range + dy; float z = master->GetPositionZ(); z = bot->GetMapHeight(x, y, z + 5.0f); - if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z)) + if (!master->GetMap()->CheckCollisionAndGetValidCoords( + master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z)) { x = master->GetPositionX() + cos(angle) * range + dx; y = master->GetPositionY() + sin(angle) * range + dy; @@ -158,13 +158,13 @@ public: float z = master->GetPositionZ(); z = bot->GetMapHeight(x, y, z + 5.0f); if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z)) - { - x = master->GetPositionX() + cos(angle) * range + dx; - y = master->GetPositionY() + sin(angle) * range + dy; - z = master->GetPositionZ() + master->GetHoverHeight(); - z = master->GetMapHeight(x, y, z); - } + master->GetPositionZ(), x, y, z)) + { + x = master->GetPositionX() + cos(angle) * range + dx; + y = master->GetPositionY() + sin(angle) * range + dy; + z = master->GetPositionZ() + master->GetHoverHeight(); + z = master->GetMapHeight(x, y, z); + } return WorldLocation(master->GetMapId(), x, y, z); } @@ -216,13 +216,13 @@ public: float x = target->GetPositionX() + cos(angle) * range; float y = target->GetPositionY() + sin(angle) * range; float z = target->GetPositionZ(); - if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z)) + if (!target->GetMap()->CheckCollisionAndGetValidCoords(target, target->GetPositionX(), target->GetPositionY(), + target->GetPositionZ(), x, y, z)) { x = target->GetPositionX() + cos(angle) * range; y = target->GetPositionY() + sin(angle) * range; z = target->GetPositionZ() + target->GetHoverHeight(); - z = master->GetMapHeight(x, y, z); + z = target->GetMapHeight(x, y, z); } return WorldLocation(bot->GetMapId(), x, y, z); } @@ -383,8 +383,8 @@ public: if (minDist) { - if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z)) + if (!master->GetMap()->CheckCollisionAndGetValidCoords( + master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z)) { x = master->GetPositionX() + cos(angle) * range + cos(followAngle) * followRange; y = master->GetPositionY() + sin(angle) * range + sin(followAngle) * followRange; @@ -398,7 +398,7 @@ public: } if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z)) + master->GetPositionZ(), x, y, z)) { x = master->GetPositionX() + cos(angle) * range + cos(followAngle) * followRange; y = master->GetPositionY() + sin(angle) * range + sin(followAngle) * followRange; From af228565fd2e9e411b314f337903bc1c5548e5cc Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 25 Aug 2024 11:19:28 +0800 Subject: [PATCH 2/6] Ulduar flame leviathan improvement --- .../raids/ulduar/RaidUlduarActions.cpp | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/strategy/raids/ulduar/RaidUlduarActions.cpp b/src/strategy/raids/ulduar/RaidUlduarActions.cpp index bef3e3ef..5cb6311a 100644 --- a/src/strategy/raids/ulduar/RaidUlduarActions.cpp +++ b/src/strategy/raids/ulduar/RaidUlduarActions.cpp @@ -47,15 +47,15 @@ bool FlameLeviathanVehicleAction::Execute(Event event) if (unit->GetEntry() == 33142) // Leviathan Defense Turret continue; if (unit->GetEntry() == 33113) // Flame Leviathan + { flame = unit; + continue; + } if (!target || bot->GetExactDist(target) > bot->GetExactDist(unit)) { target = unit; } } - if (!target) - return false; - // Flame Leviathan is chasing me if (flame && flame->GetVictim() == vehicleBase_) if (MoveAvoidChasing(flame)) @@ -65,15 +65,15 @@ bool FlameLeviathanVehicleAction::Execute(Event event) switch (entry) { case NPC_SALVAGED_DEMOLISHER: - return DemolisherAction(target); + return DemolisherAction(flame ? flame : target); case NPC_SALVAGED_DEMOLISHER_TURRET: - return DemolisherTurretAction(target); + return DemolisherTurretAction(target ? target: flame); case NPC_SALVAGED_SIEGE_ENGINE: return SiegeEngineAction(flame ? flame : target); case NPC_SALVAGED_SIEGE_ENGINE_TURRET: - return SiegeEngineTurretAction(target); + return SiegeEngineTurretAction(target ? target: flame); case NPC_VEHICLE_CHOPPER: - return ChopperAction(target); + return ChopperAction(target ? target: flame); default: break; } @@ -82,6 +82,8 @@ bool FlameLeviathanVehicleAction::Execute(Event event) bool FlameLeviathanVehicleAction::MoveAvoidChasing(Unit* target) { + if (!target) + return false; if (avoidChaseIdx == -1) { for (int i = 0; i < corners.size(); i++) @@ -106,6 +108,8 @@ bool FlameLeviathanVehicleAction::MoveAvoidChasing(Unit* target) bool FlameLeviathanVehicleAction::DemolisherAction(Unit* target) { + if (!target) + return false; Aura* bluePyrite = target->GetAura(68605); if (!bluePyrite || (bluePyrite->GetStackAmount() <= 6 && vehicleBase_->GetPower(POWER_ENERGY) > 25) || bluePyrite->GetDuration() <= 5000) { @@ -129,6 +133,7 @@ bool FlameLeviathanVehicleAction::DemolisherAction(Unit* target) bool FlameLeviathanVehicleAction::DemolisherTurretAction(Unit* target) { + int32 liquidCount = 0; { GuidVector npcs = AI_VALUE(GuidVector, "nearest npcs"); for (auto i = npcs.begin(); i != npcs.end(); i++) @@ -136,7 +141,12 @@ bool FlameLeviathanVehicleAction::DemolisherTurretAction(Unit* target) Unit* unit = botAI->GetUnit(*i); if (!unit) continue; - if (unit->GetEntry() == 33189 && vehicleBase_->GetPower(POWER_ENERGY) <= 25) // Liquid Pyrite + if (unit->GetEntry() != 33189) + continue; + if (unit->GetDistance(bot) >= 49.0f) + continue; + ++liquidCount; + if (vehicleBase_->GetPower(POWER_ENERGY) <= 25) // Liquid Pyrite { uint32 spellId = 62479; if (botAI->CanCastVehicleSpell(spellId, unit)) @@ -148,6 +158,7 @@ bool FlameLeviathanVehicleAction::DemolisherTurretAction(Unit* target) } } } + if (liquidCount <= 10) { GuidVector targets = AI_VALUE(GuidVector, "possible targets"); for (auto i = targets.begin(); i != targets.end(); i++) @@ -167,6 +178,8 @@ bool FlameLeviathanVehicleAction::DemolisherTurretAction(Unit* target) } } } + if (!target) + return false; uint32 spellId = 62634; if (botAI->CanCastVehicleSpell(spellId, target)) if (botAI->CastVehicleSpell(spellId, target)) @@ -179,6 +192,8 @@ bool FlameLeviathanVehicleAction::DemolisherTurretAction(Unit* target) bool FlameLeviathanVehicleAction::SiegeEngineAction(Unit* target) { + if (!target) + return false; if (target->GetCurrentSpell(CURRENT_CHANNELED_SPELL) || target->HasAura(62396)) { uint32 spellId = 62522; @@ -201,6 +216,8 @@ bool FlameLeviathanVehicleAction::SiegeEngineAction(Unit* target) bool FlameLeviathanVehicleAction::SiegeEngineTurretAction(Unit* target) { + if (!target) + return false; uint32 spellId = 62358; if (botAI->CanCastVehicleSpell(spellId, target)) if (botAI->CastVehicleSpell(spellId, target)) @@ -213,6 +230,8 @@ bool FlameLeviathanVehicleAction::SiegeEngineTurretAction(Unit* target) bool FlameLeviathanVehicleAction::ChopperAction(Unit* target) { + if (!target) + return false; uint32 spellId = 62286; if (botAI->CanCastVehicleSpell(spellId, target)) if (botAI->CastVehicleSpell(spellId, target)) From 63e596431bbb09beccb773ca96abf9b9abd5789e Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 25 Aug 2024 11:19:36 +0800 Subject: [PATCH 3/6] Kill broadcast --- src/strategy/actions/XpGainAction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/strategy/actions/XpGainAction.cpp b/src/strategy/actions/XpGainAction.cpp index 53fc38e7..c271def4 100644 --- a/src/strategy/actions/XpGainAction.cpp +++ b/src/strategy/actions/XpGainAction.cpp @@ -15,8 +15,6 @@ bool XpGainAction::Execute(Event event) { context->GetValue("death count")->Set(0); - if (!sRandomPlayerbotMgr->IsRandomBot(bot) || sPlayerbotAIConfig->playerbotsXPrate == 1) - return true; WorldPacket p(event.getPacket()); // (8+4+1+4+8) ObjectGuid guid; @@ -42,6 +40,9 @@ bool XpGainAction::Execute(Event event) BroadcastHelper::BroadcastKill(botAI, bot, creature); } + if (!sRandomPlayerbotMgr->IsRandomBot(bot) || sPlayerbotAIConfig->playerbotsXPrate == 1) + return true; + Unit* victim = nullptr; if (guid) victim = botAI->GetUnit(guid); From 6e5fc18b9bee59476ce052eb50aa3f4e9df67352 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 25 Aug 2024 11:19:54 +0800 Subject: [PATCH 4/6] Auto learn spell only for random bots --- src/strategy/actions/AutoMaintenanceOnLevelupAction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/strategy/actions/AutoMaintenanceOnLevelupAction.cpp b/src/strategy/actions/AutoMaintenanceOnLevelupAction.cpp index 5e01d18a..12fcf3d5 100644 --- a/src/strategy/actions/AutoMaintenanceOnLevelupAction.cpp +++ b/src/strategy/actions/AutoMaintenanceOnLevelupAction.cpp @@ -65,10 +65,10 @@ void AutoMaintenanceOnLevelupAction::AutoLearnSpell() void AutoMaintenanceOnLevelupAction::LearnSpells(std::ostringstream* out) { BroadcastHelper::BroadcastLevelup(botAI, bot); - if (sPlayerbotAIConfig->autoLearnTrainerSpells) + if (sPlayerbotAIConfig->autoLearnTrainerSpells && sRandomPlayerbotMgr->IsRandomBot(bot)) LearnTrainerSpells(out); - if (sPlayerbotAIConfig->autoLearnQuestSpells) + if (sPlayerbotAIConfig->autoLearnQuestSpells && sRandomPlayerbotMgr->IsRandomBot(bot)) LearnQuestSpells(out); } From 2c82ea23e08ed1ec264bfe31e0ab9fcf4badedc4 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 25 Aug 2024 11:20:33 +0800 Subject: [PATCH 5/6] Bot creation wait time --- src/RandomPlayerbotFactory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RandomPlayerbotFactory.cpp b/src/RandomPlayerbotFactory.cpp index 1171fc9e..3aa003b4 100644 --- a/src/RandomPlayerbotFactory.cpp +++ b/src/RandomPlayerbotFactory.cpp @@ -538,7 +538,7 @@ void RandomPlayerbotFactory::CreateRandomBots() { LOG_INFO("playerbots", "Waiting for {} characters loading into database...", bot_creation); /* wait for characters load into database, or characters will fail to loggin */ - std::this_thread::sleep_for(10s); + std::this_thread::sleep_for(5s + bot_creation * 5ms); } for (WorldSession* session : sessionBots) From 8dc00c4c6c05124272bc0e0474f91a3ea53e5dcf Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 25 Aug 2024 13:04:39 +0800 Subject: [PATCH 6/6] [Crash fix] Try to fix lfg crash --- src/strategy/actions/LfgActions.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/strategy/actions/LfgActions.cpp b/src/strategy/actions/LfgActions.cpp index cac31678..9a07f527 100644 --- a/src/strategy/actions/LfgActions.cpp +++ b/src/strategy/actions/LfgActions.cpp @@ -212,6 +212,9 @@ bool LfgAcceptAction::Execute(Event event) return true; } + + if (event.getPacket().empty()) + return false; WorldPacket p(event.getPacket());