Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

More ragdoll API #18

Merged
merged 2 commits into from
Jan 27, 2023
Merged
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
5 changes: 3 additions & 2 deletions CursedMod/CursedMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<HintPath>$(SL_REFERENCES)\Mirror-Publicized.dll</HintPath>
</Reference>
<Reference Include="NorthwoodLib">
<HintPath>..\..\..\SCPSL\Plugins\Dependencies\NorthwoodLib.dll</HintPath>
<HintPath>$(SL_REFERENCES)\NorthwoodLib.dll</HintPath>
</Reference>
<Reference Include="PluginAPI">
<HintPath>$(SL_REFERENCES)\PluginAPI-Publicized.dll</HintPath>
Expand All @@ -77,6 +77,7 @@
<Compile Include="Events\EventManager.cs" />
<Compile Include="Events\Handlers\Achievements\AchievementsEventHandler.cs" />
<Compile Include="Events\Handlers\MapGeneration\MapGenerationEventHandler.cs" />
<Compile Include="Events\Internal\Ragdoll.cs" />
<Compile Include="Events\Patches\Achievements\ServerAchievePatch.cs" />
<Compile Include="Features\Enums\AuthenticationType.cs" />
<Compile Include="Features\Enums\DoorType.cs" />
Expand Down Expand Up @@ -132,7 +133,7 @@
<Compile Include="Features\Wrappers\Player\CursedPlayerHitBox.cs" />
<Compile Include="Features\Wrappers\Player\Dummies\CursedDummy.cs" />
<Compile Include="Features\Wrappers\Player\Dummies\FakeConnection.cs" />
<Compile Include="Features\Wrappers\Player\RagDolls\CursedRagDoll.cs" />
<Compile Include="Features\Wrappers\Player\Ragdolls\CursedRagdoll.cs" />
<Compile Include="Features\Wrappers\Player\Roles\CursedRoleManager.cs" />
<Compile Include="Features\Wrappers\Player\VoiceChat\CursedVoiceChat.cs" />
<Compile Include="Features\Wrappers\Round\CursedRound.cs" />
Expand Down
5 changes: 4 additions & 1 deletion CursedMod/EntryPoint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CursedMod.Loader;
using CursedMod.Events;
using CursedMod.Loader;
using CursedMod.Loader.Configurations;
using PluginAPI.Core;
using PluginAPI.Core.Attributes;
Expand All @@ -15,6 +16,8 @@ private void Init()

Log.Info("CursedMod is being loaded");

EventManager.SubscribeEvents();

// Patch Events
// Load Plugins
}
Expand Down
8 changes: 8 additions & 0 deletions CursedMod/Events/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using CursedMod.Events.Internal;
using HarmonyLib;
using NorthwoodLib.Pools;
using PlayerRoles.Ragdolls;
using PluginAPI.Core;

namespace CursedMod.Events;
Expand Down Expand Up @@ -68,4 +70,10 @@ public static List<CodeInstruction> CheckEvent<T>(int originalCodes, IEnumerable
Log.Warning(typeof(T).FullDescription() + " has an incorrect number of OpCodes. The patch may be broken or bugged.");
return newInstructions;
}

internal static void SubscribeEvents()
{
RagdollManager.OnRagdollSpawned += Ragdoll.OnSpawnedRagdoll;
RagdollManager.OnRagdollRemoved += Ragdoll.OnRagdollRemoved;
}
}
10 changes: 10 additions & 0 deletions CursedMod/Events/Internal/Ragdoll.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using CursedMod.Features.Wrappers.Player.Ragdolls;

namespace CursedMod.Events.Internal;

public static class Ragdoll
{
public static void OnSpawnedRagdoll(BasicRagdoll basicRagdoll) => CursedRagdoll.Ragdolls.Add(new CursedRagdoll(basicRagdoll));

public static void OnRagdollRemoved(BasicRagdoll basicRagdoll) => CursedRagdoll.Ragdolls.Remove(CursedRagdoll.Get(basicRagdoll));
}
35 changes: 0 additions & 35 deletions CursedMod/Features/Wrappers/Player/RagDolls/CursedRagDoll.cs

This file was deleted.

44 changes: 44 additions & 0 deletions CursedMod/Features/Wrappers/Player/Ragdolls/CursedRagdoll.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections.Generic;
using System.Linq;
using Mirror;
using PlayerRoles;
using UnityEngine;

namespace CursedMod.Features.Wrappers.Player.Ragdolls;

public class CursedRagdoll
{
internal static List<CursedRagdoll> Ragdolls { get; } = new List<CursedRagdoll>();
public static IReadOnlyCollection<CursedRagdoll> List => Ragdolls.AsReadOnly();

public BasicRagdoll Base { get; }

internal CursedRagdoll(BasicRagdoll ragdoll)
{
Base = ragdoll;
}

public bool AutoCleanUp
{
get => !Base._cleanedUp;
set => Base._cleanedUp = !value;
}

public RoleTypeId Role => Base.Info.RoleType;

public CursedPlayer Owner => CursedPlayer.Get(Base.Info.OwnerHub);

public string Nickname => Base.NetworkInfo.Nickname;

public Vector3 Position => Base.gameObject.transform.position;

public RagdollData Data => Base.Info;

public void CleanUp() => Base.OnCleanup();

public void Destroy() => NetworkServer.Destroy(Base.gameObject);

public static CursedRagdoll Get(BasicRagdoll basicRagdoll) => List.FirstOrDefault(ragdoll => ragdoll.Base == basicRagdoll);

public static IEnumerable<CursedRagdoll> Get(CursedPlayer player) => List.Where(ragdoll => ragdoll.Owner == player);
}