fixed overflow with modifier prices

This commit is contained in:
Ellpeck 2020-06-12 17:32:50 +02:00
parent ede5fa2b58
commit cf8fcab88c
2 changed files with 7 additions and 6 deletions

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Numerics;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
@ -78,9 +79,9 @@ namespace TouchyTickets.Attractions {
return this.Modifiers.Where(m => modifier == null || m.Modifier == modifier).Sum(m => m.Amount); return this.Modifiers.Where(m => modifier == null || m.Modifier == modifier).Sum(m => m.Amount);
} }
public int GetModifierPrice(AttractionModifier modifier) { public long GetModifierPrice(AttractionModifier modifier) {
var amount = this.GetModifierAmount(modifier); var amount = this.GetModifierAmount(modifier);
return (modifier.InitialPrice * (float) Math.Pow(1 + 0.4F, amount)).Ceil(); return (long) Math.Ceiling(modifier.InitialPrice * Math.Pow(1 + 0.4F, amount));
} }
private IEnumerable<Attraction> GetSurrounding(ParkMap map, Point position, AttractionType type) { private IEnumerable<Attraction> GetSurrounding(ParkMap map, Point position, AttractionType type) {

View file

@ -153,7 +153,7 @@ namespace TouchyTickets {
IsHidden = true IsHidden = true
}; };
foreach (var attraction in AttractionType.Attractions) { foreach (var attraction in AttractionType.Attractions) {
BigInteger price = 0; long price = 0;
var attractionAmount = 0; var attractionAmount = 0;
var button = buyUi.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 40)) { var button = buyUi.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 40)) {
ChildPadding = new Vector2(4), ChildPadding = new Vector2(4),
@ -174,7 +174,7 @@ namespace TouchyTickets {
yesNoUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 30), Localization.Get("Place")) { yesNoUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 30), Localization.Get("Place")) {
OnPressed = e2 => { OnPressed = e2 => {
GameImpl.Instance.Tickets -= price; GameImpl.Instance.Tickets -= price;
GameImpl.Instance.Analytics.AddResourceEvent(true, "Tickets", (long) price, "Attraction", attraction.Key); GameImpl.Instance.Analytics.AddResourceEvent(true, "Tickets", price, "Attraction", attraction.Key);
map.Place(map.PlacingPosition, map.PlacingAttraction); map.Place(map.PlacingPosition, map.PlacingAttraction);
this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name)); this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name));
@ -190,7 +190,7 @@ namespace TouchyTickets {
// only update the price when the area updates, since it won't change while we're in the buy ui // only update the price when the area updates, since it won't change while we're in the buy ui
attractionAmount = GameImpl.Instance.Map.GetAttractionAmount(attraction.Value); attractionAmount = GameImpl.Instance.Map.GetAttractionAmount(attraction.Value);
// yay compound interest // yay compound interest
price = (attraction.Value.InitialPrice * (float) Math.Pow(1 + 0.1F, attractionAmount)).Ceil(); price = (long) Math.Ceiling(attraction.Value.InitialPrice * Math.Pow(1 + 0.1F, attractionAmount));
} }
}); });
var image = button.AddChild(new Image(Anchor.CenterLeft, new Vector2(0.2F, 40), attraction.Value.TextureRegion) { var image = button.AddChild(new Image(Anchor.CenterLeft, new Vector2(0.2F, 40), attraction.Value.TextureRegion) {
@ -306,7 +306,7 @@ namespace TouchyTickets {
var game = GameImpl.Instance; var game = GameImpl.Instance;
game.Analytics.AddResourceEvent(true, "Tickets", (long) game.Tickets, "Restart", "Restart" + game.TimesRestarted); game.Analytics.AddResourceEvent(true, "Tickets", (long) game.Tickets, "Restart", "Restart" + game.TimesRestarted);
game.Analytics.AddResourceEvent(false, "Stars", (long) game.Tickets, "Restart", "Restart" + game.TimesRestarted); game.Analytics.AddResourceEvent(false, "Stars", game.GetBuyableStars(), "Restart", "Restart" + game.TimesRestarted);
game.Stars += game.GetBuyableStars(); game.Stars += game.GetBuyableStars();
game.TimesRestarted++; game.TimesRestarted++;