feat: create creature interface
This commit is contained in:
61
Client/Application/ViewModels/CreatureListViewModel.cs
Normal file
61
Client/Application/ViewModels/CreatureListViewModel.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using Client.Domain.Common;
|
||||
using Client.Domain.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Application.ViewModels
|
||||
{
|
||||
public class CreatureListViewModel : NotifyPropertyChanged
|
||||
{
|
||||
public uint Id => creature.Id;
|
||||
|
||||
public string Name => creature.Name;
|
||||
|
||||
public string BriefInfo => creature.BriefInfo;
|
||||
|
||||
public float Distance => creature.Transform.Position.HorizontalDistance(hero.Transform.Position) / 100;
|
||||
|
||||
public float DeltaZ => (creature.Transform.Position.Z - hero.Transform.Position.Z) / 100;
|
||||
|
||||
public CreatureListViewModel(CreatureInterface creature, Hero hero)
|
||||
{
|
||||
creature.PropertyChanged += Creature_PropertyChanged;
|
||||
creature.Transform.Position.PropertyChanged += Position_PropertyChanged;
|
||||
hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged;
|
||||
|
||||
this.creature = creature;
|
||||
this.hero = hero;
|
||||
}
|
||||
|
||||
private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged("Distance");
|
||||
OnPropertyChanged("DeltaZ");
|
||||
}
|
||||
|
||||
private void Position_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged("Distance");
|
||||
OnPropertyChanged("DeltaZ");
|
||||
}
|
||||
|
||||
private void Creature_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Name")
|
||||
{
|
||||
OnPropertyChanged("Name");
|
||||
}
|
||||
if (e.PropertyName == "BriefInfo")
|
||||
{
|
||||
OnPropertyChanged("BriefInfo");
|
||||
}
|
||||
}
|
||||
|
||||
private readonly CreatureInterface creature;
|
||||
private readonly Hero hero;
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Application.ViewModels
|
||||
{
|
||||
public interface CreatureListViewModelInterface
|
||||
{
|
||||
uint Id { get; }
|
||||
string Title { get; }
|
||||
string Info { get; }
|
||||
float Distance { get; }
|
||||
float DeltaZ { get; }
|
||||
}
|
||||
}
|
@ -23,8 +23,8 @@ namespace Client.Application.ViewModels
|
||||
MainViewModelInterface,
|
||||
EventHandlerInterface<HeroCreatedEvent>,
|
||||
EventHandlerInterface<HeroDeletedEvent>,
|
||||
EventHandlerInterface<NpcCreatedEvent>,
|
||||
EventHandlerInterface<NpcDeletedEvent>
|
||||
EventHandlerInterface<CreatureCreatedEvent>,
|
||||
EventHandlerInterface<CreatureDeletedEvent>
|
||||
{
|
||||
|
||||
public void AddChatMessage(ChatMessage chatMessage)
|
||||
@ -32,19 +32,6 @@ namespace Client.Application.ViewModels
|
||||
ChatMessages.Add(new ChatMessageViewModel(chatMessage));
|
||||
}
|
||||
|
||||
public void AddPlayer(Player player)
|
||||
{
|
||||
if (hero != null)
|
||||
{
|
||||
Creatures.Add(new PlayerListViewModel(player, hero));
|
||||
}
|
||||
}
|
||||
|
||||
public void RemovePlayer(Player player)
|
||||
{
|
||||
Creatures.RemoveAll(x => x.Id == player.Id);
|
||||
}
|
||||
|
||||
public void AddDrop(Drop drop)
|
||||
{
|
||||
if (hero != null)
|
||||
@ -72,21 +59,21 @@ namespace Client.Application.ViewModels
|
||||
OnPropertyChanged("Hero");
|
||||
}
|
||||
|
||||
public void Handle(NpcCreatedEvent @event)
|
||||
public void Handle(CreatureCreatedEvent @event)
|
||||
{
|
||||
if (hero != null)
|
||||
{
|
||||
Creatures.Add(new NpcListViewModel(@event.NPC, hero));
|
||||
Creatures.Add(new CreatureListViewModel(@event.Creature, hero));
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(NpcDeletedEvent @event)
|
||||
public void Handle(CreatureDeletedEvent @event)
|
||||
{
|
||||
Creatures.RemoveAll(x => x.Id == @event.Id);
|
||||
}
|
||||
|
||||
public ObservableCollection<ChatMessageViewModel> ChatMessages { get; } = new ObservableCollection<ChatMessageViewModel>();
|
||||
public ObservableCollection<CreatureListViewModelInterface> Creatures { get; } = new ObservableCollection<CreatureListViewModelInterface>();
|
||||
public ObservableCollection<CreatureListViewModel> Creatures { get; } = new ObservableCollection<CreatureListViewModel>();
|
||||
public ObservableCollection<DropListViewModel> Drops { get; } = new ObservableCollection<DropListViewModel>();
|
||||
public HeroSummaryInfoViewModel? Hero { get; private set; }
|
||||
public Hero? hero;
|
||||
|
@ -1,110 +0,0 @@
|
||||
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 NpcListViewModel : NotifyPropertyChanged, CreatureListViewModelInterface
|
||||
{
|
||||
public uint Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return npc.Id;
|
||||
}
|
||||
}
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
string result = "";
|
||||
|
||||
if (npc.IsDead())
|
||||
{
|
||||
result += "Dead ";
|
||||
}
|
||||
result += npc.FullName.Nickname + "[" + npc.NpcId + "]";
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public string Info
|
||||
{
|
||||
get
|
||||
{
|
||||
string result = "Npc";
|
||||
|
||||
if (npc.IsHostile)
|
||||
{
|
||||
result = "Monster";
|
||||
if (npc.AggroRadius > 0)
|
||||
{
|
||||
result += "*";
|
||||
}
|
||||
}
|
||||
result += " " + npc.Level + "lvl";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public float Distance
|
||||
{
|
||||
get
|
||||
{
|
||||
return npc.Transform.Position.HorizontalDistance(hero.Transform.Position) / 100;
|
||||
}
|
||||
}
|
||||
public float DeltaZ
|
||||
{
|
||||
get
|
||||
{
|
||||
return (npc.Transform.Position.Z - hero.Transform.Position.Z) / 100;
|
||||
}
|
||||
}
|
||||
|
||||
public NpcListViewModel(NPC npc, Hero hero)
|
||||
{
|
||||
this.npc = npc;
|
||||
this.hero = hero;
|
||||
|
||||
npc.VitalStats.PropertyChanged += VitalStats_PropertyChanged;
|
||||
npc.FullName.PropertyChanged += FullName_PropertyChanged;
|
||||
npc.Transform.Position.PropertyChanged += NpcPosition_PropertyChanged;
|
||||
hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged;
|
||||
}
|
||||
|
||||
private void NpcPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged("Distance");
|
||||
OnPropertyChanged("DeltaZ");
|
||||
}
|
||||
|
||||
private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged("Distance");
|
||||
OnPropertyChanged("DeltaZ");
|
||||
}
|
||||
|
||||
private void FullName_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Nickname")
|
||||
{
|
||||
OnPropertyChanged("Title");
|
||||
}
|
||||
}
|
||||
|
||||
private void VitalStats_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Hp" || e.PropertyName == "MaxHp")
|
||||
{
|
||||
OnPropertyChanged("Title");
|
||||
}
|
||||
}
|
||||
|
||||
private readonly NPC npc;
|
||||
private readonly Hero hero;
|
||||
}
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
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 PlayerListViewModel : NotifyPropertyChanged, CreatureListViewModelInterface
|
||||
{
|
||||
public uint Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return player.Id;
|
||||
}
|
||||
}
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return player.FullName.Nickname;
|
||||
}
|
||||
}
|
||||
public string Info
|
||||
{
|
||||
get
|
||||
{
|
||||
//todo race and class strings
|
||||
return player.Phenotype.Race.ToString() + ", " + player.Phenotype.Class.ToString();
|
||||
}
|
||||
}
|
||||
public float Distance
|
||||
{
|
||||
get
|
||||
{
|
||||
return player.Transform.Position.HorizontalDistance(hero.Transform.Position) / 100;
|
||||
}
|
||||
}
|
||||
public float DeltaZ
|
||||
{
|
||||
get
|
||||
{
|
||||
return (player.Transform.Position.Z - hero.Transform.Position.Z) / 100;
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerListViewModel(Player player, Hero hero)
|
||||
{
|
||||
this.player = player;
|
||||
this.hero = hero;
|
||||
|
||||
player.Phenotype.PropertyChanged += Phenotype_PropertyChanged;
|
||||
player.FullName.PropertyChanged += FullName_PropertyChanged;
|
||||
player.Transform.Position.PropertyChanged += PlayerPosition_PropertyChanged;
|
||||
hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged;
|
||||
}
|
||||
|
||||
private void Phenotype_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Race" || e.PropertyName == "Class")
|
||||
{
|
||||
OnPropertyChanged("Info");
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayerPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged("Distance");
|
||||
OnPropertyChanged("DeltaZ");
|
||||
}
|
||||
|
||||
private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged("Distance");
|
||||
OnPropertyChanged("DeltaZ");
|
||||
}
|
||||
|
||||
private void FullName_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Nickname")
|
||||
{
|
||||
OnPropertyChanged("Title");
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Player player;
|
||||
private readonly Hero hero;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user