P2P host lobby: CONTINUE own save or NEW GAME (previous save backed up to MSCO_Saves, new world saved and sent to waiting players)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+54
-2
@@ -790,11 +790,57 @@ namespace MSCO
|
||||
public void StartHostGame()
|
||||
{
|
||||
if (!IsHost || !MenuHelper.InMenu) return;
|
||||
newGamePending = false;
|
||||
SendSaveToWaitingPlayers();
|
||||
SetStatus("Starting game...");
|
||||
MenuHelper.StartGame();
|
||||
}
|
||||
|
||||
// Host hat ein neues Spiel gestartet: es gibt noch keinen Spielstand zum Verschicken - erst im Spiel speichern
|
||||
bool newGamePending;
|
||||
|
||||
/// <summary>
|
||||
/// Host: neues Spiel statt des eigenen Spielstands. Der bisherige Spielstand wird gesichert (MSCO_Saves), die
|
||||
/// Welt frisch angelegt; die Mitspieler bekommen sie, sobald sie einmal gespeichert ist.
|
||||
/// </summary>
|
||||
public void StartHostNewGame()
|
||||
{
|
||||
if (!IsHost || !MenuHelper.InMenu) return;
|
||||
string archived;
|
||||
try { archived = SaveSync.ArchiveForNewGame(); }
|
||||
catch (System.Exception e)
|
||||
{
|
||||
// Lieber gar nicht starten, als den Spielstand ungesichert zu löschen
|
||||
MscoLog.Error("[MSCO] Could not back up your save game - new game cancelled: " + e.Message);
|
||||
SetStatus("Could not back up your save game - new game cancelled");
|
||||
return;
|
||||
}
|
||||
newGamePending = true;
|
||||
if (archived != null) overlays.Log("Your previous save game was backed up to " + archived);
|
||||
SetStatus("Starting a new game...");
|
||||
MenuHelper.StartNewGame();
|
||||
}
|
||||
|
||||
/// <summary>Neues Spiel geladen: warten, bis die Welt steht, speichern und an die wartenden Mitspieler schicken.</summary>
|
||||
System.Collections.IEnumerator NewGameSaveAndSend()
|
||||
{
|
||||
float give = Time.realtimeSinceStartup + 60f;
|
||||
while (localPlayer == null && Time.realtimeSinceStartup < give) yield return new WaitForSeconds(0.5f);
|
||||
yield return new WaitForSeconds(3f); // Spielwelt erst fertig aufbauen lassen
|
||||
if (!newGamePending || session == null || !session.IsHost || !MenuHelper.InGame) yield break;
|
||||
SaveGame();
|
||||
yield return new WaitForSeconds(LateJoinSaveDelay);
|
||||
newGamePending = false;
|
||||
var targets = new List<PlayerInfo>();
|
||||
foreach (PlayerInfo p in players.Values)
|
||||
if (!p.IsLocal && !p.SaveSent) targets.Add(p);
|
||||
if (targets.Count > 0)
|
||||
{
|
||||
SendSave(targets, true);
|
||||
SetStatus("New game sent to " + targets.Count + " player(s)");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Speichert wie die Toilette: das Spiel schickt allen FSMs das globale Event "SAVEGAME".
|
||||
/// Nur der Host speichert, Clients haben nur eine Kopie seines Spielstands.
|
||||
@@ -1582,6 +1628,7 @@ namespace MSCO
|
||||
|
||||
void SendSaveToWaitingPlayers()
|
||||
{
|
||||
if (newGamePending) return; // neues Spiel: es gibt noch keinen Spielstand - kommt nach dem ersten Speichern
|
||||
var targets = new List<PlayerInfo>();
|
||||
foreach (PlayerInfo p in players.Values)
|
||||
if (!p.IsLocal && !p.SaveSent) targets.Add(p);
|
||||
@@ -1630,8 +1677,12 @@ namespace MSCO
|
||||
nextPresenceUpdate = 0f; // Discord gleich nach dem Szenenwechsel aktualisieren
|
||||
if (MenuHelper.InGame)
|
||||
{
|
||||
// Falls der CONTINUE-Klick nicht erkannt wurde: jetzt nachholen
|
||||
if (session != null && session.IsHost) SendSaveToWaitingPlayers();
|
||||
// Falls der CONTINUE-Klick nicht erkannt wurde: jetzt nachholen. Neues Spiel: erst speichern, dann senden
|
||||
if (session != null && session.IsHost)
|
||||
{
|
||||
if (newGamePending) StartCoroutine(NewGameSaveAndSend());
|
||||
else SendSaveToWaitingPlayers();
|
||||
}
|
||||
passenger.Reset();
|
||||
localPlayer = null;
|
||||
objects.OnGameLoaded();
|
||||
@@ -1653,6 +1704,7 @@ namespace MSCO
|
||||
DestroyAvatar(p);
|
||||
}
|
||||
continueFsm = null;
|
||||
newGamePending = false;
|
||||
passenger.Reset();
|
||||
localPlayer = null;
|
||||
objects.Reset();
|
||||
|
||||
Reference in New Issue
Block a user