From ee37ffb219cc0d6f0c0642ed0780b36ec75ee89e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=98=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD?= Date: Sat, 24 Aug 2024 10:21:51 +0200 Subject: [PATCH] feat: add pickup radius --- .../Application/ViewModels/AIConfigViewModel.cs | 4 ++++ Client/Application/Views/AIConfig.xaml | 15 ++++++++++++--- Client/Domain/AI/Combat/Helper.cs | 4 +++- Client/Domain/AI/Combat/TransitionBuilder.cs | 3 --- Client/Domain/AI/Config.cs | 1 + Client/Domain/AI/State/PickupState.cs | 9 ++++++++- L2BotDll/Application.h | 2 +- 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Client/Application/ViewModels/AIConfigViewModel.cs b/Client/Application/ViewModels/AIConfigViewModel.cs index 13fbe9d..53a883e 100644 --- a/Client/Application/ViewModels/AIConfigViewModel.cs +++ b/Client/Application/ViewModels/AIConfigViewModel.cs @@ -118,6 +118,7 @@ namespace Client.Application.ViewModels public uint DelevelingAttackDistance { get => delevelingAttackDistance; set { if (value != delevelingAttackDistance) { delevelingAttackDistance = value; OnPropertyChanged(); } } } public uint DelevelingSkillId { get => delevelingSkillId; set { if (value != delevelingSkillId) { delevelingSkillId = value; OnPropertyChanged(); } } } public byte MaxPassableHeight { get => maxPassableHeight; set { if (value != maxPassableHeight) { maxPassableHeight = value; OnPropertyChanged(); } } } + public short PickupRadius { get => pickupRadius; set { if (value != pickupRadius) { pickupRadius = value; OnPropertyChanged(); } } } public void LoadConfig() { @@ -153,6 +154,7 @@ namespace Client.Application.ViewModels DelevelingAttackDistance = config.Deleveling.AttackDistance; DelevelingSkillId = config.Deleveling.SkillId; MaxPassableHeight = config.Combat.MaxPassableHeight; + PickupRadius = config.Combat.PickupRadius; } private void SaveConfig() @@ -184,6 +186,7 @@ namespace Client.Application.ViewModels config.Deleveling.AttackDistance = DelevelingAttackDistance; config.Deleveling.SkillId = DelevelingSkillId; config.Combat.MaxPassableHeight = MaxPassableHeight; + config.Combat.PickupRadius = PickupRadius; SaveCollections(); } @@ -344,5 +347,6 @@ namespace Client.Application.ViewModels private uint delevelingAttackDistance = 0; private uint delevelingSkillId = 0; private byte? mobLevelUpperLimit = null; + private short pickupRadius = 0; } } diff --git a/Client/Application/Views/AIConfig.xaml b/Client/Application/Views/AIConfig.xaml index 25f66f3..6e4365b 100644 --- a/Client/Application/Views/AIConfig.xaml +++ b/Client/Application/Views/AIConfig.xaml @@ -202,9 +202,18 @@ + Pickup if possible + + + + + + + + @@ -212,7 +221,7 @@ - + @@ -221,13 +230,13 @@ GetDropByConfig(WorldHandler worldHandler, Config config) + public static List GetDropByConfig(WorldHandler worldHandler, Config config, Hero hero) { if (!config.Combat.PickupIfPossible) { @@ -49,6 +49,8 @@ namespace Client.Domain.AI.Combat result = result.Where(x => config.Combat.IncludedItemIdsToPickup.ContainsKey(x.ItemId)); } + result = result.Where(x => x.Transform.Position.HorizontalDistance(hero.Transform.Position) <= config.Combat.PickupRadius); + return result.ToList(); } diff --git a/Client/Domain/AI/Combat/TransitionBuilder.cs b/Client/Domain/AI/Combat/TransitionBuilder.cs index f91cc35..94c28f6 100644 --- a/Client/Domain/AI/Combat/TransitionBuilder.cs +++ b/Client/Domain/AI/Combat/TransitionBuilder.cs @@ -35,9 +35,6 @@ namespace Client.Domain.AI.Combat return false; } - // TODO если нет цели, а тебя атаковали, то моб берется автоматом в таргет, из-за этого баг в Rest и MoveToSpot - // а без этой проверки зацикливается MoveToTarget->FindTarget->MoveToTarget - // один из вариантов решения, брать себя в таргет при входе в Rest и MoveToSpot if (worldHandler.Hero.Target != null && (worldHandler.Hero.AttackerIds.Contains(worldHandler.Hero.Target.Id) || worldHandler.Hero.Target.VitalStats.IsDead)) { return false; diff --git a/Client/Domain/AI/Config.cs b/Client/Domain/AI/Config.cs index cf9641b..c74098d 100644 --- a/Client/Domain/AI/Config.cs +++ b/Client/Domain/AI/Config.cs @@ -48,6 +48,7 @@ namespace Client.Domain.AI public byte PickupAttemptsCount { get; set; } = 10; public Dictionary ExcludedItemIdsToPickup { get; set; } = new Dictionary(); public Dictionary IncludedItemIdsToPickup { get; set; } = new Dictionary(); + public short PickupRadius = 200; } public class DelevelingSection diff --git a/Client/Domain/AI/State/PickupState.cs b/Client/Domain/AI/State/PickupState.cs index e35960e..66ed0da 100644 --- a/Client/Domain/AI/State/PickupState.cs +++ b/Client/Domain/AI/State/PickupState.cs @@ -15,7 +15,14 @@ namespace Client.Domain.AI.State public List GetDrops(WorldHandler worldHandler, Config config) { - var drops = Helper.GetDropByConfig(worldHandler, config); + var hero = worldHandler.Hero; + + if (hero == null) + { + return new List(); + } + + var drops = Helper.GetDropByConfig(worldHandler, config, hero); for (var i = drops.Count - 1; i >= 0; i--) { if (pickupAttempts.ContainsKey(drops[0].Id) && pickupAttempts[drops[0].Id] > config.Combat.PickupAttemptsCount) diff --git a/L2BotDll/Application.h b/L2BotDll/Application.h index b5b7043..1f12c95 100644 --- a/L2BotDll/Application.h +++ b/L2BotDll/Application.h @@ -78,4 +78,4 @@ private: const std::wstring Application::PIPE_NAME = std::wstring(L"PipeL2Bot"); const uint16_t Application::CREATURE_RADIUS = 4000; -const uint16_t Application::DROP_RADIUS = 1000; \ No newline at end of file +const uint16_t Application::DROP_RADIUS = 4000; \ No newline at end of file