9 Commits

Author SHA1 Message Date
Иванов Иван
fa078bcead feat: fix inventory occupied slots 2024-08-24 12:35:56 +02:00
Иванов Иван
f50e218013 feat: add ai type and state info 2024-08-24 12:13:40 +02:00
Иванов Иван
ee37ffb219 feat: add pickup radius 2024-08-24 10:21:51 +02:00
Иванов Иван
ca86371137 fix: fix dead state for hero 2024-08-23 17:29:50 +02:00
Иванов Иван
e0ffa3a62e feat: check attackers user type 2024-08-22 23:07:06 +02:00
Иванов Иван
936697defc feat: add max passable height to AI config 2024-08-22 09:45:11 +02:00
Иванов Иван
d0baa5c21a feat: adjust route to target 2024-08-21 22:40:23 +02:00
Иванов Иван
914f6ba20f fix: fix memory leaks 2024-08-21 22:39:22 +02:00
Иванов Иван
4e2e108076 feat: change death logic 2024-08-21 15:00:17 +02:00
37 changed files with 327 additions and 111 deletions

View File

@@ -120,8 +120,7 @@ namespace Client
.AddSingleton(
typeof(PathfinderInterface),
x => new L2jGeoDataPathfinder(
config.GetValue<string>("GeoDataDirectory") ?? "",
config.GetValue<ushort>("MaxPassableHeight")
config.GetValue<string>("GeoDataDirectory") ?? ""
)
)
.AddSingleton(
@@ -129,10 +128,10 @@ namespace Client
x => new AsyncPathMover(
x.GetRequiredService<WorldHandler>(),
x.GetRequiredService<PathfinderInterface>(),
config.GetValue<int>("PathNumberOfAttempts"),
config.GetValue<double>("NodeWaitingTime"),
config.GetValue<int>("NodeDistanceTolerance"),
config.GetValue<int>("NextNodeDistanceTolerance")
config.GetValue<int>("NextNodeDistanceTolerance"),
config.GetValue<ushort>("MaxPassableHeight")
)
)

View File

@@ -117,6 +117,8 @@ 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 short PickupRadius { get => pickupRadius; set { if (value != pickupRadius) { pickupRadius = value; OnPropertyChanged(); } } }
public void LoadConfig()
{
@@ -151,6 +153,8 @@ namespace Client.Application.ViewModels
DelevelingTargetLevel = config.Deleveling.TargetLevel;
DelevelingAttackDistance = config.Deleveling.AttackDistance;
DelevelingSkillId = config.Deleveling.SkillId;
MaxPassableHeight = config.Combat.MaxPassableHeight;
PickupRadius = config.Combat.PickupRadius;
}
private void SaveConfig()
@@ -181,6 +185,8 @@ namespace Client.Application.ViewModels
config.Deleveling.TargetLevel = DelevelingTargetLevel;
config.Deleveling.AttackDistance = DelevelingAttackDistance;
config.Deleveling.SkillId = DelevelingSkillId;
config.Combat.MaxPassableHeight = MaxPassableHeight;
config.Combat.PickupRadius = PickupRadius;
SaveCollections();
}
@@ -318,7 +324,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 +346,7 @@ namespace Client.Application.ViewModels
private byte delevelingTargetLevel = 0;
private uint delevelingAttackDistance = 0;
private uint delevelingSkillId = 0;
private byte? mobLevelUpperLimit = null;
private short pickupRadius = 0;
}
}

View File

@@ -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)
@@ -62,6 +62,14 @@ namespace Client.Application.ViewModels
this.pathMover = pathMover;
}
public void UnsubscribeAll()
{
creature.PropertyChanged -= Creature_PropertyChanged;
creature.Transform.Position.PropertyChanged -= Position_PropertyChanged;
hero.Transform.Position.PropertyChanged -= HeroPosition_PropertyChanged;
hero.PropertyChanged -= Hero_PropertyChanged;
}
private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
OnPropertyChanged("Distance");

View File

@@ -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)
@@ -109,6 +109,16 @@ namespace Client.Application.ViewModels
MouseRightClickCommand = new RelayCommand(async (o) => await OnMouseRightClick(o));
}
public void UnsubscribeAll()
{
creature.PropertyChanged -= Creature_PropertyChanged;
creature.Transform.PropertyChanged -= Transform_PropertyChanged;
creature.Transform.Position.PropertyChanged -= Position_PropertyChanged;
creature.VitalStats.PropertyChanged -= VitalStats_PropertyChanged;
hero.Transform.Position.PropertyChanged -= HeroPosition_PropertyChanged;
hero.PropertyChanged -= Hero_PropertyChanged;
}
private void VitalStats_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "Hp" || e.PropertyName == "MaxHp")

View File

@@ -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)
@@ -92,6 +92,13 @@ namespace Client.Application.ViewModels
MouseRightClickCommand = new RelayCommand(async (o) => await OnMouseRightClick(o));
}
public void UnsubscribeAll()
{
drop.PropertyChanged -= Drop_PropertyChanged;
drop.Transform.Position.PropertyChanged -= DropPosition_PropertyChanged;
hero.Transform.Position.PropertyChanged -= HeroPosition_PropertyChanged;
}
private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
OnPropertyChanged("Distance");

View File

@@ -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)
@@ -73,24 +73,31 @@ namespace Client.Application.ViewModels
this.hero = hero;
this.worldHandler = worldHandler;
this.pathMover = pathMover;
drop.PropertyChanged += Creature_PropertyChanged;
drop.Transform.Position.PropertyChanged += Position_PropertyChanged;
drop.PropertyChanged += Drop_PropertyChanged;
drop.Transform.Position.PropertyChanged += DropPosition_PropertyChanged;
hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged;
MouseLeftClickCommand = new RelayCommand(OnMouseLeftClick);
MouseRightClickCommand = new RelayCommand(async (o) => await OnMouseRightClick(o));
}
public void UnsubscribeAll()
{
drop.PropertyChanged -= Drop_PropertyChanged;
drop.Transform.Position.PropertyChanged -= DropPosition_PropertyChanged;
hero.Transform.Position.PropertyChanged -= HeroPosition_PropertyChanged;
}
private void HeroPosition_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
OnPropertyChanged("Position");
}
private void Position_PropertyChanged(object? sender, PropertyChangedEventArgs e)
private void DropPosition_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
OnPropertyChanged("Position");
}
private void Creature_PropertyChanged(object? sender, PropertyChangedEventArgs e)
private void Drop_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Name" || e.PropertyName == "Amount")
{

View File

@@ -1,8 +1,10 @@
using Client.Domain.Common;
using Client.Domain.AI;
using Client.Domain.Common;
using Client.Domain.Entities;
using Client.Domain.ValueObjects;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -59,13 +61,6 @@ namespace Client.Application.ViewModels
return hero.InventoryInfo;
}
}
public ulong Money
{
get
{
return 0;
}
}
public TargetSummaryInfoViewModel? Target
{
@@ -81,10 +76,33 @@ namespace Client.Application.ViewModels
return hero.AttackerIds.ToList();
}
}
public HeroSummaryInfoViewModel(Hero hero)
public string AIType
{
get
{
return ai.Type.ToString();
}
}
public string AIState
{
get
{
return ai.IsEnabled ? ai.CurrentState.ToString() : "Disabled";
}
}
public int InventoryOccupiedSlots
{
get
{
return items.Count + questItems.Count;
}
}
public HeroSummaryInfoViewModel(Hero hero, AIInterface ai, ObservableCollection<ItemListViewModel> items, ObservableCollection<ItemListViewModel> questItems)
{
this.hero = hero;
this.ai = ai;
this.items = items;
this.questItems = questItems;
hero.FullName.PropertyChanged += FullName_PropertyChanged;
hero.Phenotype.PropertyChanged += Phenotype_PropertyChanged;
hero.ExperienceInfo.PropertyChanged += ExperienceInfo_PropertyChanged;
@@ -92,6 +110,31 @@ namespace Client.Application.ViewModels
hero.VitalStats.PropertyChanged += VitalStats_PropertyChanged;
hero.InventoryInfo.PropertyChanged += InventoryInfo_PropertyChanged;
hero.PropertyChanged += Hero_PropertyChanged;
ai.PropertyChanged += Ai_PropertyChanged;
items.CollectionChanged += Items_CollectionChanged;
questItems.CollectionChanged += QuestItems_CollectionChanged;
}
private void QuestItems_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged("InventoryOccupiedSlots");
}
private void Items_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged("InventoryOccupiedSlots");
}
private void Ai_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "Type")
{
OnPropertyChanged("AIType");
}
if (e.PropertyName == "CurrentState" || e.PropertyName == "IsEnabled")
{
OnPropertyChanged("AIState");
}
}
private void Hero_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
@@ -105,6 +148,7 @@ namespace Client.Application.ViewModels
}
else if (target != null && hero.Target == null)
{
target.UnsubscribeAll();
target = null;
OnPropertyChanged("Target");
}
@@ -146,6 +190,9 @@ namespace Client.Application.ViewModels
}
private readonly Hero hero;
private readonly AIInterface ai;
private readonly ObservableCollection<ItemListViewModel> items;
private readonly ObservableCollection<ItemListViewModel> questItems;
private TargetSummaryInfoViewModel? target;
}
}

View File

@@ -6,6 +6,7 @@ using Client.Domain.Entities;
using Client.Domain.Events;
using Client.Domain.Service;
using Client.Domain.ValueObjects;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -38,7 +39,7 @@ namespace Client.Application.ViewModels
public void Handle(HeroCreatedEvent @event)
{
Hero = new HeroSummaryInfoViewModel(@event.Hero);
Hero = new HeroSummaryInfoViewModel(@event.Hero, ai, Items, QuestItems);
hero = @event.Hero;
Map.Hero = hero;
Map.CombatZone = new AICombatZoneMapViewModel(aiConfig.Combat.Zone, hero);
@@ -72,7 +73,12 @@ namespace Client.Application.ViewModels
public void Handle(CreatureDeletedEvent @event)
{
Creatures.RemoveAll(x => x.Id == @event.Id);
var creature = Creatures.Where(x => x.Id == @event.Id).FirstOrDefault();
if (creature != null)
{
creature.UnsubscribeAll();
Creatures.Remove(creature);
}
RemoveCreature(@event.Id);
}
@@ -87,8 +93,18 @@ namespace Client.Application.ViewModels
public void Handle(DropDeletedEvent @event)
{
Drops.RemoveAll(x => x.Id == @event.Id);
Map.Drops.RemoveAll(x => x.Id == @event.Id);
var drop = Drops.Where(x => x.Id == @event.Id).FirstOrDefault();
if (drop != null)
{
drop.UnsubscribeAll();
Drops.Remove(drop);
}
var mapDrop = Map.Drops.Where(x => x.Id == @event.Id).FirstOrDefault();
if (mapDrop != null)
{
mapDrop.UnsubscribeAll();
Map.Drops.Remove(mapDrop);
}
}
public void Handle(ChatMessageCreatedEvent @event)
@@ -156,7 +172,12 @@ namespace Client.Application.ViewModels
private void RemoveCreature(uint id)
{
Map.Creatures.RemoveAll(x => x.Id == id);
var creature = Map.Creatures.Where(x => x.Id == id).FirstOrDefault();
if (creature != null)
{
creature.UnsubscribeAll();
Map.Creatures.Remove(creature);
}
}
private void OnToggleAI(object? sender)

View File

@@ -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)
@@ -230,11 +230,16 @@ namespace Client.Application.ViewModels
{
foreach (var item in e.OldItems)
{
Path[0].UnsubscribeAll();
Path.RemoveAt(0);
}
}
else if (e.Action == NotifyCollectionChangedAction.Reset)
{
foreach (var item in Path)
{
item.UnsubscribeAll();
}
Path.RemoveAll();
}
}

View File

@@ -69,6 +69,11 @@ namespace Client.Application.ViewModels
hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged;
}
public void UnsubscribeAll()
{
hero.Transform.Position.PropertyChanged -= HeroPosition_PropertyChanged;
}
private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
OnPropertyChanged("From");

View File

@@ -38,6 +38,14 @@ namespace Client.Application.ViewModels
this.hero = hero;
}
public void UnsubscribeAll()
{
creature.PropertyChanged -= Creature_PropertyChanged;
creature.Transform.Position.PropertyChanged -= Position_PropertyChanged;
creature.VitalStats.PropertyChanged -= VitalStats_PropertyChanged;
hero.Transform.Position.PropertyChanged -= HeroPosition_PropertyChanged;
}
private void VitalStats_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "Hp")

View File

@@ -40,10 +40,19 @@
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<CheckBox Grid.Row="0" Grid.Column="0" IsChecked="{Binding AutoUseShots}">Auto use soul and spiritshots</CheckBox>
<CheckBox Grid.Row="1" Grid.Column="0" IsChecked="{Binding UseOnlySkills}">Use only skills</CheckBox>
<StackPanel Grid.Row="2" Grid.Column="0">
<Label>Pathfinder max passable height:</Label>
<TextBox Width="100" HorizontalAlignment="Left">
<TextBox.Text>
<Binding Path="MaxPassableHeight" UpdateSourceTrigger="PropertyChanged"/>
</TextBox.Text>
</TextBox>
</StackPanel>
<StackPanel Grid.Row="3" Grid.Column="0">
<Label>Attack distance for mili weapon:</Label>
<TextBox Width="100" HorizontalAlignment="Left">
<TextBox.Text>
@@ -51,7 +60,7 @@
</TextBox.Text>
</TextBox>
</StackPanel>
<StackPanel Grid.Row="3" Grid.Column="0">
<StackPanel Grid.Row="4" Grid.Column="0">
<Label>Attack distance for bows:</Label>
<TextBox Width="100" HorizontalAlignment="Left">
<TextBox.Text>
@@ -59,7 +68,7 @@
</TextBox.Text>
</TextBox>
</StackPanel>
<StackPanel Grid.Row="4" Grid.Column="0">
<StackPanel Grid.Row="5" Grid.Column="0">
<Label>Skill conditions:</Label>
<DataGrid
AutoGenerateColumns="False"
@@ -91,7 +100,7 @@
</DataGrid.Columns>
</DataGrid>
</StackPanel>
<StackPanel Grid.Row="5" Grid.Column="0">
<StackPanel Grid.Row="6" Grid.Column="0">
<Label>Combat zone:</Label>
<Grid>
<Grid.ColumnDefinitions>
@@ -193,9 +202,18 @@
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<CheckBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" IsChecked="{Binding PickupIfPossible}">Pickup if possible</CheckBox>
<StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
<Label>Pickup radius:</Label>
<TextBox Width="100" HorizontalAlignment="Left">
<TextBox.Text>
<Binding Path="PickupRadius" UpdateSourceTrigger="PropertyChanged"/>
</TextBox.Text>
</TextBox>
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
<Label>Max delta z:</Label>
<TextBox Width="100" HorizontalAlignment="Left">
<TextBox.Text>
@@ -203,7 +221,7 @@
</TextBox.Text>
</TextBox>
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
<StackPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2">
<Label>Pickup attempts count:</Label>
<TextBox Width="100" HorizontalAlignment="Left">
<TextBox.Text>
@@ -212,13 +230,13 @@
</TextBox>
</StackPanel>
<components:MultipleObjectSelector
Grid.Row="3"
Grid.Row="4"
Grid.Column="0"
Source="{Binding ExcludedItems}"
Target="{Binding SelectedExcludedItems}"
Header="Excluded:"/>
<components:MultipleObjectSelector
Grid.Row="3"
Grid.Row="4"
Grid.Column="1"
Source="{Binding IncludedItems}"
Target="{Binding SelectedIncludedItems}"

View File

@@ -225,8 +225,8 @@
<TextBlock Padding="0 0 0 3">Position:</TextBlock>
<TextBlock Padding="0 0 0 3">Exp:</TextBlock>
<TextBlock Padding="0 0 0 3">Weight:</TextBlock>
<TextBlock Padding="0 0 0 3">Adena:</TextBlock>
<TextBlock Padding="0 0 0 3">Inv. slots:</TextBlock>
<TextBlock Padding="0 0 0 3">AI:</TextBlock>
</StackPanel>
<StackPanel>
<TextBlock Padding="0 0 0 3">
@@ -254,12 +254,19 @@
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Text="{Binding Path=Money, Mode=OneWay}" Padding="0 0 0 3"></TextBlock>
<TextBlock Padding="0 0 0 3">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}/{1}">
<Binding Path="InventoryOccupiedSlots" Mode="OneWay"/>
<Binding Path="InventoryInfo.Slots" Mode="OneWay"/>
<Binding Path="InventoryInfo.Slots" Mode="OneWay"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Padding="0 0 0 3">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} ({1})">
<Binding Path="AIType" Mode="OneWay"/>
<Binding Path="AIState" Mode="OneWay"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>

View File

@@ -1,4 +1,5 @@
using Client.Domain.AI.State;
using Client.Domain.Common;
using Client.Domain.Entities;
using Client.Domain.Events;
using Client.Domain.Service;
@@ -13,7 +14,7 @@ using System.Windows.Input;
namespace Client.Domain.AI
{
public class AI : AIInterface
public class AI : ObservableObject, AIInterface
{
public AI(WorldHandler worldHandler, Config config, AsyncPathMoverInterface asyncPathMover, TransitionBuilderLocator locator)
{
@@ -27,16 +28,17 @@ namespace Client.Domain.AI
public void Toggle()
{
isEnabled = !isEnabled;
if (isEnabled)
IsEnabled = !IsEnabled;
if (IsEnabled)
{
ResetState();
}
}
public bool IsEnabled => isEnabled;
public bool IsEnabled { get { return isEnabled; } private set { if (isEnabled != value) { isEnabled = value; OnPropertyChanged(); } } }
public TypeEnum Type { get { return type; } set { if (type != value) { type = value; ResetState(); } } }
public TypeEnum Type { get { return type; } set { if (type != value) { type = value; ResetState(); OnPropertyChanged(); } } }
public BaseState.Type CurrentState { get { return currentState; } private set { if (currentState != value) { currentState = value; OnPropertyChanged(); } } }
public async Task Update()
{
@@ -44,19 +46,18 @@ namespace Client.Domain.AI
await Task.Run(() =>
{
if (isEnabled && worldHandler.Hero != null)
if (IsEnabled && worldHandler.Hero != null)
{
states[currentState].Execute();
states[CurrentState].Execute();
foreach (var transition in locator.Get(Type).Build(worldHandler, config, asyncPathMover))
{
if (transition.fromStates.ContainsKey(BaseState.Type.Any) && transition.toState != currentState || transition.fromStates.ContainsKey(currentState))
if (transition.fromStates.ContainsKey(BaseState.Type.Any) && transition.toState != CurrentState || transition.fromStates.ContainsKey(CurrentState))
{
if (transition.predicate(states[currentState]))
if (transition.predicate(states[CurrentState]))
{
states[currentState].OnLeave();
currentState = transition.toState;
Debug.WriteLine(currentState.ToString());
states[currentState].OnEnter();
states[CurrentState].OnLeave();
CurrentState = transition.toState;
states[CurrentState].OnEnter();
break;
}
}
@@ -87,7 +88,7 @@ namespace Client.Domain.AI
private void ResetState()
{
currentState = BaseState.Type.Idle;
CurrentState = BaseState.Type.Idle;
}
private readonly WorldHandler worldHandler;

View File

@@ -1,4 +1,6 @@
using Client.Domain.Events;
using Client.Domain.AI.State;
using Client.Domain.Common;
using Client.Domain.Events;
using System;
using System.Collections.Generic;
using System.Data;
@@ -8,7 +10,7 @@ using System.Threading.Tasks;
namespace Client.Domain.AI
{
public interface AIInterface
public interface AIInterface : ObservableObjectInterface
{
Task Update();
@@ -17,5 +19,6 @@ namespace Client.Domain.AI
bool IsEnabled { get; }
TypeEnum Type { get; set; }
BaseState.Type CurrentState { get; }
}
}

View File

@@ -34,7 +34,7 @@ namespace Client.Domain.AI.Combat
return null;
}
public static List<Drop> GetDropByConfig(WorldHandler worldHandler, Config config)
public static List<Drop> 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();
}

View File

@@ -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;
@@ -99,11 +96,6 @@ namespace Client.Domain.AI.Combat
return false;
}
if (!pathMover.Pathfinder.HasLineOfSight(worldHandler.Hero.Transform.Position, worldHandler.Hero.Target.Transform.Position))
{
return false;
}
if (config.Combat.SpoilIsPriority) {
var spoil = worldHandler.GetSkillById(config.Combat.SpoilSkillId);
if (spoil != null && !spoil.IsReadyToUse) {
@@ -112,7 +104,8 @@ namespace Client.Domain.AI.Combat
}
var distance = worldHandler.Hero.Transform.Position.HorizontalDistance(worldHandler.Hero.Target.Transform.Position);
return distance < Helper.GetAttackDistanceByConfig(worldHandler, config, worldHandler.Hero, worldHandler.Hero.Target);
return distance < Helper.GetAttackDistanceByConfig(worldHandler, config, worldHandler.Hero, worldHandler.Hero.Target)
&& pathMover.Pathfinder.HasLineOfSight(worldHandler.Hero.Transform.Position, worldHandler.Hero.Target.Transform.Position);
}),
new(new List<BaseState.Type>{BaseState.Type.Attack}, BaseState.Type.Pickup, (state) => {
if (worldHandler.Hero == null) {

View File

@@ -33,6 +33,7 @@ namespace Client.Domain.AI
public uint AttackDistanceBow { get; set; } = 500;
public bool UseOnlySkills { get; set; } = false;
public List<SkillCondition> SkillConditions { get; set; } = new List<SkillCondition>();
public byte MaxPassableHeight { get; set; } = 30;
public bool SpoilIfPossible { get; set; } = true;
public bool SpoilIsPriority { get; set; } = false;
@@ -47,6 +48,7 @@ namespace Client.Domain.AI
public byte PickupAttemptsCount { get; set; } = 10;
public Dictionary<uint, bool> ExcludedItemIdsToPickup { get; set; } = new Dictionary<uint, bool>();
public Dictionary<uint, bool> IncludedItemIdsToPickup { get; set; } = new Dictionary<uint, bool>();
public short PickupRadius = 200;
}
public class DelevelingSection

View File

@@ -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);
}
}
}

View File

@@ -1,7 +1,8 @@
using Client.Domain.AI.Combat;
using Client.Domain.Entities;
using Client.Domain.Service;
using Client.Infrastructure.Service;
using Client.Domain.ValueObjects;
using System;
namespace Client.Domain.AI.State
{
@@ -19,17 +20,32 @@ namespace Client.Domain.AI.State
target = hero;
}
var distance = hero.Transform.Position.HorizontalDistance(target.Transform.Position);
var distanceToPrevPosition = targetPosition != null ? targetPosition.HorizontalDistance(target.Transform.Position) : 0;
var routeNeedsToBeAdjusted = MathF.Abs(distanceToPrevPosition) > config.Combat.AttackDistanceMili;
if (routeNeedsToBeAdjusted)
{
asyncPathMover.Unlock();
}
if (asyncPathMover.IsLocked)
{
return;
}
var hasLineOfSight = asyncPathMover.Pathfinder.HasLineOfSight(hero.Transform.Position, target.Transform.Position);
if (distance >= Helper.GetAttackDistanceByConfig(worldHandler, config, hero, target) || !hasLineOfSight)
var distance = hero.Transform.Position.HorizontalDistance(target.Transform.Position);
if (routeNeedsToBeAdjusted || distance >= Helper.GetAttackDistanceByConfig(worldHandler, config, hero, target) || !asyncPathMover.Pathfinder.HasLineOfSight(hero.Transform.Position, target.Transform.Position))
{
asyncPathMover.MoveAsync(target.Transform.Position);
targetPosition = target.Transform.Position.Clone() as Vector3;
asyncPathMover.MoveAsync(target.Transform.Position, config.Combat.MaxPassableHeight);
}
}
protected override void DoOnLeave(WorldHandler worldHandler, Config config, Hero hero)
{
targetPosition = null;
}
private Vector3? targetPosition = null;
}
}

View File

@@ -15,7 +15,14 @@ namespace Client.Domain.AI.State
public List<Drop> GetDrops(WorldHandler worldHandler, Config config)
{
var drops = Helper.GetDropByConfig(worldHandler, config);
var hero = worldHandler.Hero;
if (hero == null)
{
return new List<Drop>();
}
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)

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Client.Domain.Common
{
public class ObservableObject : INotifyPropertyChanged
public class ObservableObject : ObservableObjectInterface
{
public event PropertyChangedEventHandler? PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string prop = "")

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace Client.Domain.Common
{
public interface ObservableObjectInterface : INotifyPropertyChanged
{
void OnPropertyChanged([CallerMemberName] string prop = "");
}
}

View File

@@ -13,10 +13,9 @@ namespace Client.Domain.Service
{
public PathfinderInterface Pathfinder { get; }
public ObservableCollection<PathSegment> Path { get; }
public Task<bool> MoveAsync(Vector3 location, ushort maxPassableHeight);
public Task<bool> MoveAsync(Vector3 location);
public Task MoveUntilReachedAsync(Vector3 location);
public bool IsLocked { get; }
public void Unlock();
}
}

View File

@@ -10,7 +10,7 @@ namespace Client.Domain.Service
{
public interface PathfinderInterface
{
public List<PathSegment> FindPath(Vector3 start, Vector3 end);
public List<PathSegment> FindPath(Vector3 start, Vector3 end, ushort maxPassableHeight);
public bool HasLineOfSight(Vector3 start, Vector3 end);
}
}

View File

@@ -3,7 +3,7 @@ using System;
namespace Client.Domain.ValueObjects
{
public class Vector3 : ObservableObject
public class Vector3 : ObservableObject, ICloneable
{
private float x;
private float y;
@@ -77,6 +77,11 @@ namespace Client.Domain.ValueObjects
return MathF.Sqrt(MathF.Pow(x - other.x, 2) + MathF.Pow(y - other.y, 2) + MathF.Pow(z - other.z, 2));
}
public object Clone()
{
return MemberwiseClone();
}
public static Vector3 operator -(Vector3 left, Vector3 right)
{
return new Vector3(left.x - right.x, left.y - right.y, left.z - right.z);

View File

@@ -11,13 +11,15 @@ namespace Client.Domain.ValueObjects
private uint maxMp;
private uint cp;
private uint maxCp;
private bool isDead;
public uint Hp { get => hp; set { if (value != hp) { hp = value; OnPropertyChanged(); OnPropertyChanged("MaxHp"); OnPropertyChanged("IsDead"); } } }
public uint MaxHp { get => Math.Max(hp, maxHp); set { if (value != maxHp) { maxHp = value; OnPropertyChanged(); OnPropertyChanged("IsDead"); } } }
public uint Hp { get => hp; set { if (value != hp) { hp = value; OnPropertyChanged(); OnPropertyChanged("MaxHp"); } } }
public uint MaxHp { get => Math.Max(hp, maxHp); set { if (value != maxHp) { maxHp = value; OnPropertyChanged(); } } }
public uint Mp { get => mp; set { if (value != mp) { mp = value; OnPropertyChanged(); } } }
public uint MaxMp { get => maxMp; set { if (value != maxMp) { maxMp = value; OnPropertyChanged(); } } }
public uint Cp { get => cp; set { if (value != cp) { cp = value; OnPropertyChanged(); } } }
public uint MaxCp { get => maxCp; set { if (value != maxCp) { maxCp = value; OnPropertyChanged(); } } }
public bool IsDead { get => isDead; set { if (value != isDead) { isDead = value; OnPropertyChanged(); } } }
public double HpPercent
{
@@ -41,9 +43,7 @@ namespace Client.Domain.ValueObjects
}
}
public bool IsDead => MaxHp > 0 && hp == 0;
public VitalStats(uint hp, uint maxHp, uint mp, uint maxMp, uint cp, uint maxCp)
public VitalStats(uint hp, uint maxHp, uint mp, uint maxMp, uint cp, uint maxCp, bool isDead)
{
this.hp = hp;
this.maxHp = maxHp;
@@ -51,6 +51,7 @@ namespace Client.Domain.ValueObjects
this.maxMp = maxMp;
this.cp = cp;
this.maxCp = maxCp;
this.isDead = isDead;
}
}
}

View File

@@ -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<bool> MoveAsync(Vector3 location)
public async Task<bool> 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<bool> 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);

View File

@@ -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<PathSegment> FindPath(Vector3 start, Vector3 end)
public List<PathSegment> 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<PathSegment> BuildPath(List<PathNode> 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;
}
}

Binary file not shown.

View File

@@ -31,7 +31,7 @@ namespace L2Bot::Domain::Entities
WorldObject::Update(transform);
m_FullName = fullName;
m_VitalStats = vitalStats;
m_VitalStats.LoadFromOther(vitalStats);
m_Phenotype = phenotype;
m_ExperienceInfo = experienceInfo;
m_PermanentStats = permanentStats;

View File

@@ -28,7 +28,7 @@ namespace L2Bot::Domain::Entities
m_IsHostile = isHostile;
m_NpcId = npcId;
m_FullName = fullName;
m_VitalStats = vitalStats;
m_VitalStats.LoadFromOther(vitalStats);
}
const size_t GetHash() const override
{
@@ -45,6 +45,10 @@ namespace L2Bot::Domain::Entities
{
return "npc";
}
void MarkAsDead()
{
m_VitalStats.MarkAsDead();
}
const std::vector<Serializers::Node> BuildSerializationNodes() const override
{

View File

@@ -19,7 +19,7 @@ namespace L2Bot::Domain::Entities
m_FullName = fullName;
m_Phenotype = phenotype;
m_VitalStats = vitalStats;
m_VitalStats.LoadFromOther(vitalStats);
}
const size_t GetHash() const override
{

View File

@@ -10,9 +10,9 @@ namespace L2Bot::Domain::ValueObjects
class VitalStats : public Serializers::Serializable, public Entities::Hashable
{
public:
const bool IsAlive() const
const bool IsDead() const
{
return m_MaxHp <= 0 || m_Hp > 0;
return m_IsDead || (m_MaxHp > 0 && m_Hp <= 0);
}
const uint32_t GetMaxHp() const
{
@@ -46,9 +46,19 @@ namespace L2Bot::Domain::ValueObjects
std::hash<uint32_t>{}(m_MaxMp),
std::hash<uint32_t>{}(m_Mp),
std::hash<uint32_t>{}(m_MaxCp),
std::hash<uint32_t>{}(m_Cp)
std::hash<uint32_t>{}(m_Cp),
std::hash<bool>{}(m_IsDead)
});
}
void LoadFromOther(VitalStats other)
{
m_MaxHp = other.m_MaxHp;
m_Hp = other.m_Hp;
m_MaxMp = other.m_MaxMp;
m_Mp = other.m_Mp;
m_MaxCp = other.m_MaxCp;
m_Cp = other.m_Cp;
}
const std::vector<Serializers::Node> BuildSerializationNodes() const override
{
@@ -59,9 +69,14 @@ namespace L2Bot::Domain::ValueObjects
{ L"maxMp", std::to_wstring(m_MaxMp) },
{ L"mp", std::to_wstring(m_Mp) },
{ L"maxCp", std::to_wstring(m_MaxCp) },
{ L"cp", std::to_wstring(m_Cp) }
{ L"cp", std::to_wstring(m_Cp) },
{ L"isDead", std::to_wstring(IsDead()) }
};
}
void MarkAsDead()
{
m_IsDead = true;;
}
VitalStats(
uint32_t maxHp,
@@ -90,5 +105,6 @@ namespace L2Bot::Domain::ValueObjects
uint32_t m_Mp = 0;
uint32_t m_MaxCp = 0;
uint32_t m_Cp = 0;
uint32_t m_IsDead = false;
};
}

View File

@@ -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;
const uint16_t Application::DROP_RADIUS = 4000;

View File

@@ -103,7 +103,11 @@ namespace Interlude
{
if (m_Hero->GetId() == casted.GetTargetId())
{
m_Hero->AddAttacker(casted.GetAttackerId());
const auto attacker = m_NetworkHandler.GetUser(casted.GetAttackerId());
if (attacker && attacker->userType == L2::UserType::NPC)
{
m_Hero->AddAttacker(casted.GetAttackerId());
}
}
else if (casted.GetAttackerId() != casted.GetTargetId())
{

View File

@@ -111,6 +111,9 @@ namespace Interlude
m_Spoiled[casted.GetCreatureId()] = Enums::SpoilStateEnum::none;
}
}
if (m_Npcs.find(casted.GetCreatureId()) != m_Npcs.end()) {
m_Npcs[casted.GetCreatureId()]->MarkAsDead();
}
}
}