using Server.Items;
using Server.Mobiles;
using Server.Network;
namespace Server.Interfaces
{
public interface IDestructible
{
int HitPoints { get; set; }
int MaxHitPoints { get; set; }
}
public static class IDestructibleExt
{
public static double Destructchance { get { return 0.05; } }
public static bool HandleDurability(this IDestructible item, BaseWeapon weapon, int Absorbed)
{
if (Utility.RandomDouble() <= Destructchance)
{
if (item is BaseArmor)
{
var ba = (BaseArmor)item;
var sr = ba.ArmorAttributes.SelfRepair + (ba.IsSetItem && ba.SetEquipped ? ba.SetSelfRepair : 0);
if (sr > Utility.RandomMinMax(0, 9))
ba.HitPoints += 2;
else
{
int wear;
if (weapon.Type == WeaponType.Bashing)
wear = Absorbed / 2;
else
wear = Utility.RandomMinMax(0, 1);
if (wear > 0 && ba.MaxHitPoints > 0)
{
if (ba.HitPoints >= wear)
{
ba.HitPoints -= wear;
wear = 0;
}
else
{
wear -= ba.HitPoints;
ba.HitPoints = 0;
}
if (wear > 0)
{
if (ba.MaxHitPoints > wear)
{
ba.MaxHitPoints -= wear;
if (ba.Parent is Mobile)
((Mobile)ba.Parent).LocalOverheadMessage(MessageType.Regular, 0x3B2, 1061121); // Your equipment is severely damaged.
}
else
{
ba.Delete();
}
}
}
}
}
else if (item is BaseWeapon)
{
}
}
return true;
}
public static bool HandleDurability(this IDestructible item, Mobile attacker, Mobile defender)
{
if ((item.MaxHitPoints > 0) && (item is BaseWeapon))
{
var bw = (BaseWeapon)item;
var doaction = (defender is Slime || defender is ToxicElemental || defender is CorrosiveSlime || (Utility.RandomDouble() <= Destructchance));
if ((bw.MaxRange <= 1) && (doaction))
{
if (bw.MaxRange <= 1 && (defender is Slime || defender is ToxicElemental || defender is CorrosiveSlime))
{
attacker.LocalOverheadMessage(MessageType.Regular, 0x3B2, 500263); // *Acid blood scars your weapon!*
}
var sr = bw.WeaponAttributes.SelfRepair + (bw.IsSetItem && bw.SetEquipped ? bw.SetSelfRepair : 0);
if (sr > Utility.RandomMinMax(0, 9))
bw.HitPoints += 2;
else
{
if (bw.HitPoints > 0)
{
--bw.HitPoints;
}
else if (bw.MaxHitPoints > 1)
{
--bw.MaxHitPoints;
if (bw.Parent is Mobile)
{
((Mobile)bw.Parent).LocalOverheadMessage(MessageType.Regular, 0x3B2, 1061121);// Your equipment is severely damaged.
}
}
else
{
bw.Delete();
}
}
}
}
return true;
}
}
}