Fixes dictionary uses (#7)
This commit is contained in:
parent
d4a52344f2
commit
916d404c51
161 changed files with 1211 additions and 1722 deletions
|
|
@ -219,9 +219,7 @@ namespace Server.Spells
|
|||
return null;
|
||||
}
|
||||
|
||||
Table.TryGetValue(m, out SpecialMove move);
|
||||
|
||||
if (move != null && move.ValidatesDuringHit && !move.Validate(m))
|
||||
if (Table.TryGetValue(m, out SpecialMove move) && move.ValidatesDuringHit && !move.Validate(m))
|
||||
{
|
||||
ClearCurrentMove(m);
|
||||
return null;
|
||||
|
|
@ -272,9 +270,9 @@ namespace Server.Spells
|
|||
|
||||
public static void ClearCurrentMove(Mobile m)
|
||||
{
|
||||
Table.TryGetValue(m, out SpecialMove move);
|
||||
;
|
||||
|
||||
if (move != null)
|
||||
if (Table.TryGetValue(m, out SpecialMove move))
|
||||
{
|
||||
move.OnClearMove(m);
|
||||
|
||||
|
|
@ -306,17 +304,7 @@ namespace Server.Spells
|
|||
|
||||
private static SpecialMoveContext GetContext(Mobile m)
|
||||
{
|
||||
return m_PlayersTable.ContainsKey(m) ? m_PlayersTable[m] : null;
|
||||
}
|
||||
|
||||
public static bool GetContext(Mobile m, Type type)
|
||||
{
|
||||
m_PlayersTable.TryGetValue(m, out SpecialMoveContext context);
|
||||
|
||||
if (context == null)
|
||||
return false;
|
||||
|
||||
return context.Type == type;
|
||||
return m_PlayersTable.TryGetValue(m, out SpecialMoveContext context) ? context : null;
|
||||
}
|
||||
|
||||
private class SpecialMoveTimer : Timer
|
||||
|
|
@ -349,4 +337,4 @@ namespace Server.Spells
|
|||
public Type Type{ get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,16 +84,9 @@ namespace Server.Spells
|
|||
public virtual void OnCasterHurt()
|
||||
{
|
||||
//Confirm: Monsters and pets cannot be disturbed.
|
||||
if (!Caster.Player)
|
||||
return;
|
||||
|
||||
if (IsCasting)
|
||||
{
|
||||
double d = ProtectionSpell.Registry[Caster];
|
||||
|
||||
if (d <= Utility.RandomDouble() * 100.0)
|
||||
Disturb(DisturbType.Hurt, false, true);
|
||||
}
|
||||
if (Caster.Player && IsCasting && ProtectionSpell.Registry.TryGetValue(Caster, out double d) &&
|
||||
d <= Utility.RandomDouble() * 100.0)
|
||||
Disturb(DisturbType.Hurt, false, true);
|
||||
}
|
||||
|
||||
public virtual void OnCasterKilled()
|
||||
|
|
@ -144,20 +137,15 @@ namespace Server.Spells
|
|||
return; //Sanity
|
||||
|
||||
if (!m_ContextTable.TryGetValue(GetType(), out DelayedDamageContextWrapper contexts))
|
||||
{
|
||||
contexts = new DelayedDamageContextWrapper();
|
||||
m_ContextTable.Add(GetType(), contexts);
|
||||
}
|
||||
m_ContextTable[GetType()] = contexts = new DelayedDamageContextWrapper();
|
||||
|
||||
contexts.Add(m, t);
|
||||
}
|
||||
|
||||
public void RemoveDelayedDamageContext(Mobile m)
|
||||
{
|
||||
if (!m_ContextTable.TryGetValue(GetType(), out DelayedDamageContextWrapper contexts))
|
||||
return;
|
||||
|
||||
contexts.Remove(m);
|
||||
if (m_ContextTable.TryGetValue(GetType(), out DelayedDamageContextWrapper contexts))
|
||||
contexts.Remove(m);
|
||||
}
|
||||
|
||||
public void HarmfulSpell(Mobile m)
|
||||
|
|
|
|||
|
|
@ -1041,7 +1041,7 @@ namespace Server.Spells
|
|||
|
||||
if (context == null) /* cleanup */
|
||||
return;
|
||||
|
||||
|
||||
if (context.Type == typeof(WraithFormSpell))
|
||||
{
|
||||
int wraithLeech =
|
||||
|
|
@ -1137,7 +1137,7 @@ namespace Server.Spells
|
|||
{
|
||||
BaseCreature bcFrom = m_From as BaseCreature;
|
||||
BaseCreature bcTarg = m_Target as BaseCreature;
|
||||
|
||||
|
||||
if (bcFrom != null && m_Target != null)
|
||||
bcFrom.AlterSpellDamageTo(m_Target, ref m_Damage);
|
||||
|
||||
|
|
@ -1299,24 +1299,24 @@ namespace Server.Spells
|
|||
|
||||
public static void RemoveContext(Mobile m, TransformContext context, bool resetGraphics)
|
||||
{
|
||||
if (m_Table.ContainsKey(m))
|
||||
if (!m_Table.ContainsKey(m))
|
||||
return;
|
||||
|
||||
m_Table.Remove(m);
|
||||
|
||||
List<ResistanceMod> mods = context.Mods;
|
||||
|
||||
for (int i = 0; i < mods.Count; ++i)
|
||||
m.RemoveResistanceMod(mods[i]);
|
||||
|
||||
if (resetGraphics)
|
||||
{
|
||||
m_Table.Remove(m);
|
||||
|
||||
List<ResistanceMod> mods = context.Mods;
|
||||
|
||||
for (int i = 0; i < mods.Count; ++i)
|
||||
m.RemoveResistanceMod(mods[i]);
|
||||
|
||||
if (resetGraphics)
|
||||
{
|
||||
m.HueMod = -1;
|
||||
m.BodyMod = 0;
|
||||
}
|
||||
|
||||
context.Timer.Stop();
|
||||
context.Spell.RemoveEffect(m);
|
||||
m.HueMod = -1;
|
||||
m.BodyMod = 0;
|
||||
}
|
||||
|
||||
context.Timer.Stop();
|
||||
context.Spell.RemoveEffect(m);
|
||||
}
|
||||
|
||||
public static TransformContext GetContext(Mobile m)
|
||||
|
|
@ -1406,4 +1406,4 @@ namespace Server.Spells
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,10 +70,7 @@ namespace Server.Spells
|
|||
|
||||
public static int GetRegistryNumber(Type type)
|
||||
{
|
||||
if (m_IDsFromTypes.ContainsKey(type))
|
||||
return m_IDsFromTypes[type];
|
||||
|
||||
return -1;
|
||||
return m_IDsFromTypes.TryGetValue(type, out int value) ? value : -1;
|
||||
}
|
||||
|
||||
public static void Register(int spellID, Type type)
|
||||
|
|
@ -99,6 +96,7 @@ namespace Server.Spells
|
|||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
if (spm != null)
|
||||
|
|
@ -113,10 +111,11 @@ namespace Server.Spells
|
|||
|
||||
Type t = m_Types[spellID];
|
||||
|
||||
if (t == null || !t.IsSubclassOf(typeof(SpecialMove)) || !SpecialMoves.ContainsKey(spellID))
|
||||
if (t == null || !t.IsSubclassOf(typeof(SpecialMove)))
|
||||
return null;
|
||||
|
||||
return SpecialMoves[spellID];
|
||||
SpecialMoves.TryGetValue(spellID, out SpecialMove move);
|
||||
return move;
|
||||
}
|
||||
|
||||
public static Spell NewSpell(int spellID, Mobile caster, Item scroll)
|
||||
|
|
@ -167,4 +166,4 @@ namespace Server.Spells
|
|||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue