public static PlanetDetail AddResearchQueue(BuildingQue buildingQue) { PlanetDetail pl = PlanetDAL.GetPlanet(buildingQue.PlanetID, buildingQue.UserID); AllbuildQues BuildingsQueLeft = PlanetBLL.GetBuildingQueue(buildingQue.PlanetID, buildingQue.UserID); DateTime UTC = DateTime.UtcNow; BuildingQue bq = new BuildingQue(); bq.BuildingID = buildingQue.BuildingID; bq.PlanetID = buildingQue.PlanetID; bq.Seconds = buildingQue.Seconds; bq.UserID = buildingQue.UserID; bq.MaterialCost = 0; bq.Type = 2; DateTime?maxCompletetionDate = BuildingsQueLeft.researchQue.FindAll(x => x.Type == 2).Max(x => x.CompletetionDate); if (maxCompletetionDate.HasValue) { bq.CompletetionDate = maxCompletetionDate.Value.AddSeconds(buildingQue.Seconds.Value); } else { bq.CompletetionDate = UTC.AddSeconds(buildingQue.Seconds.Value); } PlanetDAL.AddBuildingQue(bq); return(pl); }
public IHttpActionResult GetPlanet(int PlanetID, int UserID) { try { return(Ok(PlanetDAL.GetPlanet(PlanetID, UserID))); } catch (Exception e) { return(InternalServerError(e)); } }
public static PlanetDetail UpdatePlanetHarvest(PlanetDetail planet) { PlanetDetail pl = PlanetDAL.GetPlanet(planet.PlanetID, planet.Owner); if (pl.LastHarvest.HasValue && pl.LastHarvest.Value <= DateTime.UtcNow) { pl.LastHarvest = PlanetDAL.UpdatePlanetHarvest(planet); pl.Materials += planet.Materials; pl.Population += planet.Population; pl.Military += planet.Military; } else { throw new Exception("Not time to harvest."); } return(pl); }
public static PlanetDetail AddShipQueue(BuildingQue buildingQue) { PlanetDetail pl = PlanetDAL.GetPlanet(buildingQue.PlanetID, buildingQue.UserID); UserDesigns ship = ShipDAL.GetShipDesignbyUser(buildingQue.UserID).Find(x => x.ShipDesignID == buildingQue.BuildingID); if (pl.Materials < ship.MaterialCost || pl.Military < ship.MilitaryCost) { throw new Exception("Not enough resources"); } else { PlanetDAL.UpdatePopAndMats(buildingQue.PlanetID, pl.Materials - buildingQue.MaterialCost, pl.Population, pl.Military - (int)ship.MilitaryCost.Value); pl.Materials -= buildingQue.MaterialCost; pl.Military -= (int)ship.MilitaryCost.Value; } AllbuildQues BuildingsQueLeft = PlanetBLL.GetBuildingQueue(buildingQue.PlanetID, buildingQue.UserID); DateTime UTC = DateTime.UtcNow; BuildingQue bq = new BuildingQue(); bq.BuildingID = buildingQue.BuildingID; bq.PlanetID = buildingQue.PlanetID; bq.Seconds = buildingQue.Seconds; bq.UserID = buildingQue.UserID; bq.MaterialCost = buildingQue.MaterialCost; bq.Movement = buildingQue.Movement; bq.Type = 3; DateTime?maxCompletetionDate = BuildingsQueLeft.shipQue.FindAll(x => x.Type == 3).Max(x => x.CompletetionDate); if (maxCompletetionDate.HasValue) { bq.CompletetionDate = maxCompletetionDate.Value.AddSeconds(buildingQue.Seconds.Value); } else { bq.CompletetionDate = UTC.AddSeconds(buildingQue.Seconds.Value); } PlanetDAL.AddBuildingQue(bq); return(pl); }
public static PlanetDetail AddBuildingQueue(BuildingQue buildingQue) { List <PlanetBuildings> buildings = PlanetDAL.GetBuildingTypes(buildingQue.PlanetID); PlanetBuildings pb = buildings.Find(x => x.BuildingID == buildingQue.BuildingID); PlanetDetail pl = PlanetDAL.GetPlanet(buildingQue.PlanetID, buildingQue.UserID); if (pl.Materials < buildingQue.MaterialCost || pl.Population < pb.PopulationCost) { throw new Exception("Not enough resources"); } else { PlanetDAL.UpdatePopAndMats(buildingQue.PlanetID, pl.Materials - buildingQue.MaterialCost, pl.Population - (int)pb.PopulationCost.Value, pl.Military); pl.Materials -= buildingQue.MaterialCost; pl.Population -= (int)pb.PopulationCost.Value; } AllbuildQues BuildingsQueLeft = GetBuildingQueue(buildingQue.PlanetID, buildingQue.UserID); DateTime UTC = DateTime.UtcNow; BuildingQue bq = new BuildingQue(); bq.BuildingID = buildingQue.BuildingID; bq.PlanetID = buildingQue.PlanetID; bq.Seconds = buildingQue.Seconds; bq.UserID = buildingQue.UserID; bq.MaterialCost = buildingQue.MaterialCost; bq.Type = 1; DateTime?maxCompletetionDate = BuildingsQueLeft.buildingQue.FindAll(x => x.Type == 1).Max(x => x.CompletetionDate); if (maxCompletetionDate.HasValue) { bq.CompletetionDate = maxCompletetionDate.Value.AddSeconds(buildingQue.Seconds.Value); } else { bq.CompletetionDate = UTC.AddSeconds(buildingQue.Seconds.Value); } PlanetDAL.AddBuildingQue(bq); return(pl); }