Skip to content

Commit cb8fbbe

Browse files
authored
Multiple change (UwU) (#79)
Add `Player::AddAmmo(Dictionary<ItemType, ushort> ammo)` Add `Player::GrantLoadout()` Add `Player::GrantLoadout(RoleTypeId)` Add `GetEffect<T>()` Add `Scp3114Role::UpdateIdentity()` Fixed `Scp3114Role::DisguiseDuration` not being sync to client
1 parent daecbb9 commit cb8fbbe

7 files changed

Lines changed: 69 additions & 16 deletions

File tree

EXILED/Exiled.API/Features/Player.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,6 +2335,16 @@ public void Broadcast(ushort duration, string message, global::Broadcast.Broadca
23352335
public void AddAmmo(AmmoType ammoType, ushort amount) =>
23362336
Inventory.ServerAddAmmo(ammoType.GetItemType(), amount);
23372337

2338+
/// <summary>
2339+
/// Adds the amount of a specified ammo to player's inventory.
2340+
/// </summary>
2341+
/// <param name="ammo">A dictionary of ItemType and ushort of ammo and amount.</param>
2342+
public void AddAmmo(Dictionary<ItemType, ushort> ammo)
2343+
{
2344+
foreach (KeyValuePair<ItemType, ushort> kvp in ammo)
2345+
AddAmmo(kvp.Key.GetAmmoType(), kvp.Value);
2346+
}
2347+
23382348
/// <summary>
23392349
/// Adds the amount of a specified <see cref="AmmoType">ammo type</see> to player's inventory.
23402350
/// </summary>
@@ -2578,6 +2588,23 @@ public void ResetCategoryLimit(ItemCategory category)
25782588
/// <returns>If the player has a custom limit for the specific <see cref="ItemCategory"/>.</returns>
25792589
public bool HasCustomCategoryLimit(ItemCategory category) => CustomCategoryLimits.ContainsKey(category);
25802590

2591+
/// <summary>
2592+
/// Grants the player their current role's loadout.
2593+
/// </summary>
2594+
public void GrantLoadout() => GrantLoadout(Role.Type);
2595+
2596+
/// <summary>
2597+
/// Grants a player a role's loadout.
2598+
/// </summary>
2599+
/// <param name="roleType">The role loadout to give.</param>
2600+
public void GrantLoadout(RoleTypeId roleType)
2601+
{
2602+
InventoryRoleInfo info = roleType.GetInventory();
2603+
2604+
AddItem(info.Items);
2605+
AddAmmo(info.Ammo);
2606+
}
2607+
25812608
/// <summary>
25822609
/// Adds an item of the specified type with default durability(ammo/charge) and no mods to the player's inventory.
25832610
/// </summary>
@@ -3305,6 +3332,14 @@ public void SyncEffects(IEnumerable<Effect> effects)
33053332
SyncEffect(effect);
33063333
}
33073334

3335+
/// <summary>
3336+
/// Gets an effect of a player.
3337+
/// </summary>
3338+
/// <typeparam name="T">The <see cref="StatusEffectBase"/> to get.</typeparam>
3339+
/// <returns>The <see cref="StatusEffectBase"/> found.</returns>
3340+
public T GetEffect<T>()
3341+
where T : StatusEffectBase => ReferenceHub.playerEffectsController.GetEffect<T>();
3342+
33083343
/// <summary>
33093344
/// Gets an instance of <see cref="StatusEffectBase"/> by <see cref="EffectType"/>.
33103345
/// </summary>

EXILED/Exiled.API/Features/Roles/Scp3114Role.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public RoleTypeId StolenRole
153153
return;
154154

155155
Ragdoll.Role = value;
156-
Identity.ServerResendIdentity();
156+
UpdateIdentity();
157157
}
158158
}
159159

@@ -166,7 +166,7 @@ public Ragdoll Ragdoll
166166
set
167167
{
168168
Identity.CurIdentity.Ragdoll = value?.Base;
169-
Identity.ServerResendIdentity();
169+
UpdateIdentity();
170170
}
171171
}
172172

@@ -179,7 +179,7 @@ public byte UnitId
179179
set
180180
{
181181
Identity.CurIdentity.UnitNameId = value;
182-
Identity.ServerResendIdentity();
182+
UpdateIdentity();
183183
}
184184
}
185185

@@ -192,7 +192,7 @@ public DisguiseStatus DisguiseStatus
192192
set
193193
{
194194
Identity.CurIdentity.Status = value;
195-
Identity.ServerResendIdentity();
195+
UpdateIdentity();
196196
}
197197
}
198198

@@ -202,7 +202,11 @@ public DisguiseStatus DisguiseStatus
202202
public float DisguiseDuration
203203
{
204204
get => Identity._disguiseDurationSeconds;
205-
set => Identity._disguiseDurationSeconds = value;
205+
set
206+
{
207+
Identity._disguiseDurationSeconds = value;
208+
UpdateIdentity();
209+
}
206210
}
207211

208212
/// <summary>
@@ -219,13 +223,18 @@ public float WarningTime
219223
/// </summary>
220224
internal DanceType DanceType { get; set; }
221225

226+
/// <summary>
227+
/// Updates the identity of SCP-3114.
228+
/// </summary>
229+
public void UpdateIdentity() => Identity.ServerResendIdentity();
230+
222231
/// <summary>
223232
/// Reset Scp3114 FakeIdentity.
224233
/// </summary>
225234
public void ResetIdentity()
226235
{
227236
Identity.CurIdentity.Reset();
228-
Identity.ServerResendIdentity();
237+
UpdateIdentity();
229238
}
230239

231240
/// <summary>

EXILED/Exiled.CustomItems/CustomItems.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Exiled.CustomItems
1919
/// </summary>
2020
public class CustomItems : Plugin<Config>
2121
{
22-
private RoundHandler? roundHandler;
22+
private MapHandler? mapHandler;
2323
private PlayerHandler? playerHandler;
2424
private Harmony? harmony;
2525

@@ -32,10 +32,10 @@ public class CustomItems : Plugin<Config>
3232
public override void OnEnabled()
3333
{
3434
Instance = this;
35-
roundHandler = new RoundHandler();
35+
mapHandler = new MapHandler();
3636
playerHandler = new PlayerHandler();
3737

38-
Exiled.Events.Handlers.Server.RoundStarted += roundHandler.OnRoundStarted;
38+
Exiled.Events.Handlers.Map.Generated += mapHandler.OnMapGenerated;
3939

4040
Exiled.Events.Handlers.Player.ChangingItem += playerHandler.OnChangingItem;
4141

@@ -50,7 +50,7 @@ public override void OnEnabled()
5050
/// <inheritdoc />
5151
public override void OnDisabled()
5252
{
53-
Exiled.Events.Handlers.Server.RoundStarted -= roundHandler!.OnRoundStarted;
53+
Exiled.Events.Handlers.Map.Generated -= mapHandler!.OnMapGenerated;
5454

5555
Exiled.Events.Handlers.Player.ChangingItem -= playerHandler!.OnChangingItem;
5656

EXILED/Exiled.CustomItems/Events/RoundHandler.cs renamed to EXILED/Exiled.CustomItems/Events/MapHandler.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// -----------------------------------------------------------------------
2-
// <copyright file="RoundHandler.cs" company="Exiled Team">
2+
// <copyright file="MapHandler.cs" company="Exiled Team">
33
// Copyright (c) Exiled Team. All rights reserved.
44
// Licensed under the CC BY-SA 3.0 license.
55
// </copyright>
@@ -12,10 +12,12 @@ namespace Exiled.CustomItems.Events
1212
/// <summary>
1313
/// Event Handlers for the CustomItem API.
1414
/// </summary>
15-
internal sealed class RoundHandler
15+
internal sealed class MapHandler
1616
{
17-
/// <inheritdoc cref="Exiled.Events.Handlers.Server.OnRoundStarted"/>
18-
public void OnRoundStarted()
17+
/// <summary>
18+
/// Handle spawning Custom Items.
19+
/// </summary>
20+
public void OnMapGenerated()
1921
{
2022
foreach (CustomItem customItem in CustomItem.Registered)
2123
customItem?.SpawnAll();

EXILED/Exiled.Events/EventArgs/Player/KillingPlayerEventArgs.cs

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

88
namespace Exiled.Events.EventArgs.Player
99
{
10-
using Interfaces;
10+
using System;
1111

12+
using Interfaces;
1213
using PlayerStatsSystem;
1314

1415
/// <summary>
1516
/// Contains all information before player data to kill player is sent.
1617
/// </summary>
18+
[Obsolete]
1719
public class KillingPlayerEventArgs : IPlayerEvent
1820
{
1921
/// <summary>

EXILED/Exiled.Events/Handlers/Player.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
namespace Exiled.Events.Handlers
99
{
10-
using Exiled.API.Features.Pickups;
10+
using System;
11+
1112
#pragma warning disable IDE0079
1213
#pragma warning disable IDE0060
1314
#pragma warning disable SA1623 // Property summary documentation should match accessors
@@ -516,6 +517,7 @@ public class Player
516517
/// <summary>
517518
/// Invoked before KillPlayer is called.
518519
/// </summary>
520+
[Obsolete("Use DyingEventArgs")]
519521
public static Event<KillingPlayerEventArgs> KillingPlayer { get; set; } = new();
520522

521523
/// <summary>
@@ -976,6 +978,7 @@ public class Player
976978
/// Called before KillPlayer is called.
977979
/// </summary>
978980
/// <param name="ev">The <see cref="KillingPlayerEventArgs"/> event handler. </param>
981+
[Obsolete("Use DyingEventArgs")]
979982
public static void OnKillPlayer(KillingPlayerEventArgs ev) => KillingPlayer.InvokeSafely(ev);
980983

981984
/// <summary>

EXILED/Exiled.Events/Patches/Fixes/KillPlayer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
namespace Exiled.Events.Patches.Fixes
99
{
1010
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
11+
#pragma warning disable CS0612 // Type or member is obsolete
12+
#pragma warning disable CS0618 // Type or member is obsolete
1113

1214
using API.Features;
1315
using API.Features.DamageHandlers;

0 commit comments

Comments
 (0)