public static IEnumerable <StructureOption> GetMotherhipModuleBuildOption(string playerName, string password) { var db = new DbDataContext(); var player = db.GetPlayer(playerName, password); var structureOptions = new List <StructureOption>(); var noRoom = player.Level <= player.MothershipStructures.Sum(x => x.Count); foreach (var u in db.StructureTypes.Where(x => x.NeedsTechID == null || x.Tech.StarSystemTeches.Any(y => y.StarSystemID == player.SystemID))) { var option = new StructureOption() { StructureType = u }; if (noRoom) { option.CanBuild = BuildResponse.NotEnoughRoomOrBuildpower; } else if (u.CostMetal >= player.Metal) { option.CanBuild = BuildResponse.NotEnoughResources; } else { option.CanBuild = BuildResponse.Ok; } structureOptions.Add(option); } return(structureOptions); }
public static BodyResponse GetBodyOptions(string playerName, string password, int bodyID) { var db = new DbDataContext(); var player = db.GetPlayer(playerName, password); if (player == null) { throw new ApplicationException("Fail login"); } var body = player.CelestialObjects.Single(x => x.CelestialObjectID == bodyID); body.CelestialObjectStructures.Load(); body.CelestialObjectShips.Load(); var shipOptions = new List <ShipOption>(); foreach (var opt in db.ShipTypes.Where(x => x.NeedsTechID == null || x.Tech.StarSystemTeches.Any(y => y.StarSystemID == player.SystemID))) { var so = new ShipOption(); so.ShipType = opt; if (opt.MetalCost > player.Metal || opt.QuantiumCost > player.Quantium || opt.DarkMetalCost > player.DarkMatter) { so.CanBuild = BuildResponse.NotEnoughResources; } if (opt.MetalCost > body.Buildpower - body.BuildpowerUsed) { so.CanBuild = BuildResponse.NotEnoughRoomOrBuildpower; } shipOptions.Add(so); } var noRoom = body.Size <= body.CelestialObjectStructures.Sum(x => x.Count); var structureOptions = new List <StructureOption>(); foreach (var u in db.StructureTypes.Where(x => x.NeedsTechID == null || x.Tech.StarSystemTeches.Any(y => y.StarSystemID == player.SystemID))) { var option = new StructureOption() { StructureType = u }; if (noRoom) { option.CanBuild = BuildResponse.NotEnoughRoomOrBuildpower; } else if (u.CostMetal >= player.Metal) { option.CanBuild = BuildResponse.NotEnoughResources; } else { option.CanBuild = BuildResponse.Ok; } structureOptions.Add(option); } var ret = new BodyResponse() { Body = body, NewShipOptions = shipOptions, Player = player, Response = BuildResponse.Ok, NewStructureOptions = structureOptions }; return(ret); }