Skip to content

Commit cb8320e

Browse files
committed
relase
1 parent 8659b37 commit cb8320e

12 files changed

Lines changed: 413 additions & 70 deletions

File tree

UncomplicatedCustomTeams/API/Features/SummonedCustomRole.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using Exiled.API.Features;
2-
using System.Collections.Generic;
3-
using System.Linq;
1+
using Exiled.API.Extensions;
2+
using Exiled.API.Features;
3+
using PlayerRoles;
44
using UncomplicatedCustomRoles.Extensions;
55
using UncomplicatedCustomTeams.Utilities;
6-
using UnityEngine.Rendering;
6+
using UnityEngine;
77

88
namespace UncomplicatedCustomTeams.API.Features
99
{
@@ -40,9 +40,17 @@ public void Destroy()
4040
}
4141

4242
#pragma warning disable CS0618 // A class member was marked with the Obsolete attribute -> the [Obsolete()] attribute is only there to avoid users to use this in a wrong way!
43-
public void AddRole()
43+
public void AddRole(RoleTypeId proposed)
4444
{
4545
LogManager.Debug($"Changing role to player {Player.Nickname} ({Player.Id}) to {CustomRole.Name} ({CustomRole.Id}) from team {Team.Team.Name}");
46+
47+
Player.Role.Set(CustomRole.Role, Exiled.API.Enums.SpawnReason.Respawn, RoleSpawnFlags.None);
48+
49+
if (Team.Team.SpawnPosition == Vector3.zero || Team.Team.SpawnPosition == Vector3.one)
50+
Player.Position = proposed.GetRandomSpawnLocation().Position;
51+
else
52+
Player.Position = Team.Team.SpawnPosition;
53+
4654
Player.SetCustomRoleAttributes(CustomRole);
4755
IsRoleSet = true;
4856
}

UncomplicatedCustomTeams/API/Features/SummonedTeam.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using Exiled.API.Features;
2+
using PlayerRoles;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
5-
using System.Runtime.Remoting.Messaging;
66

77
namespace UncomplicatedCustomTeams.API.Features
88
{
@@ -30,6 +30,32 @@ public SummonedTeam(Team team)
3030
List.Add(this);
3131
}
3232

33+
public void SpawnAll()
34+
{
35+
foreach (SummonedCustomRole Role in Players)
36+
{
37+
if (Role.Player.IsAlive)
38+
{
39+
Players.Remove(Role);
40+
continue;
41+
}
42+
43+
RoleTypeId SpawnType = RoleTypeId.ChaosConscript;
44+
45+
if (Team.SpawnWave is Respawning.SpawnableTeamType.NineTailedFox)
46+
SpawnType = RoleTypeId.NtfPrivate;
47+
48+
Role.AddRole(SpawnType);
49+
}
50+
}
51+
52+
public void CheckPlayers()
53+
{
54+
foreach (SummonedCustomRole Role in Players)
55+
if (Role.Player.IsAlive)
56+
Players.Remove(Role);
57+
}
58+
3359
public void Destroy()
3460
{
3561
foreach (SummonedCustomRole role in Players) { role.Destroy(); }
@@ -56,6 +82,20 @@ public static SummonedTeam Summon(Team team, IEnumerable<Player> players)
5682
return SummonedTeam;
5783
}
5884

85+
public void RefreshPlayers(IEnumerable<Player> players)
86+
{
87+
foreach (Player Player in players)
88+
{
89+
foreach (CustomRole Role in Team.Roles)
90+
{
91+
if (SummonedPlayersCount(Role) < Role.MaxPlayers)
92+
{
93+
Players.Add(new(this, Player, Role));
94+
break;
95+
}
96+
}
97+
}
98+
}
5999

60100
public int SummonedPlayersCount(CustomRole role)
61101
{
@@ -72,7 +112,7 @@ public bool SummonedPlayersTryGet(Player player, out SummonedCustomRole role)
72112
return role != null;
73113
}
74114

75-
public void TrySpawnPlayer(Player player) => SummonedPlayersGet(player)?.AddRole();
115+
public void TrySpawnPlayer(Player player, RoleTypeId role) => SummonedPlayersGet(player)?.AddRole(role);
76116

77117
public static SummonedTeam Get(string Id) => List.Where(st => st.Id == Id).FirstOrDefault();
78118

UncomplicatedCustomTeams/API/Features/Team.cs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
using Exiled.API.Extensions;
2-
using Exiled.API.Features;
3-
using Respawning;
4-
using System;
1+
using Respawning;
52
using System.Collections.Generic;
63
using System.ComponentModel;
74
using System.Linq;
85
using UncomplicatedCustomTeams.Utilities;
6+
using UnityEngine;
97

108
namespace UncomplicatedCustomTeams.API.Features
119
{
@@ -16,6 +14,18 @@ public class Team
1614
/// </summary>
1715
public static List<Team> List { get; } = new();
1816

17+
/// <summary>
18+
/// Register a new custom <see cref="Team"/>
19+
/// </summary>
20+
/// <param name="team"></param>
21+
public static void Register(Team team) => List.Add(team);
22+
23+
/// <summary>
24+
/// Unregister a custom <see cref="Team"/>
25+
/// </summary>
26+
/// <param name="team"></param>
27+
public static void Unregister(Team team) => List.Remove(team);
28+
1929
/// <summary>
2030
/// The Id of the custom <see cref="Team"/>
2131
/// </summary>
@@ -43,6 +53,22 @@ public class Team
4353
/// </summary>
4454
public SpawnableTeamType SpawnWave { get; set; } = SpawnableTeamType.NineTailedFox;
4555

56+
/// <summary>
57+
/// The SpawnPosition of the wave.<br></br>
58+
/// If Vector3.zero or Vector3.one then it will be retrived from the RoleTypeId
59+
/// </summary>
60+
public Vector3 SpawnPosition { get; set; } = Vector3.zero;
61+
62+
/// <summary>
63+
/// The cassie message that will be sent to every player
64+
/// </summary>
65+
public string CassieMessage { get; set; } = "team arrived";
66+
67+
/// <summary>
68+
/// The translation of the cassie message
69+
/// </summary>
70+
public string CassieTranslation { get; set; } = "Team arrived!";
71+
4672
/// <summary>
4773
/// The list of every role that will be a part of this wave
4874
/// </summary>
@@ -71,7 +97,7 @@ public static Team EvaluateSpawn(SpawnableTeamType wave)
7197

7298
LogManager.Debug($"Evaluated team count, found {Teams.Count}/100 elements [{List.Where(t => t.SpawnWave == wave).Count()}]!\nIf the number is less than 100 THERE's A PROBLEM!");
7399

74-
int Chance = new Random().Next(0, 99);
100+
int Chance = new System.Random().Next(0, 99);
75101
if (Teams.Count > Chance)
76102
return Teams[Chance];
77103

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using CommandSystem;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using UncomplicatedCustomRoles.Commands;
6+
using UncomplicatedCustomTeams.Interfaces;
7+
using Exiled.API.Extensions;
8+
using Exiled.Permissions.Extensions;
9+
10+
namespace UncomplicatedCustomTeams.Commands
11+
{
12+
[CommandHandler(typeof(RemoteAdminCommandHandler))]
13+
internal class CommandParent : ParentCommand
14+
{
15+
public CommandParent() => LoadGeneratedCommands();
16+
17+
public override string Command { get; } = "uct";
18+
19+
public override string[] Aliases { get; } = new string[] { };
20+
21+
public override string Description { get; } = "Manage the UCT features";
22+
23+
public override void LoadGeneratedCommands()
24+
{
25+
RegisteredCommands.Add(new Spawn());
26+
RegisteredCommands.Add(new Owner());
27+
}
28+
29+
public List<IUCTCommand> RegisteredCommands { get; } = new();
30+
31+
protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSender sender, out string response)
32+
{
33+
if (arguments.Count() == 0)
34+
{
35+
// Help page
36+
response = $"\n>> UncomplicatedCustomTeams v{Plugin.Instance.Version} <<\nby FoxWorn3365\n\nAvailable commands:";
37+
38+
foreach (IUCTCommand Command in RegisteredCommands)
39+
{
40+
response += $"\n- uct {Command.Name} -> {Command.Description}";
41+
}
42+
43+
return true;
44+
}
45+
else
46+
{
47+
// Arguments compactor:
48+
List<string> Arguments = new();
49+
foreach (string Argument in arguments.Where(arg => arg != arguments.At(0)))
50+
{
51+
Arguments.Add(Argument);
52+
}
53+
54+
IUCTCommand Command = RegisteredCommands.Where(command => command.Name == arguments.At(0)).FirstOrDefault();
55+
56+
if (Command is not null && sender.CheckPermission(Command.RequiredPermission))
57+
{
58+
// Let's call the command
59+
return Command.Executor(Arguments, sender, out response);
60+
}
61+
else
62+
{
63+
response = "Command not found";
64+
return false;
65+
}
66+
}
67+
}
68+
}
69+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using CommandSystem;
2+
using Exiled.API.Features;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using UncomplicatedCustomTeams.API.Features;
6+
using UncomplicatedCustomTeams.API.Storage;
7+
8+
namespace UncomplicatedCustomTeams.Commands
9+
{
10+
internal class ForceNextWave
11+
{
12+
public string Name { get; } = "force_next_wave";
13+
14+
public string Description { get; } = "Force the next wave to be a custom Team";
15+
16+
public string RequiredPermission { get; } = "uct.force_next_wave";
17+
18+
public bool Executor(List<string> arguments, ICommandSender _, out string response)
19+
{
20+
if (arguments.Count != 1)
21+
{
22+
response = "Usage: uct force_next_wave <TeamId>";
23+
return false;
24+
}
25+
26+
Team Team = Team.List.Where(team => team.Id == uint.Parse(arguments[0])).FirstOrDefault();
27+
28+
if (Team is null)
29+
{
30+
response = $"Team {uint.Parse(arguments[0])} is not registered!";
31+
return false;
32+
}
33+
else
34+
{
35+
Bucket.SpawnBucket = new();
36+
foreach (Player Player in Player.List.Where(p => !p.IsAlive && p.Role.Type is PlayerRoles.RoleTypeId.Spectator && !p.IsOverwatchEnabled))
37+
Bucket.SpawnBucket.Add(Player.Id);
38+
39+
Plugin.NextTeam = SummonedTeam.Summon(Team, Player.List.Where(p => !p.IsAlive && p.Role.Type is PlayerRoles.RoleTypeId.Spectator && !p.IsOverwatchEnabled));
40+
41+
response = $"Successfully forced the team {Team.Name} to be the next respawn wave!";
42+
43+
return true;
44+
}
45+
}
46+
}
47+
}
Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
using CommandSystem;
2-
using Newtonsoft.Json;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Net.Http;
6-
using System.Net;
7-
using UncomplicatedCustomTeams.Utilities;
8-
9-
namespace UncomplicatedCustomTeams.Commands
10-
{
11-
[CommandHandler(typeof(GameConsoleCommandHandler))]
12-
internal class UCTLogShare : ParentCommand
13-
{
14-
public UCTLogShare() => LoadGeneratedCommands();
15-
16-
public override string Command { get; } = "uctlogs";
17-
18-
public override string[] Aliases { get; } = new string[] { };
19-
20-
public override string Description { get; } = "Share the UCT Debug logs with the developers";
21-
22-
public override void LoadGeneratedCommands() { }
23-
24-
protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSender sender, out string response)
25-
{
26-
if (sender.LogName is not "SERVER CONSOLE")
27-
{
28-
response = "Sorry but this command is reserved to the game console!";
29-
return false;
30-
}
31-
32-
long Start = DateTimeOffset.Now.ToUnixTimeMilliseconds();
33-
34-
HttpStatusCode Response = LogManager.SendReport(out HttpContent Content);
35-
Dictionary<string, string> Data = JsonConvert.DeserializeObject<Dictionary<string, string>>(Plugin.HttpManager.RetriveString(Content));
36-
37-
if (Response is HttpStatusCode.OK && Data.ContainsKey("id"))
38-
{
39-
response = $"Successfully shared the UCT logs with the developers!\nSend this Id to the developers: {Data["id"]}\n\nTook {DateTimeOffset.Now.ToUnixTimeMilliseconds() - Start}ms";
40-
}
41-
else
42-
{
43-
response = $"Failed to share the UCT logs with the developers: Server says: {Response}";
44-
}
45-
46-
47-
return true;
48-
}
49-
}
50-
}
1+
using CommandSystem;
2+
using Newtonsoft.Json;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Net.Http;
6+
using System.Net;
7+
using UncomplicatedCustomTeams.Utilities;
8+
9+
namespace UncomplicatedCustomTeams.Commands
10+
{
11+
[CommandHandler(typeof(GameConsoleCommandHandler))]
12+
internal class LogShare : ParentCommand
13+
{
14+
public LogShare() => LoadGeneratedCommands();
15+
16+
public override string Command { get; } = "uctlogs";
17+
18+
public override string[] Aliases { get; } = new string[] { };
19+
20+
public override string Description { get; } = "Share the UCT Debug logs with the developers";
21+
22+
public override void LoadGeneratedCommands() { }
23+
24+
protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSender sender, out string response)
25+
{
26+
if (sender.LogName is not "SERVER CONSOLE")
27+
{
28+
response = "Sorry but this command is reserved to the game console!";
29+
return false;
30+
}
31+
32+
long Start = DateTimeOffset.Now.ToUnixTimeMilliseconds();
33+
34+
HttpStatusCode Response = LogManager.SendReport(out HttpContent Content);
35+
Dictionary<string, string> Data = JsonConvert.DeserializeObject<Dictionary<string, string>>(Plugin.HttpManager.RetriveString(Content));
36+
37+
if (Response is HttpStatusCode.OK && Data.ContainsKey("id"))
38+
{
39+
response = $"Successfully shared the UCT logs with the developers!\nSend this Id to the developers: {Data["id"]}\n\nTook {DateTimeOffset.Now.ToUnixTimeMilliseconds() - Start}ms";
40+
}
41+
else
42+
{
43+
response = $"Failed to share the UCT logs with the developers: Server says: {Response}";
44+
}
45+
46+
47+
return true;
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)