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

Additions #29

Merged
merged 12 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
37 changes: 37 additions & 0 deletions EXILED/Exiled.API/Enums/HazardType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// -----------------------------------------------------------------------
// <copyright file="HazardType.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Enums
{
using Exiled.API.Features.Hazards;

/// <summary>
/// Unique identifier for a <see cref="Hazard"/>.
/// </summary>
public enum HazardType
{
/// <summary>
/// SCP-939 amnestic cloud.
/// </summary>
AmnesticCloud,

/// <summary>
/// Sinkhole spawned at start of round.
/// </summary>
Sinkhole,

/// <summary>
/// SCP-173 tantrum.
/// </summary>
Tantrum,

/// <summary>
/// Should never happen
/// </summary>
Unknown,
}
}
63 changes: 63 additions & 0 deletions EXILED/Exiled.API/Extensions/BitwiseExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// -----------------------------------------------------------------------
// <copyright file="BitwiseExtensions.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Extensions
{
using System;

/// <summary>
/// Extensions for bitwise operations.
/// </summary>
public static class BitwiseExtensions
{
/// <summary>
/// Adds the specified flags to the given enum value.
/// </summary>
/// <typeparam name="T">The type of the enum.</typeparam>
/// <param name="flags">The enum value to add flags to.</param>
/// <param name="newFlags">The flags to add.</param>
/// <returns>The enum value with the specified flags added.</returns>
public static T AddFlags<T>(this T flags, params T[] newFlags)
where T : Enum => flags.ModifyFlags(true, newFlags);

/// <summary>
/// Removes the specified flags from the given enum value.
/// </summary>
/// <typeparam name="T">The type of the enum.</typeparam>
/// <param name="flags">The enum value to remove flags from.</param>
/// <param name="oldFlags">The flags to remove.</param>
/// <returns>The enum value with the specified flags removed.</returns>
public static T RemoveFlags<T>(this T flags, params T[] oldFlags)
where T : Enum => flags.ModifyFlags(false, oldFlags);

/// <summary>
/// Sets the specified flag to the given value, default is true.
/// </summary>
/// <param name="flags">The flags enum to modify.</param>
/// <param name="value">The value to set the flag to.</param>
/// <param name="changeFlags">The flags to modify.</param>
/// <typeparam name="T">The type of the enum.</typeparam>
/// <returns>The flags enum with the flag set to the given value.</returns>
public static T ModifyFlags<T>(this T flags, bool value, params T[] changeFlags)
where T : Enum
{
long currentValue = Convert.ToInt64(flags);

foreach (T flag in changeFlags)
{
long flagValue = Convert.ToInt64(flag);

if (value)
currentValue |= flagValue;
else
currentValue &= ~flagValue;
}

return (T)Enum.ToObject(typeof(T), currentValue);
}
}
}
22 changes: 21 additions & 1 deletion EXILED/Exiled.API/Features/Hazards/AmnesticCloudHazard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------
// ------------------------------------------------------------------------

namespace Exiled.API.Features.Hazards
{
using Exiled.API.Enums;
using PlayerRoles.PlayableScps.Scp939;

/// <summary>
/// A wrapper for SCP-939's amnestic cloud.
/// </summary>
public class AmnesticCloudHazard : TemporaryHazard
{
private static Scp939AmnesticCloudInstance amnesticCloudPrefab;

/// <summary>
/// Initializes a new instance of the <see cref="AmnesticCloudHazard"/> class.
/// </summary>
Expand All @@ -26,9 +29,26 @@ public AmnesticCloudHazard(Scp939AmnesticCloudInstance hazard)
Owner = Player.Get(Ability.Owner);
}

/// <summary>
/// Gets the amnestic cloud prefab.
/// </summary>
public static Scp939AmnesticCloudInstance AmnesticCloudPrefab
{
get
{
if (amnesticCloudPrefab == null)
amnesticCloudPrefab = PrefabHelper.GetPrefab<Scp939AmnesticCloudInstance>(PrefabType.AmnesticCloudHazard);

return amnesticCloudPrefab;
}
}

/// <inheritdoc cref="Hazard.Base"/>
public new Scp939AmnesticCloudInstance Base { get; }

/// <inheritdoc />
public override HazardType Type => HazardType.AmnesticCloud;

/// <summary>
/// Gets the <see cref="Scp939AmnesticCloudAbility"/> for this instance.
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions EXILED/Exiled.API/Features/Hazards/Hazard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Exiled.API.Features.Hazards
using System.Collections.Generic;
using System.Linq;

using Exiled.API.Enums;
using Exiled.API.Features.Core;
using Exiled.API.Interfaces;
using global::Hazards;
Expand Down Expand Up @@ -48,6 +49,11 @@ public Hazard(EnvironmentalHazard hazard)
/// </summary>
public EnvironmentalHazard Base { get; }

/// <summary>
/// Gets the <see cref="HazardType"/> associated with the current Hazard.
/// </summary>
public virtual HazardType Type { get; } = HazardType.Unknown;

/// <summary>
/// Gets or sets the list with all affected by this hazard players.
/// </summary>
Expand Down Expand Up @@ -144,6 +150,13 @@ public static Hazard Get(EnvironmentalHazard environmentalHazard) =>
/// <returns><see cref="IEnumerable{T}"/> of <see cref="Hazard"/> based on predicate.</returns>
public static IEnumerable<Hazard> Get(Func<Hazard, bool> predicate) => List.Where(predicate);

/// <summary>
/// Gets an <see cref="IEnumerable{T}"/> of <see cref="Hazard"/>.
/// </summary>
/// <param name="type">The <see cref="HazardType"/> to get.</param>
/// <returns><see cref="IEnumerable{T}"/> of <see cref="Hazard"/> based on type.</returns>
public static IEnumerable<Hazard> Get(HazardType type) => Get(h => h.Type == type);

/// <summary>
/// Checks if player is in hazard zone.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions EXILED/Exiled.API/Features/Hazards/SinkholeHazard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Exiled.API.Features.Hazards
{
using Exiled.API.Enums;
using global::Hazards;

/// <summary>
Expand All @@ -28,5 +29,8 @@ public SinkholeHazard(SinkholeEnvironmentalHazard hazard)
/// Gets the <see cref="SinkholeEnvironmentalHazard"/>.
/// </summary>
public new SinkholeEnvironmentalHazard Base { get; }

/// <inheritdoc />
public override HazardType Type => HazardType.Sinkhole;
}
}
44 changes: 44 additions & 0 deletions EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

namespace Exiled.API.Features.Hazards
{
using Exiled.API.Enums;
using global::Hazards;
using Mirror;
using RelativePositioning;
using UnityEngine;

Expand All @@ -16,6 +18,8 @@ namespace Exiled.API.Features.Hazards
/// </summary>
public class TantrumHazard : TemporaryHazard
{
private static TantrumEnvironmentalHazard tantrumPrefab;

/// <summary>
/// Initializes a new instance of the <see cref="TantrumHazard"/> class.
/// </summary>
Expand All @@ -26,11 +30,28 @@ public TantrumHazard(TantrumEnvironmentalHazard hazard)
Base = hazard;
}

/// <summary>
/// Gets the tantrum prefab.
/// </summary>
public static TantrumEnvironmentalHazard TantrumPrefab
{
get
{
if (tantrumPrefab == null)
tantrumPrefab = PrefabHelper.GetPrefab<TantrumEnvironmentalHazard>(PrefabType.TantrumObj);

return tantrumPrefab;
}
}

/// <summary>
/// Gets the <see cref="TantrumEnvironmentalHazard"/>.
/// </summary>
public new TantrumEnvironmentalHazard Base { get; }

/// <inheritdoc />
public override HazardType Type => HazardType.Tantrum;

/// <summary>
/// Gets or sets a value indicating whether or not sizzle should be played.
/// </summary>
Expand All @@ -57,5 +78,28 @@ public Transform CorrectPosition
get => Base._correctPosition;
set => Base._correctPosition = value;
}

/// <summary>
/// Places a Tantrum (SCP-173's ability) in the indicated position.
/// </summary>
/// <param name="position">The position where you want to spawn the Tantrum.</param>
/// <param name="isActive">Whether or not the tantrum will apply the <see cref="EffectType.Stained"/> effect.</param>
/// <remarks>If <paramref name="isActive"/> is <see langword="true"/>, the tantrum is moved slightly up from its original position. Otherwise, the collision will not be detected and the slowness will not work.</remarks>
/// <returns>The <see cref="TantrumHazard"/> instance.</returns>
public static TantrumHazard PlaceTantrum(Vector3 position, bool isActive = true)
{
TantrumEnvironmentalHazard tantrum = Object.Instantiate(TantrumPrefab);

if (!isActive)
tantrum.SynchronizedPosition = new(position);
else
tantrum.SynchronizedPosition = new(position + (Vector3.up * 0.25f));

tantrum._destroyed = !isActive;

NetworkServer.Spawn(tantrum.gameObject);

return Get(tantrum) as TantrumHazard;
}
}
}
56 changes: 3 additions & 53 deletions EXILED/Exiled.API/Features/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ namespace Exiled.API.Features
using LightContainmentZoneDecontamination;
using MapGeneration;
using MapGeneration.Distributors;
using Mirror;
using PlayerRoles;
using PlayerRoles.PlayableScps.Scp173;
using PlayerRoles.PlayableScps.Scp939;
using PlayerRoles.Ragdolls;
using RelativePositioning;
Expand All @@ -39,8 +36,6 @@ namespace Exiled.API.Features
using Utils.Networking;

using Object = UnityEngine.Object;
using Scp173GameRole = PlayerRoles.PlayableScps.Scp173.Scp173Role;
using Scp939GameRole = PlayerRoles.PlayableScps.Scp939.Scp939Role;

/// <summary>
/// A set of tools to easily handle the in-game map.
Expand All @@ -57,48 +52,17 @@ public static class Map
/// </summary>
internal static readonly List<PocketDimensionTeleport> TeleportsValue = new(8);

private static TantrumEnvironmentalHazard tantrumPrefab;
private static Scp939AmnesticCloudInstance amnesticCloudPrefab;

private static AmbientSoundPlayer ambientSoundPlayer;

/// <summary>
/// Gets the tantrum prefab.
/// </summary>
public static TantrumEnvironmentalHazard TantrumPrefab
{
get
{
if (tantrumPrefab == null)
{
Scp173GameRole scp173Role = (Scp173GameRole)RoleTypeId.Scp173.GetRoleBase();

if (scp173Role.SubroutineModule.TryGetSubroutine(out Scp173TantrumAbility scp173TantrumAbility))
tantrumPrefab = scp173TantrumAbility._tantrumPrefab;
}

return tantrumPrefab;
}
}
public static TantrumEnvironmentalHazard TantrumPrefab => TantrumHazard.TantrumPrefab; // TODO: Remove this.

/// <summary>
/// Gets the amnestic cloud prefab.
/// </summary>
public static Scp939AmnesticCloudInstance AmnesticCloudPrefab
{
get
{
if (amnesticCloudPrefab == null)
{
Scp939GameRole scp939Role = (Scp939GameRole)RoleTypeId.Scp939.GetRoleBase();

if (scp939Role.SubroutineModule.TryGetSubroutine(out Scp939AmnesticCloudAbility ability))
amnesticCloudPrefab = ability._instancePrefab;
}

return amnesticCloudPrefab;
}
}
public static Scp939AmnesticCloudInstance AmnesticCloudPrefab => AmnesticCloudHazard.AmnesticCloudPrefab; // TODO: Remove this.

/// <summary>
/// Gets a value indicating whether decontamination has begun in the light containment zone.
Expand Down Expand Up @@ -281,21 +245,7 @@ public static void PlayAmbientSound(int id)
/// <param name="isActive">Whether or not the tantrum will apply the <see cref="EffectType.Stained"/> effect.</param>
/// <remarks>If <paramref name="isActive"/> is <see langword="true"/>, the tantrum is moved slightly up from its original position. Otherwise, the collision will not be detected and the slowness will not work.</remarks>
/// <returns>The <see cref="TantrumHazard"/> instance.</returns>
public static TantrumHazard PlaceTantrum(Vector3 position, bool isActive = true)
{
TantrumEnvironmentalHazard tantrum = Object.Instantiate(TantrumPrefab);

if (!isActive)
tantrum.SynchronizedPosition = new RelativePosition(position);
else
tantrum.SynchronizedPosition = new RelativePosition(position + (Vector3.up * 0.25f));

tantrum._destroyed = !isActive;

NetworkServer.Spawn(tantrum.gameObject);

return Hazard.Get(tantrum).Cast<TantrumHazard>();
}
public static TantrumHazard PlaceTantrum(Vector3 position, bool isActive = true) => TantrumHazard.PlaceTantrum(position, isActive); // TODO: Remove this.

/// <summary>
/// Destroy all <see cref="ItemPickupBase"/> objects.
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3241,7 +3241,7 @@ public void ChangeEffectIntensity(string effectName, byte intensity, float durat
/// <param name="isActive">Whether or not the tantrum will apply the <see cref="EffectType.Stained"/> effect.</param>
/// <remarks>If <paramref name="isActive"/> is <see langword="true"/>, the tantrum is moved slightly up from its original position. Otherwise, the collision will not be detected and the slowness will not work.</remarks>
/// <returns>The <see cref="TantrumHazard"/> instance..</returns>
public TantrumHazard PlaceTantrum(bool isActive = true) => Map.PlaceTantrum(Position, isActive);
public TantrumHazard PlaceTantrum(bool isActive = true) => TantrumHazard.PlaceTantrum(Position, isActive);

/// <summary>
/// Gives a new <see cref="AhpStat">to the player</see>.
Expand Down
Loading
Loading