feat: add ai type and state info
This commit is contained in:
parent
ee37ffb219
commit
f50e218013
@ -1,4 +1,5 @@
|
||||
using Client.Domain.Common;
|
||||
using Client.Domain.AI;
|
||||
using Client.Domain.Common;
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.ValueObjects;
|
||||
using System;
|
||||
@ -59,13 +60,6 @@ namespace Client.Application.ViewModels
|
||||
return hero.InventoryInfo;
|
||||
}
|
||||
}
|
||||
public ulong Money
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public TargetSummaryInfoViewModel? Target
|
||||
{
|
||||
@ -81,10 +75,24 @@ 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 HeroSummaryInfoViewModel(Hero hero, AIInterface ai)
|
||||
{
|
||||
this.hero = hero;
|
||||
|
||||
this.ai = ai;
|
||||
hero.FullName.PropertyChanged += FullName_PropertyChanged;
|
||||
hero.Phenotype.PropertyChanged += Phenotype_PropertyChanged;
|
||||
hero.ExperienceInfo.PropertyChanged += ExperienceInfo_PropertyChanged;
|
||||
@ -92,6 +100,19 @@ namespace Client.Application.ViewModels
|
||||
hero.VitalStats.PropertyChanged += VitalStats_PropertyChanged;
|
||||
hero.InventoryInfo.PropertyChanged += InventoryInfo_PropertyChanged;
|
||||
hero.PropertyChanged += Hero_PropertyChanged;
|
||||
ai.PropertyChanged += Ai_PropertyChanged;
|
||||
}
|
||||
|
||||
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)
|
||||
@ -147,6 +168,7 @@ namespace Client.Application.ViewModels
|
||||
}
|
||||
|
||||
private readonly Hero hero;
|
||||
private readonly AIInterface ai;
|
||||
private TargetSummaryInfoViewModel? target;
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ namespace Client.Application.ViewModels
|
||||
|
||||
public void Handle(HeroCreatedEvent @event)
|
||||
{
|
||||
Hero = new HeroSummaryInfoViewModel(@event.Hero);
|
||||
Hero = new HeroSummaryInfoViewModel(@event.Hero, ai);
|
||||
hero = @event.Hero;
|
||||
Map.Hero = hero;
|
||||
Map.CombatZone = new AICombatZoneMapViewModel(aiConfig.Combat.Zone, hero);
|
||||
|
@ -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,7 +254,6 @@
|
||||
</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}">
|
||||
@ -263,6 +262,14 @@
|
||||
</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>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
<StackPanel Grid.Column="1" DataContext="{Binding Target, Mode=OneWay}" Visibility="{Binding Path=.,Converter={StaticResource NullToVisibilityConverter}}" Margin="4">
|
||||
|
@ -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;
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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 = "");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user