Changes properties to use automatic property initializers

This commit is contained in:
Kamron Batman 2018-09-14 15:23:29 -07:00
parent f0a48ad431
commit 06fa31a7bf
623 changed files with 13072 additions and 19304 deletions

View file

@ -80,18 +80,18 @@ namespace Server.Factions
Movable = false;
Town = town;
Faction = faction;
m_Monoliths.Add( this );
Monoliths.Add( this );
}
public BaseMonolith( Serial serial ) : base( serial )
{
m_Monoliths.Add( this );
Monoliths.Add( this );
}
public override void OnAfterDelete()
{
base.OnAfterDelete();
m_Monoliths.Remove( this );
Monoliths.Remove( this );
}
public override void Serialize( GenericWriter writer )
@ -124,12 +124,6 @@ namespace Server.Factions
}
}
private static List<BaseMonolith> m_Monoliths = new List<BaseMonolith>();
public static List<BaseMonolith> Monoliths
{
get => m_Monoliths;
set => m_Monoliths = value;
}
public static List<BaseMonolith> Monoliths { get; set; } = new List<BaseMonolith>();
}
}

View file

@ -32,20 +32,17 @@ namespace Server {
}
private sealed class WeightedItem {
private int _weight;
private Type _type;
public int Weight { get; }
public int Weight => _weight;
public Type Type => _type;
public Type Type { get; }
public WeightedItem( int weight, Type type ) {
_weight = weight;
_type = type;
Weight = weight;
Type = type;
}
public Item Construct() {
return Activator.CreateInstance( _type ) as Item;
return Activator.CreateInstance( Type ) as Item;
}
}

View file

@ -22,44 +22,21 @@ namespace Server.Factions
// Once it's been returned the corrupting faction owns the town for this period of time
public static readonly TimeSpan PurificationPeriod = TimeSpan.FromDays( 3.0 );
private BaseMonolith m_LastMonolith;
private Town m_Town;
private Faction m_Corrupted;
private Faction m_Corrupting;
private DateTime m_LastStolen;
private DateTime m_GraceStart;
private DateTime m_CorruptionStart;
private DateTime m_PurificationStart;
[CommandProperty( AccessLevel.Counselor, AccessLevel.Administrator )]
public DateTime LastStolen { get; set; }
[CommandProperty( AccessLevel.Counselor, AccessLevel.Administrator )]
public DateTime LastStolen
{
get => m_LastStolen;
set => m_LastStolen = value;
}
public DateTime GraceStart { get; set; }
[CommandProperty( AccessLevel.Counselor, AccessLevel.Administrator )]
public DateTime GraceStart
{
get => m_GraceStart;
set => m_GraceStart = value;
}
public DateTime CorruptionStart { get; set; }
[CommandProperty( AccessLevel.Counselor, AccessLevel.Administrator )]
public DateTime CorruptionStart
{
get => m_CorruptionStart;
set => m_CorruptionStart = value;
}
[CommandProperty( AccessLevel.Counselor, AccessLevel.Administrator )]
public DateTime PurificationStart
{
get => m_PurificationStart;
set => m_PurificationStart = value;
}
public DateTime PurificationStart { get; set; }
[CommandProperty( AccessLevel.Counselor, AccessLevel.Administrator )]
public Town Town
@ -83,20 +60,16 @@ namespace Server.Factions
}
[CommandProperty( AccessLevel.Counselor, AccessLevel.Administrator )]
public BaseMonolith LastMonolith
{
get => m_LastMonolith;
set => m_LastMonolith = value;
}
public BaseMonolith LastMonolith { get; set; }
[CommandProperty( AccessLevel.Counselor )]
public bool IsBeingCorrupted => ( m_LastMonolith is StrongholdMonolith && m_LastMonolith.Faction == m_Corrupting && m_Corrupting != null );
public bool IsBeingCorrupted => ( LastMonolith is StrongholdMonolith && LastMonolith.Faction == m_Corrupting && m_Corrupting != null );
[CommandProperty( AccessLevel.Counselor )]
public bool IsCorrupted => ( m_Corrupted != null );
[CommandProperty( AccessLevel.Counselor )]
public bool IsPurifying => ( m_PurificationStart != DateTime.MinValue );
public bool IsPurifying => ( PurificationStart != DateTime.MinValue );
[CommandProperty( AccessLevel.Counselor )]
public bool IsCorrupting => ( m_Corrupting != null && m_Corrupting != m_Corrupted );
@ -198,7 +171,7 @@ namespace Server.Factions
Movable = false;
Town = town;
m_Sigils.Add( this );
Sigils.Add( this );
}
public override void OnDoubleClick( Mobile from )
@ -220,13 +193,13 @@ namespace Server.Factions
private void BeginCorrupting( Faction faction )
{
m_Corrupting = faction;
m_CorruptionStart = DateTime.UtcNow;
CorruptionStart = DateTime.UtcNow;
}
private void ClearCorrupting()
{
m_Corrupting = null;
m_CorruptionStart = DateTime.MinValue;
CorruptionStart = DateTime.MinValue;
}
[CommandProperty( AccessLevel.GameMaster )]
@ -237,7 +210,7 @@ namespace Server.Factions
if ( !IsBeingCorrupted )
return TimeSpan.Zero;
TimeSpan ts = ( m_CorruptionStart + CorruptionPeriod ) - DateTime.UtcNow;
TimeSpan ts = ( CorruptionStart + CorruptionPeriod ) - DateTime.UtcNow;
if ( ts < TimeSpan.Zero )
ts = TimeSpan.Zero;
@ -301,25 +274,25 @@ namespace Server.Factions
if ( m_Corrupted != newController )
BeginCorrupting( newController );
}
else if ( m_GraceStart > DateTime.MinValue && (m_GraceStart + CorruptionGrace) < DateTime.UtcNow )
else if ( GraceStart > DateTime.MinValue && (GraceStart + CorruptionGrace) < DateTime.UtcNow )
{
if ( m_Corrupted != newController )
BeginCorrupting( newController ); // grace time over, reset period
else
ClearCorrupting();
m_GraceStart = DateTime.MinValue;
GraceStart = DateTime.MinValue;
}
else if ( newController == oldController )
{
m_GraceStart = DateTime.MinValue; // returned within grace period
GraceStart = DateTime.MinValue; // returned within grace period
}
else if ( m_GraceStart == DateTime.MinValue )
else if ( GraceStart == DateTime.MinValue )
{
m_GraceStart = DateTime.UtcNow;
GraceStart = DateTime.UtcNow;
}
m_PurificationStart = DateTime.MinValue;
PurificationStart = DateTime.MinValue;
}
}
#endregion
@ -336,8 +309,8 @@ namespace Server.Factions
tm.Sigil = this;
m_Corrupting = null;
m_PurificationStart = DateTime.UtcNow;
m_CorruptionStart = DateTime.MinValue;
PurificationStart = DateTime.UtcNow;
CorruptionStart = DateTime.MinValue;
m_Town.Capture( m_Corrupted );
m_Corrupted = null;
@ -355,7 +328,7 @@ namespace Server.Factions
public Sigil( Serial serial ) : base( serial )
{
m_Sigils.Add( this );
Sigils.Add( this );
}
public override void Serialize( GenericWriter writer )
@ -368,12 +341,12 @@ namespace Server.Factions
Faction.WriteReference( writer, m_Corrupted );
Faction.WriteReference( writer, m_Corrupting );
writer.Write( (Item) m_LastMonolith );
writer.Write( (Item) LastMonolith );
writer.Write( m_LastStolen );
writer.Write( m_GraceStart );
writer.Write( m_CorruptionStart );
writer.Write( m_PurificationStart );
writer.Write( LastStolen );
writer.Write( GraceStart );
writer.Write( CorruptionStart );
writer.Write( PurificationStart );
}
public override void Deserialize( GenericReader reader )
@ -390,12 +363,12 @@ namespace Server.Factions
m_Corrupted = Faction.ReadReference( reader );
m_Corrupting = Faction.ReadReference( reader );
m_LastMonolith = reader.ReadItem() as BaseMonolith;
LastMonolith = reader.ReadItem() as BaseMonolith;
m_LastStolen = reader.ReadDateTime();
m_GraceStart = reader.ReadDateTime();
m_CorruptionStart = reader.ReadDateTime();
m_PurificationStart = reader.ReadDateTime();
LastStolen = reader.ReadDateTime();
GraceStart = reader.ReadDateTime();
CorruptionStart = reader.ReadDateTime();
PurificationStart = reader.ReadDateTime();
Update();
@ -409,7 +382,7 @@ namespace Server.Factions
public bool ReturnHome()
{
BaseMonolith monolith = m_LastMonolith;
BaseMonolith monolith = LastMonolith;
if ( monolith == null && m_Town != null )
monolith = m_Town.Monolith;
@ -431,7 +404,7 @@ namespace Server.Factions
{
base.OnAfterDelete();
m_Sigils.Remove( this );
Sigils.Remove( this );
}
public override void Delete()
@ -442,8 +415,6 @@ namespace Server.Factions
base.Delete();
}
private static List<Sigil> m_Sigils = new List<Sigil>();
public static List<Sigil> Sigils => m_Sigils;
public static List<Sigil> Sigils { get; } = new List<Sigil>();
}
}

View file

@ -15,32 +15,16 @@ namespace Server.Factions
public abstract class BaseFactionTrap : BaseTrap
{
private Faction m_Faction;
private Mobile m_Placer;
private DateTime m_TimeOfPlacement;
private Timer m_Concealing;
[CommandProperty( AccessLevel.GameMaster )]
public Faction Faction
{
get => m_Faction;
set => m_Faction = value;
}
public Faction Faction { get; set; }
[CommandProperty( AccessLevel.GameMaster )]
public Mobile Placer
{
get => m_Placer;
set => m_Placer = value;
}
public Mobile Placer { get; set; }
[CommandProperty( AccessLevel.GameMaster )]
public DateTime TimeOfPlacement
{
get => m_TimeOfPlacement;
set => m_TimeOfPlacement = value;
}
public DateTime TimeOfPlacement { get; set; }
public virtual int EffectSound => 0;
@ -79,24 +63,24 @@ namespace Server.Factions
int silverToAward = ( from.Alive ? 20 : 40 );
if ( silverToAward > 0 && m_Placer != null && m_Faction != null )
if ( silverToAward > 0 && Placer != null && Faction != null )
{
PlayerState victimState = PlayerState.Find( from );
if ( victimState != null && victimState.CanGiveSilverTo( m_Placer ) && victimState.KillPoints > 0 )
if ( victimState != null && victimState.CanGiveSilverTo( Placer ) && victimState.KillPoints > 0 )
{
int silverGiven = m_Faction.AwardSilver( m_Placer, silverToAward );
int silverGiven = Faction.AwardSilver( Placer, silverToAward );
if ( silverGiven > 0 )
{
// TODO: Get real message
if ( from.Alive )
m_Placer.SendMessage( "You have earned {0} silver pieces because {1} fell for your trap.", silverGiven, from.Name );
Placer.SendMessage( "You have earned {0} silver pieces because {1} fell for your trap.", silverGiven, from.Name );
else
m_Placer.SendLocalizedMessage( 1042736, $"{silverGiven} silver\t{from.Name}"); // You have earned ~1_SILVER_AMOUNT~ pieces for vanquishing ~2_PLAYER_NAME~!
Placer.SendLocalizedMessage( 1042736, $"{silverGiven} silver\t{from.Name}"); // You have earned ~1_SILVER_AMOUNT~ pieces for vanquishing ~2_PLAYER_NAME~!
}
victimState.OnGivenSilverTo( m_Placer );
victimState.OnGivenSilverTo( Placer );
}
}
@ -131,7 +115,7 @@ namespace Server.Factions
{
StrongholdRegion region = (StrongholdRegion) Region.Find( p, m ).GetRegion( typeof( StrongholdRegion ) );
if ( region != null && region.Faction == m_Faction )
if ( region != null && region.Faction == Faction )
return 0;
return 1010355; // This trap can only be placed in your stronghold
@ -149,7 +133,7 @@ namespace Server.Factions
{
Town town = Town.FromRegion( Region.Find( p, m ) );
if ( town != null && town.Owner == m_Faction )
if ( town != null && town.Owner == Faction )
return 0;
return 1010357; // This trap can only be placed in a town your faction controls
@ -181,9 +165,9 @@ namespace Server.Factions
{
Visible = false;
m_Faction = f;
m_TimeOfPlacement = DateTime.UtcNow;
m_Placer = m;
Faction = f;
TimeOfPlacement = DateTime.UtcNow;
Placer = m;
}
public BaseFactionTrap( Serial serial ) : base( serial )
@ -197,7 +181,7 @@ namespace Server.Factions
if ( decayPeriod == TimeSpan.MaxValue )
return false;
if ( (m_TimeOfPlacement + decayPeriod) < DateTime.UtcNow )
if ( (TimeOfPlacement + decayPeriod) < DateTime.UtcNow )
{
Timer.DelayCall( TimeSpan.Zero, Delete );
return true;
@ -229,9 +213,9 @@ namespace Server.Factions
writer.Write( (int) 0 ); // version
Faction.WriteReference( writer, m_Faction );
writer.Write( (Mobile) m_Placer );
writer.Write( (DateTime) m_TimeOfPlacement );
Faction.WriteReference( writer, Faction );
writer.Write( (Mobile) Placer );
writer.Write( (DateTime) TimeOfPlacement );
if ( Visible )
BeginConceal();
@ -243,9 +227,9 @@ namespace Server.Factions
int version = reader.ReadInt();
m_Faction = Faction.ReadReference( reader );
m_Placer = reader.ReadMobile();
m_TimeOfPlacement = reader.ReadDateTime();
Faction = Faction.ReadReference( reader );
Placer = reader.ReadMobile();
TimeOfPlacement = reader.ReadDateTime();
if ( Visible )
BeginConceal();
@ -255,8 +239,8 @@ namespace Server.Factions
public override void OnDelete()
{
if ( m_Faction != null && m_Faction.Traps.Contains( this ) )
m_Faction.Traps.Remove( this );
if ( Faction != null && Faction.Traps.Contains( this ) )
Faction.Traps.Remove( this );
base.OnDelete();
}
@ -277,7 +261,7 @@ namespace Server.Factions
if ( faction == null )
return false;
return ( faction != m_Faction );
return ( faction != Faction );
}
}
}

View file

@ -2,14 +2,8 @@ namespace Server.Factions
{
public class FactionTrapRemovalKit : Item
{
private int m_Charges;
[CommandProperty( AccessLevel.GameMaster )]
public int Charges
{
get => m_Charges;
set => m_Charges = value;
}
public int Charges { get; set; }
public override int LabelNumber => 1041508; // a faction trap removal kit
@ -17,14 +11,14 @@ namespace Server.Factions
public FactionTrapRemovalKit() : base( 7867 )
{
LootType = LootType.Blessed;
m_Charges = 25;
Charges = 25;
}
public void ConsumeCharge( Mobile consumer )
{
--m_Charges;
--Charges;
if ( m_Charges <= 0 )
if ( Charges <= 0 )
{
Delete();
@ -37,7 +31,7 @@ namespace Server.Factions
base.GetProperties( list );
// NOTE: OSI does not list uses remaining; intentional difference
list.Add( 1060584, m_Charges.ToString() ); // uses remaining: ~1_val~
list.Add( 1060584, Charges.ToString() ); // uses remaining: ~1_val~
}
public FactionTrapRemovalKit( Serial serial ) : base( serial )
@ -50,7 +44,7 @@ namespace Server.Factions
writer.Write( (int) 1 ); // version
writer.WriteEncodedInt( (int) m_Charges );
writer.WriteEncodedInt( (int) Charges );
}
public override void Deserialize( GenericReader reader )
@ -63,12 +57,12 @@ namespace Server.Factions
{
case 1:
{
m_Charges = reader.ReadEncodedInt();
Charges = reader.ReadEncodedInt();
break;
}
case 0:
{
m_Charges = 25;
Charges = 25;
break;
}
}