Full Version : XmlBioMastery
xmlspawner >>XMLSpawner Attachments >>XmlBioMastery
<< Prev | Next >>
DazedAndConfused- 01-02-2007
I use Roning's FSTaming system on my shard. This system allows you to construct your own tames using DNA from monsters. The "bios" are controlled using BaseBioCreature. As you can imagine, some of these bios are quite powerul and I wanted an attachment to do them extra damage.
So I started to edit an XmlPetMastery attachment that Arte scripted a while ago. But I ran into a bit of problem. It worked fine when Bios attacked the mob with the attachment, but crashed the shard when anything else attacked. Anything else is controlled by BaseCreature not BaseBioCreature, and the attachment could not assign a damagegiven value, and the shard would crash.
So I added a check to assign the damage for a basecreature before checking that the defender is a bio. I tested it with player mobiles, regular pets, summoned pets, and provoked mobs and it seems to work. I include it here for others to use and hopefully for those with better scripting skills than I to inspect for faults. Hate to crash my shard more.

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;
}
}
}

ArteGordon- 01-03-2007
Thanks for the contribution.
Do you want this to only do extra damage to BaseBioCreatures?
Currently it will give an additional percentage of damage to basebiocreatures, but it will also give an additional 100% damage to all basecreatures because of this

CODE
if (defender is BaseCreature && attacker != null) { defender.Damage(damageGiven, attacker); }

If you just want it to do extra damage to basebiocreatures, then you can take out all of the tests for basecreatures.
Here is a modified version that also fixes some of the messages that still refer to PetMastery

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;
}
}
}

DazedAndConfused- 01-04-2007
That works great Arte. Thanks.