/// <summary> /// Increases the resource generation. /// </summary> /// <param name="account">Current account.</param> /// <param name="actionTime">Action time.</param> /// <param name="entitypos">Entity position.</param> /// <param name="regionManagerC">Region manager controller.</param> public static void IncreaseResourceGeneration(Account account, DateTime actionTime, PositionI entitypos, Controllers.RegionManagerController regionManagerC) { switch (regionManagerC.GetRegion(entitypos.RegionPosition).GetEntity(entitypos.CellPosition).DefinitionID) { case (int)Core.Models.Definitions.EntityType.Lab: account.Technology.Set(actionTime, account.Technology.GetValue(actionTime), Constants.TECHNOLOGY_INCREMENT_VALUE); break; case (int)Core.Models.Definitions.EntityType.Furnace: account.Scrap.Set(actionTime, account.Scrap.GetValue(actionTime), Constants.SCRAP_INCREMENT_VALUE); break; } }
/// <summary> /// Destroy the building and undo the functionality. /// </summary> /// <param name="entity">Current entity.</param> /// <param name="regionPos">Region position.</param> /// <param name="action">Action which is currently done.</param> /// <param name="regionManagerC">Region manager controller.</param> public static void DestroyBuilding(Entity entity, Region regionPos, Action action, Controllers.RegionManagerController regionManagerC) { // TODO: in pseudo klasse kapseln und generischer lösen switch ((long)entity.DefinitionID) { case (long)Models.Definitions.EntityType.Headquarter: regionPos.FreeClaimedTerritory(LogicRules.GetSurroundedPositions(entity.Position, Constants.HEADQUARTER_TERRITORY_RANGE), entity.Owner); DecreaseWholeStorage(entity.Owner); DisableBuildOptions(entity.DefinitionID, entity.Owner); entity.Owner.TerritoryBuildings.Remove(entity.Position); // TODO: bessere lösung als alles neu claimen finden foreach (var building in entity.Owner.TerritoryBuildings) { var list = new HashSet<PositionI>(); var range = 0; if (building.Value == (long)Definitions.EntityType.Headquarter) { range = Constants.HEADQUARTER_TERRITORY_RANGE; } else if (building.Value == (long)Definitions.EntityType.GuardTower) { range = Constants.GUARDTOWER_TERRITORY_RANGE; } list = GetSurroundedPositions(building.Key, range); var region = building.Key.RegionPosition; regionManagerC.GetRegion(region).ClaimTerritory(list, entity.Owner, region, regionManagerC.RegionManager); } // DestroyAllBuildingsWithoutTerritory(entity.Owner, action, regionManagerC); break; case (long)Models.Definitions.EntityType.GuardTower: regionPos.FreeClaimedTerritory(LogicRules.GetSurroundedPositions(entity.Position, Constants.GUARDTOWER_TERRITORY_RANGE), entity.Owner); entity.Owner.TerritoryBuildings.Remove(entity.Position); // TODO: bessere lösung als alles neu claimen finden foreach (var building in entity.Owner.TerritoryBuildings) { var list = new HashSet<PositionI>(); var range = 0; if (building.Value == (long)Definitions.EntityType.Headquarter) { range = Constants.HEADQUARTER_TERRITORY_RANGE; } else if (building.Value == (long)Definitions.EntityType.GuardTower) { range = Constants.GUARDTOWER_TERRITORY_RANGE; } list = GetSurroundedPositions(building.Key, range); var region = building.Key.RegionPosition; regionManagerC.GetRegion(region).ClaimTerritory(list, entity.Owner, region, regionManagerC.RegionManager); } // DestroyAllBuildingsWithoutTerritory(entity.Owner, action, regionManagerC); break; case (long)Models.Definitions.EntityType.Barracks: var count = 0; foreach (var element in entity.Owner.Buildings) { if (entity.Owner.Buildings.ContainsValue(element.Value)) { count++; } } if (count == 1) { DisableBuildOptions(entity.DefinitionID, entity.Owner); } entity.Owner.Buildings.Remove(entity.Position); break; case (long)Models.Definitions.EntityType.Furnace: DecreaseResourceGeneration(entity.Owner, action.ActionTime, entity.Position, regionManagerC); entity.Owner.Buildings.Remove(entity.Position); break; case (long)Models.Definitions.EntityType.Factory: entity.Owner.Buildings.Remove(entity.Position); break; case (long)Models.Definitions.EntityType.Attachment: entity.Owner.Buildings.Remove(entity.Position); break; case (long)Models.Definitions.EntityType.Hospital: entity.Owner.Buildings.Remove(entity.Position); break; case (long)Models.Definitions.EntityType.TradingPost: entity.Owner.Buildings.Remove(entity.Position); break; case (long)Models.Definitions.EntityType.Tent: DecreaseMaxPopulation(entity.Owner, entity); entity.Owner.Buildings.Remove(entity.Position); break; case (long)Models.Definitions.EntityType.Lab: DecreaseResourceGeneration(entity.Owner, action.ActionTime, entity.Position, regionManagerC); entity.Owner.Buildings.Remove(entity.Position); break; case (long)Models.Definitions.EntityType.Scrapyard: DecreaseScrap(entity.Owner, entity); entity.Owner.Buildings.Remove(entity.Position); break; } }
/// <summary> /// Gathers the resources. /// </summary> /// <param name="account">Current account.</param> /// <param name="actionTime">Action time.</param> /// <param name="regionManagerC">Region manager controller.</param> /// <param name="range">Range of the building.</param> public static void GatherResources(Account account, DateTime actionTime, Controllers.RegionManagerController regionManagerC, int range) { foreach (var element in account.TerritoryBuildings) { var list = LogicRules.GetSurroundedPositions(element.Key, range); float scrapAmount = 0; float plutoniumAmount = 0; foreach (var item in list) { // TODO: add ressources in Terrain var resources = regionManagerC.GetRegion(item.RegionPosition).GetTerrain(item.CellPosition); scrapAmount += 0.5f; plutoniumAmount += 0.3f; } account.Scrap.Set(actionTime, account.Scrap.GetValue(actionTime), Constants.SCRAP_INCREMENT_VALUE); account.Plutonium.Set(actionTime, account.Plutonium.GetValue(actionTime), Constants.PLUTONIUM_INCREMENT_VALUE); } }
/// <summary> /// Destroy all buildings without territory. /// </summary> /// <param name="account">Current account.</param> /// <param name="action">Action which is in use.</param> /// <param name="regionManagerC">Region manager controller.</param> public static void DestroyAllBuildingsWithoutTerritory(Account account, Action action, Controllers.RegionManagerController regionManagerC) { Dictionary<PositionI, long> copylist = new Dictionary<PositionI, long>(account.Buildings); foreach (var building in copylist) { var region = regionManagerC.GetRegion(building.Key.RegionPosition); if (region.GetClaimedTerritory(building.Key) == null) { DestroyBuilding(region.GetEntity(building.Key.CellPosition), region, action, regionManagerC); region.RemoveEntity(action.ActionTime, region.GetEntity(building.Key.CellPosition)); } } account.Buildings.Clear(); foreach (var test in copylist) { account.Buildings.Add(test.Key, test.Value); } }