Skip to content

Commit 40b7ed0

Browse files
authored
Merge branch 'dev' into escape-fix
2 parents 12ddfc6 + 1f2d209 commit 40b7ed0

File tree

11 files changed

+205
-22
lines changed

11 files changed

+205
-22
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: 7 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>

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.
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
}

EXILED/Exiled.Events/Handlers/Server.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
namespace Exiled.Events.Handlers
99
{
10+
using System.Collections.Generic;
11+
12+
using Respawning;
1013
#pragma warning disable SA1623 // Property summary documentation should match accessors
1114

1215
using Exiled.Events.EventArgs.Player;
@@ -53,6 +56,11 @@ public static class Server
5356
/// </summary>
5457
public static Event<RespawningTeamEventArgs> RespawningTeam { get; set; } = new();
5558

59+
/// <summary>
60+
/// Invoked after team spawns.
61+
/// </summary>
62+
public static Event<RespawnedTeamEventArgs> RespawnedTeam { get; set; } = new();
63+
5664
/// <summary>
5765
/// Invoked before adding an unit name.
5866
/// </summary>
@@ -142,6 +150,13 @@ public static class Server
142150
/// <param name="ev">The <see cref="RespawningTeamEventArgs"/> instance.</param>
143151
public static void OnRespawningTeam(RespawningTeamEventArgs ev) => RespawningTeam.InvokeSafely(ev);
144152

153+
/// <summary>
154+
/// Called after team spawns.
155+
/// </summary>
156+
/// <param name="teamType"><inheritdoc cref="RespawnedTeamEventArgs.Team"/></param>
157+
/// <param name="hubs"><inheritdoc cref="RespawnedTeamEventArgs.Players"/></param>
158+
public static void OnRespawnedTeam(SpawnableTeamType teamType, List<ReferenceHub> hubs) => RespawnedTeam.InvokeSafely(new RespawnedTeamEventArgs(teamType, hubs));
159+
145160
/// <summary>
146161
/// Called before adding an unit name.
147162
/// </summary>

0 commit comments

Comments
 (0)