Skip to content

Commit

Permalink
Made style more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
djakkalap committed Oct 23, 2019
1 parent df9ed45 commit efbafd2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
27 changes: 16 additions & 11 deletions ZombiesBreakDoors/ZombiesBreakDoors/BreakDoorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public void OnDoorAccess(PlayerDoorAccessEvent ev) {
Smod2.API.Door door = ev.Door;

// Only allow to destroy doors which normally can't be opened. Also check if there are even enough zombies in the round.
// if ((!ev.Allow && canBeBrokenDown(door)) && zombies.Count >= threshold)
if (!ev.Allow && canBeBrokenDown(door))
if ((!ev.Allow && canBeBrokenDown(door)) && zombies.Count >= threshold)
{
nearbyZombies = getZombiesNearby(door, zombies);
nearbyZombiesCount = nearbyZombies.Count;
Expand All @@ -57,8 +56,10 @@ public void OnDoorAccess(PlayerDoorAccessEvent ev) {
if (plugin.GetConfigBool("zbd_broadcast_countdown"))
{
// Display the countdown for each player
foreach (Player zombie in nearbyZombies) {
if (!playersGettingBC.Contains(zombie.SteamId)) {
foreach (Player zombie in nearbyZombies)
{
if (!playersGettingBC.Contains(zombie.SteamId))
{
Timing.RunCoroutine(_displayCountdown(zombie, delay));
}
}
Expand All @@ -69,8 +70,9 @@ public void OnDoorAccess(PlayerDoorAccessEvent ev) {
{
int amountNeeded = threshold - nearbyZombiesCount;

foreach(Player zombie in nearbyZombies) {
if (!playersGettingBC.Contains(zombie.SteamId)) {
foreach (Player zombie in nearbyZombies) {
if (!playersGettingBC.Contains(zombie.SteamId))
{
Timing.RunCoroutine(_displayZombiesNeeded(zombie, amountNeeded));
}
}
Expand All @@ -85,8 +87,9 @@ private IEnumerator<float> _displayCountdown(Player player, float seconds) {

playersGettingBC.Add(player.SteamId);

for (int i = (int) seconds; i >= 0; i--) {
message = "Breaking door in " + i + " seconds";
for (int i = (int) seconds; i >= 0; i--)
{
message = "Breaking door in " + i;

plugin.CommandManager.CallCommand(new Smod2.Commands.ICommandSender(), "pbc", new string[] { player.Name, "1", message });

Expand Down Expand Up @@ -122,8 +125,10 @@ private bool canBeBrokenDown(Smod2.API.Door door) {
bool breakIfOpen = plugin.GetConfigBool("zbd_breakopendoors");
string[] disallowedDoors = plugin.GetConfigList("zbd_doors_disallow");

if ((door.Open && breakIfOpen) || !door.Open) {
if (!disallowedDoors.Contains(door.Name) && !markedDoorsPos.Contains(door.Position.GetHashCode())) {
if ((door.Open && breakIfOpen) || !door.Open)
{
if (!disallowedDoors.Contains(door.Name) && !markedDoorsPos.Contains(door.Position.GetHashCode()))
{
return true;
}
}
Expand All @@ -136,7 +141,7 @@ private List<Player> getZombiesNearby(Smod2.API.Door door, List<Player> zombies)
List<Player> nearbyZombies = new List<Player>();
Vector doorPos = door.Position;

foreach(Player zombie in zombies)
foreach (Player zombie in zombies)
{
Vector zombiePos = zombie.GetPosition();

Expand Down
3 changes: 1 addition & 2 deletions ZombiesBreakDoors/ZombiesBreakDoors/MiscEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class MiscEventHandler : IEventHandlerWaitingForPlayers {
public MiscEventHandler(ZBDPlugin plugin) => this.plugin = plugin;

public void OnWaitingForPlayers(WaitingForPlayersEvent ev) {
if (plugin.GetConfigBool("zbd_disable"))
plugin.PluginManager.DisablePlugin(plugin);
if (plugin.GetConfigBool("zbd_disable")) plugin.PluginManager.DisablePlugin(plugin);
}
}
}
30 changes: 14 additions & 16 deletions ZombiesBreakDoors/ZombiesBreakDoors/ZBDPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;

using Smod2;
using Smod2;
using Smod2.Attributes;
using Smod2.Config;
using Smod2.EventHandlers;
Expand All @@ -12,7 +10,7 @@ namespace ZombiesBreakDoors {
description = "This plugin allows zombies to gather near a door and break it.",
id = "djakkalap.zbdplugin",
configPrefix = "zbd",
version = "0.3",
version = "0.4",
SmodMajor = 3,
SmodMinor = 5,
SmodRevision = 0
Expand All @@ -21,30 +19,30 @@ namespace ZombiesBreakDoors {
public class ZBDPlugin : Plugin {
// Display info on disable.
public override void OnDisable() {
this.Info(this.Details.name + " has been disabled.");
Info(Details.name + " has been disabled.");
}

// Display info on enable.
public override void OnEnable() {
this.Info(this.Details.name + " has been enabled.");
Info(Details.name + " has been enabled.");
}

// Register the parts of the plugin.
public override void Register() {
// Add new config settings
this.AddConfig(new ConfigSetting("zbd_zombies_threshold", 3, true, "This number determines how many zombies need to be near a door for it to break."));
this.AddConfig(new ConfigSetting("zbd_zombies_range", 2.5f, true, "This number determines how far the zombies need to be in range for them to be considered 'near the door'."));
this.AddConfig(new ConfigSetting("zbd_breakopendoors", false, true, "This boolean determines whether or not to break open doors."));
this.AddConfig(new ConfigSetting("zbd_delay", 2.0f, true, "This number determines how many seconds it takes for a door to break."));
this.AddConfig(new ConfigSetting("zbd_disable", false, true, "This boolean decides whether to load the plugin."));
this.AddConfig(new ConfigSetting("zbd_doors_disallow", new string[] { }, true, "This array contains the rooms which should not be allowed to be broken."));
this.AddConfig(new ConfigSetting("zbd_broadcast_countdown", true, true, "This boolean determines whether to show a countdown for when the door breaks on the players' screens."));
AddConfig(new ConfigSetting("zbd_zombies_threshold", 3, true, "This number determines how many zombies need to be near a door for it to break."));
AddConfig(new ConfigSetting("zbd_zombies_range", 2.5f, true, "This number determines how far the zombies need to be in range for them to be considered 'near the door'."));
AddConfig(new ConfigSetting("zbd_breakopendoors", false, true, "This boolean determines whether or not to break open doors."));
AddConfig(new ConfigSetting("zbd_delay", 2.0f, true, "This number determines how many seconds it takes for a door to break."));
AddConfig(new ConfigSetting("zbd_disable", false, true, "This boolean decides whether to load the plugin."));
AddConfig(new ConfigSetting("zbd_doors_disallow", new string[] { }, true, "This array contains the rooms which should not be allowed to be broken."));
AddConfig(new ConfigSetting("zbd_broadcast_countdown", true, true, "This boolean determines whether to show a countdown for when the door breaks on the players' screens."));
AddConfig(new ConfigSetting("zbd_broadcast_zombiesneeded", true, true, "This boolean determines whether to show how many zombies extra are needed near the door."));

this.AddCommand("zbddisable", new ZBDDisableCommand(this));
AddCommand("zbddisable", new ZBDDisableCommand(this));

this.AddEventHandler(typeof(IEventHandlerDoorAccess), new BreakDoorHandler(this));
this.AddEventHandler(typeof(IEventHandlerWaitingForPlayers), new MiscEventHandler(this));
AddEventHandler(typeof(IEventHandlerDoorAccess), new BreakDoorHandler(this));
AddEventHandler(typeof(IEventHandlerWaitingForPlayers), new MiscEventHandler(this));
}
}
}

0 comments on commit efbafd2

Please sign in to comment.