Skip to content

Commit

Permalink
Add Session EXP dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Apr 8, 2022
1 parent 5baee0d commit 750ba3e
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 131 deletions.
52 changes: 52 additions & 0 deletions EOLib/Domain/Character/CharacterSessionRepository.cs
@@ -0,0 +1,52 @@
using AutomaticTypeMapper;
using System;

namespace EOLib.Domain.Character
{
public interface ICharacterSessionRepository : IResettable
{
DateTime SessionStartTime { get; set; }

int BestKillExp { get; set; }

int LastKillExp { get; set; }

int TodayTotalExp { get; set; }
}

public interface ICharacterSessionProvider : IResettable
{
DateTime SessionStartTime { get; }

int BestKillExp { get; }

int LastKillExp { get; }

int TodayTotalExp { get; }
}

[AutoMappedType(IsSingleton = true)]
public class CharacterSessionRepository : ICharacterSessionRepository, ICharacterSessionProvider
{
public DateTime SessionStartTime { get; set; }

public int BestKillExp { get; set; }

public int LastKillExp { get; set; }

public int TodayTotalExp { get; set; }

public CharacterSessionRepository()
{
ResetState();
}

public void ResetState()
{
SessionStartTime = DateTime.Now;
BestKillExp = 0;
LastKillExp = 0;
TodayTotalExp = 0;
}
}
}
2 changes: 1 addition & 1 deletion EOLib/Domain/Character/CharacterStat.cs
Expand Up @@ -30,6 +30,6 @@ public enum CharacterStat
Charisma,

Weight,
MaxWeight
MaxWeight,
}
}
6 changes: 5 additions & 1 deletion EOLib/Domain/Login/LoginActions.cs
Expand Up @@ -28,6 +28,7 @@ public class LoginActions : ILoginActions
private readonly INewsRepository _newsRepository;
private readonly ICharacterInventoryRepository _characterInventoryRepository;
private readonly IPaperdollRepository _paperdollRepository;
private readonly ICharacterSessionRepository _characterSessionRepository;

public LoginActions(IPacketSendService packetSendService,
IPacketTranslator<IAccountLoginData> loginPacketTranslator,
Expand All @@ -40,7 +41,8 @@ public class LoginActions : ILoginActions
ILoginFileChecksumRepository loginFileChecksumRepository,
INewsRepository newsRepository,
ICharacterInventoryRepository characterInventoryRepository,
IPaperdollRepository paperdollRepository)
IPaperdollRepository paperdollRepository,
ICharacterSessionRepository characterSessionRepository)
{
_packetSendService = packetSendService;
_loginPacketTranslator = loginPacketTranslator;
Expand All @@ -54,6 +56,7 @@ public class LoginActions : ILoginActions
_newsRepository = newsRepository;
_characterInventoryRepository = characterInventoryRepository;
_paperdollRepository = paperdollRepository;
_characterSessionRepository = characterSessionRepository;
}

public bool LoginParametersAreValid(ILoginParameters parameters)
Expand Down Expand Up @@ -185,6 +188,7 @@ public async Task<CharacterLoginReply> CompleteCharacterLogin(short sessionID)
_currentMapStateRepository.MapItems = new HashSet<IItem>(data.MapItems);

_playerInfoRepository.PlayerIsInGame = true;
_characterSessionRepository.ResetState();

return CharacterLoginReply.RequestCompleted;
}
Expand Down
12 changes: 10 additions & 2 deletions EOLib/PacketHandlers/NPCLeaveMapHandler.cs
Expand Up @@ -16,6 +16,7 @@ public class NPCLeaveMapHandler : InGameOnlyPacketHandler
{
protected readonly ICurrentMapStateRepository _currentMapStateRepository;
protected readonly ICharacterRepository _characterRepository;
private readonly ICharacterSessionRepository _characterSessionRepository;
private readonly IEnumerable<INPCActionNotifier> _npcAnimationNotifiers;
private readonly IEnumerable<IMainCharacterEventNotifier> _mainCharacterEventNotifiers;

Expand All @@ -26,12 +27,14 @@ public class NPCLeaveMapHandler : InGameOnlyPacketHandler
public NPCLeaveMapHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapStateRepository currentMapStateRepository,
ICharacterRepository characterRepository,
ICharacterSessionRepository characterSessionRepository,
IEnumerable<INPCActionNotifier> npcAnimationNotifiers,
IEnumerable<IMainCharacterEventNotifier> mainCharacterEventNotifiers)
: base(playerInfoProvider)
{
_currentMapStateRepository = currentMapStateRepository;
_characterRepository = characterRepository;
_characterSessionRepository = characterSessionRepository;
_npcAnimationNotifiers = npcAnimationNotifiers;
_mainCharacterEventNotifiers = mainCharacterEventNotifiers;
}
Expand Down Expand Up @@ -79,7 +82,11 @@ public override bool HandlePacket(IPacket packet)
notifier.NotifyGainedExp(expDifference);

UpdateCharacterStat(CharacterStat.Experience, playerExp);
//todo: update last kill, best kill, and today exp

_characterSessionRepository.LastKillExp = expDifference;
if (expDifference > _characterSessionRepository.BestKillExp)
_characterSessionRepository.BestKillExp = expDifference;
_characterSessionRepository.TodayTotalExp += expDifference;
}

if (droppedItemID > 0)
Expand Down Expand Up @@ -153,9 +160,10 @@ public class NPCDieFromSpellCastHandler : NPCLeaveMapHandler
public NPCDieFromSpellCastHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapStateRepository currentMapStateRepository,
ICharacterRepository characterRepository,
ICharacterSessionRepository characterSessionRepository,
IEnumerable<INPCActionNotifier> npcAnimationNotifiers,
IEnumerable<IMainCharacterEventNotifier> mainCharacterEventNotifiers)
: base(playerInfoProvider, currentMapStateRepository, characterRepository,
: base(playerInfoProvider, currentMapStateRepository, characterRepository, characterSessionRepository,
npcAnimationNotifiers, mainCharacterEventNotifiers) { }
}
}
6 changes: 4 additions & 2 deletions EOLib/PacketHandlers/PlayerLevelUpHandler.cs
Expand Up @@ -20,10 +20,11 @@ public class PlayerLevelUpHandler : NPCLeaveMapHandler
public PlayerLevelUpHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapStateRepository currentMapStateRepository,
ICharacterRepository characterRepository,
ICharacterSessionRepository characterSessionRepository,
IEnumerable<INPCActionNotifier> npcAnimationNotifiers,
IEnumerable<IMainCharacterEventNotifier> mainCharacterEventNotifiers,
IEnumerable<IEmoteNotifier> emoteNotifiers)
: base(playerInfoProvider, currentMapStateRepository, characterRepository,
: base(playerInfoProvider, currentMapStateRepository, characterRepository, characterSessionRepository,
npcAnimationNotifiers, mainCharacterEventNotifiers)
{
_emoteNotifiers = emoteNotifiers;
Expand Down Expand Up @@ -67,10 +68,11 @@ public class PlayerLevelUpFromSpellCastHandler : PlayerLevelUpHandler
public PlayerLevelUpFromSpellCastHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapStateRepository currentMapStateRepository,
ICharacterRepository characterRepository,
ICharacterSessionRepository characterSessionRepository,
IEnumerable<INPCActionNotifier> npcAnimationNotifiers,
IEnumerable<IMainCharacterEventNotifier> mainCharacterEventNotifiers,
IEnumerable<IEmoteNotifier> emoteNotifiers)
: base(playerInfoProvider, currentMapStateRepository, characterRepository,
: base(playerInfoProvider, currentMapStateRepository, characterRepository, characterSessionRepository,
npcAnimationNotifiers, mainCharacterEventNotifiers, emoteNotifiers) { }
}
}
17 changes: 17 additions & 0 deletions EndlessClient/Dialogs/Actions/InGameDialogActions.cs
Expand Up @@ -15,6 +15,7 @@ public class InGameDialogActions : IInGameDialogActions, INPCInteractionNotifier
{
private readonly IFriendIgnoreListDialogFactory _friendIgnoreListDialogFactory;
private readonly IPaperdollDialogFactory _paperdollDialogFactory;
private readonly ISessionExpDialogFactory _sessionExpDialogFactory;
private readonly IQuestStatusDialogFactory _questStatusDialogFactory;
private readonly IActiveDialogRepository _activeDialogRepository;
private readonly IShopDataRepository _shopDataRepository;
Expand All @@ -24,6 +25,7 @@ public class InGameDialogActions : IInGameDialogActions, INPCInteractionNotifier

public InGameDialogActions(IFriendIgnoreListDialogFactory friendIgnoreListDialogFactory,
IPaperdollDialogFactory paperdollDialogFactory,
ISessionExpDialogFactory sessionExpDialogFactory,
IQuestStatusDialogFactory questStatusDialogFactory,
IShopDialogFactory shopDialogFactory,
IQuestDialogFactory questDialogFactory,
Expand All @@ -33,6 +35,7 @@ public class InGameDialogActions : IInGameDialogActions, INPCInteractionNotifier
{
_friendIgnoreListDialogFactory = friendIgnoreListDialogFactory;
_paperdollDialogFactory = paperdollDialogFactory;
_sessionExpDialogFactory = sessionExpDialogFactory;
_questStatusDialogFactory = questStatusDialogFactory;
_activeDialogRepository = activeDialogRepository;
_shopDataRepository = shopDataRepository;
Expand Down Expand Up @@ -65,6 +68,18 @@ public void ShowIgnoreListDialog()
});
}

public void ShowSessionExpDialog()
{
_activeDialogRepository.SessionExpDialog.MatchNone(() =>
{
var dlg = _sessionExpDialogFactory.Create();
dlg.DialogClosed += (_, _) => _activeDialogRepository.SessionExpDialog = Option.None<SessionExpDialog>();
_activeDialogRepository.SessionExpDialog = Option.Some(dlg);
dlg.Show();
});
}

public void ShowQuestStatusDialog()
{
_activeDialogRepository.QuestStatusDialog.MatchNone(() =>
Expand Down Expand Up @@ -141,6 +156,8 @@ public interface IInGameDialogActions

void ShowIgnoreListDialog();

void ShowSessionExpDialog();

void ShowQuestStatusDialog();

void ShowPaperdollDialog(ICharacter character, bool isMainCharacter);
Expand Down
8 changes: 8 additions & 0 deletions EndlessClient/Dialogs/ActiveDialogRepository.cs
Expand Up @@ -11,6 +11,8 @@ public interface IActiveDialogProvider : IDisposable
{
Option<ScrollingListDialog> FriendIgnoreDialog { get; }

Option<SessionExpDialog> SessionExpDialog { get; }

Option<QuestStatusDialog> QuestStatusDialog { get; }

Option<PaperdollDialog> PaperdollDialog { get; }
Expand All @@ -26,6 +28,8 @@ public interface IActiveDialogRepository : IDisposable
{
Option<ScrollingListDialog> FriendIgnoreDialog { get; set; }

Option<SessionExpDialog> SessionExpDialog { get; set; }

Option<QuestStatusDialog> QuestStatusDialog { get; set; }

Option<PaperdollDialog> PaperdollDialog { get; set; }
Expand All @@ -42,6 +46,8 @@ public class ActiveDialogRepository : IActiveDialogRepository, IActiveDialogProv
{
public Option<ScrollingListDialog> FriendIgnoreDialog { get; set; }

public Option<SessionExpDialog> SessionExpDialog { get; set; }

public Option<QuestStatusDialog> QuestStatusDialog { get; set; }

public Option<PaperdollDialog> PaperdollDialog { get; set; }
Expand All @@ -57,6 +63,7 @@ IReadOnlyList<Option<IXNADialog>> ActiveDialogs
return new[]
{
FriendIgnoreDialog.Map(d => (IXNADialog)d),
SessionExpDialog.Map(d => (IXNADialog)d),
QuestStatusDialog.Map(d => (IXNADialog)d),
PaperdollDialog.Map(d => (IXNADialog)d),
ShopDialog.Map(d => (IXNADialog)d),
Expand All @@ -75,6 +82,7 @@ public void Dispose()
dlg.MatchSome(d => d.Dispose());

FriendIgnoreDialog = Option.None<ScrollingListDialog>();
SessionExpDialog = Option.None<SessionExpDialog>();
QuestStatusDialog = Option.None<QuestStatusDialog>();
PaperdollDialog = Option.None<PaperdollDialog>();
ShopDialog = Option.None<ShopDialog>();
Expand Down
49 changes: 49 additions & 0 deletions EndlessClient/Dialogs/Factories/SessionExpDialogFactory.cs
@@ -0,0 +1,49 @@
using AutomaticTypeMapper;
using EndlessClient.Dialogs.Services;
using EOLib.Domain.Character;
using EOLib.Graphics;
using EOLib.Localization;

namespace EndlessClient.Dialogs.Factories
{
[AutoMappedType]
public class SessionExpDialogFactory : ISessionExpDialogFactory
{
private readonly INativeGraphicsManager _nativeGraphicsManager;
private readonly IEODialogButtonService _dialogButtonService;
private readonly ILocalizedStringFinder _localizedStringFinder;
private readonly ICharacterProvider _characterProvider;
private readonly IExperienceTableProvider _expTableProvider;
private readonly ICharacterSessionProvider _characterSessionProvider;

public SessionExpDialogFactory(INativeGraphicsManager nativeGraphicsManager,
IEODialogButtonService dialogButtonService,
ILocalizedStringFinder localizedStringFinder,
ICharacterProvider characterProvider,
IExperienceTableProvider expTableProvider,
ICharacterSessionProvider characterSessionProvider)
{
_nativeGraphicsManager = nativeGraphicsManager;
_dialogButtonService = dialogButtonService;
_localizedStringFinder = localizedStringFinder;
_characterProvider = characterProvider;
_expTableProvider = expTableProvider;
_characterSessionProvider = characterSessionProvider;
}

public SessionExpDialog Create()
{
return new SessionExpDialog(_nativeGraphicsManager,
_dialogButtonService,
_localizedStringFinder,
_characterProvider,
_expTableProvider,
_characterSessionProvider);
}
}

public interface ISessionExpDialogFactory
{
SessionExpDialog Create();
}
}

0 comments on commit 750ba3e

Please sign in to comment.