Code cleanup (#188)

This commit is contained in:
Kamron Batman 2020-08-01 08:40:06 -07:00 • committed by GitHub
parent df53c16620
commit 010fd9402a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
185 changed files with 1052 additions and 1271 deletions

View file

@ -1126,32 +1126,31 @@ namespace Server.Mobiles
double distance = m_Mobile.GetDistanceToSqrt(target);
if (distance < 1 || distance > 15)
if (!(distance < 1 || distance > 15))
{
if (distance < 1 && target.X == 1076 && target.Y == 450 && m_Mobile is HordeMinionFamiliar)
if (m_Mobile.ControlMaster is PlayerMobile pm)
{
QuestSystem qs = pm.Quest;
if (qs is DarkTidesQuest)
{
QuestObjective obj = qs.FindObjective<FetchAbraxusScrollObjective>();
if (obj?.Completed == false)
{
m_Mobile.AddToBackpack(new ScrollOfAbraxus());
obj.Complete();
}
}
}
m_Mobile.TargetLocation = null;
return false; // At the target or too far away
DoMove(m_Mobile.GetDirectionTo(target));
return true;
}
DoMove(m_Mobile.GetDirectionTo(target));
if (distance < 1 && target.X == 1076 && target.Y == 450 && m_Mobile is HordeMinionFamiliar)
if (m_Mobile.ControlMaster is PlayerMobile pm)
{
QuestSystem qs = pm.Quest;
return true;
if (qs is DarkTidesQuest)
{
QuestObjective obj = qs.FindObjective<FetchAbraxusScrollObjective>();
if (obj?.Completed == false)
{
m_Mobile.AddToBackpack(new ScrollOfAbraxus());
obj.Complete();
}
}
}
m_Mobile.TargetLocation = null;
return false; // At the target or too far away
}
public virtual bool DoOrderFollow()
@ -2099,8 +2098,7 @@ namespace Server.Mobiles
if (!DoMove(dirTo, true) && needCloser)
{
m_Path = new PathFollower(m_Mobile, m);
m_Path.Mover = DoMoveImpl;
m_Path = new PathFollower(m_Mobile, m) {Mover = DoMoveImpl};
if (m_Path.Follow(bRun, 1))
m_Path = null;
@ -2379,17 +2377,11 @@ namespace Server.Mobiles
var spawner = m_Mobile.Spawner;
if (spawner?.ReturnOnDeactivate == true && !m_Mobile.Controlled)
{
if (spawner.HomeLocation == Point3D.Zero)
{
if (!m_Mobile.Region.AcceptsSpawnsFrom(spawner.Region)) Timer.DelayCall(TimeSpan.Zero, ReturnToHome);
}
else if (!m_Mobile.InRange(spawner.HomeLocation, spawner.HomeRange))
{
Timer.DelayCall(TimeSpan.Zero, ReturnToHome);
}
}
if (spawner?.ReturnOnDeactivate == true && !m_Mobile.Controlled && (
spawner.HomeLocation == Point3D.Zero && !m_Mobile.Region.AcceptsSpawnsFrom(spawner.Region) ||
!m_Mobile.InRange(spawner.HomeLocation, spawner.HomeRange)
))
Timer.DelayCall(ReturnToHome);
}
}

View file

@ -141,10 +141,7 @@ namespace Server.Mobiles
public void RemoveFollowers()
{
if (m_Rider != null)
m_Rider.Followers -= FollowerSlots;
if (m_Rider?.Followers < 0)
m_Rider.Followers = 0;
m_Rider.Followers -= Math.Min(m_Rider.Followers, FollowerSlots);
}
public void AddFollowers()
@ -161,7 +158,7 @@ namespace Server.Mobiles
return false;
}
if ((IsRewardItem && !RewardSystem.CheckIsUsableBy(from, this)) || !BaseMount.CheckMountAllowed(from))
if (IsRewardItem && !RewardSystem.CheckIsUsableBy(from, this) || !BaseMount.CheckMountAllowed(from))
return false;
if (from.Mounted)

View file

@ -167,14 +167,8 @@ namespace Server.Mobiles
base.Deserialize(reader);
int version = reader.ReadInt();
if (version == 0)
Timer.DelayCall(TimeSpan.Zero, () => { Hue = GetHue(); });
if (version <= 1)
Timer.DelayCall(TimeSpan.Zero, () =>
{
if (InternalItem != null) InternalItem.Hue = Hue;
});
Timer.DelayCall(Fix, version);
if (version < 2)
for (int i = 0; i < Skills.Length; ++i)
@ -185,6 +179,23 @@ namespace Server.Mobiles
}
}
private void Fix(int version)
{
switch (version)
{
case 1:
{
if (InternalItem != null) InternalItem.Hue = Hue;
goto case 0;
}
case 0:
{
Hue = GetHue();
break;
}
}
}
private class ExpireTimer : Timer
{
private readonly Mobile m_Mobile;

View file

@ -184,14 +184,8 @@ namespace Server.Mobiles
base.Deserialize(reader);
int version = reader.ReadInt();
if (version == 0)
Timer.DelayCall(TimeSpan.Zero, () => Hue = GetHue());
if (version <= 1)
Timer.DelayCall(TimeSpan.Zero, () =>
{
if (InternalItem != null) InternalItem.Hue = Hue;
});
Timer.DelayCall(Fix, version);
if (version < 2)
for (int i = 0; i < Skills.Length; ++i)
@ -202,6 +196,23 @@ namespace Server.Mobiles
}
}
private void Fix(int version)
{
switch (version)
{
case 1:
{
if (InternalItem != null) InternalItem.Hue = Hue;
goto case 0;
}
case 0:
{
Hue = GetHue();
break;
}
}
}
private class ExpireTimer : Timer
{
private readonly Mobile m_Mobile;

View file

@ -411,7 +411,7 @@ namespace Server.Mobiles
public int Loyalty
{
get => m_Loyalty;
set => m_Loyalty = Math.Min(Math.Max(value, 0), MaxLoyalty);
set => m_Loyalty = Math.Clamp(value, 0, MaxLoyalty);
}
[CommandProperty(AccessLevel.GameMaster)]
@ -871,10 +871,12 @@ namespace Server.Mobiles
int SkillBonus = taming - (int)(dMinTameSkill * 10);
int LoreBonus = lore - (int)(dMinTameSkill * 10);
int SkillMod = 6, LoreMod = 6;
int SkillMod = 6;
int LoreMod = 6;
if (SkillBonus < 0)
SkillMod = 28;
if (LoreBonus < 0)
LoreMod = 14;
@ -2045,7 +2047,7 @@ namespace Server.Mobiles
public virtual void CheckedAnimate(int action, int frameCount, int repeatCount, bool forward, bool repeat, int delay)
{
if (!Mounted)
this.Animate(action, frameCount, repeatCount, forward, repeat, delay);
Animate(action, frameCount, repeatCount, forward, repeat, delay);
}
private void CheckAIActive()
@ -2138,7 +2140,7 @@ namespace Server.Mobiles
Timer.DelayCall(TimeSpan.FromSeconds(5.0), ReleaseGuardLock);
m_NoDupeGuards = m;
Timer.DelayCall(TimeSpan.Zero, ReleaseGuardDupeLock);
Timer.DelayCall(ReleaseGuardDupeLock);
}
}
@ -3297,7 +3299,7 @@ namespace Server.Mobiles
if (Owners == null || Owners.Count == 0)
return null;
return Owners[Owners.Count - 1];
return Owners[^1];
}
}
@ -4026,12 +4028,9 @@ namespace Server.Mobiles
if (theirSkill.Lock != SkillLock.Up)
return TeachResult.SkillNotRaisable;
int freePoints = m.Skills.Cap - m.Skills.Total;
int freePoints = Math.Max(m.Skills.Cap - m.Skills.Total, 0);
int freeablePoints = 0;
if (freePoints < 0)
freePoints = 0;
for (int i = 0; freePoints + freeablePoints < pointsToLearn && i < m.Skills.Length; ++i)
{
Skill sk = m.Skills[i];

View file

@ -147,7 +147,11 @@ namespace Server.Mobiles
toBuff.FixedParticles(0x375A, 10, 15, 5017, EffectLayer.Waist);
toBuff.PlaySound(0x1EE);
Timer.DelayCall(TimeSpan.FromSeconds(20.0), () => Unbuff(toBuff, toBuff.HitsMaxSeed, toBuff.RawStr, toBuff.RawDex));
Timer.DelayCall(
TimeSpan.FromSeconds(20.0),
Unbuff,
toBuff, toBuff.HitsMaxSeed, toBuff.RawStr, toBuff.RawDex
);
}
}
else
@ -186,4 +190,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -81,10 +81,15 @@ namespace Server.Mobiles
m_CanTalk = false;
Timer.DelayCall(TimeSpan.FromSeconds(Utility.RandomMinMax(20, 30)), () => { m_CanTalk = true; });
Timer.DelayCall(TimeSpan.FromSeconds(Utility.RandomMinMax(20, 30)), ResetCanTalk);
}
}
private void ResetCanTalk()
{
m_CanTalk = true;
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);

View file

@ -98,7 +98,7 @@ namespace Server.Mobiles
from.LocalOverheadMessage(MessageType.Regular, 0x21,
1071904); // * You slice through the plague beast's amorphous tissue *
Timer.DelayCall(TimeSpan.Zero, pack.Open, from);
Timer.DelayCall(pack.Open, from);
}
}
@ -190,7 +190,7 @@ namespace Server.Mobiles
m_Timer = new DecayTimer(this);
m_Timer.Start();
Timer.DelayCall(TimeSpan.Zero, BroadcastMessage);
Timer.DelayCall(BroadcastMessage);
}
private void BroadcastMessage()

View file

@ -143,7 +143,7 @@ namespace Server.Mobiles
SetResistance(ResistanceType.Energy, 40, 60);
}
Timer.DelayCall(TimeSpan.Zero, RemoveDisguise);
Timer.DelayCall(RemoveDisguise);
}
private class ExpireTimer : Timer

View file

@ -531,7 +531,7 @@ namespace Server.Mobiles
EventSink.EquipMacro += EquipMacro;
EventSink.UnequipMacro += UnequipMacro;
if (Core.SE) Timer.DelayCall(TimeSpan.Zero, CheckPets);
if (Core.SE) Timer.DelayCall(CheckPets);
}
private static void TargetedSkillUse(Mobile from, IEntity target, int skillId)
@ -685,7 +685,7 @@ namespace Server.Mobiles
m_LastPersonalLight = personal;
ns.Send(GlobalLightLevel.Instantiate(global));
ns.Send(new PersonalLightLevel(this.Serial, personal));
ns.Send(new PersonalLightLevel(Serial, personal));
}
public override int GetMinResistance(ResistanceType type)
@ -733,7 +733,8 @@ namespace Server.Mobiles
notice =
"The server is currently under lockdown. You do not have sufficient access level to connect.";
Timer.DelayCall(TimeSpan.FromSeconds(1.0), () => from.NetState?.Dispose());
if (from.NetState != null)
Timer.DelayCall(TimeSpan.FromSeconds(1.0), from.NetState.Dispose);
}
else if (from.AccessLevel >= AccessLevel.Administrator)
{
@ -762,7 +763,7 @@ namespace Server.Mobiles
return;
m_NoDeltaRecursion = true;
Timer.DelayCall(TimeSpan.Zero, ValidateEquipment_Sandbox);
Timer.DelayCall(ValidateEquipment_Sandbox);
}
private void ValidateEquipment_Sandbox()
@ -981,7 +982,7 @@ namespace Server.Mobiles
DisguiseTimers.StartTimer(m);
Timer.DelayCall(TimeSpan.Zero, SpecialMove.ClearAllMoves, m);
Timer.DelayCall(SpecialMove.ClearAllMoves, m);
}
private static void EventSink_Disconnected(Mobile from)
@ -2592,7 +2593,7 @@ namespace Server.Mobiles
public virtual void CheckedAnimate(int action, int frameCount, int repeatCount, bool forward, bool repeat, int delay)
{
if (!Mounted)
this.Animate(action, frameCount, repeatCount, forward, repeat, delay);
Animate(action, frameCount, repeatCount, forward, repeat, delay);
}
public override bool CanSee(Item item) => DesignContext?.Foundation.IsHiddenToCustomizer(item) != true && base.CanSee(item);
@ -2739,7 +2740,7 @@ namespace Server.Mobiles
if (pet.Map != Map)
{
pet.PlaySound(pet.GetAngerSound());
Timer.DelayCall(TimeSpan.Zero, pet.Delete);
Timer.DelayCall(pet.Delete);
}
continue;
@ -4351,15 +4352,12 @@ namespace Server.Mobiles
{
m_Values ??= new TitleInfo[ChampionSpawnInfo.Table.Length];
if (value < 0)
value = 0;
if (index < 0 || index >= m_Values.Length)
return;
m_Values[index] ??= new TitleInfo();
m_Values[index].Value = value;
m_Values[index].Value = Math.Max(value, 0);
}
public void Award(int index, int value)
@ -4385,10 +4383,7 @@ namespace Server.Mobiles
int before = m_Values[index].Value;
if (m_Values[index].Value - value < 0)
m_Values[index].Value = 0;
else
m_Values[index].Value -= value;
m_Values[index].Value -= Math.Min(value, m_Values[index].Value);
if (before != m_Values[index].Value)
m_Values[index].LastDecay = DateTime.UtcNow;

View file

@ -1188,7 +1188,7 @@ namespace Server.Mobiles
if (IsParagon)
IsParagon = false;
Timer.DelayCall(TimeSpan.Zero, CheckMorph);
Timer.DelayCall(CheckMorph);
}
public override void AddCustomContextEntries(Mobile from, List<ContextMenuEntry> list)

View file

@ -523,7 +523,7 @@ namespace Server.Mobiles
}
if (version < 1)
Timer.DelayCall(TimeSpan.Zero, UpgradeFromVersion0);
Timer.DelayCall(UpgradeFromVersion0);
}
private void UpgradeFromVersion0()

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Server.ContextMenus;
using Server.Engines.BulkOrders;
using Server.Ethics;
@ -326,16 +327,10 @@ namespace Server.Mobiles
{
if (BaseHouse.NewVendorSystem) return ChargePerRealWorldDay / 12;
long total = 0;
foreach (VendorItem vi in m_SellItems.Values)
total += vi.Price;
long total = m_SellItems.Values.Aggregate<VendorItem, long>(0, (current, vi) =>
current + vi.Price) - 500;
total -= 500;
if (total < 0)
total = 0;
return (int)(20 + total / 500);
return (int)(20 + Math.Max(total, 0) / 500);
}
}
@ -345,9 +340,7 @@ namespace Server.Mobiles
{
if (BaseHouse.NewVendorSystem)
{
long total = 0;
foreach (VendorItem vi in m_SellItems.Values)
total += vi.Price;
long total = m_SellItems.Values.Aggregate<VendorItem, long>(0, (current, vi) => current + vi.Price);
return (int)(60 + total / 500 * 3);
}
@ -438,11 +431,11 @@ namespace Server.Mobiles
if (version < 1)
{
m_ShopName = "Shop Not Yet Named";
Timer.DelayCall(TimeSpan.Zero, UpgradeFromVersion0, newVendorSystemActivated);
Timer.DelayCall(UpgradeFromVersion0, newVendorSystemActivated);
}
else
{
Timer.DelayCall(TimeSpan.Zero, FixDresswear);
Timer.DelayCall(FixDresswear);
}
NextPayTime = DateTime.UtcNow + PayTimer.GetInterval();
@ -829,7 +822,7 @@ namespace Server.Mobiles
if (IsOwner(from))
{
if (GetVendorItem(item) == null)
Timer.DelayCall(TimeSpan.Zero, () => OnItemGiven(from, item));
Timer.DelayCall(OnItemGiven, from, item);
return true;
}
@ -1521,7 +1514,7 @@ namespace Server.Mobiles
Vendor = (PlayerVendor)reader.ReadMobile();
Timer.DelayCall(TimeSpan.Zero, Delete);
Timer.DelayCall(Delete);
}
private class ExpireTimer : Timer

View file

@ -41,7 +41,7 @@ namespace Server.Mobiles
if (Items.Count == 0 && Gold == 0)
{
Timer.DelayCall(TimeSpan.Zero, Delete);
Timer.DelayCall(Delete);
}
else
{