예제 #1
0
        /// <summary>
        /// Tries to add the UI Element as an interactable. Returns true if it succeeded, false if it didn't.
        /// </summary>
        public bool AddInteractable(UIElement uiElement)
        {
            if (uiElement is IInteractable interactable)
            {
                Interactables.Add(interactable);

                return(true);
            }

            return(false);
        }
예제 #2
0
 public RoomWrapper(Room r)
 {
     RoomBase = r;
     foreach (var exit in r.Exits)
     {
         Exits.Add(new ExitWrapper(exit));
     }
     foreach (var interactable in r.DefaultInteractables)
     {
         Interactables.Add(new InteractableWrapper(interactable.LinkedInteractable));
     }
 }
        public void ParseOverworld(BinaryReader b)
        {
            uint fileSize = b.ReadUInt32();

            if (fileSize < 0x4)
            {
                b.Close();
                throw new Exception("Invalid overworld container.");
            }

            byte interactableCount = b.ReadByte();
            byte npcCount          = b.ReadByte();
            byte warpCount         = b.ReadByte();
            byte triggerCount      = b.ReadByte();

            for (int i = 0; i < interactableCount; ++i)
            {
                Interactables.Add(new Interactable(b));
            }

            for (int i = 0; i < npcCount; ++i)
            {
                NPCs.Add(new NPC(b));
            }

            for (int i = 0; i < warpCount; ++i)
            {
                Warps.Add(new Warp(b));
            }

            for (int i = 0; i < triggerCount; ++i)
            {
                Triggers.Add(new Trigger(b));
            }

            while (b.PeekChar() != 0)
            {
                LevelScripts.Add(new LevelScriptDeclaration(b));
            }

            b.BaseStream.Position += 0x2;

            int index = 0;

            while (b.PeekChar() != 0 && b.PeekChar() != -1 && index < LevelScripts.Count)
            {
                LevelScripts[index++].Data = new LevelScriptData(b);
            }
        }
예제 #4
0
        /// <summary>
        /// Adds a UI Element and makes it interactable if it implements <see cref="IInteractable"/> and scrollable if it implements <see cref="IScrollable"/>.
        /// </summary>
        /// <typeparam name="T">UIElement descendant of type T.</typeparam>
        /// <param name="uiElement">The UI Element to add.</param>
        /// <returns>Returns the craeted UI Element.</returns>
        public T AddUIElement <T>(T uiElement) where T : UIElement
        {
            UIElements.Add(uiElement);

            if (uiElement is IInteractable interactable)
            {
                Interactables.Add(interactable);
            }

            if (uiElement is IScrollable scrollable)
            {
                Scrollables.Add(scrollable);
            }

            return(uiElement);
        }
예제 #5
0
        // still_todo: perhaps change to message received? Or handle separately?
        private void Mh_TodoCreated(object sender, TodoCreatedEventArgs e)
        {
            Console.WriteLine("MESSAGE ACCEPTED IN VM!");
            // filter interatables, do logic
            var toDo = e.Todo;

            // still_todo: ask for this logic, why? Resolve in AM-2683
            // still_todo: implement backend helper or something like that
            //if (toDo.Assignee == null && Interactables.Any(x => x != toDo && x.Blocking && !x.InteractionPending))
            //{
            //    //await BackendHelper.DeclineTodoAsync(toDo, true, false);
            //    toDo.RabbitEventHeader = "DECLINED_BECAUSE_BLOCKED";
            //}


            //if we added a new interactable
            Interactables.Add(e.Todo);
            Settings.Interactables = Interactables;
        }
예제 #6
0
        //private bool isFuture;

        /// <summary>
        /// Creates a level given a file name and a dictionary of tile textures to use
        /// </summary>
        public Level(String fileName, Dictionary <String, Texture2D> tileTextures)
        {
            myRNG         = new Random();
            tileVariant   = 0;
            interactables = new List <Interactable>();
            recepticles   = new List <Recepticle>();
            indicators    = new List <Indicator>();
            doors         = new List <Point>();
            tiles         = new Tile[12, 16];
            //finds file, creates holder string for reader
            StreamReader reader = new StreamReader(fileName);
            String       line   = "";

            String[] words;

            //for every tile in the 2D array:\
            //checks if this tile is a floor tile is past and/or future
            //if floor, make it non-collidable in that timeState
            //otherwise, it is collidable
            for (int h = 0; h < 12; h++)
            {
                for (int w = 0; w < 16; w++)
                {
                    line = reader.ReadLine();
                    //ignore documented lines in Level files
                    if (line[0] != '/')
                    {
                        tileVariant = myRNG.Next(20) + 1;

                        if (tileVariant == 17)
                        {
                            tileVariant = 1;
                        }
                        else if (tileVariant == 18)
                        {
                            tileVariant = 2;
                        }
                        else if (tileVariant == 19)
                        {
                            tileVariant = 3;
                        }
                        else if (tileVariant == 20)
                        {
                            tileVariant = 4;
                        }
                        else
                        {
                            tileVariant = 0;
                        }

                        words = line.Split(' ');

                        //handles situations where both, one, or neither time state is collidable
                        //HEY YOURE GONNA HAVE TO FIX THIS LATER
                        //^^this is bad documentation
                        //I think I fixed this, because this only generates an error with out-of-date level files
                        if (words[0] == "door" || words[0] == "OpenDoorExtHoriz" || words[0] == "OpenDoorExtVert" || words[0] == "OpenDoorIntVert" || words[0] == "OpenDoorIntVert" ||
                            words[2] == "door" || words[2] == "OpenDoorExtHoriz" || words[2] == "OpenDoorExtVert" || words[2] == "OpenDoorIntVert" || words[2] == "OpenDoorIntVert")
                        {
                            tiles[h, w] = new Door(
                                new Rectangle((w * 64), (h * 64), 64, 64),
                                new AnimatedTexture(0, 32, 32, tileTextures["Past" + words[0]]), int.Parse(words[1]), false,
                                new AnimatedTexture(0, 32, 32, tileTextures["Future" + words[2] + tileVariant]), int.Parse(words[3]), false, 1);
                            doors.Add(new Point(h, w));
                        }
                        else if (words[0] == "LockedDoorExtHoriz" || words[0] == "LockedDoorExtVert" || words[0] == "LockedDoorIntVert" || words[0] == "LockedDoorIntVert" ||
                                 words[2] == "LockedDoorExtHoriz" || words[2] == "LockedDoorExtVert" || words[2] == "LockedDoorIntVert" || words[2] == "LockedDoorIntVert")
                        {
                            tiles[h, w] = new Door(
                                new Rectangle((w * 64), (h * 64), 64, 64),
                                new AnimatedTexture(0, 32, 32, tileTextures["Past" + words[0]]), int.Parse(words[1]), true,
                                new AnimatedTexture(0, 32, 32, tileTextures["Future" + words[2] + tileVariant]), int.Parse(words[3]), true, 1);
                            doors.Add(new Point(h, w));
                        }
                        else if (words[0] == "Floor" && words[2] == "Floor")
                        {
                            tiles[h, w] = new Tile(
                                new Rectangle((w * 64), (h * 64), 64, 64),
                                new AnimatedTexture(0, 32, 32, tileTextures["Past" + words[0]]), int.Parse(words[1]), false,
                                new AnimatedTexture(0, 32, 32, tileTextures["Future" + words[2] + tileVariant]), int.Parse(words[3]), false, 1);
                        }
                        else if (words[0] == "Floor" && words[2] != "Floor")
                        {
                            tiles[h, w] = new Tile(
                                new Rectangle((w * 64), (h * 64), 64, 64),
                                new AnimatedTexture(0, 32, 32, tileTextures["Past" + words[0]]), int.Parse(words[1]), false,
                                new AnimatedTexture(0, 32, 32, tileTextures["Future" + words[2] + tileVariant]), int.Parse(words[3]), true, 1);
                        }
                        else if (words[0] != "Floor" && words[2] == "Floor")
                        {
                            tiles[h, w] = new Tile(
                                new Rectangle((w * 64), (h * 64), 64, 64),
                                new AnimatedTexture(0, 32, 32, tileTextures["Past" + words[0]]), int.Parse(words[1]), true,
                                new AnimatedTexture(0, 32, 32, tileTextures["Future" + words[2] + tileVariant]), int.Parse(words[3]), false, 1);
                        }
                        //HEY YOURE GONNA HAVE TO FIX THIS LATER
                        //see above document
                        else if (words[0] != "Floor" && words[2] != "Floor")
                        {
                            tiles[h, w] = new Tile(
                                new Rectangle((w * 64), (h * 64), 64, 64),
                                new AnimatedTexture(0, 32, 32, tileTextures["Past" + words[0]]), int.Parse(words[1]), true,
                                new AnimatedTexture(0, 32, 32, tileTextures["Future" + words[2] + tileVariant]), int.Parse(words[3]), true, 1);
                        }
                    }
                    //this part of if ladder just makes sure that skipping lines due to documentation in the level files
                    //doesn't skip a tile
                    else if (w == 0)
                    {
                        w = 15;
                        h--;
                    }
                    else
                    {
                        w--;
                    }
                }
            }

            //begin interactable stuff
            while (true)
            {
                line = reader.ReadLine();
                if (line == null || line == "/recepticles")
                {
                    break;
                }
                words = line.Split(' ');
                if (words.Length < 4)
                {
                    continue;
                }
                string    interactableName  = words[0];
                string    interactableState = words[1];
                int       gridX             = int.Parse(words[2]);
                int       gridY             = int.Parse(words[3]);
                Rectangle r = new Rectangle(gridX * 64, gridY * 64, 64, 64);
                switch (interactableName)
                {
                case "Chicken":
                    interactables.Add(new Chicken(r, (ChickenState)Enum.Parse(typeof(ChickenState), interactableState), 1, this));
                    break;

                case "Flower":
                    interactables.Add(new Flower(r, (FlowerState)Enum.Parse(typeof(FlowerState), interactableState), 1, this));
                    break;

                case "Tree":
                    interactables.Add(new Tree(r, (TreeState)Enum.Parse(typeof(TreeState), interactableState), 1, this));
                    break;

                case "WateringCan":
                    interactables.Add(new WateringCan(r, (WateringCanState)Enum.Parse(typeof(WateringCanState), interactableState), 1, this));
                    break;

                case "Shovel":
                    interactables.Add(new Shovel(r, (ShovelState)Enum.Parse(typeof(ShovelState), interactableState), 1, this));
                    break;

                case "Axe":
                    Interactables.Add(new Axe(r, (AxeState)Enum.Parse(typeof(AxeState), interactableState), 1, this));
                    break;
                }
            }

            //skip documentation line in level file
            line = reader.ReadLine();

            //handles recepticles
            while (line != null)
            {
                //to store coordinates of the door
                String[] doorCoord;
                //a temporary reference to a door that needs to be linked to this recepticle
                Tile door;
                //a temporary reference to this recepticle
                Recepticle r;

                words = line.Split(' ');

                if (words[0] == "Past")
                {
                    r = new Recepticle(
                        TimeState.Past,
                        (words[1] + "_" + words[2]),
                        new Rectangle(int.Parse(words[4]) * 64, int.Parse(words[3]) * 64, 64, 64));

                    //loops through remainder of words
                    //which are only coordinates for doors to link to the recepticles
                    for (int i = 5; i < words.Length; i++)
                    {
                        doorCoord = words[i].Split(',');
                        //find that door
                        door = tiles[int.Parse(doorCoord[1]), int.Parse(doorCoord[0])];
                        ((Door)(door)).LinkRecepticle(r);
                    }
                    recepticles.Add(r);
                }
                else if (words[0] == "Future")
                {
                    r = new Recepticle(
                        TimeState.Future,
                        (words[1] + "_" + words[2]),
                        new Rectangle(int.Parse(words[4]) * 64, int.Parse(words[3]) * 64, 64, 64));

                    //loops through remainder of words
                    //which are only coordinates for doors to link to the recepticles
                    for (int i = 5; i < words.Length; i++)
                    {
                        doorCoord = words[i].Split(',');
                        //find that door
                        door = tiles[int.Parse(doorCoord[1]), int.Parse(doorCoord[0])];
                        ((Door)(door)).LinkRecepticle(r);
                    }
                    recepticles.Add(r);
                }

                //go to next line
                line = reader.ReadLine();
            }
        }