feat: add items #wip
This commit is contained in:
parent
03423d0c41
commit
c35f4e317a
@ -94,6 +94,7 @@ namespace Client
|
||||
.AddTransient(typeof(EntityFactoryInterface<Player>), typeof(EntityFactory<Player>))
|
||||
.AddTransient(typeof(EntityFactoryInterface<ChatMessage>), typeof(EntityFactory<ChatMessage>))
|
||||
.AddTransient(typeof(EntityFactoryInterface<Skill>), typeof(EntityFactory<Skill>))
|
||||
.AddTransient(typeof(EntityFactoryInterface<BaseItem>), typeof(ItemFactory))
|
||||
|
||||
.AddSingleton<HeroHandler>()
|
||||
.AddSingleton<DropHandler>()
|
||||
@ -101,6 +102,7 @@ namespace Client
|
||||
.AddSingleton<PlayerHandler>()
|
||||
.AddSingleton<ChatMessageHandler>()
|
||||
.AddSingleton<SkillHandler>()
|
||||
.AddSingleton<ItemHander>()
|
||||
|
||||
.AddSingleton<MainViewModel>();
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Client.Application.Converters
|
||||
{
|
||||
public class CenterOfParentConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return (double)values[0] + (double)values[2] / 2 - (double)values[1] / 2;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Client.Application.Converters
|
||||
{
|
||||
public class PercentWidthConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (!(values[0] is double))
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
return ((double)values[0] / 100 * (Double)values[1]);
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -26,7 +26,9 @@ namespace Client.Application.ViewModels
|
||||
EventHandlerInterface<DropDeletedEvent>,
|
||||
EventHandlerInterface<ChatMessageCreatedEvent>,
|
||||
EventHandlerInterface<SkillCreatedEvent>,
|
||||
EventHandlerInterface<SkillDeletedEvent>
|
||||
EventHandlerInterface<SkillDeletedEvent>,
|
||||
EventHandlerInterface<ItemCreatedEvent>,
|
||||
EventHandlerInterface<ItemDeletedEvent>
|
||||
{
|
||||
public void Handle(HeroCreatedEvent @event)
|
||||
{
|
||||
@ -94,11 +96,25 @@ namespace Client.Application.ViewModels
|
||||
PassiveSkills.RemoveAll(x => x.Id == @event.Id);
|
||||
}
|
||||
|
||||
public void Handle(ItemCreatedEvent @event)
|
||||
{
|
||||
if (hero != null)
|
||||
{
|
||||
Items.Add(@event.Item);
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(ItemDeletedEvent @event)
|
||||
{
|
||||
Items.RemoveAll(x => x.Id == @event.Id);
|
||||
}
|
||||
|
||||
public ObservableCollection<ChatMessageViewModel> ChatMessages { get; } = new ObservableCollection<ChatMessageViewModel>();
|
||||
public ObservableCollection<CreatureListViewModel> Creatures { get; } = new ObservableCollection<CreatureListViewModel>();
|
||||
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 ObservableCollection<BaseItem> Items { get; } = new ObservableCollection<BaseItem>();
|
||||
public HeroSummaryInfoViewModel? Hero { get; private set; }
|
||||
public Hero? hero;
|
||||
}
|
||||
|
@ -116,6 +116,61 @@
|
||||
</TabControl>
|
||||
</TabItem.Content>
|
||||
</TabItem>
|
||||
<TabItem>
|
||||
<TabItem.Header>Inventory</TabItem.Header>
|
||||
<TabItem.Content>
|
||||
<TabControl>
|
||||
<TabItem>
|
||||
<TabItem.Header>Items</TabItem.Header>
|
||||
<TabItem.Content>
|
||||
<ItemsControl ItemsSource="{Binding Path=Items}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Button>
|
||||
<Button.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
|
||||
<DataTemplate x:Key="ToolTipContent">
|
||||
<StackPanel MaxWidth="300">
|
||||
<TextBlock TextWrapping="Wrap" FontWeight="Bold" FontSize="14" Margin="0,0,0,5">
|
||||
<TextBlock.Text>
|
||||
<MultiBinding StringFormat="{}{0} ({1})">
|
||||
<Binding Path="Name" Mode="OneWay" />
|
||||
<Binding Path="Amount" Mode="OneWay" />
|
||||
</MultiBinding>
|
||||
</TextBlock.Text>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</Button.Resources>
|
||||
<Button.Content>
|
||||
<Grid>
|
||||
<Image Source="{Binding Path=ImageSource}" Height="32" Width="32" />
|
||||
</Grid>
|
||||
</Button.Content>
|
||||
<Button.ToolTip >
|
||||
<ContentControl ContentTemplate="{StaticResource ToolTipContent}"/>
|
||||
</Button.ToolTip>
|
||||
</Button>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
</ItemsControl>
|
||||
</TabItem.Content>
|
||||
</TabItem>
|
||||
<TabItem>
|
||||
<TabItem.Header>Quest Items</TabItem.Header>
|
||||
<TabItem.Content>
|
||||
<Label Content="Under construction" />
|
||||
</TabItem.Content>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</TabItem.Content>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
<Grid Grid.Row="1" Grid.Column="1" DataContext="{Binding Hero, Mode=OneWay}" Margin="4" Visibility="{Binding Path=.,Converter={StaticResource NullToVisibilityConverter}}">
|
||||
<Grid.ColumnDefinitions>
|
||||
|
@ -75,6 +75,8 @@ namespace Client
|
||||
eventBus.Subscrbe((EventHandlerInterface<ChatMessageCreatedEvent>)viewModel);
|
||||
eventBus.Subscrbe((EventHandlerInterface<SkillCreatedEvent>)viewModel);
|
||||
eventBus.Subscrbe((EventHandlerInterface<SkillDeletedEvent>)viewModel);
|
||||
eventBus.Subscrbe((EventHandlerInterface<ItemCreatedEvent>)viewModel);
|
||||
eventBus.Subscrbe((EventHandlerInterface<ItemDeletedEvent>)viewModel);
|
||||
|
||||
eventBus.Subscrbe((EventHandlerInterface<TargetChangedEvent>)serviceProvider.GetRequiredService<HeroHandler>());
|
||||
eventBus.Subscrbe((EventHandlerInterface<TargetChangedEvent>)serviceProvider.GetRequiredService<NpcHandler>());
|
||||
|
35
Client/Domain/Entities/BaseItem.cs
Normal file
35
Client/Domain/Entities/BaseItem.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using Client.Domain.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Entities
|
||||
{
|
||||
public abstract class BaseItem : EntityInterface
|
||||
{
|
||||
public uint Id { get; set; }
|
||||
public uint ItemId { get; set; }
|
||||
public ItemTypeEnum Type { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string IconName { get; set; }
|
||||
public string Description { get; set; }
|
||||
public int Mana { get { return mana; } set { mana = value; }}
|
||||
public uint Weight { get; set; }
|
||||
|
||||
public BaseItem(uint id, uint itemId, ItemTypeEnum type, string name, string iconName, string description, int mana, uint weight)
|
||||
{
|
||||
Id = id;
|
||||
ItemId = itemId;
|
||||
Type = type;
|
||||
Name = name;
|
||||
IconName = iconName;
|
||||
Description = description;
|
||||
this.mana = mana;
|
||||
Weight = weight;
|
||||
}
|
||||
|
||||
private int mana;
|
||||
}
|
||||
}
|
26
Client/Domain/Entities/EtcItem.cs
Normal file
26
Client/Domain/Entities/EtcItem.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Client.Domain.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Entities
|
||||
{
|
||||
public class EtcItem : BaseItem
|
||||
{
|
||||
public uint Amount { get => amount; set => amount = value; }
|
||||
public bool IsQuest { get; set; }
|
||||
public bool IsAutoused { get => isAutoused; set => isAutoused = value; }
|
||||
public EtcItem(uint id, uint itemId, ItemTypeEnum type, string name, string iconName, string description, int mana, uint weight, uint amount, bool isQuest, bool isAutoused) :
|
||||
base(id, itemId, type, name, iconName, description, mana, weight)
|
||||
{
|
||||
this.amount = amount;
|
||||
IsQuest = isQuest;
|
||||
this.isAutoused = isAutoused;
|
||||
}
|
||||
|
||||
private uint amount;
|
||||
private bool isAutoused;
|
||||
}
|
||||
}
|
17
Client/Domain/Enums/ItemTypeEnum.cs
Normal file
17
Client/Domain/Enums/ItemTypeEnum.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Enums
|
||||
{
|
||||
public enum ItemTypeEnum
|
||||
{
|
||||
None = -1,
|
||||
Etc,
|
||||
Armor,
|
||||
Weapon,
|
||||
Shield
|
||||
}
|
||||
}
|
19
Client/Domain/Events/ItemCreatedEvent.cs
Normal file
19
Client/Domain/Events/ItemCreatedEvent.cs
Normal 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 ItemCreatedEvent : EventInterface
|
||||
{
|
||||
public readonly BaseItem Item;
|
||||
|
||||
public ItemCreatedEvent(BaseItem item)
|
||||
{
|
||||
Item = item;
|
||||
}
|
||||
}
|
||||
}
|
19
Client/Domain/Events/ItemDeletedEvent.cs
Normal file
19
Client/Domain/Events/ItemDeletedEvent.cs
Normal 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 ItemDeletedEvent : EventInterface
|
||||
{
|
||||
public readonly uint Id;
|
||||
|
||||
public ItemDeletedEvent(uint id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
}
|
||||
}
|
30
Client/Domain/Service/ItemHandler.cs
Normal file
30
Client/Domain/Service/ItemHandler.cs
Normal 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 ItemHander : EntityHandler<BaseItem>
|
||||
{
|
||||
public override void OnCreate(BaseItem entity)
|
||||
{
|
||||
eventBus.Publish(new ItemCreatedEvent(entity));
|
||||
}
|
||||
public override void OnDelete(BaseItem entity)
|
||||
{
|
||||
eventBus.Publish(new ItemDeletedEvent(entity.Id));
|
||||
}
|
||||
|
||||
public ItemHander(EntityFactoryInterface<BaseItem> factory, EventBusInterface eventBus) : base(factory)
|
||||
{
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
|
||||
private readonly EventBusInterface eventBus;
|
||||
}
|
||||
}
|
@ -39,6 +39,9 @@ namespace Client.Infrastructure.Factories
|
||||
case MessageTypeEnum.Skill:
|
||||
result = serviceProvider.GetService<SkillHandler>();
|
||||
break;
|
||||
case MessageTypeEnum.Item:
|
||||
result = serviceProvider.GetService<ItemHander>();
|
||||
break;
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
|
48
Client/Infrastructure/Factories/ItemFactory.cs
Normal file
48
Client/Infrastructure/Factories/ItemFactory.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Enums;
|
||||
using Client.Domain.Factories;
|
||||
using Client.Infrastructure.Parsers.Converters;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Infrastructure.Factories
|
||||
{
|
||||
public class ItemFactory : EntityFactoryInterface<BaseItem>
|
||||
{
|
||||
public BaseItem? Create(string data)
|
||||
{
|
||||
var type = JsonConvert.DeserializeObject<ItemType>(data, settings);
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
}
|
||||
|
||||
switch (type.Type)
|
||||
{
|
||||
case ItemTypeEnum.Etc:
|
||||
return JsonConvert.DeserializeObject<EtcItem>(data, settings);
|
||||
default:
|
||||
return JsonConvert.DeserializeObject<EtcItem>(data, settings); //fixme temporary
|
||||
}
|
||||
|
||||
throw new ArgumentException("Invalid item type " + type.Type.ToString());
|
||||
}
|
||||
|
||||
public void Update(BaseItem entity, string data)
|
||||
{
|
||||
JsonConvert.PopulateObject(data, entity, settings);
|
||||
}
|
||||
|
||||
private JsonSerializerSettings settings = new JsonSerializerSettings { Converters = { new BooleanConverter() } };
|
||||
|
||||
private class ItemType
|
||||
{
|
||||
public ItemTypeEnum Type { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user