show applied upgrades in the map menu

This commit is contained in:
Ellpeck 2020-07-10 20:45:23 +02:00
parent 906b9eb6a1
commit 247912cbc9
10 changed files with 105 additions and 44 deletions

View file

@ -9,6 +9,7 @@ using MLEM.Extensions;
using MLEM.Misc; using MLEM.Misc;
using MLEM.Startup; using MLEM.Startup;
using MLEM.Textures; using MLEM.Textures;
using TouchyTickets.Upgrades;
using static TouchyTickets.Attractions.AttractionFlags; using static TouchyTickets.Attractions.AttractionFlags;
using static TouchyTickets.Attractions.AttractionType; using static TouchyTickets.Attractions.AttractionType;
@ -65,14 +66,8 @@ namespace TouchyTickets.Attractions {
genRate *= mod; genRate *= mod;
// apply star upgrades // apply star upgrades
if (Upgrade.FerrisWheelModifier.IsActive() && this.GetSurrounding(map, position, FerrisWheel).Any()) foreach (var upgrade in Upgrade.Upgrades.Values.OfType<NeighborModifierUpgrade>())
genRate *= 2; genRate *= upgrade.GetCurrentMultiplier(this, map, position);
if (Upgrade.FoodCourtModifier.IsActive() && this.GetSurrounding(map, position, FoodCourt).Any())
genRate *= 2;
if (Upgrade.SpiralSlideModifier.IsActive() && this.GetSurrounding(map, position, SpiralSlide).Any())
genRate *= 2;
if (Upgrade.HauntedHouseModifier.IsActive() && this.Type.Flags.HasFlag(Relaxed) && this.GetSurrounding(map, position, HauntedHouse).Any())
genRate *= 3;
return genRate; return genRate;
} }
@ -102,7 +97,7 @@ namespace TouchyTickets.Attractions {
this.animationSizeModifier = MathHelper.Pi; this.animationSizeModifier = MathHelper.Pi;
} }
private IEnumerable<Attraction> GetSurrounding(ParkMap map, Point position, AttractionType type) { public IEnumerable<Attraction> GetSurrounding(ParkMap map, Point position, AttractionType type) {
foreach (var tile in this.Type.GetCoveredTiles()) { foreach (var tile in this.Type.GetCoveredTiles()) {
foreach (var dir in Direction2Helper.Adjacent) { foreach (var dir in Direction2Helper.Adjacent) {
var other = map.GetAttractionAt(position + tile + dir.Offset()); var other = map.GetAttractionAt(position + tile + dir.Offset());

View file

@ -1,8 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MLEM.Textures; using MLEM.Textures;
using Newtonsoft.Json; using Newtonsoft.Json;
using TouchyTickets.Upgrades;
using static TouchyTickets.Attractions.AttractionFlags; using static TouchyTickets.Attractions.AttractionFlags;
namespace TouchyTickets.Attractions { namespace TouchyTickets.Attractions {
@ -50,14 +52,8 @@ namespace TouchyTickets.Attractions {
public double GetGenerationRate() { public double GetGenerationRate() {
var genRate = this.generationPerSecond; var genRate = this.generationPerSecond;
foreach (var upgrade in Upgrade.Upgrades.Values.OfType<ModifierUpgrade>())
if (this.Flags.HasFlag(FastCars) && Upgrade.RollerCoasterModifier.IsActive()) genRate *= upgrade.GetCurrentMultiplier(this);
genRate *= 2;
if (this.Flags.HasFlag(Walking) && Upgrade.ManualRideModifier.IsActive())
genRate *= 3;
if (this.Flags.HasFlag(NonTechnology) && Upgrade.NatureModifier.IsActive())
genRate *= 2;
return genRate; return genRate;
} }

@ -1 +1 @@
Subproject commit 83e0e71857a74015ae547ab1ab5d0b9622082e85 Subproject commit 8428712d0a64e36334908cd25bec7dddd9abd66d

View file

@ -6,6 +6,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Cameras; using MLEM.Cameras;
using MLEM.Startup; using MLEM.Startup;
using TouchyTickets.Upgrades;
namespace TouchyTickets { namespace TouchyTickets {
public class GameImpl : MlemGame { public class GameImpl : MlemGame {

View file

@ -10,6 +10,7 @@ using MLEM.Misc;
using MLEM.Startup; using MLEM.Startup;
using MLEM.Textures; using MLEM.Textures;
using TouchyTickets.Attractions; using TouchyTickets.Attractions;
using TouchyTickets.Upgrades;
namespace TouchyTickets { namespace TouchyTickets {
[DataContract] [DataContract]

View file

@ -4,6 +4,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using Newtonsoft.Json; using Newtonsoft.Json;
using TouchyTickets.Upgrades;
namespace TouchyTickets { namespace TouchyTickets {
public static class SaveHandler { public static class SaveHandler {

View file

@ -18,6 +18,7 @@ using MLEM.Textures;
using MLEM.Ui; using MLEM.Ui;
using MLEM.Ui.Elements; using MLEM.Ui.Elements;
using TouchyTickets.Attractions; using TouchyTickets.Attractions;
using TouchyTickets.Upgrades;
namespace TouchyTickets { namespace TouchyTickets {
public class Ui { public class Ui {
@ -33,6 +34,8 @@ namespace TouchyTickets {
this.uiSystem = uiSystem; this.uiSystem = uiSystem;
foreach (var modifier in AttractionModifier.Modifiers.Values) foreach (var modifier in AttractionModifier.Modifiers.Values)
this.uiSystem.TextFormatter.AddImage(modifier.Name, Assets.UiTexture[modifier.Texture]); this.uiSystem.TextFormatter.AddImage(modifier.Name, Assets.UiTexture[modifier.Texture]);
foreach (var upgrade in Upgrade.Upgrades.Values)
this.uiSystem.TextFormatter.AddImage(upgrade.Name, Assets.UiTexture[upgrade.Texture]);
// main ticket store ui // main ticket store ui
var rainingTickets = new List<RainingTicket>(); var rainingTickets = new List<RainingTicket>();
@ -651,6 +654,20 @@ namespace TouchyTickets {
var attraction = map.GetAttractionAt(map.SelectedPosition.Value); var attraction = map.GetAttractionAt(map.SelectedPosition.Value);
return string.Join(" ", attraction.Modifiers.Select(m => $"{m.Amount}<i {m.Modifier.Name}>")); return string.Join(" ", attraction.Modifiers.Select(m => $"{m.Amount}<i {m.Modifier.Name}>"));
}, true)); }, true));
element.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => {
if (map.SelectedPosition == null)
return string.Empty;
var pos = map.SelectedPosition.Value;
var attraction = map.GetAttractionAt(pos);
// beautiful
return string.Join(" ", Upgrade.Upgrades.Values
.Select(u => {
var multiplier =
u is ModifierUpgrade mod ? mod.GetCurrentMultiplier(attraction.Type) :
u is NeighborModifierUpgrade neighbor ? neighbor.GetCurrentMultiplier(attraction, map, pos) : 1;
return multiplier > 1 ? $"<i {u.Name}> x{multiplier}" : null;
}).Where(s => s != null));
}, true));
element.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => { element.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => {
if (map.SelectedPosition == null) if (map.SelectedPosition == null)
return string.Empty; return string.Empty;

View file

@ -0,0 +1,23 @@
using Microsoft.Xna.Framework;
using TouchyTickets.Attractions;
namespace TouchyTickets.Upgrades {
public class ModifierUpgrade : Upgrade {
private readonly AttractionFlags requiredFlag;
private readonly float modifier;
public ModifierUpgrade(string name, int price, Point texture, AttractionFlags requiredFlag, float modifier, params Upgrade[] dependencies) :
base(name, price, texture, dependencies) {
this.requiredFlag = requiredFlag;
this.modifier = modifier;
}
public float GetCurrentMultiplier(AttractionType attraction) {
if (this.IsActive() && attraction.Flags.HasFlag(this.requiredFlag))
return this.modifier;
return 1;
}
}
}

View file

@ -0,0 +1,26 @@
using System.Linq;
using Microsoft.Xna.Framework;
using TouchyTickets.Attractions;
namespace TouchyTickets.Upgrades {
public class NeighborModifierUpgrade : Upgrade {
private readonly AttractionType requiredNeighbor;
private readonly AttractionFlags requiredFlag;
private readonly float modifier;
public NeighborModifierUpgrade(string name, int price, Point texture, AttractionType requiredNeighbor, float modifier, AttractionFlags requiredFlag = AttractionFlags.None, params Upgrade[] dependencies) :
base(name, price, texture, dependencies) {
this.requiredNeighbor = requiredNeighbor;
this.requiredFlag = requiredFlag;
this.modifier = modifier;
}
public float GetCurrentMultiplier(Attraction attraction, ParkMap map, Point position) {
if (this.IsActive() && attraction.Type.Flags.HasFlag(this.requiredFlag) && attraction.GetSurrounding(map, position, this.requiredNeighbor).Any())
return this.modifier;
return 1;
}
}
}

View file

@ -3,9 +3,10 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MLEM.Extensions; using MLEM.Extensions;
using MLEM.Textures; using static TouchyTickets.Attractions.AttractionFlags;
using static TouchyTickets.Attractions.AttractionType;
namespace TouchyTickets { namespace TouchyTickets.Upgrades {
public class Upgrade { public class Upgrade {
public static readonly Dictionary<string, Upgrade> Upgrades = new Dictionary<string, Upgrade>(); public static readonly Dictionary<string, Upgrade> Upgrades = new Dictionary<string, Upgrade>();
@ -13,13 +14,13 @@ namespace TouchyTickets {
public static readonly Upgrade[] TapIncrease = RegisterTiers("TapIncrease", 3, 1, 0.5F, new Point(6, 3)); public static readonly Upgrade[] TapIncrease = RegisterTiers("TapIncrease", 3, 1, 0.5F, new Point(6, 3));
public static readonly Upgrade[] ModifierIncrease = RegisterTiers("ModifierIncrease", 3, 1, 1.5F, new Point(9, 3)); public static readonly Upgrade[] ModifierIncrease = RegisterTiers("ModifierIncrease", 3, 1, 1.5F, new Point(9, 3));
public static readonly Upgrade[] AutoPlaceModifiers = RegisterTiers("AutoPlaceModifiers", 2, 6, 1, new Point(10, 3)); public static readonly Upgrade[] AutoPlaceModifiers = RegisterTiers("AutoPlaceModifiers", 2, 6, 1, new Point(10, 3));
public static readonly Upgrade FerrisWheelModifier = Register(new Upgrade("FerrisWheelModifier", 1, new Point(2, 3))); public static readonly Upgrade FerrisWheelModifier = Register(new NeighborModifierUpgrade("FerrisWheelModifier", 1, new Point(2, 3), FerrisWheel, 2));
public static readonly Upgrade NatureModifier = Register(new Upgrade("NatureModifier", 1, new Point(8, 3))); public static readonly Upgrade NatureModifier = Register(new ModifierUpgrade("NatureModifier", 1, new Point(8, 3), NonTechnology, 2));
public static readonly Upgrade FoodCourtModifier = Register(new Upgrade("FoodCourtModifier", 2, new Point(1, 3))); public static readonly Upgrade FoodCourtModifier = Register(new NeighborModifierUpgrade("FoodCourtModifier", 2, new Point(1, 3), FoodCourt, 2));
public static readonly Upgrade RollerCoasterModifier = Register(new Upgrade("RollerCoasterModifier", 2, new Point(3, 3))); public static readonly Upgrade RollerCoasterModifier = Register(new ModifierUpgrade("RollerCoasterModifier", 2, new Point(3, 3), FastCars, 2));
public static readonly Upgrade ManualRideModifier = Register(new Upgrade("ManualRideModifier", 2, new Point(4, 3))); public static readonly Upgrade ManualRideModifier = Register(new ModifierUpgrade("ManualRideModifier", 2, new Point(4, 3), Walking, 3));
public static readonly Upgrade SpiralSlideModifier = Register(new Upgrade("SpiralSlideModifier", 2, new Point(5, 3))); public static readonly Upgrade SpiralSlideModifier = Register(new NeighborModifierUpgrade("SpiralSlideModifier", 2, new Point(5, 3), SpiralSlide, 2));
public static readonly Upgrade HauntedHouseModifier = Register(new Upgrade("HauntedHouseModifier", 2, new Point(7, 3))); public static readonly Upgrade HauntedHouseModifier = Register(new NeighborModifierUpgrade("HauntedHouseModifier", 2, new Point(7, 3), HauntedHouse, 3, Relaxed));
public readonly string Name; public readonly string Name;
public readonly int Price; public readonly int Price;
@ -33,6 +34,23 @@ namespace TouchyTickets {
this.Dependencies = dependencies; this.Dependencies = dependencies;
} }
public void OnApplied() {
// map size upgrades
if (MapSize.Contains(this)) {
var oldMap = GameImpl.Instance.Map;
GameImpl.Instance.Map = oldMap.Copy(oldMap.Width + 10, oldMap.Height + 10);
}
}
public bool IsActive() {
return GameImpl.Instance.AppliedUpgrades.Contains(this);
}
private static Upgrade Register(Upgrade upgrade) {
Upgrades.Add(upgrade.Name, upgrade);
return upgrade;
}
private static Upgrade[] RegisterTiers(string name, int amount, int startPrice, float priceIncrease, Point texture) { private static Upgrade[] RegisterTiers(string name, int amount, int startPrice, float priceIncrease, Point texture) {
var ret = new Upgrade[amount]; var ret = new Upgrade[amount];
for (var i = 0; i < amount; i++) { for (var i = 0; i < amount; i++) {
@ -44,22 +62,5 @@ namespace TouchyTickets {
return ret; return ret;
} }
public void OnApplied() {
// map size upgrades
if (MapSize.Contains(this)) {
var oldMap = GameImpl.Instance.Map;
GameImpl.Instance.Map = oldMap.Copy(oldMap.Width + 10, oldMap.Height + 10);
}
}
private static Upgrade Register(Upgrade upgrade) {
Upgrades.Add(upgrade.Name, upgrade);
return upgrade;
}
public bool IsActive() {
return GameImpl.Instance.AppliedUpgrades.Contains(this);
}
} }
} }