Skip to content

Commit

Permalink
Synapse 3
Browse files Browse the repository at this point in the history
  • Loading branch information
GrafDimenzio committed Mar 8, 2023
1 parent 10ad776 commit 2e2750a
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 186 deletions.
148 changes: 50 additions & 98 deletions Scp056/EventHandler.cs
Original file line number Diff line number Diff line change
@@ -1,122 +1,74 @@
using System.Linq;
using Interactables.Interobjects.DoorUtils;
using Neuron.Core.Logging;
using Synapse3.SynapseModule.Enums;
using Neuron.Core.Events;
using Neuron.Core.Meta;
using Ninject;
using PlayerRoles;
using PlayerRoles.RoleAssign;
using Synapse3.SynapseModule;
using Synapse3.SynapseModule.Events;
using Synapse3.SynapseModule.Player;
using UnityEngine;
using VoiceChat;

namespace Scp056;

public class EventHandler
[Automatic]
public class EventHandler : Listener
{
private readonly Scp056Plugin _plugin;
private readonly PlayerService _player;
[Inject]
public Scp056Plugin Plugin { get; set; }
[Inject]
public PlayerService Player { get; set; }

public EventHandler(PlayerEvents playerEvents, RoundEvents roundEvents, PlayerService player,
Scp056Plugin plugin)
[EventHandler]
public void FirstSpawn(FirstSpawnEvent ev)
{
_player = player;
_plugin = plugin;

playerEvents.KeyPress.Subscribe(KeyPress);
playerEvents.Death.Subscribe(Death);
roundEvents.FirstSpawn.Subscribe(FirstSpawn);
}

private void FirstSpawn(FirstSpawnEvent ev)
{
if (!_plugin.Config.EnableDefaultSpawnBehaviour) return;
if (ev.PlayerAndRoles.Count < _plugin.Config.RequiredPlayers) return;
if (Random.Range(1f, 100f) > _plugin.Config.SpawnChance) return;

var possiblePlayers = _plugin.Config.ReplaceScp
? ev.PlayerAndRoles.Where(x => IsScpID(x.Value))
: ev.PlayerAndRoles.Where(x => !IsScpID(x.Value));

if (possiblePlayers.Count() == 0)
return;

System.Collections.Generic.KeyValuePair<SynapsePlayer, uint> pair;


if (_plugin.Config.ReplaceScp && _plugin.Config.Replace079 && possiblePlayers.Count() == 2 &&
possiblePlayers.Any(x => x.Value == (int)RoleType.Scp079))
pair = possiblePlayers.FirstOrDefault(x => x.Value == (uint)RoleType.Scp079);
else
pair = possiblePlayers.ElementAt(UnityEngine.Random.Range(0, possiblePlayers.Count()));

ev.PlayerAndRoles[pair.Key] = 56;
if (!Plugin.Config.EnableDefaultSpawnBehaviour) return;
if (Player.Players.Count < Plugin.Config.RequiredPlayers) return;
if (Random.Range(1f, 100f) > Plugin.Config.SpawnChance) return;
if(Plugin.Config.ReplaceScp && ev.AmountOfScpSpawns <= 0) return;

var possiblePlayers = Player.Players.Where(x => RoleAssigner.CheckPlayer(x.Hub)).ToArray();
if (!possiblePlayers.Any()) return;
var player = possiblePlayers[Random.Range(0, possiblePlayers.Count())];
ev.PlayersBlockedFromSpawning.Add(player);
player.RoleID = 56;
if (Plugin.Config.ReplaceScp)
ev.AmountOfScpSpawns--;
}

private bool IsScpID(uint id) => id is (uint)RoleType.Scp173 or (uint)RoleType.Scp049 or (uint)RoleType.Scp0492
or (uint)RoleType.Scp079 or (uint)RoleType.Scp096 or (uint)RoleType.Scp106 or (uint)RoleType.Scp93953
or (uint)RoleType.Scp93989;

private void Death(DeathEvent ev)

[EventHandler]
public void Death(DeathEvent ev)
{
if (ev.Attacker == null || ev.Attacker == ev.Player) return;

if (ev.Player.RoleID == 56)
ev.Attacker.SendBroadcast(_plugin.Translation.Get(ev.Attacker).Killed056, 7);
ev.Attacker.SendBroadcast(Plugin.Translation.Get(ev.Attacker).Killed056, 7);
else if (ev.Attacker.RoleID == 56)
ev.Player.SendWindowMessage(_plugin.Translation.Get(ev.Player).KilledBy056);
ev.Player.SendWindowMessage(Plugin.Translation.Get(ev.Player).KilledBy056);
}

private void KeyPress(KeyPressEvent ev)
//TODO: Implement SCP Chat ability
/*
[EventHandler]
public void SpeakEvent(SpeakEvent ev)
{
if (ev.Player.RoleID != 56) return;
RoleType role;

switch (ev.KeyCode)
if (ev.Player.RoleID == 56 && (ev.Player.CustomRole as Scp056PlayerScript)?.ScpChat == true)
{
case KeyCode.Keypad1:
role = RoleType.ClassD;
break;

case KeyCode.Keypad2:
role = RoleType.Scientist;
break;

case KeyCode.Keypad3:
role = RoleType.FacilityGuard;
break;

case KeyCode.Keypad4:
role = RoleType.NtfSergeant;
break;

case KeyCode.Keypad5:
role = RoleType.ChaosRepressor;
break;

case KeyCode.Keypad6:
role = RoleType.Scp049;
break;

case KeyCode.Keypad7:
role = RoleType.Scp096;
break;

case KeyCode.Keypad8:
role = RoleType.Scp173;
break;

case KeyCode.Keypad9:
role = RoleType.Scp93953;
break;

case KeyCode.Keypad0:
var targets = _player
.GetPlayers(x => x.TeamID is (uint)Team.MTF or (uint)Team.CDP or (uint)Team.RSC).Count;

ev.Player.SendBroadcast(
_plugin.Translation.Get(ev.Player).Targets.Replace("%targets%", targets.ToString()), 7);
return;
SynapseLogger<Scp056Plugin>.Warn("SpeakEvent");
ev.Channel = VoiceChatChannel.ScpChat;
}
}
default: return;
[EventHandler]
public void SpeakPlayerEvent(SpeakToPlayerEvent ev)
{
if (ev.Receiver.RoleID == 56 && ev.Player.Hub.IsSCP() &&
(ev.Player.CustomRole as Scp056PlayerScript)?.ScpChat == true)
{
SynapseLogger<Scp056Plugin>.Warn("SpeakEventPlayer");
ev.Channel = VoiceChatChannel.ScpChat;
}

(ev.Player.CustomRole as Scp056PlayerScript)?.SwapRole(role);
}
*/
}
15 changes: 15 additions & 0 deletions Scp056/KeyBind/Scp056SwapBind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using PlayerRoles;
using Synapse3.SynapseModule.Player;

namespace Scp056.KeyBind;

public abstract class Scp056SwapBind : Synapse3.SynapseModule.KeyBind.KeyBind
{
public abstract RoleTypeId SwapRole { get; }

public override void Execute(SynapsePlayer player)
{
if (player.RoleID != 56) return;
(player.CustomRole as Scp056PlayerScript)?.SwapRole(SwapRole);
}
}
105 changes: 105 additions & 0 deletions Scp056/KeyBind/SwapClasses.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using Neuron.Core.Meta;
using PlayerRoles;
using Synapse3.SynapseModule.KeyBind;
using UnityEngine;

namespace Scp056.KeyBind;

[Automatic]
[KeyBind(
Bind = KeyCode.Keypad1,
CommandDescription = "Swaps to D-Class as 056",
CommandName = "ClassDSwap"
)]
public class ClassD : Scp056SwapBind
{
public override RoleTypeId SwapRole => RoleTypeId.ClassD;
}

[Automatic]
[KeyBind(
Bind = KeyCode.Keypad2,
CommandDescription = "Swaps to Scientist as 056",
CommandName = "ScientistSwap"
)]
public class Scientist : Scp056SwapBind
{
public override RoleTypeId SwapRole => RoleTypeId.Scientist;
}

[Automatic]
[KeyBind(
Bind = KeyCode.Keypad3,
CommandDescription = "Swaps to Guard as 056",
CommandName = "GuardSwap"
)]
public class Guard : Scp056SwapBind
{
public override RoleTypeId SwapRole => RoleTypeId.FacilityGuard;
}

[Automatic]
[KeyBind(
Bind = KeyCode.Keypad4,
CommandDescription = "Swaps to NTF as 056",
CommandName = "NtfSwap"
)]
public class Ntf : Scp056SwapBind
{
public override RoleTypeId SwapRole => RoleTypeId.NtfSergeant;
}

[Automatic]
[KeyBind(
Bind = KeyCode.Keypad5,
CommandDescription = "Swaps to Chaos as 056",
CommandName = "ChaosSwap"
)]
public class Chaos : Scp056SwapBind
{
public override RoleTypeId SwapRole => RoleTypeId.ChaosRepressor;
}

[Automatic]
[KeyBind(
Bind = KeyCode.Keypad6,
CommandDescription = "Swaps to Scp049 as 056",
CommandName = "Scp049Swap"
)]
public class Scp049 : Scp056SwapBind
{
public override RoleTypeId SwapRole => RoleTypeId.Scp049;
}

[Automatic]
[KeyBind(
Bind = KeyCode.Keypad7,
CommandDescription = "Swaps to Scp173 as 056",
CommandName = "Scp173Swap"
)]
public class Scp173 : Scp056SwapBind
{
public override RoleTypeId SwapRole => RoleTypeId.Scp173;
}

[Automatic]
[KeyBind(
Bind = KeyCode.Keypad8,
CommandDescription = "Swaps to Scp096 as 056",
CommandName = "Scp096Swap"
)]
public class Scp096 : Scp056SwapBind
{
public override RoleTypeId SwapRole => RoleTypeId.Scp096;
}

[Automatic]
[KeyBind(
Bind = KeyCode.Keypad9,
CommandDescription = "Swaps to Scp939 as 056",
CommandName = "Scp939Swap"
)]
public class Scp939 : Scp056SwapBind
{
public override RoleTypeId SwapRole => RoleTypeId.Scp939;
}
35 changes: 35 additions & 0 deletions Scp056/KeyBind/TargetBind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Neuron.Core.Meta;
using Ninject;
using PlayerRoles;
using Synapse3.SynapseModule;
using Synapse3.SynapseModule.KeyBind;
using Synapse3.SynapseModule.Player;
using UnityEngine;

namespace Scp056.KeyBind;

[Automatic]
[KeyBind(
Bind = KeyCode.Keypad0,
CommandDescription = "Displays the number of targets for SCP-056",
CommandName = "Scp056Targets"
)]
public class TargetBind : Synapse3.SynapseModule.KeyBind.KeyBind
{
[Inject]
public PlayerService PlayerService { get; set; }

[Inject]
public Scp056Plugin Plugin { get; set; }

public override void Execute(SynapsePlayer player)
{
if (player.RoleID != 56) return;

var targets = PlayerService.GetPlayers(x =>
x.TeamID is (uint)Team.FoundationForces or (uint)Team.ClassD or (uint)Team.Scientists).Count;

player.SendBroadcast(
Plugin.Translation.Get(player).Targets.Replace("%targets%", targets.ToString()), 7);
}
}
1 change: 0 additions & 1 deletion Scp056/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Allgemeine Informationen über eine Assembly werden über die folgenden
Expand Down
Loading

0 comments on commit 2e2750a

Please sign in to comment.