1
0
forked from akanyan/mu3-mods

fix(BetterGiveUp): proper hard resets

This commit is contained in:
2024-12-28 01:18:33 +00:00
parent e5e177f226
commit 4f0cf6b327
5 changed files with 78 additions and 61 deletions

View File

@ -0,0 +1,7 @@
using MU3.Util;
namespace MU3.Mod;
class State: Singleton<State> {
public bool SkipPlay { get; set; }
}

View File

@ -11,81 +11,45 @@ namespace MU3.Sequence;
class patch_PlayMusic: PlayMusic {
private static readonly TimeSpan HOLD_DURATION = TimeSpan.FromSeconds(1.0f);
private static readonly TimeSpan ROLL_DURATION = TimeSpan.FromSeconds(0.5f);
public static bool QuickSkip = false;
private GameEngine _gameEngine;
private SessionInfo _sessionInfo;
private patch_NotesManager ntMgr => (patch_NotesManager)_gameEngine?.notesManager;
private bool _pressedYellow;
private bool _isRolling;
private float _totalRollingFrame;
private DateTime _rollingStartTime;
private bool _isHoldingAck;
private DateTime _holdingStartTime;
private float enemyPosX;
private patch_NotesManager ntMgr => (patch_NotesManager)_gameEngine?.notesManager;
private float _enemyPosX;
[MonoModIgnore]
private extern bool isPartyPlay();
public static double FadeOut(double progress, double min, double max) {
return min + (max - min) * (1.0 - Math.Pow(1.0 - progress, 2.0));
}
public static double FadeIn(double progress, double min, double max) {
return min + (max - min) * Math.Pow(progress, 2.0);
}
private bool IsHolding() {
return Singleton<UIInput>.instance.getStateOn(UIInput.Key.MenuLeft)
^ (_pressedYellow && Singleton<UIInput>.instance.getStateOn(UIInput.Key.MenuRight));
}
private void StartRolling() {
_pressedYellow = false;
_isRolling = true;
_totalRollingFrame = ntMgr.getCurrentFrame();
_rollingStartTime = CustomDateTime.Now;
enemyPosX = ntMgr.getEnemyPos().x;
ntMgr.forceRecover(recover: 100);
Singleton<GameSound>.instance.gameBGM.stop();
}
private void EndRolling() {
_isRolling = false;
ntMgr.stopPlay();
ntMgr.setPause(false);
ntMgr.reset();
ntMgr.reloadScore(_gameEngine.IsStageDazzling);
_gameEngine.counters.reset();
_gameEngine.battleReward.initialize(_sessionInfo);
_gameEngine.enemyManager.destroy();
_gameEngine.enemyManager.initialize();
_gameEngine.reset();
Singleton<GameSound>.instance.gameBGM.playMusic(_sessionInfo.musicData, 0);
ntMgr.startPlay(0.0f);
ntMgr.led.setGameColor(true);
}
private extern void orig_Execute_Play();
private void Execute_Play() {
if(isPartyPlay()) {
if(isPartyPlay() || _sessionInfo.isTutorial) {
orig_Execute_Play();
return;
}
if(Singleton<UIInput>.instance.getTriggerOn(UIInput.Key.MenuRight)) {
_pressedYellow = true;
}
if(_isRolling) {
TimeSpan timeSpan = CustomDateTime.Now - _rollingStartTime;
if(timeSpan <= ROLL_DURATION) {
double num1 = FadeOut(timeSpan.TotalMilliseconds / ROLL_DURATION.TotalMilliseconds, 0.0, 1.0);
double num2 = FadeIn(timeSpan.TotalMilliseconds / ROLL_DURATION.TotalMilliseconds, 0.0, 1.0);
double num1 = fadeOut(timeSpan.TotalMilliseconds / ROLL_DURATION.TotalMilliseconds, 0.0, 1.0);
double num2 = fadeIn(timeSpan.TotalMilliseconds / ROLL_DURATION.TotalMilliseconds, 0.0, 1.0);
ntMgr.setFrameForce(_totalRollingFrame * (float)(1.0 - num1));
ntMgr.enemyOffset = new Vector3(
ntMgr.enemyOffset.x + (enemyPosX - ntMgr.getEnemyPos().x), 20f * (float)num2, 0.0f
ntMgr.enemyOffset.x + (_enemyPosX - ntMgr.getEnemyPos().x), 20f * (float)num2, 0.0f
);
} else {
EndRolling();
endRolling();
}
} else if(IsHolding() && !_sessionInfo.isTutorial) {
} else if(isHolding()) {
if(!_isHoldingAck) {
_holdingStartTime = CustomDateTime.Now;
_isHoldingAck = true;
@ -95,12 +59,12 @@ class patch_PlayMusic: PlayMusic {
if(ts > HOLD_DURATION) {
if(Singleton<UIInput>.instance.getStateOn(UIInput.Key.MenuRight)) {
if(ntMgr.retireResult != RetireResult.None) {
setNextState(EState.Init);
hardReset();
} else {
StartRolling();
startRolling();
}
} else {
QuickSkip = true;
Singleton<Mod.State>.instance.SkipPlay = true;
setNextState(EState.End);
destroy();
ntMgr.stopPlay();
@ -115,10 +79,58 @@ class patch_PlayMusic: PlayMusic {
}
}
private static double fadeOut(double progress, double min, double max) {
return min + (max - min) * (1.0 - Math.Pow(1.0 - progress, 2.0));
}
private static double fadeIn(double progress, double min, double max) {
return min + (max - min) * Math.Pow(progress, 2.0);
}
private bool isHolding() {
return Singleton<UIInput>.instance.getStateOn(UIInput.Key.MenuLeft)
^ (_pressedYellow && Singleton<UIInput>.instance.getStateOn(UIInput.Key.MenuRight));
}
private void hardReset() {
ntMgr.stopPlay();
ntMgr.setPause(false);
_gameEngine.reset();
Singleton<GameSound>.instance.gameBGM.stop();
setNextState(EState.Init);
}
private void startRolling() {
_pressedYellow = false;
_isRolling = true;
_totalRollingFrame = ntMgr.getCurrentFrame();
_rollingStartTime = CustomDateTime.Now;
_enemyPosX = ntMgr.getEnemyPos().x;
ntMgr.forceRecover(recover: 100);
Singleton<GameSound>.instance.gameBGM.stop();
}
private void endRolling() {
_isRolling = false;
ntMgr.stopPlay();
ntMgr.setPause(false);
ntMgr.reset();
_gameEngine.counters.reset();
_gameEngine.enemyManager.destroy();
ntMgr.reloadScore(_gameEngine.IsStageDazzling);
_gameEngine.battleReward.initialize(_sessionInfo);
_gameEngine.enemyManager.initialize();
_gameEngine.reset();
ntMgr.startPlay(0.0f);
ntMgr.led.setGameColor(true);
Singleton<GameSound>.instance.gameBGM.playMusic(_sessionInfo.musicData, 0);
}
private void listenForPanicRestart() {
if(Singleton<UIInput>.instance.getTriggerOn(UIInput.Key.MenuRight) && ntMgr.retireResult != RetireResult.None && !isPartyPlay()) {
Singleton<GameSound>.instance.gameBGM.stop();
setNextState(EState.Init);
hardReset();
}
}

View File

@ -1,4 +1,4 @@
using MU3.Sequence;
using MU3.Util;
namespace MU3;
@ -6,8 +6,8 @@ class patch_Scene_32_PrePlayMusic_MusicSelect: Scene_32_PrePlayMusic_MusicSelect
private bool _playVoice;
private extern void orig_Enter_Select();
private void Enter_Select() {
if(patch_PlayMusic.QuickSkip) {
patch_PlayMusic.QuickSkip = false;
if(Singleton<Mod.State>.instance.SkipPlay) {
Singleton<Mod.State>.instance.SkipPlay = false;
_playVoice = false;
}
orig_Enter_Select();

View File

@ -1,5 +1,4 @@
using MonoMod;
using MU3.Sequence;
using MU3.Util;
namespace MU3;
@ -15,7 +14,7 @@ class patch_Scene_37_Result: Scene_37_Result {
private extern void orig_Init_Init();
private void Init_Init() {
orig_Init_Init();
if(patch_PlayMusic.QuickSkip) {
if(Singleton<Mod.State>.instance.SkipPlay) {
mode_.set(State.End);
}
}

View File

@ -1,5 +1,4 @@
using MonoMod;
using MU3.Sequence;
using MU3.Util;
namespace MU3;
@ -18,7 +17,7 @@ class patch_Scene_38_End: Scene_38_End {
private void Init_Init() {
orig_Init_Init();
if(patch_PlayMusic.QuickSkip) {
if(Singleton<Mod.State>.instance.SkipPlay) {
result_ = 0;
mode_.set(State.End);
}
@ -27,7 +26,7 @@ class patch_Scene_38_End: Scene_38_End {
private void End_Init() {
SystemUI instance = SingletonMonoBehaviour<SystemUI>.instance;
instance.Panel.popState();
if(!patch_PlayMusic.QuickSkip) {
if(!Singleton<Mod.State>.instance.SkipPlay) {
instance.fadeOut();
}
commonWindow_.end();