Change setters to init only

This commit is contained in:
Kurt 2020-12-21 17:05:05 -08:00
parent c6b702ae54
commit 68ee8cfcc4
12 changed files with 54 additions and 57 deletions

View File

@ -9,8 +9,8 @@ namespace PKHeX.Core
public abstract class EncounterArea : IVersion
{
public GameVersion Version { get; }
public int Location { get; protected set; }
public SlotType Type { get; protected set; } = SlotType.Any;
public int Location { get; protected init; }
public SlotType Type { get; protected init; } = SlotType.Any;
public EncounterSlot[] Slots = Array.Empty<EncounterSlot>();
protected EncounterArea(GameVersion game) => Version = game;

View File

@ -8,10 +8,10 @@ namespace PKHeX.Core
/// <remarks>Wild encounter slots are found as random encounters in-game.</remarks>
public abstract class EncounterSlot : IEncounterable, ILocation
{
public int Species { get; protected set; }
public int Form { get; protected set; }
public int LevelMin { get; protected set; }
public int LevelMax { get; protected set; }
public int Species { get; protected init; }
public int Form { get; protected init; }
public int LevelMin { get; protected init; }
public int LevelMax { get; protected init; }
public abstract int Generation { get; }
public bool EggEncounter => false;
public override string ToString() => $"{(Species) Species} @ {LevelMin}-{LevelMax}";

View File

@ -7,7 +7,7 @@ namespace PKHeX.Core
public sealed class EncounterSlot6XY : EncounterSlot
{
public override int Generation => 6;
public bool Pressure { get; set; }
public bool Pressure { get; init; }
public EncounterSlot6XY(EncounterArea6XY area, int species, int form, int min, int max) : base(area)
{
@ -31,10 +31,7 @@ public override string GetConditionString(out bool valid)
public EncounterSlot6XY CreatePressureFormCopy(int evoForm)
{
var clone = (EncounterSlot6XY)Clone();
clone.Form = evoForm;
clone.Pressure = true;
return clone;
return new((EncounterArea6XY) Area, Species, evoForm, LevelMin, LevelMax) {Pressure = true};
}
}
}

View File

@ -11,32 +11,32 @@ namespace PKHeX.Core
/// </remarks>
public abstract class EncounterStatic : IEncounterable, IMoveset, ILocation, IVersionSet
{
public int Species { get; set; }
public int Form { get; set; }
public virtual int Level { get; set; }
public int Species { get; init; }
public int Form { get; init; }
public virtual int Level { get; init; }
public virtual int LevelMin => Level;
public virtual int LevelMax => Level;
public abstract int Generation { get; }
public GameVersion Version { get; set; } = GameVersion.Any;
public virtual int Location { get; set; }
public int Ability { get; set; }
public Shiny Shiny { get; set; } = Shiny.Random;
public int Gender { get; set; } = -1;
public int EggLocation { get; set; }
public Nature Nature { get; set; } = Nature.Random;
public bool Gift { get; set; }
public int Ball { get; set; } = 4; // Only checked when is Gift
public virtual int Location { get; init; }
public int Ability { get; init; }
public Shiny Shiny { get; init; } = Shiny.Random;
public int Gender { get; init; } = -1;
public int EggLocation { get; init; }
public Nature Nature { get; init; } = Nature.Random;
public bool Gift { get; init; }
public int Ball { get; init; } = 4; // Only checked when is Gift
public IReadOnlyList<int> Moves { get; set; } = Array.Empty<int>();
public IReadOnlyList<int> IVs { get; set; } = Array.Empty<int>();
public int FlawlessIVCount { get; set; }
public IReadOnlyList<int> Moves { get; init; } = Array.Empty<int>();
public IReadOnlyList<int> IVs { get; init; } = Array.Empty<int>();
public int FlawlessIVCount { get; init; }
public int HeldItem { get; set; }
public int EggCycles { get; set; }
public int HeldItem { get; init; }
public int EggCycles { get; init; }
public bool Fateful { get; set; }
public bool SkipFormCheck { get; set; }
public bool Fateful { get; init; }
public bool SkipFormCheck { get; init; }
public bool EggEncounter => EggLocation > 0;
internal EncounterStatic Clone() => (EncounterStatic)MemberwiseClone();

View File

@ -10,7 +10,7 @@ namespace PKHeX.Core
public class EncounterStatic2 : EncounterStatic
{
public sealed override int Generation => 2;
public sealed override int Level { get; set; }
public sealed override int Level { get; init; }
public EncounterStatic2(int species, int level, GameVersion ver)
{

View File

@ -16,8 +16,8 @@ public sealed class EncounterStatic8N : EncounterStatic8Nest<EncounterStatic8N>
private IReadOnlyList<byte> NestLocations => Encounters8Nest.NestLocations[NestID];
public override int Location { get => SharedNest; set { } }
public override int Level { get => LevelMin; set { } }
public override int Location { get => SharedNest; init { } }
public override int Level { get => LevelMin; init { } }
public override int LevelMin => LevelCaps[MinRank * 2];
public override int LevelMax => LevelCaps[(MaxRank * 2) + 1];

View File

@ -8,7 +8,7 @@ namespace PKHeX.Core
/// <inheritdoc cref="EncounterStatic8Nest{T}"/>
public sealed class EncounterStatic8NC : EncounterStatic8Nest<EncounterStatic8NC>
{
public override int Location { get => SharedNest; set { } }
public override int Location { get => SharedNest; init { } }
protected override bool IsMatchLocation(PKM pkm)
{

View File

@ -15,7 +15,7 @@ public abstract class EncounterStatic8Nest<T> : EncounterStatic, IGigantamax, ID
public bool CanGigantamax { get; set; }
public byte DynamaxLevel { get; set; }
public override int Location { get => SharedNest; set { } }
public override int Location { get => SharedNest; init { } }
protected override bool IsMatchLevel(PKM pkm, DexLevel evo)
{

View File

@ -10,8 +10,8 @@ namespace PKHeX.Core
/// <inheritdoc cref="EncounterStatic"/>
public sealed class EncounterStatic8S : EncounterStatic8
{
public override int Location { get => Locations[0]; set { } }
public IReadOnlyList<int> Locations { get; internal set; } = Array.Empty<int>();
public override int Location { get => Locations[0]; init { } }
public IReadOnlyList<int> Locations { get; init; } = Array.Empty<int>();
protected override bool IsMatchLocation(PKM pkm) => Locations.Contains(pkm.Met_Location);
}
}

View File

@ -8,7 +8,7 @@ namespace PKHeX.Core
/// <inheritdoc cref="EncounterStatic8Nest{T}"/>
public sealed class EncounterStatic8U : EncounterStatic8Nest<EncounterStatic8U>
{
public override int Location { get => MaxLair; set { } }
public override int Location { get => MaxLair; init { } }
public EncounterStatic8U(int species, int form, int level)
{

View File

@ -9,12 +9,12 @@ namespace PKHeX.Core
/// <inheritdoc cref="EncounterStatic"/>
public sealed class EncounterStaticTyped : EncounterStatic4, IEncounterTypeTile
{
public bool Roaming { get; set; }
public bool Roaming { get; init; }
/// <summary>
/// <see cref="PK4.EncounterType"/> values permitted for the encounter.
/// </summary>
public EncounterType TypeEncounter { get; internal set; } = EncounterType.None;
public EncounterType TypeEncounter { get; init; } = EncounterType.None;
protected override bool IsMatchLocation(PKM pkm)
{

View File

@ -12,33 +12,33 @@ namespace PKHeX.Core
/// </remarks>
public abstract class EncounterTrade : IEncounterable, IMoveset, ILocation, IVersionSet
{
public int Species { get; set; }
public int Form { get; set; }
public int Level { get; set; }
public int Species { get; init; }
public int Form { get; init; }
public int Level { get; init; }
public virtual int LevelMin => Level;
public int LevelMax => 100;
public IReadOnlyList<int> Moves { get; set; } = Array.Empty<int>();
public IReadOnlyList<int> Moves { get; init; } = Array.Empty<int>();
public abstract int Generation { get; }
public int CurrentLevel { get; set; } = -1;
public int Location { get; set; }
public int Ability { get; set; }
public int Gender { get; set; } = -1;
public int CurrentLevel { get; init; } = -1;
public int Location { get; init; }
public int Ability { get; init; }
public int Gender { get; init; } = -1;
public Nature Nature = Nature.Random;
public virtual Shiny Shiny { get; set; } = Shiny.Never;
public int Ball { get; set; } = 4;
public Shiny Shiny { get; init; } = Shiny.Never;
public int Ball { get; init; } = 4;
public int TID { get; set; }
public int SID { get; set; }
public int OTGender { get; set; } = -1;
public int TID { get; internal set; }
public int SID { get; internal set; }
public int OTGender { get; init; } = -1;
public GameVersion Version { get; set; } = GameVersion.Any;
public IReadOnlyList<int> IVs { get; set; } = Array.Empty<int>();
public int FlawlessIVCount { get; set; }
public IReadOnlyList<int> IVs { get; init; } = Array.Empty<int>();
public int FlawlessIVCount { get; init; }
public bool EggEncounter => false;
public int EggLocation { get; set; }
public bool EvolveOnTrade { get; set; }
public int EggLocation { get; init; }
public bool EvolveOnTrade { get; init; }
public int TID7
{
@ -52,7 +52,7 @@ public int TID7
private const string _name = "In-game Trade";
public string Name => _name;
public string LongName => _name;
public bool IsNicknamed { get; set; } = true;
public bool IsNicknamed { get; init; } = true;
public IReadOnlyList<string> Nicknames { get; internal set; } = Array.Empty<string>();
public IReadOnlyList<string> TrainerNames { get; internal set; } = Array.Empty<string>();