feat: add skills

This commit is contained in:
k0t9i 2023-02-01 00:30:20 +04:00
parent 823241ef32
commit 32fdef9b1c
13 changed files with 310 additions and 14 deletions

View File

@ -93,12 +93,14 @@ namespace Client
.AddTransient(typeof(EntityFactoryInterface<NPC>), typeof(EntityFactory<NPC>)) .AddTransient(typeof(EntityFactoryInterface<NPC>), typeof(EntityFactory<NPC>))
.AddTransient(typeof(EntityFactoryInterface<Player>), typeof(EntityFactory<Player>)) .AddTransient(typeof(EntityFactoryInterface<Player>), typeof(EntityFactory<Player>))
.AddTransient(typeof(EntityFactoryInterface<ChatMessage>), typeof(EntityFactory<ChatMessage>)) .AddTransient(typeof(EntityFactoryInterface<ChatMessage>), typeof(EntityFactory<ChatMessage>))
.AddTransient(typeof(EntityFactoryInterface<Skill>), typeof(EntityFactory<Skill>))
.AddSingleton<HeroHandler>() .AddSingleton<HeroHandler>()
.AddSingleton<DropHandler>() .AddSingleton<DropHandler>()
.AddSingleton<NpcHandler>() .AddSingleton<NpcHandler>()
.AddSingleton<PlayerHandler>() .AddSingleton<PlayerHandler>()
.AddSingleton<ChatMessageHandler>() .AddSingleton<ChatMessageHandler>()
.AddSingleton<SkillHandler>()
.AddSingleton<MainViewModel>(); .AddSingleton<MainViewModel>();
} }

View File

@ -24,7 +24,9 @@ namespace Client.Application.ViewModels
EventHandlerInterface<CreatureDeletedEvent>, EventHandlerInterface<CreatureDeletedEvent>,
EventHandlerInterface<DropCreatedEvent>, EventHandlerInterface<DropCreatedEvent>,
EventHandlerInterface<DropDeletedEvent>, EventHandlerInterface<DropDeletedEvent>,
EventHandlerInterface<ChatMessageCreatedEvent> EventHandlerInterface<ChatMessageCreatedEvent>,
EventHandlerInterface<SkillCreatedEvent>,
EventHandlerInterface<SkillDeletedEvent>
{ {
public void Handle(HeroCreatedEvent @event) public void Handle(HeroCreatedEvent @event)
{ {
@ -71,9 +73,32 @@ namespace Client.Application.ViewModels
ChatMessages.Add(new ChatMessageViewModel(@event.Message)); ChatMessages.Add(new ChatMessageViewModel(@event.Message));
} }
public void Handle(SkillCreatedEvent @event)
{
if (hero != null)
{
if (@event.Skill.IsActive)
{
ActiveSkills.Add(new SkillListViewModel(@event.Skill));
}
else
{
PassiveSkills.Add(new SkillListViewModel(@event.Skill));
}
}
}
public void Handle(SkillDeletedEvent @event)
{
ActiveSkills.RemoveAll(x => x.Id == @event.Id);
PassiveSkills.RemoveAll(x => x.Id == @event.Id);
}
public ObservableCollection<ChatMessageViewModel> ChatMessages { get; } = new ObservableCollection<ChatMessageViewModel>(); public ObservableCollection<ChatMessageViewModel> ChatMessages { get; } = new ObservableCollection<ChatMessageViewModel>();
public ObservableCollection<CreatureListViewModel> Creatures { get; } = new ObservableCollection<CreatureListViewModel>(); public ObservableCollection<CreatureListViewModel> Creatures { get; } = new ObservableCollection<CreatureListViewModel>();
public ObservableCollection<DropListViewModel> Drops { get; } = new ObservableCollection<DropListViewModel>(); public ObservableCollection<DropListViewModel> Drops { get; } = new ObservableCollection<DropListViewModel>();
public ObservableCollection<SkillListViewModel> ActiveSkills { get; } = new ObservableCollection<SkillListViewModel>();
public ObservableCollection<SkillListViewModel> PassiveSkills { get; } = new ObservableCollection<SkillListViewModel>();
public HeroSummaryInfoViewModel? Hero { get; private set; } public HeroSummaryInfoViewModel? Hero { get; private set; }
public Hero? hero; public Hero? hero;
} }

View File

@ -0,0 +1,66 @@
using Client.Domain.Common;
using Client.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.Application.ViewModels
{
public class SkillListViewModel : ObservableObject
{
public uint Id => skill.Id;
public string Name => skill.Name;
public uint Level => skill.Level;
public string Description=> skill.Description;
public string IconName => "/Assets/icons/" + skill.IconName + ".png";
public bool IsActive => skill.IsActive;
public bool IsReadyToUse => skill.IsReadyToUse;
public bool IsBusy => !skill.IsReadyToUse;
public uint Cost => skill.Cost;
public int Range => skill.Range;
public SkillListViewModel(Skill skill)
{
this.skill = skill;
skill.PropertyChanged += Skill_PropertyChanged;
}
private void Skill_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "Description")
{
OnPropertyChanged("Description");
}
if (e.PropertyName == "IsReadyToUse")
{
OnPropertyChanged("IsBusy");
OnPropertyChanged("IsReadyToUse");
}
if (e.PropertyName == "Level")
{
OnPropertyChanged("Level");
}
if (e.PropertyName == "Cost")
{
OnPropertyChanged("Cost");
}
if (e.PropertyName == "Range")
{
OnPropertyChanged("Range");
}
if (e.PropertyName == "Name")
{
OnPropertyChanged("Name");
}
if (e.PropertyName == "IconName")
{
OnPropertyChanged("IconName");
}
}
private readonly Skill skill;
}
}

View File

@ -5,6 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Client" xmlns:local="clr-namespace:Client"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase" xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:ctrls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
xmlns:converters="clr-namespace:Client.Application.Converters" xmlns:converters="clr-namespace:Client.Application.Converters"
xmlns:components="clr-namespace:Client.Application.Components" xmlns:components="clr-namespace:Client.Application.Components"
mc:Ignorable="d" mc:Ignorable="d"
@ -21,11 +22,12 @@
</CollectionViewSource.SortDescriptions> </CollectionViewSource.SortDescriptions>
</CollectionViewSource> </CollectionViewSource>
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/> <converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
<ctrls:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</Window.Resources> </Window.Resources>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="454"></ColumnDefinition> <ColumnDefinition Width="444"></ColumnDefinition>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition></RowDefinition> <RowDefinition></RowDefinition>
@ -96,6 +98,86 @@
</Grid> </Grid>
</TabItem.Content> </TabItem.Content>
</TabItem> </TabItem>
<TabItem>
<TabItem.Header>Skills</TabItem.Header>
<TabItem.Content>
<TabControl>
<TabItem>
<TabItem.Header>Active</TabItem.Header>
<TabItem.Content>
<ItemsControl ItemsSource="{Binding ActiveSkills,Mode=OneWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button IsEnabled="{Binding Path=IsReadyToUse,Mode=OneWay}">
<Button.Content>
<Grid>
<Image Source="{Binding Path=IconName}" Height="32" Width="32" />
<Rectangle Fill="Black" Opacity=".5" Visibility="{Binding Path=IsBusy,Converter={StaticResource BooleanToVisibilityConverter},Mode=OneWay}"/>
</Grid>
</Button.Content>
<Button.ToolTip>
<StackPanel MaxWidth="300">
<TextBlock TextWrapping="Wrap" FontWeight="Bold" FontSize="14" Margin="0,0,0,5">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} Lv {1}">
<Binding Path="Name" Mode="OneWay"/>
<Binding Path="Level" Mode="OneWay"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Cost,Mode=OneWay,StringFormat='MP Cost {0}'}" />
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Range,Mode=OneWay,StringFormat='Range {0}'}" />
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Description,Mode=OneWay}" />
</StackPanel>
</Button.ToolTip>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</TabItem.Content>
</TabItem>
<TabItem>
<TabItem.Header>Passive</TabItem.Header>
<TabItem.Content>
<ItemsControl ItemsSource="{Binding PassiveSkills,Mode=OneWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button IsEnabled="False" ToolTipService.ShowOnDisabled="True">
<Button.Content>
<Image Source="{Binding Path=IconName}" Height="32" Width="32" />
</Button.Content>
<Button.ToolTip>
<StackPanel MaxWidth="300">
<TextBlock TextWrapping="Wrap" FontWeight="Bold" FontSize="14" Margin="0,0,0,5">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} Lv {1}">
<Binding Path="Name" Mode="OneWay"/>
<Binding Path="Level" Mode="OneWay"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Description,Mode=OneWay}" />
</StackPanel>
</Button.ToolTip>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</TabItem.Content>
</TabItem>
</TabControl>
</TabItem.Content>
</TabItem>
</TabControl> </TabControl>
<Grid Grid.Row="1" Grid.Column="1" DataContext="{Binding Hero, Mode=OneWay}" Margin="4" Visibility="{Binding Path=.,Converter={StaticResource NullToVisibilityConverter}}"> <Grid Grid.Row="1" Grid.Column="1" DataContext="{Binding Hero, Mode=OneWay}" Margin="4" Visibility="{Binding Path=.,Converter={StaticResource NullToVisibilityConverter}}">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@ -107,7 +189,7 @@
<RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition> <RowDefinition></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel> <StackPanel Margin="4">
<TextBlock FontSize="16" Text="{Binding Path=Fullname.Nickname, Mode=OneWay}"></TextBlock> <TextBlock FontSize="16" Text="{Binding Path=Fullname.Nickname, Mode=OneWay}"></TextBlock>
<TextBlock> <TextBlock>
<TextBlock.Text> <TextBlock.Text>

View File

@ -73,6 +73,8 @@ namespace Client
eventBus.Subscrbe((EventHandlerInterface<DropCreatedEvent>)viewModel); eventBus.Subscrbe((EventHandlerInterface<DropCreatedEvent>)viewModel);
eventBus.Subscrbe((EventHandlerInterface<DropDeletedEvent>)viewModel); eventBus.Subscrbe((EventHandlerInterface<DropDeletedEvent>)viewModel);
eventBus.Subscrbe((EventHandlerInterface<ChatMessageCreatedEvent>)viewModel); eventBus.Subscrbe((EventHandlerInterface<ChatMessageCreatedEvent>)viewModel);
eventBus.Subscrbe((EventHandlerInterface<SkillCreatedEvent>)viewModel);
eventBus.Subscrbe((EventHandlerInterface<SkillDeletedEvent>)viewModel);
eventBus.Subscrbe((EventHandlerInterface<TargetChangedEvent>)serviceProvider.GetRequiredService<HeroHandler>()); eventBus.Subscrbe((EventHandlerInterface<TargetChangedEvent>)serviceProvider.GetRequiredService<HeroHandler>());
eventBus.Subscrbe((EventHandlerInterface<TargetChangedEvent>)serviceProvider.GetRequiredService<NpcHandler>()); eventBus.Subscrbe((EventHandlerInterface<TargetChangedEvent>)serviceProvider.GetRequiredService<NpcHandler>());

View File

@ -29,8 +29,4 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Application\Extensions\" />
</ItemGroup>
</Project> </Project>

View File

@ -7,11 +7,6 @@ namespace Client.Domain.Entities
{ {
public class Hero : ObservableObject, EntityInterface, CreatureInterface public class Hero : ObservableObject, EntityInterface, CreatureInterface
{ {
private FullName fullName;
private Phenotype phenotype;
private CreatureInterface? target;
private uint targetId;
public uint Id { get; set; } public uint Id { get; set; }
public Transform Transform { get; set; } public Transform Transform { get; set; }
public VitalStats VitalStats { get; set; } public VitalStats VitalStats { get; set; }
@ -96,5 +91,10 @@ namespace Client.Domain.Entities
OnPropertyChanged("Name"); OnPropertyChanged("Name");
} }
} }
private FullName fullName;
private Phenotype phenotype;
private CreatureInterface? target;
private uint targetId;
} }
} }

View File

@ -0,0 +1,52 @@
using Client.Domain.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.Domain.Entities
{
public class Skill : ObservableObject, EntityInterface
{
public uint Id { get; set; }
public uint Level { get => level; set { if (value != level) { level = value; OnPropertyChanged(); } } }
public bool IsActive { get; set; }
public uint Cost { get => cost; set { if (value != cost) { cost = value; OnPropertyChanged(); } } }
public int Range { get => range; set { if (value != range) { range = value; OnPropertyChanged(); } } }
public string Name { get => name; set { if (value != name) { name = value; OnPropertyChanged(); } } }
public string Description { get => description; set { if (value != description) { description = value; OnPropertyChanged(); } } }
public string IconName { get => iconName; set { if (value != iconName) { iconName = value; OnPropertyChanged(); } } }
public bool IsToggled { get => isToggled; set { if (value != isToggled) { isToggled = value; OnPropertyChanged(); } } }
public bool IsCasting { get => isCasting; set { if (value != isCasting) { isCasting = value; OnPropertyChanged(); } } }
public bool IsReloading { get => isReloading; set { if (value != isReloading) { isReloading = value; OnPropertyChanged(); } } }
public bool IsReadyToUse { get => isReadyToUse; set { if (value != isReadyToUse) { isReadyToUse = value; OnPropertyChanged(); } } }
public Skill(uint id, uint level, bool isActive, uint cost, int range, string name, string description, string iconName, bool isToggled, bool isCasting, bool isReloading, bool isReadyToUse)
{
Id = id;
this.level = level;
IsActive = isActive;
this.cost = cost;
this.range = range;
Name = name;
this.description = description;
IconName = iconName;
this.isToggled = isToggled;
this.isCasting = isCasting;
this.isReloading = isReloading;
this.isReadyToUse = isReadyToUse;
}
private string description;
private uint cost;
private int range;
private bool isToggled;
private bool isCasting;
private bool isReloading;
private bool isReadyToUse;
private uint level;
private string name;
private string iconName;
}
}

View File

@ -0,0 +1,20 @@
using Client.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.Domain.Events
{
public class SkillCreatedEvent : EventInterface
{
public readonly Skill Skill;
public SkillCreatedEvent(Skill skill)
{
Skill = skill;
}
}
}

View File

@ -0,0 +1,19 @@
using Client.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.Domain.Events
{
public class SkillDeletedEvent : EventInterface
{
public readonly uint Id;
public SkillDeletedEvent(uint id)
{
Id = id;
}
}
}

View File

@ -45,8 +45,7 @@ namespace Client.Domain.Service
public T? GetEntity(uint id) public T? GetEntity(uint id)
{ {
T? result = null; T? result;
entities.TryGetValue(id, out result); entities.TryGetValue(id, out result);
return result; return result;

View File

@ -0,0 +1,30 @@
using Client.Domain.Entities;
using Client.Domain.Events;
using Client.Domain.Factories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.Domain.Service
{
public class SkillHandler : EntityHandler<Skill>
{
public override void OnCreate(Skill entity)
{
eventBus.Publish(new SkillCreatedEvent(entity));
}
public override void OnDelete(Skill entity)
{
eventBus.Publish(new SkillDeletedEvent(entity.Id));
}
public SkillHandler(EntityFactoryInterface<Skill> factory, EventBusInterface eventBus) : base(factory)
{
this.eventBus = eventBus;
}
private readonly EventBusInterface eventBus;
}
}

View File

@ -36,6 +36,9 @@ namespace Client.Infrastructure.Factories
case MessageTypeEnum.Chat: case MessageTypeEnum.Chat:
result = serviceProvider.GetService<ChatMessageHandler>(); result = serviceProvider.GetService<ChatMessageHandler>();
break; break;
case MessageTypeEnum.Skill:
result = serviceProvider.GetService<SkillHandler>();
break;
} }
if (result == null) if (result == null)