Skip to content

Commit

Permalink
Fix pathfinding issues & add hit reaction
Browse files Browse the repository at this point in the history
  • Loading branch information
zealsprince committed Apr 14, 2024
1 parent b3a8c92 commit 44ec14e
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 47 deletions.
Binary file modified AssetBundle/locker
Binary file not shown.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

# Changelog #

## 1.1.2 ##

- Add reaction to hit events
- Fix Locker pathfinding getting stuck
- Fix path calculation if off navmesh

## 1.1.1 ##

- Patch for v50
Expand Down
6 changes: 5 additions & 1 deletion Locker/Locker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
<Reference Include="UnityEngine">
<HintPath>E:\Lethal Company IDE\Lethal Company_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AIModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\Lethal Company IDE\Lethal Company_Data\Managed\UnityEngine.AIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AnimationModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\Lethal Company IDE\Lethal Company_Data\Managed\UnityEngine.AnimationModule.dll</HintPath>
Expand Down Expand Up @@ -117,7 +121,7 @@
<HintPath>E:\Lethal Company IDE\Lethal Company_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>E:\Lethal Company IDE\BepInEx\core\0Harmony.dll</HintPath>
</Reference>
Expand Down
87 changes: 46 additions & 41 deletions Locker/MonoBehaviours/LockerAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using GameNetcodeStuff;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem.HID;
using UnityEngine.VFX;

namespace Locker.MonoBehaviours
Expand Down Expand Up @@ -197,6 +199,20 @@ public override void DoAIInterval()
base.DoAIInterval();
}

public override void HitEnemy(
int force = 1,
PlayerControllerB playerWhoHit = null,
bool playHitSFX = false,
int hitID = -1
)
{
// Target players if they hit the enemy.
if (playerWhoHit != null)
{
TargetServerRpc(playerWhoHit.playerClientId, playerWhoHit.transform.position);
}
}

public override void Update()
{
base.Update();
Expand Down Expand Up @@ -531,12 +547,9 @@ public void FixedUpdate()
< 3f
)
{
if (IsServer)
{
DestroyDoorEffectsServerRpc();
Utilities.Explode(door.transform.position, 2, 4, 100, 0);

Destroy(door.transform.parent.gameObject);
}
Destroy(door.transform.parent.gameObject);
}
}
}
Expand All @@ -551,26 +564,29 @@ public void FixedUpdate()
// Store our movement for the next check.
lastChasePosition = transform.position;

if (
IsServer && Vector3.Distance(transform.position, targetPosition) <= 0.5f
|| chaseMovementAverage < chaseMovementAverageMinimum
)
if (IsServer)
{
if (chaseMovementAverage > chaseMovementAverageMinimum)
if (
Vector3.Distance(transform.position, targetPosition) <= 0.5f
|| chaseMovementAverage < chaseMovementAverageMinimum
)
{
// Possibly trigger another lunge at the closest visible player.
if (
Random.Range(0f, 100f)
< Config.LockerMechanicsReactivationChance.Value
)
if (chaseMovementAverage > chaseMovementAverageMinimum)
{
ReactivateServerRpc();
// Possibly trigger another lunge at the closest visible player.
if (
Random.Range(0f, 100f)
< Config.LockerMechanicsReactivationChance.Value
)
{
ReactivateServerRpc();

break;
break;
}
}
}

ResetServerRpc();
ResetServerRpc();
}
}

break;
Expand Down Expand Up @@ -752,7 +768,8 @@ public void SwitchState(LockerState state)

case LockerState.Chasing:
// Initiate moving to our destination.
SetDestinationToPosition(targetPosition, true);
if (IsServer && agent.isOnNavMesh)
SetDestinationToPosition(targetPosition, true);

// Set default chasing calculations.
lastChasePosition = transform.position;
Expand Down Expand Up @@ -1064,9 +1081,9 @@ public void TargetClientRpc(ulong clientId, Vector3 position)
else if (State == LockerState.Chasing || State == LockerState.Reactivating)
{
// Update the nav mesh destination if we're the host.
if (IsOwner)
if (IsServer && agent.isOnNavMesh)
{
SetDestinationToPosition(targetPosition);
SetDestinationToPosition(targetPosition, true);
}

// Make sure we go into another chase from the reactivation state.
Expand All @@ -1086,9 +1103,9 @@ public void ReactivateServerRpc()
targetPosition = transform.position;

// Update the nav mesh destination if we're the host.
if (IsServer)
if (IsServer && agent.isOnNavMesh)
{
SetDestinationToPosition(targetPosition);
SetDestinationToPosition(targetPosition, true);
}

ReactivateClientRpc();
Expand Down Expand Up @@ -1121,7 +1138,7 @@ public void ConsumeServerRpc(ulong clientid)
targetPosition = transform.position;

// Update the nav mesh destination if we're the host.
if (IsServer)
if (IsServer && agent.isOnNavMesh)
{
SetDestinationToPosition(targetPosition);
}
Expand All @@ -1141,12 +1158,12 @@ public void ConsumeClientRpc(ulong id)
[ServerRpc(RequireOwnership = false)]
public void ResetServerRpc()
{
// Stop movement.
targetPosition = transform.position;

// Update the nav mesh destination if we're the host.
if (IsServer)
if (IsServer && agent.isOnNavMesh)
{
// Stop movement.
targetPosition = transform.position;

SetDestinationToPosition(targetPosition);
}

Expand Down Expand Up @@ -1179,18 +1196,6 @@ public void ExplodeClientRpc()
Destroy(gameObject);
}

[ServerRpc(RequireOwnership = true)]
public void DestroyDoorEffectsServerRpc()
{
DestroyDoorEffectsClientRpc();
}

[ClientRpc]
public void DestroyDoorEffectsClientRpc()
{
Utilities.Explode(transform.position, 2, 4, 100, 0);
}

public IEnumerator KillPlayer(ulong id)
{
PlayerControllerB player = StartOfRound.Instance.allPlayerScripts[id];
Expand Down
2 changes: 1 addition & 1 deletion Locker/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Plugin : BaseUnityPlugin
{
public const string ModGUID = "com.zealsprince.locker";
public const string ModName = "Locker";
public const string ModVersion = "1.1.1";
public const string ModVersion = "1.1.2";

// These need to be lowercase because we're passing through the protected properties.
public static ManualLogSource logger;
Expand Down
4 changes: 2 additions & 2 deletions Locker/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.1.0")]
[assembly: AssemblyFileVersion("1.1.1.1")]
[assembly: AssemblyVersion("1.1.2.0")]
[assembly: AssemblyFileVersion("1.1.2.1")]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<img src="https://img.shields.io/badge/version-1.1.1-0AF" /></a>
<img src="https://img.shields.io/badge/version-1.1.2-0AF" /></a>
<img src="https://img.shields.io/badge/lc--version-v50-000" /></a>

![banner](https://github.com/zealsprince/lc-locker/assets/1859270/120046ff-144a-4e17-b5fb-f973d5fc3a0f)
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Locker",
"version_number": "1.1.1",
"version_number": "1.1.2",
"website_url": "https://github.com/zealsprince/lc-locker",
"description": "A new and unique enemy that acts as a situational threat, praying on player's perception",
"dependencies": [
Expand Down

0 comments on commit 44ec14e

Please sign in to comment.