-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from ethanmoffat/record_types
Update immutable types to use [Record] attribute. Remove boilerplate code in favor of third-party code generation.
- Loading branch information
Showing
168 changed files
with
989 additions
and
2,701 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string>.Default.GetHashCode(Name); | ||
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Title); | ||
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(GuildName); | ||
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(GuildRank); | ||
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(GuildTag); | ||
hashCode = hashCode * -1521134295 + ClassID.GetHashCode(); | ||
hashCode = hashCode * -1521134295 + AdminLevel.GetHashCode(); | ||
hashCode = hashCode * -1521134295 + EqualityComparer<ICharacterRenderProperties>.Default.GetHashCode(RenderProperties); | ||
hashCode = hashCode * -1521134295 + EqualityComparer<ICharacterStats>.Default.GetHashCode(Stats); | ||
hashCode = hashCode * -1521134295 + MapID.GetHashCode(); | ||
hashCode = hashCode * -1521134295 + NoWall.GetHashCode(); | ||
return hashCode; | ||
} | ||
public bool NoWall { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.