Skip to content

Commit

Permalink
char select / char creation states
Browse files Browse the repository at this point in the history
  • Loading branch information
shnok committed Dec 4, 2024
1 parent f56a81e commit 1e67ba0
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ public class GameManager : MonoBehaviour
{
[SerializeField] private bool _enableLogs;
[SerializeField] private int _protocolVersion = 740;
[SerializeField] private GameState _gameState = GameState.LOGIN_SCREEN;
[SerializeField] private bool _autoLogin = false;
[SerializeField] private Camera _loadingCamera;
[SerializeField] private bool _loading;
public bool Loading { get { return _loading; } }
public int ProtocolVersion { get { return _protocolVersion; } }
public bool AutoLogin { get { return _autoLogin; } }

Expand Down Expand Up @@ -443,7 +443,8 @@ private void InitializeState()
GameState.LOGIN_SCREEN => new LoginState(this),
GameState.LOGIN_CONNECTED => new LoginConnectedState(this),
GameState.LOGIN_AUTHED => new LoginAuthedState(this),
GameState.CHAR_SELECT => new CharSelectState(this),
GameState.CHAR_SELECT => new CharSelectionState(this),
GameState.CHAR_CREATION => new CharCreationState(this),
_ => throw new ArgumentException("Invalid state")
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using UnityEngine;

public class CharCreationState : GameStateBase
{
public CharCreationState(GameManager stateMachine) : base(stateMachine) { }

public override void Enter(object arg0)
{
L2LoginUI.Instance.ShowCharCreationWindow();

LoginCameraManager.Instance.SwitchCamera("Login");
}

public override void Update()
{

}

public override void HandleEvent(GameEvent evt, object arg0)
{
switch (evt)
{
case GameEvent.GAME_DISCONNECTED:
L2LoginUI.Instance.ShowLoginWindow();
_stateMachine.ChangeState(GameState.LOGIN_SCREEN);
break;
case GameEvent.CHAR_LOADED:
case GameEvent.RETURN:
L2LoginUI.Instance.ShowCharSelectWindow();
_stateMachine.ChangeState(GameState.CHAR_SELECT);
break;
case GameEvent.CHAR_CREATED:
_stateMachine.ChangeState(GameState.CHAR_CREATION);
break;
default:
Debug.LogWarning($"[GameStateMachine] Unhandled event {evt} for state {_stateMachine.State}");
break;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using UnityEngine;

public class CharSelectState : GameStateBase
public class CharSelectionState : GameStateBase
{
public CharSelectState(GameManager stateMachine) : base(stateMachine) { }
public CharSelectionState(GameManager stateMachine) : base(stateMachine) { }

public override void Enter(object arg0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ public LoginState(GameManager stateMachine) : base(stateMachine) { }

public override void Enter(object arg0)
{
if (!_stateMachine.Loading)
{
LoginCameraManager.Instance.SwitchCamera("Login");
L2LoginUI.Instance.ShowLoginWindow();
}
}

public override void Update()
Expand All @@ -19,7 +24,6 @@ public override void HandleEvent(GameEvent evt, object arg0)
{
case GameEvent.LOADING_COMPLETE:
_stateMachine.StopLoading();

LoginCameraManager.Instance.SwitchCamera("Login");
LoginWindow.Instance.ShowWindow();
LoginWindow.Instance.ShowLogo();
Expand All @@ -33,4 +37,8 @@ public override void HandleEvent(GameEvent evt, object arg0)
break;
}
}

private void ResetLoginState()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,10 @@ private void OnCharSelectionInfoReceive(byte[] data)
CharacterSelector.Instance.Characters = packet.Characters;
CharacterSelector.Instance.DefaultSelectedSlot = packet.SelectedSlotId;

if (GameManager.Instance.State != GameState.RESTARTING)
Debug.Log($"Received {packet.Characters.Count} character(s) from server.");

if (GameManager.Instance.State == GameState.LOGIN_AUTHED)
{
Debug.Log($"Received {packet.Characters.Count} character(s) from server.");

EventProcessor.Instance.QueueEvent(() =>
{
Expand Down
3 changes: 2 additions & 1 deletion l2-unity/Assets/Scripts/Networking/GameClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public override void OnAuthAllowed()
public void OnCharSelectAllowed()
{
Debug.Log("Return to character selection.");
// GameManager.Instance.OnCharSelectAllowed();
// /GameManager.Instance.OnCharSelectAllowed();
GameManager.Instance.NotifyEvent(GameEvent.CHAR_LOADED);
}

public override void OnDisconnect()
Expand Down
3 changes: 1 addition & 2 deletions l2-unity/Assets/Scripts/UI/Login/CharSelectWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,12 @@ private void StartGamePressed()

private void ReLoginPressed()
{
GameManager.Instance.NotifyEvent(GameEvent.RETURN);
GameClient.Instance.Disconnect();
}

private void CreatePressed()
{
GameManager.Instance.NotifyEvent(GameEvent.CHAR_CREATED);
GameManager.Instance.ChangeState(GameState.CHAR_CREATION);
}

private void DeletePressed()
Expand Down
Loading

0 comments on commit 1e67ba0

Please sign in to comment.