Fixes bad expressions, bad bool checks in loops, a few null pointer exceptions, and optimizes constructors.

This commit is contained in:
Kamron Batman 2018-09-15 23:16:45 -07:00
parent 8da55d6043
commit f93c3b992e
62 changed files with 318 additions and 634 deletions

View file

@ -220,9 +220,6 @@ namespace Server.Engines.Doom
else
trap = new MushroomTrap();
if (trap == null)
return;
if (trap is FireColumnTrap || trap is MushroomTrap)
trap.Hue = 0x451;

View file

@ -327,7 +327,7 @@ namespace Server.Factions
{
double prio = m_Mobile.GetDistanceToSqrt(m);
if (!activeOnly && (inactive == null || prio < inactPrio))
if (inactive == null || prio < inactPrio)
{
inactive = m;
inactPrio = prio;

View file

@ -160,48 +160,48 @@ namespace Server.PathAlgorithms.FastAStar
bool wasTouched = m_Touched[newNode];
if (!wasTouched)
if (wasTouched)
continue;
int newCost = m_Nodes[bestNode].cost + 1;
int newTotal = newCost + Heuristic(newNode % AreaSize, newNode / AreaSize % AreaSize,
m_Nodes[newNode].z);
if (m_Nodes[newNode].total <= newTotal)
continue;
m_Nodes[newNode].parent = bestNode;
m_Nodes[newNode].cost = newCost;
m_Nodes[newNode].total = newTotal;
if (m_OnOpen[newNode])
continue;
AddToChain(newNode);
if (newNode != destNode)
continue;
pathCount = 0;
parent = m_Nodes[newNode].parent;
while (parent != -1)
{
int newCost = m_Nodes[bestNode].cost + 1;
int newTotal = newCost + Heuristic(newNode % AreaSize, newNode / AreaSize % AreaSize,
m_Nodes[newNode].z);
path[pathCount++] = GetDirection(parent % AreaSize, parent / AreaSize % AreaSize,
newNode % AreaSize, newNode / AreaSize % AreaSize);
newNode = parent;
parent = m_Nodes[newNode].parent;
if (!wasTouched || m_Nodes[newNode].total > newTotal)
{
m_Nodes[newNode].parent = bestNode;
m_Nodes[newNode].cost = newCost;
m_Nodes[newNode].total = newTotal;
if (!wasTouched || !m_OnOpen[newNode])
{
AddToChain(newNode);
if (newNode == destNode)
{
pathCount = 0;
parent = m_Nodes[newNode].parent;
while (parent != -1)
{
path[pathCount++] = GetDirection(parent % AreaSize, parent / AreaSize % AreaSize,
newNode % AreaSize, newNode / AreaSize % AreaSize);
newNode = parent;
parent = m_Nodes[newNode].parent;
if (newNode == fromNode)
break;
}
Direction[] dirs = new Direction[pathCount];
while (pathCount > 0)
dirs[backtrack++] = path[--pathCount];
return dirs;
}
}
}
if (newNode == fromNode)
break;
}
Direction[] dirs = new Direction[pathCount];
while (pathCount > 0)
dirs[backtrack++] = path[--pathCount];
return dirs;
}
}

View file

@ -529,7 +529,7 @@ namespace Server.Movement
zLow = landZ;
zCenter = landCenter;
if (!isSet || landTop > zTop)
if (landTop > zTop)
zTop = landTop;
isSet = true;

View file

@ -152,10 +152,10 @@ namespace Server.Engines.Plants
if (firstPrimary && secondPrimary)
return notBrightFirst | notBrightSecond;
if (firstPrimary && !secondPrimary)
if (firstPrimary)
return notBrightFirst;
if (!firstPrimary && secondPrimary)
if (secondPrimary)
return notBrightSecond;
return notBrightFirst & notBrightSecond;

View file

@ -125,15 +125,8 @@ namespace Server.Engines.Plants
private int m_SeedLabelPlural;
private PlantTypeInfo(int itemID, int offsetX, int offsetY, PlantType plantType, bool containsPlant, bool flowery,
bool crossable, bool reproduces, PlantCategory plantCategory)
: this(itemID, offsetX, offsetY, plantType, containsPlant, flowery, crossable, reproduces, plantCategory, -1, -1,
-1, -1, -1, -1)
{
}
private PlantTypeInfo(int itemID, int offsetX, int offsetY, PlantType plantType, bool containsPlant, bool flowery,
bool crossable, bool reproduces, PlantCategory plantCategory, int plantLabelSeed, int plantLabelPlant,
int plantLabelFullGrown, int plantLabelDecorative, int seedLabel, int seedLabelPlural)
bool crossable, bool reproduces, PlantCategory plantCategory, int plantLabelSeed = -1, int plantLabelPlant = -1,
int plantLabelFullGrown = -1, int plantLabelDecorative = -1, int seedLabel = -1, int seedLabelPlural = -1)
{
ItemID = itemID;
OffsetX = offsetX;

View file

@ -110,7 +110,7 @@ namespace Server.Engines.Quests.Doom
}
else
{
bool hasRights = true;
bool hasRights = false;
if (m_Daemon != null)
{

View file

@ -72,11 +72,12 @@ namespace Server.RemoteAdmin
{
LazyInitialize();
if (!Enabled) return;
if (!Enabled)
return;
try
{
Account acct = state.Account as Account;
Account acct = state?.Account as Account;
string name = acct == null ? "(UNKNOWN)" : acct.Username;
string accesslevel = acct == null ? "NoAccount" : acct.AccessLevel.ToString();
string statestr = state == null ? "NULLSTATE" : state.ToString();
@ -97,6 +98,7 @@ namespace Server.RemoteAdmin
}
catch
{
// ignored
}
}
}

View file

@ -188,15 +188,14 @@ namespace Server.Engines.Reports
for (int i = 0; i < _chartItems.Count; i++)
{
DataItem item = (DataItem)_chartItems[i];
SolidBrush brs = null;
DataItem item = (DataItem)_chartItems[i];
try
{
grp.DrawPie(new Pen(_borderColor, 0.5f), pieRect, item.StartPos, item.SweepSize);
}
finally
catch
{
brs?.Dispose();
// ignored
}
}
@ -226,8 +225,8 @@ namespace Server.Engines.Reports
}
finally
{
sf?.Dispose();
grp?.Dispose();
sf.Dispose();
grp.Dispose();
sfp?.Dispose();
fnt?.Dispose();
pen?.Dispose();

View file

@ -354,44 +354,40 @@ namespace Server.Mobiles
{
Defrag();
if (Entries.Count > 0 && !IsFull)
if (Entries.Count <= 0 || IsFull)
return;
int probsum = 0;
for (int i = 0; i < Entries.Count; i++)
if (!Entries[i].IsFull)
probsum += Entries[i].SpawnedProbability;
if (probsum <= 0)
return;
int rand = Utility.RandomMinMax(1, probsum);
for (int i = 0; i < Entries.Count; i++)
{
int probsum = 0;
SpawnerEntry entry = Entries[i];
if (entry.IsFull)
continue;
for (int i = 0; i < Entries.Count; i++)
if (!Entries[i].IsFull)
probsum += Entries[i].SpawnedProbability;
if (probsum > 0)
if (rand <= entry.SpawnedProbability)
{
int rand = Utility.RandomMinMax(1, probsum);
for (int i = 0; i < Entries.Count; i++)
{
SpawnerEntry entry = Entries[i];
if (!entry.IsFull)
{
bool success = true;
if (rand <= entry.SpawnedProbability)
{
EntryFlags flags;
success = Spawn(entry, out flags);
entry.Valid = flags;
return;
}
if (success)
rand -= entry.SpawnedProbability;
}
}
Spawn(entry, out EntryFlags flags);
entry.Valid = flags;
return;
}
rand -= entry.SpawnedProbability;
}
}
private static string[,] FormatProperties(string[] args)
{
string[,] props = null;
string[,] props;
int remains = args.Length;

View file

@ -11,15 +11,7 @@ namespace Server.Mobiles
private int m_Page;
private Spawner m_Spawner;
public SpawnerGump(Spawner spawner) : this(spawner, 0)
{
}
public SpawnerGump(Spawner spawner, int page) : this(spawner, null, page)
{
}
public SpawnerGump(Spawner spawner, SpawnerEntry focusentry, int page) : base(50, 50)
public SpawnerGump(Spawner spawner, SpawnerEntry focusentry = null, int page = 0) : base(50, 50)
{
m_Spawner = spawner;
m_Entry = focusentry;
@ -51,7 +43,7 @@ namespace Server.Mobiles
AddButton(5, 22 * i + 21 + offset, entry != null ? 0xFBA : 0xFA5, entry != null ? 0xFBC : 0xFA7,
GetButtonID(2, i * 2), GumpButtonType.Reply, 0); //Expand
else
AddButton(5, 22 * i + 21 + offset, entry != null ? 0xFBB : 0xFA5, entry != null ? 0xFBC : 0xFA7,
AddButton(5, 22 * i + 21 + offset, 0xFBB, 0xFBC,
GetButtonID(2, i * 2), GumpButtonType.Reply, 0); //Unexpand
AddButton(38, 22 * i + 21 + offset, 0xFA2, 0xFA4, GetButtonID(2, 1 + i * 2), GumpButtonType.Reply,
@ -163,7 +155,7 @@ namespace Server.Mobiles
if (type != null)
{
SpawnerEntry entry = null;
SpawnerEntry entry;
if (entryindex < ocount)
{
@ -221,8 +213,6 @@ namespace Server.Mobiles
if (m_Spawner.Deleted)
return;
Mobile from = state.Mobile;
int val = info.ButtonID - 1;
if (val < 0)
@ -309,7 +299,7 @@ namespace Server.Mobiles
}
}
if (m_Entry != null && m_Spawner.Entries.Contains(m_Entry))
if (m_Entry != null && m_Spawner.Entries?.Contains(m_Entry) == true)
state.Mobile.SendGump(new SpawnerGump(m_Spawner, m_Entry, m_Page));
else
state.Mobile.SendGump(new SpawnerGump(m_Spawner, null, m_Page));

View file

@ -53,7 +53,7 @@ namespace Server.Gumps
string fealtyName;
if (fealty == null || (fealtyName = fealty.Name) == null || (fealtyName = fealtyName.Trim()).Length <= 0)
if ((fealtyName = fealty.Name) == null || (fealtyName = fealtyName.Trim()).Length <= 0)
fealtyName = "(empty)";
if (beholder == fealty)

View file

@ -652,23 +652,15 @@ namespace Server.Gumps
private class CustomItem
{
public CustomItem(int itemID, int loc) : this(null, itemID, loc, 0, false)
public CustomItem(int itemID, int loc, bool longText = false) : this(null, itemID, loc, 0, longText)
{
}
public CustomItem(int itemID, int loc, bool longText) : this(null, itemID, loc, 0, longText)
public CustomItem(Type type, int loc, int art = 0) : this(type, 0, loc, art)
{
}
public CustomItem(Type type, int loc) : this(type, loc, 0)
{
}
public CustomItem(Type type, int loc, int art) : this(type, 0, loc, art, false)
{
}
public CustomItem(Type type, int itemID, int loc, int art, bool longText)
public CustomItem(Type type, int itemID = 0, int loc = 0, int art = 0, bool longText = false)
{
Type = type;
ItemID = itemID;
@ -702,6 +694,7 @@ namespace Server.Gumps
}
catch
{
// ignored
}
return i;

View file

@ -452,9 +452,7 @@ namespace Server.Gumps
private static bool HasAttribute(Type type, Type check, bool inherit)
{
object[] objs = type.GetCustomAttributes(check, inherit);
return objs != null && objs.Length > 0;
return type.GetCustomAttributes(check, inherit).Length > 0;
}
private static bool IsType(Type type, Type check)

View file

@ -140,8 +140,7 @@ namespace Server.Gumps
public override void OnResponse(NetState sender, RelayInfo info)
{
object toSet;
bool shouldSet, shouldSend = true;
bool shouldSend = true;
object viewProps = null;
switch (info.ButtonID)
@ -149,25 +148,17 @@ namespace Server.Gumps
case 0: // closed
{
m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page));
toSet = null;
shouldSet = false;
shouldSend = false;
break;
}
case 1: // Change by Target
{
m_Mobile.Target = new SetObjectTarget(m_Property, m_Mobile, m_Object, m_Stack, m_Type, m_Page, m_List);
toSet = null;
shouldSet = false;
shouldSend = false;
break;
}
case 2: // Change by Serial
{
toSet = null;
shouldSet = false;
shouldSend = false;
m_Mobile.SendMessage("Enter the serial you wish to find:");
@ -177,16 +168,20 @@ namespace Server.Gumps
}
case 3: // Nullify
{
toSet = null;
shouldSet = true;
try
{
CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name, "(null)");
m_Property.SetValue(m_Object, null, null);
PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack);
}
catch
{
m_Mobile.SendMessage("An exception was caught. The property may not have changed.");
}
break;
}
case 4: // View Properties
{
toSet = null;
shouldSet = false;
object obj = m_Property.GetValue(m_Object, null);
if (obj == null)
@ -196,30 +191,10 @@ namespace Server.Gumps
else
viewProps = obj;
break;
}
default:
{
toSet = null;
shouldSet = false;
break;
}
}
if (shouldSet)
try
{
CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name,
toSet == null ? "(null)" : toSet.ToString());
m_Property.SetValue(m_Object, toSet, null);
PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack);
}
catch
{
m_Mobile.SendMessage("An exception was caught. The property may not have changed.");
}
if (shouldSend)
m_Mobile.SendGump(new SetObjectGump(m_Property, m_Mobile, m_Object, m_Stack, m_Type, m_Page, m_List));
@ -256,52 +231,41 @@ namespace Server.Gumps
public override void OnResponse(Mobile from, string text)
{
object toSet;
bool shouldSet;
try
{
int serial = Utility.ToInt32(text);
toSet = World.FindEntity(serial);
IEntity toSet = World.FindEntity(serial);
if (toSet == null)
{
shouldSet = false;
m_Mobile.SendMessage("No object with that serial was found.");
}
else if (!m_Type.IsAssignableFrom(toSet.GetType()))
else if (!m_Type.IsInstanceOfType(toSet))
{
toSet = null;
shouldSet = false;
m_Mobile.SendMessage("The object with that serial could not be assigned to a property of type : {0}",
m_Type.Name);
}
else
{
shouldSet = true;
try
{
CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name,
toSet.ToString());
m_Property.SetValue(m_Object, toSet, null);
PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack);
}
catch
{
m_Mobile.SendMessage("An exception was caught. The property may not have changed.");
}
}
}
catch
{
toSet = null;
shouldSet = false;
m_Mobile.SendMessage("Bad format");
}
if (shouldSet)
try
{
CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name,
toSet == null ? "(null)" : toSet.ToString());
m_Property.SetValue(m_Object, toSet, null);
PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack);
}
catch
{
m_Mobile.SendMessage("An exception was caught. The property may not have changed.");
}
m_Mobile.SendGump(new SetObjectGump(m_Property, m_Mobile, m_Object, m_Stack, m_Type, m_Page, m_List));
}
}

View file

@ -44,7 +44,7 @@ namespace Server.Gumps
AddHtmlLocalized(45, 110, 150, 20, 1061279, GetColor(SecureLevel.Friends), false, false); // Friends
Mobile houseOwner = house.Owner;
if (Guild.NewGuildSystem && house != null && houseOwner?.Guild != null &&
if (Guild.NewGuildSystem && houseOwner?.Guild != null &&
((Guild)houseOwner.Guild).Leader == houseOwner
) //Only the actual House owner AND guild master can set guild secures
{

View file

@ -65,32 +65,32 @@ namespace Server.Engines.Events
{
Mobile twin = new NaughtyTwin(m_From);
if (twin != null && !twin.Deleted)
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);
if (m_Items.Count > 0)
{
foreach (Item item in m_From.Items)
for (int i = 0; i < m_Items.Count; i++) /* dupe exploits start out like this ... */
twin.AddItem(Mobile.LiftItemDupe(m_Items[i], 1));
foreach (Item item in twin.Items) /* ... and end like this */
if (item.Layer != Layer.Backpack && item.Layer != Layer.Mount && item.Layer != Layer.Bank)
m_Items.Add(item);
if (m_Items.Count > 0)
{
for (int i = 0; i < m_Items.Count; i++) /* dupe exploits start out like this ... */
twin.AddItem(Mobile.LiftItemDupe(m_Items[i], 1));
foreach (Item item in twin.Items) /* ... and end like this */
if (item.Layer != Layer.Backpack && item.Layer != Layer.Mount && item.Layer != Layer.Bank)
item.Movable = false;
}
twin.Hue = m_From.Hue;
twin.BodyValue = m_From.BodyValue;
twin.Kills = m_From.Kills;
Point3D point = RandomPointOneAway(m_From.X, m_From.Y, m_From.Z, m_From.Map);
twin.MoveToWorld(m_From.Map.CanSpawnMobile(point) ? point : m_From.Location, m_From.Map);
Timer.DelayCall(TimeSpan.FromSeconds(5), DeleteTwin, twin);
item.Movable = false;
}
twin.Hue = m_From.Hue;
twin.BodyValue = m_From.BodyValue;
twin.Kills = m_From.Kills;
Point3D point = RandomPointOneAway(m_From.X, m_From.Y, m_From.Z, m_From.Map);
twin.MoveToWorld(m_From.Map.CanSpawnMobile(point) ? point : m_From.Location, m_From.Map);
Timer.DelayCall(TimeSpan.FromSeconds(5), DeleteTwin, twin);
}
}
@ -184,11 +184,11 @@ namespace Server.Engines.Events
{
m_Begged.Say(1076770); /* TRICK! */
int m_Action = Utility.Random(4);
int action = Utility.Random(4);
if (m_Action == 0)
if (action == 0)
Timer.DelayCall(OneSecond, OneSecond, 10, Bleeding, from);
else if (m_Action == 1)
else if (action == 1)
Timer.DelayCall(TimeSpan.FromSeconds(2), SolidHueMobile, from);
else
Timer.DelayCall(TimeSpan.FromSeconds(2), MakeTwin, from);
@ -302,8 +302,6 @@ namespace Server.Engines.Events
public static Point3D RandomMoongate(Mobile target)
{
Map map = target.Map;
switch (target.Map.MapID)
{
case 2: return Ilshenar_Locations[Utility.Random(Ilshenar_Locations.Length)];

View file

@ -7,11 +7,10 @@ namespace Server.Items
{
int itemID = 4280;
int count = 5;
bool leftToRight = false;
for (int i = 0; i < count; ++i)
AddComponent(new AddonComponent(itemID++), leftToRight ? i : count - 1 - i,
-(leftToRight ? i : count - 1 - i), 0);
AddComponent(new AddonComponent(itemID++), count - 1 - i,
-(count - 1 - i), 0);
}
public GiantWeb1(Serial serial)
@ -41,11 +40,10 @@ namespace Server.Items
{
int itemID = 4285;
int count = 5;
bool leftToRight = true;
for (int i = 0; i < count; ++i)
AddComponent(new AddonComponent(itemID++), leftToRight ? i : count - 1 - i,
-(leftToRight ? i : count - 1 - i), 0);
AddComponent(new AddonComponent(itemID++), i,
-i, 0);
}
public GiantWeb2(Serial serial)
@ -75,11 +73,10 @@ namespace Server.Items
{
int itemID = 4290;
int count = 4;
bool leftToRight = true;
for (int i = 0; i < count; ++i)
AddComponent(new AddonComponent(itemID++), leftToRight ? i : count - 1 - i,
-(leftToRight ? i : count - 1 - i), 0);
AddComponent(new AddonComponent(itemID++), i,
-i, 0);
}
public GiantWeb3(Serial serial)
@ -109,11 +106,10 @@ namespace Server.Items
{
int itemID = 4294;
int count = 4;
bool leftToRight = false;
for (int i = 0; i < count; ++i)
AddComponent(new AddonComponent(itemID++), leftToRight ? i : count - 1 - i,
-(leftToRight ? i : count - 1 - i), 0);
AddComponent(new AddonComponent(itemID++), count - 1 - i,
-(count - 1 - i), 0);
}
public GiantWeb4(Serial serial)
@ -143,11 +139,10 @@ namespace Server.Items
{
int itemID = 4298;
int count = 4;
bool leftToRight = true;
for (int i = 0; i < count; ++i)
AddComponent(new AddonComponent(itemID++), leftToRight ? i : count - 1 - i,
-(leftToRight ? i : count - 1 - i), 0);
AddComponent(new AddonComponent(itemID++), i,
-i, 0);
}
public GiantWeb5(Serial serial)
@ -177,11 +172,10 @@ namespace Server.Items
{
int itemID = 4302;
int count = 4;
bool leftToRight = false;
for (int i = 0; i < count; ++i)
AddComponent(new AddonComponent(itemID++), leftToRight ? i : count - 1 - i,
-(leftToRight ? i : count - 1 - i), 0);
AddComponent(new AddonComponent(itemID++), count - 1 - i,
-(count - 1 - i), 0);
}
public GiantWeb6(Serial serial)

View file

@ -197,21 +197,21 @@ namespace Server.Items
{
Item item = m_Content.Construct();
if (item != null)
if (item == null)
continue;
List<Item> list = Items;
for (int j = 0; j < list.Count; ++j)
{
List<Item> list = Items;
Item subItem = list[j];
for (int j = 0; j < list.Count; ++j)
{
Item subItem = list[j];
if (!(subItem is Container) && subItem.StackWith(null, item, false))
break;
}
if (item != null && !item.Deleted)
DropItem(item);
if (!(subItem is Container) && subItem.StackWith(null, item, false))
break;
}
if (!item.Deleted)
DropItem(item);
}
}

View file

@ -17,11 +17,7 @@ namespace Server.Items
}
}*/
protected Beard(int itemID) : this(itemID, 0)
{
}
protected Beard(int itemID, int hue) : base(itemID)
protected Beard(int itemID, int hue = 0) : base(itemID)
{
LootType = LootType.Blessed;
Layer = Layer.FacialHair;
@ -67,12 +63,7 @@ namespace Server.Items
public class GenericBeard : Beard
{
private GenericBeard(int itemID) : this(itemID, 0)
{
}
private GenericBeard(int itemID, int hue) : base(itemID, hue)
private GenericBeard(int itemID, int hue = 0) : base(itemID, hue)
{
}
@ -97,12 +88,7 @@ namespace Server.Items
public class LongBeard : Beard
{
private LongBeard()
: this(0)
{
}
private LongBeard(int hue)
private LongBeard(int hue = 0)
: base(0x203E, hue)
{
}
@ -128,13 +114,7 @@ namespace Server.Items
public class ShortBeard : Beard
{
private ShortBeard()
: this(0)
{
}
private ShortBeard(int hue)
private ShortBeard(int hue = 0)
: base(0x203f, hue)
{
}
@ -160,13 +140,7 @@ namespace Server.Items
public class Goatee : Beard
{
private Goatee()
: this(0)
{
}
private Goatee(int hue)
private Goatee(int hue = 0)
: base(0x2040, hue)
{
}
@ -192,13 +166,7 @@ namespace Server.Items
public class Mustache : Beard
{
private Mustache()
: this(0)
{
}
private Mustache(int hue)
private Mustache(int hue = 0)
: base(0x2041, hue)
{
}
@ -224,13 +192,7 @@ namespace Server.Items
public class MediumShortBeard : Beard
{
private MediumShortBeard()
: this(0)
{
}
private MediumShortBeard(int hue)
private MediumShortBeard(int hue = 0)
: base(0x204B, hue)
{
}
@ -256,13 +218,7 @@ namespace Server.Items
public class MediumLongBeard : Beard
{
private MediumLongBeard()
: this(0)
{
}
private MediumLongBeard(int hue)
private MediumLongBeard(int hue = 0)
: base(0x204C, hue)
{
}
@ -288,13 +244,7 @@ namespace Server.Items
public class Vandyke : Beard
{
private Vandyke()
: this(0)
{
}
private Vandyke(int hue)
private Vandyke(int hue = 0)
: base(0x204D, hue)
{
}

View file

@ -62,12 +62,7 @@ namespace Server.Items
}
* */
protected Hair(int itemID)
: this(itemID, 0)
{
}
protected Hair(int itemID, int hue)
protected Hair(int itemID, int hue = 0)
: base(itemID)
{
LootType = LootType.Blessed;
@ -115,13 +110,7 @@ namespace Server.Items
public class GenericHair : Hair
{
private GenericHair(int itemID)
: this(itemID, 0)
{
}
private GenericHair(int itemID, int hue)
private GenericHair(int itemID, int hue = 0)
: base(itemID, hue)
{
}
@ -148,13 +137,7 @@ namespace Server.Items
public class Mohawk : Hair
{
private Mohawk()
: this(0)
{
}
private Mohawk(int hue)
private Mohawk(int hue = 0)
: base(0x2044, hue)
{
}
@ -181,13 +164,7 @@ namespace Server.Items
public class PageboyHair : Hair
{
private PageboyHair()
: this(0)
{
}
private PageboyHair(int hue)
private PageboyHair(int hue = 0)
: base(0x2045, hue)
{
}
@ -214,13 +191,7 @@ namespace Server.Items
public class BunsHair : Hair
{
private BunsHair()
: this(0)
{
}
private BunsHair(int hue)
private BunsHair(int hue = 0)
: base(0x2046, hue)
{
}
@ -247,13 +218,7 @@ namespace Server.Items
public class LongHair : Hair
{
private LongHair()
: this(0)
{
}
private LongHair(int hue)
private LongHair(int hue = 0)
: base(0x203C, hue)
{
}
@ -280,13 +245,7 @@ namespace Server.Items
public class ShortHair : Hair
{
private ShortHair()
: this(0)
{
}
private ShortHair(int hue)
private ShortHair(int hue = 0)
: base(0x203B, hue)
{
}
@ -313,13 +272,7 @@ namespace Server.Items
public class PonyTail : Hair
{
private PonyTail()
: this(0)
{
}
private PonyTail(int hue)
private PonyTail(int hue = 0)
: base(0x203D, hue)
{
}
@ -346,13 +299,7 @@ namespace Server.Items
public class Afro : Hair
{
private Afro()
: this(0)
{
}
private Afro(int hue)
private Afro(int hue = 0)
: base(0x2047, hue)
{
}
@ -379,13 +326,7 @@ namespace Server.Items
public class ReceedingHair : Hair
{
private ReceedingHair()
: this(0)
{
}
private ReceedingHair(int hue)
private ReceedingHair(int hue = 0)
: base(0x2048, hue)
{
}
@ -412,13 +353,7 @@ namespace Server.Items
public class TwoPigTails : Hair
{
private TwoPigTails()
: this(0)
{
}
private TwoPigTails(int hue)
private TwoPigTails(int hue = 0)
: base(0x2049, hue)
{
}
@ -445,13 +380,7 @@ namespace Server.Items
public class KrisnaHair : Hair
{
private KrisnaHair()
: this(0)
{
}
private KrisnaHair(int hue)
private KrisnaHair(int hue = 0)
: base(0x204A, hue)
{
}

View file

@ -126,7 +126,7 @@ namespace Server.Items
armor.ColdBonus =
armor.PoisonBonus = armor.EnergyBonus = 0; // Is there a method to remove bonuses?
}
else if (weapon != null)
else
{
weapon.Quality = WeaponQuality.Regular;
weapon.Crafter = from;

View file

@ -488,44 +488,32 @@ namespace Server.Items
public static Container Mobile_CreateCorpseHandler(Mobile owner, HairInfo hair, FacialHairInfo facialhair,
List<Item> initialContent, List<Item> equipItems)
{
bool shouldFillCorpse = true;
//if ( owner is BaseCreature )
// shouldFillCorpse = !((BaseCreature)owner).IsBonded;
Corpse c;
if (owner is MilitiaFighter)
c = new MilitiaFighterCorpse(owner, hair, facialhair, shouldFillCorpse ? equipItems : new List<Item>());
c = new MilitiaFighterCorpse(owner, hair, facialhair, equipItems);
else
c = new Corpse(owner, hair, facialhair, shouldFillCorpse ? equipItems : new List<Item>());
c = new Corpse(owner, hair, facialhair, equipItems);
owner.Corpse = c;
if (shouldFillCorpse)
for (int i = 0; i < initialContent.Count; ++i)
{
for (int i = 0; i < initialContent.Count; ++i)
{
Item item = initialContent[i];
Item item = initialContent[i];
if (Core.AOS && owner.Player && item.Parent == owner.Backpack)
c.AddItem(item);
else
c.DropItem(item);
if (Core.AOS && owner.Player && item.Parent == owner.Backpack)
c.AddItem(item);
else
c.DropItem(item);
if (owner.Player && Core.AOS)
c.SetRestoreInfo(item, item.Location);
}
if (Core.SE && !owner.Player)
c.AssignInstancedLoot();
else if (Core.AOS && owner is PlayerMobile pm)
c.RestoreEquip = pm.EquipSnapshot;
}
else
{
c.Carved = true; // TODO: Is it needed?
if (owner.Player && Core.AOS)
c.SetRestoreInfo(item, item.Location);
}
if (Core.SE && !owner.Player)
c.AssignInstancedLoot();
else if (Core.AOS && owner is PlayerMobile pm)
c.RestoreEquip = pm.EquipSnapshot;
Point3D loc = owner.Location;
Map map = owner.Map;
@ -769,11 +757,11 @@ namespace Server.Items
public bool DevourCorpse()
{
if (Devoured || Deleted || Killer == null || Killer.Deleted || !Killer.Alive || !(Killer is IDevourer) ||
if (Devoured || Deleted || Killer == null || Killer.Deleted || !Killer.Alive || !(Killer is IDevourer devourer) ||
Owner == null || Owner.Deleted)
return false;
m_Devourer = (IDevourer)Killer; // Set the devourer the killer
m_Devourer = devourer; // Set the devourer the killer
return m_Devourer.Devour(this); // Devour the corpse if it hasn't
}
@ -803,7 +791,7 @@ namespace Server.Items
{
PartyMemberInfo pmi = p[Owner];
if (pmi != null && pmi.CanLoot)
if (pmi?.CanLoot == true)
return false;
}

View file

@ -197,27 +197,24 @@ namespace Server.Items
BaseCreature bc =
(BaseCreature)Activator.CreateInstance(Creatures[Utility.Random(Creatures.Length)]);
if (bc != null)
Point3D spawnLoc = GetSpawnPosition();
DoEffect(spawnLoc, map);
Timer.DelayCall(TimeSpan.FromSeconds(1), delegate
{
Point3D spawnLoc = GetSpawnPosition();
bc.Home = Location;
bc.RangeHome = SpawnRange;
bc.FightMode = FightMode.Closest;
bc.MoveToWorld(spawnLoc, map);
DoEffect(spawnLoc, map);
Timer.DelayCall(TimeSpan.FromSeconds(1), delegate
{
bc.Home = Location;
bc.RangeHome = SpawnRange;
bc.FightMode = FightMode.Closest;
bc.ForceReacquire();
});
bc.MoveToWorld(spawnLoc, map);
DoEffect(spawnLoc, map);
bc.ForceReacquire();
});
NextSpawn = DateTime.UtcNow + NextSpawnDelay;
}
NextSpawn = DateTime.UtcNow + NextSpawnDelay;
}
else
{
@ -227,6 +224,7 @@ namespace Server.Items
}
catch
{
// ignored
}
else
from.SendLocalizedMessage(500446); // That is too far away.

View file

@ -143,16 +143,13 @@ namespace Server.Items
{
BasePotion pot = (BasePotion)Activator.CreateInstance(GetType());
if (pot != null)
{
Amount--;
Amount--;
if (from.Backpack != null && !from.Backpack.Deleted)
from.Backpack.DropItem(pot);
else
pot.MoveToWorld(from.Location, from.Map);
pot.Drink(from);
}
if (from.Backpack != null && !from.Backpack.Deleted)
from.Backpack.DropItem(pot);
else
pot.MoveToWorld(from.Location, from.Map);
pot.Drink(from);
}
else
{

View file

@ -142,13 +142,8 @@ namespace Server.Items
return low + (high - low) * percent / 1000001;
}
private static void ApplyAttribute(AosAttributes attrs, int min, int max, AosAttribute attr, int low, int high)
{
ApplyAttribute(attrs, min, max, attr, low, high, 1);
}
private static void ApplyAttribute(AosAttributes attrs, int min, int max, AosAttribute attr, int low, int high,
int scale)
int scale = 1)
{
if (attr == AosAttribute.CastSpeed)
attrs[attr] += Scale(min, max, low / scale, high / scale) * scale;
@ -436,9 +431,7 @@ namespace Server.Items
public static void GetElementalDamages(BaseWeapon weapon, bool randomizeOrder)
{
int fire, phys, cold, nrgy, pois, chaos, direct;
weapon.GetDamageTypes(null, out phys, out fire, out cold, out pois, out nrgy, out chaos, out direct);
weapon.GetDamageTypes(null, out int phys, out int fire, out int cold, out int pois, out int nrgy, out int chaos, out int direct);
int totalDamage = phys;

View file

@ -52,7 +52,7 @@ namespace Server.Items
if (freeze)
{
m.Frozen = freeze;
m.Frozen = true;
Timer.DelayCall(TimeSpan.FromSeconds(message == 1095162 ? 2.0 : 1.25),
new TimerStateCallback(EndFall_Callback), m);
}

View file

@ -301,12 +301,7 @@ namespace Server.Items
}
else if (north || west)
{
Banner banner = null;
if (north)
banner = new Banner(m_ItemID);
else if (west)
banner = new Banner(m_ItemID + 1);
Banner banner = new Banner(m_ItemID + (west ? 0 : 1));
house.Addons.Add(banner);

View file

@ -210,11 +210,7 @@ namespace Server.Items
private DecorativeShieldDeed m_Shield;
public InternalGump(DecorativeShieldDeed shield) : this(shield, 1)
{
}
public InternalGump(DecorativeShieldDeed shield, int page) : base(150, 50)
public InternalGump(DecorativeShieldDeed shield, int page = 1) : base(150, 50)
{
m_Shield = shield;
m_Page = page;
@ -321,12 +317,7 @@ namespace Server.Items
}
else if (north || west)
{
DecorativeShield shield = null;
if (north)
shield = new DecorativeShield(m_ItemID);
else if (west)
shield = new DecorativeShield(GetWestItemID(m_ItemID));
DecorativeShield shield = new DecorativeShield(west ? GetWestItemID(m_ItemID) : m_ItemID);
house.Addons.Add(shield);

View file

@ -309,12 +309,7 @@ namespace Server.Items
}
else if (north || west)
{
HangingSkeleton banner = null;
if (north)
banner = new HangingSkeleton(m_ItemID);
else if (west)
banner = new HangingSkeleton(GetWestItemID(m_ItemID));
HangingSkeleton banner = new HangingSkeleton(west ? GetWestItemID(m_ItemID) : m_ItemID);
house.Addons.Add(banner);

View file

@ -25,7 +25,7 @@ namespace Server.Items
// Swing again:
// If no combatant, wrong map, one of us is a ghost, or cannot see, or deleted, then stop combat
if (defender == null || defender.Deleted || attacker.Deleted || defender.Map != attacker.Map ||
if (defender.Deleted || attacker.Deleted || defender.Map != attacker.Map ||
!defender.Alive || !attacker.Alive || !attacker.CanSee(defender))
{
attacker.Combatant = null;

View file

@ -1225,9 +1225,7 @@ namespace Server.Items
AddBlood(attacker, defender, damage);
int phys, fire, cold, pois, nrgy, chaos, direct;
GetDamageTypes(attacker, out phys, out fire, out cold, out pois, out nrgy, out chaos, out direct);
GetDamageTypes(attacker, out int phys, out int fire, out int cold, out int pois, out int nrgy, out int chaos, out int direct);
if (Core.ML && this is BaseRanged)
if (attacker.FindItemOnLayer(Layer.Cloak) is BaseQuiver quiver)

View file

@ -128,8 +128,7 @@ namespace Server.Misc
return false;
if (item is ICommodity || item is BaseBoat
|| item is Fish || item is BigFish
|| item is BasePotion || item is Food || item is CookableFood
|| item is Fish || item is BigFish || item is Food || item is CookableFood
|| item is SpecialFishingNet || item is BaseMagicFish
|| item is Shoes || item is Sandals
|| item is Boots || item is ThighBoots
@ -137,7 +136,6 @@ namespace Server.Misc
|| item is BaseArmor || item is BaseWeapon
|| item is BaseClothing
|| item is BaseJewel && Core.AOS
|| item is BasePotion && Core.ML
#region Champion artifacts

View file

@ -349,7 +349,7 @@ namespace Server.Misc
if (highest == null || check.BaseFixedPoint > highest.BaseFixedPoint)
highest = check;
else if (highest != null && highest.Lock != SkillLock.Up && check.Lock == SkillLock.Up &&
else if (highest.Lock != SkillLock.Up && check.Lock == SkillLock.Up &&
check.BaseFixedPoint == highest.BaseFixedPoint)
highest = check;
}

View file

@ -37,14 +37,11 @@ namespace Server
{
Type type = typeof(T);
if (type != null)
{
MethodInfo m = type.GetMethod("Validate", BindingFlags.Instance | BindingFlags.Public);
MethodInfo m = type.GetMethod("Validate", BindingFlags.Instance | BindingFlags.Public);
if (m != null)
for (int i = 0; i < m_Queue.Count; ++i)
m.Invoke(m_Queue[i], null);
}
if (m != null)
for (int i = 0; i < m_Queue.Count; ++i)
m.Invoke(m_Queue[i], null);
m_Queue.Clear();
m_Queue = null;

View file

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Server.Commands;
using Server.Mobiles;
@ -140,7 +141,7 @@ namespace Server
bool hasSpawner = false;
for (int j = 0; !hasSpawner && j < si.m_Floor.Count; ++j)
for (int j = 0; j < si.m_Floor.Count; ++j)
{
Point2D fp = (Point2D)si.m_Floor[j];
@ -148,13 +149,7 @@ namespace Server
yTotal += fp.Y;
IPooledEnumerable<Spawner> eable = map.GetItemsInRange<Spawner>(new Point3D(fp.X, fp.Y, 0), 0);
foreach (Spawner item in eable)
{
hasSpawner = true;
break;
}
hasSpawner = eable.Any();
eable.Free();
if (hasSpawner)
@ -237,9 +232,7 @@ namespace Server
if (cp == Point2D.Zero)
continue;
int z;
if (!GetFloorZ(map, cp.X, cp.Y, out z))
if (!GetFloorZ(map, cp.X, cp.Y, out int z))
continue;
new Spawner(1, 1, 1, 0, 4, (string)names[j]).MoveToWorld(new Point3D(cp.X, cp.Y, z), map);

View file

@ -150,12 +150,7 @@ namespace Server.Mobiles
m_Mobile.UseSkill(SkillName.SpiritSpeak);
}
else
{
spell = new GreaterHealSpell(m_Mobile, null);
if (spell == null)
spell = new HealSpell(m_Mobile, null);
}
}
else if (m_Mobile.Hits < m_Mobile.HitsMax - 10)
{
@ -933,7 +928,7 @@ namespace Server.Mobiles
{
double prio = m_Mobile.GetDistanceToSqrt(m);
if (!activeOnly && (inactive == null || prio < inactPrio))
if (inactive == null || prio < inactPrio)
{
inactive = m;
inactPrio = prio;

View file

@ -96,7 +96,7 @@ namespace Server.Mobiles
UnmountMe();
RemoveFollowers();
m_Rider = value;
m_Rider = null;
}
else
{

View file

@ -154,7 +154,7 @@ namespace Server.Mobiles
{
object[] objs = t.GetCustomAttributes(typeof(FriendlyNameAttribute), false);
if (objs != null && objs.Length > 0)
if (objs.Length > 0)
{
FriendlyNameAttribute friendly = objs[0] as FriendlyNameAttribute;

View file

@ -55,7 +55,7 @@ namespace Server.Mobiles
public override void OnDamage(int amount, Mobile from, bool willKill)
{
if (from != null && !willKill && amount > 3 && from != null && !InRange(from, 7))
if (from != null && !willKill && amount > 3 && !InRange(from, 7))
{
MovingEffect(from, 0xF51, 10, 0, false, false);
SpellHelper.Damage(TimeSpan.FromSeconds(1.0), from, this, Utility.RandomMinMax(30, 40) - (Core.AOS ? 0 : 10),

View file

@ -292,11 +292,7 @@ namespace Server.Mobiles
{
private PlagueBeastLord m_Lord;
public DecayTimer(PlagueBeastLord lord) : this(lord, 0, 120)
{
}
public DecayTimer(PlagueBeastLord lord, int count, int deadline) : base(TimeSpan.Zero, TimeSpan.FromSeconds(1))
public DecayTimer(PlagueBeastLord lord, int count = 0, int deadline = 120) : base(TimeSpan.Zero, TimeSpan.FromSeconds(1))
{
m_Lord = lord;
Count = count;

View file

@ -571,7 +571,7 @@ namespace Server.Mobiles
private static bool CheckBlock(MountBlock block)
{
return block is MountBlock && block.m_Timer.Running;
return block?.m_Timer.Running == true;
}
public void SetMountBlock(BlockMountType type, TimeSpan duration, bool dismount)
@ -640,9 +640,7 @@ namespace Server.Mobiles
if (ns == null)
return;
int global, personal;
ComputeLightLevels(out global, out personal);
ComputeLightLevels(out int global, out int personal);
if (!forceResend)
forceResend = global != m_LastGlobalLight || personal != m_LastPersonalLight;

View file

@ -227,8 +227,8 @@ namespace Server.Spells.Necromancy
protected override void OnTarget(Mobile from, object o)
{
if (o is Mobile)
m_Owner.Target((Mobile)o);
if (o is Mobile mobile)
m_Owner.Target(mobile);
}
protected override void OnTargetFinish(Mobile from)

View file

@ -128,12 +128,12 @@ namespace Server.Spells.Necromancy
AddButton(27, 53 + i * 21, 9702, 9703, i + 1, GumpButtonType.Reply, 0);
if (name is int)
AddHtmlLocalized(50, 51 + i * 21, 150, 20, (int)name, enabled ? EnabledColor16 : DisabledColor16, false,
if (name is int intName)
AddHtmlLocalized(50, 51 + i * 21, 150, 20, intName, enabled ? EnabledColor16 : DisabledColor16, false,
false);
else if (name is string)
else if (name is string strName)
AddHtml(50, 51 + i * 21, 150, 20,
$"<BASEFONT COLOR=#{(enabled ? EnabledColor32 : DisabledColor32):X6}>{name}</BASEFONT>", false,
$"<BASEFONT COLOR=#{(enabled ? EnabledColor32 : DisabledColor32):X6}>{strName}</BASEFONT>", false,
false);
}
}

View file

@ -82,8 +82,8 @@ namespace Server.Spells.Necromancy
protected override void OnTarget(Mobile from, object o)
{
if (o is Mobile)
m_Owner.Target((Mobile)o);
if (o is Mobile mobile)
m_Owner.Target(mobile);
}
protected override void OnTargetFinish(Mobile from)

View file

@ -52,10 +52,8 @@ namespace Server.Spells.Necromancy
{
if (isMonster)
{
if (m is BaseCreature)
if (m is BaseCreature bc)
{
BaseCreature bc = (BaseCreature)m;
if (!bc.Controlled && !bc.Summoned && bc.Team == cbc.Team)
continue;
}

View file

@ -33,8 +33,8 @@ namespace Server.Spells.Necromancy
public override void DoEffect(Mobile m)
{
if (m is PlayerMobile)
((PlayerMobile)m).IgnoreMobiles = true;
if (m is PlayerMobile mobile)
mobile.IgnoreMobiles = true;
m.PlaySound(0x17F);
m.FixedParticles(0x374A, 1, 15, 9902, 1108, 4, EffectLayer.Waist);
@ -42,8 +42,8 @@ namespace Server.Spells.Necromancy
public override void RemoveEffect(Mobile m)
{
if (m is PlayerMobile && m.AccessLevel == AccessLevel.Player)
((PlayerMobile)m).IgnoreMobiles = false;
if (m is PlayerMobile mobile && mobile.AccessLevel == AccessLevel.Player)
mobile.IgnoreMobiles = false;
}
}
}

View file

@ -482,9 +482,9 @@ namespace Server.Spells.Ninjitsu
m_Caster.SendLocalizedMessage(1060174,
mana.ToString()); // You must have at least ~1_MANA_REQUIREMENT~ Mana to use this ability.
}
else if (m_Caster is PlayerMobile && (m_Caster as PlayerMobile).MountBlockReason != BlockMountType.None)
else if (m_Caster is PlayerMobile mobile && mobile.MountBlockReason != BlockMountType.None)
{
m_Caster.SendLocalizedMessage(1063108); // You cannot use this ability right now.
mobile.SendLocalizedMessage(1063108); // You cannot use this ability right now.
}
else if (BaseFormTalisman.EntryEnabled(sender.Mobile, entry.Type))
{

View file

@ -85,9 +85,7 @@ namespace Server.Spells.Ninjitsu
public static void AddStep(Mobile m)
{
DeathStrikeInfo info = m_Table[m] as DeathStrikeInfo;
if (info == null)
if (!(m_Table[m] is DeathStrikeInfo info))
return;
if (++info.m_Steps >= 5)
@ -98,12 +96,10 @@ namespace Server.Spells.Ninjitsu
{
Mobile defender = (Mobile)state;
DeathStrikeInfo info = m_Table[defender] as DeathStrikeInfo;
if (info == null) //sanity
if (!(m_Table[defender] is DeathStrikeInfo info)) //sanity
return;
int maxDamage, damage = 0;
int damage;
double ninjitsu = info.m_Attacker.Skills[SkillName.Ninjitsu].Value;
double stalkingBonus = Tracking.GetStalkingBonus(info.m_Attacker, info.m_Target);
@ -130,7 +126,7 @@ namespace Server.Spells.Ninjitsu
int divisor = info.m_Steps >= 5 ? 30 : 80;
double baseDamage = ninjitsu / divisor * 10;
maxDamage = info.m_Steps >= 5 ? 62 : 22; // DamageBonus is 8 at most. That brings the cap up to 70/30.
int maxDamage = info.m_Steps >= 5 ? 62 : 22;
damage = Math.Max(0, Math.Min(maxDamage, (int)(baseDamage + stalkingBonus))) + info.m_DamageBonus;
}

View file

@ -78,8 +78,8 @@ namespace Server.Spells.Third
protected override void OnTarget(Mobile from, object o)
{
if (o is Mobile)
m_Owner.Target((Mobile)o);
if (o is Mobile mobile)
m_Owner.Target(mobile);
}
protected override void OnTargetFinish(Mobile from)

View file

@ -72,8 +72,8 @@ namespace Server.Spells.Third
protected override void OnTarget(Mobile from, object o)
{
if (o is LockableContainer)
m_Owner.Target((LockableContainer)o);
if (o is LockableContainer container)
m_Owner.Target(container);
else
from.SendLocalizedMessage(501762); // Target must be an unlocked chest.
}

View file

@ -75,17 +75,15 @@ namespace Server.Spells.Third
double total = Caster.Skills[SkillName.Magery].Value;
if (Caster is PlayerMobile)
if (Caster is PlayerMobile pm)
{
PlayerMobile pm = (PlayerMobile)Caster;
if (pm.DuelContext != null && pm.DuelContext.Started && !pm.DuelContext.Finished &&
!pm.DuelContext.Ruleset.GetOption("Skills", "Poisoning"))
{
}
else
{
total += Caster.Skills[SkillName.Poisoning].Value;
total += pm.Skills[SkillName.Poisoning].Value;
}
}
else
@ -133,7 +131,7 @@ namespace Server.Spells.Third
protected override void OnTarget(Mobile from, object o)
{
if (o is Mobile) m_Owner.Target((Mobile)o);
if (o is Mobile mobile) m_Owner.Target(mobile);
}
protected override void OnTargetFinish(Mobile from)

View file

@ -55,7 +55,7 @@ namespace Server.Spells.Third
{
item.OnSnoop(Caster);
}
else if (item is Corpse && !((Corpse)item).CheckLoot(Caster, null))
else if (item is Corpse corpse && !corpse.CheckLoot(Caster, null))
{
}
else if (Caster.Region.OnDoubleClick(Caster, item))
@ -82,10 +82,10 @@ namespace Server.Spells.Third
protected override void OnTarget(Mobile from, object o)
{
if (o is ITelekinesisable)
m_Owner.Target((ITelekinesisable)o);
else if (o is Container)
m_Owner.Target((Container)o);
if (o is ITelekinesisable telekinesisable)
m_Owner.Target(telekinesisable);
else if (o is Container container)
m_Owner.Target(container);
else
from.SendLocalizedMessage(501857); // This spell won't work on that!
}

View file

@ -130,9 +130,7 @@ namespace Server.Spells.Third
protected override void OnTarget(Mobile from, object o)
{
IPoint3D p = o as IPoint3D;
if (p != null)
if (o is IPoint3D p)
m_Owner.Target(p);
}

View file

@ -37,9 +37,7 @@ namespace Server.Spells.Third
protected override void OnTarget(Mobile from, object o)
{
IPoint3D loc = o as IPoint3D;
if (loc == null)
if (!(o is IPoint3D loc))
return;
if (m_Owner.CheckSequence())
@ -81,7 +79,7 @@ namespace Server.Spells.Third
int level = (int)(from.Skills[SkillName.Magery].Value * 0.8) - 4;
if (level >= cont.RequiredSkill &&
!(cont is TreasureMapChest && ((TreasureMapChest)cont).Level > 2))
!(cont is TreasureMapChest chest && chest.Level > 2))
{
cont.Locked = false;

View file

@ -156,11 +156,9 @@ namespace Server.Spells.Third
public override bool OnMoveOver(Mobile m)
{
int noto;
if (m is PlayerMobile)
{
noto = Notoriety.Compute(m_Caster, m);
int noto = Notoriety.Compute(m_Caster, m);
if (noto == Notoriety.Enemy || noto == Notoriety.Ally)
return false;
}
@ -203,8 +201,8 @@ namespace Server.Spells.Third
protected override void OnTarget(Mobile from, object o)
{
if (o is IPoint3D)
m_Owner.Target((IPoint3D)o);
if (o is IPoint3D d)
m_Owner.Target(d);
}
protected override void OnTargetFinish(Mobile from)

View file

@ -18,8 +18,8 @@ namespace Server.Targets
protected override void OnTargetOutOfRange(Mobile from, object targeted)
{
if (targeted is UnholyBone && from.InRange((UnholyBone)targeted, 12))
((UnholyBone)targeted).Carve(from, m_Item);
if (targeted is UnholyBone bone && from.InRange(bone, 12))
bone.Carve(from, m_Item);
else
base.OnTargetOutOfRange(from, targeted);
}
@ -29,14 +29,12 @@ namespace Server.Targets
if (m_Item.Deleted)
return;
if (targeted is ICarvable)
if (targeted is ICarvable carvable)
{
((ICarvable)targeted).Carve(from, m_Item);
carvable.Carve(from, m_Item);
}
else if (targeted is SwampDragon && ((SwampDragon)targeted).HasBarding)
else if (targeted is SwampDragon pet && pet.HasBarding)
{
SwampDragon pet = (SwampDragon)targeted;
if (!pet.Controlled || pet.ControlMaster != from)
from.SendLocalizedMessage(1053022); // You cannot remove barding from a swamp dragon you do not own.
else
@ -44,9 +42,9 @@ namespace Server.Targets
}
else
{
if (targeted is StaticTarget)
if (targeted is StaticTarget target)
{
int itemID = ((StaticTarget)targeted).ItemID;
int itemID = target.ItemID;
if (itemID == 0xD15 || itemID == 0xD16) // red mushroom
{
@ -56,10 +54,7 @@ namespace Server.Targets
if (qs is WitchApprenticeQuest)
{
FindIngredientObjective obj =
qs.FindObjective(typeof(FindIngredientObjective)) as FindIngredientObjective;
if (obj != null && !obj.Completed && obj.Ingredient == Ingredient.RedMushrooms)
if (qs.FindObjective(typeof(FindIngredientObjective)) is FindIngredientObjective obj && !obj.Completed && obj.Ingredient == Ingredient.RedMushrooms)
{
player.SendLocalizedMessage(1055036); // You slice a red cap mushroom from its stem.
obj.Complete();
@ -72,11 +67,7 @@ namespace Server.Targets
HarvestSystem system = Lumberjacking.System;
HarvestDefinition def = Lumberjacking.System.Definition;
int tileID;
Map map;
Point3D loc;
if (!system.GetHarvestDetails(from, m_Item, targeted, out tileID, out map, out loc))
if (!system.GetHarvestDetails(from, m_Item, targeted, out int tileID, out Map map, out Point3D loc))
{
from.SendLocalizedMessage(500494); // You can't use a bladed item on that!
}

View file

@ -15,9 +15,7 @@ namespace Server.Targets
protected override void OnTarget(Mobile from, object o)
{
IPoint3D p = o as IPoint3D;
if (p != null)
if (o is IPoint3D p)
{
if (!BaseCommand.IsAccessible(from, m_Object))
{
@ -31,17 +29,13 @@ namespace Server.Targets
CommandLogging.WriteLine(from, "{0} {1} moving {2} to {3}", from.AccessLevel, CommandLogging.Format(from),
CommandLogging.Format(m_Object), new Point3D(p));
if (m_Object is Item)
if (m_Object is Item item)
{
Item item = (Item)m_Object;
if (!item.Deleted)
item.MoveToWorld(new Point3D(p), from.Map);
}
else if (m_Object is Mobile)
else if (m_Object is Mobile m)
{
Mobile m = (Mobile)m_Object;
if (!m.Deleted)
m.MoveToWorld(new Point3D(p), from.Map);
}