Code cleanup (#188)

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

View file

@ -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));

View file

@ -53,7 +53,7 @@ namespace Server.Engines.CannedEvil
m_DamageEntries = new Dictionary<Mobile, int>();
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);
}
}

View file

@ -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];

View file

@ -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;

View file

@ -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)

View file

@ -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)

View file

@ -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();
}
}

View file

@ -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)

View file

@ -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;

View file

@ -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)

View file

@ -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)

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
namespace Server.Engines.Craft
{
public static class CraftCollectionExtensions
{
public static int SearchFor(this List<CraftGroup> 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<CraftItem> 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<CraftItem> list, Type type)
{
for (int i = 0; i < list.Count; i++)
{
CraftItem craftItem = list[i];
if (craftItem.ItemType == type) return craftItem;
}
return null;
}
}
}

View file

@ -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<CraftItem>();
}
public CraftItemCol CraftItems { get; }
public List<CraftItem> CraftItems { get; }
public string NameString { get; }
@ -20,4 +22,4 @@ namespace Server.Engines.Craft
CraftItems.Add(craftItem);
}
}
}
}

View file

@ -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;
}
}
}

View file

@ -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<CraftItem> 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<CraftGroup> 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<CraftGroup> 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;

View file

@ -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;

View file

@ -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<CraftRes>();
Skills = new List<CraftSkill>();
ItemType = type;
@ -82,9 +82,9 @@ namespace Server.Engines.Craft
public int NameNumber { get; }
public CraftResCol Resources { get; }
public List<CraftRes> Resources { get; }
public CraftSkillCol Skills { get; }
public List<CraftSkill> 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;

View file

@ -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;
}
}
}

View file

@ -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];
}
}

View file

@ -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];
}
}

View file

@ -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<CraftSubRes>
{
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;
}
}
}
}

View file

@ -23,8 +23,8 @@ namespace Server.Engines.Craft
MaxCraftEffect = maxCraftEffect;
Delay = delay;
CraftItems = new CraftItemCol();
CraftGroups = new CraftGroupCol();
CraftItems = new List<CraftItem>();
CraftGroups = new List<CraftGroup>();
CraftSubRes = new CraftSubResCol();
CraftSubRes2 = new CraftSubResCol();
@ -40,9 +40,9 @@ namespace Server.Engines.Craft
public double Delay { get; }
public CraftItemCol CraftItems { get; }
public List<CraftItem> CraftItems { get; }
public CraftGroupCol CraftGroups { get; }
public List<CraftGroup> 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)

View file

@ -54,11 +54,11 @@ namespace Server.Engines.Craft
foreach (KeyValuePair<int, Recipe> 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!");
}
});
}

View file

@ -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

View file

@ -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.

View file

@ -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.

View file

@ -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;

View file

@ -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 };
}

View file

@ -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))

View file

@ -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]);
}
}
}
}

View file

@ -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;
}

View file

@ -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<Mobile> 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<Mobile> 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);

View file

@ -177,7 +177,7 @@ namespace Server.Factions
if (TimeOfPlacement + decayPeriod < DateTime.UtcNow)
{
Timer.DelayCall(TimeSpan.Zero, Delete);
Timer.DelayCall(Delete);
return true;
}

View file

@ -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);
}
}

View file

@ -193,7 +193,7 @@ namespace Server.Items
int version = reader.ReadEncodedInt();
Timer.DelayCall(TimeSpan.Zero, Refresh);
Timer.DelayCall(Refresh);
}
}
}

View file

@ -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();
}
}
}
}

View file

@ -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));

View file

@ -88,7 +88,7 @@ namespace Server.Engines.Quests.Samurai
int version = reader.ReadEncodedInt();
Timer.DelayCall(TimeSpan.Zero, GenerateTreasure);
Timer.DelayCall(GenerateTreasure);
}
}
}
}

View file

@ -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);
}
}

View file

@ -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; }

View file

@ -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)

View file

@ -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()