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

@ -58,7 +58,7 @@ namespace Server.Engines.MLQuests.Objectives
public static void WriteTimeRemaining(Gump g, ref int y, TimeSpan timeRemaining)
{
g.AddHtmlLocalized(103, y, 120, 16, 1062379, 0x15F90, false, false); // Est. time remaining:
g.AddHtmlLocalized(103, y, 120, 16, 1062379, 0x15F90); // Est. time remaining:
g.AddLabel(223, y, 0x481, timeRemaining.TotalSeconds.ToString("F0"));
y += 16;
}

View file

@ -1,4 +1,5 @@
using System;
using System.Linq;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
@ -7,12 +8,7 @@ namespace Server.Engines.MLQuests.Objectives
{
public class CollectObjective : BaseObjective
{
public CollectObjective()
: this(0, null, null)
{
}
public CollectObjective(int amount, Type type, TextDefinition name)
public CollectObjective(int amount = 0, Type type = null, TextDefinition name = null)
{
DesiredAmount = amount;
AcceptedType = type;
@ -37,7 +33,7 @@ namespace Server.Engines.MLQuests.Objectives
public bool CheckType(Type type)
{
return AcceptedType != null && AcceptedType.IsAssignableFrom(type);
return AcceptedType?.IsAssignableFrom(type) == true;
}
public virtual bool CheckItem(Item item)
@ -58,12 +54,12 @@ namespace Server.Engines.MLQuests.Objectives
{
string amount = DesiredAmount.ToString();
g.AddHtmlLocalized(98, y, 350, 16, 1072205, 0x15F90, false, false); // Obtain
g.AddHtmlLocalized(98, y, 350, 16, 1072205, 0x15F90); // Obtain
g.AddLabel(143, y, 0x481, amount);
if (Name.Number > 0)
{
g.AddHtmlLocalized(143 + amount.Length * 15, y, 190, 18, Name.Number, 0x77BF, false, false);
g.AddHtmlLocalized(143 + amount.Length * 15, y, 190, 18, Name.Number, 0x77BF);
g.AddItem(350, y, LabelToItemID(Name.Number));
}
else if (Name.String != null)
@ -74,7 +70,7 @@ namespace Server.Engines.MLQuests.Objectives
else
{
if (Name.Number > 0)
g.AddHtmlLocalized(98, y, 312, 32, Name.Number, 0x15F90, false, false);
g.AddHtmlLocalized(98, y, 312, 32, Name.Number, 0x15F90);
else if (Name.String != null)
g.AddLabel(98, y, 0x481, Name.String);
}
@ -122,13 +118,7 @@ namespace Server.Engines.MLQuests.Objectives
return 0;
Item[] items = pack.FindItemsByType(Objective.AcceptedType, false); // Note: subclasses are included
int total = 0;
foreach (Item item in items)
if (item.QuestItem && Objective.CheckItem(item))
total += item.Amount;
return total;
return items.Where(item => item.QuestItem && Objective.CheckItem(item)).Sum(item => item.Amount);
}
public override bool AllowsQuestItem(Item item, Type type)
@ -211,14 +201,14 @@ namespace Server.Engines.MLQuests.Objectives
{
base.WriteToGump(g, ref y);
g.AddHtmlLocalized(103, y, 120, 16, 3000087, 0x15F90, false, false); // Total
g.AddHtmlLocalized(103, y, 120, 16, 3000087, 0x15F90); // Total
g.AddLabel(223, y, 0x481, GetCurrentTotal().ToString());
y += 16;
g.AddHtmlLocalized(103, y, 120, 16, 1074782, 0x15F90, false, false); // Return to
g.AddHtmlLocalized(103, y, 120, 16, 1074782, 0x15F90); // Return to
g.AddLabel(223, y, 0x481, QuesterNameAttribute.GetQuesterNameFor(Instance.QuesterType));
y += 16;
}
}
}
}
}

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
@ -8,12 +9,7 @@ namespace Server.Engines.MLQuests.Objectives
{
public class DeliverObjective : BaseObjective
{
public DeliverObjective(Type delivery, int amount, TextDefinition name, Type destination)
: this(delivery, amount, name, destination, true)
{
}
public DeliverObjective(Type delivery, int amount, TextDefinition name, Type destination, bool spawnsDelivery)
public DeliverObjective(Type delivery, int amount, TextDefinition name, Type destination, bool spawnsDelivery = true)
{
Delivery = delivery;
Amount = amount;
@ -69,12 +65,12 @@ namespace Server.Engines.MLQuests.Objectives
{
string amount = Amount.ToString();
g.AddHtmlLocalized(98, y, 312, 16, 1072207, 0x15F90, false, false); // Deliver
g.AddHtmlLocalized(98, y, 312, 16, 1072207, 0x15F90); // Deliver
g.AddLabel(143, y, 0x481, amount);
if (Name.Number > 0)
{
g.AddHtmlLocalized(143 + amount.Length * 15, y, 190, 18, Name.Number, 0x77BF, false, false);
g.AddHtmlLocalized(143 + amount.Length * 15, y, 190, 18, Name.Number, 0x77BF);
g.AddItem(350, y, CollectObjective.LabelToItemID(Name.Number));
}
else if (Name.String != null)
@ -84,7 +80,7 @@ namespace Server.Engines.MLQuests.Objectives
y += 32;
g.AddHtmlLocalized(103, y, 120, 16, 1072379, 0x15F90, false, false); // Deliver to
g.AddHtmlLocalized(103, y, 120, 16, 1072379, 0x15F90); // Deliver to
g.AddLabel(223, y, 0x481, QuesterNameAttribute.GetQuesterNameFor(Destination));
y += 16;
@ -100,13 +96,8 @@ namespace Server.Engines.MLQuests.Objectives
public class TimedDeliverObjective : DeliverObjective
{
public TimedDeliverObjective(TimeSpan duration, Type delivery, int amount, TextDefinition name, Type destination)
: this(duration, delivery, amount, name, destination, true)
{
}
public TimedDeliverObjective(TimeSpan duration, Type delivery, int amount, TextDefinition name, Type destination,
bool spawnsDelivery)
bool spawnsDelivery = true)
: base(delivery, amount, name, destination, spawnsDelivery)
{
Duration = duration;
@ -158,12 +149,7 @@ namespace Server.Engines.MLQuests.Objectives
return 0;
Item[] items = pack.FindItemsByType(Objective.Delivery, false); // Note: subclasses are included
int total = 0;
foreach (Item item in items)
total += item.Amount;
return total;
return items.Sum(item => item.Amount);
}
public override bool OnBeforeClaimReward()
@ -240,4 +226,4 @@ namespace Server.Engines.MLQuests.Objectives
writer.Write(HasCompleted);
}
}
}
}

View file

@ -7,12 +7,7 @@ namespace Server.Engines.MLQuests.Objectives
{
public class EscortObjective : BaseObjective
{
public EscortObjective()
: this(null)
{
}
public EscortObjective(QuestArea destination)
public EscortObjective(QuestArea destination = null)
{
Destination = destination;
}
@ -60,10 +55,10 @@ namespace Server.Engines.MLQuests.Objectives
public override void WriteToGump(Gump g, ref int y)
{
g.AddHtmlLocalized(98, y, 312, 16, 1072206, 0x15F90, false, false); // Escort to
g.AddHtmlLocalized(98, y, 312, 16, 1072206, 0x15F90); // Escort to
if (Destination.Name.Number > 0)
g.AddHtmlLocalized(173, y, 312, 20, Destination.Name.Number, 0xFFFFFF, false, false);
g.AddHtmlLocalized(173, y, 312, 20, Destination.Name.Number, 0xFFFFFF);
else if (Destination.Name.String != null)
g.AddLabel(173, y, 0x481, Destination.Name.String);
@ -212,7 +207,7 @@ namespace Server.Engines.MLQuests.Objectives
MLQuestInstance instance = Instance;
PlayerMobile pm = instance.Player;
if (m_Escort != null && !m_Escort.Deleted)
if (m_Escort?.Deleted == false)
{
if (!pm.Alive)
m_Escort.Say(500901); // Ack! My escort has come to haunt me!
@ -268,4 +263,4 @@ namespace Server.Engines.MLQuests.Objectives
writer.Write(HasCompleted);
}
}
}
}

View file

@ -67,7 +67,7 @@ namespace Server.Engines.MLQuests.Objectives
args = ThresholdFixed % 10 == 0 ? $"#{skillLabel}\t{ThresholdFixed / 10}" : $"#{skillLabel}\t{(double)ThresholdFixed / 10:0.0}";
g.AddHtmlLocalized(98, y, 312, 16, 1077485, args, 0x15F90, false, false); // Increase ~1_SKILL~ to ~2_VALUE~
g.AddHtmlLocalized(98, y, 312, 16, 1077485, args, 0x15F90); // Increase ~1_SKILL~ to ~2_VALUE~
y += 16;
}
@ -154,7 +154,7 @@ namespace Server.Engines.MLQuests.Objectives
if (IsCompleted())
{
g.AddHtmlLocalized(113, y, 312, 20, 1055121, 0xFFFFFF, false, false); // Complete
g.AddHtmlLocalized(113, y, 312, 20, 1055121, 0xFFFFFF); // Complete
y += 16;
}
}

View file

@ -6,17 +6,9 @@ namespace Server.Engines.MLQuests.Objectives
{
public class KillObjective : BaseObjective
{
public KillObjective()
: this(0, null, null, null)
{
}
public KillObjective(int amount, Type[] types, TextDefinition name)
: this(amount, types, name, null)
{
}
public KillObjective(int amount, Type[] types, TextDefinition name, QuestArea area)
public KillObjective(
int amount = 0, Type[] types = null, TextDefinition name = null, QuestArea area = null)
{
DesiredAmount = amount;
AcceptedTypes = types;
@ -36,11 +28,11 @@ namespace Server.Engines.MLQuests.Objectives
{
string amount = DesiredAmount.ToString();
g.AddHtmlLocalized(98, y, 312, 16, 1072204, 0x15F90, false, false); // Slay
g.AddHtmlLocalized(98, y, 312, 16, 1072204, 0x15F90); // Slay
g.AddLabel(133, y, 0x481, amount);
if (Name.Number > 0)
g.AddHtmlLocalized(133 + amount.Length * 15, y, 190, 18, Name.Number, 0x77BF, false, false);
g.AddHtmlLocalized(133 + amount.Length * 15, y, 190, 18, Name.Number, 0x77BF);
else if (Name.String != null)
g.AddLabel(133 + amount.Length * 15, y, 0x481, Name.String);
@ -50,10 +42,10 @@ namespace Server.Engines.MLQuests.Objectives
if (Area != null)
{
g.AddHtmlLocalized(103, y, 312, 20, 1018327, 0x15F90, false, false); // Location
g.AddHtmlLocalized(103, y, 312, 20, 1018327, 0x15F90); // Location
if (Area.Name.Number > 0)
g.AddHtmlLocalized(223, y, 312, 20, Area.Name.Number, 0xFFFFFF, false, false);
g.AddHtmlLocalized(223, y, 312, 20, Area.Name.Number, 0xFFFFFF);
else if (Area.Name.String != null)
g.AddLabel(223, y, 0x481, Area.Name.String);
@ -73,12 +65,7 @@ namespace Server.Engines.MLQuests.Objectives
public class TimedKillObjective : KillObjective
{
public TimedKillObjective(TimeSpan duration, int amount, Type[] types, TextDefinition name)
: this(duration, amount, types, name, null)
{
}
public TimedKillObjective(TimeSpan duration, int amount, Type[] types, TextDefinition name, QuestArea area)
public TimedKillObjective(TimeSpan duration, int amount, Type[] types, TextDefinition name, QuestArea area = null)
: base(amount, types, name, area)
{
Duration = duration;
@ -112,7 +99,7 @@ namespace Server.Engines.MLQuests.Objectives
foreach (Type acceptedType in Objective.AcceptedTypes)
if (acceptedType.IsAssignableFrom(type))
{
if (Objective.Area != null && !Objective.Area.Contains(mob))
if (Objective.Area?.Contains(mob) == false)
return false;
PlayerMobile pm = Instance.Player;
@ -140,11 +127,11 @@ namespace Server.Engines.MLQuests.Objectives
base.WriteToGump(g, ref y);
g.AddHtmlLocalized(103, y, 120, 16, 3000087, 0x15F90, false, false); // Total
g.AddHtmlLocalized(103, y, 120, 16, 3000087, 0x15F90); // Total
g.AddLabel(223, y, 0x481, Slain.ToString());
y += 16;
g.AddHtmlLocalized(103, y, 120, 16, 1074782, 0x15F90, false, false); // Return to
g.AddHtmlLocalized(103, y, 120, 16, 1074782, 0x15F90); // Return to
g.AddLabel(223, y, 0x481, QuesterNameAttribute.GetQuesterNameFor(Instance.QuesterType));
y += 16;
}
@ -156,4 +143,4 @@ namespace Server.Engines.MLQuests.Objectives
writer.Write(Slain);
}
}
}
}