Skip to content

Commit e65293d

Browse files
feat: portals toggle cheat (#452)
* Added toggle portal cheat Co-authored-by: Fernando Cortez <[email protected]>
1 parent ac655fa commit e65293d

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

Assets/BossRoom/Scripts/DebugCheats/DebugCheatsManager.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ ServerSwitchedDoor ServerSwitchedDoor
4343

4444
const int k_NbTouchesToOpenWindow = 4;
4545

46+
bool m_DestroyPortalsOnNextToggle = true;
47+
4648
void Update()
4749
{
4850
if (Input.touchCount == k_NbTouchesToOpenWindow && AnyTouchDown() ||
@@ -111,7 +113,7 @@ public void ToggleDoor()
111113

112114
public void TogglePortals()
113115
{
114-
LogCheatNotImplemented("TogglePortals");
116+
TogglePortalsServerRpc();
115117
}
116118

117119
public void GoToPostGame()
@@ -225,6 +227,28 @@ void HealPlayerServerRpc(ServerRpcParams serverRpcParams = default)
225227
LogCheatUsedClientRPC(serverRpcParams.Receive.SenderClientId, "HealPlayer");
226228
}
227229
}
230+
231+
[ServerRpc(RequireOwnership = false)]
232+
void TogglePortalsServerRpc(ServerRpcParams serverRpcParams = default)
233+
{
234+
foreach (var portal in FindObjectsOfType<ServerEnemyPortal>())
235+
{
236+
if (m_DestroyPortalsOnNextToggle)
237+
{
238+
// This will only affect portals that are currently active in a scene and are currently loaded.
239+
// Portals that are already destroyed will not be affected by this, and won't have their cooldown
240+
// reinitialized.
241+
portal.ForceDestroy();
242+
}
243+
else
244+
{
245+
portal.ForceRestart();
246+
}
247+
}
248+
249+
m_DestroyPortalsOnNextToggle = !m_DestroyPortalsOnNextToggle;
250+
LogCheatUsedClientRPC(serverRpcParams.Receive.SenderClientId, "TogglePortals");
251+
}
228252

229253
[ServerRpc(RequireOwnership = false)]
230254
void ToggleDoorServerRpc(ServerRpcParams serverRpcParams = default)

Assets/BossRoom/Scripts/Server/Game/Entity/ServerEnemyPortal.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections;
23
using System.Collections.Generic;
34
using Unity.Netcode;
@@ -101,6 +102,11 @@ IEnumerator CoroGoDormantAndThenRestart()
101102
{
102103
yield return new WaitForSeconds(m_DormantCooldown);
103104

105+
Restart();
106+
}
107+
108+
void Restart()
109+
{
104110
foreach (var state in m_BreakableElements)
105111
{
106112
if (state)
@@ -110,10 +116,35 @@ IEnumerator CoroGoDormantAndThenRestart()
110116
serverComponent.Unbreak();
111117
}
112118
}
119+
113120
m_State.IsBroken.Value = false;
114121
m_WaveSpawner.SetSpawnerEnabled(true);
115122
m_CoroDormant = null;
116123
}
124+
125+
#if UNITY_EDITOR || DEVELOPMENT_BUILD
126+
public void ForceRestart()
127+
{
128+
if (m_CoroDormant != null)
129+
{
130+
StopCoroutine(m_CoroDormant);
131+
}
132+
Restart();
133+
}
134+
135+
public void ForceDestroy()
136+
{
137+
foreach (var state in m_BreakableElements)
138+
{
139+
if (state)
140+
{
141+
var serverComponent = state.GetComponent<ServerBreakableLogic>();
142+
Assert.IsNotNull(serverComponent);
143+
serverComponent.ReceiveHP(null, Int32.MinValue);
144+
}
145+
}
146+
}
147+
#endif
117148
}
118149

119150

0 commit comments

Comments
 (0)