improved auto-buying logic
This commit is contained in:
parent
dd6b7fc89c
commit
019157ad34
4 changed files with 36 additions and 39 deletions
|
@ -28,7 +28,6 @@
|
||||||
"OtherOptions": "Other",
|
"OtherOptions": "Other",
|
||||||
"AutoBuyEnabled": "Auto-Buying Enabled",
|
"AutoBuyEnabled": "Auto-Buying Enabled",
|
||||||
"MinTicketsForAutoBuy": "Min Tickets for Auto-Buying",
|
"MinTicketsForAutoBuy": "Min Tickets for Auto-Buying",
|
||||||
"AutoBuyInterval": "Auto-Buying Interval/s",
|
|
||||||
"----- Tutorial -----": "",
|
"----- 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>!",
|
"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.",
|
"Tutorial2": "Great! Now, you can buy your first attraction. Access the menu on the right by swiping and purchase a carousel.",
|
||||||
|
|
|
@ -35,8 +35,6 @@ namespace TouchyTickets {
|
||||||
public bool AutoBuyEnabled = true;
|
public bool AutoBuyEnabled = true;
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public int MinTicketsForAutoBuy = 50000;
|
public int MinTicketsForAutoBuy = 50000;
|
||||||
[DataMember]
|
|
||||||
public float AutoBuyIntervalSecs = 60;
|
|
||||||
|
|
||||||
public static void Save() {
|
public static void Save() {
|
||||||
var file = GetOptionsFile(true);
|
var file = GetOptionsFile(true);
|
||||||
|
|
|
@ -16,6 +16,8 @@ namespace TouchyTickets {
|
||||||
public class ParkMap {
|
public class ParkMap {
|
||||||
|
|
||||||
private const int AdditionalRadius = 15;
|
private const int AdditionalRadius = 15;
|
||||||
|
private const int AutoBuyIntervalSecs = 30;
|
||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public readonly int Width;
|
public readonly int Width;
|
||||||
[DataMember]
|
[DataMember]
|
||||||
|
@ -33,7 +35,7 @@ namespace TouchyTickets {
|
||||||
public Point PlacingPosition;
|
public Point PlacingPosition;
|
||||||
public Point? SelectedPosition;
|
public Point? SelectedPosition;
|
||||||
private bool draggingAttraction;
|
private bool draggingAttraction;
|
||||||
private TimeSpan autoBuyCounter;
|
private double autoBuyCounter;
|
||||||
|
|
||||||
public ParkMap(int width, int height) {
|
public ParkMap(int width, int height) {
|
||||||
this.Width = width;
|
this.Width = width;
|
||||||
|
@ -73,11 +75,9 @@ namespace TouchyTickets {
|
||||||
var toSimulate = wasAway ? new TimeSpan(passed.Ticks / 2) : passed;
|
var toSimulate = wasAway ? new TimeSpan(passed.Ticks / 2) : passed;
|
||||||
|
|
||||||
// handle auto-buying
|
// handle auto-buying
|
||||||
this.autoBuyCounter += toSimulate;
|
this.autoBuyCounter += toSimulate.TotalSeconds;
|
||||||
if (this.autoBuyCounter.TotalSeconds >= Options.Instance.AutoBuyIntervalSecs) {
|
this.TryAutoBuy();
|
||||||
this.autoBuyCounter = TimeSpan.Zero;
|
var autoBuysPerAttraction = ((float) this.autoBuyCounter / AutoBuyIntervalSecs / this.attractions.Count).Ceil();
|
||||||
this.TryAutoBuy();
|
|
||||||
}
|
|
||||||
|
|
||||||
// update tickets
|
// update tickets
|
||||||
this.TicketsPerSecond = 0;
|
this.TicketsPerSecond = 0;
|
||||||
|
@ -85,9 +85,15 @@ namespace TouchyTickets {
|
||||||
var genPerSecond = attraction.Update(toSimulate, this, pos);
|
var genPerSecond = attraction.Update(toSimulate, this, pos);
|
||||||
this.TicketsPerSecond += genPerSecond;
|
this.TicketsPerSecond += genPerSecond;
|
||||||
|
|
||||||
// after each attraction has sold their tickets, try auto-buying again if we were away
|
// if we were away, we have to catch up with auto-buys while also taking into account
|
||||||
if (wasAway && passed.TotalSeconds >= Options.Instance.AutoBuyIntervalSecs)
|
// the amount of tickets that each ride generates. The easiest way we can do this is
|
||||||
this.TryAutoBuy();
|
// 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
|
// map movement
|
||||||
|
@ -241,28 +247,31 @@ namespace TouchyTickets {
|
||||||
return newMap;
|
return newMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TryAutoBuy() {
|
private bool TryAutoBuy() {
|
||||||
if (!Options.Instance.AutoBuyEnabled)
|
if (!Options.Instance.AutoBuyEnabled)
|
||||||
return;
|
return false;
|
||||||
while (GameImpl.Instance.Tickets >= Options.Instance.MinTicketsForAutoBuy) {
|
if (GameImpl.Instance.Tickets < Options.Instance.MinTicketsForAutoBuy)
|
||||||
var success = false;
|
return false;
|
||||||
|
if (this.autoBuyCounter < AutoBuyIntervalSecs)
|
||||||
|
return false;
|
||||||
|
this.autoBuyCounter -= AutoBuyIntervalSecs;
|
||||||
|
|
||||||
// auto-buy modifiers
|
var success = false;
|
||||||
if (Upgrade.AutoPlaceModifiers[0].IsActive()) {
|
// auto-buy modifiers
|
||||||
foreach (var modifier in AttractionModifier.Modifiers.Values) {
|
if (Upgrade.AutoPlaceModifiers[0].IsActive()) {
|
||||||
var match = this.attractions.Select(pa => pa.Item2).Where(modifier.IsAffected);
|
// loop through all attractions, but look at attractions with fewer applied modifiers first
|
||||||
// if we don't have level 2, we only want to increase existing modifiers
|
foreach (var attraction in this.attractions.Select(kv => kv.Item2).OrderBy(a => a.GetModifierAmount(null))) {
|
||||||
if (!Upgrade.AutoPlaceModifiers[1].IsActive())
|
var match = AttractionModifier.Modifiers.Values.Where(m => m.IsAffected(attraction));
|
||||||
match = match.Where(a => a.GetModifierAmount(modifier) > 0);
|
// if we don't have level 2, we only want to increase existing modifiers
|
||||||
var attraction = match.OrderBy(a => a.GetModifierAmount(modifier)).FirstOrDefault();
|
if (!Upgrade.AutoPlaceModifiers[1].IsActive())
|
||||||
if (attraction != null && modifier.Buy(attraction))
|
match = match.Where(m => attraction.GetModifierAmount(m) > 0);
|
||||||
success = true;
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -391,15 +391,6 @@ namespace TouchyTickets {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
num.PositionOffset = new Vector2(0, 1);
|
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) {
|
optionList.AddChild(new Paragraph(Anchor.AutoCenter, 1, Localization.Get("OtherOptions"), true) {
|
||||||
PositionOffset = new Vector2(0, 10),
|
PositionOffset = new Vector2(0, 10),
|
||||||
|
|
Loading…
Reference in a new issue