Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public GenericDamageHandler(Player player, Player attacker, float damage, Damage
case DamageType.MicroHid:
InventorySystem.Items.MicroHID.MicroHIDItem microHidOwner = new();
microHidOwner.Owner = attacker.ReferenceHub;
Base = new MicroHidDamageHandler(microHidOwner, damage);
Base = new MicroHidDamageHandler(damage, microHidOwner);
break;
case DamageType.Explosion:
Base = new ExplosionDamageHandler(attacker.Footprint, UnityEngine.Vector3.zero, damage, 0, ExplosionType.Grenade);
Expand Down
6 changes: 4 additions & 2 deletions EXILED/Exiled.API/Features/Items/Jailbird.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Exiled.API.Features.Items

using Exiled.API.Features.Pickups;
using Exiled.API.Interfaces;
using InventorySystem.Items;
using InventorySystem.Items.Autosync;
using InventorySystem.Items.Jailbird;
using Mirror;
Expand Down Expand Up @@ -152,13 +153,14 @@ public float GetDamage(JailbirdWearState wearState)
public void Break()
{
WearState = JailbirdWearState.Broken;
using (new AutosyncRpc(Base, true, out NetworkWriter networkWriter))
ItemIdentifier identifier = new(Base);
using (new AutosyncRpc(identifier, out NetworkWriter networkWriter))
{
networkWriter.WriteByte(0);
networkWriter.WriteByte((byte)JailbirdWearState.Broken);
}

using (new AutosyncRpc(Base, true, out NetworkWriter networkWriter2))
using (new AutosyncRpc(identifier, out NetworkWriter networkWriter2))
{
networkWriter2.WriteByte(1);
}
Expand Down
166 changes: 157 additions & 9 deletions EXILED/Exiled.API/Features/Items/MicroHid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@

namespace Exiled.API.Features.Items
{
using Exiled.API.Interfaces;
using System;
using System.Reflection;

using Exiled.API.Features.Pickups;
using Exiled.API.Interfaces;
using InventorySystem.Items.MicroHID;
using InventorySystem.Items.MicroHID.Modules;

using Random = UnityEngine.Random;

/// <summary>
/// A wrapper class for <see cref="MicroHIDItem"/>.
Expand All @@ -24,6 +30,11 @@ public MicroHid(MicroHIDItem itemBase)
: base(itemBase)
{
Base = itemBase;

EnergyManager = Base.EnergyManager;
BrokenModule = Base.BrokenSync;
InputModule = Base.InputSync;
CycleController = Base.CycleController;
}

/// <summary>
Expand All @@ -34,13 +45,34 @@ internal MicroHid()
{
}

/// <summary>
/// Gets the <see cref="EnergyManagerModule"/> of the MicroHID.
/// </summary>
public EnergyManagerModule EnergyManager { get; }

/// <summary>
/// Gets the <see cref="BrokenSyncModule"/> of the MicroHID.
/// </summary>
public BrokenSyncModule BrokenModule { get; }

/// <summary>
/// Gets the <see cref="InputSyncModule"/> of the MicroHID.
/// </summary>
public InputSyncModule InputModule { get; }

/// <summary>
/// Gets the <see cref="CycleController"/> of the MicroHID.
/// </summary>
public CycleController CycleController { get; }

/// <summary>
/// Gets or sets the remaining energy in the MicroHID.
/// </summary>
/// <value>Maximum energy is <c>1</c>. Minimum energy is <c>0</c>.</value>
public float Energy
{
get => Base.RemainingEnergy;
set => Base.RemainingEnergy = value;
get => EnergyManager.Energy;
set => EnergyManager.ServerSetEnergy(Serial, value);
}

/// <summary>
Expand All @@ -49,23 +81,128 @@ public float Energy
public new MicroHIDItem Base { get; }

/// <summary>
/// Gets or sets the <see cref="HidState"/>.
/// Gets or sets a value indicating whether the MicroHID is broken.
/// </summary>
public bool IsBroken
{
get => BrokenModule.Broken;
set => BrokenModule.ServerSetBroken(Serial, value);
}

/// <summary>
/// Gets a time when this <see cref="MicroHid"/> was broken.
/// </summary>
/// <value>A time when this <see cref="MicroHid"/> was broken, or <c>0</c> if it is not broken.</value>
public float BrokeTime => BrokenSyncModule.TryGetBrokenElapsed(Serial, out float time) ? time : 0;

/// <summary>
/// Gets or sets the <see cref="MicroHidPhase"/>.
/// </summary>
public MicroHidPhase State
{
get => CycleController.Phase;
set => CycleController.Phase = value;
}

/// <summary>
/// Gets or sets progress of winging up.
/// </summary>
/// <value>A value between <c>0</c> and <c>1</c>.</value>
public float WindUpProgress
{
get => CycleController.ServerWindUpProgress;
set => CycleController.ServerWindUpProgress = value;
}

/// <summary>
/// Gets or sets the last received <see cref="MicroHidFiringMode"/>.
/// </summary>
public MicroHidFiringMode LastFiringMode
{
get => CycleController.LastFiringMode;
set => CycleController.LastFiringMode = value;
}

/// <summary>
/// Gets or sets the last received <see cref="InputSyncModule.SyncData"/>.
/// </summary>
public HidState State
public InputSyncModule.SyncData LastReceived
{
get => Base.State;
set => Base.State = value;
get => InputModule._lastReceived;
set => InputModule._lastReceived = value;
}

/// <summary>
/// Gets a value indicating whether the <see cref="LastReceived"/> is <see cref="InputSyncModule.SyncData.Primary"/>.
/// </summary>
public bool IsPrimary => InputModule.Primary;

/// <summary>
/// Starts firing the MicroHID.
/// </summary>
public void Fire() => Base.Fire();
/// <param name="firingMode">Fire mode.</param>
public void Fire(MicroHidFiringMode firingMode = MicroHidFiringMode.PrimaryFire)
{
switch (firingMode)
{
case MicroHidFiringMode.PrimaryFire:
if (TryGetFireController(MicroHidFiringMode.PrimaryFire, out PrimaryFireModeModule primaryFireModeModule))
primaryFireModeModule.ServerFire();
break;
case MicroHidFiringMode.ChargeFire:
if (TryGetFireController(MicroHidFiringMode.ChargeFire, out ChargeFireModeModule chargeFireModeModule))
chargeFireModeModule.ServerFire();
break;
default:
if (TryGetFireController(MicroHidFiringMode.BrokenFire, out BrokenFireModeModule brokenFireModeModule))
brokenFireModeModule.ServerFire();
break;
}
}

/// <summary>
/// Recharges the MicroHID.
/// </summary>
public void Recharge() => Base.Recharge();
public void Recharge()
{
if (IsBroken)
Energy = Random.value;
else
Energy = 1;
}

/// <summary>
/// Explodes the MicroHID.
/// </summary>
public void Explode()
{
if (TryGetFireController(MicroHidFiringMode.ChargeFire, out ChargeFireModeModule module))
module.ServerExplode();
}

/// <summary>
/// Tries to get a <see cref="FiringModeControllerModule"/> assosiated with the specified <see cref="MicroHidFiringMode"/>.
/// </summary>
/// <param name="firingMode">Target firing mode.</param>
/// <param name="module">Found module or <c>null</c>.</param>
/// <typeparam name="T">Type of module.</typeparam>
/// <returns><c>true</c> if module was found, <c>false</c> otherwise.</returns>
public bool TryGetFireController<T>(MicroHidFiringMode firingMode, out T module)
where T : FiringModeControllerModule
{
if (CycleController._firingModeControllers.Count == 0)
CycleController.RecacheFiringModes(Base);

module = (T)CycleController._firingModeControllers.Find(x => x.AssignedMode == firingMode);
return module != null;
}

/// <summary>
/// Tries to get a <see cref="FiringModeControllerModule"/> assosiated with the last <see cref="MicroHidFiringMode"/>.
/// </summary>
/// <param name="module">Found module or <c>null</c>.</param>
/// <returns><c>true</c> if module was found, <c>false</c> otherwise.</returns>
public bool TryGetLastFireController(out FiringModeControllerModule module) => TryGetFireController(LastFiringMode, out module);

/// <summary>
/// Clones current <see cref="MicroHid"/> object.
Expand All @@ -82,5 +219,16 @@ public HidState State
/// </summary>
/// <returns>A string containing MicroHid-related data.</returns>
public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* |{Energy}| -{State}-";

/// <inheritdoc />
internal override void ReadPickupInfo(Pickup pickup)
{
base.ReadPickupInfo(pickup);

if (pickup.Is(out Pickups.MicroHIDPickup microHidPickup))
{
Energy = microHidPickup.Energy;
}
}
}
}
107 changes: 104 additions & 3 deletions EXILED/Exiled.API/Features/Pickups/MicroHIDPickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

namespace Exiled.API.Features.Pickups
{
using Exiled.API.Features.Items;
using Exiled.API.Interfaces;
using InventorySystem.Items.MicroHID.Modules;

using BaseMicroHID = InventorySystem.Items.MicroHID.MicroHIDPickup;

Expand Down Expand Up @@ -40,19 +42,118 @@ internal MicroHIDPickup()
/// </summary>
public new BaseMicroHID Base { get; }

/// <summary>
/// Gets the <see cref="InventorySystem.Items.MicroHID.Modules.CycleController"/> of this <see cref="MicroHIDPickup"/>.
/// </summary>
public CycleController CycleController => Base._cycleController;

/// <summary>
/// Gets or sets the MicroHID Energy Level.
/// </summary>
public float Energy
public float Energy { get; set; }

/// <summary>
/// Gets or sets the <see cref="MicroHidPhase"/>.
/// </summary>
public MicroHidPhase State
{
get => CycleController.Phase;
set => CycleController.Phase = value;
}

/// <summary>
/// Gets or sets progress of winging up.
/// </summary>
/// <value>A value between <c>0</c> and <c>1</c>.</value>
public float WindUpProgress
{
get => CycleController.ServerWindUpProgress;
set => CycleController.ServerWindUpProgress = value;
}

/// <summary>
/// Gets or sets the last received <see cref="MicroHidFiringMode"/>.
/// </summary>
public MicroHidFiringMode LastFiringMode
{
get => Base.NetworkEnergy;
set => Base.NetworkEnergy = value;
get => CycleController.LastFiringMode;
set => CycleController.LastFiringMode = value;
}

/// <summary>
/// Starts firing the MicroHID.
/// </summary>
/// <param name="firingMode">Fire mode.</param>
public void Fire(MicroHidFiringMode firingMode = MicroHidFiringMode.PrimaryFire)
{
switch (firingMode)
{
case MicroHidFiringMode.PrimaryFire:
if (TryGetFireController(MicroHidFiringMode.PrimaryFire, out PrimaryFireModeModule primaryFireModeModule))
primaryFireModeModule.ServerFire();
break;
case MicroHidFiringMode.ChargeFire:
if (TryGetFireController(MicroHidFiringMode.ChargeFire, out ChargeFireModeModule chargeFireModeModule))
chargeFireModeModule.ServerFire();
break;
default:
if (TryGetFireController(MicroHidFiringMode.BrokenFire, out BrokenFireModeModule brokenFireModeModule))
brokenFireModeModule.ServerFire();
break;
}
}

/// <summary>
/// Explodes the MicroHID.
/// </summary>
public void Explode()
{
if (TryGetFireController(MicroHidFiringMode.ChargeFire, out ChargeFireModeModule module))
module.ServerExplode();
}

/// <summary>
/// Tries to get a <see cref="FiringModeControllerModule"/> assosiated with the specified <see cref="MicroHidFiringMode"/>.
/// </summary>
/// <param name="firingMode">Target firing mode.</param>
/// <param name="module">Found module or <c>null</c>.</param>
/// <typeparam name="T">Type of module.</typeparam>
/// <returns><c>true</c> if module was found, <c>false</c> otherwise.</returns>
public bool TryGetFireController<T>(MicroHidFiringMode firingMode, out T module)
where T : FiringModeControllerModule
{
if (CycleController._firingModeControllers.Count == 0)
{
module = null;
return false;
}

module = (T)CycleController._firingModeControllers.Find(x => x.AssignedMode == firingMode);
return module != null;
}

/// <summary>
/// Tries to get a <see cref="FiringModeControllerModule"/> assosiated with the last <see cref="MicroHidFiringMode"/>.
/// </summary>
/// <param name="module">Found module or <c>null</c>.</param>
/// <returns><c>true</c> if module was found, <c>false</c> otherwise.</returns>
public bool TryGetLastFireController(out FiringModeControllerModule module) => TryGetFireController(LastFiringMode, out module);

/// <summary>
/// Returns the MicroHIDPickup in a human readable format.
/// </summary>
/// <returns>A string containing MicroHIDPickup related data.</returns>
public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* |{Energy}|";

/// <inheritdoc/>
internal override void ReadItemInfo(Item item)
{
base.ReadItemInfo(item);

if (item.Is(out MicroHid microHid))
{
Energy = microHid.Energy;
}
}
}
}
2 changes: 1 addition & 1 deletion EXILED/Exiled.CustomItems/API/Features/CustomGrenade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public virtual Pickup Throw(Vector3 position, float force, float weight, float f
NetworkServer.Spawn(thrownProjectile.gameObject);
thrownProjectile.InfoReceivedHook(default, newInfo);
if (thrownProjectile.TryGetComponent(out Rigidbody component))
throwable.Base.PropelBody(component, throwable.Base.FullThrowSettings.StartTorque, ThrowableNetworkHandler.GetLimitedVelocity(velocity), force, throwable.Base.FullThrowSettings.UpwardsFactor);
throwable.Base.PropelBody(component, throwable.Base.FullThrowSettings.StartTorque, ThrowableNetworkHandler.GetLimitedVelocity(velocity));
thrownProjectile.ServerActivate();

return Pickup.Get(thrownProjectile);
Expand Down
Loading