Skip to content

Commit

Permalink
relase
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxWorn3365 committed Jul 13, 2024
1 parent 8659b37 commit cb8320e
Show file tree
Hide file tree
Showing 12 changed files with 413 additions and 70 deletions.
18 changes: 13 additions & 5 deletions UncomplicatedCustomTeams/API/Features/SummonedCustomRole.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Exiled.API.Features;
using System.Collections.Generic;
using System.Linq;
using Exiled.API.Extensions;
using Exiled.API.Features;
using PlayerRoles;
using UncomplicatedCustomRoles.Extensions;
using UncomplicatedCustomTeams.Utilities;
using UnityEngine.Rendering;
using UnityEngine;

namespace UncomplicatedCustomTeams.API.Features
{
Expand Down Expand Up @@ -40,9 +40,17 @@ public void Destroy()
}

#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!
public void AddRole()
public void AddRole(RoleTypeId proposed)
{
LogManager.Debug($"Changing role to player {Player.Nickname} ({Player.Id}) to {CustomRole.Name} ({CustomRole.Id}) from team {Team.Team.Name}");

Player.Role.Set(CustomRole.Role, Exiled.API.Enums.SpawnReason.Respawn, RoleSpawnFlags.None);

if (Team.Team.SpawnPosition == Vector3.zero || Team.Team.SpawnPosition == Vector3.one)
Player.Position = proposed.GetRandomSpawnLocation().Position;
else
Player.Position = Team.Team.SpawnPosition;

Player.SetCustomRoleAttributes(CustomRole);
IsRoleSet = true;
}
Expand Down
44 changes: 42 additions & 2 deletions UncomplicatedCustomTeams/API/Features/SummonedTeam.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Exiled.API.Features;
using PlayerRoles;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;

namespace UncomplicatedCustomTeams.API.Features
{
Expand Down Expand Up @@ -30,6 +30,32 @@ public SummonedTeam(Team team)
List.Add(this);
}

public void SpawnAll()
{
foreach (SummonedCustomRole Role in Players)
{
if (Role.Player.IsAlive)
{
Players.Remove(Role);
continue;
}

RoleTypeId SpawnType = RoleTypeId.ChaosConscript;

if (Team.SpawnWave is Respawning.SpawnableTeamType.NineTailedFox)
SpawnType = RoleTypeId.NtfPrivate;

Role.AddRole(SpawnType);
}
}

public void CheckPlayers()
{
foreach (SummonedCustomRole Role in Players)
if (Role.Player.IsAlive)
Players.Remove(Role);
}

public void Destroy()
{
foreach (SummonedCustomRole role in Players) { role.Destroy(); }
Expand All @@ -56,6 +82,20 @@ public static SummonedTeam Summon(Team team, IEnumerable<Player> players)
return SummonedTeam;
}

public void RefreshPlayers(IEnumerable<Player> players)
{
foreach (Player Player in players)
{
foreach (CustomRole Role in Team.Roles)
{
if (SummonedPlayersCount(Role) < Role.MaxPlayers)
{
Players.Add(new(this, Player, Role));
break;
}
}
}
}

public int SummonedPlayersCount(CustomRole role)
{
Expand All @@ -72,7 +112,7 @@ public bool SummonedPlayersTryGet(Player player, out SummonedCustomRole role)
return role != null;
}

public void TrySpawnPlayer(Player player) => SummonedPlayersGet(player)?.AddRole();
public void TrySpawnPlayer(Player player, RoleTypeId role) => SummonedPlayersGet(player)?.AddRole(role);

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

Expand Down
36 changes: 31 additions & 5 deletions UncomplicatedCustomTeams/API/Features/Team.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Exiled.API.Extensions;
using Exiled.API.Features;
using Respawning;
using System;
using Respawning;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using UncomplicatedCustomTeams.Utilities;
using UnityEngine;

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

/// <summary>
/// Register a new custom <see cref="Team"/>
/// </summary>
/// <param name="team"></param>
public static void Register(Team team) => List.Add(team);

/// <summary>
/// Unregister a custom <see cref="Team"/>
/// </summary>
/// <param name="team"></param>
public static void Unregister(Team team) => List.Remove(team);

/// <summary>
/// The Id of the custom <see cref="Team"/>
/// </summary>
Expand Down Expand Up @@ -43,6 +53,22 @@ public class Team
/// </summary>
public SpawnableTeamType SpawnWave { get; set; } = SpawnableTeamType.NineTailedFox;

/// <summary>
/// The SpawnPosition of the wave.<br></br>
/// If Vector3.zero or Vector3.one then it will be retrived from the RoleTypeId
/// </summary>
public Vector3 SpawnPosition { get; set; } = Vector3.zero;

/// <summary>
/// The cassie message that will be sent to every player
/// </summary>
public string CassieMessage { get; set; } = "team arrived";

/// <summary>
/// The translation of the cassie message
/// </summary>
public string CassieTranslation { get; set; } = "Team arrived!";

/// <summary>
/// The list of every role that will be a part of this wave
/// </summary>
Expand Down Expand Up @@ -71,7 +97,7 @@ public static Team EvaluateSpawn(SpawnableTeamType wave)

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!");

int Chance = new Random().Next(0, 99);
int Chance = new System.Random().Next(0, 99);
if (Teams.Count > Chance)
return Teams[Chance];

Expand Down
69 changes: 69 additions & 0 deletions UncomplicatedCustomTeams/Commands/CommandParent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using CommandSystem;
using System;
using System.Collections.Generic;
using System.Linq;
using UncomplicatedCustomRoles.Commands;
using UncomplicatedCustomTeams.Interfaces;
using Exiled.API.Extensions;
using Exiled.Permissions.Extensions;

namespace UncomplicatedCustomTeams.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
internal class CommandParent : ParentCommand
{
public CommandParent() => LoadGeneratedCommands();

public override string Command { get; } = "uct";

public override string[] Aliases { get; } = new string[] { };

public override string Description { get; } = "Manage the UCT features";

public override void LoadGeneratedCommands()
{
RegisteredCommands.Add(new Spawn());
RegisteredCommands.Add(new Owner());
}

public List<IUCTCommand> RegisteredCommands { get; } = new();

protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (arguments.Count() == 0)
{
// Help page
response = $"\n>> UncomplicatedCustomTeams v{Plugin.Instance.Version} <<\nby FoxWorn3365\n\nAvailable commands:";

foreach (IUCTCommand Command in RegisteredCommands)
{
response += $"\n- uct {Command.Name} -> {Command.Description}";
}

return true;
}
else
{
// Arguments compactor:
List<string> Arguments = new();
foreach (string Argument in arguments.Where(arg => arg != arguments.At(0)))
{
Arguments.Add(Argument);
}

IUCTCommand Command = RegisteredCommands.Where(command => command.Name == arguments.At(0)).FirstOrDefault();

if (Command is not null && sender.CheckPermission(Command.RequiredPermission))
{
// Let's call the command
return Command.Executor(Arguments, sender, out response);
}
else
{
response = "Command not found";
return false;
}
}
}
}
}
47 changes: 47 additions & 0 deletions UncomplicatedCustomTeams/Commands/ForceNextWave.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using CommandSystem;
using Exiled.API.Features;
using System.Collections.Generic;
using System.Linq;
using UncomplicatedCustomTeams.API.Features;
using UncomplicatedCustomTeams.API.Storage;

namespace UncomplicatedCustomTeams.Commands
{
internal class ForceNextWave
{
public string Name { get; } = "force_next_wave";

public string Description { get; } = "Force the next wave to be a custom Team";

public string RequiredPermission { get; } = "uct.force_next_wave";

public bool Executor(List<string> arguments, ICommandSender _, out string response)
{
if (arguments.Count != 1)
{
response = "Usage: uct force_next_wave <TeamId>";
return false;
}

Team Team = Team.List.Where(team => team.Id == uint.Parse(arguments[0])).FirstOrDefault();

if (Team is null)
{
response = $"Team {uint.Parse(arguments[0])} is not registered!";
return false;
}
else
{
Bucket.SpawnBucket = new();
foreach (Player Player in Player.List.Where(p => !p.IsAlive && p.Role.Type is PlayerRoles.RoleTypeId.Spectator && !p.IsOverwatchEnabled))
Bucket.SpawnBucket.Add(Player.Id);

Plugin.NextTeam = SummonedTeam.Summon(Team, Player.List.Where(p => !p.IsAlive && p.Role.Type is PlayerRoles.RoleTypeId.Spectator && !p.IsOverwatchEnabled));

response = $"Successfully forced the team {Team.Name} to be the next respawn wave!";

return true;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
using CommandSystem;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net;
using UncomplicatedCustomTeams.Utilities;

namespace UncomplicatedCustomTeams.Commands
{
[CommandHandler(typeof(GameConsoleCommandHandler))]
internal class UCTLogShare : ParentCommand
{
public UCTLogShare() => LoadGeneratedCommands();

public override string Command { get; } = "uctlogs";

public override string[] Aliases { get; } = new string[] { };

public override string Description { get; } = "Share the UCT Debug logs with the developers";

public override void LoadGeneratedCommands() { }

protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (sender.LogName is not "SERVER CONSOLE")
{
response = "Sorry but this command is reserved to the game console!";
return false;
}

long Start = DateTimeOffset.Now.ToUnixTimeMilliseconds();

HttpStatusCode Response = LogManager.SendReport(out HttpContent Content);
Dictionary<string, string> Data = JsonConvert.DeserializeObject<Dictionary<string, string>>(Plugin.HttpManager.RetriveString(Content));

if (Response is HttpStatusCode.OK && Data.ContainsKey("id"))
{
response = $"Successfully shared the UCT logs with the developers!\nSend this Id to the developers: {Data["id"]}\n\nTook {DateTimeOffset.Now.ToUnixTimeMilliseconds() - Start}ms";
}
else
{
response = $"Failed to share the UCT logs with the developers: Server says: {Response}";
}


return true;
}
}
}
using CommandSystem;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net;
using UncomplicatedCustomTeams.Utilities;

namespace UncomplicatedCustomTeams.Commands
{
[CommandHandler(typeof(GameConsoleCommandHandler))]
internal class LogShare : ParentCommand
{
public LogShare() => LoadGeneratedCommands();

public override string Command { get; } = "uctlogs";

public override string[] Aliases { get; } = new string[] { };

public override string Description { get; } = "Share the UCT Debug logs with the developers";

public override void LoadGeneratedCommands() { }

protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (sender.LogName is not "SERVER CONSOLE")
{
response = "Sorry but this command is reserved to the game console!";
return false;
}

long Start = DateTimeOffset.Now.ToUnixTimeMilliseconds();

HttpStatusCode Response = LogManager.SendReport(out HttpContent Content);
Dictionary<string, string> Data = JsonConvert.DeserializeObject<Dictionary<string, string>>(Plugin.HttpManager.RetriveString(Content));

if (Response is HttpStatusCode.OK && Data.ContainsKey("id"))
{
response = $"Successfully shared the UCT logs with the developers!\nSend this Id to the developers: {Data["id"]}\n\nTook {DateTimeOffset.Now.ToUnixTimeMilliseconds() - Start}ms";
}
else
{
response = $"Failed to share the UCT logs with the developers: Server says: {Response}";
}


return true;
}
}
}
Loading

0 comments on commit cb8320e

Please sign in to comment.