Skip to content

Commit

Permalink
queue spawn instead of rejecting
Browse files Browse the repository at this point in the history
now we don't need to notify backend anymore
set "ingame" only after loading screen ends
  • Loading branch information
Govorunb committed Jun 12, 2024
1 parent 398da35 commit 78f6f58
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion SCHIZO/SwarmControl/MessageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void OnRedeem(RedeemMessage msg)
LogSink.Info,
new ShowUsage(command),
new DelegateSink((ref object res) => {
if (res is null or CommonResults.OKResult && msg.Announce)
if (res is null or string or CommonResults.OKResult && msg.Announce)
{
ErrorMessage.AddMessage($"{msg.GetDisplayName()} redeemed {msg.Title}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@ internal record IngameStateChangedMessage : GameMessage
{
public override MessageType MessageType => MessageType.IngameStateChanged;
public bool Ingame { get; set; }
/// <summary>
/// Spawning is forbidden while on land or inside a base/seatruck (prawn suit is fine)
/// </summary>
public bool CanSpawn { get; set; }
}
21 changes: 19 additions & 2 deletions SCHIZO/SwarmControl/Redeems/Spawns/SpawnFiltered.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using System.Collections;
using System.Collections.Generic;
using SCHIZO.Commands.Base;
using SCHIZO.Commands.ConsoleCommands;
using SCHIZO.Commands.Context;
using SCHIZO.Commands.Input;
using SCHIZO.Commands.Output;
using UnityEngine;
using UWE;

namespace SCHIZO.SwarmControl.Redeems.Spawns;

Expand All @@ -31,8 +34,16 @@ public SpawnFiltered() : base("spawn")
protected override object? ExecuteCore(CommandExecutionContext ctx)
{
if (!SwarmControlManager.Instance.CanSpawn)
return CommonResults.Error("Cannot spawn at this time.");
return base.ExecuteCore(ctx);
{
// return fake OK and queue the actual spawn
JsonContext targetCtx = GetContextForTarget((JsonContext)ctx);
CoroutineHost.StartCoroutine(QueueSpawn(targetCtx));
return "Your spawn redeem is queued.";
}
else
{
return base.ExecuteCore(ctx);
}
}

protected override Dictionary<string, object?>? GetTargetArgs(Dictionary<string, object?>? proxyArgs)
Expand All @@ -56,4 +67,10 @@ public SpawnFiltered() : base("spawn")

return targetArgs;
}

private IEnumerator QueueSpawn(JsonContext ctx)
{
yield return new WaitUntil(() => SwarmControlManager.Instance.CanSpawn);
Target.Execute(ctx);
}
}
32 changes: 14 additions & 18 deletions SCHIZO/SwarmControl/SwarmControlManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Cci;
using Nautilus.Utility;
using SCHIZO.Attributes;
using SCHIZO.Commands.Attributes;
Expand Down Expand Up @@ -41,7 +39,13 @@ public string PrivateApiKey
private ControlWebSocket _socket;

public bool Ingame { get; private set; }
public bool CanSpawn { get; private set; }
public bool CanSpawn => Ingame
&& Player.main
&& Player.main.IsUnderwaterForSwimming()
&& !Player.main.IsPilotingSeatruck()

Check failure on line 45 in SCHIZO/SwarmControl/SwarmControlManager.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'Player' does not contain a definition for 'IsPilotingSeatruck' and no accessible extension method 'IsPilotingSeatruck' accepting a first argument of type 'Player' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in SCHIZO/SwarmControl/SwarmControlManager.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'Player' does not contain a definition for 'IsPilotingSeatruck' and no accessible extension method 'IsPilotingSeatruck' accepting a first argument of type 'Player' could be found (are you missing a using directive or an assembly reference?)
&& !Player.main.IsInBase()
//&& Time.timeScale > 0
;

private void Awake()
{
Expand All @@ -54,6 +58,13 @@ private void Awake()

private void OnLoad()
{
StartCoroutine(OnLoadCoro());
}

private IEnumerator OnLoadCoro()
{
uGUI gui = uGUI.main;
yield return new WaitUntil(() => gui.loading && !gui.loading.IsLoading);

Check failure on line 67 in SCHIZO/SwarmControl/SwarmControlManager.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'uGUI_SceneLoading' does not contain a definition for 'IsLoading' and no accessible extension method 'IsLoading' accepting a first argument of type 'uGUI_SceneLoading' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 67 in SCHIZO/SwarmControl/SwarmControlManager.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'uGUI_SceneLoading' does not contain a definition for 'IsLoading' and no accessible extension method 'IsLoading' accepting a first argument of type 'uGUI_SceneLoading' could be found (are you missing a using directive or an assembly reference?)
Ingame = true;
SendIngameStateMsg();
}
Expand Down Expand Up @@ -179,20 +190,6 @@ private void Update()
action();
}

private void FixedUpdate()
{
bool canSpawn = Player.main
&& Player.main.IsUnderwaterForSwimming()
&& !Player.main.IsPilotingSeatruck()
&& !Player.main.IsInBase()
;
if (canSpawn != CanSpawn)
{
CanSpawn = canSpawn;
SendIngameStateMsg();
}
}

private int _retries;
private const int MaxRetries = int.MaxValue;
private IEnumerator AutoReconnectCoro()
Expand Down Expand Up @@ -224,7 +221,6 @@ internal void SendIngameStateMsg()
_socket.SendMessage(new IngameStateChangedMessage()
{
Ingame = Ingame,
CanSpawn = CanSpawn,
});
}
}
Expand Down

0 comments on commit 78f6f58

Please sign in to comment.