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

修改了战斗临时buff存储方式到对象存储 #86

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

AnLanyoru
Copy link
Contributor

@AnLanyoru AnLanyoru commented Dec 16, 2024

原代码因为boss_zs boss_hx等等会在战斗的同时被声明全局,如果有玩家A进行boss战,此时boss_zs等buff会遗留在全局变量,而无论玩家战斗或是boss战斗的函数均调用全局boss_zs等参数,此时会导致buff遗留。

Summary by Sourcery

增强功能:

  • 通过将临时战斗增益封装到专用类 BossBuff 和 UserRandomBuff 中,重构其存储,以防止在并发战斗期间发生全局变量冲突。
Original summary in English

Summary by Sourcery

Enhancements:

  • Refactor the storage of temporary battle buffs by encapsulating them into dedicated classes, BossBuff and UserRandomBuff, to prevent global variable conflicts during concurrent battles.

Copy link

sourcery-ai bot commented Dec 16, 2024

审核者指南由 Sourcery 提供

此拉取请求通过引入基于类的存储而不是全局变量来重构战斗增益存储系统。主要更改涉及创建两个新类 - BossBuff 和 UserRandomBuff - 以封装之前存储在全局变量中的增益相关状态。

BossBuff 和 UserRandomBuff 的类图

classDiagram
    class BossBuff {
        +int boss_zs
        +int boss_hx
        +int boss_bs
        +int boss_xx
        +int boss_jg
        +int boss_jh
        +int boss_jb
        +int boss_xl
    }

    class UserRandomBuff {
        +int random_break
        +int random_xx
        +int random_hx
        +int random_def
    }
Loading

文件级更改

更改 详情 文件
为战斗增益引入基于类的存储
  • 创建 BossBuff 类以存储与 boss 相关的增益值
  • 创建 UserRandomBuff 类以存储用户随机增益值
  • 移除用于增益存储的全局变量
  • 添加 empty_boss_buff 和 empty_ussr_random_buff 作为默认实例
nonebot_plugin_xiuxian_2/xiuxian/xiuxian_utils/player_fight.py
更新战斗函数以使用新的增益类
  • 修改 get_turnatk() 以接受 BossBuff 和 UserRandomBuff 参数
  • 修改 get_turnatk_boss() 以接受 BossBuff 参数
  • 更新 after_atk_sub_buff_handle() 以使用新的增益类
  • 重构增益计算以使用类属性而不是全局变量
nonebot_plugin_xiuxian_2/xiuxian/xiuxian_utils/player_fight.py
代码清理和格式改进
  • 修复缩进和间距问题
  • 为增益类参数添加类型提示
  • 通过一致的格式提高代码可读性
  • 为增益相关代码添加描述性注释
nonebot_plugin_xiuxian_2/xiuxian/xiuxian_utils/player_fight.py

提示和命令

与 Sourcery 互动

  • 触发新审核: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审核评论。
  • 从审核评论生成 GitHub 问题: 通过回复审核评论请求 Sourcery 创建一个问题。
  • 生成拉取请求标题: 在拉取请求标题的任何地方写 @sourcery-ai 以随时生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任何地方写 @sourcery-ai summary 以随时生成 PR 摘要。您也可以使用此命令指定摘要应插入的位置。

自定义您的体验

访问您的仪表板以:

  • 启用或禁用审核功能,例如 Sourcery 生成的拉取请求摘要、审核者指南等。
  • 更改审核语言。
  • 添加、删除或编辑自定义审核说明。
  • 调整其他审核设置。

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This pull request refactors the battle buff storage system by introducing class-based storage instead of global variables. The main changes involve creating two new classes - BossBuff and UserRandomBuff - to encapsulate buff-related state that was previously stored in global variables.

Class diagram for BossBuff and UserRandomBuff

classDiagram
    class BossBuff {
        +int boss_zs
        +int boss_hx
        +int boss_bs
        +int boss_xx
        +int boss_jg
        +int boss_jh
        +int boss_jb
        +int boss_xl
    }

    class UserRandomBuff {
        +int random_break
        +int random_xx
        +int random_hx
        +int random_def
    }
Loading

File-Level Changes

Change Details Files
Introduced class-based storage for battle buffs
  • Created BossBuff class to store boss-related buff values
  • Created UserRandomBuff class to store user random buff values
  • Removed global variables for buff storage
  • Added empty_boss_buff and empty_ussr_random_buff as default instances
nonebot_plugin_xiuxian_2/xiuxian/xiuxian_utils/player_fight.py
Updated battle functions to use the new buff classes
  • Modified get_turnatk() to accept BossBuff and UserRandomBuff parameters
  • Modified get_turnatk_boss() to accept BossBuff parameter
  • Updated after_atk_sub_buff_handle() to use the new buff classes
  • Refactored buff calculations to use class attributes instead of global variables
nonebot_plugin_xiuxian_2/xiuxian/xiuxian_utils/player_fight.py
Code cleanup and formatting improvements
  • Fixed indentation and spacing issues
  • Added type hints for buff class parameters
  • Improved code readability with consistent formatting
  • Added descriptive comments for buff-related code
nonebot_plugin_xiuxian_2/xiuxian/xiuxian_utils/player_fight.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

@AnLanyoru - 我已经审查了你的更改 - 这里有一些反馈:

总体评论

  • 考虑在未来的 PR 中将数值魔法值(如增益百分比和阈值)提取为命名常量,以提高代码可读性
这是我在审查期间查看的内容
  • 🟢 一般问题:一切看起来都很好
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

Sourcery 对开源项目免费 - 如果你喜欢我们的评论,请考虑分享它们 ✨
帮助我变得更有用!请点击每条评论上的 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English

Hey @AnLanyoru - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider extracting numeric magic values (like buff percentages and thresholds) into named constants in a future PR to improve code readability
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Member

@PackageInstaller PackageInstaller left a comment

Choose a reason for hiding this comment

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

ok

@PackageInstaller PackageInstaller merged commit 2aede78 into MyXiaoNan:dev Dec 16, 2024
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.

2 participants