public void HandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (CanHandleCommandOnUnit(command, unit))
            {
                var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

                var firstUnpillagedImprovement = ImprovementLocationCanon
                                                 .GetPossessionsOfOwner(unitLocation)
                                                 .Where(improvement => !improvement.IsPillaged)
                                                 .FirstOrDefault();

                if (firstUnpillagedImprovement != null)
                {
                    firstUnpillagedImprovement.Pillage();
                }
                else
                {
                    unitLocation.HasRoads = false;
                }

                unit.CurrentMovement--;
            }
            else
            {
                throw new InvalidOperationException("Cannot handle command");
            }
        }
        public bool CanHandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (command.Type != AbilityCommandType.Pillage)
            {
                return(false);
            }

            var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);
            var unitOwner    = UnitPossessionCanon.GetOwnerOfPossession(unit);

            bool hasImprovement = ImprovementLocationCanon.GetPossessionsOfOwner(unitLocation).Any(
                improvement => !improvement.IsPillaged
                );

            if (hasImprovement || unitLocation.HasRoads)
            {
                var cellOwner = CivTerritoryLogic.GetCivClaimingCell(unitLocation);

                return(cellOwner == null || WarCanon.AreAtWar(unitOwner, cellOwner));
            }
            else
            {
                return(false);
            }
        }
        public bool CanHandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

            return(command.Type == AbilityCommandType.BuildRoad &&
                   unitLocation != null &&
                   !unitLocation.HasRoads);
        }
        public bool CanHandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            int argAsInt;

            return(command.Type == AbilityCommandType.StartGoldenAge &&
                   command.ArgsToPass.Count == 1 &&
                   int.TryParse(command.ArgsToPass[0], out argAsInt));
        }
 public bool CanHandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
 {
     if (command.Type == AbilityCommandType.SetUpToBombard)
     {
         return(unit.CurrentMovement > 0 && !unit.IsSetUpToBombard);
     }
     else
     {
         return(false);
     }
 }
Пример #6
0
 public bool CanHandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
 {
     if (command.Type == AbilityCommandType.Fortify)
     {
         return(!unit.IsFortified);
     }
     else
     {
         return(false);
     }
 }
Пример #7
0
 public void HandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
 {
     if (CanHandleCommandOnUnit(command, unit))
     {
         unit.BeginFortifying();
     }
     else
     {
         throw new InvalidOperationException("Cannot handle command");
     }
 }
Пример #8
0
        private bool CanHandleWithNewSite(AbilityCommandRequest command, IUnit unit)
        {
            var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

            var templateOfName    = GetTemplateOfName(command.ArgsToPass.FirstOrDefault());
            var improvementOnCell = ImprovementLocationCanon.GetPossessionsOfOwner(unitLocation).FirstOrDefault();

            return(templateOfName != null &&
                   ValidityLogic.IsTemplateValidForCell(templateOfName, unitLocation, false) &&
                   (improvementOnCell == null || improvementOnCell.Template != templateOfName));
        }
 public void HandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
 {
     if (CanHandleCommandOnUnit(command, unit))
     {
         unit.SetUpToBombard();
         unit.CurrentMovement -= 1;
     }
     else
     {
         throw new InvalidOperationException("Cannot handle command");
     }
 }
Пример #10
0
        public bool CanHandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (command.Type == AbilityCommandType.ClearVegetation)
            {
                var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

                return(unitLocation.Vegetation.ToString().Equals(command.ArgsToPass.FirstOrDefault()));
            }
            else
            {
                return(false);
            }
        }
        public void HandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (CanHandleCommandOnUnit(command, unit))
            {
                var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

                unitLocation.HasRoads = true;
            }
            else
            {
                throw new InvalidOperationException("Cannot handle command");
            }
        }
Пример #12
0
        public bool CanHandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (command.Type == AbilityCommandType.FoundCity)
            {
                var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

                return(CityValidityLogic.IsCellValidForCity(unitLocation));
            }
            else
            {
                return(false);
            }
        }
Пример #13
0
        public void HandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (CanHandleCommandOnUnit(command, unit))
            {
                var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

                CellModificationLogic.ChangeVegetationOfCell(unitLocation, CellVegetation.None);
            }
            else
            {
                throw new InvalidOperationException("Cannot handle command");
            }
        }
Пример #14
0
        private bool CanHandleWithExistingSite(AbilityCommandRequest command, IUnit unit)
        {
            var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

            var templateOfName    = GetTemplateOfName(command.ArgsToPass.FirstOrDefault());
            var improvementOnCell = ImprovementLocationCanon.GetPossessionsOfOwner(unitLocation).FirstOrDefault();

            return(templateOfName != null &&
                   improvementOnCell != null &&
                   templateOfName == improvementOnCell.Template &&
                   !improvementOnCell.IsConstructed &&
                   !improvementOnCell.IsPillaged);
        }
Пример #15
0
        public void HandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (CanHandleCommandOnUnit(command, unit))
            {
                var unitOwner = UnitPossessionCanon.GetOwnerOfPossession(unit);

                TechCanon.AddFreeTechToCiv(unitOwner);
            }
            else
            {
                throw new InvalidOperationException("Cannot handle command");
            }
        }
Пример #16
0
        public bool CanHandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            var unitOwner = UnitPossessionCanon.GetOwnerOfPossession(unit);

            var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

            bool hasRightType = command.Type == AbilityCommandType.AnnexAdjacentTerritory;

            bool unitInOwnerTerritory = CivTerritoryLogic.GetCivClaimingCell(unitLocation) == unitOwner;

            bool hasAnyCities = CityPossessionCanon.GetPossessionsOfOwner(unitOwner).Any();

            return(hasRightType && unitInOwnerTerritory && hasAnyCities);
        }
Пример #17
0
        public void HandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (CanHandleCommandOnUnit(command, unit))
            {
                var unitOwner     = UnitOwnershipCanon.GetOwnerOfPossession(unit);
                var citiesOfOwner = CityPossessionCanon.GetPossessionsOfOwner(unitOwner);

                var cityName = unitOwner.Template.GetNextName(citiesOfOwner);

                CityFactory.Create(UnitPositionCanon.GetOwnerOfPossession(unit), unitOwner, cityName);
            }
            else
            {
                throw new InvalidOperationException("Cannot handle command");
            }
        }
Пример #18
0
        public void HandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (!CanHandleCommandOnUnit(command, unit))
            {
                throw new InvalidOperationException("Cannot handle command");
            }

            if (CanHandleWithExistingSite(command, unit))
            {
                var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

                unit.LockIntoConstruction();

                var improvementOnCell = ImprovementLocationCanon.GetPossessionsOfOwner(unitLocation).FirstOrDefault();

                improvementOnCell.WorkInvested += ImprovementWorkLogic.GetWorkOfUnitOnImprovement(unit, improvementOnCell);

                if (improvementOnCell.IsReadyToConstruct)
                {
                    improvementOnCell.Construct();
                }
            }
            else
            {
                var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

                var templateOfName        = GetTemplateOfName(command.ArgsToPass.FirstOrDefault());
                var improvementAtLocation = ImprovementLocationCanon.GetPossessionsOfOwner(unitLocation).FirstOrDefault();

                if (improvementAtLocation != null)
                {
                    ImprovementLocationCanon.ChangeOwnerOfPossession(improvementAtLocation, null);
                    improvementAtLocation.Destroy();
                }

                var newImprovement = ImprovementFactory.BuildImprovement(templateOfName, unitLocation);

                unit.LockIntoConstruction();

                newImprovement.WorkInvested += ImprovementWorkLogic.GetWorkOfUnitOnImprovement(unit, newImprovement);

                if (newImprovement.IsReadyToConstruct)
                {
                    newImprovement.Construct();
                }
            }
        }
        public void HandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (CanHandleCommandOnUnit(command, unit))
            {
                var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

                var cityAt = CityLocationCanon.GetPossessionsOfOwner(unitLocation).FirstOrDefault();

                float productionAdded = CityConfig.HurryAbilityBaseProduction
                                        + CityConfig.HurryAbilityPerPopProduction * cityAt.Population;

                cityAt.ActiveProject.Progress += Mathf.RoundToInt(productionAdded);
            }
            else
            {
                throw new InvalidOperationException("Cannot handle command");
            }
        }
        public bool CanHandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (command.Type != AbilityCommandType.HurryProduction)
            {
                return(false);
            }

            var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

            var cityAtLocation = CityLocationCanon.GetPossessionsOfOwner(unitLocation).FirstOrDefault();

            if (cityAtLocation == null || cityAtLocation.ActiveProject == null)
            {
                return(false);
            }

            var unitOwner = UnitPossessionCanon.GetOwnerOfPossession(unit);
            var cityOwner = CityPossessionCanon.GetOwnerOfPossession(cityAtLocation);

            return(unitOwner == cityOwner);
        }
        public void HandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (CanHandleCommandOnUnit(command, unit))
            {
                var unitOwner = UnitPossessionCanon.GetOwnerOfPossession(unit);

                int ageDuration = int.Parse(command.ArgsToPass[0]);

                if (GoldenAgeCanon.IsCivInGoldenAge(unitOwner))
                {
                    GoldenAgeCanon.ChangeTurnsOfGoldenAgeForCiv(unitOwner, ageDuration);
                }
                else
                {
                    GoldenAgeCanon.StartGoldenAgeForCiv(unitOwner, ageDuration);
                }
            }
            else
            {
                throw new InvalidOperationException("Cannot handle command");
            }
        }
Пример #22
0
        public void HandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (CanHandleCommandOnUnit(command, unit))
            {
                var unitOwner = UnitPossessionCanon.GetOwnerOfPossession(unit);

                var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

                var nearestCity = GetNearestDomesticCity(unitLocation, unitOwner);

                foreach (var nearbyCell in Grid.GetNeighbors(unitLocation))
                {
                    if (CellPossessionCanon.CanChangeOwnerOfPossession(nearbyCell, nearestCity))
                    {
                        CellPossessionCanon.ChangeOwnerOfPossession(nearbyCell, nearestCity);
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("Command cannot be handled");
            }
        }
        public void HandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (CanHandleCommandOnUnit(command, unit))
            {
                var unitPosition = UnitPositionCanon.GetOwnerOfPossession(unit);
                var unitOwner    = UnitPossessionCanon.GetOwnerOfPossession(unit);

                var nearbyCells = Grid.GetCellsInRadius(unitPosition, 1);

                foreach (var nearbyUnit in nearbyCells.SelectMany(cell => UnitPositionCanon.GetPossessionsOfOwner(cell)))
                {
                    var nearbyOwner = UnitPossessionCanon.GetOwnerOfPossession(nearbyUnit);

                    if (nearbyUnit.Type.IsWaterMilitary() && nearbyOwner == unitOwner)
                    {
                        nearbyUnit.CurrentHitpoints = nearbyUnit.MaxHitpoints;
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("Cannot handle command");
            }
        }
Пример #24
0
 public bool CanHandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
 {
     return(command.Type == AbilityCommandType.BuildImprovement &&
            (CanHandleWithExistingSite(command, unit) || CanHandleWithNewSite(command, unit)));
 }
 public bool CanHandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
 {
     return(command.Type == AbilityCommandType.RepairAdjacentShips);
 }
Пример #26
0
 public bool CanHandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
 {
     return(command.Type == AbilityCommandType.GainFreeTech);
 }