コード例 #1
0
        public bool BuyIt(GameUserVM vm, Building building)
        {
            bool result = true;

            this.ApplyResourceConfigurations(building);
            foreach (var resource in building.NextCost)
            {
                var realResource = vm.PrincipalPlanet.Resources.FirstOrDefault(x => x.Name.Equals(resource.Name));
                if (resource.LastQuantity > realResource.LastQuantity)
                {
                    result = false;
                }
            }

            if (result)
            {
                using (var db = new ASPNetOgameLikeTPContext())
                {
                    foreach (var resource in building.NextCost)
                    {
                        var realResource = vm.PrincipalPlanet.Resources.FirstOrDefault(x => x.Name.Equals(resource.Name));
                        realResource.LastQuantity = realResource.LastQuantity - resource.LastQuantity;
                        this.SaveResource(db, realResource);
                    }
                }
            }

            return(result);
        }
コード例 #2
0
        public ActionResult GameUserView(GameUserVM vm)
        {
            if (vm == null || vm.PrincipalPlanet == null || vm.Universe == null)
            {
                InitFakeDatas(GameUserController.vm);
            }

            return(View(GameUserController.vm));
        }
コード例 #3
0
 private static void InitFakeDatas(GameUserVM vm)
 {
     try
     {
         using (var db = new ASPNetOgameLikeTPContext())
         {
             Universe universe = db.Universes
                                 .Include(x => x.SolarSystems.Select(y => y.Planets.Select(p => p.Resources)))
                                 .Include(x => x.SolarSystems.Select(y => y.Planets.Select(p => p.Buildings)))
                                 .FirstOrDefault();
             vm.Universe        = universe;
             vm.PrincipalPlanet = universe.SolarSystems.SelectMany(y => y.Planets).FirstOrDefault();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.StackTrace);
     }
 }
コード例 #4
0
        public void RefreshResources(GameUserVM vm)
        {
            List <Resource> resourcesGenerate = new List <Resource>();

            foreach (var building in vm.PrincipalPlanet.Buildings)
            {
                if (building is ResourceGenerator)
                {
                    var resourceGenerator = building as ResourceGenerator;
                    this.ApplyResourceConfigurations(resourceGenerator);

                    foreach (var resource in resourceGenerator.ResourceBySecond)
                    {
                        var      realResource = vm.PrincipalPlanet.Resources.FirstOrDefault(x => x.Name.Equals(resource.Name));
                        TimeSpan ts           = DateTime.Now - realResource.LastUpdate;
                        int      calc         = (int)((double)resource.LastQuantity.Value * ts.TotalSeconds);
                        if (resourcesGenerate.Any(x => x.Name.Equals(resource.Name)))
                        {
                            var resTmp = resourcesGenerate.FirstOrDefault(x => x.Name.Equals(resource.Name));
                            resTmp.LastQuantity = resTmp.LastQuantity + calc;
                        }
                        else
                        {
                            resourcesGenerate.Add(new Resource()
                            {
                                Name = resource.Name, LastQuantity = calc
                            });
                        }
                    }
                }
            }

            using (var db = new ASPNetOgameLikeTPContext())
            {
                foreach (var resource in vm.PrincipalPlanet.Resources)
                {
                    resource.LastQuantity = resource.LastQuantity + resourcesGenerate.FirstOrDefault(x => x.Name.Equals(resource.Name)).LastQuantity;
                    this.SaveResource(db, resource);
                }
            }
        }
コード例 #5
0
 public ActionResult GetContent(GameUserVM vm)
 {
     return(PartialView("~/Views/GameUser/GameUserContent.cshtml", vm));
 }
コード例 #6
0
 public ActionResult GetLeftPanel(GameUserVM vm)
 {
     return(PartialView("~/Views/GameUser/GameUserLeftPanel.cshtml", vm));
 }
コード例 #7
0
 public ActionResult GetHeadband(GameUserVM vm)
 {
     return(PartialView("~/Views/GameUser/GameUserTopHeadband.cshtml", vm));
 }