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,4 +1,5 @@
using System;
using System.Linq;
using Server.Items;
namespace Server.Commands
@ -16,46 +17,33 @@ namespace Server.Commands
{
IPooledEnumerable<Item> eable = Map.Felucca.GetItemsInRange(new Point3D(x, y, z), 0);
foreach (Item item in eable)
if (item is MorphItem morphItem && morphItem.Z == z && morphItem.InactiveItemID == inactiveItemID &&
morphItem.ActiveItemID == activeItemID)
{
eable.Free();
return true;
}
bool found = eable.Any(item => item is MorphItem morphItem && morphItem.Z == z &&
morphItem.InactiveItemID == inactiveItemID &&
morphItem.ActiveItemID == activeItemID);
eable.Free();
return false;
return found;
}
public static bool FindEffectController(int x, int y, int z)
{
IPooledEnumerable eable = Map.Felucca.GetItemsInRange(new Point3D(x, y, z), 0);
foreach (Item item in eable)
if (item is EffectController && item.Z == z)
{
eable.Free();
return true;
}
IPooledEnumerable<Item> eable = Map.Felucca.GetItemsInRange(new Point3D(x, y, z), 0);
bool found = eable.Any(item => item is EffectController && item.Z == z);
eable.Free();
return false;
return found;
}
public static T TryCreateItem<T>(int x, int y, int z, T srcItem) where T : Item
{
IPooledEnumerable<T> eable = Map.Felucca.GetItemsInBounds<T>(new Rectangle2D(x, y, 1, 1));
foreach (T item in eable)
if (item.GetType() == srcItem.GetType())
{
eable.Free();
srcItem.Delete();
return item;
}
T t = eable.FirstOrDefault(item => item.GetType() == srcItem.GetType());
eable.Free();
if (t != null)
{
srcItem.Delete();
return t;
}
srcItem.MoveToWorld(new Point3D(x, y, z), Map.Felucca);
m_Count++;
@ -205,4 +193,4 @@ namespace Server.Commands
e.Mobile.SendMessage($"{m_Count} dynamic Khaldun item{(m_Count == 1 ? "" : "s")} generated.");
}
}
}
}

View file

@ -408,7 +408,7 @@ namespace Server.Items
DropItem(gem);
if (0.2 > Utility.RandomDouble())
DropItem(new BagOfReagents(50));
DropItem(new BagOfReagents());
for (int i = 0; i < 2; i++)
{
@ -557,7 +557,7 @@ namespace Server.Items
AddImage(62, 20, 0x67);
AddHtmlLocalized(80, 36, 110, 70, 1018309, true, false); // A Puzzle Lock
AddHtmlLocalized(80, 36, 110, 70, 1018309, true); // A Puzzle Lock
/* Correctly choose the sequence of cylinders needed to open the latch. Each cylinder
* may potentially be used more than once. Beware! A false attempt could be deadly!
@ -577,16 +577,16 @@ namespace Server.Items
double lockpicking = from.Skills.Lockpicking.Base;
if (lockpicking >= 60.0)
{
AddHtmlLocalized(160, 125, 230, 24, 1018308, false, false); // Lockpicking hint:
AddHtmlLocalized(160, 125, 230, 24, 1018308); // Lockpicking hint:
AddBackground(159, 150, 230, 95, 0x13EC);
if (lockpicking >= 80.0)
{
AddHtmlLocalized(165, 157, 200, 40, 1018312, false, false); // In the first slot:
AddHtmlLocalized(165, 157, 200, 40, 1018312); // In the first slot:
AddCylinder(350, 165, chest.Solution.First);
AddHtmlLocalized(165, 197, 200, 40, 1018313, false, false); // Used in unknown slot:
AddHtmlLocalized(165, 197, 200, 40, 1018313); // Used in unknown slot:
AddCylinder(350, 200, chest.FirstHint);
if (lockpicking >= 90.0)
@ -597,7 +597,7 @@ namespace Server.Items
}
else
{
AddHtmlLocalized(165, 157, 200, 40, 1018313, false, false); // Used in unknown slot:
AddHtmlLocalized(165, 157, 200, 40, 1018313); // Used in unknown slot:
AddCylinder(350, 160, chest.FirstHint);
if (lockpicking >= 70.0)
@ -608,7 +608,7 @@ namespace Server.Items
PuzzleChestSolution lastGuess = chest.GetLastGuess(from);
if (lastGuess != null)
{
AddHtmlLocalized(127, 249, 170, 20, 1018311, false, false); // Thy previous guess:
AddHtmlLocalized(127, 249, 170, 20, 1018311); // Thy previous guess:
AddBackground(290, 247, 115, 25, 0x13EC);
@ -625,21 +625,21 @@ namespace Server.Items
AddPedestal(305, 270, solution.Fourth, 3, check == 3);
AddPedestal(360, 270, solution.Fifth, 4, check == 4);
AddButton(258, 370, 0xFA5, 0xFA7, 1, GumpButtonType.Reply, 0);
AddButton(258, 370, 0xFA5, 0xFA7, 1);
}
private void AddLeftCylinderButton(int x, int y, PuzzleChestCylinder cylinder, int buttonID)
{
AddBackground(x, y, 30, 30, 0x13EC);
AddCylinder(x - 7, y + 10, cylinder);
AddButton(x + 38, y + 9, 0x13A8, 0x4B9, buttonID, GumpButtonType.Reply, 0);
AddButton(x + 38, y + 9, 0x13A8, 0x4B9, buttonID);
}
private void AddRightCylinderButton(int x, int y, PuzzleChestCylinder cylinder, int buttonID)
{
AddBackground(x, y, 30, 30, 0x13EC);
AddCylinder(x - 7, y + 10, cylinder);
AddButton(x - 26, y + 9, 0x13A8, 0x4B9, buttonID, GumpButtonType.Reply, 0);
AddButton(x - 26, y + 9, 0x13A8, 0x4B9, buttonID);
}
private void AddPedestal(int x, int y, PuzzleChestCylinder cylinder, int switchID, bool initialState)
@ -739,15 +739,15 @@ namespace Server.Items
AddBackground(15, 250, 305, 163, 0x53);
AddBackground(28, 265, 280, 133, 0xBB8);
AddHtmlLocalized(35, 271, 270, 24, 1018314, false, false); // Thou hast failed to solve the puzzle!
AddHtmlLocalized(35, 271, 270, 24, 1018314); // Thou hast failed to solve the puzzle!
AddHtmlLocalized(35, 297, 250, 24, 1018315, false, false); // Correctly placed colors:
AddHtmlLocalized(35, 297, 250, 24, 1018315); // Correctly placed colors:
AddLabel(285, 297, 0x44, correctCylinders.ToString());
AddHtmlLocalized(35, 323, 250, 24, 1018316, false, false); // Used colors in wrong slots:
AddHtmlLocalized(35, 323, 250, 24, 1018316); // Used colors in wrong slots:
AddLabel(285, 323, 0x44, correctColors.ToString());
AddButton(152, 369, 0xFA5, 0xFA7, 0, GumpButtonType.Reply, 0);
AddButton(152, 369, 0xFA5, 0xFA7, 0);
}
}
}
@ -805,4 +805,4 @@ namespace Server.Items
int version = reader.ReadEncodedInt();
}
}
}
}

View file

@ -1,4 +1,5 @@
using System;
using System.Linq;
using Server.Network;
namespace Server.Items
@ -7,12 +8,7 @@ namespace Server.Items
{
private ResetTimer m_ResetTimer;
[Constructible]
public RaiseSwitch() : this(0x1093)
{
}
protected RaiseSwitch(int itemID) : base(itemID)
public RaiseSwitch(int itemID = 0x1093) : base(itemID)
{
Movable = false;
}
@ -32,24 +28,24 @@ namespace Server.Items
return;
}
if (RaisableItem != null && RaisableItem.Deleted)
if (RaisableItem?.Deleted == true)
RaisableItem = null;
Flip();
if (RaisableItem != null)
if (RaisableItem == null)
return;
if (RaisableItem.IsRaisable)
{
if (RaisableItem.IsRaisable)
{
RaisableItem.Raise();
m.LocalOverheadMessage(MessageType.Regular, 0x5A, true,
"You hear a grinding noise echoing in the distance.");
}
else
{
m.LocalOverheadMessage(MessageType.Regular, 0x5A, true,
"You flip the switch again, but nothing happens.");
}
RaisableItem.Raise();
m.LocalOverheadMessage(MessageType.Regular, 0x5A, true,
"You hear a grinding noise echoing in the distance.");
}
else
{
m.LocalOverheadMessage(MessageType.Regular, 0x5A, true,
"You flip the switch again, but nothing happens.");
}
}
@ -65,10 +61,7 @@ namespace Server.Items
{
ItemID = 0x1095;
if (RaisableItem != null && RaisableItem.CloseDelay >= TimeSpan.Zero)
StartResetTimer(RaisableItem.CloseDelay);
else
StartResetTimer(TimeSpan.FromMinutes(2.0));
StartResetTimer(RaisableItem?.CloseDelay >= TimeSpan.Zero ? RaisableItem.CloseDelay : TimeSpan.FromMinutes(2.0));
}
Effects.PlaySound(Location, Map, 0x3E8);
@ -183,22 +176,12 @@ namespace Server.Items
public void Refresh()
{
bool found = false;
foreach (Mobile mob in GetMobilesInRange(CurrentRange))
{
if (mob.Hidden && mob.AccessLevel > AccessLevel.Player)
continue;
found = true;
break;
}
Visible = found;
Visible = GetMobilesInRange(CurrentRange).Any(mob => !mob.Hidden || mob.AccessLevel <= AccessLevel.Player);
}
public override void Serialize(GenericWriter writer)
{
if (RaisableItem != null && RaisableItem.Deleted)
if (RaisableItem?.Deleted == true)
RaisableItem = null;
base.Serialize(writer);
@ -215,4 +198,4 @@ namespace Server.Items
Timer.DelayCall(TimeSpan.Zero, Refresh);
}
}
}
}