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

[Tweak] Melee / Ближнее Оружие #62

Merged
merged 2 commits into from
Sep 26, 2024
Merged

[Tweak] Melee / Ближнее Оружие #62

merged 2 commits into from
Sep 26, 2024

Conversation

Spatison
Copy link
Member

Описание PR

Переместил систему удара в спину на сервер. Добавил систему критического попадания для кровавого кинжала

@Spatison Spatison requested a review from Remuchi September 19, 2024 18:21
@Spatison Spatison self-assigned this Sep 19, 2024
Copy link
Contributor

coderabbitai bot commented Sep 19, 2024

Walkthrough

The pull request implements substantial modifications to the melee combat system in the codebase. Key changes include the reorganization of namespaces for the BackStabComponent and BackStabSystem to a server-specific context, the introduction of critical hit mechanics through new CritComponent and CritSystem classes, and updates to localization files for English and Russian languages. These alterations aim to refine the melee combat functionality and enhance user feedback via localized messages.

Changes

Files Change Summary
Content.Server/_White/Melee/BackStab/BackStabComponent.cs Changed namespace from Content.Shared._White.BackStab to Content.Server._White.Melee.BackStab.
Content.Server/_White/Melee/BackStab/BackStabSystem.cs Changed namespace from Content.Shared._White.BackStab to Content.Server._White.Melee.BackStab, removed INetManager dependency, updated popup message localization key from backstab-damage-betrayal-dagger to melee-backstab-damage.
Content.Server/_White/Melee/Crit/CritComponent.cs Added CritComponent class with properties: CritChance, CritMultiplier, and RealChance.
Content.Server/_White/Melee/Crit/CritSystem.cs Added CritSystem class that handles critical hit logic for melee attacks, subscribing to MeleeHitEvent and displaying damage messages.
Resources/Locale/en-US/_white/backstab/backstab.ftl Removed localization string backstab-damage-betrayal-dagger.
Resources/Locale/en-US/_white/melee/backstab.ftl Added localization string melee-backstab-damage for backstab damage messages.
Resources/Locale/en-US/_white/melee/crit.ftl Added localization string melee-crit-damage for critical hit damage messages.
Resources/Locale/ru-RU/_white/backstab/backstab.ftl Removed localization string for backstab damage in Russian.
Resources/Locale/ru-RU/_white/melee/backstab.ftl Added localization string melee-backstab-damage for backstab damage messages in Russian.
Resources/Locale/ru-RU/_white/melee/crit.ftl Added localization string melee-crit-damage for critical hit damage messages in Russian.

Possibly related PRs


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4272976 and dcfd816.

Files selected for processing (2)
  • Content.Server/_White/Melee/Crit/CritComponent.cs (1 hunks)
  • Content.Server/_White/Melee/Crit/CritSystem.cs (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • Content.Server/_White/Melee/Crit/CritComponent.cs
  • Content.Server/_White/Melee/Crit/CritSystem.cs

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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: 0

Outside diff range and nitpick comments (1)
Content.Server/_White/Melee/Crit/CritComponent.cs (1)

12-12: Clarify the purpose and usage of the RealChance property.

The RealChance property is a nullable float, but its intended purpose and usage are unclear from the code alone. Consider adding comments or documentation to explain how this property is meant to be utilized within the critical hit system.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6fb8e63 and 4272976.

Files selected for processing (10)
  • Content.Server/_White/Melee/BackStab/BackStabComponent.cs (1 hunks)
  • Content.Server/_White/Melee/BackStab/BackStabSystem.cs (2 hunks)
  • Content.Server/_White/Melee/Crit/CritComponent.cs (1 hunks)
  • Content.Server/_White/Melee/Crit/CritSystem.cs (1 hunks)
  • Resources/Locale/en-US/_white/backstab/backstab.ftl (0 hunks)
  • Resources/Locale/en-US/_white/melee/backstab.ftl (1 hunks)
  • Resources/Locale/en-US/_white/melee/crit.ftl (1 hunks)
  • Resources/Locale/ru-RU/_white/backstab/backstab.ftl (0 hunks)
  • Resources/Locale/ru-RU/_white/melee/backstab.ftl (1 hunks)
  • Resources/Locale/ru-RU/_white/melee/crit.ftl (1 hunks)
Files not reviewed due to no reviewable changes (2)
  • Resources/Locale/en-US/_white/backstab/backstab.ftl
  • Resources/Locale/ru-RU/_white/backstab/backstab.ftl
Files skipped from review due to trivial changes (4)
  • Content.Server/_White/Melee/BackStab/BackStabComponent.cs
  • Resources/Locale/en-US/_white/melee/backstab.ftl
  • Resources/Locale/ru-RU/_white/melee/backstab.ftl
  • Resources/Locale/ru-RU/_white/melee/crit.ftl
Additional comments not posted (10)
Resources/Locale/en-US/_white/melee/crit.ftl (1)

1-1: LGTM!

The localization string for critical hit damage is well-defined and follows the FTL (Fluent) format. The placeholder {$damage} is correctly used to dynamically insert the actual damage value. This addition enhances the user experience by providing clear feedback on critical hits.

Content.Server/_White/Melee/Crit/CritComponent.cs (1)

1-13: The CritComponent class implementation looks good!

The CritComponent class provides a solid foundation for managing critical hit mechanics within the melee combat system. The default values for CritChance and CritMultiplier seem balanced, but their impact on gameplay should be monitored and adjusted as needed.

Content.Server/_White/Melee/BackStab/BackStabSystem.cs (5)

1-8: LGTM!

The added using directives are consistent with the changes made to the BackStabSystem class.


9-9: Namespace change looks good!

Moving the BackStabSystem class to the Content.Server._White.Melee.BackStab namespace improves the organization of the codebase and reflects the server-specific nature of the class.


15-15: Dependency change is appropriate!

Changing the SharedPopupSystem dependency to PopupSystem aligns with the server-specific nature of the BackStabSystem class.


51-52: Localization key update is an improvement!

The new localization key, "melee-backstab-damage", is more descriptive and consistent with the context of the backstab damage message. This change improves the clarity and maintainability of the localization system.


Line range hint 1-54: Removing the INetManager dependency is a good decision!

The removal of the INetManager dependency aligns with the server-specific nature of the BackStabSystem class and improves the maintainability and performance of the codebase by eliminating unused dependencies.

Content.Server/_White/Melee/Crit/CritSystem.cs (3)

12-53: LGTM!

The CritSystem class is well-implemented and follows good coding practices. It has a clear single responsibility, well-defined dependencies, and a logical flow for handling critical hits in melee attacks.

The core logic for processing critical hits is properly encapsulated within the HandleHit method, which checks for hit entities, determines if the hit is critical, calculates the bonus damage, updates the event data, and displays a popup message to the user.

The IsCriticalHit method uses the IRobustRandom to generate random values and compare them with the critical hit chance defined in the CritComponent. It also manages the dynamic adjustment of the critical hit chance based on the outcome of the current hit.

The code is well-structured, readable, and follows consistent naming conventions. The use of dependency injection and event subscription aligns with best practices.

Overall, the implementation of the CritSystem class is solid and enhances the melee combat mechanics by introducing critical hits.


23-38: LGTM!

The HandleHit method is well-structured and handles the critical hit logic effectively. It follows a clear flow of checking the necessary conditions, calculating the bonus damage, updating the event data, and providing user feedback.

The method starts by checking if there are any hit entities and if the hit is critical using the IsCriticalHit method. This early return avoids unnecessary processing if the conditions are not met.

If the hit is critical, the method calculates the bonus damage by multiplying the base damage by the critical multiplier defined in the CritComponent. It then updates the BonusDamage property of the MeleeHitEvent with a new DamageSpecifier that represents the additional damage dealt by the critical hit. The usage of the "Slash" damage type prototype and the calculated bonus damage ensures consistent damage application.

Finally, the method displays a localized popup message to the user indicating the critical hit damage using the PopupSystem. The message is constructed using the Loc.GetString method with the appropriate localization key and the formatted damage value.

Overall, the HandleHit method is well-implemented and effectively handles the critical hit logic for melee attacks.


40-52: LGTM!

The IsCriticalHit method is well-implemented and provides a clean and concise way to determine if a hit is critical based on the chance defined in the CritComponent.

The method starts by checking if the RealChance property of the component is null and initializes it with the base CritChance value if necessary. This ensures that the RealChance property is always properly initialized before being used.

The method then generates a random float value using the IRobustRandom and compares it with the RealChance value. If the random value is less than or equal to the RealChance, the hit is considered critical. This logic effectively simulates the probability of a critical hit occurring based on the defined chance.

If the hit is critical, the method resets the RealChance to the base CritChance value defined in the component. This ensures that the critical hit chance is reset to its original value after a successful critical hit, maintaining consistency with the intended mechanics.

If the hit is not critical, the method increments the RealChance value. This dynamic adjustment of the critical hit chance for future hits adds an interesting gameplay element, increasing the likelihood of a critical hit occurring if the current hit is not critical. It provides a sense of escalating tension and rewards players for persistent attacks.

The method returns a boolean value indicating whether the hit is critical or not, making it easy to use and integrate with other parts of the codebase.

Overall, the IsCriticalHit method is well-structured, readable, and effectively determines the criticality of a hit based on the defined chance and dynamic adjustments.

Content.Server/_White/Melee/Crit/CritSystem.cs Outdated Show resolved Hide resolved
Content.Server/_White/Melee/Crit/CritSystem.cs Outdated Show resolved Hide resolved
Content.Server/_White/Melee/Crit/CritComponent.cs Outdated Show resolved Hide resolved
@Spatison Spatison requested a review from Remuchi September 23, 2024 04:51
@Remuchi Remuchi merged commit f3dd435 into master Sep 26, 2024
11 checks passed
@Remuchi Remuchi deleted the melee-tweaks branch September 26, 2024 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants