Ejemplo n.º 1
0
        public IntroMetaData LoadMenu(INodePluginContext pc)
        {
            var              roleList = pc.ProcessingContext.InputModel.SecurityModel.Roles;
            var              name     = pc.ProcessingContext.InputModel.SecurityModel.UserName;
            string           command  = string.Empty;
            IntroMetaDataDto metaData = new IntroMetaDataDto();

            using (SqliteConnection connection = new SqliteConnection(_ConnectionString))
            {
                connection.Open();
                if (roleList.Contains("administrator") || roleList.Contains("manager"))
                {
                    command = _QueryBuilder.GetMenuQuery(true);
                }
                else
                {
                    command = _QueryBuilder.GetMenuQuery(false);
                }
                SqliteCommand readMetaDataCommand = new SqliteCommand
                {
                    Connection  = connection,
                    CommandText = command
                };
                readMetaDataCommand.Parameters.Add(new SqliteParameter("name", name));
                using (SqliteDataReader reader = readMetaDataCommand.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            IntroSection sec = new IntroSection
                            {
                                Caption   = reader.GetString(reader.GetOrdinal("scaption")),
                                ImagePath = reader.GetString(reader.GetOrdinal("img")),
                                Id        = reader.GetString(reader.GetOrdinal("sid")),
                                OrderIdx  = int.Parse(reader.GetString(reader.GetOrdinal("sord")))
                            };
                            IntroItem it = new IntroItem
                            {
                                Caption     = reader.GetString(reader.GetOrdinal("itcaption")),
                                Id          = reader.GetString(reader.GetOrdinal("itid")),
                                Description = reader.GetString(reader.GetOrdinal("desc")),
                                OrderIdx    = int.Parse(reader.GetString(reader.GetOrdinal("itord"))),
                                Sources     = null,
                                LaunchSpec  = null
                            };

                            metaData.AddSection(sec).IntroItems.Add(it);
                        }
                    }
                }
            }
            IntroMetaData introMetaData = new IntroMetaData(metaData.Sections);

            if (introMetaData.Sections.Count == 0)
            {
                throw new Exception("Configuration failure.");
            }
            return(introMetaData);
        }
        //This is the beginning of where the game logic starts
        public async Task <IActionResult> PlayGameAsync(Player activePlayer, int?choice)
        {
            // Constructs the IntroSection and assigns it to "intro".
            IntroSection intro = new IntroSection();

            // This should be how to get values from the scene properties.
            //   ViewData["paragraph"] = intro.getIntroScene(0).MainParagraph;
            activePlayer.GameProgress++;
            _context.Update(activePlayer);
            await _context.SaveChangesAsync();

            int playerProgress = activePlayer.GameProgress;

            if (choice == null)
            {
                ViewData["Title"]     = "In the beginning....";
                ViewData["heading"]   = intro.getIntroScene(0).Heading;
                ViewData["paragraph"] = intro.getIntroScene(0).MainParagraph;
                ViewData["prompt"]    = intro.getIntroScene(0).Prompt;
                ViewData["option1"]   = "Turn around, walk away quickly.";
                ViewData["option2"]   = "Read the sign.";
                ViewData["choice1"]   = 1;
                ViewData["choice2"]   = 3;
                return(View("~/Views/Home/TwoOptions.cshtml", activePlayer));
            }
            else if (choice == 1)
            {
                activePlayer.GameProgress++;
                _context.Update(activePlayer);
                await _context.SaveChangesAsync();

                ViewData["Title"]        = "In the beginning....";
                ViewData["heading"]      = intro.getIntroScene(1).Heading;
                ViewData["paragraph"]    = intro.getIntroScene(1).MainParagraph;
                ViewData["prompt"]       = intro.getIntroScene(1).Prompt;
                ViewData["option1"]      = "Walk away for real.";
                ViewData["option2"]      = "Read the sign.";
                ViewData["choice1"]      = 2;
                ViewData["choice2"]      = 3;
                ViewData["activePlayer"] = activePlayer;
                return(View("~/Views/Home/TwoOptions.cshtml", activePlayer));
            }
            else if (choice == 2)
            {
                activePlayer.GameProgress++;
                _context.Update(activePlayer);
                await _context.SaveChangesAsync();

                ViewData["Title"]        = "In the beginning....";
                ViewData["heading"]      = intro.getIntroScene(2).Heading;
                ViewData["paragraph"]    = intro.getIntroScene(2).MainParagraph;
                ViewData["prompt"]       = intro.getIntroScene(2).Prompt;
                ViewData["option1"]      = "You are sad";
                ViewData["option2"]      = "You wish you had changed your mind";
                ViewData["choice1"]      = null;
                ViewData["choice2"]      = null;
                ViewData["activePlayer"] = activePlayer;
                return(View("~/Views/Home/TwoOptions.cshtml", activePlayer));
            }
            else if (choice == 3)
            {
                activePlayer.GameProgress++;
                _context.Update(activePlayer);
                await _context.SaveChangesAsync();

                ViewData["Title"]        = "In the beginning....";
                ViewData["heading"]      = intro.getIntroScene(3).Heading;
                ViewData["paragraph"]    = intro.getIntroScene(3).MainParagraph;
                ViewData["prompt"]       = intro.getIntroScene(3).Prompt;
                ViewData["option1"]      = "Descend the creepy stairs";
                ViewData["option2"]      = "You ignore your curiousity and walk away. Solemnly.";
                ViewData["choice1"]      = 4;
                ViewData["choice2"]      = 2;
                ViewData["activePlayer"] = activePlayer;
                return(View("~/Views/Home/TwoOptions.cshtml", activePlayer));
            }
            else if (choice == 4)
            {
                activePlayer.GameProgress++;
                _context.Update(activePlayer);
                await _context.SaveChangesAsync();

                ViewData["Title"]        = "In the beginning....";
                ViewData["heading"]      = intro.getIntroScene(4).Heading;
                ViewData["paragraph"]    = intro.getIntroScene(4).MainParagraph;
                ViewData["prompt"]       = intro.getIntroScene(4).Prompt;
                ViewData["option1"]      = "Open the door";
                ViewData["option2"]      = "You ignore your cuiousity and walk away. Solemnly.";
                ViewData["choice1"]      = 5;
                ViewData["choice2"]      = 2;
                ViewData["activePlayer"] = activePlayer;
                return(View("~/Views/Home/TwoOptions.cshtml", activePlayer));
            }
            else if (choice == 5)
            {
                activePlayer.GameProgress++;
                _context.Update(activePlayer);
                await _context.SaveChangesAsync();

                ViewData["Title"]        = "In the beginning....";
                ViewData["heading"]      = intro.getIntroScene(5).Heading;
                ViewData["paragraph"]    = intro.getIntroScene(5).MainParagraph;
                ViewData["prompt"]       = intro.getIntroScene(5).Prompt;
                ViewData["option1"]      = "Ask about Dave";
                ViewData["option2"]      = "Ask about Valmor";
                ViewData["choice1"]      = 8;
                ViewData["choice2"]      = 7;
                ViewData["activePlayer"] = activePlayer;
                return(View("~/Views/Home/TwoOptions.cshtml", activePlayer));
            }
            else if (choice == 6)
            {
                activePlayer.GameProgress++;
                _context.Update(activePlayer);
                await _context.SaveChangesAsync();

                ViewData["Title"]        = "In the beginning....";
                ViewData["heading"]      = intro.getIntroScene(4).Heading;
                ViewData["paragraph"]    = intro.getIntroScene(4).MainParagraph;
                ViewData["prompt"]       = intro.getIntroScene(4).Prompt;
                ViewData["option1"]      = "You run for your life.";
                ViewData["option2"]      = "You shake your head and walk away.";
                ViewData["choice1"]      = null;
                ViewData["choice2"]      = null;
                ViewData["activePlayer"] = activePlayer;
                return(View("~/Views/Home/TwoOptions.cshtml", activePlayer));
            }
            else if (choice == 7)
            {
                activePlayer.GameProgress++;
                _context.Update(activePlayer);
                await _context.SaveChangesAsync();

                ViewData["Title"]        = "In the beginning....";
                ViewData["heading"]      = intro.getIntroScene(7).Heading;
                ViewData["paragraph"]    = intro.getIntroScene(7).MainParagraph;
                ViewData["prompt"]       = intro.getIntroScene(7).Prompt;
                ViewData["option1"]      = "Go back";
                ViewData["option2"]      = "Ask about Dave.";
                ViewData["choice1"]      = 5;
                ViewData["choice2"]      = 8;
                ViewData["activePlayer"] = activePlayer;
                return(View("~/Views/Home/TwoOptions.cshtml", activePlayer));
            }
            else if (choice == 8)
            {
                activePlayer.GameProgress++;
                _context.Update(activePlayer);
                await _context.SaveChangesAsync();

                ViewData["Title"]        = "In the beginning....";
                ViewData["heading"]      = intro.getIntroScene(8).Heading;
                ViewData["paragraph"]    = intro.getIntroScene(8).MainParagraph;
                ViewData["prompt"]       = intro.getIntroScene(8).Prompt;
                ViewData["option1"]      = "Yes, I'll fight. ";
                ViewData["option2"]      = "No, I'm not ready for battle. ";
                ViewData["choice1"]      = 9;
                ViewData["choice2"]      = 6;
                ViewData["activePlayer"] = activePlayer;
                return(View("~/Views/Home/TwoOptions.cshtml", activePlayer));
            }
            else
            {
                activePlayer.GameProgress++;
                _context.Update(activePlayer);
                await _context.SaveChangesAsync();

                ViewData["Title"]        = "In the beginning....";
                ViewData["heading"]      = intro.getIntroScene(9).Heading;
                ViewData["paragraph"]    = intro.getIntroScene(9).MainParagraph;
                ViewData["prompt"]       = intro.getIntroScene(9).Prompt;
                ViewData["option1"]      = "End of this tutorial. ";
                ViewData["option2"]      = "Thanks for playing";
                ViewData["choice1"]      = null;
                ViewData["choice2"]      = null;
                ViewData["activePlayer"] = activePlayer;
                return(View("~/Views/Home/TwoOptions.cshtml", activePlayer));
            }



            //else if (activePlayer.GameProgress == 1)
            //{
            //    if (choice == 1)
            //    {
            //        activePlayer.GameProgress = activePlayer.GameProgress++;
            //        _context.Update(activePlayer);
            //        await _context.SaveChangesAsync();
            //        ViewData["Title"] = "In the beginning....";
            //        ViewData["heading"] = "You turn to leave";
            //        ViewData["paragraph"] = "For a long moment you stand with your back to the sign. Urging yourself to walk away. Who cares if there's a new place you've never seen before. It's late, cold, wet, and you should hurry home. But still you stand there-unable to leave. Finally you turn around and inspect the sign.";
            //        ViewData["option1"] = "Read the sign.";
            //        ViewData["option2"] = "Read the sign in a funny accent in your head.";
            //        return View("~/Views/Home/TwoOptions.cshtml", activePlayer);
            //    }
            //    else if (choice == 2)
            //    {
            //        activePlayer.GameProgress = activePlayer.GameProgress+2;
            //        _context.Update(activePlayer);
            //        await _context.SaveChangesAsync();
            //        ViewData["Title"] = "In the beginning....";
            //        ViewData["heading"] = "The Dungeon";
            //        ViewData["paragraph"] = "The medieval style lettering simply reads 'The Dungeon'. Beneath these words there shines an arrow directing your attention to a stairway leading to underground cafes and shops. You peer down the stairs and find a similar sign, though bigger, perhaps redundant and pointless, indicating the entrance to the Dungeon is the first door at the bottom of the stairs. It now appears to be a nightclub...";
            //        ViewData["option1"] = "Turn around, walk away for real.";
            //        ViewData["option2"] = "Walk down the stairs, appease your curiousity.";
            //        return View("~/Views/Home/TwoOptions.cshtml", activePlayer);
            //    }
            //    else
            //    {
            //        ViewData["Title"] = "In the beginning....";
            //        ViewData["heading"] = "Late one night...";
            //        ViewData["paragraph"] = "The air around you is chilled, riddled with mist, and perhaps a hint of magic. Your shoes are on teh brink of slipping on the rain coated sidewalk. The view around you painted by the neon lights of the shops and bars. Surrounded by an array of shops closed early, (due to reduced hours), you stumble your way along. Your mind weak from sleep deprivation and caffeine withdrawl. In the darkness, a faint red light emerges in the distance. You find yourself intrigued. You've walked this path every night for months, yet this blood red glow has no place in your memory. The next two steps allow you to see that the glow is a neon sign.";
            //        ViewData["option1"] = "Turn around, walk away quickly.";
            //        ViewData["option2"] = "Read the sign.";
            //        return View("~/Views/Home/TwoOptions.cshtml", activePlayer);

            //    }

            //}else
            //{
            //    ViewData["heading"] = "Something went wrong.";
            //    ViewData["paragraph"] = "This isn't implemented yet.";
            //    return View("~/Views/Home/TwoOptions.cshtml", activePlayer);
            //}
        }