示例#1
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);
        }
示例#2
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);
        }
示例#3
0
        private static ObjectData 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 ObjectData(thing, spriteGroup));
        }
示例#4
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);
        }