public HarvestOrder CreateHarvestOrder(int PlanetID, int BuildingID) { IInsert query; HarvestOrder item; object result; LogEnter(); item = new HarvestOrder() { PlanetID = PlanetID, BuildingID = BuildingID }; Log(LogLevels.Information, $"Inserting into Order table ()"); query = new Insert().Into(BotsDB.OrderTable) .Set(OrderTable.BotID, item.BotID); result = Try(query).OrThrow <PIODataException>("Failed to insert"); item.OrderID = Convert.ToInt32(result); Log(LogLevels.Information, $"Inserting into HarvestOrder table (OrderID={item.OrderID},PlanetID={item.PlanetID}, BuildingID={BuildingID})"); query = new Insert().Into(BotsDB.HarvestOrderTable) .Set(HarvestOrderTable.OrderID, item.OrderID) .Set(HarvestOrderTable.PlanetID, item.PlanetID) .Set(HarvestOrderTable.BuildingID, item.BuildingID); result = Try(query).OrThrow <PIODataException>("Failed to insert"); item.HarvestOrderID = Convert.ToInt32(result); return(item); }
public Task CreateTaskFromHarvestOrder(Worker Worker, HarvestOrder HarvestOrder) { bool result; Building building; Task task; building = AssertExists <Building>(() => client.GetBuilding(HarvestOrder.BuildingID), $"BuildingID={HarvestOrder.BuildingID}"); Log(LogLevels.Information, $"Checking if worker is on site (WorkerID={Worker.WorkerID}, BuildingID={HarvestOrder.BuildingID})"); result = Try(() => client.WorkerIsInBuilding(Worker.WorkerID, building.BuildingID)).OrThrow <PIOInternalErrorException>("Failed to check worker location"); if (result) { Log(LogLevels.Information, $"Worker is on site, creating harvest task"); task = Try(() => client.Harvest(Worker.WorkerID)).OrThrow <PIOInternalErrorException>("Failed to create task"); } else { Log(LogLevels.Information, $"Worker is not on site, creating moveto task"); task = Try(() => client.MoveToBuilding(Worker.WorkerID, building.BuildingID)).OrThrow <PIOInternalErrorException>("Failed to create task"); } return(task); }