Skip to content

Commit 073a57a

Browse files
authored
Merge pull request #211 from Quaver/mines-again
2 parents e70ca37 + 45e91c0 commit 073a57a

File tree

9 files changed

+194
-40
lines changed

9 files changed

+194
-40
lines changed

Quaver.API/Enums/HitObjectType.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Quaver.API.Enums
2+
{
3+
/// <summary>
4+
/// Indicates the type of a hit object
5+
/// </summary>
6+
public enum HitObjectType
7+
{
8+
Normal, // Regular hit object. It should be hit normally.
9+
Mine // A mine object. It should not be hit, and hitting it will result in a miss.
10+
}
11+
}

Quaver.API/Maps/Processors/Difficulty/Rulesets/Keys/DifficultyProcessorKeys.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public DifficultyProcessorKeys(Qua map, StrainConstants constants, ModIdentifier
137137
StrainConstants = (StrainConstantsKeys)constants;
138138

139139
// Don't bother calculating map difficulty if there's less than 2 hit objects
140-
if (map.HitObjects.Count < 2)
140+
if (map.DifficultyContributingHitObjects < 2)
141141
return;
142142

143143
// Solve for difficulty
@@ -203,6 +203,8 @@ private void ComputeBaseStrainStates(float rate, Hand assumeHand)
203203
{
204204
if (Map.HasScratchKey && Map.HitObjects[i].Lane == Map.GetKeyCount())
205205
continue;
206+
if (Map.HitObjects[i].Type == HitObjectType.Mine)
207+
continue;
206208

207209
var curHitOb = new StrainSolverHitObject(Map.HitObjects[i]);
208210
var curStrainData = new StrainSolverData(curHitOb, rate);
@@ -675,7 +677,7 @@ private float CalculateOverallDifficulty()
675677
private void ComputeNoteDensityData(float rate)
676678
{
677679
//MapLength = Qua.Length;
678-
AverageNoteDensity = SECONDS_TO_MILLISECONDS * Map.HitObjects.Count / (Map.Length * (-.5f * rate + 1.5f));
680+
AverageNoteDensity = SECONDS_TO_MILLISECONDS * Map.DifficultyContributingHitObjects / (Map.Length * (-.5f * rate + 1.5f));
679681
}
680682

681683
/// <summary>

Quaver.API/Maps/Processors/Scoring/ScoreProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public ScoreProcessor(Replay replay, JudgementWindows windows = null)
223223
/// <summary>
224224
/// Adds a judgement to the score and recalculates the score.
225225
/// </summary>
226-
public abstract void CalculateScore(Judgement judgement, bool isLongNoteRelease = false);
226+
public abstract void CalculateScore(Judgement judgement, bool isLongNoteRelease = false, bool isMine = false);
227227

228228
/// <summary>
229229
/// Calculates the accuracy of the current play session.

Quaver.API/Maps/Processors/Scoring/ScoreProcessorKeys.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Quaver.API.Maps.Processors.Scoring.Data;
1515
using Quaver.API.Maps.Processors.Scoring.Multiplayer;
1616
using Quaver.API.Replays;
17+
using HitObjectType = Quaver.API.Enums.HitObjectType;
1718

1819
namespace Quaver.API.Maps.Processors.Scoring
1920
{
@@ -173,7 +174,9 @@ public ScoreProcessorKeys(Replay replay, JudgementWindows windows = null) : base
173174
/// <param name="hitDifference"></param>
174175
/// <param name="keyPressType"></param>
175176
/// <param name="calculateAllStats"></param>
176-
public Judgement CalculateScore(int hitDifference, KeyPressType keyPressType, bool calculateAllStats = true)
177+
/// <param name="isMine"></param>
178+
public Judgement CalculateScore(int hitDifference, KeyPressType keyPressType, bool calculateAllStats = true,
179+
bool isMine = false)
177180
{
178181
var absoluteDifference = 0;
179182

@@ -222,18 +225,25 @@ public Judgement CalculateScore(int hitDifference, KeyPressType keyPressType, bo
222225
return judgement;
223226

224227
if (calculateAllStats)
225-
CalculateScore(judgement, keyPressType == KeyPressType.Release);
228+
CalculateScore(judgement, keyPressType == KeyPressType.Release, isMine);
226229

227230
return judgement;
228231
}
229232

233+
public void CalculateScore(HitStat hitStat)
234+
{
235+
CalculateScore(hitStat.Judgement, hitStat.KeyPressType == KeyPressType.Release,
236+
hitStat.HitObject.Type is HitObjectType.Mine);
237+
}
238+
230239
/// <inheritdoc />
231240
/// <summary>
232241
/// Calculate Score and Health increase/decrease with a given judgement.
233242
/// </summary>
234243
/// <param name="judgement"></param>
235244
/// <param name="isLongNoteRelease"></param>
236-
public override void CalculateScore(Judgement judgement, bool isLongNoteRelease = false)
245+
/// <param name="isMine"></param>
246+
public override void CalculateScore(Judgement judgement, bool isLongNoteRelease = false, bool isMine = false)
237247
{
238248
// Update Judgement count
239249
CurrentJudgements[judgement]++;
@@ -257,7 +267,9 @@ public override void CalculateScore(Judgement judgement, bool isLongNoteRelease
257267
MultiplierCount++;
258268

259269
// Add to the combo since the user hit.
260-
Combo++;
270+
// Only do this when the note is not a mine (so it is a regular note)
271+
if (!isMine)
272+
Combo++;
261273

262274
// Set the max combo if applicable.
263275
if (Combo > MaxCombo)
@@ -372,17 +384,7 @@ protected override void InitializeHealthWeighting()
372384
/// <returns></returns>
373385
public int GetTotalJudgementCount()
374386
{
375-
var judgements = 0;
376-
377-
foreach (var o in Map.HitObjects)
378-
{
379-
if (o.IsLongNote)
380-
judgements += 2;
381-
else
382-
judgements++;
383-
}
384-
385-
return judgements;
387+
return Map.HitObjects.Sum(o => o.JudgementCount);
386388
}
387389

388390
/// <summary>

Quaver.API/Maps/Qua.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ namespace Quaver.API.Maps
2727
public class Qua
2828
{
2929
// 0 versioning added
30+
// 1 mines
3031
public int QuaVersion { get; set; } = 0;
3132

3233
// Max supported version by this client
3334
// This should be incremented whenever breaking changes are made to quas
3435
// DetermineMinimumQuaVersion() should also be updated to allow older clients to load maps without new features
35-
public const int CurrentQuaVersion = 0;
36+
public const int CurrentQuaVersion = 1;
3637

3738
/// <summary>
3839
/// The name of the audio file
@@ -193,6 +194,19 @@ public List<ScrollSpeedFactorInfo> ScrollSpeedFactors
193194
/// </summary>
194195
public List<HitObjectInfo> HitObjects { get; private set; } = new List<HitObjectInfo>();
195196

197+
/// <summary>
198+
/// Number of mines in the map
199+
/// </summary>
200+
[YamlIgnore]
201+
public int MineCount => HitObjects.Count(x => x.Type is HitObjectType.Mine);
202+
203+
/// <summary>
204+
/// Number of notes counted for diffcalc.
205+
/// Currently, it's every note except mines
206+
/// </summary>
207+
[YamlIgnore]
208+
public int DifficultyContributingHitObjects => HitObjects.Count - MineCount;
209+
196210
public Dictionary<string, TimingGroup> TimingGroups { get; private set; } =
197211
new Dictionary<string, TimingGroup>();
198212

@@ -314,7 +328,19 @@ private bool CompareTimingGroups(Dictionary<string, TimingGroup> other)
314328

315329
public int DetermineMinimumQuaVersion()
316330
{
317-
return 0;
331+
int ver = 0;
332+
333+
void Check(int v, Func<bool> f)
334+
{
335+
if (ver < v && f())
336+
{
337+
ver = v;
338+
}
339+
}
340+
341+
Check(1, () => MineCount != 0);
342+
343+
return ver;
318344
}
319345

320346
/// <summary>
@@ -373,7 +399,8 @@ static HitObjectInfo SerializableHitObject(HitObjectInfo obj) =>
373399
.Select(x => new KeySoundInfo { Sample = x.Sample, Volume = x.Volume == 100 ? 0 : x.Volume })
374400
.ToList(),
375401
Lane = obj.Lane, StartTime = obj.StartTime,
376-
TimingGroup = obj.TimingGroup == DefaultScrollGroupId ? null : obj.TimingGroup
402+
TimingGroup = obj.TimingGroup == DefaultScrollGroupId ? null : obj.TimingGroup,
403+
Type = obj.Type
377404
};
378405

379406
static SoundEffectInfo SerializableSoundEffect(SoundEffectInfo x) =>
@@ -1117,8 +1144,15 @@ public HitObjectInfo GetHitObjectAtJudgementIndex(int index)
11171144

11181145
// ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator
11191146
foreach (var h in HitObjects)
1120-
if (total++ == index || (h.IsLongNote && total++ == index))
1147+
{
1148+
var judgementCount = h.JudgementCount;
1149+
if (total <= index && index < total + judgementCount)
1150+
{
11211151
return h;
1152+
}
1153+
1154+
total += judgementCount;
1155+
}
11221156

11231157
return null;
11241158
}

Quaver.API/Maps/Structures/HitObjectInfo.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public HitSounds HitSound
6464
set;
6565
}
6666

67+
/// <summary>
68+
/// The hit object could be a normal note or a mine
69+
/// </summary>
70+
public HitObjectType Type { get; [MoonSharpVisible(false)] set; }
71+
6772
/// <summary>
6873
/// Key sounds to play when this object is hit.
6974
/// </summary>
@@ -95,6 +100,11 @@ public string TimingGroup
95100
[YamlIgnore]
96101
public bool IsLongNote => EndTime > 0;
97102

103+
/// <summary>
104+
/// The number of judgements generated by this object
105+
/// </summary>
106+
[YamlIgnore] public int JudgementCount => IsLongNote && Type != HitObjectType.Mine ? 2 : 1;
107+
98108
/// <summary>
99109
/// Returns if the object is allowed to be edited in lua scripts
100110
/// </summary>
@@ -175,6 +185,7 @@ public bool Equals(HitObjectInfo x, HitObjectInfo y)
175185
x.Lane == y.Lane &&
176186
x.EndTime == y.EndTime &&
177187
x.HitSound == y.HitSound &&
188+
x.Type == y.Type &&
178189
x.KeySounds.SequenceEqual(y.KeySounds, KeySoundInfo.ByValueComparer) &&
179190
x.EditorLayer == y.EditorLayer;
180191
}
@@ -186,6 +197,7 @@ public int GetHashCode(HitObjectInfo obj)
186197
var hashCode = obj.StartTime;
187198
hashCode = (hashCode * 397) ^ obj.Lane;
188199
hashCode = (hashCode * 397) ^ obj.EndTime;
200+
hashCode = (hashCode * 397) ^ (int)obj.Type;
189201
hashCode = (hashCode * 397) ^ (int)obj.HitSound;
190202

191203
foreach (var keySound in obj.KeySounds)

Quaver.API/Replays/Replay.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ public static Replay GeneratePerfectReplayKeys(Replay replay, Qua map)
332332

333333
foreach (var hitObject in map.HitObjects)
334334
{
335+
if (hitObject.Type is HitObjectType.Mine)
336+
continue;
337+
335338
// Add key press frame
336339
nonCombined.Add(new ReplayAutoplayFrame(hitObject, ReplayAutoplayFrameType.Press, hitObject.StartTime, KeyLaneToPressState(hitObject.Lane)));
337340

0 commit comments

Comments
 (0)