public IActionResult SleepDachi(int energy, int fullness, int happiness, int meals, object Sleep) { Dachi moddachi = HttpContext.Session.GetObjectFromJson <Dachi>("gotchi"); int modenergy = Convert.ToInt32(HttpContext.Session.GetInt32("energylevel")); int modhappiness = Convert.ToInt32(HttpContext.Session.GetInt32("happinesslevel")); int modfullness = Convert.ToInt32(HttpContext.Session.GetInt32("fullnesslevel")); moddachi.Sleep(modenergy, modhappiness, modfullness); HttpContext.Session.SetInt32("energylevel", modenergy); HttpContext.Session.SetInt32("happinesslevel", modhappiness); HttpContext.Session.SetInt32("fullnesslevel", modfullness); HttpContext.Session.SetObjectAsJson("gotchi", moddachi); // moddachi.Energy = energy; // moddachi.Happiness = happiness; // moddachi.Fullness = fullness; return(Redirect("/")); }
public IActionResult Update(string action) { string oldDachi = HttpContext.Session.GetString("getDachi"); Dachi dachi = JsonConvert.DeserializeObject <Dachi>(oldDachi); Random rand = new Random(); switch (action) { case "Feed": dachi.Feed(); break; case "Play": dachi.Play(); break; case "Work": dachi.Work(); break; case "Sleep": dachi.Sleep(); break; } if (dachi.Fullness < 1 || dachi.Happiness < 1) { dachi.Messages = "Your DojoDachi has died :("; string newDachi = JsonConvert.SerializeObject(dachi); HttpContext.Session.SetString("getDachi", newDachi); } else if (dachi.Energy > 99 && dachi.Fullness > 99 && dachi.Happiness > 99) { dachi.Messages = "Congrats! You've won! You have done a good job raising your DojoDachi!"; string newDachi = JsonConvert.SerializeObject(dachi); HttpContext.Session.SetString("getDachi", newDachi); } else { string newDachi = JsonConvert.SerializeObject(dachi); HttpContext.Session.SetString("getDachi", newDachi); } return(RedirectToAction("Index")); }