TouchyTickets/TouchyTickets/Attractions/Attraction.cs

61 lines
2.3 KiB
C#

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<Texture2D>("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();
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;
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<Attraction> 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;
}
}
}
}
}