fix: Cleans up some comments and spell code (#1120)

This commit is contained in:
Kamron Batman 2022-07-16 19:45:41 -07:00 • committed by GitHub
parent 56c97ca84a
commit fa3515f930
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 338 additions and 469 deletions

View file

@ -138,7 +138,7 @@ namespace Server.Spells.Chivalry
sendEffect = true;
}
sendEffect = EvilOmenSpell.TryEndEffect(m) || sendEffect;
sendEffect = EvilOmenSpell.EndEffect(m) || sendEffect;
sendEffect = StrangleSpell.RemoveCurse(m) || sendEffect;
sendEffect = CorpseSkinSpell.RemoveCurse(m) || sendEffect;
sendEffect = CurseSpell.RemoveEffect(m) || sendEffect;

View file

@ -98,7 +98,7 @@ namespace Server.Spells.Chivalry
m.Paralyzed = false;
EvilOmenSpell.TryEndEffect(m);
EvilOmenSpell.EndEffect(m);
StrangleSpell.RemoveCurse(m);
CorpseSkinSpell.RemoveCurse(m);
CurseSpell.RemoveEffect(m);

View file

@ -66,7 +66,7 @@ namespace Server.Spells.Necromancy
var duration = TimeSpan.FromSeconds(Caster.Skills.SpiritSpeak.Value / 12 + 1.0);
Timer.StartTimer(duration, () => TryEndEffect(m));
Timer.StartTimer(duration, () => EndEffect(m));
HarmfulSpell(m);
@ -81,7 +81,7 @@ namespace Server.Spells.Necromancy
Caster.Target = new SpellTargetMobile(this, TargetFlags.Harmful, Core.ML ? 10 : 12);
}
public static bool TryEndEffect(Mobile m)
public static bool EndEffect(Mobile m)
{
if (!_table.Remove(m, out var mod))
{

View file

@ -25,7 +25,7 @@ namespace Server.Spells.Ninjitsu
9002
);
private static readonly Dictionary<Mobile, int> m_LastAnimalForms = new();
private static readonly Dictionary<Mobile, int> _lastAnimalForms = new();
private static readonly Dictionary<Mobile, AnimalFormContext> _table = new();
private bool m_WasMoving;
@ -135,10 +135,8 @@ namespace Server.Spells.Ninjitsu
var mana = ScaleMana(RequiredMana);
if (mana > Caster.Mana)
{
Caster.SendLocalizedMessage(
1060174,
mana.ToString()
); // You must have at least ~1_MANA_REQUIREMENT~ Mana to use this ability.
// You must have at least ~1_MANA_REQUIREMENT~ Mana to use this ability.
Caster.SendLocalizedMessage(1060174, mana.ToString());
}
else if (context != null)
{
@ -167,24 +165,21 @@ namespace Server.Spells.Ninjitsu
}
}
}
else if (Morph(Caster, GetLastAnimalForm(Caster)) == MorphResult.Fail)
{
DoFizzle();
}
else
{
if (Morph(Caster, GetLastAnimalForm(Caster)) == MorphResult.Fail)
{
DoFizzle();
}
else
{
Caster.FixedParticles(0x3728, 10, 13, 2023, EffectLayer.Waist);
Caster.Mana -= mana;
}
Caster.FixedParticles(0x3728, 10, 13, 2023, EffectLayer.Waist);
Caster.Mana -= mana;
}
}
FinishSequence();
}
public int GetLastAnimalForm(Mobile m) => m_LastAnimalForms.TryGetValue(m, out var value) ? value : -1;
public int GetLastAnimalForm(Mobile m) => _lastAnimalForms.TryGetValue(m, out var value) ? value : -1;
public static MorphResult Morph(Mobile m, int entryID)
{
@ -195,15 +190,12 @@ namespace Server.Spells.Ninjitsu
var entry = Entries[entryID];
m_LastAnimalForms[m] = entryID; // On OSI, it's the last /attempted/ one not the last succeeded one
_lastAnimalForms[m] = entryID; // On OSI, it's the last /attempted/ one not the last succeeded one
if (m.Skills.Ninjitsu.Value < entry.ReqSkill)
{
var args = $"{entry.ReqSkill:F1}\t{SkillName.Ninjitsu}\t ";
m.SendLocalizedMessage(
1063013,
args
); // You need at least ~1_SKILL_REQUIREMENT~ ~2_SKILL_NAME~ skill to use that ability.
// You need at least ~1_SKILL_REQUIREMENT~ ~2_SKILL_NAME~ skill to use that ability.
m.SendLocalizedMessage(1063013, $"{entry.ReqSkill:F1}\t{SkillName.Ninjitsu}\t ");
return MorphResult.NoSkill;
}
@ -539,81 +531,81 @@ namespace Server.Spells.Ninjitsu
public class AnimalFormTimer : Timer
{
private readonly int m_Body;
private readonly int m_Hue;
private readonly Mobile m_Mobile;
private int m_Counter;
private Mobile m_LastTarget;
private int _body;
private int _hue;
private Mobile _mobile;
private int _counter;
private Mobile _lastTarget;
public AnimalFormTimer(Mobile from, int body, int hue)
: base(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0))
{
m_Mobile = from;
m_Body = body;
m_Hue = hue;
m_Counter = 0;
_mobile = from;
_body = body;
_hue = hue;
_counter = 0;
}
protected override void OnTick()
{
if (m_Mobile.Deleted || !m_Mobile.Alive || m_Mobile.Body != m_Body || m_Mobile.Hue != m_Hue)
if (_mobile.Deleted || !_mobile.Alive || _mobile.Body != _body || _mobile.Hue != _hue)
{
AnimalForm.RemoveContext(m_Mobile, true);
AnimalForm.RemoveContext(_mobile, true);
Stop();
return;
}
if (m_Body == 0x115) // Cu Sidhe
if (_body == 0x115) // Cu Sidhe
{
if (m_Counter++ >= 8)
if (_counter++ >= 8)
{
if (m_Mobile.Hits < m_Mobile.HitsMax && m_Mobile.Backpack != null)
if (_mobile.Hits < _mobile.HitsMax && _mobile.Backpack != null)
{
var b = m_Mobile.Backpack.FindItemByType<Bandage>();
var b = _mobile.Backpack.FindItemByType<Bandage>();
if (b != null)
{
m_Mobile.Hits += Utility.RandomMinMax(20, 50);
_mobile.Hits += Utility.RandomMinMax(20, 50);
b.Consume();
}
}
m_Counter = 0;
_counter = 0;
}
}
else if (m_Body == 0x114) // Reptalon
else if (_body == 0x114) // Reptalon
{
if (m_Mobile.Combatant != null && m_Mobile.Combatant != m_LastTarget)
if (_mobile.Combatant != null && _mobile.Combatant != _lastTarget)
{
m_Counter = 1;
m_LastTarget = m_Mobile.Combatant;
_counter = 1;
_lastTarget = _mobile.Combatant;
}
if (m_Mobile.Warmode && m_LastTarget is { Alive: true, Deleted: false } && m_Counter-- <= 0)
if (_mobile.Warmode && _lastTarget is { Alive: true, Deleted: false } && _counter-- <= 0)
{
if (m_Mobile.CanBeHarmful(m_LastTarget) && m_LastTarget.Map == m_Mobile.Map &&
m_LastTarget.InRange(m_Mobile.Location, BaseCreature.DefaultRangePerception) &&
m_Mobile.InLOS(m_LastTarget))
if (_mobile.CanBeHarmful(_lastTarget) && _lastTarget.Map == _mobile.Map &&
_lastTarget.InRange(_mobile.Location, BaseCreature.DefaultRangePerception) &&
_mobile.InLOS(_lastTarget))
{
m_Mobile.Direction = m_Mobile.GetDirectionTo(m_LastTarget);
m_Mobile.Freeze(TimeSpan.FromSeconds(1));
m_Mobile.PlaySound(0x16A);
_mobile.Direction = _mobile.GetDirectionTo(_lastTarget);
_mobile.Freeze(TimeSpan.FromSeconds(1));
_mobile.PlaySound(0x16A);
StartTimer(TimeSpan.FromSeconds(1.3), () => BreathEffect_Callback(m_LastTarget));
StartTimer(TimeSpan.FromSeconds(1.3), () => BreathEffect_Callback(_lastTarget));
}
m_Counter = Math.Min((int)m_Mobile.GetDistanceToSqrt(m_LastTarget), 10);
_counter = Math.Min((int)_mobile.GetDistanceToSqrt(_lastTarget), 10);
}
}
}
public void BreathEffect_Callback(Mobile target)
{
if (m_Mobile.CanBeHarmful(target))
if (_mobile.CanBeHarmful(target))
{
m_Mobile.RevealingAction();
m_Mobile.PlaySound(0x227);
Effects.SendMovingEffect(m_Mobile, target, 0x36D4, 5, 0);
_mobile.RevealingAction();
_mobile.PlaySound(0x227);
Effects.SendMovingEffect(_mobile, target, 0x36D4, 5, 0);
StartTimer(TimeSpan.FromSeconds(1), () => BreathDamage_Callback(target));
}
@ -621,11 +613,11 @@ namespace Server.Spells.Ninjitsu
public void BreathDamage_Callback(Mobile target)
{
if (m_Mobile.CanBeHarmful(target))
if (_mobile.CanBeHarmful(target))
{
m_Mobile.RevealingAction();
m_Mobile.DoHarmful(target);
AOS.Damage(target, m_Mobile, 20, !target.Player, 0, 100, 0, 0, 0);
_mobile.RevealingAction();
_mobile.DoHarmful(target);
AOS.Damage(target, _mobile, 20, !target.Player, 0, 100, 0, 0, 0);
}
}
}

View file

@ -29,19 +29,15 @@ namespace Server.Spells.Ninjitsu
var ninjitsu = attacker.Skills.Ninjitsu.Value;
double chance;
// TODO: should be defined onHit method, what if the player hit and remove the weapon before process? ;)
var isRanged = attacker.Weapon is BaseRanged;
if (ninjitsu < 100) // This formula is an approximation from OSI data. TODO: find correct formula
var chance = ninjitsu switch
{
chance = 30 + (ninjitsu - 85) * 2.2;
}
else
{
chance = 63 + (ninjitsu - 100) * 1.1;
}
// This formula is an approximation from OSI data. TODO: find correct formula
< 100 => 30 + (ninjitsu - 85) * 2.2,
_ => 63 + (ninjitsu - 100) * 1.1
};
if (chance / 100 < Utility.RandomDouble())
{
@ -91,19 +87,19 @@ namespace Server.Spells.Ninjitsu
private class DeathStrikeTimer : Timer
{
public readonly Mobile m_Attacker;
public readonly int m_DamageBonus;
public readonly bool m_isRanged;
public readonly Mobile m_Target;
private Mobile _attacker;
private int _damageBonus;
private bool _isRanged;
private Mobile _target;
public int Steps { get; set; }
internal DeathStrikeTimer(Mobile target, Mobile attacker, int damageBonus, bool isRanged)
: base(TimeSpan.FromSeconds(5.0))
{
m_Target = target;
m_Attacker = attacker;
m_DamageBonus = damageBonus;
m_isRanged = isRanged;
_target = target;
_attacker = attacker;
_damageBonus = damageBonus;
_isRanged = isRanged;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -116,13 +112,12 @@ namespace Server.Spells.Ninjitsu
{
int damage;
var ninjitsu = m_Attacker.Skills.Ninjitsu.Value;
var stalkingBonus = Tracking.GetStalkingBonus(m_Attacker, m_Target);
var ninjitsu = _attacker.Skills.Ninjitsu.Value;
var stalkingBonus = Tracking.GetStalkingBonus(_attacker, _target);
if (Core.ML)
{
var scalar = Math.Min(1, (m_Attacker.Skills.Hiding.Value +
m_Attacker.Skills.Stealth.Value) / 220);
var scalar = Math.Min(1, (_attacker.Skills.Hiding.Value + _attacker.Skills.Stealth.Value) / 220);
// New formula doesn't apply DamageBonus anymore, caps must be, directly, 60/30.
if (Steps >= 5)
@ -134,7 +129,7 @@ namespace Server.Spells.Ninjitsu
damage = (int)Math.Floor(Math.Min(30, ninjitsu / 9 * (0.3 + 0.7 * scalar) + stalkingBonus));
}
if (m_isRanged)
if (_isRanged)
{
damage /= 2;
}
@ -145,18 +140,19 @@ namespace Server.Spells.Ninjitsu
var baseDamage = ninjitsu / divisor * 10;
var maxDamage = Steps >= 5 ? 62 : 22;
damage = Math.Clamp((int)(baseDamage + stalkingBonus), 0, maxDamage) + m_DamageBonus;
damage = Math.Clamp((int)(baseDamage + stalkingBonus), 0, maxDamage) + _damageBonus;
}
if (Core.ML)
{
m_Target.Damage(damage, m_Attacker); // Damage is direct.
_target.Damage(damage, _attacker); // Damage is direct.
}
else
{
// Damage is physical.
AOS.Damage(
m_Target,
m_Attacker,
_target,
_attacker,
damage,
true,
100,
@ -169,7 +165,7 @@ namespace Server.Spells.Ninjitsu
false,
false,
true
); // Damage is physical.
);
}
Stop();

View file

@ -99,29 +99,29 @@ namespace Server.Spells.Ninjitsu
return 0;
}
var xDelta = t.m_Location.X - from.X;
var yDelta = t.m_Location.Y - from.Y;
var xDelta = t._location.X - from.X;
var yDelta = t._location.Y - from.Y;
return Math.Min(Math.Sqrt(xDelta * xDelta + yDelta * yDelta), 20.0);
}
private class KiAttackTimer : Timer
{
public readonly Mobile m_Mobile;
public Point3D m_Location;
public Mobile _mobile;
public Point3D _location;
public KiAttackTimer(Mobile m) : base(TimeSpan.FromSeconds(2.0))
{
m_Mobile = m;
m_Location = m.Location;
_mobile = m;
_location = m.Location;
}
protected override void OnTick()
{
ClearCurrentMove(m_Mobile);
m_Mobile.SendLocalizedMessage(1063102); // You failed to complete your Ki Attack in time.
ClearCurrentMove(_mobile);
_mobile.SendLocalizedMessage(1063102); // You failed to complete your Ki Attack in time.
_table.Remove(m_Mobile);
_table.Remove(_mobile);
}
}
}

View file

@ -10,7 +10,7 @@ namespace Server.Spells.Ninjitsu
{
public class MirrorImage : NinjaSpell
{
private static readonly Dictionary<Mobile, int> m_CloneCount = new();
private static readonly Dictionary<Mobile, int> _cloneCount = new();
private static readonly SpellInfo _info = new(
"Mirror Image",
@ -30,7 +30,7 @@ namespace Server.Spells.Ninjitsu
public override bool BlockedByAnimalForm => false;
public static bool HasClone(Mobile m) => m_CloneCount.ContainsKey(m);
public static bool HasClone(Mobile m) => _cloneCount.ContainsKey(m);
public static void AddClone(Mobile m)
{
@ -39,23 +39,23 @@ namespace Server.Spells.Ninjitsu
return;
}
m_CloneCount[m] = 1 + (m_CloneCount.TryGetValue(m, out var count) ? count : 0);
_cloneCount[m] = 1 + (_cloneCount.TryGetValue(m, out var count) ? count : 0);
}
public static void RemoveClone(Mobile m)
{
if (m == null || !m_CloneCount.TryGetValue(m, out var count))
if (m == null || !_cloneCount.TryGetValue(m, out var count))
{
return;
}
if (count <= 1)
{
m_CloneCount.Remove(m);
_cloneCount.Remove(m);
}
else
{
m_CloneCount[m]--;
_cloneCount[m]--;
}
}

View file

@ -6,8 +6,7 @@ namespace Server.Spells.Ninjitsu
{
public class SurpriseAttack : NinjaMove
{
private static readonly Dictionary<Mobile, SurpriseAttackInfo>
_table = new();
private static readonly Dictionary<Mobile, SurpriseAttackTimer> _table = new();
public override int BaseMana => 20;
public override double RequiredSkill => Core.ML ? 60.0 : 30.0;
@ -59,10 +58,10 @@ namespace Server.Spells.Ninjitsu
var malus = ninjitsu / 60 + (int)Tracking.GetStalkingBonus(attacker, defender);
var info = new SurpriseAttackInfo(defender, malus);
Timer.StartTimer(TimeSpan.FromSeconds(8.0), () => EndSurprise(info), out info._timerToken);
var timer = new SurpriseAttackTimer(defender, malus);
timer.Start();
_table[defender] = info;
_table[defender] = timer;
CheckGain(attacker);
}
@ -83,34 +82,39 @@ namespace Server.Spells.Ninjitsu
return false;
}
malus = info.m_Malus;
malus = info.Malus;
return true;
}
private static void StopTimer(Mobile m)
{
if (_table.Remove(m, out var info))
if (_table.Remove(m, out var timer))
{
info._timerToken.Cancel();
timer.Stop();
}
}
private static void EndSurprise(SurpriseAttackInfo info)
private static void EndSurprise(SurpriseAttackTimer info)
{
StopTimer(info.m_Target);
info.m_Target.SendLocalizedMessage(1063131); // Your defenses have returned to normal.
StopTimer(info.Target);
info.Target.SendLocalizedMessage(1063131); // Your defenses have returned to normal.
}
private class SurpriseAttackInfo
private class SurpriseAttackTimer : Timer
{
public readonly int m_Malus;
public readonly Mobile m_Target;
public TimerExecutionToken _timerToken;
public int Malus;
public Mobile Target;
public SurpriseAttackInfo(Mobile target, int effect)
public SurpriseAttackTimer(Mobile target, int effect) : base(TimeSpan.FromSeconds(8.0))
{
m_Target = target;
m_Malus = effect;
Target = target;
Malus = effect;
}
protected override void OnTick()
{
StopTimer(Target);
Target.SendLocalizedMessage(1063131); // Your defenses have returned to normal.
}
}
}

View file

@ -57,9 +57,9 @@ namespace Server.Spells
MessageType.Regular,
0x3B2,
3,
502357,
502357, // I can not recall from that object.
from.Name
); // I can not recall from that object.
);
}
}
else if (o is HouseRaffleDeed deed && deed.ValidLocation())
@ -74,9 +74,9 @@ namespace Server.Spells
MessageType.Regular,
0x3B2,
3,
502357,
502357, // I can not recall from that object.
from.Name
); // I can not recall from that object.
);
}
}

View file

@ -19,6 +19,11 @@ namespace Server.Spells
protected override bool CanTarget(Mobile from, StaticTarget staticTarget, ref Point3D loc, ref Map map) => false;
protected override bool CanTarget(Mobile from, Mobile mobile, ref Point3D loc, ref Map map) => false;
protected override void OnCantSeeTarget(Mobile from, object o)
{
from.SendLocalizedMessage(500237); // Target can not be seen.
}
protected override void OnTarget(Mobile from, object o)
{
_spell.Target(o as Item);

View file

@ -27,6 +27,11 @@ namespace Server.Spells
_spell.Target(o as IPoint3D);
}
protected override void OnCantSeeTarget(Mobile from, object o)
{
from.SendLocalizedMessage(500237); // Target can not be seen.
}
protected override void OnTargetOutOfLOS(Mobile from, object o)
{
if (!_retryOnLos)