Skip to content
Open
16 changes: 12 additions & 4 deletions EXILED/Exiled.API/Enums/WarheadStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,38 @@

namespace Exiled.API.Enums
{
using System;

/// <summary>
/// All the available warhead statuses.
/// </summary>
/// <seealso cref="Features.Warhead.Status"/>
[Flags]
public enum WarheadStatus
{
/// <summary>
/// The warhead is not armed.
/// </summary>
NotArmed,
NotArmed = 0,

/// <summary>
/// The warhead is armed.
/// </summary>
Armed,
Armed = 1,

/// <summary>
/// The warhead detonation is in progress.
/// </summary>
InProgress,
InProgress = 2,

/// <summary>
/// The warhead has detonated.
/// </summary>
Detonated,
Detonated = 4,

/// <summary>
/// The warhead is on cooldown.
/// </summary>
OnCooldown = 8,
}
}
72 changes: 52 additions & 20 deletions EXILED/Exiled.API/Features/Warhead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

namespace Exiled.API.Features
{
using System;
using System.Collections.Generic;

using Enums;
using Exiled.API.Extensions;
using Interactables.Interobjects.DoorUtils;
using Mirror;

using UnityEngine;

/// <summary>
Expand All @@ -33,7 +34,7 @@ public static class Warhead
/// <summary>
/// Gets the cached <see cref="AlphaWarheadOutsitePanel"/> component.
/// </summary>
public static AlphaWarheadOutsitePanel OutsitePanel => field != null ? field : (field = Object.FindFirstObjectByType<AlphaWarheadOutsitePanel>());
public static AlphaWarheadOutsitePanel OutsitePanel => field != null ? field : (field = UnityEngine.Object.FindFirstObjectByType<AlphaWarheadOutsitePanel>());

/// <summary>
/// Gets the <see cref="GameObject"/> of the warhead lever.
Expand Down Expand Up @@ -67,6 +68,15 @@ public static bool OpenDoors
set => Controller._openDoors = value;
}

/// <summary>
/// Gets or sets the remaining cooldown before the nuke can be triggered again.
/// </summary>
public static double RemainingCooldown
{
get => Math.Max(0, Controller.NetworkCooldownEndTime - NetworkTime.time);
set => Controller.NetworkCooldownEndTime = NetworkTime.time + Math.Max(0, value);
}

/// <summary>
/// Gets all of the warhead blast doors.
/// </summary>
Expand Down Expand Up @@ -95,25 +105,42 @@ public static bool IsKeycardActivated
/// </summary>
public static WarheadStatus Status
{
get => IsInProgress ? IsDetonated ? WarheadStatus.Detonated : WarheadStatus.InProgress : LeverStatus ? WarheadStatus.Armed : WarheadStatus.NotArmed;
get
{
WarheadStatus status = WarheadStatus.NotArmed;

if (IsDetonated)
status |= WarheadStatus.Detonated;

if (IsInProgress)
status |= WarheadStatus.InProgress;

if (IsOnCooldown)
status |= WarheadStatus.OnCooldown;

if (LeverStatus)
status |= WarheadStatus.Armed;

return status;
}

set
{
switch (value)
{
case WarheadStatus.NotArmed:
case WarheadStatus.Armed:
Stop();
LeverStatus = value is WarheadStatus.Armed;
break;

case WarheadStatus.InProgress:
Start();
break;

case WarheadStatus.Detonated:
Detonate();
break;
}
if (IsDetonated)
return;

LeverStatus = value.HasFlagFast(WarheadStatus.Armed);

if (!IsInProgress && value.HasFlagFast(WarheadStatus.InProgress))
Start();
else if (!value.HasFlagFast(WarheadStatus.InProgress))
Stop();

if (value.HasFlagFast(WarheadStatus.Detonated))
Detonate();

if (!IsOnCooldown && value.HasFlagFast(WarheadStatus.OnCooldown))
RemainingCooldown = Controller._cooldown;
}
}

Expand All @@ -127,6 +154,11 @@ public static WarheadStatus Status
/// </summary>
public static bool IsInProgress => Controller.Info.InProgress;

/// <summary>
/// Gets a value indicating whether the warhead detonation is on cooldown.
/// </summary>
public static bool IsOnCooldown => RemainingCooldown > 0;

/// <summary>
/// Gets or sets the warhead detonation timer.
/// </summary>
Expand Down Expand Up @@ -162,7 +194,7 @@ public static int Kills
/// <summary>
/// Gets a value indicating whether the warhead can be started.
/// </summary>
public static bool CanBeStarted => !IsInProgress && !IsDetonated && Controller.CooldownEndTime <= NetworkTime.time;
public static bool CanBeStarted => !IsInProgress && !IsDetonated && !IsOnCooldown;

/// <summary>
/// Closes the surface blast doors.
Expand Down