public IBuilding BuildBuilding(IBuildingTemplate template, ICity city) { if (template == null) { throw new ArgumentNullException("template"); } else if (city == null) { throw new ArgumentNullException("city"); } var newBuilding = new Building(template); var slots = new List <IWorkerSlot>(); for (int i = 0; i < template.SpecialistCount; i++) { slots.Add(WorkerSlotFactory.BuildSlot(newBuilding)); } newBuilding.Slots = slots.AsReadOnly(); if (!PossessionCanon.CanChangeOwnerOfPossession(newBuilding, city)) { throw new BuildingCreationException("The building produced from this template cannot be placed into this city"); } PossessionCanon.ChangeOwnerOfPossession(newBuilding, city); allBuildings.Add(newBuilding); return(newBuilding); }
public IUnit BuildUnit(IHexCell location, IUnitTemplate template, ICivilization owner, IPromotionTree promotionTree) { if (location == null) { throw new ArgumentNullException("location"); } else if (template == null) { throw new ArgumentNullException("template"); } else if (owner == null) { throw new ArgumentNullException("owner"); } var newUnitObject = GameObject.Instantiate(UnitConfig.UnitPrefab); var newUnitDisplay = GameObject.Instantiate(template.DisplayPrefab); newUnitDisplay.transform.SetParent(newUnitObject.transform); Container.InjectGameObject(newUnitObject); var newUnit = newUnitObject.GetComponent <GameUnit>(); newUnit.transform.SetParent(UnitContainer, false); newUnit.Template = template; newUnit.CurrentMovement = template.MaxMovement; newUnit.CurrentHitpoints = newUnit.MaxHitpoints; newUnit.CanAttack = true; newUnit.Level = 1; newUnit.PromotionTree = promotionTree; allUnits.Add(newUnit); if (UnitPossessionCanon.CanChangeOwnerOfPossession(newUnit, owner)) { UnitPossessionCanon.ChangeOwnerOfPossession(newUnit, owner); } else { throw new UnitCreationException("The newly created unit cannot be assigned to its owner"); } if (newUnit.CanRelocate(location)) { newUnit.Relocate(location); } else { throw new UnitCreationException("The newly created unit cannot be placed at its location"); } UnitSignals.NewUnitCreated.OnNext(newUnit); return(newUnit); }
public override bool CanExecuteBetweenCivs(ICivilization fromCiv, ICivilization toCiv) { if (CityInput == null) { return(false); } var cityOwner = CityPossessionCanon.GetOwnerOfPossession(CityInput); return(cityOwner == fromCiv && CityPossessionCanon.CanChangeOwnerOfPossession(CityInput, toCiv)); }
/// <inheritdoc/> public void PerformExpansion() { CellBeingPursued = ExpansionLogic.GetNextCellToPursue(this); var costOfPursuit = ExpansionLogic.GetCultureCostOfAcquiringCell(this, CellBeingPursued); if (CellBeingPursued != null && costOfPursuit <= CultureStockpile && TilePossessionCanon.CanChangeOwnerOfPossession(CellBeingPursued, this) ) { CultureStockpile -= costOfPursuit; TilePossessionCanon.ChangeOwnerOfPossession(CellBeingPursued, this); CellBeingPursued = ExpansionLogic.GetNextCellToPursue(this); } }
public void RespondToCombat(IUnit attacker, IUnit defender, CombatInfo combatInfo) { if (attacker.CurrentHitpoints <= 0 && attacker.Type != UnitType.City) { DestroyUnit(attacker); } if (defender.CurrentHitpoints <= 0) { if (defender.Type == UnitType.City) { defender.CurrentHitpoints = 1; } else { var defenderLocation = UnitPositionCanon.GetOwnerOfPossession(defender); var attackerOwner = UnitPossessionCanon.GetOwnerOfPossession(attacker); if (combatInfo.CombatType == CombatType.Melee && UnitConfig.CapturableTemplates.Contains(defender.Template) && UnitPossessionCanon.CanChangeOwnerOfPossession(defender, attackerOwner) ) { UnitPossessionCanon.ChangeOwnerOfPossession(defender, attackerOwner); } else { DestroyUnit(defender); } if (attacker.CurrentHitpoints > 0 && combatInfo.CombatType == CombatType.Melee) { attacker.CurrentPath = new List <IHexCell>() { defenderLocation }; attacker.PerformMovement(false); } } } }
private void OnCellClicked(Tuple <IHexCell, PointerEventData> data) { if (DisplayType != CityDisplayType.MapEditor) { return; } var cell = data.Item1; if (CellPossessionCanon.GetOwnerOfPossession(cell) == ObjectToDisplay) { if (CellPossessionCanon.CanChangeOwnerOfPossession(cell, null)) { CellPossessionCanon.ChangeOwnerOfPossession(cell, null); } } else if (BorderExpansionLogic.IsCellAvailable(ObjectToDisplay, cell)) { CellPossessionCanon.ChangeOwnerOfPossession(cell, ObjectToDisplay); } }
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 ICity Create(IHexCell location, ICivilization owner, string name) { if (location == null) { throw new ArgumentNullException("location"); } else if (owner == null) { throw new ArgumentNullException("owner"); } var newCityGameObject = GameObject.Instantiate(CityPrefab); Container.InjectGameObject(newCityGameObject); newCityGameObject.transform.position = location.AbsolutePosition; newCityGameObject.name = name; newCityGameObject.transform.SetParent(CityContainer, true); var newCity = newCityGameObject.GetComponent <City>(); CityLocationCanon.ChangeOwnerOfPossession(newCity, location); location.SuppressSlot = true; CellModificationLogic.ChangeVegetationOfCell(location, CellVegetation.None); if (CityPossessionCanon.CanChangeOwnerOfPossession(newCity, owner)) { CityPossessionCanon.ChangeOwnerOfPossession(newCity, owner); } else { throw new CityCreationException("Cannot assign the newly created city to its intended civilization"); } var combatantTemplate = Container.Instantiate <CityCombatantTemplate>(new object[] { newCity }); newCity.CombatFacade = UnitFactory.BuildUnit(location, combatantTemplate, owner); if (CellPossessionCanon.CanChangeOwnerOfPossession(location, newCity)) { CellPossessionCanon.ChangeOwnerOfPossession(location, newCity); } else { throw new CityCreationException("Cannot assign the given location to the newly created city"); } foreach (var neighbor in Grid.GetNeighbors(location)) { if (CellPossessionCanon.CanChangeOwnerOfPossession(neighbor, newCity)) { CellPossessionCanon.ChangeOwnerOfPossession(neighbor, newCity); } } newCity.YieldFocus = YieldFocusType.TotalYield; newCity.Population = 1; allCities.Add(newCity); return(newCity); }