using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using MLEM.Extensions; using MLEM.Textures; namespace TouchyTickets.Upgrades { public class Upgrade { public static readonly Dictionary Upgrades = new Dictionary(); public static readonly Upgrade[] MapSize = RegisterTiers("MapSize", 10, 1, 0.5F, Ui.Texture[0, 3]); public readonly string Name; public readonly int Price; public readonly TextureRegion Texture; public readonly Upgrade[] Dependencies; public Upgrade(string name, int price, TextureRegion texture, params Upgrade[] dependencies) { this.Name = name; this.Price = price; this.Texture = texture; this.Dependencies = dependencies; } private static Upgrade[] RegisterTiers(string name, int amount, int startPrice, float priceIncrease, TextureRegion texture) { var ret = new Upgrade[amount]; for (var i = 0; i < amount; i++) { // every tier except first depends on last tier var deps = i == 0 ? Array.Empty() : new[] {ret[i - 1]}; var price = (startPrice * (1 + i * priceIncrease)).Floor(); Register(ret[i] = new Upgrade(name + (i + 1), price, texture, deps)); } return ret; } public void OnApplied() { // map size upgrades if (MapSize.Contains(this)) { var oldMap = GameImpl.Instance.Map; var newMap = new ParkMap(oldMap.Width + 5, oldMap.Height + 5); newMap.CopyAttractionsFrom(oldMap); GameImpl.Instance.Map = newMap; } } private static void Register(Upgrade upgrade) { Upgrades.Add(upgrade.Name, upgrade); } public static bool IsActive(Upgrade upgrade) { return GameImpl.Instance.AppliedUpgrades.Contains(upgrade); } } }