-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreMod.cs
123 lines (99 loc) · 4.08 KB
/
ScoreMod.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Collections.Generic;
using SpinCore.Utility;
using UnityEngine;
namespace SRXDScoreMod;
/// <summary>
/// Enables the introduction of custom score systems and score modifiers
/// </summary>
public static class ScoreMod {
/// <summary>
/// Invoke when the current score system is changed
/// </summary>
public static event Action<IScoreSystem> OnScoreSystemChanged;
/// <summary>
/// The currently visible score system
/// </summary>
public static IScoreSystem CurrentScoreSystem => CurrentScoreSystemInternal;
/// <summary>
/// The currently used modifier set
/// </summary>
public static ScoreModifierSet CurrentModifierSet { get; private set; }
internal static bool AnyModifiersEnabled { get; private set; }
internal static IScoreSystemInternal CurrentScoreSystemInternal { get; private set; }
internal static List<IScoreSystemInternal> ScoreSystems { get; } = new();
internal static List<CustomScoreSystem> CustomScoreSystems { get; } = new();
private static int scoreSystemIndex;
private static float modifierMultiplier = 1f;
/// <summary>
/// Adds a new custom score system with a given profile
/// </summary>
/// <param name="profile">The profile to use</param>
public static void AddCustomScoreSystem(ScoreSystemProfile profile) {
foreach (var system in ScoreSystems) {
if (profile.Id != system.Id)
continue;
Plugin.Logger.LogWarning($"WARNING: Score system with ID {profile.Id} already exists");
return;
}
var scoreSystem = new CustomScoreSystem(profile);
ScoreSystems.Add(scoreSystem);
CustomScoreSystems.Add(scoreSystem);
}
/// <summary>
/// Sets the modifier set to use
/// </summary>
/// <param name="modifierSet">The modifier set to use</param>
public static void SetModifierSet(ScoreModifierSet modifierSet) {
if (modifierSet == CurrentModifierSet)
return;
if (CurrentModifierSet != null) {
CurrentModifierSet.ModifierChanged -= OnModifierChanged;
CurrentModifierSet.DisableAll();
}
CurrentModifierSet = modifierSet;
if (modifierSet != null) {
modifierSet.DisableAll();
modifierSet.ModifierChanged += OnModifierChanged;
HighScoresContainer.RemoveInvalidHighScoresForModifierSet(modifierSet);
}
OnModifierChanged();
}
internal static void Init() {
ScoreSystems.Add(new BaseScoreSystemWrapper());
AddCustomScoreSystem(DefaultScoreSystemProfiles.StandardPPM16);
// AddCustomScoreSystem(DefaultScoreSystemProfiles.StandardPPM32);
CurrentScoreSystemInternal = ScoreSystems[0];
}
internal static void LateInit() => Plugin.CurrentSystem.BindAndInvoke(OnCurrentSystemChanged);
internal static int GetModifiedScore(int score) {
if (AnyModifiersEnabled)
return Mathf.CeilToInt(modifierMultiplier * score);
return score;
}
private static void OnCurrentSystemChanged(int value) {
if (value == scoreSystemIndex)
return;
scoreSystemIndex = value;
CurrentScoreSystemInternal = ScoreSystems[value];
GameplayUI.UpdateUI();
CompleteScreenUI.UpdateUI(true);
LevelSelectUI.UpdateUI();
OnScoreSystemChanged?.Invoke(CurrentScoreSystem);
}
private static void OnModifierChanged() {
if (CurrentModifierSet == null) {
AnyModifiersEnabled = false;
modifierMultiplier = 1f;
ScoreSubmissionUtility.EnableScoreSubmission(Plugin.Instance);
}
else {
AnyModifiersEnabled = CurrentModifierSet.GetAnyEnabled();
modifierMultiplier = 0.01f * CurrentModifierSet.GetOverallMultiplier();
if (AnyModifiersEnabled)
ScoreSubmissionUtility.DisableScoreSubmission(Plugin.Instance);
else
ScoreSubmissionUtility.EnableScoreSubmission(Plugin.Instance);
}
}
}