示例#1
0
        public ActionResult FastTravel()
        {
            var userId         = User.Identity.GetUserId();
            var user           = db.Users.Find(userId);
            var rainbowGemCost = Convert.ToInt32(Request.Form.Get("rainbowGemCost"));

            if (!db.Travels.Any(t => t.UserId == userId) || user.RainbowGems < rainbowGemCost)
            {
                return(RedirectToAction("Index"));
            }

            user.RainbowGems -= rainbowGemCost;

            var travel = db.Travels.First(t => t.UserId == userId);

            travel.ArrivalTime = DateTimeOffset.Now;

            db.SaveChanges();

            var travelService = new TravelService();

            travelService.CheckArrivalTime(userId);

            return(RedirectToAction("Index", "Land"));
        }
示例#2
0
        public ActionResult Travelling()
        {
            var userId = User.Identity.GetUserId();

            var travelService = new TravelService();

            travelService.CheckArrivalTime(userId);

            if (db.CurrentLands.Any(cl => cl.UserId == userId))
            {
                return(RedirectToAction("Index", "Land"));
            }

            if (!db.Travels.Any(t => t.UserId == userId))
            {
                return(RedirectToAction("Index"));
            }


            var travel = db.Travels.First(t => t.UserId == userId);

            return(View(travel));
        }
        void RunServices()
        {
            var db = new ApplicationDbContext();

            var userId = User.Identity.GetUserId();
            var user   = db.Users.Find(userId);

            if ((DateTimeOffset.Now - user.LastRainbowGemTime).TotalHours >= 24)
            {
                user.RainbowGems++;
                user.LastRainbowGemTime = DateTimeOffset.Now;
            }

            user.LastActive = DateTimeOffset.Now;
            db.SaveChanges();

            if (db.Travels.Any(t => t.UserId == userId))
            {
                var travelService = new TravelService();
                travelService.CheckArrivalTime(userId);
            }

            if (user.Stamina < user.MaxStamina)
            {
                var staminaService = new StaminaService();
                staminaService.UpdateStamina(userId);
            }

            var battleService = new BattleService();

            battleService.RunBattles();

            var auctionService = new AuctionService();

            auctionService.CheckAuctions();
        }