Skip to content

Commit

Permalink
Merge branch 'dev' into Item-T-Get()-and-Pickup-T-Get()
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 authored Aug 6, 2024
2 parents 7d62ef0 + 1f2d209 commit 57038ef
Show file tree
Hide file tree
Showing 19 changed files with 301 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ Localization: # Add the 'Localization' label
- changed-files:
- any-glob-to-any-file: EXILED/Localization/** # Any modifications to Localization

GitHub_Actions: # Add the 'GitHub' label
GitHub: # Add the 'GitHub' label
- changed-files:
- any-glob-to-any-file: .github/** # Any modifications to github related files
35 changes: 35 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Description
**Describe the changes**


**What is the current behavior?** (You can also link to an open issue here)


**What is the new behavior?** (if this is a feature change)


**Does this PR introduce a breaking change?** (What changes might users need to make in their application due to this PR?)


**Other information**:

<br />

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Documentations
<br />

## Submission checklist
<!--- Put an `x` in all the boxes that apply: -->
- [ ] I have checked the project can be compiled
- [ ] I have tested my changes and it worked as expected

### Patches (if there are any changes related to Harmony patches)
- [ ] I have checked no IL patching errors in the console

### Other
- [ ] Still requires more testing
4 changes: 2 additions & 2 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ defaults:
working-directory: ./EXILED

env:
EXILED_REFERENCES_URL: https://Exiled-Official.github.io/SL-References/Dev.zip
EXILED_REFERENCES_URL: https://exmod-team.github.io/SL-References/Dev.zip
EXILED_REFERENCES_PATH: ${{ github.workspace }}/EXILED/References
EXILED_DLL_ARCHIVER_URL: https://github.com/Exiled-Official/EXILED-DLL-Archiver/releases/latest/download/EXILED-DLL-Archiver.exe
EXILED_DLL_ARCHIVER_URL: https://github.com/ExMod-Team/EXILED-DLL-Archiver/releases/latest/download/EXILED-DLL-Archiver.exe

jobs:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:
id-token: write

env:
EXILED_REFERENCES_URL: https://Exiled-Official.github.io/SL-References/Dev.zip
EXILED_REFERENCES_URL: https://exmod-team.github.io/SL-References/Master.zip
EXILED_REFERENCES_PATH: ${{ github.workspace }}/EXILED/References

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/labeler.yml
sync-labels: true
assign-author:
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
- uses: toshimaru/auto-author-assign@v2.1.1
13 changes: 13 additions & 0 deletions EXILED/Exiled.API/Extensions/MirrorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Exiled.API.Extensions
using PlayerRoles;
using PlayerRoles.FirstPersonControl;
using PlayerRoles.PlayableScps.Scp049.Zombies;
using PlayerRoles.Voice;
using RelativePositioning;

using Respawning;
Expand Down Expand Up @@ -181,6 +182,18 @@ public static void PlayGunSound(this Player player, Vector3 position, ItemType i
player.Connection.Send(message);
}

/// <summary>
/// Sets <see cref="Features.Intercom.DisplayText"/> that only the <paramref name="target"/> player can see.
/// </summary>
/// <param name="target">Only this player can see Display Text.</param>
/// <param name="text">Text displayed to the player.</param>
public static void SetIntercomDisplayTextForTargetOnly(this Player target, string text) => target.SendFakeSyncVar(IntercomDisplay._singleton.netIdentity, typeof(IntercomDisplay), nameof(IntercomDisplay.Network_overrideText), text);

/// <summary>
/// Resync <see cref="Features.Intercom.DisplayText"/>.
/// </summary>
public static void ResetIntercomDisplayText() => ResyncSyncVar(IntercomDisplay._singleton.netIdentity, typeof(IntercomDisplay), nameof(IntercomDisplay.Network_overrideText));

/// <summary>
/// Sets <see cref="Room.Color"/> of a <paramref name="room"/> that only the <paramref name="target"/> player can see.
/// </summary>
Expand Down
30 changes: 28 additions & 2 deletions EXILED/Exiled.API/Features/Items/Jailbird.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@

namespace Exiled.API.Features.Items
{
using System;

using Exiled.API.Features.Pickups;
using Exiled.API.Interfaces;
using InventorySystem.Items.Autosync;
using InventorySystem.Items.Jailbird;
using Mirror;
using UnityEngine;

using JailbirdPickup = Pickups.JailbirdPickup;

Expand Down Expand Up @@ -114,12 +117,35 @@ public JailbirdWearState WearState
get => Base._deterioration.WearState;
set
{
if (JailbirdDeteriorationTracker.ReceivedStates.ContainsKey(Serial))
JailbirdDeteriorationTracker.ReceivedStates[Serial] = value;
TotalDamageDealt = GetDamage(value);
TotalCharges = GetCharge(value);
Base._deterioration.RecheckUsage();
}
}

/// <summary>
/// Calculates the damage corresponding to a given <see cref="JailbirdWearState"/>.
/// </summary>
/// <param name="wearState">The wear state to calculate damage for.</param>
/// <returns>The amount of damage associated with the specified wear state.</returns>
public float GetDamage(JailbirdWearState wearState)
{
foreach (Keyframe keyframe in Base._deterioration._damageToWearState.keys)
{
if (Base._deterioration.FloatToState(keyframe.value) == wearState)
return keyframe.time;
}

throw new Exception("Wear state not found in damage to wear state mapping.");
}

/// <summary>
/// Gets the charge needed to reach a specific <see cref="JailbirdWearState"/>.
/// </summary>
/// <param name="wearState">The desired wear state to calculate the charge for.</param>
/// <returns>The charge value required to achieve the specified wear state.</returns>
public int GetCharge(JailbirdWearState wearState) => (int)wearState;

/// <summary>
/// Breaks the Jailbird.
/// </summary>
Expand Down
7 changes: 1 addition & 6 deletions EXILED/Exiled.API/Features/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ public static class Map
/// </summary>
internal static readonly List<PocketDimensionTeleport> TeleportsValue = new(8);

/// <summary>
/// A list of <see cref="AdminToy"/>s on the map.
/// </summary>
internal static readonly List<AdminToy> ToysValue = new();

private static TantrumEnvironmentalHazard tantrumPrefab;
private static Scp939AmnesticCloudInstance amnesticCloudPrefab;

Expand Down Expand Up @@ -130,7 +125,7 @@ DecontaminationController.Singleton.NetworkDecontaminationOverride is Decontamin
/// <summary>
/// Gets all <see cref="AdminToy"/> objects.
/// </summary>
public static ReadOnlyCollection<AdminToy> Toys { get; } = ToysValue.AsReadOnly();
public static ReadOnlyCollection<AdminToy> Toys => AdminToy.BaseToAdminToy.Values.ToList().AsReadOnly(); // TODO: Obsolete it and make people use AdminToy.List

/// <summary>
/// Gets or sets the current seed of the map.
Expand Down
31 changes: 28 additions & 3 deletions EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,13 @@ public static Player Get(GameObject gameObject)
if (Dictionary.TryGetValue(gameObject, out Player player))
return player;

UnverifiedPlayers.TryGetValue(gameObject, out player);
return player;
if (UnverifiedPlayers.TryGetValue(gameObject, out player))
return player;

if (ReferenceHub.TryGetHub(gameObject, out ReferenceHub hub))
return new(hub);

return null;
}

/// <summary>
Expand Down Expand Up @@ -2319,6 +2324,16 @@ public void Broadcast(ushort duration, string message, global::Broadcast.Broadca
public void AddAmmo(AmmoType ammoType, ushort amount) =>
Inventory.ServerAddAmmo(ammoType.GetItemType(), amount);

/// <summary>
/// Adds the amount of a specified <see cref="AmmoType">ammo type</see> to player's inventory.
/// </summary>
/// <param name="ammoBag">A dictionary of <see cref="AmmoType">ammo types</see> that will be added.</param>
public void AddAmmo(Dictionary<AmmoType, ushort> ammoBag)
{
foreach (KeyValuePair<AmmoType, ushort> kvp in ammoBag)
AddAmmo(kvp.Key, kvp.Value);
}

/// <summary>
/// Adds the amount of a weapon's <see cref="AmmoType">ammo type</see> to the player's inventory.
/// </summary>
Expand All @@ -2338,6 +2353,16 @@ public void SetAmmo(AmmoType ammoType, ushort amount)
Inventory.ServerSetAmmo(itemType, amount);
}

/// <summary>
/// Sets the amount of a specified <see cref="AmmoType">ammo type</see> to player's inventory.
/// </summary>
/// <param name="ammoBag">A dictionary of <see cref="AmmoType">ammo types</see> that will be added.</param>
public void SetAmmo(Dictionary<AmmoType, ushort> ammoBag)
{
foreach (KeyValuePair<AmmoType, ushort> kvp in ammoBag)
SetAmmo(kvp.Key, kvp.Value);
}

/// <summary>
/// Gets the ammo count of a specified <see cref="AmmoType">ammo type</see> in a player's inventory.
/// </summary>
Expand Down Expand Up @@ -2728,8 +2753,8 @@ public void ResetInventory(IEnumerable<Item> newItems)
/// <seealso cref="DropItems()"/>
public void ClearInventory(bool destroy = true)
{
ClearItems(destroy);
ClearAmmo();
ClearItems(destroy);
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions EXILED/Exiled.API/Features/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ public static bool IsWhitelisted
set => ServerConsole.WhiteListEnabled = value;
}

/// <summary>
/// Gets the list of user IDs of players currently whitelisted.
/// </summary>
public static HashSet<string> WhitelistedPlayers => WhiteList.Users;

/// <summary>
/// Gets a value indicating whether or not this server is verified.
/// </summary>
Expand Down
33 changes: 30 additions & 3 deletions EXILED/Exiled.API/Features/Toys/AdminToy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

namespace Exiled.API.Features.Toys
{
using System.Collections.Generic;
using System.Linq;

using AdminToys;

using Enums;
using Exiled.API.Interfaces;
using Footprinting;
using InventorySystem.Items;
using Mirror;

using UnityEngine;
Expand All @@ -23,6 +25,11 @@ namespace Exiled.API.Features.Toys
/// </summary>
public abstract class AdminToy : IWorldSpace
{
/// <summary>
/// A dictionary of all <see cref="AdminToys.AdminToyBase"/>'s that have been converted into <see cref="AdminToy"/>.
/// </summary>
internal static readonly Dictionary<AdminToyBase, AdminToy> BaseToAdminToy = new(new ComponentsEqualityComparer());

/// <summary>
/// Initializes a new instance of the <see cref="AdminToy"/> class.
/// </summary>
Expand All @@ -33,9 +40,14 @@ internal AdminToy(AdminToyBase toyAdminToyBase, AdminToyType type)
AdminToyBase = toyAdminToyBase;
ToyType = type;

Map.ToysValue.Add(this);
BaseToAdminToy.Add(toyAdminToyBase, this);
}

/// <summary>
/// Gets a list of all <see cref="AdminToy"/>'s on the server.
/// </summary>
public static IReadOnlyCollection<AdminToy> List => BaseToAdminToy.Values;

/// <summary>
/// Gets the original <see cref="AdminToys.AdminToyBase"/>.
/// </summary>
Expand Down Expand Up @@ -130,7 +142,22 @@ public bool IsStatic
/// </summary>
/// <param name="adminToyBase">The <see cref="AdminToys.AdminToyBase"/> instance.</param>
/// <returns>The corresponding <see cref="AdminToy"/> instance.</returns>
public static AdminToy Get(AdminToyBase adminToyBase) => Map.Toys.FirstOrDefault(x => x.AdminToyBase == adminToyBase);
public static AdminToy Get(AdminToyBase adminToyBase)
{
if (adminToyBase == null)
return null;

if (BaseToAdminToy.TryGetValue(adminToyBase, out AdminToy adminToy))
return adminToy;

return adminToyBase switch
{
LightSourceToy lightSourceToy => new Light(lightSourceToy),
PrimitiveObjectToy primitiveObjectToy => new Primitive(primitiveObjectToy),
ShootingTarget shootingTarget => new ShootingTargetToy(shootingTarget),
_ => throw new System.NotImplementedException()
};
}

/// <summary>
/// Gets the <see cref="AdminToy"/> by <see cref="AdminToys.AdminToyBase"/>.
Expand All @@ -156,7 +183,7 @@ public static T Get<T>(AdminToyBase adminToyBase)
/// </summary>
public void Destroy()
{
Map.ToysValue.Remove(this);
BaseToAdminToy.Remove(AdminToyBase);
NetworkServer.Destroy(AdminToyBase.gameObject);
}
}
Expand Down
22 changes: 18 additions & 4 deletions EXILED/Exiled.Events/EventArgs/Item/ChargingJailbirdEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Exiled.Events.EventArgs.Item
{
using System;

using Exiled.API.Features;
using Exiled.API.Features.Items;
using Exiled.Events.EventArgs.Interfaces;
Expand All @@ -25,8 +27,10 @@ public class ChargingJailbirdEventArgs : IPlayerEvent, IItemEvent, IDeniableEven
public ChargingJailbirdEventArgs(ReferenceHub player, InventorySystem.Items.ItemBase swingItem, bool isAllowed = true)
{
Player = Player.Get(player);
Item = Item.Get(swingItem);
Jailbird = (Jailbird)Item.Get(swingItem);
#pragma warning disable CS0618
IsAllowed = isAllowed;
#pragma warning restore CS0618
}

/// <summary>
Expand All @@ -35,13 +39,23 @@ public ChargingJailbirdEventArgs(ReferenceHub player, InventorySystem.Items.Item
public Player Player { get; }

/// <summary>
/// Gets the <see cref="API.Features.Items.Item"/> that is being charged. This will always be a <see cref="Jailbird"/>.
/// Gets the <see cref="API.Features.Items.Jailbird"/> that is being charged.
/// </summary>
public Jailbird Jailbird { get; }

/// <summary>
/// Gets the <see cref="API.Features.Items.Item"/> that is being charged.
/// </summary>
public Item Item { get; }
public Item Item => Jailbird;

/// <summary>
/// Gets or sets a value indicating whether or not the Jailbird can be charged.
/// </summary>
public bool IsAllowed { get; set; }
public bool IsAllowed
{
get;
[Obsolete("This event cannot be denied as it will cause desync.")]
set;
}
}
}
9 changes: 7 additions & 2 deletions EXILED/Exiled.Events/EventArgs/Item/SwingingEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SwingingEventArgs : IPlayerEvent, IItemEvent, IDeniableEvent
public SwingingEventArgs(ReferenceHub player, InventorySystem.Items.ItemBase swingItem, bool isAllowed = true)
{
Player = Player.Get(player);
Item = Item.Get(swingItem);
Jailbird = (Jailbird)Item.Get(swingItem);
IsAllowed = isAllowed;
}

Expand All @@ -34,10 +34,15 @@ public SwingingEventArgs(ReferenceHub player, InventorySystem.Items.ItemBase swi
/// </summary>
public Player Player { get; }

/// <summary>
/// Gets the <see cref="API.Features.Items.Jailbird"/> that is being swung.
/// </summary>
public Jailbird Jailbird { get; }

/// <summary>
/// Gets the <see cref="API.Features.Items.Item"/> that is being swung.
/// </summary>
public Item Item { get; }
public Item Item => Jailbird;

/// <summary>
/// Gets or sets a value indicating whether or not the item can be swung.
Expand Down
Loading

0 comments on commit 57038ef

Please sign in to comment.