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

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