forked from hajsdfgj/modular-overhaul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISkill.cs
196 lines (158 loc) · 8.21 KB
/
ISkill.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
namespace DaLion.Overhaul.Modules.Professions;
#region using directives
using System.Collections.Generic;
using System.Linq;
using DaLion.Overhaul.Modules.Professions.Extensions;
using DaLion.Shared.Extensions;
using DaLion.Shared.Extensions.Collections;
using StardewValley;
#endregion using directives
/// <summary>Interface for all of the <see cref="Farmer"/>'s skills.</summary>
public interface ISkill
{
/// <summary>The vanilla experience cap.</summary>
public const int ExpAtLevel10 = 15000;
/// <summary>Gets the skill's unique string id.</summary>
string StringId { get; }
/// <summary>Gets the localized in-game name of this skill.</summary>
string DisplayName { get; }
/// <summary>Gets the current experience total gained by the local player for this skill.</summary>
int CurrentExp { get; }
/// <summary>Gets the current level for this skill.</summary>
int CurrentLevel { get; }
/// <summary>Gets the highest allowed level for this skill.</summary>
int MaxLevel { get; }
/// <summary>Gets the amount of experience required for the next level-up.</summary>
int ExperienceToNextLevel => this.CurrentLevel == this.MaxLevel ? 0 : ExperienceCurve[this.CurrentLevel + 1];
/// <summary>Gets the amount of experience required to reach the max level.</summary>
int ExperienceToMaxLevel => ExperienceCurve[this.MaxLevel];
/// <summary>Gets the base experience multiplier set by the player for this skill.</summary>
float BaseExperienceMultiplier { get; }
/// <summary>Gets the experience multiplier due to this skill's prestige level.</summary>
float PrestigeExperienceMultiplier =>
(float)Math.Pow(1f + ProfessionsModule.Config.Prestige.ExpBonusPerSkillReset, this.AcquiredProfessions.Length);
/// <summary>Gets the new levels gained during the current game day, which have not yet been accomplished by an overnight menu.</summary>
IEnumerable<int> NewLevels { get; }
/// <summary>Gets the <see cref="IProfession"/>s associated with this skill.</summary>
IList<IProfession> Professions { get; }
/// <summary>Gets the <see cref="ProfessionPair"/>s offered by this skill.</summary>
IDictionary<int, ProfessionPair> ProfessionPairs { get; }
/// <summary>Gets integer ids used in-game to track professions acquired by the player.</summary>
IEnumerable<int> ProfessionIds => this.Professions.Select(p => p.Id);
/// <summary>Gets subset of <see cref="ProfessionIds"/> containing only the level five profession ids.</summary>
/// <remarks>Should always contain exactly 2 elements.</remarks>
IEnumerable<int> TierOneProfessionIds => this.ProfessionIds.Take(2);
/// <summary>Gets subset of <see cref="ProfessionIds"/> containing only the level ten profession ids.</summary>
/// <remarks>
/// Should always contains exactly 4 elements. The elements are assumed to be ordered correctly with respect to
/// <see cref="TierOneProfessionIds"/>, such that elements 0 and 1 in this array correspond to branches of element 0
/// in the latter, and elements 2 and 3 correspond to branches of element 1.
/// </remarks>
IEnumerable<int> TierTwoProfessionIds => this.ProfessionIds.TakeLast(4);
/// <summary>Gets the local player's acquired professions from this skill.</summary>
IProfession[] AcquiredProfessions => Game1.player.GetProfessionsForSkill(this, true);
/// <summary>Gets the experience required for each level up.</summary>
internal static int[] ExperienceCurve { get; } =
{
0,
100,
380,
770,
1300,
2150,
3300,
4800,
6900,
10000,
ExpAtLevel10,
ExpAtLevel10 + (int)ProfessionsModule.Config.Prestige.ExpPerPrestigeLevel,
ExpAtLevel10 + ((int)ProfessionsModule.Config.Prestige.ExpPerPrestigeLevel * 2),
ExpAtLevel10 + ((int)ProfessionsModule.Config.Prestige.ExpPerPrestigeLevel * 3),
ExpAtLevel10 + ((int)ProfessionsModule.Config.Prestige.ExpPerPrestigeLevel * 4),
ExpAtLevel10 + ((int)ProfessionsModule.Config.Prestige.ExpPerPrestigeLevel * 5),
ExpAtLevel10 + ((int)ProfessionsModule.Config.Prestige.ExpPerPrestigeLevel * 6),
ExpAtLevel10 + ((int)ProfessionsModule.Config.Prestige.ExpPerPrestigeLevel * 7),
ExpAtLevel10 + ((int)ProfessionsModule.Config.Prestige.ExpPerPrestigeLevel * 8),
ExpAtLevel10 + ((int)ProfessionsModule.Config.Prestige.ExpPerPrestigeLevel * 9),
ExpAtLevel10 + ((int)ProfessionsModule.Config.Prestige.ExpPerPrestigeLevel * 10),
};
/// <summary>Adds experience points for this skill.</summary>
/// <param name="amount">The amount of experience to add.</param>
void AddExperience(int amount);
/// <summary>Sets the level of this skill.</summary>
/// <param name="level">The new level.</param>
/// <remarks>Will not affect professions or recipes.</remarks>
void SetLevel(int level);
/// <summary>Determines whether this skill can be reset for Prestige.</summary>
/// <returns><see langword="true"/> if the local player meets all reset conditions, otherwise <see langword="false"/>.</returns>
bool CanReset()
{
var farmer = Game1.player;
var isSkillLevelTen = this.CurrentLevel >= 10;
if (!isSkillLevelTen)
{
Log.D($"[Prestige]: {this.StringId} skill cannot be reset because it's level is lower than 10.");
return false;
}
var justLeveledUp = this.NewLevels.Contains(10);
if (justLeveledUp)
{
Log.D($"[Prestige]: {this.StringId} skill cannot be reset because {farmer.Name} has not yet seen the level-up menu.");
return false;
}
var hasProfessionsLeftToAcquire = farmer.GetProfessionsForSkill(this, true).Length.IsIn(1..3);
if (!hasProfessionsLeftToAcquire)
{
Log.D(
$"[Prestige]: {this.StringId} skill cannot be reset because {farmer.Name} either already has all professions in the skill, or has none at all.");
return false;
}
var alreadyResetThisSkill = ProfessionsModule.State.SkillsToReset.Contains(this);
if (alreadyResetThisSkill)
{
Log.D($"[Prestige]: {this.StringId} skill has already been marked for reset tonight.");
return false;
}
return true;
}
/// <summary>Gets the cost of resetting this skill.</summary>
/// <returns>A sum of gold to be paid.</returns>
int GetResetCost()
{
var multiplier = ProfessionsModule.Config.Prestige.SkillResetCostMultiplier;
if (multiplier <= 0f)
{
return 0;
}
var baseCost = this.AcquiredProfessions.Length switch
{
1 => 10000,
2 => 50000,
3 => 100000,
_ => 0,
};
return (int)(baseCost * multiplier);
}
/// <summary>Resets the skill for Prestige.</summary>
void Reset();
/// <summary>Removes all recipes associated with this skill from the local player.</summary>
/// <param name="saveForRecovery">Whether to store crafted quantities for later recovery.</param>
void ForgetRecipes(bool saveForRecovery = true);
/// <summary>Determines whether this skill can gain Prestige Levels.</summary>
/// <returns><see langword="true"/> if the local player meets all Prestige conditions, otherwise <see langword="false"/>.</returns>
bool CanGainPrestigeLevels();
/// <summary>Determines whether this skill's level matches the expected level for the current experience, and if not fixes those levels.</summary>
void Revalidate();
/// <summary>Determines whether any skill at all can be reset for Prestige.</summary>
/// <returns><see langword="true"/> if at least one vanilla or loaded custom skill can be reset, otherwise <see langword="false"/>.</returns>
internal static bool CanResetAny()
{
return Skill.List.Any(s => ((ISkill)s).CanReset()) || CustomSkill.Loaded.Values.Any(s => s.CanReset());
}
/// <summary>Revalidates all vanilla and custom skills.</summary>
internal static void RevalidateAll()
{
Skill.List.ForEach(s => s.Revalidate());
CustomSkill.Loaded.Values.ForEach(s => s.Revalidate());
}
}