Skip to content

feat: portals toggle cheat #452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion Assets/BossRoom/Scripts/DebugCheats/DebugCheatsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class DebugCheatsManager : NetworkBehaviour

const int k_NbTouchesToOpenWindow = 4;

bool m_DestroyPortalsOnNextToggle = true;

void Update()
{
if (Input.touchCount == k_NbTouchesToOpenWindow && AnyTouchDown() ||
Expand Down Expand Up @@ -97,7 +99,7 @@ public void ToggleDoor()

public void TogglePortals()
{
LogCheatNotImplemented("TogglePortals");
TogglePortalsServerRpc();
}

public void GoToPostGame()
Expand Down Expand Up @@ -196,6 +198,28 @@ void HealPlayerServerRpc(ServerRpcParams serverRpcParams = default)
LogCheatUsedClientRPC(serverRpcParams.Receive.SenderClientId, "HealPlayer");
}
}

[ServerRpc(RequireOwnership = false)]
void TogglePortalsServerRpc(ServerRpcParams serverRpcParams = default)
{
foreach (var portal in FindObjectsOfType<ServerEnemyPortal>())
{
if (m_DestroyPortalsOnNextToggle)
{
// This will only affect portals that are currently active in a scene and are currently loaded.
// Portals that are already destroyed will not be affected by this, and won't have their cooldown
// reinitialized.
portal.ForceDestroy();
}
else
{
portal.ForceRestart();
}
}

m_DestroyPortalsOnNextToggle = !m_DestroyPortalsOnNextToggle;
LogCheatUsedClientRPC(serverRpcParams.Receive.SenderClientId, "TogglePortals");
}

[ServerRpc(RequireOwnership = false)]
void GoToPostGameServerRpc(ServerRpcParams serverRpcParams = default)
Expand Down
31 changes: 31 additions & 0 deletions Assets/BossRoom/Scripts/Server/Game/Entity/ServerEnemyPortal.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
Expand Down Expand Up @@ -101,6 +102,11 @@ IEnumerator CoroGoDormantAndThenRestart()
{
yield return new WaitForSeconds(m_DormantCooldown);

Restart();
}

void Restart()
{
foreach (var state in m_BreakableElements)
{
if (state)
Expand All @@ -110,10 +116,35 @@ IEnumerator CoroGoDormantAndThenRestart()
serverComponent.Unbreak();
}
}

m_State.IsBroken.Value = false;
m_WaveSpawner.SetSpawnerEnabled(true);
m_CoroDormant = null;
}

#if UNITY_EDITOR || DEVELOPMENT_BUILD
public void ForceRestart()
{
if (m_CoroDormant != null)
{
StopCoroutine(m_CoroDormant);
}
Restart();
}

public void ForceDestroy()
{
foreach (var state in m_BreakableElements)
{
if (state)
{
var serverComponent = state.GetComponent<ServerBreakableLogic>();
Assert.IsNotNull(serverComponent);
serverComponent.ReceiveHP(null, Int32.MinValue);
}
}
}
#endif
}


Expand Down