Skip to content

Commit

Permalink
Jailbird
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 committed Jul 31, 2024
1 parent 21dae12 commit 1fe545d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
39 changes: 37 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,44 @@ 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._chargesToWearState.keys)
{
if (Base._deterioration.FloatToState(keyframe.value) == wearState)
return keyframe.time;
}

throw new Exception("Wear state not found in charges 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)
{
foreach (Keyframe keyframe in Base._deterioration._chargesToWearState.keys)
{
if (Base._deterioration.FloatToState(keyframe.value) == wearState)
return Mathf.RoundToInt(keyframe.time);
}

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

/// <summary>
/// Breaks the Jailbird.
/// </summary>
Expand Down
11 changes: 8 additions & 3 deletions EXILED/Exiled.Events/EventArgs/Item/ChargingJailbirdEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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);
IsAllowed = isAllowed;
}

Expand All @@ -35,9 +35,14 @@ 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 Item Item { get; }
public Jailbird Jailbird { get; }

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

/// <summary>
/// Gets or sets a value indicating whether or not the Jailbird can be charged.
Expand Down
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

0 comments on commit 1fe545d

Please sign in to comment.