Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use external camera #419

Open
wants to merge 234 commits into
base: main
Choose a base branch
from
Open

use external camera #419

wants to merge 234 commits into from

Conversation

xAstroBoy
Copy link
Contributor

@xAstroBoy xAstroBoy commented Feb 23, 2024

Fix Enemies Nodes not updating
Fix spider mesh not following the current position & rotation
when not controlling, the spider will use that last position and claim it as it's nest.
add LcHaxCamera and make all mods use that one on phantom mode.
add isDead()

add OnOutsideStatusChange to reset all enemies's NavMesh's searches to not be broken when AI Nodes update.

@winstxnhdw all done.

Summary by CodeRabbit

  • New Features

    • Added movement permission control and sprinting logic for characters.
    • Introduced dynamic camera positioning to enhance gameplay experience.
    • New classes for controlling characters "Bracken," "Jester," "Manticoil," and "Snare Flea" with unique abilities and camera interactions.
    • Implemented a custom camera setup with advanced controls and settings.
    • Enhanced possession mechanics with updated conditions and event handling.
    • Added phantom mode with enable/disable functionality and improved integration with the game's camera system.
    • Introduced new enemy handling methods for improved interaction.
  • Refactor

    • Improved code readability and maintainability in character movement and camera management.
  • Bug Fixes

    • Adjusted camera offset calculations and skill use conditions for a smoother gameplay experience.
  • Chores

    • Updated internal access modifiers and method adjustments for better code organization.

lc-hax/Scripts/Helpers/Players.cs Outdated Show resolved Hide resolved
@xAstroBoy
Copy link
Contributor Author

@winstxnhdw looks solid to me, i have been testing these past 3 hours and got this custom camera to work and preserve hud and the rest, enemies work properly when they go outside, and best of all spider now follows the controller .

@xAstroBoy
Copy link
Contributor Author

xAstroBoy commented Feb 23, 2024

@winstxnhdw with the jester i had to add a new Event , OnPlayerCollision , because for some weird reason the jester wouldn't kill a player if outside, so i fixed that.

EDIT : i checked the other enemies that are inside and replicated their collision system without a check to make sure they work

@winstxnhdw
Copy link
Owner

winstxnhdw commented Mar 17, 2024

There's still too many things I want to change. I don't like how DisablePhantom is exposed. Phantom should turn off on it's own and not couple with the camera. I'll continue again next week or the week after that.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b39c60e and eb7c0f4.
Files selected for processing (2)
  • lc-hax/Scripts/Core/HaxCamera.cs (1 hunks)
  • lc-hax/Scripts/Modules/PhantomMod.cs (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • lc-hax/Scripts/Core/HaxCamera.cs
  • lc-hax/Scripts/Modules/PhantomMod.cs

@xAstroBoy
Copy link
Contributor Author

@winstxnhdw just to let you know, im done collabing to your repo trying to follow your strict requirements.

@winstxnhdw
Copy link
Owner

@winstxnhdw just to let you know, im done collabing to your repo trying to follow your strict requirements.

you never really ever did follow any. cheers.

@xAstroBoy
Copy link
Contributor Author

xAstroBoy commented Apr 28, 2024

@winstxnhdw just to let you know, im done collabing to your repo trying to follow your strict requirements.

you never really ever did follow any. cheers.

the issue is that you dont know how to accept diverse code styles, i understand readability , but how you do it is too much

@winstxnhdw
Copy link
Owner

I won't argue with you further on this. You probably won't find another maintainer that would bother to refactor your code. All I hope is that you won't keep this attitude at a real job. Also, https://blog.codacy.com/coding-standards

Have a nice week.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🧹 Outside diff range and nitpick comments (6)
lc-hax/Scripts/Modules/Possession/Controllers/CircuitBeesController.cs (3)

13-13: Consider simplifying the GetCameraOffset method

The GetCameraOffset method looks good, but it can be simplified. Since the RedLocustBees parameter is unused, you could remove it and use an expression-bodied member for conciseness.

Here's a suggested improvement:

-    public Vector3 GetCameraOffset(RedLocustBees _) => this.CameraOffset;
+    public Vector3 GetCameraOffset() => CameraOffset;

This change maintains the functionality while making the code more concise.


24-24: LGTM: OnOutsideStatusChange method added

The OnOutsideStatusChange method is a good addition for handling changes in the enemy's outside status. It appropriately stops the search for a hive when the status changes.

For improved readability, consider extracting the boolean parameter to a named constant:

-    public void OnOutsideStatusChange(RedLocustBees enemy) => enemy.StopSearch(enemy.searchForHive, true);
+    public void OnOutsideStatusChange(RedLocustBees enemy)
+    {
+        const bool stopImmediately = true;
+        enemy.StopSearch(enemy.searchForHive, stopImmediately);
+    }

This change makes the intent of the true parameter more clear.


Potential Issues Detected: Residual InteractRange References

The InteractRange method remains referenced in multiple files:

  • lc-hax/Scripts/Modules/Possession/PossessionMod.cs
  • lc-hax/Scripts/Modules/Possession/Controllers/IEnemyController.cs
  • lc-hax/Scripts/Modules/Possession/Controllers/ForestGiantController.cs
  • lc-hax/Scripts/Modules/Possession/Controllers/EarthLeviathanController.cs

Please review these references to ensure that the removal of InteractRange in CircuitBeesController.cs does not introduce inconsistencies or bugs elsewhere in the codebase.

🔗 Analysis chain

Line range hint 1-24: Overall changes look good, but clarification needed on InteractRange method

The additions to the CircuitBeesController class improve its functionality by adding camera offset handling and outside status change management. These changes align well with the PR objectives related to camera functionality and enemy behavior.

However, the AI summary mentioned the removal of the InteractRange method, which is not visible in the provided code. To ensure we're not missing any important changes, please run the following script to verify the removal of this method:

If the method has indeed been removed, please confirm if this change affects the enemy's interaction capabilities and if any adjustments are needed in other parts of the codebase.


Further Verification Required: InteractRange Method Removal

The initial verification did not locate the InteractRange method in CircuitBeesController.cs. To ensure complete removal and identify any remaining references across the codebase, please execute the following script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the removal of the InteractRange method

# Test: Search for the InteractRange method in the current and previous versions of the file
git show HEAD:lc-hax/Scripts/Modules/Possession/Controllers/CircuitBeesController.cs | grep -n "InteractRange"
git show HEAD^:lc-hax/Scripts/Modules/Possession/Controllers/CircuitBeesController.cs | grep -n "InteractRange"

Length of output: 224


Script:

#!/bin/bash
# Description: Search the entire codebase for any references to the InteractRange method

rg 'InteractRange' --type cs

Length of output: 1060

lc-hax/Scripts/Components/CharacterMovement.cs (3)

Line range hint 69-90: Potential logic issue in sprint toggling

In the Move method, when the sprint key is not pressed (lines 81-86), IsSprinting is toggled using this.IsSprinting = !this.IsSprinting;. This will cause IsSprinting to change state every time the sprint key is released, which might not be the intended behavior. Typically, when the sprint key is released, sprinting should stop.

Consider updating the logic to explicitly set IsSprinting to false when the sprint key is not pressed.

Apply this diff to fix the issue:

else {
    this.IsSprintHeld = false;
-   this.IsSprinting = !this.IsSprinting;
+   this.IsSprinting = false;
}

98-100: Clarify the naming of CharacterSprintSpeed

In line 99, CharacterSprintSpeed is used as a multiplier to CharacterSpeed when sprinting:

float sprintModifier = this.IsSprinting ? this.CharacterSpeed * this.CharacterSprintSpeed : this.CharacterSpeed;

Since it's acting as a multiplier rather than an absolute speed, consider renaming CharacterSprintSpeed to CharacterSprintMultiplier for clarity.


23-24: Initialize Keyboard in Awake to avoid potential issues

Initializing the Keyboard property directly with Keyboard.current might lead to issues if the input system is not yet initialized when the class is constructed. To ensure the keyboard is initialized properly, consider setting it in the Awake method.

Apply this diff to adjust the initialization:

-Keyboard Keyboard { get; } = Keyboard.current;
+Keyboard Keyboard { get; set; }

void Awake() {
+    this.Keyboard = Keyboard.current;
     this.NoClipKeyboard = this.gameObject.AddComponent<KeyboardMovement>();
     this.CharacterController = this.gameObject.AddComponent<CharacterController>();
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between eb7c0f4 and 31e830b.

📒 Files selected for processing (5)
  • lc-hax/Scripts/Components/CharacterMovement.cs (3 hunks)
  • lc-hax/Scripts/Loader.cs (1 hunks)
  • lc-hax/Scripts/Mixins/IEnemyPrompter.cs (7 hunks)
  • lc-hax/Scripts/Modules/Possession/Controllers/CircuitBeesController.cs (2 hunks)
  • lc-hax/Scripts/Modules/Possession/PossessionMod.cs (1 hunks)
🔇 Additional comments (3)
lc-hax/Scripts/Modules/Possession/Controllers/CircuitBeesController.cs (1)

11-11: LGTM: Camera offset property added

The CameraOffset property is a good addition for defining the camera position relative to the controlled enemy. The read-only nature ensures that the offset cannot be modified externally, maintaining encapsulation.

lc-hax/Scripts/Loader.cs (1)

65-65: LGTM! Verify HaxCamera initialization and compatibility.

The addition of HaxCamera to the LoadHaxGameObjects method is consistent with the existing pattern and aligns with the PR objectives. This change should enable the new camera system for phantom mode as intended.

To ensure proper integration, please verify:

  1. HaxCamera doesn't require any specific initialization beyond what AddHaxGameObject provides.
  2. HaxCamera is compatible with other loaded components, especially any existing camera systems.

You can run the following script to check for any potential conflicts or dependencies:

lc-hax/Scripts/Components/CharacterMovement.cs (1)

8-9: Review the SprintDuration value

The SprintDuration is set to 0.0f, which means sprinting will activate immediately upon pressing the sprint key without any delay. If this is intentional, then it's acceptable. However, if you intended to have a delay before sprinting starts, consider setting SprintDuration to a positive value.

Comment on lines +107 to +110
void Update() {
if (this.NoClipKeyboard is { enabled: true }) return;
if (this.CharacterController is { enabled: false }) return;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Prevent potential null reference exceptions

In the Update method, you check if NoClipKeyboard is enabled or if CharacterController is disabled. However, if CharacterController is null, accessing CharacterController.enabled could throw a null reference exception.

Consider adding a null check for CharacterController before accessing its enabled property:

if (this.NoClipKeyboard is { enabled: true }) return;
-if (this.CharacterController is { enabled: false }) return;
+if (this.CharacterController == null || !this.CharacterController.enabled) return;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void Update() {
if (this.NoClipKeyboard is { enabled: true }) return;
if (this.CharacterController is { enabled: false }) return;
void Update() {
if (this.NoClipKeyboard is { enabled: true }) return;
if (this.CharacterController == null || !this.CharacterController.enabled) return;

Comment on lines +98 to +103
float speedModifier = this.Keyboard.leftCtrlKey.isPressed ? CharacterMovement.WalkingSpeed : 1.0f;
float sprintModifier = this.IsSprinting ? this.CharacterSpeed * this.CharacterSprintSpeed : this.CharacterSpeed;

return sprintModifier * (
(this.transform.forward * moveInput.y) +
(this.transform.right * moveInput.x * speedModifier)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Apply speedModifier consistently to movement

Currently, speedModifier is applied only to the horizontal movement (line 103) but not to the forward/backward movement (line 102). This could lead to inconsistent movement speeds when moving diagonally, as holding the left control key will slow horizontal movement but not forward movement.

Consider applying speedModifier to both movement axes to ensure consistent speed adjustments.

Apply this diff to adjust the movement calculation:

return sprintModifier * (
-    (this.transform.forward * moveInput.y) +
-    (this.transform.right * moveInput.x * speedModifier)
+    (this.transform.forward * moveInput.y * speedModifier) +
+    (this.transform.right * moveInput.x * speedModifier)
);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
float speedModifier = this.Keyboard.leftCtrlKey.isPressed ? CharacterMovement.WalkingSpeed : 1.0f;
float sprintModifier = this.IsSprinting ? this.CharacterSpeed * this.CharacterSprintSpeed : this.CharacterSpeed;
return sprintModifier * (
(this.transform.forward * moveInput.y) +
(this.transform.right * moveInput.x * speedModifier)
float speedModifier = this.Keyboard.leftCtrlKey.isPressed ? CharacterMovement.WalkingSpeed : 1.0f;
float sprintModifier = this.IsSprinting ? this.CharacterSpeed * this.CharacterSprintSpeed : this.CharacterSpeed;
return sprintModifier * (
(this.transform.forward * moveInput.y * speedModifier) +
(this.transform.right * moveInput.x * speedModifier)
);

@@ -124,13 +131,16 @@ void HandleNutcracker(NutcrackerEnemyAI nutcracker, PlayerControllerB targetPlay

void HandleMaskedPlayer(MaskedPlayerEnemy maskedPlayer, PlayerControllerB targetPlayer, bool willTeleportEnemy) {
this.TeleportEnemyToPlayer(maskedPlayer, targetPlayer, willTeleportEnemy, true, true);
maskedPlayer.SetBehaviourState(BehaviourState.CHASE);
maskedPlayer.SwitchToBehaviourServerRpc(1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid magic numbers by using named constants or enums.

In the HandleMaskedPlayer method, the call to maskedPlayer.SwitchToBehaviourServerRpc(1); uses the hard-coded value 1. To enhance code clarity and maintainability, replace the magic number with a named constant or enum value.

Update the code as follows:

- maskedPlayer.SwitchToBehaviourServerRpc(1);
+ maskedPlayer.SwitchToBehaviourServerRpc(MaskedPlayerState.Chase);

Ensure that the MaskedPlayerState enum is defined and includes the Chase value.

Committable suggestion was skipped due to low confidence.


void HandleDocileLocustBees(DocileLocustBeesAI docileLocustBees, PlayerControllerB targetPlayer, bool willTeleportEnemy) {
this.TeleportEnemyToPlayer(docileLocustBees, targetPlayer, willTeleportEnemy, true);
docileLocustBees.SetBehaviourState(BehaviourState.IDLE);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Align behavior state with enemy-specific enums for clarity.

In the HandleDocileLocustBees method, you're setting the behavior state using BehaviourState.IDLE. To improve clarity and maintain consistency with other enemy handlers, consider using an enemy-specific enum, such as DocileLocustBeesState, if it exists.

Update the code if an enemy-specific enum is available:

- docileLocustBees.SetBehaviourState(BehaviourState.IDLE);
+ docileLocustBees.SetBehaviourState(DocileLocustBeesState.Idle);

This ensures that the behavior states are explicitly tied to their respective enemy types.

Committable suggestion was skipped due to low confidence.

Comment on lines +85 to +89
if (willTeleportEnemy) {
bunkerSpider.meshContainerPosition = targetPlayer.transform.position;
bunkerSpider.SyncMeshContainerPositionToClients();
}
bunkerSpider.SwitchToBehaviourServerRpc(2);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Replace magic numbers with meaningful constants or enums for clarity.

In the HandleBunkerSpider method, the call to bunkerSpider.SwitchToBehaviourServerRpc(2); uses a hard-coded value 2. Using magic numbers can make the code less readable and more challenging to maintain. Consider defining an enum or constant to represent the behavior state.

Apply this diff to improve readability:

- bunkerSpider.SwitchToBehaviourServerRpc(2);
+ bunkerSpider.SwitchToBehaviourServerRpc(BunkerSpiderState.Chase);

Ensure that the BunkerSpiderState enum is defined and includes the Chase value.

Committable suggestion was skipped due to low confidence.

this.TeleportEnemyToPlayer(dressGirl, targetPlayer, willTeleportEnemy, true);
dressGirl.hauntingPlayer = targetPlayer;
dressGirl.ChangeEnemyOwnerServerRpc(targetPlayer.playerClientId);
dressGirl.SetBehaviourState(BehaviourState.IDLE);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use specific enemy behavior states for consistency.

In the HandleDressGirl method, you're setting the behavior state using the general BehaviourState.IDLE. For consistency with other enemy handlers that use enemy-specific enums (e.g., GiantState.CHASE), consider using a DressGirlState enum if available.

If a DressGirlState enum exists, update the code:

- dressGirl.SetBehaviourState(BehaviourState.IDLE);
+ dressGirl.SetBehaviourState(DressGirlState.Idle);

This enhances readability and maintains consistency across enemy behavior management.

Committable suggestion was skipped due to low confidence.

Comment on lines +411 to +414
void UsePrimarySkill() {
if (this.Possession.Enemy is not EnemyAI enemy || this.Controller is null) return;
this.Controller.UsePrimarySkill(enemy);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor repeated null checks into a helper method

The method UsePrimarySkill and other similar methods repeat null checks for Possession.Enemy and Controller. To reduce code duplication and enhance maintainability, consider creating a helper method for these checks.

Apply this diff to UsePrimarySkill:

- void UsePrimarySkill() {
-     if (this.Possession.Enemy is not EnemyAI enemy || this.Controller is null) return;
-     this.Controller.UsePrimarySkill(enemy);
- }
+ void UsePrimarySkill() {
+     if (this.TryGetEnemyAndController(out var enemy, out var controller))
+         controller.UsePrimarySkill(enemy);
+ }

Add the helper method outside the selected line ranges:

private bool TryGetEnemyAndController(out EnemyAI enemy, out IController controller)
{
    enemy = null;
    controller = null;
    if (this.Possession.Enemy is not EnemyAI e || this.Controller is null)
    {
        return false;
    }
    enemy = e;
    controller = this.Controller;
    return true;
}

Update the other methods (UseSecondarySkill, OnSecondarySkillHold, ReleaseSecondarySkill, UseSpecialAbility) similarly to utilize the helper method.

if (this.Possession.Enemy is not EnemyAI enemy) return;
if (enemy.agent is not NavMeshAgent agent) return;

enemy.ChangeEnemyOwnerServerRpc(localPlayer.actualClientId);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Optimize ownership change to prevent unnecessary network traffic

Calling ChangeEnemyOwnerServerRpc every frame in the Update method can lead to unnecessary network usage and performance issues. Consider checking if the enemy's owner has changed before invoking this method.

Apply this diff to optimize the code:

- enemy.ChangeEnemyOwnerServerRpc(localPlayer.actualClientId);
+ if (enemy.OwnerClientId != localPlayer.actualClientId) {
+     enemy.ChangeEnemyOwnerServerRpc(localPlayer.actualClientId);
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
enemy.ChangeEnemyOwnerServerRpc(localPlayer.actualClientId);
if (enemy.OwnerClientId != localPlayer.actualClientId) {
enemy.ChangeEnemyOwnerServerRpc(localPlayer.actualClientId);
}

Comment on lines +386 to +389
Transform? GetExitPointFromDoor(EntranceTeleport entrance) =>
Helper.FindObjects<EntranceTeleport>().First(teleport =>
teleport.entranceId == entrance.entranceId && teleport.isEntranceToBuilding != entrance.isEntranceToBuilding
)?.entrancePoint;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Prevent potential InvalidOperationException by using FirstOrDefault

Using .First() may throw an InvalidOperationException if no matching teleport is found. Replace .First() with .FirstOrDefault() to safely return null when no exit point exists.

Apply this diff to fix the issue:

- Helper.FindObjects<EntranceTeleport>().First(teleport =>
+ Helper.FindObjects<EntranceTeleport>().FirstOrDefault(teleport =>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Transform? GetExitPointFromDoor(EntranceTeleport entrance) =>
Helper.FindObjects<EntranceTeleport>().First(teleport =>
teleport.entranceId == entrance.entranceId && teleport.isEntranceToBuilding != entrance.isEntranceToBuilding
)?.entrancePoint;
Transform? GetExitPointFromDoor(EntranceTeleport entrance) =>
Helper.FindObjects<EntranceTeleport>().FirstOrDefault(teleport =>
teleport.entranceId == entrance.entranceId && teleport.isEntranceToBuilding != entrance.isEntranceToBuilding
)?.entrancePoint;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants