示例#1
0
        public void SendBlock(IBlock Block)
        {
            switch (Block.Type)
            {
            case BlockType.SimpleBlock:
                SimpleBlock sb = Block as SimpleBlock;
                Send(WorldMap.Key, 0, Block.Position.X, Block.Position.Y, Block.ID);
                break;

            case BlockType.BackgroundBlock:
                BackgroundBlock bb = Block as BackgroundBlock;
                Send(WorldMap.Key, 1, Block.Position.X, Block.Position.Y, Block.ID);
                break;

            case BlockType.RotatableBlock:
                RotatableBlock rb = Block as RotatableBlock;
                Send(WorldMap.Key, 0, Block.Position.X, Block.Position.Y, Block.ID, (int)rb.Rotation);
                break;

            case BlockType.ValuedBlock:
                ValuedBlock vb = Block as ValuedBlock;
                Send(WorldMap.Key, 0, Block.Position.X, Block.Position.Y, Block.ID, vb.Value);
                break;

            case BlockType.PortalBlock:
                PortalBlock pb = Block as PortalBlock;
                Send(WorldMap.Key, 0, Block.Position.X, Block.Position.Y, Block.ID, (int)pb.Rotation, pb.Identificator, pb.Target);
                break;
            }
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="RotatablePlaceSendEvent" /> class.
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <param name="x">The x-coordinate.</param>
        /// <param name="y">The y-coordinate.</param>
        /// <param name="block">The block.</param>
        /// <param name="rotation">The rotation.</param>
        public RotatablePlaceSendEvent(Layer layer, int x, int y, RotatableBlock block, uint rotation)
        {
            this.Block = block;
            this.X = x;
            this.Y = y;
            this.Layer = BlockUtils.CorrectLayer((Block)block, layer);

            this.Rotation = rotation;
        }
示例#3
0
        /// <summary>
        /// Tests if a rotatatable block is equal to a block
        /// </summary>
        /// <param name="b">The block</param>
        /// <returns>True if equal in value</returns>
        public bool EqualsBlock(Block b)
        {
            if (b is RotatableBlock)
            {
                RotatableBlock rB = (RotatableBlock)b;
                return(rB.X == X && rB.Y == Y && rB.Layer == Layer && rB.ID == ID && rB.Rotation == Rotation);
            }

            return(false);
        }
示例#4
0
        public override bool Equals(System.Object Obj)
        {
            if (Obj == null)
            {
                return(false);
            }

            RotatableBlock Block = Obj as RotatableBlock;

            if ((System.Object)Block == null)
            {
                return(false);
            }

            return(this == Block);
        }
示例#5
0
 public bool IsSameAs(IBlock Block)
 {
     if (this.Type == Block.Type)
     {
         RotatableBlock RBlock = Block as RotatableBlock;
         if (RBlock == this)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
示例#6
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            WorldConnection worldCon = (WorldConnection)connectionBase;
            World           world    = worldCon.World;

            int      x        = message.GetInt(0);
            int      y        = message.GetInt(1);
            BlockID  blockId  = (BlockID)message.GetInt(2);
            Rotation rotation = (Rotation)message.GetUInt(3);

            RotatableBlock rotatableBlock = null;

            if (message.Count > 4)
            {
                int         userId = message.GetInt(4);
                WorldPlayer player = worldCon.Players.GetPlayer(userId);

                rotatableBlock = new RotatableBlock(worldCon, blockId, x, y, rotation)
                {
                    Placer = player
                };
            }
            else
            {
                rotatableBlock = new RotatableBlock(worldCon, blockId, x, y, rotation);
            }

            if (!handled)
            {
                world.SetBlock(rotatableBlock);
            }

            worldCon.CheckBlock(rotatableBlock);
            RotatableBlockEvent rotatableBlockEvent = new RotatableBlockEvent()
            {
                Raw            = message,
                RotatableBlock = rotatableBlock
            };

            connectionBase.RaiseServerEvent <RotatableBlockEvent>(rotatableBlockEvent);
        }
示例#7
0
        /// <summary>
        /// Tests if the player is overlapping a block
        /// </summary>
        /// <param name="p">The player</param>
        private bool Overlaps(WorldPlayer p)
        {
            if ((p.X < 0 || p.Y < 0) || ((p.X > World.Width * 16 - 16) || (p.Y > World.Height * 16 - 16)))
            {
                return(true);
            }

            if (p.IsGod())
            {
                return(false);
            }

            var    firstX = ((int)p.X >> 4);
            var    firstY = ((int)p.Y >> 4);
            double lastX  = (p.X + 16) / 16;
            double lastY  = (p.Y + 16) / 16;
            bool   skip   = false;

            int x;
            int y = firstY;

            int a = firstY;
            int b;

            while (y < lastY)
            {
                x = firstX;
                b = firstX;
                for (; x < lastX; x++)
                {
                    Block   block  = World[x, y, Layer.Foreground];
                    BlockID tileId = block.ID;

                    if (IsSolid(tileId))
                    {
                        if (CanJumpThrough(tileId))
                        {
                            uint rot = 0;
                            if (block is RotatableBlock)
                            {
                                RotatableBlock rotatableBlock = (RotatableBlock)block;
                                rot = (uint)rotatableBlock.Rotation;
                            }

                            if (tileId == BlockID.OneWayCyan || tileId == BlockID.OneWayPink || tileId == BlockID.OneWayRed || tileId == BlockID.OneWayYellow)
                            {
                                if ((p.SpeedY < 0 || a <= p.m_overlapy) && rot == 1)
                                {
                                    if (a != firstY || p.m_overlapy == -1)
                                    {
                                        p.m_overlapy = a;
                                    }

                                    skip = true;
                                    continue;
                                }

                                if ((p.SpeedX > 0 || b <= p.m_overlapy) && rot == 2)
                                {
                                    if (b == firstX || p.m_overlapy == -1)
                                    {
                                        p.m_overlapy = b;
                                    }

                                    skip = true;
                                    continue;
                                }

                                if ((p.SpeedY > 0 || a <= p.m_overlapy) && rot == 3)
                                {
                                    if (a == firstY || p.m_overlapy == -1)
                                    {
                                        p.m_overlapy = a;
                                    }

                                    skip = true;
                                    continue;
                                }
                                if ((p.SpeedX < 0 || b <= p.m_overlapy) && rot == 0)
                                {
                                    if (b != firstX || p.m_overlapy == -1)
                                    {
                                        p.m_overlapy = b;
                                    }

                                    skip = true;
                                    continue;
                                }
                            }
                            else
                            {
                                if (p.SpeedY < 0 || a <= p.m_overlapy)
                                {
                                    if (a != y || p.m_overlapy == -1)
                                    {
                                        p.m_overlapy = a;
                                    }

                                    skip = true;
                                    continue;
                                }
                            }
                        }

                        switch (tileId)
                        {
                        case (BlockID)23:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.Red))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)24:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.Green))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)25:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.Blue))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)26:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.Red))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)27:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.Green))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)28:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.Blue))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)156:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.TimeDoor))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)157:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.TimeDoor))
                            {
                                continue;
                            }
                            break;

                        case BlockID.CyanDoor:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.Cyan))
                            {
                                continue;
                            }
                            break;

                        case BlockID.MagentaDoor:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.Magenta))
                            {
                                continue;
                            }
                            break;

                        case BlockID.YellowDoor:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.Yellow))
                            {
                                continue;
                            }
                            break;

                        case BlockID.CyanGate:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.Cyan))
                            {
                                continue;
                            }
                            break;

                        case BlockID.MagentaGate:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.Magenta))
                            {
                                continue;
                            }
                            break;

                        case BlockID.YellowGate:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.Yellow))
                            {
                                continue;
                            }
                            break;

                        case BlockID.PurpleSwitchDoor:
                        {
                            PurpleBlock purpleBlock = (PurpleBlock)World[x, y, Layer.Foreground];

                            if (p.m_switches[purpleBlock.SwitchID])
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.PurpleSwitchGate:
                        {
                            PurpleBlock purpleBlock = (PurpleBlock)World[x, y, Layer.Foreground];

                            if (!p.m_switches[purpleBlock.SwitchID])
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.DeathDoor:
                        {
                            DeathBlock deathBlock = (DeathBlock)World[x, y, Layer.Foreground];

                            if (p.m_deaths >= deathBlock.RequiredDeaths)
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.DeathGate:
                        {
                            DeathBlock deathBlock = (DeathBlock)World[x, y, Layer.Foreground];

                            if (p.m_deaths < deathBlock.RequiredDeaths)
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.DoorBuildersClub:
                            if (p.HasBuildersClub)
                            {
                                continue;
                            }
                            break;

                        case BlockID.GateBuildersClub:
                            if (!p.HasBuildersClub)
                            {
                                continue;
                            }
                            break;

                        case BlockID.CoinDoor:
                        case BlockID.BlueCoinDoor:
                        {
                            CoinBlock coinBlock = (CoinBlock)World[x, y, Layer.Foreground];

                            if (coinBlock.Goal <= p.GoldCoins)
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.CoinGate:
                        case BlockID.BlueCoinGate:
                        {
                            CoinBlock coinBlock = (CoinBlock)World[x, y, Layer.Foreground];

                            if (coinBlock.Goal > p.BlueCoins)
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.GateZombie:
                        {
                            if (p.HasPotionActive(Potion.Zombie))
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.DoorZombie:
                        {
                            if (!p.HasPotionActive(Potion.Zombie))
                            {
                                continue;
                            }
                        }
                        break;

                        case (BlockID)61:
                        case (BlockID)62:
                        case (BlockID)63:
                        case (BlockID)64:
                        case (BlockID)89:
                        case (BlockID)90:
                        case (BlockID)91:
                        case (BlockID)96:
                        case (BlockID)97:
                        case (BlockID)122:
                        case (BlockID)123:
                        case (BlockID)124:
                        case (BlockID)125:
                        case (BlockID)126:
                        case (BlockID)127:
                        case (BlockID)146:
                        case (BlockID)154:
                        case (BlockID)158:
                        case (BlockID)194:
                        case (BlockID)211:
                            if (p.SpeedY < 0 || y <= p.m_overlapy)
                            {
                                if (y != firstY || p.m_overlapy == -1)
                                {
                                    p.m_overlapy = y;
                                }

                                skip = true;
                                continue;
                            }
                            break;

                        case (BlockID)83:
                        case (BlockID)77:
                            continue;
                        }
                        return(true);
                    }
                }
                y++;
            }

            if (!skip)
            {
                p.m_overlapy = -1;
            }
            return(false);
        }
示例#8
0
        internal void SetRotatable(RotatableBlock block, uint rotation)
        {
            this.BlockType = BlockType.Rotatable;
            this.Block = (Block)block;

            this._data = new BlockData
            {
                Rotation = rotation
            };
        }
示例#9
0
 public UploadRequestEvent GetRotatable(int x, int y, RotatableBlock block, SciFiSlopeRotation rotation)
 {
     return this.GetRotatable(x, y, block, (uint)rotation);
 }
示例#10
0
 public UploadRequestEvent GetRotatable(int x, int y, RotatableBlock block, uint rotation)
 {
     var e = new RotatablePlaceSendEvent(Layer.Foreground, x, y, block, rotation);
     return new UploadRequestEvent(e);
 }
示例#11
0
 public void UploadRotatable(int x, int y, RotatableBlock block, SciFiStraightRotation rotation)
 {
     this.Events.Raise(this.GetRotatable(x, y, block, rotation));
 }
示例#12
0
        /// <summary>
        /// Deserialize's the world data
        /// </summary>
        /// <param name="message">The message</param>
        internal void Deserialize(Message message)
        {
            // Find the start of the init message's world data
            uint start = 0;

            for (uint i = 0; i < message.Count; i++)
            {
                if (message[i] is string)
                {
                    if (string.Compare(message.GetString(i), "ws", false) == 0)
                    {
                        start = i + 1;
                        break;
                    }
                }
            }

            uint index = start;

            try
            {
                while (index < message.Count)
                {
                    if (message[index] is string)
                    {
                        if (string.Compare(message.GetString(index), "we", false) == 0)
                        {
                            break;
                        }
                    }

                    int blockInt = message.GetInt(index++);
                    int layerInt = message.GetInt(index++);

                    byte[] bytesX = message.GetByteArray(index++);
                    byte[] bytesY = message.GetByteArray(index++);

                    List <FluidPoint> locations = GetLocations(bytesX, bytesY);

                    BlockID blockId = (BlockID)blockInt;
                    Layer   layer   = (Layer)layerInt;

                    switch (blockId)
                    {
                    case BlockID.HazardSpike:
                    case BlockID.DecorSciFi2013BlueSlope:
                    case BlockID.DecorSciFi2013BlueStraight:
                    case BlockID.DecorSciFi2013YellowSlope:
                    case BlockID.DecorSciFi2013YellowStraight:
                    case BlockID.DecorSciFi2013GreenSlope:
                    case BlockID.DecorSciFi2013GreenStraight:
                    case BlockID.OneWayCyan:
                    case BlockID.OneWayPink:
                    case BlockID.OneWayRed:
                    case BlockID.OneWayYellow:
                    {
                        Rotation rotation = (Rotation)message.GetUInt(index++);

                        foreach (FluidPoint p in locations)
                        {
                            RotatableBlock rotatableBlock = new RotatableBlock(blockId, p.X, p.Y, rotation);
                            SetBlock(rotatableBlock);
                        }
                    }
                    break;

                    case BlockID.CoinDoor:
                    case BlockID.BlueCoinDoor:
                    case BlockID.CoinGate:
                    case BlockID.BlueCoinGate:
                    {
                        uint goal = message.GetUInt(index++);

                        foreach (FluidPoint p in locations)
                        {
                            CoinBlock door = new CoinBlock(blockId, p.X, p.Y, goal);
                            SetBlock(door);
                        }
                    }
                    break;

                    case BlockID.MusicDrum:
                    case BlockID.MusicPiano:
                    {
                        uint musicId = message.GetUInt(index++);

                        foreach (FluidPoint p in locations)
                        {
                            MusicBlock musicBlock = new MusicBlock(blockId, p.X, p.Y, musicId);
                            SetBlock(musicBlock);
                        }
                    }
                    break;

                    case BlockID.Portal:
                    case BlockID.InvisiblePortal:
                    {
                        Rotation rotation     = (Rotation)message.GetUInt(index++);
                        uint     portalid     = message.GetUInt(index++);
                        uint     portaltarget = message.GetUInt(index++);

                        foreach (FluidPoint p in locations)
                        {
                            Portal portal = new Portal(blockId, p.X, p.Y, rotation, portalid, portaltarget);
                            SetBlock(portal);
                        }
                    }
                    break;

                    case BlockID.SwitchPurple:
                    case BlockID.PurpleSwitchDoor:
                    case BlockID.PurpleSwitchGate:
                    {
                        uint goal = message.GetUInt(index++);

                        foreach (FluidPoint p in locations)
                        {
                            PurpleBlock purpleBlock = new PurpleBlock(blockId, p.X, p.Y, goal);
                            SetBlock(purpleBlock);
                        }
                    }
                    break;

                    case BlockID.DeathDoor:
                    case BlockID.DeathGate:
                    {
                        uint goal = message.GetUInt(index++);

                        foreach (FluidPoint p in locations)
                        {
                            DeathBlock deathBlock = new DeathBlock(blockId, p.X, p.Y, goal);
                            SetBlock(deathBlock);
                        }
                    }
                    break;

                    case BlockID.WorldPortal:
                    {
                        string targetId = message.GetString(index++);

                        foreach (FluidPoint p in locations)
                        {
                            WorldPortal worldPortal = new WorldPortal(blockId, p.X, p.Y, targetId);
                            SetBlock(worldPortal);
                        }
                    }
                    break;

                    case BlockID.DecorSign:
                    {
                        string text = message.GetString(index++);

                        foreach (FluidPoint p in locations)
                        {
                            TextBlock textBlock = new TextBlock(blockId, p.X, p.Y, text);
                            SetBlock(textBlock);
                        }
                    }
                    break;

                    case BlockID.DecorLabel:
                    {
                        string text     = message.GetString(index++);
                        string hexColor = message.GetString(index++);

                        foreach (FluidPoint p in locations)
                        {
                            LabelBlock labelBlock = new LabelBlock(blockId, p.X, p.Y, text, hexColor);
                            SetBlock(labelBlock);
                        }
                    }
                    break;

                    default:
                        foreach (FluidPoint p in locations)
                        {
                            Block block = new Block(blockId, layer, p.X, p.Y);
                            SetBlock(block);
                        }
                        break;
                    }
                }
            }
            catch
            {
                m_Client.Log.Add(FluidLogCategory.Message, "World init deserializer is out of date. Check for an update.");
            }
        }
示例#13
0
        /// <summary>
        /// Deserialize's the world data
        /// </summary>
        /// <param name="worldObject">The world data as a database array</param>
        private void Deserialize(DatabaseObject worldObject)
        {
            Owner           = GetValue <string>(worldObject, "owner");
            Width           = GetValue <int>(worldObject, "width", 200);
            Height          = GetValue <int>(worldObject, "height", 200);
            Title           = GetValue <string>(worldObject, "name");
            Plays           = GetValue <int>(worldObject, "plays");
            WorldType       = (WorldType)GetValue <int>(worldObject, "type", 3);
            AllowPotions    = GetValue <bool>(worldObject, "allowpotions", true);
            Woots           = GetValue <int>(worldObject, "woots", 0);
            TotalWoots      = GetValue <int>(worldObject, "totalwoots", 0);
            Visible         = GetValue <bool>(worldObject, "visible", true);
            BackgroundColor = new FluidColor(GetValue <uint>(worldObject, "backgroundColor", 0));

            //Check is worlddata is present
            if (!worldObject.Contains("worlddata"))
            {
                return;
            }

            CreateEmptyWorld();

            DatabaseArray        databaseArray = (DatabaseArray)worldObject["worlddata"];
            IEnumerable <object> databaseEnum  = (IEnumerable <object>)databaseArray;

            using (IEnumerator <object> enumerator = databaseEnum.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    DatabaseObject blockData = (DatabaseObject)enumerator.Current;

                    byte[]  xBytes  = blockData.GetBytes("x");
                    byte[]  yBytes  = blockData.GetBytes("y");
                    BlockID blockId = (BlockID)blockData.GetUInt("type");

                    for (int i = 0; i < xBytes.Length; i += 2)
                    {
                        int x = xBytes[i] << 8 | xBytes[i + 1];
                        int y = yBytes[i] << 8 | yBytes[i + 1];
                        if (blockData.Contains("layer"))
                        {
                            Layer layer = (Layer)blockData.GetInt("layer");

                            switch (blockId)
                            {
                            case BlockID.HazardSpike:
                            case BlockID.DecorSciFi2013BlueSlope:
                            case BlockID.DecorSciFi2013BlueStraight:
                            case BlockID.DecorSciFi2013YellowSlope:
                            case BlockID.DecorSciFi2013YellowStraight:
                            case BlockID.DecorSciFi2013GreenSlope:
                            case BlockID.DecorSciFi2013GreenStraight:
                            case BlockID.OneWayCyan:
                            case BlockID.OneWayPink:
                            case BlockID.OneWayRed:
                            case BlockID.OneWayYellow:
                            {
                                Rotation rotation = (Rotation)blockData.GetUInt("rotation");

                                RotatableBlock rotatableBlock = new RotatableBlock(blockId, x, y, rotation);
                                SetBlock(rotatableBlock);
                            }
                            break;

                            case BlockID.CoinDoor:
                            case BlockID.BlueCoinDoor:
                            case BlockID.CoinGate:
                            case BlockID.BlueCoinGate:
                            {
                                uint goal = blockData.GetUInt("goal");

                                CoinBlock door = new CoinBlock(blockId, x, y, goal);
                                SetBlock(door);
                            }
                            break;

                            case BlockID.MusicDrum:
                            case BlockID.MusicPiano:
                            {
                                uint musicId = blockData.GetUInt("id");

                                MusicBlock musicBlock = new MusicBlock(blockId, x, y, musicId);
                                SetBlock(musicBlock);
                            }
                            break;

                            case BlockID.Portal:
                            case BlockID.InvisiblePortal:
                            {
                                Rotation rotation     = (Rotation)blockData.GetUInt("rotation");
                                uint     portalid     = blockData.GetUInt("id");
                                uint     portaltarget = blockData.GetUInt("target");

                                Portal portal = new Portal(blockId, x, y, rotation, portalid, portaltarget);
                                SetBlock(portal);
                            }
                            break;

                            case BlockID.SwitchPurple:
                            case BlockID.PurpleSwitchDoor:
                            case BlockID.PurpleSwitchGate:
                            {
                                uint goal = 0;
                                if (blockData.Contains("goal"))
                                {
                                    goal = blockData.GetUInt("goal");
                                }

                                PurpleBlock purpleBlock = new PurpleBlock(blockId, x, y, goal);
                                SetBlock(purpleBlock);
                            }
                            break;

                            case BlockID.DeathDoor:
                            case BlockID.DeathGate:
                            {
                                uint goal = blockData.GetUInt("goal");

                                DeathBlock deathBlock = new DeathBlock(blockId, x, y, goal);
                                SetBlock(deathBlock);
                            }
                            break;

                            case BlockID.WorldPortal:
                            {
                                string targetId = blockData.GetString("target");

                                WorldPortal worldPortal = new WorldPortal(blockId, x, y, targetId);
                                SetBlock(worldPortal);
                            }
                            break;

                            case BlockID.DecorSign:
                            {
                                string text = blockData.GetString("text");

                                TextBlock textBlock = new TextBlock(blockId, x, y, text);
                                SetBlock(textBlock);
                            }
                            break;

                            case BlockID.DecorLabel:
                            {
                                string text = blockData.GetString("text");
                                if (blockData.Contains("text_color"))
                                {
                                    string hexColor = blockData.GetString("text_color");

                                    LabelBlock labelBlock = new LabelBlock(blockId, x, y, text, hexColor);
                                    SetBlock(labelBlock);
                                }
                                else
                                {
                                    LabelBlock labelBlock = new LabelBlock(blockId, x, y, text);
                                    SetBlock(labelBlock);
                                }
                            }
                            break;

                            default:
                                Block block = new Block(blockId, layer, x, y);
                                SetBlock(block);
                                break;
                            }
                        }
                    }
                }
            }

            IsLoaded = true;
        }