Skip to content
Open
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
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,
}
}
62 changes: 43 additions & 19 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 Down Expand Up @@ -69,6 +70,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 @@ -97,25 +107,39 @@ 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;
}
LeverStatus = value.HasFlagFast(WarheadStatus.Armed);

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

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

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

Expand All @@ -132,7 +156,7 @@ public static WarheadStatus Status
/// <summary>
/// Gets a value indicating whether the warhead detonation is on cooldown.
/// </summary>
public static bool IsOnCooldown => Controller.CooldownEndTime > NetworkTime.time;
public static bool IsOnCooldown => RemainingCooldown > 0;

/// <summary>
/// Gets or sets the warhead detonation timer.
Expand Down
Loading