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; using static TouchyTickets.Attractions.AttractionFlags; using static TouchyTickets.Attractions.AttractionType; 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 List Modifiers = new List(); [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.GetGenerationRate(map, position); // apply generation rate to ticket amount this.ticketPercentage += genRate * (float) passed.TotalSeconds; var total = this.ticketPercentage.Floor(); if (total > 0) { GameImpl.Instance.Tickets += total; this.ticketPercentage -= total; } // return the generation rate per second return genRate; } public float GetGenerationRate(ParkMap map, Point position) { var genRate = this.Type.GetGenerationRate(); // apply attraction modifiers foreach (var modifier in this.Modifiers) genRate *= (float) Math.Pow(modifier.Modifier.Multiplier, modifier.Amount); // apply star upgrades if (Upgrade.FoodCourtModifier.IsActive() && this.GetSurrounding(map, position, FoodCourt).Any()) genRate *= 2; if (Upgrade.SpiralSlideModifier.IsActive() && this.GetSurrounding(map, position, SpiralSlide).Any()) genRate *= 2; if (Upgrade.HauntedHouseModifier.IsActive() && this.Type.Flags.HasFlag(Relaxed) && this.GetSurrounding(map, position, HauntedHouse).Any()) genRate *= 3; return genRate; } public void ApplyModifier(AttractionModifier modifier) { // increase the amount of existing modifiers foreach (var mod in this.Modifiers) { if (mod.Modifier == modifier) { mod.Amount++; return; } } // or add a new modifier this.Modifiers.Add(new ActiveModifier(modifier, 1)); } public int GetModifierAmount(AttractionModifier modifier) { return this.Modifiers.Where(m => modifier == null || m.Modifier == modifier).Sum(m => m.Amount); } public int GetModifierPrice(AttractionModifier modifier) { var amount = this.GetModifierAmount(modifier); return (modifier.InitialPrice * (float) Math.Pow(1 + 0.4F, amount)).Ceil(); } private 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; } } } } }