Skip to content
This repository has been archived by the owner on Feb 28, 2021. It is now read-only.

Commit

Permalink
Changed how spawning works
Browse files Browse the repository at this point in the history
  • Loading branch information
PintTheDragon committed Jun 23, 2020
1 parent d29ed28 commit a854582
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Buddy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace PintBuddy
id = "com.PintTheDragon.BuddyPlugin",
configPrefix = "buddy",
langFile = "buddyplugin",
version = "1.1.3",
version = "1.1.5",
SmodMajor = 3,
SmodMinor = 7,
SmodRevision = 0
Expand Down Expand Up @@ -106,6 +106,7 @@ public override void Register()
this.AddEventHandler(typeof(IEventHandlerRoundStart), new RoundStartHandler(this), Priority.Highest);
this.AddEventHandler(typeof(IEventHandlerCallCommand), new CommandHandler(this), Priority.Normal);
this.AddEventHandler(typeof(IEventHandlerPlayerJoin), new JoinHandler(this), Priority.Normal);
this.AddEventHandler(typeof(IEventHandlerRoundRestart), new RoundRestartHandler(this), Priority.Normal);
this.prefixedMessage = BuddyMessage.Replace("$buddyCMD", "."+buddyCommand);
this.invalidUsage = invalidUsage.Replace("$buddyCMD", "." + buddyCommand);
}
Expand Down
1 change: 1 addition & 0 deletions Buddy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<Compile Include="CommandHandler.cs" />
<Compile Include="JoinHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RoundRestartHandler.cs" />
<Compile Include="RoundStartHandler.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
26 changes: 26 additions & 0 deletions RoundRestartHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Smod2.API;
using Smod2.EventHandlers;
using Smod2.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PintBuddy
{
class RoundRestartHandler : IEventHandlerRoundRestart
{
private Buddy buddyPlugin;

public RoundRestartHandler(Buddy buddyPlugin)
{
this.buddyPlugin = buddyPlugin;
}

public void OnRoundRestart(RoundRestartEvent ev)
{
buddyPlugin.buddies = new Dictionary<string, Player>();
}
}
}
26 changes: 16 additions & 10 deletions RoundStartHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Smod2.Events;
using System;
using System.Collections.Generic;
using System.Linq;

namespace PintBuddy
{
Expand All @@ -19,12 +20,13 @@ public RoundStartHandler(Buddy buddyPlugin)

public void OnRoundStart(RoundStartEvent ev)
{
List<Player> players = ev.Server.GetPlayers();
IEnumerable<Player> players = buddyPlugin.buddies.Values;
List<String> doneIDs = new List<String>();

//loop through all players
for(int i = 0; i < players.Count; i++)
for (int i = 0; i < players.Count(); i++)
{
Player player = players[i];
Player player = players.ElementAt(i);
//check if player has a buddy
if (buddyPlugin.buddies.ContainsKey(player.UserId))
{
Expand All @@ -33,8 +35,9 @@ public void OnRoundStart(RoundStartEvent ev)
Player buddy = null;
buddyPlugin.buddies.TryGetValue(player.UserId, out buddy);
if (buddy == null) continue;
if (doneIDs.Contains(player.UserId) || doneIDs.Contains(buddy.UserId)) continue;
//take action if they have different roles
if(player.TeamRole.Role != buddy.TeamRole.Role &&
if (player.TeamRole.Role != buddy.TeamRole.Role &&
/* massive check for scientist/guard combo */
!(!buddyPlugin.disallowGuardScientistCombo && ((player.TeamRole.Role == RoleType.FACILITY_GUARD && buddy.TeamRole.Role == RoleType.SCIENTIST) || (player.TeamRole.Role == RoleType.SCIENTIST && buddy.TeamRole.Role == RoleType.FACILITY_GUARD)))
)
Expand All @@ -46,24 +49,25 @@ public void OnRoundStart(RoundStartEvent ev)
if (buddyPlugin.forceExactRole)
{
buddy.ChangeRole(player.TeamRole.Role);
players = ev.Server.GetPlayers();
doneIDs.Add(buddy.UserId);
doneIDs.Add(player.UserId);
continue;
}
//if they are an scp, we need to remove another scp first
if (player.TeamRole.Team == TeamType.SCP)
{
//loop through every scp and swap the buddy with one of them
Boolean setRole = false;
for (int y = 0; y < players.Count; y++)
foreach (Player player1 in ev.Server.GetPlayers())
{
Player player1 = players[y];
//check if the player is an scp
if (player1.UserId != player.UserId && player1.UserId != buddy.UserId && !buddyPlugin.buddies.ContainsKey(player1.UserId) && player1.TeamRole.Team == TeamType.SCP)
{
//set the buddy to that player's role and set the player to classd
buddy.ChangeRole(player1.TeamRole.Role);
player1.ChangeRole(RoleType.CLASSD);
players = ev.Server.GetPlayers();
doneIDs.Add(buddy.UserId);
doneIDs.Add(player.UserId);
setRole = true;
break;
}
Expand All @@ -73,13 +77,15 @@ public void OnRoundStart(RoundStartEvent ev)
List<RoleType> roles = new List<RoleType>(tmpArr);
roles.Remove(player.TeamRole.Role);
buddy.ChangeRole(roles[rnd.Next(roles.Count)]);
players = ev.Server.GetPlayers();
doneIDs.Add(buddy.UserId);
doneIDs.Add(player.UserId);
}
continue;
}
//if they are not an scp, we can just set them to the same role as their buddy
buddy.ChangeRole(player.TeamRole.Role);
players = ev.Server.GetPlayers();
doneIDs.Add(buddy.UserId);
doneIDs.Add(player.UserId);
}
}
catch (ArgumentException e)
Expand Down

0 comments on commit a854582

Please sign in to comment.