60 lines
No EOL
2.3 KiB
C#
60 lines
No EOL
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using Microsoft.Xna.Framework;
|
|
using TouchyTickets.Attractions;
|
|
|
|
namespace TouchyTickets;
|
|
|
|
public class Achievement {
|
|
|
|
public static readonly Dictionary<string, Achievement> Achievements = new();
|
|
|
|
static Achievement() {
|
|
foreach (var amount in new[] {1, 10, 100})
|
|
Achievement.Register(new Achievement($"{amount}Stars", g => g.Stars >= amount));
|
|
Achievement.Register(new Achievement("FullMap", g => {
|
|
for (var x = 0; x < g.Map.Width; x++) {
|
|
for (var y = 0; y < g.Map.Height; y++) {
|
|
if (g.Map.GetAttractionAt(new Point(x, y)) == null)
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}));
|
|
foreach (var flag in new[] {AttractionFlags.Small, AttractionFlags.Relaxed, AttractionFlags.Walking, AttractionFlags.NonTechnology})
|
|
Achievement.Register(new Achievement($"Only{flag}Rides", g => g.Map.GetAttractionAmount(null) >= 100 && g.Map.GetAttractions().All(a => a.Item2.Type.Flags.HasFlag(flag))));
|
|
foreach (var amount in new[] {100, 500, 1000, 5000})
|
|
Achievement.Register(new Achievement($"{amount}Modifiers", g => g.Map.GetAttractionAmount(null) > 0 && g.Map.GetAttractions().All(a => a.Item2.GetModifierAmount(null) >= amount)));
|
|
for (var i = 1; i <= 10; i++) {
|
|
var amount = BigInteger.Pow(1000, i + 1);
|
|
Achievement.Register(new Achievement($"{i}ExpTickets", g => g.Tickets >= amount));
|
|
}
|
|
}
|
|
|
|
public readonly string Name;
|
|
private readonly Func<GameImpl, bool> condition;
|
|
// this value doesn't save between game runs, since achievements
|
|
// are only displayed inside of the respective stores anyway
|
|
private bool unlocked;
|
|
|
|
public Achievement(string name, Func<GameImpl, bool> condition) {
|
|
this.Name = name;
|
|
this.condition = condition;
|
|
}
|
|
|
|
public void Update() {
|
|
if (this.unlocked)
|
|
return;
|
|
if (!this.condition.Invoke(GameImpl.Instance))
|
|
return;
|
|
if (GameImpl.Instance.Platform.GainAchievement(this))
|
|
this.unlocked = true;
|
|
}
|
|
|
|
public static void Register(Achievement achievement) {
|
|
Achievement.Achievements.Add(achievement.Name, achievement);
|
|
}
|
|
|
|
} |