feat: create creature interface

This commit is contained in:
k0t9i
2023-01-31 15:14:19 +04:00
parent b8b92b7cf8
commit 31febdd341
16 changed files with 279 additions and 275 deletions

View File

@@ -0,0 +1,19 @@
using Client.Domain.ValueObjects;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.Domain.Entities
{
public interface CreatureInterface : INotifyPropertyChanged
{
uint Id { get; set; }
Transform Transform { get; set; }
string Name { get; }
string BriefInfo { get; }
}
}

View File

@@ -10,17 +10,97 @@ using System.Threading.Tasks;
namespace Client.Domain.Entities
{
public class NPC : NotifyPropertyChanged, EntityInterface
public class NPC : NotifyPropertyChanged, EntityInterface, CreatureInterface
{
public uint Id { get; set; }
public Transform Transform { get; set; }
public bool IsHostile { get; set; }
public uint NpcId { get; set; }
public SpoilStateEnum SpoilState { get; set; }
public FullName FullName { get; set; }
public VitalStats VitalStats { get; set; }
public uint Level { get => level; set { if (value != level) { level = value; OnPropertyChanged("Level"); } } }
public uint AggroRadius { get => aggroRadius; set { if (value != aggroRadius) { aggroRadius = value; OnPropertyChanged("AggroRadius"); } } }
public FullName FullName
{
get => fullName;
set
{
fullName = value;
if (fullName != null)
{
FullName.PropertyChanged += FullName_PropertyChanged;
}
}
}
public VitalStats VitalStats
{
get => vitalStats;
set
{
vitalStats = value;
if (vitalStats != null)
{
VitalStats.PropertyChanged += VitalStats_PropertyChanged;
}
}
}
public uint Level
{
get => level;
set
{
if (value != level)
{
level = value;
OnPropertyChanged("Level");
OnPropertyChanged("BriefInfo");
}
}
}
public uint AggroRadius
{
get => aggroRadius;
set
{
if (value != aggroRadius)
{
aggroRadius = value;
OnPropertyChanged("AggroRadius");
OnPropertyChanged("BriefInfo");
}
}
}
public string Name
{
get
{
string result = "";
if (IsDead())
{
result += "Dead ";
}
result += FullName.Nickname + "[" + NpcId + "]";
return result;
}
}
public string BriefInfo
{
get
{
string result = "Npc";
if (IsHostile)
{
result = "Monster";
if (AggroRadius > 0)
{
result += "*";
}
}
result += " " + Level + "lvl";
return result;
}
}
public NPC(uint id, Transform transform, bool isHostile, uint npcId, SpoilStateEnum spoilState, FullName fullName, VitalStats vitalStats)
{
@@ -33,6 +113,22 @@ namespace Client.Domain.Entities
VitalStats = vitalStats;
}
private void FullName_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "Nickname")
{
OnPropertyChanged("Name");
}
}
private void VitalStats_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "Hp" || e.PropertyName == "MaxHp")
{
OnPropertyChanged("Name");
}
}
public bool IsDead()
{
return VitalStats.MaxHp > 0 && VitalStats.Hp <= 0;
@@ -40,5 +136,7 @@ namespace Client.Domain.Entities
private uint level;
private uint aggroRadius;
private VitalStats vitalStats;
private FullName fullName;
}
}

View File

@@ -1,19 +1,62 @@
using Client.Domain.Enums;
using Client.Domain.Common;
using Client.Domain.Enums;
using Client.Domain.ValueObjects;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace Client.Domain.Entities
{
public class Player : EntityInterface
public class Player : NotifyPropertyChanged, EntityInterface, CreatureInterface
{
private FullName fullName;
private Phenotype phenotype;
public uint Id { get; set; }
public Transform Transform { get; set; }
public FullName FullName { get; set; }
public Phenotype Phenotype { get; set; }
public FullName FullName
{
get => fullName;
set
{
fullName = value;
if (fullName != null)
{
FullName.PropertyChanged += FullName_PropertyChanged;
}
}
}
public Phenotype Phenotype
{
get => phenotype;
set
{
phenotype = value;
if (phenotype != null)
{
Phenotype.PropertyChanged += Phenotype_PropertyChanged;
}
}
}
public string Name
{
get
{
return FullName.Nickname;
}
}
public string BriefInfo
{
get
{
//todo race and class strings
return Phenotype.Race.ToString() + ", " + Phenotype.Class.ToString();
}
}
public Player(uint id, Transform transform, FullName fullName, Phenotype phenotype)
{
@@ -22,5 +65,21 @@ namespace Client.Domain.Entities
FullName = fullName;
Phenotype = phenotype;
}
private void Phenotype_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Race" || e.PropertyName == "Class")
{
OnPropertyChanged("BriefInfo");
}
}
private void FullName_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Nickname")
{
OnPropertyChanged("Name");
}
}
}
}