コード例 #1
0
ファイル: CoinBlock.cs プロジェクト: AustinJGreen/Fluid
        /// <summary>
        /// Tests if a coin block is equal to an block
        /// </summary>
        /// <param name="b">The block</param>
        /// <returns>True if equal in value</returns>
        public bool EqualsBlock(Block b)
        {
            if (b is CoinBlock)
            {
                CoinBlock cB = (CoinBlock)b;
                return(cB.X == X && cB.Y == Y && cB.Layer == Layer && cB.ID == ID && cB.Goal == Goal);
            }

            return(false);
        }
コード例 #2
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);

            uint arg = message.GetUInt(3);

            WorldPlayer player = null;

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

            switch (blockId)
            {
            case BlockID.BlueCoinDoor:
            case BlockID.BlueCoinGate:
            case BlockID.CoinDoor:
            case BlockID.CoinGate:
            {
                CoinBlock block = new CoinBlock(worldCon, blockId, x, y, arg)
                {
                    Placer = player
                };

                if (!handled)
                {
                    world.SetBlock(block);
                    worldCon.CheckBlock(block);
                }

                CoinBlockEvent coinBlockEvent = new CoinBlockEvent()
                {
                    Raw       = message,
                    CoinBlock = block
                };

                connectionBase.RaiseServerEvent <CoinBlockEvent>(coinBlockEvent);
            }
            break;

            case BlockID.DeathDoor:
            case BlockID.DeathGate:
            {
                DeathBlock block = new DeathBlock(worldCon, blockId, x, y, arg)
                {
                    Placer = player
                };

                if (!handled)
                {
                    world.SetBlock(block);
                    worldCon.CheckBlock(block);
                }

                DeathBlockEvent deathBlockEvent = new DeathBlockEvent()
                {
                    Raw        = message,
                    DeathBlock = block
                };

                connectionBase.RaiseServerEvent <DeathBlockEvent>(deathBlockEvent);
            }
            break;

            case BlockID.SwitchPurple:
            case BlockID.PurpleSwitchDoor:
            case BlockID.PurpleSwitchGate:
            {
                PurpleBlock block = new PurpleBlock(worldCon, blockId, x, y, arg)
                {
                    Placer = player
                };

                if (!handled)
                {
                    world.SetBlock(block);
                    worldCon.CheckBlock(block);
                }

                PurpleBlockEvent purpleBlockEvent = new PurpleBlockEvent()
                {
                    Raw         = message,
                    PurpleBlock = block
                };

                connectionBase.RaiseServerEvent <PurpleBlockEvent>(purpleBlockEvent);
            }
            break;
            }
        }
コード例 #3
0
 public CoinBlockUpdateCommand(Level level, CoinBlock gameObject)
 {
     this.level = level;
     coinBlock  = gameObject;
 }
コード例 #4
0
ファイル: PhysicsEngine.cs プロジェクト: AustinJGreen/Fluid
        /// <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);
        }
コード例 #5
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.");
            }
        }
コード例 #6
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;
        }