public float CalculateMaxCompanyPrice(SurveyObject obj) { //no interest in that atmosphere? return empty price. if (!AtmosphereRating.ContainsKey(obj.Atmosphere)) { return(0); } if (MinTimeToDevelop > LastWon) { return(0); } float price = 0; if (AtmosphereRating.ContainsKey(obj.Atmosphere)) { price += AtmosphereRating[obj.Atmosphere].Price; } foreach (var resource in obj.Resources) { if (ResourceRatings.ContainsKey(resource.Name)) { price += ResourceRatings[resource.Name].Price * resource.Amount; } } price *= (obj.Size * SizeModifier); return(price); }
/// <summary> /// Start an auction. /// </summary> /// <param name="obj"></param> public void AuctionObject(SurveyObject obj) { if (!string.IsNullOrWhiteSpace(obj.Owner)) { return; } Player.Money -= AuctionCost; MessageWindow.Show($"-{AuctionCost} to claim and start auction"); obj.Owner = "Auction"; StartCoroutine(Auction(obj)); }
IEnumerator Auction(SurveyObject obj) { float currentPrice = 100; List <CompanyMaxBid> maxBids = new List <CompanyMaxBid>(); foreach (var comp in Companies.Values) { maxBids.Add(new CompanyMaxBid() { name = comp.Name, maxPrice = comp.CalculateMaxCompanyPrice(obj) }); } maxBids = maxBids.Where(x => x.maxPrice > currentPrice).ToList(); //no one wanted it; bid fails. if (maxBids.Count < 1) { MessageWindow.Show($"Auction for {obj.Name} has failed!"); //fail the auction. obj.Owner = ""; yield break; } CompanyMaxBid currentWinner; do { currentWinner = maxBids[0]; currentPrice += 100; maxBids = maxBids.Where(x => x.maxPrice > currentPrice).ToList(); yield return(null); } while (maxBids.Count > 1); yield return(null); MessageWindow.Show($"{currentWinner.name} has won the auction for {obj.Name}"); obj.Owner = currentWinner.name; Companies[currentWinner.name].LastWon = 0; Player.Money += currentPrice; MessageWindow.Show($"Recieved {currentPrice} from auction"); }
SurveyObject GenerateObject(StarSystem starSystem) { var location = new Vector3(); do { location.x = Random.Range(-PlayingArea, PlayingArea); location.y = Random.Range(-PlayingArea, PlayingArea); } while (isTooClose(30, location, starSystem.Objects)); var obj = new SurveyObject() { StarSystem = starSystem.Name, Position = location, Name = $"{starSystem.Name} {(starSystem.Objects.Count + 1).ToRoman()}", Atmosphere = Atmospheres.RandomElement(), Image = "Base3", Color = new Color32(60, 1, 1, 255), SurveyDifficulty = Random.Range(0.5f, 1.5f), Size = Random.Range(1, 5), Type = "Planet", Resources = new List <Resource>(), SurveyProgress = 0f }; //add resources to a planet. for (int idx = 0; idx < Random.Range(-3, 10); idx++) { var resource = ResourceMananger.ResourceDefinitions.Values.RandomElement(); Resource res = obj.Resources.FirstOrDefault(x => x.Name == resource.Name); if (res == null) { res = new Resource() { Name = resource.Name, Amount = 0 }; obj.Resources.Add(res); } res.Amount++; } return(obj); }
/// <summary> /// Shows the survey in the survey review panel. /// </summary> /// <param name="survey"></param> public void ShowSurvey(SurveyObject survey) { GameController.Game.Pause = true; if (Text == null) { InitText(); } SurveyObject = survey; Text.text = $"System Survey Review: {Environment.NewLine}" + $"StarSystem: {survey.StarSystem} {Environment.NewLine}" + $"Name: {survey.Name} {Environment.NewLine}" + $"Type: {survey.Type} {Environment.NewLine}" + $"Atmosphere: {survey.Atmosphere} {Environment.NewLine}" + $"Size: {survey.Size} {Environment.NewLine}" + $"Owner: {survey.Owner} {Environment.NewLine}" + $"Resources: {Environment.NewLine}"; foreach (var res in survey.Resources) { Text.text += $" {res.Name}: {res.Amount} {Environment.NewLine}"; } }
public void LoadSurveyObject(SurveyObject surveyObject) { SurveyObject = surveyObject; var sprite = ContentManager.Inst.GetSprite(surveyObject.Image); if (sprite != null) { if (SpriteRenderer == null) { SpriteRenderer = GetComponent <SpriteRenderer>(); } SpriteRenderer.sprite = sprite; SpriteRenderer.color = surveyObject.Color; GetComponent <CircleCollider2D>().RescaleToSprite(); } else { Debug.Log($"Sprite {surveyObject.Name} not found"); } }