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-02 12:20:16 +02:00
|
|
|
public float Update(GameTime time, TimeSpan passed, ParkMap map, Point position) {
|
2020-06-02 14:16:14 +02:00
|
|
|
var genRate = this.Type.GetGenerationRate();
|
2020-06-02 12:20:16 +02:00
|
|
|
|
2020-06-02 15:49:46 +02:00
|
|
|
// only apply dynamic upgrades here, static ones go into the type
|
2020-06-02 12:20:16 +02:00
|
|
|
if (Upgrade.FoodCourtModifier.IsActive() && this.GetSurrounding(map, position, AttractionType.FoodCourt).Any())
|
2020-06-02 15:49:46 +02:00
|
|
|
genRate *= 2;
|
2020-06-03 15:13:41 +02:00
|
|
|
if (Upgrade.SpiralSlideModifier.IsActive() && this.GetSurrounding(map, position, AttractionType.SpiralSlide).Any())
|
|
|
|
genRate *= 2;
|
2020-06-02 12:20:16 +02:00
|
|
|
|
|
|
|
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) {
|
2020-06-02 15:49:46 +02:00
|
|
|
foreach (var tile in this.Type.GetCoveredTiles()) {
|
2020-06-02 12:20:16 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|