using System;
using Server;using System.Collections.Generic;
using System.Linq;
using Server.Items;
using Server.Network;
using System.Collections;
using Server.Spells;
namespace Server.Mobiles
{
public class ImpaleAoe : CustomAbility
{
public override double TriggerChance { get { return 0.2; } }
public override int MaxRange { get { return 5; } }
public override TimeSpan CooldownDuration { get { return TimeSpan.FromSeconds(25); } }
private static readonly Dictionary<Mobile, BleedTimer> m_BleedTable = new Dictionary<Mobile, BleedTimer>();
public static bool IsBleeding(Mobile m)
{
return m_BleedTable.ContainsKey(m);
}
private int m_ItemID;
private int m_Hue;
private int m_Min;
private int m_Max;
public int ItemID
{
get { return m_ItemID; }
set { m_ItemID = value; }
}
public int Hue
{
get { return m_Hue; }
set { m_Hue = value; }
}
public ImpaleAoe()
{
m_ItemID = Utility.RandomList(0x8E0, 0x8E7, 0x8E1);
m_Hue = 0;
m_Min = 11;
m_Max = 29;
}
public void SetDamage(int min, int max)
{
m_Min = min;
m_Max = max;
}
public int GetDamage()
{
return Utility.RandomMinMax(m_Min, m_Max);
}
public override void Trigger(BaseCreature creature, Mobile defender, int min, int max)
{
if(min == 0 && max == 0)
{
min = m_Min;
max = m_Max;
}
if(creature.InRange(defender.Location, MaxRange) && TriggerChance >= Utility.RandomDouble() && !IsInCooldown(creature))
{
DoEffects(creature, defender, min, max);
AddToCooldown(creature);
}
}
public override void DoEffects(BaseCreature creature, Mobile defender, int min, int max)
{
if( creature.Body == 0x191 || creature.Body == 0x190)
creature.Animate(AnimationType.Spell, 0);
else
creature.Animate(AnimationType.Attack, 0);
if (!creature.Alive || creature.Map == null)
return;
BeginBleed(defender, creature, this);
}
public static void BeginBleed(Mobile defender, Mobile creature, ImpaleAoe ability)
{
BeginBleed(defender, creature, ability, false);
}
public static void BeginBleed(Mobile defender, Mobile creature, ImpaleAoe ability, bool splintering)
{
BleedTimer timer = null;
Effects.PlaySound(defender.Location, defender.Map, 0x21D);
BaseCreature bc = creature as BaseCreature;
IPooledEnumerable eable = creature.GetMobilesInRange(ability.MaxRange);
foreach (Mobile m in eable)
{
if (!bc.Controlled && (m is PlayerMobile || (m is BaseCreature && ((BaseCreature)m).GetMaster() is PlayerMobile)) && creature.CanBeHarmful(m)
|| bc.Controlled && (m is BaseCreature && !((BaseCreature)m).Controlled))
{
if (m_BleedTable.ContainsKey(m))
{
if (splintering)
{
timer = m_BleedTable[m];
timer.Stop();
}
else
{
return;
}
}
Effects.SendLocationEffect(EffectItem.Create(m.Location, m.Map, EffectItem.DefaultDuration), m.Map, ability.ItemID, 150, 10, ability.Hue, 0); //0xAA8 is ice
Timer.DelayCall(TimeSpan.FromSeconds(0.75), () =>
{
int d = ability.GetDamage();
AOS.Damage(m, creature, d, 100, 0, 0, 0, 0);
timer = new BleedTimer(creature, m);
m_BleedTable[m] = timer;
timer.Start();
m.SendLocalizedMessage(1060160); // You are bleeding!
if (m is PlayerMobile)
{
m.LocalOverheadMessage(MessageType.Regular, 0x21, 1060757); // You are bleeding profusely
m.NonlocalOverheadMessage(MessageType.Regular, 0x21, 1060758, m.Name); // ~1_NAME~ is bleeding profusely
}
m.FixedParticles(0x377A, 244, 25, 9950, 31, 0, EffectLayer.Waist);
});
}
}
eable.Free();
}
public static void DoBleed(Mobile m, Mobile from, int damage)
{
if (m.Alive && !m.IsDeadBondedPet && m != from)
{
if (!m.Player)
damage *= 2;
m.PlaySound(0x133);
AOS.Damage(m, from, damage, false, 0, 0, 0, 0, 0, 0, 100, false, false, false);
Blood blood = new Blood();
blood.ItemID = Utility.Random(0x122A, 5);
blood.MoveToWorld(m.Location, m.Map);
}
else
{
EndBleed(m, false);
}
}
public static void EndBleed(Mobile m, bool message)
{
Timer t = null;
if (m_BleedTable.ContainsKey(m))
{
t = m_BleedTable[m];
m_BleedTable.Remove(m);
}
if (t == null)
return;
t.Stop();
if (message)
m.SendLocalizedMessage(1060167); // The bleeding wounds have healed, you are no longer bleeding!
}
private class BleedTimer : Timer
{
private readonly Mobile m_From;
private readonly Mobile m_Mobile;
private int m_Count;
private int m_MaxCount;
public BleedTimer(Mobile from, Mobile m)
: base(TimeSpan.FromSeconds(2.0), TimeSpan.FromSeconds(2.0))
{
m_From = from;
m_Mobile = m;
Priority = TimerPriority.TwoFiftyMS;
m_MaxCount = 5;
}
protected override void OnTick()
{
if (!m_Mobile.Alive || m_Mobile.Deleted )
{
EndBleed(m_Mobile, true);
}
else
{
int damage = 0;
if (!Server.Spells.SkillMasteries.WhiteTigerFormSpell.HasBleedMod(m_From, out damage))
damage = Math.Max(1, Utility.RandomMinMax(5 - m_Count, (5 - m_Count) * 2));
DoBleed(m_Mobile, m_From, damage);
if (++m_Count == m_MaxCount)
EndBleed(m_Mobile, true);
}
}
}
public override void Serialize(GenericWriter writer)
{
writer.Write(m_ItemID);
writer.Write(m_Hue);
writer.Write(m_Min);
writer.Write(m_Max);
}
public override void Deserialize(GenericReader reader)
{
m_ItemID = reader.ReadInt();
m_Hue = reader.ReadInt();
m_Min = reader.ReadInt();
m_Max = reader.ReadInt();
}
}
}