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

@ -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)