/// <summary> /// This method is called automatically when your ship lands on a planet. /// You can use this method to purchase commodities, equip your ship and launch it towards another star system. /// All you have to do is implement this method and the ShipFlying() method - you don't /// need to touch the other files in the solution. /// /// Don't forget: post any issues you have on the forum! {FORUM URL HERE} /// The starmap and all other information can be found on: {GAME URL HERE} /// </summary> public static async Task ShipLandedAsync(Guid currentShip) { //Get the status of our ship var ship = await NavigationComputer.GetSpaceshipStatusAsync(); //Get our current star var currentStar = await NavigationComputer.GetCurrentStarAsync(); //Get the stars we can see var stars = await NavigationComputer.GetVisibleStarsAsync(); //Please note that you can own multiple ships. You can differentiate between ships using the //currentShip parameter and provide separate logic for each ship. This is not checked in this example, //so all ships behave in the same way after landing. See more details in the ShipFlying() method at the //bottom! //If we can, buy a larger ship model! //This costs a lot of credits, but increases storage space. if (ship.Money > 1100000 && ship.TotalCapacity == 100) { await NavigationComputer.UpgradeShipCapacityTo200Async(); } else if (ship.Money > 11000000 && ship.TotalCapacity == 200) { await NavigationComputer.UpgradeShipCapacityTo300Async(); } /*if (ship.TotalCapacity == 200 && ship.CannonCount < 1) * { * await NavigationComputer.AddCannonAsync(); * } * else if (ship.TotalCapacity == 300 && ship.CannonCount < 2) * { * await NavigationComputer.AddCannonAsync(); * }*/ if (ship.TotalCapacity == 200 && ship.DriveCount < 2) { await NavigationComputer.AddDriveAsync(); } else if (ship.TotalCapacity == 300 && ship.DriveCount < 4) { await NavigationComputer.AddDriveAsync(); } if (ship.TotalCapacity == 200 && ship.SensorCount < 2) { await NavigationComputer.AddSensorAsync(); ship = await NavigationComputer.GetSpaceshipStatusAsync(); stars = await NavigationComputer.GetVisibleStarsAsync(); } else if (ship.TotalCapacity == 100 && ship.SensorCount < 1) { await NavigationComputer.AddSensorAsync(); ship = await NavigationComputer.GetSpaceshipStatusAsync(); stars = await NavigationComputer.GetVisibleStarsAsync(); } //Sell everything we've brought. foreach (var cargoItem in ship.Cargo) { //These method calls do not throw exceptions, to avoid disrupting program flow. //Instead they return any error as a string. await NavigationComputer.SellAsync(cargoItem.Name, cargoItem.Stock); } //Let's trade water! //Check if any of the nearby stars have a higher price level for water than this star system. //If we find such a star we can make a profit by buying water here and selling it there. /* int localPrice = currentStar.Commodities.Min(i => i.Price); * var stuffToBuy = currentStar.Commodities.Where(i => i.Price == localPrice).ToList()[0].Name; * int maxPrice = stars.Max(i => i.Commodities.Single(j => j.Name == stuffToBuy).Price); * */ var target = await TradeHelper.GetPriceDiff(currentStar, stars); if (target != null) { await NavigationComputer.BuyMaximumAsync(target.Item1); if (await TradeHelper.AvailableCargoSpace() > await TradeHelper.UsedCargoSpace()) { try { var item = await TradeHelper.GetSecondMaxDiff(currentStar, target.Item2); if (item != null) { await NavigationComputer.BuyMaximumAsync(item.Item1.ProductName); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.StackTrace); } } await NavigationComputer.LaunchSpaceshipAsync(target.Item2); } else { var rnd = new Random((int)DateTime.Now.Ticks); var randomStar = stars[rnd.Next(0, stars.Length)]; await NavigationComputer.LaunchSpaceshipAsync(randomStar); } //Profit can be made by trading water - buy as much as we can, and go to that star! /*if (maxPrice > localPrice) * { * await NavigationComputer.BuyMaximumAsync(stuffToBuy); * var targetStar = stars.First(i => i.Commodities.Single(j => j.Name == stuffToBuy).Price == maxPrice); * await NavigationComputer.LaunchSpaceshipAsync(targetStar); * } */ }
/// <summary> /// This method is called automatically when your ship lands on a planet. /// You can use this method to purchase commodities, equip your ship and launch it towards another star system. /// All you have to do is implement this method and the ShipFlying() method - you don't /// need to touch the other files in the solution. /// /// Don't forget: post any issues you have on the forum! {FORUM URL HERE} /// The starmap and all other information can be found on: {GAME URL HERE} /// </summary> public static async Task ShipLandedAsync(Guid currentShip) { //Get the status of our ship var ship = await NavigationComputer.GetSpaceshipStatusAsync(); //Get our current star var currentStar = await NavigationComputer.GetCurrentStarAsync(); //Get the stars we can see var stars = await NavigationComputer.GetVisibleStarsAsync(); //Please note that you can own multiple ships. You can differentiate between ships using the //currentShip parameter and provide separate logic for each ship. This is not checked in this example, //so all ships behave in the same way after landing. See more details in the ShipFlying() method at the //bottom! //If we can, buy a larger ship model! //This costs a lot of credits, but increases storage space. if (ship.Money > 1000000 && ship.TotalCapacity == 100) { await NavigationComputer.UpgradeShipCapacityTo200Async(); } //If the ship has no extra sensor yet, then purchase one, to see further. //(This increases sensor range to 70 light years from 50 light years, but decreases available //cargo space from 100 to 80 units - this is probably worth it.) if (ship.SensorCount == 0) { //These method calls do not throw exceptions, to avoid disrupting program flow. //Instead they return any error as a string. await NavigationComputer.AddSensorAsync(); //Refresh ship status and visible stars right away (we'll quite possible see more stars, since //our sensor range has increased). ship = await NavigationComputer.GetSpaceshipStatusAsync(); stars = await NavigationComputer.GetVisibleStarsAsync(); //You can use the same logic to add or remove drives, sensors, cannons and shields. } //Sell everything we've brought. foreach (var cargoItem in ship.Cargo) { //These method calls do not throw exceptions, to avoid disrupting program flow. //Instead they return any error as a string. await NavigationComputer.SellAsync(cargoItem.Name, cargoItem.Stock); } //Let's trade water! //Check if any of the nearby stars have a higher price level for water than this star system. //If we find such a star we can make a profit by buying water here and selling it there. int localPrice = currentStar.Commodities.Single(i => i.Name == "Water").Price; int maxPrice = stars.Max(i => i.Commodities.Single(j => j.Name == "Water").Price); //Profit can be made by trading water - buy as much as we can, and go to that star! if (maxPrice > localPrice) { await NavigationComputer.BuyMaximumAsync("Water"); var targetStar = stars.First(i => i.Commodities.Single(j => j.Name == "Water").Price == maxPrice); await NavigationComputer.LaunchSpaceshipAsync(targetStar); } //There is no trade opportunity in water - go to a random star and hope for better luck. else { var rnd = new Random((int)DateTime.Now.Ticks); var randomStar = stars[rnd.Next(0, stars.Length)]; await NavigationComputer.LaunchSpaceshipAsync(randomStar); } }