Beispiel #1
0
 //Sets Object with tag "Pick Up" unactive when collide.
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag("Pick Up"))
     {
         source.PlayOneShot(LootSound, 1F);
         //Add item to list inventory
         AddToInventory(other.gameObject.GetComponent <Item> ());
         other.gameObject.SetActive(false);
     }
     //if world portal is enabled allows player to move through it
     if (other.gameObject.CompareTag("WorldPortal"))
     {
         WorldPortal portal = other.gameObject.GetComponent <WorldPortal> ();
         if (portal.isEnabled())
         {
             this.transform.position = new Vector3((float)portal.getX(), (float)portal.getY(), 0.0f);
         }
     }
     //
     if (other.gameObject.CompareTag("Trigger"))
     {
         Trigger t = other.gameObject.GetComponent <Trigger> ();
         t.Enter();
     }
 }
Beispiel #2
0
        /// <summary>
        /// Tests if a wolrd portal 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 WorldPortal)
            {
                WorldPortal wpB = (WorldPortal)b;
                return(wpB.X == X && wpB.Y == Y && wpB.Layer == Layer && wpB.ID == ID && wpB.TargetID == TargetID);
            }

            return(false);
        }
Beispiel #3
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);
            string  target  = message.GetString(3);

            WorldPortal worldPortal = null;

            if (message.Count > 4)
            {
                int         userId = message.GetInt(4);
                WorldPlayer player = worldCon.Players.GetPlayer(userId);
                worldPortal = new WorldPortal(worldCon, blockId, x, y, target)
                {
                    Placer = player
                };
            }
            else
            {
                worldPortal = new WorldPortal(worldCon, blockId, x, y, target);
            }

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

            worldCon.CheckBlock(worldPortal);
            WorldPortalBlockEvent worldPortalBlockEvent = new WorldPortalBlockEvent()
            {
                Raw         = message,
                WorldPortal = worldPortal
            };

            connectionBase.RaiseServerEvent <WorldPortalBlockEvent>(worldPortalBlockEvent);
        }
Beispiel #4
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.");
            }
        }
Beispiel #5
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;
        }