diff --git a/EOBot/Interpreter/BuiltInIdentifierConfigurator.cs b/EOBot/Interpreter/BuiltInIdentifierConfigurator.cs index 65be892a5..6cac73f90 100644 --- a/EOBot/Interpreter/BuiltInIdentifierConfigurator.cs +++ b/EOBot/Interpreter/BuiltInIdentifierConfigurator.cs @@ -258,7 +258,7 @@ private Task LoginToCharacterAsync(string charName) return Readonly(mapStateObj); } - private IVariable GetMapStateCharacter(ICharacter c) + private IVariable GetMapStateCharacter(Character c) { var charObj = new ObjectVariable(); charObj.SymbolTable[PredefinedIdentifiers.NAME] = Readonly(new StringVariable(c.Name)); @@ -269,7 +269,7 @@ private IVariable GetMapStateCharacter(ICharacter c) return charObj; } - private IVariable GetMapStateNPC(INPC npc) + private IVariable GetMapStateNPC(NPC npc) { var npcFile = DependencyMaster.TypeRegistry[_botIndex].Resolve().ENFFile; @@ -282,7 +282,7 @@ private IVariable GetMapStateNPC(INPC npc) return npcObj; } - private IVariable GetMapStateItem(IItem item) + private IVariable GetMapStateItem(MapItem item) { var itemFile = DependencyMaster.TypeRegistry[_botIndex].Resolve().EIFFile; diff --git a/EOBot/TrainerBot.cs b/EOBot/TrainerBot.cs index 1db72809a..1017852c3 100644 --- a/EOBot/TrainerBot.cs +++ b/EOBot/TrainerBot.cs @@ -90,8 +90,8 @@ protected override async Task DoWorkAsync(CancellationToken ct) var charInventoryRepo = c.Resolve(); var walkValidator = c.Resolve(); - var healItems = new List(); - var healSpells = new List(); + var healItems = new List(); + var healSpells = new List(); int attackCount = 0, cachedPlayerCount = 0; bool time_to_die = false; @@ -297,7 +297,7 @@ private async Task PickUpItems(IMapCellState cellState) } } - private async Task PickUpItem(IItem item) + private async Task PickUpItem(MapItem item) { await TrySend(() => { @@ -311,14 +311,14 @@ await TrySend(() => await Task.Delay(TimeSpan.FromMilliseconds(ATTACK_BACKOFF_MS)); } - private async Task JunkItem(IItem item) + private async Task JunkItem(MapItem item) { ConsoleHelper.WriteMessage(ConsoleHelper.Type.JunkItem, $"{item.Amount,7} - {_itemData.Single(x => x.ID == item.ItemID).Name}"); await TrySend(() => _itemActions.JunkItem(item.ItemID, item.Amount)); await Task.Delay(TimeSpan.FromMilliseconds(ATTACK_BACKOFF_MS)); } - private async Task CastHealSpell(IEnumerable healSpells) + private async Task CastHealSpell(IEnumerable healSpells) { var spellToUse = _spellData .Where(x => healSpells.Any(y => y.ID == x.ID) && x.Target != SpellTarget.Group) @@ -335,7 +335,7 @@ private async Task CastHealSpell(IEnumerable healSpells) await Task.Delay((int)Math.Round(spellToUse.CastTime / 2.0 * 950)); // ? } - private async Task UseHealItem(IEnumerable healItems) + private async Task UseHealItem(IEnumerable healItems) { var itemToUse = _itemData .Where(x => healItems.Any(y => y.ItemID == x.ID)) diff --git a/EOLib/Domain/Character/Character.cs b/EOLib/Domain/Character/Character.cs index 7319442f5..d3fb87a8c 100644 --- a/EOLib/Domain/Character/Character.cs +++ b/EOLib/Domain/Character/Character.cs @@ -1,177 +1,43 @@ -using System.Collections.Generic; +using Amadevus.RecordGenerator; +using EOLib.Domain.Spells; namespace EOLib.Domain.Character { - public class Character : ICharacter + [Record] + public sealed partial class Character : ISpellTargetable { - public int ID { get; private set; } - - public int Index => ID; - - public string Name { get; private set; } - - public string Title { get; private set; } - - public string GuildName { get; private set; } - - public string GuildRank { get; private set; } - - public string GuildTag { get; private set; } - - public byte ClassID { get; private set; } - - public AdminLevel AdminLevel { get; private set; } - - public ICharacterRenderProperties RenderProperties { get; private set; } - - public ICharacterStats Stats { get; private set; } - - public int MapID { get; private set; } - - public bool NoWall { get; private set; } - - public Character() + private static readonly Character _default = new Builder { - RenderProperties = new CharacterRenderProperties(); - Stats = new CharacterStats(); - } + Stats = new CharacterStats(), + RenderProperties = new CharacterRenderProperties.Builder().ToImmutable() + }.ToImmutable(); - public ICharacter WithID(int id) - { - var character = MakeCopy(this); - character.ID = id; - return character; - } + public static Character Default => _default; - public ICharacter WithName(string name) - { - var character = MakeCopy(this); - character.Name = name; - return character; - } + public int ID { get; } - public ICharacter WithTitle(string title) - { - var character = MakeCopy(this); - character.Title = title; - return character; - } + public int Index => ID; - public ICharacter WithGuildName(string guildName) - { - var character = MakeCopy(this); - character.GuildName = guildName; - return character; - } + public string Name { get; } - public ICharacter WithGuildRank(string guildRank) - { - var character = MakeCopy(this); - character.GuildRank = guildRank; - return character; - } + public string Title { get; } - public ICharacter WithGuildTag(string guildTag) - { - var character = MakeCopy(this); - character.GuildTag = guildTag; - return character; - } + public string GuildName { get; } - public ICharacter WithClassID(byte newClassID) - { - var character = MakeCopy(this); - character.ClassID = newClassID; - return character; - } + public string GuildRank { get; } - public ICharacter WithAdminLevel(AdminLevel level) - { - var character = MakeCopy(this); - character.AdminLevel = level; - return character; - } + public string GuildTag { get; } - public ICharacter WithRenderProperties(ICharacterRenderProperties renderProperties) - { - var character = MakeCopy(this); - character.RenderProperties = renderProperties; - return character; - } + public byte ClassID { get; } - public ICharacter WithStats(ICharacterStats stats) - { - var character = MakeCopy(this); - character.Stats = stats; - return character; - } + public AdminLevel AdminLevel { get; } - public ICharacter WithMapID(int mapID) - { - var character = MakeCopy(this); - character.MapID = mapID; - return character; - } + public CharacterRenderProperties RenderProperties { get; } - public ICharacter WithNoWall(bool noWall) - { - var character = MakeCopy(this); - character.NoWall = noWall; - return character; - } + public CharacterStats Stats { get; } - private static Character MakeCopy(ICharacter source) - { - return new Character - { - ID = source.ID, - Name = source.Name, - Title = source.Title, - GuildName = source.GuildName, - GuildRank = source.GuildRank, - GuildTag = source.GuildTag, - ClassID = source.ClassID, - AdminLevel = source.AdminLevel, - RenderProperties = source.RenderProperties, - Stats = source.Stats, - MapID = source.MapID, - NoWall = source.NoWall - }; - } + public int MapID { get; } - public override bool Equals(object obj) - { - return obj is Character character && - ID == character.ID && - Name == character.Name && - Title == character.Title && - GuildName == character.GuildName && - GuildRank == character.GuildRank && - GuildTag == character.GuildTag && - ClassID == character.ClassID && - AdminLevel == character.AdminLevel && - RenderProperties.Equals(character.RenderProperties) && - Stats.Equals(character.Stats) && - MapID == character.MapID && - NoWall == character.NoWall; - } - - public override int GetHashCode() - { - int hashCode = 170256730; - hashCode = hashCode * -1521134295 + ID.GetHashCode(); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Name); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Title); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(GuildName); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(GuildRank); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(GuildTag); - hashCode = hashCode * -1521134295 + ClassID.GetHashCode(); - hashCode = hashCode * -1521134295 + AdminLevel.GetHashCode(); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(RenderProperties); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Stats); - hashCode = hashCode * -1521134295 + MapID.GetHashCode(); - hashCode = hashCode * -1521134295 + NoWall.GetHashCode(); - return hashCode; - } + public bool NoWall { get; } } } \ No newline at end of file diff --git a/EOLib/Domain/Character/CharacterActions.cs b/EOLib/Domain/Character/CharacterActions.cs index 4d29622f0..5f292bf27 100644 --- a/EOLib/Domain/Character/CharacterActions.cs +++ b/EOLib/Domain/Character/CharacterActions.cs @@ -133,9 +133,9 @@ public void CastSpell(int spellId, ISpellTargetable target) } else { - var spellTargetType = target is INPC + var spellTargetType = target is NPC.NPC ? SpellTargetType.NPC - : target is ICharacter + : target is Character ? SpellTargetType.Player : throw new InvalidOperationException("Invalid spell target specified, must be player or character"); builder = builder.AddChar((byte)spellTargetType); diff --git a/EOLib/Domain/Character/CharacterCreateData.cs b/EOLib/Domain/Character/CharacterCreateData.cs index f96c5ab48..55138251c 100644 --- a/EOLib/Domain/Character/CharacterCreateData.cs +++ b/EOLib/Domain/Character/CharacterCreateData.cs @@ -7,10 +7,10 @@ public class CharacterCreateData : ICharacterCreateData { public CharacterReply Response { get; } - private readonly List _characters; - public IReadOnlyList Characters => _characters; + private readonly List _characters; + public IReadOnlyList Characters => _characters; - public CharacterCreateData(CharacterReply response, List characters) + public CharacterCreateData(CharacterReply response, List characters) { Response = response; _characters = characters; @@ -21,6 +21,6 @@ public interface ICharacterCreateData : ITranslatedData { CharacterReply Response { get; } - IReadOnlyList Characters { get; } + IReadOnlyList Characters { get; } } } \ No newline at end of file diff --git a/EOLib/Domain/Character/CharacterInventoryRepository.cs b/EOLib/Domain/Character/CharacterInventoryRepository.cs index 8fd40cade..8b5db1b55 100644 --- a/EOLib/Domain/Character/CharacterInventoryRepository.cs +++ b/EOLib/Domain/Character/CharacterInventoryRepository.cs @@ -5,31 +5,31 @@ namespace EOLib.Domain.Character { public interface ICharacterInventoryRepository { - HashSet ItemInventory { get; set; } + HashSet ItemInventory { get; set; } - HashSet SpellInventory { get; set; } + HashSet SpellInventory { get; set; } } public interface ICharacterInventoryProvider { - IReadOnlyCollection ItemInventory { get; } + IReadOnlyCollection ItemInventory { get; } - IReadOnlyCollection SpellInventory { get; } + IReadOnlyCollection SpellInventory { get; } } [AutoMappedType(IsSingleton = true)] public class CharacterInventoryRepository : ICharacterInventoryRepository, ICharacterInventoryProvider { - public HashSet ItemInventory { get; set; } - public HashSet SpellInventory { get; set; } + public HashSet ItemInventory { get; set; } + public HashSet SpellInventory { get; set; } - IReadOnlyCollection ICharacterInventoryProvider.ItemInventory => ItemInventory; - IReadOnlyCollection ICharacterInventoryProvider.SpellInventory => SpellInventory; + IReadOnlyCollection ICharacterInventoryProvider.ItemInventory => ItemInventory; + IReadOnlyCollection ICharacterInventoryProvider.SpellInventory => SpellInventory; public CharacterInventoryRepository() { - ItemInventory = new HashSet(); - SpellInventory = new HashSet(); + ItemInventory = new HashSet(); + SpellInventory = new HashSet(); } } } diff --git a/EOLib/Domain/Character/CharacterRenderProperties.cs b/EOLib/Domain/Character/CharacterRenderProperties.cs index e78481884..3980ab486 100644 --- a/EOLib/Domain/Character/CharacterRenderProperties.cs +++ b/EOLib/Domain/Character/CharacterRenderProperties.cs @@ -1,353 +1,46 @@ -using EOLib.Net.API; +using Amadevus.RecordGenerator; namespace EOLib.Domain.Character { - public class CharacterRenderProperties : ICharacterRenderProperties + [Record] + public sealed partial class CharacterRenderProperties { - public const int MAX_NUMBER_OF_WALK_FRAMES = 5; - public const int MAX_NUMBER_OF_ATTACK_FRAMES = 3; + public const int MAX_NUMBER_OF_WALK_FRAMES = 5; + public const int MAX_NUMBER_OF_ATTACK_FRAMES = 3; public const int MAX_NUMBER_OF_RANGED_ATTACK_FRAMES = 2; - private const int MAX_NUMBER_OF_EMOTE_FRAMES = 3; + public const int MAX_NUMBER_OF_EMOTE_FRAMES = 3; - public CharacterActionState CurrentAction { get; private set; } + public CharacterActionState CurrentAction { get; } - public byte HairStyle { get; private set; } - public byte HairColor { get; private set; } - public byte Race { get; private set; } - public byte Gender { get; private set; } + public byte HairStyle { get; } + public byte HairColor { get; } + public byte Race { get; } + public byte Gender { get; } - public short BootsGraphic { get; private set; } - public short ArmorGraphic { get; private set; } - public short HatGraphic { get; private set; } - public short ShieldGraphic { get; private set; } - public short WeaponGraphic { get; private set; } + public short BootsGraphic { get; } + public short ArmorGraphic { get; } + public short HatGraphic { get; } + public short ShieldGraphic { get; } + public short WeaponGraphic { get; } - public EODirection Direction { get; private set; } - public int MapX { get; private set; } - public int MapY { get; private set; } + public EODirection Direction { get; } + public int MapX { get; } + public int MapY { get; } - public int ActualWalkFrame { get; private set; } - public int RenderWalkFrame { get; private set; } - public int ActualAttackFrame { get; private set; } - public int RenderAttackFrame { get; private set; } - public int EmoteFrame { get; private set; } - public int ActualSpellCastFrame { get; private set; } + public int ActualWalkFrame { get; } + public int RenderWalkFrame { get; } + public int ActualAttackFrame { get; } + public int RenderAttackFrame { get; } + public int EmoteFrame { get; } + public int ActualSpellCastFrame { get; } - public SitState SitState { get; private set; } - public Emote Emote { get; private set; } + public SitState SitState { get; } + public Emote Emote { get; } - public bool IsHidden { get; private set; } - public bool IsDead { get; private set; } - public bool IsDrunk { get; private set; } + public bool IsHidden { get; } + public bool IsDead { get; } + public bool IsDrunk { get; } - public bool IsRangedWeapon { get; private set; } - - public ICharacterRenderProperties WithHairStyle(byte newHairStyle) - { - var props = MakeCopy(this); - props.HairStyle = newHairStyle; - return props; - } - - public ICharacterRenderProperties WithHairColor(byte newHairColor) - { - var props = MakeCopy(this); - props.HairColor = newHairColor; - return props; - } - - public ICharacterRenderProperties WithRace(byte newRace) - { - var props = MakeCopy(this); - props.Race = newRace; - return props; - } - - public ICharacterRenderProperties WithGender(byte newGender) - { - var props = MakeCopy(this); - props.Gender = newGender; - return props; - } - - public ICharacterRenderProperties WithBootsGraphic(short bootsGraphic) - { - var props = MakeCopy(this); - props.BootsGraphic = bootsGraphic; - return props; - } - - public ICharacterRenderProperties WithArmorGraphic(short armorGraphic) - { - var props = MakeCopy(this); - props.ArmorGraphic = armorGraphic; - return props; - } - - public ICharacterRenderProperties WithHatGraphic(short hatGraphic) - { - var props = MakeCopy(this); - props.HatGraphic = hatGraphic; - return props; - } - - public ICharacterRenderProperties WithShieldGraphic(short shieldGraphic) - { - var props = MakeCopy(this); - props.ShieldGraphic = shieldGraphic; - return props; - } - - public ICharacterRenderProperties WithWeaponGraphic(short weaponGraphic, bool isRangedWeapon) - { - var props = MakeCopy(this); - props.WeaponGraphic = weaponGraphic; - props.IsRangedWeapon = isRangedWeapon; - return props; - } - - public ICharacterRenderProperties WithDirection(EODirection newDirection) - { - var props = MakeCopy(this); - props.Direction = newDirection; - return props; - } - - public ICharacterRenderProperties WithMapX(int mapX) - { - var props = MakeCopy(this); - props.MapX = mapX; - return props; - } - - public ICharacterRenderProperties WithMapY(int mapY) - { - var props = MakeCopy(this); - props.MapY = mapY; - return props; - } - - public ICharacterRenderProperties WithNextWalkFrame(bool isSteppingStone = false) - { - var props = MakeCopy(this); - props.ActualWalkFrame = (props.ActualWalkFrame + 1) % MAX_NUMBER_OF_WALK_FRAMES; - - if (isSteppingStone && props.ActualWalkFrame > 1) - { - // force first walk frame when on a stepping stone (this is the graphic used for jump, Y adjusted) - props.RenderWalkFrame = 1; - } - else - { - props.RenderWalkFrame = props.ActualWalkFrame; - } - - props.CurrentAction = props.RenderWalkFrame == 0 ? CharacterActionState.Standing : CharacterActionState.Walking; - - return props; - } - - public ICharacterRenderProperties WithNextAttackFrame() - { - var props = MakeCopy(this); - props.ActualAttackFrame = (props.ActualAttackFrame + 1) % MAX_NUMBER_OF_WALK_FRAMES; - props.RenderAttackFrame = props.ActualAttackFrame; - - if (IsRangedWeapon) - { - // ranged attack ticks: 0 0 1 1 1 - props.RenderAttackFrame /= MAX_NUMBER_OF_RANGED_ATTACK_FRAMES; - props.RenderAttackFrame = System.Math.Min(props.RenderAttackFrame, MAX_NUMBER_OF_RANGED_ATTACK_FRAMES - 1); - } - else - { - // melee attack ticks: 0 1 2 2 2 - props.RenderAttackFrame = System.Math.Min(props.RenderAttackFrame, MAX_NUMBER_OF_ATTACK_FRAMES - 1); - } - - props.CurrentAction = props.ActualAttackFrame == 0 ? CharacterActionState.Standing : CharacterActionState.Attacking; - - return props; - } - - public ICharacterRenderProperties WithNextEmoteFrame() - { - var props = MakeCopy(this); - props.EmoteFrame = (props.EmoteFrame + 1) % MAX_NUMBER_OF_EMOTE_FRAMES; - props.CurrentAction = props.EmoteFrame == 0 - ? CharacterActionState.Standing - : props.CurrentAction == CharacterActionState.Attacking // when using an instrument keep the current state as "Attacking" - ? CharacterActionState.Attacking - : CharacterActionState.Emote; - return props; - } - - public ICharacterRenderProperties WithNextSpellCastFrame() - { - // spell cast frame ticks: 0 0 1 1 1 - var props = MakeCopy(this); - props.ActualSpellCastFrame = (props.ActualSpellCastFrame + 1) % MAX_NUMBER_OF_ATTACK_FRAMES; - props.CurrentAction = props.ActualSpellCastFrame == 0 ? CharacterActionState.Standing : CharacterActionState.SpellCast; - return props; - } - - public ICharacterRenderProperties ResetAnimationFrames() - { - var props = MakeCopy(this); - props.RenderWalkFrame = 0; - props.ActualWalkFrame = 0; - props.RenderAttackFrame = 0; - props.EmoteFrame = 0; - props.CurrentAction = props.SitState == SitState.Standing ? CharacterActionState.Standing : CharacterActionState.Sitting; - return props; - } - - public ICharacterRenderProperties WithSitState(SitState newState) - { - var props = MakeCopy(this); - props.SitState = newState; - props.CurrentAction = newState == SitState.Standing ? CharacterActionState.Standing : CharacterActionState.Sitting; - return props; - } - - public ICharacterRenderProperties WithEmote(Emote emote) - { - var props = MakeCopy(this); - props.Emote = emote; - return props; - } - - public ICharacterRenderProperties WithIsHidden(bool hidden) - { - var props = MakeCopy(this); - props.IsHidden = hidden; - return props; - } - - public ICharacterRenderProperties WithDead() - { - var props = MakeCopy(this); - props.IsDead = true; - return props; - } - - public ICharacterRenderProperties WithAlive() - { - var props = MakeCopy(this); - props.IsDead = false; - return props; - } - - public ICharacterRenderProperties WithIsDrunk(bool drunk) - { - var props = MakeCopy(this); - props.IsDrunk = drunk; - return props; - } - - public object Clone() - { - return MakeCopy(this); - } - - private static CharacterRenderProperties MakeCopy(ICharacterRenderProperties other) - { - return new CharacterRenderProperties - { - CurrentAction = other.CurrentAction, - - HairStyle = other.HairStyle, - HairColor = other.HairColor, - Race = other.Race, - Gender = other.Gender, - - BootsGraphic = other.BootsGraphic, - ArmorGraphic = other.ArmorGraphic, - HatGraphic = other.HatGraphic, - ShieldGraphic = other.ShieldGraphic, - WeaponGraphic = other.WeaponGraphic, - - Direction = other.Direction, - MapX = other.MapX, - MapY = other.MapY, - - ActualWalkFrame = other.ActualWalkFrame, - RenderWalkFrame = other.RenderWalkFrame, - ActualAttackFrame = other.ActualAttackFrame, - RenderAttackFrame = other.RenderAttackFrame, - EmoteFrame = other.EmoteFrame, - ActualSpellCastFrame = other.ActualSpellCastFrame, - - SitState = other.SitState, - Emote = other.Emote, - - IsHidden = other.IsHidden, - IsDead = other.IsDead, - IsDrunk = other.IsDrunk, - - IsRangedWeapon = other.IsRangedWeapon - }; - } - - public override bool Equals(object obj) - { - return obj is CharacterRenderProperties properties && - CurrentAction == properties.CurrentAction && - HairStyle == properties.HairStyle && - HairColor == properties.HairColor && - Race == properties.Race && - Gender == properties.Gender && - BootsGraphic == properties.BootsGraphic && - ArmorGraphic == properties.ArmorGraphic && - HatGraphic == properties.HatGraphic && - ShieldGraphic == properties.ShieldGraphic && - WeaponGraphic == properties.WeaponGraphic && - Direction == properties.Direction && - MapX == properties.MapX && - MapY == properties.MapY && - ActualWalkFrame == properties.ActualWalkFrame && - ActualAttackFrame == properties.ActualAttackFrame && - RenderWalkFrame == properties.RenderWalkFrame && - RenderAttackFrame == properties.RenderAttackFrame && - EmoteFrame == properties.EmoteFrame && - ActualSpellCastFrame == properties.ActualSpellCastFrame && - SitState == properties.SitState && - Emote == properties.Emote && - IsHidden == properties.IsHidden && - IsDead == properties.IsDead && - IsDrunk == properties.IsDrunk && - IsRangedWeapon == properties.IsRangedWeapon; - } - - public override int GetHashCode() - { - int hashCode = 1754760722; - hashCode = hashCode * -1521134295 + CurrentAction.GetHashCode(); - hashCode = hashCode * -1521134295 + HairStyle.GetHashCode(); - hashCode = hashCode * -1521134295 + HairColor.GetHashCode(); - hashCode = hashCode * -1521134295 + Race.GetHashCode(); - hashCode = hashCode * -1521134295 + Gender.GetHashCode(); - hashCode = hashCode * -1521134295 + BootsGraphic.GetHashCode(); - hashCode = hashCode * -1521134295 + ArmorGraphic.GetHashCode(); - hashCode = hashCode * -1521134295 + HatGraphic.GetHashCode(); - hashCode = hashCode * -1521134295 + ShieldGraphic.GetHashCode(); - hashCode = hashCode * -1521134295 + WeaponGraphic.GetHashCode(); - hashCode = hashCode * -1521134295 + Direction.GetHashCode(); - hashCode = hashCode * -1521134295 + MapX.GetHashCode(); - hashCode = hashCode * -1521134295 + MapY.GetHashCode(); - hashCode = hashCode * -1521134295 + ActualWalkFrame.GetHashCode(); - hashCode = hashCode * -1521134295 + RenderWalkFrame.GetHashCode(); - hashCode = hashCode * -1521134295 + ActualAttackFrame.GetHashCode(); - hashCode = hashCode * -1521134295 + RenderAttackFrame.GetHashCode(); - hashCode = hashCode * -1521134295 + EmoteFrame.GetHashCode(); - hashCode = hashCode * -1521134295 + ActualSpellCastFrame.GetHashCode(); - hashCode = hashCode * -1521134295 + SitState.GetHashCode(); - hashCode = hashCode * -1521134295 + Emote.GetHashCode(); - hashCode = hashCode * -1521134295 + IsHidden.GetHashCode(); - hashCode = hashCode * -1521134295 + IsDead.GetHashCode(); - hashCode = hashCode * -1521134295 + IsDrunk.GetHashCode(); - hashCode = hashCode * -1521134295 + IsRangedWeapon.GetHashCode(); - return hashCode; - } + public bool IsRangedWeapon { get; } } } diff --git a/EOLib/Domain/Character/CharacterRepository.cs b/EOLib/Domain/Character/CharacterRepository.cs index b1c73b351..a6bf0ab5d 100644 --- a/EOLib/Domain/Character/CharacterRepository.cs +++ b/EOLib/Domain/Character/CharacterRepository.cs @@ -4,17 +4,17 @@ namespace EOLib.Domain.Character { public interface ICharacterRepository { - ICharacter MainCharacter { get; set; } + Character MainCharacter { get; set; } } public interface ICharacterProvider { - ICharacter MainCharacter { get; } + Character MainCharacter { get; } } [AutoMappedType(IsSingleton = true)] public class CharacterRepository : ICharacterRepository, ICharacterProvider { - public ICharacter MainCharacter { get; set; } + public Character MainCharacter { get; set; } } } diff --git a/EOLib/Domain/Character/CharacterStats.cs b/EOLib/Domain/Character/CharacterStats.cs index bcb43b0d9..674485d95 100644 --- a/EOLib/Domain/Character/CharacterStats.cs +++ b/EOLib/Domain/Character/CharacterStats.cs @@ -1,61 +1,25 @@ -using System; +using Amadevus.RecordGenerator; +using System; using System.Collections.Generic; using System.Linq; namespace EOLib.Domain.Character { - public class CharacterStats : ICharacterStats + [Record(Features.Constructor | Features.ToString | Features.ObjectEquals)] + public sealed partial class CharacterStats { public IReadOnlyDictionary Stats { get; } public int this[CharacterStat stat] => Stats[stat]; - public CharacterStats() - { - Stats = CreateStatCollection(); - } - - private CharacterStats(IReadOnlyDictionary stats) - { - Stats = stats; - } + public CharacterStats() => + Stats = ((IEnumerable)Enum.GetValues(typeof(CharacterStat))).ToDictionary(k => k, v => 0); - public ICharacterStats WithNewStat(CharacterStat whichStat, int statValue) + public CharacterStats WithNewStat(CharacterStat whichStat, int statValue) { var newStats = Stats.ToDictionary(x => x.Key, x => x.Value); newStats[whichStat] = statValue; return new CharacterStats(newStats); } - - private static IReadOnlyDictionary CreateStatCollection() - { - var stats = new Dictionary(25); - - var allStatTypes = Enum.GetValues(typeof(CharacterStat)); - foreach (CharacterStat stat in allStatTypes) - stats.Add(stat, 0); - - return stats; - } - - public override bool Equals(object obj) - { - return obj is CharacterStats stats && - EqualityComparer>.Default.Equals(Stats, stats.Stats); - } - - public override int GetHashCode() - { - return -1464643476 + EqualityComparer>.Default.GetHashCode(Stats); - } - } - - public interface ICharacterStats - { - IReadOnlyDictionary Stats { get; } - - int this[CharacterStat stat] { get; } - - ICharacterStats WithNewStat(CharacterStat whichStat, int statValue); } } diff --git a/EOLib/Domain/Character/Emote.cs b/EOLib/Domain/Character/Emote.cs index 2dfe99597..7cacde529 100644 --- a/EOLib/Domain/Character/Emote.cs +++ b/EOLib/Domain/Character/Emote.cs @@ -2,6 +2,7 @@ { public enum Emote { + None = 0, Happy = 1, Depressed = 2, Sad = 3, diff --git a/EOLib/Domain/Character/ICharacter.cs b/EOLib/Domain/Character/ICharacter.cs deleted file mode 100644 index c09ea8569..000000000 --- a/EOLib/Domain/Character/ICharacter.cs +++ /dev/null @@ -1,54 +0,0 @@ -using EOLib.Domain.Spells; - -namespace EOLib.Domain.Character -{ - public interface ICharacter : ISpellTargetable - { - string Name { get; } - - string Title { get; } - - //todo: guild stuff should be in a guild object - string GuildName { get; } - - string GuildRank { get; } - - string GuildTag { get; } - - byte ClassID { get; } - - ICharacterRenderProperties RenderProperties { get; } - - ICharacterStats Stats { get; } - - AdminLevel AdminLevel { get; } - - int MapID { get; } - - bool NoWall { get; } - - ICharacter WithID(int id); - - ICharacter WithName(string name); - - ICharacter WithTitle(string title); - - ICharacter WithGuildName(string guildName); - - ICharacter WithGuildRank(string guildRank); - - ICharacter WithGuildTag(string guildTag); - - ICharacter WithClassID(byte newClassID); - - ICharacter WithRenderProperties(ICharacterRenderProperties renderProperties); - - ICharacter WithStats(ICharacterStats stats); - - ICharacter WithAdminLevel(AdminLevel level); - - ICharacter WithMapID(int mapID); - - ICharacter WithNoWall(bool noWall); - } -} diff --git a/EOLib/Domain/Character/ICharacterRenderProperties.cs b/EOLib/Domain/Character/ICharacterRenderProperties.cs deleted file mode 100644 index b4235307c..000000000 --- a/EOLib/Domain/Character/ICharacterRenderProperties.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using EOLib.Net.API; - -namespace EOLib.Domain.Character -{ - public interface ICharacterRenderProperties : ICloneable - { - CharacterActionState CurrentAction { get; } - - byte HairStyle { get; } - byte HairColor { get; } - byte Race { get; } - byte Gender { get; } - - short BootsGraphic { get; } - short ArmorGraphic { get; } - short HatGraphic { get; } - short ShieldGraphic { get; } - short WeaponGraphic { get; } - - EODirection Direction { get; } - int MapX { get; } - int MapY { get; } - - int ActualWalkFrame { get; } - int RenderWalkFrame { get; } - int ActualAttackFrame { get; } - int RenderAttackFrame { get; } - int EmoteFrame { get; } - int ActualSpellCastFrame { get; } - - SitState SitState { get; } - Emote Emote { get; } - - bool IsHidden { get; } - bool IsDead { get; } - bool IsDrunk { get; } - - bool IsRangedWeapon { get; } - - ICharacterRenderProperties WithHairStyle(byte newHairStyle); - ICharacterRenderProperties WithHairColor(byte newHairColor); - ICharacterRenderProperties WithRace(byte newRace); - ICharacterRenderProperties WithGender(byte newGender); - - ICharacterRenderProperties WithBootsGraphic(short bootsGraphic); - ICharacterRenderProperties WithArmorGraphic(short armorGraphic); - ICharacterRenderProperties WithHatGraphic(short hatGraphic); - ICharacterRenderProperties WithShieldGraphic(short shieldGraphic); - ICharacterRenderProperties WithWeaponGraphic(short weaponGraphic, bool isRanged); - - ICharacterRenderProperties WithDirection(EODirection newDirection); - ICharacterRenderProperties WithMapX(int mapX); - ICharacterRenderProperties WithMapY(int mapY); - - ICharacterRenderProperties WithNextWalkFrame(bool isSteppingStone = false); - ICharacterRenderProperties WithNextAttackFrame(); - ICharacterRenderProperties WithNextEmoteFrame(); - ICharacterRenderProperties WithNextSpellCastFrame(); - ICharacterRenderProperties ResetAnimationFrames(); - - ICharacterRenderProperties WithSitState(SitState newState); - ICharacterRenderProperties WithEmote(Emote emote); - - ICharacterRenderProperties WithIsHidden(bool hidden); - ICharacterRenderProperties WithDead(); - ICharacterRenderProperties WithAlive(); - - ICharacterRenderProperties WithIsDrunk(bool drunk); - } -} diff --git a/EOLib/Domain/Character/InventoryItem.cs b/EOLib/Domain/Character/InventoryItem.cs index 4cbcdcbd1..5b3a7602b 100644 --- a/EOLib/Domain/Character/InventoryItem.cs +++ b/EOLib/Domain/Character/InventoryItem.cs @@ -1,44 +1,12 @@ +using Amadevus.RecordGenerator; + namespace EOLib.Domain.Character { - public class InventoryItem : IInventoryItem + [Record] + public sealed partial class InventoryItem { public short ItemID { get; } public int Amount { get; } - - public InventoryItem(short itemID, int amount) - { - ItemID = itemID; - Amount = amount; - } - - public IInventoryItem WithAmount(int newAmount) - { - return new InventoryItem(ItemID, newAmount); - } - - public override bool Equals(object obj) - { - var other = obj as InventoryItem; - if (other == null) return false; - return other.ItemID == ItemID && other.Amount == Amount; - } - - public override int GetHashCode() - { - int hashCode = 1754760722; - hashCode = hashCode * -1521134295 + ItemID.GetHashCode(); - hashCode = hashCode * -1521134295 + Amount.GetHashCode(); - return hashCode; - } - } - - public interface IInventoryItem - { - short ItemID { get; } - - int Amount { get; } - - IInventoryItem WithAmount(int newAmount); } } \ No newline at end of file diff --git a/EOLib/Domain/Character/InventorySpell.cs b/EOLib/Domain/Character/InventorySpell.cs index cbc3af8d3..21c9caf7c 100644 --- a/EOLib/Domain/Character/InventorySpell.cs +++ b/EOLib/Domain/Character/InventorySpell.cs @@ -1,44 +1,12 @@ -namespace EOLib.Domain.Character +using Amadevus.RecordGenerator; + +namespace EOLib.Domain.Character { - public class InventorySpell : IInventorySpell + [Record] + public sealed partial class InventorySpell { public short ID { get; } public short Level { get; } - - public InventorySpell(short id, short level) - { - ID = id; - Level = level; - } - - public IInventorySpell WithLevel(short newLevel) - { - return new InventorySpell(ID, newLevel); - } - - public override bool Equals(object obj) - { - var other = obj as InventorySpell; - if (other == null) return false; - return other.ID == ID && other.Level == Level; - } - - public override int GetHashCode() - { - int hashCode = 1754760722; - hashCode = hashCode * -1521134295 + ID.GetHashCode(); - hashCode = hashCode * -1521134295 + Level.GetHashCode(); - return hashCode; - } - } - - public interface IInventorySpell - { - short ID { get; } - - short Level { get; } - - IInventorySpell WithLevel(short newLevel); } } \ No newline at end of file diff --git a/EOLib/Domain/Character/PaperdollData.cs b/EOLib/Domain/Character/PaperdollData.cs index 6566a0f9e..617b579f4 100644 --- a/EOLib/Domain/Character/PaperdollData.cs +++ b/EOLib/Domain/Character/PaperdollData.cs @@ -1,186 +1,38 @@ -using EOLib.Domain.Online; +using Amadevus.RecordGenerator; +using EOLib.Domain.Online; using EOLib.IO; using System.Collections.Generic; -using System.Linq; namespace EOLib.Domain.Character { - public class PaperdollData : IPaperdollData + [Record] + public sealed partial class PaperdollData { - public string Name { get; private set; } + public string Name { get; } - public string Home { get; private set; } + public string Home { get; } - public string Partner { get; private set; } + public string Partner { get; } - public string Title { get; private set; } + public string Title { get; } - public string Guild { get; private set; } + public string Guild { get; } - public string Rank { get; private set; } + public string Rank { get; } - public short PlayerID { get; private set; } + public short PlayerID { get; } - public byte Class { get; private set; } + public byte Class { get; } - public byte Gender { get; private set; } + public byte Gender { get; } - public IReadOnlyDictionary Paperdoll { get; private set; } + public IReadOnlyDictionary Paperdoll { get; } - public OnlineIcon Icon { get; private set; } + public OnlineIcon Icon { get; } public PaperdollData() { Paperdoll = new Dictionary(); } - - private PaperdollData(string name, - string home, - string partner, - string title, - string guild, - string rank, - short playerID, - byte @class, - byte gender, - IReadOnlyDictionary paperdoll, - OnlineIcon icon) - { - Name = name; - Home = home; - Partner = partner; - Title = title; - Guild = guild; - Rank = rank; - PlayerID = playerID; - Class = @class; - Gender = gender; - Paperdoll = paperdoll; - Icon = icon; - } - - public IPaperdollData WithName(string name) - { - return new PaperdollData(name, Home, Partner, Title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithHome(string home) - { - return new PaperdollData(Name, home, Partner, Title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithPartner(string partner) - { - return new PaperdollData(Name, Home, partner, Title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithTitle(string title) - { - return new PaperdollData(Name, Home, Partner, title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithGuild(string guild) - { - return new PaperdollData(Name, Home, Partner, Title, guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithRank(string rank) - { - return new PaperdollData(Name, Home, Partner, Title, Guild, rank, PlayerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithPlayerID(short playerID) - { - return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, playerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithClass(byte @class) - { - return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, PlayerID, @class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithGender(byte gender) - { - return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, PlayerID, Class, gender, Paperdoll, Icon); - } - - public IPaperdollData WithPaperdoll(IReadOnlyDictionary paperdoll) - { - return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, PlayerID, Class, Gender, paperdoll, Icon); - } - - public IPaperdollData WithIcon(OnlineIcon icon) - { - return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, icon); - } - - public override bool Equals(object obj) - { - var other = obj as PaperdollData; - if (other == null) - return false; - - return Name == other.Name && Home == other.Home && Partner == other.Partner && Title == other.Title && - Guild == other.Guild && Rank == other.Rank && PlayerID == other.PlayerID && - Class == other.Class && Gender == other.Gender && Icon == other.Icon && Paperdoll.SequenceEqual(other.Paperdoll); - } - - public override int GetHashCode() - { - int hashCode = 170256730; - hashCode = hashCode * -1521134295 + Name.GetHashCode(); - hashCode = hashCode * -1521134295 + Home.GetHashCode(); - hashCode = hashCode * -1521134295 + Partner.GetHashCode(); - hashCode = hashCode * -1521134295 + Title.GetHashCode(); - hashCode = hashCode * -1521134295 + Guild.GetHashCode(); - hashCode = hashCode * -1521134295 + Rank.GetHashCode(); - hashCode = hashCode * -1521134295 + PlayerID.GetHashCode(); - hashCode = hashCode * -1521134295 + Class.GetHashCode(); - hashCode = hashCode * -1521134295 + Gender.GetHashCode(); - hashCode = hashCode * -1521134295 + Paperdoll.Select(x => (int)x.Value) - .Aggregate(hashCode * -1521134295, (a, b) => a * -1521134295 + b.GetHashCode()); - hashCode = hashCode * -1521134295 + Icon.GetHashCode(); - return hashCode; - } - } - - public interface IPaperdollData - { - string Name { get; } - string Home { get; } - string Partner { get; } - string Title { get; } - string Guild { get; } - string Rank { get; } - - short PlayerID { get; } - byte Class { get; } - byte Gender { get; } - - IReadOnlyDictionary Paperdoll { get; } - - OnlineIcon Icon { get; } - - IPaperdollData WithName(string name); - - IPaperdollData WithHome(string home); - - IPaperdollData WithPartner(string partner); - - IPaperdollData WithTitle(string title); - - IPaperdollData WithGuild(string guild); - - IPaperdollData WithRank(string rank); - - IPaperdollData WithPlayerID(short playerID); - - IPaperdollData WithClass(byte @class); - - IPaperdollData WithGender(byte gender); - - IPaperdollData WithPaperdoll(IReadOnlyDictionary paperdoll); - - IPaperdollData WithIcon(OnlineIcon icon); } } diff --git a/EOLib/Domain/Character/PaperdollRepository.cs b/EOLib/Domain/Character/PaperdollRepository.cs index d3875f098..87eb64a98 100644 --- a/EOLib/Domain/Character/PaperdollRepository.cs +++ b/EOLib/Domain/Character/PaperdollRepository.cs @@ -5,19 +5,19 @@ namespace EOLib.Domain.Character { public interface IPaperdollRepository { - Dictionary VisibleCharacterPaperdolls { get; set; } + Dictionary VisibleCharacterPaperdolls { get; set; } } public interface IPaperdollProvider { - IReadOnlyDictionary VisibleCharacterPaperdolls { get; } + IReadOnlyDictionary VisibleCharacterPaperdolls { get; } } [AutoMappedType(IsSingleton = true)] public class PaperdollRepository : IPaperdollRepository, IPaperdollProvider { - public Dictionary VisibleCharacterPaperdolls { get; set; } = new Dictionary(); + public Dictionary VisibleCharacterPaperdolls { get; set; } = new Dictionary(); - IReadOnlyDictionary IPaperdollProvider.VisibleCharacterPaperdolls => VisibleCharacterPaperdolls; + IReadOnlyDictionary IPaperdollProvider.VisibleCharacterPaperdolls => VisibleCharacterPaperdolls; } } diff --git a/EOLib/Domain/Character/WalkValidationActions.cs b/EOLib/Domain/Character/WalkValidationActions.cs index 2377060f2..2f85cb8d1 100644 --- a/EOLib/Domain/Character/WalkValidationActions.cs +++ b/EOLib/Domain/Character/WalkValidationActions.cs @@ -65,7 +65,7 @@ public bool IsCellStateWalkable(IMapCellState cellState) none: () => mc.NoWall || IsTileSpecWalkable(cellState.TileSpec)))); } - private bool IsWarpWalkable(IWarp warp, TileSpec tile) + private bool IsWarpWalkable(Warp warp, TileSpec tile) { if (warp.DoorType != DoorSpec.NoDoor) return _currentMapStateProvider.OpenDoors.Any(w => w.X == warp.X && w.Y == warp.Y) && diff --git a/EOLib/Domain/Extensions/CharacterExtensions.cs b/EOLib/Domain/Extensions/CharacterExtensions.cs index 4aa586911..4dcc2e6ec 100644 --- a/EOLib/Domain/Extensions/CharacterExtensions.cs +++ b/EOLib/Domain/Extensions/CharacterExtensions.cs @@ -5,24 +5,18 @@ namespace EOLib.Domain.Extensions { public static class CharacterExtensions { - public static ICharacter WithAppliedData(this ICharacter original, ICharacter updatedData, bool isRangedWeapon) + public static Character.Character WithAppliedData(this Character.Character original, Character.Character updatedData, bool isRangedWeapon) { var existingRenderProps = original.RenderProperties; - var newRenderProps = existingRenderProps - .WithBootsGraphic(updatedData.RenderProperties.BootsGraphic) - .WithArmorGraphic(updatedData.RenderProperties.ArmorGraphic) - .WithHatGraphic(updatedData.RenderProperties.HatGraphic) - .WithShieldGraphic(updatedData.RenderProperties.ShieldGraphic) - .WithWeaponGraphic(updatedData.RenderProperties.WeaponGraphic, isRangedWeapon) - .WithDirection(updatedData.RenderProperties.Direction) - .WithHairStyle(updatedData.RenderProperties.HairStyle) - .WithHairColor(updatedData.RenderProperties.HairColor) - .WithGender(updatedData.RenderProperties.Gender) - .WithRace(updatedData.RenderProperties.Race) - .WithSitState(updatedData.RenderProperties.SitState) - .WithMapX(updatedData.RenderProperties.MapX) - .WithMapY(updatedData.RenderProperties.MapY) - .ResetAnimationFrames(); + var newRenderProps = updatedData.RenderProperties.ToBuilder(); + + newRenderProps.CurrentAction = updatedData.RenderProperties.SitState == SitState.Standing + ? CharacterActionState.Standing + : CharacterActionState.Sitting; + newRenderProps.IsDead = existingRenderProps.IsDead; + newRenderProps.IsRangedWeapon = isRangedWeapon; + newRenderProps.IsDrunk = existingRenderProps.IsDrunk; + newRenderProps.IsHidden = existingRenderProps.IsHidden; var existingStats = original.Stats; var newStats = existingStats @@ -36,18 +30,17 @@ public static ICharacter WithAppliedData(this ICharacter original, ICharacter up .WithName(updatedData.Name) .WithGuildTag(updatedData.GuildTag) .WithMapID(updatedData.MapID) - .WithRenderProperties(newRenderProps) + .WithRenderProperties(newRenderProps.ToImmutable()) .WithStats(newStats); } - public static ICharacter WithDamage(this ICharacter original, int damageTaken, bool isDead) + public static Character.Character WithDamage(this Character.Character original, int damageTaken, bool isDead) { var stats = original.Stats; stats = stats.WithNewStat(CharacterStat.HP, (short)Math.Max(stats[CharacterStat.HP] - damageTaken, 0)); - var props = original.RenderProperties; - if (isDead) - props = props.WithDead(); + var props = original.RenderProperties + .WithIsDead(isDead); return original.WithStats(stats).WithRenderProperties(props); } diff --git a/EOLib/Domain/Extensions/CharacterRenderPropertiesExtensions.cs b/EOLib/Domain/Extensions/CharacterRenderPropertiesExtensions.cs index 975125103..077b94f1f 100644 --- a/EOLib/Domain/Extensions/CharacterRenderPropertiesExtensions.cs +++ b/EOLib/Domain/Extensions/CharacterRenderPropertiesExtensions.cs @@ -5,23 +5,23 @@ namespace EOLib.Domain.Extensions { public static class CharacterRenderPropertiesExtensions { - public static bool IsFacing(this ICharacterRenderProperties renderProperties, params EODirection[] directions) + public static bool IsFacing(this CharacterRenderProperties renderProperties, params EODirection[] directions) { return directions.Contains(renderProperties.Direction); } - public static bool IsActing(this ICharacterRenderProperties renderProperties, params CharacterActionState[] actions) + public static bool IsActing(this CharacterRenderProperties renderProperties, params CharacterActionState[] actions) { return actions.Contains(renderProperties.CurrentAction); } - public static int GetDestinationX(this ICharacterRenderProperties renderProperties) + public static int GetDestinationX(this CharacterRenderProperties renderProperties) { var offset = GetXOffset(renderProperties.Direction); return renderProperties.MapX + offset; } - public static int GetDestinationY(this ICharacterRenderProperties renderProperties) + public static int GetDestinationY(this CharacterRenderProperties renderProperties) { var offset = GetYOffset(renderProperties.Direction); return renderProperties.MapY + offset; @@ -38,5 +38,80 @@ private static int GetYOffset(EODirection direction) return direction == EODirection.Down ? 1 : direction == EODirection.Up ? -1 : 0; } + + public static CharacterRenderProperties WithNextWalkFrame(this CharacterRenderProperties rp, bool isSteppingStone = false) + { + var props = rp.ToBuilder(); + props.ActualWalkFrame = (props.ActualWalkFrame + 1) % CharacterRenderProperties.MAX_NUMBER_OF_WALK_FRAMES; + + if (isSteppingStone && props.ActualWalkFrame > 1) + { + // force first walk frame when on a stepping stone (this is the graphic used for jump, Y adjusted) + props.RenderWalkFrame = 1; + } + else + { + props.RenderWalkFrame = props.ActualWalkFrame; + } + + props.CurrentAction = props.RenderWalkFrame == 0 ? CharacterActionState.Standing : CharacterActionState.Walking; + + return props.ToImmutable(); + } + + public static CharacterRenderProperties WithNextAttackFrame(this CharacterRenderProperties rp) + { + var props = rp.ToBuilder(); + props.ActualAttackFrame = (props.ActualAttackFrame + 1) % CharacterRenderProperties.MAX_NUMBER_OF_WALK_FRAMES; + props.RenderAttackFrame = props.ActualAttackFrame; + + if (props.IsRangedWeapon) + { + // ranged attack ticks: 0 0 1 1 1 + props.RenderAttackFrame /= CharacterRenderProperties.MAX_NUMBER_OF_RANGED_ATTACK_FRAMES; + props.RenderAttackFrame = System.Math.Min(props.RenderAttackFrame, CharacterRenderProperties.MAX_NUMBER_OF_RANGED_ATTACK_FRAMES - 1); + } + else + { + // melee attack ticks: 0 1 2 2 2 + props.RenderAttackFrame = System.Math.Min(props.RenderAttackFrame, CharacterRenderProperties.MAX_NUMBER_OF_ATTACK_FRAMES - 1); + } + + props.CurrentAction = props.ActualAttackFrame == 0 ? CharacterActionState.Standing : CharacterActionState.Attacking; + + return props.ToImmutable(); + } + + public static CharacterRenderProperties WithNextEmoteFrame(this CharacterRenderProperties rp) + { + var props = rp.ToBuilder(); + props.EmoteFrame = (props.EmoteFrame + 1) % CharacterRenderProperties.MAX_NUMBER_OF_EMOTE_FRAMES; + props.CurrentAction = props.EmoteFrame == 0 + ? CharacterActionState.Standing + : props.CurrentAction == CharacterActionState.Attacking // when using an instrument keep the current state as "Attacking" + ? CharacterActionState.Attacking + : CharacterActionState.Emote; + return props.ToImmutable(); + } + + public static CharacterRenderProperties WithNextSpellCastFrame(this CharacterRenderProperties rp) + { + // spell cast frame ticks: 0 0 1 1 1 + var props = rp.ToBuilder(); + props.ActualSpellCastFrame = (props.ActualSpellCastFrame + 1) % CharacterRenderProperties.MAX_NUMBER_OF_ATTACK_FRAMES; + props.CurrentAction = props.ActualSpellCastFrame == 0 ? CharacterActionState.Standing : CharacterActionState.SpellCast; + return props.ToImmutable(); + } + + public static CharacterRenderProperties ResetAnimationFrames(this CharacterRenderProperties rp) + { + var props = rp.ToBuilder(); + props.RenderWalkFrame = 0; + props.ActualWalkFrame = 0; + props.RenderAttackFrame = 0; + props.EmoteFrame = 0; + props.CurrentAction = props.SitState == SitState.Standing ? CharacterActionState.Standing : CharacterActionState.Sitting; + return props.ToImmutable(); + } } } diff --git a/EOLib/Domain/Extensions/CharacterStatExtensions.cs b/EOLib/Domain/Extensions/CharacterStatExtensions.cs index eccf52ebf..4cbbd9487 100644 --- a/EOLib/Domain/Extensions/CharacterStatExtensions.cs +++ b/EOLib/Domain/Extensions/CharacterStatExtensions.cs @@ -4,7 +4,7 @@ namespace EOLib.Domain.Extensions { public static class CharacterStatExtensions { - public static string GetKarmaString(this ICharacterStats characterStats) + public static string GetKarmaString(this CharacterStats characterStats) { /* 0 - 100 = Demonic * 101 - 500 = Doomed diff --git a/EOLib/Domain/Extensions/NPCExtensions.cs b/EOLib/Domain/Extensions/NPCExtensions.cs index 8ec6680c4..fd2710241 100644 --- a/EOLib/Domain/Extensions/NPCExtensions.cs +++ b/EOLib/Domain/Extensions/NPCExtensions.cs @@ -6,12 +6,12 @@ namespace EOLib.Domain.Extensions { public static class NPCExtensions { - public static bool IsFacing(this INPC npc, params EODirection[] directions) + public static bool IsFacing(this NPC.NPC npc, params EODirection[] directions) { return directions.Contains(npc.Direction); } - public static bool IsActing(this INPC npc, NPCActionState action) + public static bool IsActing(this NPC.NPC npc, NPCActionState action) { switch (action) { @@ -29,31 +29,35 @@ public static bool IsActing(this INPC npc, NPCActionState action) } } - public static int GetWalkFrame(this INPC npc) + public static int GetWalkFrame(this NPC.NPC npc) { if (!npc.IsActing(NPCActionState.Walking)) return 0; return npc.Frame - NPCFrame.WalkFrame1 + 1; } - public static INPC WithNextWalkFrame(this INPC npc) + public static NPC.NPC WithNextWalkFrame(this NPC.NPC npc) { if (npc.Frame == NPCFrame.WalkFrame4) + { return npc.WithFrame(NPCFrame.Standing); - if (npc.Frame == NPCFrame.Standing) + } + else if (npc.Frame == NPCFrame.Standing) + { return npc.WithFrame(NPCFrame.WalkFrame1); + } return npc.WithFrame(npc.Frame + 1); } - public static int GetAttackFrame(this INPC npc) + public static int GetAttackFrame(this NPC.NPC npc) { if (!npc.IsActing(NPCActionState.Attacking)) return 0; return npc.Frame - NPCFrame.Attack1 + 1; } - public static INPC WithNextAttackFrame(this INPC npc) + public static NPC.NPC WithNextAttackFrame(this NPC.NPC npc) { if (npc.Frame == NPCFrame.Attack2) return npc.WithFrame(NPCFrame.Standing); @@ -63,13 +67,13 @@ public static INPC WithNextAttackFrame(this INPC npc) return npc.WithFrame(npc.Frame + 1); } - public static int GetDestinationX(this INPC npc) + public static int GetDestinationX(this NPC.NPC npc) { var offset = GetXOffset(npc.Direction); return npc.X + offset; } - public static int GetDestinationY(this INPC npc) + public static int GetDestinationY(this NPC.NPC npc) { var offset = GetYOffset(npc.Direction); return npc.Y + offset; diff --git a/EOLib/Domain/Interact/MapNPCActions.cs b/EOLib/Domain/Interact/MapNPCActions.cs index 1582d2dcd..e243a7ca6 100644 --- a/EOLib/Domain/Interact/MapNPCActions.cs +++ b/EOLib/Domain/Interact/MapNPCActions.cs @@ -23,7 +23,7 @@ public MapNPCActions(IPacketSendService packetSendService, _questDataRepository = questDataRepository; } - public void RequestShop(INPC npc) + public void RequestShop(NPC.NPC npc) { var packet = new PacketBuilder(PacketFamily.Shop, PacketAction.Open) .AddShort((short)npc.Index) @@ -32,7 +32,7 @@ public void RequestShop(INPC npc) _packetSendService.SendPacket(packet); } - public void RequestQuest(INPC npc) + public void RequestQuest(NPC.NPC npc) { _questDataRepository.RequestedNPC = npc; @@ -46,7 +46,7 @@ public void RequestQuest(INPC npc) _packetSendService.SendPacket(packet); } - public void RequestBank(INPC npc) + public void RequestBank(NPC.NPC npc) { var packet = new PacketBuilder(PacketFamily.Bank, PacketAction.Open) .AddShort((short)npc.Index) @@ -55,7 +55,7 @@ public void RequestBank(INPC npc) _packetSendService.SendPacket(packet); } - public void RequestSkillmaster(INPC npc) + public void RequestSkillmaster(NPC.NPC npc) { var packet = new PacketBuilder(PacketFamily.StatSkill, PacketAction.Open) .AddShort((short)npc.Index) @@ -67,12 +67,12 @@ public void RequestSkillmaster(INPC npc) public interface IMapNPCActions { - void RequestShop(INPC npc); + void RequestShop(NPC.NPC npc); - void RequestQuest(INPC npc); + void RequestQuest(NPC.NPC npc); - void RequestBank(INPC npc); + void RequestBank(NPC.NPC npc); - void RequestSkillmaster(INPC npc); + void RequestSkillmaster(NPC.NPC npc); } } diff --git a/EOLib/Domain/Interact/Quest/QuestDataRepository.cs b/EOLib/Domain/Interact/Quest/QuestDataRepository.cs index be3f453a0..417e8aa60 100644 --- a/EOLib/Domain/Interact/Quest/QuestDataRepository.cs +++ b/EOLib/Domain/Interact/Quest/QuestDataRepository.cs @@ -7,22 +7,22 @@ namespace EOLib.Domain.Interact.Quest { public interface IQuestDataRepository : IResettable { - INPC RequestedNPC { get; set; } + NPC.NPC RequestedNPC { get; set; } - Option QuestDialogData { get; set; } + Option QuestDialogData { get; set; } - List QuestProgress { get; set; } + List QuestProgress { get; set; } List QuestHistory { get; set; } } public interface IQuestDataProvider : IResettable { - INPC RequestedNPC { get; } + NPC.NPC RequestedNPC { get; } - Option QuestDialogData { get; } + Option QuestDialogData { get; } - IReadOnlyList QuestProgress { get; } + IReadOnlyList QuestProgress { get; } IReadOnlyList QuestHistory { get; } } @@ -30,15 +30,15 @@ public interface IQuestDataProvider : IResettable [AutoMappedType(IsSingleton = true)] public class QuestDataRepository : IQuestDataProvider, IQuestDataRepository { - public INPC RequestedNPC { get; set; } + public NPC.NPC RequestedNPC { get; set; } - public Option QuestDialogData { get; set; } + public Option QuestDialogData { get; set; } - public List QuestProgress { get; set; } + public List QuestProgress { get; set; } public List QuestHistory { get; set; } - IReadOnlyList IQuestDataProvider.QuestProgress => QuestProgress; + IReadOnlyList IQuestDataProvider.QuestProgress => QuestProgress; IReadOnlyList IQuestDataProvider.QuestHistory => QuestHistory; @@ -49,8 +49,8 @@ public QuestDataRepository() public void ResetState() { - QuestDialogData = Option.None(); - QuestProgress = new List(); + QuestDialogData = Option.None(); + QuestProgress = new List(); QuestHistory = new List(); } } diff --git a/EOLib/Domain/Interact/Quest/QuestDialogData.cs b/EOLib/Domain/Interact/Quest/QuestDialogData.cs index f2782072a..9502a8b14 100644 --- a/EOLib/Domain/Interact/Quest/QuestDialogData.cs +++ b/EOLib/Domain/Interact/Quest/QuestDialogData.cs @@ -1,23 +1,24 @@ -using System.Collections.Generic; -using System.Linq; +using Amadevus.RecordGenerator; +using System.Collections.Generic; namespace EOLib.Domain.Interact.Quest { - public class QuestDialogData : IQuestDialogData + [Record] + public sealed partial class QuestDialogData { - public short VendorID { get; private set; } + public short VendorID { get; } - public short QuestID { get; private set; } + public short QuestID { get; } - public short SessionID { get; private set; } + public short SessionID { get; } - public short DialogID { get; private set; } + public short DialogID { get; } - public IReadOnlyDictionary DialogTitles { get; private set; } + public IReadOnlyDictionary DialogTitles { get; } - public IReadOnlyList PageText { get; private set; } + public IReadOnlyList PageText { get; } - public IReadOnlyList<(short ActionID, string DisplayText)> Actions { get; private set; } + public IReadOnlyList<(short ActionID, string DisplayText)> Actions { get; } public QuestDialogData() { @@ -25,162 +26,5 @@ public QuestDialogData() PageText = new List(); Actions = new List<(short, string)>(); } - - private QuestDialogData(short vendorID, - short questID, - short sessionID, - short dialogID, - IReadOnlyDictionary dialogTitles, - IReadOnlyList pageText, - IReadOnlyList<(short, string)> actions) - { - VendorID = vendorID; - QuestID = questID; - SessionID = sessionID; - DialogID = dialogID; - DialogTitles = dialogTitles; - PageText = pageText; - Actions = actions; - } - - public IQuestDialogData WithVendorID(short vendorId) - { - var copy = MakeCopy(this); - copy.VendorID = vendorId; - return copy; - } - - public IQuestDialogData WithQuestID(short questId) - { - var copy = MakeCopy(this); - copy.QuestID = questId; - return copy; - } - - public IQuestDialogData WithSessionID(short sessionId) - { - var copy = MakeCopy(this); - copy.SessionID = sessionId; - return copy; - } - - public IQuestDialogData WithDialogID(short dialogId) - { - var copy = MakeCopy(this); - copy.DialogID = dialogId; - return copy; - } - - public IQuestDialogData WithDialogTitles(IReadOnlyDictionary dialogTitles) - { - var copy = MakeCopy(this); - copy.DialogTitles = dialogTitles; - return copy; - } - - public IQuestDialogData WithPageText(IReadOnlyList pageText) - { - var copy = MakeCopy(this); - copy.PageText = pageText; - return copy; - } - - public IQuestDialogData WithActions(IReadOnlyList<(short, string)> actions) - { - var copy = MakeCopy(this); - copy.Actions = actions; - return copy; - } - - private static QuestDialogData MakeCopy(IQuestDialogData other) - { - return new QuestDialogData( - other.VendorID, - other.QuestID, - other.SessionID, - other.DialogID, - other.DialogTitles.ToDictionary(k => k.Key, v => v.Value), - new List(other.PageText), - new List<(short, string)>(other.Actions)); - } - - public override bool Equals(object obj) - { - var other = obj as QuestDialogData; - if (other == null) return false; - - return other.VendorID == VendorID - && other.QuestID == QuestID - && other.SessionID == SessionID - && other.DialogID == DialogID - && other.DialogTitles.SequenceEqual(DialogTitles) - && other.PageText.SequenceEqual(PageText) - && other.Actions.SequenceEqual(Actions); - } - - public override int GetHashCode() - { - int hashCode = 170256730; - hashCode = hashCode * -1521134295 + VendorID.GetHashCode(); - hashCode = hashCode * -1521134295 + QuestID.GetHashCode(); - hashCode = hashCode * -1521134295 + SessionID.GetHashCode(); - hashCode = hashCode * -1521134295 + DialogID.GetHashCode(); - hashCode = hashCode * -1521134295 + DialogTitles.Aggregate(170256730, (a, b) => a * -1521134295 + b.GetHashCode()); - hashCode = hashCode * -1521134295 + PageText.Aggregate(170256730, (a, b) => a * -1521134295 + b.GetHashCode()); - hashCode = hashCode * -1521134295 + Actions.Aggregate(170256730, (a, b) => a * -1521134295 + b.GetHashCode()); - return hashCode; - } - } - - public interface IQuestDialogData - { - /// - /// NPC Vendor ID () - /// - short VendorID { get; } - - /// - /// Quest ID, for the current dialog being shown (part of quest state in EO+ parser) - /// - short QuestID { get; } - - /// - /// Session ID, not used by eoserv - /// - short SessionID { get; } - - /// - /// Dialog ID, not used by eoserv - /// - short DialogID { get; } - - /// - /// Quest dialog titles for the current character, keyed on . - /// - IReadOnlyDictionary DialogTitles { get; } - - /// - /// Text for the quest dialog, one entry per page. - /// - IReadOnlyList PageText { get; } - - /// - /// Links for the quest dialog, only shown on the last page. - /// - IReadOnlyList<(short ActionID, string DisplayText)> Actions { get; } - - IQuestDialogData WithVendorID(short vendorId); - - IQuestDialogData WithQuestID(short questId); - - IQuestDialogData WithSessionID(short sessionId); - - IQuestDialogData WithDialogID(short dialogId); - - IQuestDialogData WithDialogTitles(IReadOnlyDictionary dialogTitles); - - IQuestDialogData WithPageText(IReadOnlyList pageText); - - IQuestDialogData WithActions(IReadOnlyList<(short, string)> actions); } } diff --git a/EOLib/Domain/Interact/Quest/QuestProgressData.cs b/EOLib/Domain/Interact/Quest/QuestProgressData.cs index 3428e8218..6f312265a 100644 --- a/EOLib/Domain/Interact/Quest/QuestProgressData.cs +++ b/EOLib/Domain/Interact/Quest/QuestProgressData.cs @@ -1,14 +1,16 @@ -using System; +using Amadevus.RecordGenerator; +using System; namespace EOLib.Domain.Interact.Quest { - public class QuestProgressData : IQuestProgressData + [Record] + public sealed partial class QuestProgressData { - public string Name { get; private set; } + public string Name { get; } - public string Description { get; private set; } + public string Description { get; } - public BookIcon Icon { get; private set; } + public BookIcon Icon { get; } public int IconIndex { @@ -31,73 +33,9 @@ public int IconIndex } } - public short Progress { get; private set; } + public short Progress { get; } - public short Target { get; private set; } + public short Target { get; } - public QuestProgressData() { } - - private QuestProgressData(string name, - string description, - BookIcon icon, - short progress, - short target) - { - Name = name; - Description = description; - Icon = icon; - Progress = progress; - Target = target; - } - - public IQuestProgressData WithName(string name) - { - return new QuestProgressData(name, Description, Icon, Progress, Target); - } - - public IQuestProgressData WithDescription(string description) - { - return new QuestProgressData(Name, description, Icon, Progress, Target); - } - - public IQuestProgressData WithIcon(BookIcon icon) - { - return new QuestProgressData(Name, Description, icon, Progress, Target); - } - - public IQuestProgressData WithProgress(short progress) - { - return new QuestProgressData(Name, Description, Icon, progress, Target); - } - - public IQuestProgressData WithTarget(short target) - { - return new QuestProgressData(Name, Description, Icon, Progress, target); - } - } - - public interface IQuestProgressData - { - string Name { get; } - - string Description { get; } - - BookIcon Icon { get; } - - int IconIndex { get; } - - short Progress { get; } - - short Target { get; } - - IQuestProgressData WithName(string name); - - IQuestProgressData WithDescription(string description); - - IQuestProgressData WithIcon(BookIcon icon); - - IQuestProgressData WithProgress(short progress); - - IQuestProgressData WithTarget(short target); } } diff --git a/EOLib/Domain/Item/ItemDropValidator.cs b/EOLib/Domain/Item/ItemDropValidator.cs index aa89b41f1..22a21da7b 100644 --- a/EOLib/Domain/Item/ItemDropValidator.cs +++ b/EOLib/Domain/Item/ItemDropValidator.cs @@ -20,13 +20,13 @@ public ItemDropValidator(IEIFFileProvider eifFileProvider, _currentMapStateProvider = currentMapStateProvider; } - public ItemDropResult ValidateItemDrop(ICharacter mainCharacter, IInventoryItem item) + public ItemDropResult ValidateItemDrop(Character.Character mainCharacter, InventoryItem item) { var coord = new MapCoordinate(mainCharacter.RenderProperties.MapX, mainCharacter.RenderProperties.MapY); return ValidateItemDrop(mainCharacter, item, coord); } - public ItemDropResult ValidateItemDrop(ICharacter mainCharacter, IInventoryItem item, MapCoordinate dropPoint) + public ItemDropResult ValidateItemDrop(Character.Character mainCharacter, InventoryItem item, MapCoordinate dropPoint) { if (item.ItemID <= 0) throw new ArgumentException("Item ID is invalid", nameof(item)); @@ -49,8 +49,8 @@ public ItemDropResult ValidateItemDrop(ICharacter mainCharacter, IInventoryItem public interface IItemDropValidator { - ItemDropResult ValidateItemDrop(ICharacter mainCharacter, IInventoryItem item); + ItemDropResult ValidateItemDrop(Character.Character mainCharacter, InventoryItem item); - ItemDropResult ValidateItemDrop(ICharacter mainCharacter, IInventoryItem item, MapCoordinate dropPoint); + ItemDropResult ValidateItemDrop(Character.Character mainCharacter, InventoryItem item, MapCoordinate dropPoint); } } diff --git a/EOLib/Domain/Item/ItemEquipValidator.cs b/EOLib/Domain/Item/ItemEquipValidator.cs index d48757d5a..603156e22 100644 --- a/EOLib/Domain/Item/ItemEquipValidator.cs +++ b/EOLib/Domain/Item/ItemEquipValidator.cs @@ -21,7 +21,7 @@ public ItemEquipValidator(IECFFileProvider ecfFileProvider, _paperdollProvider = paperdollProvider; } - public (ItemEquipResult, string, bool) ValidateItemEquip(ICharacter c, EIFRecord itemData) + public (ItemEquipResult, string, bool) ValidateItemEquip(Character.Character c, EIFRecord itemData) { if (!_paperdollProvider.VisibleCharacterPaperdolls.ContainsKey(c.ID)) { @@ -80,6 +80,6 @@ public ItemEquipValidator(IECFFileProvider ecfFileProvider, public interface IItemEquipValidator { - (ItemEquipResult Result, string Detail, bool IsAlternateEquipLocation) ValidateItemEquip(ICharacter mainCharacter, EIFRecord itemData); + (ItemEquipResult Result, string Detail, bool IsAlternateEquipLocation) ValidateItemEquip(Character.Character mainCharacter, EIFRecord itemData); } } diff --git a/EOLib/Domain/Item/ItemPickupValidator.cs b/EOLib/Domain/Item/ItemPickupValidator.cs index 7e3a8a662..5ce014970 100644 --- a/EOLib/Domain/Item/ItemPickupValidator.cs +++ b/EOLib/Domain/Item/ItemPickupValidator.cs @@ -21,7 +21,7 @@ public ItemPickupValidator(IConfigurationProvider configurationProvider, _eifFileProvider = eifFileProvider; } - public ItemPickupResult ValidateItemPickup(ICharacter mainCharacter, IItem item) + public ItemPickupResult ValidateItemPickup(Character.Character mainCharacter, MapItem item) { var now = DateTime.Now; @@ -58,6 +58,6 @@ public ItemPickupResult ValidateItemPickup(ICharacter mainCharacter, IItem item) public interface IItemPickupValidator { - ItemPickupResult ValidateItemPickup(ICharacter mainCharacter, IItem item); + ItemPickupResult ValidateItemPickup(Character.Character mainCharacter, MapItem item); } } diff --git a/EOLib/Domain/Login/AccountLoginData.cs b/EOLib/Domain/Login/AccountLoginData.cs index e976123a0..7a4478140 100644 --- a/EOLib/Domain/Login/AccountLoginData.cs +++ b/EOLib/Domain/Login/AccountLoginData.cs @@ -1,6 +1,5 @@ -using System.Collections.Generic; -using EOLib.Domain.Character; -using EOLib.Net.Translators; +using EOLib.Net.Translators; +using System.Collections.Generic; namespace EOLib.Domain.Login { @@ -8,10 +7,10 @@ public class AccountLoginData : IAccountLoginData { public LoginReply Response { get; } - private readonly List _characters; - public IReadOnlyList Characters => _characters; + private readonly List _characters; + public IReadOnlyList Characters => _characters; - public AccountLoginData(LoginReply reply, List characters) + public AccountLoginData(LoginReply reply, List characters) { Response = reply; _characters = characters; @@ -22,6 +21,6 @@ public interface IAccountLoginData : ITranslatedData { LoginReply Response { get; } - IReadOnlyList Characters { get; } + IReadOnlyList Characters { get; } } } diff --git a/EOLib/Domain/Login/CharacterSelectorRepository.cs b/EOLib/Domain/Login/CharacterSelectorRepository.cs index 70055c102..4c6f302d0 100644 --- a/EOLib/Domain/Login/CharacterSelectorRepository.cs +++ b/EOLib/Domain/Login/CharacterSelectorRepository.cs @@ -1,29 +1,28 @@ -using System.Collections.Generic; -using AutomaticTypeMapper; -using EOLib.Domain.Character; +using AutomaticTypeMapper; using Optional; +using System.Collections.Generic; namespace EOLib.Domain.Login { public interface ICharacterSelectorRepository { - IReadOnlyList Characters { get; set; } + IReadOnlyList Characters { get; set; } - Option CharacterForDelete { get; set; } + Option CharacterForDelete { get; set; } } public interface ICharacterSelectorProvider { - IReadOnlyList Characters { get; } + IReadOnlyList Characters { get; } - Option CharacterForDelete { get; } + Option CharacterForDelete { get; } } [AutoMappedType(IsSingleton = true)] public class CharacterSelectorRepository : ICharacterSelectorRepository, ICharacterSelectorProvider { - public IReadOnlyList Characters { get; set; } + public IReadOnlyList Characters { get; set; } - public Option CharacterForDelete { get; set; } + public Option CharacterForDelete { get; set; } } } diff --git a/EOLib/Domain/Login/ILoginRequestCompletedData.cs b/EOLib/Domain/Login/ILoginRequestCompletedData.cs deleted file mode 100644 index 14c24d271..000000000 --- a/EOLib/Domain/Login/ILoginRequestCompletedData.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Collections.Generic; -using EOLib.Domain.Character; -using EOLib.Domain.Map; -using EOLib.Domain.NPC; -using EOLib.Net.Translators; - -namespace EOLib.Domain.Login -{ - public interface ILoginRequestCompletedData : ITranslatedData - { - IReadOnlyList News { get; } - - byte CharacterWeight { get; } - - byte CharacterMaxWeight { get; } - - IReadOnlyList CharacterItemInventory { get; } - - IReadOnlyList CharacterSpellInventory { get; } - - IReadOnlyList MapCharacters { get; } - - IReadOnlyList MapNPCs { get; } - - IReadOnlyList MapItems { get; } - - CharacterLoginReply Error { get; } - - ILoginRequestCompletedData WithNews(IEnumerable newsStrings); - - ILoginRequestCompletedData WithWeight(byte weight); - - ILoginRequestCompletedData WithMaxWeight(byte maxWeight); - - ILoginRequestCompletedData WithInventory(IEnumerable inventoryItems); - - ILoginRequestCompletedData WithSpells(IEnumerable inventorySpells); - - ILoginRequestCompletedData WithCharacters(IEnumerable characters); - - ILoginRequestCompletedData WithNPCs(IEnumerable npcs); - - ILoginRequestCompletedData WithItems(IEnumerable items); - - ILoginRequestCompletedData WithError(CharacterLoginReply error); - } -} diff --git a/EOLib/Domain/Login/ILoginRequestGrantedData.cs b/EOLib/Domain/Login/ILoginRequestGrantedData.cs deleted file mode 100644 index 296a845f2..000000000 --- a/EOLib/Domain/Login/ILoginRequestGrantedData.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.Collections.Generic; -using EOLib.Domain.Character; -using EOLib.IO; -using EOLib.Net.Translators; - -namespace EOLib.Domain.Login -{ - public interface ILoginRequestGrantedData : ITranslatedData - { - short SessionID { get; } - int CharacterID { get; } - - short MapID { get; } - IReadOnlyList MapRID { get; } - int MapLen { get; } - - int EifRid { get; } - short EifLen { get; } - int EnfRid { get; } - short EnfLen { get; } - int EsfRid { get; } - short EsfLen { get; } - int EcfRid { get; } - short EcfLen { get; } - - string Name { get; } - string Title { get; } - string GuildName { get; } - string GuildRank { get; } - byte ClassID { get; } - string GuildTag { get; } - AdminLevel AdminLevel { get; } - - ICharacterStats CharacterStats { get; } - - IReadOnlyDictionary Paperdoll { get; } - - byte GuildRankNum { get; } - short JailMap { get; } - bool FirstTimePlayer { get; } - - ILoginRequestGrantedData WithSessionID(short sessionID); - ILoginRequestGrantedData WithCharacterID(int characterID); - ILoginRequestGrantedData WithMapID(short mapID); - ILoginRequestGrantedData WithMapRID(IEnumerable mapRID); - ILoginRequestGrantedData WithMapLen(int mapLen); - ILoginRequestGrantedData WithEifRID(int eifRid); - ILoginRequestGrantedData WithEifLen(short eifLen); - ILoginRequestGrantedData WithEnfRID(int enfRid); - ILoginRequestGrantedData WithEnfLen(short enfLen); - ILoginRequestGrantedData WithEsfRID(int esfRid); - ILoginRequestGrantedData WithEsfLen(short esfLen); - ILoginRequestGrantedData WithEcfRID(int ecfRid); - ILoginRequestGrantedData WithEcfLen(short ecfLen); - ILoginRequestGrantedData WithName(string name); - ILoginRequestGrantedData WithTitle(string title); - ILoginRequestGrantedData WithGuildName(string guildName); - ILoginRequestGrantedData WithGuildRank(string guildRank); - ILoginRequestGrantedData WithClassId(byte classID); - ILoginRequestGrantedData WithGuildTag(string guildTag); - ILoginRequestGrantedData WithAdminLevel(AdminLevel adminLevel); - ILoginRequestGrantedData WithCharacterStats(ICharacterStats stats); - ILoginRequestGrantedData WithPaperdoll(IReadOnlyDictionary paperdoll); - ILoginRequestGrantedData WithGuildRankNum(byte rankNum); - ILoginRequestGrantedData WithJailMap(short jailMapID); - ILoginRequestGrantedData WithFirstTimePlayer(bool isFirstTimePlayer); - } -} diff --git a/EOLib/Domain/Login/LoginActions.cs b/EOLib/Domain/Login/LoginActions.cs index 469f110b8..18472e41b 100644 --- a/EOLib/Domain/Login/LoginActions.cs +++ b/EOLib/Domain/Login/LoginActions.cs @@ -18,8 +18,8 @@ public class LoginActions : ILoginActions { private readonly IPacketSendService _packetSendService; private readonly IPacketTranslator _loginPacketTranslator; - private readonly IPacketTranslator _loginRequestGrantedPacketTranslator; - private readonly IPacketTranslator _loginRequestCompletedPacketTranslator; + private readonly IPacketTranslator _loginRequestGrantedPacketTranslator; + private readonly IPacketTranslator _loginRequestCompletedPacketTranslator; private readonly ICharacterSelectorRepository _characterSelectorRepository; private readonly IPlayerInfoRepository _playerInfoRepository; private readonly ICharacterRepository _characterRepository; @@ -32,8 +32,8 @@ public class LoginActions : ILoginActions public LoginActions(IPacketSendService packetSendService, IPacketTranslator loginPacketTranslator, - IPacketTranslator loginRequestGrantedPacketTranslator, - IPacketTranslator loginRequestCompletedPacketTranslator, + IPacketTranslator loginRequestGrantedPacketTranslator, + IPacketTranslator loginRequestCompletedPacketTranslator, ICharacterSelectorRepository characterSelectorRepository, IPlayerInfoRepository playerInfoRepository, ICharacterRepository characterRepository, @@ -88,7 +88,7 @@ public async Task LoginToServer(ILoginParameters parameters) return data.Response; } - public async Task RequestCharacterLogin(ICharacter character) + public async Task RequestCharacterLogin(Character.Character character) { var packet = new PacketBuilder(PacketFamily.Welcome, PacketAction.Request) .AddInt(character.ID) @@ -180,12 +180,12 @@ public async Task CompleteCharacterLogin(short sessionID) .WithStats(stats) .WithRenderProperties(mainCharacter.RenderProperties); - _characterInventoryRepository.ItemInventory = new HashSet(data.CharacterItemInventory); - _characterInventoryRepository.SpellInventory = new HashSet(data.CharacterSpellInventory); + _characterInventoryRepository.ItemInventory = new HashSet(data.CharacterItemInventory); + _characterInventoryRepository.SpellInventory = new HashSet(data.CharacterSpellInventory); _currentMapStateRepository.Characters = data.MapCharacters.Except(new[] { mainCharacter }).ToDictionary(k => k.ID, v => v); - _currentMapStateRepository.NPCs = new HashSet(data.MapNPCs); - _currentMapStateRepository.MapItems = new HashSet(data.MapItems); + _currentMapStateRepository.NPCs = new HashSet(data.MapNPCs); + _currentMapStateRepository.MapItems = new HashSet(data.MapItems); _playerInfoRepository.PlayerIsInGame = true; _characterSessionRepository.ResetState(); @@ -211,7 +211,7 @@ public interface ILoginActions Task LoginToServer(ILoginParameters parameters); - Task RequestCharacterLogin(ICharacter character); + Task RequestCharacterLogin(Character.Character character); Task CompleteCharacterLogin(short sessionID); } diff --git a/EOLib/Domain/Login/LoginRequestCompletedData.cs b/EOLib/Domain/Login/LoginRequestCompletedData.cs index 96490674c..ac88e7ac7 100644 --- a/EOLib/Domain/Login/LoginRequestCompletedData.cs +++ b/EOLib/Domain/Login/LoginRequestCompletedData.cs @@ -1,109 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using Amadevus.RecordGenerator; using EOLib.Domain.Character; using EOLib.Domain.Map; -using EOLib.Domain.NPC; +using EOLib.Net.Translators; +using System.Collections.Generic; namespace EOLib.Domain.Login { - public class LoginRequestCompletedData : ILoginRequestCompletedData + [Record] + public sealed partial class LoginRequestCompletedData : ITranslatedData { - public IReadOnlyList News { get; private set; } - - public byte CharacterWeight { get; private set; } - - public byte CharacterMaxWeight { get; private set; } - - public IReadOnlyList CharacterItemInventory { get; private set; } - - public IReadOnlyList CharacterSpellInventory { get; private set; } - - public IReadOnlyList MapCharacters { get; private set; } - - public IReadOnlyList MapNPCs { get; private set; } - - public IReadOnlyList MapItems { get; private set; } - - public CharacterLoginReply Error { get; private set; } - - public ILoginRequestCompletedData WithNews(IEnumerable newsStrings) - { - var copy = MakeCopy(this); - copy.News = newsStrings.ToList(); - return copy; - } - - public ILoginRequestCompletedData WithWeight(byte weight) - { - var copy = MakeCopy(this); - copy.CharacterWeight = weight; - return copy; - } + public IReadOnlyList News { get; } - public ILoginRequestCompletedData WithMaxWeight(byte maxWeight) - { - var copy = MakeCopy(this); - copy.CharacterMaxWeight = maxWeight; - return copy; - } + public byte CharacterWeight { get; } - public ILoginRequestCompletedData WithInventory(IEnumerable inventoryItems) - { - var copy = MakeCopy(this); - copy.CharacterItemInventory = inventoryItems.ToList(); - return copy; - } + public byte CharacterMaxWeight { get; } - public ILoginRequestCompletedData WithSpells(IEnumerable inventorySpells) - { - var copy = MakeCopy(this); - copy.CharacterSpellInventory = inventorySpells.ToList(); - return copy; - } + public IReadOnlyList CharacterItemInventory { get; } - public ILoginRequestCompletedData WithCharacters(IEnumerable characters) - { - var copy = MakeCopy(this); - copy.MapCharacters = characters.ToList(); - return copy; - } + public IReadOnlyList CharacterSpellInventory { get; } - public ILoginRequestCompletedData WithNPCs(IEnumerable npcs) - { - var copy = MakeCopy(this); - copy.MapNPCs = npcs.ToList(); - return copy; - } + public IReadOnlyList MapCharacters { get; } - public ILoginRequestCompletedData WithItems(IEnumerable items) - { - var copy = MakeCopy(this); - copy.MapItems = items.ToList(); - return copy; - } + public IReadOnlyList MapNPCs { get; } - public ILoginRequestCompletedData WithError(CharacterLoginReply error) - { - var copy = MakeCopy(this); - copy.Error = error; - return copy; - } + public IReadOnlyList MapItems { get; } - private static LoginRequestCompletedData MakeCopy(ILoginRequestCompletedData source) - { - return new LoginRequestCompletedData - { - News = source.News, - CharacterWeight = source.CharacterWeight, - CharacterMaxWeight = source.CharacterMaxWeight, - CharacterItemInventory = source.CharacterItemInventory, - CharacterSpellInventory = source.CharacterSpellInventory, - MapCharacters = source.MapCharacters, - MapNPCs = source.MapNPCs, - MapItems = source.MapItems, - Error = source.Error, - }; - } + public CharacterLoginReply Error { get; } } } \ No newline at end of file diff --git a/EOLib/Domain/Login/LoginRequestGrantedData.cs b/EOLib/Domain/Login/LoginRequestGrantedData.cs index 0d155e5f5..52b1dd52e 100644 --- a/EOLib/Domain/Login/LoginRequestGrantedData.cs +++ b/EOLib/Domain/Login/LoginRequestGrantedData.cs @@ -1,256 +1,44 @@ -using System.Collections.Generic; -using System.Linq; +using Amadevus.RecordGenerator; using EOLib.Domain.Character; using EOLib.IO; +using EOLib.Net.Translators; +using System.Collections.Generic; namespace EOLib.Domain.Login { - public class LoginRequestGrantedData : ILoginRequestGrantedData + [Record] + public sealed partial class LoginRequestGrantedData : ITranslatedData { - public short SessionID { get; private set; } - public int CharacterID { get; private set; } - - public short MapID { get; private set; } - public IReadOnlyList MapRID { get; private set; } - public int MapLen { get; private set; } - - public int EifRid { get; private set; } - public short EifLen { get; private set; } - public int EnfRid { get; private set; } - public short EnfLen { get; private set; } - public int EsfRid { get; private set; } - public short EsfLen { get; private set; } - public int EcfRid { get; private set; } - public short EcfLen { get; private set; } - - public string Name { get; private set; } - public string Title { get; private set; } - public string GuildName { get; private set; } - public string GuildRank { get; private set; } - public byte ClassID { get; private set; } - public string GuildTag { get; private set; } - public AdminLevel AdminLevel { get; private set; } - - public ICharacterStats CharacterStats { get; private set; } - - private IReadOnlyDictionary _paperdoll = new Dictionary(); - public IReadOnlyDictionary Paperdoll => _paperdoll; - - public byte GuildRankNum { get; private set; } - public short JailMap { get; private set; } - public bool FirstTimePlayer { get; private set; } - - public ILoginRequestGrantedData WithSessionID(short sessionID) - { - var copy = MakeCopy(this); - copy.SessionID = sessionID; - return copy; - } - - public ILoginRequestGrantedData WithCharacterID(int characterID) - { - var copy = MakeCopy(this); - copy.CharacterID = characterID; - return copy; - } - - public ILoginRequestGrantedData WithMapID(short mapID) - { - var copy = MakeCopy(this); - copy.MapID = mapID; - return copy; - } - - public ILoginRequestGrantedData WithMapRID(IEnumerable mapRID) - { - var copy = MakeCopy(this); - copy.MapRID = mapRID.ToList(); - return copy; - } - - public ILoginRequestGrantedData WithMapLen(int mapLen) - { - var copy = MakeCopy(this); - copy.MapLen = mapLen; - return copy; - } - - public ILoginRequestGrantedData WithEifRID(int eifRid) - { - var copy = MakeCopy(this); - copy.EifRid = eifRid; - return copy; - } - - public ILoginRequestGrantedData WithEifLen(short eifLen) - { - var copy = MakeCopy(this); - copy.EifLen = eifLen; - return copy; - } - - public ILoginRequestGrantedData WithEnfRID(int enfRid) - { - var copy = MakeCopy(this); - copy.EnfRid = enfRid; - return copy; - } - - public ILoginRequestGrantedData WithEnfLen(short enfLen) - { - var copy = MakeCopy(this); - copy.EnfLen = enfLen; - return copy; - } - - public ILoginRequestGrantedData WithEsfRID(int esfRid) - { - var copy = MakeCopy(this); - copy.EsfRid = esfRid; - return copy; - } - - public ILoginRequestGrantedData WithEsfLen(short esfLen) - { - var copy = MakeCopy(this); - copy.EsfLen = esfLen; - return copy; - } - - public ILoginRequestGrantedData WithEcfRID(int ecfRid) - { - var copy = MakeCopy(this); - copy.EcfRid = ecfRid; - return copy; - } - - public ILoginRequestGrantedData WithEcfLen(short ecfLen) - { - var copy = MakeCopy(this); - copy.EcfLen = ecfLen; - return copy; - } - - public ILoginRequestGrantedData WithName(string name) - { - var copy = MakeCopy(this); - copy.Name = name; - return copy; - } - - public ILoginRequestGrantedData WithTitle(string title) - { - var copy = MakeCopy(this); - copy.Title = title; - return copy; - } - - public ILoginRequestGrantedData WithGuildName(string guildName) - { - var copy = MakeCopy(this); - copy.GuildName = guildName; - return copy; - } - - public ILoginRequestGrantedData WithGuildRank(string guildRank) - { - var copy = MakeCopy(this); - copy.GuildRank = guildRank; - return copy; - } - - public ILoginRequestGrantedData WithClassId(byte classID) - { - var copy = MakeCopy(this); - copy.ClassID = classID; - return copy; - } - - public ILoginRequestGrantedData WithGuildTag(string guildTag) - { - var copy = MakeCopy(this); - copy.GuildTag = guildTag; - return copy; - } - - public ILoginRequestGrantedData WithAdminLevel(AdminLevel adminLevel) - { - var copy = MakeCopy(this); - copy.AdminLevel = adminLevel; - return copy; - } - - public ILoginRequestGrantedData WithCharacterStats(ICharacterStats stats) - { - var copy = MakeCopy(this); - copy.CharacterStats = stats; - return copy; - } - - public ILoginRequestGrantedData WithPaperdoll(IReadOnlyDictionary paperdoll) - { - var copy = MakeCopy(this); - copy._paperdoll = paperdoll; - return copy; - } - - public ILoginRequestGrantedData WithGuildRankNum(byte rankNum) - { - var copy = MakeCopy(this); - copy.GuildRankNum = rankNum; - return copy; - } - - public ILoginRequestGrantedData WithJailMap(short jailMapID) - { - var copy = MakeCopy(this); - copy.JailMap = jailMapID; - return copy; - } - - public ILoginRequestGrantedData WithFirstTimePlayer(bool isFirstTimePlayer) - { - var copy = MakeCopy(this); - copy.FirstTimePlayer = isFirstTimePlayer; - return copy; - } - - private static LoginRequestGrantedData MakeCopy(LoginRequestGrantedData source) - { - return new LoginRequestGrantedData - { - SessionID = source.SessionID, - CharacterID = source.CharacterID, - - MapID = source.MapID, - MapRID = source.MapRID, - MapLen = source.MapLen, - - EifLen = source.EifLen, - EifRid = source.EifRid, - EnfLen = source.EnfLen, - EnfRid = source.EnfRid, - EsfLen = source.EsfLen, - EsfRid = source.EsfRid, - EcfLen = source.EcfLen, - EcfRid = source.EcfRid, - - Name = source.Name, - Title = source.Title, - GuildName = source.GuildName, - GuildRank = source.GuildRank, - ClassID = source.ClassID, - GuildTag = source.GuildTag, - AdminLevel = source.AdminLevel, - - CharacterStats = source.CharacterStats, - - _paperdoll = source._paperdoll, - - JailMap = source.JailMap, - GuildRankNum = source.GuildRankNum, - FirstTimePlayer = source.FirstTimePlayer - }; - } + public short SessionID { get; } + public int CharacterID { get; } + + public short MapID { get; } + public IReadOnlyList MapRID { get; } + public int MapLen { get; } + + public int EifRid { get; } + public short EifLen { get; } + public int EnfRid { get; } + public short EnfLen { get; } + public int EsfRid { get; } + public short EsfLen { get; } + public int EcfRid { get; } + public short EcfLen { get; } + + public string Name { get; } + public string Title { get; } + public string GuildName { get; } + public string GuildRank { get; } + public byte ClassID { get; } + public string GuildTag { get; } + public AdminLevel AdminLevel { get; } + + public CharacterStats CharacterStats { get; } + + public IReadOnlyDictionary Paperdoll { get; } + + public byte GuildRankNum { get; } + public short JailMap { get; } + public bool FirstTimePlayer { get; } } } diff --git a/EOLib/Domain/Map/ChestActions.cs b/EOLib/Domain/Map/ChestActions.cs index 49a045ca6..39bf116cb 100644 --- a/EOLib/Domain/Map/ChestActions.cs +++ b/EOLib/Domain/Map/ChestActions.cs @@ -18,7 +18,7 @@ public ChestActions(IPacketSendService packetSendService, _chestDataProvider = chestDataProvider; } - public void AddItemToChest(IInventoryItem item) + public void AddItemToChest(InventoryItem item) { var packet = new PacketBuilder(PacketFamily.Chest, PacketAction.Add) .AddChar((byte)_chestDataProvider.Location.X) @@ -45,7 +45,7 @@ public void TakeItemFromChest(short itemId) public interface IChestActions { - void AddItemToChest(IInventoryItem item); + void AddItemToChest(InventoryItem item); void TakeItemFromChest(short itemId); } diff --git a/EOLib/Domain/Map/ChestDataRepository.cs b/EOLib/Domain/Map/ChestDataRepository.cs index 697e841d4..edb3bdaff 100644 --- a/EOLib/Domain/Map/ChestDataRepository.cs +++ b/EOLib/Domain/Map/ChestDataRepository.cs @@ -8,14 +8,14 @@ public interface IChestDataRepository : IResettable { MapCoordinate Location { get; set; } - HashSet Items { get; set; } + HashSet Items { get; set; } } public interface IChestDataProvider : IResettable { MapCoordinate Location { get; } - IReadOnlyCollection Items { get; } + IReadOnlyCollection Items { get; } } [AutoMappedType(IsSingleton = true)] @@ -23,9 +23,9 @@ public class ChestDataRepository : IChestDataProvider, IChestDataRepository { public MapCoordinate Location { get; set; } - public HashSet Items { get; set; } + public HashSet Items { get; set; } - IReadOnlyCollection IChestDataProvider.Items => Items; + IReadOnlyCollection IChestDataProvider.Items => Items; public ChestDataRepository() { @@ -35,7 +35,7 @@ public ChestDataRepository() public void ResetState() { Location = MapCoordinate.Zero; - Items = new HashSet(); + Items = new HashSet(); } } } diff --git a/EOLib/Domain/Map/ChestItem.cs b/EOLib/Domain/Map/ChestItem.cs index d11230c83..a095a3b44 100644 --- a/EOLib/Domain/Map/ChestItem.cs +++ b/EOLib/Domain/Map/ChestItem.cs @@ -1,26 +1,14 @@ -using EOLib.Domain.Character; +using Amadevus.RecordGenerator; namespace EOLib.Domain.Map { - public class ChestItem : InventoryItem + [Record] + public sealed partial class ChestItem { - public int Slot { get; } - - public ChestItem(short itemID, int amount, int slot) - : base(itemID, amount) - { - Slot = slot; - } + public short ItemID { get; } - public override bool Equals(object obj) - { - var chestItem = obj as ChestItem; - return base.Equals(chestItem) && Slot == chestItem.Slot; - } + public int Amount { get; } - public override int GetHashCode() - { - return base.GetHashCode() * -1521134295 + Slot.GetHashCode(); - } + public int Slot { get; } } } diff --git a/EOLib/Domain/Map/CurrentMapStateRepository.cs b/EOLib/Domain/Map/CurrentMapStateRepository.cs index 4eafa7012..2649d825a 100644 --- a/EOLib/Domain/Map/CurrentMapStateRepository.cs +++ b/EOLib/Domain/Map/CurrentMapStateRepository.cs @@ -1,7 +1,5 @@ -using System.Collections.Generic; using AutomaticTypeMapper; -using EOLib.Domain.Character; -using EOLib.Domain.NPC; +using System.Collections.Generic; namespace EOLib.Domain.Map { @@ -13,15 +11,15 @@ public interface ICurrentMapStateRepository short JailMapID { get; set; } - Dictionary Characters { get; set; } + Dictionary Characters { get; set; } - HashSet NPCs { get; set; } + HashSet NPCs { get; set; } - HashSet MapItems { get; set; } + HashSet MapItems { get; set; } - HashSet OpenDoors { get; set; } + HashSet OpenDoors { get; set; } - HashSet PendingDoors { get; set; } + HashSet PendingDoors { get; set; } HashSet VisibleSpikeTraps { get; set; } @@ -40,15 +38,15 @@ public interface ICurrentMapStateProvider short JailMapID { get; } - IReadOnlyDictionary Characters { get; } + IReadOnlyDictionary Characters { get; } - IReadOnlyCollection NPCs { get; } + IReadOnlyCollection NPCs { get; } - IReadOnlyCollection MapItems { get; } + IReadOnlyCollection MapItems { get; } - IReadOnlyCollection OpenDoors { get; } + IReadOnlyCollection OpenDoors { get; } - IReadOnlyCollection PendingDoors { get; } + IReadOnlyCollection PendingDoors { get; } IReadOnlyCollection VisibleSpikeTraps { get; } @@ -68,15 +66,15 @@ public class CurrentMapStateRepository : ICurrentMapStateRepository, ICurrentMap public short JailMapID { get; set; } - public Dictionary Characters { get; set; } + public Dictionary Characters { get; set; } - public HashSet NPCs { get; set; } + public HashSet NPCs { get; set; } - public HashSet MapItems { get; set; } + public HashSet MapItems { get; set; } - public HashSet OpenDoors { get; set; } + public HashSet OpenDoors { get; set; } - public HashSet PendingDoors { get; set; } + public HashSet PendingDoors { get; set; } public HashSet VisibleSpikeTraps { get; set; } @@ -86,15 +84,15 @@ public class CurrentMapStateRepository : ICurrentMapStateRepository, ICurrentMap public HashSet UnknownNPCIndexes { get; set; } - IReadOnlyDictionary ICurrentMapStateProvider.Characters => Characters; + IReadOnlyDictionary ICurrentMapStateProvider.Characters => Characters; - IReadOnlyCollection ICurrentMapStateProvider.NPCs => NPCs; + IReadOnlyCollection ICurrentMapStateProvider.NPCs => NPCs; - IReadOnlyCollection ICurrentMapStateProvider.MapItems => MapItems; + IReadOnlyCollection ICurrentMapStateProvider.MapItems => MapItems; - IReadOnlyCollection ICurrentMapStateProvider.OpenDoors => OpenDoors; + IReadOnlyCollection ICurrentMapStateProvider.OpenDoors => OpenDoors; - IReadOnlyCollection ICurrentMapStateProvider.PendingDoors => PendingDoors; + IReadOnlyCollection ICurrentMapStateProvider.PendingDoors => PendingDoors; IReadOnlyCollection ICurrentMapStateProvider.VisibleSpikeTraps => VisibleSpikeTraps; @@ -109,11 +107,11 @@ public void ResetState() ShowMiniMap = false; JailMapID = 0; - Characters = new Dictionary(); - NPCs = new HashSet(); - MapItems = new HashSet(); - OpenDoors = new HashSet(); - PendingDoors = new HashSet(); + Characters = new Dictionary(); + NPCs = new HashSet(); + MapItems = new HashSet(); + OpenDoors = new HashSet(); + PendingDoors = new HashSet(); VisibleSpikeTraps = new HashSet(); UnknownPlayerIDs = new HashSet(); UnknownNPCIndexes = new HashSet(); diff --git a/EOLib/Domain/Map/IMapCellState.cs b/EOLib/Domain/Map/IMapCellState.cs index c481aef79..6fa34f3d4 100644 --- a/EOLib/Domain/Map/IMapCellState.cs +++ b/EOLib/Domain/Map/IMapCellState.cs @@ -1,8 +1,7 @@ -using System.Collections.Generic; -using EOLib.Domain.Character; -using EOLib.Domain.NPC; +using EOLib.Domain.Character; using EOLib.IO.Map; using Optional; +using System.Collections.Generic; namespace EOLib.Domain.Map { @@ -12,18 +11,18 @@ public interface IMapCellState MapCoordinate Coordinate { get; } - IReadOnlyList Items { get; } + IReadOnlyList Items { get; } TileSpec TileSpec { get; } - Option NPC { get; } + Option NPC { get; } - Option Character { get; } + Option Character { get; } Option ChestKey { get; } - Option Warp { get; } + Option Warp { get; } - Option Sign { get; } + Option Sign { get; } } } diff --git a/EOLib/Domain/Map/Item.cs b/EOLib/Domain/Map/Item.cs deleted file mode 100644 index af4efb829..000000000 --- a/EOLib/Domain/Map/Item.cs +++ /dev/null @@ -1,127 +0,0 @@ -using Optional; -using System; - -namespace EOLib.Domain.Map -{ - public class Item : IItem - { - public short UniqueID { get; } - - public short ItemID { get; } - - public byte X { get; } - - public byte Y { get; } - - public int Amount { get; private set; } - - public bool IsNPCDrop { get; private set; } - - public Option OwningPlayerID { get; private set; } - - public Option DropTime { get; private set; } - - public static IItem None => new Item(0, 0, 0, 0); - - public Item(short uid, short itemID, byte x, byte y) - { - UniqueID = uid; - ItemID = itemID; - X = x; - Y = y; - } - - public IItem WithAmount(int newAmount) - { - var newItem = MakeCopy(this); - newItem.Amount = newAmount; - return newItem; - } - - public IItem WithIsNPCDrop(bool isNPCDrop) - { - var newItem = MakeCopy(this); - newItem.IsNPCDrop = isNPCDrop; - return newItem; - } - - public IItem WithOwningPlayerID(int owningPlayerID) - { - var newItem = MakeCopy(this); - newItem.OwningPlayerID = Option.Some(owningPlayerID); - return newItem; - } - - public IItem WithDropTime(DateTime dropTime) - { - var newItem = MakeCopy(this); - newItem.DropTime = Option.Some(dropTime); - return newItem; - } - - private static Item MakeCopy(IItem input) - { - return new Item(input.UniqueID, input.ItemID, input.X, input.Y) - { - Amount = input.Amount, - IsNPCDrop = input.IsNPCDrop, - OwningPlayerID = input.OwningPlayerID, - DropTime = input.DropTime - }; - } - - public override bool Equals(object obj) - { - return obj is Item item && - UniqueID == item.UniqueID && - ItemID == item.ItemID && - X == item.X && - Y == item.Y && - Amount == item.Amount && - IsNPCDrop == item.IsNPCDrop && - OwningPlayerID.Equals(item.OwningPlayerID) && - DropTime.Equals(item.DropTime); - } - - public override int GetHashCode() - { - int hashCode = -885092675; - hashCode = hashCode * -1521134295 + UniqueID.GetHashCode(); - hashCode = hashCode * -1521134295 + ItemID.GetHashCode(); - hashCode = hashCode * -1521134295 + X.GetHashCode(); - hashCode = hashCode * -1521134295 + Y.GetHashCode(); - hashCode = hashCode * -1521134295 + Amount.GetHashCode(); - hashCode = hashCode * -1521134295 + IsNPCDrop.GetHashCode(); - hashCode = hashCode * -1521134295 + OwningPlayerID.GetHashCode(); - hashCode = hashCode * -1521134295 + DropTime.GetHashCode(); - return hashCode; - } - } - - public interface IItem - { - short UniqueID { get; } - - short ItemID { get; } - - byte X { get; } - - byte Y { get; } - - int Amount { get; } - - bool IsNPCDrop { get; } - - Option OwningPlayerID { get; } - - Option DropTime { get; } - - IItem WithAmount(int newAmount); - - IItem WithIsNPCDrop(bool isNPCDrop); - - IItem WithOwningPlayerID(int owningPlayerID); - - IItem WithDropTime(DateTime dropTime); - } -} \ No newline at end of file diff --git a/EOLib/Domain/Map/LockerActions.cs b/EOLib/Domain/Map/LockerActions.cs index 1f0500c2c..31d333b9c 100644 --- a/EOLib/Domain/Map/LockerActions.cs +++ b/EOLib/Domain/Map/LockerActions.cs @@ -19,7 +19,7 @@ public LockerActions(IPacketSendService packetSendService, _lockerDataProvider = lockerDataProvider; } - public void AddItemToLocker(IInventoryItem item) + public void AddItemToLocker(InventoryItem item) { var packet = new PacketBuilder(PacketFamily.Locker, PacketAction.Add) .AddChar((byte)_lockerDataProvider.Location.X) @@ -52,7 +52,7 @@ public int GetNewItemAmount(short itemId, int amount) public interface ILockerActions { - void AddItemToLocker(IInventoryItem item); + void AddItemToLocker(InventoryItem item); void TakeItemFromLocker(short itemId); diff --git a/EOLib/Domain/Map/LockerDataRepository.cs b/EOLib/Domain/Map/LockerDataRepository.cs index 033b6930e..c653933ab 100644 --- a/EOLib/Domain/Map/LockerDataRepository.cs +++ b/EOLib/Domain/Map/LockerDataRepository.cs @@ -8,14 +8,14 @@ public interface ILockerDataRepository : IResettable { MapCoordinate Location { get; set; } - HashSet Items { get; set; } + HashSet Items { get; set; } } public interface ILockerDataProvider : IResettable { MapCoordinate Location { get; } - IReadOnlyCollection Items { get; } + IReadOnlyCollection Items { get; } } [AutoMappedType(IsSingleton = true)] @@ -23,9 +23,9 @@ public class LockerDataRepository : ILockerDataProvider, ILockerDataRepository { public MapCoordinate Location { get; set; } - public HashSet Items { get; set; } + public HashSet Items { get; set; } - IReadOnlyCollection ILockerDataProvider.Items => Items; + IReadOnlyCollection ILockerDataProvider.Items => Items; public LockerDataRepository() { @@ -35,7 +35,7 @@ public LockerDataRepository() public void ResetState() { Location = MapCoordinate.Zero; - Items = new HashSet(); + Items = new HashSet(); } } } diff --git a/EOLib/Domain/Map/MapActions.cs b/EOLib/Domain/Map/MapActions.cs index 49a10fba0..585ee7de3 100644 --- a/EOLib/Domain/Map/MapActions.cs +++ b/EOLib/Domain/Map/MapActions.cs @@ -34,7 +34,7 @@ public void RequestRefresh() _packetSendService.SendPacket(packet); } - public ItemPickupResult PickUpItem(IItem item) + public ItemPickupResult PickUpItem(MapItem item) { var pickupResult = _itemPickupValidator.ValidateItemPickup(_characterProvider.MainCharacter, item); if (pickupResult == ItemPickupResult.Ok) @@ -49,7 +49,7 @@ public ItemPickupResult PickUpItem(IItem item) return pickupResult; } - public void OpenDoor(IWarp warp) + public void OpenDoor(Warp warp) { var packet = new PacketBuilder(PacketFamily.Door, PacketAction.Open) .AddChar((byte)warp.X) @@ -85,9 +85,9 @@ public interface IMapActions { void RequestRefresh(); - ItemPickupResult PickUpItem(IItem item); + ItemPickupResult PickUpItem(MapItem item); - void OpenDoor(IWarp warp); + void OpenDoor(Warp warp); void OpenChest(byte x, byte y); diff --git a/EOLib/Domain/Map/MapCellState.cs b/EOLib/Domain/Map/MapCellState.cs index f7ef88fbb..9605713ee 100644 --- a/EOLib/Domain/Map/MapCellState.cs +++ b/EOLib/Domain/Map/MapCellState.cs @@ -1,8 +1,7 @@ -using System.Collections.Generic; -using EOLib.Domain.Character; -using EOLib.Domain.NPC; +using EOLib.Domain.Character; using EOLib.IO.Map; using Optional; +using System.Collections.Generic; namespace EOLib.Domain.Map { @@ -12,30 +11,30 @@ public class MapCellState : IMapCellState public MapCoordinate Coordinate { get; set; } - public IReadOnlyList Items { get; set; } + public IReadOnlyList Items { get; set; } public TileSpec TileSpec { get; set; } - public Option NPC { get; set; } + public Option NPC { get; set; } - public Option Character { get; set; } + public Option Character { get; set; } public Option ChestKey { get; set; } - public Option Warp { get; set; } + public Option Warp { get; set; } - public Option Sign { get; set; } + public Option Sign { get; set; } public MapCellState() { Coordinate = new MapCoordinate(0, 0); - Items = new List(); + Items = new List(); TileSpec = TileSpec.None; - NPC = Option.None(); - Character = Option.None(); + NPC = Option.None(); + Character = Option.None(); ChestKey = Option.None(); - Warp = Option.None(); - Sign = Option.None(); + Warp = Option.None(); + Sign = Option.None(); } } } diff --git a/EOLib/Domain/Map/MapCellStateProvider.cs b/EOLib/Domain/Map/MapCellStateProvider.cs index c533e7bc5..57cd408d2 100644 --- a/EOLib/Domain/Map/MapCellStateProvider.cs +++ b/EOLib/Domain/Map/MapCellStateProvider.cs @@ -47,22 +47,22 @@ public IMapCellState GetCellStateAt(int x, int y) Coordinate = new MapCoordinate(x, y), Items = items.ToList(), TileSpec = tileSpec, - Warp = warp.SomeNotNull().Map(w => new Warp(w)), + Warp = warp.SomeNotNull().Map(w => new Warp(w)), ChestKey = chest.SomeNotNull(), - Sign = sign.SomeNotNull().Map(s => new Sign(s)), + Sign = sign.SomeNotNull().Map(s => new Sign(s)), Character = character, NPC = npc }; } - private static bool CharacterAtCoordinates(ICharacter character, int x, int y) + private static bool CharacterAtCoordinates(Character.Character character, int x, int y) { return character.RenderProperties.IsActing(CharacterActionState.Walking) ? character.RenderProperties.GetDestinationX() == x && character.RenderProperties.GetDestinationY() == y : character.RenderProperties.MapX == x && character.RenderProperties.MapY == y; } - private static bool NPCAtCoordinates(INPC npc, int x, int y) + private static bool NPCAtCoordinates(NPC.NPC npc, int x, int y) { return npc.IsActing(NPCActionState.Walking) ? npc.GetDestinationX() == x && npc.GetDestinationY() == y diff --git a/EOLib/Domain/Map/MapItem.cs b/EOLib/Domain/Map/MapItem.cs new file mode 100644 index 000000000..6c4a7156a --- /dev/null +++ b/EOLib/Domain/Map/MapItem.cs @@ -0,0 +1,39 @@ +using Amadevus.RecordGenerator; +using Optional; +using System; + +namespace EOLib.Domain.Map +{ + [Record] + public sealed partial class MapItem + { + public short UniqueID { get; } + + public short ItemID { get; } + + public byte X { get; } + + public byte Y { get; } + + public int Amount { get; } + + public bool IsNPCDrop { get; } + + public Option OwningPlayerID { get; } + + public Option DropTime { get; } + + public static MapItem None => new MapItem(); + + public MapItem(short uid, short id, byte x, byte y, int amount) + { + UniqueID = uid; + ItemID = id; + X = x; + Y = y; + Amount = amount; + } + + private MapItem() { } + } +} \ No newline at end of file diff --git a/EOLib/Domain/Map/RefreshReplyPacketData.cs b/EOLib/Domain/Map/RefreshReplyPacketData.cs index b50c2a606..2c3d72280 100644 --- a/EOLib/Domain/Map/RefreshReplyPacketData.cs +++ b/EOLib/Domain/Map/RefreshReplyPacketData.cs @@ -1,69 +1,23 @@ -using System.Collections.Generic; -using EOLib.Domain.Character; -using EOLib.Domain.NPC; +using Amadevus.RecordGenerator; using EOLib.Net.Translators; +using System.Collections.Generic; namespace EOLib.Domain.Map { - public class RefreshReplyData : IRefreshReplyData + [Record] + public sealed partial class RefreshReplyData : ITranslatedData { - public IReadOnlyList Characters { get; private set; } + public IReadOnlyList Characters { get; } - public IReadOnlyList NPCs { get; private set; } + public IReadOnlyList NPCs { get; } - public IReadOnlyList Items { get; private set; } + public IReadOnlyList Items { get; } public RefreshReplyData() { - Characters = new List(); - NPCs = new List(); - Items = new List(); + Characters = new List(); + NPCs = new List(); + Items = new List(); } - - public IRefreshReplyData WithCharacters(IEnumerable characters) - { - var newData = MakeCopy(this); - newData.Characters = new List(characters); - return newData; - } - - public IRefreshReplyData WithNPCs(IEnumerable npcs) - { - var newData = MakeCopy(this); - newData.NPCs = new List(npcs); - return newData; - } - - public IRefreshReplyData WithItems(IEnumerable items) - { - var newData = MakeCopy(this); - newData.Items = new List(items); - return newData; - } - - private static RefreshReplyData MakeCopy(IRefreshReplyData source) - { - return new RefreshReplyData - { - Characters = new List(source.Characters), - NPCs = new List(source.NPCs), - Items = new List(source.Items) - }; - } - } - - public interface IRefreshReplyData : ITranslatedData - { - IReadOnlyList Characters { get; } - - IReadOnlyList NPCs { get; } - - IReadOnlyList Items { get; } - - IRefreshReplyData WithCharacters(IEnumerable characters); - - IRefreshReplyData WithNPCs(IEnumerable npcs); - - IRefreshReplyData WithItems(IEnumerable items); } } diff --git a/EOLib/Domain/Map/Sign.cs b/EOLib/Domain/Map/Sign.cs index e2d9831f5..407dc9a6c 100644 --- a/EOLib/Domain/Map/Sign.cs +++ b/EOLib/Domain/Map/Sign.cs @@ -3,13 +3,13 @@ namespace EOLib.Domain.Map { - public class Sign : ISign + public class Sign { public string Title { get; private set; } public string Message { get; private set; } - public static ISign None => new Sign(); + public static Sign None => new Sign(); private Sign() { @@ -28,11 +28,4 @@ private static string Filter(string input) return new string(input.Where(x => !char.IsControl(x)).ToArray()); } } - - public interface ISign - { - string Title { get; } - - string Message { get; } - } } diff --git a/EOLib/Domain/Map/UnlockDoorValidator.cs b/EOLib/Domain/Map/UnlockDoorValidator.cs index a23950bdb..caf48117f 100644 --- a/EOLib/Domain/Map/UnlockDoorValidator.cs +++ b/EOLib/Domain/Map/UnlockDoorValidator.cs @@ -21,7 +21,7 @@ public UnlockDoorValidator(ICharacterInventoryProvider characterInventoryProvide _eifFileProvider = eifFileProvider; } - public bool CanMainCharacterOpenDoor(IWarp warp) + public bool CanMainCharacterOpenDoor(Warp warp) { return GetRequiredKey(warp).Match( some: keyName => _characterInventoryProvider @@ -32,7 +32,7 @@ public bool CanMainCharacterOpenDoor(IWarp warp) none: () => true); } - public Option GetRequiredKey(IWarp warp) + public Option GetRequiredKey(Warp warp) { switch (warp.DoorType) { @@ -46,8 +46,8 @@ public Option GetRequiredKey(IWarp warp) public interface IUnlockDoorValidator { - bool CanMainCharacterOpenDoor(IWarp warp); + bool CanMainCharacterOpenDoor(Warp warp); - Option GetRequiredKey(IWarp warp); + Option GetRequiredKey(Warp warp); } } diff --git a/EOLib/Domain/Map/Warp.cs b/EOLib/Domain/Map/Warp.cs index 191951b42..c322943f9 100644 --- a/EOLib/Domain/Map/Warp.cs +++ b/EOLib/Domain/Map/Warp.cs @@ -1,9 +1,10 @@ -using EOLib.IO.Map; -using System.Collections.Generic; +using Amadevus.RecordGenerator; +using EOLib.IO.Map; namespace EOLib.Domain.Map { - public class Warp : IWarp + [Record(Features.ObjectEquals)] + public sealed partial class Warp { private readonly WarpMapEntity _warpEntity; @@ -19,35 +20,5 @@ public Warp(WarpMapEntity warpEntity) { _warpEntity = warpEntity; } - - public override bool Equals(object obj) - { - return obj is Warp warp && - X == warp.X && - Y == warp.Y && - DoorType == warp.DoorType && - LevelRequirement == warp.LevelRequirement; - } - - public override int GetHashCode() - { - int hashCode = 514290371; - hashCode = hashCode * -1521134295 + X.GetHashCode(); - hashCode = hashCode * -1521134295 + Y.GetHashCode(); - hashCode = hashCode * -1521134295 + DoorType.GetHashCode(); - hashCode = hashCode * -1521134295 + LevelRequirement.GetHashCode(); - return hashCode; - } - } - - public interface IWarp - { - int X { get; } - - int Y { get; } - - DoorSpec DoorType { get; } - - int LevelRequirement { get; } } } diff --git a/EOLib/Domain/Map/WarpAgreePacketData.cs b/EOLib/Domain/Map/WarpAgreePacketData.cs index 9ef2d5003..631832af2 100644 --- a/EOLib/Domain/Map/WarpAgreePacketData.cs +++ b/EOLib/Domain/Map/WarpAgreePacketData.cs @@ -1,97 +1,27 @@ -using System.Collections.Generic; -using EOLib.Domain.Character; -using EOLib.Domain.NPC; +using Amadevus.RecordGenerator; using EOLib.Net.Translators; +using System.Collections.Generic; namespace EOLib.Domain.Map { - public class WarpAgreePacketData : IWarpAgreePacketData + [Record] + public sealed partial class WarpAgreePacketData : ITranslatedData { - public short MapID { get; private set; } + public short MapID { get; } - public WarpAnimation WarpAnimation { get; private set; } + public WarpAnimation WarpAnimation { get; } - public IReadOnlyList Characters { get; private set; } + public IReadOnlyList Characters { get; } - public IReadOnlyList NPCs { get; private set; } + public IReadOnlyList NPCs { get; } - public IReadOnlyList Items { get; private set; } + public IReadOnlyList Items { get; } public WarpAgreePacketData() { - Characters = new List(); - NPCs = new List(); - Items = new List(); + Characters = new List(); + NPCs = new List(); + Items = new List(); } - - public IWarpAgreePacketData WithMapID(short mapID) - { - var newData = MakeCopy(this); - newData.MapID = mapID; - return newData; - } - - public IWarpAgreePacketData WithWarpAnimation(WarpAnimation warpAnimation) - { - var newData = MakeCopy(this); - newData.WarpAnimation = warpAnimation; - return newData; - } - - public IWarpAgreePacketData WithCharacters(IEnumerable characters) - { - var newData = MakeCopy(this); - newData.Characters = new List(characters); - return newData; - } - - public IWarpAgreePacketData WithNPCs(IEnumerable npcs) - { - var newData = MakeCopy(this); - newData.NPCs = new List(npcs); - return newData; - } - - public IWarpAgreePacketData WithItems(IEnumerable items) - { - var newData = MakeCopy(this); - newData.Items = new List(items); - return newData; - } - - private static WarpAgreePacketData MakeCopy(IWarpAgreePacketData source) - { - return new WarpAgreePacketData - { - MapID = source.MapID, - WarpAnimation = source.WarpAnimation, - Characters = new List(source.Characters), - NPCs = new List(source.NPCs), - Items = new List(source.Items) - }; - } - } - - public interface IWarpAgreePacketData : ITranslatedData - { - short MapID { get; } - - WarpAnimation WarpAnimation { get; } - - IReadOnlyList Characters { get; } - - IReadOnlyList NPCs { get; } - - IReadOnlyList Items { get; } - - IWarpAgreePacketData WithMapID(short mapID); - - IWarpAgreePacketData WithWarpAnimation(WarpAnimation warpAnimation); - - IWarpAgreePacketData WithCharacters(IEnumerable characters); - - IWarpAgreePacketData WithNPCs(IEnumerable npcs); - - IWarpAgreePacketData WithItems(IEnumerable items); } } diff --git a/EOLib/Domain/NPC/INPC.cs b/EOLib/Domain/NPC/INPC.cs deleted file mode 100644 index f5086802d..000000000 --- a/EOLib/Domain/NPC/INPC.cs +++ /dev/null @@ -1,28 +0,0 @@ -using EOLib.Domain.Spells; -using Optional; - -namespace EOLib.Domain.NPC -{ - public interface INPC : ISpellTargetable - { - byte X { get; } - - byte Y { get; } - - EODirection Direction { get; } - - NPCFrame Frame { get; } - - Option OpponentID { get; } - - INPC WithX(byte x); - - INPC WithY(byte y); - - INPC WithDirection(EODirection direction); - - INPC WithFrame(NPCFrame frame); - - INPC WithOpponentID(short opponentID); - } -} \ No newline at end of file diff --git a/EOLib/Domain/NPC/NPC.cs b/EOLib/Domain/NPC/NPC.cs index 0db602411..b9e45cf8a 100644 --- a/EOLib/Domain/NPC/NPC.cs +++ b/EOLib/Domain/NPC/NPC.cs @@ -1,100 +1,24 @@ -using System.Collections.Generic; +using Amadevus.RecordGenerator; +using EOLib.Domain.Spells; using Optional; namespace EOLib.Domain.NPC { - public class NPC : INPC + [Record] + public sealed partial class NPC : ISpellTargetable { public int ID { get; } public int Index { get; } - public byte X { get; private set; } + public byte X { get; } - public byte Y { get; private set; } + public byte Y { get; } - public EODirection Direction { get; private set; } + public EODirection Direction { get; } - public NPCFrame Frame { get; private set; } + public NPCFrame Frame { get; } - public Option OpponentID { get; private set; } - - public NPC(int id, int index) - { - ID = id; - Index = index; - } - - public INPC WithX(byte x) - { - var copy = MakeCopy(this); - copy.X = x; - return copy; - } - - public INPC WithY(byte y) - { - var copy = MakeCopy(this); - copy.Y = y; - return copy; - } - - public INPC WithDirection(EODirection direction) - { - var copy = MakeCopy(this); - copy.Direction = direction; - return copy; - } - - public INPC WithFrame(NPCFrame frame) - { - var copy = MakeCopy(this); - copy.Frame = frame; - return copy; - } - - public INPC WithOpponentID(short opponentID) - { - var copy = MakeCopy(this); - copy.OpponentID = Option.Some(opponentID); - return copy; - } - - private static NPC MakeCopy(INPC input) - { - return new NPC(input.ID, input.Index) - { - X = input.X, - Y = input.Y, - Direction = input.Direction, - Frame = input.Frame, - OpponentID = input.OpponentID - }; - } - - public override bool Equals(object obj) - { - return obj is NPC npc && - ID == npc.ID && - Index == npc.Index && - X == npc.X && - Y == npc.Y && - Direction == npc.Direction && - Frame == npc.Frame && - OpponentID.Equals(npc.OpponentID); - } - - public override int GetHashCode() - { - int hashCode = 137608487; - hashCode = hashCode * -1521134295 + ID.GetHashCode(); - hashCode = hashCode * -1521134295 + Index.GetHashCode(); - hashCode = hashCode * -1521134295 + X.GetHashCode(); - hashCode = hashCode * -1521134295 + Y.GetHashCode(); - hashCode = hashCode * -1521134295 + Direction.GetHashCode(); - hashCode = hashCode * -1521134295 + Frame.GetHashCode(); - hashCode = hashCode * -1521134295 + OpponentID.GetHashCode(); - return hashCode; - } + public Option OpponentID { get; } } } \ No newline at end of file diff --git a/EOLib/Domain/Online/OnlineListData.cs b/EOLib/Domain/Online/OnlineListData.cs index 0bca0ab33..94696e040 100644 --- a/EOLib/Domain/Online/OnlineListData.cs +++ b/EOLib/Domain/Online/OnlineListData.cs @@ -1,20 +1,12 @@ -using EOLib.Net.Translators; +using Amadevus.RecordGenerator; +using EOLib.Net.Translators; using System.Collections.Generic; namespace EOLib.Domain.Online { - public class OnlineListData : IOnlineListData + [Record(Features.ObjectEquals | Features.Constructor)] + public sealed partial class OnlineListData : ITranslatedData { public IReadOnlyList OnlineList { get; } - - public OnlineListData(IReadOnlyList onlineList) - { - OnlineList = onlineList; - } - } - - public interface IOnlineListData : ITranslatedData - { - IReadOnlyList OnlineList { get; } } } diff --git a/EOLib/Domain/Online/OnlinePlayerActions.cs b/EOLib/Domain/Online/OnlinePlayerActions.cs index 5603fd88a..2afe767dd 100644 --- a/EOLib/Domain/Online/OnlinePlayerActions.cs +++ b/EOLib/Domain/Online/OnlinePlayerActions.cs @@ -11,10 +11,10 @@ namespace EOLib.Domain.Online public class OnlinePlayerActions : IOnlinePlayerActions { private readonly IPacketSendService _packetSendService; - private readonly IPacketTranslator _onlineListPacketTranslator; + private readonly IPacketTranslator _onlineListPacketTranslator; public OnlinePlayerActions(IPacketSendService packetSendService, - IPacketTranslator onlineListPacketTranslator) + IPacketTranslator onlineListPacketTranslator) { _packetSendService = packetSendService; _onlineListPacketTranslator = onlineListPacketTranslator; diff --git a/EOLib/Domain/Online/OnlinePlayerInfo.cs b/EOLib/Domain/Online/OnlinePlayerInfo.cs index faee5bbff..da51743a3 100644 --- a/EOLib/Domain/Online/OnlinePlayerInfo.cs +++ b/EOLib/Domain/Online/OnlinePlayerInfo.cs @@ -1,6 +1,9 @@ -namespace EOLib.Domain.Online +using Amadevus.RecordGenerator; + +namespace EOLib.Domain.Online { - public class OnlinePlayerInfo + [Record] + public sealed partial class OnlinePlayerInfo { public string Name { get; } @@ -16,14 +19,5 @@ public OnlinePlayerInfo(string name) : this(name, string.Empty, string.Empty, string.Empty, OnlineIcon.Normal) { } - - public OnlinePlayerInfo(string name, string title, string guild, string @class, OnlineIcon icon) - { - Name = name; - Title = title; - Guild = guild; - Class = @class; - Icon = icon; - } } } diff --git a/EOLib/Domain/Spells/SpellCastValidationActions.cs b/EOLib/Domain/Spells/SpellCastValidationActions.cs index 8e62212a6..b95ecf8d3 100644 --- a/EOLib/Domain/Spells/SpellCastValidationActions.cs +++ b/EOLib/Domain/Spells/SpellCastValidationActions.cs @@ -46,7 +46,7 @@ public SpellCastValidationResult ValidateSpellCast(int spellId, ISpellTargetable var spellData = _pubFileProvider.ESFFile[spellId]; - if (spellTarget is INPC) + if (spellTarget is NPC.NPC) { if (spellData.TargetRestrict == SpellTargetRestrict.Friendly || spellData.Target != SpellTarget.Normal || @@ -58,7 +58,7 @@ public SpellCastValidationResult ValidateSpellCast(int spellId, ISpellTargetable if (npcData.Type != NPCType.Passive && npcData.Type != NPCType.Aggressive) return SpellCastValidationResult.CannotAttackNPC; } - else if (spellTarget is ICharacter) + else if (spellTarget is Character.Character) { if (spellData.TargetRestrict == SpellTargetRestrict.NPCOnly || spellData.Target != SpellTarget.Normal || diff --git a/EOLib/Net/Translators/AccountLoginPacketTranslator.cs b/EOLib/Net/Translators/AccountLoginPacketTranslator.cs index 74aa073f0..92e3b61d0 100644 --- a/EOLib/Net/Translators/AccountLoginPacketTranslator.cs +++ b/EOLib/Net/Translators/AccountLoginPacketTranslator.cs @@ -16,7 +16,7 @@ public AccountLoginPacketTranslator(IEIFFileProvider eifFileProvider) public override IAccountLoginData TranslatePacket(IPacket packet) { LoginReply reply; - var characters = new List(); + var characters = new List(); if (packet.Family == PacketFamily.Login && packet.Action == PacketAction.Reply) { diff --git a/EOLib/Net/Translators/CharacterDisplayPacketTranslator.cs b/EOLib/Net/Translators/CharacterDisplayPacketTranslator.cs index e82d79afc..c318e77aa 100644 --- a/EOLib/Net/Translators/CharacterDisplayPacketTranslator.cs +++ b/EOLib/Net/Translators/CharacterDisplayPacketTranslator.cs @@ -18,9 +18,9 @@ protected CharacterDisplayPacketTranslator(IEIFFileProvider eifFileProvider) public abstract T TranslatePacket(IPacket packet); - protected IEnumerable GetCharacters(IPacket packet) + protected IEnumerable GetCharacters(IPacket packet) { - var characters = new List(); + var characters = new List(); var numberOfCharacters = (int)packet.ReadChar(); @@ -38,35 +38,46 @@ protected IEnumerable GetCharacters(IPacket packet) return characters; } - private ICharacter GetNextCharacter(IPacket packet) + private Character GetNextCharacter(IPacket packet) { - ICharacter character = new Character() - .WithName(packet.ReadBreakString()) - .WithID(packet.ReadInt()); - - var stats = new CharacterStats() - .WithNewStat(CharacterStat.Level, packet.ReadChar()); - - var renderProperties = new CharacterRenderProperties() - .WithGender(packet.ReadChar()) - .WithHairStyle(packet.ReadChar()) - .WithHairColor(packet.ReadChar()) - .WithRace(packet.ReadChar()); - - character = character.WithAdminLevel((AdminLevel)packet.ReadChar()); - - renderProperties = renderProperties - .WithBootsGraphic(packet.ReadShort()) - .WithArmorGraphic(packet.ReadShort()) - .WithHatGraphic(packet.ReadShort()) - .WithShieldGraphic(packet.ReadShort()); - - var weaponGraphic = packet.ReadShort(); - renderProperties = renderProperties.WithWeaponGraphic(weaponGraphic, _eifFileProvider.EIFFile.IsRangedWeapon(weaponGraphic)); - - return character - .WithRenderProperties(renderProperties) - .WithStats(stats); + var character = new Character.Builder + { + Name = packet.ReadBreakString(), + ID = packet.ReadInt() + }; + + var stats = new CharacterStats().WithNewStat(CharacterStat.Level, packet.ReadChar()); + + var gender = packet.ReadChar(); + var hairStyle = packet.ReadChar(); + var hairColor = packet.ReadChar(); + var race = packet.ReadChar(); + var adminLevel = (AdminLevel)packet.ReadChar(); + var boots = packet.ReadShort(); + var armor = packet.ReadShort(); + var hat = packet.ReadShort(); + var shield = packet.ReadShort(); + var weapon = packet.ReadShort(); + + var renderProperties = new CharacterRenderProperties.Builder + { + Gender = gender, + HairStyle = hairStyle, + HairColor = hairColor, + Race = race, + BootsGraphic = boots, + ArmorGraphic = armor, + HatGraphic = hat, + ShieldGraphic = shield, + WeaponGraphic = weapon, + IsRangedWeapon = _eifFileProvider.EIFFile.IsRangedWeapon(weapon), + }; + + character.Stats = stats; + character.AdminLevel = adminLevel; + character.RenderProperties = renderProperties.ToImmutable(); + + return character.ToImmutable(); } } diff --git a/EOLib/Net/Translators/CharacterFromPacketFactory.cs b/EOLib/Net/Translators/CharacterFromPacketFactory.cs index bf9cd2877..b3fba825d 100644 --- a/EOLib/Net/Translators/CharacterFromPacketFactory.cs +++ b/EOLib/Net/Translators/CharacterFromPacketFactory.cs @@ -16,7 +16,7 @@ public CharacterFromPacketFactory(IEIFFileProvider eifFileProvider) _eifFileProvider = eifFileProvider; } - public ICharacter CreateCharacter(IPacket packet) + public Character CreateCharacter(IPacket packet) { var name = packet.ReadBreakString(); name = char.ToUpper(name[0]) + name.Substring(1); @@ -59,35 +59,41 @@ public ICharacter CreateCharacter(IPacket packet) .WithNewStat(CharacterStat.TP, tp) .WithNewStat(CharacterStat.MaxTP, maxTP); - var renderProps = new CharacterRenderProperties() - .WithDirection(direction) - .WithGender(gender) - .WithHairStyle(hairStyle) - .WithHairColor(hairColor) - .WithRace(race) - .WithBootsGraphic(boots) - .WithArmorGraphic(armor) - .WithHatGraphic(hat) - .WithShieldGraphic(shield) - .WithWeaponGraphic(weapon, _eifFileProvider.EIFFile.IsRangedWeapon(weapon)) - .WithSitState(sitState) - .WithIsHidden(hidden) - .WithMapX(xLoc) - .WithMapY(yLoc); + var renderProps = new CharacterRenderProperties.Builder + { + Direction = direction, + Gender = gender, + HairStyle = hairStyle, + HairColor = hairColor, + Race = race, + BootsGraphic = boots, + ArmorGraphic = armor, + HatGraphic = hat, + ShieldGraphic = shield, + WeaponGraphic = weapon, + IsRangedWeapon = _eifFileProvider.EIFFile.IsRangedWeapon(weapon), + SitState = sitState, + CurrentAction = sitState == SitState.Standing ? CharacterActionState.Standing : CharacterActionState.Sitting, + IsHidden = hidden, + MapX = xLoc, + MapY = yLoc, + }; - return new Character() - .WithName(name) - .WithID(id) - .WithClassID(classID) - .WithMapID(mapID) - .WithGuildTag(guildTag) - .WithStats(stats) - .WithRenderProperties(renderProps); + return new Character.Builder + { + Name = name, + ID = id, + ClassID = classID, + MapID = mapID, + GuildTag = guildTag, + Stats = stats, + RenderProperties = renderProps.ToImmutable(), + }.ToImmutable(); } } public interface ICharacterFromPacketFactory { - ICharacter CreateCharacter(IPacket packet); + Character CreateCharacter(IPacket packet); } } diff --git a/EOLib/Net/Translators/CharacterReplyPacketTranslator.cs b/EOLib/Net/Translators/CharacterReplyPacketTranslator.cs index 767bf0b6d..b545fb49a 100644 --- a/EOLib/Net/Translators/CharacterReplyPacketTranslator.cs +++ b/EOLib/Net/Translators/CharacterReplyPacketTranslator.cs @@ -15,7 +15,7 @@ public override ICharacterCreateData TranslatePacket(IPacket packet) { var reply = (CharacterReply) packet.ReadShort(); - var characters = new List(); + var characters = new List(); if (reply == CharacterReply.Ok || reply == CharacterReply.Deleted) characters.AddRange(GetCharacters(packet)); diff --git a/EOLib/Net/Translators/LoginRequestCompletedPacketTranslator.cs b/EOLib/Net/Translators/LoginRequestCompletedPacketTranslator.cs index f5907de6f..16e185dde 100644 --- a/EOLib/Net/Translators/LoginRequestCompletedPacketTranslator.cs +++ b/EOLib/Net/Translators/LoginRequestCompletedPacketTranslator.cs @@ -7,14 +7,14 @@ namespace EOLib.Net.Translators { [AutoMappedType] - public class LoginRequestCompletedPacketTranslator : MapStatePacketTranslator + public class LoginRequestCompletedPacketTranslator : MapStatePacketTranslator { private const int MAX_NEWS_LINES = 9; public LoginRequestCompletedPacketTranslator(ICharacterFromPacketFactory characterFromPacketFactory) : base(characterFromPacketFactory) { } - public override ILoginRequestCompletedData TranslatePacket(IPacket packet) + public override LoginRequestCompletedData TranslatePacket(IPacket packet) { var reply = (CharacterLoginReply)packet.ReadShort(); @@ -23,7 +23,7 @@ public override ILoginRequestCompletedData TranslatePacket(IPacket packet) if (packet.ReadEndString() != "NO") throw new MalformedPacketException("Expected NO bytes in CharacterLoginReply login", packet); - return new LoginRequestCompletedData().WithError(reply); + return new LoginRequestCompletedData.Builder { Error = reply }.ToImmutable(); } else if (reply != CharacterLoginReply.RequestCompleted) { @@ -51,15 +51,17 @@ public override ILoginRequestCompletedData TranslatePacket(IPacket packet) var npcs = GetNPCs(packet).ToList(); var items = GetMapItems(packet).ToList(); - return new LoginRequestCompletedData() - .WithNews(news) - .WithWeight(weight) - .WithMaxWeight(maxWeight) - .WithInventory(inventoryItems) - .WithSpells(inventorySpells) - .WithCharacters(characters) - .WithNPCs(npcs) - .WithItems(items); + return new LoginRequestCompletedData.Builder + { + News = news, + CharacterWeight = weight, + CharacterMaxWeight = maxWeight, + CharacterItemInventory = inventoryItems, + CharacterSpellInventory = inventorySpells, + MapCharacters = characters, + MapNPCs = npcs, + MapItems = items, + }.ToImmutable(); } private IEnumerable GetNews(IPacket packet) @@ -68,7 +70,7 @@ private IEnumerable GetNews(IPacket packet) yield return packet.ReadBreakString(); } - private IEnumerable GetInventoryItems(IPacket packet) + private IEnumerable GetInventoryItems(IPacket packet) { while (packet.PeekByte() != 255) yield return new InventoryItem(packet.ReadShort(), packet.ReadInt()); @@ -76,7 +78,7 @@ private IEnumerable GetInventoryItems(IPacket packet) packet.ReadByte(); } - private IEnumerable GetInventorySpells(IPacket packet) + private IEnumerable GetInventorySpells(IPacket packet) { while (packet.PeekByte() != 255) yield return new InventorySpell(packet.ReadShort(), packet.ReadShort()); diff --git a/EOLib/Net/Translators/LoginRequestGrantedPacketTranslator.cs b/EOLib/Net/Translators/LoginRequestGrantedPacketTranslator.cs index 979ec6937..534efd78f 100644 --- a/EOLib/Net/Translators/LoginRequestGrantedPacketTranslator.cs +++ b/EOLib/Net/Translators/LoginRequestGrantedPacketTranslator.cs @@ -9,9 +9,9 @@ namespace EOLib.Net.Translators { [AutoMappedType] - public class LoginRequestGrantedPacketTranslator : IPacketTranslator + public class LoginRequestGrantedPacketTranslator : IPacketTranslator { - public ILoginRequestGrantedData TranslatePacket(IPacket packet) + public LoginRequestGrantedData TranslatePacket(IPacket packet) { var reply = (CharacterLoginReply)packet.ReadShort(); if (reply != CharacterLoginReply.RequestGranted) @@ -111,32 +111,34 @@ public ILoginRequestGrantedData TranslatePacket(IPacket packet) if (packet.ReadByte() != 255) throw new MalformedPacketException("Missing terminating 255 byte", packet); - return new LoginRequestGrantedData() - .WithSessionID(sessionID) - .WithCharacterID(characterID) - .WithMapID(mapID) - .WithMapRID(mapRid) - .WithMapLen(mapLen) - .WithEifRID(eifRid) - .WithEifLen(eifLen) - .WithEnfRID(enfRid) - .WithEnfLen(enfLen) - .WithEsfRID(esfRid) - .WithEsfLen(esfLen) - .WithEcfRID(ecfRid) - .WithEcfLen(ecfLen) - .WithName(characterName) - .WithTitle(characterTitle) - .WithGuildName(guildName) - .WithGuildRank(guildRank) - .WithClassId(classID) - .WithGuildTag(paddedGuildTag) - .WithAdminLevel(adminLevel) - .WithCharacterStats(characterStats) - .WithPaperdoll(paperDoll) - .WithGuildRankNum(guildRankNum) - .WithJailMap(jailMap) - .WithFirstTimePlayer(firstTimePlayer); + return new LoginRequestGrantedData.Builder + { + SessionID = sessionID, + CharacterID = characterID, + MapID = mapID, + MapRID = mapRid, + MapLen = mapLen, + EifRid = eifRid, + EifLen = eifLen, + EnfRid = enfRid, + EnfLen = enfLen, + EsfRid = esfRid, + EsfLen = esfLen, + EcfRid = ecfRid, + EcfLen = ecfLen, + Name = characterName, + Title = characterTitle, + GuildName = guildName, + GuildRank = guildRank, + ClassID = classID, + GuildTag = paddedGuildTag, + AdminLevel = adminLevel, + CharacterStats = characterStats, + Paperdoll = paperDoll, + GuildRankNum = guildRankNum, + JailMap = jailMap, + FirstTimePlayer = firstTimePlayer, + }.ToImmutable(); } } } diff --git a/EOLib/Net/Translators/MapStatePacketTranslator.cs b/EOLib/Net/Translators/MapStatePacketTranslator.cs index bbb2349f4..a746553cf 100644 --- a/EOLib/Net/Translators/MapStatePacketTranslator.cs +++ b/EOLib/Net/Translators/MapStatePacketTranslator.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using EOLib.Domain.Character; using EOLib.Domain.Map; using EOLib.Domain.NPC; +using Optional; namespace EOLib.Net.Translators { @@ -17,7 +19,7 @@ protected MapStatePacketTranslator(ICharacterFromPacketFactory characterFromPack public abstract T TranslatePacket(IPacket packet); - protected IEnumerable GetCharacters(IPacket packet) + protected IEnumerable GetCharacters(IPacket packet) { var numCharacters = packet.ReadChar(); @@ -34,7 +36,7 @@ protected IEnumerable GetCharacters(IPacket packet) throw new MalformedPacketException("Missing final 255 byte after characters loop", packet); } - protected IEnumerable GetNPCs(IPacket packet) + protected IEnumerable GetNPCs(IPacket packet) { while (packet.PeekByte() != 255) { @@ -44,16 +46,20 @@ protected IEnumerable GetNPCs(IPacket packet) var y = packet.ReadChar(); var direction = (EODirection) packet.ReadChar(); - yield return new NPC(id, index) - .WithX(x) - .WithY(y) - .WithDirection(direction); + yield return new NPC.Builder() + { + ID = id, + Index = index, + X = x, + Y = y, + Direction = direction, + }.ToImmutable(); } packet.ReadByte(); //consume the tail 255 byte that broke loop iteration } - protected IEnumerable GetMapItems(IPacket packet) + protected IEnumerable GetMapItems(IPacket packet) { while (packet.ReadPosition < packet.Length) { @@ -63,7 +69,7 @@ protected IEnumerable GetMapItems(IPacket packet) var y = packet.ReadChar(); var amount = packet.ReadThree(); - yield return new Item(uid, itemID, x, y).WithAmount(amount); + yield return new MapItem(uid, itemID, x, y, amount); } } } diff --git a/EOLib/Net/Translators/NPCFromPacketFactory.cs b/EOLib/Net/Translators/NPCFromPacketFactory.cs index 51afe8bfd..afc431701 100644 --- a/EOLib/Net/Translators/NPCFromPacketFactory.cs +++ b/EOLib/Net/Translators/NPCFromPacketFactory.cs @@ -6,7 +6,7 @@ namespace EOLib.Net.Translators [AutoMappedType] public class NPCFromPacketFactory : INPCFromPacketFactory { - public INPC CreateNPC(IPacket packet) + public NPC CreateNPC(IPacket packet) { var index = packet.ReadChar(); var id = packet.ReadShort(); @@ -14,14 +14,21 @@ public INPC CreateNPC(IPacket packet) var y = packet.ReadChar(); var direction = (EODirection)packet.ReadChar(); - INPC npc = new NPC(id, index); - npc = npc.WithX(x).WithY(y).WithDirection(direction).WithFrame(NPCFrame.Standing); - return npc; + var npc = new NPC.Builder() + { + ID = id, + Index = index, + X = x, + Y = y, + Direction = direction, + Frame = NPCFrame.Standing, + }; + return npc.ToImmutable(); } } public interface INPCFromPacketFactory { - INPC CreateNPC(IPacket packet); + NPC CreateNPC(IPacket packet); } } diff --git a/EOLib/Net/Translators/OnlineListPacketTranslator.cs b/EOLib/Net/Translators/OnlineListPacketTranslator.cs index d42043077..c10412190 100644 --- a/EOLib/Net/Translators/OnlineListPacketTranslator.cs +++ b/EOLib/Net/Translators/OnlineListPacketTranslator.cs @@ -7,7 +7,7 @@ namespace EOLib.Net.Translators { [AutoMappedType] - public class OnlineListPacketTranslator : IPacketTranslator + public class OnlineListPacketTranslator : IPacketTranslator { private readonly IECFFileProvider _classFileProvider; @@ -16,7 +16,7 @@ public OnlineListPacketTranslator(IECFFileProvider classFileProvider) _classFileProvider = classFileProvider; } - public IOnlineListData TranslatePacket(IPacket packet) + public OnlineListData TranslatePacket(IPacket packet) { var reply = (InitReply)packet.ReadByte(); diff --git a/EOLib/Net/Translators/RefreshReplyPacketTranslator.cs b/EOLib/Net/Translators/RefreshReplyPacketTranslator.cs index 990b63d89..65f659af4 100644 --- a/EOLib/Net/Translators/RefreshReplyPacketTranslator.cs +++ b/EOLib/Net/Translators/RefreshReplyPacketTranslator.cs @@ -1,25 +1,27 @@ using AutomaticTypeMapper; using EOLib.Domain.Map; +using System.Linq; namespace EOLib.Net.Translators { [AutoMappedType] - public class RefreshReplyPacketTranslator : MapStatePacketTranslator + public class RefreshReplyPacketTranslator : MapStatePacketTranslator { public RefreshReplyPacketTranslator(ICharacterFromPacketFactory characterFromPacketFactory) : base(characterFromPacketFactory) { } - public override IRefreshReplyData TranslatePacket(IPacket packet) + public override RefreshReplyData TranslatePacket(IPacket packet) { var characters = GetCharacters(packet); var npcs = GetNPCs(packet); var items = GetMapItems(packet); - IRefreshReplyData data = new RefreshReplyData(); - - return data.WithCharacters(characters) - .WithNPCs(npcs) - .WithItems(items); + return new RefreshReplyData.Builder + { + Characters = characters.ToList(), + NPCs = npcs.ToList(), + Items = items.ToList(), + }.ToImmutable(); } } } diff --git a/EOLib/Net/Translators/WarpAgreePacketTranslator.cs b/EOLib/Net/Translators/WarpAgreePacketTranslator.cs index d1f27e410..1285de6c9 100644 --- a/EOLib/Net/Translators/WarpAgreePacketTranslator.cs +++ b/EOLib/Net/Translators/WarpAgreePacketTranslator.cs @@ -1,18 +1,17 @@ using AutomaticTypeMapper; using EOLib.Domain.Map; +using System.Linq; namespace EOLib.Net.Translators { [AutoMappedType] - public class WarpAgreePacketTranslator : MapStatePacketTranslator + public class WarpAgreePacketTranslator : MapStatePacketTranslator { public WarpAgreePacketTranslator(ICharacterFromPacketFactory characterFromPacketFactory) : base(characterFromPacketFactory) { } - public override IWarpAgreePacketData TranslatePacket(IPacket packet) + public override WarpAgreePacketData TranslatePacket(IPacket packet) { - IWarpAgreePacketData retData = new WarpAgreePacketData(); - if (packet.ReadChar() != 2) throw new MalformedPacketException("Missing initial marker value of 2", packet); @@ -23,12 +22,14 @@ public override IWarpAgreePacketData TranslatePacket(IPacket packet) var npcs = GetNPCs(packet); var items = GetMapItems(packet); - return retData - .WithMapID(newMapID) - .WithWarpAnimation(warpAnim) - .WithCharacters(characters) - .WithNPCs(npcs) - .WithItems(items); + return new WarpAgreePacketData.Builder + { + MapID = newMapID, + WarpAnimation = warpAnim, + Characters = characters.ToList(), + NPCs = npcs.ToList(), + Items = items.ToList(), + }.ToImmutable(); } } } diff --git a/EOLib/PacketHandlers/AdminHideHandler.cs b/EOLib/PacketHandlers/AdminHideHandler.cs index 13b5a172e..ece8d1dda 100644 --- a/EOLib/PacketHandlers/AdminHideHandler.cs +++ b/EOLib/PacketHandlers/AdminHideHandler.cs @@ -49,7 +49,7 @@ public override bool HandlePacket(IPacket packet) return true; } - private static ICharacter Hidden(ICharacter input) + private static Character Hidden(Character input) { var renderProps = input.RenderProperties.WithIsHidden(true); return input.WithRenderProperties(renderProps); diff --git a/EOLib/PacketHandlers/AdminShowHandler.cs b/EOLib/PacketHandlers/AdminShowHandler.cs index 368aa4b76..c443901b3 100644 --- a/EOLib/PacketHandlers/AdminShowHandler.cs +++ b/EOLib/PacketHandlers/AdminShowHandler.cs @@ -49,7 +49,7 @@ public override bool HandlePacket(IPacket packet) return true; } - private static ICharacter Shown(ICharacter input) + private static Character Shown(Character input) { var renderProps = input.RenderProperties.WithIsHidden(false); return input.WithRenderProperties(renderProps); diff --git a/EOLib/PacketHandlers/Chat/GroupChatHandler.cs b/EOLib/PacketHandlers/Chat/GroupChatHandler.cs index 58becbebe..382014aea 100644 --- a/EOLib/PacketHandlers/Chat/GroupChatHandler.cs +++ b/EOLib/PacketHandlers/Chat/GroupChatHandler.cs @@ -27,7 +27,7 @@ public GroupChatHandler(ICurrentMapStateProvider currentMapStateProvider, _notifiers = notifiers; } - protected override void DoTalk(IPacket packet, ICharacter character) + protected override void DoTalk(IPacket packet, Character character) { var message = packet.ReadBreakString(); diff --git a/EOLib/PacketHandlers/Chat/PlayerChatByIDHandler.cs b/EOLib/PacketHandlers/Chat/PlayerChatByIDHandler.cs index beea77a10..960df6a5e 100644 --- a/EOLib/PacketHandlers/Chat/PlayerChatByIDHandler.cs +++ b/EOLib/PacketHandlers/Chat/PlayerChatByIDHandler.cs @@ -30,6 +30,6 @@ public override bool HandlePacket(IPacket packet) return true; } - protected abstract void DoTalk(IPacket packet, ICharacter character); + protected abstract void DoTalk(IPacket packet, Character character); } } diff --git a/EOLib/PacketHandlers/Chat/PublicChatHandler.cs b/EOLib/PacketHandlers/Chat/PublicChatHandler.cs index e90ff1b38..ef0928be0 100644 --- a/EOLib/PacketHandlers/Chat/PublicChatHandler.cs +++ b/EOLib/PacketHandlers/Chat/PublicChatHandler.cs @@ -27,7 +27,7 @@ public PublicChatHandler(ICurrentMapStateProvider currentMapStateProvider, _notifiers = notifiers; } - protected override void DoTalk(IPacket packet, ICharacter character) + protected override void DoTalk(IPacket packet, Character character) { var message = packet.ReadEndString(); diff --git a/EOLib/PacketHandlers/DoorOpenHandler.cs b/EOLib/PacketHandlers/DoorOpenHandler.cs index 8e60d5d57..daa5771c6 100644 --- a/EOLib/PacketHandlers/DoorOpenHandler.cs +++ b/EOLib/PacketHandlers/DoorOpenHandler.cs @@ -31,7 +31,7 @@ public override bool HandlePacket(IPacket packet) var x = packet.ReadChar(); var y = packet.ReadShort(); - IWarp warp; + Warp warp; try { warp = _currentMapStateRepository.PendingDoors.Single(w => w.X == x && w.Y == y); @@ -40,9 +40,6 @@ public override bool HandlePacket(IPacket packet) { // another player attempted to open a door warp = new Warp(_currentMapProvider.CurrentMap.Warps[y, x]); - - if (warp.X < 0 && warp.Y < 0) - return false; // bad packet? this should never be hit } _currentMapStateRepository.PendingDoors.Remove(warp); diff --git a/EOLib/PacketHandlers/Effects/MapDebuffHandler.cs b/EOLib/PacketHandlers/Effects/MapDebuffHandler.cs index 8d42c215a..1f9fec0f8 100644 --- a/EOLib/PacketHandlers/Effects/MapDebuffHandler.cs +++ b/EOLib/PacketHandlers/Effects/MapDebuffHandler.cs @@ -61,8 +61,7 @@ public override bool HandlePacket(IPacket packet) character = character.WithStats(originalStats.WithNewStat(CharacterStat.HP, hp) .WithNewStat(CharacterStat.MaxHP, maxHp)); - if (hp <= 0) - character = character.WithRenderProperties(character.RenderProperties.WithDead()); + character = character.WithRenderProperties(character.RenderProperties.WithIsDead(hp <= 0)); _characterRepository.MainCharacter = character; diff --git a/EOLib/PacketHandlers/EndPlayerWarpHandler.cs b/EOLib/PacketHandlers/EndPlayerWarpHandler.cs index f44be1e81..7c383ece9 100644 --- a/EOLib/PacketHandlers/EndPlayerWarpHandler.cs +++ b/EOLib/PacketHandlers/EndPlayerWarpHandler.cs @@ -18,7 +18,7 @@ namespace EOLib.PacketHandlers [AutoMappedType] public class EndPlayerWarpHandler : InGameOnlyPacketHandler { - private readonly IPacketTranslator _warpAgreePacketTranslator; + private readonly IPacketTranslator _warpAgreePacketTranslator; private readonly ICharacterRepository _characterRepository; private readonly ICurrentMapStateRepository _currentMapStateRepository; private readonly ICurrentMapProvider _currentMapProvider; @@ -30,7 +30,7 @@ public class EndPlayerWarpHandler : InGameOnlyPacketHandler public override PacketAction Action => PacketAction.Agree; public EndPlayerWarpHandler(IPlayerInfoProvider playerInfoProvider, - IPacketTranslator warpAgreePacketTranslator, + IPacketTranslator warpAgreePacketTranslator, ICharacterRepository characterRepository, ICurrentMapStateRepository currentMapStateRepository, ICurrentMapProvider currentMapProvider, @@ -56,20 +56,20 @@ public override bool HandlePacket(IPacket packet) //character.renderproperties.isdead is set True by the attack handler //the character needs to be brought back to life when they are taken to the home map - var bringBackToLife = _characterRepository.MainCharacter.RenderProperties.WithAlive(); + var bringBackToLife = _characterRepository.MainCharacter.RenderProperties.WithIsDead(false); _characterRepository.MainCharacter = _characterRepository.MainCharacter .WithRenderProperties(bringBackToLife) .WithAppliedData(updatedMainCharacter, _eifFileProvider.EIFFile.IsRangedWeapon(updatedMainCharacter.RenderProperties.WeaponGraphic)); var withoutMainCharacter = warpAgreePacketData.Characters.Where(x => !MainCharacterIDMatches(x)); - warpAgreePacketData = warpAgreePacketData.WithCharacters(withoutMainCharacter); + warpAgreePacketData = warpAgreePacketData.WithCharacters(withoutMainCharacter.ToList()); var differentMapID = _currentMapStateRepository.CurrentMapID != warpAgreePacketData.MapID; _currentMapStateRepository.CurrentMapID = warpAgreePacketData.MapID; _currentMapStateRepository.Characters = warpAgreePacketData.Characters.ToDictionary(k => k.ID, v => v); - _currentMapStateRepository.NPCs = new HashSet(warpAgreePacketData.NPCs); - _currentMapStateRepository.MapItems = new HashSet(warpAgreePacketData.Items); + _currentMapStateRepository.NPCs = new HashSet(warpAgreePacketData.NPCs); + _currentMapStateRepository.MapItems = new HashSet(warpAgreePacketData.Items); _currentMapStateRepository.OpenDoors.Clear(); _currentMapStateRepository.VisibleSpikeTraps.Clear(); _currentMapStateRepository.ShowMiniMap = _currentMapStateRepository.ShowMiniMap && @@ -84,7 +84,7 @@ public override bool HandlePacket(IPacket packet) return true; } - private bool MainCharacterIDMatches(ICharacter x) + private bool MainCharacterIDMatches(Character x) { return x.ID == _characterRepository.MainCharacter.ID; } diff --git a/EOLib/PacketHandlers/ItemEquipHandler.cs b/EOLib/PacketHandlers/ItemEquipHandler.cs index 876eeee43..0139a1052 100644 --- a/EOLib/PacketHandlers/ItemEquipHandler.cs +++ b/EOLib/PacketHandlers/ItemEquipHandler.cs @@ -70,7 +70,7 @@ protected bool HandlePaperdollPacket(IPacket packet, bool itemUnequipped) ? Option.Some(_characterRepository.MainCharacter) : _currentMapStateRepository.Characters.ContainsKey(playerId) ? Option.Some(_currentMapStateRepository.Characters[playerId]) - : Option.None(); + : Option.None(); update.MatchSome(c => { diff --git a/EOLib/PacketHandlers/Items/DropItemHandler.cs b/EOLib/PacketHandlers/Items/DropItemHandler.cs index 443544114..3407d21ff 100644 --- a/EOLib/PacketHandlers/Items/DropItemHandler.cs +++ b/EOLib/PacketHandlers/Items/DropItemHandler.cs @@ -5,6 +5,7 @@ using EOLib.Domain.Notifiers; using EOLib.Net; using EOLib.Net.Handlers; +using Optional; using System; using System.Collections.Generic; @@ -57,9 +58,8 @@ public override bool HandlePacket(IPacket packet) .WithNewStat(CharacterStat.MaxWeight, maxWeight); _characterRepository.MainCharacter = _characterRepository.MainCharacter.WithStats(stats); - var mapItem = new Item(uid, id, dropX, dropY) - .WithAmount(amountDropped) - .WithDropTime(DateTime.Now.AddSeconds(-5)); + var mapItem = new MapItem(uid, id, dropX, dropY, amountDropped) + .WithDropTime(Option.Some(DateTime.Now.AddSeconds(-5))); _currentMapStateRepository.MapItems.Add(mapItem); foreach (var notifier in _mainCharacterEventNotifiers) diff --git a/EOLib/PacketHandlers/Items/OtherPlayerDropItemHandler.cs b/EOLib/PacketHandlers/Items/OtherPlayerDropItemHandler.cs index c6fb25631..407290427 100644 --- a/EOLib/PacketHandlers/Items/OtherPlayerDropItemHandler.cs +++ b/EOLib/PacketHandlers/Items/OtherPlayerDropItemHandler.cs @@ -3,6 +3,7 @@ using EOLib.Domain.Map; using EOLib.Net; using EOLib.Net.Handlers; +using Optional; using System; namespace EOLib.PacketHandlers.Items @@ -32,9 +33,8 @@ public override bool HandlePacket(IPacket packet) var dropX = packet.ReadChar(); var dropY = packet.ReadChar(); - var mapItem = new Item(uid, id, dropX, dropY) - .WithAmount(amountDropped) - .WithDropTime(DateTime.Now); + var mapItem = new MapItem(uid, id, dropX, dropY, amountDropped) + .WithDropTime(Option.Some(DateTime.Now)); _currentMapStateRepository.MapItems.Add(mapItem); return true; diff --git a/EOLib/PacketHandlers/Items/UseItemHandler.cs b/EOLib/PacketHandlers/Items/UseItemHandler.cs index 737892148..c8a931a7f 100644 --- a/EOLib/PacketHandlers/Items/UseItemHandler.cs +++ b/EOLib/PacketHandlers/Items/UseItemHandler.cs @@ -133,7 +133,7 @@ public override bool HandlePacket(IPacket packet) else if (loc == EquipLocation.Hat) renderProps = renderProps.WithHatGraphic(0); else if (loc == EquipLocation.Weapon) - renderProps = renderProps.WithWeaponGraphic(0, false); + renderProps = renderProps.WithWeaponGraphic(0).WithIsRangedWeapon(false); else if (loc == EquipLocation.Shield) renderProps = renderProps.WithShieldGraphic(0); } diff --git a/EOLib/PacketHandlers/Jukebox/JukeboxMessageHandler.cs b/EOLib/PacketHandlers/Jukebox/JukeboxMessageHandler.cs index c12e8d921..66600914d 100644 --- a/EOLib/PacketHandlers/Jukebox/JukeboxMessageHandler.cs +++ b/EOLib/PacketHandlers/Jukebox/JukeboxMessageHandler.cs @@ -1,5 +1,4 @@ using AutomaticTypeMapper; -using EOLib.Domain.Character; using EOLib.Domain.Login; using EOLib.Domain.Map; using EOLib.Domain.Notifiers; @@ -12,9 +11,7 @@ namespace EOLib.PacketHandlers.Jukebox [AutoMappedType] public class JukeboxMessageHandler : InGameOnlyPacketHandler { - private readonly ICharacterRepository _characterRepository; private readonly ICurrentMapStateRepository _currentMapStateRepository; - private readonly IEnumerable _mainCharacterEventNotifiers; private readonly IEnumerable _otherCharacterAnimationNotifiers; public override PacketFamily Family => PacketFamily.JukeBox; diff --git a/EOLib/PacketHandlers/MainPlayerWalkHandler.cs b/EOLib/PacketHandlers/MainPlayerWalkHandler.cs index 8df46d5f4..b5ee1c712 100644 --- a/EOLib/PacketHandlers/MainPlayerWalkHandler.cs +++ b/EOLib/PacketHandlers/MainPlayerWalkHandler.cs @@ -53,7 +53,7 @@ public override bool HandlePacket(IPacket packet) var y = packet.ReadChar(); var amount = packet.ReadThree(); - var newItem = new Item(uid, itemID, x, y).WithAmount(amount); + var newItem = new MapItem(uid, itemID, x, y, amount); _currentMapStateRepository.MapItems.Add(newItem); } diff --git a/EOLib/PacketHandlers/NPCActionHandler.cs b/EOLib/PacketHandlers/NPCActionHandler.cs index ee139c2c7..1123ee245 100644 --- a/EOLib/PacketHandlers/NPCActionHandler.cs +++ b/EOLib/PacketHandlers/NPCActionHandler.cs @@ -64,7 +64,7 @@ public override bool HandlePacket(IPacket packet) } var index = packet.ReadChar(); - INPC npc; + NPC npc; try { npc = _currentMapStateRepository.NPCs.Single(n => n.Index == index); @@ -75,7 +75,7 @@ public override bool HandlePacket(IPacket packet) return true; } - var updatedNpc = Option.None(); + var updatedNpc = Option.None(); switch (num255s) { case NPC_WALK_ACTION: HandleNPCWalk(packet, npc); break; @@ -93,7 +93,7 @@ public override bool HandlePacket(IPacket packet) return true; } - private void HandleNPCWalk(IPacket packet, INPC npc) + private void HandleNPCWalk(IPacket packet, NPC npc) { //npc remove from view sets x/y to either 0,0 or 252,252 based on target coords var x = packet.ReadChar(); @@ -112,7 +112,7 @@ private void HandleNPCWalk(IPacket packet, INPC npc) notifier.StartNPCWalkAnimation(npc.Index); } - private INPC HandleNPCAttack(IPacket packet, INPC npc) + private NPC HandleNPCAttack(IPacket packet, NPC npc) { var isDead = packet.ReadChar() == 2; //2 if target player is dead, 1 if alive var npcDirection = (EODirection)packet.ReadChar(); @@ -129,10 +129,7 @@ private INPC HandleNPCAttack(IPacket packet, INPC npc) var stats = characterToUpdate.Stats; stats = stats.WithNewStat(CharacterStat.HP, (short)Math.Max(stats[CharacterStat.HP] - damageTaken, 0)); - var props = characterToUpdate.RenderProperties; - if (isDead) - props = props.WithDead(); - + var props = characterToUpdate.RenderProperties.WithIsDead(isDead); _characterRepository.MainCharacter = characterToUpdate.WithStats(stats).WithRenderProperties(props); foreach (var notifier in _mainCharacterNotifiers) @@ -157,7 +154,7 @@ private INPC HandleNPCAttack(IPacket packet, INPC npc) return npc.WithDirection(npcDirection); } - private void HandleNPCTalk(IPacket packet, INPC npc) + private void HandleNPCTalk(IPacket packet, NPC npc) { var messageLength = packet.ReadChar(); var message = packet.ReadString(messageLength); @@ -171,7 +168,7 @@ private void HandleNPCTalk(IPacket packet, INPC npc) notifier.ShowNPCSpeechBubble(npc.Index, message); } - private static INPC EnsureCorrectXAndY(INPC npc, byte destinationX, byte destinationY) + private static NPC EnsureCorrectXAndY(NPC npc, byte destinationX, byte destinationY) { var opposite = npc.Direction.Opposite(); var tempNPC = npc diff --git a/EOLib/PacketHandlers/NPCLeaveMapHandler.cs b/EOLib/PacketHandlers/NPCLeaveMapHandler.cs index 5b83aafbf..1957dccbc 100644 --- a/EOLib/PacketHandlers/NPCLeaveMapHandler.cs +++ b/EOLib/PacketHandlers/NPCLeaveMapHandler.cs @@ -135,11 +135,10 @@ private void UpdateCharacterStat(CharacterStat whichStat, int statValue) private void ShowDroppedItem(short playerID, short droppedItemUID, short droppedItemID, byte x, byte y, int droppedAmount) { - IItem mapItem = new Item(droppedItemUID, droppedItemID, x, y); - mapItem = mapItem.WithAmount(droppedAmount) + var mapItem = new MapItem(droppedItemUID, droppedItemID, x, y, droppedAmount) .WithIsNPCDrop(true) - .WithDropTime(DateTime.Now) - .WithOwningPlayerID(playerID); + .WithDropTime(Option.Some(DateTime.Now)) + .WithOwningPlayerID(Option.Some(playerID)); _currentMapStateRepository.MapItems.RemoveWhere(item => item.UniqueID == droppedItemUID); _currentMapStateRepository.MapItems.Add(mapItem); diff --git a/EOLib/PacketHandlers/NPCTakeDamageHandler.cs b/EOLib/PacketHandlers/NPCTakeDamageHandler.cs index 2cc6fd01a..11b72a6df 100644 --- a/EOLib/PacketHandlers/NPCTakeDamageHandler.cs +++ b/EOLib/PacketHandlers/NPCTakeDamageHandler.cs @@ -77,7 +77,7 @@ public override bool HandlePacket(IPacket packet) try { var npc = _currentMapStateRepository.NPCs.Single(x => x.Index == npcIndex); - var newNpc = npc.WithOpponentID(fromPlayerId); + var newNpc = npc.WithOpponentID(Option.Some(fromPlayerId)); _currentMapStateRepository.NPCs.Remove(npc); _currentMapStateRepository.NPCs.Add(newNpc); foreach (var notifier in _npcNotifiers) diff --git a/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs b/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs index c5ea97d30..f4386b691 100644 --- a/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs +++ b/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs @@ -34,7 +34,7 @@ public PlayerAvatarChangeHandler(IPlayerInfoProvider playerInfoProvider, public override bool HandlePacket(IPacket packet) { var playerID = packet.ReadShort(); - ICharacter currentCharacter; + Character currentCharacter; if (_characterRepository.MainCharacter.ID == playerID) { @@ -66,7 +66,8 @@ public override bool HandlePacket(IPacket packet) var weaponGraphic = packet.ReadShort(); currentRenderProps = currentRenderProps - .WithWeaponGraphic(weaponGraphic, _eifFileProvider.EIFFile.IsRangedWeapon(weaponGraphic)) + .WithWeaponGraphic(weaponGraphic) + .WithIsRangedWeapon(_eifFileProvider.EIFFile.IsRangedWeapon(weaponGraphic)) .WithShieldGraphic(packet.ReadShort()); break; diff --git a/EOLib/PacketHandlers/PlayerPKSpellHandler.cs b/EOLib/PacketHandlers/PlayerPKSpellHandler.cs index 6a0d914d0..21a09dd32 100644 --- a/EOLib/PacketHandlers/PlayerPKSpellHandler.cs +++ b/EOLib/PacketHandlers/PlayerPKSpellHandler.cs @@ -60,9 +60,8 @@ public override bool HandlePacket(IPacket packet) if (targetPlayerId == _characterRepository.MainCharacter.ID) { - var renderProps = _characterRepository.MainCharacter.RenderProperties; - if (targetIsDead) - renderProps = renderProps.WithDead(); + var renderProps = _characterRepository.MainCharacter.RenderProperties + .WithIsDead(targetIsDead); var stats = _characterRepository.MainCharacter.Stats; stats = stats.WithNewStat(CharacterStat.HP, stats[CharacterStat.HP] - damage); @@ -74,9 +73,7 @@ public override bool HandlePacket(IPacket packet) { var c = _currentMapStateRepository.Characters[targetPlayerId]; - var renderProps = c.RenderProperties; - if (targetIsDead) - renderProps = renderProps.WithDead(); + var renderProps = c.RenderProperties.WithIsDead(targetIsDead); var stats = c.Stats; stats = stats.WithNewStat(CharacterStat.HP, stats[CharacterStat.HP] - damage); diff --git a/EOLib/PacketHandlers/PlayerSitHandler.cs b/EOLib/PacketHandlers/PlayerSitHandler.cs index 4db159986..b7744d67f 100644 --- a/EOLib/PacketHandlers/PlayerSitHandler.cs +++ b/EOLib/PacketHandlers/PlayerSitHandler.cs @@ -39,6 +39,7 @@ public override bool HandlePacket(IPacket packet) { var renderProperties = _characterRepository.MainCharacter.RenderProperties; var updatedRenderProperties = renderProperties.WithSitState(sitState) + .WithCurrentAction(sitState == SitState.Standing ? CharacterActionState.Standing : CharacterActionState.Sitting) .WithMapX(x) .WithMapY(y) .WithDirection(direction); @@ -48,6 +49,7 @@ public override bool HandlePacket(IPacket packet) { var oldCharacter = _currentMapStateRepository.Characters[playerId]; var renderProperties = oldCharacter.RenderProperties.WithSitState(sitState) + .WithCurrentAction(sitState == SitState.Standing ? CharacterActionState.Standing : CharacterActionState.Sitting) .WithMapX(x) .WithMapY(y) .WithDirection(direction); diff --git a/EOLib/PacketHandlers/PlayerStandHandler.cs b/EOLib/PacketHandlers/PlayerStandHandler.cs index 7a925f7cb..71bbcc288 100644 --- a/EOLib/PacketHandlers/PlayerStandHandler.cs +++ b/EOLib/PacketHandlers/PlayerStandHandler.cs @@ -33,6 +33,7 @@ public override bool HandlePacket(IPacket packet) { var renderProperties = _characterRepository.MainCharacter.RenderProperties; var updatedRenderProperties = renderProperties.WithSitState(SitState.Standing) + .WithCurrentAction(CharacterActionState.Standing) .WithMapX(x) .WithMapY(y); _characterRepository.MainCharacter = _characterRepository.MainCharacter.WithRenderProperties(updatedRenderProperties); @@ -41,6 +42,7 @@ public override bool HandlePacket(IPacket packet) { var oldCharacter = _currentMapStateRepository.Characters[playerId]; var renderProperties = oldCharacter.RenderProperties.WithSitState(SitState.Standing) + .WithCurrentAction(CharacterActionState.Standing) .WithMapX(x) .WithMapY(y); diff --git a/EOLib/PacketHandlers/PlayerWalkHandler.cs b/EOLib/PacketHandlers/PlayerWalkHandler.cs index 257e82a39..adc0fa2cc 100644 --- a/EOLib/PacketHandlers/PlayerWalkHandler.cs +++ b/EOLib/PacketHandlers/PlayerWalkHandler.cs @@ -60,7 +60,7 @@ public override bool HandlePacket(IPacket packet) return true; } - private static ICharacterRenderProperties EnsureCorrectXAndY(ICharacterRenderProperties renderProperties, byte x, byte y) + private static CharacterRenderProperties EnsureCorrectXAndY(CharacterRenderProperties renderProperties, byte x, byte y) { var opposite = renderProperties.Direction.Opposite(); var tempRenderProperties = renderProperties diff --git a/EOLib/PacketHandlers/Quest/QuestDialogHandler.cs b/EOLib/PacketHandlers/Quest/QuestDialogHandler.cs index 97ddaa08d..b464d4bdb 100644 --- a/EOLib/PacketHandlers/Quest/QuestDialogHandler.cs +++ b/EOLib/PacketHandlers/Quest/QuestDialogHandler.cs @@ -45,11 +45,13 @@ public override bool HandlePacket(IPacket packet) if (packet.ReadByte() != 255) return false; - var questData = new QuestDialogData() - .WithVendorID(vendorID) - .WithQuestID(questID) - .WithSessionID(sessionID) // not used by eoserv - .WithDialogID(dialogID); // not used by eoserv + var questData = new QuestDialogData.Builder + { + VendorID = vendorID, + QuestID = questID, + SessionID = sessionID, // not used by eoserv + DialogID = dialogID, // not used by eoserv + }; var dialogTitles = new Dictionary(numDialogs); for (int i = 0; i < numDialogs; i++) @@ -68,11 +70,11 @@ public override bool HandlePacket(IPacket packet) } } - questData = questData.WithDialogTitles(dialogTitles) - .WithPageText(pages) - .WithActions(links); + questData.DialogTitles = dialogTitles; + questData.PageText = pages; + questData.Actions = links; - _questDataRepository.QuestDialogData = Option.Some(questData); + _questDataRepository.QuestDialogData = Option.Some(questData.ToImmutable()); foreach (var notifier in _npcInteractionNotifiers) notifier.NotifyInteractionFromNPC(IO.NPCType.Quest); diff --git a/EOLib/PacketHandlers/Quest/QuestListHandler.cs b/EOLib/PacketHandlers/Quest/QuestListHandler.cs index 504c0b224..79fcf5f13 100644 --- a/EOLib/PacketHandlers/Quest/QuestListHandler.cs +++ b/EOLib/PacketHandlers/Quest/QuestListHandler.cs @@ -32,18 +32,20 @@ public override bool HandlePacket(IPacket packet) { case QuestPage.Progress: { - var progress = new List(numQuests); + var progress = new List(numQuests); for (int i = 0; packet.ReadPosition < packet.Length && i < numQuests; i++) { - var progressData = new QuestProgressData() - .WithName(packet.ReadBreakString()) - .WithDescription(packet.ReadBreakString()) - .WithIcon((BookIcon)packet.ReadShort()) - .WithProgress(packet.ReadShort()) - .WithTarget(packet.ReadShort()); + var progressData = new QuestProgressData.Builder + { + Name = packet.ReadBreakString(), + Description = packet.ReadBreakString(), + Icon = (BookIcon)packet.ReadShort(), + Progress = packet.ReadShort(), + Target = packet.ReadShort(), + }; - progress.Add(progressData); + progress.Add(progressData.ToImmutable()); if (packet.ReadByte() != 255) return false; diff --git a/EOLib/PacketHandlers/RefreshMapStateHandler.cs b/EOLib/PacketHandlers/RefreshMapStateHandler.cs index 7da388323..50ad9cb71 100644 --- a/EOLib/PacketHandlers/RefreshMapStateHandler.cs +++ b/EOLib/PacketHandlers/RefreshMapStateHandler.cs @@ -15,7 +15,7 @@ namespace EOLib.PacketHandlers [AutoMappedType] public class RefreshMapStateHandler : InGameOnlyPacketHandler { - private readonly IPacketTranslator _refreshReplyTranslator; + private readonly IPacketTranslator _refreshReplyTranslator; private readonly ICharacterRepository _characterRepository; private readonly ICurrentMapStateRepository _currentMapStateRepository; private readonly IEnumerable _mapChangedNotifiers; @@ -25,7 +25,7 @@ public class RefreshMapStateHandler : InGameOnlyPacketHandler public override PacketAction Action => PacketAction.Reply; public RefreshMapStateHandler(IPlayerInfoProvider playerInfoProvider, - IPacketTranslator refreshReplyTranslator, + IPacketTranslator refreshReplyTranslator, ICharacterRepository characterRepository, ICurrentMapStateRepository currentMapStateRepository, IEnumerable mapChangedNotifiers) @@ -48,14 +48,14 @@ public override bool HandlePacket(IPacket packet) .WithMapY(updatedMainCharacter.RenderProperties.MapY); var withoutMainCharacter = data.Characters.Where(x => !IDMatches(x)); - data = data.WithCharacters(withoutMainCharacter); + data = data.WithCharacters(withoutMainCharacter.ToList()); _characterRepository.MainCharacter = _characterRepository.MainCharacter .WithRenderProperties(updatedRenderProperties); _currentMapStateRepository.Characters = data.Characters.ToDictionary(k => k.ID, v => v); - _currentMapStateRepository.NPCs = new HashSet(data.NPCs); - _currentMapStateRepository.MapItems = new HashSet(data.Items); + _currentMapStateRepository.NPCs = new HashSet(data.NPCs); + _currentMapStateRepository.MapItems = new HashSet(data.Items); _currentMapStateRepository.OpenDoors.Clear(); _currentMapStateRepository.PendingDoors.Clear(); @@ -67,7 +67,7 @@ public override bool HandlePacket(IPacket packet) return true; } - private bool IDMatches(ICharacter x) + private bool IDMatches(Character x) { return x.ID == _characterRepository.MainCharacter.ID; } diff --git a/EndlessClient/Controllers/CharacterManagementController.cs b/EndlessClient/Controllers/CharacterManagementController.cs index f430693f1..8d8fd75eb 100644 --- a/EndlessClient/Controllers/CharacterManagementController.cs +++ b/EndlessClient/Controllers/CharacterManagementController.cs @@ -66,9 +66,9 @@ public async Task CreateCharacter() }); } - public async Task DeleteCharacter(ICharacter characterToDelete) + public async Task DeleteCharacter(Character characterToDelete) { - void ShowCharacterDeleteWarning(ICharacter c) + void ShowCharacterDeleteWarning(Character c) { _characterDialogActions.ShowCharacterDeleteWarning(c.Name); _characterSelectorRepository.CharacterForDelete = Option.Some(c); @@ -110,7 +110,7 @@ void ShowCharacterDeleteWarning(ICharacter c) var response = deleteOp.Result; - _characterSelectorRepository.CharacterForDelete = Option.None(); + _characterSelectorRepository.CharacterForDelete = Option.None(); if (response != CharacterReply.Deleted) { SetInitialStateAndShowError(); @@ -150,6 +150,6 @@ public interface ICharacterManagementController { Task CreateCharacter(); - Task DeleteCharacter(ICharacter characterToDelete); + Task DeleteCharacter(Character characterToDelete); } } \ No newline at end of file diff --git a/EndlessClient/Controllers/InventoryController.cs b/EndlessClient/Controllers/InventoryController.cs index e889fd898..8e8553faf 100644 --- a/EndlessClient/Controllers/InventoryController.cs +++ b/EndlessClient/Controllers/InventoryController.cs @@ -185,7 +185,7 @@ public void UnequipItem(EquipLocation equipLocation) _itemActions.UnequipItem(equipId, alternateLocation: locName.Contains('2')); } - public void DropItem(EIFRecord itemData, IInventoryItem inventoryItem) + public void DropItem(EIFRecord itemData, InventoryItem inventoryItem) { var mapRenderer = _hudControlProvider.GetComponent(HudControlIdentifier.MapRenderer); if (_activeDialogProvider.ActiveDialogs.Any(x => x.HasValue) && mapRenderer.MouseOver) @@ -221,7 +221,7 @@ public void DropItem(EIFRecord itemData, IInventoryItem inventoryItem) } } - public void DropItemInChest(EIFRecord itemData, IInventoryItem inventoryItem) + public void DropItemInChest(EIFRecord itemData, InventoryItem inventoryItem) { var validationResult = _itemDropValidator.ValidateItemDrop(_characterProvider.MainCharacter, inventoryItem); @@ -236,7 +236,7 @@ public void DropItemInChest(EIFRecord itemData, IInventoryItem inventoryItem) } } - public void DropItemInLocker(EIFRecord itemData, IInventoryItem inventoryItem) + public void DropItemInLocker(EIFRecord itemData, InventoryItem inventoryItem) { if (inventoryItem.ItemID == 1) { @@ -262,7 +262,7 @@ public void DropItemInLocker(EIFRecord itemData, IInventoryItem inventoryItem) } } - public void JunkItem(EIFRecord itemData, IInventoryItem inventoryItem) + public void JunkItem(EIFRecord itemData, InventoryItem inventoryItem) { if (inventoryItem.Amount > 1) { @@ -286,7 +286,7 @@ public void JunkItem(EIFRecord itemData, IInventoryItem inventoryItem) } } - private void DoItemDrop(EIFRecord itemData, IInventoryItem inventoryItem, Action dropAction, + private void DoItemDrop(EIFRecord itemData, InventoryItem inventoryItem, Action dropAction, ItemTransferDialog.TransferType transferType = ItemTransferDialog.TransferType.DropItems, EOResourceID message = EOResourceID.DIALOG_TRANSFER_DROP) { @@ -336,12 +336,12 @@ public interface IInventoryController void UnequipItem(EquipLocation equipLocation); - void DropItem(EIFRecord itemData, IInventoryItem inventoryItem); + void DropItem(EIFRecord itemData, InventoryItem inventoryItem); - void DropItemInChest(EIFRecord itemData, IInventoryItem inventoryItem); + void DropItemInChest(EIFRecord itemData, InventoryItem inventoryItem); - void DropItemInLocker(EIFRecord itemData, IInventoryItem inventoryItem); + void DropItemInLocker(EIFRecord itemData, InventoryItem inventoryItem); - void JunkItem(EIFRecord itemData, IInventoryItem inventoryItem); + void JunkItem(EIFRecord itemData, InventoryItem inventoryItem); } } diff --git a/EndlessClient/Controllers/LoginController.cs b/EndlessClient/Controllers/LoginController.cs index b6edd3143..c277a825b 100644 --- a/EndlessClient/Controllers/LoginController.cs +++ b/EndlessClient/Controllers/LoginController.cs @@ -96,7 +96,7 @@ public async Task LoginToAccount(ILoginParameters loginParameters) } } - public async Task LoginToCharacter(ICharacter character) + public async Task LoginToCharacter(Character character) { var requestCharacterLoginOperation = _networkOperationFactory.CreateSafeBlockingOperation( async () => await _loginActions.RequestCharacterLogin(character), @@ -261,6 +261,6 @@ public interface ILoginController { Task LoginToAccount(ILoginParameters loginParameters); - Task LoginToCharacter(ICharacter character); + Task LoginToCharacter(Character character); } } \ No newline at end of file diff --git a/EndlessClient/Controllers/MapInteractionController.cs b/EndlessClient/Controllers/MapInteractionController.cs index 3f3e620a7..9dab6beb9 100644 --- a/EndlessClient/Controllers/MapInteractionController.cs +++ b/EndlessClient/Controllers/MapInteractionController.cs @@ -101,7 +101,7 @@ public void LeftClick(IMapCellState cellState, Option mous var optionalItem = cellState.Items.FirstOrNone(); if (optionalItem.HasValue) { - var item = optionalItem.ValueOr(Item.None); + var item = optionalItem.ValueOr(MapItem.None); if (!_inventorySpaceValidator.ItemFits(item)) _statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_INFORMATION, EOResourceID.STATUS_LABEL_ITEM_PICKUP_NO_SPACE_LEFT); else @@ -188,7 +188,7 @@ public void LeftClick(ISpellTargetable spellTarget) _userInputTimeRepository.LastInputTime = DateTime.Now; } - public void RightClick(ICharacter character) + public void RightClick(Character character) { if (_activeDialogProvider.ActiveDialogs.Any(x => x.HasValue)) return; @@ -212,7 +212,7 @@ public void RightClick(ICharacter character) } } - private void HandlePickupResult(ItemPickupResult pickupResult, IItem item) + private void HandlePickupResult(ItemPickupResult pickupResult, MapItem item) { switch (pickupResult) { @@ -281,6 +281,6 @@ public interface IMapInteractionController void LeftClick(ISpellTargetable spellTarget); - void RightClick(ICharacter character); + void RightClick(Character character); } } diff --git a/EndlessClient/Controllers/NPCInteractionController.cs b/EndlessClient/Controllers/NPCInteractionController.cs index 0324d6ed0..1074ea75b 100644 --- a/EndlessClient/Controllers/NPCInteractionController.cs +++ b/EndlessClient/Controllers/NPCInteractionController.cs @@ -36,7 +36,7 @@ public NPCInteractionController(IMapNPCActions mapNpcActions, _userInputRepository = userInputRepository; } - public void ShowNPCDialog(INPC npc) + public void ShowNPCDialog(NPC npc) { if (_activeDialogProvider.ActiveDialogs.Any(x => x.HasValue)) return; @@ -74,6 +74,6 @@ public void ShowNPCDialog(INPC npc) public interface INPCInteractionController { - void ShowNPCDialog(INPC npc); + void ShowNPCDialog(NPC npc); } } diff --git a/EndlessClient/Dialogs/Actions/InGameDialogActions.cs b/EndlessClient/Dialogs/Actions/InGameDialogActions.cs index e3367c6ec..c28b55f3f 100644 --- a/EndlessClient/Dialogs/Actions/InGameDialogActions.cs +++ b/EndlessClient/Dialogs/Actions/InGameDialogActions.cs @@ -108,7 +108,7 @@ public void ShowQuestStatusDialog() }); } - public void ShowPaperdollDialog(ICharacter character, bool isMainCharacter) + public void ShowPaperdollDialog(Character character, bool isMainCharacter) { _activeDialogRepository.PaperdollDialog.MatchNone(() => { @@ -227,7 +227,7 @@ public interface IInGameDialogActions void ShowQuestStatusDialog(); - void ShowPaperdollDialog(ICharacter character, bool isMainCharacter); + void ShowPaperdollDialog(Character character, bool isMainCharacter); void ShowShopDialog(); diff --git a/EndlessClient/Dialogs/ChestDialog.cs b/EndlessClient/Dialogs/ChestDialog.cs index 7d2c5679a..1aa0dd180 100644 --- a/EndlessClient/Dialogs/ChestDialog.cs +++ b/EndlessClient/Dialogs/ChestDialog.cs @@ -33,7 +33,7 @@ public class ChestDialog : ScrollingListDialog private readonly ICharacterProvider _characterProvider; private readonly InventoryPanel _inventoryPanel; - private HashSet _cachedItems; + private HashSet _cachedItems; public ChestDialog(INativeGraphicsManager nativeGraphicsManager, IChestActions chestActions, @@ -64,7 +64,7 @@ public ChestDialog(INativeGraphicsManager nativeGraphicsManager, Buttons = ScrollingListDialogButtons.Cancel; _inventoryPanel = _hudControlProvider.GetComponent(HudControlIdentifier.InventoryPanel); - _cachedItems = new HashSet(); + _cachedItems = new HashSet(); _statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, EOResourceID.STATUS_LABEL_CHEST_YOU_OPENED, @@ -107,7 +107,7 @@ private void RefreshItemList() } } - private void TakeItem(IInventoryItem item, EIFRecord itemData) + private void TakeItem(ChestItem item, EIFRecord itemData) { if (!_inventorySpaceValidator.ItemFits(item.ItemID)) { diff --git a/EndlessClient/Dialogs/CreateCharacterDialog.cs b/EndlessClient/Dialogs/CreateCharacterDialog.cs index eb78b117e..a8a03207e 100644 --- a/EndlessClient/Dialogs/CreateCharacterDialog.cs +++ b/EndlessClient/Dialogs/CreateCharacterDialog.cs @@ -31,7 +31,7 @@ public class CreateCharacterDialog : BaseEODialog public string Name => _inputBox.Text.Trim(); - private ICharacterRenderProperties RenderProperties => _characterControl.RenderProperties; + private CharacterRenderProperties RenderProperties => _characterControl.RenderProperties; public byte Gender => RenderProperties.Gender; public byte HairStyle => RenderProperties.HairStyle; public byte HairColor => RenderProperties.HairColor; diff --git a/EndlessClient/Dialogs/Factories/PaperdollDialogFactory.cs b/EndlessClient/Dialogs/Factories/PaperdollDialogFactory.cs index af09b20aa..70b99a09e 100644 --- a/EndlessClient/Dialogs/Factories/PaperdollDialogFactory.cs +++ b/EndlessClient/Dialogs/Factories/PaperdollDialogFactory.cs @@ -46,7 +46,7 @@ public PaperdollDialogFactory(IGameStateProvider gameStateProvider, _statusLabelSetter = statusLabelSetter; } - public PaperdollDialog Create(ICharacter character, bool isMainCharacter) + public PaperdollDialog Create(Character character, bool isMainCharacter) { return new PaperdollDialog(_gameStateProvider, _nativeGraphicsManager, @@ -70,7 +70,7 @@ public void InjectInventoryController(IInventoryController inventoryController) public interface IPaperdollDialogFactory { - PaperdollDialog Create(ICharacter character, bool isMainCharacter); + PaperdollDialog Create(Character character, bool isMainCharacter); void InjectInventoryController(IInventoryController inventoryController); } diff --git a/EndlessClient/Dialogs/LockerDialog.cs b/EndlessClient/Dialogs/LockerDialog.cs index d3af52fba..fad43e339 100644 --- a/EndlessClient/Dialogs/LockerDialog.cs +++ b/EndlessClient/Dialogs/LockerDialog.cs @@ -30,7 +30,7 @@ public class LockerDialog : ScrollingListDialog private readonly IEIFFileProvider _eifFileProvider; private readonly InventoryPanel _inventoryPanel; - private HashSet _cachedItems; + private HashSet _cachedItems; public LockerDialog(INativeGraphicsManager nativeGraphicsManager, ILockerActions lockerActions, @@ -55,7 +55,7 @@ public LockerDialog(INativeGraphicsManager nativeGraphicsManager, _eifFileProvider = eifFileProvider; _inventoryPanel = hudControlProvider.GetComponent(HudControlIdentifier.InventoryPanel); - _cachedItems = new HashSet(); + _cachedItems = new HashSet(); Title = GetDialogTitle(); Buttons = ScrollingListDialogButtons.Cancel; @@ -98,7 +98,7 @@ private void UpdateItemList() } } - private void TakeItem(EIFRecord itemData, IInventoryItem item) + private void TakeItem(EIFRecord itemData, InventoryItem item) { if (!_inventorySpaceValidator.ItemFits(item.ItemID)) { diff --git a/EndlessClient/Dialogs/PaperdollDialog.cs b/EndlessClient/Dialogs/PaperdollDialog.cs index 651bcaf38..b4eddd7a4 100644 --- a/EndlessClient/Dialogs/PaperdollDialog.cs +++ b/EndlessClient/Dialogs/PaperdollDialog.cs @@ -43,7 +43,7 @@ public class PaperdollDialog : BaseEODialog private Option _characterIconSourceRect; private readonly InventoryPanel _inventoryPanel; - private Option _paperdollData; + private Option _paperdollData; private readonly List _childItems; @@ -55,7 +55,7 @@ public class PaperdollDialog : BaseEODialog _guild, _rank; - public ICharacter Character { get; } + public Character Character { get; } public PaperdollDialog(IGameStateProvider gameStateProvider, INativeGraphicsManager nativeGraphicsManager, @@ -67,7 +67,7 @@ public PaperdollDialog(IGameStateProvider gameStateProvider, IInventorySpaceValidator inventorySpaceValidator, IEOMessageBoxFactory eoMessageBoxFactory, IStatusLabelSetter statusLabelSetter, - ICharacter character, bool isMainCharacter) + Character character, bool isMainCharacter) : base(gameStateProvider) { _paperdollProvider = paperdollProvider; @@ -128,7 +128,7 @@ public PaperdollDialog(IGameStateProvider gameStateProvider, CenterInGameView(); DrawPosition = new Vector2(DrawPosition.X, 15); - _paperdollData = Option.None(); + _paperdollData = Option.None(); } public bool NoItemsDragging() => !_childItems.Any(x => x.IsBeingDragged); @@ -173,7 +173,7 @@ protected override void OnDrawControl(GameTime gameTime) _spriteBatch.End(); } - private void UpdateDisplayedData(IPaperdollData paperdollData) + private void UpdateDisplayedData(PaperdollData paperdollData) { _name.Text = Capitalize(paperdollData.Name); _home.Text = Capitalize(paperdollData.Home); diff --git a/EndlessClient/Dialogs/QuestDialog.cs b/EndlessClient/Dialogs/QuestDialog.cs index ed5fcfb72..cb41115ae 100644 --- a/EndlessClient/Dialogs/QuestDialog.cs +++ b/EndlessClient/Dialogs/QuestDialog.cs @@ -21,7 +21,7 @@ public class QuestDialog : ScrollingListDialog private readonly IENFFileProvider _enfFileProvider; private readonly IContentProvider _contentProvider; - private Option _cachedData; + private Option _cachedData; private int _pageIndex = 0; @@ -38,7 +38,7 @@ public QuestDialog(INativeGraphicsManager nativeGraphicsManager, _enfFileProvider = enfFileProvider; _contentProvider = contentProvider; - _cachedData = Option.None(); + _cachedData = Option.None(); ListItemType = ListDialogItem.ListItemStyle.Small; @@ -57,7 +57,7 @@ protected override void OnUpdateControl(GameTime gameTime) base.OnUpdateControl(gameTime); } - private void UpdateCachedDataIfNeeded(Option cachedData, IQuestDialogData repoData) + private void UpdateCachedDataIfNeeded(Option cachedData, QuestDialogData repoData) { cachedData.Match( some: cached => @@ -73,7 +73,7 @@ private void UpdateCachedDataIfNeeded(Option cachedData, IQues }); } - private void UpdateDialogControls(IQuestDialogData repoData) + private void UpdateDialogControls(QuestDialogData repoData) { _pageIndex = 0; @@ -82,7 +82,7 @@ private void UpdateDialogControls(IQuestDialogData repoData) UpdateButtons(repoData); } - private void UpdateTitle(IQuestDialogData repoData) + private void UpdateTitle(QuestDialogData repoData) { var npcName = _enfFileProvider.ENFFile[_questDataProvider.RequestedNPC.ID].Name; var titleText = npcName; @@ -95,7 +95,7 @@ private void UpdateTitle(IQuestDialogData repoData) _titleText.ResizeBasedOnText(); } - private void UpdateDialogDisplayText(IQuestDialogData repoData) + private void UpdateDialogDisplayText(QuestDialogData repoData) { ClearItemList(); @@ -143,7 +143,7 @@ private void UpdateDialogDisplayText(IQuestDialogData repoData) } } - private void UpdateButtons(IQuestDialogData repoData) + private void UpdateButtons(QuestDialogData repoData) { bool morePages = _pageIndex < repoData.PageText.Count - 1; bool firstPage = _pageIndex == 0; diff --git a/EndlessClient/Dialogs/QuestStatusDialog.cs b/EndlessClient/Dialogs/QuestStatusDialog.cs index a7f9c3f34..4e314503c 100644 --- a/EndlessClient/Dialogs/QuestStatusDialog.cs +++ b/EndlessClient/Dialogs/QuestStatusDialog.cs @@ -15,7 +15,7 @@ public class QuestStatusDialog : ScrollingListDialog private readonly ICharacterProvider _characterProvider; - private IReadOnlyList _cachedProgress = new List(); + private IReadOnlyList _cachedProgress = new List(); private IReadOnlyList _cachedHistory = new List(); private QuestPage _page; diff --git a/EndlessClient/Dialogs/ShopDialog.cs b/EndlessClient/Dialogs/ShopDialog.cs index e5f120cf2..3fbb263ac 100644 --- a/EndlessClient/Dialogs/ShopDialog.cs +++ b/EndlessClient/Dialogs/ShopDialog.cs @@ -43,7 +43,7 @@ private enum ShopState private ShopState _state; private Option _cachedShopId; - private HashSet _cachedInventory; + private HashSet _cachedInventory; private ulong _tick; public ShopDialog(INativeGraphicsManager nativeGraphicsManager, @@ -76,7 +76,7 @@ public ShopDialog(INativeGraphicsManager nativeGraphicsManager, BackAction += (_, _) => SetState(ShopState.Initial); - _cachedInventory = new HashSet(_characterInventoryProvider.ItemInventory); + _cachedInventory = new HashSet(_characterInventoryProvider.ItemInventory); } protected override void OnUpdateControl(GameTime gameTime) @@ -101,7 +101,7 @@ protected override void OnUpdateControl(GameTime gameTime) if (++_tick % 8 == 0 && !_cachedInventory.SetEquals(_characterInventoryProvider.ItemInventory)) { _sellItems = _shopDataProvider.TradeItems.Where(x => x.Sell > 0 && _characterInventoryProvider.ItemInventory.Any(inv => inv.ItemID == x.ID && inv.Amount > 0)).ToList(); - _cachedInventory = new HashSet(_characterInventoryProvider.ItemInventory); + _cachedInventory = new HashSet(_characterInventoryProvider.ItemInventory); if (_state == ShopState.Selling) SetState(ShopState.Selling); diff --git a/EndlessClient/Dialogs/SkillmasterDialog.cs b/EndlessClient/Dialogs/SkillmasterDialog.cs index 2efb41c9f..d98eca114 100644 --- a/EndlessClient/Dialogs/SkillmasterDialog.cs +++ b/EndlessClient/Dialogs/SkillmasterDialog.cs @@ -31,7 +31,7 @@ private enum SkillState private SkillState _state; private HashSet _cachedSkills; - private HashSet _cachedSpells; + private HashSet _cachedSpells; private string _cachedTitle; private bool _showingRequirements; @@ -66,7 +66,7 @@ public SkillmasterDialog(INativeGraphicsManager nativeGraphicsManager, ListItemType = ListDialogItem.ListItemStyle.Large; _cachedSkills = new HashSet(); - _cachedSpells = new HashSet(); + _cachedSpells = new HashSet(); _cachedTitle = string.Empty; BackAction += BackClicked; diff --git a/EndlessClient/GameExecution/EndlessGame.cs b/EndlessClient/GameExecution/EndlessGame.cs index 190b75f4c..1cafed08b 100644 --- a/EndlessClient/GameExecution/EndlessGame.cs +++ b/EndlessClient/GameExecution/EndlessGame.cs @@ -116,7 +116,7 @@ protected override void LoadContent() // for some reason initializing these and then killing them speeds up transition from Login -> LoggedIn state // TODO: figure out why this happens???? - foreach (var panel in _characterInfoPanelFactory.CreatePanels(Enumerable.Repeat(new Character(), 3))) + foreach (var panel in _characterInfoPanelFactory.CreatePanels(Enumerable.Repeat(Character.Default, 3))) { panel.Initialize(); panel.Dispose(); diff --git a/EndlessClient/HUD/Inventory/InventoryPanelItem.cs b/EndlessClient/HUD/Inventory/InventoryPanelItem.cs index 73c04645a..ba3a303e2 100644 --- a/EndlessClient/HUD/Inventory/InventoryPanelItem.cs +++ b/EndlessClient/HUD/Inventory/InventoryPanelItem.cs @@ -64,7 +64,7 @@ public int Slot } } - public IInventoryItem InventoryItem { get; set; } + public InventoryItem InventoryItem { get; set; } public string Text { @@ -88,7 +88,7 @@ public InventoryPanelItem(IItemNameColorService itemNameColorService, InventoryPanel inventoryPanel, IActiveDialogProvider activeDialogProvider, int slot, - IInventoryItem inventoryItem, + InventoryItem inventoryItem, EIFRecord data) { _inventoryPanel = inventoryPanel; diff --git a/EndlessClient/HUD/Inventory/InventorySpaceValidator.cs b/EndlessClient/HUD/Inventory/InventorySpaceValidator.cs index af0b0a4d7..42a30ad6f 100644 --- a/EndlessClient/HUD/Inventory/InventorySpaceValidator.cs +++ b/EndlessClient/HUD/Inventory/InventorySpaceValidator.cs @@ -28,7 +28,7 @@ public InventorySpaceValidator(IEIFFileProvider eifFileProvider, _inventoryService = inventoryService; } - public bool ItemFits(IItem item) + public bool ItemFits(MapItem item) { return _characterInventoryProvider.ItemInventory.Any(x => x.ItemID == item.ItemID) || ItemFits(item.ItemID); } @@ -48,7 +48,7 @@ private bool ItemFits(ItemSize itemSize) public interface IInventorySpaceValidator { - bool ItemFits(IItem item); + bool ItemFits(MapItem item); bool ItemFits(int itemId); diff --git a/EndlessClient/HUD/Panels/ActiveSpellsPanel.cs b/EndlessClient/HUD/Panels/ActiveSpellsPanel.cs index 8831ab85d..b5f73e298 100644 --- a/EndlessClient/HUD/Panels/ActiveSpellsPanel.cs +++ b/EndlessClient/HUD/Panels/ActiveSpellsPanel.cs @@ -52,8 +52,8 @@ public class ActiveSpellsPanel : XNAPanel, IHudPanel private readonly XNAButton _levelUpButton1, _levelUpButton2; private readonly ScrollBar _scrollBar; - private HashSet _cachedSpells; - private ICharacterStats _cachedStats; + private HashSet _cachedSpells; + private CharacterStats _cachedStats; private Option _cachedSelectedSpell; private bool _confirmedTraining; @@ -86,7 +86,7 @@ public ActiveSpellsPanel(INativeGraphicsManager nativeGraphicsManager, _childItems = new List(); ResetChildItems(); - _cachedSpells = new HashSet(); + _cachedSpells = new HashSet(); _functionKeyLabelSheet = NativeGraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, 58, true); _functionKeyRow1Source = new Rectangle(148, 51, 18, 13); @@ -193,7 +193,7 @@ protected override void OnUpdateControl(GameTime gameTime) _childItems.Remove(childControl); _childItems.Add(CreateEmptySpell(childControl.Slot)); - _spellSlotDataRepository.SpellSlots[childControl.Slot] = Option.None(); + _spellSlotDataRepository.SpellSlots[childControl.Slot] = Option.None(); }); } @@ -434,7 +434,7 @@ private void ItemDraggingCompleted(object sender, SpellDragCompletedEventArgs e) child.Slot = oldSlot; child.DisplaySlot = oldDisplaySlot; - _spellSlotDataRepository.SpellSlots[oldSlot] = Option.None(); + _spellSlotDataRepository.SpellSlots[oldSlot] = Option.None(); _spellSlotDataRepository.SpellSlots[newSlot] = Option.Some(item.InventorySpell); _spellSlotDataRepository.SelectedSpellSlot = Option.Some(newSlot); _spellSlotDataRepository.SpellIsPrepared = false; diff --git a/EndlessClient/HUD/Panels/InventoryPanel.cs b/EndlessClient/HUD/Panels/InventoryPanel.cs index a6e81835e..b02d4671f 100644 --- a/EndlessClient/HUD/Panels/InventoryPanel.cs +++ b/EndlessClient/HUD/Panels/InventoryPanel.cs @@ -55,8 +55,8 @@ public class InventoryPanel : XNAPanel, IHudPanel private readonly IXNAButton _drop, _junk, _paperdoll; //private readonly ScrollBar _scrollBar; - private Option _cachedStats; - private HashSet _cachedInventory; + private Option _cachedStats; + private HashSet _cachedInventory; public INativeGraphicsManager NativeGraphicsManager { get; } @@ -114,8 +114,8 @@ public InventoryPanel(INativeGraphicsManager nativeGraphicsManager, _junk = new XNAButton(weirdOffsetSheet, new Vector2(431, 68), new Rectangle(0, 89, 38, 37), new Rectangle(0, 126, 38, 37)); _junk.OnMouseEnter += MouseOverButton; - _cachedStats = Option.None(); - _cachedInventory = new HashSet(); + _cachedStats = Option.None(); + _cachedInventory = new HashSet(); BackgroundImage = NativeGraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, 44); DrawArea = new Rectangle(102, 330, BackgroundImage.Width, BackgroundImage.Height); diff --git a/EndlessClient/HUD/Panels/StatsPanel.cs b/EndlessClient/HUD/Panels/StatsPanel.cs index a9f79cd39..9f4d32dec 100644 --- a/EndlessClient/HUD/Panels/StatsPanel.cs +++ b/EndlessClient/HUD/Panels/StatsPanel.cs @@ -33,8 +33,8 @@ public class StatsPanel : XNAPanel, IHudPanel GOLD = 4, EXP = 5, TNL = 6, KARMA = 7; private readonly IXNALabel[] _otherInfo; - private ICharacterStats _lastCharacterStats; - private IInventoryItem _lastCharacterGold; + private CharacterStats _lastCharacterStats; + private InventoryItem _lastCharacterGold; private bool _confirmedTraining; public StatsPanel(INativeGraphicsManager nativeGraphicsManager, @@ -222,7 +222,7 @@ private async void HandleArrowButtonClick(object sender, EventArgs e) } } - private IInventoryItem CurrentCharacterGold + private InventoryItem CurrentCharacterGold => _characterInventoryProvider.ItemInventory.Single(x => x.ItemID == 1); private int ExperienceToNextLevel => diff --git a/EndlessClient/HUD/Spells/BaseSpellPanelItem.cs b/EndlessClient/HUD/Spells/BaseSpellPanelItem.cs index a0d3bdba1..88426d76c 100644 --- a/EndlessClient/HUD/Spells/BaseSpellPanelItem.cs +++ b/EndlessClient/HUD/Spells/BaseSpellPanelItem.cs @@ -35,7 +35,7 @@ public int DisplaySlot public virtual bool IsBeingDragged => false; - public abstract IInventorySpell InventorySpell { get; set; } + public abstract InventorySpell InventorySpell { get; set; } public abstract ESFRecord SpellData { get; } diff --git a/EndlessClient/HUD/Spells/EmptySpellPanelItem.cs b/EndlessClient/HUD/Spells/EmptySpellPanelItem.cs index 19cbfa044..82d37b456 100644 --- a/EndlessClient/HUD/Spells/EmptySpellPanelItem.cs +++ b/EndlessClient/HUD/Spells/EmptySpellPanelItem.cs @@ -7,7 +7,7 @@ namespace EndlessClient.HUD.Spells { public class EmptySpellPanelItem : BaseSpellPanelItem { - public override IInventorySpell InventorySpell + public override InventorySpell InventorySpell { get => new InventorySpell(0, 0); set => throw new InvalidOperationException("There is no Spell associated with this slot"); diff --git a/EndlessClient/HUD/Spells/ISpellPanelItem.cs b/EndlessClient/HUD/Spells/ISpellPanelItem.cs index 611180150..851a01fae 100644 --- a/EndlessClient/HUD/Spells/ISpellPanelItem.cs +++ b/EndlessClient/HUD/Spells/ISpellPanelItem.cs @@ -15,7 +15,7 @@ public interface ISpellPanelItem : IXNAControl bool IsBeingDragged { get; } - IInventorySpell InventorySpell { get; set; } + InventorySpell InventorySpell { get; set; } ESFRecord SpellData { get; } diff --git a/EndlessClient/HUD/Spells/SpellPanelItem.cs b/EndlessClient/HUD/Spells/SpellPanelItem.cs index 2fb8fc0cd..a14490743 100644 --- a/EndlessClient/HUD/Spells/SpellPanelItem.cs +++ b/EndlessClient/HUD/Spells/SpellPanelItem.cs @@ -24,9 +24,9 @@ public class SpellDragCompletedEventArgs private Rectangle _levelDestinationRectangle; private int _lastSlot; - private IInventorySpell _lastInventorySpell; + private InventorySpell _lastInventorySpell; - public override IInventorySpell InventorySpell { get; set; } + public override InventorySpell InventorySpell { get; set; } public override bool IsBeingDragged => _dragging; @@ -34,7 +34,7 @@ public class SpellDragCompletedEventArgs public override event EventHandler DoneDragging; - public SpellPanelItem(ActiveSpellsPanel parent, int slot, IInventorySpell spell, ESFRecord spellData) + public SpellPanelItem(ActiveSpellsPanel parent, int slot, InventorySpell spell, ESFRecord spellData) : base(parent, slot) { InventorySpell = spell; diff --git a/EndlessClient/HUD/Spells/SpellSlotDataRepository.cs b/EndlessClient/HUD/Spells/SpellSlotDataRepository.cs index 396073d90..a477c05c8 100644 --- a/EndlessClient/HUD/Spells/SpellSlotDataRepository.cs +++ b/EndlessClient/HUD/Spells/SpellSlotDataRepository.cs @@ -16,7 +16,7 @@ public interface ISpellSlotDataRepository /// /// Spell info for the selected spell (based on SelectedSpellSlot value) /// - Option SelectedSpellInfo { get; } + Option SelectedSpellInfo { get; } /// /// True if the selected spell slot has been prepared by using a hotkey. @@ -26,18 +26,18 @@ public interface ISpellSlotDataRepository /// /// Array of inventory spells by their slot number. /// - Option[] SpellSlots { get; set; } + Option[] SpellSlots { get; set; } } public interface ISpellSlotDataProvider { Option SelectedSpellSlot { get; } - Option SelectedSpellInfo { get; } + Option SelectedSpellInfo { get; } bool SpellIsPrepared { get; } - IReadOnlyList> SpellSlots { get; } + IReadOnlyList> SpellSlots { get; } } [AutoMappedType(IsSingleton = true)] @@ -45,22 +45,22 @@ public class SpellSlotDataRepository : ISpellSlotDataRepository, ISpellSlotDataP { public Option SelectedSpellSlot { get; set; } - public Option SelectedSpellInfo => + public Option SelectedSpellInfo => SelectedSpellSlot.Match( x => SpellSlots[x].Match( y => Option.Some(y), - () => Option.None()), - () => Option.None()); + () => Option.None()), + () => Option.None()); public bool SpellIsPrepared { get; set; } - public Option[] SpellSlots { get; set; } + public Option[] SpellSlots { get; set; } - IReadOnlyList> ISpellSlotDataProvider.SpellSlots => SpellSlots; + IReadOnlyList> ISpellSlotDataProvider.SpellSlots => SpellSlots; public SpellSlotDataRepository() { - SpellSlots = new Option[ActiveSpellsPanel.SpellRows * ActiveSpellsPanel.SpellRowLength]; + SpellSlots = new Option[ActiveSpellsPanel.SpellRows * ActiveSpellsPanel.SpellRowLength]; } } } diff --git a/EndlessClient/HUD/StatusBars/StatusBarBase.cs b/EndlessClient/HUD/StatusBars/StatusBarBase.cs index eeed81c54..7331cfc4d 100644 --- a/EndlessClient/HUD/StatusBars/StatusBarBase.cs +++ b/EndlessClient/HUD/StatusBars/StatusBarBase.cs @@ -18,7 +18,7 @@ public abstract class StatusBarBase : XNAControl protected readonly XNALabel _label; protected readonly Texture2D _texture; - protected ICharacterStats Stats => _characterProvider.MainCharacter.Stats; + protected CharacterStats Stats => _characterProvider.MainCharacter.Stats; protected Rectangle _sourceRectangleArea; private Option _labelShowTime; diff --git a/EndlessClient/Input/UnwalkableTileActions.cs b/EndlessClient/Input/UnwalkableTileActions.cs index 86dfc2482..b9fd65fc7 100644 --- a/EndlessClient/Input/UnwalkableTileActions.cs +++ b/EndlessClient/Input/UnwalkableTileActions.cs @@ -75,7 +75,7 @@ public UnwalkableTileAction HandleUnwalkableTile(IMapCellState cellState) none: () => HandleWalkToTileSpec(cellState))); } - private UnwalkableTileAction HandleWalkThroughOtherCharacter(ICharacter c) + private UnwalkableTileAction HandleWalkThroughOtherCharacter(Character c) { // EOGame.Instance.Hud.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, // EOResourceID.STATUS_LABEL_KEEP_MOVING_THROUGH_PLAYER); @@ -89,7 +89,7 @@ private UnwalkableTileAction HandleWalkThroughOtherCharacter(ICharacter c) return UnwalkableTileAction.None; } - private UnwalkableTileAction HandleWalkToWarpTile(IWarp warp) + private UnwalkableTileAction HandleWalkToWarpTile(Warp warp) { if (warp.DoorType != DoorSpec.NoDoor) { @@ -171,7 +171,7 @@ private UnwalkableTileAction HandleWalkToTileSpec(IMapCellState cellState) return UnwalkableTileAction.None; } - private ICharacter MainCharacter => _characterProvider.MainCharacter; + private Character MainCharacter => _characterProvider.MainCharacter; } public interface IUnwalkableTileActions diff --git a/EndlessClient/Rendering/Character/CharacterAnimationActions.cs b/EndlessClient/Rendering/Character/CharacterAnimationActions.cs index 9afbd076f..03979c580 100644 --- a/EndlessClient/Rendering/Character/CharacterAnimationActions.cs +++ b/EndlessClient/Rendering/Character/CharacterAnimationActions.cs @@ -237,7 +237,7 @@ private void ShowWaterSplashiesIfNeeded(CharacterActionState action, int charact ? Option.Some(_characterRepository.MainCharacter) : _currentMapStateProvider.Characters.ContainsKey(characterID) ? Option.Some(_currentMapStateProvider.Characters[characterID]) - : Option.None(); + : Option.None(); var characterRenderer = characterID == _characterRepository.MainCharacter.ID ? _characterRendererProvider.MainCharacterRenderer @@ -272,7 +272,7 @@ private void CancelSpellPrep() _characterRendererProvider.MainCharacterRenderer.MatchSome(r => r.StopShout()); } - private void PlayWeaponSound(ICharacter character, int noteIndex = -1) + private void PlayWeaponSound(EOLib.Domain.Character.Character character, int noteIndex = -1) { _pubFileProvider.EIFFile.SingleOrNone(x => x.Type == ItemType.Weapon && x.DollGraphic == character.RenderProperties.WeaponGraphic) .MatchSome(x => diff --git a/EndlessClient/Rendering/Character/CharacterAnimator.cs b/EndlessClient/Rendering/Character/CharacterAnimator.cs index 913013451..8ccb9e199 100644 --- a/EndlessClient/Rendering/Character/CharacterAnimator.cs +++ b/EndlessClient/Rendering/Character/CharacterAnimator.cs @@ -347,7 +347,7 @@ private void AnimateCharacterWalking() _otherPlayerStartWalkingTimes.Remove(key); } - private ICharacterRenderProperties AnimateOneWalkFrame(ICharacterRenderProperties renderProperties) + private CharacterRenderProperties AnimateOneWalkFrame(CharacterRenderProperties renderProperties) { var isSteppingStone = _currentMapProvider.CurrentMap.Tiles[renderProperties.MapY, renderProperties.MapX] == TileSpec.Jump || _currentMapProvider.CurrentMap.Tiles[renderProperties.GetDestinationY(), renderProperties.GetDestinationX()] == TileSpec.Jump; @@ -363,7 +363,7 @@ private ICharacterRenderProperties AnimateOneWalkFrame(ICharacterRenderPropertie return nextFrameRenderProperties; } - private ICharacterRenderProperties FaceTarget(MapCoordinate characterCoord, MapCoordinate next, ICharacterRenderProperties rp) + private CharacterRenderProperties FaceTarget(MapCoordinate characterCoord, MapCoordinate next, CharacterRenderProperties rp) { var diff = next - characterCoord; @@ -511,16 +511,17 @@ private void AnimateCharacterEmotes() #endregion - private Option GetCurrentCharacterFromRepository(RenderFrameActionTime pair) + private Option GetCurrentCharacterFromRepository(RenderFrameActionTime pair) { return pair.UniqueID == _characterRepository.MainCharacter.ID ? Option.Some(_characterRepository.MainCharacter) : _currentMapStateRepository.Characters.ContainsKey(pair.UniqueID) ? Option.Some(_currentMapStateRepository.Characters[pair.UniqueID]) - : Option.None(); + : Option.None(); } - private void UpdateCharacterInRepository(ICharacter currentCharacter, ICharacter nextFrameCharacter) + private void UpdateCharacterInRepository(EOLib.Domain.Character.Character currentCharacter, + EOLib.Domain.Character.Character nextFrameCharacter) { if (currentCharacter == _characterRepository.MainCharacter) { diff --git a/EndlessClient/Rendering/Character/CharacterRenderer.cs b/EndlessClient/Rendering/Character/CharacterRenderer.cs index 9cb1fba9d..388612ea3 100644 --- a/EndlessClient/Rendering/Character/CharacterRenderer.cs +++ b/EndlessClient/Rendering/Character/CharacterRenderer.cs @@ -1,8 +1,5 @@ -using System; -using System.Linq; -using EndlessClient.Controllers; +using EndlessClient.Controllers; using EndlessClient.GameExecution; -using EndlessClient.HUD.Spells; using EndlessClient.Input; using EndlessClient.Rendering.CharacterProperties; using EndlessClient.Rendering.Chat; @@ -20,6 +17,8 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Optional; +using System; +using System.Linq; using XNAControls; namespace EndlessClient.Rendering.Character @@ -40,7 +39,7 @@ public class CharacterRenderer : DrawableGameComponent, ICharacterRenderer private readonly IUserInputProvider _userInputProvider; private readonly IEffectRenderer _effectRenderer; - private ICharacter _character; + private EOLib.Domain.Character.Character _character; private bool _textureUpdateRequired, _positionIsRelative = true; private SpriteBatch _sb; @@ -54,7 +53,7 @@ public class CharacterRenderer : DrawableGameComponent, ICharacterRenderer private IHealthBarRenderer _healthBarRenderer; private Lazy _chatBubble; - public ICharacter Character + public EOLib.Domain.Character.Character Character { get { return _character; } set @@ -90,7 +89,7 @@ public CharacterRenderer(INativeGraphicsManager nativeGraphicsmanager, ICharacterPropertyRendererBuilder characterPropertyRendererBuilder, ICharacterTextures characterTextures, ICharacterSpriteCalculator characterSpriteCalculator, - ICharacter character, + EOLib.Domain.Character.Character character, IGameStateProvider gameStateProvider, ICurrentMapProvider currentMapProvider, IUserInputProvider userInputProvider) @@ -254,7 +253,7 @@ public void DrawToSpriteBatch(SpriteBatch spriteBatch) #region Texture Loading Helpers - private static int FigureOutTopPixel(ICharacterSpriteCalculator spriteCalculator, ICharacterRenderProperties renderProperties) + private static int FigureOutTopPixel(ICharacterSpriteCalculator spriteCalculator, CharacterRenderProperties renderProperties) { var spriteForSkin = spriteCalculator.GetSkinTexture(renderProperties); var skinData = spriteForSkin.GetSourceTextureData(); @@ -377,7 +376,7 @@ private Vector2 GetNameLabelPosition() TopPixelWithOffset - 8 - _nameLabel.ActualHeight); } - private bool GetIsSteppingStone(ICharacterRenderProperties renderProps) + private bool GetIsSteppingStone(CharacterRenderProperties renderProps) { if (_gameStateProvider.CurrentState != GameStates.PlayingTheGame) return false; @@ -386,7 +385,7 @@ private bool GetIsSteppingStone(ICharacterRenderProperties renderProps) || (renderProps.IsActing(CharacterActionState.Walking) && _currentMapProvider.CurrentMap.Tiles[renderProps.GetDestinationY(), renderProps.GetDestinationX()] == TileSpec.Jump); } - private int GetSteppingStoneOffset(ICharacterRenderProperties renderProps) + private int GetSteppingStoneOffset(CharacterRenderProperties renderProps) { var isSteppingStone = GetIsSteppingStone(renderProps); diff --git a/EndlessClient/Rendering/Character/CharacterRendererUpdater.cs b/EndlessClient/Rendering/Character/CharacterRendererUpdater.cs index 553c99c72..4a29668a3 100644 --- a/EndlessClient/Rendering/Character/CharacterRendererUpdater.cs +++ b/EndlessClient/Rendering/Character/CharacterRendererUpdater.cs @@ -170,7 +170,7 @@ private void UpdateDeadCharacters() _currentMapStateRepository.Characters.Remove(id); } - private ICharacterRenderer InitializeRendererForCharacter(ICharacter character) + private ICharacterRenderer InitializeRendererForCharacter(EOLib.Domain.Character.Character character) { var renderer = _characterRendererFactory.CreateCharacterRenderer(character); renderer.Initialize(); diff --git a/EndlessClient/Rendering/Character/CharacterStateCache.cs b/EndlessClient/Rendering/Character/CharacterStateCache.cs index b39209ee7..965db4211 100644 --- a/EndlessClient/Rendering/Character/CharacterStateCache.cs +++ b/EndlessClient/Rendering/Character/CharacterStateCache.cs @@ -1,28 +1,29 @@ using AutomaticTypeMapper; -using EOLib.Domain.Character; using Optional; using System; using System.Collections.Generic; using System.Linq; +using DomainCharacter = EOLib.Domain.Character.Character; + namespace EndlessClient.Rendering.Character { - [MappedType(BaseType = typeof(ICharacterStateCache), IsSingleton = true)] + [AutoMappedType(IsSingleton = true)] public class CharacterStateCache : ICharacterStateCache { - public Option MainCharacter { get; private set; } + public Option MainCharacter { get; private set; } - private readonly Dictionary _otherCharacters; + private readonly Dictionary _otherCharacters; private readonly List _deathStartTimes; - public IReadOnlyDictionary OtherCharacters => _otherCharacters; + public IReadOnlyDictionary OtherCharacters => _otherCharacters; public IReadOnlyList DeathStartTimes => _deathStartTimes; public CharacterStateCache() { - MainCharacter = Option.None(); - _otherCharacters = new Dictionary(); + MainCharacter = Option.None(); + _otherCharacters = new Dictionary(); _deathStartTimes = new List(); } @@ -31,12 +32,12 @@ public bool HasCharacterWithID(int id) return _otherCharacters.ContainsKey(id); } - public void UpdateMainCharacterState(ICharacter updatedCharacter) + public void UpdateMainCharacterState(DomainCharacter updatedCharacter) { MainCharacter = Option.Some(updatedCharacter); } - public void UpdateCharacterState(int id, ICharacter updatedCharacter) + public void UpdateCharacterState(int id, DomainCharacter updatedCharacter) { _otherCharacters[id] = updatedCharacter; } @@ -69,7 +70,7 @@ public void ClearAllOtherCharacterStates() public void Reset() { - MainCharacter = Option.None(); + MainCharacter = Option.None(); ClearAllOtherCharacterStates(); } } diff --git a/EndlessClient/Rendering/Character/CharacterTextures.cs b/EndlessClient/Rendering/Character/CharacterTextures.cs index c19576f57..91cde3d69 100644 --- a/EndlessClient/Rendering/Character/CharacterTextures.cs +++ b/EndlessClient/Rendering/Character/CharacterTextures.cs @@ -27,7 +27,7 @@ public CharacterTextures(ICharacterSpriteCalculator characterSpriteCalculator) _characterSpriteCalculator = characterSpriteCalculator; } - public void Refresh(ICharacterRenderProperties characterRenderProperties) + public void Refresh(CharacterRenderProperties characterRenderProperties) { Boots = _characterSpriteCalculator.GetBootsTexture(characterRenderProperties); Armor = _characterSpriteCalculator.GetArmorTexture(characterRenderProperties); diff --git a/EndlessClient/Rendering/Character/ICharacterRenderer.cs b/EndlessClient/Rendering/Character/ICharacterRenderer.cs index 33a448f89..37b2b744b 100644 --- a/EndlessClient/Rendering/Character/ICharacterRenderer.cs +++ b/EndlessClient/Rendering/Character/ICharacterRenderer.cs @@ -1,14 +1,13 @@ -using System; -using EndlessClient.Rendering.Effects; -using EOLib.Domain.Character; +using EndlessClient.Rendering.Effects; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using System; namespace EndlessClient.Rendering.Character { public interface ICharacterRenderer : IDrawable, IUpdateable, IGameComponent, IDisposable, IMapActor, IEffectTarget, ISpellCaster { - ICharacter Character { get; set; } + EOLib.Domain.Character.Character Character { get; set; } new bool Visible { get; set; } diff --git a/EndlessClient/Rendering/Character/ICharacterStateCache.cs b/EndlessClient/Rendering/Character/ICharacterStateCache.cs index fa4f7b5ec..4dba53934 100644 --- a/EndlessClient/Rendering/Character/ICharacterStateCache.cs +++ b/EndlessClient/Rendering/Character/ICharacterStateCache.cs @@ -1,22 +1,23 @@ -using EOLib.Domain.Character; -using Optional; +using Optional; using System.Collections.Generic; +using DomainCharacter = EOLib.Domain.Character.Character; + namespace EndlessClient.Rendering.Character { public interface ICharacterStateCache { - Option MainCharacter { get; } + Option MainCharacter { get; } - IReadOnlyDictionary OtherCharacters { get; } + IReadOnlyDictionary OtherCharacters { get; } IReadOnlyList DeathStartTimes { get; } bool HasCharacterWithID(int id); - void UpdateMainCharacterState(ICharacter updatedCharacter); + void UpdateMainCharacterState(DomainCharacter updatedCharacter); - void UpdateCharacterState(int id, ICharacter updatedCharacter); + void UpdateCharacterState(int id, DomainCharacter updatedCharacter); void RemoveCharacterState(int id); diff --git a/EndlessClient/Rendering/Character/ICharacterTextures.cs b/EndlessClient/Rendering/Character/ICharacterTextures.cs index 72da74635..4d9f06358 100644 --- a/EndlessClient/Rendering/Character/ICharacterTextures.cs +++ b/EndlessClient/Rendering/Character/ICharacterTextures.cs @@ -19,6 +19,6 @@ public interface ICharacterTextures ISpriteSheet Emote { get; } ISpriteSheet Face { get; } - void Refresh(ICharacterRenderProperties characterRenderProperties); + void Refresh(CharacterRenderProperties characterRenderProperties); } } diff --git a/EndlessClient/Rendering/CharacterProperties/ArmorRenderer.cs b/EndlessClient/Rendering/CharacterProperties/ArmorRenderer.cs index c5b2dd65c..65e73b37f 100644 --- a/EndlessClient/Rendering/CharacterProperties/ArmorRenderer.cs +++ b/EndlessClient/Rendering/CharacterProperties/ArmorRenderer.cs @@ -14,7 +14,7 @@ public class ArmorRenderer : BaseCharacterPropertyRenderer public override bool CanRender => _armorSheet.HasTexture && _renderProperties.ArmorGraphic != 0; - public ArmorRenderer(ICharacterRenderProperties renderProperties, + public ArmorRenderer(CharacterRenderProperties renderProperties, ISpriteSheet armorSheet) : base(renderProperties) { diff --git a/EndlessClient/Rendering/CharacterProperties/BaseCharacterPropertyRenderer.cs b/EndlessClient/Rendering/CharacterProperties/BaseCharacterPropertyRenderer.cs index 7b7d3498c..beb5f907b 100644 --- a/EndlessClient/Rendering/CharacterProperties/BaseCharacterPropertyRenderer.cs +++ b/EndlessClient/Rendering/CharacterProperties/BaseCharacterPropertyRenderer.cs @@ -9,7 +9,7 @@ namespace EndlessClient.Rendering.CharacterProperties { public abstract class BaseCharacterPropertyRenderer : ICharacterPropertyRenderer { - protected readonly ICharacterRenderProperties _renderProperties; + protected readonly CharacterRenderProperties _renderProperties; public abstract bool CanRender { get; } @@ -17,7 +17,7 @@ public abstract class BaseCharacterPropertyRenderer : ICharacterPropertyRenderer protected virtual bool ShouldFlip => _renderProperties.IsFacing(EODirection.Up, EODirection.Right); - protected BaseCharacterPropertyRenderer(ICharacterRenderProperties renderProperties) + protected BaseCharacterPropertyRenderer(CharacterRenderProperties renderProperties) { _renderProperties = renderProperties; LayerDepth = 1.0f; diff --git a/EndlessClient/Rendering/CharacterProperties/BootsRenderer.cs b/EndlessClient/Rendering/CharacterProperties/BootsRenderer.cs index 06e0e8a7a..713264aaa 100644 --- a/EndlessClient/Rendering/CharacterProperties/BootsRenderer.cs +++ b/EndlessClient/Rendering/CharacterProperties/BootsRenderer.cs @@ -14,7 +14,7 @@ public class BootsRenderer : BaseCharacterPropertyRenderer public override bool CanRender => _bootsSheet.HasTexture && _renderProperties.BootsGraphic != 0; - public BootsRenderer(ICharacterRenderProperties renderProperties, + public BootsRenderer(CharacterRenderProperties renderProperties, ISpriteSheet bootsSheet) : base(renderProperties) { diff --git a/EndlessClient/Rendering/CharacterProperties/CharacterPropertyRendererBuilder.cs b/EndlessClient/Rendering/CharacterProperties/CharacterPropertyRendererBuilder.cs index 10e9ff9e4..986cbccbb 100644 --- a/EndlessClient/Rendering/CharacterProperties/CharacterPropertyRendererBuilder.cs +++ b/EndlessClient/Rendering/CharacterProperties/CharacterPropertyRendererBuilder.cs @@ -30,7 +30,7 @@ public CharacterPropertyRendererBuilder(IEIFFileProvider eifFileProvider, } public IEnumerable BuildList(ICharacterTextures textures, - ICharacterRenderProperties renderProperties) + CharacterRenderProperties renderProperties) { const float BaseLayer = 0.00001f; @@ -65,12 +65,12 @@ public IEnumerable BuildList(ICharacterTextures text }; } - private bool IsShieldBehindCharacter(ICharacterRenderProperties renderProperties) + private bool IsShieldBehindCharacter(CharacterRenderProperties renderProperties) { return renderProperties.IsFacing(EODirection.Right, EODirection.Down) && EIFFile.IsShieldOnBack(renderProperties.ShieldGraphic); } - private bool IsWeaponBehindCharacter(ICharacterRenderProperties renderProperties) + private bool IsWeaponBehindCharacter(CharacterRenderProperties renderProperties) { var weaponInfo = EIFFile.FirstOrDefault( x => x.Type == ItemType.Weapon && @@ -83,7 +83,7 @@ private bool IsWeaponBehindCharacter(ICharacterRenderProperties renderProperties return pass1 || pass2 || pass3; } - private HatMaskType GetHatMaskType(ICharacterRenderProperties renderProperties) + private HatMaskType GetHatMaskType(CharacterRenderProperties renderProperties) { var hatInfo = EIFFile.FirstOrDefault( x => x.Type == ItemType.Hat && diff --git a/EndlessClient/Rendering/CharacterProperties/EmoteRenderer.cs b/EndlessClient/Rendering/CharacterProperties/EmoteRenderer.cs index a1cf5a5d6..a1229803e 100644 --- a/EndlessClient/Rendering/CharacterProperties/EmoteRenderer.cs +++ b/EndlessClient/Rendering/CharacterProperties/EmoteRenderer.cs @@ -16,7 +16,7 @@ public class EmoteRenderer : BaseCharacterPropertyRenderer protected override bool ShouldFlip => false; - public EmoteRenderer(ICharacterRenderProperties renderProperties, + public EmoteRenderer(CharacterRenderProperties renderProperties, ISpriteSheet emoteSheet, ISpriteSheet skinSheet) : base(renderProperties) @@ -28,6 +28,9 @@ public EmoteRenderer(ICharacterRenderProperties renderProperties, public override void Render(SpriteBatch spriteBatch, Rectangle parentCharacterDrawArea) { + if (_emoteSheet is EmptySpriteSheet) + return; + var skinLoc = _skinRenderLocationCalculator.CalculateDrawLocationOfCharacterSkin(_skinSheet.SourceRectangle, parentCharacterDrawArea); var emotePos = new Vector2(skinLoc.X - 15, parentCharacterDrawArea.Y - _emoteSheet.SheetTexture.Height); Render(spriteBatch, _emoteSheet, emotePos, 128); diff --git a/EndlessClient/Rendering/CharacterProperties/FaceRenderer.cs b/EndlessClient/Rendering/CharacterProperties/FaceRenderer.cs index 97ef88c5d..b0c295efd 100644 --- a/EndlessClient/Rendering/CharacterProperties/FaceRenderer.cs +++ b/EndlessClient/Rendering/CharacterProperties/FaceRenderer.cs @@ -19,7 +19,7 @@ public class FaceRenderer : BaseCharacterPropertyRenderer _renderProperties.Emote != Emote.LevelUp && _renderProperties.Emote != Emote.MusicNotes; - public FaceRenderer(ICharacterRenderProperties renderProperties, + public FaceRenderer(CharacterRenderProperties renderProperties, ISpriteSheet faceSheet, ISpriteSheet skinSheet) : base(renderProperties) diff --git a/EndlessClient/Rendering/CharacterProperties/HairRenderLocationCalculator.cs b/EndlessClient/Rendering/CharacterProperties/HairRenderLocationCalculator.cs index 62664c4ee..772919588 100644 --- a/EndlessClient/Rendering/CharacterProperties/HairRenderLocationCalculator.cs +++ b/EndlessClient/Rendering/CharacterProperties/HairRenderLocationCalculator.cs @@ -8,9 +8,9 @@ namespace EndlessClient.Rendering.CharacterProperties { public class HairRenderLocationCalculator { - private readonly ICharacterRenderProperties _renderProperties; + private readonly CharacterRenderProperties _renderProperties; - public HairRenderLocationCalculator(ICharacterRenderProperties renderProperties) + public HairRenderLocationCalculator(CharacterRenderProperties renderProperties) { _renderProperties = renderProperties; } diff --git a/EndlessClient/Rendering/CharacterProperties/HairRenderer.cs b/EndlessClient/Rendering/CharacterProperties/HairRenderer.cs index 46446969d..4bae8d260 100644 --- a/EndlessClient/Rendering/CharacterProperties/HairRenderer.cs +++ b/EndlessClient/Rendering/CharacterProperties/HairRenderer.cs @@ -1,7 +1,5 @@ using EndlessClient.Rendering.Sprites; -using EOLib; using EOLib.Domain.Character; -using EOLib.Domain.Extensions; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -14,7 +12,7 @@ public class HairRenderer : BaseCharacterPropertyRenderer public override bool CanRender => _hairSheet.HasTexture && _renderProperties.HairStyle != 0; - public HairRenderer(ICharacterRenderProperties renderProperties, + public HairRenderer(CharacterRenderProperties renderProperties, ISpriteSheet hairSheet) : base(renderProperties) { diff --git a/EndlessClient/Rendering/CharacterProperties/HatRenderer.cs b/EndlessClient/Rendering/CharacterProperties/HatRenderer.cs index 662c8b50b..f6b4df50f 100644 --- a/EndlessClient/Rendering/CharacterProperties/HatRenderer.cs +++ b/EndlessClient/Rendering/CharacterProperties/HatRenderer.cs @@ -19,7 +19,7 @@ public class HatRenderer : BaseCharacterPropertyRenderer public override bool CanRender => _hatSheet.HasTexture && _renderProperties.HatGraphic != 0; public HatRenderer(IShaderProvider shaderProvider, - ICharacterRenderProperties renderProperties, + CharacterRenderProperties renderProperties, ISpriteSheet hatSheet, ISpriteSheet hairSheet) : base(renderProperties) diff --git a/EndlessClient/Rendering/CharacterProperties/ICharacterPropertyRendererBuilder.cs b/EndlessClient/Rendering/CharacterProperties/ICharacterPropertyRendererBuilder.cs index f642551dd..2b03ff394 100644 --- a/EndlessClient/Rendering/CharacterProperties/ICharacterPropertyRendererBuilder.cs +++ b/EndlessClient/Rendering/CharacterProperties/ICharacterPropertyRendererBuilder.cs @@ -7,6 +7,6 @@ namespace EndlessClient.Rendering.CharacterProperties public interface ICharacterPropertyRendererBuilder { IEnumerable BuildList(ICharacterTextures characterTextures, - ICharacterRenderProperties renderProperties); + CharacterRenderProperties renderProperties); } } \ No newline at end of file diff --git a/EndlessClient/Rendering/CharacterProperties/ShieldRenderer.cs b/EndlessClient/Rendering/CharacterProperties/ShieldRenderer.cs index fe9e75935..eda25b30e 100644 --- a/EndlessClient/Rendering/CharacterProperties/ShieldRenderer.cs +++ b/EndlessClient/Rendering/CharacterProperties/ShieldRenderer.cs @@ -21,7 +21,7 @@ public class ShieldRenderer : BaseCharacterPropertyRenderer //? _isShieldOnBack && _renderProperties.IsFacing(EODirection.Left, EODirection.Right) //: base.ShouldFlip; - public ShieldRenderer(ICharacterRenderProperties renderProperties, + public ShieldRenderer(CharacterRenderProperties renderProperties, ISpriteSheet shieldSheet, bool isShieldOnBack) : base(renderProperties) diff --git a/EndlessClient/Rendering/CharacterProperties/SkinRenderLocationCalculator.cs b/EndlessClient/Rendering/CharacterProperties/SkinRenderLocationCalculator.cs index dcef8372b..7d3f8f399 100644 --- a/EndlessClient/Rendering/CharacterProperties/SkinRenderLocationCalculator.cs +++ b/EndlessClient/Rendering/CharacterProperties/SkinRenderLocationCalculator.cs @@ -8,9 +8,9 @@ namespace EndlessClient.Rendering.CharacterProperties { public class SkinRenderLocationCalculator { - private readonly ICharacterRenderProperties _renderProperties; + private readonly CharacterRenderProperties _renderProperties; - public SkinRenderLocationCalculator(ICharacterRenderProperties renderProperties) + public SkinRenderLocationCalculator(CharacterRenderProperties renderProperties) { _renderProperties = renderProperties; } diff --git a/EndlessClient/Rendering/CharacterProperties/SkinRenderer.cs b/EndlessClient/Rendering/CharacterProperties/SkinRenderer.cs index 955c8166e..5325fe240 100644 --- a/EndlessClient/Rendering/CharacterProperties/SkinRenderer.cs +++ b/EndlessClient/Rendering/CharacterProperties/SkinRenderer.cs @@ -14,7 +14,7 @@ public class SkinRenderer : BaseCharacterPropertyRenderer public override bool CanRender => true; - public SkinRenderer(ICharacterRenderProperties renderProperties, + public SkinRenderer(CharacterRenderProperties renderProperties, ISpriteSheet skinSheet) : base(renderProperties) { diff --git a/EndlessClient/Rendering/CharacterProperties/WeaponRenderer.cs b/EndlessClient/Rendering/CharacterProperties/WeaponRenderer.cs index 7ad6dd4e7..6dc37a046 100644 --- a/EndlessClient/Rendering/CharacterProperties/WeaponRenderer.cs +++ b/EndlessClient/Rendering/CharacterProperties/WeaponRenderer.cs @@ -14,7 +14,7 @@ public class WeaponRenderer : BaseCharacterPropertyRenderer public override bool CanRender => _weaponSheet.HasTexture && _renderProperties.WeaponGraphic != 0; - public WeaponRenderer(ICharacterRenderProperties renderProperties, + public WeaponRenderer(CharacterRenderProperties renderProperties, ISpriteSheet weaponSheet) : base(renderProperties) { diff --git a/EndlessClient/Rendering/Factories/CharacterRendererFactory.cs b/EndlessClient/Rendering/Factories/CharacterRendererFactory.cs index b6015b1af..a8f768598 100644 --- a/EndlessClient/Rendering/Factories/CharacterRendererFactory.cs +++ b/EndlessClient/Rendering/Factories/CharacterRendererFactory.cs @@ -62,7 +62,7 @@ public CharacterRendererFactory(INativeGraphicsManager nativeGraphicsManager, _userInputProvider = userInputProvider; } - public ICharacterRenderer CreateCharacterRenderer(ICharacter character) + public ICharacterRenderer CreateCharacterRenderer(EOLib.Domain.Character.Character character) { return new CharacterRenderer( _nativeGraphicsManager, diff --git a/EndlessClient/Rendering/Factories/ICharacterRendererFactory.cs b/EndlessClient/Rendering/Factories/ICharacterRendererFactory.cs index ce080db7d..f79dd0852 100644 --- a/EndlessClient/Rendering/Factories/ICharacterRendererFactory.cs +++ b/EndlessClient/Rendering/Factories/ICharacterRendererFactory.cs @@ -1,10 +1,9 @@ using EndlessClient.Rendering.Character; -using EOLib.Domain.Character; namespace EndlessClient.Rendering.Factories { public interface ICharacterRendererFactory { - ICharacterRenderer CreateCharacterRenderer(ICharacter character); + ICharacterRenderer CreateCharacterRenderer(EOLib.Domain.Character.Character character); } } diff --git a/EndlessClient/Rendering/Map/DynamicMapObjectUpdater.cs b/EndlessClient/Rendering/Map/DynamicMapObjectUpdater.cs index 902e8d4d3..9ff15e212 100644 --- a/EndlessClient/Rendering/Map/DynamicMapObjectUpdater.cs +++ b/EndlessClient/Rendering/Map/DynamicMapObjectUpdater.cs @@ -20,7 +20,7 @@ public class DynamicMapObjectUpdater : IDynamicMapObjectUpdater private class DoorTimePair { - public IWarp Door { get; set; } + public Warp Door { get; set; } public DateTime OpenTime { get; set; } } @@ -114,7 +114,7 @@ private void CheckForObjectClicks() { var cellState = new MapCellState { - Sign = Option.Some(new Sign(sign)), + Sign = Option.Some(new Sign(sign)), Coordinate = new MapCoordinate(sign.X, sign.Y) }; _mapInteractionController.LeftClick(cellState, Option.None()); diff --git a/EndlessClient/Rendering/Map/IMapRenderDistanceCalculator.cs b/EndlessClient/Rendering/Map/IMapRenderDistanceCalculator.cs index 5326d8940..6d976aafa 100644 --- a/EndlessClient/Rendering/Map/IMapRenderDistanceCalculator.cs +++ b/EndlessClient/Rendering/Map/IMapRenderDistanceCalculator.cs @@ -1,10 +1,9 @@ -using EOLib.Domain.Character; -using EOLib.IO.Map; +using EOLib.IO.Map; namespace EndlessClient.Rendering.Map { public interface IMapRenderDistanceCalculator { - MapRenderBounds CalculateRenderBounds(ICharacter character, IMapFile currentMap); + MapRenderBounds CalculateRenderBounds(EOLib.Domain.Character.Character character, IMapFile currentMap); } } diff --git a/EndlessClient/Rendering/Map/MapRenderDistanceCalculator.cs b/EndlessClient/Rendering/Map/MapRenderDistanceCalculator.cs index b54b888f4..558bb9ec3 100644 --- a/EndlessClient/Rendering/Map/MapRenderDistanceCalculator.cs +++ b/EndlessClient/Rendering/Map/MapRenderDistanceCalculator.cs @@ -1,16 +1,15 @@ -using System; -using AutomaticTypeMapper; -using EOLib.Domain.Character; +using AutomaticTypeMapper; using EOLib.IO.Map; +using System; namespace EndlessClient.Rendering.Map { - [MappedType(BaseType = typeof(IMapRenderDistanceCalculator))] + [AutoMappedType] public class MapRenderDistanceCalculator : IMapRenderDistanceCalculator { private const int DEFAULT_BOUNDS_DISTANCE = 22; - public MapRenderBounds CalculateRenderBounds(ICharacter character, IMapFile currentMap) + public MapRenderBounds CalculateRenderBounds(EOLib.Domain.Character.Character character, IMapFile currentMap) { var firstRow = Math.Max(character.RenderProperties.MapY - DEFAULT_BOUNDS_DISTANCE, 0); var lastRow = Math.Min(character.RenderProperties.MapY + DEFAULT_BOUNDS_DISTANCE, currentMap.Properties.Height); diff --git a/EndlessClient/Rendering/Map/MapRenderer.cs b/EndlessClient/Rendering/Map/MapRenderer.cs index 576b39fb6..a84a0b16d 100644 --- a/EndlessClient/Rendering/Map/MapRenderer.cs +++ b/EndlessClient/Rendering/Map/MapRenderer.cs @@ -310,7 +310,7 @@ private Vector2 GetGroundLayerDrawPosition() ViewportHeightFactor - (props.MapY * 16) - (props.MapX * 16) - charOffY); } - private int GetAlphaForCoordinates(int objX, int objY, ICharacter character) + private int GetAlphaForCoordinates(int objX, int objY, EOLib.Domain.Character.Character character) { if (!_configurationProvider.ShowTransition) { diff --git a/EndlessClient/Rendering/MouseCursorRenderer.cs b/EndlessClient/Rendering/MouseCursorRenderer.cs index a39f6f1fe..2c0f3a0be 100644 --- a/EndlessClient/Rendering/MouseCursorRenderer.cs +++ b/EndlessClient/Rendering/MouseCursorRenderer.cs @@ -177,7 +177,7 @@ private void UpdateCursorSourceRectangle(IMapCellState cellState) UpdateCursorIndexForTileSpec(cellState.TileSpec); if (!cellState.Items.Any()) - UpdateMapItemLabel(Option.None()); + UpdateMapItemLabel(Option.None()); _startClickTime.MatchSome(st => { @@ -211,7 +211,7 @@ private static Vector2 GetDrawCoordinatesFromGridUnits(int x, int y, int cOffX, return new Vector2(x*32 - y*32 + 288 - cOffX, y*16 + x*16 + 144 - cOffY); } - private void UpdateMapItemLabel(Option item) + private void UpdateMapItemLabel(Option item) { item.Match( some: i => diff --git a/EndlessClient/Rendering/NPC/INPCRenderer.cs b/EndlessClient/Rendering/NPC/INPCRenderer.cs index 27c0ccddc..a95e8e09b 100644 --- a/EndlessClient/Rendering/NPC/INPCRenderer.cs +++ b/EndlessClient/Rendering/NPC/INPCRenderer.cs @@ -1,6 +1,5 @@ using System; using EndlessClient.Rendering.Effects; -using EOLib.Domain.NPC; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -8,7 +7,7 @@ namespace EndlessClient.Rendering.NPC { public interface INPCRenderer : IDrawable, IUpdateable, IGameComponent, IDisposable, IMapActor, IEffectTarget { - INPC NPC { get; set; } + EOLib.Domain.NPC.NPC NPC { get; set; } bool IsDead { get; } diff --git a/EndlessClient/Rendering/NPC/NPCAnimator.cs b/EndlessClient/Rendering/NPC/NPCAnimator.cs index 6bf324aa6..f012b9844 100644 --- a/EndlessClient/Rendering/NPC/NPCAnimator.cs +++ b/EndlessClient/Rendering/NPC/NPCAnimator.cs @@ -116,7 +116,7 @@ private void AnimateNPCAttacking() _npcStartAttackingTimes.RemoveAll(npcsDoneAttacking.Contains); } - private static INPC AnimateOneWalkFrame(INPC npc) + private static EOLib.Domain.NPC.NPC AnimateOneWalkFrame(EOLib.Domain.NPC.NPC npc) { var nextFrameNPC = npc.WithNextWalkFrame(); diff --git a/EndlessClient/Rendering/NPC/NPCCache.cs b/EndlessClient/Rendering/NPC/NPCCache.cs index de3dcb311..94c1e3fe4 100644 --- a/EndlessClient/Rendering/NPC/NPCCache.cs +++ b/EndlessClient/Rendering/NPC/NPCCache.cs @@ -1,19 +1,18 @@ -using System.Collections.Generic; -using AutomaticTypeMapper; -using EOLib.Domain.NPC; +using AutomaticTypeMapper; +using System.Collections.Generic; namespace EndlessClient.Rendering.NPC { [MappedType(BaseType = typeof(INPCStateCache), IsSingleton = true)] public class NPCStateCache : INPCStateCache { - private readonly Dictionary _npcStates; + private readonly Dictionary _npcStates; - public IReadOnlyDictionary NPCStates => _npcStates; + public IReadOnlyDictionary NPCStates => _npcStates; public NPCStateCache() { - _npcStates = new Dictionary(); + _npcStates = new Dictionary(); } public bool HasNPCStateWithIndex(int index) @@ -21,7 +20,7 @@ public bool HasNPCStateWithIndex(int index) return _npcStates.ContainsKey(index) && _npcStates[index] != null; } - public void UpdateNPCState(int index, INPC npc) + public void UpdateNPCState(int index, EOLib.Domain.NPC.NPC npc) { if (!_npcStates.ContainsKey(index)) _npcStates.Add(index, npc); @@ -43,11 +42,11 @@ public void Reset() public interface INPCStateCache { - IReadOnlyDictionary NPCStates { get; } + IReadOnlyDictionary NPCStates { get; } bool HasNPCStateWithIndex(int index); - void UpdateNPCState(int index, INPC npc); + void UpdateNPCState(int index, EOLib.Domain.NPC.NPC npc); void RemoveStateByIndex(int index); diff --git a/EndlessClient/Rendering/NPC/NPCRenderer.cs b/EndlessClient/Rendering/NPC/NPCRenderer.cs index 8691df572..d06333711 100644 --- a/EndlessClient/Rendering/NPC/NPCRenderer.cs +++ b/EndlessClient/Rendering/NPC/NPCRenderer.cs @@ -1,6 +1,4 @@ -using System; -using System.Linq; -using EndlessClient.Controllers; +using EndlessClient.Controllers; using EndlessClient.GameExecution; using EndlessClient.HUD.Spells; using EndlessClient.Input; @@ -18,6 +16,8 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Optional; +using System; +using System.Linq; using XNAControls; namespace EndlessClient.Rendering.NPC @@ -63,7 +63,7 @@ public class NPCRenderer : DrawableGameComponent, INPCRenderer public Rectangle MapProjectedDrawArea { get; private set; } - public INPC NPC { get; set; } + public EOLib.Domain.NPC.NPC NPC { get; set; } public bool IsDead { get; private set; } @@ -81,7 +81,7 @@ public NPCRenderer(INativeGraphicsManager nativeGraphicsManager, IMapInteractionController mapInteractionController, IUserInputProvider userInputProvider, ISpellSlotDataProvider spellSlotDataProvider, - INPC initialNPC) + EOLib.Domain.NPC.NPC initialNPC) : base((Game)endlessGameProvider.Game) { NPC = initialNPC; diff --git a/EndlessClient/Rendering/NPC/NPCRendererFactory.cs b/EndlessClient/Rendering/NPC/NPCRendererFactory.cs index 78199c8ff..b676d5c41 100644 --- a/EndlessClient/Rendering/NPC/NPCRendererFactory.cs +++ b/EndlessClient/Rendering/NPC/NPCRendererFactory.cs @@ -7,7 +7,6 @@ using EndlessClient.Rendering.Chat; using EndlessClient.Rendering.Factories; using EndlessClient.Rendering.Sprites; -using EOLib.Domain.NPC; using EOLib.Graphics; using EOLib.IO.Repositories; @@ -56,7 +55,7 @@ public NPCRendererFactory(INativeGraphicsManager nativeGraphicsManager, _spellSlotDataProvider = spellSlotDataProvider; } - public INPCRenderer CreateRendererFor(INPC npc) + public INPCRenderer CreateRendererFor(EOLib.Domain.NPC.NPC npc) { return new NPCRenderer(_nativeGraphicsManager, _endlessGameProvider, @@ -76,6 +75,6 @@ public INPCRenderer CreateRendererFor(INPC npc) public interface INPCRendererFactory { - INPCRenderer CreateRendererFor(INPC npc); + INPCRenderer CreateRendererFor(EOLib.Domain.NPC.NPC npc); } } diff --git a/EndlessClient/Rendering/NPC/NPCRendererUpdater.cs b/EndlessClient/Rendering/NPC/NPCRendererUpdater.cs index 743dc3960..f366087b2 100644 --- a/EndlessClient/Rendering/NPC/NPCRendererUpdater.cs +++ b/EndlessClient/Rendering/NPC/NPCRendererUpdater.cs @@ -67,7 +67,7 @@ private void CreateAndCacheNPCRenderers() } } - private void CreateAndCacheRendererForNPC(INPC npc) + private void CreateAndCacheRendererForNPC(EOLib.Domain.NPC.NPC npc) { _npcStateCache.UpdateNPCState(npc.Index, npc); @@ -84,7 +84,7 @@ private void CreateAndCacheRendererForNPC(INPC npc) _npcRendererRepository.NPCRenderers.Add(npc.Index, renderer); } - private void UpdateCachedNPC(INPC npc) + private void UpdateCachedNPC(EOLib.Domain.NPC.NPC npc) { _npcRendererRepository.NPCRenderers[npc.Index].NPC = npc; _npcStateCache.UpdateNPCState(npc.Index, npc); diff --git a/EndlessClient/Rendering/RenderOffsetCalculator.cs b/EndlessClient/Rendering/RenderOffsetCalculator.cs index d0a4b950d..4af28bdc9 100644 --- a/EndlessClient/Rendering/RenderOffsetCalculator.cs +++ b/EndlessClient/Rendering/RenderOffsetCalculator.cs @@ -14,31 +14,31 @@ public class RenderOffsetCalculator : IRenderOffsetCalculator private const int WalkWidthFactor = WidthFactor/4; private const int WalkHeightFactor = HeightFactor/4; - public int CalculateOffsetX(ICharacterRenderProperties properties) + public int CalculateOffsetX(CharacterRenderProperties properties) { return properties.MapX*WidthFactor - properties.MapY*WidthFactor + CalculateWalkAdjustX(properties); } - public int CalculateWalkAdjustX(ICharacterRenderProperties properties) + public int CalculateWalkAdjustX(CharacterRenderProperties properties) { var multiplier = properties.IsFacing(EODirection.Left, EODirection.Down) ? -1 : 1; var walkAdjust = properties.IsActing(CharacterActionState.Walking) ? WalkWidthFactor * properties.ActualWalkFrame : 0; return walkAdjust * multiplier; } - public int CalculateOffsetY(ICharacterRenderProperties properties) + public int CalculateOffsetY(CharacterRenderProperties properties) { return properties.MapX*HeightFactor + properties.MapY*HeightFactor + CalculateWalkAdjustY(properties); } - public int CalculateWalkAdjustY(ICharacterRenderProperties properties) + public int CalculateWalkAdjustY(CharacterRenderProperties properties) { var multiplier = properties.IsFacing(EODirection.Left, EODirection.Up) ? -1 : 1; var walkAdjust = properties.IsActing(CharacterActionState.Walking) ? WalkHeightFactor * properties.ActualWalkFrame : 0; return walkAdjust * multiplier; } - public int CalculateOffsetX(INPC npc) + public int CalculateOffsetX(EOLib.Domain.NPC.NPC npc) { var multiplier = npc.IsFacing(EODirection.Left, EODirection.Down) ? -1 : 1; var walkAdjust = npc.IsActing(NPCActionState.Walking) ? WalkWidthFactor * npc.GetWalkFrame() : 0; @@ -47,7 +47,7 @@ public int CalculateOffsetX(INPC npc) return npc.X*WidthFactor - npc.Y*WidthFactor + walkAdjust*multiplier; } - public int CalculateOffsetY(INPC npc) + public int CalculateOffsetY(EOLib.Domain.NPC.NPC npc) { var multiplier = npc.IsFacing(EODirection.Left, EODirection.Up) ? -1 : 1; var walkAdjust = npc.IsActing(NPCActionState.Walking) ? WalkHeightFactor * npc.GetWalkFrame() : 0; @@ -59,14 +59,14 @@ public int CalculateOffsetY(INPC npc) public interface IRenderOffsetCalculator { - int CalculateOffsetX(ICharacterRenderProperties properties); - int CalculateWalkAdjustX(ICharacterRenderProperties properties); + int CalculateOffsetX(CharacterRenderProperties properties); + int CalculateWalkAdjustX(CharacterRenderProperties properties); - int CalculateOffsetY(ICharacterRenderProperties properties); - int CalculateWalkAdjustY(ICharacterRenderProperties properties); + int CalculateOffsetY(CharacterRenderProperties properties); + int CalculateWalkAdjustY(CharacterRenderProperties properties); - int CalculateOffsetX(INPC npc); + int CalculateOffsetX(EOLib.Domain.NPC.NPC npc); - int CalculateOffsetY(INPC npc); + int CalculateOffsetY(EOLib.Domain.NPC.NPC npc); } } \ No newline at end of file diff --git a/EndlessClient/Rendering/Sprites/CharacterSpriteCalculator.cs b/EndlessClient/Rendering/Sprites/CharacterSpriteCalculator.cs index 8a492b124..2c12dbe2d 100644 --- a/EndlessClient/Rendering/Sprites/CharacterSpriteCalculator.cs +++ b/EndlessClient/Rendering/Sprites/CharacterSpriteCalculator.cs @@ -26,7 +26,7 @@ public CharacterSpriteCalculator(INativeGraphicsManager gfxManager, _eifFileProvider = eifFileProvider; } - public ISpriteSheet GetBootsTexture(ICharacterRenderProperties characterRenderProperties) + public ISpriteSheet GetBootsTexture(CharacterRenderProperties characterRenderProperties) { if (characterRenderProperties.BootsGraphic == 0) return new EmptySpriteSheet(); @@ -66,7 +66,7 @@ public ISpriteSheet GetBootsTexture(ICharacterRenderProperties characterRenderPr return new SpriteSheet(_gfxManager.TextureFromResource(gfxFile, gfxNumber, true)); } - public ISpriteSheet GetArmorTexture(ICharacterRenderProperties characterRenderProperties) + public ISpriteSheet GetArmorTexture(CharacterRenderProperties characterRenderProperties) { if (characterRenderProperties.ArmorGraphic == 0) return new EmptySpriteSheet(); @@ -126,7 +126,7 @@ public ISpriteSheet GetArmorTexture(ICharacterRenderProperties characterRenderPr return new SpriteSheet(_gfxManager.TextureFromResource(gfxFile, gfxNumber, true)); } - public ISpriteSheet GetHatTexture(ICharacterRenderProperties characterRenderProperties) + public ISpriteSheet GetHatTexture(CharacterRenderProperties characterRenderProperties) { if (characterRenderProperties.HatGraphic == 0) return new EmptySpriteSheet(); @@ -140,7 +140,7 @@ public ISpriteSheet GetHatTexture(ICharacterRenderProperties characterRenderProp return new SpriteSheet(_gfxManager.TextureFromResource(gfxFile, gfxNumber, true)); } - public ISpriteSheet GetShieldTexture(ICharacterRenderProperties characterRenderProperties) + public ISpriteSheet GetShieldTexture(CharacterRenderProperties characterRenderProperties) { if (characterRenderProperties.ShieldGraphic == 0) return new EmptySpriteSheet(); @@ -197,7 +197,7 @@ public ISpriteSheet GetShieldTexture(ICharacterRenderProperties characterRenderP return new SpriteSheet(_gfxManager.TextureFromResource(gfxFile, gfxNumber, true)); } - public ISpriteSheet[] GetWeaponTextures(ICharacterRenderProperties characterRenderProperties) + public ISpriteSheet[] GetWeaponTextures(CharacterRenderProperties characterRenderProperties) { var retTextures = new ISpriteSheet[] { new EmptySpriteSheet(), new EmptySpriteSheet() }; if (characterRenderProperties.WeaponGraphic == 0) @@ -272,7 +272,7 @@ public ISpriteSheet[] GetWeaponTextures(ICharacterRenderProperties characterRend return retTextures; } - public ISpriteSheet GetSkinTexture(ICharacterRenderProperties characterRenderProperties) + public ISpriteSheet GetSkinTexture(CharacterRenderProperties characterRenderProperties) { const int SheetRows = 7; var sheetColumns = 4; @@ -347,7 +347,7 @@ public ISpriteSheet GetSkinTexture(ICharacterRenderProperties characterRenderPro return new SpriteSheet(texture, sourceArea); } - public ISpriteSheet GetHairTexture(ICharacterRenderProperties characterRenderProperties) + public ISpriteSheet GetHairTexture(CharacterRenderProperties characterRenderProperties) { // Use dummy rectangle for no hair so hats are still correctly aligned var hairStyle = characterRenderProperties.HairStyle == 0 ? 1 : characterRenderProperties.HairStyle; @@ -363,7 +363,7 @@ public ISpriteSheet GetHairTexture(ICharacterRenderProperties characterRenderPro : new SpriteSheet(hairTexture); } - public ISpriteSheet GetFaceTexture(ICharacterRenderProperties characterRenderProperties) + public ISpriteSheet GetFaceTexture(CharacterRenderProperties characterRenderProperties) { if (characterRenderProperties.EmoteFrame < 0 || characterRenderProperties.Emote == Emote.Trade || @@ -391,7 +391,7 @@ public ISpriteSheet GetFaceTexture(ICharacterRenderProperties characterRenderPro return new SpriteSheet(texture, sourceRectangle); } - public ISpriteSheet GetEmoteTexture(ICharacterRenderProperties characterRenderProperties) + public ISpriteSheet GetEmoteTexture(CharacterRenderProperties characterRenderProperties) { if (characterRenderProperties.Emote == 0 || characterRenderProperties.EmoteFrame < 0) return new EmptySpriteSheet(); @@ -496,7 +496,7 @@ private int GetOffsetBasedOnState(WeaponSpriteType type) return 1; } - private bool BowIsEquipped(ICharacterRenderProperties characterRenderProperties) + private bool BowIsEquipped(CharacterRenderProperties characterRenderProperties) { if (EIFFile == null) return false; diff --git a/EndlessClient/Rendering/Sprites/ICharacterSpriteCalculator.cs b/EndlessClient/Rendering/Sprites/ICharacterSpriteCalculator.cs index 986819f4c..70275c6c1 100644 --- a/EndlessClient/Rendering/Sprites/ICharacterSpriteCalculator.cs +++ b/EndlessClient/Rendering/Sprites/ICharacterSpriteCalculator.cs @@ -4,15 +4,15 @@ namespace EndlessClient.Rendering.Sprites { public interface ICharacterSpriteCalculator { - ISpriteSheet GetBootsTexture(ICharacterRenderProperties _characterRenderProperties); - ISpriteSheet GetArmorTexture(ICharacterRenderProperties _characterRenderProperties); - ISpriteSheet GetHatTexture(ICharacterRenderProperties _characterRenderProperties); - ISpriteSheet GetShieldTexture(ICharacterRenderProperties _characterRenderProperties); - ISpriteSheet[] GetWeaponTextures(ICharacterRenderProperties _characterRenderProperties); + ISpriteSheet GetBootsTexture(CharacterRenderProperties _characterRenderProperties); + ISpriteSheet GetArmorTexture(CharacterRenderProperties _characterRenderProperties); + ISpriteSheet GetHatTexture(CharacterRenderProperties _characterRenderProperties); + ISpriteSheet GetShieldTexture(CharacterRenderProperties _characterRenderProperties); + ISpriteSheet[] GetWeaponTextures(CharacterRenderProperties _characterRenderProperties); - ISpriteSheet GetSkinTexture(ICharacterRenderProperties _characterRenderProperties); - ISpriteSheet GetHairTexture(ICharacterRenderProperties _characterRenderProperties); - ISpriteSheet GetFaceTexture(ICharacterRenderProperties _characterRenderProperties); - ISpriteSheet GetEmoteTexture(ICharacterRenderProperties _characterRenderProperties); + ISpriteSheet GetSkinTexture(CharacterRenderProperties _characterRenderProperties); + ISpriteSheet GetHairTexture(CharacterRenderProperties _characterRenderProperties); + ISpriteSheet GetFaceTexture(CharacterRenderProperties _characterRenderProperties); + ISpriteSheet GetEmoteTexture(CharacterRenderProperties _characterRenderProperties); } } diff --git a/EndlessClient/Test/CharacterStateTest.cs b/EndlessClient/Test/CharacterStateTest.cs index 7e4b757a5..de51ab072 100644 --- a/EndlessClient/Test/CharacterStateTest.cs +++ b/EndlessClient/Test/CharacterStateTest.cs @@ -6,6 +6,7 @@ using EndlessClient.Rendering.Factories; using EOLib; using EOLib.Domain.Character; +using EOLib.Domain.Extensions; using EOLib.IO; using EOLib.IO.Extensions; using EOLib.IO.Pub; @@ -43,7 +44,7 @@ static CharacterStateTest() private readonly ICharacterRendererFactory _characterRendererFactory; private readonly IEIFFileProvider _eifFileProvider; - private ICharacterRenderProperties _baseProperties; + private CharacterRenderProperties _baseProperties; private readonly Dictionary _itemIndices; private readonly List _renderersForDifferentStates; @@ -70,11 +71,11 @@ public override void Initialize() { DrawOrder = 0; - _baseProperties = new CharacterRenderProperties(); + _baseProperties = new CharacterRenderProperties.Builder().ToImmutable(); foreach (var displayState in _allDisplayStates) { var props = GetRenderPropertiesForState(displayState); - _renderersForDifferentStates.Add(_characterRendererFactory.CreateCharacterRenderer(new Character().WithRenderProperties(props))); + _renderersForDifferentStates.Add(_characterRendererFactory.CreateCharacterRenderer(Character.Default.WithRenderProperties(props))); _renderersForDifferentStates.OfType().Last().DrawOrder = 10; } @@ -152,7 +153,7 @@ public override void Update(GameTime gameTime) else if (KeyPressed(Keys.D6) && !_isBowEquipped) { var nextGraphic = GetNextItemGraphicMatching(ItemType.Weapon, _baseProperties.WeaponGraphic); - _baseProperties = _baseProperties.WithWeaponGraphic(nextGraphic, EIFFile.IsRangedWeapon(nextGraphic)); + _baseProperties = _baseProperties.WithWeaponGraphic(nextGraphic).WithIsRangedWeapon(EIFFile.IsRangedWeapon(nextGraphic)); update = true; } else if (KeyPressed(Keys.D7)) @@ -172,11 +173,11 @@ public override void Update(GameTime gameTime) { _lastGraphic = _baseProperties.WeaponGraphic; var firstBowWeapon = EIFFile.First(x => x.Type == ItemType.Weapon && x.SubType == ItemSubType.Ranged); - _baseProperties = _baseProperties.WithWeaponGraphic((short)firstBowWeapon.DollGraphic, isRanged: true); + _baseProperties = _baseProperties.WithWeaponGraphic((short)firstBowWeapon.DollGraphic).WithIsRangedWeapon(true); } else { - _baseProperties = _baseProperties.WithWeaponGraphic(_lastGraphic, EIFFile.IsRangedWeapon(_lastGraphic)); + _baseProperties = _baseProperties.WithWeaponGraphic(_lastGraphic).WithIsRangedWeapon(EIFFile.IsRangedWeapon(_lastGraphic)); } _isBowEquipped = !_isBowEquipped; @@ -192,7 +193,7 @@ public override void Update(GameTime gameTime) if ((now - _lastWalk).TotalMilliseconds > 500) { var rend = _renderersForDifferentStates[(int) DisplayState.WalkingAnimation]; - rend.Character = rend.Character.WithRenderProperties(rend.Character.RenderProperties.WithNextWalkFrame()); + rend.Character = rend.Character.WithRenderProperties(rend.Character.RenderProperties.WithNextWalkFrame(false)); _lastWalk = now; } @@ -220,7 +221,7 @@ public override void Draw(GameTime gameTime) base.Draw(gameTime); } - private ICharacterRenderProperties GetRenderPropertiesForState(DisplayState displayState) + private CharacterRenderProperties GetRenderPropertiesForState(DisplayState displayState) { switch (displayState) { @@ -246,7 +247,7 @@ private ICharacterRenderProperties GetRenderPropertiesForState(DisplayState disp case DisplayState.WalkingAnimation: case DisplayState.SpellCastAnimation: case DisplayState.AttackingAnimation: - return (ICharacterRenderProperties)_baseProperties.Clone(); + return _baseProperties.ToBuilder().ToImmutable(); default: throw new ArgumentOutOfRangeException(); } @@ -257,7 +258,7 @@ private void RefreshDisplayedCharacters() foreach (var displayState in _allDisplayStates) { var props = GetRenderPropertiesForState(displayState); - _renderersForDifferentStates[(int) displayState].Character = new Character().WithRenderProperties(props); + _renderersForDifferentStates[(int) displayState].Character = Character.Default.WithRenderProperties(props); } } diff --git a/EndlessClient/UIControls/CharacterControl.cs b/EndlessClient/UIControls/CharacterControl.cs index bd97f1ae8..96765a509 100644 --- a/EndlessClient/UIControls/CharacterControl.cs +++ b/EndlessClient/UIControls/CharacterControl.cs @@ -8,7 +8,7 @@ namespace EndlessClient.UIControls { public class CharacterControl : XNAControl { - public ICharacterRenderProperties RenderProperties + public CharacterRenderProperties RenderProperties { get { return _characterRenderer.Character.RenderProperties; } @@ -20,7 +20,7 @@ protected set protected readonly ICharacterRenderer _characterRenderer; - public CharacterControl(ICharacter character, + public CharacterControl(Character character, ICharacterRendererFactory characterRendererFactory) { _characterRenderer = characterRendererFactory.CreateCharacterRenderer(character); diff --git a/EndlessClient/UIControls/CharacterInfoPanel.cs b/EndlessClient/UIControls/CharacterInfoPanel.cs index de5d9e693..58e291f64 100644 --- a/EndlessClient/UIControls/CharacterInfoPanel.cs +++ b/EndlessClient/UIControls/CharacterInfoPanel.cs @@ -20,7 +20,7 @@ namespace EndlessClient.UIControls public class CharacterInfoPanel : XNAControl { private readonly INativeGraphicsManager _gfxManager; - private readonly ICharacter _character; + private readonly Character _character; private readonly ILoginController _loginController; private readonly ICharacterManagementController _characterManagementController; private readonly IRendererRepositoryResetter _rendererRepositoryResetter; @@ -63,7 +63,7 @@ protected CharacterInfoPanel(int characterIndex, } public CharacterInfoPanel(int characterIndex, - ICharacter character, + Character character, INativeGraphicsManager gfxManager, IEODialogButtonService dialogButtonService, ILoginController loginController, diff --git a/EndlessClient/UIControls/CharacterInfoPanelFactory.cs b/EndlessClient/UIControls/CharacterInfoPanelFactory.cs index 80bfa74ca..13a73dce2 100644 --- a/EndlessClient/UIControls/CharacterInfoPanelFactory.cs +++ b/EndlessClient/UIControls/CharacterInfoPanelFactory.cs @@ -46,7 +46,7 @@ public void InjectCharacterManagementController(ICharacterManagementController c _characterManagementController = characterManagementController; } - public IEnumerable CreatePanels(IEnumerable characters) + public IEnumerable CreatePanels(IEnumerable characters) { if(_loginController == null || _characterManagementController == null) throw new InvalidOperationException("Missing controllers - the Unity container was initialized incorrectly"); diff --git a/EndlessClient/UIControls/CreateCharacterControl.cs b/EndlessClient/UIControls/CreateCharacterControl.cs index 924d523b4..db4a5c013 100644 --- a/EndlessClient/UIControls/CreateCharacterControl.cs +++ b/EndlessClient/UIControls/CreateCharacterControl.cs @@ -12,7 +12,7 @@ public class CreateCharacterControl : CharacterControl private Vector2 _lastPosition; public CreateCharacterControl(ICharacterRendererFactory characterRendererFactory) - : base(new Character().WithRenderProperties(GetDefaultProperties()), characterRendererFactory) + : base(Character.Default.WithRenderProperties(GetDefaultProperties()), characterRendererFactory) { SetSize(99, 123); _lastPosition = Vector2.Zero; @@ -63,9 +63,9 @@ public void NextHairColor() RenderProperties = RenderProperties.WithHairColor((byte)((RenderProperties.HairColor + 1) % 10)); } - private static ICharacterRenderProperties GetDefaultProperties() + private static CharacterRenderProperties GetDefaultProperties() { - return new CharacterRenderProperties().WithHairStyle(1); + return new CharacterRenderProperties.Builder { HairStyle = 1 }.ToImmutable(); } } } diff --git a/EndlessClient/UIControls/ICharacterInfoPanelFactory.cs b/EndlessClient/UIControls/ICharacterInfoPanelFactory.cs index ff8e41531..f3f1591a0 100644 --- a/EndlessClient/UIControls/ICharacterInfoPanelFactory.cs +++ b/EndlessClient/UIControls/ICharacterInfoPanelFactory.cs @@ -6,7 +6,7 @@ namespace EndlessClient.UIControls { public interface ICharacterInfoPanelFactory { - IEnumerable CreatePanels(IEnumerable characters); + IEnumerable CreatePanels(IEnumerable characters); void InjectLoginController(ILoginController loginController); void InjectCharacterManagementController(ICharacterManagementController characterManagementController); } diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 22c5e3745..09e4d09bf 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,4 +1,4 @@ -name: 0.9.$(rev:rrr) +name: 0.10.$(rev:rrr) trigger: - master