using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using MLEM.Extensions; using MLEM.Misc; using MLEM.Startup; using MLEM.Textures; namespace TouchyTickets.Attractions { [DataContract] public class Attraction { public static readonly UniformTextureAtlas Texture = new UniformTextureAtlas(MlemGame.LoadContent("Textures/Attractions"), 16, 16); public static readonly Vector2 TileSize = new Vector2(Texture.RegionWidth, Texture.RegionHeight); [DataMember] public readonly AttractionType Type; [DataMember] private float ticketPercentage; public Attraction(AttractionType type) { this.Type = type; } public float Update(GameTime time, TimeSpan passed, ParkMap map, Point position) { var genRate = this.Type.GetGenerationRate(); // only apply dynamic upgrades here, static ones go into the type if (Upgrade.FoodCourtModifier.IsActive() && this.GetSurrounding(map, position, AttractionType.FoodCourt).Any()) genRate *= 2; if (Upgrade.SpiralSlideModifier.IsActive() && this.GetSurrounding(map, position, AttractionType.SpiralSlide).Any()) genRate *= 2; this.ticketPercentage += genRate * (float) passed.TotalSeconds; var amount = this.ticketPercentage.Floor(); if (amount > 0) { GameImpl.Instance.Tickets += amount; this.ticketPercentage -= amount; } // return the generation rate per second return genRate; } public IEnumerable GetSurrounding(ParkMap map, Point position, AttractionType type) { foreach (var tile in this.Type.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; } } } } }