CODE |
using System; using System.Collections; using Server.Items; using Server.Mobiles; using Server.Misc; using Server.Engines.XmlSpawner2; namespace Server.Commands { public class testloot { public static void Initialize() { CommandSystem.Register( "testloot", AccessLevel.Player, new CommandEventHandler( testloot_OnCommand ) ); } [Usage( "testloot" )] [Description( "test the loot options xmlattachment" )] public static void testloot_OnCommand( CommandEventArgs e ) { // does player already have a lootdata attachment? if (XmlAttach.FindAttachment(e.Mobile, typeof(LootData))==null) { // create lootdata attachment and add it to the player LootData lootoptions = new LootData(); XmlAttach.AttachTo(e.Mobile, lootoptions); } else { // player has the attachment so set the variable LootData lootoptions = (LootData)XmlAttach.FindAttachment(e.Mobile, typeof(LootData)); } Console.WriteLine("bool getall is:" + lootoptions.GetAll); } } } |
CODE |
// LootData.cs // Author: ssalter // Version: .01 // Server Tested with: 2.0 build 64 // Revision Date: 7/1/2006 using System; using Server; using Server.Items; using Server.Network; using Server.Mobiles; namespace Server.Engines.XmlSpawner2 { public class LootData : XmlAttachment { private bool m_getall; private bool m_getgold; private bool m_getweapons; private bool m_getarmor; private bool m_getjewelry; private bool m_getpotions; private bool m_getregs; private bool m_getclothes; private bool m_getgems; private bool m_getartifact; private bool m_gethides; private bool m_getfood; [CommandProperty( AccessLevel.GameMaster )] public bool GetAll { get { return m_getall; } set { m_getall = value; } } [CommandProperty( AccessLevel.GameMaster )] public bool GetGold { get { return m_getgold; } set { m_getgold = value; } } [CommandProperty( AccessLevel.GameMaster )] public bool GetWeapons { get { return m_getweapons; } set { m_getweapons = value; } } [CommandProperty( AccessLevel.GameMaster )] public bool GetArmor { get { return m_getarmor; } set { m_getarmor = value; } } [CommandProperty( AccessLevel.GameMaster )] public bool GetJewelry { get { return m_getjewelry; } set { m_getjewelry = value; } } [CommandProperty( AccessLevel.GameMaster )] public bool GetPotions { get { return m_getpotions; } set { m_getpotions = value; } } [CommandProperty( AccessLevel.GameMaster )] public bool GetRegs { get { return m_getregs; } set { m_getregs = value; } } [CommandProperty( AccessLevel.GameMaster )] public bool GetClothes { get { return m_getclothes; } set { m_getclothes = value; } } [CommandProperty( AccessLevel.GameMaster )] public bool GetGems { get { return m_getgems; } set { m_getgems = value; } } [CommandProperty( AccessLevel.GameMaster )] public bool GetArtifact { get { return m_getartifact; } set { m_getartifact = value; } } [CommandProperty( AccessLevel.GameMaster )] public bool GetHides { get { return m_gethides; } set { m_gethides = value; } } [CommandProperty( AccessLevel.GameMaster )] public bool GetFood { get { return m_getfood; } set { m_getfood = value; } } public LootData(ASerial serial) : base(serial) { } [Attachable] public LootData() { } [Attachable] public LootData(bool allflag, bool goldflag, bool weaponsflag, bool armorflag, bool jewelryflag, bool potionsflag, bool regsflag, bool clothesflag, bool gemsflag, bool artifactflag, bool hidesflag, bool foodflag) { m_getall=allflag; m_getgold=goldflag; m_getweapons=weaponsflag; m_getarmor=armorflag; m_getjewelry=jewelryflag; m_getpotions=potionsflag; m_getregs=regsflag; m_getclothes=clothesflag; m_getgems=gemsflag; m_getartifact=artifactflag; m_gethides=hidesflag; m_getfood=foodflag; } public override void Serialize( GenericWriter writer ) { base.Serialize(writer); writer.Write( (int) 0 ); // version 0 writer.Write(m_getall); writer.Write(m_getgold); writer.Write(m_getweapons); writer.Write(m_getarmor); writer.Write(m_getjewelry); writer.Write(m_getpotions); writer.Write(m_getregs); writer.Write(m_getclothes); writer.Write(m_getgems); writer.Write(m_getartifact); writer.Write(m_gethides); writer.Write(m_getfood); } public override void Deserialize(GenericReader reader) { base.Deserialize(reader); // version 0 int version = reader.ReadInt(); m_getall = reader.ReadBool(); m_getgold = reader.ReadBool(); m_getweapons = reader.ReadBool(); m_getarmor = reader.ReadBool(); m_getjewelry = reader.ReadBool(); m_getpotions = reader.ReadBool(); m_getregs = reader.ReadBool(); m_getclothes = reader.ReadBool(); m_getgems = reader.ReadBool(); m_getartifact = reader.ReadBool(); m_gethides = reader.ReadBool(); m_getfood = reader.ReadBool(); } } } |
CODE |
// does player already have a lootdata attachment? if (XmlAttach.FindAttachment(e.Mobile, typeof(LootData))==null) { // create lootdata attachment and add it to the player LootData lootoptions = new LootData(); XmlAttach.AttachTo(e.Mobile, lootoptions); } else { // player has the attachment so set the variable LootData lootoptions = (LootData)XmlAttach.FindAttachment(e.Mobile, typeof(LootData)); } Console.WriteLine("bool getall is:" + lootoptions.GetAll); |
CODE |
else { // player has the attachment so set the variable LootData lootoptions = (LootData)XmlAttach.FindAttachment(e.Mobile, typeof(LootData)); // lootoptions exists in here } // but it doesnt exist out here Console.WriteLine("bool getall is:" + lootoptions.GetAll); |
CODE |
[Usage("testloot")] [Description("test the loot options xmlattachment")] public static void testloot_OnCommand(CommandEventArgs e) { // does player already have a lootdata attachment? LootData lootoptions = (LootData)XmlAttach.FindAttachment(e.Mobile, typeof(LootData)); if (lootoptions == null) { // create lootdata attachment and add it to the player lootoptions = new LootData(); XmlAttach.AttachTo(e.Mobile, lootoptions); } if (lootoptions != null) { Console.WriteLine("bool getall is:" + lootoptions.GetAll); } } |