96 lines
No EOL
4.4 KiB
C#
96 lines
No EOL
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.Xna.Framework;
|
|
using MLEM.Textures;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace TouchyTickets.Attractions {
|
|
[JsonConverter(typeof(Converter))]
|
|
public class AttractionType {
|
|
|
|
public static readonly Dictionary<string, AttractionType> Attractions = new Dictionary<string, AttractionType>();
|
|
public static readonly AttractionType Carousel = Register(new AttractionType("Carousel", RectArea(1, 1), Attraction.Texture[0, 0, 1, 1], 0.5F, 50));
|
|
public static readonly AttractionType FoodCourt = Register(new AttractionType("FoodCourt", RectArea(2, 1), Attraction.Texture[1, 0, 2, 1], 1.1F, 300));
|
|
public static readonly AttractionType SpiralSlide = Register(new AttractionType("SpiralSlide", RectArea(1, 2), Attraction.Texture[5, 0, 1, 2], 2.5F, 1200));
|
|
public static readonly AttractionType HedgeMaze = Register(new AttractionType("HedgeMaze", RectArea(2, 2), Attraction.Texture[3, 3, 2, 2], 4, 2500));
|
|
public static readonly AttractionType FerrisWheel = Register(new AttractionType("FerrisWheel", RectArea(2, 2), Attraction.Texture[0, 1, 2, 2], 6.5F, 4000));
|
|
public static readonly AttractionType WildMouse = Register(new AttractionType("WildMouse", RectArea(3, 2), Attraction.Texture[2, 1, 3, 2], 15, 8000));
|
|
public static readonly AttractionType LogFlume = Register(new AttractionType("LogFlume", new[,] {{true, true, false}, {true, true, true}}, Attraction.Texture[0, 3, 3, 2], 25, 12000));
|
|
|
|
public readonly string Name;
|
|
public readonly bool[,] Area;
|
|
public int Width => this.Area.GetLength(1);
|
|
public int Height => this.Area.GetLength(0);
|
|
public readonly TextureRegion TextureRegion;
|
|
private readonly float generationPerSecond;
|
|
public readonly long InitialPrice;
|
|
private readonly Constructor create;
|
|
|
|
public AttractionType(string name, bool[,] area, TextureRegion texture, float generationPerSecond, long initialPrice, Constructor constructor = null) {
|
|
this.Name = name;
|
|
this.Area = area;
|
|
this.TextureRegion = texture;
|
|
this.generationPerSecond = generationPerSecond;
|
|
this.InitialPrice = initialPrice;
|
|
this.create = constructor ?? (t => new Attraction(t));
|
|
}
|
|
|
|
public Attraction Create() {
|
|
return this.create(this);
|
|
}
|
|
|
|
public float GetGenerationRate() {
|
|
var genRate = this.generationPerSecond;
|
|
|
|
if (this == FerrisWheel && Upgrade.FerrisWheelModifier.IsActive())
|
|
genRate *= 4;
|
|
// this should contain all car-based coasters
|
|
if ((this == Carousel || this == WildMouse) && Upgrade.RollerCoasterModifier.IsActive())
|
|
genRate *= 2;
|
|
// this should contain all coasters where people just walk around on their own
|
|
if ((this == SpiralSlide || this == HedgeMaze) && Upgrade.ManualRideModifier.IsActive())
|
|
genRate *= 3;
|
|
|
|
return genRate;
|
|
}
|
|
|
|
public IEnumerable<Point> GetCoveredTiles() {
|
|
for (var x = 0; x < this.Width; x++) {
|
|
for (var y = 0; y < this.Height; y++) {
|
|
if (this.Area[y, x])
|
|
yield return new Point(x, y);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static AttractionType Register(AttractionType type) {
|
|
Attractions.Add(type.Name, type);
|
|
return type;
|
|
}
|
|
|
|
private static bool[,] RectArea(int width, int height) {
|
|
var ret = new bool[height, width];
|
|
for (var x = 0; x < width; x++) {
|
|
for (var y = 0; y < height; y++)
|
|
ret[y, x] = true;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
public delegate Attraction Constructor(AttractionType type);
|
|
|
|
public class Converter : JsonConverter<AttractionType> {
|
|
|
|
public override void WriteJson(JsonWriter writer, AttractionType value, JsonSerializer serializer) {
|
|
if (value != null)
|
|
writer.WriteValue(value.Name);
|
|
}
|
|
|
|
public override AttractionType ReadJson(JsonReader reader, Type objectType, AttractionType existingValue, bool hasExistingValue, JsonSerializer serializer) {
|
|
return reader.Value != null ? Attractions[reader.Value.ToString()] : null;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
} |