Skip to content

Commit f40e371

Browse files
authored
Merge branch 'dev' into NWBugsFix
2 parents 618dfd9 + 4e50826 commit f40e371

File tree

13 files changed

+250
-25
lines changed

13 files changed

+250
-25
lines changed

EXILED/Exiled.API/Features/Items/Jailbird.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
namespace Exiled.API.Features.Items
99
{
10+
using System;
11+
1012
using Exiled.API.Features.Pickups;
1113
using Exiled.API.Interfaces;
1214
using InventorySystem.Items.Autosync;
1315
using InventorySystem.Items.Jailbird;
1416
using Mirror;
17+
using UnityEngine;
1518

1619
using JailbirdPickup = Pickups.JailbirdPickup;
1720

@@ -114,12 +117,35 @@ public JailbirdWearState WearState
114117
get => Base._deterioration.WearState;
115118
set
116119
{
117-
if (JailbirdDeteriorationTracker.ReceivedStates.ContainsKey(Serial))
118-
JailbirdDeteriorationTracker.ReceivedStates[Serial] = value;
120+
TotalDamageDealt = GetDamage(value);
121+
TotalCharges = GetCharge(value);
119122
Base._deterioration.RecheckUsage();
120123
}
121124
}
122125

126+
/// <summary>
127+
/// Calculates the damage corresponding to a given <see cref="JailbirdWearState"/>.
128+
/// </summary>
129+
/// <param name="wearState">The wear state to calculate damage for.</param>
130+
/// <returns>The amount of damage associated with the specified wear state.</returns>
131+
public float GetDamage(JailbirdWearState wearState)
132+
{
133+
foreach (Keyframe keyframe in Base._deterioration._damageToWearState.keys)
134+
{
135+
if (Base._deterioration.FloatToState(keyframe.value) == wearState)
136+
return keyframe.time;
137+
}
138+
139+
throw new Exception("Wear state not found in damage to wear state mapping.");
140+
}
141+
142+
/// <summary>
143+
/// Gets the charge needed to reach a specific <see cref="JailbirdWearState"/>.
144+
/// </summary>
145+
/// <param name="wearState">The desired wear state to calculate the charge for.</param>
146+
/// <returns>The charge value required to achieve the specified wear state.</returns>
147+
public int GetCharge(JailbirdWearState wearState) => (int)wearState;
148+
123149
/// <summary>
124150
/// Breaks the Jailbird.
125151
/// </summary>

EXILED/Exiled.API/Features/Map.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ public static class Map
5757
/// </summary>
5858
internal static readonly List<PocketDimensionTeleport> TeleportsValue = new(8);
5959

60-
/// <summary>
61-
/// A list of <see cref="AdminToy"/>s on the map.
62-
/// </summary>
63-
internal static readonly List<AdminToy> ToysValue = new();
64-
6560
private static TantrumEnvironmentalHazard tantrumPrefab;
6661
private static Scp939AmnesticCloudInstance amnesticCloudPrefab;
6762

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

135130
/// <summary>
136131
/// Gets or sets the current seed of the map.

EXILED/Exiled.API/Features/Player.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,8 +1266,13 @@ public static Player Get(GameObject gameObject)
12661266
if (Dictionary.TryGetValue(gameObject, out Player player))
12671267
return player;
12681268

1269-
UnverifiedPlayers.TryGetValue(gameObject, out player);
1270-
return player;
1269+
if (UnverifiedPlayers.TryGetValue(gameObject, out player))
1270+
return player;
1271+
1272+
if (ReferenceHub.TryGetHub(gameObject, out ReferenceHub hub))
1273+
return new(hub);
1274+
1275+
return null;
12711276
}
12721277

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

2327+
/// <summary>
2328+
/// Adds the amount of a specified <see cref="AmmoType">ammo type</see> to player's inventory.
2329+
/// </summary>
2330+
/// <param name="ammoBag">A dictionary of <see cref="AmmoType">ammo types</see> that will be added.</param>
2331+
public void AddAmmo(Dictionary<AmmoType, ushort> ammoBag)
2332+
{
2333+
foreach (KeyValuePair<AmmoType, ushort> kvp in ammoBag)
2334+
AddAmmo(kvp.Key, kvp.Value);
2335+
}
2336+
23222337
/// <summary>
23232338
/// Adds the amount of a weapon's <see cref="AmmoType">ammo type</see> to the player's inventory.
23242339
/// </summary>
@@ -2338,6 +2353,16 @@ public void SetAmmo(AmmoType ammoType, ushort amount)
23382353
Inventory.ServerSetAmmo(itemType, amount);
23392354
}
23402355

2356+
/// <summary>
2357+
/// Sets the amount of a specified <see cref="AmmoType">ammo type</see> to player's inventory.
2358+
/// </summary>
2359+
/// <param name="ammoBag">A dictionary of <see cref="AmmoType">ammo types</see> that will be added.</param>
2360+
public void SetAmmo(Dictionary<AmmoType, ushort> ammoBag)
2361+
{
2362+
foreach (KeyValuePair<AmmoType, ushort> kvp in ammoBag)
2363+
SetAmmo(kvp.Key, kvp.Value);
2364+
}
2365+
23412366
/// <summary>
23422367
/// Gets the ammo count of a specified <see cref="AmmoType">ammo type</see> in a player's inventory.
23432368
/// </summary>

EXILED/Exiled.API/Features/Toys/AdminToy.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88
namespace Exiled.API.Features.Toys
99
{
10+
using System.Collections.Generic;
1011
using System.Linq;
1112

1213
using AdminToys;
1314

1415
using Enums;
1516
using Exiled.API.Interfaces;
1617
using Footprinting;
18+
using InventorySystem.Items;
1719
using Mirror;
1820

1921
using UnityEngine;
@@ -23,6 +25,11 @@ namespace Exiled.API.Features.Toys
2325
/// </summary>
2426
public abstract class AdminToy : IWorldSpace
2527
{
28+
/// <summary>
29+
/// A dictionary of all <see cref="AdminToys.AdminToyBase"/>'s that have been converted into <see cref="AdminToy"/>.
30+
/// </summary>
31+
internal static readonly Dictionary<AdminToyBase, AdminToy> BaseToAdminToy = new(new ComponentsEqualityComparer());
32+
2633
/// <summary>
2734
/// Initializes a new instance of the <see cref="AdminToy"/> class.
2835
/// </summary>
@@ -33,9 +40,14 @@ internal AdminToy(AdminToyBase toyAdminToyBase, AdminToyType type)
3340
AdminToyBase = toyAdminToyBase;
3441
ToyType = type;
3542

36-
Map.ToysValue.Add(this);
43+
BaseToAdminToy.Add(toyAdminToyBase, this);
3744
}
3845

46+
/// <summary>
47+
/// Gets a list of all <see cref="AdminToy"/>'s on the server.
48+
/// </summary>
49+
public static IReadOnlyCollection<AdminToy> List => BaseToAdminToy.Values;
50+
3951
/// <summary>
4052
/// Gets the original <see cref="AdminToys.AdminToyBase"/>.
4153
/// </summary>
@@ -130,7 +142,22 @@ public bool IsStatic
130142
/// </summary>
131143
/// <param name="adminToyBase">The <see cref="AdminToys.AdminToyBase"/> instance.</param>
132144
/// <returns>The corresponding <see cref="AdminToy"/> instance.</returns>
133-
public static AdminToy Get(AdminToyBase adminToyBase) => Map.Toys.FirstOrDefault(x => x.AdminToyBase == adminToyBase);
145+
public static AdminToy Get(AdminToyBase adminToyBase)
146+
{
147+
if (adminToyBase == null)
148+
return null;
149+
150+
if (BaseToAdminToy.TryGetValue(adminToyBase, out AdminToy adminToy))
151+
return adminToy;
152+
153+
return adminToyBase switch
154+
{
155+
LightSourceToy lightSourceToy => new Light(lightSourceToy),
156+
PrimitiveObjectToy primitiveObjectToy => new Primitive(primitiveObjectToy),
157+
ShootingTarget shootingTarget => new ShootingTargetToy(shootingTarget),
158+
_ => throw new System.NotImplementedException()
159+
};
160+
}
134161

135162
/// <summary>
136163
/// Spawns the toy into the game. Use <see cref="UnSpawn"/> to remove it.
@@ -147,7 +174,7 @@ public bool IsStatic
147174
/// </summary>
148175
public void Destroy()
149176
{
150-
Map.ToysValue.Remove(this);
177+
BaseToAdminToy.Remove(AdminToyBase);
151178
NetworkServer.Destroy(AdminToyBase.gameObject);
152179
}
153180
}

EXILED/Exiled.Events/EventArgs/Item/ChargingJailbirdEventArgs.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ChargingJailbirdEventArgs : IPlayerEvent, IItemEvent, IDeniableEven
2727
public ChargingJailbirdEventArgs(ReferenceHub player, InventorySystem.Items.ItemBase swingItem, bool isAllowed = true)
2828
{
2929
Player = Player.Get(player);
30-
Item = Item.Get(swingItem);
30+
Jailbird = (Jailbird)Item.Get(swingItem);
3131
#pragma warning disable CS0618
3232
IsAllowed = isAllowed;
3333
#pragma warning restore CS0618
@@ -39,9 +39,14 @@ public ChargingJailbirdEventArgs(ReferenceHub player, InventorySystem.Items.Item
3939
public Player Player { get; }
4040

4141
/// <summary>
42-
/// Gets the <see cref="API.Features.Items.Item"/> that is being charged. This will always be a <see cref="Jailbird"/>.
42+
/// Gets the <see cref="API.Features.Items.Jailbird"/> that is being charged.
4343
/// </summary>
44-
public Item Item { get; }
44+
public Jailbird Jailbird { get; }
45+
46+
/// <summary>
47+
/// Gets the <see cref="API.Features.Items.Item"/> that is being charged.
48+
/// </summary>
49+
public Item Item => Jailbird;
4550

4651
/// <summary>
4752
/// Gets or sets a value indicating whether or not the Jailbird can be charged.

EXILED/Exiled.Events/EventArgs/Item/SwingingEventArgs.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class SwingingEventArgs : IPlayerEvent, IItemEvent, IDeniableEvent
2525
public SwingingEventArgs(ReferenceHub player, InventorySystem.Items.ItemBase swingItem, bool isAllowed = true)
2626
{
2727
Player = Player.Get(player);
28-
Item = Item.Get(swingItem);
28+
Jailbird = (Jailbird)Item.Get(swingItem);
2929
IsAllowed = isAllowed;
3030
}
3131

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

37+
/// <summary>
38+
/// Gets the <see cref="API.Features.Items.Jailbird"/> that is being swung.
39+
/// </summary>
40+
public Jailbird Jailbird { get; }
41+
3742
/// <summary>
3843
/// Gets the <see cref="API.Features.Items.Item"/> that is being swung.
3944
/// </summary>
40-
public Item Item { get; }
45+
public Item Item => Jailbird;
4146

4247
/// <summary>
4348
/// Gets or sets a value indicating whether or not the item can be swung.

EXILED/Exiled.Events/EventArgs/Scp079/RecontainedEventArgs.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ public class RecontainedEventArgs : IScp079Event
2222
/// <param name="player">
2323
/// <inheritdoc cref="Player" />
2424
/// </param>
25-
public RecontainedEventArgs(Player player)
25+
/// <param name="scp079Recontainer">
26+
/// <inheritdoc cref="Recontainer" />
27+
/// </param>
28+
public RecontainedEventArgs(Player player, PlayerRoles.PlayableScps.Scp079.Scp079Recontainer scp079Recontainer)
2629
{
2730
Player = player;
2831
Scp079 = player.Role.As<Scp079Role>();
32+
Recontainer = scp079Recontainer;
33+
Attacker = Player.Get(scp079Recontainer._activatorGlass.LastAttacker);
34+
IsAutomatic = scp079Recontainer._activatorGlass.LastAttacker.IsSet;
2935
}
3036

3137
/// <summary>
@@ -35,5 +41,20 @@ public RecontainedEventArgs(Player player)
3541

3642
/// <inheritdoc/>
3743
public Scp079Role Scp079 { get; }
44+
45+
/// <summary>
46+
/// Gets the instance that handle SCP-079 recontained proccess.
47+
/// </summary>
48+
public PlayerRoles.PlayableScps.Scp079.Scp079Recontainer Recontainer { get; }
49+
50+
/// <summary>
51+
/// Gets the player who recontained SCP-079.
52+
/// </summary>
53+
public Player Attacker { get; }
54+
55+
/// <summary>
56+
/// Gets a value indicating whether the recontainment has been made automatically or by triggering the process.
57+
/// </summary>
58+
public bool IsAutomatic { get; }
3859
}
39-
}
60+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="RespawnedTeamEventArgs.cs" company="Exiled Team">
3+
// Copyright (c) Exiled Team. All rights reserved.
4+
// Licensed under the CC BY-SA 3.0 license.
5+
// </copyright>
6+
// -----------------------------------------------------------------------
7+
8+
namespace Exiled.Events.EventArgs.Server
9+
{
10+
using System.Collections.Generic;
11+
using System.Linq;
12+
13+
using Exiled.API.Features;
14+
using Exiled.Events.EventArgs.Interfaces;
15+
using Respawning;
16+
17+
/// <summary>
18+
/// Contains all information after team spawns.
19+
/// </summary>
20+
public class RespawnedTeamEventArgs : IExiledEvent
21+
{
22+
/// <summary>
23+
/// Initializes a new instance of the <see cref="RespawnedTeamEventArgs"/> class.
24+
/// </summary>
25+
/// <param name="hubs"><inheritdoc cref="Players"/></param>
26+
/// <param name="team"><inheritdoc cref="Team"/></param>
27+
public RespawnedTeamEventArgs(SpawnableTeamType team, IEnumerable<ReferenceHub> hubs)
28+
{
29+
Players = hubs.Select(Player.Get);
30+
Team = team;
31+
}
32+
33+
/// <summary>
34+
/// Gets the list of spawned players.
35+
/// </summary>
36+
public IEnumerable<Player> Players { get; }
37+
38+
/// <summary>
39+
/// Gets the spawned team.
40+
/// </summary>
41+
public SpawnableTeamType Team { get; }
42+
}
43+
}

EXILED/Exiled.Events/Events.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Exiled.Events
2121
using PlayerRoles.Ragdolls;
2222
using PlayerRoles.RoleAssign;
2323
using PluginAPI.Events;
24+
using Respawning;
2425
using UnityEngine.SceneManagement;
2526

2627
/// <summary>
@@ -70,7 +71,7 @@ public override void OnEnabled()
7071
Handlers.Map.ChangedIntoGrenade += Handlers.Internal.ExplodingGrenade.OnChangedIntoGrenade;
7172

7273
CharacterClassManager.OnRoundStarted += Handlers.Server.OnRoundStarted;
73-
74+
RespawnManager.ServerOnRespawned += Handlers.Server.OnRespawnedTeam;
7475
InventorySystem.InventoryExtensions.OnItemAdded += Handlers.Player.OnItemAdded;
7576
InventorySystem.InventoryExtensions.OnItemRemoved += Handlers.Player.OnItemRemoved;
7677

@@ -105,7 +106,7 @@ public override void OnDisabled()
105106

106107
InventorySystem.InventoryExtensions.OnItemAdded -= Handlers.Player.OnItemAdded;
107108
InventorySystem.InventoryExtensions.OnItemRemoved -= Handlers.Player.OnItemRemoved;
108-
109+
RespawnManager.ServerOnRespawned -= Handlers.Server.OnRespawnedTeam;
109110
RagdollManager.OnRagdollSpawned -= Handlers.Internal.RagdollList.OnSpawnedRagdoll;
110111
RagdollManager.OnRagdollRemoved -= Handlers.Internal.RagdollList.OnRemovedRagdoll;
111112
ItemPickupBase.OnPickupAdded -= Handlers.Internal.PickupEvent.OnSpawnedPickup;

EXILED/Exiled.Events/Handlers/Internal/SceneUnloaded.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Exiled.Events.Handlers.Internal
99
{
1010
using API.Features;
11-
11+
using Exiled.API.Features.Toys;
1212
using UnityEngine.SceneManagement;
1313

1414
#pragma warning disable SA1611 // Element parameters should be documented
@@ -35,7 +35,7 @@ public static void OnSceneUnloaded(Scene _)
3535
{
3636
Player.UserIdsCache.Clear();
3737
Player.Dictionary.Clear();
38-
Map.ToysValue.Clear();
38+
AdminToy.BaseToAdminToy.Clear();
3939
}
4040
}
4141
}

0 commit comments

Comments
 (0)