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

@ -1,3 +1,4 @@
using System.Linq;
using Server.Gumps;
using Server.Multis;
using Server.Network;
@ -8,13 +9,7 @@ namespace Server.Items
public class Fireflies : Item, IAddon
{
[Constructible]
public Fireflies()
: this(0x1596)
{
}
[Constructible]
public Fireflies(int itemID)
public Fireflies(int itemID = 0x1596)
: base(itemID)
{
LootType = LootType.Blessed;
@ -65,7 +60,7 @@ namespace Server.Items
{
BaseHouse house = BaseHouse.FindHouseAt(this);
if (house != null && house.IsOwner(from))
if (house?.IsOwner(from) == true)
{
from.CloseGump<RewardDemolitionGump>();
from.SendGump(new RewardDemolitionGump(this, 1049783)); // Do you wish to re-deed this decoration?
@ -120,7 +115,7 @@ namespace Server.Items
{
BaseHouse house = BaseHouse.FindHouseAt(from);
if (house != null && house.IsOwner(from))
if (house?.IsOwner(from) == true)
{
from.CloseGump<FacingGump>();
@ -175,8 +170,8 @@ namespace Server.Items
AddItem(90, 30, 0x2332);
AddItem(180, 30, 0x2336);
AddButton(50, 35, 0x868, 0x869, (int)Buttons.East, GumpButtonType.Reply, 0);
AddButton(145, 35, 0x868, 0x869, (int)Buttons.South, GumpButtonType.Reply, 0);
AddButton(50, 35, 0x868, 0x869, (int)Buttons.East);
AddButton(145, 35, 0x868, 0x869, (int)Buttons.South);
}
public override void OnResponse(NetState sender, RelayInfo info)
@ -219,14 +214,14 @@ namespace Server.Items
protected override void OnTarget(Mobile from, object targeted)
{
if (m_FirefliesDeed == null || m_FirefliesDeed.Deleted)
if (m_FirefliesDeed?.Deleted != false)
return;
if (m_FirefliesDeed.IsChildOf(from.Backpack))
{
BaseHouse house = BaseHouse.FindHouseAt(from);
if (house != null && house.IsOwner(from))
if (house?.IsOwner(from) == true)
{
IPoint3D p = targeted as IPoint3D;
Map map = from.Map;
@ -241,16 +236,12 @@ namespace Server.Items
{
house = BaseHouse.FindHouseAt(p3d, map, id.Height);
if (house != null && house.IsOwner(from))
if (house?.IsOwner(from) == true)
{
bool north = BaseAddon.IsWall(p3d.X, p3d.Y - 1, p3d.Z, map);
bool west = BaseAddon.IsWall(p3d.X - 1, p3d.Y, p3d.Z, map);
bool isclear = true;
foreach (Item item in Map.Malas.GetItemsInRange(p3d, 0))
if (item is Fireflies)
isclear = false;
bool isclear = !Map.Malas.GetItemsInRange(p3d, 0).OfType<Fireflies>().Any();
if ((m_ItemID == 0x2336 && north || m_ItemID == 0x2332 && west) && isclear)
{
@ -290,4 +281,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -44,7 +44,8 @@ namespace Server.Engines.Events
public static void RemoveHueMod(Mobile target)
{
if (target != null && !target.Deleted) target.SolidHueOverride = -1;
if (target?.Deleted == false)
target.SolidHueOverride = -1;
}
public static void SolidHueMobile(Mobile target)
@ -67,7 +68,7 @@ namespace Server.Engines.Events
if (twin.Deleted)
return;
foreach (Item item in m_From.Items)
if (item.Layer != Layer.Backpack && item.Layer != Layer.Mount && item.Layer != Layer.Bank)
m_Items.Add(item);
@ -122,78 +123,80 @@ namespace Server.Engines.Events
protected override void OnTarget(Mobile from, object targ)
{
if (targ != null && CheckMobile(from))
if (targ == null || !CheckMobile(from))
return;
if (!(targ is Mobile))
{
if (!(targ is Mobile))
from.SendLocalizedMessage(1076781); /* There is little chance of getting candy from that! */
return;
}
BaseVendor begged = targ as BaseVendor;
if (begged?.Deleted != false)
{
from.SendLocalizedMessage(1076765); /* That doesn't look friendly. */
return;
}
DateTime now = DateTime.UtcNow;
if (CheckMobile(begged))
{
if (begged.NextTrickOrTreat > now)
{
from.SendLocalizedMessage(1076781); /* There is little chance of getting candy from that! */
from.SendLocalizedMessage(1076767); /* That doesn't appear to have any more candy. */
return;
}
if (!(targ is BaseVendor) || ((BaseVendor)targ).Deleted)
{
from.SendLocalizedMessage(1076765); /* That doesn't look friendly. */
begged.NextTrickOrTreat = now + TimeSpan.FromMinutes(Utility.RandomMinMax(5, 10));
if (from.Backpack?.Deleted != false)
return;
}
DateTime now = DateTime.UtcNow;
BaseVendor m_Begged = targ as BaseVendor;
if (CheckMobile(m_Begged))
if (Utility.RandomDouble() > .10)
{
if (m_Begged.NextTrickOrTreat > now)
switch (Utility.Random(3))
{
from.SendLocalizedMessage(1076767); /* That doesn't appear to have any more candy. */
return;
case 0:
begged.Say(1076768);
break; /* Oooooh, aren't you cute! */
case 1:
begged.Say(1076779);
break; /* All right...This better not spoil your dinner! */
case 2:
begged.Say(1076778);
break; /* Here you go! Enjoy! */
}
m_Begged.NextTrickOrTreat = now + TimeSpan.FromMinutes(Utility.RandomMinMax(5, 10));
if (from.Backpack != null && !from.Backpack.Deleted)
if (Utility.RandomDouble() <= .01 && from.Skills.Begging.Value >= 100)
{
if (Utility.RandomDouble() > .10)
{
switch (Utility.Random(3))
{
case 0:
m_Begged.Say(1076768);
break; /* Oooooh, aren't you cute! */
case 1:
m_Begged.Say(1076779);
break; /* All right...This better not spoil your dinner! */
case 2:
m_Begged.Say(1076778);
break; /* Here you go! Enjoy! */
}
from.AddToBackpack(HolidaySettings.RandomGMBeggerItem);
if (Utility.RandomDouble() <= .01 && from.Skills.Begging.Value >= 100)
{
from.AddToBackpack(HolidaySettings.RandomGMBeggerItem);
from.SendLocalizedMessage(1076777); /* You receive a special treat! */
}
else
{
from.AddToBackpack(HolidaySettings.RandomTreat);
from.SendLocalizedMessage(1076769); /* You receive some candy. */
}
}
else
{
m_Begged.Say(1076770); /* TRICK! */
int action = Utility.Random(4);
if (action == 0)
Timer.DelayCall(OneSecond, OneSecond, 10, Bleeding, from);
else if (action == 1)
Timer.DelayCall(TimeSpan.FromSeconds(2), SolidHueMobile, from);
else
Timer.DelayCall(TimeSpan.FromSeconds(2), MakeTwin, from);
}
from.SendLocalizedMessage(1076777); /* You receive a special treat! */
}
else
{
from.AddToBackpack(HolidaySettings.RandomTreat);
from.SendLocalizedMessage(1076769); /* You receive some candy. */
}
}
else
{
begged.Say(1076770); /* TRICK! */
int action = Utility.Random(4);
if (action == 0)
Timer.DelayCall(OneSecond, OneSecond, 10, Bleeding, from);
else if (action == 1)
Timer.DelayCall(TimeSpan.FromSeconds(2), SolidHueMobile, from);
else
Timer.DelayCall(TimeSpan.FromSeconds(2), MakeTwin, from);
}
}
}
@ -263,7 +266,8 @@ namespace Server.Engines.Events
public override void OnThink()
{
if (m_From == null || m_From.Deleted) Delete();
if (m_From?.Deleted != false)
Delete();
}
public static Item FindCandyTypes(Mobile target)
@ -287,7 +291,7 @@ namespace Server.Engines.Events
target.SendLocalizedMessage(1113967); /* Your naughty twin steals some of your candy. */
if (item != null && !item.Deleted)
if (item?.Deleted == false)
item.Delete();
}
else
@ -321,4 +325,4 @@ namespace Server.Engines.Events
int version = reader.ReadInt();
}
}
}
}

View file

@ -1,4 +1,5 @@
using System;
using System.Linq;
using Server.Events.Halloween;
using Server.Items;
@ -41,18 +42,10 @@ namespace Server.Engines.Events
Rectangle2D rect = m_PumpkinFields[i];
int spawncount = rect.Height * rect.Width / 20;
int pumpkins = 0;
foreach (Item item in map.GetItemsInBounds(rect))
if (item is HalloweenPumpkin)
pumpkins++;
int pumpkins = map.GetItemsInBounds(rect).OfType<HalloweenPumpkin>().Count();
if (spawncount > pumpkins)
{
Item item = new HalloweenPumpkin();
item.MoveToWorld(RandomPointIn(rect, map), map);
}
new HalloweenPumpkin().MoveToWorld(RandomPointIn(rect, map), map);
}
}
@ -65,4 +58,4 @@ namespace Server.Engines.Events
return new Point3D(x, y, z);
}
}
}
}

View file

@ -8,8 +8,7 @@
public class CreepyCake : Food
{
[Constructible]
public CreepyCake()
: base(0x9e9)
public CreepyCake() : base(0x9e9, 1)
{
Hue = 0x3E4;
}
@ -35,4 +34,4 @@
int version = reader.ReadInt();
}
}
}
}

View file

@ -3,8 +3,7 @@
public class MrPlainsCookies : Food
{
[Constructible]
public MrPlainsCookies()
: base(0x160C)
public MrPlainsCookies() : base(0x160C, 1)
{
Weight = 1.0;
FillFactor = 4;
@ -32,4 +31,4 @@
int version = reader.ReadInt();
}
}
}
}

View file

@ -39,9 +39,7 @@ namespace Server.Items.Holiday
{
get
{
if (m_Staffer != null) return $"{MaskName} hand painted by {m_Staffer}";
return MaskName;
return m_Staffer != null ? $"{MaskName} hand painted by {m_Staffer}" : MaskName;
}
}

View file

@ -87,10 +87,9 @@ namespace Server.Mobiles
public virtual void Lifted_Callback(Mobile from)
{
if (from != null && !from.Deleted && from is PlayerMobile)
if (from?.Deleted == false && from is PlayerMobile)
{
Combatant = from;
Warmode = true;
}
}
@ -127,4 +126,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -37,7 +37,7 @@ namespace Server.Engines.Events
new Rectangle2D(4528,1314,28,20), // Moonglow
new Rectangle2D(712,1104,22,30), // Yew
new Rectangle2D(5824,1464,6,22), // Fire Dungeon
new Rectangle2D(5224,3655,5,14), // T2A
new Rectangle2D(5224,3655,5,14) // T2A
};
public static void Initialize()
@ -98,7 +98,7 @@ namespace Server.Engines.Events
}
}
if ( player != null && !player.Deleted && ReAnimated.Count < m_TotalZombieLimit )
if (player?.Deleted == false && ReAnimated.Count < m_TotalZombieLimit )
{
Map map = Utility.RandomBool() ? Map.Trammel : Map.Felucca;
@ -158,7 +158,7 @@ namespace Server.Engines.Events
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( ( int )0 );
writer.Write( 0 );
}
public override void Deserialize( GenericReader reader )
@ -175,17 +175,12 @@ namespace Server.Engines.Events
private PlayerMobile m_DeadPlayer;
public ZombieSkeleton()
: this( null )
{
}
public ZombieSkeleton( PlayerMobile player )
public ZombieSkeleton(PlayerMobile player = null)
: base( AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4 )
{
m_DeadPlayer = player;
Name = ( player != null ) ? $"{player.Name}'s {m_Name}" : m_Name;
Name = player != null ? $"{player.Name}'s {m_Name}" : m_Name;
Body = 0x93;
BaseSoundID = 0x1c3;
@ -228,7 +223,7 @@ namespace Server.Engines.Events
case 2: PackItem( new Torso() ); break;
case 3: PackItem( new Bone() ); break;
case 4: PackItem( new RibCage() ); break;
case 5: if ( m_DeadPlayer != null && !m_DeadPlayer.Deleted ) { PackItem( new PlayerBones( m_DeadPlayer.Name ) ); } break;
case 5: if (m_DeadPlayer?.Deleted == false) { PackItem( new PlayerBones( m_DeadPlayer.Name ) ); } break;
default: break;
}
@ -248,7 +243,7 @@ namespace Server.Engines.Events
{
if ( HalloweenHauntings.ReAnimated != null )
{
if ( m_DeadPlayer != null && !m_DeadPlayer.Deleted )
if (m_DeadPlayer?.Deleted == false)
{
if ( HalloweenHauntings.ReAnimated.ContainsKey( m_DeadPlayer ) )
HalloweenHauntings.ReAnimated.Remove( m_DeadPlayer );

View file

@ -2,13 +2,7 @@
{
public class JellyBeans : CandyCane
{
[Constructible]
public JellyBeans()
: this(1)
{
}
public JellyBeans(int amount)
public JellyBeans(int amount = 1)
: base(0x468C)
{
Stackable = true;
@ -35,4 +29,4 @@
int version = reader.ReadInt();
}
}
}
}

View file

@ -4,13 +4,7 @@
public class Lollipops : CandyCane
{
[Constructible]
public Lollipops()
: this(1)
{
}
[Constructible]
public Lollipops(int amount)
public Lollipops(int amount = 1)
: base(0x468D + Utility.Random(3))
{
Stackable = true;
@ -35,4 +29,4 @@
int version = reader.ReadInt();
}
}
}
}

View file

@ -3,12 +3,7 @@
public class NougatSwirl : CandyCane
{
[Constructible]
public NougatSwirl() : this(1)
{
}
[Constructible]
public NougatSwirl(int amount)
public NougatSwirl(int amount = 1)
: base(0x4690)
{
Stackable = true;
@ -35,4 +30,4 @@
int version = reader.ReadInt();
}
}
}
}

View file

@ -2,13 +2,7 @@
{
public class Taffy : CandyCane
{
[Constructible]
public Taffy()
: this(1)
{
}
public Taffy(int amount)
public Taffy(int amount = 1)
: base(0x469D)
{
Stackable = true;
@ -35,4 +29,4 @@
int version = reader.ReadInt();
}
}
}
}

View file

@ -2,13 +2,7 @@
{
public class WrappedCandy : CandyCane
{
[Constructible]
public WrappedCandy()
: this(1)
{
}
public WrappedCandy(int amount)
public WrappedCandy(int amount = 1)
: base(0x469e)
{
Stackable = true;
@ -35,4 +29,4 @@
int version = reader.ReadInt();
}
}
}
}

View file

@ -167,24 +167,23 @@ namespace Server.Items
AddPage(0);
AddBackground(0, 0, 420, 320, 9300);
AddHtml(10, 10, 400, 21, "<CENTER>St. Valentine Bear</CENTER>", false, false);
AddHtmlLocalized(10, 40, 400, 75, 1150293, 0, false,
false); // Enter up to three lines of personalized greeting for your St. Valentine Bear. You many enter up to 25 characters per line. Once you enter text, you will only be able to correct mistakes for 10 minutes.
AddHtml(10, 10, 400, 21, "<CENTER>St. Valentine Bear</CENTER>");
AddHtmlLocalized(10, 40, 400, 75, 1150293, 0); // Enter up to three lines of personalized greeting for your St. Valentine Bear. You many enter up to 25 characters per line. Once you enter text, you will only be able to correct mistakes for 10 minutes.
AddHtmlLocalized(10, 129, 400, 21, 1150296, 0, false, false); // Line 1:
AddHtmlLocalized(10, 129, 400, 21, 1150296, 0); // Line 1:
AddBackground(10, 150, 400, 24, 9350);
AddTextEntry(15, 152, 390, 20, 0, 0, "", 25);
AddHtmlLocalized(10, 179, 400, 21, 1150297, 0, false, false); // Line 2:
AddHtmlLocalized(10, 179, 400, 21, 1150297, 0); // Line 2:
AddBackground(10, 200, 400, 24, 9350);
AddTextEntry(15, 202, 390, 20, 0, 1, "", 25);
AddHtmlLocalized(10, 229, 400, 21, 1150298, 0, false, false); // Line 3:
AddHtmlLocalized(10, 229, 400, 21, 1150298, 0); // Line 3:
AddBackground(10, 250, 400, 24, 9350);
AddTextEntry(15, 252, 390, 20, 0, 2, "", 25);
AddButton(15, 285, 242, 241, 0, GumpButtonType.Reply, 0);
AddButton(335, 285, 247, 248, 1, GumpButtonType.Reply, 0);
AddButton(15, 285, 242, 241, 0);
AddButton(335, 285, 247, 248, 1);
}
public override void OnResponse(NetState sender, RelayInfo info)
@ -237,13 +236,7 @@ namespace Server.Items
public class StValentinesPanda : StValentinesBear
{
[Constructible]
public StValentinesPanda()
: this(null)
{
}
[Constructible]
public StValentinesPanda(string name)
public StValentinesPanda(string name = null)
: base(0x48E0, name)
{
}
@ -272,13 +265,7 @@ namespace Server.Items
public class StValentinesPolarBear : StValentinesBear
{
[Constructible]
public StValentinesPolarBear()
: this(null)
{
}
[Constructible]
public StValentinesPolarBear(string name)
public StValentinesPolarBear(string name = null)
: base(0x48E2, name)
{
}
@ -302,4 +289,4 @@ namespace Server.Items
int version = reader.ReadInt();
}
}
}
}

View file

@ -110,7 +110,7 @@ namespace Server.Items
{
base.Serialize( writer );
writer.Write( (int)0 );
writer.Write( 0 );
writer.Write( m_From );
writer.Write( m_To );