Skip to content

Commit

Permalink
v2.4.1 (SCP SL 14)
Browse files Browse the repository at this point in the history
  • Loading branch information
IkaOverride committed Dec 7, 2024
1 parent 6920705 commit 1f28546
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 44 deletions.
38 changes: 5 additions & 33 deletions ShootingInteractions/EventsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,14 @@ internal sealed class EventsHandler
/// </summary>
public static List<GameObject> BlacklistedObjects = new();

public void OnShooting(ShootingEventArgs args)
{
if (Config.AccurateBullets)
return;

// Check what's the player shooting at with a raycast, and return if the raycast doesn't hit something within 70 distance (maximum realistic distance)
if (!Physics.Raycast(args.Player.CameraTransform.position, args.Player.CameraTransform.forward, out RaycastHit raycastHit, 70f, ~(1 << 1 | 1 << 13 | 1 << 16 | 1 << 28)))
return;

// Interact and check the interaction with the player that's shooting, and the GameObject associated to the raycast
if (Interact(args.Player, raycastHit.transform.gameObject))
{
// Add the GameObject in the blacklist for a server tick
BlacklistedObjects.Add(raycastHit.transform.gameObject);
Timing.CallDelayed(0.02f, () => BlacklistedObjects.Remove(raycastHit.transform.gameObject));
}
}

/// <summary>
/// The shot event. Used for accurate shooting interaction.
/// </summary>
/// <param name="args">The <see cref="ShotEventArgs"/>.</param>
public void OnShot(ShotEventArgs args)
{
if (!Config.AccurateBullets)
return;

// Check what's the player shooting at with a raycast, and return if the raycast doesn't hit something within 70 distance (maximum realistic distance)
if (!Physics.Raycast(args.Player.CameraTransform.position, (args.RaycastHit.point - args.Player.CameraTransform.position).normalized, out RaycastHit raycastHit, 70f, ~(1 << 1 | 1 << 13 | 1 << 16 | 1 << 28)))
if (!Physics.Raycast(args.Player.CameraTransform.position, Config.AccurateBullets ? (args.RaycastHit.point - args.Player.CameraTransform.position).normalized : args.Player.CameraTransform.forward, out RaycastHit raycastHit, 70f, ~(1 << 1 | 1 << 13 | 1 << 16 | 1 << 28)))
return;

// Interact and check the interaction with the player that's shooting, and the GameObject associated to the raycast
Expand Down Expand Up @@ -162,7 +141,6 @@ public static bool Interact(Player player, GameObject gameObject)
if (!door.IsLocked && doorBreak && doorInteraction.MoveBeforeBreaking)
Timing.CallDelayed(cooldown, () =>
{

door.ChangeLock(DoorLockType.SpecialDoorFeature);

if (doorInteraction.ButtonsBreakTime > 0)
Expand Down Expand Up @@ -208,10 +186,10 @@ public static bool Interact(Player player, GameObject gameObject)
else if (gameObject.GetComponentInParent<ElevatorPanel>() is ElevatorPanel panel && Config.Elevators.IsEnabled)
{
// Get the elevator associated to the button
Lift elevator = Lift.Get(panel.AssignedChamber);
Lift elevator = Lift.Get(panel._assignedChamber);

// Return if there's no elevator associated to the button, it's moving, it's locked and the player doesn't have bypass mode enabled, or it can't get its doors
if (elevator is null || elevator.IsMoving || !elevator.IsOperative || (elevator.IsLocked && !player.IsBypassModeEnabled) || !ElevatorDoor.AllElevatorDoors.TryGetValue(panel.AssignedChamber.AssignedGroup, out List<ElevatorDoor> list))
if (elevator is null || elevator.IsMoving || !elevator.IsOperative || (elevator.IsLocked && !player.IsBypassModeEnabled) || !ElevatorDoor.AllElevatorDoors.TryGetValue(panel._assignedChamber.AssignedGroup, out List<ElevatorDoor> list))
return true;

// Should the buttons break ? (Generate a number from 1 to 100 then check if it's lesser than config percentage)
Expand All @@ -221,13 +199,10 @@ public static bool Interact(Player player, GameObject gameObject)
if (!elevator.IsLocked && elevatorBreak && !Config.Elevators.MoveBeforeBreaking)
{
foreach (ElevatorDoor door in list)
{
door.ServerChangeLock(DoorLockReason.SpecialDoorFeature, true);
elevator.Base.RefreshLocks(elevator.Group, door);
}

if (Config.Elevators.ButtonsBreakTime > 0)
Timing.CallDelayed(Config.Elevators.ButtonsBreakTime + elevator.MoveTime, () =>
Timing.CallDelayed(Config.Elevators.ButtonsBreakTime, () =>
{
foreach (ElevatorDoor door in list)
{
Expand All @@ -242,7 +217,7 @@ public static bool Interact(Player player, GameObject gameObject)
}

// Move the elevator to the next level
int nextLevel = panel.AssignedChamber.CurrentLevel + 1;
int nextLevel = panel._assignedChamber.DestinationLevel + 1;
if (nextLevel >= list.Count)
nextLevel = 0;

Expand All @@ -252,10 +227,7 @@ public static bool Interact(Player player, GameObject gameObject)
if (!elevator.IsLocked && elevatorBreak && Config.Elevators.MoveBeforeBreaking)
{
foreach (ElevatorDoor door in list)
{
door.ServerChangeLock(DoorLockReason.SpecialDoorFeature, true);
elevator.Base.RefreshLocks(elevator.Group, door);
}

if (Config.Elevators.ButtonsBreakTime > 0)
Timing.CallDelayed(Config.Elevators.ButtonsBreakTime + elevator.MoveTime, () =>
Expand Down
6 changes: 2 additions & 4 deletions ShootingInteractions/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class Plugin : Plugin<Config> {

public override string Author => "Ika";

public override Version RequiredExiledVersion => new(8, 8, 0);
public override Version RequiredExiledVersion => new(9, 0, 0);

public override Version Version => new(2, 4, 0);
public override Version Version => new(2, 4, 1);

public override PluginPriority Priority => PluginPriority.First;

Expand Down Expand Up @@ -57,12 +57,10 @@ public override void OnDisabled() {
public void RegisterEvents() {
eventsHandler = new EventsHandler();

PlayerEvent.Shooting += eventsHandler.OnShooting;
PlayerEvent.Shot += eventsHandler.OnShot;
}

public void UnregisterEvents() {
PlayerEvent.Shooting -= eventsHandler.OnShooting;
PlayerEvent.Shot -= eventsHandler.OnShot;

eventsHandler = null;
Expand Down
14 changes: 7 additions & 7 deletions ShootingInteractions/ShootingInteractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
<ItemGroup>
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Packages\SCP SL 13.5\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath>..\..\..\Packages\SCP SL 14\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Mirror, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Packages\SCP SL 13.5\Mirror.dll</HintPath>
<HintPath>..\..\..\Packages\SCP SL 14\Mirror.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -53,15 +53,15 @@
<Reference Include="System.Xml" />
<Reference Include="UnityEngine.AudioModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Packages\SCP SL 13.5\UnityEngine.AudioModule.dll</HintPath>
<HintPath>..\..\..\Packages\SCP SL 14\UnityEngine.AudioModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Packages\SCP SL 13.5\UnityEngine.CoreModule.dll</HintPath>
<HintPath>..\..\..\Packages\SCP SL 14\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Packages\SCP SL 13.5\UnityEngine.PhysicsModule.dll</HintPath>
<HintPath>..\..\..\Packages\SCP SL 14\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -77,8 +77,8 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="EXILEDOFFICIAL">
<Version>8.11.0</Version>
<PackageReference Include="ExMod.Exiled">
<Version>9.0.0-alpha.4</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down

0 comments on commit 1f28546

Please sign in to comment.