forked from tukasa0001/TownOfHost
-
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.
Merge pull request #53 from Hyz-sui/H-dev
2024.3.5.3
- Loading branch information
Showing
25 changed files
with
515 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace TownOfHost.Modules.GameEventHistory; | ||
|
||
public abstract class Event : IHistoryEvent | ||
{ | ||
public DateTime UtcTime { get; } | ||
public abstract string Bullet { get; } | ||
protected Event() | ||
{ | ||
UtcTime = DateTime.UtcNow; | ||
} | ||
|
||
public abstract void AppendDiscordString(StringBuilder builder); | ||
|
||
protected void AppendPlayerWithEmoji(StringBuilder builder, EventCommittedPlayer player, bool isAlive) | ||
{ | ||
builder.Append(Utils.ColorIdToDiscordEmoji(player.ColorId, isAlive)); | ||
builder.Append(" **"); | ||
builder.Append(player.Name); | ||
builder.Append("**"); | ||
} | ||
} |
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,13 @@ | ||
using TownOfHost.Roles.Core; | ||
|
||
namespace TownOfHost.Modules.GameEventHistory; | ||
|
||
public readonly struct EventCommittedPlayer(string name, byte playerId, int colorId, CustomRoles roleId) | ||
{ | ||
public string Name { get; init; } = name; | ||
public byte PlayerId { get; init; } = playerId; | ||
public int ColorId { get; init; } = colorId; | ||
public CustomRoles RoleId { get; init; } = roleId; | ||
|
||
public EventCommittedPlayer(PlayerControl playerControl) : this(playerControl.GetRealName(), playerControl.PlayerId, playerControl.Data.DefaultOutfit.ColorId, playerControl.GetCustomRole()) { } | ||
} |
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,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using TownOfHost.Attributes; | ||
|
||
namespace TownOfHost.Modules.GameEventHistory; | ||
|
||
public sealed class EventHistory : IHistoryEvent | ||
{ | ||
public static EventHistory CurrentInstance { get; private set; } | ||
|
||
[GameModuleInitializer] | ||
public static void NewGame() | ||
{ | ||
CurrentInstance = new(); | ||
} | ||
|
||
private readonly List<Event> events = []; | ||
|
||
public void AddEvent(Event @event) | ||
{ | ||
events.Add(@event); | ||
} | ||
public void AppendDiscordString(StringBuilder builder) | ||
{ | ||
foreach (var @event in events) | ||
{ | ||
builder.Append(@event.Bullet); | ||
builder.Append(' '); | ||
builder.Append("<t:"); | ||
var unixTime = (long)@event.UtcTime.Subtract(Epoch).TotalSeconds; | ||
builder.Append(unixTime); | ||
builder.Append(":T> "); | ||
@event.AppendDiscordString(builder); | ||
builder.AppendLine(); | ||
} | ||
} | ||
public string ToDiscordString() | ||
{ | ||
var builder = new StringBuilder(); | ||
AppendDiscordString(builder); | ||
return builder.ToString(); | ||
} | ||
|
||
private readonly static DateTime Epoch = new(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); | ||
} |
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 @@ | ||
using System.Text; | ||
|
||
namespace TownOfHost.Modules.GameEventHistory.Events; | ||
|
||
public sealed class CrewTaskFinishEvent(EventCommittedPlayer player) : Event | ||
{ | ||
public override string Bullet { get; } = ":blue_circle:"; | ||
public EventCommittedPlayer Player { get; } = player; | ||
|
||
public override void AppendDiscordString(StringBuilder builder) | ||
{ | ||
builder.Append("**タスク完了:** "); | ||
AppendPlayerWithEmoji(builder, Player, true); | ||
} | ||
} |
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 @@ | ||
using System.Text; | ||
|
||
namespace TownOfHost.Modules.GameEventHistory.Events; | ||
|
||
public sealed class GameEndEvent(string winsText) : Event | ||
{ | ||
public override string Bullet { get; } = ":green_circle:"; | ||
public string WinsText { get; } = winsText; | ||
|
||
public override void AppendDiscordString(StringBuilder builder) | ||
{ | ||
builder.Append("**ゲーム終了:** "); | ||
builder.Append(WinsText); | ||
} | ||
} |
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,13 @@ | ||
using System.Text; | ||
|
||
namespace TownOfHost.Modules.GameEventHistory.Events; | ||
|
||
public sealed class GameStartEvent : Event | ||
{ | ||
public override string Bullet { get; } = ":green_circle:"; | ||
|
||
public override void AppendDiscordString(StringBuilder builder) | ||
{ | ||
builder.Append("**ゲーム開始**"); | ||
} | ||
} |
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,39 @@ | ||
using System.Text; | ||
|
||
namespace TownOfHost.Modules.GameEventHistory.Events; | ||
|
||
public sealed class MeetingCallEvent(EventCommittedPlayer reporter) : Event | ||
{ | ||
public override string Bullet { get; } = ":green_circle:"; | ||
public EventCommittedPlayer Reporter { get; } = reporter; | ||
public EventCommittedPlayer? Dead { get; } = null; | ||
|
||
public MeetingCallEvent(EventCommittedPlayer reporter, EventCommittedPlayer dead) : this(reporter) | ||
{ | ||
Dead = dead; | ||
} | ||
|
||
public override void AppendDiscordString(StringBuilder builder) | ||
{ | ||
if (Dead.HasValue) | ||
{ | ||
AppendDiscordReport(builder); | ||
} | ||
else | ||
{ | ||
AppendDiscordEmergency(builder); | ||
} | ||
} | ||
private void AppendDiscordReport(StringBuilder builder) | ||
{ | ||
builder.Append("**通報:** "); | ||
AppendPlayerWithEmoji(builder, Reporter, true); | ||
builder.Append(" → "); | ||
AppendPlayerWithEmoji(builder, Dead.Value, false); | ||
} | ||
private void AppendDiscordEmergency(StringBuilder builder) | ||
{ | ||
builder.Append("**緊急会議:** "); | ||
AppendPlayerWithEmoji(builder, Reporter, true); | ||
} | ||
} |
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,27 @@ | ||
using System.Text; | ||
|
||
namespace TownOfHost.Modules.GameEventHistory.Events; | ||
|
||
public sealed class MeetingEndEvent() : Event | ||
{ | ||
public override string Bullet { get; } = ":green_circle:"; | ||
public EventCommittedPlayer? Exiled { get; } = null; | ||
|
||
public MeetingEndEvent(EventCommittedPlayer exiled) : this() | ||
{ | ||
Exiled = exiled; | ||
} | ||
|
||
public override void AppendDiscordString(StringBuilder builder) | ||
{ | ||
builder.Append("**会議結果:** 追放者 "); | ||
if (Exiled.HasValue) | ||
{ | ||
AppendPlayerWithEmoji(builder, Exiled.Value, false); | ||
} | ||
else | ||
{ | ||
builder.Append("なし"); | ||
} | ||
} | ||
} |
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,40 @@ | ||
using System.Text; | ||
using TownOfHost.Roles.Core; | ||
|
||
namespace TownOfHost.Modules.GameEventHistory.Events; | ||
|
||
public sealed class MurderEvent(EventCommittedPlayer killer, EventCommittedPlayer victim, SystemTypes room) : Event | ||
{ | ||
public override string Bullet { get; } = killer.RoleId is CustomRoles.Sheriff ? ":yellow_square:" : ":red_square:"; | ||
public EventCommittedPlayer Killer { get; } = killer; | ||
public EventCommittedPlayer Victim { get; } = victim; | ||
public SystemTypes Room { get; } = room; | ||
|
||
public override void AppendDiscordString(StringBuilder builder) | ||
{ | ||
if (Killer.PlayerId == Victim.PlayerId) | ||
{ | ||
AppendDiscordSuicide(builder); | ||
} | ||
else | ||
{ | ||
AppendDiscordMurder(builder); | ||
} | ||
} | ||
private void AppendDiscordSuicide(StringBuilder builder) | ||
{ | ||
builder.Append("**自爆:** "); | ||
AppendPlayerWithEmoji(builder, Killer, false); | ||
builder.Append(" @"); | ||
builder.Append(DestroyableSingleton<TranslationController>.Instance.GetString(Room)); | ||
} | ||
private void AppendDiscordMurder(StringBuilder builder) | ||
{ | ||
builder.Append("**キル:** "); | ||
AppendPlayerWithEmoji(builder, Killer, true); | ||
builder.Append(" → "); | ||
AppendPlayerWithEmoji(builder, Victim, false); | ||
builder.Append(" @"); | ||
builder.Append(DestroyableSingleton<TranslationController>.Instance.GetString(Room)); | ||
} | ||
} |
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,18 @@ | ||
using System.Text; | ||
|
||
namespace TownOfHost.Modules.GameEventHistory.Events; | ||
|
||
public sealed class RevengeEvent(EventCommittedPlayer cat, EventCommittedPlayer victim) : Event | ||
{ | ||
public override string Bullet { get; } = ":red_circle:"; | ||
public EventCommittedPlayer Cat { get; } = cat; | ||
public EventCommittedPlayer Victim { get; } = victim; | ||
|
||
public override void AppendDiscordString(StringBuilder builder) | ||
{ | ||
builder.Append("**道連れ:** "); | ||
AppendPlayerWithEmoji(builder, Cat, true); | ||
builder.Append(" → "); | ||
AppendPlayerWithEmoji(builder, Victim, false); | ||
} | ||
} |
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,21 @@ | ||
using System.Text; | ||
using TownOfHost.Roles.Core; | ||
|
||
namespace TownOfHost.Modules.GameEventHistory.Events; | ||
|
||
public sealed class RoleChangeEvent(EventCommittedPlayer player, CustomRoles to) : Event | ||
{ | ||
public override string Bullet { get; } = ":green_circle:"; | ||
public EventCommittedPlayer Player { get; } = player; | ||
public CustomRoles To { get; } = to; | ||
|
||
public override void AppendDiscordString(StringBuilder builder) | ||
{ | ||
builder.Append("**ロール変更:** "); | ||
AppendPlayerWithEmoji(builder, Player, true); | ||
builder.Append(" "); | ||
builder.Append(Translator.GetRoleString(Player.RoleId.ToString())); | ||
builder.Append(" → "); | ||
builder.Append(Translator.GetRoleString(To.ToString())); | ||
} | ||
} |
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,8 @@ | ||
using System.Text; | ||
|
||
namespace TownOfHost.Modules.GameEventHistory; | ||
|
||
public interface IHistoryEvent | ||
{ | ||
public void AppendDiscordString(StringBuilder builder); | ||
} |
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
Oops, something went wrong.