コード例 #1
0
        public ActionResult New(CivilizationUnitsForm form)
        {
            Debug.WriteLine($"POST: Civilization Units Controller: New");
            DB_users user = Auth.User;
            var      game = GameState.Game;

            var dbUnit = game.GameStatistics.Units
                         .Where(x => x.Info.id == form.SelectedUnitID.Value)
                         .FirstOrDefault();

            if (dbUnit == null)
            {
                return(View(form));
            }

            DB_civilization_units unit = new DB_civilization_units();

            unit.game_id         = game.ID;
            unit.unit_id         = dbUnit.Info.id;
            unit.species_id      = (form.SelectedSpeciesID == -1) ? null : form.SelectedSpeciesID;
            unit.civilization_id = form.CivilizationID.Value;
            unit.name            = form.Name;
            unit.current_health  = dbUnit.Info.base_health;
            unit.experience      = form.Experience;
            unit.gmnotes         = form.GMNotes;
            Database.Session.Save(unit);

            Database.Session.Flush();
            return(RedirectToRoute("ViewCivilization", new { civilizationID = form.CivilizationID.Value }));
        }
コード例 #2
0
        public CivilizationUnit(DB_civilization_units dbCivilizationUnit, Civilization owner)
        {
            CivilizationInfo = dbCivilizationUnit;
            Owner            = owner;
            Unit             = new Unit();

            QueryBattlegroup();
        }
コード例 #3
0
        public ActionResult Edit(CivilizationUnitsForm form)
        {
            Debug.WriteLine($"POST: Civilization Units Controller: Edit");
            DB_users user = Auth.User;
            var      game = GameState.Game;

            DB_civilization_units unit = FindCivilizationUnit(form.ID).CivilizationInfo;

            if (unit.game_id != game.ID)
            {
                return(RedirectToRoute("game", new { gameID = game.Info.id }));
            }

            var dbUnit = game.GameStatistics.UnitsRaw
                         .Where(x => x.id == form.SelectedUnitID.Value)
                         .FirstOrDefault();

            if (dbUnit == null)
            {
                return(View(form));
            }

            unit.name = form.Name;
            if (RequireGMAdminAttribute.IsGMOrAdmin())
            {
                unit.civilization_id = form.CivilizationID.Value;
                unit.unit_id         = dbUnit.id;
                unit.species_id      = (form.SelectedSpeciesID == -1) ? null : form.SelectedSpeciesID;
                unit.current_health  = form.CurrentHealth;
                unit.experience      = form.Experience;
                unit.gmnotes         = form.GMNotes;
            }
            Database.Session.Update(unit);

            Database.Session.Flush();
            return(RedirectToRoute("ViewCivilization", new { civilizationID = form.CivilizationID.Value }));
        }
コード例 #4
0
        public void ProcessTurn()
        {
            int militaryResearchBuildRate = CalculateScienceBuildRate(true);
            int civilianResearchBuildRate = CalculateScienceBuildRate(false);

            foreach (var research in IncompleteResearch)
            {
                if (research.BuildingAt.CivilizationInfo.current_health <= 0)
                {
                    continue;
                }
                int buildRate = 0;

                // Add in the Military Status Build Rate
                if (research.BeingResearched.apply_military)
                {
                    if (research.BuildingAt.CivilizationInfo.is_military == true)
                    {
                        buildRate += research.BuildingAt.InfrastructureInfo.Infrastructure.science_bonus;
                    }

                    buildRate += militaryResearchBuildRate;
                }
                else
                {
                    if (research.BuildingAt.CivilizationInfo.is_military == false)
                    {
                        buildRate += research.BuildingAt.InfrastructureInfo.Infrastructure.science_bonus;
                    }

                    buildRate += civilianResearchBuildRate;
                }

                // Append the temp variable to the build percentage
                research.Info.build_percentage += buildRate;

                // And if the item is more than 100% built, we go ahead and build the item, disposing of the R&D in the process
                if (research.Info.build_percentage >= 100)
                {
                    DB_civilization_research civResearch = new DB_civilization_research();
                    civResearch.civilization_id = research.Info.civilization_id;
                    civResearch.game_id         = research.Info.game_id;
                    civResearch.research_id     = research.Info.research_id;
                    Database.Session.Save(civResearch);

                    Database.Session.Delete(research.Info);
                }
                else // Otherwise, just update the status
                {
                    Database.Session.Update(research.Info);
                }
            }

            int militaryColonialDevelopmentBonus = CalculateColonialDevelopmentBonus(true);
            int civilianColonialDevelopmentBonus = CalculateColonialDevelopmentBonus(false);

            foreach (var infrastructure in IncompleteInfrastructure)
            {
                if (infrastructure.BuildingAt.CivilizationInfo.current_health <= 0)
                {
                    continue;
                }
                int buildRate = 0;

                // Check if the facility we are building it at is equal to the units military status
                buildRate += infrastructure.BuildingAt.Planet.TierInfo.build_rate;
                if (infrastructure.BuildingAt.CivilizationInfo.is_military == infrastructure.BeingBuilt.Infrastructure.is_military)
                {
                    buildRate += infrastructure.BuildingAt.InfrastructureInfo.Infrastructure.colonial_development_bonus;
                }

                // Add in the Military Status Build Rate
                if (infrastructure.BeingBuilt.Infrastructure.is_military)
                {
                    buildRate += militaryColonialDevelopmentBonus;
                }
                else
                {
                    buildRate += civilianColonialDevelopmentBonus;
                }

                // Append the temp variable to the build percentage
                infrastructure.Info.build_percentage += buildRate;

                // And if the item is more than 100% built, we go ahead and build the item, disposing of the R&D in the process
                if (infrastructure.Info.build_percentage >= 100)
                {
                    int maxHealth = infrastructure.BeingBuilt.Infrastructure.base_health;
                    foreach (var research in CompletedResearch)
                    {
                        if (research.ResearchInfo.apply_infrastructure)
                        {
                            maxHealth += research.ResearchInfo.health_bonus;
                        }
                    }

                    DB_civilization_infrastructure civInfrastructure = new DB_civilization_infrastructure();
                    civInfrastructure.game_id         = infrastructure.Info.game_id;
                    civInfrastructure.civilization_id = infrastructure.Info.civilization_id;
                    civInfrastructure.planet_id       = infrastructure.Info.planet_id;
                    civInfrastructure.struct_id       = infrastructure.Info.struct_id;
                    civInfrastructure.name            = infrastructure.Info.name;
                    civInfrastructure.current_health  = maxHealth;
                    civInfrastructure.can_upgrade     = infrastructure.BeingBuilt.UpgradeInfrastructure.Count > 0;
                    civInfrastructure.is_military     = infrastructure.BeingBuilt.Infrastructure.is_military;
                    Database.Session.Save(civInfrastructure);

                    Database.Session.Delete(infrastructure.Info);
                }
                else // Otherwise, just update the status
                {
                    Database.Session.Update(infrastructure.Info);
                }
            }

            int militaryShipConstructionBonus = CalculateShipConstructionBonus(true);
            int civilianShipConstructionBonus = CalculateShipConstructionBonus(false);

            foreach (var ship in IncompleteSpaceUnits)
            {
                if (ship.BuildingAt.CivilizationInfo.current_health <= 0)
                {
                    continue;
                }
                int buildRate = 0;

                // Check if the facility we are building it at is equal to the units military status
                if (ship.BuildingAt.CivilizationInfo.is_military == ship.BeingBuilt.UnitCategory.is_military)
                {
                    buildRate += ship.BeingBuilt.UnitCategory.build_rate;
                    buildRate += ship.BuildingAt.InfrastructureInfo.Infrastructure.ship_construction_bonus;
                }

                // Add in the Military Status Build Rate
                if (ship.BeingBuilt.UnitCategory.is_military)
                {
                    buildRate += militaryShipConstructionBonus;
                }
                else
                {
                    buildRate += civilianShipConstructionBonus;
                }

                // Append the temp variable to the build percentage
                ship.Info.build_percentage += buildRate;

                // And if the item is more than 100% built, we go ahead and build the item, disposing of the R&D in the process
                if (ship.Info.build_percentage >= 100)
                {
                    int maxHealth = ship.BeingBuilt.Info.base_health;
                    foreach (var research in CompletedResearch)
                    {
                        if (research.ResearchInfo.apply_ships)
                        {
                            maxHealth += research.ResearchInfo.health_bonus;
                        }
                    }

                    for (int i = 0; i < ship.BeingBuilt.Info.number_to_build; i++)
                    {
                        var newShip = new DB_civilization_units();
                        newShip.battlegroup_id  = null;
                        newShip.civilization_id = ship.Info.civilization_id;
                        newShip.current_health  = maxHealth;
                        newShip.experience      = 0;
                        newShip.game_id         = ship.Info.game_id;
                        newShip.gmnotes         = "";
                        newShip.name            = ship.Info.name;
                        newShip.species_id      = ship.Info.species_id;
                        newShip.unit_id         = ship.Info.unit_id;
                        Database.Session.Save(newShip);
                    }

                    Database.Session.Delete(ship.Info);
                }
                else // Otherwise, just update the status
                {
                    Database.Session.Update(ship.Info);
                }
            }

            int militaryUnitTrainingBonus = CalculateUnitTrainingBonus(true);
            int civilianUnitTrainingBonus = CalculateUnitTrainingBonus(false);

            foreach (var unit in IncompleteGroundUnits)
            {
                if (unit.BuildingAt.CivilizationInfo.current_health <= 0)
                {
                    continue;
                }
                int buildRate = 0;

                // Check if the facility we are building it at is equal to the units military status
                if (unit.BuildingAt.CivilizationInfo.is_military == unit.BeingBuilt.UnitCategory.is_military)
                {
                    buildRate += unit.BeingBuilt.UnitCategory.build_rate;
                    buildRate += unit.BuildingAt.InfrastructureInfo.Infrastructure.unit_training_bonus;
                }

                // Add in the Military Status Build Rate
                if (unit.BeingBuilt.UnitCategory.is_military)
                {
                    buildRate += militaryUnitTrainingBonus;
                }
                else
                {
                    buildRate += civilianUnitTrainingBonus;
                }

                // Append the temp variable to the build percentage
                unit.Info.build_percentage += buildRate;

                // And if the item is more than 100% built, we go ahead and build the item, disposing of the R&D in the process
                if (unit.Info.build_percentage >= 100)
                {
                    int maxHealth = unit.BeingBuilt.Info.base_health;
                    foreach (var research in CompletedResearch)
                    {
                        if (research.ResearchInfo.apply_ships)
                        {
                            maxHealth += research.ResearchInfo.health_bonus;
                        }
                    }

                    var newUnit = new DB_civilization_units();
                    newUnit.battlegroup_id  = null;
                    newUnit.civilization_id = unit.Info.civilization_id;
                    newUnit.current_health  = maxHealth;
                    newUnit.experience      = 0;
                    newUnit.game_id         = unit.Info.game_id;
                    newUnit.gmnotes         = "";
                    newUnit.name            = unit.Info.name;
                    newUnit.species_id      = unit.Info.species_id;
                    newUnit.unit_id         = unit.Info.unit_id;
                    Database.Session.Save(newUnit);

                    Database.Session.Delete(unit.Info);
                }
                else // Otherwise, just update the status
                {
                    Database.Session.Update(unit.Info);
                }
            }
        }