Skip to content

Commit a393c8f

Browse files
MS-crewlouis1706
andauthored
feat: Fake effect extensions (#618)
* Update MirrorExtensions.cs * Update MirrorExtensions.cs * IndexOf is better --------- Co-authored-by: Yamato <louismonneyron5@yahoo.com>
1 parent b5d6e20 commit a393c8f

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

EXILED/Exiled.API/Extensions/MirrorExtensions.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Exiled.API.Extensions
1616
using System.Text;
1717

1818
using AudioPooling;
19+
using CustomPlayerEffects;
1920
using Exiled.API.Enums;
2021
using Exiled.API.Features.Items;
2122
using Features;
@@ -342,6 +343,64 @@ public static void ChangeAppearance(this Player player, RoleTypeId type, IEnumer
342343
player.Position += Vector3.up * 0.25f;
343344
}
344345

346+
/// <summary>
347+
/// Resynchronizes a specific effect from the effect owner to the target player.
348+
/// </summary>
349+
/// <param name="effectOwner">The player who owns the effect to be resynchronized.</param>
350+
/// <param name="target">The target player to whom the effect will be resynchronized.</param>
351+
/// <param name="effect">The type of effect to be resynchronized.</param>
352+
public static void ResyncEffectTo(this Player effectOwner, Player target, EffectType effect) => effectOwner.SendFakeEffectTo(target, effect, effectOwner.GetEffect(effect).Intensity);
353+
354+
/// <summary>
355+
/// Resynchronizes a specific effect from the effect owner to the target players.
356+
/// </summary>
357+
/// <param name="effectOwner">The player who owns the effect to be resynchronized.</param>
358+
/// <param name="targets">The list of target players to whom the effect will be resynchronized.</param>
359+
/// <param name="effect">The type of effect to be resynchronized.</param>
360+
public static void ResyncEffectTo(this Player effectOwner, IEnumerable<Player> targets, EffectType effect) => effectOwner.SendFakeEffectTo(targets, effect, effectOwner.GetEffect(effect).Intensity);
361+
362+
/// <summary>
363+
/// Sends a fake effect to a list of target players, simulating the effect as if it originated from the effect owner.
364+
/// </summary>
365+
/// <param name="effectOwner">The player who owns the effect.</param>
366+
/// <param name="targets">The list of target players to whom the effect will be sent.</param>
367+
/// <param name="effect">The type of effect to be sent.</param>
368+
/// <param name="intensity">The intensity of the effect.</param>
369+
public static void SendFakeEffectTo(this Player effectOwner, IEnumerable<Player> targets, EffectType effect, byte intensity)
370+
{
371+
foreach (Player target in targets)
372+
{
373+
effectOwner.SendFakeEffectTo(target, effect, intensity);
374+
}
375+
}
376+
377+
/// <summary>
378+
/// Sends a fake effect to a target player, simulating the effect as if it originated from the effect owner.
379+
/// </summary>
380+
/// <param name="effectOwner">The player who owns the effect.</param>
381+
/// <param name="target">The target player to whom the effect will be sent.</param>
382+
/// <param name="effect">The type of effect to be sent.</param>
383+
/// <param name="intensity">The intensity of the effect.</param>
384+
public static void SendFakeEffectTo(this Player effectOwner, Player target, EffectType effect, byte intensity)
385+
{
386+
SendFakeSyncObject(target, effectOwner.NetworkIdentity, typeof(PlayerEffectsController), (writer) =>
387+
{
388+
StatusEffectBase foundEffect = effectOwner.GetEffect(effect);
389+
int foundIndex = effectOwner.ReferenceHub.playerEffectsController.AllEffects.IndexOf(foundEffect);
390+
if (foundIndex == -1)
391+
{
392+
Log.Error($"Effect {effect} not found in {effectOwner.Nickname}'s effects list.");
393+
return;
394+
}
395+
396+
writer.WriteULong(0b0001);
397+
writer.WriteUInt(1);
398+
writer.WriteByte((byte)SyncList<byte>.Operation.OP_SET);
399+
writer.WriteUInt((uint)foundIndex);
400+
writer.WriteByte(intensity);
401+
});
402+
}
403+
345404
/// <summary>
346405
/// Send CASSIE announcement that only <see cref="Player"/> can hear.
347406
/// </summary>

0 commit comments

Comments
 (0)