improved auto-buying logic

This commit is contained in:
Ellpeck 2020-07-09 00:25:44 +02:00
parent dd6b7fc89c
commit 019157ad34
4 changed files with 36 additions and 39 deletions

View file

@ -28,7 +28,6 @@
"OtherOptions": "Other",
"AutoBuyEnabled": "Auto-Buying Enabled",
"MinTicketsForAutoBuy": "Min Tickets for Auto-Buying",
"AutoBuyInterval": "Auto-Buying Interval/s",
"----- Tutorial -----": "",
"Tutorial1": "Hi! Welcome to Touchy Tickets. To start the game, simply tap the ticket booth to sell a <i ticket>. Start by racking up 50<i ticket>!",
"Tutorial2": "Great! Now, you can buy your first attraction. Access the menu on the right by swiping and purchase a carousel.",

View file

@ -35,8 +35,6 @@ namespace TouchyTickets {
public bool AutoBuyEnabled = true;
[DataMember]
public int MinTicketsForAutoBuy = 50000;
[DataMember]
public float AutoBuyIntervalSecs = 60;
public static void Save() {
var file = GetOptionsFile(true);

View file

@ -16,6 +16,8 @@ namespace TouchyTickets {
public class ParkMap {
private const int AdditionalRadius = 15;
private const int AutoBuyIntervalSecs = 30;
[DataMember]
public readonly int Width;
[DataMember]
@ -33,7 +35,7 @@ namespace TouchyTickets {
public Point PlacingPosition;
public Point? SelectedPosition;
private bool draggingAttraction;
private TimeSpan autoBuyCounter;
private double autoBuyCounter;
public ParkMap(int width, int height) {
this.Width = width;
@ -73,11 +75,9 @@ namespace TouchyTickets {
var toSimulate = wasAway ? new TimeSpan(passed.Ticks / 2) : passed;
// handle auto-buying
this.autoBuyCounter += toSimulate;
if (this.autoBuyCounter.TotalSeconds >= Options.Instance.AutoBuyIntervalSecs) {
this.autoBuyCounter = TimeSpan.Zero;
this.autoBuyCounter += toSimulate.TotalSeconds;
this.TryAutoBuy();
}
var autoBuysPerAttraction = ((float) this.autoBuyCounter / AutoBuyIntervalSecs / this.attractions.Count).Ceil();
// update tickets
this.TicketsPerSecond = 0;
@ -85,9 +85,15 @@ namespace TouchyTickets {
var genPerSecond = attraction.Update(toSimulate, this, pos);
this.TicketsPerSecond += genPerSecond;
// after each attraction has sold their tickets, try auto-buying again if we were away
if (wasAway && passed.TotalSeconds >= Options.Instance.AutoBuyIntervalSecs)
this.TryAutoBuy();
// if we were away, we have to catch up with auto-buys while also taking into account
// the amount of tickets that each ride generates. The easiest way we can do this is
// to progress, between updating each ride, by a percentage of the total update amount
if (wasAway) {
for (var i = autoBuysPerAttraction; i > 0; i--) {
if (!this.TryAutoBuy())
break;
}
}
}
// map movement
@ -241,28 +247,31 @@ namespace TouchyTickets {
return newMap;
}
private void TryAutoBuy() {
private bool TryAutoBuy() {
if (!Options.Instance.AutoBuyEnabled)
return;
while (GameImpl.Instance.Tickets >= Options.Instance.MinTicketsForAutoBuy) {
var success = false;
return false;
if (GameImpl.Instance.Tickets < Options.Instance.MinTicketsForAutoBuy)
return false;
if (this.autoBuyCounter < AutoBuyIntervalSecs)
return false;
this.autoBuyCounter -= AutoBuyIntervalSecs;
var success = false;
// auto-buy modifiers
if (Upgrade.AutoPlaceModifiers[0].IsActive()) {
foreach (var modifier in AttractionModifier.Modifiers.Values) {
var match = this.attractions.Select(pa => pa.Item2).Where(modifier.IsAffected);
// loop through all attractions, but look at attractions with fewer applied modifiers first
foreach (var attraction in this.attractions.Select(kv => kv.Item2).OrderBy(a => a.GetModifierAmount(null))) {
var match = AttractionModifier.Modifiers.Values.Where(m => m.IsAffected(attraction));
// if we don't have level 2, we only want to increase existing modifiers
if (!Upgrade.AutoPlaceModifiers[1].IsActive())
match = match.Where(a => a.GetModifierAmount(modifier) > 0);
var attraction = match.OrderBy(a => a.GetModifierAmount(modifier)).FirstOrDefault();
if (attraction != null && modifier.Buy(attraction))
match = match.Where(m => attraction.GetModifierAmount(m) > 0);
// we want to apply the least applied modifier on this attraction
var modifier = match.OrderBy(m => attraction.GetModifierAmount(m)).FirstOrDefault();
if (modifier != null && modifier.Buy(attraction))
success = true;
}
}
if (!success)
break;
}
return success;
}
}

View file

@ -391,15 +391,6 @@ namespace TouchyTickets {
}
}));
num.PositionOffset = new Vector2(0, 1);
optionList.AddChild(new Paragraph(Anchor.AutoLeft, 1, p => Localization.Get("AutoBuyInterval") + ": " + Options.Instance.AutoBuyIntervalSecs));
optionList.AddChild(new Slider(Anchor.AutoLeft, new Vector2(1, 20), 10, 299) {
PositionOffset = new Vector2(0, 1),
CurrentValue = Options.Instance.AutoBuyIntervalSecs - 1,
OnValueChanged = (s, v) => {
Options.Instance.AutoBuyIntervalSecs = (int) v + 1;
Options.Save();
}
});
optionList.AddChild(new Paragraph(Anchor.AutoCenter, 1, Localization.Get("OtherOptions"), true) {
PositionOffset = new Vector2(0, 10),