public void PlaceBuildable(Buildables type) { //TODO rework data storing, add buildings to colony when placing etc resourcesHandler = sceneHandler.currentColony.GetComponent <ResourcesHandler>(); switch (type) { case Buildables.PowerPlant: objectBeingPlaced = Instantiate(Prefabs.Instance.powerPlant); break; case Buildables.Mine: objectBeingPlaced = Instantiate(Prefabs.Instance.mine); break; case Buildables.ResearchLab: objectBeingPlaced = Instantiate(Prefabs.Instance.researchLab); break; default: break; } objectBeingPlaced.transform.SetParent(sceneHandler.currentColony.transform); objectBeingPlaced.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 0.5f); CheckResources(); placingObject = true; }
public void SetAmount(Buildables buildable, long number) { foreach (PropertyInfo prop in this.GetType().GetProperties()) { if (prop.Name == buildable.ToString()) { prop.SetValue(this, number); return; } } }
public long GetAmount(Buildables buildable) { foreach (PropertyInfo prop in this.GetType().GetProperties()) { if (prop.Name == buildable.ToString()) { return((long)prop.GetValue(this)); } } return(0); }
public Ships Add(Buildables buildable, long quantity) { foreach (PropertyInfo prop in this.GetType().GetProperties()) { if (prop.Name == buildable.ToString()) { prop.SetValue(this, (long)prop.GetValue(this) + quantity); } } return(this); }
public int GetLevel(Buildables research) { int output = 0; foreach (PropertyInfo prop in GetType().GetProperties()) { if (prop.Name == research.ToString()) { output = (int)prop.GetValue(this); } } return(output); }
public int GetAmount(Buildables defence) { int output = 0; foreach (PropertyInfo prop in GetType().GetProperties()) { if (prop.Name == defence.ToString()) { output = (int)prop.GetValue(this); } } return(output); }
public bool BuildTechnology(Celestial celestial, Buildables buildable) { try { var request = new RestRequest { Resource = $"/bot/planets/{celestial.ID}/build/technology/{(int) buildable}", Method = Method.POST }; var result = JsonConvert.DeserializeObject <OgamedResponse>(Client.Execute(request).Content); if (result.Status != "ok") { return(false); } else { return(true); } } catch { return(false); } }
public bool BuildConstruction(Celestial celestial, Buildables buildable) { var request = new RestRequest { Resource = "/bot/planets/" + celestial.ID + "/build/building/" + (int)buildable, Method = Method.POST, }; var result = JsonConvert.DeserializeObject <OgamedResponse>(Client.Execute(request).Content); if (result.Status != "ok") { throw new Exception("An error has occurred: Status: " + result.Status + " - Message: " + result.Message); } else { return(true); } }
public bool BuildDefences(Celestial celestial, Buildables buildable, long quantity) { try { var request = new RestRequest { Resource = $"/bot/planets/{celestial.ID}/build/defence/{(int) buildable}/{quantity}", Method = Method.POST, }; var result = JsonConvert.DeserializeObject <OgamedResponse>(Client.Execute(request).Content); if (result.Status != "ok") { return(false); } else { return(true); } } catch { return(false); } }
public Model.Resources GetPrice(Buildables buildable, int levelOrQuantity) { var request = new RestRequest { Resource = "/bot/price/" + (int)buildable + "/" + levelOrQuantity, Method = Method.GET, }; var result = JsonConvert.DeserializeObject <OgamedResponse>(Client.Execute(request).Content); if (result.Status != "ok") { throw new Exception("An error has occurred: Status: " + result.Status + " - Message: " + result.Message); } else { return(JsonConvert.DeserializeObject <Model.Resources>(JsonConvert.SerializeObject(result.Result))); } }
public Ships Remove(Buildables buildable, int quantity) { foreach (PropertyInfo prop in this.GetType().GetProperties()) { if (prop.Name == buildable.ToString()) { long val = (long)prop.GetValue(this); if (val >= quantity) { prop.SetValue(this, val); } else { prop.SetValue(this, 0); } } } return(this); }
public Model.Resources GetPrice(Buildables buildable, long levelOrQuantity) { var request = new RestRequest { Resource = $"/bot/price/{(int) buildable}/{levelOrQuantity}", Method = Method.GET, }; var result = JsonConvert.DeserializeObject <OgamedResponse>(Client.Execute(request).Content); if (result.Status != "ok") { throw new Exception($"An error has occurred: Status: {result.Status} - Message: {result.Message}"); } else { return(JsonConvert.DeserializeObject <Model.Resources>(JsonConvert.SerializeObject(result.Result), new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Local })); } }
public int GetLevel(Buildables building) { int output = 0; foreach (PropertyInfo prop in Buildings.GetType().GetProperties()) { if (prop.Name == building.ToString()) { output = (int)prop.GetValue(Buildings); } } if (output == 0) { foreach (PropertyInfo prop in Facilities.GetType().GetProperties()) { if (prop.Name == building.ToString()) { output = (int)prop.GetValue(Facilities); } } } return(output); }
private void AddBuilding(AbstractBuilding building) { Buildings.Add(building); Buildables.Add(building.Id, building); foreach (var capability in building.BuildCapabilities) { if (!BuildCapabilities.ContainsKey(capability.Key)) { BuildCapabilities.Add(capability.Key, capability.Value); } } foreach (var capability in building.TrainCapabilities) { if (!TrainCapabilities.ContainsKey(capability.Key)) { TrainCapabilities.Add(capability.Key, capability.Value); } } building.UnderConstructionEvent += Building_UnderConstructionEvent; building.StartBuilding(); }
private void AddUnit(AbstractUnit unit) { Units.Add(unit); Buildables.Add(unit.Id, unit); }
private static void AutoBuildCargo(object state) { Helpers.WriteLog(LogType.Info, LogSender.Brain, "Checking capacity..."); celestials = UpdatePlanets(UpdateType.Ships); celestials = UpdatePlanets(UpdateType.Resources); celestials = UpdatePlanets(UpdateType.Productions); foreach (Celestial planet in celestials) { var capacity = Helpers.CalcFleetCapacity(planet.Ships, researches.HyperspaceTechnology, userInfo.Class); Helpers.WriteLog(LogType.Info, LogSender.Brain, "Planet " + planet.ToString() + ": Available capacity: " + capacity.ToString("N0") + " - Resources: " + planet.Resources.TotalResources.ToString("N0")); if (planet.Coordinate.Type == Celestials.Moon && settings.Brain.AutoCargo.ExcludeMoons) { Helpers.WriteLog(LogType.Info, LogSender.Brain, "Skipping moon."); continue; } if (capacity <= planet.Resources.TotalResources) { long difference = planet.Resources.TotalResources - capacity; Buildables preferredCargoShip = Enum.Parse <Buildables>(settings.Brain.AutoCargo.CargoType.ToString() ?? "SmallCargo") ?? Buildables.SmallCargo; int oneShipCapacity = Helpers.CalcShipCapacity(preferredCargoShip, researches.HyperspaceTechnology, userInfo.Class); int neededCargos = (int)Math.Round((float)difference / (float)oneShipCapacity, MidpointRounding.ToPositiveInfinity); Helpers.WriteLog(LogType.Info, LogSender.Brain, difference.ToString("N0") + " more capacity is needed, " + neededCargos + " more " + preferredCargoShip.ToString() + " are needed."); if (planet.HasProduction()) { Helpers.WriteLog(LogType.Warning, LogSender.Brain, "There is already a production ongoing. Skipping planet."); foreach (Production production in planet.Productions) { Buildables productionType = (Buildables)production.ID; Helpers.WriteLog(LogType.Info, LogSender.Brain, production.Nbr + "x" + productionType.ToString() + " are in production."); } continue; } var cost = ogamedService.GetPrice(preferredCargoShip, neededCargos); if (planet.Resources.IsEnoughFor(cost)) { Helpers.WriteLog(LogType.Info, LogSender.Brain, "Building " + neededCargos + "x" + preferredCargoShip.ToString()); ogamedService.BuildShips(planet, preferredCargoShip, neededCargos); } else { Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Not enough resources to build " + neededCargos + "x" + preferredCargoShip.ToString()); ogamedService.BuildShips(planet, Buildables.SmallCargo, neededCargos); } planet.Productions = ogamedService.GetProductions(planet); foreach (Production production in planet.Productions) { Buildables productionType = (Buildables)production.ID; Helpers.WriteLog(LogType.Info, LogSender.Brain, production.Nbr + "x" + productionType.ToString() + " are in production."); } } else { Helpers.WriteLog(LogType.Info, LogSender.Brain, "Capacity is ok."); } } var time = ogamedService.GetServerTime(); var interval = Helpers.CalcRandomInterval((int)settings.Brain.AutoCargo.CheckIntervalMin, (int)settings.Brain.AutoCargo.CheckIntervalMax); var newTime = time.AddMilliseconds(interval); capacityTimer.Change(interval, Timeout.Infinite); Helpers.WriteLog(LogType.Info, LogSender.Brain, "Next capacity check at " + newTime.ToString()); }
private static void AutoRepatriate(object state) { Helpers.WriteLog(LogType.Info, LogSender.Brain, "Reaptriating resources..."); celestials = UpdatePlanets(UpdateType.Resources); celestials = UpdatePlanets(UpdateType.Ships); var rand = new Random(); foreach (Celestial celestial in settings.Brain.AutoRepatriate.RandomOrder ? celestials.OrderBy(celestial => rand.Next()).ToList() : celestials) { if (celestial.Coordinate.Type == Celestials.Moon && settings.Brain.AutoRepatriate.ExcludeMoons) { Helpers.WriteLog(LogType.Info, LogSender.Brain, "Skipping moon."); continue; } if (celestial.Resources.TotalResources < (int)settings.Brain.AutoRepatriate.MinimumResources) { Helpers.WriteLog(LogType.Info, LogSender.Brain, "Skipping celestial: resources under set limit"); continue; } Buildables preferredShip = Enum.Parse <Buildables>(settings.Brain.AutoRepatriate.CargoType.ToString() ?? "SmallCargo") ?? Buildables.SmallCargo; int idealShips = Helpers.CalcShipNumberForPayload(celestial.Resources, preferredShip, researches.HyperspaceTechnology, userInfo.Class); Ships ships = new Ships(); if (idealShips <= celestial.Ships.GetAmount(preferredShip)) { ships.Add(preferredShip, idealShips); } else { ships.Add(preferredShip, celestial.Ships.GetAmount(preferredShip)); } Resources payload = Helpers.CalcMaxTransportableResources(ships, celestial.Resources, researches.HyperspaceTechnology, userInfo.Class); Celestial destination = celestials .OrderBy(planet => planet.Coordinate.Type == Celestials.Moon) .OrderByDescending(planet => Helpers.CalcFleetCapacity(planet.Ships, researches.HyperspaceTechnology, userInfo.Class)) .First(); if (settings.Brain.AutoRepatriate.Target) { try { Celestial customDestination = celestials .Where(planet => planet.Coordinate.Galaxy == (int)settings.Brain.AutoRepatriate.Target.Galaxy) .Where(planet => planet.Coordinate.System == (int)settings.Brain.AutoRepatriate.Target.System) .Where(planet => planet.Coordinate.Position == (int)settings.Brain.AutoRepatriate.Target.Position) .Where(planet => planet.Coordinate.Type == Enum.Parse <Celestials>(settings.Brain.AutoRepatriate.Target.Type.ToString())) .Single(); destination = customDestination; if (celestial.ID == customDestination.ID) { Helpers.WriteLog(LogType.Info, LogSender.Brain, "Skipping celestial: this celestial is the destination"); continue; } } catch (Exception e) { Helpers.WriteLog(LogType.Debug, LogSender.Brain, "Exception: " + e.Message); Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Unable to parse custom destination"); } } SendFleet(celestial, ships, destination.Coordinate, Missions.Transport, Speeds.HundredPercent, payload); } var time = ogamedService.GetServerTime(); var interval = Helpers.CalcRandomInterval((int)settings.Brain.AutoRepatriate.CheckIntervalMin, (int)settings.Brain.AutoRepatriate.CheckIntervalMax); var newTime = time.AddMilliseconds(interval); repatriateTimer.Change(interval, Timeout.Infinite); Helpers.WriteLog(LogType.Info, LogSender.Brain, "Next repatriate check at " + newTime.ToString()); }
private static void HandleExpeditions(object state) { celestials = UpdatePlanets(UpdateType.Ships); if ((bool)settings.Expeditions.AutoSendExpeditions.Active) { UpdateSlots(); UpdateFleets(); int expsToSend; if (settings.Expeditions.AutoSendExpeditions.WaitForAllExpeditions) { if (slots.ExpInUse == 0) { expsToSend = slots.ExpTotal; } else { expsToSend = 0; } } else { expsToSend = Math.Min(slots.ExpFree, slots.Free); } if (expsToSend > 0) { if (slots.ExpFree > 0) { if (slots.Free > 0) { Celestial origin = celestials .OrderBy(planet => planet.Coordinate.Type == Celestials.Moon) .OrderByDescending(planet => Helpers.CalcFleetCapacity(planet.Ships, researches.HyperspaceTechnology, userInfo.Class)) .First(); if (settings.Expeditions.AutoSendExpeditions.Origin) { try { Celestial customOrigin = celestials .Where(planet => planet.Coordinate.Galaxy == (int)settings.Expeditions.AutoSendExpeditions.Origin.Galaxy) .Where(planet => planet.Coordinate.System == (int)settings.Expeditions.AutoSendExpeditions.Origin.System) .Where(planet => planet.Coordinate.Position == (int)settings.Expeditions.AutoSendExpeditions.Origin.Position) .Where(planet => planet.Coordinate.Type == Enum.Parse <Celestials>(settings.Expeditions.AutoSendExpeditions.Origin.Type.ToString())) .Single(); origin = customOrigin; } catch (Exception e) { Helpers.WriteLog(LogType.Debug, LogSender.Expeditions, "Exception: " + e.Message); Helpers.WriteLog(LogType.Warning, LogSender.Expeditions, "Unable to parse custom origin"); } } if (origin.Ships.IsEmpty()) { Helpers.WriteLog(LogType.Warning, LogSender.Expeditions, "Unable to send expeditions: no ships available"); } else { Buildables mainShip = Enum.Parse <Buildables>(settings.Expeditions.AutoSendExpeditions.MainShip.ToString() ?? "LargeCargo") ?? Buildables.LargeCargo; Ships fleet = Helpers.CalcFullExpeditionShips(origin.Ships, mainShip, expsToSend, serverData, researches, userInfo.Class); Helpers.WriteLog(LogType.Info, LogSender.Expeditions, expsToSend.ToString() + " expeditions with " + fleet.ToString() + " will be sent from " + origin.ToString()); for (int i = 0; i < expsToSend; i++) { Coordinate destination; if (settings.Expeditions.AutoSendExpeditions.SplitExpeditionsBetweenSystems) { var rand = new Random(); destination = new Coordinate { Galaxy = origin.Coordinate.Galaxy, System = rand.Next(origin.Coordinate.System - 1, origin.Coordinate.System + 2), Position = 16, Type = Celestials.DeepSpace }; } else { destination = new Coordinate { Galaxy = origin.Coordinate.Galaxy, System = origin.Coordinate.System, Position = 16, Type = Celestials.DeepSpace }; } SendFleet(origin, fleet, destination, Missions.Expedition, Speeds.HundredPercent); } } } else { Helpers.WriteLog(LogType.Warning, LogSender.Expeditions, "Unable to send expeditions: no fleet slots available"); } } else { Helpers.WriteLog(LogType.Warning, LogSender.Expeditions, "Unable to send expeditions: no expeditions slots available"); } } UpdateSlots(); UpdateFleets(); var time = ogamedService.GetServerTime(); List <Fleet> orderedFleets = fleets .Where(fleet => fleet.Mission == Missions.Expedition) .OrderByDescending(fleet => fleet.BackIn) .ToList(); int interval; if (orderedFleets.Count == 0) { interval = Helpers.CalcRandomInterval(IntervalType.AboutHalfAnHour); } else { interval = (int)((1000 * orderedFleets.First().BackIn) + Helpers.CalcRandomInterval(IntervalType.AMinuteOrTwo)); } DateTime newTime = time.AddMilliseconds(interval); expeditionsTimer.Change(interval, Timeout.Infinite); Helpers.WriteLog(LogType.Info, LogSender.Expeditions, "Next check at " + newTime.ToString()); } if ((bool)settings.Expeditions.AutoHarvest.Active) { UpdateSlots(); UpdateFleets(); Celestial origin = celestials .OrderBy(planet => planet.Coordinate.Type == Celestials.Moon) .OrderByDescending(planet => Helpers.CalcFleetCapacity(planet.Ships, researches.HyperspaceTechnology, userInfo.Class)) .First(); if (settings.Expeditions.AutoSendExpeditions.Origin) { try { Celestial customOrigin = celestials .Where(planet => planet.Coordinate.Galaxy == (int)settings.Expeditions.AutoSendExpeditions.Origin.Galaxy) .Where(planet => planet.Coordinate.System == (int)settings.Expeditions.AutoSendExpeditions.Origin.System) .Where(planet => planet.Coordinate.Position == (int)settings.Expeditions.AutoSendExpeditions.Origin.Position) .Where(planet => planet.Coordinate.Type == Enum.Parse <Celestials>(settings.Expeditions.AutoSendExpeditions.Origin.Type.ToString())) .Single(); origin = customOrigin; } catch (Exception e) { Helpers.WriteLog(LogType.Debug, LogSender.Expeditions, "Exception: " + e.Message); Helpers.WriteLog(LogType.Warning, LogSender.Expeditions, "Unable to parse custom origin"); } } List <Coordinate> destinations = new List <Coordinate>(); if (settings.Expeditions.AutoSendExpeditions.SplitExpeditionsBetweenSystems) { var rand = new Random(); for (int i = origin.Coordinate.System - 1; i < origin.Coordinate.System + 2; i++) { destinations.Add(new Coordinate { Galaxy = origin.Coordinate.Galaxy, System = rand.Next(i, i + 1), Position = 16, Type = Celestials.DeepSpace }); } } else { destinations.Add(new Coordinate { Galaxy = origin.Coordinate.Galaxy, System = origin.Coordinate.System, Position = 16, Type = Celestials.DeepSpace }); } foreach (Coordinate destination in destinations) { var galaxyInfos = ogamedService.GetGalaxyInfo(destination); if (galaxyInfos.ExpeditionDebris.Resources.TotalResources > 0) { Helpers.WriteLog(LogType.Info, LogSender.Expeditions, "Debris detected at " + destination.ToString()); if (galaxyInfos.ExpeditionDebris.Resources.TotalResources >= settings.Expeditions.AutoHarvest.MinimumResources) { int pathfindersToSend = Helpers.CalcShipNumberForPayload(galaxyInfos.ExpeditionDebris.Resources, Buildables.Pathfinder, researches.HyperspaceTechnology, userInfo.Class); SendFleet(origin, new Ships { Pathfinder = pathfindersToSend }, destination, Missions.Harvest, Speeds.HundredPercent); } else { Helpers.WriteLog(LogType.Info, LogSender.Expeditions, "Skipping hervest: resources under set limit."); } } } } }