diff --git a/Enhancements/BetterGiveUp/MU3.Battle/patch_PlayerControl.cs b/Enhancements/BetterGiveUp/MU3.Battle/patch_PlayerControl.cs new file mode 100644 index 0000000..da07272 --- /dev/null +++ b/Enhancements/BetterGiveUp/MU3.Battle/patch_PlayerControl.cs @@ -0,0 +1,19 @@ +using MonoMod; +using UnityEngine; + +namespace MU3.Battle; + +class patch_PlayerControl(PlayerParam param): PlayerControl(param) { + private Vector3? _positionForce = null; + + public extern Vector3 orig_get__playPosition(); + [MonoModPublic] + public new Vector3 _playPosition { + get { + return _positionForce ?? orig_get__playPosition(); + } + set { + _positionForce = value; + } + } +} diff --git a/Enhancements/BetterGiveUp/MU3.Game/patch_GameLED.cs b/Enhancements/BetterGiveUp/MU3.Game/patch_GameLED.cs deleted file mode 100644 index e676c96..0000000 --- a/Enhancements/BetterGiveUp/MU3.Game/patch_GameLED.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Collections.Generic; - -namespace MU3.Game; - -class patch_GameLED: GameLED { - private patch_ButtonList _buttonList = new(); - - public extern void orig_initialize(); - public new void initialize() { - _buttonList.Clear(); - orig_initialize(); - } - - private class patch_ButtonParam { } - private class patch_ButtonList: List { } -} \ No newline at end of file diff --git a/Enhancements/BetterGiveUp/MU3.Notes/patch_FieldObject.cs b/Enhancements/BetterGiveUp/MU3.Notes/patch_FieldObject.cs deleted file mode 100644 index 977f485..0000000 --- a/Enhancements/BetterGiveUp/MU3.Notes/patch_FieldObject.cs +++ /dev/null @@ -1,18 +0,0 @@ -using UnityEngine; - -namespace MU3.Notes; - -class patch_FieldObject: FieldObject { - class patch_BarNotes { - class patch_Bar: BarNotes.Bar { - public extern void orig_update(NotesManager mgr, float width = 1f); - public new void update(NotesManager mgr, float width = 1f) { - orig_update(mgr, width); - if(frameAppear <= (double)mgr.getCurrentFrame() || itemBar == null) { - return; - } - itemBar.go.transform.localScale = Vector3.zero; - } - } - } -} diff --git a/Enhancements/BetterGiveUp/MU3.Notes/patch_NotesManager.cs b/Enhancements/BetterGiveUp/MU3.Notes/patch_NotesManager.cs index cb4f5fa..4c01211 100644 --- a/Enhancements/BetterGiveUp/MU3.Notes/patch_NotesManager.cs +++ b/Enhancements/BetterGiveUp/MU3.Notes/patch_NotesManager.cs @@ -3,14 +3,8 @@ namespace MU3.Notes; class patch_NotesManager: NotesManager { - public Vector3 enemyOffset { get; set; } + public Vector3? EnemyPositionForce { private get; set; } = null; public extern Vector3 orig_getEnemyPos(); - public new Vector3 getEnemyPos() => orig_getEnemyPos() + enemyOffset; - - public extern void orig_reset(); - public new void reset() { - enemyOffset = Vector3.zero; - orig_reset(); - } + public new Vector3 getEnemyPos() => EnemyPositionForce ?? orig_getEnemyPos(); } \ No newline at end of file diff --git a/Enhancements/BetterGiveUp/MU3.Sequence/patch_PlayMusic.cs b/Enhancements/BetterGiveUp/MU3.Sequence/patch_PlayMusic.cs index 7c5cb9f..71ab16b 100644 --- a/Enhancements/BetterGiveUp/MU3.Sequence/patch_PlayMusic.cs +++ b/Enhancements/BetterGiveUp/MU3.Sequence/patch_PlayMusic.cs @@ -4,6 +4,8 @@ using MU3.Game; using MU3.Notes; using MU3.Util; using System; +using System.Collections; +using System.Reflection; using UnityEngine; namespace MU3.Sequence; @@ -12,14 +14,8 @@ class patch_PlayMusic: PlayMusic { private static readonly TimeSpan HOLD_DURATION = TimeSpan.FromSeconds(0.67f); private static readonly TimeSpan ROLL_DURATION = TimeSpan.FromSeconds(0.5f); - private double fadeOut(double progress, double min, double max) - => min + (max - min) * (1.0 - Math.Pow(1.0 - progress, 2.0)); - private double fadeIn(double progress, double min, double max) - => min + (max - min) * Math.Pow(progress, 2.0); - private bool isHolding - => Singleton.instance.getStateOn(UIInput.Key.MenuLeft) - || Singleton.instance.getStateOn(UIInput.Key.MenuRight); - private patch_NotesManager ntMgr => (patch_NotesManager)_gameEngine?.notesManager; + [MonoModIgnore] + private patch_NotesManager ntMgr => null; private GameEngine _gameEngine; private SessionInfo _sessionInfo; @@ -27,10 +23,7 @@ class patch_PlayMusic: PlayMusic { private bool _isRolling; private bool _isHoldingAck; - private float _totalRollingFrame; - private DateTime _rollingStartTime; private DateTime _holdingStartTime; - private float _enemyPosX; [MonoModIgnore] private extern bool isPartyPlay(); @@ -43,36 +36,27 @@ class patch_PlayMusic: PlayMusic { } 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); - ntMgr.setFrameForce(_totalRollingFrame * (float)(1.0 - num1)); - ntMgr.enemyOffset = new Vector3( - ntMgr.enemyOffset.x + (_enemyPosX - ntMgr.getEnemyPos().x), 20f * (float)num2, 0.0f - ); - } else { - endRolling(); - } - } else if(isHolding) { - if(!_isHoldingAck) { - _holdingStartTime = CustomDateTime.Now; - _isHoldingAck = true; - } + return; + } - TimeSpan ts = CustomDateTime.Now - _holdingStartTime; - if(ts > HOLD_DURATION) { + if(Singleton.instance.getTriggerOn(UIInput.Key.MenuLeft) || Singleton.instance.getTriggerOn(UIInput.Key.MenuRight)) { + _holdingStartTime = CustomDateTime.Now; + _isHoldingAck = true; + } + + if(_isHoldingAck && (Singleton.instance.getStateOn(UIInput.Key.MenuLeft) || Singleton.instance.getStateOn(UIInput.Key.MenuRight))) { + if(CustomDateTime.Now - _holdingStartTime > HOLD_DURATION) { if(Singleton.instance.getStateOn(UIInput.Key.MenuRight)) { - startRolling(); + restartPlay(shouldRoll: true); } else { skipPlay(); } } - orig_Execute_Play(); } else { _isHoldingAck = false; - orig_Execute_Play(); } + + orig_Execute_Play(); } private extern void orig_Execute_DispCombo(); @@ -80,8 +64,7 @@ class patch_PlayMusic: PlayMusic { orig_Execute_DispCombo(); if(Singleton.instance.getStateOn(UIInput.Key.MenuRight) && ntMgr.retireResult != RetireResult.None && !isPartyPlay()) { - startRolling(); - endRolling(); + restartPlay(shouldRoll: false); _gameEngine.battleUI.skipDispRetireResult(); setNextState(EState.Play); } @@ -100,18 +83,22 @@ class patch_PlayMusic: PlayMusic { } } - private void startRolling() { - _isRolling = true; - _totalRollingFrame = ntMgr.getCurrentFrame(); - _rollingStartTime = CustomDateTime.Now; - _enemyPosX = ntMgr.getEnemyPos().x; + private void restartPlay(bool shouldRoll) { + _isHoldingAck = false; + _gameEngine.destroyAllies(); ntMgr.forceRecover(recover: 100); Singleton.instance.gameBGM.stop(); + + if(shouldRoll) { + _isRolling = true; + _gameEngine.StartCoroutine(roll()); + } else { + finishRestart(); + } } - private void endRolling() { - _isRolling = false; + private void finishRestart() { _isForceEndBattle = false; ntMgr.stopPlay(); @@ -134,6 +121,42 @@ class patch_PlayMusic: PlayMusic { Singleton.instance.gameBGM.playMusic(_sessionInfo.musicData, 0); } + private IEnumerator roll() { + static float fadeOut(float progress, float min, float max) + => min + (max - min) * (1f - Mathf.Pow(1f - progress, 2f)); + static float fadeIn(float progress, float min, float max) + => min + (max - min) * Mathf.Pow(progress, 2f); + + FieldInfo fi = typeof(Player).GetField("_object", BindingFlags.Instance | BindingFlags.NonPublic); + var po = (PlayerObject)fi.GetValue(_gameEngine.player); + var control = (patch_PlayerControl)po.control; + + po.leaveField(); + + var enemyPos = ntMgr.getEnemyPos(); + var playerPos = control._playPosition; + var finalRollingFrame = ntMgr.getCurrentFrame(); + var rollingStartTime = CustomDateTime.Now; + + while(_isRolling) { + TimeSpan timeSpan = CustomDateTime.Now - rollingStartTime; + if(timeSpan <= ROLL_DURATION) { + float frame = (float)(timeSpan.TotalMilliseconds / ROLL_DURATION.TotalMilliseconds); + float num1 = fadeOut(frame, 0f, 1f); + float num2 = fadeIn(frame, 0f, 1f); + ntMgr.setFrameForce(finalRollingFrame * (1f - num1)); + ntMgr.EnemyPositionForce = new Vector3(enemyPos.x, enemyPos.y + num2 * 215f, enemyPos.z + num2 * 1600f); + control._playPosition = new Vector3(playerPos.x, playerPos.y, playerPos.z - num2 * 10f); + } else { + _isRolling = false; + ntMgr.EnemyPositionForce = null; + finishRestart(); + yield break; + } + yield return new WaitForEndOfFrame(); + } + } + private void skipPlay() { Singleton.instance.SkipPlay = true; setNextState(EState.End);