Skip to content

Commit

Permalink
Remove comments, refactor to focus on disconnecting players
Browse files Browse the repository at this point in the history
  • Loading branch information
PatPeter committed Jun 4, 2018
1 parent 2d7479d commit f36537b
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 140 deletions.
2 changes: 1 addition & 1 deletion Smod2/Smod2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ProjectGuid>{6B3C975A-CA75-4764-8192-E1D8EC8E6475}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ZombieSuicideHotline</RootNamespace>
<RootNamespace>Smod2</RootNamespace>
<AssemblyName>Smod2</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
Expand Down
26 changes: 14 additions & 12 deletions ZombieSuicideHotline/ZombieSuicideHotline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ namespace ZombieSuicideHotline
name = "ZombieSuicideHotline",
description = "Respawns zombies that intentionally kill themselves.",
id = "patpeter.zombiesuicidehotline",
version = "1.0-build17",
version = "1.0-build18",
SmodMajor = 2,
SmodMinor = 0,
SmodRevision = 0
SmodMinor = 2,
SmodRevision = 1
)]
class ZombieSuicideHotlinePlugin : Plugin
{
public HashSet<string> zombieSuicides = new HashSet<string>();
public HashSet<string> deadDoctors = new HashSet<string>();
public TeamClass plagueDoctorClass = null;
public TeamClass zombieClass = null;
public Dictionary<Classes, TeamClass> ClassList = new Dictionary<Classes, TeamClass>();
internal bool duringRound = false;
internal HashSet<string> scp049Kills = new HashSet<string>();
internal HashSet<string> zombieDisconnects = new HashSet<string>();
internal Dictionary<Classes, TeamClass> ClassList = new Dictionary<Classes, TeamClass>();

public override void OnEnable()
{
Expand All @@ -33,16 +32,19 @@ public override void OnEnable()

public override void OnDisable()
{

}

public override void Register()
{
// Register Events
this.AddEventHandler(typeof(IEventRoundStart), new RoundStartHandler(this), Priority.Highest);
this.AddEventHandler(typeof(IEventPlayerDie), new PlayerDieHandler(this), Priority.Highest);
//this.AddEventHandler(typeof(IEventAssignTeam), new AssignTeamHandler(this), Priority.High);
this.AddEventHandler(typeof(IEventSetClass), new SetClass1Handler(this), Priority.High);
this.AddEventHandler(typeof(IEventSetClass), new SetClass2Handler(this), Priority.Normal);
this.AddEventHandler(typeof(IEventRoundEnd), new RoundEndHandler(this), Priority.Highest);
this.AddEventHandler(typeof(IEventPlayerJoin), new PlayerJoinHandler(this), Priority.Highest);
this.AddEventHandler(typeof(IEventPlayerLeave), new PlayerLeaveHandler(this), Priority.Highest);
this.AddEventHandler(typeof(IEventSetClass), new SetClassHandler(this), Priority.Highest);
this.AddEventHandler(typeof(IEventPlayerDie), new PlayerDieHandler(this), Priority.Highest);
this.AddEventHandler(typeof(IEventPlayerHurt), new PlayerHurtHandler(this), Priority.Highest);
// Register config settings
this.AddConfig(new Smod2.Config.ConfigSetting("zombie_suicide_hotline_enabled", true, Smod2.Config.SettingType.BOOL, true, "Enables or disables the zombie suicide hotline."));
}
Expand Down
211 changes: 84 additions & 127 deletions ZombieSuicideHotline/ZombieSuicideHotlineEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,202 +10,159 @@ class RoundStartHandler : IEventRoundStart

public RoundStartHandler(Plugin plugin)
{
this.plugin = (ZombieSuicideHotlinePlugin)plugin;
this.plugin = (ZombieSuicideHotlinePlugin) plugin;
}

public void OnRoundStart(Server server)
{
this.plugin.duringRound = true;
this.plugin.scp049Kills = new System.Collections.Generic.HashSet<string>();
this.plugin.zombieDisconnects = new System.Collections.Generic.HashSet<string>();
foreach (TeamClass teamClass in server.GetClasses())
{
this.plugin.ClassList.Add(teamClass.ClassType, teamClass);
}
plugin.Info("ClassList SIZE " + this.plugin.ClassList.Count);
}
}

class PlayerDieHandler : IEventPlayerDie
class RoundEndHandler : IEventRoundEnd
{
private ZombieSuicideHotlinePlugin plugin;

public PlayerDieHandler(Plugin plugin)
public RoundEndHandler(Plugin plugin)
{
this.plugin = (ZombieSuicideHotlinePlugin)plugin;
this.plugin = (ZombieSuicideHotlinePlugin) plugin;
}

public void OnPlayerDie(Player player, Player killer, out bool spawnRagdoll)
public void OnRoundEnd(Server server, Round round)
{
//plugin.Info("ZombieSuicideHotline OnPlayerDie");
//plugin.Info(player.ToString());
//plugin.Info(player.Class.Name);
//plugin.Info(killer.ToString());
//plugin.Info(killer.Class.Name);
if (player.Class.ClassType == Classes.SCP_049_2)
{
//plugin.Info("ZombieSuicideHotline OnPlayerDie 049-2");
//if (killer == null)
//if (player == killer)
if (player.SteamId == killer.SteamId)
{
spawnRagdoll = false;

this.plugin.zombieSuicides.Add(player.SteamId);
/*Vector position = null;
if (this.plugin.SCPSpawnPoints.TryGetValue(Classes.SCP_049, out position))
{
plugin.Info("ZombieSuicideHotline OnPlayerDie RESPAWN");
//player.ChangeClass(Classes.SCP_049_2, true, true);
player.Teleport(position);
}
else
{
plugin.Info("SCP-049-2 SPAWNED WITHOUT SCP-049.");
//player.ChangeClass(Classes.SCP_049_2, true, true);
}*/
}
else
{
spawnRagdoll = true;
}
}
else if (player.Class.ClassType == Classes.SCP_106)
{
plugin.Info("ZombieSuicideHotline Larry");
spawnRagdoll = false;
}
else
this.plugin.duringRound = false;
foreach (TeamClass teamClass in server.GetClasses())
{
plugin.Info("ZombieSuicideHotline Other");
spawnRagdoll = true;
this.plugin.ClassList.Add(teamClass.ClassType, teamClass);
}
plugin.Info("ClassList SIZE " + this.plugin.ClassList.Count);
}
}

/*class AssignTeamHandler : IEventAssignTeam
class PlayerJoinHandler : IEventPlayerJoin
{
private ZombieSuicideHotlinePlugin plugin;

public AssignTeamHandler(Plugin plugin)
public PlayerJoinHandler(Plugin plugin)
{
this.plugin = (ZombieSuicideHotlinePlugin)plugin;
this.plugin = (ZombieSuicideHotlinePlugin) plugin;
}

public void OnAssignTeam(Player player, Teams team, out Teams teamOutput)
public void OnPlayerJoin(Player player)
{
if (this.plugin.zombieSuicides.Contains(player.SteamId))
if (this.plugin.duringRound && this.plugin.zombieDisconnects.Contains(player.SteamId))
{
plugin.Info("SUICIDE ZOMBIE FOUND " + player.ToString() + " " + player.Class.ToString());
this.plugin.zombieSuicides.Remove(player.SteamId);
TeamClass teamClass = null;
if (this.plugin.ClassList.TryGetValue(Classes.SCP_049_2, out teamClass))
{
plugin.Info("ZOMBIE CLASS FOUND, SET FROM SPECTATOR TO ZOMBIE " + teamClass.ToString());
teamOutput = teamClass.Team;
} else
{
plugin.Info("ZOMBIE CLASS NOT FOUND");
teamOutput = team;
}
player.ChangeClass(Classes.SCP_049_2, true, true);
this.plugin.zombieDisconnects.Add(player.SteamId);
}
else
}
}

class PlayerLeaveHandler : IEventPlayerLeave
{
private ZombieSuicideHotlinePlugin plugin;

public PlayerLeaveHandler(Plugin plugin)
{
this.plugin = (ZombieSuicideHotlinePlugin) plugin;
}

public void OnPlayerLeave(Player player)
{
if (this.plugin.duringRound && this.plugin.scp049Kills.Contains(player.SteamId))
{
plugin.Info("NON-ZOMBIE ASSIGNED TEAM " + player.ToString() + " " + player.Class.ToString());
teamOutput = team;
this.plugin.scp049Kills.Remove(player.SteamId);
this.plugin.zombieDisconnects.Add(player.SteamId);
}
}
}*/
}

class SetClass1Handler : IEventSetClass
class SetClassHandler : IEventSetClass
{
private ZombieSuicideHotlinePlugin plugin;

public SetClass1Handler(Plugin plugin)
public SetClassHandler(Plugin plugin)
{
this.plugin = (ZombieSuicideHotlinePlugin)plugin;
}

public void OnSetClass(Player player, TeamClass teamclass, out TeamClass teamclassOutput)
{
// Player's vector is spectator vector in this event
/*switch (teamclass.ClassType)
{
case Classes.SCP_049:
case Classes.SCP_096:
case Classes.SCP_106:
case Classes.SCP_173:
this.plugin.SCPSpawnPoints.Add(player.Class.ClassType, player.GetPosition());
break;
}*/

/*plugin.Info("PLAYER " + player.Name + " is changing class to " + teamclass.Name);
if (teamclass.ClassType == Classes.SCP_049)
if (this.plugin.duringRound && this.plugin.scp049Kills.Contains(player.SteamId))
{
this.plugin.plagueDoctorClass = teamclass;
plugin.Info("PLAGUE DOCTOR ASSIGNED." + this.plugin.plagueDoctorClass.Name);
plugin.Info("Remove player from scp049Kills");
this.plugin.scp049Kills.Remove(player.SteamId);
teamclassOutput = teamclass;
}
else if (teamclass.ClassType == Classes.SCP_049_2)
else
{
this.plugin.zombieClass = teamclass;
plugin.Info("ZOMBIE CLASS ASSIGNED." + this.plugin.zombieClass.Name);
plugin.Info("NOT RESPAWNING ZOMBIE");
teamclassOutput = teamclass;
}
}
}

plugin.Info("ZOMBIE SUICIDES");
foreach (string s in this.plugin.zombieSuicides)
{
plugin.Info(s);
}
class PlayerDieHandler : IEventPlayerDie
{
private ZombieSuicideHotlinePlugin plugin;

plugin.Info("DEAD DOCTORS");
foreach (string s in this.plugin.zombieSuicides)
{
plugin.Info(s);
}*/
public PlayerDieHandler(Plugin plugin)
{
this.plugin = (ZombieSuicideHotlinePlugin) plugin;
}

if (this.plugin.zombieSuicides.Contains(player.SteamId))
public void OnPlayerDie(Player player, Player killer, out bool spawnRagdoll)
{
if (this.plugin.duringRound && killer.Class.ClassType == Classes.SCP_049)
{
plugin.Info("RESPAWNING AS PLAGUE DOCTOR " //+ this.plugin.plagueDoctorClass.Name
);
//teamclassOutput.Team = Teams.SCP;
//teamclassOutput.ClassType = Classes.SCP_049_2;
this.plugin.zombieSuicides.Remove(player.SteamId);
this.plugin.deadDoctors.Add(player.SteamId);
teamclassOutput = this.plugin.ClassList[Classes.SCP_049]; //this.plugin.plagueDoctorClass;
this.plugin.scp049Kills.Add(player.SteamId);
spawnRagdoll = true;
}
/*else if (this.plugin.deadDoctors.Contains(player.SteamId))
else if (player.Class.ClassType == Classes.SCP_106)
{
plugin.Info("KILLING DOCTOR " + this.plugin.zombieClass.Name);
//player.Damage(9999, DamageType.TESLA);
this.plugin.deadDoctors.Remove(player.SteamId);
teamclassOutput = this.plugin.ClassList[Classes.SCP_049_2]; //this.plugin.zombieClass;
}*/
spawnRagdoll = false;
}
else
{
plugin.Info("NOT RESPAWNING ZOMBIE");
teamclassOutput = teamclass;
spawnRagdoll = true;
}
}
}

class SetClass2Handler : IEventSetClass
class PlayerHurtHandler : IEventPlayerHurt
{
private ZombieSuicideHotlinePlugin plugin;

public SetClass2Handler(Plugin plugin)
public PlayerHurtHandler(Plugin plugin)
{
this.plugin = (ZombieSuicideHotlinePlugin)plugin;
this.plugin = (ZombieSuicideHotlinePlugin) plugin;
}

public void OnSetClass(Player player, TeamClass teamclass, out TeamClass teamclassOutput)
public void OnPlayerHurt(Player player, Player attacker, float damage, out float damageOutput, DamageType type, out DamageType typeOutput)
{
if (this.plugin.deadDoctors.Contains(player.SteamId))
switch (player.Class.ClassType)
{
plugin.Info("KILLING DOCTOR " + this.plugin.zombieClass.Name);
//player.Damage(9999, DamageType.TESLA);
this.plugin.deadDoctors.Remove(player.SteamId);
teamclassOutput = this.plugin.ClassList[Classes.SCP_049_2]; //this.plugin.zombieClass;
} else
{
plugin.Info("NOT RESPAWNING DOCTOR");
teamclassOutput = teamclass;
case Classes.SCP_049_2:
if (type == DamageType.TESLA)
{
typeOutput = DamageType.NONE;
damageOutput = 0f;
}
else
{
goto default;
}
break;
default:
typeOutput = type;
damageOutput = damage;
break;
}
}
}
Expand Down

0 comments on commit f36537b

Please sign in to comment.