internal CacheExpirationActionParameters(CacheExpirationActionParametersOdataType odataType, CacheBehavior cacheBehavior, CacheType cacheType, string cacheDuration) { OdataType = odataType; CacheBehavior = cacheBehavior; CacheType = cacheType; CacheDuration = cacheDuration; }
public ParkingAreaResponse GetResponse(CacheBehavior cacheBehavior) { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.GetAsync("https://stkorspublicservices.linkoping.se/parkeringsapp/ParkeringsappV2.svc/GetParkeringsytaList/").Result; if (response.IsSuccessStatusCode) { string strJson = response.Content.ReadAsStringAsync().Result; ParkingAreaResponse parkingResponse = JsonConvert.DeserializeObject<ParkingAreaResponse>(strJson); return parkingResponse; } } return new ParkingAreaResponse(); }
private void GenerateDeployPointsFromMinesToMilk(CacheBehavior behavior = CacheBehavior.Default) { // Find all mines List <Building> mines = new List <Building>(); TownHall th = TownHall.Find(); if (th != null) { mines.Add(th); } if (!resourcesFull.HasFlag(ResourcesFull.Gold)) { mines.AddRange(GoldMine.Find(behavior)); } if (!resourcesFull.HasFlag(ResourcesFull.Elixir)) { mines.AddRange(ElixirCollector.Find(behavior)); } if (!resourcesFull.HasFlag(ResourcesFull.Delixir)) { mines.AddRange(DarkElixirDrill.Find(behavior)); } List <PointFT> resultPoints = new List <PointFT>(); foreach (Building mine in mines) { PointFT center = mine.Location.GetCenter(); PointFT closest = GameGrid.RedPoints.OrderBy(p => p.DistanceSq(center)).First(); float distanceSq = center.DistanceSq(closest); Log.Debug("DistanceSq from " + mine.GetType().Name + " to red point: " + distanceSq.ToString("F1")); if (distanceSq < 9) // 3 tiles (squared = 9) means there is no wall or building between us and the collector { Log.Debug("Adding deploy point"); PointFT awayFromRedLine = closest.AwayFrom(center, 0.5f); resultPoints.Add(awayFromRedLine); } } Log.Debug("Found " + resultPoints.Count + " deploy points"); deployPoints = resultPoints.ToArray(); }
public static Target TargetDarkElixirStorage(CacheBehavior behavior = CacheBehavior.Default) { var target = new Target(); var des = DarkElixirStorage.Find(behavior); target.ValidTarget = false; if (des.Length > 0) { target.ValidTarget = true; target.TargetBuilding = des[0]; target.Center = des[0].Location.GetCenter(); target.Edge = Origin.PointOnLineAwayFromEnd(target.Center, _DEStorageCenterToOuterEdgeDistance); target.NearestRedLine = GameGrid.RedPoints.OrderBy(p => p.DistanceSq(target.Edge)).First(); target.EdgeToRedline = target.Edge.DistanceSq(target.NearestRedLine); //Fill the DeployGrunts Property with where out main dragon force should go. target.DeployGrunts = Origin.PointOnLineAwayFromEnd(target.NearestRedLine, 0.2f); //TODO Move to Constants.. } return(target); }
public static Target[] GenerateTargets(float minimumDistance, bool ignoreGold, bool ignoreElixir, CacheBehavior behavior = CacheBehavior.Default) { // Find all Collectors & storages just sitting around... List <Building> buildings = new List <Building>(); if (!ignoreGold) { //User has Gold min set to ZERO - which means Dont include Gold Targets buildings.AddRange(GoldMine.Find(behavior)); buildings.AddRange(GoldStorage.Find(behavior)); } if (!ignoreElixir) { //User has Elixir min set to ZERO - which means Dont include Elixir Targets buildings.AddRange(ElixirCollector.Find(behavior)); buildings.AddRange(ElixirStorage.Find(behavior)); } //We always includ DarkElixir - Because who doesnt love dark Elixir? buildings.AddRange(DarkElixirDrill.Find(behavior)); buildings.AddRange(DarkElixirStorage.Find(behavior)); List <Target> targetList = new List <Target>(); foreach (Building building in buildings) { Target current = new Target(); current.TargetBuilding = building; current.Center = building.Location.GetCenter(); current.NearestRedLine = GameGrid.RedPoints.OrderBy(p => p.DistanceSq(current.Center)).First(); current.CenterToRedline = current.Center.DistanceSq(current.NearestRedLine); Log.Debug($"[Berts Algorithms] DistanceSq from {current.Name} to red point: {current.CenterToRedline.ToString("F1")}"); if (current.CenterToRedline < minimumDistance) //Compare distance to Redline to the Minimum acceptable distance Passed in { current.DeployGrunts = current.Center.PointOnLineAwayFromEnd(current.NearestRedLine, _gruntDeployDistanceFromRedline); //Barbs & Goblins current.DeployRanged = current.Center.PointOnLineAwayFromEnd(current.NearestRedLine, _rangedDeployDistanceFromRedline); //Archers & Minions targetList.Add(current); } } Log.Debug($"[Berts Algorithms] Found {targetList.Count} deploy points"); return(targetList.ToArray()); }
public static int CountRipeCollectors(float minimumDistance, bool ignoreGold, bool ignoreElixir, CacheBehavior behavior = CacheBehavior.Default) { Target[] targets = GenerateTargets(minimumDistance, ignoreGold, ignoreElixir, behavior); return(targets.Length); }
public static Target[] GenerateTargets(string algorithmName, float minimumDistance, bool ignoreGold, bool ignoreElixir, string AttackId, out double avgFillstate, out double avgCollectorLvl, CacheBehavior behavior = CacheBehavior.Default, bool outputDebugImage = false, bool activeBase = false) { // Find all Collectors & storages just sitting around... List <Building> buildings = new List <Building>(); //Get a list of Gold Mines. List <GoldMine> goldMines = new List <GoldMine>(); goldMines.AddRange(GoldMine.Find(behavior)); //Get a list of Elixir Collectors. List <ElixirCollector> elixirCollectors = new List <ElixirCollector>(); elixirCollectors.AddRange(ElixirCollector.Find(behavior)); avgFillstate = 0; //Get the Average Fill State of all the Elixir Collectors - From this we can tell what percentage of the loot is in Collectors. if (elixirCollectors.Count > 1) { avgFillstate = elixirCollectors.Average(c => c.FillState); } //Log the Average Fill State of aLL elixir Collectors... Log.Debug($"[Berts Algorithms] - Fill State Average of ALL Elixir Collectors: {(avgFillstate * 10).ToString("F1")}"); if (!ignoreGold) { buildings.AddRange(goldMines); if (activeBase) { buildings.AddRange(GoldStorage.Find(behavior)); } } if (!ignoreElixir) { buildings.AddRange(elixirCollectors); if (activeBase) { buildings.AddRange(ElixirStorage.Find(behavior)); } } //Determine the Average Collector Level. avgCollectorLvl = 0; if (ignoreGold && !ignoreElixir) { if (elixirCollectors.Count(c => c.Level.HasValue) > 1) { avgCollectorLvl = elixirCollectors.Where(c => c.Level.HasValue).Average(c => (int)c.Level); } } else if (ignoreElixir && !ignoreGold) { if (goldMines.Count(c => c.Level.HasValue) > 1) { avgCollectorLvl = goldMines.Where(c => c.Level.HasValue).Average(c => (int)c.Level); } } else if (!ignoreElixir && !ignoreGold) { if (buildings.Count(c => c.Level.HasValue) > 1) { avgCollectorLvl = buildings.Where(c => c.Level.HasValue).Average(c => (int)c.Level); } } //We always includ DarkElixir - Because who doesnt love dark Elixir? buildings.AddRange(DarkElixirDrill.Find(behavior)); if (activeBase) { buildings.AddRange(DarkElixirStorage.Find(behavior)); } List <Target> targetList = new List <Target>(); foreach (Building building in buildings) { Target current = new Target(); current.TargetBuilding = building; current.Center = building.Location.GetCenter(); current.Edge = Origin.PointOnLineAwayFromEnd(current.Center, 1.0f); current.NearestRedLine = AllPoints.OrderBy(p => p.DistanceSq(current.Edge)).First(); current.CenterToRedline = current.Center.DistanceSq(current.NearestRedLine); if (current.CenterToRedline < minimumDistance) //Compare distance to Redline to the Minimum acceptable distance Passed in { Log.Debug($"[Berts Algorithms] Distance from {current.Name} to red point: {Math.Sqrt(current.CenterToRedline).ToString("F1")}, Min Distance: {Math.Sqrt(minimumDistance).ToString("F1")} - GO!"); current.DeployGrunts = current.Center.PointOnLineAwayFromEnd(current.NearestRedLine, _gruntDeployDistanceFromRedline); //Barbs & Goblins current.DeployRanged = current.Center.PointOnLineAwayFromEnd(current.NearestRedLine, _rangedDeployDistanceFromRedline); //Archers & Minions targetList.Add(current); } else { Log.Debug($"[Berts Algorithms] Distance from {current.Name} to red point: {Math.Sqrt(current.CenterToRedline).ToString("F1")}, Min Distance: {Math.Sqrt(minimumDistance).ToString("F1")} - TOO FAR!"); } } if (outputDebugImage) { OutputDebugImage(algorithmName, buildings, targetList, AttackId); } return(targetList.ToArray()); }
public static int CountRipeCollectors(string algorithmName, float minimumDistance, bool ignoreGold, bool ignoreElixir, string AttackId, out double fillState, out double collectorLvl, CacheBehavior behavior = CacheBehavior.Default, bool activeBase = false) { Target[] targets = GenerateTargets(algorithmName, minimumDistance, ignoreGold, ignoreElixir, AttackId, out fillState, out collectorLvl, behavior, false, activeBase); return(targets.Length); }
/// <summary> /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider" /// /> and <see cref="ignoreCase" /> /// </summary> /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param> /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param> /// <param name="formatProvider">not used by this TypeConverter.</param> /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param> /// <returns> /// an instance of <see cref="CacheBehavior" />, or <c>null</c> if there is no suitable conversion. /// </returns> public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => CacheBehavior.CreateFrom(sourceValue);
public CacheableAttribute(CacheBehavior action, string dependencyKey) { Action = action; DependencyKey = dependencyKey; }
public EnableCacheAttribute(CacheBehavior behavior, params string[] tags) { Behavior = behavior; Tags = tags; }
public EnableCacheAttribute(params string[] tags) { Behavior = CacheBehavior.Clone; Tags = tags; }
public CacheExpirationActionParameters(CacheExpirationActionParametersOdataType odataType, CacheBehavior cacheBehavior, CacheType cacheType) { OdataType = odataType; CacheBehavior = cacheBehavior; CacheType = cacheType; }
public static Target[] GenerateTargets(float minimumDistance, bool ignoreGold, bool ignoreElixir, CacheBehavior behavior = CacheBehavior.Default, bool outputDebugImage = false) { // Find all Collectors & storages just sitting around... List <Building> buildings = new List <Building>(); if (!ignoreGold) { //User has Gold min set to ZERO - which means Dont include Gold Targets buildings.AddRange(GoldMine.Find(behavior)); buildings.AddRange(GoldStorage.Find(behavior)); } if (!ignoreElixir) { //User has Elixir min set to ZERO - which means Dont include Elixir Targets buildings.AddRange(ElixirCollector.Find(behavior)); buildings.AddRange(ElixirStorage.Find(behavior)); } //We always includ DarkElixir - Because who doesnt love dark Elixir? buildings.AddRange(DarkElixirDrill.Find(behavior)); buildings.AddRange(DarkElixirStorage.Find(behavior)); List <Target> targetList = new List <Target>(); foreach (Building building in buildings) { Target current = new Target(); current.TargetBuilding = building; current.Center = building.Location.GetCenter(); current.NearestRedLine = GameGrid.RedPoints.OrderBy(p => p.DistanceSq(current.Center)).First(); current.CenterToRedline = current.Center.DistanceSq(current.NearestRedLine); Log.Debug($"[Berts Algorithms] DistanceSq from {current.Name} to red point: {current.CenterToRedline.ToString("F1")}"); if (current.CenterToRedline < minimumDistance) //Compare distance to Redline to the Minimum acceptable distance Passed in { current.DeployGrunts = current.Center.PointOnLineAwayFromEnd(current.NearestRedLine, _gruntDeployDistanceFromRedline); //Barbs & Goblins current.DeployRanged = current.Center.PointOnLineAwayFromEnd(current.NearestRedLine, _rangedDeployDistanceFromRedline); //Archers & Minions targetList.Add(current); } } if (outputDebugImage) { var d = DateTime.UtcNow; var debugFileName = $"Human Barch {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}"; //Get a screen Capture of all targets we found... using (Bitmap canvas = Screenshot.Capture()) { Screenshot.Save(canvas, $"{debugFileName}_1"); foreach (var building in buildings) { var color = Color.White; if (building.GetType() == typeof(ElixirCollector) || building.GetType() == typeof(ElixirStorage)) { color = Color.Violet; } if (building.GetType() == typeof(GoldMine) || building.GetType() == typeof(GoldStorage)) { color = Color.Gold; } if (building.GetType() == typeof(DarkElixirDrill) || building.GetType() == typeof(DarkElixirStorage)) { color = Color.Brown; } //Draw a target on each building. Visualize.Target(canvas, building.Location.GetCenter(), 40, color); } //Save the Image to the Debug Folder... Screenshot.Save(canvas, $"{debugFileName}_2"); } //Get a screen Capture of all targets we found... using (Bitmap canvas = Screenshot.Capture()) { foreach (var target in targetList) { var color = Color.White; if (target.TargetBuilding.GetType() == typeof(ElixirCollector) || target.TargetBuilding.GetType() == typeof(ElixirStorage)) { color = Color.Violet; } if (target.TargetBuilding.GetType() == typeof(GoldMine) || target.TargetBuilding.GetType() == typeof(GoldStorage)) { color = Color.Gold; } if (target.TargetBuilding.GetType() == typeof(DarkElixirDrill) || target.TargetBuilding.GetType() == typeof(DarkElixirStorage)) { color = Color.Brown; } //Draw a target on each building. Visualize.Target(canvas, target.TargetBuilding.Location.GetCenter(), 40, color); Visualize.Target(canvas, target.DeployGrunts, 20, color); Visualize.Target(canvas, target.DeployRanged, 20, color); } //Save the Image to the Debug Folder... Screenshot.Save(canvas, $"{debugFileName}_3"); } Log.Debug("[Berts Algorithms] Collector/Storage & Target Debug Images Saved!"); } Log.Debug($"[Berts Algorithms] Found {targetList.Count} deploy points"); return(targetList.ToArray()); }