Skip to content
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

Miscellaneous bugfixes for beta 1 #313

Merged
merged 3 commits into from
May 20, 2023
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
4 changes: 4 additions & 0 deletions EOLib/Domain/Map/MapCellStateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public IMapCellState GetCellStateAt(int x, int y)

Option<NPC.NPC> npc = Option.None<NPC.NPC>();
if (_mapStateProvider.NPCs.TryGetValues(new MapCoordinate(x, y), out var npcs))
{
npc = npcs.FirstOrNone();
if (npc.Map(x => x.IsActing(NPCActionState.Walking)).ValueOr(false))
npc = Option.None<NPC.NPC>();
}

var items = _mapStateProvider.MapItems.TryGetValues(new MapCoordinate(x, y), out var mapItems)
? mapItems.OrderByDescending(i => i.UniqueID)
Expand Down
19 changes: 12 additions & 7 deletions EndlessClient/Controllers/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public async Task LoginToAccount(ILoginParameters loginParameters)
var reply = loginToServerOperation.Result;

if (reply == LoginReply.Ok)
_gameStateActions.ChangeToState(GameStates.LoggedIn);
{
await DispatcherGameComponent.Invoke(() => _gameStateActions.ChangeToState(GameStates.LoggedIn));
}
else
{
_errorDisplayAction.ShowLoginError(reply);
Expand Down Expand Up @@ -227,12 +229,15 @@ await DispatcherGameComponent.Invoke(() =>
_clientWindowSizeRepository.Resizable = true;
}

_gameStateActions.ChangeToState(GameStates.PlayingTheGame);
_chatTextBoxActions.FocusChatTextBox();
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING,
EOResourceID.LOADING_GAME_HINT_FIRST);
_firstTimePlayerActions.WarnFirstTimePlayers();
_mapChangedActions.ActiveCharacterEnterMapForLogin();
await DispatcherGameComponent.Invoke(() =>
{
_gameStateActions.ChangeToState(GameStates.PlayingTheGame);
_chatTextBoxActions.FocusChatTextBox();
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING,
EOResourceID.LOADING_GAME_HINT_FIRST);
_firstTimePlayerActions.WarnFirstTimePlayers();
_mapChangedActions.ActiveCharacterEnterMapForLogin();
});
}

private void SetInitialStateAndShowError(NoDataSentException ex)
Expand Down
19 changes: 14 additions & 5 deletions EndlessClient/Controllers/MainButtonController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AutomaticTypeMapper;
using EndlessClient.Dialogs.Actions;
using EndlessClient.GameExecution;
using EndlessClient.Rendering;
using EOLib.Domain;
using EOLib.Domain.Protocol;
using EOLib.Net.Communication;
Expand Down Expand Up @@ -49,12 +50,15 @@ public void GoToInitialState()
_gameStateActions.ChangeToState(GameStates.Initial);
}

public void GoToInitialStateAndDisconnect()
public void GoToInitialStateAndDisconnect(bool showLostConnection = false)
{
GoToInitialState();
StopReceivingAndDisconnect();

_resetStateAction.ResetState();

if (showLostConnection)
_errorDialogDisplayAction.ShowConnectionLost(false);
}

public async Task ClickCreateAccount()
Expand All @@ -63,8 +67,11 @@ public async Task ClickCreateAccount()

if (result)
{
_gameStateActions.ChangeToState(GameStates.CreateAccount);
_accountDialogDisplayActions.ShowInitialCreateWarningDialog();
await DispatcherGameComponent.Invoke(() =>
{
_gameStateActions.ChangeToState(GameStates.CreateAccount);
_accountDialogDisplayActions.ShowInitialCreateWarningDialog();
});
}
}

Expand All @@ -73,7 +80,9 @@ public async Task ClickLogin()
var result = await StartNetworkConnection().ConfigureAwait(false);

if (result)
_gameStateActions.ChangeToState(GameStates.Login);
{
await DispatcherGameComponent.Invoke(() => _gameStateActions.ChangeToState(GameStates.Login));
}
}

public void ClickViewCredits()
Expand Down Expand Up @@ -150,7 +159,7 @@ public interface IMainButtonController
{
void GoToInitialState();

void GoToInitialStateAndDisconnect();
void GoToInitialStateAndDisconnect(bool showLostConnection = false);

Task ClickCreateAccount();

Expand Down
14 changes: 10 additions & 4 deletions EndlessClient/GameExecution/EndlessGame.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AutomaticTypeMapper;
using EndlessClient.Audio;
using EndlessClient.Content;
using EndlessClient.Controllers;
using EndlessClient.ControlSets;
using EndlessClient.Rendering;
using EndlessClient.Rendering.Chat;
Expand Down Expand Up @@ -43,6 +44,8 @@ public class EndlessGame : Game, IEndlessGame
private readonly IMfxPlayer _mfxPlayer;
private readonly IXnaControlSoundMapper _soundMapper;
private readonly IFixedTimeStepRepository _fixedTimeStepRepository;
private readonly IMainButtonController _mainButtonController;

private GraphicsDeviceManager _graphicsDeviceManager;

private KeyboardState _previousKeyState;
Expand All @@ -69,7 +72,8 @@ public EndlessGame(IClientWindowSizeRepository windowSizeRepository,
IConfigurationProvider configurationProvider,
IMfxPlayer mfxPlayer,
IXnaControlSoundMapper soundMapper,
IFixedTimeStepRepository fixedTimeStepRepository)
IFixedTimeStepRepository fixedTimeStepRepository,
IMainButtonController mainButtonController)
{
_windowSizeRepository = windowSizeRepository;
_contentProvider = contentProvider;
Expand All @@ -86,6 +90,8 @@ public EndlessGame(IClientWindowSizeRepository windowSizeRepository,
_mfxPlayer = mfxPlayer;
_soundMapper = soundMapper;
_fixedTimeStepRepository = fixedTimeStepRepository;
_mainButtonController = mainButtonController;

_graphicsDeviceManager = new GraphicsDeviceManager(this)
{
PreferredBackBufferWidth = ClientWindowSizeRepository.DEFAULT_BACKBUFFER_WIDTH,
Expand Down Expand Up @@ -203,9 +209,9 @@ protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
catch (InvalidOperationException ioe) when (ioe.InnerException is NullReferenceException)
catch
{
// hide "failed to compare two elements in the array" error from Monogame
_mainButtonController.GoToInitialStateAndDisconnect(showLostConnection: true);
}

_lastFrameUpdate = gameTime.TotalGameTime;
Expand Down Expand Up @@ -287,7 +293,7 @@ private void SetUpInitialControlSet()
_controlSetRepository.CurrentControlSet);
_controlSetRepository.CurrentControlSet = controls;

//since the controls are being created in Initialize(), adding them to the default game
//since the controls are being created in LoadContent(), adding them to the default game
// doesn't call the Initialize() method on any controls, so it must be done here
foreach (var xnaControl in _controlSetRepository.CurrentControlSet.AllComponents)
xnaControl.Initialize();
Expand Down
7 changes: 1 addition & 6 deletions EndlessClient/Network/PacketHandlerGameComponent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using AutomaticTypeMapper;
using EndlessClient.Controllers;
using EndlessClient.Dialogs.Actions;
using EndlessClient.GameExecution;
using EOLib.Net.Communication;
using EOLib.Net.Handlers;
Expand All @@ -14,21 +13,18 @@ public class PacketHandlerGameComponent : GameComponent
private readonly IOutOfBandPacketHandler _packetHandler;
private readonly INetworkClientProvider _networkClientProvider;
private readonly IGameStateProvider _gameStateProvider;
private readonly IErrorDialogDisplayAction _errorDialogDisplayAction;
private readonly IMainButtonController _mainButtonController;

public PacketHandlerGameComponent(IEndlessGame game,
IOutOfBandPacketHandler packetHandler,
INetworkClientProvider networkClientProvider,
IGameStateProvider gameStateProvider,
IErrorDialogDisplayAction errorDialogDisplayAction,
IMainButtonController mainButtonController)
: base((Game) game)
{
_packetHandler = packetHandler;
_networkClientProvider = networkClientProvider;
_gameStateProvider = gameStateProvider;
_errorDialogDisplayAction = errorDialogDisplayAction;
_mainButtonController = mainButtonController;

UpdateOrder = int.MinValue;
Expand All @@ -41,8 +37,7 @@ public override void Update(GameTime gameTime)
!_networkClientProvider.NetworkClient.Connected)
{
var isInGame = _gameStateProvider.CurrentState == GameStates.PlayingTheGame;
_mainButtonController.GoToInitialStateAndDisconnect();
_errorDialogDisplayAction.ShowConnectionLost(isInGame);
_mainButtonController.GoToInitialStateAndDisconnect(showLostConnection: true);
}

_packetHandler.PollForPacketsAndHandle();
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/Rendering/Character/PeriodicEmoteHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public override void Update(GameTime gameTime)
{
if ((now - _userInputTimeProvider.LastInputTime).TotalMilliseconds >= AFK_TIME_MS + AFK_TIME_ALERT_MS)
{
_mainButtonController.GoToInitialStateAndDisconnect();
_mainButtonController.GoToInitialStateAndDisconnect(showLostConnection: true);
}
else
{
Expand Down