Compare commits
14 Commits
0.0.1-alph
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa078bcead | ||
|
|
f50e218013 | ||
|
|
ee37ffb219 | ||
|
|
ca86371137 | ||
|
|
e0ffa3a62e | ||
|
|
936697defc | ||
|
|
d0baa5c21a | ||
|
|
914f6ba20f | ||
|
|
4e2e108076 | ||
|
|
ad7a4c3074 | ||
|
|
5f19cc1f76 | ||
|
|
abadf90d4a | ||
|
|
4a45d1d615 | ||
|
|
248099b323 |
@@ -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")
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
MouseLeave="ContentControl_MouseLeave"
|
||||
MouseMove="ContentControl_MouseMove"
|
||||
>
|
||||
<ContentControl.Resources>
|
||||
<BitmapImage x:Key="FallbackImage" UriSource="../../Assets/maps/fallback.jpg" />
|
||||
<Int32Collection x:Key="mapLevels">0,1,2,3,4,5</Int32Collection>
|
||||
</ContentControl.Resources>
|
||||
<Grid Background="Transparent">
|
||||
<Grid.InputBindings>
|
||||
<MouseBinding Gesture="LeftClick" Command="{Binding MouseLeftClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Grid}}" />
|
||||
@@ -29,7 +33,7 @@
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Image
|
||||
Source="{Binding ImageSource,Mode=OneWay}"
|
||||
Source="{Binding ImageSource,Mode=OneWay,FallbackValue={StaticResource FallbackImage},TargetNullValue={StaticResource FallbackImage}}"
|
||||
Width="{Binding Size,Mode=OneWay}"
|
||||
Height="{Binding Size,Mode=OneWay}"
|
||||
Visibility="{Binding Visible,Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
@@ -286,10 +290,17 @@
|
||||
<StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Right" Background="#66ffffff">
|
||||
<Grid Margin="10 5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"></ColumnDefinition>
|
||||
<ColumnDefinition Width="90"></ColumnDefinition>
|
||||
<ColumnDefinition Width="30"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Padding="0 0 0 3">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label>Map level:</Label>
|
||||
<ComboBox
|
||||
SelectedValue="{Binding MapLevel}"
|
||||
ItemsSource="{StaticResource mapLevels}" Margin="0,0,10,0"/>
|
||||
</StackPanel>
|
||||
<TextBlock Grid.Column="1" Padding="0 0 0 3" VerticalAlignment="Center">
|
||||
<TextBlock.Text>
|
||||
<MultiBinding StringFormat="{}{0:F0}, {1:F0}">
|
||||
<Binding Path="MousePosition.X" Mode="OneWay"/>
|
||||
@@ -297,7 +308,7 @@
|
||||
</MultiBinding>
|
||||
</TextBlock.Text>
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="1" Text="{Binding Scale,Mode=OneWay,StringFormat='{}1:{0}'}" HorizontalAlignment="Right" />
|
||||
<Label Grid.Column="2" Content="{Binding Scale,Mode=OneWay,StringFormat='{}1:{0}'}" HorizontalAlignment="Right" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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")
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Client.Application.ViewModels
|
||||
{
|
||||
public class MapBlockViewModel : ObservableObject
|
||||
{
|
||||
public string ImageSource => "/Assets/maps/" + mapBlock.BlockX + "_" + mapBlock.BlockY + ".jpg";
|
||||
public string ImageSource => "/Assets/maps/" + mapBlock.BlockX + "_" + mapBlock.BlockY + (mapBlock.Level > 0 ? "_" + mapBlock.Level : "") + ".jpg";
|
||||
public float DeltaX => mapBlock.DeltaX;
|
||||
public float DeltaY => mapBlock.DeltaY;
|
||||
public float Size => mapBlock.Size;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Client.Application.Commands;
|
||||
using Client.Application.Components;
|
||||
using Client.Domain.Common;
|
||||
using Client.Domain.DTO;
|
||||
using Client.Domain.Entities;
|
||||
@@ -83,6 +84,19 @@ namespace Client.Application.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public int MapLevel
|
||||
{
|
||||
get => mapLevel;
|
||||
set
|
||||
{
|
||||
if (mapLevel != value)
|
||||
{
|
||||
mapLevel = value;
|
||||
UpdateMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 MousePosition
|
||||
{
|
||||
get => mousePosition;
|
||||
@@ -107,7 +121,7 @@ namespace Client.Application.ViewModels
|
||||
|
||||
if (hero != null)
|
||||
{
|
||||
var blocks = selector.SelectImages((float)ViewportWidth, (float)ViewportHeight, hero.Transform.Position, Scale);
|
||||
var blocks = selector.SelectImages((float)ViewportWidth, (float)ViewportHeight, hero.Transform.Position, Scale, MapLevel);
|
||||
|
||||
foreach (var block in blocks)
|
||||
{
|
||||
@@ -155,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)
|
||||
@@ -216,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();
|
||||
}
|
||||
}
|
||||
@@ -328,7 +347,7 @@ namespace Client.Application.ViewModels
|
||||
public readonly static float MAX_SCALE = 128;
|
||||
private readonly AsyncPathMoverInterface pathMover;
|
||||
private MapImageSelector selector = new MapImageSelector();
|
||||
private Dictionary<uint, MapBlockViewModel> blocks = new Dictionary<uint, MapBlockViewModel>();
|
||||
private Dictionary<int, MapBlockViewModel> blocks = new Dictionary<int, MapBlockViewModel>();
|
||||
private Hero? hero;
|
||||
private float scale = 8;
|
||||
private double viewportWidth = 0;
|
||||
@@ -336,5 +355,6 @@ namespace Client.Application.ViewModels
|
||||
private Vector3 mousePosition = new Vector3(0, 0, 0);
|
||||
private object pathCollectionLock = new object();
|
||||
private AICombatZoneMapViewModel? combatZone = null;
|
||||
private int mapLevel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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>
|
||||
|
||||
BIN
Client/Assets/maps/fallback.jpg
Normal file
BIN
Client/Assets/maps/fallback.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
@@ -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();
|
||||
foreach (var transition in locator.Get(Type).Build())
|
||||
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(worldHandler, config, 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;
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,17 +27,14 @@ namespace Client.Domain.AI.Combat
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (skill.IsReadyToUse && hero.VitalStats.Mp >= skill.Cost)
|
||||
{
|
||||
return skill;
|
||||
}
|
||||
return skill;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -52,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();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,32 +12,29 @@ namespace Client.Domain.AI.Combat
|
||||
{
|
||||
public class TransitionBuilder : TransitionBuilderInterface
|
||||
{
|
||||
public List<TransitionBuilderInterface.Transition> Build()
|
||||
public List<TransitionBuilderInterface.Transition> Build(WorldHandler worldHandler, Config config, AsyncPathMoverInterface pathMover)
|
||||
{
|
||||
if (transitions.Count == 0)
|
||||
{
|
||||
transitions = new List<TransitionBuilderInterface.Transition>()
|
||||
{
|
||||
new(new List<BaseState.Type>{BaseState.Type.Any}, BaseState.Type.Dead, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.Any}, BaseState.Type.Dead, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
return worldHandler.Hero.VitalStats.IsDead;
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.Dead}, BaseState.Type.Idle, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.Dead}, BaseState.Type.Idle, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
return !worldHandler.Hero.VitalStats.IsDead;
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.Idle, BaseState.Type.MoveToTarget, BaseState.Type.Rest, BaseState.Type.MoveToSpot}, BaseState.Type.FindTarget, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.Idle, BaseState.Type.MoveToTarget, BaseState.Type.Rest, BaseState.Type.MoveToSpot}, BaseState.Type.FindTarget, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
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;
|
||||
@@ -45,13 +42,13 @@ namespace Client.Domain.AI.Combat
|
||||
|
||||
return worldHandler.Hero.AttackerIds.Count > 0;
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.FindTarget}, BaseState.Type.MoveToTarget, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.FindTarget}, BaseState.Type.MoveToTarget, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
return worldHandler.Hero.HasValidTarget;
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.FindTarget}, BaseState.Type.MoveToSpot, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.FindTarget}, BaseState.Type.MoveToSpot, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -59,7 +56,7 @@ namespace Client.Domain.AI.Combat
|
||||
return Helper.GetMobsToAttackByConfig(worldHandler, config, worldHandler.Hero).Count == 0
|
||||
&& !Helper.IsOnSpot(worldHandler, config, worldHandler.Hero);
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.MoveToSpot}, BaseState.Type.Idle, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.MoveToSpot}, BaseState.Type.Idle, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -70,27 +67,27 @@ namespace Client.Domain.AI.Combat
|
||||
|
||||
return Helper.IsOnSpot(worldHandler, config, worldHandler.Hero);
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.MoveToTarget}, BaseState.Type.Idle, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.MoveToTarget}, BaseState.Type.Idle, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
return !worldHandler.Hero.HasValidTarget;
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.Idle}, BaseState.Type.Rest, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.Idle}, BaseState.Type.Rest, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
};
|
||||
return worldHandler.Hero.AttackerIds.Count == 0 && (worldHandler.Hero.VitalStats.HpPercent < config.Combat.RestStartPercentHp
|
||||
|| worldHandler.Hero.VitalStats.MpPercent < config.Combat.RestStartPecentMp);
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.Rest}, BaseState.Type.Idle, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.Rest}, BaseState.Type.Idle, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
return worldHandler.Hero.VitalStats.HpPercent >= config.Combat.RestEndPecentHp
|
||||
&& worldHandler.Hero.VitalStats.MpPercent >= config.Combat.RestEndPecentMp;
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.MoveToTarget}, BaseState.Type.Attack, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.MoveToTarget}, BaseState.Type.Attack, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -107,23 +104,24 @@ 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, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.Attack}, BaseState.Type.Pickup, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !worldHandler.Hero.HasValidTarget;
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.Attack}, BaseState.Type.FindTarget, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.Attack}, BaseState.Type.FindTarget, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return worldHandler.Hero.HasValidTarget && worldHandler.Hero.AttackerIds.Count > 0 && !worldHandler.Hero.AttackerIds.Contains(worldHandler.Hero.TargetId);
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.Pickup}, BaseState.Type.Idle, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.Pickup}, BaseState.Type.Idle, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -12,37 +12,39 @@ namespace Client.Domain.AI.Deleveling
|
||||
{
|
||||
public class TransitionBuilder : TransitionBuilderInterface
|
||||
{
|
||||
public List<TransitionBuilderInterface.Transition> Build()
|
||||
|
||||
// todo add MoveToDropState, SweepState
|
||||
public List<TransitionBuilderInterface.Transition> Build(WorldHandler worldHandler, Config config, AsyncPathMoverInterface pathMover)
|
||||
{
|
||||
if (transitions.Count == 0)
|
||||
{
|
||||
transitions = new List<TransitionBuilderInterface.Transition>()
|
||||
{
|
||||
new(new List<BaseState.Type>{BaseState.Type.Any}, BaseState.Type.Dead, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.Any}, BaseState.Type.Dead, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
return worldHandler.Hero.VitalStats.IsDead;
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.Dead}, BaseState.Type.Idle, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.Dead}, BaseState.Type.Idle, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
return !worldHandler.Hero.VitalStats.IsDead;
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.FindGuard}, BaseState.Type.MoveToTarget, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.FindGuard}, BaseState.Type.MoveToTarget, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
return worldHandler.Hero.Target != null;
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.MoveToTarget}, BaseState.Type.Idle, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.MoveToTarget}, BaseState.Type.Idle, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
return worldHandler.Hero.Target == null;
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.MoveToTarget}, BaseState.Type.AttackGuard, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.MoveToTarget}, BaseState.Type.AttackGuard, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -55,7 +57,7 @@ namespace Client.Domain.AI.Deleveling
|
||||
var expectedDistance = config.Deleveling.AttackDistance;
|
||||
return distance < expectedDistance;
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.AttackGuard}, BaseState.Type.FindGuard, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.AttackGuard}, BaseState.Type.FindGuard, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -68,7 +70,7 @@ namespace Client.Domain.AI.Deleveling
|
||||
var expectedDistance = config.Deleveling.AttackDistance;
|
||||
return distance >= expectedDistance;
|
||||
}),
|
||||
new(new List<BaseState.Type>{BaseState.Type.Idle}, BaseState.Type.FindGuard, (worldHandler, config, state) => {
|
||||
new(new List<BaseState.Type>{BaseState.Type.Idle}, BaseState.Type.FindGuard, (state) => {
|
||||
if (worldHandler.Hero == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Client.Domain.AI.State
|
||||
}
|
||||
|
||||
var skill = Helper.GetSkillByConfig(worldHandler, config, hero, hero.Target);
|
||||
if (skill != null)
|
||||
if (skill != null && skill.IsReadyToUse && hero.VitalStats.Mp >= skill.Cost)
|
||||
{
|
||||
worldHandler.RequestUseSkill(skill.Id, false, false);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,16 +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;
|
||||
}
|
||||
if (distance >= Helper.GetAttackDistanceByConfig(worldHandler, config, hero, target))
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -14,16 +14,16 @@ namespace Client.Domain.AI
|
||||
{
|
||||
public readonly Dictionary<BaseState.Type, BaseState.Type> fromStates;
|
||||
public readonly BaseState.Type toState;
|
||||
public readonly Func<WorldHandler, Config, BaseState, bool> predicate;
|
||||
public readonly Func<BaseState, bool> predicate;
|
||||
|
||||
public Transition(List<BaseState.Type> fromStates, BaseState.Type toState, Func<WorldHandler, Config, BaseState, bool>? predicate = null)
|
||||
public Transition(List<BaseState.Type> fromStates, BaseState.Type toState, Func<BaseState, bool>? predicate = null)
|
||||
{
|
||||
this.fromStates = fromStates.ToDictionary(x => x, x => x);
|
||||
this.toState = toState;
|
||||
this.predicate = predicate != null ? predicate : (worldHandler, config, state) => { return true; };
|
||||
this.predicate = predicate != null ? predicate : (state) => { return true; };
|
||||
}
|
||||
}
|
||||
|
||||
List<Transition> Build();
|
||||
List<Transition> Build(WorldHandler worldHandler, Config config, AsyncPathMoverInterface pathMover);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = "")
|
||||
|
||||
15
Client/Domain/Common/ObservableObjectInterface.cs
Normal file
15
Client/Domain/Common/ObservableObjectInterface.cs
Normal 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 = "");
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,11 @@ namespace Client.Domain.Service
|
||||
{
|
||||
public interface AsyncPathMoverInterface
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Client.Domain.Service
|
||||
private static readonly uint DELTA_X = 20;
|
||||
private static readonly uint DELTA_Y = 18;
|
||||
|
||||
public List<MapBlock> SelectImages(float viewportWidth, float viewportHeight, Vector3 heroPosition, float scale)
|
||||
public List<MapBlock> SelectImages(float viewportWidth, float viewportHeight, Vector3 heroPosition, float scale, int level)
|
||||
{
|
||||
var viewportCenter = new Tuple<float, float>(viewportWidth / 2, viewportHeight / 2);
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Client.Domain.Service
|
||||
(blockTopLeft.Item2 - topLeft.Item2) / scale
|
||||
);
|
||||
|
||||
result.Add(new MapBlock(x, y, delta.Item1, delta.Item2, BLOCK_SIZE / scale));
|
||||
result.Add(new MapBlock(x, y, delta.Item1, delta.Item2, BLOCK_SIZE / scale, level));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,20 +13,24 @@ namespace Client.Domain.ValueObjects
|
||||
private float deltaY;
|
||||
private float size;
|
||||
|
||||
public uint Id => (BlockX + BlockY) * (BlockX + BlockY + 1) / 2 + BlockX;
|
||||
public int Id => (IdWithOutLevel + Level) * (IdWithOutLevel + Level + 1) / 2 + IdWithOutLevel;
|
||||
public uint BlockX { get; set; }
|
||||
public uint BlockY { get; set; }
|
||||
public float DeltaX { get => deltaX; set { if (value != deltaX) { deltaX = value; OnPropertyChanged(); } } }
|
||||
public float DeltaY { get => deltaY; set { if (value != deltaY) { deltaY = value; OnPropertyChanged(); } } }
|
||||
public float Size { get => size; set { if (value != size) { size = value; OnPropertyChanged(); } } }
|
||||
public int Level { get; set; }
|
||||
|
||||
public MapBlock(uint blockX, uint blockY, float deltaX, float deltaY, float size)
|
||||
private int IdWithOutLevel => (int) ((BlockX + BlockY) * (BlockX + BlockY + 1) / 2 + BlockX);
|
||||
|
||||
public MapBlock(uint blockX, uint blockY, float deltaX, float deltaY, float size, int level)
|
||||
{
|
||||
BlockX = blockX;
|
||||
BlockY = blockY;
|
||||
DeltaX = deltaX;
|
||||
DeltaY = deltaY;
|
||||
Size = size;
|
||||
Level = level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,13 @@ 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;
|
||||
public ObservableCollection<PathSegment> Path { get; private set; } = new ObservableCollection<PathSegment>();
|
||||
public bool IsLocked { get; private set; } = false;
|
||||
|
||||
@@ -42,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;
|
||||
|
||||
@@ -68,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");
|
||||
|
||||
|
||||
@@ -98,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;
|
||||
|
||||
@@ -118,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);
|
||||
|
||||
@@ -17,13 +17,15 @@ namespace Client.Infrastructure.Service
|
||||
[DllImport("L2JGeoDataPathFinder.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern uint ReleasePath(IntPtr arrayPtr);
|
||||
|
||||
public L2jGeoDataPathfinder(string geodataDirectory, ushort maxPassableHeight)
|
||||
[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)
|
||||
{
|
||||
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);
|
||||
@@ -48,6 +50,11 @@ namespace Client.Infrastructure.Service
|
||||
return BuildPath(nodes);
|
||||
}
|
||||
|
||||
public bool HasLineOfSight(Vector3 start, Vector3 end)
|
||||
{
|
||||
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)
|
||||
{
|
||||
var result = new List<PathSegment>();
|
||||
@@ -90,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.
@@ -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;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -52,7 +52,7 @@ namespace Interlude
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
throw CriticalRuntimeException(L"UNetworkHandler::GetNextCreature failed");
|
||||
throw RuntimeException(L"UNetworkHandler::GetNextCreature failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace Interlude
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
throw CriticalRuntimeException(L"UNetworkHandler::GetUser failed");
|
||||
throw RuntimeException(L"UNetworkHandler::GetUser failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace Interlude
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
throw CriticalRuntimeException(L"UNetworkHandler::GetItem failed");
|
||||
throw RuntimeException(L"UNetworkHandler::GetItem failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace Interlude
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
throw CriticalRuntimeException(L"UNetworkHandler::MTL failed");
|
||||
throw RuntimeException(L"UNetworkHandler::MTL failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace Interlude
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
throw CriticalRuntimeException(L"UNetworkHandler::Action failed");
|
||||
throw RuntimeException(L"UNetworkHandler::Action failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace Interlude
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
throw CriticalRuntimeException(L"UNetworkHandler::RequestMagicSkillUse failed");
|
||||
throw RuntimeException(L"UNetworkHandler::RequestMagicSkillUse failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace Interlude
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
throw CriticalRuntimeException(L"UNetworkHandler::RequestUseItem failed");
|
||||
throw RuntimeException(L"UNetworkHandler::RequestUseItem failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ namespace Interlude
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
throw CriticalRuntimeException(L"UNetworkHandler::RequestAutoSoulShot failed");
|
||||
throw RuntimeException(L"UNetworkHandler::RequestAutoSoulShot failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace Interlude
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
throw CriticalRuntimeException(L"UNetworkHandler::ChangeWaitType failed");
|
||||
throw RuntimeException(L"UNetworkHandler::ChangeWaitType failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ namespace Interlude
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
throw CriticalRuntimeException(L"UNetworkHandler::RequestItemList failed");
|
||||
throw RuntimeException(L"UNetworkHandler::RequestItemList failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace Interlude
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
throw CriticalRuntimeException(L"UNetworkHandler::RequestRestartPoint failed");
|
||||
throw RuntimeException(L"UNetworkHandler::RequestRestartPoint failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
README.md
11
README.md
@@ -18,3 +18,14 @@ Communication between the client and the injected code occurs through a named pi
|
||||
Pathfinding is done using [L2jGeodataPathFinder](https://github.com/k0t9i/L2jGeodataPathFinder).
|
||||
|
||||

|
||||
|
||||
## AI
|
||||
The bot client have two AI: combat and deleveling.
|
||||
|
||||
Combat AI can attack and spoil mobs in any combination depending on the settings. It can also collect the selected drop and rest when it reaches a certain level of HP and MP.
|
||||
|
||||
Deleveling AI can automatically attack guards in any town/village until it reaches a configured level.
|
||||
|
||||
Both AIs use pathfinding to achieve desired goals.
|
||||
|
||||

|
||||
|
||||
Reference in New Issue
Block a user