Exemple #1
0
        private static BlockDataWorld GetWorld(Message m, int width, int height)
        {
            var world = new BlockDataWorld(width, height);
            var datas = InitParse.Parse(m);

            foreach (var data in datas)
            {
                var block = data.Type;
                var l     = (Layer)data.Layer;

                switch (l)
                {
                case Layer.Background:
                    var bgWorldBlock = new BackgroundBlock((Background.Id)block);
                    var bg           = new BlockData <BackgroundBlock>(bgWorldBlock);
                    foreach (var pos in data.Locations)
                    {
                        world.Background[pos.X, pos.Y] = bg;
                    }
                    break;

                case Layer.Foreground:
                    var fgWorldBlock = WorldUtils.GetForegroundFromArgs((Foreground.Id)block, data.Args);
                    var fg           = new BlockData <ForegroundBlock>(fgWorldBlock);
                    foreach (var pos in data.Locations)
                    {
                        world.Foreground[pos.X, pos.Y] = fg;
                    }
                    break;
                }
            }

            return(world);
        }
 public static void SetMany <T>(this IEnumerable <IEnumerable <T> > blocks, BackgroundBlock block) where T : IBlockSettable <ForegroundBlock, BackgroundBlock>
 {
     foreach (var item in blocks)
     {
         item.Set(block);
     }
 }
Exemple #3
0
 public static void Set(this IEnumerable <BlocksItem> blocks, BackgroundBlock block)
 {
     foreach (var item in blocks)
     {
         item.Set(block);
     }
 }
Exemple #4
0
        private void RaiseBackground(int x, int y, BackgroundBlock newBlock, Player player)
        {
            var oldData = this.World.Background[x, y];
            var newData = new BlockData <BackgroundBlock>(player, newBlock);

            this.World.Background[x, y] = newData;

            new BackgroundPlaceEvent(x, y, oldData, newData)
            .RaiseIn(this.BotBits);
        }
Exemple #5
0
        private void UnserializeFromComplexObject(DatabaseArray worlddata)
        {
            foreach (DatabaseObject ct in worlddata)
            {
                if (ct.Count == 0)
                {
                    continue;
                }

                try
                {
                    var type     = Convert.ToUInt32(ct.GetValue("type"));
                    var layerNum = ct.GetInt("layer", 0);
                    var xArr     = ct.GetBytes("x", new byte[0]);
                    var yArr     = ct.GetBytes("y", new byte[0]);
                    var x1Arr    = ct.GetBytes("x1", new byte[0]);
                    var y1Arr    = ct.GetBytes("y1", new byte[0]);
                    var points   = WorldUtils.GetShortPos(x1Arr, y1Arr)
                                   .Concat(WorldUtils.GetPos(xArr, yArr));

                    if (layerNum == 0)
                    {
                        var foreground = (Foreground.Id)type;
                        var block      = WorldUtils.GetForegroundFromDatabase(ct, foreground);
                        foreach (var loc in points)
                        {
                            this.Foreground[loc.X, loc.Y] = block;
                        }
                    }
                    else
                    {
                        var background = (Background.Id)type;
                        var block      = new BackgroundBlock(background);
                        foreach (var loc in points)
                        {
                            this.Background[loc.X, loc.Y] = block;
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }
Exemple #6
0
        private void UnserializeFromComplexObject(DatabaseArray worlddata)
        {
            foreach (DatabaseObject ct in worlddata)
            {
                if (ct.Count == 0)
                {
                    continue;
                }
                var type     = (uint)ct.GetValue("type");
                var layerNum = ct.GetInt("layer", 0);
                var xs       = ct.GetBytes("x", new byte[0]);
                var ys       = ct.GetBytes("y", new byte[0]);

                if (layerNum == 0)
                {
                    var foreground = (Foreground.Id)type;
                    var block      = WorldUtils.GetDatabaseBlock(ct, foreground);
                    for (var b = 0; b < xs.Length; b += 2)
                    {
                        var nx = (xs[b] << 8) + xs[b + 1];
                        var ny = (ys[b] << 8) + ys[b + 1];
                        this.Foreground[nx, ny] = block;
                    }
                }
                else
                {
                    var background = (Background.Id)type;
                    var block      = new BackgroundBlock(background);
                    for (var b = 0; b < xs.Length; b += 2)
                    {
                        var nx = (xs[b] << 8) + xs[b + 1];
                        var ny = (ys[b] << 8) + ys[b + 1];
                        this.Background[nx, ny] = block;
                    }
                }
            }
        }
Exemple #7
0
 public void Set(BackgroundBlock block)
 {
     this._blocks.Place(this._x, this._y, block);
 }
Exemple #8
0
        internal static BlockDataWorld GetWorld(Message m, int width, int height, uint offset = InitOffset)
        {
            var  world   = new BlockDataWorld(width, height);
            uint pointer = GetStart(m, offset);

            string strValue2;

            while ((strValue2 = m[pointer] as string) == null || strValue2 != "we")
            {
                var    block      = m.GetInteger(pointer++);
                var    l          = (Layer)m.GetInteger(pointer++);
                byte[] byteArrayX = m.GetByteArray(pointer++);
                byte[] byteArrayY = m.GetByteArray(pointer++);

                switch (l)
                {
                case Layer.Background:
                    var bgWorldBlock = new BackgroundBlock((Background.Id)block);
                    foreach (Point pos in GetPos(byteArrayX, byteArrayY))
                    {
                        world.Background[pos.X, pos.Y] = new BlockData <BackgroundBlock>(bgWorldBlock);
                    }
                    break;

                case Layer.Foreground:
                    ForegroundBlock foregroundBlock;
                    BlockArgsType   blockArgsType = WorldUtils.GetBlockArgsType(WorldUtils.GetForegroundType(id: (Foreground.Id)block));

                    switch (blockArgsType)
                    {
                    case BlockArgsType.None:
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block);
                        break;

                    case BlockArgsType.Number:
                        uint i = m.GetUInt(pointer++);
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block, i);
                        break;

                    case BlockArgsType.String:
                        string str = m.GetString(pointer++);
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block, str);
                        break;

                    case BlockArgsType.Portal:
                        var  portalRotation = (Morph.Id)m.GetUInt(pointer++);
                        uint portalId       = m.GetUInt(pointer++);
                        uint portalTarget   = m.GetUInt(pointer++);
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block, portalId, portalTarget, portalRotation);
                        break;

                    case BlockArgsType.Label:
                        string text      = m.GetString(pointer++);
                        string textcolor = m.GetString(pointer++);
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block, text, textcolor);
                        break;

                    default:
                        throw new NotSupportedException("Invalid block.");
                    }

                    var fg = new BlockData <ForegroundBlock>(foregroundBlock);
                    foreach (Point pos in GetPos(byteArrayX, byteArrayY))
                    {
                        world.Foreground[pos.X, pos.Y] = fg;
                    }
                    break;
                }
            }

            return(world);
        }
Exemple #9
0
 public void Place(int x, int y, BackgroundBlock block)
 {
     new PlaceSendMessage(Layer.Background, x, y, (int)block.Id)
     .SendIn(this.BotBits);
 }