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 void SetAmount(Buildables buildable, long number) { foreach (PropertyInfo prop in this.GetType().GetProperties()) { if (prop.Name == buildable.ToString()) { prop.SetValue(this, number); return; } } }
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 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 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 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); }
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); }
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()); }