Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last alive broadcast #2

Merged
merged 6 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions AutoBroadcast.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@


<ItemGroup>
<PackageReference Include="EXILED" Version="8.4.3" />
<PackageReference Include="EXILED" Version="8.8.0" />
<PackageReference Include="Lib.Harmony" Version="2.2.2" />
<PackageReference Include="UnityEngine.Modules" Version="2019.4.15" IncludeAssets="compile" />
</ItemGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp-firstpass" HintPath="$(EXILED_REFERENCES)\Assembly-CSharp-firstpass.dll"/>
<Reference Include="Mirror" HintPath="$(EXILED_REFERENCES)\Mirror.dll"/>
<Reference Include="Assembly-CSharp-firstpass" HintPath="$(EXILED_REFERENCES)\Assembly-CSharp-firstpass.dll" />
<Reference Include="Mirror" HintPath="$(EXILED_REFERENCES)\Mirror.dll" />
<Reference Include="UnityEngine.CoreModule" HintPath ="$(EXILED_REFERENCES)\UnityEngine.CoreModule.dll" />
<Reference Include="UnityEngine.PhysicsModule" HintPath="$(EXILED_REFERENCES)\UnityEngine.PhysicsModule.dll" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ public class Config : IConfig
Message = "Containment breach detected",
}
};

public BroadCassie? LastPlayerOnTeam { get; set; } = new()
{
Broadcast = new()
{
Message = "You are the last remaining on your team!",
},
Cassie = new()
{
Message = "There is 1 {role} remaining!"
}
};

public Dictionary<int, BroadCassie> Delayed { get; set; } = new()
{
Expand Down
21 changes: 19 additions & 2 deletions Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Exiled.API.Features;
using MEC;
using Exiled.Events.EventArgs.Map;
using PlayerRoles;

namespace AutoBroadcastSystem.Events;

Expand All @@ -19,8 +20,9 @@ public Handler()
Exiled.Events.Handlers.Server.RespawningTeam += OnRespawningTeam;
Exiled.Events.Handlers.Player.Verified += OnVerified;
Exiled.Events.Handlers.Player.Spawned += OnSpawned;
Exiled.Events.Handlers.Player.Died += OnDied;

if(AutoBroadcast.Instance.Config.NtfAnnouncementCassie != "DISABLED" && AutoBroadcast.Instance.Config.NtfAnnouncementCassieNoScps != "DISABLED")
if (AutoBroadcast.Instance.Config.NtfAnnouncementCassie != "DISABLED" && AutoBroadcast.Instance.Config.NtfAnnouncementCassieNoScps != "DISABLED")
Exiled.Events.Handlers.Map.AnnouncingNtfEntrance += OnAnnouncingNtf;
}

Expand All @@ -31,8 +33,9 @@ public Handler()
Exiled.Events.Handlers.Server.RespawningTeam -= OnRespawningTeam;
Exiled.Events.Handlers.Player.Verified -= OnVerified;
Exiled.Events.Handlers.Player.Spawned -= OnSpawned;
Exiled.Events.Handlers.Player.Died -= OnDied;

if(AutoBroadcast.Instance.Config.NtfAnnouncementCassie != "DISABLED" || AutoBroadcast.Instance.Config.NtfAnnouncementCassieNoScps != "DISABLED")
if (AutoBroadcast.Instance.Config.NtfAnnouncementCassie != "DISABLED" || AutoBroadcast.Instance.Config.NtfAnnouncementCassieNoScps != "DISABLED")
Exiled.Events.Handlers.Map.AnnouncingNtfEntrance -= OnAnnouncingNtf;
}

Expand Down Expand Up @@ -130,6 +133,20 @@ public void OnSpawned(SpawnedEventArgs ev)
}
}

public void OnDied(DiedEventArgs ev)
{
if (ev.TargetOldRole.GetTeam() is not Team.SCPs and not Team.OtherAlive)
{
List<Player> playerTeam = Player.Get(ev.Player.Role.Team).ToList();
if (playerTeam.Count == 1)
{
Log.Debug($"{ev.TargetOldRole.GetTeam()} has 1 person remaining on their team, starting LastPlayerAlive Broadcast/Cassie");
config.LastPlayerOnTeam?.Broadcast?.Show(playerTeam.FirstOrDefault());
config.LastPlayerOnTeam?.Cassie?.Send(ev.Player.Role.Type);
}
}
}

public IEnumerator<float> DoIntervalBroadcast(int interval, BroadCassie message)
{
while (Round.IsStarted)
Expand Down
37 changes: 27 additions & 10 deletions Objects.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Exiled.API.Features;
using PlayerRoles;
using System.ComponentModel;
using AutoBroadcastSystem.Events;
using Exiled.API.Extensions;

namespace AutoBroadcastSystem;

Expand All @@ -14,11 +17,11 @@ public class BroadcastSystem
[Description("How long the hint/broadcast should show")]
public ushort Duration { get; set; } = 3;
[Description("The message shown on the broadcast")]
public string Message { get; set; } = "";
public string Message { get; set; } = string.Empty;
[Description("Override broadcasts")]
public bool Override { get; set; } = false;
public bool Override { get; set; }
[Description("Whether or not to use hints instead")]
public bool UseHints { get; set; } = false;
public bool UseHints { get; set; }

public void Show()
{
Expand All @@ -31,7 +34,7 @@ public void Show()
public void Show(Player player)
{
if (UseHints)
player.ShowHint(Message, Duration);
player.ShowHint(Message, Duration);
else
player.Broadcast(Duration, Message, default, Override);
}
Expand All @@ -42,15 +45,29 @@ public class CassieBroadcast
[Description("The CASSIE message to be sent")]
public string Message { get; set; } = "";
[Description("The text to be shown")]
public string Translation { get; set; } = "";
public string Translation { get; set; } = string.Empty;
[Description("Whether or not to hide the subtitle for the cassie message")]
public bool ShowSubtitles { get; set; } = true;

public void Send()
{
Cassie.MessageTranslated(
Message,
Translation.IsEmpty() ? Message : Translation,
isSubtitles: ShowSubtitles);
Cassie.MessageTranslated(Message,Translation.IsEmpty() ? Message : Translation, isSubtitles: ShowSubtitles);
}
}

public void Send(Player player)
{
player.MessageTranslated(Message, Translation.IsEmpty() ? Message : Translation, isSubtitles: ShowSubtitles);
}

/// <summary>
/// Sends the CASSIE to all players replacing "{role}" with <paramref name="role"/>'s full name.
/// </summary>
/// <remarks>Used by <see cref="Handler.OnDied"/></remarks>
public void Send(RoleTypeId role)
{
Cassie.MessageTranslated(
Message.Replace("{role}", role.GetFullName()),
Translation.IsEmpty() ? Message.Replace("{role}", role.GetFullName()) : Translation.Replace("{role}", role.GetFullName()),
isSubtitles: ShowSubtitles);
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ chaos_announcement: null
ntf_announcement_cassie_no_scps: 'DISABLED'
ntf_announcement_cassie: 'DISABLED'
round_start: null
last_player_on_team: null
timed: {}
intervals: {}
spawn_broadcasts: {}
Expand Down