Ejemplo n.º 1
0
        /// <summary>
        /// This method returns a created eventsviewmodel which loads its content from a database with the characterid stored in the session.
        /// </summary>
        /// <returns></returns>
        public EventsViewModel GetEventsViewModel()
        {
            RPGSQLContext rpgsqlContext = new RPGSQLContext();
            RPGRepository repo          = new RPGRepository(rpgsqlContext);
            Character     cha           = repo.GetById(Convert.ToInt32(Session["CharId"]));

            cha.InventoryList = repo.GetInventory(Convert.ToInt32(Session["CharId"]));
            cha.initWeapons();
            eventsViewModel.EventsSystem                   = new EventSystem();
            eventsViewModel.EventsSystem.character         = cha;
            eventsViewModel.EventsSystem.ScenarioList      = repo.GetStory();
            eventsViewModel.EventsSystem.playerProgression = Convert.ToInt32(Session["playerProgression"]);
            Session["Button1Name"] = eventsViewModel.EventsSystem.ScenarioList[(int)Session["playerProgression"] - 1].Button1Text;
            Session["Button2Name"] = eventsViewModel.EventsSystem.ScenarioList[(int)Session["playerProgression"] - 1].Button2Text;

            return(eventsViewModel);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Start the game with the given character id. The story and the events system also gets loaded here.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Play(int id)
        {
            RPGRepository rpgrepo = new RPGRepository(rpgct);

            Character character = rpgrepo.GetById(id);

            character.InventoryList = rpgrepo.GetInventory(id);
            character.initWeapons();

            if (character == null)
            {
                throw new Exception("id does not exist.");
            }


            eventsViewModel.EventsSystem = new EventSystem();
            eventsViewModel.EventsSystem.ScenarioList      = rpgrepo.GetStory();
            eventsViewModel.EventsSystem.playerProgression = 1;
            eventsViewModel.EventsSystem.character         = character;

            if (Session["itemdrop"] != null)
            {
                int  itmid = (int)Session["itemdrop"];
                Item item  = rpgrepo.GetItemById(itmid);
                Session["itemdrop"] = item;
                character.InventoryList.Add(item);
                eventsViewModel.droppedItem = item;
            }
            Session["CharId"] = character.CharacterID;
            if (Session["playerProgression"] == null)
            {
                Session["playerProgression"] = 1;
            }
            Session["Button1Name"] = eventsViewModel.EventsSystem.ScenarioList[(int)Session["playerProgression"] - 1].Button1Text;
            Session["Button2Name"] = eventsViewModel.EventsSystem.ScenarioList[(int)Session["playerProgression"] - 1].Button2Text;

            GloballyAccessibleClass.Instance.EventsSystem = new EventSystem();
            return(View(eventsViewModel));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method uses the characters progressionid to show events linked to that id. It also uses this to redirect the user to combat if nessesary.
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public ActionResult RedirectToCommand(string command)
        {
            RPGRepository rpgrepo = new RPGRepository(rpgct);
            int           prog    = Convert.ToInt32(Session["playerProgression"]);

            if (command == "Action1")
            {
                if (prog == 1)
                {
                    prog = 3;
                }
                else if (prog == 2)
                {
                    //add combat redirect
                    prog = 5;
                    Session["playerProgression"] = prog;
                    return(RedirectToAction("Combat"));
                }
                else if (prog == 3)
                {
                    prog = 4;
                }
                else if (prog == 4)
                {
                    prog = 5;
                }
                else if (prog == 5)
                {
                    //Add DBO querry voor weapon repair
                    prog = 7;

                    RPGSQLContext rpgsqlContext = new RPGSQLContext();
                    RPGRepository repo          = new RPGRepository(rpgsqlContext);
                    Character     cha           = repo.GetById(Convert.ToInt32(Session["CharId"]));
                    cha.InventoryList = repo.GetInventory(Convert.ToInt32(Session["CharId"]));
                    cha.initWeapons();

                    cha.Weapon.RepairItem();
                }
                else if (prog == 6)
                {
                    prog = 7;
                }
                else if (prog == 7)
                {
                    prog = 10;
                    Session["playerProgression"] = prog;
                    return(RedirectToAction("Combat"));
                }
                else if (prog == 9)
                {
                    prog = 11;
                }
                else if (prog == 10)
                {
                    prog = 11;
                }
                else if (prog == 11)
                {
                    Session["playerProgression"] = 1;
                    return(RedirectToAction("Logout", "Account"));
                }
            }
            else if (command == "Action2")
            {
                if (prog == 1)
                {
                    prog = 2;
                }
                else if (prog == 4)
                {
                    prog = 6;
                }
                else if (prog == 7)
                {
                    prog = 9;
                }
                else if (prog == 11)
                {
                    Session["playerProgression"] = 1;
                    return(RedirectToAction("Logout", "Account"));
                }
            }
            Session["playerProgression"] = prog;

            return(View("Play", GetEventsViewModel()));
        }