From 936697defc01f9319cea9316d182e75b2e43ca23 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: Thu, 22 Aug 2024 09:45:11 +0200 Subject: [PATCH] feat: add max passable height to AI config --- Client/App.xaml.cs | 7 ++--- .../ViewModels/AIConfigViewModel.cs | 6 +++- .../ViewModels/CreatureListViewModel.cs | 2 +- .../ViewModels/CreatureMapViewModel.cs | 2 +- .../ViewModels/DropListViewModel.cs | 2 +- .../ViewModels/DropMapViewModel.cs | 2 +- Client/Application/ViewModels/MapViewModel.cs | 2 +- Client/Application/Views/AIConfig.xaml | 15 ++++++++-- Client/Domain/AI/Config.cs | 1 + Client/Domain/AI/State/MoveToSpotState.cs | 2 +- Client/Domain/AI/State/MoveToTargetState.cs | 2 +- .../Domain/Service/AsyncPathMoverInterface.cs | 3 +- Client/Domain/Service/PathfinderInterface.cs | 2 +- .../Infrastructure/Service/AsyncPathMover.cs | 28 ++++++++---------- .../Service/L2jGeoDataPathfinder.cs | 9 +++--- Client/config.json | Bin 512 -> 452 bytes 16 files changed, 46 insertions(+), 39 deletions(-) diff --git a/Client/App.xaml.cs b/Client/App.xaml.cs index 6f9a791..8e33f21 100644 --- a/Client/App.xaml.cs +++ b/Client/App.xaml.cs @@ -120,8 +120,7 @@ namespace Client .AddSingleton( typeof(PathfinderInterface), x => new L2jGeoDataPathfinder( - config.GetValue("GeoDataDirectory") ?? "", - config.GetValue("MaxPassableHeight") + config.GetValue("GeoDataDirectory") ?? "" ) ) .AddSingleton( @@ -129,10 +128,10 @@ namespace Client x => new AsyncPathMover( x.GetRequiredService(), x.GetRequiredService(), - config.GetValue("PathNumberOfAttempts"), config.GetValue("NodeWaitingTime"), config.GetValue("NodeDistanceTolerance"), - config.GetValue("NextNodeDistanceTolerance") + config.GetValue("NextNodeDistanceTolerance"), + config.GetValue("MaxPassableHeight") ) ) diff --git a/Client/Application/ViewModels/AIConfigViewModel.cs b/Client/Application/ViewModels/AIConfigViewModel.cs index ac6670c..13fbe9d 100644 --- a/Client/Application/ViewModels/AIConfigViewModel.cs +++ b/Client/Application/ViewModels/AIConfigViewModel.cs @@ -117,6 +117,7 @@ namespace Client.Application.ViewModels public byte DelevelingTargetLevel { get => delevelingTargetLevel; set { if (value != delevelingTargetLevel) { delevelingTargetLevel = value; OnPropertyChanged(); } } } 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 void LoadConfig() { @@ -151,6 +152,7 @@ namespace Client.Application.ViewModels DelevelingTargetLevel = config.Deleveling.TargetLevel; DelevelingAttackDistance = config.Deleveling.AttackDistance; DelevelingSkillId = config.Deleveling.SkillId; + MaxPassableHeight = config.Combat.MaxPassableHeight; } private void SaveConfig() @@ -181,6 +183,7 @@ namespace Client.Application.ViewModels config.Deleveling.TargetLevel = DelevelingTargetLevel; config.Deleveling.AttackDistance = DelevelingAttackDistance; config.Deleveling.SkillId = DelevelingSkillId; + config.Combat.MaxPassableHeight = MaxPassableHeight; SaveCollections(); } @@ -318,7 +321,7 @@ namespace Client.Application.ViewModels private readonly ConfigDeserializerInterface configDeserializer; private uint mobsMaxDeltaZ = 0; private byte? mobLevelLowerLimit = null; - private byte? mobLevelUpperLimit = null; + private byte maxPassableHeight = 0; private bool spoilIfPossible = false; private bool spoilIsPriority = false; private uint spoilSkillId = 0; @@ -340,5 +343,6 @@ namespace Client.Application.ViewModels private byte delevelingTargetLevel = 0; private uint delevelingAttackDistance = 0; private uint delevelingSkillId = 0; + private byte? mobLevelUpperLimit = null; } } diff --git a/Client/Application/ViewModels/CreatureListViewModel.cs b/Client/Application/ViewModels/CreatureListViewModel.cs index 8e03d98..f1e0a94 100644 --- a/Client/Application/ViewModels/CreatureListViewModel.cs +++ b/Client/Application/ViewModels/CreatureListViewModel.cs @@ -43,7 +43,7 @@ namespace Client.Application.ViewModels private async Task OnMouseRightClick(object? obj) { - await pathMover.MoveUntilReachedAsync(creature.Transform.Position); + await pathMover.MoveAsync(creature.Transform.Position); } public CreatureListViewModel(WorldHandler worldHandler, AsyncPathMoverInterface pathMover, CreatureInterface creature, Hero hero) diff --git a/Client/Application/ViewModels/CreatureMapViewModel.cs b/Client/Application/ViewModels/CreatureMapViewModel.cs index ab04580..7702136 100644 --- a/Client/Application/ViewModels/CreatureMapViewModel.cs +++ b/Client/Application/ViewModels/CreatureMapViewModel.cs @@ -89,7 +89,7 @@ namespace Client.Application.ViewModels private async Task OnMouseRightClick(object? obj) { - await pathMover.MoveUntilReachedAsync(creature.Transform.Position); + await pathMover.MoveAsync(creature.Transform.Position); } public CreatureMapViewModel(WorldHandler worldHandler, AsyncPathMoverInterface pathMover, CreatureInterface creature, Hero hero) diff --git a/Client/Application/ViewModels/DropListViewModel.cs b/Client/Application/ViewModels/DropListViewModel.cs index 8aab018..dd8f2e9 100644 --- a/Client/Application/ViewModels/DropListViewModel.cs +++ b/Client/Application/ViewModels/DropListViewModel.cs @@ -76,7 +76,7 @@ namespace Client.Application.ViewModels } private async Task OnMouseRightClick(object? obj) { - await pathMover.MoveUntilReachedAsync(drop.Transform.Position); + await pathMover.MoveAsync(drop.Transform.Position); } public DropListViewModel(WorldHandler worldHandler, AsyncPathMoverInterface pathMover, Drop drop, Hero hero) diff --git a/Client/Application/ViewModels/DropMapViewModel.cs b/Client/Application/ViewModels/DropMapViewModel.cs index dfe7591..ceb4f8a 100644 --- a/Client/Application/ViewModels/DropMapViewModel.cs +++ b/Client/Application/ViewModels/DropMapViewModel.cs @@ -64,7 +64,7 @@ namespace Client.Application.ViewModels } private async Task OnMouseRightClick(object? obj) { - await pathMover.MoveUntilReachedAsync(drop.Transform.Position); + await pathMover.MoveAsync(drop.Transform.Position); } public DropMapViewModel(WorldHandler worldHandler, AsyncPathMoverInterface pathMover, Drop drop, Hero hero) diff --git a/Client/Application/ViewModels/MapViewModel.cs b/Client/Application/ViewModels/MapViewModel.cs index e28cb33..c4ac548 100644 --- a/Client/Application/ViewModels/MapViewModel.cs +++ b/Client/Application/ViewModels/MapViewModel.cs @@ -169,7 +169,7 @@ namespace Client.Application.ViewModels hero.Transform.Position.Z ); - await pathMover.MoveUntilReachedAsync(location); + await pathMover.MoveAsync(location); } public void OnMouseWheel(object sender, MouseWheelEventArgs e) diff --git a/Client/Application/Views/AIConfig.xaml b/Client/Application/Views/AIConfig.xaml index f1466c0..25f66f3 100644 --- a/Client/Application/Views/AIConfig.xaml +++ b/Client/Application/Views/AIConfig.xaml @@ -40,10 +40,19 @@ + Auto use soul and spiritshots Use only skills + + + + + + + + @@ -51,7 +60,7 @@ - + @@ -59,7 +68,7 @@ - + - + diff --git a/Client/Domain/AI/Config.cs b/Client/Domain/AI/Config.cs index e14fd1a..cf9641b 100644 --- a/Client/Domain/AI/Config.cs +++ b/Client/Domain/AI/Config.cs @@ -33,6 +33,7 @@ namespace Client.Domain.AI public uint AttackDistanceBow { get; set; } = 500; public bool UseOnlySkills { get; set; } = false; public List SkillConditions { get; set; } = new List(); + public byte MaxPassableHeight { get; set; } = 30; public bool SpoilIfPossible { get; set; } = true; public bool SpoilIsPriority { get; set; } = false; diff --git a/Client/Domain/AI/State/MoveToSpotState.cs b/Client/Domain/AI/State/MoveToSpotState.cs index fc3e955..e72b2d3 100644 --- a/Client/Domain/AI/State/MoveToSpotState.cs +++ b/Client/Domain/AI/State/MoveToSpotState.cs @@ -31,7 +31,7 @@ namespace Client.Domain.AI.State config.Combat.Zone.Center.X, config.Combat.Zone.Center.Y, hero.Transform.Position.Z - )); + ), config.Combat.MaxPassableHeight); } } } diff --git a/Client/Domain/AI/State/MoveToTargetState.cs b/Client/Domain/AI/State/MoveToTargetState.cs index fc251d3..05fec8a 100644 --- a/Client/Domain/AI/State/MoveToTargetState.cs +++ b/Client/Domain/AI/State/MoveToTargetState.cs @@ -37,7 +37,7 @@ namespace Client.Domain.AI.State if (routeNeedsToBeAdjusted || distance >= Helper.GetAttackDistanceByConfig(worldHandler, config, hero, target) || !asyncPathMover.Pathfinder.HasLineOfSight(hero.Transform.Position, target.Transform.Position)) { targetPosition = target.Transform.Position.Clone() as Vector3; - asyncPathMover.MoveAsync(target.Transform.Position); + asyncPathMover.MoveAsync(target.Transform.Position, config.Combat.MaxPassableHeight); } } diff --git a/Client/Domain/Service/AsyncPathMoverInterface.cs b/Client/Domain/Service/AsyncPathMoverInterface.cs index beab996..3e33afd 100644 --- a/Client/Domain/Service/AsyncPathMoverInterface.cs +++ b/Client/Domain/Service/AsyncPathMoverInterface.cs @@ -13,10 +13,9 @@ namespace Client.Domain.Service { public PathfinderInterface Pathfinder { get; } public ObservableCollection Path { get; } + public Task MoveAsync(Vector3 location, ushort maxPassableHeight); public Task MoveAsync(Vector3 location); - public Task MoveUntilReachedAsync(Vector3 location); public bool IsLocked { get; } - public void Unlock(); } } diff --git a/Client/Domain/Service/PathfinderInterface.cs b/Client/Domain/Service/PathfinderInterface.cs index a4662b9..97e948c 100644 --- a/Client/Domain/Service/PathfinderInterface.cs +++ b/Client/Domain/Service/PathfinderInterface.cs @@ -10,7 +10,7 @@ namespace Client.Domain.Service { public interface PathfinderInterface { - public List FindPath(Vector3 start, Vector3 end); + public List FindPath(Vector3 start, Vector3 end, ushort maxPassableHeight); public bool HasLineOfSight(Vector3 start, Vector3 end); } } diff --git a/Client/Infrastructure/Service/AsyncPathMover.cs b/Client/Infrastructure/Service/AsyncPathMover.cs index 2df9677..3143948 100644 --- a/Client/Infrastructure/Service/AsyncPathMover.cs +++ b/Client/Infrastructure/Service/AsyncPathMover.cs @@ -21,10 +21,10 @@ namespace Client.Infrastructure.Service { private readonly WorldHandler worldHandler; private readonly PathfinderInterface pathfinder; - private readonly int pathNumberOfAttempts; private readonly double nodeWaitingTime; private readonly int nodeDistanceTolerance; private readonly int nextNodeDistanceTolerance; + private readonly ushort maxPassableHeight; private CancellationTokenSource? cancellationTokenSource; public PathfinderInterface Pathfinder => pathfinder; @@ -43,16 +43,7 @@ namespace Client.Infrastructure.Service } } - public async Task MoveUntilReachedAsync(Vector3 location) - { - var remainingAttempts = pathNumberOfAttempts; - while (!await MoveAsync(location) && remainingAttempts > 0) - { - remainingAttempts--; - } - } - - public async Task MoveAsync(Vector3 location) + public async Task MoveAsync(Vector3 location, ushort maxPassableHeight) { IsLocked = true; @@ -69,7 +60,7 @@ namespace Client.Infrastructure.Service return await Task.Run(async () => { Debug.WriteLine("Find path started"); - FindPath(location); + FindPath(location, maxPassableHeight); Debug.WriteLine("Find path finished"); @@ -99,17 +90,22 @@ namespace Client.Infrastructure.Service } } - public AsyncPathMover(WorldHandler worldHandler, PathfinderInterface pathfinder, int pathNumberOfAttempts, double nodeWaitingTime, int nodeDistanceTolerance, int nextNodeDistanceTolerance) + public async Task MoveAsync(Vector3 location) + { + return await MoveAsync(location, maxPassableHeight); + } + + public AsyncPathMover(WorldHandler worldHandler, PathfinderInterface pathfinder, double nodeWaitingTime, int nodeDistanceTolerance, int nextNodeDistanceTolerance, ushort maxPassableHeight) { this.worldHandler = worldHandler; this.pathfinder = pathfinder; - this.pathNumberOfAttempts = pathNumberOfAttempts; this.nodeWaitingTime = nodeWaitingTime; this.nodeDistanceTolerance = nodeDistanceTolerance; this.nextNodeDistanceTolerance = nextNodeDistanceTolerance; + this.maxPassableHeight = maxPassableHeight; } - private void FindPath(Vector3 location) + private void FindPath(Vector3 location, ushort maxPassableHeight) { var hero = worldHandler.Hero; @@ -119,7 +115,7 @@ namespace Client.Infrastructure.Service return; } - var path = pathfinder.FindPath(hero.Transform.Position, location); + var path = pathfinder.FindPath(hero.Transform.Position, location, maxPassableHeight); foreach (var segment in path) { Path.Add(segment); diff --git a/Client/Infrastructure/Service/L2jGeoDataPathfinder.cs b/Client/Infrastructure/Service/L2jGeoDataPathfinder.cs index e977f72..c69c2ea 100644 --- a/Client/Infrastructure/Service/L2jGeoDataPathfinder.cs +++ b/Client/Infrastructure/Service/L2jGeoDataPathfinder.cs @@ -20,13 +20,12 @@ namespace Client.Infrastructure.Service [DllImport("L2JGeoDataPathFinder.dll", CallingConvention = CallingConvention.Cdecl)] private static extern bool HasLineOfSight(string geoDataDirectory, float startX, float startY, float startZ, float endX, float endY, ushort maxPassableHeight); - public L2jGeoDataPathfinder(string geodataDirectory, ushort maxPassableHeight) + public L2jGeoDataPathfinder(string geodataDirectory) { this.geodataDirectory = geodataDirectory; - this.maxPassableHeight = maxPassableHeight; } - public List FindPath(Vector3 start, Vector3 end) + public List FindPath(Vector3 start, Vector3 end, ushort maxPassableHeight) { var arrayPtr = IntPtr.Zero; var size = FindPath(out arrayPtr, GetGeodataFullpath(), start.X, start.Y, start.Z, end.X, end.Y, maxPassableHeight); @@ -53,7 +52,7 @@ namespace Client.Infrastructure.Service public bool HasLineOfSight(Vector3 start, Vector3 end) { - return HasLineOfSight(GetGeodataFullpath(), start.X, start.Y, start.Z, end.X, end.Y, maxPassableHeight); + return HasLineOfSight(GetGeodataFullpath(), start.X, start.Y, start.Z, end.X, end.Y, LINE_OF_SIGHT_HEIGHT_OF_OBSTACLE); } private List BuildPath(List nodes) @@ -98,6 +97,6 @@ namespace Client.Infrastructure.Service } private readonly string geodataDirectory; - private readonly ushort maxPassableHeight; + private const ushort LINE_OF_SIGHT_HEIGHT_OF_OBSTACLE = 999; } } diff --git a/Client/config.json b/Client/config.json index 994f8c92d23efd614ca128ffb15561e1111cc6a5..bcbb65bd3f449fa04cf237b765f15eac46a0e3d7 100644 GIT binary patch delta 11 ScmZo*Il{a_h;gzX<0b$V+5@8i delta 59 zcmX@Y+`zIyh*3X)A(5ekA%nq>p_Cz)A&DWCp@_ksA&tQiC|UyK0$;Y1}g>y K2Ghx`jQatC#SBCM