Skip to content

Commit 1fe545d

Browse files
committed
Jailbird
1 parent 21dae12 commit 1fe545d

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

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

Lines changed: 37 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,44 @@ 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._chargesToWearState.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 charges 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)
148+
{
149+
foreach (Keyframe keyframe in Base._deterioration._chargesToWearState.keys)
150+
{
151+
if (Base._deterioration.FloatToState(keyframe.value) == wearState)
152+
return Mathf.RoundToInt(keyframe.time);
153+
}
154+
155+
throw new Exception("Wear state not found in charges to wear state mapping.");
156+
}
157+
123158
/// <summary>
124159
/// Breaks the Jailbird.
125160
/// </summary>

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class ChargingJailbirdEventArgs : IPlayerEvent, IItemEvent, IDeniableEven
2525
public ChargingJailbirdEventArgs(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

@@ -35,9 +35,14 @@ public ChargingJailbirdEventArgs(ReferenceHub player, InventorySystem.Items.Item
3535
public Player Player { get; }
3636

3737
/// <summary>
38-
/// Gets the <see cref="API.Features.Items.Item"/> that is being charged. This will always be a <see cref="Jailbird"/>.
38+
/// Gets the <see cref="API.Features.Items.Jailbird"/> that is being charged.
3939
/// </summary>
40-
public Item Item { get; }
40+
public Jailbird Jailbird { get; }
41+
42+
/// <summary>
43+
/// Gets the <see cref="API.Features.Items.Item"/> that is being charged.
44+
/// </summary>
45+
public Item Item => Jailbird;
4146

4247
/// <summary>
4348
/// 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.

0 commit comments

Comments
 (0)