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-12 17:32:50 +02:00
|
|
|
using System.Numerics;
|
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-06-02 12:20:16 +02:00
|
|
|
using MLEM.Misc;
|
2020-05-31 00:44:15 +02:00
|
|
|
using MLEM.Textures;
|
2020-07-10 20:45:23 +02:00
|
|
|
using TouchyTickets.Upgrades;
|
2023-02-11 10:16:42 +01:00
|
|
|
using Vector2 = Microsoft.Xna.Framework.Vector2;
|
2020-05-31 00:44:15 +02:00
|
|
|
|
2023-02-11 10:16:42 +01:00
|
|
|
namespace TouchyTickets.Attractions;
|
2020-06-16 17:52:29 +02:00
|
|
|
|
2023-02-11 10:16:42 +01:00
|
|
|
[DataContract]
|
|
|
|
public class Attraction {
|
2020-06-16 17:52:29 +02:00
|
|
|
|
2023-02-11 10:16:42 +01:00
|
|
|
[DataMember]
|
|
|
|
public readonly List<ActiveModifier> Modifiers = new();
|
|
|
|
[DataMember]
|
|
|
|
public readonly AttractionType Type;
|
|
|
|
[DataMember]
|
|
|
|
private double ticketPercentage;
|
|
|
|
private float animationSizeModifier;
|
2020-06-08 22:55:33 +02:00
|
|
|
|
2023-02-11 10:16:42 +01:00
|
|
|
public Attraction(AttractionType type) {
|
|
|
|
this.Type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double Update(TimeSpan passed, ParkMap map, Point position) {
|
|
|
|
var genRate = this.GetGenerationRate(map, position);
|
|
|
|
// apply generation rate to ticket amount
|
|
|
|
this.ticketPercentage += genRate * passed.TotalSeconds;
|
|
|
|
var total = (BigInteger) this.ticketPercentage;
|
|
|
|
if (total > 0) {
|
|
|
|
GameImpl.Instance.Tickets += total;
|
|
|
|
this.ticketPercentage -= (double) total;
|
2020-06-16 17:52:29 +02:00
|
|
|
}
|
|
|
|
|
2023-02-11 10:16:42 +01:00
|
|
|
// animation stuff
|
|
|
|
if (this.animationSizeModifier > 0)
|
|
|
|
this.animationSizeModifier = Math.Max(this.animationSizeModifier - 0.2F, 0);
|
2020-06-02 12:20:16 +02:00
|
|
|
|
2023-02-11 10:16:42 +01:00
|
|
|
// return the generation rate per second
|
|
|
|
return genRate;
|
|
|
|
}
|
2020-06-08 18:01:10 +02:00
|
|
|
|
2023-02-11 10:16:42 +01:00
|
|
|
public void Draw(SpriteBatch batch, Vector2 position, float alpha, float scale) {
|
|
|
|
var drawScale = scale;
|
|
|
|
if (this.animationSizeModifier > 0)
|
|
|
|
drawScale += (float) Math.Sin(this.animationSizeModifier) * 0.05F;
|
|
|
|
var tex = Assets.AttractionTexture[this.Type.TextureRegion];
|
|
|
|
var center = tex.Size.ToVector2() / 2;
|
|
|
|
batch.Draw(tex, position + center * scale, Color.White * alpha, 0, center, drawScale, SpriteEffects.None, 0);
|
|
|
|
}
|
2020-06-10 20:39:40 +02:00
|
|
|
|
2023-02-11 10:16:42 +01:00
|
|
|
public double GetGenerationRate(ParkMap map, Point position) {
|
|
|
|
var genRate = this.Type.GetGenerationRate();
|
|
|
|
|
|
|
|
// apply attraction modifiers
|
|
|
|
var mod = 1D;
|
|
|
|
foreach (var modifier in this.Modifiers)
|
|
|
|
mod += Math.Pow(modifier.Modifier.Multiplier, modifier.Amount) - 1;
|
|
|
|
genRate *= mod;
|
2020-06-02 12:20:16 +02:00
|
|
|
|
2023-02-11 10:16:42 +01:00
|
|
|
// apply star upgrades
|
|
|
|
foreach (var upgrade in Upgrade.Upgrades.Values.OfType<NeighborModifierUpgrade>())
|
|
|
|
genRate *= upgrade.GetCurrentMultiplier(this, map, position);
|
|
|
|
|
|
|
|
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;
|
2020-06-08 18:01:10 +02:00
|
|
|
}
|
|
|
|
}
|
2023-02-11 10:16:42 +01:00
|
|
|
// or add a new modifier
|
|
|
|
this.Modifiers.Add(new ActiveModifier(modifier, 1));
|
|
|
|
}
|
2020-06-08 18:01:10 +02:00
|
|
|
|
2023-02-11 10:16:42 +01:00
|
|
|
public int GetModifierAmount(AttractionModifier modifier) {
|
|
|
|
return this.Modifiers.Where(m => modifier == null || m.Modifier == modifier).Sum(m => m.Amount);
|
|
|
|
}
|
2020-06-08 22:55:33 +02:00
|
|
|
|
2023-02-11 10:16:42 +01:00
|
|
|
public BigInteger GetModifierPrice(AttractionModifier modifier) {
|
|
|
|
var amount = this.GetModifierAmount(modifier);
|
|
|
|
return (BigInteger) Math.Ceiling(modifier.InitialPrice * Math.Pow(1 + 0.45F, amount));
|
|
|
|
}
|
2020-06-08 18:01:10 +02:00
|
|
|
|
2023-02-11 10:16:42 +01:00
|
|
|
public void Wobble() {
|
|
|
|
this.animationSizeModifier = MathHelper.Pi;
|
|
|
|
}
|
2020-06-16 17:52:29 +02:00
|
|
|
|
2023-02-11 10:16:42 +01:00
|
|
|
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;
|
2020-06-02 12:20:16 +02:00
|
|
|
}
|
2020-05-31 17:24:10 +02:00
|
|
|
}
|
2020-05-31 00:44:15 +02:00
|
|
|
}
|
2023-02-11 10:16:42 +01:00
|
|
|
|
2020-05-31 00:44:15 +02:00
|
|
|
}
|