Skip to content

Commit

Permalink
Add a bunch
Browse files Browse the repository at this point in the history
  • Loading branch information
Misfiy committed Aug 2, 2024
1 parent 6ebeac5 commit 2160cca
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 53 deletions.
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 { get; } = 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 { get; } = 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 { get; } = 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;
}
}
}
51 changes: 3 additions & 48 deletions EXILED/Exiled.API/Features/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,48 +62,17 @@ public static class Map
/// </summary>
internal static readonly List<AdminToy> ToysValue = new();

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 @@ -286,21 +255,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
19 changes: 16 additions & 3 deletions EXILED/Exiled.API/Features/PrefabHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ public static PrefabAttribute GetPrefabAttribute(this PrefabType prefabType)
return type.GetField(Enum.GetName(type, prefabType)).GetCustomAttribute<PrefabAttribute>();
}

/// <summary>
/// Gets the prefab of the specified <see cref="PrefabType"/>.
/// </summary>
/// <param name="type">The <see cref="PrefabType"/> to get prefab of.</param>
/// <typeparam name="T">The <see cref="Component"/> to get.</typeparam>
/// <returns>Returns the prefab component as <see cref="T"/>.</returns>
public static T GetPrefab<T>(PrefabType type)
where T : Component
{
if (!Stored.TryGetValue(type, out GameObject gameObject) || !gameObject.TryGetComponent(out T component))
return null;

return component;
}

/// <summary>
/// Spawns a prefab on server.
/// </summary>
Expand Down Expand Up @@ -68,9 +83,7 @@ public static GameObject Spawn(PrefabType prefabType, Vector3 position = default
public static T Spawn<T>(PrefabType prefabType, Vector3 position = default, Quaternion rotation = default)
where T : Component
{
if (!Stored.TryGetValue(prefabType, out GameObject gameObject) || !gameObject.TryGetComponent(out T component))
return null;
T obj = UnityEngine.Object.Instantiate(component, position, rotation);
T obj = UnityEngine.Object.Instantiate(GetPrefab<T>(prefabType), position, rotation);
NetworkServer.Spawn(obj.gameObject);
return obj;
}
Expand Down
Loading

0 comments on commit 2160cca

Please sign in to comment.