-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace GuildWars2.Guilds.Logs; | ||
|
||
/// <summary>A log entry about a started or ended guild mission.</summary> | ||
[PublicAPI] | ||
[DataTransferObject] | ||
public sealed record GuildMission : GuildLogEntry | ||
{ | ||
/// <summary>The ID of the user who started the mission.</summary> | ||
/// <remarks>Can be empty.</remarks> | ||
public required string User { get; init; } | ||
|
||
/// <summary>The state to which the mission transitioned.</summary> | ||
public required Extensible<GuildMissionState> State { get; init; } | ||
|
||
/// <summary>The amount of guild influence awarded.</summary> | ||
public required int Influence { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Text.Json; | ||
using GuildWars2.Json; | ||
|
||
namespace GuildWars2.Guilds.Logs; | ||
|
||
internal static class GuildMissionJson | ||
{ | ||
public static GuildMission GetGuildMission(this JsonElement json) | ||
{ | ||
RequiredMember id = "id"; | ||
RequiredMember time = "time"; | ||
RequiredMember state = "state"; | ||
RequiredMember influence = "influence"; | ||
OptionalMember user = "user"; | ||
|
||
foreach (var member in json.EnumerateObject()) | ||
{ | ||
if (member.NameEquals("type")) | ||
{ | ||
if (!member.Value.ValueEquals("mission")) | ||
{ | ||
ThrowHelper.ThrowInvalidDiscriminator(member.Value.GetString()); | ||
} | ||
} | ||
else if (id.Match(member)) | ||
{ | ||
id = member; | ||
} | ||
else if (time.Match(member)) | ||
{ | ||
time = member; | ||
} | ||
else if (state.Match(member)) | ||
{ | ||
state = member; | ||
} | ||
else if (influence.Match(member)) | ||
{ | ||
influence = member; | ||
} | ||
else if (user.Match(member)) | ||
{ | ||
user = member; | ||
} | ||
else if (JsonOptions.MissingMemberBehavior == MissingMemberBehavior.Error) | ||
{ | ||
ThrowHelper.ThrowUnexpectedMember(member.Name); | ||
} | ||
} | ||
|
||
return new GuildMission | ||
{ | ||
Id = id.Map(static value => value.GetInt32()), | ||
Time = time.Map(static value => value.GetDateTimeOffset()), | ||
User = user.Map(static value => value.GetString()) ?? "", | ||
State = state.Map(static value => value.GetEnum<GuildMissionState>()), | ||
Influence = influence.Map(static value => value.GetInt32()) | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace GuildWars2.Guilds.Logs; | ||
|
||
/// <summary>The guild mission state transitions.</summary> | ||
[PublicAPI] | ||
public enum GuildMissionState | ||
{ | ||
/// <summary>Logged when the mission starts.</summary> | ||
Start = 1, | ||
|
||
/// <summary>Logged when the mission ends successfully.</summary> | ||
Success, | ||
|
||
/// <summary>Logged when the mission ends unsuccessfully.</summary> | ||
Fail | ||
} |