Fixes dictionary uses (#7)

This commit is contained in:
Kamron Batman 2018-11-02 08:16:42 -07:00 committed by GitHub
parent d4a52344f2
commit 916d404c51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
161 changed files with 1211 additions and 1722 deletions

View file

@ -79,11 +79,7 @@ namespace Server.Misc
if (a.LoginIPs.Length > 0)
{
IPAddress ip = a.LoginIPs[0];
if (m_IPTable.ContainsKey(ip))
m_IPTable[ip]++;
else
m_IPTable[ip] = 1;
m_IPTable[ip] = (m_IPTable.TryGetValue(ip, out int value) ? value : 0) + 1;
}
}
@ -424,4 +420,4 @@ namespace Server.Misc
return false;
}
}
}
}

View file

@ -91,12 +91,9 @@ namespace Server.Commands
continue;
Type type = obj.GetType();
PropertyInfo[] chain = propertyChains[type];
string failReason = "";
if (chain == null)
if (!propertyChains.TryGetValue(type, out PropertyInfo[] chain))
propertyChains[type] = chain = Properties.GetPropertyInfoChain(e.Mobile, type, bc.Object,
PropertyAccess.Read, ref failReason);

View file

@ -69,9 +69,7 @@ namespace Server.Commands
TypeInfo info = new TypeInfo(type);
m_Types[type] = info;
m_Namespaces.TryGetValue(nspace, out List<TypeInfo> nspaces);
if (nspaces == null)
if (!m_Namespaces.TryGetValue(nspace, out List<TypeInfo> nspaces))
m_Namespaces[nspace] = nspaces = new List<TypeInfo>();
nspaces.Add(info);
@ -682,9 +680,8 @@ namespace Server.Commands
m_Types = new Dictionary<Type, TypeInfo>();
m_Namespaces = new Dictionary<string, List<TypeInfo>>();
List<Assembly> assemblies = new List<Assembly>();
List<Assembly> assemblies = new List<Assembly> { Core.Assembly };
assemblies.Add(Core.Assembly);
foreach (Assembly asm in ScriptCompiler.Assemblies)
assemblies.Add(asm);
@ -1882,9 +1879,7 @@ namespace Server.Commands
lastIndex = index;
table.TryGetValue(index, out SpeechEntry entry);
if (entry == null)
if (!table.TryGetValue(index, out SpeechEntry entry))
table[index] = entry = new SpeechEntry(index);
entry.Strings.Add(text);
@ -1925,12 +1920,12 @@ namespace Server.Commands
public int Compare(DocCommandEntry a, DocCommandEntry b)
{
if (a == null && b == null) return 0;
int v = b?.AccessLevel.CompareTo(a?.AccessLevel) ?? 1;
if (v != 0)
return v;
return a?.Name.CompareTo(b?.Name) ?? 1;
}
}
@ -2290,9 +2285,7 @@ namespace Server.Commands
{
html.Write(" <a ");
m_Types.TryGetValue(parms[j].ParameterType, out TypeInfo typeInfo);
if (typeInfo != null)
if (m_Types.TryGetValue(parms[j].ParameterType, out TypeInfo typeInfo))
html.Write("href=\"types/{0}\" ", typeInfo.FileName);
html.Write("title=\"{0}\">{1}</a>", GetTooltipFor(parms[j]), parms[j].Name);
@ -2732,10 +2725,10 @@ namespace Server.Commands
if (v != 0)
return v;
return a?.Name.CompareTo(b?.Name) ?? 1;
}
}
#endregion
}
}

View file

@ -251,9 +251,7 @@ namespace Server.Commands.Generic
{
if (e.Length >= 1)
{
Commands.TryGetValue(e.GetString(0), out BaseCommand command);
if (command == null)
if (!Commands.TryGetValue(e.GetString(0), out BaseCommand command))
{
e.Mobile.SendMessage(
"That is either an invalid command name or one that does not support this modifier.");
@ -294,4 +292,4 @@ namespace Server.Commands.Generic
impl.Register();
}
}
}
}

View file

@ -99,10 +99,7 @@ namespace Server.Commands
{
Type type = item.GetType();
if (table.ContainsKey(type))
table[type] = 1 + table[type];
else
table[type] = 1;
table[type] = (table.TryGetValue(type, out int value) ? value : 0) + 1;
}
List<KeyValuePair<Type, int>> items = table.ToList();
@ -112,10 +109,7 @@ namespace Server.Commands
{
Type type = m.GetType();
if (table.ContainsKey(type))
table[type] = 1 + table[type];
else
table[type] = 1;
table[type] = (table.TryGetValue(type, out int value) ? value : 0) + 1;
}
List<KeyValuePair<Type, int>> mobiles = table.ToList();
@ -161,10 +155,8 @@ namespace Server.Commands
do
{
typeTable.TryGetValue(itemType, out int[] countTable);
if (countTable == null)
countTable = new int[9];
if (!typeTable.TryGetValue(itemType, out int[] countTable))
typeTable[itemType] = countTable = new int[9];
if ((flags & ExpandFlag.Name) != 0)
++countTable[0];
@ -253,13 +245,13 @@ namespace Server.Commands
++totalCount;
Type type = item.GetType();
int[] parms = table[type];
if (parms == null)
table[type] = parms = new[] { 0, 0 };
parms[0]++;
parms[1] += item.Amount;
if (table.TryGetValue(type, out int[] parms))
{
parms[0]++;
parms[1] += item.Amount;
} else
table[type] = new[] { 1, item.Amount };
}
using (StreamWriter op = new StreamWriter("internal.log"))
@ -319,13 +311,9 @@ namespace Server.Commands
int length = bin.ReadInt32();
Type objType = types[typeID];
while (objType != typeof(object))
while (objType != null && objType != typeof(object))
{
if (table.ContainsKey(objType))
table[objType] = length + table[objType];
else
table[objType] = length;
table[objType] = length + (table.TryGetValue(objType, out int value) ? value : 0);
objType = objType.BaseType;
total += length;
}
@ -362,10 +350,7 @@ namespace Server.Commands
int v = -aCount.CompareTo(bCount);
if (v != 0)
return v;
return x.Key.FullName.CompareTo(y.Key.FullName);
return v != 0 ? v : x.Key.FullName.CompareTo(y.Key.FullName);
}
}
@ -378,10 +363,7 @@ namespace Server.Commands
int v = -aCount.CompareTo(bCount);
if (v != 0)
return v;
return x.Key.FullName.CompareTo(y.Key.FullName);
return v != 0 ? v : x.Key.FullName.CompareTo(y.Key.FullName);
}
}
}

View file

@ -125,16 +125,12 @@ namespace Server
if (itemMap == null || itemMap == Map.Internal)
continue;
Dictionary<Point2D, DeltaState> table = mapTable[itemMap];
if (table == null)
if (!mapTable.TryGetValue(itemMap, out Dictionary<Point2D, DeltaState> table))
mapTable[itemMap] = table = new Dictionary<Point2D, DeltaState>();
Point2D p = new Point2D(item.X >> 3, item.Y >> 3);
DeltaState state = table[p];
if (state == null)
if (!table.TryGetValue(p, out DeltaState state))
table[p] = state = new DeltaState(p);
state.m_List.Add(item);
@ -159,16 +155,12 @@ namespace Server
if (itemMap == null || itemMap == Map.Internal)
continue;
Dictionary<Point2D, DeltaState> table = mapTable[itemMap];
if (table == null)
if (!mapTable.TryGetValue(itemMap, out Dictionary<Point2D, DeltaState> table))
mapTable[itemMap] = table = new Dictionary<Point2D, DeltaState>();
Point2D p = new Point2D(item.X >> 3, item.Y >> 3);
DeltaState state = table[p];
if (state == null)
if (!table.TryGetValue(p, out DeltaState state))
table[p] = state = new DeltaState(p);
state.m_List.Add(item);

View file

@ -953,10 +953,7 @@ namespace Server.Engines.CannedEvil
if (from == null || !from.Player)
return;
if (m_DamageEntries.ContainsKey(from))
m_DamageEntries[from] += amount;
else
m_DamageEntries.Add(from, amount);
m_DamageEntries[from] = amount + (m_DamageEntries.TryGetValue(from, out int value) ? value : 0);
}
public void AwardArtifact(Item artifact)
@ -1073,12 +1070,10 @@ namespace Server.Engines.CannedEvil
case 5:
{
int entries = reader.ReadInt();
Mobile m;
int damage;
for (int i = 0; i < entries; ++i)
{
m = reader.ReadMobile();
damage = reader.ReadInt();
Mobile m = reader.ReadMobile();
int damage = reader.ReadInt();
if (m == null)
continue;
@ -1243,4 +1238,4 @@ namespace Server.Engines.CannedEvil
}
}
}
}
}

View file

@ -117,9 +117,7 @@ namespace Server.Engines.ConPVP
public static void BeginIgnore(Mobile source, Mobile toIgnore)
{
List<IgnoreEntry> list = m_IgnoreLists[source];
if (list == null)
if (!m_IgnoreLists.TryGetValue(source, out List<IgnoreEntry> list))
m_IgnoreLists[source] = list = new List<IgnoreEntry>();
for (int i = 0; i < list.Count; ++i)
@ -141,9 +139,7 @@ namespace Server.Engines.ConPVP
public static bool IsIgnored(Mobile source, Mobile check)
{
List<IgnoreEntry> list = m_IgnoreLists[source];
if (list == null)
if (!m_IgnoreLists.TryGetValue(source, out List<IgnoreEntry> list))
return false;
for (int i = 0; i < list.Count; ++i)
@ -280,4 +276,4 @@ namespace Server.Engines.ConPVP
}
}
}
}
}

View file

@ -1247,7 +1247,7 @@ namespace Server.Engines.ConPVP
if (mob == null)
return null;
if (!(Players[mob] is BRPlayerInfo val))
if (!Players.TryGetValue(mob, out BRPlayerInfo val))
Players[mob] = val = new BRPlayerInfo(this, mob);
return val;

View file

@ -604,7 +604,7 @@ namespace Server.Engines.ConPVP
if (mob == null)
return null;
if (!(Players[mob] is KHPlayerInfo val))
if (!Players.TryGetValue(mob, out KHPlayerInfo val))
Players[mob] = val = new KHPlayerInfo(this, mob);
return val;

View file

@ -269,9 +269,7 @@ namespace Server.Engines.ConPVP
public LadderEntry Find(Mobile mob)
{
LadderEntry entry = m_Table[mob];
if (entry == null)
if (m_Table.TryGetValue(mob, out LadderEntry entry))
{
m_Table[mob] = entry = new LadderEntry(mob, this);
entry.Index = Entries.Count;
@ -283,7 +281,8 @@ namespace Server.Engines.ConPVP
public LadderEntry FindNoCreate(Mobile mob)
{
return m_Table[mob];
m_Table.TryGetValue(mob, out LadderEntry entry);
return entry;
}
public void Serialize(GenericWriter writer)
@ -364,4 +363,4 @@ namespace Server.Engines.ConPVP
writer.WriteEncodedInt(Losses);
}
}
}
}

View file

@ -107,9 +107,7 @@ namespace Server.Engines.ConPVP
public PreferencesEntry Find(Mobile mob)
{
PreferencesEntry entry = m_Table[mob];
if (entry == null)
if (m_Table.TryGetValue(mob, out PreferencesEntry entry))
{
m_Table[mob] = entry = new PreferencesEntry(mob);
Entries.Add(entry);
@ -276,4 +274,4 @@ namespace Server.Engines.ConPVP
m_ColumnX += width;
}
}
}
}

View file

@ -110,50 +110,50 @@ namespace Server.Engines.Craft
public static int ItemIDOf(Type type)
{
if (!_itemIds.TryGetValue(type, out int itemId))
if (_itemIds.TryGetValue(type, out int itemId))
return itemId;
if (type == typeof(FactionExplosionTrap))
itemId = 14034;
else if (type == typeof(FactionGasTrap))
itemId = 4523;
else if (type == typeof(FactionSawTrap))
itemId = 4359;
else if (type == typeof(FactionSpikeTrap)) itemId = 4517;
if (itemId == 0)
{
if (type == typeof(FactionExplosionTrap))
itemId = 14034;
else if (type == typeof(FactionGasTrap))
itemId = 4523;
else if (type == typeof(FactionSawTrap))
itemId = 4359;
else if (type == typeof(FactionSpikeTrap)) itemId = 4517;
object[] attrs = type.GetCustomAttributes(typeof(CraftItemIDAttribute), false);
if (itemId == 0)
if (attrs.Length > 0)
{
object[] attrs = type.GetCustomAttributes(typeof(CraftItemIDAttribute), false);
if (attrs.Length > 0)
{
CraftItemIDAttribute craftItemID = (CraftItemIDAttribute)attrs[0];
itemId = craftItemID.ItemID;
}
CraftItemIDAttribute craftItemID = (CraftItemIDAttribute)attrs[0];
itemId = craftItemID.ItemID;
}
if (itemId == 0)
{
Item item = null;
try
{
item = Activator.CreateInstance(type) as Item;
}
catch
{
// ignored
}
if (item != null)
{
itemId = item.ItemID;
item.Delete();
}
}
_itemIds[type] = itemId;
}
if (itemId == 0)
{
Item item = null;
try
{
item = Activator.CreateInstance(type) as Item;
}
catch
{
// ignored
}
if (item != null)
{
itemId = item.ItemID;
item.Delete();
}
}
_itemIds[type] = itemId;
return itemId;
}
@ -1248,4 +1248,4 @@ namespace Server.Engines.Craft
#endregion
}
}
}

View file

@ -81,9 +81,7 @@ namespace Server.Engines.Craft
return null;
}
m_ContextTable.TryGetValue(m, out CraftContext c);
if (c == null)
if (!m_ContextTable.TryGetValue(m, out CraftContext c))
m_ContextTable[m] = c = new CraftContext();
return c;
@ -91,9 +89,7 @@ namespace Server.Engines.Craft
public void OnMade(Mobile m, CraftItem item)
{
CraftContext c = GetContext(m);
c?.OnMade(item);
GetContext(m)?.OnMade(item);
}
public virtual bool ConsumeOnFailure(Mobile from, Type resourceType, CraftItem craftItem)
@ -104,8 +100,8 @@ namespace Server.Engines.Craft
public void CreateItem(Mobile from, Type type, Type typeRes, BaseTool tool, CraftItem realCraftItem)
{
// Verify if the type is in the list of the craftable item
CraftItem craftItem = CraftItems.SearchFor(type);
if (craftItem != null) realCraftItem.Craft(from, this, typeRes, tool);
if (CraftItems.SearchFor(type) != null)
realCraftItem.Craft(from, this, typeRes, tool);
}
public int RandomRecipe()
@ -359,4 +355,4 @@ namespace Server.Engines.Craft
public abstract int CanCraft(Mobile from, BaseTool tool, Type itemType);
}
}
}

View file

@ -5,11 +5,6 @@ namespace Server.Engines.Harvest
{
public class HarvestDefinition
{
public HarvestDefinition()
{
Banks = new Dictionary<Map, Dictionary<Point2D, HarvestBank>>();
}
public int BankWidth{ get; set; }
public int BankHeight{ get; set; }
@ -70,7 +65,8 @@ namespace Server.Engines.Harvest
public bool RandomizeVeins{ get; set; }
public Dictionary<Map, Dictionary<Point2D, HarvestBank>> Banks{ get; set; }
public Dictionary<Map, Dictionary<Point2D, HarvestBank>> Banks{ get; }
= new Dictionary<Map, Dictionary<Point2D, HarvestBank>>();
public void SendMessageTo(Mobile from, object message)
{
@ -88,15 +84,12 @@ namespace Server.Engines.Harvest
x /= BankWidth;
y /= BankHeight;
Banks.TryGetValue(map, out Dictionary<Point2D, HarvestBank> banks);
if (banks == null)
if (!Banks.TryGetValue(map, out Dictionary<Point2D, HarvestBank> banks))
Banks[map] = banks = new Dictionary<Point2D, HarvestBank>();
Point2D key = new Point2D(x, y);
banks.TryGetValue(key, out HarvestBank bank);
if (bank == null)
if (!banks.TryGetValue(key, out HarvestBank bank))
banks[key] = bank = new HarvestBank(this, GetVeinAt(map, x, y));
return bank;
@ -178,4 +171,4 @@ namespace Server.Engines.Harvest
return dist == 0;
}
}
}
}

View file

@ -199,9 +199,7 @@ namespace Server.Engines.Help
[Description("Opens the page queue menu.")]
private static void Pages_OnCommand(CommandEventArgs e)
{
PageEntry entry = (PageEntry)m_KeyedByHandler[e.Mobile];
if (entry != null)
if (m_KeyedByHandler.TryGetValue(e.Mobile, out PageEntry entry))
e.Mobile.SendGump(new PageEntryGump(e.Mobile, entry));
else if (List.Count > 0)
e.Mobile.SendGump(new PageQueueGump());
@ -224,11 +222,6 @@ namespace Server.Engines.Help
return List.IndexOf(e);
}
public static void Cancel(Mobile sender)
{
Remove((PageEntry)m_KeyedBySender[sender]);
}
public static void Remove(PageEntry e)
{
if (e == null)
@ -245,7 +238,8 @@ namespace Server.Engines.Help
public static PageEntry GetEntry(Mobile sender)
{
return (PageEntry)m_KeyedBySender[sender];
m_KeyedBySender.TryGetValue(sender, out PageEntry entry);
return entry;
}
public static void Remove(Mobile sender)
@ -285,9 +279,10 @@ namespace Server.Engines.Help
Mobile sender = entry.Sender;
DateTime time = DateTime.UtcNow;
MailMessage mail = new MailMessage(Email.FromAddress, Email.SpeechLogPageAddresses);
mail.Subject = "RunUO Speech Log Page Forwarding";
MailMessage mail = new MailMessage(Email.FromAddress, Email.SpeechLogPageAddresses)
{
Subject = "RunUO Speech Log Page Forwarding"
};
using (StringWriter writer = new StringWriter())
{

View file

@ -108,7 +108,7 @@ namespace Server.Engines.MLQuests.Gumps
private static void Timeout(NetState ns)
{
if (m_Pending.ContainsKey(ns))
if (IsPending(ns))
{
m_Pending.Remove(ns);
ns.Send(CloseRaceChanger.Instance);
@ -339,4 +339,4 @@ namespace Server.Engines.MLQuests.Gumps
}
#endregion
}
}

View file

@ -26,12 +26,7 @@ namespace Server.Engines.MLQuests
object[] attributes = t.GetCustomAttributes(m_Type, false);
if (attributes.Length != 0)
result = ((QuesterNameAttribute)attributes[0]).QuesterName;
else
result = t.Name;
return m_Cache[t] = result;
return m_Cache[t] = attributes.Length != 0 ? ((QuesterNameAttribute)attributes[0]).QuesterName : t.Name;
}
}
}
}

View file

@ -17,8 +17,7 @@ namespace Server.Engines.PartySystem
public static void Start(Mobile m, Mobile leader)
{
DeclineTimer t = m_Table[m];
m_Table.TryGetValue(m, out DeclineTimer t);
t?.Stop();
m_Table[m] = t = new DeclineTimer(m, leader);

View file

@ -87,12 +87,13 @@ namespace Server.Items
private static OrangePetalsContext GetContext(Mobile m)
{
return m_Table[m] as OrangePetalsContext;
m_Table.TryGetValue(m, out OrangePetalsContext context);
return context;
}
public static bool UnderEffect(Mobile m)
{
return GetContext(m) != null;
return m_Table.ContainsKey(m);
}
public override void Serialize(GenericWriter writer)

View file

@ -43,27 +43,29 @@ namespace Server.Engines.Plants
static PlantHueInfo()
{
m_Table = new Dictionary<PlantHue, PlantHueInfo>();
m_Table = new Dictionary<PlantHue, PlantHueInfo>
{
[PlantHue.Plain] = new PlantHueInfo(0, 1060813, PlantHue.Plain, 0x835),
[PlantHue.Red] = new PlantHueInfo(0x66D, 1060814, PlantHue.Red, 0x24),
[PlantHue.Blue] = new PlantHueInfo(0x53D, 1060815, PlantHue.Blue, 0x6),
[PlantHue.Yellow] = new PlantHueInfo(0x8A5, 1060818, PlantHue.Yellow, 0x38),
[PlantHue.BrightRed] = new PlantHueInfo(0x21, 1060814, PlantHue.BrightRed, 0x21),
[PlantHue.BrightBlue] = new PlantHueInfo(0x5, 1060815, PlantHue.BrightBlue, 0x6),
[PlantHue.BrightYellow] = new PlantHueInfo(0x38, 1060818, PlantHue.BrightYellow, 0x35),
[PlantHue.Purple] = new PlantHueInfo(0xD, 1060816, PlantHue.Purple, 0x10),
[PlantHue.Green] = new PlantHueInfo(0x59B, 1060819, PlantHue.Green, 0x42),
[PlantHue.Orange] = new PlantHueInfo(0x46F, 1060817, PlantHue.Orange, 0x2E),
[PlantHue.BrightPurple] = new PlantHueInfo(0x10, 1060816, PlantHue.BrightPurple, 0xD),
[PlantHue.BrightGreen] = new PlantHueInfo(0x42, 1060819, PlantHue.BrightGreen, 0x3F),
[PlantHue.BrightOrange] = new PlantHueInfo(0x2B, 1060817, PlantHue.BrightOrange, 0x2B),
[PlantHue.Black] = new PlantHueInfo(0x455, 1060820, PlantHue.Black, 0),
[PlantHue.White] = new PlantHueInfo(0x481, 1060821, PlantHue.White, 0x481),
[PlantHue.Pink] = new PlantHueInfo(0x48E, 1061854, PlantHue.Pink),
[PlantHue.Magenta] = new PlantHueInfo(0x486, 1061852, PlantHue.Magenta),
[PlantHue.Aqua] = new PlantHueInfo(0x495, 1061853, PlantHue.Aqua),
[PlantHue.FireRed] = new PlantHueInfo(0x489, 1061855, PlantHue.FireRed)
};
m_Table[PlantHue.Plain] = new PlantHueInfo(0, 1060813, PlantHue.Plain, 0x835);
m_Table[PlantHue.Red] = new PlantHueInfo(0x66D, 1060814, PlantHue.Red, 0x24);
m_Table[PlantHue.Blue] = new PlantHueInfo(0x53D, 1060815, PlantHue.Blue, 0x6);
m_Table[PlantHue.Yellow] = new PlantHueInfo(0x8A5, 1060818, PlantHue.Yellow, 0x38);
m_Table[PlantHue.BrightRed] = new PlantHueInfo(0x21, 1060814, PlantHue.BrightRed, 0x21);
m_Table[PlantHue.BrightBlue] = new PlantHueInfo(0x5, 1060815, PlantHue.BrightBlue, 0x6);
m_Table[PlantHue.BrightYellow] = new PlantHueInfo(0x38, 1060818, PlantHue.BrightYellow, 0x35);
m_Table[PlantHue.Purple] = new PlantHueInfo(0xD, 1060816, PlantHue.Purple, 0x10);
m_Table[PlantHue.Green] = new PlantHueInfo(0x59B, 1060819, PlantHue.Green, 0x42);
m_Table[PlantHue.Orange] = new PlantHueInfo(0x46F, 1060817, PlantHue.Orange, 0x2E);
m_Table[PlantHue.BrightPurple] = new PlantHueInfo(0x10, 1060816, PlantHue.BrightPurple, 0xD);
m_Table[PlantHue.BrightGreen] = new PlantHueInfo(0x42, 1060819, PlantHue.BrightGreen, 0x3F);
m_Table[PlantHue.BrightOrange] = new PlantHueInfo(0x2B, 1060817, PlantHue.BrightOrange, 0x2B);
m_Table[PlantHue.Black] = new PlantHueInfo(0x455, 1060820, PlantHue.Black, 0);
m_Table[PlantHue.White] = new PlantHueInfo(0x481, 1060821, PlantHue.White, 0x481);
m_Table[PlantHue.Pink] = new PlantHueInfo(0x48E, 1061854, PlantHue.Pink);
m_Table[PlantHue.Magenta] = new PlantHueInfo(0x486, 1061852, PlantHue.Magenta);
m_Table[PlantHue.Aqua] = new PlantHueInfo(0x495, 1061853, PlantHue.Aqua);
m_Table[PlantHue.FireRed] = new PlantHueInfo(0x489, 1061855, PlantHue.FireRed);
}
private PlantHueInfo(int hue, int name, PlantHue plantHue) : this(hue, name, plantHue, hue)
@ -88,9 +90,7 @@ namespace Server.Engines.Plants
public static PlantHueInfo GetInfo(PlantHue plantHue)
{
if (m_Table.TryGetValue(plantHue, out PlantHueInfo info))
return info;
return m_Table[PlantHue.Plain];
return m_Table.TryGetValue(plantHue, out PlantHueInfo info) ? info : m_Table[PlantHue.Plain];
}
public static PlantHue RandomFirstGeneration()
@ -181,4 +181,4 @@ namespace Server.Engines.Plants
return IsPrimary(PlantHue);
}
}
}
}

View file

@ -118,14 +118,14 @@ namespace Server.Engines.Quests.Necro
public override void CheckProgress()
{
if (System.From.Map == Map.Malas && System.From.InRange(new Point3D(1076, 450, -84), 5))
if (SummonFamiliarSpell.Table[System.From] is HordeMinionFamiliar hmf && hmf.InRange(System.From, 5) &&
hmf.TargetLocation == null)
{
System.From.SendLocalizedMessage(
1060113); // You instinctively will your familiar to fetch the scroll for you.
hmf.TargetLocation = new Point2D(1076, 450);
}
if (System.From.Map != Map.Malas || !System.From.InRange(new Point3D(1076, 450, -84), 5) ||
!SummonFamiliarSpell.Table.TryGetValue(System.From, out BaseCreature bc) || !(bc is HordeMinionFamiliar hmf) ||
!hmf.InRange(System.From, 5) || hmf.TargetLocation != null)
return;
System.From.SendLocalizedMessage(
1060113); // You instinctively will your familiar to fetch the scroll for you.
hmf.TargetLocation = new Point2D(1076, 450);
}
public override void OnComplete()
@ -376,4 +376,4 @@ namespace Server.Engines.Quests.Necro
System.AddConversation(new BankerConversation());
}
}
}
}

View file

@ -45,7 +45,7 @@ namespace Server.Engines.Reports
if (string.IsNullOrEmpty(account))
return null;
if (!(StaffInfo[account] is StaffInfo info))
if (!StaffInfo.TryGetValue(account, out StaffInfo info))
StaffInfo[account] = info = new StaffInfo(account);
return info;
@ -57,7 +57,7 @@ namespace Server.Engines.Reports
if (string.IsNullOrEmpty(account))
return null;
if (!(UserInfo[account] is UserInfo info))
if (!UserInfo.TryGetValue(account, out UserInfo info))
UserInfo[account] = info = new UserInfo(account);
return info;

View file

@ -32,7 +32,8 @@ namespace Server.Engines.Reports
public static PersistableType Find(string name)
{
return m_Table[name];
m_Table.TryGetValue(name, out PersistableType value);
return value;
}
public static void Register(PersistableType type)

View file

@ -209,12 +209,7 @@ namespace Server.Mobiles
false);
}
public SpawnerEntry AddEntry(string creaturename, int probability, int amount)
{
return AddEntry(creaturename, probability, amount, true);
}
public SpawnerEntry AddEntry(string creaturename, int probability, int amount, bool dotimer)
public SpawnerEntry AddEntry(string creaturename, int probability, int amount, bool dotimer = true)
{
SpawnerEntry entry = new SpawnerEntry(creaturename, probability, amount);
Entries.Add(entry);
@ -356,7 +351,7 @@ namespace Server.Mobiles
if (Entries.Count <= 0 || IsFull)
return;
int probsum = 0;
for (int i = 0; i < Entries.Count; i++)
@ -365,7 +360,7 @@ namespace Server.Mobiles
if (probsum <= 0)
return;
int rand = Utility.RandomMinMax(1, probsum);
for (int i = 0; i < Entries.Count; i++)
@ -639,7 +634,7 @@ namespace Server.Mobiles
{
int x = Location.X + (Utility.Random(m_HomeRange * 2 + 1) - m_HomeRange);
int y = Location.Y + (Utility.Random(m_HomeRange * 2 + 1) - m_HomeRange);
int mapZ = map.GetAverageZ(x, y);
if (waterMob)
@ -1221,4 +1216,4 @@ namespace Server.Mobiles
}
}
}
}
}

View file

@ -77,9 +77,7 @@ namespace Server
return;
}
m_Callbacks.TryGetValue(e.GumpID, out OnVirtueUsed callback);
if (callback != null)
if (m_Callbacks.TryGetValue(e.GumpID, out OnVirtueUsed callback))
callback(e.Beholder);
else
e.Beholder.SendLocalizedMessage(1052066); // That virtue is not active yet.
@ -180,4 +178,4 @@ namespace Server
}
}
}
}
}

View file

@ -181,9 +181,7 @@ namespace Server.Gumps
else
tree = Tokuno;
tree.LastBranch.TryGetValue(from, out ParentNode branch);
if (branch == null)
if (!tree.LastBranch.TryGetValue(from, out ParentNode branch))
branch = tree.Root;
if (branch != null)
@ -236,4 +234,4 @@ namespace Server.Gumps
}
}
}
}
}

View file

@ -15,9 +15,7 @@ namespace Server.Gumps
if (File.Exists(path))
{
XmlTextReader xml = new XmlTextReader(new StreamReader(path));
xml.WhitespaceHandling = WhitespaceHandling.None;
XmlTextReader xml = new XmlTextReader(new StreamReader(path)) { WhitespaceHandling = WhitespaceHandling.None };
Root = Parse(xml);
@ -40,4 +38,4 @@ namespace Server.Gumps
return new ParentNode(xml, null);
}
}
}
}

View file

@ -250,10 +250,8 @@ namespace Server.Engines.Events
{
if ( m_DeadPlayer != null && !m_DeadPlayer.Deleted )
{
if ( HalloweenHauntings.ReAnimated.Count > 0 && HalloweenHauntings.ReAnimated.ContainsKey( m_DeadPlayer ) )
{
if ( HalloweenHauntings.ReAnimated.ContainsKey( m_DeadPlayer ) )
HalloweenHauntings.ReAnimated.Remove( m_DeadPlayer );
}
}
}
}
@ -261,7 +259,7 @@ namespace Server.Engines.Events
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( ( int )0 );
writer.Write( 0 );
writer.WriteMobile( m_DeadPlayer );
}
@ -271,7 +269,7 @@ namespace Server.Engines.Events
base.Deserialize( reader );
int version = reader.ReadInt();
m_DeadPlayer = ( PlayerMobile )reader.ReadMobile();
m_DeadPlayer = reader.ReadMobile<PlayerMobile>();
}
}
}

View file

@ -95,9 +95,7 @@ namespace Server.Items
if ( m_Entries == null )
m_Entries = new Dictionary<Mobile, ScoreEntry>();
ScoreEntry e = m_Entries[from];
if ( e == null )
if (!m_Entries.TryGetValue(from, out ScoreEntry e))
m_Entries[from] = e = new ScoreEntry();
return e;

View file

@ -1529,7 +1529,7 @@ namespace Server.Items
!(nearest is Cobbler && mob is Provisioner))
continue;
if (m_AcquireTable[mob.GetType()] is FillableContent check)
if (m_AcquireTable.TryGetValue(mob.GetType(), out FillableContent check))
{
nearest = mob;
content = check;

View file

@ -390,9 +390,7 @@ namespace Server.Items
public static void Close(Container c)
{
m_Table.TryGetValue(c, out Timer t);
if (t != null)
if (m_Table.TryGetValue(c, out Timer t))
{
t.Stop();
m_Table.Remove(c);
@ -436,4 +434,4 @@ namespace Server.Items
DynamicFurniture.Close(m_Container);
}
}
}
}

View file

@ -219,7 +219,11 @@ namespace Server.Items
public static StealableInstance GetStealableInstance(Item item)
{
return (StealableInstance)Instance?.m_Table[item];
if (Instance == null)
return null;
Instance.m_Table.TryGetValue(item, out StealableInstance value);
return value;
}
public override void OnDelete()

View file

@ -1106,30 +1106,23 @@ namespace Server.Items
{
if (from.BAC > 0 && from.Map != Map.Internal && !from.Deleted)
{
Timer t = m_Table[from];
if (m_Table.ContainsKey(from))
return;
if (t == null)
{
if (from.BAC > 60)
from.BAC = 60;
if (from.BAC > 60)
from.BAC = 60;
t = new HeaveTimer(from);
t.Start();
Timer t = new HeaveTimer(from);
t.Start();
m_Table[from] = t;
}
m_Table[from] = t;
}
else
else if (m_Table.TryGetValue(from, out Timer t))
{
Timer t = m_Table[from];
t.Stop();
m_Table.Remove(from);
if (t != null)
{
t.Stop();
m_Table.Remove(from);
from.SendLocalizedMessage(500850); // You feel sober.
}
from.SendLocalizedMessage(500850); // You feel sober.
}
}

View file

@ -342,9 +342,9 @@ namespace Server.Items
if (!m.Player || m.AccessLevel > AccessLevel.Player) //Staff and creatures not subject to instancing.
return true;
if (m_InstancedItems != null)
if (m_InstancedItems.TryGetValue(child, out InstancedItemInfo info) && (InstancedCorpse || info.Perpetual))
return info.IsOwner(m); //IsOwner checks Party stuff.
if (m_InstancedItems != null && m_InstancedItems.TryGetValue(child, out InstancedItemInfo info)
&& (InstancedCorpse || info.Perpetual))
return info.IsOwner(m); //IsOwner checks Party stuff.
return true;
}
@ -495,7 +495,7 @@ namespace Server.Items
c = new Corpse(owner, hair, facialhair, equipItems);
owner.Corpse = c;
for (int i = 0; i < initialContent.Count; ++i)
{
Item item = initialContent[i];
@ -830,7 +830,7 @@ namespace Server.Items
if (!Looters.Contains(from))
Looters.Add(from);
if (m_InstancedItems != null && m_InstancedItems.ContainsKey(item))
if (m_InstancedItems?.ContainsKey(item) == true)
m_InstancedItems.Remove(item);
}
@ -847,7 +847,7 @@ namespace Server.Items
if (!Looters.Contains(from))
Looters.Add(from);
if (m_InstancedItems != null && m_InstancedItems.ContainsKey(item))
if (m_InstancedItems?.ContainsKey(item) == true)
m_InstancedItems.Remove(item);
}
@ -891,12 +891,7 @@ namespace Server.Items
if (!IsCriminalAction(from))
return true;
Map map = Map;
if (map == null || (map.Rules & MapRules.HarmfulRestrictions) != 0)
return false;
return true;
return Map != null && (Map.Rules & MapRules.HarmfulRestrictions) == 0;
}
public bool CheckLoot(Mobile from, Item item)
@ -1194,4 +1189,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -58,7 +58,7 @@ namespace Server.Items
{
private static readonly TimeSpan m_UseTimeout = TimeSpan.FromMinutes(2.0);
private Dictionary<Mobile, DamageTimer> m_DamageTable = new Dictionary<Mobile, DamageTimer>();
private HashSet<Mobile> m_DamageTable = new HashSet<Mobile>();
private DateTime m_LastUse;
private int m_SideLength;
@ -217,12 +217,12 @@ namespace Server.Items
if (!to.Alive)
return;
if (m_DamageTable[to] == null)
if (!m_DamageTable.Contains(to))
{
to.Frozen = true;
DamageTimer timer = new DamageTimer(this, to);
m_DamageTable[to] = timer;
m_DamageTable.Add(to);
timer.Start();
}

View file

@ -690,7 +690,7 @@ namespace Server.Items
m.SendLocalizedMessage(ProgressNumber);
if (ShowTimeRemaining)
m.SendMessage("Time remaining: {0}", FormatTime(m_Table[m].Timer.Next - DateTime.UtcNow));
m.SendMessage("Time remaining: {0}", FormatTime(info.Timer.Next - DateTime.UtcNow));
Timer.DelayCall(TimeSpan.FromSeconds(5), EndLock, m);
}
@ -764,19 +764,12 @@ namespace Server.Items
private Dictionary<Mobile, Timer> m_Teleporting;
[Constructible]
public TimeoutTeleporter()
: this(new Point3D(0, 0, 0), null, false)
public TimeoutTeleporter() : this(new Point3D(0, 0, 0))
{
}
[Constructible]
public TimeoutTeleporter(Point3D pointDest, Map mapDest)
: this(pointDest, mapDest, false)
{
}
[Constructible]
public TimeoutTeleporter(Point3D pointDest, Map mapDest, bool creatures)
public TimeoutTeleporter(Point3D pointDest, Map mapDest = null, bool creatures = false)
: base(pointDest, mapDest, creatures)
{
m_Teleporting = new Dictionary<Mobile, Timer>();
@ -1195,4 +1188,4 @@ namespace Server.Items
DeadOnly = 0x100
}
}
}
}

View file

@ -46,7 +46,7 @@ namespace Server.Items
{
CampfireEntry entry = Campfire.GetEntry(from);
if (entry != null && entry.Safe)
if (entry?.Safe == true)
from.SendGump(new LogoutGump(entry, this));
}
}
@ -127,4 +127,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -86,7 +86,8 @@ namespace Server.Items
public static CampfireEntry GetEntry(Mobile player)
{
return m_Table[player];
m_Table.TryGetValue(player, out CampfireEntry value);
return value;
}
public static void RemoveEntry(CampfireEntry entry)
@ -195,4 +196,4 @@ namespace Server.Items
set => m_Safe = value;
}
}
}
}

View file

@ -288,14 +288,14 @@ namespace Server.Items
public static void AddDelay(Mobile m)
{
m_Delay[m]?.Stop();
m_Delay.TryGetValue(m, out Timer timer);
timer?.Stop();
m_Delay[m] = Timer.DelayCall(TimeSpan.FromSeconds(30), EndDelay, m);
}
public static int GetDelay(Mobile m)
{
Timer timer = m_Delay[m];
if (timer?.Next > DateTime.UtcNow)
if (m_Delay.TryGetValue(m, out Timer timer) && timer.Next > DateTime.UtcNow)
return (int)(timer.Next - DateTime.UtcNow).TotalSeconds;
return 0;
@ -303,9 +303,7 @@ namespace Server.Items
public static void EndDelay(Mobile m)
{
Timer timer = m_Delay[m];
if (timer != null)
if (m_Delay.TryGetValue(m, out Timer timer))
{
timer.Stop();
m_Delay.Remove(m);

View file

@ -153,14 +153,14 @@ namespace Server.Items
public static void AddDelay(Mobile m)
{
m_Delay[m]?.Stop();
m_Delay.TryGetValue(m, out Timer timer);
timer?.Stop();
m_Delay[m] = Timer.DelayCall(TimeSpan.FromSeconds(60), EndDelay, m);
}
public static int GetDelay(Mobile m)
{
Timer timer = m_Delay[m];
if (timer?.Next > DateTime.UtcNow)
if (m_Delay.TryGetValue(m, out Timer timer) && timer.Next > DateTime.UtcNow)
return (int)(timer.Next - DateTime.UtcNow).TotalSeconds;
return 0;
@ -168,8 +168,7 @@ namespace Server.Items
public static void EndDelay(Mobile m)
{
Timer timer = m_Delay[m];
if (timer != null)
if (m_Delay.TryGetValue(m, out Timer timer))
{
timer.Stop();
m_Delay.Remove(m);

View file

@ -63,26 +63,20 @@ namespace Server.Items
public static bool HasTimer(Mobile m)
{
return m_Table[m] != null;
return m_Table.ContainsKey(m);
}
public static void RemoveTimer(Mobile m)
public static void RemoveTimer(Mobile m, bool interrupted = false)
{
Timer timer = m_Table[m];
if (timer != null)
if (m_Table.TryGetValue(m, out Timer timer))
{
if (interrupted)
m.SendLocalizedMessage(1073187); // The invisibility effect is interrupted.
timer.Stop();
m_Table.Remove(m);
}
}
public static void Iterrupt(Mobile m)
{
m.SendLocalizedMessage(1073187); // The invisibility effect is interrupted.
RemoveTimer(m);
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);

View file

@ -435,11 +435,9 @@ namespace Server.Items
return null;
}
m_Table.TryGetValue(from, out List<Spellbook> list);
bool searchAgain = false;
if (list == null)
if (!m_Table.TryGetValue(from, out List<Spellbook> list))
m_Table[from] = list = FindAllSpellbooks(from);
else
searchAgain = true;
@ -911,4 +909,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -42,10 +42,8 @@ namespace Server.Items
{
get
{
if (Recipe.Recipes.ContainsKey(m_RecipeID))
return Recipe.Recipes[m_RecipeID];
return null;
Recipe.Recipes.TryGetValue(m_RecipeID, out Recipe recipe);
return recipe;
}
}
@ -121,4 +119,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -203,12 +203,8 @@ namespace Server.Items
public static BaseInstrument GetInstrument(Mobile from)
{
BaseInstrument item = m_Instruments[from];
if (item == null)
return null;
if (item.IsChildOf(from.Backpack))
return item;
if (m_Instruments.TryGetValue(from, out BaseInstrument instrument) && instrument.IsChildOf(from.Backpack))
return instrument;
m_Instruments.Remove(from);
return null;
@ -222,7 +218,6 @@ namespace Server.Items
public static void PickInstrument(Mobile from, InstrumentPickedCallback callback)
{
BaseInstrument instrument = GetInstrument(from);
if (instrument != null)
{
callback?.Invoke(from, instrument);
@ -531,7 +526,7 @@ namespace Server.Items
{
SetInstrument(from, this);
// Delay of 7 second before beign able to play another instrument again
// Delay of 7 second before being able to play another instrument again
new InternalTimer(from).Start();
if (CheckMusicianship(from))

View file

@ -65,7 +65,7 @@ namespace Server.Items
ConsumeUse(weapon);
if (CombatCheck(from, target))
Timer.DelayCall(TimeSpan.FromSeconds(1.0), OnHit, new object[] { from, target, weapon });
Timer.DelayCall(TimeSpan.FromSeconds(1.0), () => OnHit(from, target, weapon));
Timer.DelayCall(TimeSpan.FromSeconds(2.5), ResetUsing, from);
}
@ -187,15 +187,15 @@ namespace Server.Items
BaseWeapon defWeapon = defender.Weapon as BaseWeapon;
Skill atkSkill = defender.Skills.Ninjitsu;
Skill defSkill = defender.Skills[defWeapon.Skill];
// Skill defSkill = defender.Skills[defWeapon.Skill];
double atSkillValue = attacker.Skills.Ninjitsu.Value;
double defSkillValue = defWeapon.GetDefendSkillValue(attacker, defender);
double attackValue = AosAttributes.GetValue(attacker, AosAttribute.AttackChance);
double defSkillValue = defWeapon?.GetDefendSkillValue(attacker, defender) ?? 0.0;
if (defSkillValue <= -20.0) defSkillValue = -19.9;
double attackValue = AosAttributes.GetValue(attacker, AosAttribute.AttackChance);
if (DivineFurySpell.UnderEffect(attacker)) attackValue += 10;
if (AnimalForm.UnderTransformation(attacker, typeof(GreyWolf)) ||
@ -230,29 +230,24 @@ namespace Server.Items
return attacker.CheckSkill(atkSkill.SkillName, chance);
}
private static void OnHit(object[] states)
private static void OnHit(Mobile from, Mobile target, INinjaWeapon weapon)
{
Mobile from = states[0] as Mobile;
Mobile target = states[1] as Mobile;
INinjaWeapon weapon = states[2] as INinjaWeapon;
if (!from.CanBeHarmful(target))
return;
from.DoHarmful(target);
if (from.CanBeHarmful(target))
AOS.Damage(target, from, weapon.WeaponDamage, 100, 0, 0, 0, 0);
if (weapon.Poison != null && weapon.PoisonCharges > 0)
{
from.DoHarmful(target);
if (EvilOmenSpell.TryEndEffect(target))
target.ApplyPoison(from, Poison.GetPoison(weapon.Poison.Level + 1));
else
target.ApplyPoison(from, weapon.Poison);
AOS.Damage(target, from, weapon.WeaponDamage, 100, 0, 0, 0, 0);
weapon.PoisonCharges--;
if (weapon.Poison != null && weapon.PoisonCharges > 0)
{
if (EvilOmenSpell.TryEndEffect(target))
target.ApplyPoison(from, Poison.GetPoison(weapon.Poison.Level + 1));
else
target.ApplyPoison(from, weapon.Poison);
weapon.PoisonCharges--;
if (weapon.PoisonCharges < 1) weapon.Poison = null;
}
if (weapon.PoisonCharges < 1) weapon.Poison = null;
}
}
@ -314,4 +309,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -259,15 +259,13 @@ namespace Server.Items
public static void CreateTimer(Mobile m, TimeSpan delay)
{
if (m != null)
if (!Timers.ContainsKey(m))
Timers[m] = new InternalTimer(m, delay);
if (m != null && !IsDisguised(m))
Timers[m] = new InternalTimer(m, delay);
}
public static void StartTimer(Mobile m)
{
Timers.TryGetValue(m, out Timer t);
t?.Start();
}
@ -276,43 +274,31 @@ namespace Server.Items
return Timers.ContainsKey(m);
}
public static bool StopTimer(Mobile m)
public static void StopTimer(Mobile m)
{
Timers.TryGetValue(m, out Timer t);
if (!Timers.TryGetValue(m, out Timer t))
return;
if (t != null)
{
TimeSpan ts = t.Next - DateTime.UtcNow;
if (ts < TimeSpan.Zero)
ts = TimeSpan.Zero;
TimeSpan ts = t.Next - DateTime.UtcNow;
if (ts < TimeSpan.Zero)
ts = TimeSpan.Zero;
t.Delay = ts;
t.Stop();
}
return t != null;
t.Delay = ts;
t.Stop();
}
public static bool RemoveTimer(Mobile m)
public static void RemoveTimer(Mobile m)
{
Timers.TryGetValue(m, out Timer t);
if (t != null)
if (Timers.TryGetValue(m, out Timer t))
{
t.Stop();
Timers.Remove(m);
}
return t != null;
}
public static TimeSpan TimeRemaining(Mobile m)
{
Timers.TryGetValue(m, out Timer t);
if (t != null) return t.Next - DateTime.UtcNow;
return TimeSpan.Zero;
return Timers.TryGetValue(m, out Timer t) ? t.Next - DateTime.UtcNow : TimeSpan.Zero;
}
private class InternalTimer : Timer
@ -336,4 +322,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -20,7 +20,7 @@ namespace Server.Items
[Flippable(0x2AF9, 0x2AFD)]
public class DawnsMusicBox : Item, ISecurable
{
private static Dictionary<MusicName, DawnsMusicInfo> m_Info = new Dictionary<MusicName, DawnsMusicInfo>();
private static Dictionary<MusicName, DawnsMusicInfo> m_Info;
public static MusicName[] m_CommonTracks =
{
@ -231,76 +231,78 @@ namespace Server.Items
public static void Initialize()
{
m_Info.Add(MusicName.Samlethe, new DawnsMusicInfo(1075152, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Sailing, new DawnsMusicInfo(1075163, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Britain2, new DawnsMusicInfo(1075145, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Britain1, new DawnsMusicInfo(1075144, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Bucsden, new DawnsMusicInfo(1075146, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Forest_a, new DawnsMusicInfo(1075161, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Cove, new DawnsMusicInfo(1075176, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Death, new DawnsMusicInfo(1075171, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Dungeon9, new DawnsMusicInfo(1075160, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Dungeon2, new DawnsMusicInfo(1075175, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Cave01, new DawnsMusicInfo(1075159, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Combat3, new DawnsMusicInfo(1075170, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Combat1, new DawnsMusicInfo(1075168, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Combat2, new DawnsMusicInfo(1075169, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Jhelom, new DawnsMusicInfo(1075147, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Linelle, new DawnsMusicInfo(1075185, DawnsMusicRarity.Common));
m_Info.Add(MusicName.LBCastle, new DawnsMusicInfo(1075148, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Minoc, new DawnsMusicInfo(1075150, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Moonglow, new DawnsMusicInfo(1075177, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Magincia, new DawnsMusicInfo(1075149, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Nujelm, new DawnsMusicInfo(1075174, DawnsMusicRarity.Common));
m_Info.Add(MusicName.BTCastle, new DawnsMusicInfo(1075173, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Tavern04, new DawnsMusicInfo(1075167, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Skarabra, new DawnsMusicInfo(1075154, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Stones2, new DawnsMusicInfo(1075143, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Serpents, new DawnsMusicInfo(1075153, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Taiko, new DawnsMusicInfo(1075180, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Tavern01, new DawnsMusicInfo(1075164, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Tavern02, new DawnsMusicInfo(1075165, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Tavern03, new DawnsMusicInfo(1075166, DawnsMusicRarity.Common));
m_Info.Add(MusicName.TokunoDungeon, new DawnsMusicInfo(1075179, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Trinsic, new DawnsMusicInfo(1075155, DawnsMusicRarity.Common));
m_Info.Add(MusicName.OldUlt01, new DawnsMusicInfo(1075142, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Ocllo, new DawnsMusicInfo(1075151, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Vesper, new DawnsMusicInfo(1075156, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Victory, new DawnsMusicInfo(1075172, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Mountn_a, new DawnsMusicInfo(1075162, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Wind, new DawnsMusicInfo(1075157, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Yew, new DawnsMusicInfo(1075158, DawnsMusicRarity.Common));
m_Info.Add(MusicName.Zento, new DawnsMusicInfo(1075178, DawnsMusicRarity.Common));
m_Info.Add(MusicName.GwennoConversation, new DawnsMusicInfo(1075131, DawnsMusicRarity.Uncommon));
m_Info.Add(MusicName.DreadHornArea, new DawnsMusicInfo(1075181, DawnsMusicRarity.Uncommon));
m_Info.Add(MusicName.ElfCity, new DawnsMusicInfo(1075182, DawnsMusicRarity.Uncommon));
m_Info.Add(MusicName.GoodEndGame, new DawnsMusicInfo(1075132, DawnsMusicRarity.Uncommon));
m_Info.Add(MusicName.GoodVsEvil, new DawnsMusicInfo(1075133, DawnsMusicRarity.Uncommon));
m_Info.Add(MusicName.GreatEarthSerpents, new DawnsMusicInfo(1075134, DawnsMusicRarity.Uncommon));
m_Info.Add(MusicName.GrizzleDungeon, new DawnsMusicInfo(1075186, DawnsMusicRarity.Uncommon));
m_Info.Add(MusicName.Humanoids_U9, new DawnsMusicInfo(1075135, DawnsMusicRarity.Uncommon));
m_Info.Add(MusicName.MelisandesLair, new DawnsMusicInfo(1075183, DawnsMusicRarity.Uncommon));
m_Info.Add(MusicName.MinocNegative, new DawnsMusicInfo(1075136, DawnsMusicRarity.Uncommon));
m_Info.Add(MusicName.ParoxysmusLair, new DawnsMusicInfo(1075184, DawnsMusicRarity.Uncommon));
m_Info.Add(MusicName.Paws, new DawnsMusicInfo(1075137, DawnsMusicRarity.Uncommon));
m_Info.Add(MusicName.SelimsBar, new DawnsMusicInfo(1075138, DawnsMusicRarity.Rare));
m_Info.Add(MusicName.SerpentIsleCombat_U7, new DawnsMusicInfo(1075139, DawnsMusicRarity.Rare));
m_Info.Add(MusicName.ValoriaShips, new DawnsMusicInfo(1075140, DawnsMusicRarity.Rare));
m_Info = new Dictionary<MusicName, DawnsMusicInfo>
{
{ MusicName.Samlethe, new DawnsMusicInfo(1075152, DawnsMusicRarity.Common) },
{ MusicName.Sailing, new DawnsMusicInfo(1075163, DawnsMusicRarity.Common) },
{ MusicName.Britain2, new DawnsMusicInfo(1075145, DawnsMusicRarity.Common) },
{ MusicName.Britain1, new DawnsMusicInfo(1075144, DawnsMusicRarity.Common) },
{ MusicName.Bucsden, new DawnsMusicInfo(1075146, DawnsMusicRarity.Common) },
{ MusicName.Forest_a, new DawnsMusicInfo(1075161, DawnsMusicRarity.Common) },
{ MusicName.Cove, new DawnsMusicInfo(1075176, DawnsMusicRarity.Common) },
{ MusicName.Death, new DawnsMusicInfo(1075171, DawnsMusicRarity.Common) },
{ MusicName.Dungeon9, new DawnsMusicInfo(1075160, DawnsMusicRarity.Common) },
{ MusicName.Dungeon2, new DawnsMusicInfo(1075175, DawnsMusicRarity.Common) },
{ MusicName.Cave01, new DawnsMusicInfo(1075159, DawnsMusicRarity.Common) },
{ MusicName.Combat3, new DawnsMusicInfo(1075170, DawnsMusicRarity.Common) },
{ MusicName.Combat1, new DawnsMusicInfo(1075168, DawnsMusicRarity.Common) },
{ MusicName.Combat2, new DawnsMusicInfo(1075169, DawnsMusicRarity.Common) },
{ MusicName.Jhelom, new DawnsMusicInfo(1075147, DawnsMusicRarity.Common) },
{ MusicName.Linelle, new DawnsMusicInfo(1075185, DawnsMusicRarity.Common) },
{ MusicName.LBCastle, new DawnsMusicInfo(1075148, DawnsMusicRarity.Common) },
{ MusicName.Minoc, new DawnsMusicInfo(1075150, DawnsMusicRarity.Common) },
{ MusicName.Moonglow, new DawnsMusicInfo(1075177, DawnsMusicRarity.Common) },
{ MusicName.Magincia, new DawnsMusicInfo(1075149, DawnsMusicRarity.Common) },
{ MusicName.Nujelm, new DawnsMusicInfo(1075174, DawnsMusicRarity.Common) },
{ MusicName.BTCastle, new DawnsMusicInfo(1075173, DawnsMusicRarity.Common) },
{ MusicName.Tavern04, new DawnsMusicInfo(1075167, DawnsMusicRarity.Common) },
{ MusicName.Skarabra, new DawnsMusicInfo(1075154, DawnsMusicRarity.Common) },
{ MusicName.Stones2, new DawnsMusicInfo(1075143, DawnsMusicRarity.Common) },
{ MusicName.Serpents, new DawnsMusicInfo(1075153, DawnsMusicRarity.Common) },
{ MusicName.Taiko, new DawnsMusicInfo(1075180, DawnsMusicRarity.Common) },
{ MusicName.Tavern01, new DawnsMusicInfo(1075164, DawnsMusicRarity.Common) },
{ MusicName.Tavern02, new DawnsMusicInfo(1075165, DawnsMusicRarity.Common) },
{ MusicName.Tavern03, new DawnsMusicInfo(1075166, DawnsMusicRarity.Common) },
{ MusicName.TokunoDungeon, new DawnsMusicInfo(1075179, DawnsMusicRarity.Common) },
{ MusicName.Trinsic, new DawnsMusicInfo(1075155, DawnsMusicRarity.Common) },
{ MusicName.OldUlt01, new DawnsMusicInfo(1075142, DawnsMusicRarity.Common) },
{ MusicName.Ocllo, new DawnsMusicInfo(1075151, DawnsMusicRarity.Common) },
{ MusicName.Vesper, new DawnsMusicInfo(1075156, DawnsMusicRarity.Common) },
{ MusicName.Victory, new DawnsMusicInfo(1075172, DawnsMusicRarity.Common) },
{ MusicName.Mountn_a, new DawnsMusicInfo(1075162, DawnsMusicRarity.Common) },
{ MusicName.Wind, new DawnsMusicInfo(1075157, DawnsMusicRarity.Common) },
{ MusicName.Yew, new DawnsMusicInfo(1075158, DawnsMusicRarity.Common) },
{ MusicName.Zento, new DawnsMusicInfo(1075178, DawnsMusicRarity.Common) },
{ MusicName.GwennoConversation, new DawnsMusicInfo(1075131, DawnsMusicRarity.Uncommon) },
{ MusicName.DreadHornArea, new DawnsMusicInfo(1075181, DawnsMusicRarity.Uncommon) },
{ MusicName.ElfCity, new DawnsMusicInfo(1075182, DawnsMusicRarity.Uncommon) },
{ MusicName.GoodEndGame, new DawnsMusicInfo(1075132, DawnsMusicRarity.Uncommon) },
{ MusicName.GoodVsEvil, new DawnsMusicInfo(1075133, DawnsMusicRarity.Uncommon) },
{ MusicName.GreatEarthSerpents, new DawnsMusicInfo(1075134, DawnsMusicRarity.Uncommon) },
{ MusicName.GrizzleDungeon, new DawnsMusicInfo(1075186, DawnsMusicRarity.Uncommon) },
{ MusicName.Humanoids_U9, new DawnsMusicInfo(1075135, DawnsMusicRarity.Uncommon) },
{ MusicName.MelisandesLair, new DawnsMusicInfo(1075183, DawnsMusicRarity.Uncommon) },
{ MusicName.MinocNegative, new DawnsMusicInfo(1075136, DawnsMusicRarity.Uncommon) },
{ MusicName.ParoxysmusLair, new DawnsMusicInfo(1075184, DawnsMusicRarity.Uncommon) },
{ MusicName.Paws, new DawnsMusicInfo(1075137, DawnsMusicRarity.Uncommon) },
{ MusicName.SelimsBar, new DawnsMusicInfo(1075138, DawnsMusicRarity.Rare) },
{ MusicName.SerpentIsleCombat_U7, new DawnsMusicInfo(1075139, DawnsMusicRarity.Rare) },
{ MusicName.ValoriaShips, new DawnsMusicInfo(1075140, DawnsMusicRarity.Rare) }
};
}
public static DawnsMusicInfo GetInfo(MusicName name)
{
if (m_Info.ContainsKey(name))
return m_Info[name];
if (m_Info == null) // sanity
return null;
return null;
m_Info.TryGetValue(name, out DawnsMusicInfo info);
return info;
}
public static MusicName RandomTrack(DawnsMusicRarity rarity)
{
MusicName[] list = null;
MusicName[] list;
switch (rarity)
{
@ -319,4 +321,4 @@ namespace Server.Items
return list[Utility.Random(list.Length)];
}
}
}
}

View file

@ -23,27 +23,19 @@ namespace Server.Items
{
}
public static Dictionary<Mobile, CandyCaneTimer> ToothAches{ get; set; }
public static void Initialize()
{
ToothAches = new Dictionary<Mobile, CandyCaneTimer>();
}
private static Dictionary<Mobile, CandyCaneTimer> m_ToothAches = new Dictionary<Mobile, CandyCaneTimer>();
private static CandyCaneTimer EnsureTimer(Mobile from)
{
if (!ToothAches.TryGetValue(from, out CandyCaneTimer timer))
ToothAches[from] = timer = new CandyCaneTimer(from);
if (!m_ToothAches.TryGetValue(from, out CandyCaneTimer timer))
m_ToothAches[from] = timer = new CandyCaneTimer(from);
return timer;
}
public static int GetToothAche(Mobile from)
{
if (ToothAches.TryGetValue(from, out CandyCaneTimer timer))
return timer.Eaten;
return 0;
return m_ToothAches.TryGetValue(from, out CandyCaneTimer timer) ? timer.Eaten : 0;
}
public static void SetToothAche(Mobile from, int value)
@ -92,7 +84,7 @@ namespace Server.Items
if (Eater == null || Eater.Deleted || Eaten <= 0)
{
Stop();
ToothAches.Remove(Eater);
m_ToothAches.Remove(Eater);
}
else if (Eater.Map != Map.Internal && Eater.Alive)
{
@ -171,4 +163,4 @@ namespace Server.Items
int version = reader.ReadInt();
}
}
}
}

View file

@ -20,84 +20,70 @@ namespace Server.Items
public static class TalismanSlayer
{
private static Dictionary<TalismanSlayerName, Type[]> m_Table = new Dictionary<TalismanSlayerName, Type[]>();
private static Dictionary<TalismanSlayerName, Type[]> m_Table;
public static void Initialize()
{
m_Table[TalismanSlayerName.Bear] = new[]
m_Table = new Dictionary<TalismanSlayerName, Type[]>
{
typeof(GrizzlyBear), typeof(BlackBear), typeof(BrownBear), typeof(PolarBear) //, typeof( Grobu )
};
[TalismanSlayerName.Bear] = new[]
{
typeof(GrizzlyBear), typeof(BlackBear), typeof(BrownBear), typeof(PolarBear) //, typeof( Grobu )
},
[TalismanSlayerName.Vermin] = new[]
{
typeof(RatmanMage), typeof(RatmanMage), typeof(RatmanArcher), typeof(Barracoon), typeof(Ratman), typeof(SewerRat),
typeof(Rat), typeof(GiantRat) //, typeof( Chiikkaha )
},
[TalismanSlayerName.Bat] = new[] { typeof(Mongbat), typeof(StrongMongbat), typeof(VampireBat) },
[TalismanSlayerName.Mage] =
new[]
{
typeof(EvilMage), typeof(EvilMageLord), typeof(AncientLich), typeof(Lich), typeof(LichLord),
typeof(SkeletalMage), typeof(BoneMagi), typeof(OrcishMage), typeof(KhaldunZealot), typeof(JukaMage)
},
[TalismanSlayerName.Beetle] =
new[]
{
typeof(Beetle), typeof(RuneBeetle), typeof(FireBeetle), typeof(DeathwatchBeetle),
typeof(DeathwatchBeetleHatchling)
},
[TalismanSlayerName.Bird] = new[]
{
typeof(Bird), typeof(TropicalBird), typeof(Chicken), typeof(Crane), typeof(DesertOstard), typeof(Eagle),
typeof(ForestOstard), typeof(FrenziedOstard),
typeof(Phoenix), /*typeof( Pyre ), typeof( Swoop ), typeof( Saliva ),*/ typeof(Harpy), typeof(StoneHarpy) // ?????
},
[TalismanSlayerName.Ice] = new[]
{
typeof(ArcticOgreLord), typeof(IceElemental), typeof(SnowElemental), typeof(FrostOoze),
typeof(IceFiend), /*typeof( UnfrozenMummy ),*/ typeof(FrostSpider), typeof(LadyOfTheSnow), typeof(FrostTroll),
m_Table[TalismanSlayerName.Vermin] = new[]
{
typeof(RatmanMage), typeof(RatmanMage), typeof(RatmanArcher), typeof(Barracoon),
typeof(Ratman), typeof(SewerRat), typeof(Rat), typeof(GiantRat) //, typeof( Chiikkaha )
};
// TODO WinterReaper, check
typeof(IceSnake), typeof(SnowLeopard), typeof(PolarBear), typeof(IceSerpent), typeof(GiantIceWorm)
},
[TalismanSlayerName.Flame] = new[]
{
typeof(FireBeetle), typeof(HellHound), typeof(LavaSerpent), typeof(FireElemental), typeof(PredatorHellCat),
typeof(Phoenix), typeof(FireGargoyle), typeof(HellCat),
/*typeof( Pyre ),*/ typeof(FireSteed), typeof(LavaLizard),
m_Table[TalismanSlayerName.Bat] = new[]
{
typeof(Mongbat), typeof(StrongMongbat), typeof(VampireBat)
};
m_Table[TalismanSlayerName.Mage] = new[]
{
typeof(EvilMage), typeof(EvilMageLord), typeof(AncientLich), typeof(Lich), typeof(LichLord),
typeof(SkeletalMage), typeof(BoneMagi), typeof(OrcishMage), typeof(KhaldunZealot), typeof(JukaMage)
};
m_Table[TalismanSlayerName.Beetle] = new[]
{
typeof(Beetle), typeof(RuneBeetle), typeof(FireBeetle), typeof(DeathwatchBeetle),
typeof(DeathwatchBeetleHatchling)
};
m_Table[TalismanSlayerName.Bird] = new[]
{
typeof(Bird), typeof(TropicalBird), typeof(Chicken), typeof(Crane),
typeof(DesertOstard), typeof(Eagle), typeof(ForestOstard), typeof(FrenziedOstard),
typeof(Phoenix), /*typeof( Pyre ), typeof( Swoop ), typeof( Saliva ),*/ typeof(Harpy),
typeof(StoneHarpy) // ?????
};
m_Table[TalismanSlayerName.Ice] = new[]
{
typeof(ArcticOgreLord), typeof(IceElemental), typeof(SnowElemental), typeof(FrostOoze),
typeof(IceFiend), /*typeof( UnfrozenMummy ),*/ typeof(FrostSpider), typeof(LadyOfTheSnow),
typeof(FrostTroll),
// TODO WinterReaper, check
typeof(IceSnake), typeof(SnowLeopard), typeof(PolarBear), typeof(IceSerpent), typeof(GiantIceWorm)
};
m_Table[TalismanSlayerName.Flame] = new[]
{
typeof(FireBeetle), typeof(HellHound), typeof(LavaSerpent), typeof(FireElemental),
typeof(PredatorHellCat), typeof(Phoenix), typeof(FireGargoyle), typeof(HellCat),
/*typeof( Pyre ),*/ typeof(FireSteed), typeof(LavaLizard),
// TODO check
typeof(LavaSnake)
};
m_Table[TalismanSlayerName.Bovine] = new[]
{
typeof(Cow), typeof(Bull), typeof(Gaman) /*, typeof( MinotaurCaptain ),
typeof( MinotaurScout ), typeof( Minotaur )*/
// TODO TormentedMinotaur
// TODO check
typeof(LavaSnake)
},
[TalismanSlayerName.Bovine] = new[]
{
typeof(Cow), typeof(Bull), typeof(Gaman) /*, typeof( MinotaurCaptain ),
typeof( MinotaurScout ), typeof( Minotaur )*/
// TODO TormentedMinotaur
}
};
}
public static bool Slays(TalismanSlayerName name, Mobile m)
{
if (!m_Table.ContainsKey(name))
return false;
Type[] types = m_Table[name];
if (types == null || m == null)
return false;
if (m == null || !m_Table.TryGetValue(name, out Type[] types) || types == null)
return false;;
Type type = m.GetType();
@ -108,4 +94,4 @@ namespace Server.Items
return false;
}
}
}
}

View file

@ -59,11 +59,10 @@ namespace Server.Items
public static void BeginBleed(Mobile m, Mobile from)
{
Timer t = m_Table[m];
m_Table.TryGetValue(m, out Timer t);
t?.Stop();
m_Table[m] = t = new InternalTimer(from, m);
t.Start();
}
@ -90,9 +89,7 @@ namespace Server.Items
public static void EndBleed(Mobile m, bool message)
{
Timer t = m_Table[m];
if (t == null)
if (!m_Table.TryGetValue(m, out Timer t))
return;
t.Stop();

View file

@ -45,8 +45,7 @@ namespace Server.Items
public static bool GetBonus(Mobile targ, ref int bonus)
{
BlockInfo info = m_Table[targ];
if (info == null)
if (!m_Table.TryGetValue(targ, out BlockInfo info))
return false;
bonus = info.m_Bonus;
@ -61,9 +60,7 @@ namespace Server.Items
public static void EndBlock(Mobile m)
{
BlockInfo info = m_Table[m];
if (info == null)
if (!m_Table.TryGetValue(m, out BlockInfo info))
return;
info.m_Timer?.Stop();

View file

@ -41,9 +41,7 @@ namespace Server.Items
((Math.Max(attacker.Skills.Bushido.Value, attacker.Skills.Ninjitsu.Value) -
50.0) / 70.0));
DefenseMasteryInfo info = m_Table[attacker];
if (info != null)
if (m_Table.TryGetValue(attacker, out DefenseMasteryInfo info))
EndDefense(info);
ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, 50 + modifier);
@ -59,9 +57,7 @@ namespace Server.Items
public static bool GetMalus(Mobile targ, ref int damageMalus)
{
DefenseMasteryInfo info = m_Table[targ];
if (info == null)
if (!m_Table.TryGetValue(targ, out DefenseMasteryInfo info))
return false;
damageMalus = info.m_DamageMalus;

View file

@ -30,8 +30,7 @@ namespace Server.Items
if (!Validate(attacker) || !CheckMana(attacker, true))
return;
DualWieldTimer timer = Registry[attacker];
if (timer != null)
if (Registry.TryGetValue(attacker, out DualWieldTimer timer))
{
timer.Stop();
Registry.Remove(attacker);

View file

@ -30,8 +30,7 @@ namespace Server.Items
if (!Validate(attacker) || !CheckMana(attacker, true))
return;
FeintTimer timer = Registry[defender];
if (timer != null)
if (Registry.TryGetValue(defender, out FeintTimer timer))
{
timer.Stop();
Registry.Remove(defender);

View file

@ -78,9 +78,7 @@ namespace Server.Items
Mobile m = targets[i];
attacker.DoHarmful(m, true);
FrenziedWirlwindTimer timer = Registry[m];
if (timer != null)
if (Registry.TryGetValue(m, out FrenziedWirlwindTimer timer))
{
timer.Stop();
Registry.Remove(m);

View file

@ -41,8 +41,8 @@ namespace Server.Items
public static void BeginWound(Mobile m, TimeSpan duration)
{
InternalTimer timer = m_Table[m];
timer?.Stop();
if (m_Table.TryGetValue(m, out InternalTimer timer))
timer?.Stop();
m_Table[m] = timer = new InternalTimer(m, duration);
timer.Start();
@ -52,9 +52,7 @@ namespace Server.Items
public static void EndWound(Mobile m)
{
Timer timer = m_Table[m];
if (timer != null)
if (m_Table.TryGetValue(m, out InternalTimer timer))
{
timer.Stop();
m_Table.Remove(m);

View file

@ -88,18 +88,20 @@ namespace Server.Items
public static void BeginImmunity(Mobile m, TimeSpan duration)
{
InternalTimer timer = m_Table[m];
if (m_Table.TryGetValue(m, out InternalTimer timer))
timer?.Stop();
timer?.Stop();
m_Table[m] = timer = new InternalTimer(m, duration);
timer.Start();
}
public static void EndImmunity(Mobile m)
{
InternalTimer timer = m_Table[m];
timer?.Stop();
m_Table.Remove(m);
if (m_Table.TryGetValue(m, out InternalTimer timer))
{
timer?.Stop();
m_Table.Remove(m);
}
}
private class InternalTimer : Timer

View file

@ -8,7 +8,7 @@ namespace Server.Items
/// </summary>
public class TalonStrike : WeaponAbility
{
private static Dictionary<Mobile, InternalTimer> m_Table = new Dictionary<Mobile, InternalTimer>();
private static HashSet<Mobile> m_Table = new HashSet<Mobile>();
public override int BaseMana => 30;
public override double DamageScalar => 1.2;
@ -27,7 +27,7 @@ namespace Server.Items
public override void OnHit(Mobile attacker, Mobile defender, int damage)
{
if (m_Table.ContainsKey(defender) || !Validate(attacker) || !CheckMana(attacker, true))
if (m_Table.Contains(defender) || !Validate(attacker) || !CheckMana(attacker, true))
return;
ClearCurrentAbility(attacker);
@ -42,7 +42,7 @@ namespace Server.Items
timer.Start();
m_Table.Add(defender, timer);
m_Table.Add(defender);
}
private class InternalTimer : Timer

View file

@ -350,7 +350,7 @@ namespace Server.Items
return null;
}
WeaponAbility a = Table[m];
Table.TryGetValue(m, out WeaponAbility a);
if (!IsWeaponAbility(m, a))
{
@ -446,7 +446,8 @@ namespace Server.Items
private static WeaponAbilityContext GetContext(Mobile m)
{
return m_PlayersTable[m];
m_PlayersTable.TryGetValue(m, out WeaponAbilityContext context);
return context;
}
private class WeaponAbilityTimer : Timer

View file

@ -9,12 +9,12 @@ namespace Server.Items
public static readonly TimeSpan AttackEffectDuration = TimeSpan.FromSeconds(10.0);
public static readonly TimeSpan DefenseEffectDuration = TimeSpan.FromSeconds(8.0);
private static Dictionary<Mobile, AttackTimer> m_AttackTable = new Dictionary<Mobile, AttackTimer>();
private static Dictionary<Mobile, DefenseTimer> m_DefenseTable = new Dictionary<Mobile, DefenseTimer>();
private static HashSet<Mobile> m_AttackTable = new HashSet<Mobile>();
private static HashSet<Mobile> m_DefenseTable = new HashSet<Mobile>();
public static bool IsUnderAttackEffect(Mobile m)
{
return m_AttackTable.ContainsKey(m);
return m_AttackTable.Contains(m);
}
public static bool ApplyAttack(Mobile m)
@ -22,7 +22,9 @@ namespace Server.Items
if (IsUnderAttackEffect(m))
return false;
m_AttackTable[m] = new AttackTimer(m);
m_AttackTable.Add(m);
AttackTimer timer = new AttackTimer(m);
timer.Start();
m.SendLocalizedMessage(1062319); // Your attack chance has been reduced!
return true;
}
@ -35,7 +37,7 @@ namespace Server.Items
public static bool IsUnderDefenseEffect(Mobile m)
{
return m_DefenseTable.ContainsKey(m);
return m_DefenseTable.Contains(m);
}
public static bool ApplyDefense(Mobile m)
@ -43,7 +45,9 @@ namespace Server.Items
if (IsUnderDefenseEffect(m))
return false;
m_DefenseTable[m] = new DefenseTimer(m);
m_DefenseTable.Add(m);
DefenseTimer timer = new DefenseTimer(m);
timer.Start();
m.SendLocalizedMessage(1062318); // Your defense chance has been reduced!
return true;
}
@ -61,10 +65,7 @@ namespace Server.Items
public AttackTimer(Mobile player) : base(AttackEffectDuration)
{
m_Player = player;
Priority = TimerPriority.TwoFiftyMS;
Start();
}
protected override void OnTick()
@ -80,10 +81,7 @@ namespace Server.Items
public DefenseTimer(Mobile player) : base(DefenseEffectDuration)
{
m_Player = player;
Priority = TimerPriority.TwoFiftyMS;
Start();
}
protected override void OnTick()

View file

@ -107,7 +107,7 @@ namespace Server.Misc
m.Send(new BeginHandshake());
if (m_Dictionary.TryGetValue(m, out Timer t))
t?.Stop();
t.Stop();
m_Dictionary[m] = t = Timer.DelayCall(Settings.HandshakeTimeout, OnHandshakeTimeout, m);
t.Start();
@ -124,7 +124,7 @@ namespace Server.Misc
Mobile m = state.Mobile;
if (m_Dictionary.TryGetValue(m, out Timer t))
{
t?.Stop();
t.Stop();
m_Dictionary.Remove(m);
}
@ -159,7 +159,7 @@ namespace Server.Misc
{
if (m == null)
return;
if (m.NetState != null && m.NetState.Running)
m.NetState.Dispose();
@ -179,4 +179,4 @@ namespace Server.Misc
}
}
}
}
}

View file

@ -114,14 +114,14 @@ namespace Server
if (!m_Temps.TryGetValue( localType, out Queue<LocalBuilder> list ))
m_Temps[localType] = list = new Queue<LocalBuilder>();
if ( list.Count > 0 )
return list.Dequeue();
return CreateLocal( localType );
return list.Count > 0 ? list.Dequeue() : CreateLocal( localType );
}
public void ReleaseTemp( LocalBuilder local )
{
if (local.LocalType == null)
return;
if (!m_Temps.TryGetValue( local.LocalType, out Queue<LocalBuilder> list ))
m_Temps[local.LocalType] = list = new Queue<LocalBuilder>();

View file

@ -242,18 +242,11 @@ namespace Server.Guilds
for (int i = 0; i < m_Members.Count; i++)
m_Members[i].Alliance = null;
Alliances.TryGetValue(Name.ToLower(), out AllianceInfo aInfo);
if (aInfo == this)
if (Alliances.TryGetValue(Name.ToLower(), out AllianceInfo aInfo) && aInfo == this)
Alliances.Remove(Name.ToLower());
}
public void InvalidateMemberProperties()
{
InvalidateMemberProperties(false);
}
public void InvalidateMemberProperties(bool onlyOPL)
public void InvalidateMemberProperties(bool onlyOPL = false)
{
for (int i = 0; i < m_Members.Count; i++)
{
@ -1449,11 +1442,7 @@ namespace Server.Guilds
if (m == null)
continue;
if (!votes.TryGetValue(m, out int v))
votes[m] = 1;
else
votes[m] = v + 1;
votes[m] = 1 + (votes.TryGetValue(m, out int v) ? v : 0);
votingMembers++;
}

View file

@ -405,9 +405,7 @@ namespace Server.Misc
for ( int i = 0; i < split.Length; ++i )
{
m_KeywordHash.TryGetValue( split[i], out string keyword );
if ( keyword != null )
if (m_KeywordHash.TryGetValue( split[i], out string keyword ))
keywordsFound.Add( keyword );
}

View file

@ -8,15 +8,15 @@ namespace Server.Misc
/**
* This file requires to be saved in a Unicode
* compatible format.
*
*
* Warning: if you change String.Format methods,
* please note that the following character
* is suggested before any left-to-right text
* in order to prevent undesired formatting
* resulting from mixing LR and RL text:
*
*
* Use this one if you need to force RL:
*
*
* If you do not see the above chars, please
* enable showing of unicode control chars
**/
@ -199,17 +199,17 @@ namespace Server.Misc
string lang = mob?.Language;
if (lang != null)
{
lang = lang.ToUpper();
if (lang == null)
continue;
if (!ht.ContainsKey(lang))
ht[lang] = new InternationalCodeCounter(lang);
else
ht[lang].Increase();
lang = lang.ToUpper();
break;
}
if (ht.TryGetValue(lang, out InternationalCodeCounter codes))
codes.Increase();
else
ht[lang] = new InternationalCodeCounter(lang);
break;
}
else
foreach (Mobile mob in World.Mobiles.Values)
@ -217,15 +217,15 @@ namespace Server.Misc
{
string lang = mob.Language;
if (lang != null)
{
lang = lang.ToUpper();
if (lang == null)
continue;
if (!ht.ContainsKey(lang))
ht[lang] = new InternationalCodeCounter(lang);
else
ht[lang].Increase();
}
lang = lang.ToUpper();
if (ht.TryGetValue(lang, out InternationalCodeCounter codes))
codes.Increase();
else
ht[lang] = new InternationalCodeCounter(lang);
}
writer.WriteLine(
@ -350,4 +350,4 @@ namespace Server.Misc
}
}
}
}
}

View file

@ -45,12 +45,7 @@ namespace Server
public static string RandomName( string type )
{
NameList list = GetNameList( type );
if ( list != null )
return list.GetRandomName();
return "";
return GetNameList( type )?.GetRandomName() ?? "";
}
private static Dictionary<string, NameList> m_Table;

View file

@ -488,10 +488,7 @@ namespace Server.Items
if ( m_TypeTable == null )
return CraftResource.None;
if (!m_TypeTable.TryGetValue(resourceType, out CraftResource res))
return CraftResource.None;
return res;
return m_TypeTable.TryGetValue(resourceType, out CraftResource res) ? res : CraftResource.None;
}
/// <summary>

View file

@ -392,9 +392,10 @@ namespace Server
if (flags != ShopFlags.None)
{
Point2D p = new Point2D(x, y);
ShopInfo si = m_ShopTable[p];
if (si == null)
if (m_ShopTable.TryGetValue(p, out ShopInfo si))
si.m_Flags |= flags;
else
{
List<Point2D> floor = new List<Point2D>();
@ -409,10 +410,6 @@ namespace Server
for (int i = 0; i < floor.Count; ++i)
m_ShopTable[floor[i]] = si;
}
else
{
si.m_Flags |= flags;
}
}
}

View file

@ -45,9 +45,7 @@ namespace Server.Misc
if ( facet == null )
return null;
m_WeatherByFacet.TryGetValue( facet, out List<Weather> list );
if ( list == null )
if (!m_WeatherByFacet.TryGetValue( facet, out List<Weather> list ))
m_WeatherByFacet[facet] = list = new List<Weather>();
return list;
@ -74,10 +72,8 @@ namespace Server.Misc
if ( !isValid )
continue;
Weather w = new Weather( m_Facets[i], new[]{ area }, temperature, chanceOfPercipitation, chanceOfExtremeTemperature, TimeSpan.FromSeconds( 30.0 ) );
w.Bounds = bounds;
w.MoveSpeed = moveSpeed;
new Weather(m_Facets[i], new[] { area }, temperature, chanceOfPercipitation, chanceOfExtremeTemperature,
TimeSpan.FromSeconds(30.0)) { Bounds = bounds, MoveSpeed = moveSpeed };
}
}
@ -127,36 +123,13 @@ namespace Server.Misc
public static bool CheckIntersection( Rectangle2D r1, Rectangle2D r2 )
{
if ( r1.X >= (r2.X + r2.Width) )
return false;
if ( r2.X >= (r1.X + r1.Width) )
return false;
if ( r1.Y >= (r2.Y + r2.Height) )
return false;
if ( r2.Y >= (r1.Y + r1.Height) )
return false;
return true;
return r1.X < r2.X + r2.Width && r2.X < r1.X + r1.Width && r1.Y < r2.Y + r2.Height && r2.Y < r1.Y + r1.Height;
}
public static bool CheckContains( Rectangle2D big, Rectangle2D small )
{
if ( small.X < big.X )
return false;
if ( small.Y < big.Y )
return false;
if ( (small.X + small.Width) > (big.X + big.Width) )
return false;
if ( (small.Y + small.Height) > (big.Y + big.Height) )
return false;
return true;
return small.X >= big.X && small.Y >= big.Y && small.X + small.Width <= big.X + big.Width
&& small.Y + small.Height <= big.Y + big.Height;
}
public virtual bool IntersectsWith( Rectangle2D area )
@ -182,7 +155,7 @@ namespace Server.Misc
list?.Add( this );
Timer.DelayCall( TimeSpan.FromSeconds( (0.2+(Utility.RandomDouble()*0.8)) * interval.TotalSeconds ), interval, OnTick );
Timer.DelayCall( TimeSpan.FromSeconds( (0.2+Utility.RandomDouble()*0.8) * interval.TotalSeconds ), interval, OnTick );
}
public virtual void Reposition()
@ -231,8 +204,8 @@ namespace Server.Misc
for ( int i = 0; i < 5; ++i ) // try 5 times to find a valid spot
{
int xOffset = (MoveSpeed * MoveAngleX) / 100;
int yOffset = (MoveSpeed * MoveAngleY) / 100;
int xOffset = MoveSpeed * MoveAngleX / 100;
int yOffset = MoveSpeed * MoveAngleY / 100;
Rectangle2D oldArea = Area[0];
Rectangle2D newArea = new Rectangle2D( oldArea.X + xOffset, oldArea.Y + yOffset, oldArea.Width, oldArea.Height );
@ -255,8 +228,8 @@ namespace Server.Misc
{
if ( m_Stage == 0 )
{
m_Active = ( ChanceOfPercipitation > Utility.Random( 100 ) );
m_ExtremeTemperature = ( ChanceOfExtremeTemperature > Utility.Random( 100 ) );
m_Active = ChanceOfPercipitation > Utility.Random( 100 );
m_ExtremeTemperature = ChanceOfExtremeTemperature > Utility.Random( 100 );
if ( MoveSpeed > 0 )
{
@ -270,9 +243,8 @@ namespace Server.Misc
if ( m_Stage > 0 && MoveSpeed > 0 )
MoveForward();
int type, density, temperature;
temperature = Temperature;
int type, density;
int temperature = Temperature;
if ( m_ExtremeTemperature )
temperature *= -1;
@ -283,7 +255,7 @@ namespace Server.Misc
}
else
{
density = 150 - (m_Stage * 5);
density = 150 - m_Stage * 5;
if ( density < 10 )
density = 10;
@ -310,7 +282,7 @@ namespace Server.Misc
if ( mob == null || mob.Map != Facet )
continue;
bool contains = ( Area.Length == 0 );
bool contains = Area.Length == 0;
for ( int j = 0; !contains && j < Area.Length; ++j )
contains = Area[j].Contains( mob.Location );
@ -358,7 +330,7 @@ namespace Server.Misc
Weather w = list[i];
for ( int j = 0; j < w.Area.Length; ++j )
AddWorldPin( w.Area[j].X + (w.Area[j].Width/2), w.Area[j].Y + (w.Area[j].Height/2) );
AddWorldPin( w.Area[j].X + w.Area[j].Width/2, w.Area[j].Y + w.Area[j].Height/2 );
}
base.OnDoubleClick( from );

View file

@ -169,9 +169,9 @@ namespace Server
if (m_Table == null)
LoadTable();
m_Table.TryGetValue(obj.GetType(), out SpeedInfo sp);
;
return sp != null;
return m_Table.ContainsKey(obj.GetType());
}
public static bool GetSpeeds(object obj, ref double activeSpeed, ref double passiveSpeed)
@ -182,9 +182,7 @@ namespace Server
if (m_Table == null)
LoadTable();
m_Table.TryGetValue(obj.GetType(), out SpeedInfo sp);
if (sp == null)
if (!m_Table.TryGetValue(obj.GetType(), out SpeedInfo sp))
return false;
activeSpeed = sp.ActiveSpeed;
@ -207,4 +205,4 @@ namespace Server
}
}
}
}
}

View file

@ -167,39 +167,37 @@ namespace Server.Mobiles
{
base.OnGaveMeleeAttack(defender);
if (0.1 > Utility.RandomDouble())
{
/* Grasping Claw
if (0.1 <= Utility.RandomDouble())
return;
/* Grasping Claw
* Start cliloc: 1070836
* Effect: Physical resistance -15% for 5 seconds
* End cliloc: 1070838
* Effect: Type: "3" - From: "0x57D4F5B" (player) - To: "0x0" - ItemId: "0x37B9" - ItemIdName: "glow" - FromLocation: "(1149 808, 32)" - ToLocation: "(1149 808, 32)" - Speed: "10" - Duration: "5" - FixedDirection: "True" - Explode: "False"
*/
ExpireTimer timer = m_Table[defender];
if (timer != null)
{
timer.DoExpire();
defender.SendLocalizedMessage(1070837); // The creature lands another blow in your weakened state.
}
else
{
defender.SendLocalizedMessage(
1070836); // The blow from the creature's claws has made you more susceptible to physical attacks.
}
int effect = -(defender.PhysicalResistance * 15 / 100);
ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, effect);
defender.FixedEffect(0x37B9, 10, 5);
defender.AddResistanceMod(mod);
timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(5.0));
timer.Start();
m_Table[defender] = timer;
if (m_Table.TryGetValue(defender, out ExpireTimer timer))
{
timer.DoExpire();
defender.SendLocalizedMessage(1070837); // The creature lands another blow in your weakened state.
}
else
{
defender.SendLocalizedMessage(
1070836); // The blow from the creature's claws has made you more susceptible to physical attacks.
}
int effect = -(defender.PhysicalResistance * 15 / 100);
ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, effect);
defender.FixedEffect(0x37B9, 10, 5);
defender.AddResistanceMod(mod);
timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(5.0));
timer.Start();
m_Table[defender] = timer;
}
public override void Serialize(GenericWriter writer)

View file

@ -161,39 +161,37 @@ namespace Server.Mobiles
{
base.OnGaveMeleeAttack(defender);
if (0.1 > Utility.RandomDouble())
{
/* Grasping Claw
if (0.1 <= Utility.RandomDouble())
return;
/* Grasping Claw
* Start cliloc: 1070836
* Effect: Physical resistance -15% for 5 seconds
* End cliloc: 1070838
* Effect: Type: "3" - From: "0x57D4F5B" (player) - To: "0x0" - ItemId: "0x37B9" - ItemIdName: "glow" - FromLocation: "(1149 808, 32)" - ToLocation: "(1149 808, 32)" - Speed: "10" - Duration: "5" - FixedDirection: "True" - Explode: "False"
*/
ExpireTimer timer = m_Table[defender];
if (timer != null)
{
timer.DoExpire();
defender.SendLocalizedMessage(1070837); // The creature lands another blow in your weakened state.
}
else
{
defender.SendLocalizedMessage(
1070836); // The blow from the creature's claws has made you more susceptible to physical attacks.
}
int effect = -(defender.PhysicalResistance * 15 / 100);
ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, effect);
defender.FixedEffect(0x37B9, 10, 5);
defender.AddResistanceMod(mod);
timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(5.0));
timer.Start();
m_Table[defender] = timer;
if (m_Table.TryGetValue(defender, out ExpireTimer timer))
{
timer.DoExpire();
defender.SendLocalizedMessage(1070837); // The creature lands another blow in your weakened state.
}
else
{
defender.SendLocalizedMessage(
1070836); // The blow from the creature's claws has made you more susceptible to physical attacks.
}
int effect = -(defender.PhysicalResistance * 15 / 100);
ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, effect);
defender.FixedEffect(0x37B9, 10, 5);
defender.AddResistanceMod(mod);
timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(5.0));
timer.Start();
m_Table[defender] = timer;
}
public override void Serialize(GenericWriter writer)

View file

@ -415,7 +415,10 @@ namespace Server.Mobiles
}
}
public virtual bool IsNecroFamiliar => Summoned && m_ControlMaster != null && SummonFamiliarSpell.Table[m_ControlMaster] == this;
public virtual bool IsNecroFamiliar => Summoned && m_ControlMaster != null &&
SummonFamiliarSpell.Table.TryGetValue(m_ControlMaster, out BaseCreature bc) &&
bc == this;
public virtual bool DeleteCorpseOnDeath => !Core.AOS && m_bSummoned;
[CommandProperty(AccessLevel.GameMaster)]
@ -2317,7 +2320,7 @@ namespace Server.Mobiles
}
if (DeathAdderCharmable && from.CanBeHarmful(this, false))
if (SummonFamiliarSpell.Table[from] is DeathAdder da && !da.Deleted)
if (SummonFamiliarSpell.Table.TryGetValue(from, out BaseCreature bc) && (bc as DeathAdder)?.Deleted == false)
{
from.SendAsciiMessage("You charm the snake. Select a target to attack.");
from.Target = new DeathAdderCharmTarget(this);
@ -2345,7 +2348,7 @@ namespace Server.Mobiles
list.Add(1080078); // guarding
}
if (Summoned && !IsAnimatedDead && !IsNecroFamiliar && !(this is Clone))
if (Summoned && !(IsAnimatedDead || IsNecroFamiliar || this is Clone))
{
list.Add(1049646); // (summoned)
}
@ -3296,7 +3299,7 @@ namespace Server.Mobiles
if (!m_Charmed.DeathAdderCharmable || m_Charmed.Combatant != null || !from.CanBeHarmful(m_Charmed, false))
return;
if (!(SummonFamiliarSpell.Table[from] is DeathAdder da) || da.Deleted)
if (!(SummonFamiliarSpell.Table.TryGetValue(from, out BaseCreature bc) && (bc as DeathAdder)?.Deleted == false))
return;
if (!(targeted is Mobile targ && from.CanBeHarmful(targ, false)))

View file

@ -165,9 +165,7 @@ namespace Server.Mobiles
public static void StopEffect(Mobile m, bool message)
{
Timer timer = m_Table[m];
if (timer != null)
if (m_Table.TryGetValue(m, out Timer timer))
{
if (message)
m.PublicOverheadMessage(MessageType.Emote, m.SpeechHue, true,
@ -181,15 +179,11 @@ namespace Server.Mobiles
public void DoEffect(Mobile m, int count)
{
if (!m.Alive)
{
StopEffect(m, false);
}
else
{
if (m.FindItemOnLayer(Layer.TwoHanded) is Torch torch && torch.Burning)
{
StopEffect(m, true);
}
else
{
if (count % 4 == 0)

View file

@ -73,22 +73,22 @@ namespace Server.Mobiles
{
base.OnGaveMeleeAttack(defender);
if (Utility.RandomDouble() < 0.1)
{
if (m_Table.TryGetValue(defender, out ExpireTimer timer))
timer.DoExpire();
if (Utility.RandomDouble() >= 0.1)
return;
defender.FixedParticles(0x3709, 10, 30, 5052, EffectLayer.LeftFoot);
defender.PlaySound(0x208);
defender.SendLocalizedMessage(
1070833); // The creature fans you with fire, reducing your resistance to fire attacks.
if (m_Table.TryGetValue(defender, out ExpireTimer timer))
timer.DoExpire();
ResistanceMod mod = new ResistanceMod(ResistanceType.Fire, -10);
defender.AddResistanceMod(mod);
defender.FixedParticles(0x3709, 10, 30, 5052, EffectLayer.LeftFoot);
defender.PlaySound(0x208);
defender.SendLocalizedMessage(
1070833); // The creature fans you with fire, reducing your resistance to fire attacks.
m_Table[defender] = timer = new ExpireTimer(defender, mod);
timer.Start();
}
ResistanceMod mod = new ResistanceMod(ResistanceType.Fire, -10);
defender.AddResistanceMod(mod);
m_Table[defender] = timer = new ExpireTimer(defender, mod);
timer.Start();
}
public override void Serialize(GenericWriter writer)
@ -133,4 +133,4 @@ namespace Server.Mobiles
}
}
}
}
}

View file

@ -140,7 +140,10 @@ namespace Server.Mobiles
public static void SuppressRemove(Mobile target)
{
if (target != null && m_Suppressed[target] is Timer t)
if (target == null)
return;
if (m_Suppressed.TryGetValue(target, out Timer t))
{
if (t.Running)
t.Stop();
@ -199,7 +202,7 @@ namespace Server.Mobiles
{
Item item = m.FindItemOnLayer(layer);
if (item != null && item.Movable)
if (item?.Movable == true)
m.PlaceInBackpack(item);
}
@ -235,4 +238,4 @@ namespace Server.Mobiles
#endregion
}
}
}

View file

@ -9,7 +9,7 @@ namespace Server.Mobiles
{
public class Ilhenir : BaseChampion
{
private static Dictionary<Mobile, Timer> m_Table = new Dictionary<Mobile, Timer>();
private static HashSet<Mobile> m_Table = new HashSet<Mobile>();
[Constructible]
public Ilhenir()
@ -230,13 +230,14 @@ namespace Server.Mobiles
public virtual void CacophonicAttack(Mobile to)
{
if (to.Alive && to.Player && !m_Table.ContainsKey(to))
if (to.Alive && to.Player && !UnderCacophonicAttack(to))
{
to.Send(SpeedControl.WalkSpeed);
to.SendLocalizedMessage(1072069); // A cacophonic sound lambastes you, suppressing your ability to move.
to.PlaySound(0x584);
m_Table[to] = Timer.DelayCall(TimeSpan.FromSeconds(30), CacophonicEnd, to);
m_Table.Add(to);
Timer.DelayCall(TimeSpan.FromSeconds(30), CacophonicEnd, to);
}
}
@ -248,7 +249,7 @@ namespace Server.Mobiles
public static bool UnderCacophonicAttack(Mobile from)
{
return m_Table.ContainsKey(from);
return m_Table.Contains(from);
}
public virtual void DropOoze()

View file

@ -101,32 +101,30 @@ namespace Server.Mobiles
{
base.OnGaveMeleeAttack(defender);
if (0.1 > Utility.RandomDouble())
if (0.1 <= Utility.RandomDouble())
return;
if (m_Table.TryGetValue(defender, out ExpireTimer timer))
{
ExpireTimer timer = m_Table[defender];
if (timer != null)
{
timer.DoExpire();
defender.SendLocalizedMessage(1070837); // The creature lands another blow in your weakened state.
}
else
{
defender.SendLocalizedMessage(
1070836); // The blow from the creature's claws has made you more susceptible to physical attacks.
}
int effect = -(defender.PhysicalResistance * 15 / 100);
ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, effect);
defender.FixedEffect(0x37B9, 10, 5);
defender.AddResistanceMod(mod);
timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(5.0));
timer.Start();
m_Table[defender] = timer;
timer.DoExpire();
defender.SendLocalizedMessage(1070837); // The creature lands another blow in your weakened state.
}
else
{
defender.SendLocalizedMessage(
1070836); // The blow from the creature's claws has made you more susceptible to physical attacks.
}
int effect = -(defender.PhysicalResistance * 15 / 100);
ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, effect);
defender.FixedEffect(0x37B9, 10, 5);
defender.AddResistanceMod(mod);
timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(5.0));
timer.Start();
m_Table[defender] = timer;
}
public override void Serialize(GenericWriter writer)

View file

@ -89,7 +89,7 @@ namespace Server.Mobiles
{
base.OnGaveMeleeAttack(defender);
if (!(0.1 > Utility.RandomDouble()))
if (0.1 <= Utility.RandomDouble())
return;
/* Blood Bath
@ -100,9 +100,7 @@ namespace Server.Mobiles
* End cliloc: 1070824
*/
ExpireTimer timer = m_Table[defender];
if (timer != null)
if (m_Table.TryGetValue(defender, out ExpireTimer timer))
{
timer.DoExpire();
defender.SendLocalizedMessage(1070825); // The creature continues to rage!
@ -254,7 +252,6 @@ namespace Server.Mobiles
AddItem(new Robe(Utility.RandomNondyedHue()));
m_DisguiseTimer = null;
m_DisguiseTimer = Timer.DelayCall(TimeSpan.FromSeconds(75), RemoveDisguise);
}
@ -280,9 +277,7 @@ namespace Server.Mobiles
public void DeleteItemOnLayer(Layer layer)
{
Item item = FindItemOnLayer(layer);
item?.Delete();
FindItemOnLayer(layer)?.Delete();
}
#endregion

View file

@ -9,7 +9,7 @@ namespace Server.Mobiles
{
public class FanDancer : BaseCreature
{
private static Dictionary<Mobile, ExpireTimer> m_Table = new Dictionary<Mobile, ExpireTimer>();
private static HashSet<Mobile> m_Table = new HashSet<Mobile>();
[Constructible]
public FanDancer() : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
@ -143,13 +143,13 @@ namespace Server.Mobiles
ExpireTimer timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(10.0));
timer.Start();
m_Table[defender] = timer;
m_Table.Add(defender);
}
}
public bool IsFanned(Mobile m)
{
return m_Table.ContainsKey(m);
return m_Table.Contains(m);
}
public override void Serialize(GenericWriter writer)

View file

@ -116,8 +116,7 @@ namespace Server.Mobiles
public static void BeginLifeDrain(Mobile m, Mobile from)
{
InternalTimer timer = m_Table[m];
m_Table.TryGetValue(m, out InternalTimer timer);
timer?.Stop();
m_Table[m] = timer = new InternalTimer(from, m);
@ -139,12 +138,12 @@ namespace Server.Mobiles
public static void EndLifeDrain(Mobile m)
{
Timer timer = m_Table[m];
timer?.Stop();
m_Table.Remove(m);
m.SendLocalizedMessage(1070849); // The drain on your life force is gone.
if (m_Table.TryGetValue(m, out InternalTimer timer))
{
timer?.Stop();
m_Table.Remove(m);
m.SendLocalizedMessage(1070849); // The drain on your life force is gone.
}
}
public override void OnDamage(int amount, Mobile from, bool willKill)

View file

@ -74,9 +74,7 @@ namespace Server.Mobiles
* Effect: Type: "3" From: "0x57D4F5B" To: "0x0" ItemId: "0x37B9" ItemIdName: "glow" FromLocation: "(1048 779, 6)" ToLocation: "(1048 779, 6)" Speed: "10" Duration: "5" FixedDirection: "True" Explode: "False"
*/
ExpireTimer timer = m_FlurryOfTwigsTable[defender];
if (timer != null)
if (m_FlurryOfTwigsTable.TryGetValue(defender, out ExpireTimer timer))
{
timer.DoExpire();
defender.SendLocalizedMessage(1070851); // The creature lands another blow in your weakened state.
@ -97,8 +95,10 @@ namespace Server.Mobiles
timer = new ExpireTimer(defender, mod, m_FlurryOfTwigsTable, TimeSpan.FromSeconds(5.0));
timer.Start();
m_FlurryOfTwigsTable[defender] = timer;
return;
}
else if (0.05 > Utility.RandomDouble())
if (0.05 > Utility.RandomDouble())
{
/* Chlorophyl Blast
* Start cliloc: 1070827
@ -107,9 +107,7 @@ namespace Server.Mobiles
* Effect: Type: "3" From: "0x57D4F5B" To: "0x0" ItemId: "0x37B9" ItemIdName: "glow" FromLocation: "(1048 779, 6)" ToLocation: "(1048 779, 6)" Speed: "10" Duration: "5" FixedDirection: "True" Explode: "False"
*/
ExpireTimer timer = m_ChlorophylBlastTable[defender];
if (timer != null)
if (m_ChlorophylBlastTable.TryGetValue(defender, out ExpireTimer timer))
{
timer.DoExpire();
defender.SendLocalizedMessage(1070828); // The creature continues to hinder your energy resistance!

View file

@ -81,32 +81,30 @@ namespace Server.Mobiles
{
base.OnGaveMeleeAttack(defender);
if (0.1 > Utility.RandomDouble())
if (0.1 <= Utility.RandomDouble())
return;
/* Cold Wind
* Graphics: Message - Type: "3" From: "0x57D4F5B" To: "0x0" ItemId: "0x37B9" ItemIdName: "glow" FromLocation: "(928 164, 34)" ToLocation: "(928 164, 34)" Speed: "10" Duration: "5" FixedDirection: "True" Explode: "False"
* Start cliloc: 1070832
* Damage: 1hp per second for 5 seconds
* End cliloc: 1070830
* Reset cliloc: 1070831
*/
if (m_Table.TryGetValue(defender, out ExpireTimer timer))
{
/* Cold Wind
* Graphics: Message - Type: "3" From: "0x57D4F5B" To: "0x0" ItemId: "0x37B9" ItemIdName: "glow" FromLocation: "(928 164, 34)" ToLocation: "(928 164, 34)" Speed: "10" Duration: "5" FixedDirection: "True" Explode: "False"
* Start cliloc: 1070832
* Damage: 1hp per second for 5 seconds
* End cliloc: 1070830
* Reset cliloc: 1070831
*/
ExpireTimer timer = m_Table[defender];
if (timer != null)
{
timer.DoExpire();
defender.SendLocalizedMessage(1070831); // The freezing wind continues to blow!
}
else
{
defender.SendLocalizedMessage(1070832); // An icy wind surrounds you, freezing your lungs as you breathe!
}
timer = new ExpireTimer(defender, this);
timer.Start();
m_Table[defender] = timer;
timer.DoExpire();
defender.SendLocalizedMessage(1070831); // The freezing wind continues to blow!
}
else
{
defender.SendLocalizedMessage(1070832); // An icy wind surrounds you, freezing your lungs as you breathe!
}
timer = new ExpireTimer(defender, this);
timer.Start();
m_Table[defender] = timer;
}
public override void Serialize(GenericWriter writer)

View file

@ -6,7 +6,7 @@ namespace Server.Mobiles
{
public class RaiJu : BaseCreature
{
private static Dictionary<Mobile, ExpireTimer> m_Table = new Dictionary<Mobile, ExpireTimer>();
private static HashSet<Mobile> m_Table = new HashSet<Mobile>();
[Constructible]
public RaiJu() : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
@ -61,33 +61,28 @@ namespace Server.Mobiles
{
base.OnGaveMeleeAttack(defender);
if (0.1 > Utility.RandomDouble() && !IsStunned(defender))
{
/* Lightning Fist
* Cliloc: 1070839
* Effect: Type: "3" From: "0x57D4F5B" To: "0x0" ItemId: "0x37B9" ItemIdName: "glow" FromLocation: "(884 715, 10)" ToLocation: "(884 715, 10)" Speed: "10" Duration: "5" FixedDirection: "True" Explode: "False"
* Damage: 35-65, 100% energy, resistable
* Freezes for 4 seconds
* Effect cannot stack
*/
if (0.1 <= Utility.RandomDouble() || m_Table.Contains(defender))
return;
defender.FixedEffect(0x37B9, 10, 5);
defender.SendLocalizedMessage(1070839); // The creature attacks with stunning force!
/* Lightning Fist
* Cliloc: 1070839
* Effect: Type: "3" From: "0x57D4F5B" To: "0x0" ItemId: "0x37B9" ItemIdName: "glow" FromLocation: "(884 715, 10)" ToLocation: "(884 715, 10)" Speed: "10" Duration: "5" FixedDirection: "True" Explode: "False"
* Damage: 35-65, 100% energy, resistable
* Freezes for 4 seconds
* Effect cannot stack
*/
// This should be done in place of the normal attack damage.
//AOS.Damage( defender, this, Utility.RandomMinMax( 35, 65 ), 0, 0, 0, 0, 100 );
defender.FixedEffect(0x37B9, 10, 5);
defender.SendLocalizedMessage(1070839); // The creature attacks with stunning force!
defender.Frozen = true;
// This should be done in place of the normal attack damage.
//AOS.Damage( defender, this, Utility.RandomMinMax( 35, 65 ), 0, 0, 0, 0, 100 );
ExpireTimer timer = new ExpireTimer(defender, TimeSpan.FromSeconds(4.0));
timer.Start();
m_Table[defender] = timer;
}
}
defender.Frozen = true;
public bool IsStunned(Mobile m)
{
return m_Table.ContainsKey(m);
ExpireTimer timer = new ExpireTimer(defender, TimeSpan.FromSeconds(4.0));
timer.Start();
m_Table.Add(defender);
}
public override void Serialize(GenericWriter writer)

View file

@ -138,77 +138,75 @@ namespace Server.Mobiles
{
base.OnGaveMeleeAttack(defender);
if (0.05 > Utility.RandomDouble())
if (0.05 <= Utility.RandomDouble())
return;
/* Rune Corruption
* Start cliloc: 1070846 "The creature magically corrupts your armor!"
* Effect: All resistances -70 (lowest 0) for 5 seconds
* End ASCII: "The corruption of your armor has worn off"
*/
if (m_Table.TryGetValue(defender, out ExpireTimer timer))
{
/* Rune Corruption
* Start cliloc: 1070846 "The creature magically corrupts your armor!"
* Effect: All resistances -70 (lowest 0) for 5 seconds
* End ASCII: "The corruption of your armor has worn off"
*/
ExpireTimer timer = m_Table[defender];
if (timer != null)
{
timer.DoExpire();
defender.SendLocalizedMessage(1070845); // The creature continues to corrupt your armor!
}
else
{
defender.SendLocalizedMessage(1070846); // The creature magically corrupts your armor!
}
List<ResistanceMod> mods = new List<ResistanceMod>();
if (Core.ML)
{
if (defender.PhysicalResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Physical, -(defender.PhysicalResistance / 2)));
if (defender.FireResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Fire, -(defender.FireResistance / 2)));
if (defender.ColdResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Cold, -(defender.ColdResistance / 2)));
if (defender.PoisonResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Poison, -(defender.PoisonResistance / 2)));
if (defender.EnergyResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Energy, -(defender.EnergyResistance / 2)));
}
else
{
if (defender.PhysicalResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Physical,
defender.PhysicalResistance > 70 ? -70 : -defender.PhysicalResistance));
if (defender.FireResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Fire,
defender.FireResistance > 70 ? -70 : -defender.FireResistance));
if (defender.ColdResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Cold,
defender.ColdResistance > 70 ? -70 : -defender.ColdResistance));
if (defender.PoisonResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Poison,
defender.PoisonResistance > 70 ? -70 : -defender.PoisonResistance));
if (defender.EnergyResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Energy,
defender.EnergyResistance > 70 ? -70 : -defender.EnergyResistance));
}
for (int i = 0; i < mods.Count; ++i)
defender.AddResistanceMod(mods[i]);
defender.FixedEffect(0x37B9, 10, 5);
timer = new ExpireTimer(defender, mods, TimeSpan.FromSeconds(5.0));
timer.Start();
m_Table[defender] = timer;
timer.DoExpire();
defender.SendLocalizedMessage(1070845); // The creature continues to corrupt your armor!
}
else
{
defender.SendLocalizedMessage(1070846); // The creature magically corrupts your armor!
}
List<ResistanceMod> mods = new List<ResistanceMod>();
if (Core.ML)
{
if (defender.PhysicalResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Physical, -(defender.PhysicalResistance / 2)));
if (defender.FireResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Fire, -(defender.FireResistance / 2)));
if (defender.ColdResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Cold, -(defender.ColdResistance / 2)));
if (defender.PoisonResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Poison, -(defender.PoisonResistance / 2)));
if (defender.EnergyResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Energy, -(defender.EnergyResistance / 2)));
}
else
{
if (defender.PhysicalResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Physical,
defender.PhysicalResistance > 70 ? -70 : -defender.PhysicalResistance));
if (defender.FireResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Fire,
defender.FireResistance > 70 ? -70 : -defender.FireResistance));
if (defender.ColdResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Cold,
defender.ColdResistance > 70 ? -70 : -defender.ColdResistance));
if (defender.PoisonResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Poison,
defender.PoisonResistance > 70 ? -70 : -defender.PoisonResistance));
if (defender.EnergyResistance > 0)
mods.Add(new ResistanceMod(ResistanceType.Energy,
defender.EnergyResistance > 70 ? -70 : -defender.EnergyResistance));
}
for (int i = 0; i < mods.Count; ++i)
defender.AddResistanceMod(mods[i]);
defender.FixedEffect(0x37B9, 10, 5);
timer = new ExpireTimer(defender, mods, TimeSpan.FromSeconds(5.0));
timer.Start();
m_Table[defender] = timer;
}
public override void Serialize(GenericWriter writer)

View file

@ -103,9 +103,10 @@ namespace Server.Mobiles
{
base.OnGaveMeleeAttack(defender);
if (0.1 > Utility.RandomDouble())
{
/* Blood Bath
if (0.1 <= Utility.RandomDouble())
return;
/* Blood Bath
* Start cliloc 1070826
* Sound: 0x52B
* 2-3 blood spots
@ -113,22 +114,19 @@ namespace Server.Mobiles
* End cliloc: 1070824
*/
ExpireTimer timer = m_Table[defender];
if (timer != null)
{
timer.DoExpire();
defender.SendLocalizedMessage(1070825); // The creature continues to rage!
}
else
{
defender.SendLocalizedMessage(1070826); // The creature goes into a rage, inflicting heavy damage!
}
timer = new ExpireTimer(defender, this);
timer.Start();
m_Table[defender] = timer;
if (m_Table.TryGetValue(defender, out ExpireTimer timer))
{
timer.DoExpire();
defender.SendLocalizedMessage(1070825); // The creature continues to rage!
}
else
{
defender.SendLocalizedMessage(1070826); // The creature goes into a rage, inflicting heavy damage!
}
timer = new ExpireTimer(defender, this);
timer.Start();
m_Table[defender] = timer;
}
public override void Serialize(GenericWriter writer)

View file

@ -2139,12 +2139,10 @@ namespace Server.Mobiles
if (obj == null || m_AntiMacroTable == null || AccessLevel != AccessLevel.Player)
return true;
Dictionary<object, CountAndTimeStamp> tbl = m_AntiMacroTable[skill];
if (tbl == null)
if (!m_AntiMacroTable.TryGetValue(skill, out Dictionary<object, CountAndTimeStamp> tbl))
m_AntiMacroTable[skill] = tbl = new Dictionary<object, CountAndTimeStamp>();
CountAndTimeStamp count = tbl[obj];
if (count != null)
if (tbl.TryGetValue(obj, out CountAndTimeStamp count))
{
if (count.TimeStamp + SkillCheck.AntiMacroExpire <= DateTime.UtcNow)
{
@ -4738,10 +4736,8 @@ namespace Server.Mobiles
public virtual bool HasRecipe(int recipeID)
{
if (m_AcquiredRecipes != null && m_AcquiredRecipes.ContainsKey(recipeID))
return m_AcquiredRecipes[recipeID];
return false;
m_AcquiredRecipes?.TryGetValue(recipeID, out bool value);
return value;
}
public virtual void AcquireRecipe(Recipe r)
@ -4764,16 +4760,7 @@ namespace Server.Mobiles
}
[CommandProperty(AccessLevel.GameMaster)]
public int KnownRecipes
{
get
{
if (m_AcquiredRecipes == null)
return 0;
return m_AcquiredRecipes.Count;
}
}
public int KnownRecipes => m_AcquiredRecipes?.Count ?? 0;
#endregion
@ -4784,11 +4771,9 @@ namespace Server.Mobiles
if (!BuffInfo.Enabled || m_BuffTable == null)
return;
NetState state = NetState;
if (state != null && state.BuffIcon)
if (NetState?.BuffIcon == true)
foreach (BuffInfo info in m_BuffTable.Values)
state.Send(new AddBuffPacket(this, info));
NetState.Send(new AddBuffPacket(this, info));
}
private Dictionary<BuffIcon, BuffInfo> m_BuffTable;
@ -4805,9 +4790,8 @@ namespace Server.Mobiles
m_BuffTable.Add(b.ID, b);
NetState state = NetState;
if (state != null && state.BuffIcon) state.Send(new AddBuffPacket(this, b));
if (NetState?.BuffIcon == true)
NetState.Send(new AddBuffPacket(this, b));
}
public void RemoveBuff(BuffInfo b)
@ -4830,9 +4814,8 @@ namespace Server.Mobiles
m_BuffTable.Remove(b);
NetState state = NetState;
if (state != null && state.BuffIcon) state.Send(new RemoveBuffPacket(this, b));
if (NetState?.BuffIcon == true)
NetState.Send(new RemoveBuffPacket(this, b));
if (m_BuffTable.Count <= 0)
m_BuffTable = null;

View file

@ -391,10 +391,7 @@ namespace Server.Mobiles
if (from == null || !from.Player)
return;
if (m_DamageEntries.ContainsKey(from))
m_DamageEntries[from] += amount;
else
m_DamageEntries.Add(from, amount);
m_DamageEntries[from] = amount + (m_DamageEntries.TryGetValue(from, out int value) ? value : 0);
from.SendMessage($"Total Damage: {m_DamageEntries[from]}");
}

View file

@ -258,14 +258,10 @@ namespace Server.Mobiles
if (dest == null)
return false;
Mobile escorter = GetEscorter();
if (escorter != null || !m.Alive)
if (GetEscorter() != null || !m.Alive)
return false;
BaseEscortable escortable = EscortTable[m];
if (escortable?.Deleted == false && escortable.GetEscorter() == m)
if (EscortTable.TryGetValue(m, out BaseEscortable escortable) && escortable?.Deleted == false && escortable.GetEscorter() == m)
{
Say("I see you already have an escort.");
return false;
@ -693,7 +689,8 @@ namespace Server.Mobiles
if (name == null || m_Table == null)
return null;
return m_Table[name];
m_Table.TryGetValue(name, out EscortDestinationInfo info);
return info;
}
}

View file

@ -924,27 +924,25 @@ namespace Server.Mobiles
IShopSellInfo[] info = GetSellInfo();
Dictionary<Item, SellItemState> table = new Dictionary<Item, SellItemState>();
List<SellItemState> list = new List<SellItemState>();
foreach (IShopSellInfo ssi in info)
{
Item[] items = pack.FindItemsByType(ssi.Types);
foreach (Item item in items)
foreach (Item item in pack.FindItemsByType(ssi.Types))
{
if (item is Container container && container.Items.Count != 0)
continue;
if (item.IsStandardLoot() && item.Movable && ssi.IsSellable(item))
table[item] = new SellItemState(item, ssi.GetSellPriceFor(item), ssi.GetNameFor(item));
list.Add(new SellItemState(item, ssi.GetSellPriceFor(item), ssi.GetNameFor(item)));
}
}
if (table.Count > 0)
if (list.Count > 0)
{
SendPacksTo(from);
from.Send(new VendorSellList(this, table.Values));
from.Send(new VendorSellList(this, list));
}
else
{

View file

@ -9,10 +9,6 @@ namespace Server.Mobiles
private Dictionary<Type, int> m_Table = new Dictionary<Type, int>();
private Type[] m_Types;
public GenericSellInfo()
{
}
public void Add( Type type, int price )
{
m_Table[type] = price;

View file

@ -351,7 +351,8 @@ namespace Server.Mobiles
if (BaseHouse.NewVendorSystem) return ChargePerRealWorldDay / 12;
long total = 0;
foreach (VendorItem vi in m_SellItems.Values) total += vi.Price;
foreach (VendorItem vi in m_SellItems.Values)
total += vi.Price;
total -= 500;
@ -369,7 +370,8 @@ namespace Server.Mobiles
if (BaseHouse.NewVendorSystem)
{
long total = 0;
foreach (VendorItem vi in m_SellItems.Values) total += vi.Price;
foreach (VendorItem vi in m_SellItems.Values)
total += vi.Price;
return (int)(60 + total / 500 * 3);
}

View file

@ -71,9 +71,7 @@ namespace Server.Multis
if (owner != null)
{
m_Table.TryGetValue(owner, out List<BaseHouse> list);
if (list == null)
if (!m_Table.TryGetValue(owner, out List<BaseHouse> list))
m_Table[owner] = list = new List<BaseHouse>();
list.Add(this);
@ -276,9 +274,7 @@ namespace Server.Multis
{
if (m_Owner != null)
{
m_Table.TryGetValue(m_Owner, out List<BaseHouse> list);
if (list == null)
if (!m_Table.TryGetValue(m_Owner, out List<BaseHouse> list))
m_Table[m_Owner] = list = new List<BaseHouse>();
list.Remove(this);
@ -289,9 +285,7 @@ namespace Server.Multis
if (m_Owner != null)
{
m_Table.TryGetValue(m_Owner, out List<BaseHouse> list);
if (list == null)
if (!m_Table.TryGetValue(m_Owner, out List<BaseHouse> list))
m_Table[m_Owner] = list = new List<BaseHouse>();
list.Add(this);
@ -1111,9 +1105,7 @@ namespace Server.Multis
if (m != null)
{
m_Table.TryGetValue(m, out List<BaseHouse> exists);
if (exists != null)
if (m_Table.TryGetValue(m, out List<BaseHouse> exists))
for (int i = 0; i < exists.Count; ++i)
{
BaseHouse house = exists[i];
@ -2616,9 +2608,7 @@ namespace Server.Multis
if (m_Owner != null)
{
m_Table.TryGetValue(m_Owner, out List<BaseHouse> list);
if (list == null)
if (!m_Table.TryGetValue(m_Owner, out List<BaseHouse> list))
m_Table[m_Owner] = list = new List<BaseHouse>();
list.Add(this);
@ -2745,9 +2735,7 @@ namespace Server.Multis
if (m_Owner != null)
{
m_Table.TryGetValue(m_Owner, out List<BaseHouse> list);
if (list == null)
if (!m_Table.TryGetValue(m_Owner, out List<BaseHouse> list))
m_Table[m_Owner] = list = new List<BaseHouse>();
list.Remove(this);
@ -2888,12 +2876,7 @@ namespace Server.Multis
public static bool HasHouse(Mobile m)
{
if (m == null)
return false;
m_Table.TryGetValue(m, out List<BaseHouse> list);
if (list == null)
if (m == null || !m_Table.TryGetValue(m, out List<BaseHouse> list))
return false;
for (int i = 0; i < list.Count; ++i)

View file

@ -23,12 +23,7 @@ namespace Server.Multis
public static void Register(DecayLevel level, TimeSpan min, TimeSpan max)
{
DecayStageInfo info = new DecayStageInfo(min, max);
if (m_Stages.ContainsKey(level))
m_Stages[level] = info;
else
m_Stages.Add(level, info);
m_Stages[level] = new DecayStageInfo(min, max);
}
public static bool Decays(DecayLevel level)
@ -38,10 +33,9 @@ namespace Server.Multis
public static TimeSpan GetRandomDuration(DecayLevel level)
{
if (!m_Stages.ContainsKey(level))
if (!m_Stages.TryGetValue(level, out DecayStageInfo info))
return TimeSpan.Zero;
DecayStageInfo info = m_Stages[level];
long min = info.MinDuration.Ticks;
long max = info.MaxDuration.Ticks;
@ -61,4 +55,4 @@ namespace Server.Multis
public TimeSpan MaxDuration{ get; }
}
}
}

View file

@ -803,7 +803,7 @@ namespace Server.Items
public static HousePlacementEntry Find(BaseHouse house)
{
object obj = m_Table[house.GetType()];
m_Table.TryGetValue(house.GetType(), out object obj);
if (obj is HousePlacementEntry entry)
return entry;
@ -825,9 +825,7 @@ namespace Server.Items
{
HousePlacementEntry e = entries[i];
object obj = m_Table[e.Type];
if (obj == null)
if (!m_Table.TryGetValue(e.Type, out object obj))
{
m_Table[e.Type] = e;
}

View file

@ -258,58 +258,53 @@ namespace Server.Regions
public void CheckGuardCandidate(Mobile m)
{
if (IsDisabled())
if (IsDisabled() || !IsGuardCandidate(m))
return;
if (IsGuardCandidate(m))
if (!m_GuardCandidates.TryGetValue(m, out GuardTimer timer))
{
m_GuardCandidates.TryGetValue(m, out GuardTimer timer);
timer = new GuardTimer(m, m_GuardCandidates);
timer.Start();
if (timer == null)
{
timer = new GuardTimer(m, m_GuardCandidates);
timer.Start();
m_GuardCandidates[m] = timer;
m.SendLocalizedMessage(502275); // Guards can now be called on you!
m_GuardCandidates[m] = timer;
m.SendLocalizedMessage(502275); // Guards can now be called on you!
Map map = m.Map;
Map map = m.Map;
if (map == null)
return;
if (map != null)
Mobile fakeCall = null;
double prio = 0.0;
foreach (Mobile v in m.GetMobilesInRange(8))
if (!v.Player && v != m && !IsGuardCandidate(v) &&
((v as BaseCreature)?.IsHumanInTown() ?? v.Body.IsHuman && v.Region.IsPartOf(this)))
{
Mobile fakeCall = null;
double prio = 0.0;
double dist = m.GetDistanceToSqrt(v);
foreach (Mobile v in m.GetMobilesInRange(8))
if (!v.Player && v != m && !IsGuardCandidate(v) &&
((v as BaseCreature)?.IsHumanInTown() ?? v.Body.IsHuman && v.Region.IsPartOf(this)))
{
double dist = m.GetDistanceToSqrt(v);
if (fakeCall == null || dist < prio)
{
fakeCall = v;
prio = dist;
}
}
if (fakeCall != null)
if (fakeCall == null || dist < prio)
{
fakeCall.Say(Utility.RandomList(1007037, 501603, 1013037, 1013038, 1013039, 1013041, 1013042,
1013043, 1013052));
MakeGuard(m);
timer.Stop();
m_GuardCandidates.Remove(m);
m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
fakeCall = v;
prio = dist;
}
}
}
else
if (fakeCall != null)
{
fakeCall.Say(Utility.RandomList(1007037, 501603, 1013037, 1013038, 1013039, 1013041, 1013042,
1013043, 1013052));
MakeGuard(m);
timer.Stop();
timer.Start();
m_GuardCandidates.Remove(m);
m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
}
}
else
{
timer.Stop();
timer.Start();
}
}
public void CallGuards(Point3D p)
@ -323,9 +318,7 @@ namespace Server.Regions
if (IsGuardCandidate(m) &&
(!AllowReds && m.Kills >= 5 && m.Region.IsPartOf(this) || m_GuardCandidates.ContainsKey(m)))
{
m_GuardCandidates.TryGetValue(m, out GuardTimer timer);
if (timer != null)
if (m_GuardCandidates.TryGetValue(m, out GuardTimer timer))
{
timer.Stop();
m_GuardCandidates.Remove(m);
@ -371,4 +364,4 @@ namespace Server.Regions
}
}
}
}
}

View file

@ -36,9 +36,7 @@ namespace Server.Regions
if (!Region.ReadString(xml, "name", ref group))
return null;
SpawnDefinition def = SpawnGroup.Table[@group];
if (def == null)
if (!SpawnGroup.Table.TryGetValue(group, out SpawnGroup def))
{
Console.WriteLine("Could not find group '{0}' in a SpawnDefinition", group);
return null;
@ -152,9 +150,7 @@ namespace Server.Regions
public static SpawnMobile Get(Type type)
{
SpawnMobile sm = m_Table[type];
if (sm == null)
if (!m_Table.TryGetValue(type, out SpawnMobile sm))
m_Table[type] = sm = new SpawnMobile(type);
return sm;
@ -221,9 +217,7 @@ namespace Server.Regions
public static SpawnItem Get(Type type)
{
SpawnItem si = m_Table[type];
if (si == null)
if (!m_Table.TryGetValue(type, out SpawnItem si))
m_Table[type] = si = new SpawnItem(type);
return si;

View file

@ -209,7 +209,7 @@ namespace Server.Regions
m_SpawnTimer = null;
}
if (Table[ID] == this)
if (Table.TryGetValue(ID, out SpawnEntry entry) && entry == this)
Table.Remove(ID);
}
@ -310,6 +310,7 @@ namespace Server.Regions
Mobile from = args.Mobile;
Region reg;
if (args.Length == 0)
{
reg = from.Region;
@ -317,29 +318,26 @@ namespace Server.Regions
else
{
string name = args.GetString(0);
//reg = if (!from.Map.Regions.TryGetValue( name, out (Region) from.Map.Regions[name] ))
if (!from.Map.Regions.TryGetValue(name, out reg))
{
from.SendMessage("Could not find region '{0}'.", name);
return null;
}
}
BaseRegion br = reg as BaseRegion;
if (reg is BaseRegion br && br.Spawns != null)
return br;
if (br?.Spawns == null)
{
from.SendMessage("There are no spawners in region '{0}'.", reg);
return null;
}
return br;
from.SendMessage("There are no spawners in region '{0}'.", reg);
return null;
}
[Usage("RespawnAllRegions")]
[Description("Respawns all regions and sets the spawners as running.")]
private static void RespawnAllRegions_OnCommand(CommandEventArgs args)
{
foreach (SpawnEntry entry in Table.Values) entry.Respawn();
foreach (SpawnEntry entry in Table.Values)
entry.Respawn();
args.Mobile.SendMessage("All regions have respawned.");
}
@ -363,7 +361,8 @@ namespace Server.Regions
[Description("Deletes all spawned objects of every regions and sets the spawners as not running.")]
private static void DelAllRegionSpawns_OnCommand(CommandEventArgs args)
{
foreach (SpawnEntry entry in Table.Values) entry.DeleteSpawnedObjects();
foreach (SpawnEntry entry in Table.Values)
entry.DeleteSpawnedObjects();
args.Mobile.SendMessage("All region spawned objects have been deleted.");
}
@ -388,7 +387,8 @@ namespace Server.Regions
[Description("Sets the region spawners of all regions as running.")]
private static void StartAllRegionSpawns_OnCommand(CommandEventArgs args)
{
foreach (SpawnEntry entry in Table.Values) entry.Start();
foreach (SpawnEntry entry in Table.Values)
entry.Start();
args.Mobile.SendMessage("All region spawners have started.");
}
@ -412,7 +412,8 @@ namespace Server.Regions
[Description("Sets the region spawners of all regions as not running.")]
private static void StopAllRegionSpawns_OnCommand(CommandEventArgs args)
{
foreach (SpawnEntry entry in Table.Values) entry.Stop();
foreach (SpawnEntry entry in Table.Values)
entry.Stop();
args.Mobile.SendMessage("All region spawners have stopped.");
}

View file

@ -208,7 +208,6 @@
<Compile Include="Engines\ConPVP\Ruleset.cs" />
<Compile Include="Engines\ConPVP\RulesetLayout.cs" />
<Compile Include="Engines\ConPVP\SafeZone.cs" />
<Compile Include="Engines\ConPVP\StakesContainer.cs" />
<Compile Include="Engines\ConPVP\Tournament.cs" />
<Compile Include="Engines\ConPVP\TournamentBracketItem.cs" />
<Compile Include="Engines\ConPVP\TournamentController.cs" />

Some files were not shown because too many files have changed in this diff Show more