Skip to content

Commit 35ed908

Browse files
authored
Merge pull request #80 from swoolcock/swoolcock/lobby-map-fix-storage
Abort displaying the lobby map if the player is not standing in front
2 parents cc47d90 + 47180c1 commit 35ed908

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

Entities/LobbyMapWarp.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using Celeste.Mod.CollabUtils2.UI;
22
using Celeste.Mod.Entities;
3+
using Celeste.Pico8;
34
using Microsoft.Xna.Framework;
45
using Microsoft.Xna.Framework.Graphics;
56
using Monocle;
7+
using System;
68
using System.Collections;
79

810
namespace 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
}

UI/LobbyMapUI.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ public override void Removed(Scene scene) {
139139
public override void Update() {
140140
base.Update();
141141

142+
// if we're somehow not on the ground, bail
143+
if (Scene?.Tracker.GetEntity<Player>()?.OnGround() != true) {
144+
closeScreen();
145+
return;
146+
}
147+
142148
// handle input
143149
if (focused) {
144150
if (activeWarps.Count > 0) {

0 commit comments

Comments
 (0)