2020-06-01 14:45:20 +02:00
|
|
|
using System;
|
2020-05-31 00:44:15 +02:00
|
|
|
using System.Collections.Generic;
|
2020-06-02 12:20:16 +02:00
|
|
|
using System.Linq;
|
2020-06-01 14:45:20 +02:00
|
|
|
using System.Runtime.Serialization;
|
2020-05-31 17:24:10 +02:00
|
|
|
using Microsoft.Xna.Framework;
|
2020-05-31 00:44:15 +02:00
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2020-05-31 17:24:10 +02:00
|
|
|
using MLEM.Extensions;
|
2020-06-02 12:20:16 +02:00
|
|
|
using MLEM.Misc;
|
2020-05-31 00:44:15 +02:00
|
|
|
using MLEM.Startup;
|
|
|
|
using MLEM.Textures;
|
|
|
|
|
2020-06-01 17:39:57 +02:00
|
|
|
namespace TouchyTickets.Attractions {
|
2020-06-01 14:45:20 +02:00
|
|
|
[DataContract]
|
2020-05-31 00:44:15 +02:00
|
|
|
public class Attraction {
|
|
|
|
|
|
|
|
public static readonly UniformTextureAtlas Texture = new UniformTextureAtlas(MlemGame.LoadContent<Texture2D>("Textures/Attractions"), 16, 16);
|
2020-05-31 17:24:10 +02:00
|
|
|
public static readonly Vector2 TileSize = new Vector2(Texture.RegionWidth, Texture.RegionHeight);
|
2020-05-31 00:44:15 +02:00
|
|
|
|
2020-06-01 14:45:20 +02:00
|
|
|
[DataMember]
|
|
|
|
public readonly AttractionType Type;
|
|
|
|
[DataMember]
|
2020-05-31 17:24:10 +02:00
|
|
|
private float ticketPercentage;
|
2020-05-31 00:44:15 +02:00
|
|
|
|
2020-06-01 14:45:20 +02:00
|
|
|
public Attraction(AttractionType type) {
|
|
|
|
this.Type = type;
|
2020-05-31 00:44:15 +02:00
|
|
|
}
|
|
|
|
|
2020-06-01 01:21:54 +02:00
|
|
|
public IEnumerable<Point> GetCoveredTiles() {
|
2020-06-01 14:45:20 +02:00
|
|
|
for (var x = 0; x < this.Type.Width; x++) {
|
|
|
|
for (var y = 0; y < this.Type.Height; y++) {
|
|
|
|
if (this.Type.Area[y, x])
|
2020-06-01 01:21:54 +02:00
|
|
|
yield return new Point(x, y);
|
|
|
|
}
|
|
|
|
}
|
2020-05-31 00:44:15 +02:00
|
|
|
}
|
|
|
|
|
2020-06-02 12:20:16 +02:00
|
|
|
public float Update(GameTime time, TimeSpan passed, ParkMap map, Point position) {
|
|
|
|
var genRate = this.Type.GenerationPerSecond;
|
|
|
|
|
|
|
|
if (Upgrade.FoodCourtModifier.IsActive() && this.GetSurrounding(map, position, AttractionType.FoodCourt).Any())
|
|
|
|
genRate *= 3;
|
|
|
|
|
|
|
|
this.ticketPercentage += genRate * (float) passed.TotalSeconds;
|
2020-05-31 17:24:10 +02:00
|
|
|
var amount = this.ticketPercentage.Floor();
|
|
|
|
if (amount > 0) {
|
|
|
|
GameImpl.Instance.Tickets += amount;
|
|
|
|
this.ticketPercentage -= amount;
|
|
|
|
}
|
2020-06-02 12:20:16 +02:00
|
|
|
// return the generation rate per second
|
|
|
|
return genRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerable<Attraction> GetSurrounding(ParkMap map, Point position, AttractionType type) {
|
|
|
|
foreach (var tile in this.GetCoveredTiles()) {
|
|
|
|
foreach (var dir in Direction2Helper.Adjacent) {
|
|
|
|
var other = map.GetAttractionAt(position + tile + dir.Offset());
|
|
|
|
if (other != null && other != this && other.Type == type)
|
|
|
|
yield return other;
|
|
|
|
}
|
|
|
|
}
|
2020-05-31 17:24:10 +02:00
|
|
|
}
|
|
|
|
|
2020-05-31 00:44:15 +02:00
|
|
|
}
|
|
|
|
}
|