11using Celeste . Mod . CollabUtils2 . UI ;
22using Celeste . Mod . Entities ;
3+ using Celeste . Pico8 ;
34using Microsoft . Xna . Framework ;
45using Microsoft . Xna . Framework . Graphics ;
56using Monocle ;
7+ using System ;
68using System . Collections ;
79
810namespace Celeste . Mod . CollabUtils2 . Entities {
@@ -47,7 +49,8 @@ public override void Added(Scene scene) {
4749 }
4850
4951 private void onTalk ( Player player ) {
50- if ( player . Scene is Level level ) {
52+ // don't allow this to somehow trigger twice from the same action
53+ if ( player . Scene is Level level && level . CanRetry ) {
5154 level . CanRetry = false ;
5255 if ( level . Tracker . GetEntity < LobbyMapController > ( ) is LobbyMapController lmc ) {
5356 lmc . VisitManager ? . ActivateWarp ( info . MarkerId ) ;
@@ -65,6 +68,15 @@ private IEnumerator activateRoutine(Player player) {
6568
6669 player . StateMachine . State = Player . StDummy ;
6770 yield return player . DummyWalkToExact ( ( int ) X , false , 1f , true ) ;
71+
72+ // handle the case where we're dead or not on the ground in front of it
73+ if ( ! validPlayer ( player ) ) {
74+ if ( ! player . Dead ) {
75+ player . StateMachine . State = Player . StNormal ;
76+ }
77+ yield break ;
78+ }
79+
6880 player . Facing = playerFacing ;
6981
7082 player . Sprite . Visible = player . Hair . Visible = false ;
@@ -82,11 +94,19 @@ private IEnumerator activateRoutine(Player player) {
8294
8395 Audio . Play ( "event:/char/madeline/backpack_drop" ) ;
8496
85- while ( playerSprite . Animating ) {
97+ // loop until animation is finished or the player can no longer use the bench
98+ while ( playerSprite . Animating && validPlayer ( player ) ) {
99+ // force dummy state while animating
100+ player . StateMachine . State = Player . StDummy ;
86101 yield return null ;
87102 }
88103
89- player . Scene . Add ( new LobbyMapUI ( ) ) ;
104+ // show the UI if the player successfully sat down
105+ if ( validPlayer ( player ) ) {
106+ player . Scene . Add ( new LobbyMapUI ( ) ) ;
107+ } else {
108+ player . StateMachine . State = Player . StNormal ;
109+ }
90110
91111 yield return 0.5f ;
92112
@@ -95,5 +115,10 @@ private IEnumerator activateRoutine(Player player) {
95115
96116 player . Sprite . Visible = player . Hair . Visible = true ;
97117 }
118+
119+ private bool validPlayer ( Player player ) {
120+ // validates that the player is standing on the ground in front of the bench, and isn't dead
121+ return ( Center - player . Center ) . LengthSquared ( ) < 16 * 16 && ! player . Dead && player . OnGround ( ) ;
122+ }
98123 }
99124}
0 commit comments