Socket classes for Hermes
This commit is contained in:
33
Quests/ChatterQuestProgression.cs
Normal file
33
Quests/ChatterQuestProgression.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
namespace HermesSocketLibrary.Quests
|
||||
{
|
||||
public class ChatterQuestProgression
|
||||
{
|
||||
private readonly long _chatterId;
|
||||
private readonly Quest _quest;
|
||||
private int _counter;
|
||||
|
||||
public Quest Quest { get => _quest; }
|
||||
public int Counter { get => _counter; }
|
||||
|
||||
public ChatterQuestProgression(long chatterId, Quest quest)
|
||||
{
|
||||
_chatterId = chatterId;
|
||||
_quest = quest;
|
||||
_counter = 0;
|
||||
}
|
||||
|
||||
|
||||
public bool Process(string message, HashSet<string> emotes)
|
||||
{
|
||||
bool good = _quest.Task.Process(_chatterId, message, emotes);
|
||||
if (good)
|
||||
{
|
||||
_counter++;
|
||||
|
||||
return _quest.Task.IsCompleted(_counter);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Quests/DailyQuest.cs
Normal file
11
Quests/DailyQuest.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace HermesSocketLibrary.Quests
|
||||
{
|
||||
public class DailyQuest : Quest
|
||||
{
|
||||
public DailyQuest(short id, IQuestTask task, DateOnly day)
|
||||
: base(id, task, 1, day.ToDateTime(TimeOnly.MinValue), day.ToDateTime(TimeOnly.MaxValue))
|
||||
{
|
||||
Type = task.Type | QuestType.Daily;
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Quests/Quest.cs
Normal file
42
Quests/Quest.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
namespace HermesSocketLibrary.Quests
|
||||
{
|
||||
public abstract class Quest
|
||||
{
|
||||
public short Id { get; }
|
||||
public IQuestTask Task { get; }
|
||||
public DateTime StartTime { get; }
|
||||
public DateTime EndTime { get; }
|
||||
public QuestType Type { get; protected set; }
|
||||
public int Rewards { get; }
|
||||
|
||||
public Quest(short id, IQuestTask task, int rewards, DateTime start, DateTime end)
|
||||
{
|
||||
Id = id;
|
||||
Task = task;
|
||||
Rewards = rewards;
|
||||
StartTime = start;
|
||||
EndTime = end;
|
||||
}
|
||||
|
||||
public bool IsDaily()
|
||||
{
|
||||
return Type.HasFlag(QuestType.Daily);
|
||||
}
|
||||
|
||||
public bool IsWeekly()
|
||||
{
|
||||
return Type.HasFlag(QuestType.Weekly);
|
||||
}
|
||||
|
||||
public bool IsMonthly()
|
||||
{
|
||||
return Type.HasFlag(QuestType.Monthly);
|
||||
}
|
||||
|
||||
public bool IsOngoing()
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
return now >= StartTime && now <= EndTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Quests/QuestType.cs
Normal file
15
Quests/QuestType.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace HermesSocketLibrary.Quests
|
||||
{
|
||||
[Flags]
|
||||
public enum QuestType
|
||||
{
|
||||
Message = 0x0001,
|
||||
EmoteMessage = 0x0002,
|
||||
Redemption = 0x0004,
|
||||
WatchTime = 0x0008,
|
||||
|
||||
Daily = 0x1000,
|
||||
Weekly = 0x2000,
|
||||
Monthly = 0x4000
|
||||
}
|
||||
}
|
||||
27
Quests/Tasks/EmoteMessageQuestTask.cs
Normal file
27
Quests/Tasks/EmoteMessageQuestTask.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace HermesSocketLibrary.Quests.Tasks
|
||||
{
|
||||
public class EmoteMessageQuestTask : IQuestTask
|
||||
{
|
||||
public string Name => $"send {Target} messages";
|
||||
public QuestType Type { get; set; }
|
||||
public int Target { get; }
|
||||
|
||||
public EmoteMessageQuestTask(int target)
|
||||
{
|
||||
Target = target;
|
||||
}
|
||||
|
||||
public bool IsCompleted(int counter)
|
||||
{
|
||||
return counter >= Target;
|
||||
}
|
||||
|
||||
public bool Process(long chatterId, string message, HashSet<string> emotes)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
return false;
|
||||
|
||||
return emotes.Count > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Quests/Tasks/MessageQuestTask.cs
Normal file
30
Quests/Tasks/MessageQuestTask.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace HermesSocketLibrary.Quests.Tasks
|
||||
{
|
||||
public class MessageQuestTask : IQuestTask
|
||||
{
|
||||
public string Name => $"send {Target} messages";
|
||||
public QuestType Type { get; set; }
|
||||
public int Target { get; }
|
||||
|
||||
public MessageQuestTask(int target)
|
||||
{
|
||||
Target = target;
|
||||
}
|
||||
|
||||
public bool IsCompleted(int counter)
|
||||
{
|
||||
return counter >= Target;
|
||||
}
|
||||
|
||||
public bool Process(long chatterId, string message, HashSet<string> emotes)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
return false;
|
||||
|
||||
if (message.Length < 3)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Quests/Tasks/QuestTask.cs
Normal file
11
Quests/Tasks/QuestTask.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace HermesSocketLibrary.Quests
|
||||
{
|
||||
public interface IQuestTask
|
||||
{
|
||||
public string Name { get; }
|
||||
public QuestType Type { get; set; }
|
||||
public int Target { get; }
|
||||
public abstract bool Process(long chatterId, string message, HashSet<string> emotes);
|
||||
public abstract bool IsCompleted(int counter);
|
||||
}
|
||||
}
|
||||
12
Quests/WeeklyQuest.cs
Normal file
12
Quests/WeeklyQuest.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
namespace HermesSocketLibrary.Quests
|
||||
{
|
||||
public class WeeklyQuest : Quest
|
||||
{
|
||||
public WeeklyQuest(short id, IQuestTask task, DateOnly start)
|
||||
: base(id, task, 5, start.ToDateTime(TimeOnly.MinValue), start.AddDays(6).ToDateTime(TimeOnly.MaxValue))
|
||||
{
|
||||
Type = task.Type | QuestType.Weekly;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user