Clean up: Bugs, LINQ, constructors, default values, and null checks (#18)

This commit is contained in:
Kamron Batman 2019-03-11 14:29:59 -07:00 committed by GitHub
parent e748af4430
commit 513e54f70e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1094 changed files with 15913 additions and 21892 deletions

View file

@ -147,7 +147,7 @@ namespace Server.Items
{
base.Hue = value;
if (Addon != null && Addon.ShareHue)
if (Addon?.ShareHue == true)
Addon.Hue = value;
}
}
@ -259,4 +259,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -35,7 +35,7 @@ namespace Server.Items
{
base.Hue = value;
if (Addon != null && Addon.ShareHue)
if (Addon?.ShareHue == true)
Addon.Hue = value;
}
}
@ -152,4 +152,4 @@ namespace Server.Items
m_LabelNumber = reader.ReadInt();
}
}
}
}

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server.Network;
@ -20,7 +19,7 @@ namespace Server.Items
[CommandProperty( AccessLevel.GameMaster )]
public bool FacingEast
{
get => ( ItemID == 0x100A );
get => ItemID == 0x100A;
set => ItemID = value ? 0x100A : 0x100B;
}
@ -30,12 +29,7 @@ namespace Server.Items
[CommandProperty( AccessLevel.GameMaster )]
public int Bolts { get; set; }
[Constructible]
public ArcheryButte() : this( 0x100A )
{
}
public ArcheryButte( int itemID ) : base( itemID )
public ArcheryButte(int itemID = 0x100A) : base(itemID)
{
MinSkill = -25.0;
MaxSkill = +25.0;
@ -141,11 +135,11 @@ namespace Server.Items
Container pack = from.Backpack;
Type ammoType = bow.AmmoType;
bool isArrow = ( ammoType == typeof( Arrow ) );
bool isBolt = ( ammoType == typeof( Bolt ) );
bool isKnown = ( isArrow || isBolt );
bool isArrow = ammoType == typeof( Arrow );
bool isBolt = ammoType == typeof( Bolt );
bool isKnown = isArrow || isBolt;
if ( pack == null || !pack.ConsumeTotal( ammoType, 1 ) )
if (pack?.ConsumeTotal( ammoType ) != true)
{
if ( isArrow )
from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 500594 ); // You do not have any arrows with which to practice.
@ -241,7 +235,7 @@ namespace Server.Items
{
base.Serialize( writer );
writer.Write( (int) 0 );
writer.Write( 0 );
writer.Write( MinSkill );
writer.Write( MaxSkill );
@ -283,7 +277,7 @@ namespace Server.Items
[Constructible]
public ArcheryButteAddon()
{
AddComponent( new ArcheryButte( 0x100A ), 0, 0, 0 );
AddComponent( new ArcheryButte(), 0, 0, 0 );
}
public ArcheryButteAddon( Serial serial ) : base( serial )
@ -294,7 +288,7 @@ namespace Server.Items
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
writer.Write( 0 ); // version
}
public override void Deserialize( GenericReader reader )
@ -323,7 +317,7 @@ namespace Server.Items
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
writer.Write( 0 ); // version
}
public override void Deserialize( GenericReader reader )

View file

@ -64,7 +64,7 @@ namespace Server.Items
return true;
BaseHouse house = BaseHouse.FindHouseAt(this);
return house != null && house.IsOwner(from);
return house?.IsOwner(from) == true;
}
public bool HasVoted(Mobile from)
@ -132,11 +132,11 @@ namespace Server.Items
AddBackground(0, 0, 400, 350, 0xA28);
if (isOwner)
AddHtmlLocalized(0, 15, 400, 35, 1011000, false, false); // <center>Ballot Box Owner's Menu</center>
AddHtmlLocalized(0, 15, 400, 35, 1011000); // <center>Ballot Box Owner's Menu</center>
else
AddHtmlLocalized(0, 15, 400, 35, 1011001, false, false); // <center>Ballot Box -- Vote Here!</center>
AddHtmlLocalized(0, 15, 400, 35, 1011001); // <center>Ballot Box -- Vote Here!</center>
AddHtmlLocalized(0, 50, 400, 35, 1011002, false, false); // <center>Topic</center>
AddHtmlLocalized(0, 50, 400, 35, 1011002); // <center>Topic</center>
int lineCount = box.Topic.Length;
AddBackground(25, 90, 350, Math.Max(20 * lineCount, 20), 0x1400);
@ -153,16 +153,16 @@ namespace Server.Items
int noCount = box.No.Count;
int totalVotes = yesCount + noCount;
AddHtmlLocalized(0, 215, 400, 35, 1011003, false, false); // <center>votes</center>
AddHtmlLocalized(0, 215, 400, 35, 1011003); // <center>votes</center>
if (!isOwner)
AddButton(20, 240, 0xFA5, 0xFA7, 3, GumpButtonType.Reply, 0);
AddHtmlLocalized(55, 242, 25, 35, 1011004, false, false); // aye:
AddButton(20, 240, 0xFA5, 0xFA7, 3);
AddHtmlLocalized(55, 242, 25, 35, 1011004); // aye:
AddLabel(78, 242, 0x0, $"[{yesCount}]");
if (!isOwner)
AddButton(20, 275, 0xFA5, 0xFA7, 4, GumpButtonType.Reply, 0);
AddHtmlLocalized(55, 277, 25, 35, 1011005, false, false); // nay:
AddButton(20, 275, 0xFA5, 0xFA7, 4);
AddHtmlLocalized(55, 277, 25, 35, 1011005); // nay:
AddLabel(78, 277, 0x0, $"[{noCount}]");
if (totalVotes > 0)
@ -171,16 +171,16 @@ namespace Server.Items
AddImageTiled(130, 277, noCount * 225 / totalVotes, 10, 0xD6);
}
AddButton(45, 305, 0xFA5, 0xFA7, 0, GumpButtonType.Reply, 0);
AddHtmlLocalized(80, 308, 40, 35, 1011008, false, false); // done
AddButton(45, 305, 0xFA5, 0xFA7, 0);
AddHtmlLocalized(80, 308, 40, 35, 1011008); // done
if (isOwner)
{
AddButton(120, 305, 0xFA5, 0xFA7, 1, GumpButtonType.Reply, 0);
AddHtmlLocalized(155, 308, 100, 35, 1011006, false, false); // change topic
AddButton(120, 305, 0xFA5, 0xFA7, 1);
AddHtmlLocalized(155, 308, 100, 35, 1011006); // change topic
AddButton(240, 305, 0xFA5, 0xFA7, 2, GumpButtonType.Reply, 0);
AddHtmlLocalized(275, 308, 300, 100, 1011007, false, false); // reset votes
AddButton(240, 305, 0xFA5, 0xFA7, 2);
AddHtmlLocalized(275, 308, 300, 100, 1011007); // reset votes
}
}
@ -375,4 +375,4 @@ namespace Server.Items
int version = reader.ReadEncodedInt();
}
}
}
}

View file

@ -72,7 +72,7 @@ namespace Server.Items
{
BaseHouse house = BaseHouse.FindHouseAt(this);
if (house != null && house.IsOwner(from) && house.Addons.Contains(this))
if (house?.IsOwner(from) == true && house.Addons.Contains(this))
{
Effects.PlaySound(GetWorldLocation(), Map, 0x3B3);
from.SendLocalizedMessage(500461); // You destroy the item.
@ -165,12 +165,7 @@ namespace Server.Items
public static bool CheckHouse(Mobile from, Point3D p, Map map, int height, ref BaseHouse house)
{
house = BaseHouse.FindHouseAt(p, map, height);
if (house == null || from != null && !house.IsOwner(from))
return false;
return true;
return from == null || BaseHouse.FindHouseAt(p, map, height)?.IsOwner(from) == true;
}
public static bool IsWall(int x, int y, int z, Map map)
@ -277,4 +272,4 @@ namespace Server.Items
#endregion
}
}
}

View file

@ -79,7 +79,7 @@ namespace Server.Items
{
BaseHouse house = BaseHouse.FindHouseAt(this);
if (house != null && house.IsOwner(from))
if (house?.IsOwner(from) == true)
{
if (!IsSecure)
{
@ -255,16 +255,17 @@ namespace Server.Items
{
BaseDoor door = doors[i];
if (door != null && door.Open)
if (door?.Open == true)
return AddonFitResult.DoorsNotClosed;
Point3D doorLoc = door.GetWorldLocation();
int doorHeight = door.ItemData.CalcHeight;
int addonHeight;
foreach (AddonContainerComponent c in Components)
{
Point3D addonLoc = new Point3D(p.X + c.Offset.X, p.Y + c.Offset.Y, p.Z + c.Offset.Z);
int addonHeight = c.ItemData.CalcHeight;
addonHeight = c.ItemData.CalcHeight;
if (Utility.InRange(doorLoc, addonLoc, 1) &&
(addonLoc.Z == doorLoc.Z ||
@ -273,10 +274,10 @@ namespace Server.Items
}
Point3D addonLo = new Point3D(p.X, p.Y, p.Z);
int addonHeigh = ItemData.CalcHeight;
addonHeight = ItemData.CalcHeight;
if (Utility.InRange(doorLoc, addonLo, 1) &&
(addonLo.Z == doorLoc.Z || addonLo.Z + addonHeigh > doorLoc.Z && doorLoc.Z + doorHeight > addonLo.Z))
(addonLo.Z == doorLoc.Z || addonLo.Z + addonHeight > doorLoc.Z && doorLoc.Z + doorHeight > addonLo.Z))
return AddonFitResult.DoorTooClose;
}
}
@ -292,4 +293,4 @@ namespace Server.Items
{
}
}
}
}

View file

@ -55,7 +55,7 @@ namespace Server.Items
CraftContext context = craftSystem.GetContext(from);
if (context != null && context.DoNotColor)
if (context?.DoNotColor == true)
Hue = 0;
return quality;
@ -164,4 +164,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -5,12 +5,7 @@ namespace Server.Items
public class DartBoard : AddonComponent
{
[Constructible]
public DartBoard() : this(true)
{
}
[Constructible]
public DartBoard(bool east) : base(east ? 0x1E2F : 0x1E2E)
public DartBoard(bool east = true) : base(east ? 0x1E2F : 0x1E2E)
{
}
@ -100,7 +95,7 @@ namespace Server.Items
{
public DartBoardEastAddon()
{
AddComponent(new DartBoard(true), 0, 0, 0);
AddComponent(new DartBoard(), 0, 0, 0);
}
public DartBoardEastAddon(Serial serial) : base(serial)
@ -211,4 +206,4 @@ namespace Server.Items
int version = reader.ReadEncodedInt();
}
}
}
}

View file

@ -3,13 +3,7 @@ namespace Server.Items
public class FireColumnAddon : BaseAddon
{
[Constructible]
public FireColumnAddon()
: this(false)
{
}
[Constructible]
public FireColumnAddon(bool bloody)
public FireColumnAddon(bool bloody = false)
{
AddComponent(new AddonComponent(0x3A5), 0, 0, 0);
AddComponent(new AddonComponent(0x3A5), 0, 0, 5);
@ -54,4 +48,4 @@ namespace Server.Items
int version = reader.ReadInt();
}
}
}
}

View file

@ -3,12 +3,7 @@ namespace Server.Items
public class GozaMatEastAddon : BaseAddon
{
[Constructible]
public GozaMatEastAddon() : this(0)
{
}
[Constructible]
public GozaMatEastAddon(int hue)
public GozaMatEastAddon(int hue = 0)
{
AddComponent(new LocalizedAddonComponent(0x28a4, 1030688), 1, 0, 0);
AddComponent(new LocalizedAddonComponent(0x28a5, 1030688), 0, 0, 0);
@ -70,12 +65,7 @@ namespace Server.Items
public class GozaMatSouthAddon : BaseAddon
{
[Constructible]
public GozaMatSouthAddon() : this(0)
{
}
[Constructible]
public GozaMatSouthAddon(int hue)
public GozaMatSouthAddon(int hue = 0)
{
AddComponent(new LocalizedAddonComponent(0x28a6, 1030688), 0, 1, 0);
AddComponent(new LocalizedAddonComponent(0x28a7, 1030688), 0, 0, 0);
@ -137,12 +127,7 @@ namespace Server.Items
public class SquareGozaMatEastAddon : BaseAddon
{
[Constructible]
public SquareGozaMatEastAddon() : this(0)
{
}
[Constructible]
public SquareGozaMatEastAddon(int hue)
public SquareGozaMatEastAddon(int hue = 0)
{
AddComponent(new LocalizedAddonComponent(0x28a8, 1030688), 0, 0, 0);
Hue = hue;
@ -204,12 +189,7 @@ namespace Server.Items
public class SquareGozaMatSouthAddon : BaseAddon
{
[Constructible]
public SquareGozaMatSouthAddon() : this(0)
{
}
[Constructible]
public SquareGozaMatSouthAddon(int hue)
public SquareGozaMatSouthAddon(int hue = 0)
{
AddComponent(new LocalizedAddonComponent(0x28a9, 1030688), 0, 0, 0);
Hue = hue;
@ -270,12 +250,7 @@ namespace Server.Items
public class BrocadeGozaMatEastAddon : BaseAddon
{
[Constructible]
public BrocadeGozaMatEastAddon() : this(0)
{
}
[Constructible]
public BrocadeGozaMatEastAddon(int hue)
public BrocadeGozaMatEastAddon(int hue = 0)
{
AddComponent(new LocalizedAddonComponent(0x28AB, 1030688), 0, 0, 0);
AddComponent(new LocalizedAddonComponent(0x28AA, 1030688), 1, 0, 0);
@ -337,12 +312,7 @@ namespace Server.Items
public class BrocadeGozaMatSouthAddon : BaseAddon
{
[Constructible]
public BrocadeGozaMatSouthAddon() : this(0)
{
}
[Constructible]
public BrocadeGozaMatSouthAddon(int hue)
public BrocadeGozaMatSouthAddon(int hue = 0)
{
AddComponent(new LocalizedAddonComponent(0x28AD, 1030688), 0, 0, 0);
AddComponent(new LocalizedAddonComponent(0x28AC, 1030688), 0, 1, 0);
@ -404,12 +374,7 @@ namespace Server.Items
public class BrocadeSquareGozaMatEastAddon : BaseAddon
{
[Constructible]
public BrocadeSquareGozaMatEastAddon() : this(0)
{
}
[Constructible]
public BrocadeSquareGozaMatEastAddon(int hue)
public BrocadeSquareGozaMatEastAddon(int hue = 0)
{
AddComponent(new LocalizedAddonComponent(0x28AE, 1030688), 0, 0, 0);
Hue = hue;
@ -470,12 +435,7 @@ namespace Server.Items
public class BrocadeSquareGozaMatSouthAddon : BaseAddon
{
[Constructible]
public BrocadeSquareGozaMatSouthAddon() : this(0)
{
}
[Constructible]
public BrocadeSquareGozaMatSouthAddon(int hue)
public BrocadeSquareGozaMatSouthAddon(int hue = 0)
{
AddComponent(new LocalizedAddonComponent(0x28AF, 1030688), 0, 0, 0);
Hue = hue;
@ -532,4 +492,4 @@ namespace Server.Items
int version = reader.ReadInt();
}
}
}
}

View file

@ -3,12 +3,7 @@ namespace Server.Items
public class LargeStoneTableEastAddon : BaseAddon
{
[Constructible]
public LargeStoneTableEastAddon() : this(0)
{
}
[Constructible]
public LargeStoneTableEastAddon(int hue)
public LargeStoneTableEastAddon(int hue = 0)
{
AddComponent(new AddonComponent(0x1202), 0, 0, 0);
AddComponent(new AddonComponent(0x1203), 0, 1, 0);
@ -67,4 +62,4 @@ namespace Server.Items
int version = reader.ReadInt();
}
}
}
}

View file

@ -3,12 +3,7 @@ namespace Server.Items
public class LargeStoneTableSouthAddon : BaseAddon
{
[Constructible]
public LargeStoneTableSouthAddon() : this(0)
{
}
[Constructible]
public LargeStoneTableSouthAddon(int hue)
public LargeStoneTableSouthAddon(int hue = 0)
{
AddComponent(new AddonComponent(0x1205), 0, 0, 0);
AddComponent(new AddonComponent(0x1206), 1, 0, 0);
@ -67,4 +62,4 @@ namespace Server.Items
int version = reader.ReadInt();
}
}
}
}

View file

@ -3,12 +3,7 @@ namespace Server.Items
public class MediumStoneTableEastAddon : BaseAddon
{
[Constructible]
public MediumStoneTableEastAddon() : this(0)
{
}
[Constructible]
public MediumStoneTableEastAddon(int hue)
public MediumStoneTableEastAddon(int hue = 0)
{
AddComponent(new AddonComponent(0x1202), 0, 0, 0);
AddComponent(new AddonComponent(0x1201), 0, 1, 0);
@ -66,4 +61,4 @@ namespace Server.Items
int version = reader.ReadInt();
}
}
}
}

View file

@ -3,12 +3,7 @@ namespace Server.Items
public class MediumStoneTableSouthAddon : BaseAddon
{
[Constructible]
public MediumStoneTableSouthAddon() : this(0)
{
}
[Constructible]
public MediumStoneTableSouthAddon(int hue)
public MediumStoneTableSouthAddon(int hue = 0)
{
AddComponent(new AddonComponent(0x1205), 0, 0, 0);
AddComponent(new AddonComponent(0x1204), 1, 0, 0);
@ -66,4 +61,4 @@ namespace Server.Items
int version = reader.ReadInt();
}
}
}
}

View file

@ -1,4 +1,5 @@
using System;
using System.Linq;
using Server.Commands;
using Server.Mobiles;
@ -10,12 +11,7 @@ namespace Server.Items
private SHTeleComponent m_TeleDest;
[Constructible]
public SHTeleComponent() : this(0x1775)
{
}
[Constructible]
public SHTeleComponent(int itemID) : this(itemID, new Point3D(0, 0, 0))
public SHTeleComponent(int itemID = 0x1775) : this(itemID, new Point3D(0, 0, 0))
{
}
@ -73,7 +69,7 @@ namespace Server.Items
public override void OnDoubleClick(Mobile m)
{
if (!m_Active || m_TeleDest == null || m_TeleDest.Deleted || m_TeleDest.Map == Map.Internal)
if (!m_Active || m_TeleDest?.Deleted != false || m_TeleDest.Map == Map.Internal)
return;
if (m.InRange(this, 3))
@ -124,12 +120,7 @@ namespace Server.Items
private bool m_Changing;
[Constructible]
public SHTeleporter() : this(true)
{
}
[Constructible]
public SHTeleporter(bool external)
public SHTeleporter(bool external = true)
{
m_Changing = false;
External = external;
@ -318,16 +309,9 @@ namespace Server.Items
public static SHTeleporter FindSHTeleporter(Map map, Point3D p)
{
IPooledEnumerable<SHTeleporter> eable = map.GetItemsInRange<SHTeleporter>(p, 0);
foreach (SHTeleporter item in eable)
if (item.Z == p.Z)
{
eable.Free();
return item;
}
SHTeleporter teleporter = eable.FirstOrDefault(item => item.Z == p.Z);
eable.Free();
return null;
return teleporter;
}
public SHTeleporter AddSHT(Map map, bool ext, int x, int y, int z)
@ -435,4 +419,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -8,12 +8,7 @@ namespace Server.Items
private Timer m_Timer;
[Constructible]
public TrainingDummy() : this(0x1074)
{
}
[Constructible]
public TrainingDummy(int itemID) : base(itemID)
public TrainingDummy(int itemID = 0x1074) : base(itemID)
{
MinSkill = -25.0;
MaxSkill = +25.0;
@ -155,7 +150,7 @@ namespace Server.Items
[Constructible]
public TrainingDummyEastAddon()
{
AddComponent(new TrainingDummy(0x1074), 0, 0, 0);
AddComponent(new TrainingDummy(), 0, 0, 0);
}
public TrainingDummyEastAddon(Serial serial) : base(serial)
@ -265,4 +260,4 @@ namespace Server.Items
int version = reader.ReadInt();
}
}
}
}