Ejemplo n.º 1
0
        /// <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);
            }  
        }
Ejemplo n.º 2
0
 /// <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;
     }
 }