Some cleanup of contains keys and try get values (#246)

This commit is contained in:
Kamron Batman 2020-09-13 20:20:44 -07:00 • committed by GitHub
parent 9cbb0cfd23
commit a236617ad9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
69 changed files with 3508 additions and 350 deletions

View file

@ -151,7 +151,10 @@ namespace Server.Spells.Necromancy
{
Type type = null;
if (c.Owner != null) type = c.Owner.GetType();
if (c.Owner != null)
{
type = c.Owner.GetType();
}
if (c.ItemID != 0x2006 || c.Animated || type == typeof(PlayerMobile) || type == null ||
c.Owner != null && c.Owner.Fame < 100 ||
@ -217,10 +220,14 @@ namespace Server.Spells.Necromancy
var contains = types.Length == 0;
for (var j = 0; !contains && j < types.Length; ++j)
{
contains = types[j].IsAssignableFrom(type);
}
if (contains)
return group;
{
return @group;
}
}
return null;
@ -228,41 +235,52 @@ namespace Server.Spells.Necromancy
public static void Unregister(Mobile master, Mobile summoned)
{
if (master == null)
return;
if (!m_Table.TryGetValue(master, out var list))
if (master == null || !m_Table.TryGetValue(master, out var list))
{
return;
}
list.Remove(summoned);
if (list.Count == 0)
{
m_Table.Remove(master);
}
}
public static void Register(Mobile master, Mobile summoned)
{
if (master == null)
{
return;
}
if (!m_Table.TryGetValue(master, out var list))
{
m_Table[master] = list = new List<Mobile>();
}
for (var i = list.Count - 1; i >= 0; --i)
{
if (i >= list.Count)
{
continue;
}
var mob = list[i];
if (mob.Deleted)
{
list.RemoveAt(i--);
}
}
list.Add(summoned);
if (list.Count > 3)
{
Timer.DelayCall(list[0].Kill);
}
Timer.DelayCall(TimeSpan.FromSeconds(2.0), TimeSpan.FromSeconds(2.0), Summoned_Damage, summoned);
}
@ -270,20 +288,28 @@ namespace Server.Spells.Necromancy
private static void Summoned_Damage(Mobile mob)
{
if (mob.Hits > 0)
{
--mob.Hits;
}
else
{
mob.Kill();
}
}
private static void SummonDelay_Callback(Mobile caster, Corpse corpse, Point3D loc, Map map, CreatureGroup group)
{
if (corpse.Animated)
{
return;
}
var owner = corpse.Owner;
if (owner == null)
{
return;
}
var necromancy = caster.Skills.Necromancy.Value;
var spiritSpeak = caster.Skills.SpiritSpeak.Value;
@ -299,7 +325,9 @@ namespace Server.Spells.Necromancy
var entry = entries[i];
if (casterAbility < entry.m_Requirement)
{
continue;
}
var animates = entry.m_ToSummon;
@ -307,7 +335,9 @@ namespace Server.Spells.Necromancy
}
if (toSummon == null)
{
return;
}
Mobile summoned = null;
@ -321,7 +351,9 @@ namespace Server.Spells.Necromancy
}
if (summoned == null)
{
return;
}
if (summoned is BaseCreature bc)
{
@ -336,7 +368,9 @@ namespace Server.Spells.Necromancy
}
if (summoned is SkeletalDragon dragon)
{
Scale(dragon, 50); // lose 50% hp and strength
}
summoned.Fame = 0;
summoned.Karma = -1500;
@ -357,7 +391,9 @@ namespace Server.Spells.Necromancy
toScale = bc.HitsMaxSeed;
if (toScale > 0)
{
bc.HitsMaxSeed = AOS.Scale(toScale, scalar);
}
bc.Hits = bc.Hits; // refresh hits
}

View file

@ -45,9 +45,13 @@ namespace Server.Spells.Necromancy
else if (m_OathTable.ContainsKey(m))
{
if (m.Player)
{
Caster.SendLocalizedMessage(1061608); // That player is already bonded in a Blood Oath.
}
else
{
Caster.SendLocalizedMessage(1061609); // That creature is already bonded in a Blood Oath.
}
}
else if (CheckHSequence(m))
{
@ -128,21 +132,22 @@ namespace Server.Spells.Necromancy
protected override void OnTick()
{
if (m_Caster.Deleted || m_Target.Deleted || !m_Caster.Alive || !m_Target.Alive ||
DateTime.UtcNow >= m_End) DoExpire();
DateTime.UtcNow >= m_End)
{
DoExpire();
}
}
public void DoExpire()
{
if (m_OathTable.ContainsKey(m_Caster))
if (m_OathTable.Remove(m_Caster))
{
m_Caster.SendLocalizedMessage(1061620); // Your Blood Oath has been broken.
m_OathTable.Remove(m_Caster);
}
if (m_OathTable.ContainsKey(m_Target))
if (m_OathTable.Remove(m_Target))
{
m_Target.SendLocalizedMessage(1061620); // Your Blood Oath has been broken.
m_OathTable.Remove(m_Target);
}
Stop();

View file

@ -57,7 +57,9 @@ namespace Server.Spells.Necromancy
var mod = new DefaultSkillMod(SkillName.MagicResist, false, 50.0);
if (m.Skills.MagicResist.Base > 50.0)
{
m.AddSkillMod(mod);
}
m_Table[m] = mod;
}
@ -81,10 +83,11 @@ namespace Server.Spells.Necromancy
public static bool TryEndEffect(Mobile m)
{
if (!m_Table.TryGetValue(m, out var mod))
if (!m_Table.Remove(m, out var mod))
{
return false;
}
m_Table.Remove(m);
mod?.Remove();
return true;

View file

@ -73,12 +73,13 @@ namespace Server.Spells.Necromancy
public static void ClearMindRotScalar(Mobile m)
{
if (!m_Table.TryGetValue(m, out var tmpB))
if (!m_Table.Remove(m, out var tmpB))
{
return;
}
BuffInfo.RemoveBuff(m, BuffIcon.Mindrot);
tmpB.m_MRExpireTimer.Stop();
m_Table.Remove(m);
m.SendLocalizedMessage(1060872); // Your mind feels normal again.
}

View file

@ -29,7 +29,9 @@ namespace Server.Spells.Necromancy
public void Target(Mobile m)
{
if (m == null)
{
return;
}
if (CheckHSequence(m))
{
@ -70,7 +72,10 @@ namespace Server.Spells.Necromancy
// Calculations for the buff bar
var spiritlevel = Caster.Skills.SpiritSpeak.Value / 10;
if (spiritlevel < 4)
{
spiritlevel = 4;
}
var d_MinDamage = 4;
var d_MaxDamage = ((int)spiritlevel + 1) * 3;
var args = $"{d_MinDamage}\t{d_MaxDamage}";
@ -113,13 +118,13 @@ namespace Server.Spells.Necromancy
public static bool RemoveCurse(Mobile m)
{
if (!m_Table.TryGetValue(m, out var timer))
if (!m_Table.Remove(m, out var timer))
{
return false;
}
timer.Stop();
m.SendLocalizedMessage(1061687); // You can breath normally again.
m_Table.Remove(m);
return true;
}
@ -153,7 +158,9 @@ namespace Server.Spells.Necromancy
m_Count = (int)spiritLevel;
if (m_Count < 4)
{
m_Count = 4;
}
m_MaxCount = m_Count;
}
@ -167,7 +174,9 @@ namespace Server.Spells.Necromancy
}
if (!m_Target.Alive || DateTime.UtcNow < m_NextHit)
{
return;
}
--m_Count;
@ -182,9 +191,13 @@ namespace Server.Spells.Necromancy
var delay = (int)Math.Ceiling((1.0 + 5 * m_Count) / m_MaxCount);
if (delay <= 5)
{
m_HitDelay = delay;
}
else
{
m_HitDelay = 5;
}
}
}
@ -203,16 +216,22 @@ namespace Server.Spells.Necromancy
damage *= 3 - (double)m_Target.Stam / m_Target.StamMax * 2;
if (damage < 1)
{
damage = 1;
}
if (!m_Target.Player)
{
damage *= 1.75;
}
AOS.Damage(m_Target, m_From, (int)damage, 0, 0, 0, 100, 0);
if (Utility.RandomDouble() >= 0.60
) // OSI: randomly revealed between first and third damage tick, guessing 60% chance
{
m_Target.RevealingAction();
}
}
}
}