Ejemplo n.º 1
0
        public bool RemoveThing(ushort id, ThingCategory category)
        {
            if (this.Disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            if (!this.Loaded || category == ThingCategory.Invalid)
            {
                return(false);
            }

            ThingType changedThing = this.InternalRemoveThing(id, category);

            if (changedThing != null)
            {
                this.Changed = true;

                if (this.StorageChanged != null)
                {
                    this.StorageChanged(this, new ThingListChangedArgs(new ThingType[] { changedThing }, StorageChangeType.Remove));
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        private ThingType InternalReplaceThing(ThingType newThing, ThingType oldThing)
        {
            if (newThing == null || oldThing == null || newThing.Category != oldThing.Category || !this.HasThing(oldThing.ID, oldThing.Category))
            {
                return(null);
            }

            switch (oldThing.Category)
            {
            case ThingCategory.Item:
                this.Items[oldThing.ID] = newThing;
                break;

            case ThingCategory.Outfit:
                this.Outfits[oldThing.ID] = newThing;
                break;

            case ThingCategory.Effect:
                this.Effects[oldThing.ID] = newThing;
                break;

            case ThingCategory.Missile:
                this.Missiles[oldThing.ID] = newThing;
                break;
            }

            newThing.ID = oldThing.ID;
            return(oldThing);
        }
Ejemplo n.º 3
0
        public bool RemoveThing(ThingType thing)
        {
            if (thing == null)
            {
                throw new ArgumentNullException(nameof(thing));
            }

            if (this.Disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            if (!this.Loaded || thing.Category == ThingCategory.Invalid)
            {
                return(false);
            }

            ThingType changedThing = this.InternalRemoveThing(thing.ID, thing.Category);

            if (changedThing != null)
            {
                this.Changed = true;

                if (this.StorageChanged != null)
                {
                    this.StorageChanged(this, new ThingListChangedArgs(new ThingType[] { changedThing }, StorageChangeType.Remove));
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        private bool InternalCreate(Core.Version version, ClientFeatures features)
        {
            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            if (this.Loaded)
            {
                return(true);
            }

            if (features == ClientFeatures.None || features == ClientFeatures.Transparency)
            {
                features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features;
                features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features;
                features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features;
                features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features;
            }

            this.Version        = version;
            this.ClientFeatures = features;
            this.Items.Add(100, ThingType.Create(100, ThingCategory.Item));
            this.ItemCount = 100;
            this.Outfits.Add(1, ThingType.Create(1, ThingCategory.Outfit));
            this.OutfitCount = 1;
            this.Effects.Add(1, ThingType.Create(1, ThingCategory.Effect));
            this.EffectCount = 1;
            this.Missiles.Add(1, ThingType.Create(1, ThingCategory.Missile));
            this.MissileCount = 1;
            this.Changed      = true;
            this.Loaded       = true;
            this.Disposed     = false;
            return(true);
        }
Ejemplo n.º 5
0
        private ThingType InternalAddThing(ThingType thing)
        {
            if (thing == null || thing.Category == ThingCategory.Invalid)
            {
                return(null);
            }

            ushort id = 0;

            switch (thing.Category)
            {
            case ThingCategory.Item:
                id = ++this.ItemCount;
                this.Items.Add(id, thing);
                break;

            case ThingCategory.Outfit:
                id = ++this.OutfitCount;
                this.Outfits.Add(id, thing);
                break;

            case ThingCategory.Effect:
                id = ++this.EffectCount;
                this.Effects.Add(id, thing);
                break;

            case ThingCategory.Missile:
                id = ++this.MissileCount;
                this.Missiles.Add(id, thing);
                break;
            }

            thing.ID = id;
            return(thing);
        }
Ejemplo n.º 6
0
        public bool AddThing(ThingType thing)
        {
            if (thing == null)
            {
                throw new ArgumentNullException(nameof(thing));
            }

            if (this.Disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            if (!this.Loaded)
            {
                return(false);
            }

            ThingType changedThing = this.InternalAddThing(thing);

            if (changedThing != null)
            {
                this.Changed = true;

                if (this.StorageChanged != null)
                {
                    this.StorageChanged(this, new ThingListChangedArgs(new ThingType[] { changedThing }, StorageChangeType.Add));
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
        public static bool ReadProperties(ThingType thing, DatFormat format, BinaryReader reader)
        {
            if (format >= DatFormat.Format_1010)
            {
                if (!ReadProperties_1010_1093(thing, reader, format))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 8
0
        public static bool ReadProperties(ThingType thing, DatFormat format, BinaryReader reader)
        {
            if (format == DatFormat.Format_1010 || format == DatFormat.Format_1050 || format == DatFormat.Format_1057)
            {
                if (!ReadProperties_1010_1057(thing, reader))
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 9
0
        public static bool WriteProperties(ThingType thing, DatFormat format, FlagsBinaryWriter writer)
        {
            if (format >= DatFormat.Format_1010)
            {
                if (!WriteProperties_1010_1093(thing, writer, format))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 10
0
        public ThingType Clone()
        {
            ThingType clone = (ThingType)MemberwiseClone();

            clone.FrameGroups = new Dictionary <FrameGroupType, FrameGroup>();

            foreach (KeyValuePair <FrameGroupType, FrameGroup> keyValue in FrameGroups)
            {
                clone.FrameGroups.Add(keyValue.Key, keyValue.Value.Clone());
            }

            return(clone);
        }
Ejemplo n.º 11
0
        public ThingData(ThingType type, SpriteGroup sprites)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (sprites == null)
            {
                throw new ArgumentNullException("sprites");
            }

            this.type = type;
            this.sprites = sprites;
            this.Format = DatFormat.Format_1057;
        }
Ejemplo n.º 12
0
        public bool RemoveThings(ThingType[] things)
        {
            if (things == null)
            {
                throw new ArgumentNullException(nameof(things));
            }

            if (this.Disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            if (!this.Loaded || things.Length == 0)
            {
                return(false);
            }

            List <ThingType> changedThings = new List <ThingType>();

            for (int i = 0; i < things.Length; i++)
            {
                ThingType thing = things[i];
                if (thing != null)
                {
                    thing = this.InternalRemoveThing(thing.ID, thing.Category);
                    if (thing != null)
                    {
                        changedThings.Add(thing);
                    }
                }
            }

            if (changedThings.Count != 0)
            {
                this.Changed = true;

                if (this.StorageChanged != null)
                {
                    this.StorageChanged(this, new ThingListChangedArgs(changedThings.ToArray(), StorageChangeType.Remove));
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 13
0
        public static ThingType Create(ushort id, ThingCategory category)
        {
            if (category == ThingCategory.Invalid)
            {
                throw new ArgumentException("Invalid category.");
            }

            ThingType thing = new ThingType(id, category);

            if (category == ThingCategory.Outfit)
            {
                for (int i = 0; i < 2; i++)
                {
                    FrameGroup group = FrameGroup.Create();
                    group.PatternX       = 4; // directions
                    group.Frames         = 3; // animations
                    group.IsAnimation    = true;
                    group.SpriteIDs      = new uint[group.GetTotalSprites()];
                    group.FrameDurations = new FrameDuration[group.Frames];

                    for (int f = 0; f < group.Frames; f++)
                    {
                        group.FrameDurations[f] = new FrameDuration(category);
                    }

                    thing.SetFrameGroup((FrameGroupType)i, group);
                }
            }
            else
            {
                FrameGroup group = FrameGroup.Create();

                if (category == ThingCategory.Missile)
                {
                    group.PatternX  = 3;
                    group.PatternY  = 3;
                    group.SpriteIDs = new uint[group.GetTotalSprites()];
                }

                thing.SetFrameGroup(FrameGroupType.Default, group);
            }

            return(thing);
        }
Ejemplo n.º 14
0
 public ThingListChangedArgs(ThingType[] changedThings, StorageChangeType changeType)
 {
     this.ChangedThings = changedThings;
     this.ChangeType = changeType;
 }
Ejemplo n.º 15
0
        private static bool ReadProperties_1010_1093(ThingType thing, BinaryReader reader, DatFormat format)
        {
            DatFlags1010 flag;

            do
            {
                flag = (DatFlags1010)reader.ReadByte();

                if (flag == DatFlags1010.LastFlag)
                {
                    break;
                }

                switch (flag)
                {
                case DatFlags1010.Ground:     // 0x00
                    thing.StackOrder  = StackOrder.Ground;
                    thing.GroundSpeed = reader.ReadUInt16();
                    break;

                case DatFlags1010.GroundBorder:     // 0x01
                    thing.StackOrder = StackOrder.Border;
                    break;

                case DatFlags1010.OnBottom:     // 0x02
                    thing.StackOrder = StackOrder.Bottom;
                    break;

                case DatFlags1010.OnTop:     // 0x03
                    thing.StackOrder = StackOrder.Top;
                    break;

                case DatFlags1010.Container:     // 0x04
                    thing.IsContainer = true;
                    break;

                case DatFlags1010.Stackable:
                    thing.Stackable = true;
                    break;

                case DatFlags1010.ForceUse:
                    thing.ForceUse = true;
                    break;

                case DatFlags1010.MultiUse:
                    thing.MultiUse = true;
                    break;

                case DatFlags1010.Writable:
                    thing.Writable      = true;
                    thing.MaxTextLength = reader.ReadUInt16();
                    break;

                case DatFlags1010.WritableOnce:
                    thing.WritableOnce  = true;
                    thing.MaxTextLength = reader.ReadUInt16();
                    break;

                case DatFlags1010.FluidContainer:
                    thing.IsFluidContainer = true;
                    break;

                case DatFlags1010.Fluid:
                    thing.IsFluid = true;
                    break;

                case DatFlags1010.IsUnpassable:
                    thing.Unpassable = true;
                    break;

                case DatFlags1010.IsUnmovable:
                    thing.Unmovable = true;
                    break;

                case DatFlags1010.BlockMissiles:
                    thing.BlockMissiles = true;
                    break;

                case DatFlags1010.BlockPathfinder:
                    thing.BlockPathfinder = true;
                    break;

                case DatFlags1010.NoMoveAnimation:     // 0x10
                    thing.NoMoveAnimation = true;
                    break;

                case DatFlags1010.Pickupable:
                    thing.Pickupable = true;
                    break;

                case DatFlags1010.Hangable:
                    thing.Hangable = true;
                    break;

                case DatFlags1010.HookSouth:
                    thing.HookSouth = true;
                    break;

                case DatFlags1010.HookEast:
                    thing.HookEast = true;
                    break;

                case DatFlags1010.Rotatable:
                    thing.Rotatable = true;
                    break;

                case DatFlags1010.HasLight:
                    thing.HasLight   = true;
                    thing.LightLevel = reader.ReadUInt16();
                    thing.LightColor = reader.ReadUInt16();
                    break;

                case DatFlags1010.DontHide:
                    thing.DontHide = true;
                    break;

                case DatFlags1010.Translucent:
                    thing.Translucent = true;
                    break;

                case DatFlags1010.HasOffset:
                    thing.HasOffset = true;
                    thing.OffsetX   = reader.ReadUInt16();
                    thing.OffsetY   = reader.ReadUInt16();
                    break;

                case DatFlags1010.HasElevation:
                    thing.HasElevation = true;
                    thing.Elevation    = reader.ReadUInt16();
                    break;

                case DatFlags1010.LyingObject:
                    thing.LyingObject = true;
                    break;

                case DatFlags1010.Minimap:
                    thing.Minimap      = true;
                    thing.MinimapColor = reader.ReadUInt16();
                    break;

                case DatFlags1010.AnimateAlways:
                    thing.AnimateAlways = true;
                    break;

                case DatFlags1010.LensHelp:
                    thing.IsLensHelp = true;
                    thing.LensHelp   = reader.ReadUInt16();
                    break;

                case DatFlags1010.FullGround:
                    thing.FullGround = true;
                    break;

                case DatFlags1010.IgnoreLook:
                    thing.IgnoreLook = true;
                    break;

                case DatFlags1010.Cloth:
                    thing.IsCloth   = true;
                    thing.ClothSlot = (ClothSlot)reader.ReadUInt16();
                    break;

                case DatFlags1010.Market:
                    thing.IsMarketItem   = true;
                    thing.MarketCategory = (MarketCategory)reader.ReadUInt16();
                    thing.MarketTradeAs  = reader.ReadUInt16();
                    thing.MarketShowAs   = reader.ReadUInt16();

                    ushort nameLength = reader.ReadUInt16();
                    byte[] buffer     = reader.ReadBytes(nameLength);
                    thing.MarketName             = Encoding.Default.GetString(buffer, 0, buffer.Length);
                    thing.MarketRestrictVocation = reader.ReadUInt16();
                    thing.MarketRestrictLevel    = reader.ReadUInt16();
                    break;

                case DatFlags1010.DefaultAction:
                    thing.HasAction     = true;
                    thing.DefaultAction = (DefaultAction)reader.ReadUInt16();
                    break;

                case DatFlags1010.Wrappable:
                    thing.Wrappable = true;
                    break;

                case DatFlags1010.Unwrappable:
                    thing.Unwrappable = true;
                    break;

                case DatFlags1010.TopEffect:
                    thing.IsTopEffect = true;
                    break;

                case DatFlags1010.Usable:
                    thing.Usable = true;
                    break;

                default:
                    throw new Exception(string.Format("Error while parsing, unknown flag 0x{0:X} at object id {1}, category {2}.", flag, thing.ID, thing.Category));
                }
            }while (flag != DatFlags1010.LastFlag);

            return(true);
        }
Ejemplo n.º 16
0
 public void Add(ThingType thing)
 {
     Items.Add(thing);
 }
Ejemplo n.º 17
0
        private ThingType InternalAddThing(ThingType thing)
        {
            if (thing == null || thing.Category == ThingCategory.Invalid)
            {
                return null;
            }

            ushort id = 0;

            switch (thing.Category)
            {
                case ThingCategory.Item:
                    id = ++this.ItemCount;
                    this.Items.Add(id, thing);
                    break;

                case ThingCategory.Outfit:
                    id = ++this.OutfitCount;
                    this.Outfits.Add(id, thing);
                    break;

                case ThingCategory.Effect:
                    id = ++this.EffectCount;
                    this.Effects.Add(id, thing);
                    break;

                case ThingCategory.Missile:
                    id = ++this.MissileCount;
                    this.Missiles.Add(id, thing);
                    break;
            }

            thing.ID = id;
            return thing;
        }
Ejemplo n.º 18
0
        public Bitmap GetObjectImage(ThingType thing)
        {
            if (thing != null)
            {
                return this.GetObjectImage(thing.ID, thing.Category, FrameGroupType.Default);
            }

            return null;
        }
Ejemplo n.º 19
0
        private bool InternalLoad(string path, Core.Version version, ClientFeatures features)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"File not found: {path}", path);
            }

            if (this.Loaded)
            {
                return(true);
            }

            if (features == ClientFeatures.None || features == ClientFeatures.Transparency)
            {
                features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features;
                features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features;
                features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features;
                features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features;
            }

            using (FileStream stream = new FileStream(path, FileMode.Open))
            {
                BinaryReader reader = new BinaryReader(stream);

                uint signature = reader.ReadUInt32();
                if (signature != version.DatSignature)
                {
                    string message = "Invalid DAT signature. Expected signature is {0:X} and loaded signature is {1:X}.";
                    throw new Exception(string.Format(message, version.DatSignature, signature));
                }

                this.ItemCount    = reader.ReadUInt16();
                this.OutfitCount  = reader.ReadUInt16();
                this.EffectCount  = reader.ReadUInt16();
                this.MissileCount = reader.ReadUInt16();

                int total  = this.ItemCount + this.OutfitCount + this.EffectCount + this.MissileCount;
                int loaded = 0;

                // load item list.
                for (ushort id = 100; id <= this.ItemCount; id++)
                {
                    ThingType item = new ThingType(id, ThingCategory.Item);
                    if (!ThingTypeSerializer.ReadProperties(item, version.Format, reader) ||
                        !ThingTypeSerializer.ReadTexturePatterns(item, features, reader))
                    {
                        throw new Exception("Items list cannot be loaded.");
                    }

                    this.Items.Add(id, item);
                }

                // update progress.
                if (this.ProgressChanged != null)
                {
                    loaded += this.ItemCount;
                    this.ProgressChanged(this, (loaded * 100) / total);
                }

                // load outfit list.
                for (ushort id = 1; id <= this.OutfitCount; id++)
                {
                    ThingType outfit = new ThingType(id, ThingCategory.Outfit);
                    if (!ThingTypeSerializer.ReadProperties(outfit, version.Format, reader) ||
                        !ThingTypeSerializer.ReadTexturePatterns(outfit, features, reader))
                    {
                        throw new Exception("Outfits list cannot be loaded.");
                    }

                    this.Outfits.Add(id, outfit);
                }

                // update progress.
                if (this.ProgressChanged != null)
                {
                    loaded += this.OutfitCount;
                    this.ProgressChanged(this, (loaded * 100) / total);
                }

                // load effect list.
                for (ushort id = 1; id <= this.EffectCount; id++)
                {
                    ThingType effect = new ThingType(id, ThingCategory.Effect);
                    if (!ThingTypeSerializer.ReadProperties(effect, version.Format, reader) ||
                        !ThingTypeSerializer.ReadTexturePatterns(effect, features, reader))
                    {
                        throw new Exception("Effects list cannot be loaded.");
                    }

                    this.Effects.Add(id, effect);
                }

                // update progress.
                if (this.ProgressChanged != null)
                {
                    loaded += this.EffectCount;
                    this.ProgressChanged(this, (loaded * 100) / total);
                }

                // load missile list.
                for (ushort id = 1; id <= this.MissileCount; id++)
                {
                    ThingType missile = new ThingType(id, ThingCategory.Missile);
                    if (!ThingTypeSerializer.ReadProperties(missile, version.Format, reader) ||
                        !ThingTypeSerializer.ReadTexturePatterns(missile, features, reader))
                    {
                        throw new Exception("Missiles list cannot be loaded.");
                    }

                    this.Missiles.Add(id, missile);
                }

                // update progress.
                if (this.ProgressChanged != null)
                {
                    loaded += this.MissileCount;
                    this.ProgressChanged(this, (loaded * 100) / total);
                }
            }

            this.FilePath       = path;
            this.Version        = version;
            this.ClientFeatures = features;
            this.Changed        = false;
            this.Loaded         = true;
            this.Disposed       = false;
            return(true);
        }
Ejemplo n.º 20
0
        public static ThingType Create(ushort id, ThingCategory category)
        {
            if (category == ThingCategory.Invalid)
            {
                throw new ArgumentException("Invalid category.");
            }

            ThingType thing = new ThingType(id, category);

            if (category == ThingCategory.Outfit)
            {
                for (int i = 0; i < 2; i++)
                {
                    FrameGroup group = FrameGroup.Create();
                    group.PatternX = 4; // directions
                    group.Frames = 3;   // animations
                    group.IsAnimation = true;
                    group.SpriteIDs = new uint[group.GetTotalSprites()];
                    group.FrameDurations = new FrameDuration[group.Frames];

                    for (int f = 0; f < group.Frames; f++)
                    {
                        group.FrameDurations[f] = new FrameDuration(category);
                    }

                    thing.SetFrameGroup((FrameGroupType)i, group);
                }
            }
            else
            {
                FrameGroup group = FrameGroup.Create();

                if (category == ThingCategory.Missile)
                {
                    group.PatternX = 3;
                    group.PatternY = 3;
                    group.SpriteIDs = new uint[group.GetTotalSprites()];
                }

                thing.SetFrameGroup(FrameGroupType.Default, group);
            }

            return thing;
        }
Ejemplo n.º 21
0
        public bool Save(string path, Core.Version version, ClientFeatures features)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            if (this.Disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            if (!this.Loaded)
            {
                return(false);
            }

            if (features == ClientFeatures.None || features == ClientFeatures.Transparency)
            {
                features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features;
                features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features;
                features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features;
                features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features;
            }

            string directory = Path.GetDirectoryName(path);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            if (!this.Changed && this.Version.Equals(version) && this.ClientFeatures == features &&
                this.FilePath != null && !this.FilePath.Equals(path))
            {
                // just copy the content if nothing has changed.
                File.Copy(this.FilePath, path, true);

                if (this.ProgressChanged != null)
                {
                    this.ProgressChanged(this, 100);
                }
            }
            else
            {
                string tmpPath = Path.Combine(directory, Path.GetFileNameWithoutExtension(path) + ".tmp");

                using (FlagsBinaryWriter writer = new FlagsBinaryWriter(new FileStream(tmpPath, FileMode.Create)))
                {
                    // write the signature.
                    writer.Write(version.DatSignature);

                    // write item, outfit, effect and missile count.
                    writer.Write(this.ItemCount);
                    writer.Write(this.OutfitCount);
                    writer.Write(this.EffectCount);
                    writer.Write(this.MissileCount);

                    int total    = this.ItemCount + this.OutfitCount + this.EffectCount + this.MissileCount;
                    int compiled = 0;

                    // write item list.
                    for (ushort id = 100; id <= this.ItemCount; id++)
                    {
                        ThingType item = this.Items[id];
                        if (!ThingTypeSerializer.WriteProperties(item, version.Format, writer) ||
                            !ThingTypeSerializer.WriteTexturePatterns(item, features, writer))
                        {
                            throw new Exception("Items list cannot be compiled.");
                        }
                    }

                    // update progress.
                    if (this.ProgressChanged != null)
                    {
                        compiled += this.ItemCount;
                        this.ProgressChanged(this, (compiled * 100) / total);
                    }

                    bool onlyOneGroup = ((this.ClientFeatures & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups) &&
                                        ((features & ClientFeatures.FrameGroups) != ClientFeatures.FrameGroups);

                    // write outfit list.
                    for (ushort id = 1; id <= this.OutfitCount; id++)
                    {
                        ThingType outfit = onlyOneGroup ? ThingType.ToSingleFrameGroup(this.Outfits[id]) : this.Outfits[id];
                        if (!ThingTypeSerializer.WriteProperties(outfit, version.Format, writer) ||
                            !ThingTypeSerializer.WriteTexturePatterns(outfit, features, writer))
                        {
                            throw new Exception("Outfits list cannot be compiled.");
                        }
                    }

                    // update progress.
                    if (this.ProgressChanged != null)
                    {
                        compiled += this.OutfitCount;
                        this.ProgressChanged(this, (compiled * 100) / total);
                    }

                    // write effect list.
                    for (ushort id = 1; id <= this.EffectCount; id++)
                    {
                        ThingType effect = this.Effects[id];
                        if (!ThingTypeSerializer.WriteProperties(effect, version.Format, writer) ||
                            !ThingTypeSerializer.WriteTexturePatterns(effect, features, writer))
                        {
                            throw new Exception("Effects list cannot be compiled.");
                        }
                    }

                    // update progress.
                    if (this.ProgressChanged != null)
                    {
                        compiled += this.EffectCount;
                        this.ProgressChanged(this, (compiled * 100) / total);
                    }

                    // write missile list.
                    for (ushort id = 1; id <= this.MissileCount; id++)
                    {
                        ThingType missile = this.Missiles[id];
                        if (!ThingTypeSerializer.WriteProperties(missile, version.Format, writer) ||
                            !ThingTypeSerializer.WriteTexturePatterns(missile, features, writer))
                        {
                            throw new Exception("Missiles list cannot be compiled.");
                        }
                    }

                    // update progress.
                    if (this.ProgressChanged != null)
                    {
                        compiled += this.MissileCount;
                        this.ProgressChanged(this, (compiled * 100) / total);
                    }
                }

                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                File.Move(tmpPath, path);
            }

            this.FilePath       = path;
            this.Version        = version;
            this.ClientFeatures = features;
            this.Changed        = false;

            if (this.StorageCompiled != null)
            {
                this.StorageCompiled(this);
            }

            return(true);
        }
Ejemplo n.º 22
0
        public static ThingType ToSingleFrameGroup(ThingType thing)
        {
            if (thing.Category != ThingCategory.Outfit || thing.FrameGroupCount != 2)
            {
                return thing;
            }

            FrameGroup walkingFrameGroup = thing.GetFrameGroup(FrameGroupType.Walking);
            FrameGroup newGroup = walkingFrameGroup.Clone();

            if (walkingFrameGroup.Frames > 1)
            {
                newGroup.Frames = (byte)(newGroup.Frames + 1);
                newGroup.SpriteIDs = new uint[newGroup.GetTotalSprites()];
                newGroup.IsAnimation = true;
                newGroup.FrameDurations = new FrameDuration[newGroup.Frames];

                for (int i = 0; i < newGroup.Frames; i++)
                {
                    if (newGroup.FrameDurations[i] != null)
                    {
                        newGroup.FrameDurations[i] = newGroup.FrameDurations[i];
                    }
                    else
                    {
                        newGroup.FrameDurations[i] = new FrameDuration(ThingCategory.Outfit);
                    }
                }
            }

            for (byte k = 0; k < thing.FrameGroupCount; k++)
            {
                FrameGroup group = thing.GetFrameGroup((FrameGroupType)k);

                for (byte f = 0; f < group.Frames; f++)
                {
                    for (byte z = 0; z < group.PatternZ; z++)
                    {
                        for (byte y = 0; y < group.PatternY; y++)
                        {
                            for (byte x = 0; x < group.PatternX; x++)
                            {
                                for (byte l = 0; l < group.Layers; l++)
                                {
                                    for (byte w = 0; w < group.Width; w++)
                                    {
                                        for (byte h = 0; h < group.Height; h++)
                                        {
                                            if (k == (byte)FrameGroupType.Default && f == 0)
                                            {
                                                int i = group.GetSpriteIndex(w, h, l, x, y, z, f);
                                                int ni = newGroup.GetSpriteIndex(w, h, l, x, y, z, f);
                                                newGroup.SpriteIDs[ni] = group.SpriteIDs[i];
                                            }
                                            else if (k == (byte)FrameGroupType.Walking)
                                            {
                                                int i = group.GetSpriteIndex(w, h, l, x, y, z, f);
                                                int ni = newGroup.GetSpriteIndex(w, h, l, x, y, z, f + 1);
                                                newGroup.SpriteIDs[ni] = group.SpriteIDs[i];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            thing.frameGroups = new Dictionary<FrameGroupType, FrameGroup>();
            thing.frameGroups.Add(FrameGroupType.Default, newGroup);
            return thing;
        }
Ejemplo n.º 23
0
        public bool ReplaceThing(ThingType thing)
        {
            if (thing == null)
            {
                throw new ArgumentNullException("thing");
            }

            if (this.Disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            if (!this.Loaded)
            {
                return false;
            }

            ThingType changedThing = this.InternalReplaceThing(thing, this.GetThing(thing.ID, thing.Category));
            if (changedThing != null)
            {
                this.Changed = true;

                if (this.StorageChanged != null)
                {
                    this.StorageChanged(this, new ThingListChangedArgs(new ThingType[] { changedThing }, StorageChangeType.Replace));
                }

                return true;
            }

            return false;
        }
Ejemplo n.º 24
0
        public bool ReplaceThings(ThingType[] things)
        {
            if (things == null)
            {
                throw new ArgumentNullException("things");
            }

            if (this.Disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            if (!this.Loaded || things.Length == 0)
            {
                return false;
            }

            List<ThingType> changedThings = new List<ThingType>();

            for (int i = 0; i < things.Length; i++)
            {
                ThingType thing = things[i];
                if (thing != null)
                {
                    thing = this.InternalReplaceThing(thing, this.GetThing(thing.ID, thing.Category));
                    if (thing != null)
                    {
                        changedThings.Add(thing);
                    }
                }
            }

            if (changedThings.Count != 0)
            {
                this.Changed = true;

                if (this.StorageChanged != null)
                {
                    this.StorageChanged(this, new ThingListChangedArgs(changedThings.ToArray(), StorageChangeType.Replace));
                }

                return true;
            }

            return false;
        }
Ejemplo n.º 25
0
        public static bool WriteProperties(ThingType thing, DatFormat format, BinaryWriter writer)
        {
            if (format == DatFormat.Format_1010 || format == DatFormat.Format_1050 || format == DatFormat.Format_1057)
            {
                if (!WriteProperties_1010_1057(thing, writer))
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 26
0
        private bool InternalLoad(string path, Core.Version version, ClientFeatures features)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            if (version == null)
            {
                throw new ArgumentNullException("version");
            }

            if (!File.Exists(path))
            {
                throw new FileNotFoundException(string.Format("File not found: {0}", path), path);
            }

            if (this.Loaded)
            {
                return true;
            }

            if (features == ClientFeatures.None || features == ClientFeatures.Transparency)
            {
                features |= version.Value >= (ushort)DatFormat.Format_755 ? ClientFeatures.PatternZ : features;
                features |= version.Value >= (ushort)DatFormat.Format_960 ? ClientFeatures.Extended : features;
                features |= version.Value >= (ushort)DatFormat.Format_1050 ? ClientFeatures.FrameDurations : features;
                features |= version.Value >= (ushort)DatFormat.Format_1057 ? ClientFeatures.FrameGroups : features;
            }

            using (FileStream stream = new FileStream(path, FileMode.Open))
            {
                BinaryReader reader = new BinaryReader(stream);

                uint signature = reader.ReadUInt32();
                if (signature != version.DatSignature)
                {
                    string message = "Invalid DAT signature. Expected signature is {0:X} and loaded signature is {1:X}.";
                    throw new Exception(string.Format(message, version.DatSignature, signature));
                }

                this.ItemCount = reader.ReadUInt16();
                this.OutfitCount = reader.ReadUInt16();
                this.EffectCount = reader.ReadUInt16();
                this.MissileCount = reader.ReadUInt16();

                int total = this.ItemCount + this.OutfitCount + this.EffectCount + this.MissileCount;
                int loaded = 0;

                // load item list.
                for (ushort id = 100; id <= this.ItemCount; id++)
                {
                    ThingType item = new ThingType(id, ThingCategory.Item);
                    if (!ThingTypeSerializer.ReadProperties(item, version.Format, reader) ||
                        !ThingTypeSerializer.ReadTexturePatterns(item, features, reader))
                    {
                        throw new Exception("Items list cannot be loaded.");
                    }

                    this.Items.Add(id, item);
                }

                // update progress.
                if (this.ProgressChanged != null)
                {
                    loaded += this.ItemCount;
                    this.ProgressChanged(this, (loaded * 100) / total);
                }

                // load outfit list.
                for (ushort id = 1; id <= this.OutfitCount; id++)
                {
                    ThingType outfit = new ThingType(id, ThingCategory.Outfit);
                    if (!ThingTypeSerializer.ReadProperties(outfit, version.Format, reader) ||
                        !ThingTypeSerializer.ReadTexturePatterns(outfit, features, reader))
                    {
                        throw new Exception("Outfits list cannot be loaded.");
                    }

                    this.Outfits.Add(id, outfit);
                }

                // update progress.
                if (this.ProgressChanged != null)
                {
                    loaded += this.OutfitCount;
                    this.ProgressChanged(this, (loaded * 100) / total);
                }

                // load effect list.
                for (ushort id = 1; id <= this.EffectCount; id++)
                {
                    ThingType effect = new ThingType(id, ThingCategory.Effect);
                    if (!ThingTypeSerializer.ReadProperties(effect, version.Format, reader) ||
                        !ThingTypeSerializer.ReadTexturePatterns(effect, features, reader))
                    {
                        throw new Exception("Effects list cannot be loaded.");
                    }

                    this.Effects.Add(id, effect);
                }

                // update progress.
                if (this.ProgressChanged != null)
                {
                    loaded += this.EffectCount;
                    this.ProgressChanged(this, (loaded * 100) / total);
                }

                // load missile list.
                for (ushort id = 1; id <= this.MissileCount; id++)
                {
                    ThingType missile = new ThingType(id, ThingCategory.Missile);
                    if (!ThingTypeSerializer.ReadProperties(missile, version.Format, reader) ||
                        !ThingTypeSerializer.ReadTexturePatterns(missile, features, reader))
                    {
                        throw new Exception("Missiles list cannot be loaded.");
                    }

                    this.Missiles.Add(id, missile);
                }

                // update progress.
                if (this.ProgressChanged != null)
                {
                    loaded += this.MissileCount;
                    this.ProgressChanged(this, (loaded * 100) / total);
                }
            }

            this.FilePath = path;
            this.Version = version;
            this.ClientFeatures = features;
            this.Changed = false;
            this.Loaded = true;
            this.Disposed = false;
            return true;
        }
Ejemplo n.º 27
0
        public static bool WriteTexturePatterns(ThingType thing, ClientFeatures features, BinaryWriter writer)
        {
            bool patternZEnabled = (features & ClientFeatures.PatternZ) == ClientFeatures.PatternZ;
            bool extendedEnabled = (features & ClientFeatures.Extended) == ClientFeatures.Extended;
            bool frameDurationsEnabled = (features & ClientFeatures.FrameDurations) == ClientFeatures.FrameDurations;
            bool frameGroupsEnabled = (features & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups;
            byte groupCount = 1;

            // write frame group count.
            if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit)
            {
                groupCount = thing.FrameGroupCount;
                writer.Write(groupCount);
            }

            for (byte k = 0; k < groupCount; k++)
            {
                // write frame group type.
                if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit)
                {
                    writer.Write(k);
                }

                FrameGroup group = thing.GetFrameGroup((FrameGroupType)k);

                writer.Write(group.Width);  // write width
                writer.Write(group.Height); // write heigh

                // write exact size
                if (group.Width > 1 || group.Height > 1)
                {
                    writer.Write(group.ExactSize);
                }

                writer.Write(group.Layers);     // write layers
                writer.Write(group.PatternX);   // write pattern X
                writer.Write(group.PatternY);   // write pattern Y

                if (patternZEnabled)
                {
                    writer.Write(group.PatternZ); // write pattern Z
                }

                writer.Write(group.Frames); // write frames

                if (frameDurationsEnabled && group.Frames > 1)
                {
                    writer.Write((byte)group.AnimationMode); // write animation type
                    writer.Write(group.LoopCount); // write frame strategy
                    writer.Write(group.StartFrame); // write start frame

                    FrameDuration[] durations = group.FrameDurations;
                    for (int i = 0; i < durations.Length; i++)
                    {
                        writer.Write((uint)durations[i].Minimum); // write minimum duration
                        writer.Write((uint)durations[i].Maximum); // write maximum duration
                    }
                }

                uint[] sprites = group.SpriteIDs;
                for (int i = 0; i < sprites.Length; i++)
                {
                    // write sprite index
                    if (extendedEnabled)
                    {
                        writer.Write(sprites[i]);
                    }
                    else
                    {
                        writer.Write((ushort)sprites[i]);
                    }
                }
            }

            return true;
        }
Ejemplo n.º 28
0
        private static bool WriteProperties_1010_1093(ThingType thing, FlagsBinaryWriter writer, DatFormat format)
        {
            if (thing.Category == ThingCategory.Item)
            {
                if (thing.StackOrder == StackOrder.Ground)
                {
                    writer.Write(DatFlags1010.Ground);
                    writer.Write(thing.GroundSpeed);
                }
                else if (thing.StackOrder == StackOrder.Border)
                {
                    writer.Write(DatFlags1010.GroundBorder);
                }
                else if (thing.StackOrder == StackOrder.Bottom)
                {
                    writer.Write(DatFlags1010.OnBottom);
                }
                else if (thing.StackOrder == StackOrder.Top)
                {
                    writer.Write(DatFlags1010.OnTop);
                }

                if (thing.IsContainer)
                {
                    writer.Write(DatFlags1010.Container);
                }

                if (thing.Stackable)
                {
                    writer.Write(DatFlags1010.Stackable);
                }

                if (thing.ForceUse)
                {
                    writer.Write(DatFlags1010.ForceUse);
                }

                if (thing.MultiUse)
                {
                    writer.Write(DatFlags1010.MultiUse);
                }

                if (thing.Writable)
                {
                    writer.Write(DatFlags1010.Writable);
                    writer.Write(thing.MaxTextLength);
                }

                if (thing.WritableOnce)
                {
                    writer.Write(DatFlags1010.WritableOnce);
                    writer.Write(thing.MaxTextLength);
                }

                if (thing.IsFluidContainer)
                {
                    writer.Write(DatFlags1010.FluidContainer);
                }

                if (thing.IsFluid)
                {
                    writer.Write(DatFlags1010.Fluid);
                }

                if (thing.Unpassable)
                {
                    writer.Write(DatFlags1010.IsUnpassable);
                }

                if (thing.Unmovable)
                {
                    writer.Write(DatFlags1010.IsUnmovable);
                }

                if (thing.BlockMissiles)
                {
                    writer.Write(DatFlags1010.BlockMissiles);
                }

                if (thing.BlockPathfinder)
                {
                    writer.Write(DatFlags1010.BlockPathfinder);
                }

                if (thing.NoMoveAnimation)
                {
                    writer.Write(DatFlags1010.NoMoveAnimation);
                }

                if (thing.Pickupable)
                {
                    writer.Write(DatFlags1010.Pickupable);
                }

                if (thing.Hangable)
                {
                    writer.Write(DatFlags1010.Hangable);
                }

                if (thing.HookSouth)
                {
                    writer.Write(DatFlags1010.HookSouth);
                }

                if (thing.HookEast)
                {
                    writer.Write(DatFlags1010.HookEast);
                }

                if (thing.Rotatable)
                {
                    writer.Write(DatFlags1010.Rotatable);
                }

                if (thing.DontHide)
                {
                    writer.Write(DatFlags1010.DontHide);
                }

                if (thing.Translucent)
                {
                    writer.Write(DatFlags1010.Translucent);
                }

                if (thing.HasElevation)
                {
                    writer.Write(DatFlags1010.HasElevation);
                    writer.Write(thing.Elevation);
                }
                if (thing.LyingObject)
                {
                    writer.Write(DatFlags1010.LyingObject);
                }

                if (thing.Minimap)
                {
                    writer.Write(DatFlags1010.Minimap);
                    writer.Write(thing.MinimapColor);
                }

                if (thing.IsLensHelp)
                {
                    writer.Write(DatFlags1010.LensHelp);
                    writer.Write(thing.LensHelp);
                }

                if (thing.FullGround)
                {
                    writer.Write(DatFlags1010.FullGround);
                }

                if (thing.IgnoreLook)
                {
                    writer.Write(DatFlags1010.IgnoreLook);
                }

                if (thing.IsCloth)
                {
                    writer.Write(DatFlags1010.Cloth);
                    writer.Write((ushort)thing.ClothSlot);
                }

                if (thing.IsMarketItem)
                {
                    writer.Write(DatFlags1010.Market);
                    writer.Write((ushort)thing.MarketCategory);
                    writer.Write(thing.MarketTradeAs);
                    writer.Write(thing.MarketShowAs);
                    writer.Write((ushort)thing.MarketName.Length);
                    writer.Write(Encoding.Default.GetBytes(thing.MarketName));
                    writer.Write(thing.MarketRestrictVocation);
                    writer.Write(thing.MarketRestrictLevel);
                }

                if (thing.HasAction)
                {
                    writer.Write(DatFlags1010.DefaultAction);
                    writer.Write((ushort)thing.DefaultAction);
                }

                if (format >= DatFormat.Format_1092)
                {
                    if (thing.Wrappable)
                    {
                        writer.Write(DatFlags1010.Wrappable);
                    }

                    if (thing.Unwrappable)
                    {
                        writer.Write(DatFlags1010.Unwrappable);
                    }
                }

                if (thing.Usable)
                {
                    writer.Write(DatFlags1010.Usable);
                }
            }

            if (thing.AnimateAlways)
            {
                writer.Write(DatFlags1010.AnimateAlways);
            }

            if (thing.HasLight)
            {
                writer.Write(DatFlags1010.HasLight);
                writer.Write(thing.LightLevel);
                writer.Write(thing.LightColor);
            }

            if (thing.HasOffset)
            {
                writer.Write(DatFlags1010.HasOffset);
                writer.Write(thing.OffsetX);
                writer.Write(thing.OffsetY);
            }

            if (thing.IsTopEffect && format >= DatFormat.Format_1093)
            {
                writer.Write(DatFlags1010.TopEffect);
            }

            // close flags
            writer.Write(DatFlags1010.LastFlag);
            return(true);
        }
Ejemplo n.º 29
0
        private static ThingData DecodeV1(BinaryReader reader)
        {
            reader.BaseStream.Position = 0;

            Console.WriteLine(reader.ReadUInt16());

            ushort nameLength = reader.ReadUInt16();
            byte[] buffer = reader.ReadBytes(nameLength);
            string categoryStr = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
            ThingCategory category = ThingCategory.Invalid;

            switch (categoryStr)
            {
                case "item":
                    category = ThingCategory.Item;
                    break;

                case "outfit":
                    category = ThingCategory.Outfit;
                    break;

                case "effect":
                    category = ThingCategory.Effect;
                    break;

                case "missile":
                    category = ThingCategory.Missile;
                    break;
            }

            ThingType thing = new ThingType(category);

            if (!ThingTypeSerializer.ReadProperties(thing, DatFormat.Format_1010, reader))
            {
                return null;
            }

            FrameGroup group = new FrameGroup();

            group.Width = reader.ReadByte();
            group.Height = reader.ReadByte();

            if (group.Width > 1 || group.Height > 1)
            {
                group.ExactSize = reader.ReadByte();
            }
            else
            {
                group.ExactSize = Sprite.DefaultSize;
            }

            group.Layers = reader.ReadByte();
            group.PatternX = reader.ReadByte();
            group.PatternY = reader.ReadByte();
            group.PatternZ = reader.ReadByte();
            group.Frames = reader.ReadByte();

            if (group.Frames > 1)
            {
                group.IsAnimation = true;
                group.AnimationMode = AnimationMode.Asynchronous;
                group.LoopCount = 0;
                group.StartFrame = 0;
                group.FrameDurations = new FrameDuration[group.Frames];

                for (byte i = 0; i < group.Frames; i++)
                {
                    group.FrameDurations[i] = new FrameDuration(category);
                }
            }

            int totalSprites = group.GetTotalSprites();
            if (totalSprites > 4096)
            {
                throw new Exception("The ThingData has more than 4096 sprites.");
            }

            group.SpriteIDs = new uint[totalSprites];
            SpriteGroup spriteGroup = new SpriteGroup();
            Sprite[] sprites = new Sprite[totalSprites];

            for (int i = 0; i < totalSprites; i++)
            {
                uint spriteID = reader.ReadUInt32();
                group.SpriteIDs[i] = spriteID;

                uint dataSize = reader.ReadUInt32();
                if (dataSize > Sprite.PixelsDataSize)
                {
                    throw new Exception("Invalid sprite data size.");
                }

                byte[] pixels = reader.ReadBytes((int)dataSize);

                Sprite sprite = new Sprite(spriteID, true);
                sprite.SetPixelsARGB(pixels);
                sprites[i] = sprite;
            }

            thing.SetFrameGroup(FrameGroupType.Default, group);
            spriteGroup.Add(FrameGroupType.Default, sprites);
            return new ThingData(thing, spriteGroup);
        }
Ejemplo n.º 30
0
        public static ThingType ToSingleFrameGroup(ThingType thing)
        {
            if (thing.Category != ThingCategory.Outfit || thing.FrameGroupCount != 2)
            {
                return(thing);
            }

            FrameGroup walkingFrameGroup = thing.GetFrameGroup(FrameGroupType.Walking);
            FrameGroup newGroup          = walkingFrameGroup.Clone();

            if (walkingFrameGroup.Frames > 1)
            {
                newGroup.Frames         = (byte)(newGroup.Frames + 1);
                newGroup.SpriteIDs      = new uint[newGroup.GetTotalSprites()];
                newGroup.IsAnimation    = true;
                newGroup.FrameDurations = new FrameDuration[newGroup.Frames];

                for (int i = 0; i < newGroup.Frames; i++)
                {
                    if (newGroup.FrameDurations[i] != null)
                    {
                        newGroup.FrameDurations[i] = newGroup.FrameDurations[i];
                    }
                    else
                    {
                        newGroup.FrameDurations[i] = new FrameDuration(ThingCategory.Outfit);
                    }
                }
            }

            for (byte k = 0; k < thing.FrameGroupCount; k++)
            {
                FrameGroup group = thing.GetFrameGroup((FrameGroupType)k);

                for (byte f = 0; f < group.Frames; f++)
                {
                    for (byte z = 0; z < group.PatternZ; z++)
                    {
                        for (byte y = 0; y < group.PatternY; y++)
                        {
                            for (byte x = 0; x < group.PatternX; x++)
                            {
                                for (byte l = 0; l < group.Layers; l++)
                                {
                                    for (byte w = 0; w < group.Width; w++)
                                    {
                                        for (byte h = 0; h < group.Height; h++)
                                        {
                                            if (k == (byte)FrameGroupType.Default && f == 0)
                                            {
                                                int i  = group.GetSpriteIndex(w, h, l, x, y, z, f);
                                                int ni = newGroup.GetSpriteIndex(w, h, l, x, y, z, f);
                                                newGroup.SpriteIDs[ni] = group.SpriteIDs[i];
                                            }
                                            else if (k == (byte)FrameGroupType.Walking)
                                            {
                                                int i  = group.GetSpriteIndex(w, h, l, x, y, z, f);
                                                int ni = newGroup.GetSpriteIndex(w, h, l, x, y, z, f + 1);
                                                newGroup.SpriteIDs[ni] = group.SpriteIDs[i];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            thing.FrameGroups = new Dictionary <FrameGroupType, FrameGroup>();
            thing.FrameGroups.Add(FrameGroupType.Default, newGroup);
            return(thing);
        }
Ejemplo n.º 31
0
        private static bool WriteProperties_1010_1057(ThingType thing, BinaryWriter writer)
        {
            if (thing.StackOrder == StackOrder.Ground)
            {
                writer.Write((byte)DatFlags1010.Ground);
                writer.Write((ushort)thing.GroundSpeed);
            }
            else if (thing.StackOrder == StackOrder.Border)
            {
                writer.Write((byte)DatFlags1010.GroundBorder);
            }
            else if (thing.StackOrder == StackOrder.Bottom)
            {
                writer.Write((byte)DatFlags1010.OnBottom);
            }
            else if (thing.StackOrder == StackOrder.Top)
            {
                writer.Write((byte)DatFlags1010.OnTop);
            }

            if (thing.IsContainer)
            {
                writer.Write((byte)DatFlags1010.Container);
            }

            if (thing.Stackable)
            {
                writer.Write((byte)DatFlags1010.Stackable);
            }

            if (thing.ForceUse)
            {
                writer.Write((byte)DatFlags1010.ForceUse);
            }

            if (thing.MultiUse)
            {
                writer.Write((byte)DatFlags1010.MultiUse);
            }

            if (thing.Writable)
            {
                writer.Write((byte)DatFlags1010.Writable);
                writer.Write((ushort)thing.MaxTextLength);
            }

            if (thing.WritableOnce)
            {
                writer.Write((byte)DatFlags1010.WritableOnce);
                writer.Write((ushort)thing.MaxTextLength);
            }

            if (thing.IsFluidContainer)
            {
                writer.Write((byte)DatFlags1010.FluidContainer);
            }

            if (thing.IsFluid)
            {
                writer.Write((byte)DatFlags1010.Fluid);
            }

            if (thing.Unpassable)
            {
                writer.Write((byte)DatFlags1010.IsUnpassable);
            }

            if (thing.Unmovable)
            {
                writer.Write((byte)DatFlags1010.IsUnmovable);
            }

            if (thing.BlockMissiles)
            {
                writer.Write((byte)DatFlags1010.BlockMissiles);
            }

            if (thing.BlockPathfinder)
            {
                writer.Write((byte)DatFlags1010.BlockPathfinder);
            }

            if (thing.NoMoveAnimation)
            {
                writer.Write((byte)DatFlags1010.NoMoveAnimation);
            }

            if (thing.Pickupable)
            {
                writer.Write((byte)DatFlags1010.Pickupable);
            }

            if (thing.Hangable)
            {
                writer.Write((byte)DatFlags1010.Hangable);
            }

            if (thing.HookSouth)
            {
                writer.Write((byte)DatFlags1010.HookSouth);
            }

            if (thing.HookEast)
            {
                writer.Write((byte)DatFlags1010.HookEast);
            }

            if (thing.Rotatable)
            {
                writer.Write((byte)DatFlags1010.Rotatable);
            }

            if (thing.HasLight)
            {
                writer.Write((byte)DatFlags1010.HasLight);
                writer.Write((ushort)thing.LightLevel);
                writer.Write((ushort)thing.LightColor);
            }

            if (thing.DontHide)
            {
                writer.Write((byte)DatFlags1010.DontHide);
            }

            if (thing.Translucent)
            {
                writer.Write((byte)DatFlags1010.Translucent);
            }

            if (thing.HasOffset)
            {
                writer.Write((byte)DatFlags1010.HasOffset);
                writer.Write((ushort)thing.OffsetX);
                writer.Write((ushort)thing.OffsetY);
            }

            if (thing.HasElevation)
            {
                writer.Write((byte)DatFlags1010.HasElevation);
                writer.Write((ushort)thing.Elevation);
            }

            if (thing.LyingObject)
            {
                writer.Write((byte)DatFlags1010.LyingObject);
            }

            if (thing.AnimateAlways)
            {
                writer.Write((byte)DatFlags1010.AnimateAlways);
            }

            if (thing.Minimap)
            {
                writer.Write((byte)DatFlags1010.Minimap);
                writer.Write((ushort)thing.MinimapColor);
            }

            if (thing.IsLensHelp)
            {
                writer.Write((byte)DatFlags1010.LensHelp);
                writer.Write((ushort)thing.LensHelp);
            }

            if (thing.FullGround)
            {
                writer.Write((byte)DatFlags1010.FullGround);
            }

            if (thing.IgnoreLook)
            {
                writer.Write((byte)DatFlags1010.IgnoreLook);
            }

            if (thing.IsCloth)
            {
                writer.Write((byte)DatFlags1010.Cloth);
                writer.Write((ushort)thing.ClothSlot);
            }

            if (thing.IsMarketItem)
            {
                writer.Write((byte)DatFlags1010.Market);
                writer.Write((ushort)thing.MarketCategory);
                writer.Write((ushort)thing.MarketTradeAs);
                writer.Write((ushort)thing.MarketShowAs);
                writer.Write((ushort)thing.MarketName.Length);
                writer.Write(Encoding.UTF8.GetBytes(thing.MarketName));
                writer.Write((ushort)thing.MarketRestrictVocation);
                writer.Write((ushort)thing.MarketRestrictLevel);
            }

            if (thing.HasAction)
            {
                writer.Write((byte)DatFlags1010.DefaultAction);
                writer.Write((ushort)thing.DefaultAction);
            }

            if (thing.Usable)
            {
                writer.Write((byte)DatFlags1010.Usable);
            }

            // close flags
            writer.Write((byte)DatFlags1010.LastFlag);
            return true;
        }
Ejemplo n.º 32
0
 public void AddRange(ThingType[] things)
 {
     Items.AddRange(things);
 }
Ejemplo n.º 33
0
        public static bool ReadTexturePatterns(ThingType thing, ClientFeatures features, BinaryReader reader)
        {
            bool patternZEnabled = (features & ClientFeatures.PatternZ) == ClientFeatures.PatternZ;
            bool extendedEnabled = (features & ClientFeatures.Extended) == ClientFeatures.Extended;
            bool frameDurationsEnabled = (features & ClientFeatures.FrameDurations) == ClientFeatures.FrameDurations;
            bool frameGroupsEnabled = (features & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups;

            byte groupCount = 1;
            if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit)
            {
                groupCount = reader.ReadByte();
            }

            for (byte k = 0; k < groupCount; k++)
            {
                FrameGroupType groupType = FrameGroupType.Default;
                if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit)
                {
                    groupType = (FrameGroupType)reader.ReadByte();
                }

                FrameGroup group = new FrameGroup();

                group.Width = reader.ReadByte();
                group.Height = reader.ReadByte();

                if (group.Width > 1 || group.Height > 1)
                {
                    group.ExactSize = reader.ReadByte();
                }
                else
                {
                    group.ExactSize = Sprite.DefaultSize;
                }

                group.Layers = reader.ReadByte();
                group.PatternX = reader.ReadByte();
                group.PatternY = reader.ReadByte();
                group.PatternZ = patternZEnabled ? reader.ReadByte() : (byte)1;
                group.Frames = reader.ReadByte();

                if (frameDurationsEnabled && group.Frames > 1)
                {
                    group.IsAnimation = true;
                    group.AnimationMode = (AnimationMode)reader.ReadByte();
                    group.LoopCount = reader.ReadInt32();
                    group.StartFrame = reader.ReadSByte();
                    group.FrameDurations = new FrameDuration[group.Frames];

                    for (int i = 0; i < group.Frames; i++)
                    {
                        uint minimum = reader.ReadUInt32();
                        uint maximum = reader.ReadUInt32();
                        group.FrameDurations[i] = new FrameDuration(minimum, maximum);
                    }
                }

                int totalSprites = group.GetTotalSprites();
                if (totalSprites > 4096)
                {
                    throw new Exception("A thing type has more than 4096 sprites.");
                }

                group.SpriteIDs = new uint[totalSprites];

                if (extendedEnabled)
                {
                    for (int i = 0; i < totalSprites; i++)
                    {
                        group.SpriteIDs[i] = reader.ReadUInt32();
                    }
                }
                else
                {
                    for (int i = 0; i < totalSprites; i++)
                    {
                        group.SpriteIDs[i] = reader.ReadUInt16();
                    }
                }

                thing.SetFrameGroup(groupType, group);
            }

            return true;
        }
Ejemplo n.º 34
0
        public static bool WriteTexturePatterns(ThingType thing, ClientFeatures features, BinaryWriter writer)
        {
            bool patternZEnabled       = (features & ClientFeatures.PatternZ) == ClientFeatures.PatternZ;
            bool extendedEnabled       = (features & ClientFeatures.Extended) == ClientFeatures.Extended;
            bool frameDurationsEnabled = (features & ClientFeatures.FrameDurations) == ClientFeatures.FrameDurations;
            bool frameGroupsEnabled    = (features & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups;
            int  groupCount            = 1;

            // write frame group count.
            if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit)
            {
                groupCount = thing.FrameGroupCount;
                writer.Write((byte)groupCount); // cast to 1 byte
            }

            for (byte k = 0; k < groupCount; k++)
            {
                // write frame group type.
                if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit)
                {
                    writer.Write(k);
                }

                FrameGroup group = thing.GetFrameGroup((FrameGroupType)k);

                writer.Write(group.Width);  // write width
                writer.Write(group.Height); // write heigh

                // write exact size
                if (group.Width > 1 || group.Height > 1)
                {
                    writer.Write(group.ExactSize);
                }

                writer.Write(group.Layers);     // write layers
                writer.Write(group.PatternX);   // write pattern X
                writer.Write(group.PatternY);   // write pattern Y

                if (patternZEnabled)
                {
                    writer.Write(group.PatternZ); // write pattern Z
                }

                writer.Write(group.Frames); // write frames

                if (frameDurationsEnabled && group.Frames > 1)
                {
                    writer.Write((byte)group.AnimationMode); // write animation type
                    writer.Write(group.LoopCount);           // write frame strategy
                    writer.Write(group.StartFrame);          // write start frame

                    FrameDuration[] durations = group.FrameDurations;
                    for (int i = 0; i < durations.Length; i++)
                    {
                        writer.Write((uint)durations[i].Minimum); // write minimum duration
                        writer.Write((uint)durations[i].Maximum); // write maximum duration
                    }
                }

                uint[] sprites = group.SpriteIDs;
                for (int i = 0; i < sprites.Length; i++)
                {
                    // write sprite index
                    if (extendedEnabled)
                    {
                        writer.Write(sprites[i]);
                    }
                    else
                    {
                        writer.Write((ushort)sprites[i]);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 35
0
        private ThingType InternalReplaceThing(ThingType newThing, ThingType oldThing)
        {
            if (newThing == null || oldThing == null || newThing.Category != oldThing .Category || !this.HasThing(oldThing.ID, oldThing.Category))
            {
                return null;
            }

            switch (oldThing.Category)
            {
                case ThingCategory.Item:
                    this.Items[oldThing.ID] = newThing;
                    break;

                case ThingCategory.Outfit:
                    this.Outfits[oldThing.ID] = newThing;
                    break;

                case ThingCategory.Effect:
                    this.Effects[oldThing.ID] = newThing;
                    break;

                case ThingCategory.Missile:
                    this.Missiles[oldThing.ID] = newThing;
                    break;
            }

            newThing.ID = oldThing.ID;
            return oldThing;
        }
Ejemplo n.º 36
0
        private static bool ReadProperties_1010_1057(ThingType thing, BinaryReader reader)
        {
            DatFlags1010 flag;

            do
            {
                flag = (DatFlags1010)reader.ReadByte();

                if (flag == DatFlags1010.LastFlag)
                {
                    break;
                }

                switch (flag)
                {
                    case DatFlags1010.Ground: // 0x00
                        thing.StackOrder = StackOrder.Ground;
                        thing.GroundSpeed = reader.ReadUInt16();
                        break;

                    case DatFlags1010.GroundBorder: // 0x01
                        thing.StackOrder = StackOrder.Border;
                        break;

                    case DatFlags1010.OnBottom: // 0x02
                        thing.StackOrder = StackOrder.Bottom;
                        break;

                    case DatFlags1010.OnTop: // 0x03
                        thing.StackOrder = StackOrder.Top;
                        break;

                    case DatFlags1010.Container: // 0x04
                        thing.IsContainer = true;
                        break;

                    case DatFlags1010.Stackable:
                        thing.Stackable = true;
                        break;

                    case DatFlags1010.ForceUse:
                        thing.ForceUse = true;
                        break;

                    case DatFlags1010.MultiUse:
                        thing.MultiUse = true;
                        break;

                    case DatFlags1010.Writable:
                        thing.Writable = true;
                        thing.MaxTextLength = reader.ReadUInt16();
                        break;

                    case DatFlags1010.WritableOnce:
                        thing.WritableOnce = true;
                        thing.MaxTextLength = reader.ReadUInt16();
                        break;

                    case DatFlags1010.FluidContainer:
                        thing.IsFluidContainer = true;
                        break;

                    case DatFlags1010.Fluid:
                        thing.IsFluid = true;
                        break;

                    case DatFlags1010.IsUnpassable:
                        thing.Unpassable = true;
                        break;

                    case DatFlags1010.IsUnmovable:
                        thing.Unmovable = true;
                        break;

                    case DatFlags1010.BlockMissiles:
                        thing.BlockMissiles = true;
                        break;

                    case DatFlags1010.BlockPathfinder:
                        thing.BlockPathfinder = true;
                        break;

                    case DatFlags1010.NoMoveAnimation: // 0x10
                        thing.NoMoveAnimation = true;
                        break;

                    case DatFlags1010.Pickupable:
                        thing.Pickupable = true;
                        break;

                    case DatFlags1010.Hangable:
                        thing.Hangable = true;
                        break;

                    case DatFlags1010.HookSouth:
                        thing.HookSouth = true;
                        break;

                    case DatFlags1010.HookEast:
                        thing.HookEast = true;
                        break;

                    case DatFlags1010.Rotatable:
                        thing.Rotatable = true;
                        break;

                    case DatFlags1010.HasLight:
                        thing.HasLight = true;
                        thing.LightLevel = reader.ReadUInt16();
                        thing.LightColor = reader.ReadUInt16();
                        break;

                    case DatFlags1010.DontHide:
                        thing.DontHide = true;
                        break;

                    case DatFlags1010.Translucent:
                        thing.Translucent = true;
                        break;

                    case DatFlags1010.HasOffset:
                        thing.HasOffset = true;
                        thing.OffsetX = reader.ReadUInt16();
                        thing.OffsetY = reader.ReadUInt16();
                        break;

                    case DatFlags1010.HasElevation:
                        thing.HasElevation = true;
                        thing.Elevation = reader.ReadUInt16();
                        break;

                    case DatFlags1010.LyingObject:
                        thing.LyingObject = true;
                        break;

                    case DatFlags1010.Minimap:
                        thing.Minimap = true;
                        thing.MinimapColor = reader.ReadUInt16();
                        break;

                    case DatFlags1010.AnimateAlways:
                        thing.AnimateAlways = true;
                        break;

                    case DatFlags1010.LensHelp:
                        thing.IsLensHelp = true;
                        thing.LensHelp = reader.ReadUInt16();
                        break;

                    case DatFlags1010.FullGround:
                        thing.FullGround = true;
                        break;

                    case DatFlags1010.IgnoreLook:
                        thing.IgnoreLook = true;
                        break;

                    case DatFlags1010.Cloth:
                        thing.IsCloth = true;
                        thing.ClothSlot = (ClothSlot)reader.ReadUInt16();
                        break;

                    case DatFlags1010.Market:
                        thing.IsMarketItem = true;
                        thing.MarketCategory = (MarketCategory)reader.ReadUInt16();
                        thing.MarketTradeAs = reader.ReadUInt16();
                        thing.MarketShowAs = reader.ReadUInt16();

                        ushort nameLength = reader.ReadUInt16();
                        byte[] buffer = reader.ReadBytes(nameLength);
                        thing.MarketName = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
                        thing.MarketRestrictVocation = reader.ReadUInt16();
                        thing.MarketRestrictLevel = reader.ReadUInt16();
                        break;

                    case DatFlags1010.DefaultAction:
                        thing.HasAction = true;
                        thing.DefaultAction = (DefaultAction)reader.ReadUInt16();
                        break;

                    case DatFlags1010.Usable:
                        thing.Usable = true;
                        break;

                    default:
                        throw new Exception(string.Format("Error while parsing, unknown flag 0x{0:X} at object id {1}, category {2}.", flag, thing.ID, thing.Category));
                }
            }
            while (flag != DatFlags1010.LastFlag);

            return true;
        }
Ejemplo n.º 37
0
        private ThingType InternalRemoveThing(ushort id, ThingCategory category)
        {
            if (id == 0 || category == ThingCategory.Invalid || !this.HasThing(id, category))
            {
                return(null);
            }

            ThingType changedThing = null;

            if (category == ThingCategory.Item)
            {
                changedThing = this.Items[id];

                if (id == this.ItemCount && id != 100)
                {
                    this.ItemCount = (ushort)(this.ItemCount - 1);
                    this.Items.Remove(id);
                }
                else
                {
                    this.Items[id] = ThingType.Create(id, category);
                }
            }
            else if (category == ThingCategory.Outfit)
            {
                changedThing = this.Outfits[id];

                if (id == this.OutfitCount && id != 1)
                {
                    this.OutfitCount = (ushort)(this.OutfitCount - 1);
                    this.Outfits.Remove(id);
                }
                else
                {
                    this.Outfits[id] = ThingType.Create(id, category);
                }
            }
            else if (category == ThingCategory.Effect)
            {
                changedThing = this.Effects[id];

                if (id == this.EffectCount && id != 1)
                {
                    this.EffectCount = (ushort)(this.EffectCount - 1);
                    this.Effects.Remove(id);
                }
                else
                {
                    this.Effects[id] = ThingType.Create(id, category);
                }
            }
            else if (category == ThingCategory.Missile)
            {
                changedThing = this.Missiles[id];

                if (id == this.MissileCount && id != 1)
                {
                    this.MissileCount = (ushort)(this.MissileCount - 1);
                    this.Missiles.Remove(id);
                }
                else
                {
                    this.Missiles[id] = ThingType.Create(id, category);
                }
            }

            return(changedThing);
        }
Ejemplo n.º 38
0
        public static bool ReadTexturePatterns(ThingType thing, ClientFeatures features, BinaryReader reader)
        {
            bool patternZEnabled       = (features & ClientFeatures.PatternZ) == ClientFeatures.PatternZ;
            bool extendedEnabled       = (features & ClientFeatures.Extended) == ClientFeatures.Extended;
            bool frameDurationsEnabled = (features & ClientFeatures.FrameDurations) == ClientFeatures.FrameDurations;
            bool frameGroupsEnabled    = (features & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups;

            byte groupCount = 1;

            if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit)
            {
                groupCount = reader.ReadByte();
            }

            for (byte k = 0; k < groupCount; k++)
            {
                FrameGroupType groupType = FrameGroupType.Default;
                if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit)
                {
                    groupType = (FrameGroupType)reader.ReadByte();
                }

                FrameGroup group = new FrameGroup();

                group.Width  = reader.ReadByte();
                group.Height = reader.ReadByte();

                if (group.Width > 1 || group.Height > 1)
                {
                    group.ExactSize = reader.ReadByte();
                }
                else
                {
                    group.ExactSize = Sprite.DefaultSize;
                }

                group.Layers   = reader.ReadByte();
                group.PatternX = reader.ReadByte();
                group.PatternY = reader.ReadByte();
                group.PatternZ = patternZEnabled ? reader.ReadByte() : (byte)1;
                group.Frames   = reader.ReadByte();

                if (frameDurationsEnabled && group.Frames > 1)
                {
                    group.IsAnimation    = true;
                    group.AnimationMode  = (AnimationMode)reader.ReadByte();
                    group.LoopCount      = reader.ReadInt32();
                    group.StartFrame     = reader.ReadSByte();
                    group.FrameDurations = new FrameDuration[group.Frames];

                    for (int i = 0; i < group.Frames; i++)
                    {
                        uint minimum = reader.ReadUInt32();
                        uint maximum = reader.ReadUInt32();
                        group.FrameDurations[i] = new FrameDuration(minimum, maximum);
                    }
                }

                int totalSprites = group.GetTotalSprites();
                if (totalSprites > 4096)
                {
                    throw new Exception("A thing type has more than 4096 sprites.");
                }

                group.SpriteIDs = new uint[totalSprites];

                if (extendedEnabled)
                {
                    for (int i = 0; i < totalSprites; i++)
                    {
                        group.SpriteIDs[i] = reader.ReadUInt32();
                    }
                }
                else
                {
                    for (int i = 0; i < totalSprites; i++)
                    {
                        group.SpriteIDs[i] = reader.ReadUInt16();
                    }
                }

                thing.SetFrameGroup(groupType, group);
            }

            return(true);
        }
Ejemplo n.º 39
0
        public static bool WriteProperties(ThingType thing, BinaryWriter output)
        {
            if (thing.StackOrder == StackOrder.Ground)
            {
                output.Write((byte)ObdFlags.Ground);
                output.Write((ushort)thing.GroundSpeed);
            }
            else if (thing.StackOrder == StackOrder.Border)
            {
                output.Write((byte)ObdFlags.GroundBorder);
            }
            else if (thing.StackOrder == StackOrder.Bottom)
            {
                output.Write((byte)ObdFlags.OnBottom);
            }
            else if (thing.StackOrder == StackOrder.Top)
            {
                output.Write((byte)ObdFlags.OnTop);
            }

            if (thing.IsContainer)
            {
                output.Write((byte)ObdFlags.Container);
            }

            if (thing.Stackable)
            {
                output.Write((byte)ObdFlags.Stackable);
            }

            if (thing.ForceUse)
            {
                output.Write((byte)ObdFlags.ForceUse);
            }

            if (thing.MultiUse)
            {
                output.Write((byte)ObdFlags.MultiUse);
            }

            if (thing.Writable)
            {
                output.Write((byte)ObdFlags.Writable);
                output.Write((ushort)thing.MaxTextLength);
            }

            if (thing.WritableOnce)
            {
                output.Write((byte)ObdFlags.WritableOnce);
                output.Write((ushort)thing.MaxTextLength);
            }

            if (thing.IsFluidContainer)
            {
                output.Write((byte)ObdFlags.FluidContainer);
            }

            if (thing.IsFluid)
            {
                output.Write((byte)ObdFlags.Fluid);
            }

            if (thing.Unpassable)
            {
                output.Write((byte)ObdFlags.IsUnpassable);
            }

            if (thing.Unmovable)
            {
                output.Write((byte)ObdFlags.IsUnmovable);
            }

            if (thing.BlockMissiles)
            {
                output.Write((byte)ObdFlags.BlockMissiles);
            }

            if (thing.BlockPathfinder)
            {
                output.Write((byte)ObdFlags.BlockPathfinder);
            }

            if (thing.NoMoveAnimation)
            {
                output.Write((byte)ObdFlags.NoMoveAnimation);
            }

            if (thing.Pickupable)
            {
                output.Write((byte)ObdFlags.Pickupable);
            }

            if (thing.Hangable)
            {
                output.Write((byte)ObdFlags.Hangable);
            }

            if (thing.HookSouth)
            {
                output.Write((byte)ObdFlags.HookSouth);
            }

            if (thing.HookEast)
            {
                output.Write((byte)ObdFlags.HookEast);
            }

            if (thing.Rotatable)
            {
                output.Write((byte)ObdFlags.Rotatable);
            }

            if (thing.HasLight)
            {
                output.Write((byte)ObdFlags.HasLight);
                output.Write((ushort)thing.LightLevel);
                output.Write((ushort)thing.LightColor);
            }

            if (thing.DontHide)
            {
                output.Write((byte)ObdFlags.DontHide);
            }

            if (thing.Translucent)
            {
                output.Write((byte)ObdFlags.Translucent);
            }

            if (thing.HasOffset)
            {
                output.Write((byte)ObdFlags.HasOffset);
                output.Write((ushort)thing.OffsetX);
                output.Write((ushort)thing.OffsetY);
            }

            if (thing.HasElevation)
            {
                output.Write((byte)ObdFlags.HasElevation);
                output.Write((ushort)thing.Elevation);
            }

            if (thing.LyingObject)
            {
                output.Write((byte)ObdFlags.LyingObject);
            }

            if (thing.AnimateAlways)
            {
                output.Write((byte)ObdFlags.AnimateAlways);
            }

            if (thing.Minimap)
            {
                output.Write((byte)ObdFlags.Minimap);
                output.Write((ushort)thing.MinimapColor);
            }

            if (thing.IsLensHelp)
            {
                output.Write((byte)ObdFlags.LensHelp);
                output.Write((ushort)thing.LensHelp);
            }

            if (thing.FullGround)
            {
                output.Write((byte)ObdFlags.FullGround);
            }

            if (thing.IgnoreLook)
            {
                output.Write((byte)ObdFlags.IgnoreLook);
            }

            if (thing.IsCloth)
            {
                output.Write((byte)ObdFlags.Cloth);
                output.Write((ushort)thing.ClothSlot);
            }

            if (thing.IsMarketItem)
            {
                output.Write((byte)ObdFlags.Market);
                output.Write((ushort)thing.MarketCategory);
                output.Write((ushort)thing.MarketTradeAs);
                output.Write((ushort)thing.MarketShowAs);
                output.Write((ushort)thing.MarketName.Length);
                output.Write((string)thing.MarketName);
                output.Write((ushort)thing.MarketRestrictVocation);
                output.Write((ushort)thing.MarketRestrictLevel);
            }

            if (thing.HasAction)
            {
                output.Write((byte)ObdFlags.DefaultAction);
                output.Write((ushort)thing.DefaultAction);
            }

            if (thing.HasCharges)
            {
                output.Write((byte)ObdFlags.HasChanges);
            }

            if (thing.FloorChange)
            {
                output.Write((byte)ObdFlags.FloorChange);
            }

            if (thing.Usable)
            {
                output.Write((byte)ObdFlags.Usable);
            }

            // close flags
            output.Write((byte)ObdFlags.LastFlag);
            return true;
        }