public ActionResult NewUnit(int gameID, int civilizationID)
        {
            Debug.WriteLine($"GET: R&D Unit Controller: New");
            Game game         = GameState.Game;
            var  civilization = game.GetCivilization(civilizationID);

            var species = civilization.SpeciesInfo.Select(x => new Checkbox(x.id, x.name, false)).ToList();

            species.Insert(0, new Checkbox(-1, "None", true));

            return(View(new RnDUnitForm
            {
                CivilizationID = civilizationID,
                Units = game.GameStatistics.UnitsRaw
                        .Where(x => UnitTypes.IsSpaceship(x.unit_type) == false)
                        .Where(x => civilization.CanAfford(x.rp_cost))
                        .Select(x => new Checkbox(x.id, $"{x.rp_cost}RP - {x.name} ({x.number_to_build})", false))
                        .ToList(),

                BuildAtInfrastructure = civilization.Assets.CompletedInfrastructure
                                        .Where(x => x.InfrastructureInfo.Infrastructure.unit_training_slots > 0)
                                        .Select(x => new Checkbox(x.CivilizationInfo.id, $"{x.CivilizationInfo.name} - {x.InfrastructureInfo.Infrastructure.name}", false))
                                        .ToList(),
                Species = species
            }));
        }
        public ActionResult EditShip(int gameID, int civilizationID, int?rndUnitID)
        {
            Debug.WriteLine($"GET: Civilization RND Unit Controller: Edit - {nameof(rndUnitID)}={rndUnitID}");
            DB_users user = Auth.User;
            Game     game = GameState.Game;

            var unit           = FindRNDCivilizationUnit(rndUnitID);
            var unitCheckBoxes = game.GameStatistics.UnitsRaw
                                 .Where(x => UnitTypes.IsSpaceship(x.unit_type) == true)
                                 .Select(x => new Checkbox(x.id, x.name, x.id == unit.Info.unit_id))
                                 .ToList();

            var civilization          = game.GetCivilization(unit.Info.civilization_id);
            var buildAtInfrastructure = civilization.Assets.CompletedInfrastructure
                                        .Where(x => x.InfrastructureInfo.Infrastructure.ship_construction_slots > 0)
                                        .Select(x => new Checkbox(x.CivilizationInfo.id, $"{x.CivilizationInfo.name} - {x.InfrastructureInfo.Infrastructure.name}", x.CivilizationInfo.id == unit.Info.civ_struct_id))
                                        .ToList();

            return(View(new RnDUnitForm
            {
                ID = unit.Info.id,
                CivilizationID = unit.Info.civilization_id,

                Name = unit.Info.name,
                BuildPercentage = unit.Info.build_percentage,

                Units = unitCheckBoxes,
                SelectedUnitID = unitCheckBoxes.Where(x => x.IsChecked).First().ID,

                BuildAtInfrastructure = buildAtInfrastructure,
                SelectedBuildAtInfrastructureID = buildAtInfrastructure.Where(x => x.IsChecked).First().ID,
            }));
        }
        public ActionResult NewUnit(RnDUnitForm form)
        {
            Debug.WriteLine($"POST: Civilization RnD Unit Controller: New");
            DB_users user = Auth.User;
            var      game = GameState.Game;

            var dbUnit = game.GameStatistics.UnitsRaw
                         .Where(x => x.id == form.SelectedUnitID.Value)
                         .FirstOrDefault();
            var dbBuildAtStruct = game.GetCivilization(form.CivilizationID.Value).Assets.CompletedInfrastructure
                                  .Where(x => x.CivilizationInfo.id == form.SelectedBuildAtInfrastructureID)
                                  .FirstOrDefault();

            if (dbUnit == null || dbBuildAtStruct == null)
            {
                return(RedirectToRoute("ViewCivilization", new { civilizationID = form.CivilizationID.Value }));
            }

            // Check to ensure there are slots remaining
            var civilization = game.GetCivilization(form.CivilizationID.Value);

            if (UnitTypes.IsSpaceship(dbUnit.unit_type))
            {
                if (!civilization.Assets.HasShipConstructionSlots)
                {
                    return(RedirectToRoute("ViewCivilization", new { civilizationID = form.CivilizationID.Value }));
                }
            }
            else
            {
                if (!civilization.Assets.HasUnitTrainingSlots)
                {
                    return(RedirectToRoute("ViewCivilization", new { civilizationID = form.CivilizationID.Value }));
                }
            }

            // Save the Unit to the DB
            DB_civilization_rnd_units unit = new DB_civilization_rnd_units();

            unit.game_id          = game.ID;
            unit.civilization_id  = form.CivilizationID.Value;
            unit.unit_id          = dbUnit.id;
            unit.civ_struct_id    = dbBuildAtStruct.CivilizationInfo.id;
            unit.species_id       = form.SelectedSpeciesID == -1 ? null : form.SelectedSpeciesID;
            unit.name             = form.Name;
            unit.build_percentage = form.BuildPercentage;
            Database.Session.Save(unit);

            Database.Session.Flush();
            return(RedirectToRoute("ViewCivilization", new { civilizationID = form.CivilizationID.Value }));
        }
Beispiel #4
0
        public void SortUnitsBattlegroups()
        {
            CompletedSpaceUnits  = new List <CivilizationUnit>();
            CompletedGroundUnits = new List <CivilizationUnit>();
            foreach (var unit in CompletedUnitsRaw)
            {
                if (UnitTypes.IsSpaceship(unit.Unit.Info.unit_type))
                {
                    CompletedSpaceUnits.Add(unit);
                }
                else
                {
                    CompletedGroundUnits.Add(unit);
                }
            }

            Battlegroups = new List <Battlegroup>();
            var civilizationBattlegroups = Owner.ThisGame.GameStatistics.BattlegroupsRaw
                                           .Where(x => x.civilization_id == CivilizationID)
                                           .ToList();

            foreach (var bg in civilizationBattlegroups)
            {
                Battlegroups.Add(new Battlegroup(bg, Owner));
            }

            foreach (var unit in CompletedUnitsRaw)
            {
                if (unit.CivilizationInfo.battlegroup_id == null)
                {
                    continue;
                }

                var battlegroup = Battlegroups.Where(x => x.ID == unit.CivilizationInfo.battlegroup_id).FirstOrDefault();
                if (battlegroup == null)
                {
                    continue;
                }
                battlegroup.Units.Add(unit);
            }
        }
Beispiel #5
0
        public void QueryAndConnectCivilizations()
        {
            Debug.WriteLine(string.Format("Game: {0}, Getting Civilizations", Info.id));
            var dbCivilizations = Database.Session.Query <DB_civilization>()
                                  .Where(x => x.game_id == Info.id)
                                  .ToList();

            Civilizations = new List <Civilization>();
            foreach (var dbCivilization in dbCivilizations)
            {
                Civilizations.Add(new Civilization(dbCivilization, this));
            }

            Debug.WriteLine($"Game: {Info.id}, Connecting Civilizations");
            foreach (var civilization in Civilizations)
            {
                #region Completed Assets
                // Research
                foreach (var research in civilization.Assets.CompletedResearch)
                {
                    research.ResearchInfo = GameStatistics.Research.Where(x => x.id == research.CivilizationInfo.research_id).First();
                }

                // Units
                foreach (var unit in civilization.Assets.CompletedUnitsRaw)
                {
                    unit.Unit = GameStatistics.Units.Where(x => x.Info.id == unit.CivilizationInfo.unit_id).First();

                    if (unit.CivilizationInfo.battlegroup_id != null)
                    {
                        unit.BattlegroupInfo = GameStatistics.BattlegroupsRaw.Where(x => x.id == unit.CivilizationInfo.battlegroup_id).First();
                    }

                    if (unit.CivilizationInfo.species_id != null)
                    {
                        unit.SpeciesInfo = GameStatistics.Species.Where(x => x.id == unit.CivilizationInfo.species_id).First();
                    }

                    var experienceLevels = GameStatistics.ExperienceLevels.Where(x => x.threshold < unit.CivilizationInfo.experience).ToList();
                    var highestThreshold = experienceLevels.OrderByDescending(x => x.threshold).FirstOrDefault();
                    if (highestThreshold == null)
                    {
                        unit.ExperienceLevel = new DB_experience_levels
                        {
                            id                   = -1,
                            game_id              = Info.id,
                            name                 = "Level 0",
                            threshold            = 0,
                            agility_bonus        = 0,
                            attack_bonus         = 0,
                            health_bonus         = 0,
                            regeneration_bonus   = 0,
                            special_attack_bonus = 0
                        };
                    }
                    else
                    {
                        unit.ExperienceLevel = highestThreshold;
                    }
                }

                // Infrastructure
                foreach (var infrastructure in civilization.Assets.CompletedInfrastructure)
                {
                    #region Planet
                    bool foundPlanet = false;
                    if (Sector != null)
                    {
                        foreach (var solarsystem in Sector.StarSystemsRaw)
                        {
                            foreach (var star in solarsystem.Stars)
                            {
                                foreach (var planet in star.Planets)
                                {
                                    if (infrastructure.CivilizationInfo.planet_id == planet.Info.id)
                                    {
                                        infrastructure.Planet = planet;
                                        foundPlanet           = true;
                                        break;
                                    }
                                }

                                if (foundPlanet)
                                {
                                    break;
                                }
                            }

                            if (foundPlanet)
                            {
                                break;
                            }
                        }
                    }
                    #endregion

                    infrastructure.InfrastructureInfo = GameStatistics.Infrastructure
                                                        .Where(x => x.Infrastructure.id == infrastructure.CivilizationInfo.struct_id)
                                                        .First();

                    // Experience
                    var experienceLevels = GameStatistics.ExperienceLevels.Where(x => x.threshold < infrastructure.CivilizationInfo.experience).ToList();
                    var highestThreshold = experienceLevels.OrderByDescending(x => x.threshold).FirstOrDefault();
                    if (highestThreshold == null)
                    {
                        infrastructure.ExperienceLevel = new DB_experience_levels
                        {
                            id                   = -1,
                            game_id              = Info.id,
                            name                 = "Level 0",
                            threshold            = 0,
                            agility_bonus        = 0,
                            attack_bonus         = 0,
                            health_bonus         = 0,
                            regeneration_bonus   = 0,
                            special_attack_bonus = 0
                        };
                    }
                    else
                    {
                        infrastructure.ExperienceLevel = highestThreshold;
                    }
                }
                #endregion

                #region Research and Development
                foreach (var research in civilization.Assets.IncompleteResearch)
                {
                    research.BeingResearched = GameStatistics.Research.Where(x => x.id == research.Info.research_id).First();
                    research.BuildingAt      = civilization.Assets.CompletedInfrastructure.Where(x => x.CivilizationInfo.id == research.Info.civ_struct_id).First();
                }

                civilization.Assets.IncompleteGroundUnits = new List <RnDUnit>();
                civilization.Assets.IncompleteSpaceUnits  = new List <RnDUnit>();
                foreach (var unit in civilization.Assets.IncompleteUnitsRaw)
                {
                    unit.BeingBuilt = GameStatistics.Units.Where(x => x.Info.id == unit.Info.unit_id).First();
                    unit.BuildingAt = civilization.Assets.CompletedInfrastructure.Where(x => x.CivilizationInfo.id == unit.Info.civ_struct_id).First();

                    if (UnitTypes.IsSpaceship(unit.BeingBuilt.Info.unit_type))
                    {
                        civilization.Assets.IncompleteSpaceUnits.Add(unit);
                    }
                    else
                    {
                        civilization.Assets.IncompleteGroundUnits.Add(unit);
                    }
                }

                foreach (var infrastructure in civilization.Assets.IncompleteInfrastructure)
                {
                    infrastructure.BeingBuilt = GameStatistics.Infrastructure.Where(x => x.Infrastructure.id == infrastructure.Info.struct_id).First();
                    infrastructure.BuildingAt = civilization.Assets.CompletedInfrastructure.Where(x => x.CivilizationInfo.id == infrastructure.Info.civ_struct_id).First();

                    if (Sector != null)
                    {
                        infrastructure.Planet = Sector.PlanetFromID(infrastructure.Info.planet_id);
                    }
                }
                #endregion

                civilization.Assets.SortUnitsBattlegroups();

                if (Sector != null)
                {
                    foreach (var battlegroup in civilization.Assets.Battlegroups)
                    {
                        battlegroup.StarSystem = Sector.StarsystemFromID(battlegroup.Info.starsystem_id);
                    }
                }


                #region Civilization Traits && TechLevel
                if (civilization.Info.civilization_traits_1_id != null)
                {
                    civilization.CivilizationTrait1 = GameStatistics.CivilizationTraits.Where(x => x.id == civilization.Info.civilization_traits_1_id).First();
                }

                if (civilization.Info.civilization_traits_2_id != null)
                {
                    civilization.CivilizationTrait2 = GameStatistics.CivilizationTraits.Where(x => x.id == civilization.Info.civilization_traits_2_id).First();
                }

                if (civilization.Info.civilization_traits_3_id != null)
                {
                    civilization.CivilizationTrait3 = GameStatistics.CivilizationTraits.Where(x => x.id == civilization.Info.civilization_traits_3_id).First();
                }

                if (civilization.Info.tech_level_id != null)
                {
                    civilization.TechLevel = GameStatistics.TechLevels.Where(x => x.id == civilization.Info.tech_level_id).First();
                }
                #endregion

                if (civilization.MetCivilizations.Count > 0)
                {
                    var allCivilizationsButThis = Civilizations.Where(x => x.ID != civilization.ID);

                    foreach (var metCivilizations in civilization.MetCivilizations)
                    {
                        foreach (var allCivization in allCivilizationsButThis)
                        {
                            if (allCivization.ID == metCivilizations.Info.civilization_id1 ||
                                allCivization.ID == metCivilizations.Info.civilization_id2)
                            {
                                metCivilizations.CivilizationTwo = allCivization;
                            }
                        }
                    }
                }
            }
        }