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

@ -48,11 +48,7 @@ namespace Server.Engines.ConPVP
private bool m_Yielding;
public DuelContext(Mobile initiator, RulesetLayout layout) : this(initiator, layout, true)
{
}
public DuelContext(Mobile initiator, RulesetLayout layout, bool addNew)
public DuelContext(Mobile initiator, RulesetLayout layout, bool addNew = true)
{
Initiator = initiator;
Participants = new List<Participant>();
@ -123,13 +119,8 @@ namespace Server.Engines.ConPVP
public static bool AllowSpecialMove(Mobile from, string name, SpecialMove move)
{
if (!(from is PlayerMobile pm))
return true;
DuelContext dc = pm.DuelContext;
// No DuelContext, or InstaAllowSpecialMove
return dc?.InstAllowSpecialMove(from, name, move) != false;
return (from as PlayerMobile)?.DuelContext?.InstAllowSpecialMove(from, name, move) != false;
}
public bool InstAllowSpecialMove(Mobile from, string name, SpecialMove move)
@ -139,7 +130,7 @@ namespace Server.Engines.ConPVP
DuelPlayer pl = Find(from);
if (pl == null || pl.Eliminated)
if (pl?.Eliminated != false)
return true;
if (CantDoAnything(from))
@ -165,9 +156,7 @@ namespace Server.Engines.ConPVP
if (!StartedBeginCountdown)
return true;
DuelPlayer pl = Find(from);
if (pl?.Eliminated != false)
if (Find(from)?.Eliminated != false)
return true;
if (CantDoAnything(from))
@ -256,7 +245,7 @@ namespace Server.Engines.ConPVP
DuelPlayer pl = Find(from);
if (pl == null || pl.Eliminated)
if (pl?.Eliminated != false)
return true;
if (item is Dagger || CheckItemEquip(from, item))
@ -350,7 +339,7 @@ namespace Server.Engines.ConPVP
DuelPlayer pl = Find(from);
if (pl == null || pl.Eliminated)
if (pl?.Eliminated != false)
return true;
if (CantDoAnything(from))
@ -373,7 +362,7 @@ namespace Server.Engines.ConPVP
DuelPlayer pl = Find(from);
if (pl == null || pl.Eliminated)
if (pl?.Eliminated != false)
return true;
if (!(item is BaseRefreshPotion))
@ -507,7 +496,7 @@ namespace Server.Engines.ConPVP
DuelPlayer pl = Find(mob);
if (pl == null || pl.Eliminated)
if (pl?.Eliminated != false)
return;
if (mob.Map == Map.Internal)
@ -533,30 +522,27 @@ namespace Server.Engines.ConPVP
DuelPlayer pl = Find(mob);
if (pl != null && !pl.Eliminated)
if (pl?.Eliminated == true || m_EventGame != null && !m_EventGame.OnDeath(mob, corpse))
return;
pl.Eliminated = true;
if (mob.Poison != null)
mob.Poison = null;
Requip(mob, corpse);
DelayBounce(TimeSpan.FromSeconds(4.0), mob, corpse);
Participant winner = CheckCompletion();
if (winner != null)
{
if (m_EventGame != null && !m_EventGame.OnDeath(mob, corpse))
return;
pl.Eliminated = true;
if (mob.Poison != null)
mob.Poison = null;
Requip(mob, corpse);
DelayBounce(TimeSpan.FromSeconds(4.0), mob, corpse);
Participant winner = CheckCompletion();
if (winner != null)
{
Finish(winner);
}
else if (!m_Yielding)
{
mob.LocalOverheadMessage(MessageType.Regular, 0x22, false, "You have been defeated.");
mob.NonlocalOverheadMessage(MessageType.Regular, 0x22, false, $"{mob.Name} has been defeated.");
}
Finish(winner);
}
else if (!m_Yielding)
{
mob.LocalOverheadMessage(MessageType.Regular, 0x22, false, "You have been defeated.");
mob.NonlocalOverheadMessage(MessageType.Regular, 0x22, false, $"{mob.Name} has been defeated.");
}
}
@ -564,7 +550,7 @@ namespace Server.Engines.ConPVP
{
for (int i = 0; i < Participants.Count; ++i)
{
Participant p = (Participant)Participants[i];
Participant p = Participants[i];
if (p.HasOpenSlot)
return false;
@ -609,7 +595,7 @@ namespace Server.Engines.ConPVP
Mobile killer = from.FindMostRecentDamager(false);
if (killer != null && killer.Player)
if (killer?.Player == true)
killer.AddToBackpack(new Head(m_Tournament == null ? HeadType.Duel : HeadType.Tournament, from.Name));
}
@ -671,7 +657,7 @@ namespace Server.Engines.ConPVP
{
DuelPlayer pl = winner.Players[i];
if (pl != null && !pl.Eliminated)
if (pl?.Eliminated == false)
DelayBounce(TimeSpan.FromSeconds(8.0), pl.Mobile, null);
}
@ -688,7 +674,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < Participants.Count; ++i)
{
Participant loser = (Participant)Participants[i];
Participant loser = Participants[i];
if (loser != winner)
{
@ -714,8 +700,8 @@ namespace Server.Engines.ConPVP
if (IsOneVsOne)
{
DuelPlayer dp1 = ((Participant)Participants[0]).Players[0];
DuelPlayer dp2 = ((Participant)Participants[1]).Players[0];
DuelPlayer dp1 = Participants[0].Players[0];
DuelPlayer dp2 = Participants[1].Players[0];
if (dp1 != null && dp2 != null)
{
@ -797,7 +783,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < Participants.Count; ++i)
{
Participant p = (Participant)Participants[i];
Participant p = Participants[i];
for (int j = 0; j < p.Players.Length; ++j)
{
@ -828,7 +814,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < Participants.Count; ++i)
{
Participant oldPart = (Participant)Participants[i];
Participant oldPart = Participants[i];
Participant newPart = new Participant(dc, oldPart.Players.Length);
for (int j = 0; j < oldPart.Players.Length; ++j)
@ -858,7 +844,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < Participants.Count; ++i)
{
Participant p = (Participant)Participants[i];
Participant p = Participants[i];
DuelPlayer pl = p.Find(mob);
if (pl != null)
@ -873,7 +859,7 @@ namespace Server.Engines.ConPVP
DuelPlayer pl1 = Find(m1);
DuelPlayer pl2 = Find(m2);
return pl1 != null && pl2 != null && pl1.Participant == pl2.Participant;
return pl1 != null && pl1.Participant == pl2?.Participant;
}
public Participant CheckCompletion()
@ -885,7 +871,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < Participants.Count; ++i)
{
Participant p = (Participant)Participants[i];
Participant p = Participants[i];
if (p.Eliminated)
{
@ -900,10 +886,7 @@ namespace Server.Engines.ConPVP
}
}
if (hasWinner)
return winner ?? (Participant)Participants[0];
return null;
return hasWinner ? winner ?? Participants[0] : null;
}
public void StartCountdown(int count, CountdownCallback cb)
@ -953,13 +936,13 @@ namespace Server.Engines.ConPVP
{
for (int i = 0; i < Participants.Count; ++i)
{
Participant p = (Participant)Participants[i];
Participant p = Participants[i];
for (int j = 0; j < p.Players.Length; ++j)
{
DuelPlayer pl = p.Players[j];
if (pl == null || pl.Eliminated)
if (pl?.Eliminated != false)
continue;
pl.Mobile.SendSound(0x1E1);
@ -984,13 +967,13 @@ namespace Server.Engines.ConPVP
{
for (int i = 0; i < Participants.Count; ++i)
{
Participant p = (Participant)Participants[i];
Participant p = Participants[i];
for (int j = 0; j < p.Players.Length; ++j)
{
DuelPlayer pl = p.Players[j];
if (pl == null || pl.Eliminated)
if (pl?.Eliminated != false)
continue;
pl.Mobile.SendSound(0x1E1);
@ -1065,7 +1048,7 @@ namespace Server.Engines.ConPVP
{
DuelPlayer pl = p.Players[j];
if (pl != null && !pl.Eliminated)
if (pl?.Eliminated == false)
DelayBounce(TimeSpan.FromSeconds(8.0), pl.Mobile, null);
}
@ -1511,7 +1494,7 @@ namespace Server.Engines.ConPVP
}
}
}
public void CloseAllGumps(DuelPlayer pl)
{
pl.Mobile.CloseGump<BeginGump>();
@ -1527,7 +1510,7 @@ namespace Server.Engines.ConPVP
{
for (int i = 0; i < Participants.Count; ++i)
{
Participant p = (Participant)Participants[i];
Participant p = Participants[i];
for (int j = 0; j < p.Players.Length; ++j)
{
@ -1546,7 +1529,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < Participants.Count; ++i)
{
Participant p = (Participant)Participants[i];
Participant p = Participants[i];
for (int j = 0; j < p.Players.Length; ++j)
{
@ -1571,7 +1554,7 @@ namespace Server.Engines.ConPVP
else
mob.SendMessage(0x22, "{0} has rejected the {1}.", rejector.Name, Rematch ? "rematch" : page);
}
// Close all of them?
mob.CloseGump<DuelContextGump>();
mob.CloseGump<ReadyUpGump>();
@ -1851,9 +1834,9 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < ruleset.Flavors.Count; ++i)
{
defs.Or(((Ruleset)ruleset.Flavors[i]).Options);
defs.Or(ruleset.Flavors[i].Options);
mob.SendMessage(" + {0}", ((Ruleset)ruleset.Flavors[i]).Title);
mob.SendMessage(" + {0}", ruleset.Flavors[i].Title);
}
}
else
@ -2084,10 +2067,7 @@ namespace Server.Engines.ConPVP
}
}
Arena arena = m_OverrideArena;
if (arena == null)
arena = Arena.FindArena(players);
Arena arena = m_OverrideArena ?? Arena.FindArena(players);
if (arena == null)
{
@ -2482,7 +2462,7 @@ namespace Server.Engines.ConPVP
}
else
{
if (m_Teleporter != null && !m_Teleporter.Deleted)
if (m_Teleporter?.Deleted == false)
m_Teleporter.Register(m);
base.UseGate(m);
@ -2512,4 +2492,4 @@ namespace Server.Engines.ConPVP
}
}
}
}
}