From e8b3d21e9f32c6c206635e1608be4b1ca0edd0fd Mon Sep 17 00:00:00 2001 From: Rutherther Date: Thu, 3 Feb 2022 18:33:25 +0100 Subject: [PATCH] feat(game): add basic entity and map data --- .../Data/Characters/Character.cs | 149 +++++++--------- Core/NosSmooth.Game/Data/Characters/Skill.cs | 9 +- .../Data/Entities/GroundItem.cs | 45 ++++- Core/NosSmooth.Game/Data/Entities/IEntity.cs | 9 +- .../Data/Entities/LivingEntity.cs | 41 ++++- Core/NosSmooth.Game/Data/Entities/Monster.cs | 83 ++++++--- Core/NosSmooth.Game/Data/Entities/Npc.cs | 59 +++++- Core/NosSmooth.Game/Data/Entities/Player.cs | 168 +++++++++++++----- Core/NosSmooth.Game/Data/Info/Health.cs | 103 ++++++++++- Core/NosSmooth.Game/Data/Info/Level.cs | 2 +- Core/NosSmooth.Game/Data/Info/Position.cs | 19 +- Core/NosSmooth.Game/Data/Items/Equipment.cs | 21 +++ Core/NosSmooth.Game/Data/Items/Fairy.cs | 12 ++ Core/NosSmooth.Game/Data/Items/Item.cs | 16 ++ .../Data/Items/UpgradeableItem.cs | 18 ++ Core/NosSmooth.Game/Data/Maps/Map.cs | 36 +++- Core/NosSmooth.Game/Data/Maps/MapEntities.cs | 100 +++++++++++ Core/NosSmooth.Game/Data/Maps/Miniland.cs | 19 +- Core/NosSmooth.Game/Data/Maps/Portal.cs | 11 +- Core/NosSmooth.Game/Data/Social/Family.cs | 9 +- 20 files changed, 723 insertions(+), 206 deletions(-) create mode 100644 Core/NosSmooth.Game/Data/Items/Equipment.cs create mode 100644 Core/NosSmooth.Game/Data/Items/Fairy.cs create mode 100644 Core/NosSmooth.Game/Data/Items/Item.cs create mode 100644 Core/NosSmooth.Game/Data/Items/UpgradeableItem.cs create mode 100644 Core/NosSmooth.Game/Data/Maps/MapEntities.cs diff --git a/Core/NosSmooth.Game/Data/Characters/Character.cs b/Core/NosSmooth.Game/Data/Characters/Character.cs index 005295a..ae383f3 100644 --- a/Core/NosSmooth.Game/Data/Characters/Character.cs +++ b/Core/NosSmooth.Game/Data/Characters/Character.cs @@ -16,89 +16,66 @@ namespace NosSmooth.Game.Data.Characters; /// /// Represents the client character. /// -/// The character's inventory with items. -/// The family of the character, if any.. -/// The friends of the character. -/// The current skill set of the character. -/// The group the character is in, if any. Contains pets and partners as well. -/// The skill cp amount used for learning new skills. -/// The id of the character entity. -/// The name of the character entity. -/// The position of the character. -/// The movement speed of the character. -/// The -/// The -/// The -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -public record Character -( - Inventory.Inventory? Inventory = default, - Family? Family = default, - IReadOnlyList? Friends = default, - Skills? Skills = default, - Group? Group = default, - int? SkillCp = default, - long Id = default, - string? Name = default, - Position? Position = default, - byte? Speed = default, - Level? Level = default, - Level? JobLevel = default, - Level? HeroLevel = default, - byte? Direction = default, - Health? Hp = default, - Health? Mp = default, - FactionType? Faction = default, - short Size = default, - AuthorityType AuthorityType = default, - SexType Sex = default, - HairStyle HairStyle = default, - HairColor HairColor = default, - PlayerClass Class = default, - byte? Icon = default, - short? Compliment = default, - Morph? Morph = default, - bool? ArenaWinner = default, - bool? Invisible = default, - long? Reputation = default, - IReadOnlyList? EffectsVNums = default -) : Player( - Id, - Name, - Position, - Speed, - Level, - HeroLevel, - Direction, - Hp, - Mp, - Faction, - Size, - AuthorityType, - Sex, - HairStyle, - HairColor, - Class, - Icon, - Compliment, - Morph, - ArenaWinner, - Invisible, - Reputation, - EffectsVNums -); \ No newline at end of file +public class Character : Player +{ + /// + /// Gets or sets whether the character can't move. + /// + public bool Stunned { get; set; } + + /// + /// Gets or sets the inventory of the character. + /// + public Inventory.Inventory? Inventory { get; set; } + + /// + /// Get or sets the friends of the character. + /// + public IReadOnlyList? Friends { get; set; } + + /// + /// Gets or sets the skills of the player. + /// + public Skills? Skills { get; set; } + + /// + /// Gets or sets the group the player is in. + /// + public Group? Group { get; set; } + + /// + /// Gets or sets the c skill points. + /// + public int? SkillCp { get; set; } + + /// + /// Gets or sets the job level. + /// + public Level? JobLevel { get; set; } + + /// + /// Gets or sets the player level. + /// + public Level? PlayerLevel { get; set; } + + /// + /// Gets or sets the player level. + /// + public Level? HeroLevelStruct { get; set; } + + /// + public override short? HeroLevel + { + get => HeroLevelStruct?.Lvl; + set + { + if (HeroLevelStruct is not null && value is not null) + { + HeroLevelStruct = HeroLevelStruct with + { + Lvl = value.Value + }; + } + } + } +} \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Characters/Skill.cs b/Core/NosSmooth.Game/Data/Characters/Skill.cs index 91ed156..c329909 100644 --- a/Core/NosSmooth.Game/Data/Characters/Skill.cs +++ b/Core/NosSmooth.Game/Data/Characters/Skill.cs @@ -4,6 +4,8 @@ // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using NosSmooth.Data.Abstractions.Infos; + namespace NosSmooth.Game.Data.Characters; /// @@ -11,18 +13,13 @@ namespace NosSmooth.Game.Data.Characters; /// /// The vnum of the skill. /// The level of the skill. Unknown feature. -public record Skill(long SkillVNum, int? Level = default) +public record Skill(int SkillVNum, int? Level = default, ISkillInfo? Info = default) { /// /// Gets the last time this skill was used. /// public DateTimeOffset LastUseTime { get; internal set; } - /// - /// Gets the cooldown of the skill. - /// - public TimeSpan? Cooldown { get; internal set; } - /// /// Gets whether the skill is on cooldown. /// diff --git a/Core/NosSmooth.Game/Data/Entities/GroundItem.cs b/Core/NosSmooth.Game/Data/Entities/GroundItem.cs index 023cd5e..c03b5d2 100644 --- a/Core/NosSmooth.Game/Data/Entities/GroundItem.cs +++ b/Core/NosSmooth.Game/Data/Entities/GroundItem.cs @@ -4,6 +4,7 @@ // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using NosSmooth.Data.Abstractions.Infos; using NosSmooth.Game.Data.Info; using NosSmooth.Packets.Enums; @@ -12,14 +13,42 @@ namespace NosSmooth.Game.Data.Entities; /// /// The item on the ground. /// -/// The id of the item entity. -/// The vnum of the dropped item. -/// The position of the ground item. -public record GroundItem(long Id, long ItemVNum, Position? Position) : IEntity +public class GroundItem : IEntity { - /// - public string? Name => null; + /// + /// Gets or sets the id of the owner, if any. + /// + public long? OwnerId { get; set; } - /// - public EntityType Type => EntityType.Object; + /// + /// Gets or sets the amount of the item on the ground. + /// + public int Amount { get; internal set; } + + /// + /// Gets or sets whether the item is for a quest. + /// + public bool IsQuestRelated { get; internal set; } + + /// + /// Gets or sets the info about the item, if available. + /// + public IItemInfo? ItemInfo { get; internal set; } + + /// + /// Gets the VNum of the npc. + /// + public int VNum { get; internal set; } + + /// + public long Id { get; set; } + + /// + public Position? Position { get; set; } + + /// + public EntityType Type + { + get => EntityType.Object; + } } \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Entities/IEntity.cs b/Core/NosSmooth.Game/Data/Entities/IEntity.cs index a11821a..a827383 100644 --- a/Core/NosSmooth.Game/Data/Entities/IEntity.cs +++ b/Core/NosSmooth.Game/Data/Entities/IEntity.cs @@ -17,17 +17,12 @@ public interface IEntity /// /// Gets the id of the entity. /// - public long Id { get; } - - /// - /// Gets the name of the entity. May be null if unknown. - /// - public string? Name { get; } + public long Id { get; set; } /// /// Gets the position of the entity. /// - public Position? Position { get; } + public Position? Position { get; set; } /// /// Gets the type of the entity. diff --git a/Core/NosSmooth.Game/Data/Entities/LivingEntity.cs b/Core/NosSmooth.Game/Data/Entities/LivingEntity.cs index 6428a32..b3775e2 100644 --- a/Core/NosSmooth.Game/Data/Entities/LivingEntity.cs +++ b/Core/NosSmooth.Game/Data/Entities/LivingEntity.cs @@ -17,40 +17,65 @@ public interface ILivingEntity : IEntity /// /// Gets the speed of the entity. May be null if unknown. /// - public byte? Speed { get; } + public int? Speed { get; set; } + + /// + /// Gets or sets whether the player is invisible. + /// + public bool? IsInvisible { get; set; } /// /// Gets the level of the entity. May be null if unknown. /// - public ushort? Level { get; } + public ushort? Level { get; set; } /// /// Gets the direction the entity is looking. May be null if unknown. /// - public byte? Direction { get; } + public byte? Direction { get; set; } /// /// Gets the percentage of the health points of the entity. May be null if unknown. /// - public Health? Hp { get; } + public Health? Hp { get; set; } /// /// Gets the percentage of the mana points of the entity. May be null if unknown. /// - public Health? Mp { get; } + public Health? Mp { get; set; } /// /// Gets the faction of the entity. May be null if unknown. /// - public FactionType? Faction { get; } + public FactionType? Faction { get; set; } /// /// Gets the size of the entity. /// - public short Size { get; } + public short Size { get; set; } /// /// Gets the VNums of the effects the entity has. /// - public IReadOnlyList? EffectsVNums { get; } + public IReadOnlyList? EffectsVNums { get; set; } + + /// + /// Gets the name of the entity. May be null if unknown. + /// + public string? Name { get; set; } + + /// + /// Gets or sets whether the entity is sitting. + /// + public bool IsSitting { get; set; } + + /// + /// Gets or sets whether the entity cannot move. + /// + public bool CantMove { get; set; } + + /// + /// Gets or sets whether the entity cannot attack. + /// + public bool CantAttack { get; set; } } \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Entities/Monster.cs b/Core/NosSmooth.Game/Data/Entities/Monster.cs index 91a8d79..e5b820e 100644 --- a/Core/NosSmooth.Game/Data/Entities/Monster.cs +++ b/Core/NosSmooth.Game/Data/Entities/Monster.cs @@ -4,6 +4,7 @@ // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using NosSmooth.Data.Abstractions.Infos; using NosSmooth.Game.Data.Info; using NosSmooth.Packets.Enums; @@ -12,33 +13,63 @@ namespace NosSmooth.Game.Data.Entities; /// /// Represents nostale monster entity. /// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -public record Monster -( - long Id, - string? Name, - Position? Position, - byte? Speed, - ushort? Level, - byte? Direction, - Health? Hp, - Health? Mp, - FactionType? Faction, - short Size, - long MonsterVNum, - IReadOnlyList? EffectsVNums = default -) : ILivingEntity +public class Monster : ILivingEntity { + /// + /// Gets or sets the monster info. + /// + public IMonsterInfo? MonsterInfo { get; set; } + + /// + /// Gets the VNum of the monster. + /// + public int VNum { get; set; } + + /// + public long Id { get; set; } + + /// + public string? Name { get; set; } + + /// + public bool IsSitting { get; set; } + + /// + public bool CantMove { get; set; } + + /// + public bool CantAttack { get; set; } + + /// + public Position? Position { get; set; } + /// public EntityType Type => EntityType.Monster; + + /// + public int? Speed { get; set; } + + /// + public bool? IsInvisible { get; set; } + + /// + public ushort? Level { get; set; } + + /// + public byte? Direction { get; set; } + + /// + public Health? Hp { get; set; } + + /// + public Health? Mp { get; set; } + + /// + public FactionType? Faction { get; set; } + + /// + public short Size { get; set; } + + /// + public IReadOnlyList? EffectsVNums { get; set; } } \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Entities/Npc.cs b/Core/NosSmooth.Game/Data/Entities/Npc.cs index da75fbe..cf177ac 100644 --- a/Core/NosSmooth.Game/Data/Entities/Npc.cs +++ b/Core/NosSmooth.Game/Data/Entities/Npc.cs @@ -4,9 +4,66 @@ // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using NosSmooth.Game.Data.Info; +using NosSmooth.Packets.Enums; + namespace NosSmooth.Game.Data.Entities; /// /// Represents nostale npc entity. /// -public record Npc(); \ No newline at end of file +public class Npc : ILivingEntity +{ + /// + /// Gets the VNum of the npc. + /// + public int VNum { get; internal set; } + + /// + public long Id { get; set; } + + /// + public string? Name { get; set; } + + /// + public bool IsSitting { get; set; } + + /// + public bool CantMove { get; set; } + + /// + public bool CantAttack { get; set; } + + /// + public Position? Position { get; set; } + + /// + public EntityType Type => EntityType.Npc; + + /// + public int? Speed { get; set; } + + /// + public bool? IsInvisible { get; set; } + + /// + public ushort? Level { get; set; } + + /// + public byte? Direction { get; set; } + + /// + public Health? Hp { get; set; } + + /// + public Health? Mp { get; set; } + + /// + public FactionType? Faction { get; set; } + + /// + public short Size { get; set; } + + /// + public IReadOnlyList? EffectsVNums { get; set; } +} \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Entities/Player.cs b/Core/NosSmooth.Game/Data/Entities/Player.cs index d8ffc80..4141a1b 100644 --- a/Core/NosSmooth.Game/Data/Entities/Player.cs +++ b/Core/NosSmooth.Game/Data/Entities/Player.cs @@ -5,6 +5,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using NosSmooth.Game.Data.Info; +using NosSmooth.Game.Data.Items; +using NosSmooth.Game.Data.Social; using NosSmooth.Packets.Enums; using NosSmooth.Packets.Enums.Players; @@ -13,56 +15,128 @@ namespace NosSmooth.Game.Data.Entities; /// /// Represents nostale player entity. /// -/// The id of the player. -/// The name of the player. -/// The position the player is at. -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -public record Player -( - long Id, - string? Name = default, - Position? Position = default, - byte? Speed = default, - Level? Level = default, - Level? HeroLevel = default, - byte? Direction = default, - Health? Hp = default, - Health? Mp = default, - FactionType? Faction = default, - short Size = default, - AuthorityType AuthorityType = default, - SexType Sex = default, - HairStyle HairStyle = default, - HairColor HairColor = default, - PlayerClass Class = default, - byte? Icon = default, - short? Compliment = default, - Morph? Morph = default, - bool? ArenaWinner = default, - bool? Invisible = default, - long? Reputation = default, - IReadOnlyList? EffectsVNums = default -) : ILivingEntity +public class Player : ILivingEntity { + /// + /// Gets or sets the authority of the player. + /// + public AuthorityType Authority { get; set; } + + /// + /// Gets or sets the sex of the player. + /// + public SexType Sex { get; set; } + + /// + /// Gets or sets the hairstyle of the player. + /// + public HairStyle HairStyle { get; set; } + + /// + /// Gets or sets the hair color of the player. + /// + public HairColor HairColor { get; set; } + + /// + /// Gets or sets the class of the player. + /// + public PlayerClass Class { get; set; } + + /// + /// Gets or sets the reputation icon. UNKNOWN TODO. + /// + public byte? Icon { get; set; } + + /// + /// UNKNOWN TODO. + /// + public short? Compliment { get; set; } + + /// + /// Gets or sets the morph used for sps, vehicles and such. + /// + public Morph? Morph { get; set; } + + /// + /// Gets or sets whether the player is a champion arena winner. + /// + public bool ArenaWinner { get; set; } + + /// + /// Gets or sets the reputation number of the player. + /// + public long? Reputation { get; set; } + + /// + /// Gets or sets the visible title of the player. + /// + public short Title { get; set; } + + /// + /// Gets or sets the family. + /// + public Family? Family { get; set; } + + /// + /// Gets the VNum of the npc. + /// + public int VNum { get; set; } + + /// + public long Id { get; set; } + /// - ushort? ILivingEntity.Level => Level?.Lvl; + public string? Name { get; set; } + + /// + public bool IsSitting { get; set; } /// + public bool CantMove { get; set; } + + /// + public bool CantAttack { get; set; } + + /// + public Position? Position { get; set; } + + /// public EntityType Type => EntityType.Player; + + /// + public int? Speed { get; set; } + + /// + public bool? IsInvisible { get; set; } + + /// + public ushort? Level { get; set; } + + /// + public byte? Direction { get; set; } + + /// + public Health? Hp { get; set; } + + /// + public Health? Mp { get; set; } + + /// + public FactionType? Faction { get; set; } + + /// + public short Size { get; set; } + + /// + public IReadOnlyList? EffectsVNums { get; set; } + + /// + /// Gets or sets the hero level. + /// + public virtual short? HeroLevel { get; set; } + + /// + /// Gets or sets the equipment. + /// + public Equipment? Equipment { get; set; } } \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Info/Health.cs b/Core/NosSmooth.Game/Data/Info/Health.cs index 2ec133d..bcdb806 100644 --- a/Core/NosSmooth.Game/Data/Info/Health.cs +++ b/Core/NosSmooth.Game/Data/Info/Health.cs @@ -9,9 +9,104 @@ namespace NosSmooth.Game.Data.Info; /// /// Represents the health or mana of an entity. /// -/// The current amount of health. -/// The maximum amount of health. -public record Health(long Amount, long Maximum) +public class Health { - private decimal Percentage => (decimal)Amount / Maximum; + private byte? _percentage; + private long? _amount; + private long? _maximum; + + /// + /// Gets or sets the percentage of the health. + /// + public byte? Percentage + { + get => _percentage; + set + { + _percentage = value; + if (value is null) + { + return; + } + + var maximum = _maximum; + if (maximum is not null) + { + _amount = (long)((value / 100.0) * maximum); + return; + } + + var amount = _amount; + if (amount is not null) + { + _maximum = (long)(amount / (value / 100.0)); + } + } + } + + /// + /// Gets or sets the health amount. + /// + public long? Amount + { + get => _amount; + set + { + _amount = value; + if (value is null) + { + return; + } + + var maximum = _maximum; + if (maximum is not null) + { + _percentage = (byte)(((double)value / maximum) * 100); + return; + } + + var percentage = _percentage; + if (percentage is not null) + { + _maximum = (long)(value / (percentage / 100.0)); + } + } + } + + /// + /// Gets or sets the maximum health. + /// + public long? Maximum + { + get => _maximum; + set + { + _maximum = value; + if (value is null) + { + return; + } + + var amount = _amount; + var percentage = _percentage; + + if (amount is not null) + { + if (amount > value) + { + amount = _amount = value; + _percentage = 100; + return; + } + + _percentage = (byte)((amount / (double)value) * 100); + return; + } + + if (percentage is not null) + { // ? would this be correct? + _amount = (long)((percentage / 100.0) * value); + } + } + } } \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Info/Level.cs b/Core/NosSmooth.Game/Data/Info/Level.cs index 03e4695..9f1c92c 100644 --- a/Core/NosSmooth.Game/Data/Info/Level.cs +++ b/Core/NosSmooth.Game/Data/Info/Level.cs @@ -12,4 +12,4 @@ namespace NosSmooth.Game.Data.Info; /// The level. /// Current xp. /// Maximum xp of the current level. -public record Level(ushort Lvl, long Xp, long XpLoad); \ No newline at end of file +public record Level(short Lvl, long Xp, long XpLoad); \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Info/Position.cs b/Core/NosSmooth.Game/Data/Info/Position.cs index dae67b6..da8268b 100644 --- a/Core/NosSmooth.Game/Data/Info/Position.cs +++ b/Core/NosSmooth.Game/Data/Info/Position.cs @@ -4,20 +4,23 @@ // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Diagnostics.CodeAnalysis; + namespace NosSmooth.Game.Data.Info; /// /// Represents nostale position on map. /// -public record Position +[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1313", MessageId = "Parameter names should begin with lower-case letter", Justification = "Standard.")] +public record struct Position(long X, long Y) { /// - /// Gets the x coordinate. - /// - public long X { get; internal set; } - - /// - /// Gets the y coordinate. + /// Get the squared distance to the given position. /// - public long Y { get; internal set; } + /// The position. + /// The distance squared. + public long DistanceSquared(Position position) + { + return ((position.X - X) * (position.X - X)) + ((position.Y - Y) * (position.Y - Y)); + } } \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Items/Equipment.cs b/Core/NosSmooth.Game/Data/Items/Equipment.cs new file mode 100644 index 0000000..12e55d5 --- /dev/null +++ b/Core/NosSmooth.Game/Data/Items/Equipment.cs @@ -0,0 +1,21 @@ +// +// Equipment.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace NosSmooth.Game.Data.Items; + +public record Equipment +( + Item? Hat, + UpgradeableItem? Armor, + UpgradeableItem? MainWeapon, + UpgradeableItem? SecondaryWeapon, + Item? Mask, + Item? Fairy, + Item? CostumeSuit, + Item? CostumeHat, + short? WeaponSkin, + short? WingSkin +); \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Items/Fairy.cs b/Core/NosSmooth.Game/Data/Items/Fairy.cs new file mode 100644 index 0000000..ab4e3b1 --- /dev/null +++ b/Core/NosSmooth.Game/Data/Items/Fairy.cs @@ -0,0 +1,12 @@ +// +// Fairy.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using NosSmooth.Data.Abstractions.Infos; +using NosSmooth.Packets.Enums; + +namespace NosSmooth.Game.Data.Items; + +public record Fairy(int ItemVNum, Element Element, IItemInfo? Info) : Item(ItemVNum, Info); \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Items/Item.cs b/Core/NosSmooth.Game/Data/Items/Item.cs new file mode 100644 index 0000000..581f85a --- /dev/null +++ b/Core/NosSmooth.Game/Data/Items/Item.cs @@ -0,0 +1,16 @@ +// +// Item.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using NosSmooth.Data.Abstractions.Infos; + +namespace NosSmooth.Game.Data.Items; + +/// +/// A NosTale item. +/// +/// +/// +public record Item(int ItemVNum, IItemInfo? Info); \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Items/UpgradeableItem.cs b/Core/NosSmooth.Game/Data/Items/UpgradeableItem.cs new file mode 100644 index 0000000..e8e16de --- /dev/null +++ b/Core/NosSmooth.Game/Data/Items/UpgradeableItem.cs @@ -0,0 +1,18 @@ +// +// UpgradeableItem.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using NosSmooth.Data.Abstractions.Infos; + +namespace NosSmooth.Game.Data.Items; + +/// +/// An item that can be upgraded and has rarity, ie. weapon or armor. +/// +/// The vnum of the item. +/// The information about the item. +/// The upgrade (0 - 10). +/// The rare nubmer (0 - 8). +public record UpgradeableItem(int ItemVNum, IItemInfo? Info, byte? Upgrade, sbyte? Rare) : Item(ItemVNum, Info); \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Maps/Map.cs b/Core/NosSmooth.Game/Data/Maps/Map.cs index 80d7d80..12e53f9 100644 --- a/Core/NosSmooth.Game/Data/Maps/Map.cs +++ b/Core/NosSmooth.Game/Data/Maps/Map.cs @@ -4,9 +4,43 @@ // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Diagnostics.CodeAnalysis; +using NosSmooth.Data.Abstractions.Infos; +using NosSmooth.Game.Data.Info; + namespace NosSmooth.Game.Data.Maps; /// /// Represents nostale map. /// -public record Map(); \ No newline at end of file +public record Map +( + long Id, + byte Type, + IMapInfo? Info, + MapEntities Entities, + IReadOnlyList Portals +) +{ + /// + /// Gets whether the given position lies on a portal. + /// + /// The position. + /// The portal the position is on, if any. + /// Whether there was a portal at the specified position. + public bool IsOnPortal(Position position, [NotNullWhen(true)] out Portal? portal) + { + foreach (var p in Portals) + { + // TODO: figure out the distance + if (p.Position.DistanceSquared(position) < 3) + { + portal = p; + return true; + } + } + + portal = null; + return false; + } +} \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Maps/MapEntities.cs b/Core/NosSmooth.Game/Data/Maps/MapEntities.cs new file mode 100644 index 0000000..3e6f1ad --- /dev/null +++ b/Core/NosSmooth.Game/Data/Maps/MapEntities.cs @@ -0,0 +1,100 @@ +// +// MapEntities.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Collections.Concurrent; +using NosSmooth.Game.Data.Entities; +using NosSmooth.Packets.Enums; + +namespace NosSmooth.Game.Data.Maps; + +/// +/// Thread-safe store for the entities on the map. +/// +public class MapEntities +{ + private readonly ConcurrentDictionary _entities; + + /// + /// Initializes a new instance of the class. + /// + public MapEntities() + { + _entities = new ConcurrentDictionary(); + } + + /// + /// Gets the given entity by id. + /// + /// The id of the entity. + /// The entity, or null, if not found. + public IEntity? GetEntity(long id) + => _entities.GetValueOrDefault(id); + + /// + /// Get the given entity by id. + /// + /// The id of the entity. + /// The type of the entity. + /// The entity. + /// If the entity is not of the specified type. + public TEntity? GetEntity(long id) + { + var entity = GetEntity(id); + if (entity is null) + { + return default; + } + + if (entity is TEntity tentity) + { + return tentity; + } + + throw new Exception($"Could not find the entity with the given type {typeof(TEntity)}, was {entity.GetType()}"); + } + + /// + /// Add the given entity to the entities list. + /// + /// The entity to add. + internal void AddEntity(IEntity entity) + { + _entities.AddOrUpdate(entity.Id, _ => entity, (i, e) => entity); + } + + /// + /// . + /// + /// The id of the entity. + /// The action to execute on create. + /// The action to execute on update. + /// The type of the entity. + internal void AddOrUpdateEntity + (long entityId, Func createAction, Func updateAction) + where TEntity : IEntity + { + _entities.AddOrUpdate + (entityId, (key) => createAction(key), (key, entity) => updateAction(key, (TEntity)entity)); + } + + /// + /// Remove the given entity. + /// + /// The entity to remove. + internal void RemoveEntity(IEntity entity) + { + RemoveEntity(entity.Id); + } + + /// + /// Remove the given entity. + /// + /// The id of the entity to remove. + internal void RemoveEntity(long entityId) + { + _entities.TryRemove(entityId, out _); + } +} \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Maps/Miniland.cs b/Core/NosSmooth.Game/Data/Maps/Miniland.cs index 73a4730..6acfb98 100644 --- a/Core/NosSmooth.Game/Data/Maps/Miniland.cs +++ b/Core/NosSmooth.Game/Data/Maps/Miniland.cs @@ -4,10 +4,27 @@ // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using NosSmooth.Data.Abstractions.Infos; + namespace NosSmooth.Game.Data.Maps; /// /// Represents Miniland map that can contain miniland objects. /// /// The objects in the miniland. -public record Miniland(IReadOnlyList? Objects) : Map; \ No newline at end of file +public record Miniland +( + long Id, + byte Type, + IMapInfo? Info, + MapEntities Entities, + IReadOnlyList Portals, + IReadOnlyList? Objects +) : Map +( + Id, + Type, + Info, + Entities, + Portals +); \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Maps/Portal.cs b/Core/NosSmooth.Game/Data/Maps/Portal.cs index b1f7a78..ca92509 100644 --- a/Core/NosSmooth.Game/Data/Maps/Portal.cs +++ b/Core/NosSmooth.Game/Data/Maps/Portal.cs @@ -5,12 +5,21 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using NosSmooth.Game.Data.Info; +using NosSmooth.Packets.Enums; namespace NosSmooth.Game.Data.Maps; /// /// Represents map portal leading to another map. /// +/// The portal id. /// The position of the portal. /// The id of the target map. -public record Portal(Position Position, long TargetMapId); \ No newline at end of file +public record Portal +( + long PortalId, + Position Position, + long TargetMapId, + PortalType? PortalType, + bool IsDisabled +); \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Social/Family.cs b/Core/NosSmooth.Game/Data/Social/Family.cs index 32d1a40..448cc0f 100644 --- a/Core/NosSmooth.Game/Data/Social/Family.cs +++ b/Core/NosSmooth.Game/Data/Social/Family.cs @@ -12,4 +12,11 @@ namespace NosSmooth.Game.Data.Social; /// The id of the family. /// The name of the family. /// The level of the entity. -public record Family(string? Id, string? Name, byte? Level); \ No newline at end of file +public record Family +( + string? Id, + short? Title, + string? Name, + byte? Level, + IReadOnlyList? Icons +); \ No newline at end of file -- 2.49.0