Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

Commit

Permalink
Exiled 9.0.0-beta.2 (#2773)
Browse files Browse the repository at this point in the history
* * Added name support for give command (customroles and customitem).
* Fixed spawn probability for customroles.
* Fixed RoleAssigner not being initialized and spawning problems

* bump version
  • Loading branch information
Monaldcry7788 authored Aug 17, 2024
1 parent 4bd815d commit 5498b5d
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 217 deletions.
2 changes: 1 addition & 1 deletion EXILED.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<PropertyGroup>
<!-- This is the global version and is used for all projects that don't have a version -->
<Version Condition="$(Version) == ''">9.0.0-beta.1</Version>
<Version Condition="$(Version) == ''">9.0.0-beta.2</Version>
<!-- Enables public beta warning via the PUBLIC_BETA constant -->
<PublicBeta>false</PublicBeta>

Expand Down
2 changes: 1 addition & 1 deletion Exiled.API/Extensions/MathExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static class MathExtensions
/// <param name="minInclusive">The minimum value to include in the range.</param>
/// <param name="maxInclusive">The maximum value to include in the range.</param>
/// <returns><see langword="true"/> if the probability occurred, otherwise <see langword="false"/>.</returns>
public static bool EvaluateProbability(this int probability, int minInclusive = 0, int maxInclusive = 100) => Random.Range(minInclusive, ++maxInclusive) <= probability;
public static bool EvaluateProbability(this int probability, int minInclusive = 0, int maxInclusive = 101) => probability == 100 || Random.Range(minInclusive, maxInclusive) <= probability;

/// <summary>
/// Evaluates a probability.
Expand Down
4 changes: 3 additions & 1 deletion Exiled.API/Features/Core/StaticActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ public static StaticActor CreateNewInstance<T>()
/// <returns>The created or already existing <see cref="StaticActor"/> instance.</returns>
public static StaticActor CreateNewInstance(Type type)
{
EObject @object = CreateDefaultSubobject<StaticActor>(type);
EActor @object = CreateDefaultSubobject<StaticActor>(type);
@object.Name = "__" + type.Name + " (StaticActor)";
@object.SearchForHostObjectIfNull = true;
@object.ComponentInitialize();
return @object.Cast<StaticActor>();
}

Expand Down Expand Up @@ -181,6 +182,7 @@ protected virtual void PostInitialize_Static()
/// </remarks>
protected virtual void BeginPlay_Static()
{
SubscribeEvents();
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Exiled.CustomModules/API/Commands/CustomItem/Give.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

if (arguments.Count == 0)
{
response = "give <Custom item name/Custom item ID> [Nickname/PlayerID/UserID/all/*]";
response = "give <Custom item ID> [Nickname/PlayerID/UserID/all/*]";
return false;
}

if (!CustomItem.TryGet(arguments.At(0), out CustomItem item))
if (!CustomItem.TryGet(arguments.At(0), out CustomItem item) && (!uint.TryParse(arguments.At(0), out uint id) || !CustomItem.TryGet(id, out item)) && item is null)
{
response = $"Custom item {arguments.At(0)} not found!";
return false;
Expand Down
12 changes: 6 additions & 6 deletions Exiled.CustomModules/API/Commands/CustomRoles/Give.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private Give()
public string[] Aliases { get; } = { "g" };

/// <inheritdoc/>
public string Description { get; } = "Gives the specified custom role to the indicated player(s).";
public string Description { get; } = "Gives the specified custom role (using ID) to the indicated player(s).";

/// <inheritdoc/>
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
Expand All @@ -52,13 +52,13 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
return false;
}

if (arguments.Count == 0)
if (arguments.Count < 2)
{
response = "give <Custom role name/Custom role ID> [Nickname/PlayerID/UserID/all/*]";
response = "give Custom role ID> [Nickname/PlayerID/UserID/all/*]";
return false;
}

if (!CustomRole.TryGet(uint.Parse(arguments.At(0)), out CustomRole role) || role is null)
if (!CustomRole.TryGet(arguments.At(0), out CustomRole role) && (!uint.TryParse(arguments.At(0), out uint id) || !CustomRole.TryGet(id, out role)) && role is null)
{
response = $"Custom role {arguments.At(0)} not found!";
return false;
Expand All @@ -74,7 +74,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
return false;
}

role.Spawn(player);
role.Spawn(player, false, force: true);
response = $"{role.Name} given to {player.Nickname}.";
return true;
}
Expand All @@ -86,7 +86,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
case "*":
case "all":
List<Pawn> players = ListPool<Player>.Pool.Get(Player.List).Select(player => player.Cast<Pawn>()).ToList();
role.Spawn(players);
role.Spawn(players, true);

response = $"Custom role {role.Name} given to all players.";
ListPool<Pawn>.Pool.Return(players);
Expand Down
7 changes: 6 additions & 1 deletion Exiled.CustomModules/API/Commands/CustomRoles/Info.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Exiled.CustomModules.API.Commands.CustomRoles
using Exiled.API.Features.Core.Generic.Pools;
using Exiled.CustomModules.API.Features.CustomRoles;
using Exiled.Permissions.Extensions;
using PlayerRoles;

/// <summary>
/// The command to view info about a specific role.
Expand Down Expand Up @@ -63,9 +64,13 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

builder.Append("<color=#E6AC00>-</color> <color=#00D639>").Append(role.Name)
.Append("</color> <color=#05C4E8>(").Append(role.Id).Append(")</color>")
.AppendLine("- Probability: ").Append(role.Probability)
.Append("- ").AppendLine(role.Description)
.AppendLine(role.Role.ToString())
.Append("- Health: ").AppendLine(role.Settings.MaxHealth.ToString()).AppendLine();
.Append("- Health: ").AppendLine(role.Settings.MaxHealth.ToString())
.AppendLine("- Team: ");
foreach (Team team in role.TeamsOwnership)
builder.AppendLine(team.ToString());

response = StringBuilderPool.Pool.ToStringReturn(builder);
return true;
Expand Down
21 changes: 12 additions & 9 deletions Exiled.CustomModules/API/Extensions/PlayerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,39 @@ public static class PlayerExtensions
/// <inheritdoc cref="CustomRole.Get(Pawn)"/>
public static CustomRole Get(this Player player) => CustomRole.Get(player.Cast<Pawn>());

/// <inheritdoc cref="CustomRole.Spawn(Pawn, CustomRole, bool, SpawnReason, RoleSpawnFlags)"/>
/// <inheritdoc cref="CustomRole.Spawn(Pawn, CustomRole, bool, SpawnReason, RoleSpawnFlags, bool)"/>
public static bool Spawn(
this Player player,
CustomRole customRole,
bool shouldKeepPosition = false,
SpawnReason spawnReason = null,
RoleSpawnFlags roleSpawnFlags = RoleSpawnFlags.All) =>
CustomRole.Spawn(player.Cast<Pawn>(), customRole, shouldKeepPosition, spawnReason, roleSpawnFlags);
RoleSpawnFlags roleSpawnFlags = RoleSpawnFlags.All,
bool force = false) =>
CustomRole.Spawn(player.Cast<Pawn>(), customRole, shouldKeepPosition, spawnReason, roleSpawnFlags, force);

/// <inheritdoc cref="CustomRole.Spawn{T}(Pawn)"/>
public static bool Spawn<T>(this Player player)
where T : CustomRole => CustomRole.Spawn<T>(player.Cast<Pawn>());

/// <inheritdoc cref="CustomRole.Spawn(Pawn, string, bool, SpawnReason, RoleSpawnFlags)"/>
/// <inheritdoc cref="CustomRole.Spawn(Pawn, string, bool, SpawnReason, RoleSpawnFlags, bool)"/>
public static bool Spawn(
this Player player,
string name,
bool shouldKeepPosition = false,
SpawnReason spawnReason = null,
RoleSpawnFlags roleSpawnFlags = RoleSpawnFlags.All) =>
CustomRole.Spawn(player.Cast<Pawn>(), name, shouldKeepPosition, spawnReason, roleSpawnFlags);
RoleSpawnFlags roleSpawnFlags = RoleSpawnFlags.All,
bool force = false) =>
CustomRole.Spawn(player.Cast<Pawn>(), name, shouldKeepPosition, spawnReason, roleSpawnFlags, force);

/// <inheritdoc cref="CustomRole.Spawn(Pawn, uint, bool, SpawnReason, RoleSpawnFlags)"/>
/// <inheritdoc cref="CustomRole.Spawn(Pawn, uint, bool, SpawnReason, RoleSpawnFlags, bool)"/>
public static bool Spawn(
this Player player,
uint id,
bool shouldKeepPosition = false,
SpawnReason spawnReason = null,
RoleSpawnFlags roleSpawnFlags = RoleSpawnFlags.All) =>
CustomRole.Spawn(player.Cast<Pawn>(), id, shouldKeepPosition, spawnReason, roleSpawnFlags);
RoleSpawnFlags roleSpawnFlags = RoleSpawnFlags.All,
bool force = false) =>
CustomRole.Spawn(player.Cast<Pawn>(), id, shouldKeepPosition, spawnReason, roleSpawnFlags, force);

/// <inheritdoc cref="CustomRole.TrySpawn(Pawn, CustomRole)"/>
public static bool TrySpawn(this Player player, CustomRole customRole) => CustomRole.TrySpawn(player.Cast<Pawn>(), customRole);
Expand Down
40 changes: 32 additions & 8 deletions Exiled.CustomModules/API/Features/CustomItems/CustomItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ public abstract class CustomItem : CustomModule, IAdditiveBehaviour
/// </summary>
/// <param name="id">The custom item id to retrieve.</param>
/// <returns>The retrieved <see cref="CustomItem"/> instance if found and enabled; otherwise, <see langword="null"/>.</returns>
public static CustomItem Get(uint id) => IdLookupTable[id];
public static CustomItem Get(uint id) => IdLookupTable.ContainsKey(id) ? IdLookupTable[id] : null;

/// <summary>
/// Retrieves a <see cref="CustomItem"/> instance based on the specified item name.
/// </summary>
/// <param name="name">The name of the custom item to retrieve.</param>
/// <returns>The retrieved <see cref="CustomItem"/> instance if found; otherwise, <see langword="null"/>.</returns>
public static CustomItem Get(string name) => NameLookupTable[name];
public static CustomItem Get(string name) => NameLookupTable.ContainsKey(name) ? NameLookupTable[name] : null;

/// <summary>
/// Retrieves a <see cref="CustomItem"/> instance based on the specified type.
Expand Down Expand Up @@ -216,47 +216,71 @@ public static CustomItem Get(Pickup item)
/// <param name="id">The id or <see cref="UUCustomItemType"/> of the custom item.</param>
/// <param name="customItem">When this method returns, contains the <see cref="CustomItem"/> associated with the specified id, if the id was found; otherwise, <see langword="null"/>.</param>
/// <returns><see langword="true"/> if a <see cref="CustomItem"/> was found; otherwise, <see langword="false"/>.</returns>
public static bool TryGet(object id, out CustomItem customItem) => customItem = Get(id);
public static bool TryGet(object id, out CustomItem customItem)
{
customItem = Get(id);
return customItem is not null;
}

/// <summary>
/// Tries to retrieve a <see cref="CustomItem"/> instance based on the specified custom item id.
/// </summary>
/// <param name="id">The custom item id to retrieve.</param>
/// <param name="customItem">The retrieved <see cref="CustomItem"/> instance, if successful; otherwise, <see langword="null"/>.</param>
/// <returns><see langword="true"/> if the retrieval is successful; otherwise, <see langword="false"/>.</returns>
public static bool TryGet(uint id, out CustomItem customItem) => customItem = Get(id);
public static bool TryGet(uint id, out CustomItem customItem)
{
customItem = Get(id);
return customItem is not null;
}

/// <summary>
/// Tries to retrieve a <see cref="CustomItem"/> instance based on the specified item name.
/// </summary>
/// <param name="name">The name of the custom item to retrieve.</param>
/// <param name="customItem">The retrieved <see cref="CustomItem"/> instance, if successful; otherwise, <see langword="null"/>.</param>
/// <returns><see langword="true"/> if the retrieval is successful; otherwise, <see langword="false"/>.</returns>
public static bool TryGet(string name, out CustomItem customItem) => customItem = Get(name);
public static bool TryGet(string name, out CustomItem customItem)
{
customItem = Get(name);
return customItem is not null;
}

/// <summary>
/// Tries to retrieve a <see cref="CustomItem"/> instance based on the specified <see cref="Item"/> instance.
/// </summary>
/// <param name="item">The <see cref="Item"/> instance to retrieve the custom item for.</param>
/// <param name="customItem">The retrieved <see cref="CustomItem"/> instance, if successful; otherwise, <see langword="null"/>.</param>
/// <returns><see langword="true"/> if the retrieval is successful; otherwise, <see langword="false"/>.</returns>
public static bool TryGet(Item item, out CustomItem customItem) => customItem = Get(item);
public static bool TryGet(Item item, out CustomItem customItem)
{
customItem = Get(item);
return customItem is not null;
}

/// <summary>
/// Tries to retrieve a <see cref="CustomItem"/> instance based on the specified <see cref="Pickup"/> instance.
/// </summary>
/// <param name="pickup">The <see cref="Pickup"/> instance to retrieve the custom item for.</param>
/// <param name="customItem">The retrieved <see cref="CustomItem"/> instance, if successful; otherwise, <see langword="null"/>.</param>
/// <returns><see langword="true"/> if the retrieval is successful; otherwise, <see langword="false"/>.</returns>
public static bool TryGet(Pickup pickup, out CustomItem customItem) => customItem = Get(pickup);
public static bool TryGet(Pickup pickup, out CustomItem customItem)
{
customItem = Get(pickup);
return customItem is not null;
}

/// <summary>
/// Tries to retrieve a <see cref="CustomItem"/> instance based on the specified type.
/// </summary>
/// <param name="type">The type to retrieve the custom item for.</param>
/// <param name="customItem">The retrieved <see cref="CustomItem"/> instance, if successful; otherwise, <see langword="null"/>.</param>
/// <returns><see langword="true"/> if the retrieval is successful; otherwise, <see langword="false"/>.</returns>
public static bool TryGet(Type type, out CustomItem customItem) => customItem = Get(type);
public static bool TryGet(Type type, out CustomItem customItem)
{
customItem = Get(type);
return customItem is not null;
}

/// <summary>
/// Tries to spawn a custom item at the specified position.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ protected override void PostInitialize()
AdjustAdditivePipe();
}

/// <inheritdoc />
protected override void OnBeginPlay()
{
base.OnBeginPlay();
this.SubscribeEvents();
}

/// <inheritdoc/>
protected override void SubscribeEvents()
{
Expand Down
1 change: 1 addition & 0 deletions Exiled.CustomModules/API/Features/CustomModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ UUModuleType FindClosestModuleType(Type t, IEnumerable<FieldInfo> source)
};

ModuleInfo.AllModules.Add(moduleInfo);
CustomModules.Instance.RegistrationHandler.OnModuleEnabled(moduleInfo);

if (!shouldBeEnabled)
continue;
Expand Down
Loading

0 comments on commit 5498b5d

Please # to comment.