feat: add outgoing messages to client
This commit is contained in:
@ -1,11 +1,14 @@
|
||||
using Client.Domain.Common;
|
||||
using Client.Application.Commands;
|
||||
using Client.Domain.Common;
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Client.Application.ViewModels
|
||||
{
|
||||
@ -21,14 +24,36 @@ namespace Client.Application.ViewModels
|
||||
|
||||
public float DeltaZ => creature.DeltaZ(hero);
|
||||
|
||||
public CreatureListViewModel(CreatureInterface creature, Hero hero)
|
||||
public ICommand MouseLeftClickCommand { get; }
|
||||
public ICommand MouseLeftDoubleClickCommand { get; }
|
||||
public ICommand MouseRightClickCommand { get; }
|
||||
private void OnMouseLeftClick(object? obj)
|
||||
{
|
||||
worldHandler.RequestAcquireTarget(Id);
|
||||
}
|
||||
|
||||
private void OnMouseLeftDoubleClick(object? obj)
|
||||
{
|
||||
worldHandler.RequestAttackOrFollow(Id);
|
||||
}
|
||||
|
||||
private void OnMouseRightClick(object? obj)
|
||||
{
|
||||
worldHandler.RequestMoveToEntity(Id);
|
||||
}
|
||||
|
||||
public CreatureListViewModel(CreatureInterface creature, Hero hero, WorldHandler worldHandler)
|
||||
{
|
||||
creature.PropertyChanged += Creature_PropertyChanged;
|
||||
creature.Transform.Position.PropertyChanged += Position_PropertyChanged;
|
||||
hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged;
|
||||
MouseLeftClickCommand = new RelayCommand(OnMouseLeftClick);
|
||||
MouseLeftDoubleClickCommand = new RelayCommand(OnMouseLeftDoubleClick);
|
||||
MouseRightClickCommand = new RelayCommand(OnMouseRightClick);
|
||||
|
||||
this.creature = creature;
|
||||
this.hero = hero;
|
||||
this.worldHandler = worldHandler;
|
||||
}
|
||||
|
||||
private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
@ -57,5 +82,6 @@ namespace Client.Application.ViewModels
|
||||
|
||||
private readonly CreatureInterface creature;
|
||||
private readonly Hero hero;
|
||||
private readonly WorldHandler worldHandler;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,17 @@
|
||||
using Client.Domain.Common;
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Enums;
|
||||
using Client.Domain.Service;
|
||||
using Client.Domain.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using System.Windows;
|
||||
using Client.Application.Commands;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Client.Application.ViewModels
|
||||
{
|
||||
@ -56,20 +61,41 @@ namespace Client.Application.ViewModels
|
||||
}
|
||||
public CreatureTypeEnum Type => creature.Type;
|
||||
public bool IsTarget => Id == hero.TargetId;
|
||||
public bool IsAggressive => creature.AggroRadius > 0;
|
||||
public bool IsAggressive => creature.AggroRadius > 0 && !creature.VitalStats.IsDead && creature.IsHostile;
|
||||
public float AggroRadius => creature.AggroRadius / scale;
|
||||
|
||||
public ICommand MouseLeftClickCommand { get; }
|
||||
public ICommand MouseLeftDoubleClickCommand { get; }
|
||||
public ICommand MouseRightClickCommand { get; }
|
||||
private void OnMouseLeftClick(object? obj)
|
||||
{
|
||||
worldHandler.RequestAcquireTarget(Id);
|
||||
}
|
||||
|
||||
public CreatureMapViewModel(CreatureInterface creature, Hero hero)
|
||||
private void OnMouseLeftDoubleClick(object? obj)
|
||||
{
|
||||
worldHandler.RequestAttackOrFollow(Id);
|
||||
}
|
||||
|
||||
private void OnMouseRightClick(object? obj)
|
||||
{
|
||||
worldHandler.RequestMoveToEntity(Id);
|
||||
}
|
||||
|
||||
public CreatureMapViewModel(CreatureInterface creature, Hero hero, WorldHandler worldHandler)
|
||||
{
|
||||
this.creature = creature;
|
||||
this.hero = hero;
|
||||
this.worldHandler = worldHandler;
|
||||
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;
|
||||
MouseLeftClickCommand = new RelayCommand(OnMouseLeftClick);
|
||||
MouseLeftDoubleClickCommand = new RelayCommand(OnMouseLeftDoubleClick);
|
||||
MouseRightClickCommand = new RelayCommand(OnMouseRightClick);
|
||||
}
|
||||
|
||||
private void VitalStats_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
@ -78,6 +104,10 @@ namespace Client.Application.ViewModels
|
||||
{
|
||||
OnPropertyChanged("VitalStats");
|
||||
}
|
||||
if (e.PropertyName == "IsDead")
|
||||
{
|
||||
OnPropertyChanged("IsAggressive");
|
||||
}
|
||||
}
|
||||
|
||||
private void Hero_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
@ -118,6 +148,7 @@ namespace Client.Application.ViewModels
|
||||
|
||||
private readonly CreatureInterface creature;
|
||||
private readonly Hero hero;
|
||||
private readonly WorldHandler worldHandler;
|
||||
private float scale = 1;
|
||||
private static readonly float MAX_RADIUS = 10;
|
||||
private static readonly float MIN_RADIUS = 4;
|
||||
|
@ -1,10 +1,13 @@
|
||||
using Client.Domain.Common;
|
||||
using Client.Application.Commands;
|
||||
using Client.Domain.Common;
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Client.Application.ViewModels
|
||||
{
|
||||
@ -46,14 +49,14 @@ namespace Client.Application.ViewModels
|
||||
{
|
||||
get
|
||||
{
|
||||
return drop.Transform.Position.HorizontalDistance(hero.Transform.Position) / 100;
|
||||
return drop.Transform.Position.HorizontalDistance(hero.Transform.Position);
|
||||
}
|
||||
}
|
||||
public float DeltaZ
|
||||
{
|
||||
get
|
||||
{
|
||||
return (drop.Transform.Position.Z - hero.Transform.Position.Z) / 100;
|
||||
return (drop.Transform.Position.Z - hero.Transform.Position.Z);
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,14 +68,27 @@ namespace Client.Application.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public DropListViewModel(Drop drop, Hero hero)
|
||||
public ICommand MouseLeftClickCommand { get; }
|
||||
public ICommand MouseRightClickCommand { get; }
|
||||
private void OnMouseLeftClick(object? obj)
|
||||
{
|
||||
worldHandler.RequestPickUp(Id);
|
||||
}
|
||||
private void OnMouseRightClick(object? obj)
|
||||
{
|
||||
worldHandler.RequestMoveToEntity(Id);
|
||||
}
|
||||
|
||||
public DropListViewModel(Drop drop, Hero hero, WorldHandler worldHandler)
|
||||
{
|
||||
this.drop = drop;
|
||||
this.hero = hero;
|
||||
|
||||
this.worldHandler = worldHandler;
|
||||
drop.PropertyChanged += Drop_PropertyChanged;
|
||||
drop.Transform.Position.PropertyChanged += DropPosition_PropertyChanged;
|
||||
hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged;
|
||||
MouseLeftClickCommand = new RelayCommand(OnMouseLeftClick);
|
||||
MouseRightClickCommand = new RelayCommand(OnMouseRightClick);
|
||||
}
|
||||
|
||||
private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
@ -109,5 +125,6 @@ namespace Client.Application.ViewModels
|
||||
|
||||
private readonly Drop drop;
|
||||
private readonly Hero hero;
|
||||
private readonly WorldHandler worldHandler;
|
||||
}
|
||||
}
|
||||
|
@ -8,13 +8,16 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
using Client.Domain.Service;
|
||||
using System.Windows.Input;
|
||||
using Client.Application.Commands;
|
||||
|
||||
namespace Client.Application.ViewModels
|
||||
{
|
||||
public class DropMapViewModel : ObservableObject
|
||||
{
|
||||
public uint Id => drop.Id;
|
||||
public string Name => drop.Name;
|
||||
public string Name => drop.Name + " (" + drop.Amount + ")";
|
||||
public Vector3 Position => new Vector3(
|
||||
(drop.Transform.Position.X - hero.Transform.Position.X) / scale + (VieportSize.X / 2),
|
||||
(drop.Transform.Position.Y - hero.Transform.Position.Y) / scale + (VieportSize.Y / 2),
|
||||
@ -47,13 +50,27 @@ namespace Client.Application.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public DropMapViewModel(Drop drop, Hero hero)
|
||||
public ICommand MouseLeftClickCommand { get; }
|
||||
public ICommand MouseRightClickCommand { get; }
|
||||
private void OnMouseLeftClick(object? obj)
|
||||
{
|
||||
worldHandler.RequestPickUp(Id);
|
||||
}
|
||||
private void OnMouseRightClick(object? obj)
|
||||
{
|
||||
worldHandler.RequestMoveToEntity(Id);
|
||||
}
|
||||
|
||||
public DropMapViewModel(Drop drop, Hero hero, WorldHandler worldHandler)
|
||||
{
|
||||
this.drop = drop;
|
||||
this.hero = hero;
|
||||
this.worldHandler = worldHandler;
|
||||
drop.PropertyChanged += Creature_PropertyChanged;
|
||||
drop.Transform.Position.PropertyChanged += Position_PropertyChanged;
|
||||
hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged;
|
||||
MouseLeftClickCommand = new RelayCommand(OnMouseLeftClick);
|
||||
MouseRightClickCommand = new RelayCommand(OnMouseRightClick);
|
||||
}
|
||||
|
||||
private void HeroPosition_PropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
@ -68,7 +85,7 @@ namespace Client.Application.ViewModels
|
||||
|
||||
private void Creature_PropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Name")
|
||||
if (e.PropertyName == "Name" || e.PropertyName == "Amount")
|
||||
{
|
||||
OnPropertyChanged("Name");
|
||||
}
|
||||
@ -76,6 +93,7 @@ namespace Client.Application.ViewModels
|
||||
|
||||
private readonly Drop drop;
|
||||
private readonly Hero hero;
|
||||
private readonly WorldHandler worldHandler;
|
||||
private float scale = 1;
|
||||
private static readonly float MAX_RADIUS = 8;
|
||||
private static readonly float MIN_RADIUS = 2;
|
||||
|
@ -1,6 +1,8 @@
|
||||
using Client.Domain.Common;
|
||||
using Client.Application.Components;
|
||||
using Client.Domain.Common;
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Events;
|
||||
using Client.Domain.Service;
|
||||
using Client.Domain.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -57,7 +59,7 @@ namespace Client.Application.ViewModels
|
||||
{
|
||||
if (hero != null)
|
||||
{
|
||||
Creatures.Add(new CreatureListViewModel(@event.Creature, hero));
|
||||
Creatures.Add(new CreatureListViewModel(@event.Creature, hero, worldHandler));
|
||||
AddCreature(@event.Creature);
|
||||
}
|
||||
}
|
||||
@ -72,8 +74,8 @@ namespace Client.Application.ViewModels
|
||||
{
|
||||
if (hero != null)
|
||||
{
|
||||
Drops.Add(new DropListViewModel(@event.Drop, hero));
|
||||
Map.Drops.Add(new DropMapViewModel(@event.Drop, hero));
|
||||
Drops.Add(new DropListViewModel(@event.Drop, hero, worldHandler));
|
||||
Map.Drops.Add(new DropMapViewModel(@event.Drop, hero, worldHandler));
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,11 +96,11 @@ namespace Client.Application.ViewModels
|
||||
{
|
||||
if (@event.Skill.IsActive)
|
||||
{
|
||||
ActiveSkills.Add(new SkillListViewModel(@event.Skill));
|
||||
ActiveSkills.Add(new SkillListViewModel(worldHandler, @event.Skill));
|
||||
}
|
||||
else
|
||||
{
|
||||
PassiveSkills.Add(new SkillListViewModel(@event.Skill));
|
||||
PassiveSkills.Add(new SkillListViewModel(worldHandler, @event.Skill));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -126,7 +128,7 @@ namespace Client.Application.ViewModels
|
||||
{
|
||||
if (hero != null)
|
||||
{
|
||||
Map.Creatures.Add(new CreatureMapViewModel(creature, hero));
|
||||
Map.Creatures.Add(new CreatureMapViewModel(creature, hero, worldHandler));
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,6 +137,12 @@ namespace Client.Application.ViewModels
|
||||
Map.Creatures.RemoveAll(x => x.Id == id);
|
||||
}
|
||||
|
||||
public MainViewModel(WorldHandler worldHandler)
|
||||
{
|
||||
this.worldHandler = worldHandler;
|
||||
Map = new MapViewModel(worldHandler);
|
||||
}
|
||||
|
||||
public ObservableCollection<ChatMessageViewModel> ChatMessages { get; } = new ObservableCollection<ChatMessageViewModel>();
|
||||
public ObservableCollection<CreatureListViewModel> Creatures { get; } = new ObservableCollection<CreatureListViewModel>();
|
||||
public ObservableCollection<DropListViewModel> Drops { get; } = new ObservableCollection<DropListViewModel>();
|
||||
@ -142,7 +150,8 @@ namespace Client.Application.ViewModels
|
||||
public ObservableCollection<SkillListViewModel> PassiveSkills { get; } = new ObservableCollection<SkillListViewModel>();
|
||||
public ObservableCollection<BaseItem> Items { get; } = new ObservableCollection<BaseItem>();
|
||||
public HeroSummaryInfoViewModel? Hero { get; private set; }
|
||||
public MapViewModel Map { get; private set; } = new MapViewModel();
|
||||
public MapViewModel Map { get; private set; }
|
||||
public Hero? hero;
|
||||
private readonly WorldHandler worldHandler;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Collections.Specialized;
|
||||
using Client.Application.Commands;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Windows;
|
||||
|
||||
namespace Client.Application.ViewModels
|
||||
{
|
||||
@ -125,10 +128,33 @@ namespace Client.Application.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public MapViewModel()
|
||||
public ICommand MouseLeftClickCommand { get; }
|
||||
private void OnLeftMouseClick(object? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (hero == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Point mousePos = Mouse.GetPosition((IInputElement)obj);
|
||||
var location = new Vector3(
|
||||
(float)(mousePos.X - ViewportWidth / 2) * scale + hero.Transform.Position.X,
|
||||
(float)(mousePos.Y - ViewportHeight / 2) * scale + hero.Transform.Position.Y,
|
||||
hero.Transform.Position.Z
|
||||
);
|
||||
worldHandler.RequestMoveToLocation(location);
|
||||
}
|
||||
|
||||
public MapViewModel(WorldHandler worldHandler)
|
||||
{
|
||||
Creatures.CollectionChanged += Creatures_CollectionChanged;
|
||||
Drops.CollectionChanged += Drops_CollectionChanged;
|
||||
this.worldHandler = worldHandler;
|
||||
MouseLeftClickCommand = new RelayCommand(OnLeftMouseClick);
|
||||
}
|
||||
|
||||
private void Drops_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
@ -167,5 +193,6 @@ namespace Client.Application.ViewModels
|
||||
private float scale = 8;
|
||||
private double viewportWidth = 0;
|
||||
private double viewportHeight = 0;
|
||||
private readonly WorldHandler worldHandler;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
using Client.Domain.Common;
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Service;
|
||||
using System.Windows.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Client.Application.Commands;
|
||||
|
||||
namespace Client.Application.ViewModels
|
||||
{
|
||||
@ -21,11 +24,19 @@ namespace Client.Application.ViewModels
|
||||
public uint? Cost => skill.Cost == 0 ? null : skill.Cost;
|
||||
public int? Range => skill.Range <= 0 ? null : skill.Range;
|
||||
|
||||
public SkillListViewModel(Skill skill)
|
||||
public ICommand MouseLeftClickCommand { get; }
|
||||
private void OnLeftMouseClick(object? obj)
|
||||
{
|
||||
worldHandler.RequestUseSkill(Id, false, false);
|
||||
}
|
||||
|
||||
public SkillListViewModel(WorldHandler worldHandler, Skill skill)
|
||||
{
|
||||
this.worldHandler = worldHandler;
|
||||
this.skill = skill;
|
||||
|
||||
skill.PropertyChanged += Skill_PropertyChanged;
|
||||
MouseLeftClickCommand = new RelayCommand(OnLeftMouseClick);
|
||||
}
|
||||
|
||||
private void Skill_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
@ -61,6 +72,7 @@ namespace Client.Application.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private readonly WorldHandler worldHandler;
|
||||
private readonly Skill skill;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user