private class CombatTimer : Timer
{
private readonly Mobile _Mobile;
public CombatTimer(Mobile m)
: base(TimeSpan.FromSeconds(0.0), TimeSpan.FromSeconds(0.01), 0)
{
_Mobile = m;
if (!_Mobile._Player && _Mobile._Dex <= 100)
{
Priority = TimerPriority.FiftyMS;
}
}
protected override void OnTick()
{
if (Core.TickCount - _Mobile._NextCombatTimeOneThird >= 0 && Core.TickCount - _Mobile._NextCombatTimeOneHalf <= 0 && _Mobile.NextCombatOneThird == false)
{
_Mobile.Emote("One Third Charged");
_Mobile.NextCombatOneThird = true;
}
if (Core.TickCount - _Mobile._NextCombatTimeOneHalf >= 0 && Core.TickCount - _Mobile._NextCombatTimeTwoThird <= 0 && _Mobile.NextCombatOneHalf == false)
{
_Mobile.Emote("One Half Charged");
_Mobile.NextCombatOneHalf = true;
}
if (Core.TickCount - _Mobile._NextCombatTimeTwoThird >= 0 && Core.TickCount - _Mobile._NextCombatTime <= 0 && _Mobile.NextCombatTwoThird == false)
{
_Mobile.Emote("Two Third Charged");
_Mobile.NextCombatTwoThird = true;
}
if (Core.TickCount - _Mobile._NextCombatTime >= 0 && _Mobile.NextCombatReady == false)
{
_Mobile.Emote("Full Charged");
_Mobile.NextCombatReady = true;
}
if (Core.TickCount - _Mobile._NextCombatTime >= 0)
{
Mobile combatant = _Mobile.Combatant;
// If no combatant, wrong map, one of us is a ghost, or cannot see, or deleted, then stop combat
if (combatant == null || combatant._Deleted || _Mobile._Deleted || combatant._Map != _Mobile._Map ||
!combatant.Alive || !_Mobile.Alive || !_Mobile.CanSee(combatant) || combatant.IsDeadBondedPet ||
_Mobile.IsDeadBondedPet)
{
_Mobile.Combatant = null;
return;
}
IWeapon weapon = _Mobile.Weapon;
if (!_Mobile.InRange(combatant, weapon.MaxRange))
{
return;
}
if (_Mobile.InLOS(combatant))
{
weapon.OnBeforeSwing(_Mobile, combatant); //OnBeforeSwing for checking in regards to being hidden and whatnot
_Mobile.RevealingAction();
_Mobile.LastCombatTime = (int)weapon.OnSwing(_Mobile, null).TotalMilliseconds;
_Mobile._NextCombatTime = Core.TickCount + (int)weapon.OnSwing(_Mobile, combatant).TotalMilliseconds;
_Mobile._NextCombatTimeOneThird = Core.TickCount + _Mobile.LastCombatTime / 3;
_Mobile._NextCombatTimeOneHalf = Core.TickCount + _Mobile.LastCombatTime / 2;
_Mobile._NextCombatTimeTwoThird = Core.TickCount + _Mobile.LastCombatTime / 3 * 2;
_Mobile.NextCombatOneThird = false;
_Mobile.NextCombatOneHalf = false;
_Mobile.NextCombatTwoThird = false;
_Mobile.NextCombatReady = false;
}
}
}
}