Some cleanup of contains keys and try get values (#246)

This commit is contained in:
Kamron Batman 2020-09-13 20:20:44 -07:00 • committed by GitHub
parent 9cbb0cfd23
commit a236617ad9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
69 changed files with 3508 additions and 350 deletions

View file

@ -179,7 +179,7 @@ namespace Server
if (m_Table == null)
LoadTable();
return m_Table.ContainsKey(obj.GetType());
return m_Table!.ContainsKey(obj.GetType());
}
public static bool GetSpeeds(object obj, ref double activeSpeed, ref double passiveSpeed)
@ -190,7 +190,7 @@ namespace Server
if (m_Table == null)
LoadTable();
if (!m_Table.TryGetValue(obj.GetType(), out var sp))
if (!m_Table!.TryGetValue(obj.GetType(), out var sp))
return false;
activeSpeed = sp.ActiveSpeed;

View file

@ -146,7 +146,7 @@ namespace Server.Mobiles
public static void StopEffect(Mobile m, bool message)
{
if (m_Table.TryGetValue(m, out var timer))
if (m_Table.Remove(m, out var timer))
{
if (message)
m.PublicOverheadMessage(
@ -157,7 +157,6 @@ namespace Server.Mobiles
);
timer.Stop();
m_Table.Remove(m);
}
}

View file

@ -120,10 +120,9 @@ namespace Server.Mobiles
public static void EndLifeDrain(Mobile m)
{
if (m_Table.TryGetValue(m, out var timer))
if (m_Table.Remove(m, out var timer))
{
timer?.Stop();
m_Table.Remove(m);
m.SendLocalizedMessage(1070849); // The drain on your life force is gone.
}
}

View file

@ -1050,7 +1050,7 @@ namespace Server.Mobiles
if (from.UseSkill(skillId))
{
@from.Target?.Invoke(@from, target);
from.Target?.Invoke(from, target);
}
if (skillId == 35)
@ -1294,7 +1294,7 @@ namespace Server.Mobiles
if (from.NetState != null)
{
Timer.DelayCall(TimeSpan.FromSeconds(1.0), @from.NetState.Dispose);
Timer.DelayCall(TimeSpan.FromSeconds(1.0), from.NetState.Dispose);
}
}
else if (from.AccessLevel >= AccessLevel.Administrator)
@ -1470,11 +1470,11 @@ namespace Server.Mobiles
if (armor is BaseShield)
{
@from.SendLocalizedMessage(1062003, name); // You can no longer equip your ~1_SHIELD~
from.SendLocalizedMessage(1062003, name); // You can no longer equip your ~1_SHIELD~
}
else
{
@from.SendLocalizedMessage(1062002, name); // You can no longer wear your ~1_ARMOR~
from.SendLocalizedMessage(1062002, name); // You can no longer wear your ~1_ARMOR~
}
from.AddToBackpack(armor);
@ -1547,7 +1547,7 @@ namespace Server.Mobiles
if (moved)
{
@from.SendLocalizedMessage(500647); // Some equipment has been moved to your backpack.
from.SendLocalizedMessage(500647); // Some equipment has been moved to your backpack.
}
}
catch (Exception e)
@ -2011,7 +2011,7 @@ namespace Server.Mobiles
{
if (Core.TOL && from.InRange(this, 2))
{
list.Add(new CallbackEntry(1077728, () => OpenTrade(@from))); // Trade
list.Add(new CallbackEntry(1077728, () => OpenTrade(from))); // Trade
}
if (Alive && Core.Expansion >= Expansion.AOS)
@ -2027,11 +2027,11 @@ namespace Server.Mobiles
{
if (ourParty == null)
{
list.Add(new AddToPartyEntry(@from, this));
list.Add(new AddToPartyEntry(from, this));
}
else if (ourParty == theirParty)
{
list.Add(new RemoveFromPartyEntry(@from, this));
list.Add(new RemoveFromPartyEntry(from, this));
}
}
}
@ -2041,7 +2041,7 @@ namespace Server.Mobiles
if (curhouse != null && Alive && Core.Expansion >= Expansion.AOS && curhouse.IsAosRules &&
curhouse.IsFriend(from))
{
list.Add(new EjectPlayerEntry(@from, this));
list.Add(new EjectPlayerEntry(from, this));
}
}
}
@ -2902,11 +2902,11 @@ namespace Server.Mobiles
if (Core.ML)
{
@from.Damage((int)(amount * (1 - (@from.Skills.MagicResist.Value * .5 + 10) / 100)), this);
from.Damage((int)(amount * (1 - (from.Skills.MagicResist.Value * .5 + 10) / 100)), this);
}
else
{
@from.Damage(amount, this);
from.Damage(amount, this);
}
}
@ -2916,7 +2916,7 @@ namespace Server.Mobiles
{
var type = talisman.Protection.Type;
if (type.IsInstanceOfType(@from))
if (type.IsInstanceOfType(from))
{
amount = (int)(amount * (1 - (double)talisman.Protection.Amount / 100));
}
@ -4188,7 +4188,7 @@ namespace Server.Mobiles
if (from != null && result == ApplyPoisonResult.Poisoned && PoisonTimer is PoisonImpl.PoisonTimer timer)
{
timer.From = @from;
timer.From = from;
}
return result;
@ -4207,7 +4207,7 @@ namespace Server.Mobiles
}
else
{
base.OnPoisonImmunity(@from, poison);
base.OnPoisonImmunity(from, poison);
}
}
@ -4685,20 +4685,16 @@ namespace Server.Mobiles
public void RemoveBuff(BuffIcon b)
{
if (m_BuffTable?.ContainsKey(b) != true)
if (!m_BuffTable.Remove(b, out var info))
{
return;
}
var info = m_BuffTable[b];
if (info.Timer?.Running == true)
{
info.Timer.Stop();
}
m_BuffTable.Remove(b);
if (NetState?.BuffIcon == true)
{
NetState.Send(new RemoveBuffPacket(this, b));

View file

@ -149,11 +149,13 @@ namespace Server.Mobiles
var okay = true;
foreach (var obj in quest.Objectives)
{
if (obj is EscortObjective objective && objective.Destination.Contains(reg))
{
okay = false; // We're already there!
break;
}
}
if (okay)
{
@ -175,7 +177,9 @@ namespace Server.Mobiles
if (m_MLQuest == null)
{
if (MLQuestSystem.Debug)
{
Console.WriteLine("Warning: No suitable quest found for escort {0}", Serial);
}
return null;
}
@ -232,7 +236,9 @@ namespace Server.Mobiles
var dest = GetDestination();
if (dest == null || !m.Alive)
{
return false;
}
var escorter = GetEscorter();
@ -262,10 +268,14 @@ namespace Server.Mobiles
var dest = GetDestination();
if (dest == null)
{
return false;
}
if (GetEscorter() != null || !m.Alive)
{
return false;
}
if (EscortTable.TryGetValue(m, out var escortable) && escortable?.Deleted == false &&
escortable.GetEscorter() == m)
@ -288,7 +298,9 @@ namespace Server.Mobiles
m_LastSeenEscorter = DateTime.UtcNow;
if (m is PlayerMobile playerMobile)
{
playerMobile.LastEscortTime = DateTime.UtcNow;
}
Say(
"Lead on! Payment will be made when we arrive in {0}.",
@ -310,12 +322,18 @@ namespace Server.Mobiles
base.OnSpeech(e);
if (GetDestination() == null || e.Handled || !e.Mobile.InRange(Location, 3))
{
return;
}
if (e.HasKeyword(0x1D)) // *destination*
{
e.Handled = SayDestinationTo(e.Mobile);
}
else if (e.HasKeyword(0x1E)) // *i will take thee*
{
e.Handled = AcceptEscorter(e.Mobile);
}
}
public override void OnAfterDelete()
@ -336,7 +354,9 @@ namespace Server.Mobiles
protected override bool OnMove(Direction d)
{
if (!base.OnMove(d))
{
return false;
}
CheckAtDestination();
@ -353,7 +373,9 @@ namespace Server.Mobiles
public virtual void StartFollow(Mobile escorter)
{
if (escorter == null)
{
return;
}
ActiveSpeed = 0.1;
PassiveSpeed = 0.2;
@ -361,7 +383,11 @@ namespace Server.Mobiles
ControlOrder = OrderType.Follow;
ControlTarget = escorter;
if (IsPrisoner && CantWalk) CantWalk = false;
if (IsPrisoner && CantWalk)
{
CantWalk = false;
}
CurrentSpeed = 0.1;
}
@ -379,12 +405,16 @@ namespace Server.Mobiles
public virtual Mobile GetEscorter()
{
if (!Controlled)
{
return null;
}
var master = ControlMaster;
if (MLQuestSystem.Enabled || master == null)
{
return master;
}
if (master.Deleted || master.Map != Map || !master.InRange(Location, 30) || !master.Alive)
{
@ -409,7 +439,9 @@ namespace Server.Mobiles
}
if (ControlOrder != OrderType.Follow)
{
StartFollow(master);
}
m_LastSeenEscorter = DateTime.UtcNow;
return master;
@ -428,17 +460,23 @@ namespace Server.Mobiles
public virtual bool CheckAtDestination()
{
if (MLQuestSystem.Enabled)
{
return false;
}
var dest = GetDestination();
if (dest == null)
{
return false;
}
var escorter = GetEscorter();
if (escorter == null)
{
return false;
}
if (dest.Contains(Location))
{
@ -456,7 +494,9 @@ namespace Server.Mobiles
var gold = new Gold(500, 1000);
if (!cont.TryDropItem(escorter, gold, false))
{
gold.MoveToWorld(escorter.Location, escorter.Map);
}
StopFollow();
SetControlMaster(null);
@ -484,18 +524,24 @@ namespace Server.Mobiles
else if (VirtueHelper.Award(pm, VirtueName.Compassion, IsPrisoner ? 400 : 200, ref gainedPath))
{
if (gainedPath)
{
pm.SendLocalizedMessage(1053005); // You have achieved a path in compassion!
}
else
{
pm.SendLocalizedMessage(1053002); // You have gained in compassion.
}
pm.NextCompassionDay =
DateTime.UtcNow + TimeSpan.FromDays(1.0); // in one day CompassionGains gets reset to 0
++pm.CompassionGains;
if (pm.CompassionGains >= 5)
{
pm.SendLocalizedMessage(
1053004
); // You must wait about a day before you can gain in compassion again.
}
}
else
{
@ -529,12 +575,16 @@ namespace Server.Mobiles
writer.Write(dest != null);
if (dest != null)
{
writer.Write(dest.Name);
}
writer.Write(m_DeleteTimer != null);
if (m_DeleteTimer != null)
{
writer.WriteDeltaTime(m_DeleteTime);
}
MLQuestSystem.WriteQuestRef(writer, StaticMLQuester ? null : m_MLQuest);
}
@ -546,8 +596,10 @@ namespace Server.Mobiles
var version = reader.ReadInt();
if (reader.ReadBool())
{
m_DestinationString =
reader.ReadString(); // NOTE: We cannot EDI.Find here, regions have not yet been loaded :-(
}
if (reader.ReadBool())
{
@ -561,7 +613,9 @@ namespace Server.Mobiles
var quest = MLQuestSystem.ReadQuestRef(reader);
if (MLQuestSystem.Enabled && quest != null && !StaticMLQuester)
{
m_MLQuest = quest;
}
}
}
@ -576,14 +630,20 @@ namespace Server.Mobiles
if (!MLQuestSystem.Enabled && GetDestination() != null)
{
if (escorter == null || escorter == from)
{
list.Add(new AskDestinationEntry(this, from));
}
if (escorter == null)
{
list.Add(new AcceptEscortEntry(this, from));
}
}
if (escorter == from)
{
list.Add(new AbandonEscortEntry(this));
}
}
base.AddCustomContextEntries(from, list);
@ -594,7 +654,9 @@ namespace Server.Mobiles
public virtual string PickRandomDestination()
{
if (Map.Felucca.Regions.Count == 0 || Map == null || Map == Map.Internal || Location == Point3D.Zero)
{
return null; // Not yet fully initialized
}
var possible = GetPossibleDestinations();
string picked = null;
@ -605,7 +667,9 @@ namespace Server.Mobiles
var test = EDI.Find(picked);
if (test.Contains(Location))
{
picked = null;
}
}
return picked;
@ -614,16 +678,24 @@ namespace Server.Mobiles
public EDI GetDestination()
{
if (MLQuestSystem.Enabled)
{
return null;
}
if (m_DestinationString == null && m_DeleteTimer == null)
{
m_DestinationString = PickRandomDestination();
}
if (m_Destination != null && m_Destination.Name == m_DestinationString)
{
return m_Destination;
}
if (Map.Felucca.Regions.Count > 0)
{
return m_Destination = EDI.Find(m_DestinationString);
}
return m_Destination = null;
}
@ -668,22 +740,32 @@ namespace Server.Mobiles
ICollection list = Map.Felucca.Regions.Values;
if (list.Count == 0)
{
return;
}
m_Table = new Dictionary<string, EscortDestinationInfo>();
foreach (Region r in list)
{
if (r.Name != null && (r is DungeonRegion || r is TownRegion))
{
m_Table[r.Name] = new EscortDestinationInfo(r.Name, r);
}
}
}
public static EDI Find(string name)
{
if (m_Table == null)
{
LoadTable();
}
if (name == null || m_Table == null)
{
return null;
}
m_Table.TryGetValue(name, out var info);
return info;