Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Maticzpl committed Mar 18, 2021
1 parent 380ab65 commit d8b6774
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 19 deletions.
9 changes: 5 additions & 4 deletions MoreHazards/MoreHazards/Doors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

namespace MoreHazards
{
class DoorEventManager : EventManager
class DoorLogicManager : LogicManager
{
private static CoroutineHandle CoroutineHandle;
private static readonly DoorConfig Config = MoreHazards.Instance.Config.Doors;

public DoorEventManager()
public DoorLogicManager()
{
Warhead.Detonated += OnDetonated;
}
Expand All @@ -30,7 +30,7 @@ public override void Dispose()
Warhead.Detonated -= OnDetonated;
}

public override void OnRoundStart()
public override void OnRoundStart()
{
if (!Config.Enabled)
return;
Expand Down Expand Up @@ -58,8 +58,9 @@ public IEnumerator<float> Timer()

//random door of the room the player is inside
var door = CollectionUtils<DoorVariant>.GetRandomElement((Map.FindParentRoom(player.GameObject).Doors));

door.NetworkTargetState = false;
Debug.Log("Door closed on player:"+player.Nickname);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions MoreHazards/MoreHazards/Elevators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace MoreHazards
{
public class ElevatorEventManager : EventManager
public class ElevatorLogicManager : LogicManager
{
private CoroutineHandle CoroutineHandle;
private readonly ElevatorsConfig Config = MoreHazards.Instance.Config.Elevators;
Expand All @@ -30,7 +30,7 @@ public class ElevatorEventManager : EventManager
[ElevatorType.GateB] = (RoomType.EzGateB, RoomType.Unknown)
};

public ElevatorEventManager()
public ElevatorLogicManager()
{
Warhead.Detonated += OnDetonated;
}
Expand Down Expand Up @@ -88,6 +88,8 @@ public void LiftBreakdown(int duration)

lift.operative = false;

Debug.Log($"Elevator {lift.Type()} disabled for {duration}");

if (Config.BlackoutRoom)
{
var lower = ElevatorToRoomsLookup[lift.Type()].lower;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

namespace MoreHazards
{
public class EventManager : IDisposable
public class LogicManager : IDisposable
{
public EventManager()
public LogicManager()
{
Handlers.Server.RoundStarted += OnRoundStart;
Handlers.Server.RoundEnded += OnRoundEnd;
Expand Down
13 changes: 7 additions & 6 deletions MoreHazards/MoreHazards/MoreHazards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using CustomPlayerEffects;
using Discord;
using Exiled.API.Enums;
using Exiled.API.Features;
Expand All @@ -23,14 +24,14 @@ public class MoreHazards : Plugin<Config>

public override string Author { get; } = "Maticzpl";
public override string Name { get; } = "More Hazards";
public override Version Version { get; } = new Version(1, 0, 0);
public override Version Version { get; } = new Version(0, 1, 0);
public override Version RequiredExiledVersion { get; } = new Version(2, 9, 0);

private MoreHazards()
{
}

private static List<EventManager> EventHandlers = new List<EventManager>();
private static List<LogicManager> LogicHandlers = new List<LogicManager>();
public static MoreHazards Instance => singleton;

public override PluginPriority Priority { get; } = PluginPriority.Medium;
Expand All @@ -40,17 +41,17 @@ public override void OnEnabled()
{
base.OnEnabled();

EventHandlers.Add(new TeslaGateManager());
EventHandlers.Add(new ElevatorEventManager());
EventHandlers.Add(new DoorEventManager());
LogicHandlers.Add(new TeslaGateManager());
LogicHandlers.Add(new ElevatorLogicManager());
LogicHandlers.Add(new DoorLogicManager());
}


public override void OnDisabled()
{
base.OnDisabled();

EventHandlers.Clear();
LogicHandlers.Clear();
}

}
Expand Down
2 changes: 1 addition & 1 deletion MoreHazards/MoreHazards/MoreHazards.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<Compile Include="Config.cs" />
<Compile Include="Doors.cs" />
<Compile Include="Elevators.cs" />
<Compile Include="EventManager.cs" />
<Compile Include="LogicManager.cs" />
<Compile Include="MoreHazards.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TeslaGates.cs" />
Expand Down
8 changes: 6 additions & 2 deletions MoreHazards/MoreHazards/TeslaGates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace MoreHazards
{
public class TeslaGateManager : EventManager
public class TeslaGateManager : LogicManager
{
private Dictionary<Vector3,bool> TeslaStates = new Dictionary<Vector3, bool>();
public List<RoleType> IgnoredByTesla { get; } = new List<RoleType>();
Expand All @@ -27,6 +27,7 @@ public void LoadRolesFromConfig(Config config)
IgnoredByTesla.Clear();
foreach (var role in config.Tesla.IgnoredRoles)
{
Debug.Log($"Tesla ignore role: {role}");
IgnoredByTesla.Add(role);
}
}
Expand Down Expand Up @@ -59,6 +60,8 @@ public void DisableRandomGates(short ChancePerGate, short MaxDisabledGates, shor
SetTeslaEnabled(tesla, false);
}

Debug.Log($"Disabled {DisabledGates} tesla gates");

}

public TeslaGateManager()
Expand All @@ -75,7 +78,6 @@ public override void Dispose()

public override void OnRoundStart()
{

DisableRandomGates(
Config.TeslaGateDisableChance,
Config.MaxDisabledTeslaGates,
Expand All @@ -98,6 +100,7 @@ public void OnTeslaTrigger(TriggeringTeslaEventArgs ev)
if (IgnoredByTesla.Contains(ev.Player.Role))
{
ev.IsTriggerable = false;
Debug.Log($"Tesla ignored by player role");
return;
}

Expand All @@ -115,6 +118,7 @@ public void OnTeslaTrigger(TriggeringTeslaEventArgs ev)
if (Vector3.Distance(ev.Player.Position, tesla.Key) < 7)
{
ev.IsTriggerable = false;
Debug.Log($"Player crossed disabled tesla");
return;
}
}
Expand Down
19 changes: 17 additions & 2 deletions MoreHazards/MoreHazards/utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,34 @@ public void Speak()
Cassie.GlitchyMessage(Text, Glitches, Jams);
}
}

public class CollectionUtils<TValue>
{
public static TValue GetRandomElement(ICollection<TValue> collection)
/* public static TValue GetRandomElement(IReadOnlyCollection<TValue> collection)
{
int index = UnityEngine.Random.Range(0,collection.Count-1);
return collection.ElementAt(index);
}
public static TValue GetRandomElement(List<TValue> collection)
{
int index = UnityEngine.Random.Range(0, collection.Count - 1);
return collection[index];
}*/
public static TValue GetRandomElement(IEnumerable<TValue> enumerable)
{
var collection = (enumerable as IReadOnlyList<TValue>) ?? enumerable.ToArray();
int index = UnityEngine.Random.Range(0, collection.Count - 1);
return collection[index];
}
}

public class Debug
{
public static void Log(object msg)
{
if (MoreHazards.Instance.Config.Debug)
{
Exiled.API.Features.Log.Debug(msg);
}
}
}
}

0 comments on commit d8b6774

Please sign in to comment.