From 010fd9402a2b5a6cfda91bee022d4e36720be34e Mon Sep 17 00:00:00 2001
From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com>
Date: Sat, 1 Aug 2020 08:40:06 -0700
Subject: [PATCH] Code cleanup (#188)
---
Projects/Server/Diagnostics/BaseProfile.cs | 2 +-
Projects/Server/Diagnostics/PacketProfile.cs | 2 +-
Projects/Server/Guild.cs | 8 +-
Projects/Server/Interfaces.cs | 1 +
Projects/Server/Item.cs | 22 +-
.../Server/JsonConfiguration/JsonConfig.cs | 1 -
Projects/Server/Map.cs | 28 +-
Projects/Server/Mobile.cs | 19 +-
Projects/Server/Network/PacketHandlers.cs | 88 +++---
.../Packets/Old Packets/DamagePackets.cs | 16 +-
.../Persistence/SequentialFileWriterStream.cs | 2 +-
Projects/Server/Regions/RegionLoader.cs | 1 -
Projects/Server/Skills.cs | 14 +-
Projects/Server/TileData.cs | 1 -
Projects/Server/{ => Timer}/Timer.cs | 90 +-----
Projects/Server/Timer/TimerDelayCalls.cs | 268 ++++++++++++++++++
Projects/Server/Utilities/ActivatorUtil.cs | 20 ++
Projects/Server/Utilities/RefPool.cs | 20 ++
Projects/Server/Utilities/Utility.cs | 22 +-
.../ContainedCommandImplementor.cs | 4 +-
.../Implementors/MultiCommandImplementor.cs | 8 +-
.../Implementors/SingleCommandImplementor.cs | 4 +-
.../Object Creation/CategorizedAddGump.cs | 7 +-
Projects/UOContent/Commands/Properties.cs | 6 +-
.../Engines/BulkOrders/SmallBulkEntry.cs | 2 +-
.../Engines/CannedEvil/ChampionSpawn.cs | 4 +-
Projects/UOContent/Engines/ConPVP/Arena.cs | 35 +--
.../UOContent/Engines/ConPVP/DuelContext.cs | 2 +-
.../Engines/ConPVP/Games/BombingRun.cs | 14 +-
.../UOContent/Engines/ConPVP/Games/CTF.cs | 2 +-
.../Engines/ConPVP/Games/DoubleDom.cs | 3 +-
.../Engines/ConPVP/Games/KingOfTheHill.cs | 2 +-
.../ConPVP/Gumps/TournamentBracketGump.cs | 2 +-
.../UOContent/Engines/ConPVP/Participant.cs | 2 +-
.../UOContent/Engines/ConPVP/Tournament.cs | 8 +-
.../Craft/Core/CraftCollectionExtensions.cs | 49 ++++
.../Engines/Craft/Core/CraftGroup.cs | 8 +-
.../Engines/Craft/Core/CraftGroupCol.cs | 39 ---
.../UOContent/Engines/Craft/Core/CraftGump.cs | 23 +-
.../Engines/Craft/Core/CraftGumpItem.cs | 6 +-
.../UOContent/Engines/Craft/Core/CraftItem.cs | 16 +-
.../Engines/Craft/Core/CraftItemCol.cs | 47 ---
.../Engines/Craft/Core/CraftResCol.cs | 25 --
.../Engines/Craft/Core/CraftSkillCol.cs | 25 --
.../Engines/Craft/Core/CraftSubResCol.cs | 28 +-
.../Engines/Craft/Core/CraftSystem.cs | 58 ++--
.../UOContent/Engines/Craft/Core/Recipes.cs | 10 +-
.../UOContent/Engines/Craft/Core/Resmelt.cs | 11 +-
.../UOContent/Engines/Craft/DefCooking.cs | 1 +
.../UOContent/Engines/Craft/DefTailoring.cs | 1 +
.../UOContent/Engines/Ethics/Core/Ethic.cs | 3 +-
.../Engines/Factions/Core/Election.cs | 7 +-
.../Engines/Factions/Core/Faction.cs | 4 +-
.../Engines/Factions/Core/FactionState.cs | 4 +-
.../Engines/Factions/Core/Keywords.cs | 2 +-
.../Items/Power Faction Items/StormsEye.cs | 119 ++++----
.../Factions/Items/Traps/BaseFactionTrap.cs | 2 +-
.../Mobiles/Guards/BaseFactionGuard.cs | 2 +-
.../UOContent/Engines/Khaldun/RaiseSwitch.cs | 2 +-
.../Quests/Core/Items/HornOfRetreat.cs | 4 +-
.../Engines/Quests/Core/QuestSystem.cs | 4 +-
.../Items/HaochisTreasureChest.cs | 4 +-
.../The Summoning/Items/BellOfTheDead.cs | 2 +-
.../Quests/Witch Apprentice/Objectives.cs | 8 +-
.../Character Statue Maker/CharacterStatue.cs | 2 +-
.../CharacterStatuePlinth.cs | 4 +-
Projects/UOContent/Gumps/Go/GoGump.cs | 8 +-
.../New Guild System/BaseGuildListGump.cs | 2 +-
.../New Guild System/War Declaration gump.cs | 8 +-
Projects/UOContent/Gumps/PolymorphGump.cs | 4 +-
Projects/UOContent/Gumps/Props/PropsGump.cs | 7 +-
Projects/UOContent/Gumps/ReportMurderer.cs | 2 +-
.../Halloween/2009/Engines/PumpkinPatch.cs | 4 +-
.../Items/Addons/BaseAddonContainerDeed.cs | 2 +-
.../UOContent/Items/Addons/JackOLantern.cs | 57 ++--
.../Items/Addons/RejuvinationAnkhs.cs | 4 +-
Projects/UOContent/Items/Aquarium/Aquarium.cs | 2 +-
.../UOContent/Items/Aquarium/AquariumState.cs | 15 +-
Projects/UOContent/Items/Armor/BaseArmor.cs | 13 +-
.../UOContent/Items/Body Parts/BonePile.cs | 2 +-
.../UOContent/Items/Body Parts/RibCage.cs | 2 +-
.../Shared/DetectiveBoots.cs | 4 +-
.../UOContent/Items/Clothing/BaseClothing.cs | 65 ++---
.../Items/Containers/FillableContainers.cs | 2 +-
.../UOContent/Items/Containers/SalvageBag.cs | 2 +-
.../Items/Deeds/DragonBardingDeed.cs | 2 +-
Projects/UOContent/Items/Guilds/Guildstone.cs | 3 +-
Projects/UOContent/Items/Jewels/BaseJewel.cs | 6 +-
Projects/UOContent/Items/Maps/MapItem.cs | 11 +-
Projects/UOContent/Items/Misc/Bola.cs | 4 +-
.../UOContent/Items/Misc/Corpses/Corpse.cs | 2 +-
.../UOContent/Items/Misc/DeceitBrazier.cs | 26 +-
Projects/UOContent/Items/Misc/Firebomb.cs | 2 +-
Projects/UOContent/Items/Misc/MorphItem.cs | 3 +-
Projects/UOContent/Items/Misc/OilCloth.cs | 2 +-
.../UOContent/Items/Misc/PowerGenerator.cs | 2 +-
Projects/UOContent/Items/Misc/Teleporter.cs | 2 +-
Projects/UOContent/Items/Misc/WarningItem.cs | 6 +-
.../Items/Resources/Fishing/BigFish.cs | 2 +-
.../UOContent/Items/Resources/Fishing/Fish.cs | 2 +-
.../Items/Resources/Tailor/BoltOfCloth.cs | 2 +-
.../UOContent/Items/Resources/Tailor/Cloth.cs | 2 +-
.../UOContent/Items/Resources/Tailor/Hides.cs | 8 +-
.../Items/Resources/Tailor/UncutCloth.cs | 2 +-
.../Carpenter Items/TaxidermyKit.cs | 2 +-
.../Items/Skill Items/Lumberjack/Log.cs | 2 +-
.../Skill Items/Magical/Misc/PotionKeg.cs | 2 +-
.../BaseConflagrationPotion.cs | 2 +-
.../BaseConfusionBlastPotion.cs | 4 +-
.../Explosion Potions/BaseExplosionPotion.cs | 2 +-
.../Items/Skill Items/Misc/RepairDeed.cs | 2 +-
.../Musical Instruments/BaseInstrument.cs | 2 +-
.../Skill Items/Ninjitsu/NinjaWeapons.cs | 25 +-
.../8th Anniversary Items/FountainOfLife.cs | 8 +-
.../Special/Heritage Items/Guillotine.cs | 4 +-
.../Special/Heritage Items/IronMaiden.cs | 16 +-
.../Special/Holiday/Christmas/HolidayTree.cs | 3 +-
.../Items/Special/Holiday/IcyPatch.cs | 6 +-
.../UOContent/Items/Special/Holiday/Wreath.cs | 3 +-
.../Mutation Core/PlagueBeastOrgans.cs | 2 +-
.../UOContent/Items/Talismans/BaseTalisman.cs | 6 +-
.../Weapons/Abilities/InfectiousStrike.cs | 7 +-
.../UOContent/Items/Weapons/BaseWeapon.cs | 9 +-
.../Items/Weapons/Maces/FireworksWand.cs | 4 +-
Projects/UOContent/Misc/AutoSave.cs | 2 +-
Projects/UOContent/Misc/BuffIcons.cs | 10 +-
Projects/UOContent/Misc/ClientVerification.cs | 20 +-
Projects/UOContent/Misc/DoorGenerator.cs | 2 +-
.../Misc/Gifts/Winter2004/Mistletoe.cs | 3 +-
Projects/UOContent/Misc/Guild.cs | 2 +-
Projects/UOContent/Misc/ServerList.cs | 2 +-
Projects/UOContent/Mobiles/AI/BaseAI.cs | 62 ++--
.../Mobiles/Animals/Mounts/Ethereals.cs | 7 +-
.../UOContent/Mobiles/Animals/Mounts/Hiryu.cs | 25 +-
.../Mobiles/Animals/Mounts/LesserHiryu.cs | 25 +-
Projects/UOContent/Mobiles/BaseCreature.cs | 17 +-
.../Mobiles/Monsters/LBR/Jukas/JukaMage.cs | 8 +-
.../Mobiles/Monsters/ML/Animal/Ferret.cs | 7 +-
.../Monsters/Misc/Melee/PlagueBeastLord.cs | 4 +-
.../Mobiles/Monsters/SE/BakeKitsune.cs | 2 +-
Projects/UOContent/Mobiles/PlayerMobile.cs | 25 +-
.../UOContent/Mobiles/Vendors/BaseVendor.cs | 2 +-
.../Mobiles/Vendors/PlayerBarkeeper.cs | 2 +-
.../UOContent/Mobiles/Vendors/PlayerVendor.cs | 25 +-
.../Mobiles/Vendors/VendorInventory.cs | 2 +-
Projects/UOContent/Multis/BaseHouse.cs | 30 +-
Projects/UOContent/Multis/Camps/BaseCamp.cs | 4 +-
Projects/UOContent/Multis/ContestHouses.cs | 6 +-
Projects/UOContent/Multis/MovingCrate.cs | 4 +-
Projects/UOContent/Multis/PreviewHouse.cs | 4 +-
Projects/UOContent/Skills/AnimalTaming.cs | 4 +-
Projects/UOContent/Skills/EvalInt.cs | 10 +-
Projects/UOContent/Spells/Base/MagerySpell.cs | 13 +-
Projects/UOContent/Spells/Base/Spell.cs | 59 +---
Projects/UOContent/Spells/Base/SpellHelper.cs | 58 ++--
.../Spells/Bushido/HonorableExecution.cs | 2 +-
.../Spells/Bushido/MomentumStrike.cs | 3 +-
.../UOContent/Spells/Bushido/SamuraiSpell.cs | 2 +-
.../Spells/Chivalry/CleanseByFire.cs | 8 +-
.../UOContent/Spells/Chivalry/CloseWounds.cs | 2 +-
.../Spells/Chivalry/ConsecrateWeapon.cs | 8 +-
.../UOContent/Spells/Chivalry/DivineFury.cs | 8 +-
.../UOContent/Spells/Chivalry/EnemyOfOne.cs | 8 +-
.../UOContent/Spells/Chivalry/HolyLight.cs | 8 +-
.../Spells/Chivalry/NobleSacrifice.cs | 8 +-
.../UOContent/Spells/Eighth/Earthquake.cs | 3 +-
Projects/UOContent/Spells/Fifth/Paralyze.cs | 5 +-
Projects/UOContent/Spells/First/NightSight.cs | 15 +-
.../UOContent/Spells/First/ReactiveArmor.cs | 13 +-
.../UOContent/Spells/Fourth/ArchProtection.cs | 4 +-
Projects/UOContent/Spells/Fourth/ManaDrain.cs | 9 +-
.../Gargoyle/SpellDefinitions/FlySpell.cs | 11 +-
.../Spells/Necromancy/AnimateDeadSpell.cs | 23 +-
.../Spells/Necromancy/NecromancerSpell.cs | 13 +-
.../UOContent/Spells/Necromancy/PainSpike.cs | 5 +-
.../Spells/Necromancy/TransformationSpell.cs | 10 +-
.../UOContent/Spells/Ninjitsu/DeathStrike.cs | 2 +-
.../UOContent/Spells/Ninjitsu/FocusAttack.cs | 4 +-
Projects/UOContent/Spells/Second/MagicTrap.cs | 2 +-
.../UOContent/Spells/Second/Protection.cs | 13 +-
.../UOContent/Spells/Second/RemoveTrap.cs | 2 +-
.../UOContent/Spells/Seventh/ManaVampire.cs | 11 +-
.../UOContent/Spells/Sixth/ParalyzeField.cs | 7 +-
.../Spells/Spellweaving/Mobiles/NatureFury.cs | 4 +-
.../Spells/Spellweaving/Thunderstorm.cs | 9 +-
185 files changed, 1052 insertions(+), 1271 deletions(-)
rename Projects/Server/{ => Timer}/Timer.cs (76%)
create mode 100644 Projects/Server/Timer/TimerDelayCalls.cs
create mode 100644 Projects/UOContent/Engines/Craft/Core/CraftCollectionExtensions.cs
delete mode 100644 Projects/UOContent/Engines/Craft/Core/CraftGroupCol.cs
delete mode 100644 Projects/UOContent/Engines/Craft/Core/CraftItemCol.cs
delete mode 100644 Projects/UOContent/Engines/Craft/Core/CraftResCol.cs
delete mode 100644 Projects/UOContent/Engines/Craft/Core/CraftSkillCol.cs
diff --git a/Projects/Server/Diagnostics/BaseProfile.cs b/Projects/Server/Diagnostics/BaseProfile.cs
index 1d119e153..40d5e6b51 100644
--- a/Projects/Server/Diagnostics/BaseProfile.cs
+++ b/Projects/Server/Diagnostics/BaseProfile.cs
@@ -40,7 +40,7 @@ namespace Server.Diagnostics
public long Count { get; private set; }
- public TimeSpan AverageTime => TimeSpan.FromTicks(TotalTime.Ticks / Math.Max(1, Count));
+ public TimeSpan AverageTime => TimeSpan.FromTicks(TotalTime.Ticks / Math.Max(Count, 1));
public TimeSpan PeakTime { get; private set; }
diff --git a/Projects/Server/Diagnostics/PacketProfile.cs b/Projects/Server/Diagnostics/PacketProfile.cs
index d39c906ee..1678a6986 100644
--- a/Projects/Server/Diagnostics/PacketProfile.cs
+++ b/Projects/Server/Diagnostics/PacketProfile.cs
@@ -34,7 +34,7 @@ namespace Server.Diagnostics
public long TotalLength { get; private set; }
- public double AverageLength => (double)TotalLength / Math.Max(1, Count);
+ public double AverageLength => (double)TotalLength / Math.Max(Count, 1);
public void Finish(long length)
{
diff --git a/Projects/Server/Guild.cs b/Projects/Server/Guild.cs
index 11b8c2168..09ae92439 100644
--- a/Projects/Server/Guild.cs
+++ b/Projects/Server/Guild.cs
@@ -39,10 +39,10 @@ namespace Server.Guilds
protected BaseGuild(uint id) // serialization ctor
{
- this.Serial = id;
- List.Add(this.Serial, this);
- if (this.Serial + 1 > m_NextID)
- m_NextID = this.Serial + 1;
+ Serial = id;
+ List.Add(Serial, this);
+ if (Serial + 1 > m_NextID)
+ m_NextID = Serial + 1;
m_SaveBuffer = new BufferWriter(true);
}
diff --git a/Projects/Server/Interfaces.cs b/Projects/Server/Interfaces.cs
index f2032d604..c2d60a8d4 100644
--- a/Projects/Server/Interfaces.cs
+++ b/Projects/Server/Interfaces.cs
@@ -43,6 +43,7 @@ namespace Server
int MaxRange { get; }
void OnBeforeSwing(Mobile attacker, Mobile defender);
TimeSpan OnSwing(Mobile attacker, Mobile defender);
+ TimeSpan OnSwing(Mobile attacker, Mobile defender, double damageBonus);
void GetStatusDamage(Mobile from, out int min, out int max);
}
diff --git a/Projects/Server/Item.cs b/Projects/Server/Item.cs
index 798d67ea3..a390ff6d9 100644
--- a/Projects/Server/Item.cs
+++ b/Projects/Server/Item.cs
@@ -2550,7 +2550,7 @@ namespace Server
}
if (HeldBy != null)
- Timer.DelayCall(TimeSpan.Zero, FixHolding_Sandbox);
+ Timer.DelayCall(FixHolding_Sandbox);
// if (version < 9)
VerifyCompactInfo();
@@ -3070,18 +3070,12 @@ namespace Server
if (checkTop == checkZ && !id.Surface)
++checkTop;
- var zStart = checkZ - z;
- var zEnd = checkTop - z;
+ var zStart = Math.Max(checkZ - z, 0);
+ var zEnd = Math.Min(checkTop - z, 19);
if (zStart >= 20 || zEnd < 0)
continue;
- if (zStart < 0)
- zStart = 0;
-
- if (zEnd > 19)
- zEnd = 19;
-
var bitCount = zEnd - zStart;
m_OpenSlots &= ~(((1 << bitCount) - 1) << zStart);
@@ -3098,18 +3092,12 @@ namespace Server
if (checkTop == checkZ && !id.Surface)
++checkTop;
- var zStart = checkZ - z;
- var zEnd = checkTop - z;
+ var zStart = Math.Max(checkZ - z, 0);
+ var zEnd = Math.Min(checkTop - z, 19);
if (zStart >= 20 || zEnd < 0)
continue;
- if (zStart < 0)
- zStart = 0;
-
- if (zEnd > 19)
- zEnd = 19;
-
var bitCount = zEnd - zStart;
m_OpenSlots &= ~(((1 << bitCount) - 1) << zStart);
diff --git a/Projects/Server/JsonConfiguration/JsonConfig.cs b/Projects/Server/JsonConfiguration/JsonConfig.cs
index eaec4039e..b3858bf72 100644
--- a/Projects/Server/JsonConfiguration/JsonConfig.cs
+++ b/Projects/Server/JsonConfiguration/JsonConfig.cs
@@ -20,7 +20,6 @@
using System;
using System.Buffers;
-using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
diff --git a/Projects/Server/Map.cs b/Projects/Server/Map.cs
index 0ad437377..89d417307 100644
--- a/Projects/Server/Map.cs
+++ b/Projects/Server/Map.cs
@@ -655,34 +655,14 @@ namespace Server
public void Bound(int x, int y, out int newX, out int newY)
{
- if (x < 0)
- newX = 0;
- else if (x >= Width)
- newX = Width - 1;
- else
- newX = x;
-
- if (y < 0)
- newY = 0;
- else if (y >= Height)
- newY = Height - 1;
- else
- newY = y;
+ newX = Math.Clamp(x, 0, Width - 1);
+ newY = Math.Clamp(y, 0, Height - 1);
}
public Point2D Bound(Point2D p)
{
- int x = p.m_X, y = p.m_Y;
-
- if (x < 0)
- x = 0;
- else if (x >= Width)
- x = Width - 1;
-
- if (y < 0)
- y = 0;
- else if (y >= Height)
- y = Height - 1;
+ int x = Math.Clamp(p.m_X, 0, Width - 1);
+ int y = Math.Clamp(p.m_Y, 0, Height - 1);
return new Point2D(x, y);
}
diff --git a/Projects/Server/Mobile.cs b/Projects/Server/Mobile.cs
index c6eead6a5..15ed2cd6a 100644
--- a/Projects/Server/Mobile.cs
+++ b/Projects/Server/Mobile.cs
@@ -1486,7 +1486,7 @@ namespace Server
AddToBackpack(item.Items[j]);
}
- Timer.DelayCall(TimeSpan.Zero, item.Delete);
+ Timer.DelayCall(item.Delete);
}
}
@@ -1811,10 +1811,7 @@ namespace Server
if (m_Kills != value)
{
- m_Kills = value;
-
- if (m_Kills < 0)
- m_Kills = 0;
+ m_Kills = Math.Max(value, 0);
if (oldValue >= 5 != m_Kills >= 5)
{
@@ -1834,12 +1831,7 @@ namespace Server
set
{
if (m_ShortTermMurders != value)
- {
- m_ShortTermMurders = value;
-
- if (m_ShortTermMurders < 0)
- m_ShortTermMurders = 0;
- }
+ m_ShortTermMurders = Math.Max(value, 0);
}
}
@@ -5250,9 +5242,8 @@ namespace Server
OnDamage(amount, from, newHits < 0);
- var m = Mount;
- if (m != null && informMount)
- m.OnRiderDamaged(amount, from, newHits < 0);
+ if (informMount)
+ Mount?.OnRiderDamaged(amount, from, newHits < 0);
if (newHits < 0)
{
diff --git a/Projects/Server/Network/PacketHandlers.cs b/Projects/Server/Network/PacketHandlers.cs
index 625a7fa17..7281cd016 100644
--- a/Projects/Server/Network/PacketHandlers.cs
+++ b/Projects/Server/Network/PacketHandlers.cs
@@ -501,8 +501,7 @@ namespace Server.Network
var vendor = World.FindMobile(pvSrc.ReadUInt32());
var flag = pvSrc.ReadByte();
- if (vendor == null)
- return;
+ if (vendor == null) return;
if (vendor.Deleted || !Utility.RangeCheck(vendor.Location, state.Mobile.Location, 10))
{
@@ -840,8 +839,7 @@ namespace Server.Network
var beholder = state.Mobile;
var beheld = World.FindMobile(serial);
- if (beheld == null)
- return;
+ if (beheld == null) return;
switch (type)
{
@@ -1014,8 +1012,7 @@ namespace Server.Network
var t = from.Target;
- if (t == null)
- return;
+ if (t == null) return;
var prof = TargetProfile.Acquire(t.GetType());
prof?.Start();
@@ -1640,45 +1637,41 @@ namespace Server.Network
public static void PartyMessage_AddMember(NetState state, PacketReader pvSrc)
{
- if (PartyCommands.Handler != null)
- PartyCommands.Handler.OnAdd(state.Mobile);
+ PartyCommands.Handler?.OnAdd(state.Mobile);
}
public static void PartyMessage_RemoveMember(NetState state, PacketReader pvSrc)
{
- if (PartyCommands.Handler != null)
- PartyCommands.Handler.OnRemove(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
+ PartyCommands.Handler?.OnRemove(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
}
public static void PartyMessage_PrivateMessage(NetState state, PacketReader pvSrc)
{
- if (PartyCommands.Handler != null)
- PartyCommands.Handler.OnPrivateMessage(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()),
- pvSrc.ReadUnicodeStringSafe());
+ PartyCommands.Handler?.OnPrivateMessage(
+ state.Mobile,
+ World.FindMobile(pvSrc.ReadUInt32()),
+ pvSrc.ReadUnicodeStringSafe()
+ );
}
public static void PartyMessage_PublicMessage(NetState state, PacketReader pvSrc)
{
- if (PartyCommands.Handler != null)
- PartyCommands.Handler.OnPublicMessage(state.Mobile, pvSrc.ReadUnicodeStringSafe());
+ PartyCommands.Handler?.OnPublicMessage(state.Mobile, pvSrc.ReadUnicodeStringSafe());
}
public static void PartyMessage_SetCanLoot(NetState state, PacketReader pvSrc)
{
- if (PartyCommands.Handler != null)
- PartyCommands.Handler.OnSetCanLoot(state.Mobile, pvSrc.ReadBoolean());
+ PartyCommands.Handler?.OnSetCanLoot(state.Mobile, pvSrc.ReadBoolean());
}
public static void PartyMessage_Accept(NetState state, PacketReader pvSrc)
{
- if (PartyCommands.Handler != null)
- PartyCommands.Handler.OnAccept(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
+ PartyCommands.Handler?.OnAccept(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
}
public static void PartyMessage_Decline(NetState state, PacketReader pvSrc)
{
- if (PartyCommands.Handler != null)
- PartyCommands.Handler.OnDecline(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
+ PartyCommands.Handler?.OnDecline(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
}
public static void StunRequest(NetState state, PacketReader pvSrc)
@@ -1725,41 +1718,40 @@ namespace Server.Network
{
var from = state.Mobile;
- if (from != null)
+ if (from == null) return;
+
+ var menu = from.ContextMenu;
+
+ from.ContextMenu = null;
+
+ if (menu != null && from == menu.From)
{
- var menu = from.ContextMenu;
+ var entity = World.FindEntity(pvSrc.ReadUInt32());
- from.ContextMenu = null;
-
- if (menu != null && from == menu.From)
+ if (entity != null && entity == menu.Target && from.CanSee(entity))
{
- var entity = World.FindEntity(pvSrc.ReadUInt32());
+ Point3D p;
- if (entity != null && entity == menu.Target && from.CanSee(entity))
+ if (entity is Mobile)
+ p = entity.Location;
+ else if (entity is Item item)
+ p = item.GetWorldLocation();
+ else
+ return;
+
+ int index = pvSrc.ReadUInt16();
+
+ if (index >= 0 && index < menu.Entries.Length)
{
- Point3D p;
+ var e = menu.Entries[index];
- if (entity is Mobile)
- p = entity.Location;
- else if (entity is Item item)
- p = item.GetWorldLocation();
- else
- return;
+ var range = e.Range;
- int index = pvSrc.ReadUInt16();
+ if (range == -1)
+ range = 18;
- if (index >= 0 && index < menu.Entries.Length)
- {
- var e = menu.Entries[index];
-
- var range = e.Range;
-
- if (range == -1)
- range = 18;
-
- if (e.Enabled && from.InRange(p, range))
- e.OnClick();
- }
+ if (e.Enabled && from.InRange(p, range))
+ e.OnClick();
}
}
}
diff --git a/Projects/Server/Network/Packets/Old Packets/DamagePackets.cs b/Projects/Server/Network/Packets/Old Packets/DamagePackets.cs
index 8452eeb76..7b7486f1c 100644
--- a/Projects/Server/Network/Packets/Old Packets/DamagePackets.cs
+++ b/Projects/Server/Network/Packets/Old Packets/DamagePackets.cs
@@ -18,6 +18,8 @@
* along with this program. If not, see . *
*************************************************************************/
+using System;
+
namespace Server.Network
{
public sealed class DamagePacketOld : Packet
@@ -30,12 +32,7 @@ namespace Server.Network
Stream.Write((byte)1);
Stream.Write(mobile);
- if (amount > 255)
- amount = 255;
- else if (amount < 0)
- amount = 0;
-
- Stream.Write((byte)amount);
+ Stream.Write((byte)Math.Clamp(amount, 0, 255));
}
}
@@ -45,12 +42,7 @@ namespace Server.Network
{
Stream.Write(mobile);
- if (amount > 0xFFFF)
- amount = 0xFFFF;
- else if (amount < 0)
- amount = 0;
-
- Stream.Write((ushort)amount);
+ Stream.Write((ushort)Math.Clamp(amount, 0, 0xFFFF));
}
}
}
diff --git a/Projects/Server/Persistence/SequentialFileWriterStream.cs b/Projects/Server/Persistence/SequentialFileWriterStream.cs
index ade81f0a1..bb48d5ab3 100644
--- a/Projects/Server/Persistence/SequentialFileWriterStream.cs
+++ b/Projects/Server/Persistence/SequentialFileWriterStream.cs
@@ -37,7 +37,7 @@ namespace Server
fileStream = FileOperations.OpenSequentialStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
fileQueue = new FileQueue(
- Math.Max(1, FileOperations.Concurrency),
+ Math.Max(FileOperations.Concurrency, 1),
FileCallback);
}
diff --git a/Projects/Server/Regions/RegionLoader.cs b/Projects/Server/Regions/RegionLoader.cs
index 0ab7aa7d6..4626988ad 100644
--- a/Projects/Server/Regions/RegionLoader.cs
+++ b/Projects/Server/Regions/RegionLoader.cs
@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
-using System.Text.Json;
using Server.Json;
using Server.Utilities;
diff --git a/Projects/Server/Skills.cs b/Projects/Server/Skills.cs
index 805709594..b19dbde6f 100644
--- a/Projects/Server/Skills.cs
+++ b/Projects/Server/Skills.cs
@@ -183,12 +183,7 @@ namespace Server
get => m_Base;
set
{
- if (value < 0)
- value = 0;
- else if (value >= 0x10000)
- value = 0xFFFF;
-
- var sv = (ushort)value;
+ var sv = (ushort)Math.Clamp(value, 0, 0xFFFF);
int oldBase = m_Base;
@@ -219,12 +214,7 @@ namespace Server
get => m_Cap;
set
{
- if (value < 0)
- value = 0;
- else if (value >= 0x10000)
- value = 0xFFFF;
-
- var sv = (ushort)value;
+ var sv = (ushort)Math.Clamp(value, 0, 0xFFFF);
if (m_Cap != sv)
{
diff --git a/Projects/Server/TileData.cs b/Projects/Server/TileData.cs
index 9b2a467eb..199c6e059 100644
--- a/Projects/Server/TileData.cs
+++ b/Projects/Server/TileData.cs
@@ -20,7 +20,6 @@
using System;
using System.IO;
-using System.Linq;
using System.Text;
namespace Server
diff --git a/Projects/Server/Timer.cs b/Projects/Server/Timer/Timer.cs
similarity index 76%
rename from Projects/Server/Timer.cs
rename to Projects/Server/Timer/Timer.cs
index a76a1327c..5bc2fd697 100644
--- a/Projects/Server/Timer.cs
+++ b/Projects/Server/Timer/Timer.cs
@@ -39,11 +39,7 @@ namespace Server
OneMinute
}
- public delegate void TimerCallback();
-
- public delegate void TimerStateCallback(T state);
-
- public class Timer
+ public partial class Timer
{
private static readonly Queue m_Queue = new Queue();
@@ -464,90 +460,6 @@ namespace Server
}
}
- public static Timer DelayCall(TimerCallback callback) => DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback);
-
- public static Timer DelayCall(TimeSpan delay, TimerCallback callback) => DelayCall(delay, TimeSpan.Zero, 1, callback);
-
- public static Timer DelayCall(TimeSpan delay, TimeSpan interval, TimerCallback callback) =>
- DelayCall(delay, interval, 0, callback);
-
- public static Timer DelayCall(TimeSpan delay, TimeSpan interval, int count, TimerCallback callback)
- {
- Timer t = new DelayCallTimer(delay, interval, count, callback);
-
- t.Priority = ComputePriority(count == 1 ? delay : interval);
- t.Start();
-
- return t;
- }
-
- public static Timer DelayCall(TimerStateCallback callback, T state) =>
- DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, state);
-
- public static Timer DelayCall(TimeSpan delay, TimerStateCallback callback, T state) =>
- DelayCall(delay, TimeSpan.Zero, 1, callback, state);
-
- public static Timer DelayCall(TimeSpan delay, TimeSpan interval, TimerStateCallback callback, T state) =>
- DelayCall(delay, interval, 0, callback, state);
-
- public static Timer DelayCall(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback,
- T state)
- {
- Timer t = new DelayStateCallTimer(delay, interval, count, callback, state);
-
- t.Priority = ComputePriority(count == 1 ? delay : interval);
-
- t.Start();
-
- return t;
- }
-
- private class DelayCallTimer : Timer
- {
- public DelayCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerCallback callback) : base(delay,
- interval, count)
- {
- Callback = callback;
- RegCreation();
- }
-
- public TimerCallback Callback { get; }
-
- public override bool DefRegCreation => false;
-
- protected override void OnTick()
- {
- Callback?.Invoke();
- }
-
- public override string ToString() => $"DelayCallTimer[{FormatDelegate(Callback)}]";
- }
-
- private class DelayStateCallTimer : Timer
- {
- private readonly T m_State;
-
- public DelayStateCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback, T state)
- : base(delay, interval, count)
- {
- Callback = callback;
- m_State = state;
-
- RegCreation();
- }
-
- public TimerStateCallback Callback { get; }
-
- public override bool DefRegCreation => false;
-
- protected override void OnTick()
- {
- Callback?.Invoke(m_State);
- }
-
- public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
- }
-
private class DelayTaskTimer : Timer
{
private readonly TaskCompletionSource m_TaskCompleter;
diff --git a/Projects/Server/Timer/TimerDelayCalls.cs b/Projects/Server/Timer/TimerDelayCalls.cs
new file mode 100644
index 000000000..bab5e1036
--- /dev/null
+++ b/Projects/Server/Timer/TimerDelayCalls.cs
@@ -0,0 +1,268 @@
+/*************************************************************************
+ * ModernUO *
+ * Copyright (C) 2019-2020 - ModernUO Development Team *
+ * Email: hi@modernuo.com *
+ * File: TimerDelayCalls.cs - Created: 2020/07/31 - Updated: 2020/07/31 *
+ * *
+ * This program is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see . *
+ *************************************************************************/
+
+using System;
+
+namespace Server
+{
+ public delegate void TimerCallback();
+ public delegate void TimerStateCallback(T state);
+ public delegate void TimerStateCallback(T1 t1, T2 t2);
+ public delegate void TimerStateCallback(T1 t1, T2 t2, T3 t3);
+ public delegate void TimerStateCallback(T1 t1, T2 t2, T3 t3, T4 t4);
+
+ public partial class Timer
+ {
+ public static Timer DelayCall(TimerCallback callback) => DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback);
+
+ public static Timer DelayCall(TimeSpan delay, TimerCallback callback) => DelayCall(delay, TimeSpan.Zero, 1, callback);
+
+ public static Timer DelayCall(TimeSpan delay, TimeSpan interval, TimerCallback callback) =>
+ DelayCall(delay, interval, 0, callback);
+
+ public static Timer DelayCall(TimeSpan delay, TimeSpan interval, int count, TimerCallback callback)
+ {
+ Timer t = new DelayCallTimer(delay, interval, count, callback);
+
+ t.Priority = ComputePriority(count == 1 ? delay : interval);
+ t.Start();
+
+ return t;
+ }
+
+ private class DelayCallTimer : Timer
+ {
+ public DelayCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerCallback callback) : base(delay,
+ interval, count)
+ {
+ Callback = callback;
+ RegCreation();
+ }
+
+ public TimerCallback Callback { get; }
+
+ public override bool DefRegCreation => false;
+
+ protected override void OnTick()
+ {
+ Callback?.Invoke();
+ }
+
+ public override string ToString() => $"DelayCallTimer[{FormatDelegate(Callback)}]";
+ }
+
+ public static Timer DelayCall(TimerStateCallback callback, T state) =>
+ DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, state);
+
+ public static Timer DelayCall(TimeSpan delay, TimerStateCallback callback, T state) =>
+ DelayCall(delay, TimeSpan.Zero, 1, callback, state);
+
+ public static Timer DelayCall(TimeSpan delay, TimeSpan interval, TimerStateCallback callback, T state) =>
+ DelayCall(delay, interval, 0, callback, state);
+
+ public static Timer DelayCall(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback,
+ T state)
+ {
+ Timer t = new DelayStateCallTimer(delay, interval, count, callback, state);
+
+ t.Priority = ComputePriority(count == 1 ? delay : interval);
+
+ t.Start();
+
+ return t;
+ }
+
+ private class DelayStateCallTimer : Timer
+ {
+ private readonly T m_State;
+
+ public DelayStateCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback, T state)
+ : base(delay, interval, count)
+ {
+ Callback = callback;
+ m_State = state;
+
+ RegCreation();
+ }
+
+ public TimerStateCallback Callback { get; }
+
+ public override bool DefRegCreation => false;
+
+ protected override void OnTick()
+ {
+ Callback?.Invoke(m_State);
+ }
+
+ public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
+ }
+
+ public static Timer DelayCall(TimerStateCallback callback, T1 t1, T2 t2) =>
+ DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, t1, t2);
+
+ public static Timer DelayCall(TimeSpan delay, TimerStateCallback callback, T1 t1, T2 t2) =>
+ DelayCall(delay, TimeSpan.Zero, 1, callback, t1, t2);
+
+ public static Timer DelayCall(TimeSpan delay, TimeSpan interval, TimerStateCallback callback,
+ T1 t1, T2 t2) => DelayCall(delay, interval, 0, callback, t1, t2);
+
+ public static Timer DelayCall(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback,
+ T1 t1, T2 t2)
+ {
+ Timer t = new DelayStateCallTimer(delay, interval, count, callback, t1, t2);
+
+ t.Priority = ComputePriority(count == 1 ? delay : interval);
+
+ t.Start();
+
+ return t;
+ }
+
+ private class DelayStateCallTimer : Timer
+ {
+ private readonly T1 m_T1;
+ private readonly T2 m_T2;
+
+ public DelayStateCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback,
+ T1 t1, T2 t2) : base(delay, interval, count)
+ {
+ Callback = callback;
+ m_T1 = t1;
+ m_T2 = t2;
+
+ RegCreation();
+ }
+
+ public TimerStateCallback Callback { get; }
+
+ public override bool DefRegCreation => false;
+
+ protected override void OnTick()
+ {
+ Callback?.Invoke(m_T1, m_T2);
+ }
+
+ public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
+ }
+
+ public static Timer DelayCall(TimerStateCallback callback, T1 t1, T2 t2, T3 t3) =>
+ DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, t1, t2, t3);
+
+ public static Timer DelayCall(TimeSpan delay, TimerStateCallback callback, T1 t1, T2 t2, T3 t3) =>
+ DelayCall(delay, TimeSpan.Zero, 1, callback, t1, t2, t3);
+
+ public static Timer DelayCall(TimeSpan delay, TimeSpan interval, TimerStateCallback callback,
+ T1 t1, T2 t2, T3 t3) => DelayCall(delay, interval, 0, callback, t1, t2, t3);
+
+ public static Timer DelayCall(TimeSpan delay, TimeSpan interval, int count,
+ TimerStateCallback callback, T1 t1, T2 t2, T3 t3)
+ {
+ Timer t = new DelayStateCallTimer(delay, interval, count, callback, t1, t2, t3);
+
+ t.Priority = ComputePriority(count == 1 ? delay : interval);
+
+ t.Start();
+
+ return t;
+ }
+
+ private class DelayStateCallTimer : Timer
+ {
+ private readonly T1 m_T1;
+ private readonly T2 m_T2;
+ private readonly T3 m_T3;
+
+ public DelayStateCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback,
+ T1 t1, T2 t2, T3 t3) : base(delay, interval, count)
+ {
+ Callback = callback;
+ m_T1 = t1;
+ m_T2 = t2;
+ m_T3 = t3;
+
+ RegCreation();
+ }
+
+ public TimerStateCallback Callback { get; }
+
+ public override bool DefRegCreation => false;
+
+ protected override void OnTick()
+ {
+ Callback?.Invoke(m_T1, m_T2, m_T3);
+ }
+
+ public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
+ }
+
+ public static Timer DelayCall(TimerStateCallback callback, T1 t1, T2 t2, T3 t3, T4 t4) =>
+ DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, t1, t2, t3, t4);
+
+ public static Timer DelayCall(TimeSpan delay, TimerStateCallback callback,
+ T1 t1, T2 t2, T3 t3, T4 t4) => DelayCall(delay, TimeSpan.Zero, 1, callback, t1, t2, t3, t4);
+
+ public static Timer DelayCall(TimeSpan delay, TimeSpan interval,
+ TimerStateCallback callback, T1 t1, T2 t2, T3 t3, T4 t4) =>
+ DelayCall(delay, interval, 0, callback, t1, t2, t3, t4);
+
+ public static Timer DelayCall(TimeSpan delay, TimeSpan interval, int count,
+ TimerStateCallback callback, T1 t1, T2 t2, T3 t3, T4 t4)
+ {
+ Timer t = new DelayStateCallTimer(delay, interval, count, callback, t1, t2, t3, t4);
+
+ t.Priority = ComputePriority(count == 1 ? delay : interval);
+
+ t.Start();
+
+ return t;
+ }
+
+ private class DelayStateCallTimer : Timer
+ {
+ private readonly T1 m_T1;
+ private readonly T2 m_T2;
+ private readonly T3 m_T3;
+ private readonly T4 m_T4;
+
+ public DelayStateCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback,
+ T1 t1, T2 t2, T3 t3, T4 t4) : base(delay, interval, count)
+ {
+ Callback = callback;
+ m_T1 = t1;
+ m_T2 = t2;
+ m_T3 = t3;
+ m_T4 = t4;
+
+ RegCreation();
+ }
+
+ public TimerStateCallback Callback { get; }
+
+ public override bool DefRegCreation => false;
+
+ protected override void OnTick()
+ {
+ Callback?.Invoke(m_T1, m_T2, m_T3, m_T4);
+ }
+
+ public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
+ }
+ }
+}
diff --git a/Projects/Server/Utilities/ActivatorUtil.cs b/Projects/Server/Utilities/ActivatorUtil.cs
index 0e90346f7..958292f62 100644
--- a/Projects/Server/Utilities/ActivatorUtil.cs
+++ b/Projects/Server/Utilities/ActivatorUtil.cs
@@ -1,3 +1,23 @@
+/*************************************************************************
+ * ModernUO *
+ * Copyright (C) 2019-2020 - ModernUO Development Team *
+ * Email: hi@modernuo.com *
+ * File: ActivatorUtil.cs - Created: 2020/02/19 - Updated: 2020/07/30 *
+ * *
+ * This program is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see . *
+ *************************************************************************/
+
using System;
using System.Linq;
using System.Reflection;
diff --git a/Projects/Server/Utilities/RefPool.cs b/Projects/Server/Utilities/RefPool.cs
index b016bf4fc..2192a72c7 100644
--- a/Projects/Server/Utilities/RefPool.cs
+++ b/Projects/Server/Utilities/RefPool.cs
@@ -1,3 +1,23 @@
+/*************************************************************************
+ * ModernUO *
+ * Copyright (C) 2019-2020 - ModernUO Development Team *
+ * Email: hi@modernuo.com *
+ * File: RefPool.cs - Created: 2020/02/20 - Updated: 2020/07/30 *
+ * *
+ * This program is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see . *
+ *************************************************************************/
+
using System;
using System.Collections.Generic;
diff --git a/Projects/Server/Utilities/Utility.cs b/Projects/Server/Utilities/Utility.cs
index ab053528d..820fc0b56 100644
--- a/Projects/Server/Utilities/Utility.cs
+++ b/Projects/Server/Utilities/Utility.cs
@@ -493,19 +493,8 @@ namespace Server
return dy > 0 ? Direction.Left : Direction.Up;
}
- public static object GetArrayCap(Array array, int index, object emptyValue = null)
- {
- if (array.Length > 0)
- {
- if (index < 0)
- index = 0;
- else if (index >= array.Length) index = array.Length - 1;
-
- return array.GetValue(index);
- }
-
- return emptyValue;
- }
+ public static object GetArrayCap(Array array, int index, object emptyValue = null) =>
+ array.Length > 0 ? array.GetValue(Math.Clamp(index, 0, array.Length - 1)) : emptyValue;
public static SkillName RandomSkill() =>
m_AllSkills[Random(m_AllSkills.Length - (Core.ML ? 0 : Core.SE ? 1 : Core.AOS ? 3 : 6))];
@@ -1002,5 +991,12 @@ namespace Server
///
public static int RandomBrightHue() =>
RandomDouble() < 0.1 ? RandomList(0x62, 0x71) : RandomList(0x03, 0x0D, 0x13, 0x1C, 0x21, 0x30, 0x37, 0x3A, 0x44, 0x59);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static T Clamp(this T val, T min, T max) where T : IComparable =>
+ val.CompareTo(min) < 0 ? min : val.CompareTo(max) > 0 ? max : val;
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static TimeSpan Max(this TimeSpan val, TimeSpan max) => val > max ? max : val;
}
}
diff --git a/Projects/UOContent/Commands/Generic/Implementors/ContainedCommandImplementor.cs b/Projects/UOContent/Commands/Generic/Implementors/ContainedCommandImplementor.cs
index 320957e61..3151ee273 100644
--- a/Projects/UOContent/Commands/Generic/Implementors/ContainedCommandImplementor.cs
+++ b/Projects/UOContent/Commands/Generic/Implementors/ContainedCommandImplementor.cs
@@ -21,7 +21,7 @@ namespace Server.Commands.Generic
{
if (command.ValidateArgs(this, new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args)))
from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None,
- (m, targeted) => OnTarget(m, targeted, command, args));
+ (m, targeted, a) => OnTarget(m, targeted, command, a), args);
}
public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args)
@@ -70,4 +70,4 @@ namespace Server.Commands.Generic
}
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Commands/Generic/Implementors/MultiCommandImplementor.cs b/Projects/UOContent/Commands/Generic/Implementors/MultiCommandImplementor.cs
index bfe99f577..67db03b2b 100644
--- a/Projects/UOContent/Commands/Generic/Implementors/MultiCommandImplementor.cs
+++ b/Projects/UOContent/Commands/Generic/Implementors/MultiCommandImplementor.cs
@@ -17,7 +17,7 @@ namespace Server.Commands.Generic
{
if (command.ValidateArgs(this, new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args)))
from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None,
- (m, targeted) => OnTarget(m, targeted, command, args));
+ (m, targeted, a) => OnTarget(m, targeted, command, a), args);
}
public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args)
@@ -26,7 +26,7 @@ namespace Server.Commands.Generic
{
from.SendLocalizedMessage(500447); // That is not accessible.
from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None,
- (m, t) => OnTarget(m, t, command, args));
+ (m, t, a) => OnTarget(m, t, command, a), args);
return;
}
@@ -67,7 +67,7 @@ namespace Server.Commands.Generic
RunCommand(from, targeted, command, args);
from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None,
- (m, t) => OnTarget(m, t, command, args));
+ (m, t, a) => OnTarget(m, t, command, a), args);
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Commands/Generic/Implementors/SingleCommandImplementor.cs b/Projects/UOContent/Commands/Generic/Implementors/SingleCommandImplementor.cs
index a68146727..b07a573c5 100644
--- a/Projects/UOContent/Commands/Generic/Implementors/SingleCommandImplementor.cs
+++ b/Projects/UOContent/Commands/Generic/Implementors/SingleCommandImplementor.cs
@@ -38,7 +38,7 @@ namespace Server.Commands.Generic
{
if (command.ValidateArgs(this, new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args)))
from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None,
- (m, targeted) => OnTarget(m, targeted, command, args));
+ (m, targeted, a) => OnTarget(m, targeted, command, a), args);
}
public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args)
@@ -86,4 +86,4 @@ namespace Server.Commands.Generic
RunCommand(from, targeted, command, args);
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Commands/Object Creation/CategorizedAddGump.cs b/Projects/UOContent/Commands/Object Creation/CategorizedAddGump.cs
index ef0448c61..93a9c199c 100644
--- a/Projects/UOContent/Commands/Object Creation/CategorizedAddGump.cs
+++ b/Projects/UOContent/Commands/Object Creation/CategorizedAddGump.cs
@@ -91,12 +91,7 @@ namespace Server.Gumps
CAGNode[] nodes = m_Category.Nodes;
- int count = nodes.Length - page * EntryCount;
-
- if (count < 0)
- count = 0;
- else if (count > EntryCount)
- count = EntryCount;
+ int count = Math.Clamp(nodes.Length - page * EntryCount, 0, EntryCount);
int totalHeight = OffsetSize + (EntryHeight + OffsetSize) * (count + 1);
diff --git a/Projects/UOContent/Commands/Properties.cs b/Projects/UOContent/Commands/Properties.cs
index 377428cc8..fd17c1077 100644
--- a/Projects/UOContent/Commands/Properties.cs
+++ b/Projects/UOContent/Commands/Properties.cs
@@ -196,7 +196,7 @@ namespace Server.Commands
}
}
- return chain[chain.Length - 1];
+ return chain[^1];
}
public static string GetValue(Mobile from, object o, string name)
@@ -328,7 +328,7 @@ namespace Server.Commands
concat[i * 2 + 1] = i < chain.Length - 1 ? "." : " = ";
}
- concat[concat.Length - 1] = toString;
+ concat[^1] = toString;
return string.Concat(concat);
}
@@ -654,7 +654,7 @@ namespace Server
if (!IsBound)
throw new NotYetBoundException(this);
- return m_Chain[m_Chain.Length - 1].PropertyType;
+ return m_Chain[^1].PropertyType;
}
}
diff --git a/Projects/UOContent/Engines/BulkOrders/SmallBulkEntry.cs b/Projects/UOContent/Engines/BulkOrders/SmallBulkEntry.cs
index bf87b7997..e4194768e 100644
--- a/Projects/UOContent/Engines/BulkOrders/SmallBulkEntry.cs
+++ b/Projects/UOContent/Engines/BulkOrders/SmallBulkEntry.cs
@@ -68,7 +68,7 @@ namespace Server.Engines.BulkOrders
if (split.Length >= 2)
{
Type type = AssemblyHandler.FindFirstTypeForName(split[0]);
- int graphic = Utility.ToInt32(split[split.Length - 1]);
+ int graphic = Utility.ToInt32(split[^1]);
if (type != null && graphic > 0)
list.Add(new SmallBulkEntry(type, graphic < 0x4000 ? 1020000 + graphic : 1078872 + graphic, graphic));
diff --git a/Projects/UOContent/Engines/CannedEvil/ChampionSpawn.cs b/Projects/UOContent/Engines/CannedEvil/ChampionSpawn.cs
index c97411178..ae9a1c964 100644
--- a/Projects/UOContent/Engines/CannedEvil/ChampionSpawn.cs
+++ b/Projects/UOContent/Engines/CannedEvil/ChampionSpawn.cs
@@ -53,7 +53,7 @@ namespace Server.Engines.CannedEvil
m_DamageEntries = new Dictionary();
- Timer.DelayCall(TimeSpan.Zero, SetInitialSpawnArea);
+ Timer.DelayCall(SetInitialSpawnArea);
}
public ChampionSpawn(Serial serial) : base(serial)
@@ -1130,7 +1130,7 @@ namespace Server.Engines.CannedEvil
}
}
- Timer.DelayCall(TimeSpan.Zero, UpdateRegion);
+ Timer.DelayCall(UpdateRegion);
}
}
diff --git a/Projects/UOContent/Engines/ConPVP/Arena.cs b/Projects/UOContent/Engines/ConPVP/Arena.cs
index 7d1e510e4..d424b754f 100644
--- a/Projects/UOContent/Engines/ConPVP/Arena.cs
+++ b/Projects/UOContent/Engines/ConPVP/Arena.cs
@@ -271,7 +271,7 @@ namespace Server.Engines.ConPVP
Timer.DelayCall(TimeSpan.FromSeconds(2.0), Evict);
if (m_Tournament != null)
- Timer.DelayCall(TimeSpan.Zero, AttachToTournament_Sandbox);
+ Timer.DelayCall(AttachToTournament_Sandbox);
}
[CommandProperty(AccessLevel.GameMaster)]
@@ -345,21 +345,7 @@ namespace Server.Engines.ConPVP
set => m_Bounds = value;
}
- public int Spectators
- {
- get
- {
- if (m_Region == null)
- return 0;
-
- int specs = m_Region.GetPlayerCount() - Players.Count;
-
- if (specs < 0)
- specs = 0;
-
- return specs;
- }
- }
+ public int Spectators => m_Region == null ? 0 : Math.Max(m_Region.GetPlayerCount() - Players.Count, 0);
[CommandProperty(AccessLevel.GameMaster)]
public Rectangle2D Zone
@@ -476,22 +462,13 @@ namespace Server.Engines.ConPVP
public override string ToString() => "...";
- public Point3D GetBaseStartPoint(int index)
- {
- if (index < 0)
- index = 0;
-
- return Points.Points[index % Points.Points.Length];
- }
+ public Point3D GetBaseStartPoint(int index) => Points.Points[Math.Max(index, 0) % Points.Points.Length];
public void MoveInside(DuelPlayer[] players, int index)
{
- if (index < 0)
- index = 0;
- else
- index %= Points.Points.Length;
+ index = Math.Min(index, 0) % Points.Points.Length;
- Point3D start = GetBaseStartPoint(index);
+ Point3D start = Points.Points[index];
int offset = 0;
@@ -512,7 +489,7 @@ namespace Server.Engines.ConPVP
if (offset < offsets.Length)
p = offsets[offset++];
else
- p = offsets[offsets.Length - 1];
+ p = offsets[^1];
p.X = p.X * matrix[0, 0] + p.Y * matrix[0, 1];
p.Y = p.X * matrix[1, 0] + p.Y * matrix[1, 1];
diff --git a/Projects/UOContent/Engines/ConPVP/DuelContext.cs b/Projects/UOContent/Engines/ConPVP/DuelContext.cs
index 05a0d8840..7ffb10b62 100644
--- a/Projects/UOContent/Engines/ConPVP/DuelContext.cs
+++ b/Projects/UOContent/Engines/ConPVP/DuelContext.cs
@@ -114,7 +114,7 @@ namespace Server.Engines.ConPVP
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
{
- Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse));
+ Timer.DelayCall(ts, DelayBounce_Callback, mob, corpse);
}
public static bool AllowSpecialMove(Mobile from, string name, SpecialMove move) => (from as PlayerMobile)?.DuelContext?.InstAllowSpecialMove(from, name, move) != false;
diff --git a/Projects/UOContent/Engines/ConPVP/Games/BombingRun.cs b/Projects/UOContent/Engines/ConPVP/Games/BombingRun.cs
index 2d6834173..c4a17b45b 100644
--- a/Projects/UOContent/Engines/ConPVP/Games/BombingRun.cs
+++ b/Projects/UOContent/Engines/ConPVP/Games/BombingRun.cs
@@ -68,7 +68,7 @@ namespace Server.Engines.ConPVP
}
}
- Timer.DelayCall(TimeSpan.Zero, Delete).Start(); // delete this after the world loads
+ Timer.DelayCall(Delete); // delete this after the world loads
}
public override void Serialize(IGenericWriter writer)
@@ -202,7 +202,7 @@ namespace Server.Engines.ConPVP
m_Path.Clear();
m_PathIdx = 0;
- Timer.DelayCall(TimeSpan.FromSeconds(0.05), ContinueFlight).Start();
+ Timer.DelayCall(TimeSpan.FromSeconds(0.05), ContinueFlight);
}
private bool CheckCatch(Mobile m, Point3D myLoc)
@@ -292,7 +292,7 @@ namespace Server.Engines.ConPVP
if (list.Count > 0)
{
- Point3D p = list[list.Count - 1];
+ Point3D p = list[^1];
if (p.X != ix || p.Y != iy || p.Z != iz)
list.Add(new Point3D(ix, iy, iz));
@@ -307,7 +307,7 @@ namespace Server.Engines.ConPVP
z += zslp;
}
- if (list.Count > 0 && list[list.Count - 1] != dest)
+ if (list.Count > 0 && list[^1] != dest)
list.Add(dest);
/*if (dist3d > 4 && ( dest.X != org.X || dest.Y != org.Y ))
@@ -540,7 +540,7 @@ namespace Server.Engines.ConPVP
if (m_PathIdx > 0 && m_PathIdx - 1 < m_Path.Count)
DoAnim(GetWorldLocation(), m_Path[m_PathIdx - 1], Map);
- Timer.DelayCall(TimeSpan.FromSeconds(0.1), ContinueFlight).Start();
+ Timer.DelayCall(TimeSpan.FromSeconds(0.1), ContinueFlight);
}
else
{
@@ -734,7 +734,7 @@ namespace Server.Engines.ConPVP
// has to be delayed in case some other target canceled us...
if (m_Resend)
- Timer.DelayCall(TimeSpan.Zero, ResendBombTarget).Start();
+ Timer.DelayCall(ResendBombTarget);
}
private void ResendBombTarget()
@@ -1499,7 +1499,7 @@ namespace Server.Engines.ConPVP
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
{
- Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse));
+ Timer.DelayCall(ts, DelayBounce_Callback, mob, corpse);
}
private void DelayBounce_Callback(Mobile mob, Container corpse)
diff --git a/Projects/UOContent/Engines/ConPVP/Games/CTF.cs b/Projects/UOContent/Engines/ConPVP/Games/CTF.cs
index bbc8719a6..e3a981549 100644
--- a/Projects/UOContent/Engines/ConPVP/Games/CTF.cs
+++ b/Projects/UOContent/Engines/ConPVP/Games/CTF.cs
@@ -877,7 +877,7 @@ namespace Server.Engines.ConPVP
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
{
- Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse));
+ Timer.DelayCall(ts, DelayBounce_Callback, mob, corpse);
}
private void DelayBounce_Callback(Mobile mob, Container corpse)
diff --git a/Projects/UOContent/Engines/ConPVP/Games/DoubleDom.cs b/Projects/UOContent/Engines/ConPVP/Games/DoubleDom.cs
index 746d4243a..89322c54c 100644
--- a/Projects/UOContent/Engines/ConPVP/Games/DoubleDom.cs
+++ b/Projects/UOContent/Engines/ConPVP/Games/DoubleDom.cs
@@ -516,7 +516,7 @@ namespace Server.Engines.ConPVP
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
{
- Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse));
+ Timer.DelayCall(ts, DelayBounce_Callback, mob, corpse);
}
private void DelayBounce_Callback(Mobile mob, Container corpse)
@@ -846,7 +846,6 @@ namespace Server.Engines.ConPVP
{
m_CapStage = 0;
m_CaptureTimer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromSeconds(1.0), CaptureTick);
- m_CaptureTimer.Start();
}
}
diff --git a/Projects/UOContent/Engines/ConPVP/Games/KingOfTheHill.cs b/Projects/UOContent/Engines/ConPVP/Games/KingOfTheHill.cs
index cda7aff34..13da5ae87 100644
--- a/Projects/UOContent/Engines/ConPVP/Games/KingOfTheHill.cs
+++ b/Projects/UOContent/Engines/ConPVP/Games/KingOfTheHill.cs
@@ -883,7 +883,7 @@ namespace Server.Engines.ConPVP
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
{
- Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse));
+ Timer.DelayCall(ts, DelayBounce_Callback, mob, corpse);
}
private void DelayBounce_Callback(Mobile mob, Container corpse)
diff --git a/Projects/UOContent/Engines/ConPVP/Gumps/TournamentBracketGump.cs b/Projects/UOContent/Engines/ConPVP/Gumps/TournamentBracketGump.cs
index f1925ad97..e03a5b432 100644
--- a/Projects/UOContent/Engines/ConPVP/Gumps/TournamentBracketGump.cs
+++ b/Projects/UOContent/Engines/ConPVP/Gumps/TournamentBracketGump.cs
@@ -657,7 +657,7 @@ namespace Server.Engines.ConPVP
m_PerPage = perPage;
index = Math.Max(m_Page * perPage, 0);
- count = Math.Max(Math.Min(m_List.Count - index, perPage), 0);
+ count = Math.Clamp(m_List.Count - index, 0, perPage);
y = 53 + (12 - perPage) * 18;
diff --git a/Projects/UOContent/Engines/ConPVP/Participant.cs b/Projects/UOContent/Engines/ConPVP/Participant.cs
index 2f1acc018..e8058536c 100644
--- a/Projects/UOContent/Engines/ConPVP/Participant.cs
+++ b/Projects/UOContent/Engines/ConPVP/Participant.cs
@@ -173,7 +173,7 @@ namespace Server.Engines.ConPVP
}
Resize(Players.Length + 1);
- Players[Players.Length - 1] = new DuelPlayer(player, this);
+ Players[^1] = new DuelPlayer(player, this);
}
public void Resize(int count)
diff --git a/Projects/UOContent/Engines/ConPVP/Tournament.cs b/Projects/UOContent/Engines/ConPVP/Tournament.cs
index abf93fdae..f36a059d0 100644
--- a/Projects/UOContent/Engines/ConPVP/Tournament.cs
+++ b/Projects/UOContent/Engines/ConPVP/Tournament.cs
@@ -433,7 +433,7 @@ namespace Server.Engines.ConPVP
if (Pyramid.Levels.Count < 1)
break;
- PyramidLevel top = Pyramid.Levels[Pyramid.Levels.Count - 1];
+ PyramidLevel top = Pyramid.Levels[^1];
if (top.FreeAdvance != null || top.Matches.Count != 1)
break;
@@ -451,7 +451,7 @@ namespace Server.Engines.ConPVP
if (Pyramid.Levels.Count < 2)
break;
- PyramidLevel top = Pyramid.Levels[Pyramid.Levels.Count - 1];
+ PyramidLevel top = Pyramid.Levels[^1];
if (top.FreeAdvance != null || top.Matches.Count != 1)
break;
@@ -471,7 +471,7 @@ namespace Server.Engines.ConPVP
GiveAwards(part.Players, TrophyRank.Silver, cash / 2);
}
- PyramidLevel next = Pyramid.Levels[Pyramid.Levels.Count - 2];
+ PyramidLevel next = Pyramid.Levels[^2];
if (next.Matches.Count > 2)
break;
@@ -739,7 +739,7 @@ namespace Server.Engines.ConPVP
}
else if (Pyramid.Levels.Count > 0)
{
- PyramidLevel activeLevel = Pyramid.Levels[Pyramid.Levels.Count - 1];
+ PyramidLevel activeLevel = Pyramid.Levels[^1];
bool stillGoing = false;
for (int i = 0; i < activeLevel.Matches.Count; ++i)
diff --git a/Projects/UOContent/Engines/Craft/Core/CraftCollectionExtensions.cs b/Projects/UOContent/Engines/Craft/Core/CraftCollectionExtensions.cs
new file mode 100644
index 000000000..a1d4528d9
--- /dev/null
+++ b/Projects/UOContent/Engines/Craft/Core/CraftCollectionExtensions.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+
+namespace Server.Engines.Craft
+{
+ public static class CraftCollectionExtensions
+ {
+ public static int SearchFor(this List list, TextDefinition groupName)
+ {
+ for (int i = 0; i < list.Count; i++)
+ {
+ CraftGroup craftGroup = list[i];
+
+ int nameNumber = craftGroup.NameNumber;
+ string nameString = craftGroup.NameString;
+
+ if (nameNumber != 0 && nameNumber == groupName.Number ||
+ nameString != null && nameString == groupName.String)
+ return i;
+ }
+
+ return -1;
+ }
+
+ public static CraftItem SearchForSubclass(this List list, Type type)
+ {
+ for (int i = 0; i < list.Count; i++)
+ {
+ CraftItem craftItem = list[i];
+
+ if (craftItem.ItemType == type || type.IsSubclassOf(craftItem.ItemType))
+ return craftItem;
+ }
+
+ return null;
+ }
+
+ public static CraftItem SearchFor(this List list, Type type)
+ {
+ for (int i = 0; i < list.Count; i++)
+ {
+ CraftItem craftItem = list[i];
+ if (craftItem.ItemType == type) return craftItem;
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/Projects/UOContent/Engines/Craft/Core/CraftGroup.cs b/Projects/UOContent/Engines/Craft/Core/CraftGroup.cs
index 8072d0af7..b72e64525 100644
--- a/Projects/UOContent/Engines/Craft/Core/CraftGroup.cs
+++ b/Projects/UOContent/Engines/Craft/Core/CraftGroup.cs
@@ -1,3 +1,5 @@
+using System.Collections.Generic;
+
namespace Server.Engines.Craft
{
public class CraftGroup
@@ -6,10 +8,10 @@ namespace Server.Engines.Craft
{
NameNumber = groupName;
NameString = groupName;
- CraftItems = new CraftItemCol();
+ CraftItems = new List();
}
- public CraftItemCol CraftItems { get; }
+ public List CraftItems { get; }
public string NameString { get; }
@@ -20,4 +22,4 @@ namespace Server.Engines.Craft
CraftItems.Add(craftItem);
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Engines/Craft/Core/CraftGroupCol.cs b/Projects/UOContent/Engines/Craft/Core/CraftGroupCol.cs
deleted file mode 100644
index 9aa926c03..000000000
--- a/Projects/UOContent/Engines/Craft/Core/CraftGroupCol.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System.Collections;
-
-namespace Server.Engines.Craft
-{
- public class CraftGroupCol : CollectionBase
- {
- public int Add(CraftGroup craftGroup) => List.Add(craftGroup);
-
- public void Remove(int index)
- {
- if (index > Count - 1 || index < 0)
- {
- }
- else
- {
- List.RemoveAt(index);
- }
- }
-
- public CraftGroup GetAt(int index) => (CraftGroup)List[index];
-
- public int SearchFor(TextDefinition groupName)
- {
- for (int i = 0; i < List.Count; i++)
- {
- CraftGroup craftGroup = (CraftGroup)List[i];
-
- int nameNumber = craftGroup.NameNumber;
- string nameString = craftGroup.NameString;
-
- if ((nameNumber != 0 && nameNumber == groupName.Number) ||
- (nameString != null && nameString == groupName.String))
- return i;
- }
-
- return -1;
- }
- }
-}
\ No newline at end of file
diff --git a/Projects/UOContent/Engines/Craft/Core/CraftGump.cs b/Projects/UOContent/Engines/Craft/Core/CraftGump.cs
index 0abf2595e..d11c700b5 100644
--- a/Projects/UOContent/Engines/Craft/Core/CraftGump.cs
+++ b/Projects/UOContent/Engines/Craft/Core/CraftGump.cs
@@ -186,7 +186,7 @@ namespace Server.Engines.Craft
{
int index = i % 10;
- CraftSubRes subResource = res.GetAt(i);
+ CraftSubRes subResource = res[i];
if (index == 0)
{
@@ -279,15 +279,14 @@ namespace Server.Engines.Craft
return;
}
- CraftGroupCol craftGroupCol = m_CraftSystem.CraftGroups;
- CraftGroup craftGroup = craftGroupCol.GetAt(selectedGroup);
- CraftItemCol craftItemCol = craftGroup.CraftItems;
+ CraftGroup craftGroup = m_CraftSystem.CraftGroups[selectedGroup];
+ List craftItemCol = craftGroup.CraftItems;
for (int i = 0; i < craftItemCol.Count; ++i)
{
int index = i % 10;
- CraftItem craftItem = craftItemCol.GetAt(i);
+ CraftItem craftItem = craftItemCol[i];
if (index == 0)
{
@@ -319,14 +318,14 @@ namespace Server.Engines.Craft
public int CreateGroupList()
{
- CraftGroupCol craftGroupCol = m_CraftSystem.CraftGroups;
+ List craftGroupCol = m_CraftSystem.CraftGroups;
AddButton(15, 60, 4005, 4007, GetButtonID(6, 3));
AddHtmlLocalized(50, 63, 150, 18, 1044014, LabelColor); // LAST TEN
for (int i = 0; i < craftGroupCol.Count; i++)
{
- CraftGroup craftGroup = craftGroupCol.GetAt(i);
+ CraftGroup craftGroup = craftGroupCol[i];
AddButton(15, 80 + i * 20, 4005, 4007, GetButtonID(0, i));
@@ -378,7 +377,7 @@ namespace Server.Engines.Craft
int index = buttonID / 7;
CraftSystem system = m_CraftSystem;
- CraftGroupCol groups = system.CraftGroups;
+ List groups = system.CraftGroups;
CraftContext context = system.GetContext(m_From);
switch (type)
@@ -405,10 +404,10 @@ namespace Server.Engines.Craft
if (groupIndex >= 0 && groupIndex < groups.Count)
{
- CraftGroup group = groups.GetAt(groupIndex);
+ CraftGroup group = groups[groupIndex];
if (index >= 0 && index < group.CraftItems.Count)
- CraftItem(group.CraftItems.GetAt(index));
+ CraftItem(group.CraftItems[index]);
}
break;
@@ -422,10 +421,10 @@ namespace Server.Engines.Craft
if (groupIndex >= 0 && groupIndex < groups.Count)
{
- CraftGroup group = groups.GetAt(groupIndex);
+ CraftGroup group = groups[groupIndex];
if (index >= 0 && index < group.CraftItems.Count)
- m_From.SendGump(new CraftGumpItem(m_From, system, group.CraftItems.GetAt(index), m_Tool));
+ m_From.SendGump(new CraftGumpItem(m_From, system, group.CraftItems[index], m_Tool));
}
break;
diff --git a/Projects/UOContent/Engines/Craft/Core/CraftGumpItem.cs b/Projects/UOContent/Engines/Craft/Core/CraftGumpItem.cs
index eed593b97..24bc36be7 100644
--- a/Projects/UOContent/Engines/Craft/Core/CraftGumpItem.cs
+++ b/Projects/UOContent/Engines/Craft/Core/CraftGumpItem.cs
@@ -136,7 +136,7 @@ namespace Server.Engines.Craft
{
for (int i = 0; i < m_CraftItem.Skills.Count; i++)
{
- CraftSkill skill = m_CraftItem.Skills.GetAt(i);
+ CraftSkill skill = m_CraftItem.Skills[i];
double minSkill = skill.MinSkill;
if (minSkill < 0)
@@ -191,7 +191,7 @@ namespace Server.Engines.Craft
resIndex = m_CraftItem.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex;
bool cropScroll = m_CraftItem.Resources.Count > 1
- && m_CraftItem.Resources.GetAt(m_CraftItem.Resources.Count - 1).ItemType == typeofBlankScroll
+ && m_CraftItem.Resources[^1].ItemType == typeofBlankScroll
&& typeofSpellScroll.IsAssignableFrom(m_CraftItem.ItemType);
for (int i = 0; i < m_CraftItem.Resources.Count - (cropScroll ? 1 : 0) && i < 4; i++)
@@ -200,7 +200,7 @@ namespace Server.Engines.Craft
string nameString;
int nameNumber;
- CraftRes craftResource = m_CraftItem.Resources.GetAt(i);
+ CraftRes craftResource = m_CraftItem.Resources[i];
type = craftResource.ItemType;
nameString = craftResource.NameString;
diff --git a/Projects/UOContent/Engines/Craft/Core/CraftItem.cs b/Projects/UOContent/Engines/Craft/Core/CraftItem.cs
index 33f4ac895..dd9abae7e 100644
--- a/Projects/UOContent/Engines/Craft/Core/CraftItem.cs
+++ b/Projects/UOContent/Engines/Craft/Core/CraftItem.cs
@@ -32,8 +32,8 @@ namespace Server.Engines.Craft
public CraftItem(Type type, TextDefinition groupName, TextDefinition name)
{
- Resources = new CraftResCol();
- Skills = new CraftSkillCol();
+ Resources = new List();
+ Skills = new List();
ItemType = type;
@@ -82,9 +82,9 @@ namespace Server.Engines.Craft
public int NameNumber { get; }
- public CraftResCol Resources { get; }
+ public List Resources { get; }
- public CraftSkillCol Skills { get; }
+ public List Skills { get; }
public void AddRecipe(int id, CraftSystem system)
{
@@ -452,7 +452,7 @@ namespace Server.Engines.Craft
CraftRes res;
for (int i = 0; i < types.Length; ++i)
{
- CraftRes craftRes = Resources.GetAt(i);
+ CraftRes craftRes = Resources[i];
Type baseType = craftRes.ItemType;
// Resource Mutation
@@ -490,7 +490,7 @@ namespace Server.Engines.Craft
if (maxAmount == 0)
{
- res = Resources.GetAt(i);
+ res = Resources[i];
if (res.MessageNumber > 0)
message = res.MessageNumber;
@@ -599,7 +599,7 @@ namespace Server.Engines.Craft
return true;
}
- res = Resources.GetAt(index);
+ res = Resources[index];
if (res.MessageNumber > 0)
message = res.MessageNumber;
@@ -692,7 +692,7 @@ namespace Server.Engines.Craft
for (int i = 0; i < Skills.Count; i++)
{
- CraftSkill craftSkill = Skills.GetAt(i);
+ CraftSkill craftSkill = Skills[i];
double minSkill = craftSkill.MinSkill;
double maxSkill = craftSkill.MaxSkill;
diff --git a/Projects/UOContent/Engines/Craft/Core/CraftItemCol.cs b/Projects/UOContent/Engines/Craft/Core/CraftItemCol.cs
deleted file mode 100644
index a7149dcfc..000000000
--- a/Projects/UOContent/Engines/Craft/Core/CraftItemCol.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using System;
-using System.Collections;
-
-namespace Server.Engines.Craft
-{
- public class CraftItemCol : CollectionBase
- {
- public int Add(CraftItem craftItem) => List.Add(craftItem);
-
- public void Remove(int index)
- {
- if (index > Count - 1 || index < 0)
- {
- }
- else
- {
- List.RemoveAt(index);
- }
- }
-
- public CraftItem GetAt(int index) => (CraftItem)List[index];
-
- public CraftItem SearchForSubclass(Type type)
- {
- for (int i = 0; i < List.Count; i++)
- {
- CraftItem craftItem = (CraftItem)List[i];
-
- if (craftItem.ItemType == type || type.IsSubclassOf(craftItem.ItemType))
- return craftItem;
- }
-
- return null;
- }
-
- public CraftItem SearchFor(Type type)
- {
- for (int i = 0; i < List.Count; i++)
- {
- CraftItem craftItem = (CraftItem)List[i];
- if (craftItem.ItemType == type) return craftItem;
- }
-
- return null;
- }
- }
-}
\ No newline at end of file
diff --git a/Projects/UOContent/Engines/Craft/Core/CraftResCol.cs b/Projects/UOContent/Engines/Craft/Core/CraftResCol.cs
deleted file mode 100644
index 49a489b48..000000000
--- a/Projects/UOContent/Engines/Craft/Core/CraftResCol.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System.Collections;
-
-namespace Server.Engines.Craft
-{
- public class CraftResCol : CollectionBase
- {
- public void Add(CraftRes craftRes)
- {
- List.Add(craftRes);
- }
-
- public void Remove(int index)
- {
- if (index > Count - 1 || index < 0)
- {
- }
- else
- {
- List.RemoveAt(index);
- }
- }
-
- public CraftRes GetAt(int index) => (CraftRes)List[index];
- }
-}
\ No newline at end of file
diff --git a/Projects/UOContent/Engines/Craft/Core/CraftSkillCol.cs b/Projects/UOContent/Engines/Craft/Core/CraftSkillCol.cs
deleted file mode 100644
index 11d58ccd4..000000000
--- a/Projects/UOContent/Engines/Craft/Core/CraftSkillCol.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System.Collections;
-
-namespace Server.Engines.Craft
-{
- public class CraftSkillCol : CollectionBase
- {
- public void Add(CraftSkill craftSkill)
- {
- List.Add(craftSkill);
- }
-
- public void Remove(int index)
- {
- if (index > Count - 1 || index < 0)
- {
- }
- else
- {
- List.RemoveAt(index);
- }
- }
-
- public CraftSkill GetAt(int index) => (CraftSkill)List[index];
- }
-}
\ No newline at end of file
diff --git a/Projects/UOContent/Engines/Craft/Core/CraftSubResCol.cs b/Projects/UOContent/Engines/Craft/Core/CraftSubResCol.cs
index c499f6a31..535ba1655 100644
--- a/Projects/UOContent/Engines/Craft/Core/CraftSubResCol.cs
+++ b/Projects/UOContent/Engines/Craft/Core/CraftSubResCol.cs
@@ -1,9 +1,9 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
namespace Server.Engines.Craft
{
- public class CraftSubResCol : CollectionBase
+ public class CraftSubResCol : List
{
public CraftSubResCol() => Init = false;
@@ -15,33 +15,17 @@ namespace Server.Engines.Craft
public int NameNumber { get; set; }
- public void Add(CraftSubRes craftSubRes)
- {
- List.Add(craftSubRes);
- }
-
- public void Remove(int index)
- {
- if (index > Count - 1 || index < 0)
- {
- }
- else
- {
- List.RemoveAt(index);
- }
- }
-
- public CraftSubRes GetAt(int index) => (CraftSubRes)List[index];
+ public CraftSubRes GetAt(int index) => this[index];
public CraftSubRes SearchFor(Type type)
{
- for (int i = 0; i < List.Count; i++)
+ for (int i = 0; i < Count; i++)
{
- CraftSubRes craftSubRes = (CraftSubRes)List[i];
+ CraftSubRes craftSubRes = this[i];
if (craftSubRes.ItemType == type) return craftSubRes;
}
return null;
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Engines/Craft/Core/CraftSystem.cs b/Projects/UOContent/Engines/Craft/Core/CraftSystem.cs
index b4baf111d..18b94943f 100644
--- a/Projects/UOContent/Engines/Craft/Core/CraftSystem.cs
+++ b/Projects/UOContent/Engines/Craft/Core/CraftSystem.cs
@@ -23,8 +23,8 @@ namespace Server.Engines.Craft
MaxCraftEffect = maxCraftEffect;
Delay = delay;
- CraftItems = new CraftItemCol();
- CraftGroups = new CraftGroupCol();
+ CraftItems = new List();
+ CraftGroups = new List();
CraftSubRes = new CraftSubResCol();
CraftSubRes2 = new CraftSubResCol();
@@ -40,9 +40,9 @@ namespace Server.Engines.Craft
public double Delay { get; }
- public CraftItemCol CraftItems { get; }
+ public List CraftItems { get; }
- public CraftGroupCol CraftGroups { get; }
+ public List CraftGroups { get; }
public CraftSubResCol CraftSubRes { get; }
@@ -134,7 +134,8 @@ namespace Server.Engines.Craft
craftItem.AddSkill(skillToMake, minSkill, maxSkill);
DoGroup(group, craftItem);
- return CraftItems.Add(craftItem);
+ CraftItems.Add(craftItem);
+ return CraftItems.Count - 1;
}
private void DoGroup(TextDefinition groupName, CraftItem craftItem)
@@ -149,68 +150,58 @@ namespace Server.Engines.Craft
}
else
{
- CraftGroups.GetAt(index).AddCraftItem(craftItem);
+ CraftGroups[index].AddCraftItem(craftItem);
}
}
public void SetItemHue(int index, int hue)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.ItemHue = hue;
+ CraftItems[index].ItemHue = hue;
}
public void SetManaReq(int index, int mana)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.Mana = mana;
+ CraftItems[index].Mana = mana;
}
public void SetStamReq(int index, int stam)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.Stam = stam;
+ CraftItems[index].Stam = stam;
}
public void SetHitsReq(int index, int hits)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.Hits = hits;
+ CraftItems[index].Hits = hits;
}
public void SetUseAllRes(int index, bool useAll)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.UseAllRes = useAll;
+ CraftItems[index].UseAllRes = useAll;
}
public void SetNeedHeat(int index, bool needHeat)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.NeedHeat = needHeat;
+ CraftItems[index].NeedHeat = needHeat;
}
public void SetNeedOven(int index, bool needOven)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.NeedOven = needOven;
+ CraftItems[index].NeedOven = needOven;
}
public void SetBeverageType(int index, BeverageType requiredBeverage)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.RequiredBeverage = requiredBeverage;
+ CraftItems[index].RequiredBeverage = requiredBeverage;
}
public void SetNeedMill(int index, bool needMill)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.NeedMill = needMill;
+ CraftItems[index].NeedMill = needMill;
}
public void SetNeededExpansion(int index, Expansion expansion)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.RequiredExpansion = expansion;
+ CraftItems[index].RequiredExpansion = expansion;
}
public void AddRes(int index, Type type, TextDefinition name, int amount)
@@ -220,26 +211,22 @@ namespace Server.Engines.Craft
public void AddRes(int index, Type type, TextDefinition name, int amount, TextDefinition message)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.AddRes(type, name, amount, message);
+ CraftItems[index].AddRes(type, name, amount, message);
}
public void AddSkill(int index, SkillName skillToMake, double minSkill, double maxSkill)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.AddSkill(skillToMake, minSkill, maxSkill);
+ CraftItems[index].AddSkill(skillToMake, minSkill, maxSkill);
}
public void SetUseSubRes2(int index, bool val)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.UseSubRes2 = val;
+ CraftItems[index].UseSubRes2 = val;
}
private void AddRecipeBase(int index, int id)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.AddRecipe(id, this);
+ CraftItems[index].AddRecipe(id, this);
}
public void AddRecipe(int index, int id)
@@ -261,8 +248,7 @@ namespace Server.Engines.Craft
public void ForceNonExceptional(int index)
{
- CraftItem craftItem = CraftItems.GetAt(index);
- craftItem.ForceNonExceptional = true;
+ CraftItems[index].ForceNonExceptional = true;
}
public void SetSubRes(Type type, string name)
diff --git a/Projects/UOContent/Engines/Craft/Core/Recipes.cs b/Projects/UOContent/Engines/Craft/Core/Recipes.cs
index 7b226b28a..fe9154f40 100644
--- a/Projects/UOContent/Engines/Craft/Core/Recipes.cs
+++ b/Projects/UOContent/Engines/Craft/Core/Recipes.cs
@@ -54,11 +54,11 @@ namespace Server.Engines.Craft
foreach (KeyValuePair kvp in Recipes)
mobile.AcquireRecipe(kvp.Key);
- m.SendMessage("You teach them all of the recipes.");
+ from.SendMessage("You teach them all of the recipes.");
}
else
{
- m.SendMessage("That is not a player!");
+ from.SendMessage("That is not a player!");
}
});
}
@@ -70,17 +70,17 @@ namespace Server.Engines.Craft
Mobile m = e.Mobile;
m.SendMessage("Target a player to have them forget all of the recipes they've learned.");
- m.BeginTarget(-1, false, TargetFlags.None, delegate(Mobile from, object targeted)
+ m.BeginTarget(-1, false, TargetFlags.None, (from, targeted) =>
{
if (targeted is PlayerMobile mobile)
{
mobile.ResetRecipes();
- m.SendMessage("They forget all their recipes.");
+ from.SendMessage("They forget all their recipes.");
}
else
{
- m.SendMessage("That is not a player!");
+ from.SendMessage("That is not a player!");
}
});
}
diff --git a/Projects/UOContent/Engines/Craft/Core/Resmelt.cs b/Projects/UOContent/Engines/Craft/Core/Resmelt.cs
index fd9656894..9c88bb60c 100644
--- a/Projects/UOContent/Engines/Craft/Core/Resmelt.cs
+++ b/Projects/UOContent/Engines/Craft/Core/Resmelt.cs
@@ -13,7 +13,7 @@ namespace Server.Engines.Craft
NoSkill
}
- public class Resmelt
+ public static class Resmelt
{
public static void Do(Mobile from, CraftSystem craftSystem, BaseTool tool)
{
@@ -61,7 +61,7 @@ namespace Server.Engines.Craft
if (craftItem == null || craftItem.Resources.Count == 0)
return SmeltResult.Invalid;
- CraftRes craftResource = craftItem.Resources.GetAt(0);
+ CraftRes craftResource = craftItem.Resources[0];
if (craftResource.Amount < 2)
return SmeltResult.Invalid; // Not enough metal to resmelt
@@ -85,9 +85,9 @@ namespace Server.Engines.Craft
Type resourceType = info.ResourceTypes[0];
Item ingot = (Item)ActivatorUtil.CreateInstance(resourceType);
- if (item is DragonBardingDeed || (item is BaseArmor armor && armor.PlayerConstructed) ||
- (item is BaseWeapon weapon && weapon.PlayerConstructed) ||
- (item is BaseClothing clothing && clothing.PlayerConstructed))
+ if (item is DragonBardingDeed || item is BaseArmor armor && armor.PlayerConstructed ||
+ item is BaseWeapon weapon && weapon.PlayerConstructed ||
+ item is BaseClothing clothing && clothing.PlayerConstructed)
ingot.Amount = craftResource.Amount / 2;
else
ingot.Amount = 1;
@@ -144,7 +144,6 @@ namespace Server.Engines.Craft
else if (targeted is DragonBardingDeed deed)
{
result = Resmelt(from, deed, deed.Resource);
- isStoreBought = false;
}
message = result switch
diff --git a/Projects/UOContent/Engines/Craft/DefCooking.cs b/Projects/UOContent/Engines/Craft/DefCooking.cs
index b37f7d4af..d22978e5e 100644
--- a/Projects/UOContent/Engines/Craft/DefCooking.cs
+++ b/Projects/UOContent/Engines/Craft/DefCooking.cs
@@ -25,6 +25,7 @@ namespace Server.Engines.Craft
{
if (tool?.Deleted != false || tool.UsesRemaining < 0)
return 1044038; // You have worn out your tool!
+
if (!BaseTool.CheckAccessible(tool, from))
return 1044263; // The tool must be on your person to use.
diff --git a/Projects/UOContent/Engines/Craft/DefTailoring.cs b/Projects/UOContent/Engines/Craft/DefTailoring.cs
index 96c179143..433780791 100644
--- a/Projects/UOContent/Engines/Craft/DefTailoring.cs
+++ b/Projects/UOContent/Engines/Craft/DefTailoring.cs
@@ -33,6 +33,7 @@ namespace Server.Engines.Craft
{
if (tool?.Deleted != false || tool.UsesRemaining < 0)
return 1044038; // You have worn out your tool!
+
if (!BaseTool.CheckAccessible(tool, from))
return 1044263; // The tool must be on your person to use.
diff --git a/Projects/UOContent/Engines/Ethics/Core/Ethic.cs b/Projects/UOContent/Engines/Ethics/Core/Ethic.cs
index 50b0b5b4c..509f94737 100644
--- a/Projects/UOContent/Engines/Ethics/Core/Ethic.cs
+++ b/Projects/UOContent/Engines/Ethics/Core/Ethic.cs
@@ -1,4 +1,3 @@
-using System;
using System.Linq;
using Server.Ethics.Evil;
using Server.Ethics.Hero;
@@ -203,7 +202,7 @@ namespace Server.Ethics
Player pl = new Player(this, reader);
if (pl.Mobile != null)
- Timer.DelayCall(TimeSpan.Zero, pl.CheckAttach);
+ Timer.DelayCall(pl.CheckAttach);
}
break;
diff --git a/Projects/UOContent/Engines/Factions/Core/Election.cs b/Projects/UOContent/Engines/Factions/Core/Election.cs
index 69f8f7f3d..c4b5ce12c 100644
--- a/Projects/UOContent/Engines/Factions/Core/Election.cs
+++ b/Projects/UOContent/Engines/Factions/Core/Election.cs
@@ -423,12 +423,7 @@ namespace Server.Factions
int factorKillPts = 100 + kp * 2;
int factorGameTime = 50 + (int)(gameTime.Ticks * 100 / TimeSpan.TicksPerDay);
- int totalFactor = factorSkills * factorKillPts * Math.Max(factorGameTime, 100) / 10000;
-
- if (totalFactor > 100)
- totalFactor = 100;
- else if (totalFactor < 0)
- totalFactor = 0;
+ int totalFactor = Math.Clamp(factorSkills * factorKillPts * Math.Max(factorGameTime, 100) / 10000, 0, 100);
return new object[] { From, Address, Time, totalFactor };
}
diff --git a/Projects/UOContent/Engines/Factions/Core/Faction.cs b/Projects/UOContent/Engines/Factions/Core/Faction.cs
index 16607da6b..5e4d49ca9 100644
--- a/Projects/UOContent/Engines/Factions/Core/Faction.cs
+++ b/Projects/UOContent/Engines/Factions/Core/Faction.cs
@@ -1169,9 +1169,11 @@ namespace Server.Factions
}
}
- context.m_Timer = Timer.DelayCall(SkillLossPeriod, () => ClearSkillLoss(mob));
+ context.m_Timer = Timer.DelayCall(SkillLossPeriod, ClearSkillLoss_Event, mob);
}
+ private static void ClearSkillLoss_Event(Mobile mob) => ClearSkillLoss(mob);
+
public static bool ClearSkillLoss(Mobile mob)
{
if (!m_SkillLoss.TryGetValue(mob, out SkillLossContext context))
diff --git a/Projects/UOContent/Engines/Factions/Core/FactionState.cs b/Projects/UOContent/Engines/Factions/Core/FactionState.cs
index 5b430083f..875f16fef 100644
--- a/Projects/UOContent/Engines/Factions/Core/FactionState.cs
+++ b/Projects/UOContent/Engines/Factions/Core/FactionState.cs
@@ -112,7 +112,7 @@ namespace Server.Factions
{
FactionItem factionItem = new FactionItem(reader, m_Faction);
- Timer.DelayCall(TimeSpan.Zero, factionItem.CheckAttach); // sandbox attachment
+ Timer.DelayCall(factionItem.CheckAttach); // sandbox attachment
}
}
@@ -270,4 +270,4 @@ namespace Server.Factions
writer.Write(Traps[i]);
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Engines/Factions/Core/Keywords.cs b/Projects/UOContent/Engines/Factions/Core/Keywords.cs
index f988080d2..de0c9adf1 100644
--- a/Projects/UOContent/Engines/Factions/Core/Keywords.cs
+++ b/Projects/UOContent/Engines/Factions/Core/Keywords.cs
@@ -139,7 +139,7 @@ namespace Server.Factions
PlayerState pl = PlayerState.Find(from);
if (pl != null)
- Timer.DelayCall(TimeSpan.Zero, ShowScore_Sandbox, pl);
+ Timer.DelayCall(ShowScore_Sandbox, pl);
break;
}
diff --git a/Projects/UOContent/Engines/Factions/Items/Power Faction Items/StormsEye.cs b/Projects/UOContent/Engines/Factions/Items/Power Faction Items/StormsEye.cs
index 2e7f5acb5..6edc4149e 100644
--- a/Projects/UOContent/Engines/Factions/Items/Power Faction Items/StormsEye.cs
+++ b/Projects/UOContent/Engines/Factions/Items/Power Faction Items/StormsEye.cs
@@ -22,75 +22,78 @@ namespace Server
public override bool Use(Mobile user)
{
- if (Movable)
- user.BeginTarget(12, true, TargetFlags.None, (from, obj) =>
- {
- if (Movable && !Deleted)
- if (obj is IPoint3D pt)
- {
- SpellHelper.GetSurfaceTop(ref pt);
+ if (!Movable) return false;
- Point3D origin = new Point3D(pt);
- Map facet = from.Map;
+ user.BeginTarget(12, true, TargetFlags.None, (from, obj, stormsEye) =>
+ {
+ if (!stormsEye.Movable || stormsEye.Deleted || !(obj is IPoint3D pt)) return;
- if (facet?.CanFit(pt.X, pt.Y, pt.Z, 16, false, false) != true)
- return;
+ SpellHelper.GetSurfaceTop(ref pt);
- Movable = false;
+ Point3D origin = new Point3D(pt);
+ Map facet = from.Map;
- Effects.SendMovingEffect(
- from, new Entity(Serial.Zero, origin, facet),
- ItemID & 0x3FFF, 7, 0, false, false, Hue - 1);
+ if (facet?.CanFit(pt.X, pt.Y, pt.Z, 16, false, false) != true)
+ return;
- Timer.DelayCall(TimeSpan.FromSeconds(0.5), () =>
- {
- Delete();
+ stormsEye.Movable = false;
- Effects.PlaySound(origin, facet, 530);
- Effects.PlaySound(origin, facet, 263);
+ Effects.SendMovingEffect(
+ from, new Entity(Serial.Zero, origin, facet),
+ ItemID & 0x3FFF, 7, 0, false, false, Hue - 1);
- Effects.SendLocationEffect(
- origin, facet,
- 14284, 96, 1, 0, 2);
-
- Timer.DelayCall(TimeSpan.FromSeconds(1.0), () =>
- {
- List targets = facet.GetMobilesInRange(origin, 12).Where(mob =>
- from.CanBeHarmful(mob, false) && mob.InLOS(new Point3D(origin, origin.Z + 1)) &&
- Faction.Find(mob) != null).ToList();
-
- foreach (Mobile mob in targets)
- {
- int damage = mob.Hits * 6 / 10;
-
- if (!mob.Player && damage < 10)
- damage = 10;
- else if (damage > 75)
- damage = 75;
-
- Effects.SendMovingEffect(
- new Entity(Serial.Zero, new Point3D(origin, origin.Z + 4), facet), mob,
- 14068, 1, 32, false, false, 1111, 2);
-
- from.DoHarmful(mob);
-
- SpellHelper.Damage(TimeSpan.FromSeconds(0.50), mob, from, damage / 3.0, 0, 0, 0, 0,
- 100);
- SpellHelper.Damage(TimeSpan.FromSeconds(0.70), mob, from, damage / 3.0, 0, 0, 0, 0,
- 100);
- SpellHelper.Damage(TimeSpan.FromSeconds(1.00), mob, from, damage / 3.0, 0, 0, 0, 0,
- 100);
-
- Timer.DelayCall(TimeSpan.FromSeconds(0.50), mob.PlaySound, 0x1FB);
- }
- });
- });
- }
- });
+ Timer.DelayCall(TimeSpan.FromSeconds(0.5), OnDelay, from, stormsEye, origin, facet);
+ }, this);
return false;
}
+ private static void OnDelay(Mobile from, StormsEye stormsEye, Point3D origin, Map facet)
+ {
+ stormsEye.Delete();
+
+ Effects.PlaySound(origin, facet, 530);
+ Effects.PlaySound(origin, facet, 263);
+
+ Effects.SendLocationEffect(
+ origin, facet,
+ 14284, 96, 1, 0, 2);
+
+ Timer.DelayCall(TimeSpan.FromSeconds(1.0), OnHit, from, origin, facet);
+ }
+
+ private static void OnHit(Mobile from, Point3D origin, Map facet)
+ {
+ List targets = facet.GetMobilesInRange(origin, 12).Where(mob =>
+ from.CanBeHarmful(mob, false) && mob.InLOS(new Point3D(origin, origin.Z + 1)) &&
+ Faction.Find(mob) != null).ToList();
+
+ foreach (Mobile mob in targets)
+ {
+ int damage = mob.Hits * 6 / 10;
+
+ if (!mob.Player && damage < 10)
+ damage = 10;
+ else if (damage > 75)
+ damage = 75;
+
+ Effects.SendMovingEffect(
+ new Entity(Serial.Zero, new Point3D(origin, origin.Z + 4), facet), mob,
+ 14068, 1, 32, false, false, 1111, 2);
+
+ from.DoHarmful(mob);
+
+ SpellHelper.Damage(TimeSpan.FromSeconds(0.50), mob, from, damage / 3.0, 0, 0, 0, 0,
+ 100);
+ SpellHelper.Damage(TimeSpan.FromSeconds(0.70), mob, from, damage / 3.0, 0, 0, 0, 0,
+ 100);
+ SpellHelper.Damage(TimeSpan.FromSeconds(1.00), mob, from, damage / 3.0, 0, 0, 0, 0,
+ 100);
+
+ Timer.DelayCall(TimeSpan.FromSeconds(0.50), mob.PlaySound, 0x1FB);
+ }
+ }
+
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
diff --git a/Projects/UOContent/Engines/Factions/Items/Traps/BaseFactionTrap.cs b/Projects/UOContent/Engines/Factions/Items/Traps/BaseFactionTrap.cs
index bc52ffc65..e02c9fcd0 100644
--- a/Projects/UOContent/Engines/Factions/Items/Traps/BaseFactionTrap.cs
+++ b/Projects/UOContent/Engines/Factions/Items/Traps/BaseFactionTrap.cs
@@ -177,7 +177,7 @@ namespace Server.Factions
if (TimeOfPlacement + decayPeriod < DateTime.UtcNow)
{
- Timer.DelayCall(TimeSpan.Zero, Delete);
+ Timer.DelayCall(Delete);
return true;
}
diff --git a/Projects/UOContent/Engines/Factions/Mobiles/Guards/BaseFactionGuard.cs b/Projects/UOContent/Engines/Factions/Mobiles/Guards/BaseFactionGuard.cs
index 670f5b758..12c611ad8 100644
--- a/Projects/UOContent/Engines/Factions/Mobiles/Guards/BaseFactionGuard.cs
+++ b/Projects/UOContent/Engines/Factions/Mobiles/Guards/BaseFactionGuard.cs
@@ -437,7 +437,7 @@ namespace Server.Factions
m_Town = Town.ReadReference(reader);
Orders = new Orders(this, reader);
- Timer.DelayCall(TimeSpan.Zero, Register);
+ Timer.DelayCall(Register);
}
}
diff --git a/Projects/UOContent/Engines/Khaldun/RaiseSwitch.cs b/Projects/UOContent/Engines/Khaldun/RaiseSwitch.cs
index cf80c5346..cb623fd7b 100644
--- a/Projects/UOContent/Engines/Khaldun/RaiseSwitch.cs
+++ b/Projects/UOContent/Engines/Khaldun/RaiseSwitch.cs
@@ -193,7 +193,7 @@ namespace Server.Items
int version = reader.ReadEncodedInt();
- Timer.DelayCall(TimeSpan.Zero, Refresh);
+ Timer.DelayCall(Refresh);
}
}
}
diff --git a/Projects/UOContent/Engines/Quests/Core/Items/HornOfRetreat.cs b/Projects/UOContent/Engines/Quests/Core/Items/HornOfRetreat.cs
index 27fd4a136..ce7b74f80 100644
--- a/Projects/UOContent/Engines/Quests/Core/Items/HornOfRetreat.cs
+++ b/Projects/UOContent/Engines/Quests/Core/Items/HornOfRetreat.cs
@@ -74,7 +74,7 @@ namespace Server.Engines.Quests
--Charges;
- m_PlayTimer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), () => PlayTimer_Callback(from));
+ m_PlayTimer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), PlayTimer_Callback, from);
}
else
{
@@ -189,4 +189,4 @@ namespace Server.Engines.Quests
Delete();
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Engines/Quests/Core/QuestSystem.cs b/Projects/UOContent/Engines/Quests/Core/QuestSystem.cs
index 4692a0141..3b45a6215 100644
--- a/Projects/UOContent/Engines/Quests/Core/QuestSystem.cs
+++ b/Projects/UOContent/Engines/Quests/Core/QuestSystem.cs
@@ -259,7 +259,7 @@ namespace Server.Engines.Quests
From.SendGump(new QuestObjectivesGump(Objectives));
- QuestObjective last = Objectives[Objectives.Count - 1];
+ QuestObjective last = Objectives[^1];
if (last.Info != null)
From.SendGump(new QuestItemInfoGump(last.Info));
@@ -276,7 +276,7 @@ namespace Server.Engines.Quests
From.SendGump(new QuestConversationsGump(Conversations));
- QuestConversation last = Conversations[Conversations.Count - 1];
+ QuestConversation last = Conversations[^1];
if (last.Info != null)
From.SendGump(new QuestItemInfoGump(last.Info));
diff --git a/Projects/UOContent/Engines/Quests/Haochi's Trials/Items/HaochisTreasureChest.cs b/Projects/UOContent/Engines/Quests/Haochi's Trials/Items/HaochisTreasureChest.cs
index 98ffd5d43..0892595ab 100644
--- a/Projects/UOContent/Engines/Quests/Haochi's Trials/Items/HaochisTreasureChest.cs
+++ b/Projects/UOContent/Engines/Quests/Haochi's Trials/Items/HaochisTreasureChest.cs
@@ -88,7 +88,7 @@ namespace Server.Engines.Quests.Samurai
int version = reader.ReadEncodedInt();
- Timer.DelayCall(TimeSpan.Zero, GenerateTreasure);
+ Timer.DelayCall(GenerateTreasure);
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Engines/Quests/The Summoning/Items/BellOfTheDead.cs b/Projects/UOContent/Engines/Quests/The Summoning/Items/BellOfTheDead.cs
index b461dc919..57f73a7bf 100644
--- a/Projects/UOContent/Engines/Quests/The Summoning/Items/BellOfTheDead.cs
+++ b/Projects/UOContent/Engines/Quests/The Summoning/Items/BellOfTheDead.cs
@@ -55,7 +55,7 @@ namespace Server.Engines.Quests.Doom
Effects.PlaySound(GetWorldLocation(), Map, 0x100);
- Timer.DelayCall(TimeSpan.FromSeconds(8.0), () => EndSummon(from));
+ Timer.DelayCall(TimeSpan.FromSeconds(8.0), EndSummon, from);
}
}
diff --git a/Projects/UOContent/Engines/Quests/Witch Apprentice/Objectives.cs b/Projects/UOContent/Engines/Quests/Witch Apprentice/Objectives.cs
index 487db2a85..602a99916 100644
--- a/Projects/UOContent/Engines/Quests/Witch Apprentice/Objectives.cs
+++ b/Projects/UOContent/Engines/Quests/Witch Apprentice/Objectives.cs
@@ -59,7 +59,7 @@ namespace Server.Engines.Quests.Hag
// * You see a strange imp stealing a scrap of paper from the bloodied corpse *
Corpse.SendLocalizedMessageTo(player, 1055049);
- Timer.DelayCall(TimeSpan.FromSeconds(3.0), () => DeleteImp(imp));
+ Timer.DelayCall(TimeSpan.FromSeconds(3.0), DeleteImp, imp);
}
private void DeleteImp(Mobile m)
@@ -212,7 +212,7 @@ namespace Server.Engines.Quests.Hag
imp.Direction = imp.GetDirectionTo(from);
- Timer.DelayCall(TimeSpan.FromSeconds(3.0), () => DeleteImp(imp));
+ Timer.DelayCall(TimeSpan.FromSeconds(3.0), DeleteImp, imp);
}
private void DeleteImp(object imp)
@@ -266,7 +266,7 @@ namespace Server.Engines.Quests.Hag
for (int i = 0; i < oldIngredients.Length; i++)
Ingredients[i] = oldIngredients[i];
- Ingredients[Ingredients.Length - 1] = IngredientInfo.RandomIngredient(oldIngredients);
+ Ingredients[^1] = IngredientInfo.RandomIngredient(oldIngredients);
}
else
{
@@ -324,7 +324,7 @@ namespace Server.Engines.Quests.Hag
public Ingredient[] Ingredients { get; private set; }
- public Ingredient Ingredient => Ingredients[Ingredients.Length - 1];
+ public Ingredient Ingredient => Ingredients[^1];
public int Step => Ingredients.Length;
public bool BlackheartMet { get; private set; }
diff --git a/Projects/UOContent/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs b/Projects/UOContent/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs
index c73f9eb56..e49b386a2 100644
--- a/Projects/UOContent/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs
+++ b/Projects/UOContent/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs
@@ -230,7 +230,7 @@ namespace Server.Mobiles
Frozen = true;
if (m_SculptedBy == null || Map == Map.Internal) // Remove preview statues
- Timer.DelayCall(TimeSpan.Zero, Delete);
+ Timer.DelayCall(Delete);
}
public void Sculpt(Mobile by)
diff --git a/Projects/UOContent/Engines/VeteranRewards/Character Statue Maker/CharacterStatuePlinth.cs b/Projects/UOContent/Engines/VeteranRewards/Character Statue Maker/CharacterStatuePlinth.cs
index d5956047d..408eb24af 100644
--- a/Projects/UOContent/Engines/VeteranRewards/Character Statue Maker/CharacterStatuePlinth.cs
+++ b/Projects/UOContent/Engines/VeteranRewards/Character Statue Maker/CharacterStatuePlinth.cs
@@ -1,4 +1,3 @@
-using System;
using Server.Gumps;
using Server.Mobiles;
using Server.Multis;
@@ -86,7 +85,8 @@ namespace Server.Items
m_Statue = reader.ReadMobile() as CharacterStatue;
- if (m_Statue?.SculptedBy == null || Map == Map.Internal) Timer.DelayCall(TimeSpan.Zero, Delete);
+ if (m_Statue?.SculptedBy == null || Map == Map.Internal)
+ Timer.DelayCall(Delete);
}
public void InvalidateHue()
diff --git a/Projects/UOContent/Gumps/Go/GoGump.cs b/Projects/UOContent/Gumps/Go/GoGump.cs
index 17a233ffa..9cdab1ad4 100644
--- a/Projects/UOContent/Gumps/Go/GoGump.cs
+++ b/Projects/UOContent/Gumps/Go/GoGump.cs
@@ -1,3 +1,4 @@
+using System;
using Server.Network;
namespace Server.Gumps
@@ -107,12 +108,7 @@ namespace Server.Gumps
int x = BorderSize + OffsetSize;
int y = BorderSize + OffsetSize;
- int count = node.Categories.Length + node.Locations.Length - page * EntryCount;
-
- if (count < 0)
- count = 0;
- else if (count > EntryCount)
- count = EntryCount;
+ int count = Math.Clamp(node.Categories.Length + node.Locations.Length - page * EntryCount, 0, EntryCount);
int totalHeight = OffsetSize + (EntryHeight + OffsetSize) * (count + 1);
diff --git a/Projects/UOContent/Gumps/Guilds/New Guild System/BaseGuildListGump.cs b/Projects/UOContent/Gumps/Guilds/New Guild System/BaseGuildListGump.cs
index 5dd867fab..9da36e7ac 100644
--- a/Projects/UOContent/Gumps/Guilds/New Guild System/BaseGuildListGump.cs
+++ b/Projects/UOContent/Gumps/Guilds/New Guild System/BaseGuildListGump.cs
@@ -49,7 +49,7 @@ namespace Server.Guilds
}
m_List.Sort(m_Comparer);
- m_StartNumber = Math.Max(Math.Min(m_StartNumber, m_List.Count - 1), 0);
+ m_StartNumber = Math.Clamp(m_StartNumber, 0, m_List.Count - 1);
AddBackground(130, 75, 385, 30, 0xBB8);
AddTextEntry(135, 80, 375, 30, 0x481, 1, m_Filter);
diff --git a/Projects/UOContent/Gumps/Guilds/New Guild System/War Declaration gump.cs b/Projects/UOContent/Gumps/Guilds/New Guild System/War Declaration gump.cs
index f3798fa6b..de47fde2b 100644
--- a/Projects/UOContent/Gumps/Guilds/New Guild System/War Declaration gump.cs
+++ b/Projects/UOContent/Gumps/Guilds/New Guild System/War Declaration gump.cs
@@ -83,11 +83,9 @@ namespace Server.Guilds
TextRelay tWarLength = info.GetTextEntry(10);
int maxKills = tKills == null
- ? 0
- : Math.Max(Math.Min(Utility.ToInt32(info.GetTextEntry(11).Text), 0xFFFF), 0);
- TimeSpan warLength = TimeSpan.FromHours(tWarLength == null
- ? 0
- : Math.Max(Math.Min(Utility.ToInt32(info.GetTextEntry(10).Text), 0xFFFF), 0));
+ ? 0 : Math.Clamp(Utility.ToInt32(info.GetTextEntry(11).Text), 0, 0xFFFF);
+ TimeSpan warLength = TimeSpan.FromHours(tWarLength == null ? 0
+ : Math.Clamp(Utility.ToInt32(info.GetTextEntry(10).Text), 0, 0xFFFF));
if (war != null)
{
diff --git a/Projects/UOContent/Gumps/PolymorphGump.cs b/Projects/UOContent/Gumps/PolymorphGump.cs
index 600b5be08..77878f1f5 100644
--- a/Projects/UOContent/Gumps/PolymorphGump.cs
+++ b/Projects/UOContent/Gumps/PolymorphGump.cs
@@ -30,8 +30,8 @@ namespace Server.Gumps
ArtID = art;
BodyID = body;
LocNumber = locNum;
- this.X = x;
- this.Y = y;
+ X = x;
+ Y = y;
}
public int ArtID { get; }
diff --git a/Projects/UOContent/Gumps/Props/PropsGump.cs b/Projects/UOContent/Gumps/Props/PropsGump.cs
index b5ee03e01..571198e12 100644
--- a/Projects/UOContent/Gumps/Props/PropsGump.cs
+++ b/Projects/UOContent/Gumps/Props/PropsGump.cs
@@ -180,12 +180,7 @@ namespace Server.Gumps
{
m_Page = page;
- int count = m_List.Count - page * EntryCount;
-
- if (count < 0)
- count = 0;
- else if (count > EntryCount)
- count = EntryCount;
+ int count = Math.Clamp(m_List.Count - page * EntryCount, 0, EntryCount);
int lastIndex = page * EntryCount + count - 1;
diff --git a/Projects/UOContent/Gumps/ReportMurderer.cs b/Projects/UOContent/Gumps/ReportMurderer.cs
index 85790bcc7..7ce990677 100644
--- a/Projects/UOContent/Gumps/ReportMurderer.cs
+++ b/Projects/UOContent/Gumps/ReportMurderer.cs
@@ -144,7 +144,7 @@ namespace Server.Gumps
if (Core.SE)
{
from.RecentlyReported.Add(killer);
- Timer.DelayCall(TimeSpan.FromMinutes(10), () => ReportedListExpiry_Callback(from, killer));
+ Timer.DelayCall(TimeSpan.FromMinutes(10), ReportedListExpiry_Callback, from, killer);
}
if (killer is PlayerMobile pk)
diff --git a/Projects/UOContent/Holiday Stuff/Halloween/2009/Engines/PumpkinPatch.cs b/Projects/UOContent/Holiday Stuff/Halloween/2009/Engines/PumpkinPatch.cs
index ee0ebfc64..34c7a00c7 100644
--- a/Projects/UOContent/Holiday Stuff/Halloween/2009/Engines/PumpkinPatch.cs
+++ b/Projects/UOContent/Holiday Stuff/Halloween/2009/Engines/PumpkinPatch.cs
@@ -25,8 +25,8 @@ namespace Server.Engines.Events
{
DateTime now = DateTime.UtcNow;
- if (DateTime.UtcNow >= HolidaySettings.StartHalloween && DateTime.UtcNow <= HolidaySettings.FinishHalloween)
- m_Timer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromMinutes(.50), 0, PumpkinPatchSpawnerCallback);
+ if (now >= HolidaySettings.StartHalloween && now <= HolidaySettings.FinishHalloween)
+ m_Timer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromSeconds(30), 0, PumpkinPatchSpawnerCallback);
}
protected static void PumpkinPatchSpawnerCallback()
diff --git a/Projects/UOContent/Items/Addons/BaseAddonContainerDeed.cs b/Projects/UOContent/Items/Addons/BaseAddonContainerDeed.cs
index b0ac8d8c2..07147f378 100644
--- a/Projects/UOContent/Items/Addons/BaseAddonContainerDeed.cs
+++ b/Projects/UOContent/Items/Addons/BaseAddonContainerDeed.cs
@@ -44,7 +44,7 @@ namespace Server.Items
public virtual int OnCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes,
BaseTool tool, CraftItem craftItem, int resHue)
{
- Type resourceType = typeRes ?? craftItem.Resources.GetAt(0).ItemType;
+ Type resourceType = typeRes ?? craftItem.Resources[0].ItemType;
Resource = CraftResources.GetFromType(resourceType);
diff --git a/Projects/UOContent/Items/Addons/JackOLantern.cs b/Projects/UOContent/Items/Addons/JackOLantern.cs
index 422f068bf..6153398b2 100644
--- a/Projects/UOContent/Items/Addons/JackOLantern.cs
+++ b/Projects/UOContent/Items/Addons/JackOLantern.cs
@@ -1,5 +1,3 @@
-using System;
-
namespace Server.Items
{
public class JackOLantern : BaseAddon
@@ -15,18 +13,18 @@ namespace Server.Items
{
AddComponent(new AddonComponent(5703), 0, 0, +0);
- int hue = 1161;
+ const int hue = 1161;
// ( 1 > Utility.Random( 5 ) ? 2118 : 1161 );
if (!south)
{
- AddComponent(GetComponent(3178, 0000), 0, 0, -1);
+ AddComponent(GetComponent(3178, 0), 0, 0, -1);
AddComponent(GetComponent(3883, hue), 0, 0, +1);
AddComponent(GetComponent(3862, hue), 0, 0, +0);
}
else
{
- AddComponent(GetComponent(3179, 0000), 0, 0, +0);
+ AddComponent(GetComponent(3179, 0), 0, 0, +0);
AddComponent(GetComponent(3885, hue), 0, 0, -1);
AddComponent(GetComponent(3871, hue), 0, 0, +0);
}
@@ -39,15 +37,12 @@ namespace Server.Items
public override bool ShareHue => false;
- private AddonComponent GetComponent(int itemID, int hue)
- {
- AddonComponent ac = new AddonComponent(itemID);
-
- ac.Hue = hue;
- ac.Name = "jack-o-lantern";
-
- return ac;
- }
+ private static AddonComponent GetComponent(int itemID, int hue) =>
+ new AddonComponent(itemID)
+ {
+ Hue = hue,
+ Name = "jack-o-lantern"
+ };
public override void Serialize(IGenericWriter writer)
{
@@ -62,21 +57,31 @@ namespace Server.Items
int version = reader.ReadByte();
- if (version == 0)
- Timer.DelayCall(TimeSpan.Zero, () =>
- {
- for (int i = 0; i < Components.Count; ++i)
- if (Components[i] is AddonComponent ac && ac.Hue == 2118)
- ac.Hue = 1161;
- });
if (version <= 1)
- Timer.DelayCall(TimeSpan.Zero, () =>
+ Timer.DelayCall(Fix, version);
+ }
+
+ private void Fix(int version)
+ {
+ for (int i = 0; i < Components.Count; ++i)
+ {
+ var ac = Components[i];
+ switch (version)
{
- for (int i = 0; i < Components.Count; ++i)
- if (Components[i] is AddonComponent ac)
- ac.Name = "jack-o-lantern";
- });
+ case 1:
+ {
+ ac.Name = "jack-o-lantern";
+ goto case 0;
+ }
+ case 0:
+ {
+ if (ac.Hue == 2118)
+ ac.Hue = 1161;
+ break;
+ }
+ }
+ }
}
}
}
diff --git a/Projects/UOContent/Items/Addons/RejuvinationAnkhs.cs b/Projects/UOContent/Items/Addons/RejuvinationAnkhs.cs
index cd7d93738..1967eed95 100644
--- a/Projects/UOContent/Items/Addons/RejuvinationAnkhs.cs
+++ b/Projects/UOContent/Items/Addons/RejuvinationAnkhs.cs
@@ -38,7 +38,7 @@ namespace Server.Items
SendLocalizedMessageTo(from, 500803); // You feel as though you've slept for days!
}
- Timer.DelayCall(TimeSpan.FromHours(2.0), () => ReleaseUseLock_Callback(from, random));
+ Timer.DelayCall(TimeSpan.FromHours(2.0), ReleaseUseLock_Callback, from, random);
}
}
@@ -168,4 +168,4 @@ namespace Server.Items
int version = reader.ReadInt();
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Items/Aquarium/Aquarium.cs b/Projects/UOContent/Items/Aquarium/Aquarium.cs
index 4ee51b5c2..f0e8c9f97 100644
--- a/Projects/UOContent/Items/Aquarium/Aquarium.cs
+++ b/Projects/UOContent/Items/Aquarium/Aquarium.cs
@@ -633,7 +633,7 @@ namespace Server.Items
fish = new StrippedFlakeFish();
break;
}
- case 5:
+ default: // 5
{
message = 1074365; // A new creature has hatched overnight in the tank.
fish = new StrippedSosarianSwill();
diff --git a/Projects/UOContent/Items/Aquarium/AquariumState.cs b/Projects/UOContent/Items/Aquarium/AquariumState.cs
index aa0159ad1..5204d9d9a 100644
--- a/Projects/UOContent/Items/Aquarium/AquariumState.cs
+++ b/Projects/UOContent/Items/Aquarium/AquariumState.cs
@@ -1,3 +1,5 @@
+using System;
+
namespace Server.Items
{
public enum WaterState
@@ -27,16 +29,7 @@ namespace Server.Items
public int State
{
get => m_State;
- set
- {
- m_State = value;
-
- if (m_State < 0)
- m_State = 0;
-
- if (m_State > 4)
- m_State = 4;
- }
+ set => m_State = Math.Clamp(value, 0, 4);
}
[CommandProperty(AccessLevel.GameMaster)]
@@ -70,4 +63,4 @@ namespace Server.Items
Added = reader.ReadInt();
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Items/Armor/BaseArmor.cs b/Projects/UOContent/Items/Armor/BaseArmor.cs
index 925326df6..4d61606ad 100644
--- a/Projects/UOContent/Items/Armor/BaseArmor.cs
+++ b/Projects/UOContent/Items/Armor/BaseArmor.cs
@@ -479,7 +479,7 @@ namespace Server.Items
if (makersMark)
Crafter = from;
- Type resourceType = typeRes ?? craftItem.Resources.GetAt(0).ItemType;
+ Type resourceType = typeRes ?? craftItem.Resources[0].ItemType;
Resource = CraftResources.GetFromType(resourceType);
PlayerConstructed = true;
@@ -547,12 +547,12 @@ namespace Server.Items
CraftItem item = system.CraftItems.SearchFor(GetType());
- if (item?.Resources.Count == 1 && item.Resources.GetAt(0).Amount >= 2)
+ if (item?.Resources.Count == 1 && item.Resources[0].Amount >= 2)
try
{
Item res = (Item)ActivatorUtil.CreateInstance(CraftResources.GetInfo(m_Resource).ResourceTypes[0]);
- ScissorHelper(from, res, PlayerConstructed ? item.Resources.GetAt(0).Amount / 2 : 1);
+ ScissorHelper(from, res, PlayerConstructed ? item.Resources[0].Amount / 2 : 1);
return true;
}
catch
@@ -623,9 +623,8 @@ namespace Server.Items
double halfar = ArmorRating / 2.0;
int absorbed = (int)(halfar + halfar * Utility.RandomDouble());
- damageTaken -= absorbed;
- if (damageTaken < 0)
- damageTaken = 0;
+ // Don't go below zero
+ damageTaken = Math.Min(absorbed, damageTaken);
if (absorbed < 2)
absorbed = 2;
@@ -1584,7 +1583,7 @@ namespace Server.Items
if (Core.ML && (prop = Attributes.IncreasedKarmaLoss) != 0)
list.Add(1075210, prop.ToString()); // Increased Karma Loss ~1val~%
- this.AddResistanceProperties(list);
+ AddResistanceProperties(list);
if ((prop = GetDurabilityBonus()) > 0)
list.Add(1060410, prop.ToString()); // durability ~1_val~%
diff --git a/Projects/UOContent/Items/Body Parts/BonePile.cs b/Projects/UOContent/Items/Body Parts/BonePile.cs
index 9de0438c2..5cce8e911 100644
--- a/Projects/UOContent/Items/Body Parts/BonePile.cs
+++ b/Projects/UOContent/Items/Body Parts/BonePile.cs
@@ -19,7 +19,7 @@ namespace Server.Items
if (Deleted || !from.CanSee(this))
return false;
- this.ScissorHelper(from, new Bone(), Utility.RandomMinMax(10, 15));
+ ScissorHelper(from, new Bone(), Utility.RandomMinMax(10, 15));
return true;
}
diff --git a/Projects/UOContent/Items/Body Parts/RibCage.cs b/Projects/UOContent/Items/Body Parts/RibCage.cs
index 33308d991..25be14e48 100644
--- a/Projects/UOContent/Items/Body Parts/RibCage.cs
+++ b/Projects/UOContent/Items/Body Parts/RibCage.cs
@@ -19,7 +19,7 @@ namespace Server.Items
if (Deleted || !from.CanSee(this))
return false;
- this.ScissorHelper(from, new Bone(), Utility.RandomMinMax(3, 5));
+ ScissorHelper(from, new Bone(), Utility.RandomMinMax(3, 5));
return true;
}
diff --git a/Projects/UOContent/Items/Champion Artifacts/Shared/DetectiveBoots.cs b/Projects/UOContent/Items/Champion Artifacts/Shared/DetectiveBoots.cs
index bf7ff6b22..44d447e83 100644
--- a/Projects/UOContent/Items/Champion Artifacts/Shared/DetectiveBoots.cs
+++ b/Projects/UOContent/Items/Champion Artifacts/Shared/DetectiveBoots.cs
@@ -30,7 +30,7 @@ namespace Server.Items
get => m_Level;
set
{
- m_Level = Math.Max(Math.Min(2, value), 0);
+ m_Level = Math.Clamp(value, 0, 2);
Attributes.BonusInt = 2 + m_Level;
InvalidateProperties();
}
@@ -52,4 +52,4 @@ namespace Server.Items
Level = Attributes.BonusInt - 2;
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Items/Clothing/BaseClothing.cs b/Projects/UOContent/Items/Clothing/BaseClothing.cs
index 05b82c747..21d77d458 100644
--- a/Projects/UOContent/Items/Clothing/BaseClothing.cs
+++ b/Projects/UOContent/Items/Clothing/BaseClothing.cs
@@ -151,7 +151,7 @@ namespace Server.Items
if (DefaultResource != CraftResource.None)
{
- Type resourceType = typeRes ?? craftItem.Resources.GetAt(0).ItemType;
+ Type resourceType = typeRes ?? craftItem.Resources[0].ItemType;
Resource = CraftResources.GetFromType(resourceType);
}
@@ -200,16 +200,16 @@ namespace Server.Items
CraftItem item = system.CraftItems.SearchFor(GetType());
- if (item?.Resources.Count == 1 && item.Resources.GetAt(0).Amount >= 2)
+ if (item?.Resources.Count == 1 && item.Resources[0].Amount >= 2)
try
{
CraftResourceInfo info = CraftResources.GetInfo(m_Resource);
- Type resourceType = info.ResourceTypes?[0] ?? item.Resources.GetAt(0).ItemType;
+ Type resourceType = info.ResourceTypes?[0] ?? item.Resources[0].ItemType;
Item res = (Item)ActivatorUtil.CreateInstance(resourceType);
- ScissorHelper(from, res, PlayerConstructed ? item.Resources.GetAt(0).Amount / 2 : 1);
+ ScissorHelper(from, res, PlayerConstructed ? item.Resources[0].Amount / 2 : 1);
res.LootType = LootType.Regular;
@@ -262,12 +262,10 @@ namespace Server.Items
public virtual int OnHit(BaseWeapon weapon, int damageTaken)
{
- int Absorbed = Utility.RandomMinMax(1, 4);
+ int absorbed = Utility.RandomMinMax(1, 4);
- damageTaken -= Absorbed;
-
- if (damageTaken < 0)
- damageTaken = 0;
+ // Don't go below zero
+ damageTaken = Math.Min(absorbed, damageTaken);
if (Utility.Random(100) < 25) // 25% chance to lower durability
{
@@ -280,7 +278,7 @@ namespace Server.Items
int wear;
if (weapon.Type == WeaponType.Bashing)
- wear = Absorbed / 2;
+ wear = absorbed / 2;
else
wear = Utility.Random(2);
@@ -338,13 +336,8 @@ namespace Server.Items
InvalidateProperties();
}
- public override bool AllowSecureTrade(Mobile from, Mobile to, Mobile newOwner, bool accepted)
- {
- if (!Ethic.CheckTrade(from, to, newOwner, this))
- return false;
-
- return base.AllowSecureTrade(from, to, newOwner, accepted);
- }
+ public override bool AllowSecureTrade(Mobile from, Mobile to, Mobile newOwner, bool accepted) =>
+ Ethic.CheckTrade(from, to, newOwner, this) && base.AllowSecureTrade(from, to, newOwner, accepted);
public override bool CanEquip(Mobile from)
{
@@ -406,14 +399,13 @@ namespace Server.Items
return AOS.Scale(v, 100 - GetLowerStatReq());
}
- public int ComputeStatBonus(StatType type)
- {
- if (type == StatType.Str)
- return BaseStrBonus + Attributes.BonusStr;
- if (type == StatType.Dex)
- return BaseDexBonus + Attributes.BonusDex;
- return BaseIntBonus + Attributes.BonusInt;
- }
+ public int ComputeStatBonus(StatType type) =>
+ type switch
+ {
+ StatType.Str => BaseStrBonus + Attributes.BonusStr,
+ StatType.Dex => BaseDexBonus + Attributes.BonusDex,
+ _ => BaseIntBonus + Attributes.BonusInt
+ };
public virtual void AddStatBonuses(Mobile parent)
{
@@ -533,26 +525,19 @@ namespace Server.Items
clothing.ClothingAttributes = new AosArmorAttributes(newItem, ClothingAttributes);
}
- public override bool AllowEquippedCast(Mobile from)
- {
- if (base.AllowEquippedCast(from))
- return true;
-
- return Attributes.SpellChanneling != 0;
- }
+ public override bool AllowEquippedCast(Mobile from) => base.AllowEquippedCast(from) || Attributes.SpellChanneling != 0;
public override bool CheckPropertyConflict(Mobile m)
{
if (base.CheckPropertyConflict(m))
return true;
- if (Layer == Layer.Pants)
- return m.FindItemOnLayer(Layer.InnerLegs) != null;
-
- if (Layer == Layer.Shirt)
- return m.FindItemOnLayer(Layer.InnerTorso) != null;
-
- return false;
+ return Layer switch
+ {
+ Layer.Pants => m.FindItemOnLayer(Layer.InnerLegs) != null,
+ Layer.Shirt => m.FindItemOnLayer(Layer.InnerTorso) != null,
+ _ => false
+ };
}
private string GetNameString() => Name ?? $"#{LabelNumber}";
@@ -693,7 +678,7 @@ namespace Server.Items
if (Core.ML && (prop = Attributes.IncreasedKarmaLoss) != 0)
list.Add(1075210, prop.ToString()); // Increased Karma Loss ~1val~%
- this.AddResistanceProperties(list);
+ AddResistanceProperties(list);
if ((prop = ClothingAttributes.DurabilityBonus) > 0)
list.Add(1060410, prop.ToString()); // durability ~1_val~%
diff --git a/Projects/UOContent/Items/Containers/FillableContainers.cs b/Projects/UOContent/Items/Containers/FillableContainers.cs
index a61b6c46e..4621f2d34 100644
--- a/Projects/UOContent/Items/Containers/FillableContainers.cs
+++ b/Projects/UOContent/Items/Containers/FillableContainers.cs
@@ -307,7 +307,7 @@ namespace Server.Items
int version = reader.ReadEncodedInt();
if (version == 0 && m_Content == null)
- Timer.DelayCall(TimeSpan.Zero, AcquireContent);
+ Timer.DelayCall(AcquireContent);
}
}
diff --git a/Projects/UOContent/Items/Containers/SalvageBag.cs b/Projects/UOContent/Items/Containers/SalvageBag.cs
index 662552a08..280c02cf8 100644
--- a/Projects/UOContent/Items/Containers/SalvageBag.cs
+++ b/Projects/UOContent/Items/Containers/SalvageBag.cs
@@ -57,7 +57,7 @@ namespace Server.Items
if (craftItem == null || craftItem.Resources.Count == 0)
return false;
- CraftRes craftResource = craftItem.Resources.GetAt(0);
+ CraftRes craftResource = craftItem.Resources[0];
if (craftResource.Amount < 2)
return false; // Not enough metal to resmelt
diff --git a/Projects/UOContent/Items/Deeds/DragonBardingDeed.cs b/Projects/UOContent/Items/Deeds/DragonBardingDeed.cs
index 2d60d1207..c6c0d3953 100644
--- a/Projects/UOContent/Items/Deeds/DragonBardingDeed.cs
+++ b/Projects/UOContent/Items/Deeds/DragonBardingDeed.cs
@@ -62,7 +62,7 @@ namespace Server.Items
if (makersMark)
Crafter = from;
- Type resourceType = typeRes ?? craftItem.Resources.GetAt(0).ItemType;
+ Type resourceType = typeRes ?? craftItem.Resources[0].ItemType;
Resource = CraftResources.GetFromType(resourceType);
diff --git a/Projects/UOContent/Items/Guilds/Guildstone.cs b/Projects/UOContent/Items/Guilds/Guildstone.cs
index 2feb980de..330b89b5c 100644
--- a/Projects/UOContent/Items/Guilds/Guildstone.cs
+++ b/Projects/UOContent/Items/Guilds/Guildstone.cs
@@ -1,4 +1,3 @@
-using System;
using Server.Factions;
using Server.Guilds;
using Server.Gumps;
@@ -143,7 +142,7 @@ namespace Server.Items
m_BeforeChangeover = true;
if (Guild.NewGuildSystem && m_BeforeChangeover)
- Timer.DelayCall(TimeSpan.Zero, AddToHouse);
+ Timer.DelayCall(AddToHouse);
if (!Guild.NewGuildSystem && Guild == null)
Delete();
diff --git a/Projects/UOContent/Items/Jewels/BaseJewel.cs b/Projects/UOContent/Items/Jewels/BaseJewel.cs
index 55836dfd6..b801e6032 100644
--- a/Projects/UOContent/Items/Jewels/BaseJewel.cs
+++ b/Projects/UOContent/Items/Jewels/BaseJewel.cs
@@ -129,7 +129,7 @@ namespace Server.Items
public int OnCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool,
CraftItem craftItem, int resHue)
{
- Type resourceType = typeRes ?? craftItem.Resources.GetAt(0).ItemType;
+ Type resourceType = typeRes ?? craftItem.Resources[0].ItemType;
Resource = CraftResources.GetFromType(resourceType);
@@ -140,7 +140,7 @@ namespace Server.Items
if (craftItem.Resources.Count > 1)
{
- resourceType = craftItem.Resources.GetAt(1).ItemType;
+ resourceType = craftItem.Resources[1].ItemType;
if (resourceType == typeof(StarSapphire))
GemType = GemType.StarSapphire;
@@ -302,7 +302,7 @@ namespace Server.Items
if (Core.ML && (prop = Attributes.IncreasedKarmaLoss) != 0)
list.Add(1075210, prop.ToString()); // Increased Karma Loss ~1val~%
- this.AddResistanceProperties(list);
+ AddResistanceProperties(list);
if (m_HitPoints >= 0 && m_MaxHitPoints > 0)
list.Add(1060639, "{0}\t{1}", m_HitPoints, m_MaxHitPoints); // durability ~1_val~ / ~2_val~
diff --git a/Projects/UOContent/Items/Maps/MapItem.cs b/Projects/UOContent/Items/Maps/MapItem.cs
index 871ec731f..971a40664 100644
--- a/Projects/UOContent/Items/Maps/MapItem.cs
+++ b/Projects/UOContent/Items/Maps/MapItem.cs
@@ -160,15 +160,8 @@ namespace Server.Items
public virtual void Validate(ref int x, ref int y)
{
- if (x < 0)
- x = 0;
- else if (x >= Width)
- x = Width - 1;
-
- if (y < 0)
- y = 0;
- else if (y >= Height)
- y = Height - 1;
+ x = Math.Clamp(x, 0, Width - 1);
+ y = Math.Clamp(y, 0, Height - 1);
}
public virtual bool ValidateEdit(Mobile from) => m_Editable && Validate(from);
diff --git a/Projects/UOContent/Items/Misc/Bola.cs b/Projects/UOContent/Items/Misc/Bola.cs
index 1fda9073d..bd4f7d0d0 100644
--- a/Projects/UOContent/Items/Misc/Bola.cs
+++ b/Projects/UOContent/Items/Misc/Bola.cs
@@ -84,7 +84,7 @@ namespace Server.Items
to.Damage(1);
- Timer.DelayCall(TimeSpan.FromSeconds(2.0), () => from.EndAction());
+ Timer.DelayCall(TimeSpan.FromSeconds(2.0), from.EndAction);
}
private static bool HasFreeHands(Mobile from)
@@ -191,7 +191,7 @@ namespace Server.Items
from.Animate(11, 5, 1, true, false, 0);
from.MovingEffect(to, 0x26AC, 10, 0, false, false);
- Timer.DelayCall(TimeSpan.FromSeconds(0.5), () => FinishThrow(from, to));
+ Timer.DelayCall(TimeSpan.FromSeconds(0.5), FinishThrow, from, to);
}
else
{
diff --git a/Projects/UOContent/Items/Misc/Corpses/Corpse.cs b/Projects/UOContent/Items/Misc/Corpses/Corpse.cs
index e22403f74..278a1feff 100644
--- a/Projects/UOContent/Items/Misc/Corpses/Corpse.cs
+++ b/Projects/UOContent/Items/Misc/Corpses/Corpse.cs
@@ -391,7 +391,7 @@ namespace Server.Items
}
if (remainder == 0)
- m_InstancedItems.Add(item, new InstancedItemInfo(item, attackers[attackers.Count - 1]));
+ m_InstancedItems.Add(item, new InstancedItemInfo(item, attackers[^1]));
else
m_Unstackables.Add(item);
}
diff --git a/Projects/UOContent/Items/Misc/DeceitBrazier.cs b/Projects/UOContent/Items/Misc/DeceitBrazier.cs
index 18e838d7c..c49ce90cf 100644
--- a/Projects/UOContent/Items/Misc/DeceitBrazier.cs
+++ b/Projects/UOContent/Items/Misc/DeceitBrazier.cs
@@ -131,6 +131,19 @@ namespace Server.Items
Effects.PlaySound(loc, map, 0x225);
}
+ private void SummonCreatureToWorld(BaseCreature bc, Point3D spawnLoc, Map map)
+ {
+ bc.Home = Location;
+ bc.RangeHome = SpawnRange;
+ bc.FightMode = FightMode.Closest;
+
+ bc.MoveToWorld(spawnLoc, map);
+
+ DoEffect(spawnLoc, map);
+
+ bc.ForceReacquire();
+ }
+
public override void OnDoubleClick(Mobile from)
{
if (Utility.InRange(from.Location, Location, 2))
@@ -146,18 +159,7 @@ namespace Server.Items
DoEffect(spawnLoc, map);
- Timer.DelayCall(TimeSpan.FromSeconds(1), () =>
- {
- bc.Home = Location;
- bc.RangeHome = SpawnRange;
- bc.FightMode = FightMode.Closest;
-
- bc.MoveToWorld(spawnLoc, map);
-
- DoEffect(spawnLoc, map);
-
- bc.ForceReacquire();
- });
+ Timer.DelayCall(TimeSpan.FromSeconds(1), SummonCreatureToWorld, bc, spawnLoc, map);
NextSpawn = DateTime.UtcNow + NextSpawnDelay;
}
diff --git a/Projects/UOContent/Items/Misc/Firebomb.cs b/Projects/UOContent/Items/Misc/Firebomb.cs
index 1b429745e..9d79f6c70 100644
--- a/Projects/UOContent/Items/Misc/Firebomb.cs
+++ b/Projects/UOContent/Items/Misc/Firebomb.cs
@@ -167,7 +167,7 @@ namespace Server.Items
Effects.SendMovingEffect(from, to, ItemID, 7, 0, false, false, Hue);
- Timer.DelayCall(TimeSpan.FromSeconds(1.0), () => FirebombReposition_OnTick(p, Map));
+ Timer.DelayCall(TimeSpan.FromSeconds(1.0), FirebombReposition_OnTick, p, Map);
Internalize();
}
diff --git a/Projects/UOContent/Items/Misc/MorphItem.cs b/Projects/UOContent/Items/Misc/MorphItem.cs
index cc49b5707..9efe00c4d 100644
--- a/Projects/UOContent/Items/Misc/MorphItem.cs
+++ b/Projects/UOContent/Items/Misc/MorphItem.cs
@@ -1,4 +1,3 @@
-using System;
using System.Linq;
namespace Server.Items
@@ -118,7 +117,7 @@ namespace Server.Items
}
}
- Timer.DelayCall(TimeSpan.Zero, Refresh);
+ Timer.DelayCall(Refresh);
}
}
}
diff --git a/Projects/UOContent/Items/Misc/OilCloth.cs b/Projects/UOContent/Items/Misc/OilCloth.cs
index fb413e5cb..ded7ae2ac 100644
--- a/Projects/UOContent/Items/Misc/OilCloth.cs
+++ b/Projects/UOContent/Items/Misc/OilCloth.cs
@@ -33,7 +33,7 @@ namespace Server.Items
if (Deleted || !from.CanSee(this))
return false;
- this.ScissorHelper(from, new Bandage(), 1);
+ ScissorHelper(from, new Bandage(), 1);
return true;
}
diff --git a/Projects/UOContent/Items/Misc/PowerGenerator.cs b/Projects/UOContent/Items/Misc/PowerGenerator.cs
index a587cd0d8..513e5a32d 100644
--- a/Projects/UOContent/Items/Misc/PowerGenerator.cs
+++ b/Projects/UOContent/Items/Misc/PowerGenerator.cs
@@ -358,7 +358,7 @@ namespace Server.Items
hues[n.X, n.Y] = NodeHue.Blue;
}
- Node lastNode = path[path.Length - 1];
+ Node lastNode = path[^1];
hues[lastNode.X, lastNode.Y] = NodeHue.Red;
for (int i = 0; i < sideLength; i++)
diff --git a/Projects/UOContent/Items/Misc/Teleporter.cs b/Projects/UOContent/Items/Misc/Teleporter.cs
index 078ac25ae..808ce6f74 100644
--- a/Projects/UOContent/Items/Misc/Teleporter.cs
+++ b/Projects/UOContent/Items/Misc/Teleporter.cs
@@ -401,7 +401,7 @@ namespace Server.Items
m.Send(new MessageLocalized(Serial, ItemID, MessageType.Regular, 0x3B2, 3, m_MessageNumber, null,
""));
- Timer.DelayCall(TimeSpan.FromSeconds(5.0), () => m.EndAction(this));
+ Timer.DelayCall(TimeSpan.FromSeconds(5.0), m.EndAction, this);
}
return false;
diff --git a/Projects/UOContent/Items/Misc/WarningItem.cs b/Projects/UOContent/Items/Misc/WarningItem.cs
index f7c24dddf..a3a50d49f 100644
--- a/Projects/UOContent/Items/Misc/WarningItem.cs
+++ b/Projects/UOContent/Items/Misc/WarningItem.cs
@@ -105,10 +105,10 @@ namespace Server.Items
list[i].Broadcast(triggerer);
}
- Timer.DelayCall(TimeSpan.Zero, InternalCallback);
+ Timer.DelayCall(StopBroadcasting);
}
- private void InternalCallback()
+ private void StopBroadcasting()
{
m_Broadcasting = false;
}
@@ -207,4 +207,4 @@ namespace Server.Items
}
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Items/Resources/Fishing/BigFish.cs b/Projects/UOContent/Items/Resources/Fishing/BigFish.cs
index fe5a39827..89602108a 100644
--- a/Projects/UOContent/Items/Resources/Fishing/BigFish.cs
+++ b/Projects/UOContent/Items/Resources/Fishing/BigFish.cs
@@ -33,7 +33,7 @@ namespace Server.Items
public void Carve(Mobile from, Item item)
{
- this.ScissorHelper(from, new RawFishSteak(), Math.Max(16, (int)Weight) / 4, false);
+ ScissorHelper(from, new RawFishSteak(), Math.Max(16, (int)Weight) / 4, false);
}
public override void GetProperties(ObjectPropertyList list)
diff --git a/Projects/UOContent/Items/Resources/Fishing/Fish.cs b/Projects/UOContent/Items/Resources/Fishing/Fish.cs
index 8d0d9ef39..58c9457d2 100644
--- a/Projects/UOContent/Items/Resources/Fishing/Fish.cs
+++ b/Projects/UOContent/Items/Resources/Fishing/Fish.cs
@@ -16,7 +16,7 @@ namespace Server.Items
public void Carve(Mobile from, Item item)
{
- this.ScissorHelper(from, new RawFishSteak(), 4);
+ ScissorHelper(from, new RawFishSteak(), 4);
}
public override void Serialize(IGenericWriter writer)
diff --git a/Projects/UOContent/Items/Resources/Tailor/BoltOfCloth.cs b/Projects/UOContent/Items/Resources/Tailor/BoltOfCloth.cs
index cd9b4437a..45a10b913 100644
--- a/Projects/UOContent/Items/Resources/Tailor/BoltOfCloth.cs
+++ b/Projects/UOContent/Items/Resources/Tailor/BoltOfCloth.cs
@@ -33,7 +33,7 @@ namespace Server.Items
{
if (Deleted || !from.CanSee(this)) return false;
- this.ScissorHelper(from, new Cloth(), 50);
+ ScissorHelper(from, new Cloth(), 50);
return true;
}
diff --git a/Projects/UOContent/Items/Resources/Tailor/Cloth.cs b/Projects/UOContent/Items/Resources/Tailor/Cloth.cs
index 632aad31e..e75b4e4af 100644
--- a/Projects/UOContent/Items/Resources/Tailor/Cloth.cs
+++ b/Projects/UOContent/Items/Resources/Tailor/Cloth.cs
@@ -34,7 +34,7 @@ namespace Server.Items
{
if (Deleted || !from.CanSee(this)) return false;
- this.ScissorHelper(from, new Bandage(), 1);
+ ScissorHelper(from, new Bandage(), 1);
return true;
}
diff --git a/Projects/UOContent/Items/Resources/Tailor/Hides.cs b/Projects/UOContent/Items/Resources/Tailor/Hides.cs
index 5bffaed59..60ab13a28 100644
--- a/Projects/UOContent/Items/Resources/Tailor/Hides.cs
+++ b/Projects/UOContent/Items/Resources/Tailor/Hides.cs
@@ -121,7 +121,7 @@ namespace Server.Items
return false;
}
- this.ScissorHelper(from, new Leather(), 1);
+ ScissorHelper(from, new Leather(), 1);
return true;
}
@@ -163,7 +163,7 @@ namespace Server.Items
return false;
}
- this.ScissorHelper(from, new SpinedLeather(), 1);
+ ScissorHelper(from, new SpinedLeather(), 1);
return true;
}
@@ -205,7 +205,7 @@ namespace Server.Items
return false;
}
- this.ScissorHelper(from, new HornedLeather(), 1);
+ ScissorHelper(from, new HornedLeather(), 1);
return true;
}
@@ -247,7 +247,7 @@ namespace Server.Items
return false;
}
- this.ScissorHelper(from, new BarbedLeather(), 1);
+ ScissorHelper(from, new BarbedLeather(), 1);
return true;
}
diff --git a/Projects/UOContent/Items/Resources/Tailor/UncutCloth.cs b/Projects/UOContent/Items/Resources/Tailor/UncutCloth.cs
index b6b7bf4cd..d4928974d 100644
--- a/Projects/UOContent/Items/Resources/Tailor/UncutCloth.cs
+++ b/Projects/UOContent/Items/Resources/Tailor/UncutCloth.cs
@@ -34,7 +34,7 @@ namespace Server.Items
{
if (Deleted || !from.CanSee(this)) return false;
- this.ScissorHelper(from, new Bandage(), 1);
+ ScissorHelper(from, new Bandage(), 1);
return true;
}
diff --git a/Projects/UOContent/Items/Skill Items/Carpenter Items/TaxidermyKit.cs b/Projects/UOContent/Items/Skill Items/Carpenter Items/TaxidermyKit.cs
index 4f6780cb7..b1775e5b0 100644
--- a/Projects/UOContent/Items/Skill Items/Carpenter Items/TaxidermyKit.cs
+++ b/Projects/UOContent/Items/Skill Items/Carpenter Items/TaxidermyKit.cs
@@ -291,7 +291,7 @@ namespace Server.Items
}
}
- Timer.DelayCall(TimeSpan.Zero, FixMovingCrate);
+ Timer.DelayCall(FixMovingCrate);
}
private void FixMovingCrate()
diff --git a/Projects/UOContent/Items/Skill Items/Lumberjack/Log.cs b/Projects/UOContent/Items/Skill Items/Lumberjack/Log.cs
index 92c03f3fa..a32546d32 100644
--- a/Projects/UOContent/Items/Skill Items/Lumberjack/Log.cs
+++ b/Projects/UOContent/Items/Skill Items/Lumberjack/Log.cs
@@ -112,7 +112,7 @@ namespace Server.Items
return false;
}
- this.ScissorHelper(from, item, 1, false);
+ ScissorHelper(from, item, 1, false);
return true;
}
}
diff --git a/Projects/UOContent/Items/Skill Items/Magical/Misc/PotionKeg.cs b/Projects/UOContent/Items/Skill Items/Magical/Misc/PotionKeg.cs
index e481c9d63..f31b83df9 100644
--- a/Projects/UOContent/Items/Skill Items/Magical/Misc/PotionKeg.cs
+++ b/Projects/UOContent/Items/Skill Items/Magical/Misc/PotionKeg.cs
@@ -91,7 +91,7 @@ namespace Server.Items
}
if (version < 1)
- Timer.DelayCall(TimeSpan.Zero, UpdateWeight);
+ Timer.DelayCall(UpdateWeight);
}
public override void GetProperties(ObjectPropertyList list)
diff --git a/Projects/UOContent/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs b/Projects/UOContent/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs
index cd02aad96..cf5603a98 100644
--- a/Projects/UOContent/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs
+++ b/Projects/UOContent/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs
@@ -116,7 +116,7 @@ namespace Server.Items
to = new Entity(Serial.Zero, new Point3D(p), from.Map);
Effects.SendMovingEffect(from, to, 0xF0D, 7, 0, false, false, Potion.Hue);
- Timer.DelayCall(TimeSpan.FromSeconds(1.5), () => Potion.Explode(from, new Point3D(p), from.Map));
+ Timer.DelayCall(TimeSpan.FromSeconds(1.5), Potion.Explode, from, new Point3D(p), from.Map);
}
}
diff --git a/Projects/UOContent/Items/Skill Items/Magical/Potions/Confusion Blast Potions/BaseConfusionBlastPotion.cs b/Projects/UOContent/Items/Skill Items/Magical/Potions/Confusion Blast Potions/BaseConfusionBlastPotion.cs
index e6fc8e3fd..70cfd8c8c 100644
--- a/Projects/UOContent/Items/Skill Items/Magical/Potions/Confusion Blast Potions/BaseConfusionBlastPotion.cs
+++ b/Projects/UOContent/Items/Skill Items/Magical/Potions/Confusion Blast Potions/BaseConfusionBlastPotion.cs
@@ -80,7 +80,7 @@ namespace Server.Items
Geometry.Circle2D(loc, map, Radius, BlastEffect, 270, 90);
- Timer.DelayCall(TimeSpan.FromSeconds(0.3), () => CircleEffect2(loc, map));
+ Timer.DelayCall(TimeSpan.FromSeconds(0.3), CircleEffect2, loc, map);
foreach (Mobile mobile in map.GetMobilesInRange(loc, Radius))
if (mobile is BaseCreature mon)
@@ -121,7 +121,7 @@ namespace Server.Items
to = new Entity(Serial.Zero, new Point3D(p), from.Map);
Effects.SendMovingEffect(from, to, 0xF0D, 7, 0, false, false, Potion.Hue);
- Timer.DelayCall(TimeSpan.FromSeconds(1.0), () => Potion.Explode(from, new Point3D(p), from.Map));
+ Timer.DelayCall(TimeSpan.FromSeconds(1.0), Potion.Explode, from, new Point3D(p), from.Map);
}
}
diff --git a/Projects/UOContent/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs b/Projects/UOContent/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs
index 97c5eaaa3..ba561858b 100644
--- a/Projects/UOContent/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs
+++ b/Projects/UOContent/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs
@@ -256,7 +256,7 @@ namespace Server.Items
if (Potion.Amount > 1) Mobile.LiftItemDupe(Potion, 1);
Potion.Internalize();
- Timer.DelayCall(TimeSpan.FromSeconds(1.0), () => Potion.Reposition_OnTick(from, new Point3D(p), map));
+ Timer.DelayCall(TimeSpan.FromSeconds(1.0), Potion.Reposition_OnTick, from, new Point3D(p), map);
}
}
}
diff --git a/Projects/UOContent/Items/Skill Items/Misc/RepairDeed.cs b/Projects/UOContent/Items/Skill Items/Misc/RepairDeed.cs
index 861b18554..40163347d 100644
--- a/Projects/UOContent/Items/Skill Items/Misc/RepairDeed.cs
+++ b/Projects/UOContent/Items/Skill Items/Misc/RepairDeed.cs
@@ -65,7 +65,7 @@ namespace Server.Items
get => m_SkillLevel;
set
{
- m_SkillLevel = Math.Max(Math.Min(value, 120.0), 0);
+ m_SkillLevel = Math.Clamp(value, 0, 120.0);
InvalidateProperties();
}
}
diff --git a/Projects/UOContent/Items/Skill Items/Musical Instruments/BaseInstrument.cs b/Projects/UOContent/Items/Skill Items/Musical Instruments/BaseInstrument.cs
index 7a3f94c2d..65479adf2 100644
--- a/Projects/UOContent/Items/Skill Items/Musical Instruments/BaseInstrument.cs
+++ b/Projects/UOContent/Items/Skill Items/Musical Instruments/BaseInstrument.cs
@@ -354,7 +354,7 @@ namespace Server.Items
}
if (m_UsesRemaining != oldUses)
- Timer.DelayCall(TimeSpan.Zero, InvalidateProperties);
+ Timer.DelayCall(InvalidateProperties);
}
public override void OnSingleClick(Mobile from)
diff --git a/Projects/UOContent/Items/Skill Items/Ninjitsu/NinjaWeapons.cs b/Projects/UOContent/Items/Skill Items/Ninjitsu/NinjaWeapons.cs
index 085846c3d..ae918c16f 100644
--- a/Projects/UOContent/Items/Skill Items/Ninjitsu/NinjaWeapons.cs
+++ b/Projects/UOContent/Items/Skill Items/Ninjitsu/NinjaWeapons.cs
@@ -66,7 +66,7 @@ namespace Server.Items
ConsumeUse(weapon);
if (CombatCheck(from, target))
- Timer.DelayCall(TimeSpan.FromSeconds(1.0), () => OnHit(from, target, weapon));
+ Timer.DelayCall(TimeSpan.FromSeconds(1.0), OnHit, from, target, weapon);
Timer.DelayCall(TimeSpan.FromSeconds(2.5), ResetUsing, from);
}
@@ -86,12 +86,15 @@ namespace Server.Items
{
if (weapon.UsesRemaining > 0)
{
- INinjaAmmo ammo = ActivatorUtil.CreateInstance(weapon.AmmoType, weapon.UsesRemaining) as INinjaAmmo;
+ Item ammo = ActivatorUtil.CreateInstance(weapon.AmmoType, weapon.UsesRemaining) as Item;
- ammo.Poison = weapon.Poison;
- ammo.PoisonCharges = weapon.PoisonCharges;
+ if (ammo is INinjaAmmo ninaAmmo)
+ {
+ ninaAmmo.Poison = weapon.Poison;
+ ninaAmmo.PoisonCharges = weapon.PoisonCharges;
+ }
- from.AddToBackpack((Item)ammo);
+ from.AddToBackpack(ammo);
weapon.UsesRemaining = 0;
weapon.PoisonCharges = 0;
@@ -254,9 +257,7 @@ namespace Server.Items
private static void OnTarget(Mobile from, object targeted, INinjaWeapon weapon)
{
- PlayerMobile player = from as PlayerMobile;
-
- if (WeaponIsValid(weapon, from))
+ if (from is PlayerMobile player && WeaponIsValid(weapon, from))
{
if (targeted is Mobile mobile)
Shoot(player, mobile, weapon);
@@ -267,12 +268,8 @@ namespace Server.Items
}
}
- private static bool WeaponIsValid(INinjaWeapon weapon, Mobile from)
- {
- Item item = weapon as Item;
-
- return !item.Deleted && item.RootParent == from;
- }
+ private static bool WeaponIsValid(INinjaWeapon weapon, Mobile from) =>
+ weapon is Item item && !item.Deleted && item.RootParent == from;
public class LoadEntry : ContextMenuEntry
{
diff --git a/Projects/UOContent/Items/Special/8th Anniversary Items/FountainOfLife.cs b/Projects/UOContent/Items/Special/8th Anniversary Items/FountainOfLife.cs
index 41fce1e8d..c3315b388 100644
--- a/Projects/UOContent/Items/Special/8th Anniversary Items/FountainOfLife.cs
+++ b/Projects/UOContent/Items/Special/8th Anniversary Items/FountainOfLife.cs
@@ -151,10 +151,12 @@ namespace Server.Items
DateTime next = reader.ReadDateTime();
- if (next < DateTime.UtcNow)
- m_Timer = Timer.DelayCall(TimeSpan.Zero, RechargeTime, Recharge);
+ var now = DateTime.UtcNow;
+
+ if (next < now)
+ m_Timer = Timer.DelayCall(RechargeTime, Recharge);
else
- m_Timer = Timer.DelayCall(next - DateTime.UtcNow, RechargeTime, Recharge);
+ m_Timer = Timer.DelayCall(next - now, RechargeTime, Recharge);
}
public void Recharge()
diff --git a/Projects/UOContent/Items/Special/Heritage Items/Guillotine.cs b/Projects/UOContent/Items/Special/Heritage Items/Guillotine.cs
index 3f19b4f77..022377caf 100644
--- a/Projects/UOContent/Items/Special/Heritage Items/Guillotine.cs
+++ b/Projects/UOContent/Items/Special/Heritage Items/Guillotine.cs
@@ -54,7 +54,7 @@ namespace Server.Items
{
from.Location = Location;
- Timer.DelayCall(TimeSpan.FromSeconds(0.5), () => Activate(c, from));
+ Timer.DelayCall(TimeSpan.FromSeconds(0.5), Activate, c, from);
}
else
{
@@ -161,4 +161,4 @@ namespace Server.Items
int version = reader.ReadEncodedInt();
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Items/Special/Heritage Items/IronMaiden.cs b/Projects/UOContent/Items/Special/Heritage Items/IronMaiden.cs
index aa70d57c0..73022624c 100644
--- a/Projects/UOContent/Items/Special/Heritage Items/IronMaiden.cs
+++ b/Projects/UOContent/Items/Special/Heritage Items/IronMaiden.cs
@@ -26,7 +26,7 @@ namespace Server.Items
from.Location = Location;
c.ItemID = 0x124A;
- Timer.DelayCall(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 3, () => Activate(c, from));
+ Timer.DelayCall(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 3, Activate, c, from);
}
else
{
@@ -82,16 +82,18 @@ namespace Server.Items
blood.MoveToWorld(new Point3D(x, y, z), c.Map);
}
- if (from.Female)
- from.PlaySound(Utility.RandomMinMax(0x150, 0x153));
- else
- from.PlaySound(Utility.RandomMinMax(0x15A, 0x15D));
+ from.PlaySound(from.Female ? Utility.RandomMinMax(0x150, 0x153) : Utility.RandomMinMax(0x15A, 0x15D));
from.LocalOverheadMessage(MessageType.Regular, 0,
501777); // Hmm... you suspect that if you used this again, it might hurt.
SpellHelper.Damage(TimeSpan.Zero, from, Utility.Dice(2, 10, 5));
- Timer.DelayCall(TimeSpan.FromSeconds(1), () => c.ItemID = 0x1249);
+ Timer.DelayCall(TimeSpan.FromSeconds(1), Deactivate, c);
+ }
+
+ private void Deactivate(AddonComponent c)
+ {
+ c.ItemID = 0x1249;
}
}
@@ -121,4 +123,4 @@ namespace Server.Items
int version = reader.ReadEncodedInt();
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Items/Special/Holiday/Christmas/HolidayTree.cs b/Projects/UOContent/Items/Special/Holiday/Christmas/HolidayTree.cs
index 82a3599d6..77bdacb2d 100644
--- a/Projects/UOContent/Items/Special/Holiday/Christmas/HolidayTree.cs
+++ b/Projects/UOContent/Items/Special/Holiday/Christmas/HolidayTree.cs
@@ -1,4 +1,3 @@
-using System;
using System.Collections.Generic;
using Server.Multis;
@@ -170,7 +169,7 @@ namespace Server.Items
}
}
- Timer.DelayCall(TimeSpan.Zero, ValidatePlacement);
+ Timer.DelayCall(ValidatePlacement);
}
public void ValidatePlacement()
diff --git a/Projects/UOContent/Items/Special/Holiday/IcyPatch.cs b/Projects/UOContent/Items/Special/Holiday/IcyPatch.cs
index f8a0800d5..0ae538619 100644
--- a/Projects/UOContent/Items/Special/Holiday/IcyPatch.cs
+++ b/Projects/UOContent/Items/Special/Holiday/IcyPatch.cs
@@ -65,7 +65,7 @@ namespace Server.Items
Point3D p = new Point3D(Location);
if (SpellHelper.FindValidSpawnLocation(Map, ref p, true))
- Timer.DelayCall(TimeSpan.FromSeconds(0), () => m.MoveToWorld(p, m.Map));
+ Timer.DelayCall(TimeSpan.FromSeconds(0), m.MoveToWorld, p, m.Map);
action = 21 + Utility.Random(2);
sound = m.Female ? 0x317 : 0x426;
@@ -77,7 +77,7 @@ namespace Server.Items
}
if (action > 0)
- Timer.DelayCall(TimeSpan.FromSeconds(0.4), from => BeginFall_Callback(from, action, sound), m);
+ Timer.DelayCall(TimeSpan.FromSeconds(0.4), BeginFall_Callback, m, action, sound);
}
private static void BeginFall_Callback(Mobile m, int action, int sound)
@@ -107,4 +107,4 @@ namespace Server.Items
int version = reader.ReadInt();
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Items/Special/Holiday/Wreath.cs b/Projects/UOContent/Items/Special/Holiday/Wreath.cs
index b4171d6ab..280313b93 100644
--- a/Projects/UOContent/Items/Special/Holiday/Wreath.cs
+++ b/Projects/UOContent/Items/Special/Holiday/Wreath.cs
@@ -1,4 +1,3 @@
-using System;
using Server.Gumps;
using Server.Multis;
using Server.Network;
@@ -71,7 +70,7 @@ namespace Server.Items
int version = reader.ReadInt();
- Timer.DelayCall(TimeSpan.Zero, FixMovingCrate);
+ Timer.DelayCall(FixMovingCrate);
}
private void FixMovingCrate()
diff --git a/Projects/UOContent/Items/Special/Mutation Core/PlagueBeastOrgans.cs b/Projects/UOContent/Items/Special/Mutation Core/PlagueBeastOrgans.cs
index bfe5cd859..e32cea45c 100644
--- a/Projects/UOContent/Items/Special/Mutation Core/PlagueBeastOrgans.cs
+++ b/Projects/UOContent/Items/Special/Mutation Core/PlagueBeastOrgans.cs
@@ -15,7 +15,7 @@ namespace Server.Items
Movable = false;
Visible = itemID <= 1;
- Timer.DelayCall(TimeSpan.Zero, Initialize);
+ Timer.DelayCall(Initialize);
}
public PlagueBeastOrgan(Serial serial) : base(serial)
diff --git a/Projects/UOContent/Items/Talismans/BaseTalisman.cs b/Projects/UOContent/Items/Talismans/BaseTalisman.cs
index efe5b3b1b..33ecb3abd 100644
--- a/Projects/UOContent/Items/Talismans/BaseTalisman.cs
+++ b/Projects/UOContent/Items/Talismans/BaseTalisman.cs
@@ -475,13 +475,13 @@ namespace Server.Items
SkillBonuses.Serialize(writer);
if (GetSaveFlag(flags, SaveFlag.Protection))
- m_Protection.Serialize(writer);
+ Protection.Serialize(writer);
if (GetSaveFlag(flags, SaveFlag.Killer))
- m_Killer.Serialize(writer);
+ Killer.Serialize(writer);
if (GetSaveFlag(flags, SaveFlag.Summoner))
- m_Summoner.Serialize(writer);
+ Summoner.Serialize(writer);
if (GetSaveFlag(flags, SaveFlag.Removal))
writer.WriteEncodedInt((int)m_Removal);
diff --git a/Projects/UOContent/Items/Weapons/Abilities/InfectiousStrike.cs b/Projects/UOContent/Items/Weapons/Abilities/InfectiousStrike.cs
index 3c29e3c94..35c3e6df4 100644
--- a/Projects/UOContent/Items/Weapons/Abilities/InfectiousStrike.cs
+++ b/Projects/UOContent/Items/Weapons/Abilities/InfectiousStrike.cs
@@ -1,3 +1,5 @@
+using System;
+
namespace Server.Items
{
///
@@ -44,8 +46,7 @@ namespace Server.Items
--weapon.PoisonCharges;
// Infectious strike special move now uses poisoning skill to help determine potency
- int maxLevel = attacker.Skills.Poisoning.Fixed / 200;
- if (maxLevel < 0) maxLevel = 0;
+ int maxLevel = Math.Max(attacker.Skills.Poisoning.Fixed / 200, 0);
if (p.Level > maxLevel) p = Poison.GetPoison(maxLevel);
if (attacker.Skills.Poisoning.Value / 100.0 > Utility.RandomDouble())
@@ -72,4 +73,4 @@ namespace Server.Items
}
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Items/Weapons/BaseWeapon.cs b/Projects/UOContent/Items/Weapons/BaseWeapon.cs
index 360ec8b04..0e618807a 100644
--- a/Projects/UOContent/Items/Weapons/BaseWeapon.cs
+++ b/Projects/UOContent/Items/Weapons/BaseWeapon.cs
@@ -105,7 +105,7 @@ namespace Server.Items
PlayerConstructed = true;
- Type resourceType = typeRes ?? craftItem.Resources.GetAt(0).ItemType;
+ Type resourceType = typeRes ?? craftItem.Resources[0].ItemType;
if (Core.AOS)
{
@@ -824,10 +824,7 @@ namespace Server.Items
if (shield != null)
{
// As per OSI, no genitive effect from the Racial stuffs, ie, 120 parry and '0' bushido with humans
- chance = (parry - bushidoNonRacial) / 400.0;
-
- if (chance < 0) // chance shouldn't go below 0
- chance = 0;
+ chance = Math.Max((parry - bushidoNonRacial) / 400.0, 0);
// Parry/Bushido over 100 grants a 5% bonus.
if (parry >= 100.0 || bushido >= 100.0)
@@ -2067,7 +2064,7 @@ namespace Server.Items
list.Add(entry.Title);
}
- this.AddResistanceProperties(list);
+ AddResistanceProperties(list);
int prop;
diff --git a/Projects/UOContent/Items/Weapons/Maces/FireworksWand.cs b/Projects/UOContent/Items/Weapons/Maces/FireworksWand.cs
index e3f983b1f..f06178b61 100644
--- a/Projects/UOContent/Items/Weapons/Maces/FireworksWand.cs
+++ b/Projects/UOContent/Items/Weapons/Maces/FireworksWand.cs
@@ -73,10 +73,10 @@ namespace Server.Items
Effects.SendMovingEffect(new Entity(Serial.Zero, startLoc, map), new Entity(Serial.Zero, endLoc, map),
0x36E4, 5, 0, false, false);
- Timer.DelayCall(TimeSpan.FromSeconds(1.0), () => FinishLaunch(endLoc, map));
+ Timer.DelayCall(TimeSpan.FromSeconds(1.0), FinishLaunch, endLoc, map);
}
- private void FinishLaunch(Point3D endLoc, Map map)
+ private static void FinishLaunch(Point3D endLoc, Map map)
{
int hue = Utility.Random(40);
diff --git a/Projects/UOContent/Misc/AutoSave.cs b/Projects/UOContent/Misc/AutoSave.cs
index a2e91f9a2..cb8a91dce 100644
--- a/Projects/UOContent/Misc/AutoSave.cs
+++ b/Projects/UOContent/Misc/AutoSave.cs
@@ -141,7 +141,7 @@ namespace Server.Misc
string saves = Path.Combine(Core.BaseDirectory, "Saves");
if (Directory.Exists(saves))
- Directory.Move(saves, FormatDirectory(root, m_Backups[m_Backups.Length - 1], GetTimeStamp()));
+ Directory.Move(saves, FormatDirectory(root, m_Backups[^1], GetTimeStamp()));
}
private static DirectoryInfo Match(string[] paths, string match)
diff --git a/Projects/UOContent/Misc/BuffIcons.cs b/Projects/UOContent/Misc/BuffIcons.cs
index 2acf4d066..4d62caca4 100644
--- a/Projects/UOContent/Misc/BuffIcons.cs
+++ b/Projects/UOContent/Misc/BuffIcons.cs
@@ -19,7 +19,7 @@ namespace Server
public static void ResendBuffsOnClientVersionReceived(NetState ns, ClientVersion cv)
{
if (ns.Mobile is PlayerMobile pm)
- Timer.DelayCall(TimeSpan.Zero, pm.ResendBuffs);
+ Timer.DelayCall(pm.ResendBuffs);
}
public BuffIcon ID { get; }
@@ -62,13 +62,7 @@ namespace Server
TimeLength = length;
TimeStart = DateTime.UtcNow;
- Timer = Timer.DelayCall(length, () =>
- {
- if (!(m is PlayerMobile pm))
- return;
-
- pm.RemoveBuff(this);
- });
+ Timer = Timer.DelayCall(length, RemoveBuff, m, this);
}
public BuffInfo(BuffIcon iconID, int titleCliloc, TextDefinition args)
diff --git a/Projects/UOContent/Misc/ClientVerification.cs b/Projects/UOContent/Misc/ClientVerification.cs
index 5b851f22d..969023c6a 100644
--- a/Projects/UOContent/Misc/ClientVerification.cs
+++ b/Projects/UOContent/Misc/ClientVerification.cs
@@ -108,14 +108,7 @@ namespace Server.Misc
state.Mobile.SendMessage(0x22, kickMessage);
state.Mobile.SendMessage(0x22, "You will be disconnected in {0} seconds.", KickDelay.TotalSeconds);
- Timer.DelayCall(KickDelay, () =>
- {
- if (state.Connection != null)
- {
- Console.WriteLine("Client: {0}: Disconnecting, bad version", state);
- state.Dispose();
- }
- });
+ Timer.DelayCall(KickDelay, OnKick, state);
}
else if (Required != null && version < Required)
{
@@ -138,6 +131,15 @@ namespace Server.Misc
}
}
+ private static void OnKick(NetState ns)
+ {
+ if (ns.Connection != null)
+ {
+ Console.WriteLine("Client: {0}: Disconnecting, bad version", ns);
+ ns.Dispose();
+ }
+ }
+
private static void KickMessage(Mobile from, bool okay)
{
from.SendMessage("You will be reminded of this again.");
@@ -147,7 +149,7 @@ namespace Server.Misc
"Old clients will be kicked after {0} days of character age and {1} hours of play time",
m_AgeLeniency, m_GameTimeLeniency);
- Timer.DelayCall(TimeSpan.FromMinutes(Utility.Random(5, 15)), () => SendAnnoyGump(from));
+ Timer.DelayCall(TimeSpan.FromMinutes(Utility.Random(5, 15)), SendAnnoyGump, from);
}
private static void SendAnnoyGump(Mobile m)
diff --git a/Projects/UOContent/Misc/DoorGenerator.cs b/Projects/UOContent/Misc/DoorGenerator.cs
index 822b33774..550dd9478 100644
--- a/Projects/UOContent/Misc/DoorGenerator.cs
+++ b/Projects/UOContent/Misc/DoorGenerator.cs
@@ -390,7 +390,7 @@ namespace Server
public static bool IsFrame(int id, int[] list)
{
- if (id > list[list.Length - 1])
+ if (id > list[^1])
return false;
for (int i = 0; i < list.Length; ++i)
diff --git a/Projects/UOContent/Misc/Gifts/Winter2004/Mistletoe.cs b/Projects/UOContent/Misc/Gifts/Winter2004/Mistletoe.cs
index a7e1b0cfa..9a322fed1 100644
--- a/Projects/UOContent/Misc/Gifts/Winter2004/Mistletoe.cs
+++ b/Projects/UOContent/Misc/Gifts/Winter2004/Mistletoe.cs
@@ -1,4 +1,3 @@
-using System;
using Server.Gumps;
using Server.Multis;
using Server.Network;
@@ -71,7 +70,7 @@ namespace Server.Items
int version = reader.ReadInt();
- Timer.DelayCall(TimeSpan.Zero, FixMovingCrate);
+ Timer.DelayCall(FixMovingCrate);
}
private void FixMovingCrate()
diff --git a/Projects/UOContent/Misc/Guild.cs b/Projects/UOContent/Misc/Guild.cs
index a87f6089c..585ddac0c 100644
--- a/Projects/UOContent/Misc/Guild.cs
+++ b/Projects/UOContent/Misc/Guild.cs
@@ -1089,7 +1089,7 @@ namespace Server.Guilds
AcceptedWars ??= new List();
PendingWars ??= new List();
- Timer.DelayCall(TimeSpan.Zero, VerifyGuild_Callback);
+ Timer.DelayCall(VerifyGuild_Callback);
}
private void VerifyGuild_Callback()
diff --git a/Projects/UOContent/Misc/ServerList.cs b/Projects/UOContent/Misc/ServerList.cs
index be1df80d4..4b19c25e8 100644
--- a/Projects/UOContent/Misc/ServerList.cs
+++ b/Projects/UOContent/Misc/ServerList.cs
@@ -115,7 +115,7 @@ namespace Server.Misc
IPHostEntry iphe = Dns.GetHostEntry(addr);
if (iphe.AddressList.Length > 0)
- outValue = iphe.AddressList[iphe.AddressList.Length - 1];
+ outValue = iphe.AddressList[^1];
}
catch
{
diff --git a/Projects/UOContent/Mobiles/AI/BaseAI.cs b/Projects/UOContent/Mobiles/AI/BaseAI.cs
index c909ed23b..c2193a810 100644
--- a/Projects/UOContent/Mobiles/AI/BaseAI.cs
+++ b/Projects/UOContent/Mobiles/AI/BaseAI.cs
@@ -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();
-
- 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();
+
+ 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);
}
}
diff --git a/Projects/UOContent/Mobiles/Animals/Mounts/Ethereals.cs b/Projects/UOContent/Mobiles/Animals/Mounts/Ethereals.cs
index 927759b35..27943a582 100644
--- a/Projects/UOContent/Mobiles/Animals/Mounts/Ethereals.cs
+++ b/Projects/UOContent/Mobiles/Animals/Mounts/Ethereals.cs
@@ -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)
diff --git a/Projects/UOContent/Mobiles/Animals/Mounts/Hiryu.cs b/Projects/UOContent/Mobiles/Animals/Mounts/Hiryu.cs
index 98a5eec3f..2adc84ce1 100644
--- a/Projects/UOContent/Mobiles/Animals/Mounts/Hiryu.cs
+++ b/Projects/UOContent/Mobiles/Animals/Mounts/Hiryu.cs
@@ -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;
diff --git a/Projects/UOContent/Mobiles/Animals/Mounts/LesserHiryu.cs b/Projects/UOContent/Mobiles/Animals/Mounts/LesserHiryu.cs
index 28956f8f6..442cba089 100644
--- a/Projects/UOContent/Mobiles/Animals/Mounts/LesserHiryu.cs
+++ b/Projects/UOContent/Mobiles/Animals/Mounts/LesserHiryu.cs
@@ -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;
diff --git a/Projects/UOContent/Mobiles/BaseCreature.cs b/Projects/UOContent/Mobiles/BaseCreature.cs
index 62721b100..4ee115c24 100644
--- a/Projects/UOContent/Mobiles/BaseCreature.cs
+++ b/Projects/UOContent/Mobiles/BaseCreature.cs
@@ -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];
diff --git a/Projects/UOContent/Mobiles/Monsters/LBR/Jukas/JukaMage.cs b/Projects/UOContent/Mobiles/Monsters/LBR/Jukas/JukaMage.cs
index de31fa99d..c8340ef04 100644
--- a/Projects/UOContent/Mobiles/Monsters/LBR/Jukas/JukaMage.cs
+++ b/Projects/UOContent/Mobiles/Monsters/LBR/Jukas/JukaMage.cs
@@ -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();
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Mobiles/Monsters/ML/Animal/Ferret.cs b/Projects/UOContent/Mobiles/Monsters/ML/Animal/Ferret.cs
index cfba6c1d5..ba9d87533 100644
--- a/Projects/UOContent/Mobiles/Monsters/ML/Animal/Ferret.cs
+++ b/Projects/UOContent/Mobiles/Monsters/ML/Animal/Ferret.cs
@@ -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);
diff --git a/Projects/UOContent/Mobiles/Monsters/Misc/Melee/PlagueBeastLord.cs b/Projects/UOContent/Mobiles/Monsters/Misc/Melee/PlagueBeastLord.cs
index 8ffa4be7e..ac1c35aed 100644
--- a/Projects/UOContent/Mobiles/Monsters/Misc/Melee/PlagueBeastLord.cs
+++ b/Projects/UOContent/Mobiles/Monsters/Misc/Melee/PlagueBeastLord.cs
@@ -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()
diff --git a/Projects/UOContent/Mobiles/Monsters/SE/BakeKitsune.cs b/Projects/UOContent/Mobiles/Monsters/SE/BakeKitsune.cs
index 1018d5277..510a5d691 100644
--- a/Projects/UOContent/Mobiles/Monsters/SE/BakeKitsune.cs
+++ b/Projects/UOContent/Mobiles/Monsters/SE/BakeKitsune.cs
@@ -143,7 +143,7 @@ namespace Server.Mobiles
SetResistance(ResistanceType.Energy, 40, 60);
}
- Timer.DelayCall(TimeSpan.Zero, RemoveDisguise);
+ Timer.DelayCall(RemoveDisguise);
}
private class ExpireTimer : Timer
diff --git a/Projects/UOContent/Mobiles/PlayerMobile.cs b/Projects/UOContent/Mobiles/PlayerMobile.cs
index 15fb8944e..d8a945fe5 100644
--- a/Projects/UOContent/Mobiles/PlayerMobile.cs
+++ b/Projects/UOContent/Mobiles/PlayerMobile.cs
@@ -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;
diff --git a/Projects/UOContent/Mobiles/Vendors/BaseVendor.cs b/Projects/UOContent/Mobiles/Vendors/BaseVendor.cs
index fa8b1cbc3..16907ac44 100644
--- a/Projects/UOContent/Mobiles/Vendors/BaseVendor.cs
+++ b/Projects/UOContent/Mobiles/Vendors/BaseVendor.cs
@@ -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 list)
diff --git a/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs b/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs
index 9c75b39f2..d625b84d4 100644
--- a/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs
+++ b/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs
@@ -523,7 +523,7 @@ namespace Server.Mobiles
}
if (version < 1)
- Timer.DelayCall(TimeSpan.Zero, UpgradeFromVersion0);
+ Timer.DelayCall(UpgradeFromVersion0);
}
private void UpgradeFromVersion0()
diff --git a/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs b/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs
index bcebe6156..3c4f1bd89 100644
--- a/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs
+++ b/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs
@@ -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(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(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
diff --git a/Projects/UOContent/Mobiles/Vendors/VendorInventory.cs b/Projects/UOContent/Mobiles/Vendors/VendorInventory.cs
index 204d310b2..f536bbaed 100644
--- a/Projects/UOContent/Mobiles/Vendors/VendorInventory.cs
+++ b/Projects/UOContent/Mobiles/Vendors/VendorInventory.cs
@@ -41,7 +41,7 @@ namespace Server.Mobiles
if (Items.Count == 0 && Gold == 0)
{
- Timer.DelayCall(TimeSpan.Zero, Delete);
+ Timer.DelayCall(Delete);
}
else
{
diff --git a/Projects/UOContent/Multis/BaseHouse.cs b/Projects/UOContent/Multis/BaseHouse.cs
index 1c28c4905..3693805bb 100644
--- a/Projects/UOContent/Multis/BaseHouse.cs
+++ b/Projects/UOContent/Multis/BaseHouse.cs
@@ -494,7 +494,7 @@ namespace Server.Multis
{
if (!Deleted && DecayLevel == DecayLevel.Collapsed)
{
- Timer.DelayCall(TimeSpan.Zero, Decay_Sandbox);
+ Timer.DelayCall(Decay_Sandbox);
return true;
}
@@ -601,16 +601,10 @@ namespace Server.Multis
return (int)(hpe.Vendors * BonusStorageScalar);
}
- public virtual bool CanPlaceNewVendor()
- {
- if (!IsAosRules)
- return true;
-
- if (!NewVendorSystem)
- return CheckAosLockdowns(10);
-
- return PlayerVendors.Count + VendorRentalContracts.Count < GetNewVendorSystemMaxVendors();
- }
+ public virtual bool CanPlaceNewVendor() =>
+ !IsAosRules || (!NewVendorSystem
+ ? CheckAosLockdowns(10)
+ : PlayerVendors.Count + VendorRentalContracts.Count < GetNewVendorSystemMaxVendors());
public virtual bool CanPlaceNewBarkeep() => PlayerBarkeepers.Count < MaximumBarkeepCount;
@@ -1261,9 +1255,9 @@ namespace Server.Multis
if (LockDowns == null)
return;
- int x = this.Location.X - oldLocation.X;
- int y = this.Location.Y - oldLocation.Y;
- int z = this.Location.Z - oldLocation.Z;
+ int x = Location.X - oldLocation.X;
+ int y = Location.Y - oldLocation.Y;
+ int z = Location.Z - oldLocation.Z;
if (Sign?.Deleted == false)
Sign.Location = new Point3D(Sign.X + x, Sign.Y + y, Sign.Z + z);
@@ -2497,7 +2491,7 @@ namespace Server.Multis
if (child.Decays && !child.IsLockedDown && !child.IsSecure &&
child.LastMoved + child.DecayTime <= DateTime.UtcNow)
- Timer.DelayCall(TimeSpan.Zero, child.Delete);
+ Timer.DelayCall(child.Delete);
}
}
}
@@ -2701,7 +2695,7 @@ namespace Server.Multis
if (version <= 1)
ChangeSignType(0xBD2); // private house, plain brass sign
- if (version < 10) Timer.DelayCall(TimeSpan.Zero, FixLockdowns_Sandbox);
+ if (version < 10) Timer.DelayCall(FixLockdowns_Sandbox);
if (version < 11)
LastRefreshed = DateTime.UtcNow + TimeSpan.FromHours(24 * Utility.RandomDouble());
@@ -2719,7 +2713,7 @@ namespace Server.Multis
if (!CheckDecay())
{
if (RelocatedEntities.Count > 0)
- Timer.DelayCall(TimeSpan.Zero, RestoreRelocatedEntities);
+ Timer.DelayCall(RestoreRelocatedEntities);
if (m_Owner == null && Friends.Count == 0 && CoOwners.Count == 0)
Timer.DelayCall(TimeSpan.FromSeconds(10.0), Delete);
@@ -2757,7 +2751,7 @@ namespace Server.Multis
BaseHouse house = houses[i];
if (trans == null && house.CoOwners.Count == 0)
- Timer.DelayCall(TimeSpan.Zero, house.Delete);
+ Timer.DelayCall(house.Delete);
else
house.Owner = trans;
}
diff --git a/Projects/UOContent/Multis/Camps/BaseCamp.cs b/Projects/UOContent/Multis/Camps/BaseCamp.cs
index 59f82d4a2..fd37e4acd 100644
--- a/Projects/UOContent/Multis/Camps/BaseCamp.cs
+++ b/Projects/UOContent/Multis/Camps/BaseCamp.cs
@@ -20,7 +20,7 @@ namespace Server.Multis
m_DecayDelay = TimeSpan.FromMinutes(30.0);
RefreshDecay(true);
- Timer.DelayCall(TimeSpan.Zero, CheckAddComponents);
+ Timer.DelayCall(CheckAddComponents);
}
public BaseCamp(Serial serial) : base(serial)
@@ -194,4 +194,4 @@ namespace Server.Multis
Weight = 1.0;
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Multis/ContestHouses.cs b/Projects/UOContent/Multis/ContestHouses.cs
index 446c541d1..cc18a0a3e 100644
--- a/Projects/UOContent/Multis/ContestHouses.cs
+++ b/Projects/UOContent/Multis/ContestHouses.cs
@@ -71,9 +71,9 @@ namespace Server.Multis
{
base.OnLocationChange(oldLocation);
- int x = this.Location.X - oldLocation.X;
- int y = this.Location.Y - oldLocation.Y;
- int z = this.Location.Z - oldLocation.Z;
+ int x = Location.X - oldLocation.X;
+ int y = Location.Y - oldLocation.Y;
+ int z = Location.Z - oldLocation.Z;
if (Fixtures == null) return;
diff --git a/Projects/UOContent/Multis/MovingCrate.cs b/Projects/UOContent/Multis/MovingCrate.cs
index 9d85597aa..eabd725eb 100644
--- a/Projects/UOContent/Multis/MovingCrate.cs
+++ b/Projects/UOContent/Multis/MovingCrate.cs
@@ -217,11 +217,11 @@ namespace Server.Multis
if (House != null)
{
House.MovingCrate = this;
- Timer.DelayCall(TimeSpan.Zero, Hide);
+ Timer.DelayCall(Hide);
}
else
{
- Timer.DelayCall(TimeSpan.Zero, Delete);
+ Timer.DelayCall(Delete);
}
if (version == 0)
diff --git a/Projects/UOContent/Multis/PreviewHouse.cs b/Projects/UOContent/Multis/PreviewHouse.cs
index c93635118..5fb87c85b 100644
--- a/Projects/UOContent/Multis/PreviewHouse.cs
+++ b/Projects/UOContent/Multis/PreviewHouse.cs
@@ -120,7 +120,7 @@ namespace Server.Multis
}
}
- Timer.DelayCall(TimeSpan.Zero, Delete);
+ Timer.DelayCall(Delete);
}
private class DecayTimer : Timer
@@ -139,4 +139,4 @@ namespace Server.Multis
}
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Skills/AnimalTaming.cs b/Projects/UOContent/Skills/AnimalTaming.cs
index 1c8f652fd..090e0e734 100644
--- a/Projects/UOContent/Skills/AnimalTaming.cs
+++ b/Projects/UOContent/Skills/AnimalTaming.cs
@@ -199,7 +199,7 @@ namespace Server.SkillHandlers
creature.Direction = creature.GetDirectionTo(from);
if (creature.BardPacified && Utility.RandomDouble() > .24)
- Timer.DelayCall(TimeSpan.FromSeconds(2.0), () => creature.BardPacified = true);
+ Timer.DelayCall(TimeSpan.FromSeconds(2.0), Pacify, creature);
else
creature.BardEndTime = DateTime.UtcNow;
@@ -227,6 +227,8 @@ namespace Server.SkillHandlers
}
}
+ private static void Pacify(BaseCreature bc) => bc.BardPacified = true; // Should use bc.Pacify with an end time?
+
private class InternalTimer : Timer
{
private int m_Count;
diff --git a/Projects/UOContent/Skills/EvalInt.cs b/Projects/UOContent/Skills/EvalInt.cs
index a375f619d..becd534da 100644
--- a/Projects/UOContent/Skills/EvalInt.cs
+++ b/Projects/UOContent/Skills/EvalInt.cs
@@ -51,14 +51,8 @@ namespace Server.SkillHandlers
int mana = targ.Mana * 100 / Math.Max(targ.ManaMax, 1) +
Utility.RandomMinMax(-marginOfError, +marginOfError);
- int intMod = intel / 10;
- int mnMod = mana / 10;
-
- if (intMod > 10) intMod = 10;
- else if (intMod < 0) intMod = 0;
-
- if (mnMod > 10) mnMod = 10;
- else if (mnMod < 0) mnMod = 0;
+ int intMod = Math.Clamp(intel / 10, 0, 10);
+ int mnMod = Math.Clamp(mana / 10, 0, 10);
int body;
diff --git a/Projects/UOContent/Spells/Base/MagerySpell.cs b/Projects/UOContent/Spells/Base/MagerySpell.cs
index 2a20de195..37956a40a 100644
--- a/Projects/UOContent/Spells/Base/MagerySpell.cs
+++ b/Projects/UOContent/Spells/Base/MagerySpell.cs
@@ -79,15 +79,8 @@ namespace Server.Spells
public virtual double GetResistPercent(Mobile target) => GetResistPercentForCircle(target, Circle);
- public override TimeSpan GetCastDelay()
- {
- if (!Core.ML && Scroll is BaseWand)
- return TimeSpan.Zero;
-
- if (!Core.AOS)
- return TimeSpan.FromSeconds(0.5 + 0.25 * (int)Circle);
-
- return base.GetCastDelay();
- }
+ public override TimeSpan GetCastDelay() =>
+ !Core.ML && Scroll is BaseWand ? TimeSpan.Zero :
+ !Core.AOS ? TimeSpan.FromSeconds(0.5 + 0.25 * (int)Circle) : base.GetCastDelay();
}
}
diff --git a/Projects/UOContent/Spells/Base/Spell.cs b/Projects/UOContent/Spells/Base/Spell.cs
index 540e2cc7f..ca690c078 100644
--- a/Projects/UOContent/Spells/Base/Spell.cs
+++ b/Projects/UOContent/Spells/Base/Spell.cs
@@ -164,11 +164,10 @@ namespace Server.Spells
public virtual int GetNewAosDamage(int bonus, uint dice, uint sides, bool playerVsPlayer, double scalar)
{
int damage = Utility.Dice(dice, sides, bonus) * 100;
- int damageBonus = 0;
int inscribeSkill = GetInscribeFixed(Caster);
int inscribeBonus = (inscribeSkill + 1000 * (inscribeSkill / 1000)) / 200;
- damageBonus += inscribeBonus;
+ int damageBonus = inscribeBonus;
int intBonus = Caster.Int / 10;
damageBonus += intBonus;
@@ -197,27 +196,10 @@ namespace Server.Spells
return damage / 100;
}
- public virtual bool ConsumeReagents()
- {
- if (Scroll != null || !Caster.Player)
- return true;
-
- if (AosAttributes.GetValue(Caster, AosAttribute.LowerRegCost) > Utility.Random(100))
- return true;
-
- if (DuelContext.IsFreeConsume(Caster))
- return true;
-
- Container pack = Caster.Backpack;
-
- if (pack == null)
- return false;
-
- if (pack.ConsumeTotal(Info.Reagents, Info.Amounts) == -1)
- return true;
-
- return false;
- }
+ public virtual bool ConsumeReagents() =>
+ Scroll != null || !Caster.Player ||
+ AosAttributes.GetValue(Caster, AosAttribute.LowerRegCost) > Utility.Random(100) ||
+ DuelContext.IsFreeConsume(Caster) || Caster.Backpack?.ConsumeTotal(Info.Reagents, Info.Amounts) == -1;
public virtual double GetInscribeSkill(Mobile m) => m.Skills.Inscribe.Value;
@@ -541,10 +523,7 @@ namespace Server.Spells
if (Core.AOS)
return TimeSpan.Zero;
- double delay = 1.0 - Math.Sqrt((Core.TickCount - StartCastTime) / 1000.0 / GetCastDelay().TotalSeconds);
-
- if (delay < 0.2)
- delay = 0.2;
+ double delay = Math.Max(1.0 - Math.Sqrt((Core.TickCount - StartCastTime) / 1000.0 / GetCastDelay().TotalSeconds), 0.2);
return TimeSpan.FromSeconds(delay);
}
@@ -554,9 +533,7 @@ namespace Server.Spells
if (!Core.AOS)
return NextSpellDelay;
- int fcr = AosAttributes.GetValue(Caster, AosAttribute.CastRecovery);
-
- fcr -= ThunderstormSpell.GetCastRecoveryMalus(Caster);
+ int fcr = AosAttributes.GetValue(Caster, AosAttribute.CastRecovery) - ThunderstormSpell.GetCastRecoveryMalus(Caster);
int fcrDelay = -(CastRecoveryFastScalar * fcr);
@@ -585,13 +562,10 @@ namespace Server.Spells
int fcMax = 4;
if (CastSkill == SkillName.Magery || CastSkill == SkillName.Necromancy ||
- (CastSkill == SkillName.Chivalry && Caster.Skills.Magery.Value >= 70.0))
+ CastSkill == SkillName.Chivalry && Caster.Skills.Magery.Value >= 70.0)
fcMax = 2;
- int fc = AosAttributes.GetValue(Caster, AosAttribute.CastSpeed);
-
- if (fc > fcMax)
- fc = fcMax;
+ int fc = Math.Min(AosAttributes.GetValue(Caster, AosAttribute.CastSpeed), fcMax);
if (ProtectionSpell.Registry.ContainsKey(Caster))
fc -= 2;
@@ -599,18 +573,9 @@ namespace Server.Spells
if (EssenceOfWindSpell.IsDebuffed(Caster))
fc -= EssenceOfWindSpell.GetFCMalus(Caster);
- TimeSpan baseDelay = CastDelayBase;
-
TimeSpan fcDelay = TimeSpan.FromSeconds(-(CastDelayFastScalar * fc * CastDelaySecondsPerTick));
- // int delay = CastDelayBase + circleDelay + fcDelay;
- TimeSpan delay = baseDelay + fcDelay;
-
- if (delay < CastDelayMinimum)
- delay = CastDelayMinimum;
-
- // return TimeSpan.FromSeconds( (double)delay / CastDelayPerSecond );
- return delay;
+ return (CastDelayBase + fcDelay).Max(CastDelayMinimum);
}
public virtual void FinishSequence()
@@ -632,8 +597,8 @@ namespace Server.Spells
DoFizzle();
}
else if (Scroll != null && !(Scroll is Runebook) &&
- (Scroll.Amount <= 0 || Scroll.Deleted || Scroll.RootParent != Caster || (Scroll is BaseWand baseWand &&
- (baseWand.Charges <= 0 || baseWand.Parent != Caster))))
+ (Scroll.Amount <= 0 || Scroll.Deleted || Scroll.RootParent != Caster || Scroll is BaseWand baseWand &&
+ (baseWand.Charges <= 0 || baseWand.Parent != Caster)))
{
DoFizzle();
}
diff --git a/Projects/UOContent/Spells/Base/SpellHelper.cs b/Projects/UOContent/Spells/Base/SpellHelper.cs
index c3f7794de..9160550bc 100644
--- a/Projects/UOContent/Spells/Base/SpellHelper.cs
+++ b/Projects/UOContent/Spells/Base/SpellHelper.cs
@@ -148,13 +148,8 @@ namespace Server.Spells
public static bool DisableSkillCheck { get; set; }
- public static TimeSpan GetDamageDelayForSpell(Spell sp)
- {
- if (!sp.DelayedDamage)
- return TimeSpan.Zero;
-
- return Core.AOS ? AosDamageDelay : OldDamageDelay;
- }
+ public static TimeSpan GetDamageDelayForSpell(Spell sp) =>
+ !sp.DelayedDamage ? TimeSpan.Zero : Core.AOS ? AosDamageDelay : OldDamageDelay;
public static bool CheckMulti(Point3D p, Map map, bool houses = true, int housingrange = 0)
{
@@ -169,7 +164,7 @@ namespace Server.Spells
if (multi is BaseHouse bh)
{
- if ((houses && bh.IsInside(p, 16)) || (housingrange > 0 && bh.InRange(p, housingrange)))
+ if (houses && bh.IsInside(p, 16) || housingrange > 0 && bh.InRange(p, housingrange))
return true;
}
else if (multi.Contains(p))
@@ -260,15 +255,10 @@ namespace Server.Spells
}
}
- public static bool AddStatOffset(Mobile m, StatType type, int offset, TimeSpan duration)
- {
- if (offset > 0)
- return AddStatBonus(m, m, type, offset, duration);
- if (offset < 0)
- return AddStatCurse(m, m, type, -offset, duration);
-
- return true;
- }
+ public static bool AddStatOffset(Mobile m, StatType type, int offset, TimeSpan duration) =>
+ offset > 0
+ ? AddStatBonus(m, m, type, offset, duration)
+ : offset >= 0 || AddStatCurse(m, m, type, -offset, duration);
public static bool AddStatBonus(Mobile caster, Mobile target, StatType type) => AddStatBonus(caster, target, type, GetOffset(caster, target, type, false), GetDuration(caster, target));
@@ -318,13 +308,8 @@ namespace Server.Spells
return false;
}
- public static TimeSpan GetDuration(Mobile caster, Mobile target)
- {
- if (Core.AOS)
- return TimeSpan.FromSeconds(6 * caster.Skills.EvalInt.Fixed / 50 + 1);
-
- return TimeSpan.FromSeconds(caster.Skills.Magery.Value * 1.2);
- }
+ public static TimeSpan GetDuration(Mobile caster, Mobile target) =>
+ Core.AOS ? TimeSpan.FromSeconds(6 * caster.Skills.EvalInt.Fixed / 50 + 1) : TimeSpan.FromSeconds(caster.Skills.Magery.Value * 1.2);
public static double GetOffsetScalar(Mobile caster, Mobile target, bool curse)
{
@@ -337,10 +322,7 @@ namespace Server.Spells
percent *= 0.01;
- if (percent < 0)
- percent = 0;
-
- return percent;
+ return Math.Max(percent, 0);
}
public static int GetOffset(Mobile caster, Mobile target, StatType type, bool curse)
@@ -453,7 +435,7 @@ namespace Server.Spells
return false;
}
- return (bcTarg?.Controlled == false && bcTarg.InitialInnocent) ||
+ return bcTarg?.Controlled == false && bcTarg.InitialInnocent ||
Notoriety.Compute(from, to) != Notoriety.Innocent || from.Kills >= 5;
}
@@ -672,10 +654,10 @@ namespace Server.Spells
int x = loc.X, y = loc.Y;
- return (x >= 1182 && y >= 437 && x < 1211 && y < 470)
- || (x >= 1156 && y >= 470 && x < 1211 && y < 503)
- || (x >= 1176 && y >= 503 && x < 1208 && y < 509)
- || (x >= 1188 && y >= 509 && x < 1201 && y < 513);
+ return x >= 1182 && y >= 437 && x < 1211 && y < 470
+ || x >= 1156 && y >= 470 && x < 1211 && y < 503
+ || x >= 1176 && y >= 503 && x < 1208 && y < 509
+ || x >= 1188 && y >= 509 && x < 1201 && y < 513;
}
public static bool IsSafeZone(Map map, Point3D loc) =>
@@ -694,13 +676,7 @@ namespace Server.Spells
int x = loc.X, y = loc.Y;
- if (x >= 426 && y >= 314 && x <= 430 && y <= 331)
- return true;
-
- if (x >= 406 && y >= 247 && x <= 410 && y <= 264)
- return true;
-
- return false;
+ return x >= 426 && y >= 314 && x <= 430 && y <= 331 || x >= 406 && y >= 247 && x <= 410 && y <= 264;
}
public static bool IsTokunoDungeon(Map map, Point3D loc)
@@ -1132,7 +1108,7 @@ namespace Server.Spells
{
caster.SendLocalizedMessage(1061091); // You cannot cast that spell in this form.
}
- else if (!caster.CanBeginAction() || (caster.IsBodyMod && GetContext(caster) == null))
+ else if (!caster.CanBeginAction() || caster.IsBodyMod && GetContext(caster) == null)
{
spell.DoFizzle();
}
diff --git a/Projects/UOContent/Spells/Bushido/HonorableExecution.cs b/Projects/UOContent/Spells/Bushido/HonorableExecution.cs
index f5cf1f805..16838acf4 100644
--- a/Projects/UOContent/Spells/Bushido/HonorableExecution.cs
+++ b/Projects/UOContent/Spells/Bushido/HonorableExecution.cs
@@ -42,7 +42,7 @@ namespace Server.Spells.Bushido
attacker.Hits += 20 + (int)(bushido * bushido / 480.0);
- int swingBonus = Math.Max(1, (int)(bushido * bushido / 720.0));
+ int swingBonus = Math.Max((int)(bushido * bushido / 720.0), 1);
info = new HonorableExecutionInfo(attacker, swingBonus);
info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(20.0), RemovePenalty, info.m_Mobile);
diff --git a/Projects/UOContent/Spells/Bushido/MomentumStrike.cs b/Projects/UOContent/Spells/Bushido/MomentumStrike.cs
index 45055ddf0..c34f8e264 100644
--- a/Projects/UOContent/Spells/Bushido/MomentumStrike.cs
+++ b/Projects/UOContent/Spells/Bushido/MomentumStrike.cs
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
-using Server.Items;
namespace Server.Spells.Bushido
{
@@ -19,7 +18,7 @@ namespace Server.Spells.Bushido
ClearCurrentMove(attacker);
- BaseWeapon weapon = attacker.Weapon as BaseWeapon;
+ IWeapon weapon = attacker.Weapon;
List targets = attacker.GetMobilesInRange(weapon.MaxRange)
.Where(m => m != defender).Where(m => m.Combatant == attacker).ToList();
diff --git a/Projects/UOContent/Spells/Bushido/SamuraiSpell.cs b/Projects/UOContent/Spells/Bushido/SamuraiSpell.cs
index bc17be7ab..d401de895 100644
--- a/Projects/UOContent/Spells/Bushido/SamuraiSpell.cs
+++ b/Projects/UOContent/Spells/Bushido/SamuraiSpell.cs
@@ -42,7 +42,7 @@ namespace Server.Spells.Bushido
if (Caster.Skills[CastSkill].Value < RequiredSkill)
{
- string args = $"{RequiredSkill.ToString("F1")}\t{CastSkill.ToString()}\t ";
+ string args = $"{RequiredSkill:F1}\t{CastSkill.ToString()}\t ";
Caster.SendLocalizedMessage(1063013,
args); // You need at least ~1_SKILL_REQUIREMENT~ ~2_SKILL_NAME~ skill to use that ability.
return false;
diff --git a/Projects/UOContent/Spells/Chivalry/CleanseByFire.cs b/Projects/UOContent/Spells/Chivalry/CleanseByFire.cs
index 87d97f193..dea6f9cb1 100644
--- a/Projects/UOContent/Spells/Chivalry/CleanseByFire.cs
+++ b/Projects/UOContent/Spells/Chivalry/CleanseByFire.cs
@@ -88,13 +88,7 @@ namespace Server.Spells.Chivalry
Caster.PlaySound(0x208);
Caster.FixedParticles(0x3709, 1, 30, 9934, 0, 7, EffectLayer.Waist);
- int damage = 50 - ComputePowerValue(4);
-
- // TODO: Should caps be applied?
- if (damage < 13)
- damage = 13;
- else if (damage > 55)
- damage = 55;
+ int damage = Math.Clamp(50 - ComputePowerValue(4), 13, 55);
AOS.Damage(Caster, Caster, damage, 0, 100, 0, 0, 0, true);
}
diff --git a/Projects/UOContent/Spells/Chivalry/CloseWounds.cs b/Projects/UOContent/Spells/Chivalry/CloseWounds.cs
index 7c6d3f323..ead451c01 100644
--- a/Projects/UOContent/Spells/Chivalry/CloseWounds.cs
+++ b/Projects/UOContent/Spells/Chivalry/CloseWounds.cs
@@ -65,7 +65,7 @@ namespace Server.Spells.Chivalry
*/
// TODO: Should caps be applied?
- int toHeal = Math.Min(Math.Max(ComputePowerValue(6) + Utility.RandomMinMax(0, 2), 7), 39);
+ int toHeal = Math.Clamp(ComputePowerValue(6) + Utility.RandomMinMax(0, 2), 7, 39);
if (m.Hits + toHeal > m.HitsMax)
toHeal = m.HitsMax - m.Hits;
diff --git a/Projects/UOContent/Spells/Chivalry/ConsecrateWeapon.cs b/Projects/UOContent/Spells/Chivalry/ConsecrateWeapon.cs
index fe600185d..e9ea34a24 100644
--- a/Projects/UOContent/Spells/Chivalry/ConsecrateWeapon.cs
+++ b/Projects/UOContent/Spells/Chivalry/ConsecrateWeapon.cs
@@ -66,13 +66,7 @@ namespace Server.Spells.Chivalry
Effects.SendMovingParticles(from, to, itemID, 1, 0, false, false, 33, 3, 9501, 1, 0, EffectLayer.Head,
0x100);
- double seconds = ComputePowerValue(20);
-
- // TODO: Should caps be applied?
- if (seconds < 3.0)
- seconds = 3.0;
- else if (seconds > 11.0)
- seconds = 11.0;
+ double seconds = Math.Clamp(ComputePowerValue(20), 3.0, 11.0);
TimeSpan duration = TimeSpan.FromSeconds(seconds);
diff --git a/Projects/UOContent/Spells/Chivalry/DivineFury.cs b/Projects/UOContent/Spells/Chivalry/DivineFury.cs
index b17a77fac..13b1a0292 100644
--- a/Projects/UOContent/Spells/Chivalry/DivineFury.cs
+++ b/Projects/UOContent/Spells/Chivalry/DivineFury.cs
@@ -38,13 +38,7 @@ namespace Server.Spells.Chivalry
m_Table.TryGetValue(Caster, out Timer timer);
timer?.Stop();
- int delay = ComputePowerValue(10);
-
- // TODO: Should caps be applied?
- if (delay < 7)
- delay = 7;
- else if (delay > 24)
- delay = 24;
+ int delay = Math.Clamp(ComputePowerValue(10), 7, 24);
m_Table[Caster] = Timer.DelayCall(TimeSpan.FromSeconds(delay), Expire_Callback, Caster);
Caster.Delta(MobileDelta.WeaponDamage);
diff --git a/Projects/UOContent/Spells/Chivalry/EnemyOfOne.cs b/Projects/UOContent/Spells/Chivalry/EnemyOfOne.cs
index 9a5f51520..57b397b10 100644
--- a/Projects/UOContent/Spells/Chivalry/EnemyOfOne.cs
+++ b/Projects/UOContent/Spells/Chivalry/EnemyOfOne.cs
@@ -37,13 +37,7 @@ namespace Server.Spells.Chivalry
m_Table.TryGetValue(Caster, out Timer timer);
timer?.Stop();
- double delay = (double)ComputePowerValue(1) / 60;
-
- // TODO: Should caps be applied?
- if (delay < 1.5)
- delay = 1.5;
- else if (delay > 3.5)
- delay = 3.5;
+ double delay = Math.Clamp(ComputePowerValue(1) / 60.0, 1.5, 3.5);
m_Table[Caster] = Timer.DelayCall(TimeSpan.FromMinutes(delay), Expire_Callback, Caster);
diff --git a/Projects/UOContent/Spells/Chivalry/HolyLight.cs b/Projects/UOContent/Spells/Chivalry/HolyLight.cs
index d343f941f..b94895058 100644
--- a/Projects/UOContent/Spells/Chivalry/HolyLight.cs
+++ b/Projects/UOContent/Spells/Chivalry/HolyLight.cs
@@ -45,13 +45,7 @@ namespace Server.Spells.Chivalry
foreach (Mobile m in targets)
{
- int damage = ComputePowerValue(10) + Utility.RandomMinMax(0, 2);
-
- // TODO: Should caps be applied?
- if (damage < 8)
- damage = 8;
- else if (damage > 24)
- damage = 24;
+ int damage = Math.Clamp(ComputePowerValue(10) + Utility.RandomMinMax(0, 2), 8, 24);
Caster.DoHarmful(m);
SpellHelper.Damage(this, m, damage, 0, 0, 0, 0, 100);
diff --git a/Projects/UOContent/Spells/Chivalry/NobleSacrifice.cs b/Projects/UOContent/Spells/Chivalry/NobleSacrifice.cs
index 2972a222f..09057e5b1 100644
--- a/Projects/UOContent/Spells/Chivalry/NobleSacrifice.cs
+++ b/Projects/UOContent/Spells/Chivalry/NobleSacrifice.cs
@@ -92,13 +92,7 @@ namespace Server.Spells.Chivalry
if (m.Hits < m.HitsMax)
{
- int toHeal = ComputePowerValue(10) + Utility.RandomMinMax(0, 2);
-
- // TODO: Should caps be applied?
- if (toHeal < 8)
- toHeal = 8;
- else if (toHeal > 24)
- toHeal = 24;
+ int toHeal = Math.Clamp(ComputePowerValue(10) + Utility.RandomMinMax(0, 2), 8, 24);
Caster.DoBeneficial(m);
m.Heal(toHeal, Caster);
diff --git a/Projects/UOContent/Spells/Eighth/Earthquake.cs b/Projects/UOContent/Spells/Eighth/Earthquake.cs
index bd43ee909..f6670b6cb 100644
--- a/Projects/UOContent/Spells/Eighth/Earthquake.cs
+++ b/Projects/UOContent/Spells/Eighth/Earthquake.cs
@@ -48,7 +48,8 @@ namespace Server.Spells.Eighth
damage = m.Hits / 2;
if (!m.Player)
- damage = Math.Max(Math.Min(damage, 100), 15);
+ damage = Math.Clamp(damage, 15, 100);
+
damage += Utility.RandomMinMax(0, 15);
}
else
diff --git a/Projects/UOContent/Spells/Fifth/Paralyze.cs b/Projects/UOContent/Spells/Fifth/Paralyze.cs
index 6b1d5dec0..7764f1b02 100644
--- a/Projects/UOContent/Spells/Fifth/Paralyze.cs
+++ b/Projects/UOContent/Spells/Fifth/Paralyze.cs
@@ -56,10 +56,7 @@ namespace Server.Spells.Fifth
if (!m.Player)
secs *= 3;
- if (secs < 0)
- secs = 0;
-
- duration = secs;
+ duration = Math.Max(secs, 0);
}
else
{
diff --git a/Projects/UOContent/Spells/First/NightSight.cs b/Projects/UOContent/Spells/First/NightSight.cs
index 82b9ca289..350dea8be 100644
--- a/Projects/UOContent/Spells/First/NightSight.cs
+++ b/Projects/UOContent/Spells/First/NightSight.cs
@@ -1,3 +1,4 @@
+using System;
using Server.Targeting;
namespace Server.Spells.First
@@ -37,15 +38,13 @@ namespace Server.Spells.First
if (targ.BeginAction())
{
new LightCycle.NightSightTimer(targ).Start();
- int level = (int)(LightCycle.DungeonLevel *
- ((Core.AOS
- ? targ.Skills.Magery.Value
- : from.Skills.Magery.Value) / 100));
+ int level =
+ (int)(LightCycle.DungeonLevel *
+ ((Core.AOS
+ ? targ.Skills.Magery.Value
+ : from.Skills.Magery.Value) / 100));
- if (level < 0)
- level = 0;
-
- targ.LightLevel = level;
+ targ.LightLevel = Math.Max(level, 0);
targ.FixedParticles(0x376A, 9, 32, 5007, EffectLayer.Waist);
targ.PlaySound(0x1E3);
diff --git a/Projects/UOContent/Spells/First/ReactiveArmor.cs b/Projects/UOContent/Spells/First/ReactiveArmor.cs
index b17e4fa33..5105d96f7 100644
--- a/Projects/UOContent/Spells/First/ReactiveArmor.cs
+++ b/Projects/UOContent/Spells/First/ReactiveArmor.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
namespace Server.Spells.First
@@ -111,14 +112,10 @@ namespace Server.Spells.First
{
if (Caster.BeginAction())
{
- int value = (int)(Caster.Skills.Magery.Value + Caster.Skills.Meditation.Value +
- Caster.Skills.Inscribe.Value);
- value /= 3;
-
- if (value < 0)
- value = 1;
- else if (value > 75)
- value = 75;
+ int value = Math.Clamp(
+ (int)(Caster.Skills.Magery.Value + Caster.Skills.Meditation.Value +
+ Caster.Skills.Inscribe.Value) / 3, 1, 75
+ );
Caster.MeleeDamageAbsorb = value;
diff --git a/Projects/UOContent/Spells/Fourth/ArchProtection.cs b/Projects/UOContent/Spells/Fourth/ArchProtection.cs
index f28f7499f..9fcb36150 100644
--- a/Projects/UOContent/Spells/Fourth/ArchProtection.cs
+++ b/Projects/UOContent/Spells/Fourth/ArchProtection.cs
@@ -99,9 +99,7 @@ namespace Server.Spells.Fourth
{
_Table.Remove(m);
m.EndAction();
- m.VirtualArmorMod -= v;
- if (m.VirtualArmorMod < 0)
- m.VirtualArmorMod = 0;
+ m.VirtualArmorMod -= Math.Min(v, m.VirtualArmorMod);
}
}
diff --git a/Projects/UOContent/Spells/Fourth/ManaDrain.cs b/Projects/UOContent/Spells/Fourth/ManaDrain.cs
index 4a3f6f8d9..80ab83817 100644
--- a/Projects/UOContent/Spells/Fourth/ManaDrain.cs
+++ b/Projects/UOContent/Spells/Fourth/ManaDrain.cs
@@ -59,12 +59,7 @@ namespace Server.Spells.Fourth
if (Core.AOS)
{
- int toDrain = 40 + (int)(GetDamageSkill(Caster) - GetResistSkill(m));
-
- if (toDrain < 0)
- toDrain = 0;
- else if (toDrain > m.Mana)
- toDrain = m.Mana;
+ int toDrain = Math.Clamp(40 + (int)(GetDamageSkill(Caster) - GetResistSkill(m)), 0, m.Mana);
if (m_Table.Contains(m))
toDrain = 0;
@@ -77,7 +72,7 @@ namespace Server.Spells.Fourth
m.Mana -= toDrain;
m_Table.Add(m);
- Timer.DelayCall(TimeSpan.FromSeconds(5.0), () => AosDelay_Callback(m, toDrain));
+ Timer.DelayCall(TimeSpan.FromSeconds(5.0), AosDelay_Callback, m, toDrain);
}
}
else
diff --git a/Projects/UOContent/Spells/Gargoyle/SpellDefinitions/FlySpell.cs b/Projects/UOContent/Spells/Gargoyle/SpellDefinitions/FlySpell.cs
index 910b46cba..1a14e2c16 100644
--- a/Projects/UOContent/Spells/Gargoyle/SpellDefinitions/FlySpell.cs
+++ b/Projects/UOContent/Spells/Gargoyle/SpellDefinitions/FlySpell.cs
@@ -34,13 +34,8 @@ namespace Server.Spells
Disturb(DisturbType.Hurt, false);
}
- public override bool CheckDisturb(DisturbType type, bool checkFirst, bool resistable)
- {
- if (type == DisturbType.EquipRequest || type == DisturbType.UseRequest /* || type == DisturbType.Hurt*/)
- return false;
-
- return true;
- }
+ public override bool CheckDisturb(DisturbType type, bool checkFirst, bool resistable) =>
+ type != DisturbType.EquipRequest && type != DisturbType.UseRequest;
public override void DoHurtFizzle()
{
@@ -67,4 +62,4 @@ namespace Server.Spells
FinishSequence();
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Spells/Necromancy/AnimateDeadSpell.cs b/Projects/UOContent/Spells/Necromancy/AnimateDeadSpell.cs
index 47679d858..f7ce8e638 100644
--- a/Projects/UOContent/Spells/Necromancy/AnimateDeadSpell.cs
+++ b/Projects/UOContent/Spells/Necromancy/AnimateDeadSpell.cs
@@ -163,8 +163,8 @@ namespace Server.Spells.Necromancy
if (c.Owner != null) type = c.Owner.GetType();
if (c.ItemID != 0x2006 || c.Animated || type == typeof(PlayerMobile) || type == null ||
- (c.Owner != null && c.Owner.Fame < 100) ||
- (c.Owner is BaseCreature creature && (creature.Summoned || creature.IsBonded)))
+ c.Owner != null && c.Owner.Fame < 100 ||
+ c.Owner is BaseCreature creature && (creature.Summoned || creature.IsBonded))
{
Caster.SendLocalizedMessage(1061085); // There's not enough life force there to animate.
}
@@ -236,7 +236,7 @@ namespace Server.Spells.Necromancy
list.Add(summoned);
if (list.Count > 3)
- Timer.DelayCall(TimeSpan.Zero, list[0].Kill);
+ Timer.DelayCall(list[0].Kill);
Timer.DelayCall(TimeSpan.FromSeconds(2.0), TimeSpan.FromSeconds(2.0), Summoned_Damage, summoned);
}
@@ -262,18 +262,8 @@ namespace Server.Spells.Necromancy
double necromancy = caster.Skills.Necromancy.Value;
double spiritSpeak = caster.Skills.SpiritSpeak.Value;
- int casterAbility = 0;
-
- casterAbility += (int)(necromancy * 30);
- casterAbility += (int)(spiritSpeak * 70);
- casterAbility /= 10;
- casterAbility *= 18;
-
- if (casterAbility > owner.Fame)
- casterAbility = owner.Fame;
-
- if (casterAbility < 0)
- casterAbility = 0;
+ int casterAbility = (int)(necromancy * 30) + (int)(spiritSpeak * 70);
+ casterAbility = Math.Clamp(casterAbility / 10 * 18, 0, owner.Fame);
Type toSummon = null;
SummonEntry[] entries = group.m_Entries;
@@ -287,8 +277,7 @@ namespace Server.Spells.Necromancy
Type[] animates = entry.m_ToSummon;
- if (animates.Length >= 0)
- toSummon = animates[Utility.Random(animates.Length)];
+ toSummon = animates[Utility.Random(animates.Length)];
}
if (toSummon == null)
diff --git a/Projects/UOContent/Spells/Necromancy/NecromancerSpell.cs b/Projects/UOContent/Spells/Necromancy/NecromancerSpell.cs
index eaa58497c..39ac13a7f 100644
--- a/Projects/UOContent/Spells/Necromancy/NecromancerSpell.cs
+++ b/Projects/UOContent/Spells/Necromancy/NecromancerSpell.cs
@@ -41,17 +41,8 @@ namespace Server.Spells.Necromancy
max = Scroll != null ? min : RequiredSkill + 40.0;
}
- public override bool ConsumeReagents()
- {
- if (base.ConsumeReagents())
- return true;
-
- if (ArcaneGem.ConsumeCharges(Caster, 1))
- return true;
-
- return false;
- }
+ public override bool ConsumeReagents() => base.ConsumeReagents() || ArcaneGem.ConsumeCharges(Caster, 1);
public override int GetMana() => RequiredMana;
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Spells/Necromancy/PainSpike.cs b/Projects/UOContent/Spells/Necromancy/PainSpike.cs
index c9e563d8e..0bc787f72 100644
--- a/Projects/UOContent/Spells/Necromancy/PainSpike.cs
+++ b/Projects/UOContent/Spells/Necromancy/PainSpike.cs
@@ -52,12 +52,9 @@ namespace Server.Spells.Necromancy
m.FixedParticles(0x37C4, 1, 8, 9502, 39, 4, EffectLayer.Head);
m.PlaySound(0x210);
- double damage = (GetDamageSkill(Caster) - GetResistSkill(m)) / 10 + (m.Player ? 18 : 30);
+ double damage = Math.Max((GetDamageSkill(Caster) - GetResistSkill(m)) / 10 + (m.Player ? 18 : 30), 1);
m.CheckSkill(SkillName.MagicResist, 0.0, 120.0); // Skill check for gain
- if (damage < 1)
- damage = 1;
-
TimeSpan buffTime = TimeSpan.FromSeconds(10.0);
if (!m_Table.TryGetValue(m, out InternalTimer timer))
diff --git a/Projects/UOContent/Spells/Necromancy/TransformationSpell.cs b/Projects/UOContent/Spells/Necromancy/TransformationSpell.cs
index b0f9c2fcc..48713a62d 100644
--- a/Projects/UOContent/Spells/Necromancy/TransformationSpell.cs
+++ b/Projects/UOContent/Spells/Necromancy/TransformationSpell.cs
@@ -30,13 +30,7 @@ namespace Server.Spells.Necromancy
{
}
- public override bool CheckCast()
- {
- if (!TransformationSpellHelper.CheckCast(Caster, this))
- return false;
-
- return base.CheckCast();
- }
+ public override bool CheckCast() => TransformationSpellHelper.CheckCast(Caster, this) && base.CheckCast();
public override void OnCast()
{
@@ -45,4 +39,4 @@ namespace Server.Spells.Necromancy
FinishSequence();
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Spells/Ninjitsu/DeathStrike.cs b/Projects/UOContent/Spells/Ninjitsu/DeathStrike.cs
index cbe9913e8..3b57c56c7 100644
--- a/Projects/UOContent/Spells/Ninjitsu/DeathStrike.cs
+++ b/Projects/UOContent/Spells/Ninjitsu/DeathStrike.cs
@@ -114,7 +114,7 @@ namespace Server.Spells.Ninjitsu
double baseDamage = ninjitsu / divisor * 10;
int maxDamage = info.m_Steps >= 5 ? 62 : 22;
- damage = Math.Max(0, Math.Min(maxDamage, (int)(baseDamage + stalkingBonus))) + info.m_DamageBonus;
+ damage = Math.Clamp((int)(baseDamage + stalkingBonus), 0, maxDamage) + info.m_DamageBonus;
}
if (Core.ML)
diff --git a/Projects/UOContent/Spells/Ninjitsu/FocusAttack.cs b/Projects/UOContent/Spells/Ninjitsu/FocusAttack.cs
index fd64ac436..f1538451f 100644
--- a/Projects/UOContent/Spells/Ninjitsu/FocusAttack.cs
+++ b/Projects/UOContent/Spells/Ninjitsu/FocusAttack.cs
@@ -12,7 +12,7 @@ namespace Server.Spells.Ninjitsu
public override bool Validate(Mobile from)
{
- if (from.FindItemOnLayer(Layer.TwoHanded) as BaseShield != null)
+ if (from.FindItemOnLayer(Layer.TwoHanded) is BaseShield)
{
from.SendLocalizedMessage(1063096); // You cannot use this ability while holding a shield.
return false;
@@ -60,4 +60,4 @@ namespace Server.Spells.Ninjitsu
CheckGain(attacker);
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Spells/Second/MagicTrap.cs b/Projects/UOContent/Spells/Second/MagicTrap.cs
index 111cdf090..b338d27dd 100644
--- a/Projects/UOContent/Spells/Second/MagicTrap.cs
+++ b/Projects/UOContent/Spells/Second/MagicTrap.cs
@@ -34,7 +34,7 @@ namespace Server.Spells.Second
}
else if (cont.TrapType != TrapType.None && cont.TrapType != TrapType.MagicTrap)
{
- this.DoFizzle();
+ DoFizzle();
}
else if (CheckSequence())
{
diff --git a/Projects/UOContent/Spells/Second/Protection.cs b/Projects/UOContent/Spells/Second/Protection.cs
index 28e7b34cc..702de0c03 100644
--- a/Projects/UOContent/Spells/Second/Protection.cs
+++ b/Projects/UOContent/Spells/Second/Protection.cs
@@ -131,12 +131,7 @@ namespace Server.Spells.Second
Caster.Skills.Inscribe.Value);
value /= 4;
- if (value < 0)
- value = 0;
- else if (value > 75)
- value = 75.0;
-
- Registry.Add(Caster, value);
+ Registry.Add(Caster, Math.Clamp(value, 0.0, 75.0));
new InternalTimer(Caster).Start();
Caster.FixedParticles(0x375A, 9, 20, 5016, EffectLayer.Waist);
@@ -158,11 +153,7 @@ namespace Server.Spells.Second
public InternalTimer(Mobile caster) : base(TimeSpan.FromSeconds(0))
{
- double val = caster.Skills.Magery.Value * 2.0;
- if (val < 15)
- val = 15;
- else if (val > 240)
- val = 240;
+ double val = Math.Clamp(caster.Skills.Magery.Value * 2.0, 15, 240);
m_Caster = caster;
Delay = TimeSpan.FromSeconds(val);
diff --git a/Projects/UOContent/Spells/Second/RemoveTrap.cs b/Projects/UOContent/Spells/Second/RemoveTrap.cs
index c600aaa26..6083d6d26 100644
--- a/Projects/UOContent/Spells/Second/RemoveTrap.cs
+++ b/Projects/UOContent/Spells/Second/RemoveTrap.cs
@@ -34,7 +34,7 @@ namespace Server.Spells.Second
}
else if (cont.TrapType != TrapType.None && cont.TrapType != TrapType.MagicTrap)
{
- this.DoFizzle();
+ DoFizzle();
}
else if (CheckSequence())
{
diff --git a/Projects/UOContent/Spells/Seventh/ManaVampire.cs b/Projects/UOContent/Spells/Seventh/ManaVampire.cs
index f34bb1d0d..d2aa82aad 100644
--- a/Projects/UOContent/Spells/Seventh/ManaVampire.cs
+++ b/Projects/UOContent/Spells/Seventh/ManaVampire.cs
@@ -1,3 +1,4 @@
+using System;
using Server.Targeting;
namespace Server.Spells.Seventh
@@ -49,11 +50,6 @@ namespace Server.Spells.Seventh
if (!m.Player)
toDrain /= 2;
-
- if (toDrain < 0)
- toDrain = 0;
- else if (toDrain > m.Mana)
- toDrain = m.Mana;
}
else
{
@@ -63,10 +59,7 @@ namespace Server.Spells.Seventh
toDrain = m.Mana;
}
- if (toDrain > Caster.ManaMax - Caster.Mana)
- toDrain = Caster.ManaMax - Caster.Mana;
-
- m.Mana -= toDrain;
+ m.Mana -= Math.Clamp(toDrain, 0, Math.Min(m.Mana, Caster.ManaMax - Caster.Mana));
Caster.Mana += toDrain;
if (Core.AOS)
diff --git a/Projects/UOContent/Spells/Sixth/ParalyzeField.cs b/Projects/UOContent/Spells/Sixth/ParalyzeField.cs
index 1f624823a..87ee2c173 100644
--- a/Projects/UOContent/Spells/Sixth/ParalyzeField.cs
+++ b/Projects/UOContent/Spells/Sixth/ParalyzeField.cs
@@ -169,14 +169,11 @@ namespace Server.Spells.Sixth
if (Core.AOS)
{
- duration = 2.0 + ((int)(m_Caster.Skills.EvalInt.Value / 10) -
- (int)(m.Skills.MagicResist.Value / 10));
+ duration = Math.Max(
+ 2.0 + ((int)(m_Caster.Skills.EvalInt.Value / 10) - (int)(m.Skills.MagicResist.Value / 10)), 0.0);
if (!m.Player)
duration *= 3.0;
-
- if (duration < 0.0)
- duration = 0.0;
}
else
{
diff --git a/Projects/UOContent/Spells/Spellweaving/Mobiles/NatureFury.cs b/Projects/UOContent/Spells/Spellweaving/Mobiles/NatureFury.cs
index b1c97769f..47733453f 100644
--- a/Projects/UOContent/Spells/Spellweaving/Mobiles/NatureFury.cs
+++ b/Projects/UOContent/Spells/Spellweaving/Mobiles/NatureFury.cs
@@ -55,7 +55,7 @@ namespace Server.Mobiles
public override void MoveToWorld(Point3D loc, Map map)
{
base.MoveToWorld(loc, map);
- Timer.DelayCall(TimeSpan.Zero, DoEffects);
+ Timer.DelayCall(DoEffects);
}
public void DoEffects()
@@ -82,4 +82,4 @@ namespace Server.Mobiles
Delete();
}
}
-}
\ No newline at end of file
+}
diff --git a/Projects/UOContent/Spells/Spellweaving/Thunderstorm.cs b/Projects/UOContent/Spells/Spellweaving/Thunderstorm.cs
index 57079fe72..47ded5b4c 100644
--- a/Projects/UOContent/Spells/Spellweaving/Thunderstorm.cs
+++ b/Projects/UOContent/Spells/Spellweaving/Thunderstorm.cs
@@ -33,14 +33,9 @@ namespace Server.Spells.Spellweaving
int sdiBonus = AosAttributes.GetValue(Caster, AosAttribute.SpellDamage);
- int pvmDamage = damage * (100 + sdiBonus);
- pvmDamage /= 100;
+ int pvmDamage = damage * (100 + sdiBonus) / 100;
- if (sdiBonus > 15)
- sdiBonus = 15;
-
- int pvpDamage = damage * (100 + sdiBonus);
- pvpDamage /= 100;
+ int pvpDamage = damage * (100 + Math.Min(sdiBonus, 15)) / 100;
int range = 2 + FocusLevel;
TimeSpan duration = TimeSpan.FromSeconds(5 + FocusLevel);