added price markup

This commit is contained in:
Ellpeck 2020-06-01 15:18:20 +02:00
parent ee1acca5e8
commit 6dd20359d8
3 changed files with 15 additions and 10 deletions

View file

@ -32,10 +32,6 @@ namespace ThemeParkClicker.Attractions {
}
}
public long GetPrice() {
return this.Type.InitialPrice;
}
public void Update(GameTime time, TimeSpan passed) {
this.ticketPercentage += this.Type.GenerationPerSecond * (float) passed.TotalSeconds;
var amount = this.ticketPercentage.Floor();

View file

@ -108,5 +108,9 @@ namespace ThemeParkClicker {
return null;
}
public int GetAttractionAmount(AttractionType type) {
return this.attractions.Count(a => a.Item2.Type == type);
}
}
}

View file

@ -108,7 +108,7 @@ namespace ThemeParkClicker {
IsHidden = true
};
foreach (var attraction in AttractionType.Attractions) {
var instance = attraction.Value.Create();
BigInteger price = 0;
var button = buyUi.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 40)) {
ChildPadding = new Vector2(4),
Padding = new Padding(0, 0, 0, 4),
@ -125,7 +125,7 @@ namespace ThemeParkClicker {
});
yesNoUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 40), "Place") {
OnPressed = e2 => {
GameImpl.Instance.Tickets -= map.PlacingAttraction.GetPrice();
GameImpl.Instance.Tickets -= price;
map.Place(map.PlacingPosition, map.PlacingAttraction);
this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name));
},
@ -135,19 +135,24 @@ namespace ThemeParkClicker {
this.uiSystem.Add("PlacingYesNo", yesNoUi).Priority = -100;
this.FadeUi(true);
},
OnAreaUpdated = e => {
// only update the price when the area updates, since it won't change while we're in the buy ui
var markup = GameImpl.Instance.Map.GetAttractionAmount(attraction.Value) * 0.05F;
price = (attraction.Value.InitialPrice * (1 + markup)).Ceil();
}
});
button.OnUpdated += (e, time) => {
button.IsDisabled = GameImpl.Instance.Tickets < instance.GetPrice();
button.IsDisabled = GameImpl.Instance.Tickets < price;
};
var center = button.AddChild(new Group(Anchor.Center, new Vector2(0.8F, 1), false) {CanBeMoused = false});
center.AddChild(new Paragraph(Anchor.AutoCenter, 1, attraction.Key, true));
center.AddChild(new Paragraph(Anchor.AutoCenter, 1, instance.Type.GenerationPerSecond + "<i ticket>/s", true) {TextScale = 0.08F});
var image = button.AddChild(new Image(Anchor.CenterLeft, new Vector2(1), instance.Type.TextureRegion) {
center.AddChild(new Paragraph(Anchor.AutoCenter, 1, attraction.Value.GenerationPerSecond + "<i ticket>/s", true) {TextScale = 0.08F});
var image = button.AddChild(new Image(Anchor.CenterLeft, new Vector2(1), attraction.Value.TextureRegion) {
Padding = new Vector2(4)
});
button.OnAreaUpdated += e => image.Size = new Vector2(e.DisplayArea.Height / e.Scale);
button.AddChild(new Paragraph(Anchor.CenterRight, 1, p => instance.GetPrice() + "<i ticket>", true));
button.AddChild(new Paragraph(Anchor.CenterRight, 1, p => price + "<i ticket>", true));
}
this.uiSystem.Add("Buy", buyUi);