Skip to content

Commit

Permalink
Merge pull request #173 from ethanmoffat/quest_history_progress
Browse files Browse the repository at this point in the history
Implement quest history/progress dialog and player session exp dialog
  • Loading branch information
ethanmoffat committed Apr 8, 2022
2 parents 5e344b6 + 750ba3e commit b7f95ee
Show file tree
Hide file tree
Showing 38 changed files with 1,060 additions and 778 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,
}
}
8 changes: 7 additions & 1 deletion EOLib/Domain/Interact/MapNPCActions.cs
@@ -1,4 +1,5 @@
using AutomaticTypeMapper;
using EOLib.Domain.Interact.Quest;
using EOLib.Domain.NPC;
using EOLib.IO.Repositories;
using EOLib.Net;
Expand All @@ -11,12 +12,15 @@ public class MapNPCActions : IMapNPCActions
{
private readonly IPacketSendService _packetSendService;
private readonly IENFFileProvider _enfFileProvider;
private readonly IQuestDataRepository _questDataRepository;

public MapNPCActions(IPacketSendService packetSendService,
IENFFileProvider enfFileProvider)
IENFFileProvider enfFileProvider,
IQuestDataRepository questDataRepository)
{
_packetSendService = packetSendService;
_enfFileProvider = enfFileProvider;
_questDataRepository = questDataRepository;
}

public void RequestShop(INPC npc)
Expand All @@ -30,6 +34,8 @@ public void RequestShop(INPC npc)

public void RequestQuest(INPC npc)
{
_questDataRepository.RequestedNPC = npc;

var data = _enfFileProvider.ENFFile[npc.ID];

var packet = new PacketBuilder(PacketFamily.Quest, PacketAction.Use)
Expand Down
10 changes: 10 additions & 0 deletions EOLib/Domain/Interact/Quest/BookIcon.cs
@@ -0,0 +1,10 @@
namespace EOLib.Domain.Interact.Quest
{
public enum BookIcon : byte
{
Item = 3,
Talk = 5,
Kill = 8,
Step = 10
}
}
11 changes: 11 additions & 0 deletions EOLib/Domain/Interact/Quest/QuestActions.cs
Expand Up @@ -35,10 +35,21 @@ public void RespondToQuestDialog(DialogReply reply, byte linkId = 0)
_packetSendService.SendPacket(packet);
});
}

public void RequestQuestHistory(QuestPage page)
{
var packet = new PacketBuilder(PacketFamily.Quest, PacketAction.List)
.AddChar((byte)page)
.Build();

_packetSendService.SendPacket(packet);
}
}

public interface IQuestActions
{
void RespondToQuestDialog(DialogReply reply, byte linkId = 0);

void RequestQuestHistory(QuestPage page);
}
}
20 changes: 20 additions & 0 deletions EOLib/Domain/Interact/Quest/QuestDataRepository.cs
@@ -1,6 +1,7 @@
using AutomaticTypeMapper;
using EOLib.Domain.NPC;
using Optional;
using System.Collections.Generic;

namespace EOLib.Domain.Interact.Quest
{
Expand All @@ -9,13 +10,21 @@ public interface IQuestDataRepository : IResettable
INPC RequestedNPC { get; set; }

Option<IQuestDialogData> QuestDialogData { get; set; }

List<IQuestProgressData> QuestProgress { get; set; }

List<string> QuestHistory { get; set; }
}

public interface IQuestDataProvider : IResettable
{
INPC RequestedNPC { get; }

Option<IQuestDialogData> QuestDialogData { get; }

IReadOnlyList<IQuestProgressData> QuestProgress { get; }

IReadOnlyList<string> QuestHistory { get; }
}

[AutoMappedType(IsSingleton = true)]
Expand All @@ -25,14 +34,25 @@ public class QuestDataRepository : IQuestDataProvider, IQuestDataRepository

public Option<IQuestDialogData> QuestDialogData { get; set; }

public List<IQuestProgressData> QuestProgress { get; set; }

public List<string> QuestHistory { get; set; }

IReadOnlyList<IQuestProgressData> IQuestDataProvider.QuestProgress => QuestProgress;

IReadOnlyList<string> IQuestDataProvider.QuestHistory => QuestHistory;

public QuestDataRepository()
{
ResetState();
}

public void ResetState()
{
RequestedNPC = null;
QuestDialogData = Option.None<IQuestDialogData>();
QuestProgress = new List<IQuestProgressData>();
QuestHistory = new List<string>();
}
}
}
8 changes: 8 additions & 0 deletions EOLib/Domain/Interact/Quest/QuestPage.cs
@@ -0,0 +1,8 @@
namespace EOLib.Domain.Interact.Quest
{
public enum QuestPage
{
Progress = 1,
History
}
}
103 changes: 103 additions & 0 deletions EOLib/Domain/Interact/Quest/QuestProgressData.cs
@@ -0,0 +1,103 @@
using System;

namespace EOLib.Domain.Interact.Quest
{
public class QuestProgressData : IQuestProgressData
{
public string Name { get; private set; }

public string Description { get; private set; }

public BookIcon Icon { get; private set; }

public int IconIndex
{
get
{
//these are probably wrong. can't really tell what it's supposed to be from original
switch (Icon)
{
case BookIcon.Item:
return 2;
case BookIcon.Talk:
return 1;
case BookIcon.Kill:
return 3;
case BookIcon.Step:
return 4;
default:
throw new ArgumentOutOfRangeException();
}
}
}

public short Progress { get; private set; }

public short Target { get; private set; }

public QuestProgressData() { }

private QuestProgressData(string name,
string description,
BookIcon icon,
short progress,
short target)
{
Name = name;
Description = description;
Icon = icon;
Progress = progress;
Target = target;
}

public IQuestProgressData WithName(string name)
{
return new QuestProgressData(name, Description, Icon, Progress, Target);
}

public IQuestProgressData WithDescription(string description)
{
return new QuestProgressData(Name, description, Icon, Progress, Target);
}

public IQuestProgressData WithIcon(BookIcon icon)
{
return new QuestProgressData(Name, Description, icon, Progress, Target);
}

public IQuestProgressData WithProgress(short progress)
{
return new QuestProgressData(Name, Description, Icon, progress, Target);
}

public IQuestProgressData WithTarget(short target)
{
return new QuestProgressData(Name, Description, Icon, Progress, target);
}
}

public interface IQuestProgressData
{
string Name { get; }

string Description { get; }

BookIcon Icon { get; }

int IconIndex { get; }

short Progress { get; }

short Target { get; }

IQuestProgressData WithName(string name);

IQuestProgressData WithDescription(string description);

IQuestProgressData WithIcon(BookIcon icon);

IQuestProgressData WithProgress(short progress);

IQuestProgressData WithTarget(short target);
}
}
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
1 change: 0 additions & 1 deletion EOLib/Net/API/PacketAPI.cs
Expand Up @@ -27,7 +27,6 @@ public PacketAPI(EOClient client)
_createMusicMembers();
_createPartyMembers();
_createNPCMembers();
_createQuestMembers();
_createSpellMembers();
_createStatSkillMembers();
_createTradeMembers();
Expand Down

0 comments on commit b7f95ee

Please sign in to comment.