CODE |
using System; using Server; using Server.Items; using Server.Network; using Server.Mobiles; using Server.Spells; using System.Collections; namespace Server.Engines.XmlSpawner2 { public class XmlBioMastery : XmlAttachment { private int m_Chance = 20; // 20% chance by default private int m_PercentIncrease = 50; [CommandProperty( AccessLevel.GameMaster )] public int Chance { get{ return m_Chance; } set { m_Chance = value; } } [CommandProperty( AccessLevel.GameMaster )] public int PercentIncrease { get{ return m_PercentIncrease; } set { m_PercentIncrease = value; } } // These are the various ways in which the message attachment can be constructed. // These can be called via the [addatt interface, via scripts, via the spawner ATTACH keyword. // Other overloads could be defined to handle other types of arguments // a serial constructor is REQUIRED public XmlBioMastery(ASerial serial) : base(serial) { } [Attachable] public XmlBioMastery() { } [Attachable] public XmlBioMastery(int increase ) { m_PercentIncrease = increase; } [Attachable] public XmlBioMastery(int chance, int increase ) { m_Chance = chance; m_PercentIncrease = increase; } [Attachable] public XmlBioMastery(int chance, int increase, double expiresin) { m_Chance = chance; m_PercentIncrease = increase; Expiration = TimeSpan.FromMinutes(expiresin); } public override void OnAttach() { base.OnAttach(); if(AttachedTo is Mobile) { Mobile m = AttachedTo as Mobile; Effects.PlaySound( m, m.Map, 516 ); m.SendMessage(String.Format("You gain the power of Pet Mastery")); } } // note that this method will be called when attached to either a mobile or a weapon // when attached to a weapon, only that weapon will do additional damage // when attached to a mobile, any weapon the mobile wields will do additional damage public override void OnWeaponHit(Mobile attacker, Mobile defender, BaseWeapon weapon, int damageGiven) { if(m_Chance <= 0 || Utility.Random(100) > m_Chance) return; if ((defender is BaseBioCreature && attacker != null) || (defender is BaseCreature && attacker != null)) { //does defender derive from basecreature if (defender is BaseCreature && attacker != null) { defender.Damage(damageGiven, attacker); } // is the defender a bio? else if (((BaseBioCreature)defender).Controlled) { defender.Damage((int)(damageGiven * PercentIncrease / 100), attacker); } else defender.Damage(damageGiven, attacker); } } public override void OnDelete() { base.OnDelete(); if(AttachedTo is Mobile) { Mobile m = AttachedTo as Mobile; if(!m.Deleted) { Effects.PlaySound( m, m.Map, 958 ); m.SendMessage(String.Format("Your power of Pet Mastery fades..")); } } } public override void Serialize( GenericWriter writer ) { base.Serialize(writer); writer.Write( (int) 0 ); // version 0 writer.Write(m_PercentIncrease); writer.Write(m_Chance); } public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); // version 0 m_PercentIncrease = reader.ReadInt(); m_Chance = reader.ReadInt(); } public override string OnIdentify(Mobile from) { string msg = null; if(Expiration > TimeSpan.Zero) { msg = String.Format("Pet Mastery : +{2}% damage vs pets, {0}%, hitchance expires in {1} mins", Chance, Expiration.TotalMinutes, PercentIncrease); } else { msg = String.Format("Pet Mastery : +{1}% damage vs pets, {0}% hitchance", Chance, PercentIncrease); } return msg; } } } |
CODE |
if (defender is BaseCreature && attacker != null) { defender.Damage(damageGiven, attacker); } |
CODE |
using System; using Server; using Server.Items; using Server.Network; using Server.Mobiles; using Server.Spells; using System.Collections; namespace Server.Engines.XmlSpawner2 { public class XmlBioMastery : XmlAttachment { private int m_Chance = 20; // 20% chance by default private int m_PercentIncrease = 50; [CommandProperty(AccessLevel.GameMaster)] public int Chance { get { return m_Chance; } set { m_Chance = value; } } [CommandProperty(AccessLevel.GameMaster)] public int PercentIncrease { get { return m_PercentIncrease; } set { m_PercentIncrease = value; } } // These are the various ways in which the message attachment can be constructed. // These can be called via the [addatt interface, via scripts, via the spawner ATTACH keyword. // Other overloads could be defined to handle other types of arguments // a serial constructor is REQUIRED public XmlBioMastery(ASerial serial) : base(serial) { } [Attachable] public XmlBioMastery() { } [Attachable] public XmlBioMastery(int increase) { m_PercentIncrease = increase; } [Attachable] public XmlBioMastery(int chance, int increase) { m_Chance = chance; m_PercentIncrease = increase; } [Attachable] public XmlBioMastery(int chance, int increase, double expiresin) { m_Chance = chance; m_PercentIncrease = increase; Expiration = TimeSpan.FromMinutes(expiresin); } public override void OnAttach() { base.OnAttach(); if (AttachedTo is Mobile) { Mobile m = AttachedTo as Mobile; Effects.PlaySound(m, m.Map, 516); m.SendMessage(String.Format("You gain the power of Bio Mastery")); } } // note that this method will be called when attached to either a mobile or a weapon // when attached to a weapon, only that weapon will do additional damage // when attached to a mobile, any weapon the mobile wields will do additional damage public override void OnWeaponHit(Mobile attacker, Mobile defender, BaseWeapon weapon, int damageGiven) { if (m_Chance <= 0 || Utility.Random(100) > m_Chance) return; if (defender is BaseBioCreature && attacker != null) { // is the defender a bio pet? if (((BaseBioCreature)defender).Controlled) { defender.Damage((int)(damageGiven * PercentIncrease / 100), attacker); } } } public override void OnDelete() { base.OnDelete(); if (AttachedTo is Mobile) { Mobile m = AttachedTo as Mobile; if (!m.Deleted) { Effects.PlaySound(m, m.Map, 958); m.SendMessage(String.Format("Your power of Bio Mastery fades..")); } } } public override void Serialize(GenericWriter writer) { base.Serialize(writer); writer.Write((int)0); // version 0 writer.Write(m_PercentIncrease); writer.Write(m_Chance); } public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); // version 0 m_PercentIncrease = reader.ReadInt(); m_Chance = reader.ReadInt(); } public override string OnIdentify(Mobile from) { string msg = null; if (Expiration > TimeSpan.Zero) { msg = String.Format("Bio Mastery : +{2}% damage vs bio pets, {0}%, hitchance expires in {1} mins", Chance, Expiration.TotalMinutes, PercentIncrease); } else { msg = String.Format("Bio Mastery : +{1}% damage vs bio pets, {0}% hitchance", Chance, PercentIncrease); } return msg; } } } |