Code Cleanup & Fixes Warnings (#74)

This commit is contained in:
Kamron Batman 2020-01-18 14:56:45 -08:00 • committed by GitHub
parent e11d1f3ad9
commit 57b14ad690
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
143 changed files with 2960 additions and 3427 deletions

View file

@ -121,8 +121,7 @@ namespace Server.Mobiles
{
AcquireFocusMob(m_Mobile.RangePerception * 2, m_Mobile.FightMode, true, false, true);
if (m_Mobile.FocusMob == null)
m_Mobile.FocusMob = m_Mobile.Combatant;
m_Mobile.FocusMob ??= m_Mobile.Combatant;
return base.DoActionFlee();
}

View file

@ -403,9 +403,9 @@ namespace Server.Mobiles
}
}
public virtual bool IsNecroFamiliar => Summoned && m_ControlMaster != null &&
SummonFamiliarSpell.Table.TryGetValue(m_ControlMaster, out BaseCreature bc) &&
bc == this;
public virtual bool IsNecroFamiliar =>
Summoned && m_ControlMaster != null &&
SummonFamiliarSpell.Table.TryGetValue(m_ControlMaster, out BaseCreature bc) && bc == this;
public virtual bool DeleteCorpseOnDeath => !Core.AOS && m_bSummoned;
@ -3732,8 +3732,7 @@ namespace Server.Mobiles
public virtual void AddPetFriend(Mobile m)
{
if (Friends == null)
Friends = new List<Mobile>();
Friends ??= new List<Mobile>();
Friends.Add(m);
}

View file

@ -326,11 +326,11 @@ namespace Server.Mobiles
private bool TimeToSpare() => m_Owner.NextCombatTime - Core.TickCount > 1000;
private bool OutOfMaxDistance(Mobile target) => !m_Owner.InRange(target, m_Owner.Weapon.MaxRange);
private bool OutOfMaxDistance(IPoint2D target) => !m_Owner.InRange(target, m_Owner.Weapon.MaxRange);
private bool InMinDistance(Mobile target) => m_Owner.InRange(target, 4);
private bool InMinDistance(IPoint2D target) => m_Owner.InRange(target, 4);
private void TeleportTo(Mobile target)
private void TeleportTo(IEntity target)
{
Point3D from = m_Owner.Location;
Point3D to = target.Location;

View file

@ -61,10 +61,10 @@ namespace Server.Mobiles
foreach (Mobile m in eable)
{
if (m == this || !CanBeHarmful(m) ||
!(m is BaseCreature creature && (creature.Controlled || creature.Summoned || creature.Team != Team) ||
m.Player))
!(m.Player || m is BaseCreature creature &&
(creature.Controlled || creature.Summoned || creature.Team != Team)))
continue;
DoHarmful(m);
m.FixedParticles(0x374A, 10, 15, 5013, 0x496, 0, EffectLayer.Waist);
@ -77,7 +77,7 @@ namespace Server.Mobiles
Hits += toDrain;
m.Damage(toDrain, this);
}
eable.Free();
}
@ -109,4 +109,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -184,7 +184,7 @@ namespace Server.Mobiles
continue;
if (m is PlayerMobile pm && pm.Mounted)
pm.Mount.Rider = null;
pm.Mount.Rider = null;
int damage = (int)(m.Hits * 0.6);
if (damage < 10)

View file

@ -76,8 +76,7 @@ namespace Server.Mobiles
{
OpenedBy = from;
if (m_Timer == null)
m_Timer = new DecayTimer(this);
m_Timer ??= new DecayTimer(this);
if (!m_Timer.Running)
m_Timer.Start();

View file

@ -35,8 +35,7 @@ namespace Server.Mobiles
Body = 0x15;
BaseSoundID = 0xDB;
break;
default:
case 5: // slime
default: // slime
Body = 51;
BaseSoundID = 456;
break;

View file

@ -1882,7 +1882,7 @@ namespace Server.Mobiles
pointsToGain += (int)Math.Sqrt(GameTime.TotalSeconds * 4);
pointsToGain *= 5;
pointsToGain += (int)Math.Pow(Skills.Total / 250, 2);
pointsToGain += (int)Math.Pow(Skills.Total / 250.0, 2);
if (VirtueHelper.Award(m, VirtueName.Justice, pointsToGain, ref gainedPath))
{
@ -1894,7 +1894,7 @@ namespace Server.Mobiles
m.FixedParticles(0x375A, 9, 20, 5027, EffectLayer.Waist);
m.PlaySound(0x1F7);
m_NextJustAward = DateTime.UtcNow + TimeSpan.FromMinutes(pointsToGain / 3);
m_NextJustAward = DateTime.UtcNow + TimeSpan.FromMinutes(pointsToGain / 3.0);
}
}
}
@ -2010,9 +2010,7 @@ namespace Server.Mobiles
if (mob?.AccessLevel >= AccessLevel.GameMaster && mob.AccessLevel > from.AccessLevel)
{
if (p == null)
p = Packet.Acquire(new UnicodeMessage(from.Serial, from.Body, MessageType.Regular, from.SpeechHue, 3,
from.Language, from.Name, text));
p ??= Packet.Acquire(new UnicodeMessage(from.Serial, from.Body, MessageType.Regular, from.SpeechHue, 3, from.Language, from.Name, text));
ns.Send(p);
}
@ -2358,32 +2356,23 @@ namespace Server.Mobiles
}
}
if (RecentlyReported == null)
RecentlyReported = new List<Mobile>();
RecentlyReported ??= new List<Mobile>();
// Professions weren't verified on 1.0 RC0
if (!CharacterCreation.VerifyProfession(Profession))
Profession = 0;
if (PermaFlags == null)
PermaFlags = new List<Mobile>();
PermaFlags ??= new List<Mobile>();
JusticeProtectors ??= new List<Mobile>();
BOBFilter ??= new BOBFilter();
if (JusticeProtectors == null)
JusticeProtectors = new List<Mobile>();
if (BOBFilter == null)
BOBFilter = new BOBFilter();
if (m_GuildRank == null)
m_GuildRank =
RankDefinition
.Member; //Default to member if going from older version to new version (only time it should be null)
//Default to member if going from older version to new version (only time it should be null)
m_GuildRank ??= RankDefinition.Member;
if (LastOnline == DateTime.MinValue && Account != null)
LastOnline = ((Account)Account).LastLogin;
if (ChampionTitles == null)
ChampionTitles = new ChampionTitleInfo();
ChampionTitles ??= new ChampionTitleInfo();
if (AccessLevel > AccessLevel.Player)
m_IgnoreMobiles = true;
@ -2797,9 +2786,10 @@ namespace Server.Mobiles
for (int i = AutoStabled.Count - 1; i >= 0; --i)
{
BaseCreature pet = AutoStabled[i] as BaseCreature;
if (!(AutoStabled[i] is BaseCreature pet))
continue;
if (pet?.Deleted == true)
if (pet.Deleted)
{
pet.IsStabled = false;
pet.StabledBy = null;
@ -3099,22 +3089,15 @@ namespace Server.Mobiles
if (ammo == null)
continue;
string name = ammo.Name;
ammo.Amount = kvp.Value;
if (name == null)
string name = ammo.Name ?? ammo switch
{
if (ammo is Arrow)
name = "arrow";
else if (ammo is Bolt)
name = "bolt";
}
if (name != null && ammo.Amount > 1)
name = $"{name}s";
if (name == null)
name = $"#{ammo.LabelNumber}";
Arrow _ => $"arrow{(ammo.Amount != 1 ? "s" : "")}",
Bolt _ => $"bolt{(ammo.Amount != 1 ? "s" : "")}",
_ => $"#{ammo.LabelNumber}"
};
PlaceInBackpack(ammo);
SendLocalizedMessage(1073504, $"{ammo.Amount}\t{name}"); // You recover ~1_NUM~ ~2_AMMO~.
@ -3779,10 +3762,7 @@ namespace Server.Mobiles
m_DuelPlayer = value;
if (m_DuelPlayer == null)
DuelContext = null;
else
DuelContext = m_DuelPlayer.Participant.Context;
DuelContext = m_DuelPlayer?.Participant.Context;
bool isInTourney = DuelContext?.Finished == false && DuelContext.m_Tournament != null;
@ -4435,8 +4415,7 @@ namespace Server.Mobiles
if (m_Values == null || index < 0 || index >= m_Values.Length)
return 0;
if (m_Values[index] == null)
m_Values[index] = new TitleInfo();
m_Values[index] ??= new TitleInfo();
return m_Values[index].Value;
}
@ -4446,16 +4425,14 @@ namespace Server.Mobiles
if (m_Values == null || index < 0 || index >= m_Values.Length)
return DateTime.MinValue;
if (m_Values[index] == null)
m_Values[index] = new TitleInfo();
m_Values[index] ??= new TitleInfo();
return m_Values[index].LastDecay;
}
public void SetValue(int index, int value)
{
if (m_Values == null)
m_Values = new TitleInfo[ChampionSpawnInfo.Table.Length];
m_Values ??= new TitleInfo[ChampionSpawnInfo.Table.Length];
if (value < 0)
value = 0;
@ -4463,36 +4440,31 @@ namespace Server.Mobiles
if (index < 0 || index >= m_Values.Length)
return;
if (m_Values[index] == null)
m_Values[index] = new TitleInfo();
m_Values[index] ??= new TitleInfo();
m_Values[index].Value = value;
}
public void Award(int index, int value)
{
if (m_Values == null)
m_Values = new TitleInfo[ChampionSpawnInfo.Table.Length];
m_Values ??= new TitleInfo[ChampionSpawnInfo.Table.Length];
if (index < 0 || index >= m_Values.Length || value <= 0)
return;
if (m_Values[index] == null)
m_Values[index] = new TitleInfo();
m_Values[index] ??= new TitleInfo();
m_Values[index].Value += value;
}
public void Atrophy(int index, int value)
{
if (m_Values == null)
m_Values = new TitleInfo[ChampionSpawnInfo.Table.Length];
m_Values ??= new TitleInfo[ChampionSpawnInfo.Table.Length];
if (index < 0 || index >= m_Values.Length || value <= 0)
return;
if (m_Values[index] == null)
m_Values[index] = new TitleInfo();
m_Values[index] ??= new TitleInfo();
int before = m_Values[index].Value;
@ -4518,8 +4490,7 @@ namespace Server.Mobiles
for (int i = 0; i < length; i++)
{
if (titles.m_Values[i] == null)
titles.m_Values[i] = new TitleInfo();
titles.m_Values[i] ??= new TitleInfo();
TitleInfo.Serialize(writer, titles.m_Values[i]);
}
@ -4531,8 +4502,7 @@ namespace Server.Mobiles
if (t == null)
return;
if (t.m_Values == null)
t.m_Values = new TitleInfo[ChampionSpawnInfo.Table.Length];
t.m_Values ??= new TitleInfo[ChampionSpawnInfo.Table.Length];
for (int i = 0; i < t.m_Values.Length; i++)
if (t.GetLastDecay(i) + LossDelay < DateTime.UtcNow)
@ -4546,14 +4516,9 @@ namespace Server.Mobiles
if (t == null)
return;
if (t.m_Values == null)
t.m_Values = new TitleInfo[ChampionSpawnInfo.Table.Length];
t.m_Values ??= new TitleInfo[ChampionSpawnInfo.Table.Length];
int count = 1;
for (int i = 0; i < t.m_Values.Length; i++)
if (t.m_Values[i].Value > 900)
count++;
int count = 1 + t.m_Values.Count(t1 => t1.Value > 900);
t.Harrower = Math.Max(count, t.Harrower); //Harrower titles never decay.
}
@ -4611,8 +4576,7 @@ namespace Server.Mobiles
public virtual void AcquireRecipe(int recipeID)
{
if (m_AcquiredRecipes == null)
m_AcquiredRecipes = new Dictionary<int, bool>();
m_AcquiredRecipes ??= new Dictionary<int, bool>();
m_AcquiredRecipes[recipeID] = true;
}
@ -4648,8 +4612,7 @@ namespace Server.Mobiles
RemoveBuff(b); //Check & subsequently remove the old one.
if (m_BuffTable == null)
m_BuffTable = new Dictionary<BuffIcon, BuffInfo>();
m_BuffTable ??= new Dictionary<BuffIcon, BuffInfo>();
m_BuffTable.Add(b.ID, b);

View file

@ -50,8 +50,7 @@ namespace Server.Mobiles
public TownCrierEntry AddEntry(string[] lines, TimeSpan duration)
{
if (Entries == null)
Entries = new List<TownCrierEntry>();
Entries ??= new List<TownCrierEntry>();
TownCrierEntry tce = new TownCrierEntry(lines, duration);
@ -204,10 +203,7 @@ namespace Server.Mobiles
owner.GetRandomEntry(); // force expiration checks
int count = 0;
if (entries != null)
count = entries.Count;
int count = entries?.Count ?? 0;
AddImageTiled(0, 0, 300, 38 + (count == 0 ? 20 : count * 85), 0xA40);
AddAlphaRegion(1, 1, 298, 36 + (count == 0 ? 20 : count * 85));
@ -384,15 +380,13 @@ namespace Server.Mobiles
public TownCrierEntry AddEntry(string[] lines, TimeSpan duration)
{
if (Entries == null)
Entries = new List<TownCrierEntry>();
Entries ??= new List<TownCrierEntry>();
TownCrierEntry tce = new TownCrierEntry(lines, duration);
Entries.Add(tce);
if (m_AutoShoutTimer == null)
m_AutoShoutTimer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), TimeSpan.FromMinutes(1.0), AutoShout_Callback);
m_AutoShoutTimer ??= Timer.DelayCall(TimeSpan.FromSeconds(5.0), TimeSpan.FromMinutes(1.0), AutoShout_Callback);
return tce;
}
@ -417,8 +411,7 @@ namespace Server.Mobiles
public void ForceBeginAutoShout()
{
if (m_AutoShoutTimer == null)
m_AutoShoutTimer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), TimeSpan.FromMinutes(1.0), AutoShout_Callback);
m_AutoShoutTimer ??= Timer.DelayCall(TimeSpan.FromSeconds(5.0), TimeSpan.FromMinutes(1.0), AutoShout_Callback);
}
private void AutoShout_Callback()
@ -433,9 +426,8 @@ namespace Server.Mobiles
}
else if (m_NewsTimer == null)
{
int index = 0;
m_NewsTimer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(3.0),
() => ShoutNews_Callback(tce, index));
() => ShoutNews_Callback(tce, 0));
PublicOverheadMessage(MessageType.Regular, 0x3B2, 502976); // Hear ye! Hear ye!
}
@ -478,9 +470,8 @@ namespace Server.Mobiles
}
else
{
int index = 0;
m_NewsTimer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(3.0),
() => ShoutNews_Callback(tce, index));
() => ShoutNews_Callback(tce, 0));
PublicOverheadMessage(MessageType.Regular, 0x3B2, 502978); // Some of the latest news!
}

View file

@ -584,8 +584,7 @@ namespace Server.Mobiles
{
if (House.IsOwner(Owner)) // Move to moving crate
{
if (House.MovingCrate == null)
House.MovingCrate = new MovingCrate(House);
House.MovingCrate ??= new MovingCrate(House);
if (HoldGold > 0)
Banker.Deposit(House.MovingCrate, HoldGold);

View file

@ -129,8 +129,7 @@ namespace Server.Mobiles
{
if (RentalGold > 0 && House?.IsAosRules == true)
{
if (House.MovingCrate == null)
House.MovingCrate = new MovingCrate(House);
House.MovingCrate ??= new MovingCrate(House);
Banker.Deposit(House.MovingCrate, RentalGold);
RentalGold = 0;

View file

@ -116,8 +116,7 @@ namespace Server.Mobiles
{
if (m_Inventory.Gold > 0)
{
if (house.MovingCrate == null)
house.MovingCrate = new MovingCrate(house);
house.MovingCrate ??= new MovingCrate(house);
Banker.Deposit(house.MovingCrate, m_Inventory.Gold);
}
@ -134,4 +133,4 @@ namespace Server.Mobiles
}
}
}
}
}