Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Jailbird::WearState #12

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
louis1706 marked this conversation as resolved.
Show resolved Hide resolved
{
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)
louis1706 marked this conversation as resolved.
Show resolved Hide resolved
{
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
Loading