From 2480563914e3b3a2033f34c39c8b94caef5549bb Mon Sep 17 00:00:00 2001 From: k0t9i Date: Tue, 7 Feb 2023 22:21:15 +0400 Subject: [PATCH] feat: add creatures and drops on the map --- Client/Application/Components/Map.xaml | 121 +++++++++++++++- .../Application/Components/StatsBar.xaml.cs | 17 ++- .../ViewModels/CreatureMapViewModel.cs | 126 +++++++++++++++++ .../ViewModels/DropMapViewModel.cs | 84 +++++++++++ .../Application/ViewModels/MainViewModel.cs | 22 +++ Client/Application/ViewModels/MapViewModel.cs | 133 ++++++++++++------ Client/Domain/Entities/CreatureInterface.cs | 5 +- Client/Domain/Entities/Drop.cs | 11 +- Client/Domain/Entities/Hero.cs | 3 + Client/Domain/Entities/NPC.cs | 9 +- Client/Domain/Entities/Player.cs | 2 + Client/Domain/Enums/CreatureTypeEnum.cs | 15 ++ Client/Domain/ValueObjects/Transform.cs | 40 +++++- 13 files changed, 529 insertions(+), 59 deletions(-) create mode 100644 Client/Application/ViewModels/CreatureMapViewModel.cs create mode 100644 Client/Application/ViewModels/DropMapViewModel.cs create mode 100644 Client/Domain/Enums/CreatureTypeEnum.cs diff --git a/Client/Application/Components/Map.xaml b/Client/Application/Components/Map.xaml index 5d17507..9ebf28c 100644 --- a/Client/Application/Components/Map.xaml +++ b/Client/Application/Components/Map.xaml @@ -5,6 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Client.Application.Components" xmlns:services="clr-namespace:Client.Application.Services" + xmlns:components="clr-namespace:Client.Application.Components" mc:Ignorable="d" services:SizeObserver.Observe="True" services:SizeObserver.ObservedWidth="{Binding ViewportWidth, Mode=OneWayToSource}" @@ -35,6 +36,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -53,6 +173,5 @@ VerticalAlignment="Center" /> - diff --git a/Client/Application/Components/StatsBar.xaml.cs b/Client/Application/Components/StatsBar.xaml.cs index 38e96ad..e303af7 100644 --- a/Client/Application/Components/StatsBar.xaml.cs +++ b/Client/Application/Components/StatsBar.xaml.cs @@ -30,6 +30,8 @@ namespace Client.Application.Components DependencyProperty.Register("ForegroundWidth", typeof(double), typeof(StatsBar), new PropertyMetadata(0.0, null, OnCoerceForegroundWidth)); public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(StatsBar), new PropertyMetadata("", null, OnCoerceText)); + public static readonly DependencyProperty OnlyBarProperty = + DependencyProperty.Register("OnlyBar", typeof(bool), typeof(StatsBar), new PropertyMetadata(false, OnOnlyBarChanged)); private static void OnDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { @@ -37,7 +39,13 @@ namespace Client.Application.Components model.CoerceValue(ForegroundWidthProperty); model.CoerceValue(TextProperty); } - + + private static void OnOnlyBarChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var model = (StatsBar)d; + model.CoerceValue(TextProperty); + } + private static void OnFormatChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var model = (StatsBar)d; @@ -56,7 +64,7 @@ namespace Client.Application.Components { var model = (StatsBar)d; - return string.Format(model.Format, model.Current, model.Total, model.GetPercent()); + return model.OnlyBar ? "" : string.Format(model.Format, model.Current, model.Total, model.GetPercent()); } public StatsBar() @@ -124,5 +132,10 @@ namespace Client.Application.Components get { return (string)GetValue(FormatProperty); } set { SetValue(FormatProperty, value); } } + public bool OnlyBar + { + get { return (bool)GetValue(OnlyBarProperty); } + set { SetValue(OnlyBarProperty, value); } + } } } diff --git a/Client/Application/ViewModels/CreatureMapViewModel.cs b/Client/Application/ViewModels/CreatureMapViewModel.cs new file mode 100644 index 0000000..37e34b2 --- /dev/null +++ b/Client/Application/ViewModels/CreatureMapViewModel.cs @@ -0,0 +1,126 @@ +using Client.Domain.Common; +using Client.Domain.Entities; +using Client.Domain.Enums; +using Client.Domain.ValueObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Client.Application.ViewModels +{ + public class CreatureMapViewModel : ObservableObject + { + public uint Id => creature.Id; + public string Name => creature.Name; + public Vector3 Position => new Vector3( + (creature.Transform.Position.X - hero.Transform.Position.X) / scale + (VieportSize.X / 2), + (creature.Transform.Position.Y - hero.Transform.Position.Y) / scale + (VieportSize.Y / 2), + 0 + ); + public Vector3 Direction => new Vector3( + creature.Transform.Direction.X * Radius * 2f, + creature.Transform.Direction.Y * Radius * 2f, + 0 + ); + public VitalStats VitalStats => creature.VitalStats; + public float Radius => MathF.Max(MAX_RADIUS / scale, MIN_RADIUS); + public float Scale + { + get => scale; + set + { + if (scale != value) + { + scale = value; + OnPropertyChanged("Position"); + OnPropertyChanged("Direction"); + OnPropertyChanged("Radius"); + OnPropertyChanged("AggroRadius"); + } + } + } + public Vector3 VieportSize + { + get => vieportSize; + set + { + if (vieportSize != value) + { + vieportSize = value; + OnPropertyChanged("Position"); + OnPropertyChanged("Direction"); + } + } + } + public CreatureTypeEnum Type => creature.Type; + public bool IsTarget => Id == hero.TargetId; + public bool IsAggressive => creature.AggroRadius > 0; + public float AggroRadius => creature.AggroRadius / scale; + + + public CreatureMapViewModel(CreatureInterface creature, Hero hero) + { + this.creature = creature; + this.hero = hero; + 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; + } + + private void VitalStats_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName == "Hp" || e.PropertyName == "MaxHp") + { + OnPropertyChanged("VitalStats"); + } + } + + private void Hero_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName == "TargetId") + { + OnPropertyChanged("IsTarget"); + } + } + + private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) + { + OnPropertyChanged("Position"); + OnPropertyChanged("Direction"); + } + + private void Position_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) + { + OnPropertyChanged("Position"); + OnPropertyChanged("Direction"); + } + + private void Transform_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName == "Direction") + { + OnPropertyChanged("Direction"); + } + } + + private void Creature_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName == "Name") + { + OnPropertyChanged("Name"); + } + } + + private readonly CreatureInterface creature; + private readonly Hero hero; + private float scale = 1; + private static readonly float MAX_RADIUS = 10; + private static readonly float MIN_RADIUS = 4; + private Vector3 vieportSize = new Vector3(0, 0, 0); + } +} diff --git a/Client/Application/ViewModels/DropMapViewModel.cs b/Client/Application/ViewModels/DropMapViewModel.cs new file mode 100644 index 0000000..16a06b4 --- /dev/null +++ b/Client/Application/ViewModels/DropMapViewModel.cs @@ -0,0 +1,84 @@ +using Client.Domain.Common; +using Client.Domain.Entities; +using Client.Domain.Enums; +using Client.Domain.ValueObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; + +namespace Client.Application.ViewModels +{ + public class DropMapViewModel : ObservableObject + { + public uint Id => drop.Id; + public string Name => drop.Name; + 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), + 0 + ); + public float Radius => MathF.Max(MAX_RADIUS / scale, MIN_RADIUS); + public float Scale + { + get => scale; + set + { + if (scale != value) + { + scale = value; + OnPropertyChanged("Position"); + OnPropertyChanged("Radius"); + } + } + } + public Vector3 VieportSize + { + get => vieportSize; + set + { + if (vieportSize != value) + { + vieportSize = value; + OnPropertyChanged("Position"); + } + } + } + + public DropMapViewModel(Drop drop, Hero hero) + { + this.drop = drop; + this.hero = hero; + drop.PropertyChanged += Creature_PropertyChanged; + drop.Transform.Position.PropertyChanged += Position_PropertyChanged; + hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged; + } + + private void HeroPosition_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + OnPropertyChanged("Position"); + } + + private void Position_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + OnPropertyChanged("Position"); + } + + private void Creature_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == "Name") + { + OnPropertyChanged("Name"); + } + } + + private readonly Drop drop; + private readonly Hero hero; + private float scale = 1; + private static readonly float MAX_RADIUS = 8; + private static readonly float MIN_RADIUS = 2; + private Vector3 vieportSize = new Vector3(0, 0, 0); + } +} diff --git a/Client/Application/ViewModels/MainViewModel.cs b/Client/Application/ViewModels/MainViewModel.cs index 2681f13..7f14ff0 100644 --- a/Client/Application/ViewModels/MainViewModel.cs +++ b/Client/Application/ViewModels/MainViewModel.cs @@ -35,12 +35,17 @@ namespace Client.Application.ViewModels Hero = new HeroSummaryInfoViewModel(@event.Hero); hero = @event.Hero; Map.Hero = hero; + AddCreature(hero); OnPropertyChanged("Hero"); OnPropertyChanged("Map"); } public void Handle(HeroDeletedEvent @event) { + if (hero != null) + { + RemoveCreature(hero.Id); + } Hero = null; hero = null; Map.Hero = null; @@ -53,12 +58,14 @@ namespace Client.Application.ViewModels if (hero != null) { Creatures.Add(new CreatureListViewModel(@event.Creature, hero)); + AddCreature(@event.Creature); } } public void Handle(CreatureDeletedEvent @event) { Creatures.RemoveAll(x => x.Id == @event.Id); + RemoveCreature(@event.Id); } public void Handle(DropCreatedEvent @event) @@ -66,12 +73,14 @@ namespace Client.Application.ViewModels if (hero != null) { Drops.Add(new DropListViewModel(@event.Drop, hero)); + Map.Drops.Add(new DropMapViewModel(@event.Drop, hero)); } } public void Handle(DropDeletedEvent @event) { Drops.RemoveAll(x => x.Id == @event.Id); + Map.Drops.RemoveAll(x => x.Id == @event.Id); } public void Handle(ChatMessageCreatedEvent @event) @@ -113,6 +122,19 @@ namespace Client.Application.ViewModels Items.RemoveAll(x => x.Id == @event.Id); } + private void AddCreature(CreatureInterface creature) + { + if (hero != null) + { + Map.Creatures.Add(new CreatureMapViewModel(creature, hero)); + } + } + + private void RemoveCreature(uint id) + { + Map.Creatures.RemoveAll(x => x.Id == id); + } + public ObservableCollection ChatMessages { get; } = new ObservableCollection(); public ObservableCollection Creatures { get; } = new ObservableCollection(); public ObservableCollection Drops { get; } = new ObservableCollection(); diff --git a/Client/Application/ViewModels/MapViewModel.cs b/Client/Application/ViewModels/MapViewModel.cs index 9bc36fd..0296f88 100644 --- a/Client/Application/ViewModels/MapViewModel.cs +++ b/Client/Application/ViewModels/MapViewModel.cs @@ -8,7 +8,9 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; using System.Windows.Media.Animation; +using System.Collections.Specialized; namespace Client.Application.ViewModels { @@ -35,44 +37,6 @@ namespace Client.Application.ViewModels } } - private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) - { - UpdateMap(); - } - - private void UpdateMap() - { - foreach (var block in Blocks) - { - block.Visible = false; - } - - if (hero != null) - { - var blocks = selector.SelectImages((float)ViewportWidth, (float)ViewportHeight, hero.Transform.Position, Scale); - - foreach (var block in blocks) - { - if (this.blocks.ContainsKey(block.Id)) - { - this.blocks[block.Id].MapBlock.DeltaX = block.DeltaX; - this.blocks[block.Id].MapBlock.DeltaY = block.DeltaY; - this.blocks[block.Id].MapBlock.Size = block.Size; - - } - else - { - var model = new MapBlockViewModel(block); - this.blocks.Add(block.Id, model); - Blocks.Add(model); - } - - this.blocks[block.Id].Visible = true; - } - } - } - - public ObservableCollection Blocks { get; } = new ObservableCollection(); public double ViewportWidth { get => viewportWidth; @@ -112,11 +76,96 @@ namespace Client.Application.ViewModels } } - MapImageSelector selector = new MapImageSelector(); - Dictionary blocks = new Dictionary(); + private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) + { + UpdateMap(); + } + + private void UpdateMap() + { + foreach (var block in Blocks) + { + block.Visible = false; + } + + if (hero != null) + { + var blocks = selector.SelectImages((float)ViewportWidth, (float)ViewportHeight, hero.Transform.Position, Scale); + + foreach (var block in blocks) + { + if (this.blocks.ContainsKey(block.Id)) + { + this.blocks[block.Id].MapBlock.DeltaX = block.DeltaX; + this.blocks[block.Id].MapBlock.DeltaY = block.DeltaY; + this.blocks[block.Id].MapBlock.Size = block.Size; + + } + else + { + var model = new MapBlockViewModel(block); + this.blocks.Add(block.Id, model); + Blocks.Add(model); + } + + this.blocks[block.Id].Visible = true; + } + + foreach (var creature in Creatures) + { + creature.Scale = scale; + creature.VieportSize = new Vector3((float)ViewportWidth, (float)ViewportHeight, 0); + } + + foreach (var drop in Drops) + { + drop.Scale = scale; + drop.VieportSize = new Vector3((float)ViewportWidth, (float)ViewportHeight, 0); + } + } + } + + public MapViewModel() + { + Creatures.CollectionChanged += Creatures_CollectionChanged; + Drops.CollectionChanged += Drops_CollectionChanged; + } + + private void Drops_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) + { + if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null) + { + foreach (var item in e.NewItems) + { + var creature = (DropMapViewModel)item; + creature.Scale = scale; + creature.VieportSize = new Vector3((float)ViewportWidth, (float)ViewportHeight, 0); + } + } + } + + private void Creatures_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) + { + if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null) + { + foreach (var item in e.NewItems) + { + var creature = (CreatureMapViewModel)item; + creature.Scale = scale; + creature.VieportSize = new Vector3((float)ViewportWidth, (float)ViewportHeight, 0); + } + } + } + + public ObservableCollection Blocks { get; } = new ObservableCollection(); + public ObservableCollection Creatures { get; } = new ObservableCollection(); + public ObservableCollection Drops { get; } = new ObservableCollection(); + + private MapImageSelector selector = new MapImageSelector(); + private Dictionary blocks = new Dictionary(); private Hero? hero; private float scale = 8; - private double viewportWidth = 50; - private double viewportHeight = 50; + private double viewportWidth = 0; + private double viewportHeight = 0; } } diff --git a/Client/Domain/Entities/CreatureInterface.cs b/Client/Domain/Entities/CreatureInterface.cs index 8c2cae2..8160b0d 100644 --- a/Client/Domain/Entities/CreatureInterface.cs +++ b/Client/Domain/Entities/CreatureInterface.cs @@ -1,4 +1,5 @@ -using Client.Domain.ValueObjects; +using Client.Domain.Enums; +using Client.Domain.ValueObjects; using System; using System.Collections.Generic; using System.ComponentModel; @@ -15,6 +16,8 @@ namespace Client.Domain.Entities Transform Transform { get; set; } string Name { get; } string BriefInfo { get; } + CreatureTypeEnum Type { get; } + uint AggroRadius { get; set; } } } diff --git a/Client/Domain/Entities/Drop.cs b/Client/Domain/Entities/Drop.cs index 20543cb..7ce1bb6 100644 --- a/Client/Domain/Entities/Drop.cs +++ b/Client/Domain/Entities/Drop.cs @@ -1,4 +1,5 @@ using Client.Domain.Common; +using Client.Domain.Enums; using Client.Domain.ValueObjects; namespace Client.Domain.Entities @@ -13,11 +14,11 @@ namespace Client.Domain.Entities private string iconName; public uint Id { get => id; set => id = value; } - public Transform Transform { get => transform; set { if (value != transform) { transform = value; OnPropertyChanged("Transform"); } } } - public uint ItemId { get => itemId; set { if (value != itemId) { itemId = value; OnPropertyChanged("ItemId"); } } } - public uint Amount { get => amount; set { if (value != amount) { amount = value; OnPropertyChanged("Amount"); } } } - public string Name { get => name; set { if (value != name) { name = value; OnPropertyChanged("Name"); } } } - public string IconName { get => iconName; set { if (value != iconName) { iconName = value; OnPropertyChanged("IconName"); } } } + public Transform Transform { get => transform; set { if (value != transform) { transform = value; OnPropertyChanged(); } } } + public uint ItemId { get => itemId; set { if (value != itemId) { itemId = value; OnPropertyChanged(); } } } + public uint Amount { get => amount; set { if (value != amount) { amount = value; OnPropertyChanged(); } } } + public string Name { get => name; set { if (value != name) { name = value; OnPropertyChanged(); } } } + public string IconName { get => iconName; set { if (value != iconName) { iconName = value; OnPropertyChanged(); } } } public Drop(uint id, Transform transform, uint itemId, uint amount, string name, string iconName) { diff --git a/Client/Domain/Entities/Hero.cs b/Client/Domain/Entities/Hero.cs index f1995c1..3dba512 100644 --- a/Client/Domain/Entities/Hero.cs +++ b/Client/Domain/Entities/Hero.cs @@ -1,4 +1,5 @@ using Client.Domain.Common; +using Client.Domain.Enums; using Client.Domain.ValueObjects; using System.ComponentModel; using System.Diagnostics; @@ -18,6 +19,7 @@ namespace Client.Domain.Entities public uint TargetId { get => targetId; set { if (value != targetId) { targetId = value; OnPropertyChanged("TargetId"); } } } public CreatureInterface? Target { get => target; set { if (value != target) { target = value; OnPropertyChanged("Target"); } } } public bool IsStanding { get; set; } + public CreatureTypeEnum Type { get => CreatureTypeEnum.Hero; } public FullName FullName { get => fullName; @@ -59,6 +61,7 @@ namespace Client.Domain.Entities return Phenotype.Race.ToString() + ", " + Phenotype.Class.ToString(); } } + public uint AggroRadius { get; set; } = 0; public Hero(uint id, Transform transform, FullName fullName, VitalStats vitalStats, Phenotype phenotype, ExperienceInfo experienceInfo, PermanentStats permanentStats, VariableStats variableStats, Reputation reputation, InventoryInfo inventoryInfo, uint targetId, bool isStanding) { diff --git a/Client/Domain/Entities/NPC.cs b/Client/Domain/Entities/NPC.cs index 691dad6..4514b33 100644 --- a/Client/Domain/Entities/NPC.cs +++ b/Client/Domain/Entities/NPC.cs @@ -67,17 +67,17 @@ namespace Client.Domain.Entities } } } + public string Name { get { - string result = ""; + string result = FullName.Nickname; if (IsDead()) { - result += "Dead "; + result += " (dead)"; } - result += FullName.Nickname + "[" + NpcId + "]"; return result; } @@ -97,11 +97,12 @@ namespace Client.Domain.Entities result += "*"; } } + result += "<" + NpcId + ">"; result += " " + Level + "lvl"; return result; } } - + public CreatureTypeEnum Type { get => CreatureTypeEnum.NPC; } public NPC(uint id, Transform transform, bool isHostile, uint npcId, SpoilStateEnum spoilState, FullName fullName, VitalStats vitalStats) { Id = id; diff --git a/Client/Domain/Entities/Player.cs b/Client/Domain/Entities/Player.cs index 161f0e1..76114a0 100644 --- a/Client/Domain/Entities/Player.cs +++ b/Client/Domain/Entities/Player.cs @@ -60,6 +60,8 @@ namespace Client.Domain.Entities } public VitalStats VitalStats { get => vitalStats; set => vitalStats = value; } + public CreatureTypeEnum Type { get => CreatureTypeEnum.Player; } + public uint AggroRadius { get; set; } = 0; public Player(uint id, Transform transform, FullName fullName, Phenotype phenotype) { diff --git a/Client/Domain/Enums/CreatureTypeEnum.cs b/Client/Domain/Enums/CreatureTypeEnum.cs new file mode 100644 index 0000000..91236a6 --- /dev/null +++ b/Client/Domain/Enums/CreatureTypeEnum.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Client.Domain.Enums +{ + public enum CreatureTypeEnum + { + NPC, + Player, + Hero + } +} diff --git a/Client/Domain/ValueObjects/Transform.cs b/Client/Domain/ValueObjects/Transform.cs index 4380e42..8db9f39 100644 --- a/Client/Domain/ValueObjects/Transform.cs +++ b/Client/Domain/ValueObjects/Transform.cs @@ -1,4 +1,5 @@ using Client.Domain.Common; +using System; namespace Client.Domain.ValueObjects { @@ -9,10 +10,40 @@ namespace Client.Domain.ValueObjects private Vector3 velocity; private Vector3 acceleration; - public Vector3 Position { get => position; set { if (value != position) { position = value; OnPropertyChanged("Position"); } } } - public Vector3 Rotation { get => rotation; set { if (value != rotation) { rotation = value; OnPropertyChanged("Rotation"); } } } - public Vector3 Velocity { get => velocity; set { if (value != velocity) { velocity = value; OnPropertyChanged("Velocity"); } } } - public Vector3 Acceleration { get => acceleration; set { if (value != acceleration) { acceleration = value; OnPropertyChanged("Acceleration"); } } } + public Vector3 Position { get => position; set { if (value != position) { position = value; OnPropertyChanged(); } } } + public Vector3 Rotation { + get => rotation; + set + { + if (value != rotation) + { + rotation = value; + OnPropertyChanged(); + OnPropertyChanged("Direction"); + } + } + } + + private void Rotation_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName == "Y") + { + OnPropertyChanged("Direction"); + } + } + + public Vector3 Velocity { get => velocity; set { if (value != velocity) { velocity = value; OnPropertyChanged(); } } } + public Vector3 Acceleration { get => acceleration; set { if (value != acceleration) { acceleration = value; OnPropertyChanged(); } } } + + public Vector3 Direction + { + get + { + float deg = Rotation.Y / 65535 * 2 * MathF.PI; + + return new Vector3(MathF.Cos(deg), MathF.Sin(deg), 0); + } + } public Transform(Vector3 position, Vector3 rotation, Vector3 velocity, Vector3 acceleration) { @@ -20,6 +51,7 @@ namespace Client.Domain.ValueObjects this.rotation = rotation; this.velocity = velocity; this.acceleration = acceleration; + rotation.PropertyChanged += Rotation_PropertyChanged; } } }