Esempio 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);
        }
Esempio 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));
        }