Stomp: Fixed issues associated with specific cue setups.

This commit is contained in:
Jenny Crowe 2022-03-13 03:25:41 -07:00
parent 5a9cf5507a
commit 3a6df6035b

View file

@ -24,6 +24,7 @@ namespace RhythmHeavenMania.Games
private int currentMarchBeat; private int currentMarchBeat;
private int stepCount; private int stepCount;
private bool isStepping; private bool isStepping;
private static float inactiveStart = -1f; private static float inactiveStart = -1f;
public bool isMarching => marchStartBeat != -1f; public bool isMarching => marchStartBeat != -1f;
@ -66,20 +67,48 @@ namespace RhythmHeavenMania.Games
var cond = Conductor.instance; var cond = Conductor.instance;
var entities = GameManager.instance.Beatmap.entities; var entities = GameManager.instance.Beatmap.entities;
// Find the beat of the closest "start marching" event.
// If not found, default to current beat.
float startBeat = cond.songPositionInBeats; float startBeat = cond.songPositionInBeats;
var marchStarts = entities.FindAll(m => m.datamodel == "cropStomp/start marching"); if (inactiveStart == -1f)
for (int i = 0; i < marchStarts.Count; i++)
{ {
var sampleBeat = marchStarts[i].beat; // Find the beat of the closest "start marching" event.
if (cond.songPositionInBeats <= sampleBeat + 0.25f) // 0.25-beat buffer in case the start marching event is directly next to the game switch event. var marchStarts = entities.FindAll(m => m.datamodel == "cropStomp/start marching");
for (int i = 0; i < marchStarts.Count; i++)
{ {
startBeat = sampleBeat; var sampleBeat = marchStarts[i].beat;
break; if (cond.songPositionInBeats <= sampleBeat + 0.25f) // 0.25-beat buffer in case the start marching event is directly next to the game switch event.
{
startBeat = sampleBeat;
break;
}
} }
} }
else
{
// Find the beat of the next step, assuming marching started at inactiveStart.
int stepsPassed = 0;
while (inactiveStart + (stepsPassed * 2f) < cond.songPositionInBeats)
{
stepsPassed++;
if (stepsPassed > 1000)
{
Debug.Log("Loop broke!");
return;
}
}
startBeat = inactiveStart + (stepsPassed * 2f);
// Cue the marching proper to begin when applicable.
BeatAction.New(gameObject, new List<BeatAction.Action>()
{
new BeatAction.Action(startBeat, delegate { StartMarching(startBeat); })
});
inactiveStart = -1f;
}
// Veggie and mole events. // Veggie and mole events.
var vegEvents = entities.FindAll(v => v.datamodel == "cropStomp/veggies"); var vegEvents = entities.FindAll(v => v.datamodel == "cropStomp/veggies");
@ -92,14 +121,14 @@ namespace RhythmHeavenMania.Games
var vegLength = vegEvents[i].length; var vegLength = vegEvents[i].length;
// Only consider veggie events that aren't past the start point. // Only consider veggie events that aren't past the start point.
if (startBeat < vegBeat + vegLength) if (startBeat <= vegBeat + vegLength)
{ {
int veggiesInEvent = Mathf.CeilToInt(vegLength + 1) / 2; int veggiesInEvent = Mathf.CeilToInt(vegLength + 1) / 2;
for (int b = 0; b < veggiesInEvent; b++) for (int b = 0; b < veggiesInEvent; b++)
{ {
var targetVeggieBeat = vegBeat + 2f * b; var targetVeggieBeat = vegBeat + 2f * b;
if (startBeat < targetVeggieBeat) if (startBeat <= targetVeggieBeat)
{ {
SpawnVeggie(targetVeggieBeat, startBeat, false); SpawnVeggie(targetVeggieBeat, startBeat, false);
} }
@ -112,28 +141,13 @@ namespace RhythmHeavenMania.Games
{ {
var moleBeat = moleEvents[i].beat; var moleBeat = moleEvents[i].beat;
if (startBeat < moleBeat) if (startBeat <= moleBeat)
{ {
SpawnVeggie(moleBeat, startBeat, true); SpawnVeggie(moleBeat, startBeat, true);
} }
} }
} }
public override void OnGameSwitch(float beat)
{
if(inactiveStart != -1f)
{
StartMarching(inactiveStart);
float diff = beat - marchStartBeat;
newBeat = (Mathf.Ceil(diff) + marchStartBeat-1)*Conductor.instance.secPerBeat;
currentMarchBeat = Mathf.CeilToInt(diff);
stepCount = currentMarchBeat / 2;
farmer.nextStompBeat = newBeat/Conductor.instance.secPerBeat;
inactiveStart = -1f;
PlayAnims();
}
}
List<Beatmap.Entity> cuedMoleSounds = new List<Beatmap.Entity>(); List<Beatmap.Entity> cuedMoleSounds = new List<Beatmap.Entity>();
private void Update() private void Update()
{ {
@ -148,7 +162,7 @@ namespace RhythmHeavenMania.Games
{ {
var moleEvent = moleEvents[i]; var moleEvent = moleEvents[i];
var timeToEvent = moleEvent.beat - cond.songPositionInBeats; var timeToEvent = moleEvent.beat - cond.songPositionInBeats;
if (timeToEvent <= 3f && timeToEvent > 0f && !cuedMoleSounds.Contains(moleEvent)) if (timeToEvent <= 4f && timeToEvent > 2f && !cuedMoleSounds.Contains(moleEvent))
{ {
cuedMoleSounds.Add(moleEvent); cuedMoleSounds.Add(moleEvent);
MultiSound.Play(new MultiSound.Sound[] { new MultiSound.Sound("cropStomp/moleNyeh", (moleEvent.beat - 2f) - moleSoundOffsets[0] * Conductor.instance.songBpm / 60f), MultiSound.Play(new MultiSound.Sound[] { new MultiSound.Sound("cropStomp/moleNyeh", (moleEvent.beat - 2f) - moleSoundOffsets[0] * Conductor.instance.songBpm / 60f),