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

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