Skip to content

update(servertool):可以修改npc生成速度,作用于单个玩家附近。#1114

Merged
Controllerdestiny merged 4 commits intomasterfrom
tool
Mar 18, 2026
Merged

update(servertool):可以修改npc生成速度,作用于单个玩家附近。#1114
Controllerdestiny merged 4 commits intomasterfrom
tool

Conversation

@Controllerdestiny
Copy link
Contributor

@Controllerdestiny Controllerdestiny commented Mar 17, 2026

添加插件

  • 插件已加入解决方案 (Plugin.sln)
  • 插件项目已导入template.targets ()
  • 插件信息已添加至对应manifest.json
  • 插件的文件夹名字和插件的插件项目名字一样 (XXX/XXX.csproj)
  • 添加插件单独的README.md文件 (XXX/README.md)
  • 插件可以正常工作

更新插件/修复BUG

  • 插件已修改版本号
  • 更新插件README.md中的更新日志
  • 插件可以正常工作

其他

  • ❤️熙恩我喜欢你

Summary by Sourcery

添加按玩家配置的 NPC 刷新率控制,并更新插件元数据和消息。

新增功能:

  • 引入按玩家配置的 NPC 刷新率,当启用时可覆盖 Terraria 默认的刷新率和最大刷新增量。
  • 添加 /spawnrate 指令组(on/off/rate/max/help),并配套相应权限,用于在游戏内管理玩家的 NPC 刷新行为。

改进项:

  • 通过现有的 GetString 辅助方法对“已修改客户端”警告消息进行本地化。
  • 将 ServerTools 插件版本提升至 1.3.0.1,并在初始化时注册 NPC 刷新率钩子。
  • 在 README 中记录新的 /spawnrate 指令,并添加相应的更新日志条目。
Original summary in English

Summary by Sourcery

Add per-player NPC spawn rate controls and update plugin metadata and messaging.

New Features:

  • Introduce per-player NPC spawn rate configuration that overrides Terraria's default spawn rate and max spawns when enabled.
  • Add /spawnrate command set (on/off/rate/max/help) with appropriate permissions to manage a player's NPC spawn behavior in-game.

Enhancements:

  • Localize the modified-client warning message via the existing GetString helper.
  • Bump ServerTools plugin version to 1.3.0.1 and register the NPC spawn rate hook on initialization.
  • Document the new /spawnrate commands and add a corresponding changelog entry in the README.

@Controllerdestiny Controllerdestiny requested a review from a team as a code owner March 17, 2026 18:16
Copy link
Contributor

@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.

Hey - 我发现了 1 个问题,并留下了一些整体性的反馈:

  • 建议在 PlayerSpawnRates 中使用稳定的标识符(例如玩家索引或账号 ID)作为键,而不是使用 Terraria.Player 实例,以避免在 Player 对象被重用或其身份语义发生变化时可能出现的问题。
  • 当玩家断线时,最好清理或移除 PlayerSpawnRates 中对应的条目,以防止在长时间运行的服务器上字典无限增长。
  • 由于你在 Initialize 中订阅了 On.Terraria.NPC.Spawner.GetSpawnRate,请确保在插件卸载/释放时从这个钩子中取消订阅,以避免在插件被禁用或重新加载后仍然存在残留的事件处理程序。
给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- Consider using a stable identifier (e.g., player index or account ID) instead of `Terraria.Player` instances as the key for `PlayerSpawnRates` to avoid potential issues if `Player` objects are reused or their identity semantics change.
- It would be safer to clear or remove entries from `PlayerSpawnRates` when players disconnect to prevent the dictionary from growing indefinitely over a long-running server.
- Since you subscribe to `On.Terraria.NPC.Spawner.GetSpawnRate` in `Initialize`, ensure you unsubscribe from this hook during plugin unload/disposal to avoid lingering event handlers after the plugin is disabled or reloaded.

## Individual Comments

### Comment 1
<location path="src/ServerTools/Command/NPCSpawnRate.cs" line_range="57-61" />
<code_context>
+        args.Player.SendInfoMessage(GetString("/spawnrate on 启用生成率修改"));
+        args.Player.SendInfoMessage(GetString("/spawnrate off 关闭生成率修改"));
+        args.Player.SendInfoMessage(GetString("/spawnrate rate [生成率] 设置怪物生成速率(越小越快)"));
+        args.Player.SendInfoMessage(GetString("/spawnrate max [数量] 设置每次生成最大可生成数量)"));
+    }
+
</code_context>
<issue_to_address>
**nitpick (typo):** There appears to be an extra closing parenthesis in the help text.

The Chinese help text for the last line ends with a full-width `` that has no matching opening parenthesis, which will look like a typo to players. Please either remove the trailing `` or add the corresponding opening parenthesis.

```suggestion
        args.Player.SendInfoMessage(GetString("/spawnrate on 启用生成率修改"));
        args.Player.SendInfoMessage(GetString("/spawnrate off 关闭生成率修改"));
        args.Player.SendInfoMessage(GetString("/spawnrate rate [生成率] 设置怪物生成速率(越小越快)"));
        args.Player.SendInfoMessage(GetString("/spawnrate max [数量] 设置每次生成最大可生成数量"));
    }
```
</issue_to_address>

Sourcery 对开源项目免费——如果你觉得我们的代码审查有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • Consider using a stable identifier (e.g., player index or account ID) instead of Terraria.Player instances as the key for PlayerSpawnRates to avoid potential issues if Player objects are reused or their identity semantics change.
  • It would be safer to clear or remove entries from PlayerSpawnRates when players disconnect to prevent the dictionary from growing indefinitely over a long-running server.
  • Since you subscribe to On.Terraria.NPC.Spawner.GetSpawnRate in Initialize, ensure you unsubscribe from this hook during plugin unload/disposal to avoid lingering event handlers after the plugin is disabled or reloaded.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider using a stable identifier (e.g., player index or account ID) instead of `Terraria.Player` instances as the key for `PlayerSpawnRates` to avoid potential issues if `Player` objects are reused or their identity semantics change.
- It would be safer to clear or remove entries from `PlayerSpawnRates` when players disconnect to prevent the dictionary from growing indefinitely over a long-running server.
- Since you subscribe to `On.Terraria.NPC.Spawner.GetSpawnRate` in `Initialize`, ensure you unsubscribe from this hook during plugin unload/disposal to avoid lingering event handlers after the plugin is disabled or reloaded.

## Individual Comments

### Comment 1
<location path="src/ServerTools/Command/NPCSpawnRate.cs" line_range="57-61" />
<code_context>
+        args.Player.SendInfoMessage(GetString("/spawnrate on 启用生成率修改"));
+        args.Player.SendInfoMessage(GetString("/spawnrate off 关闭生成率修改"));
+        args.Player.SendInfoMessage(GetString("/spawnrate rate [生成率] 设置怪物生成速率(越小越快)"));
+        args.Player.SendInfoMessage(GetString("/spawnrate max [数量] 设置每次生成最大可生成数量)"));
+    }
+
</code_context>
<issue_to_address>
**nitpick (typo):** There appears to be an extra closing parenthesis in the help text.

The Chinese help text for the last line ends with a full-width `` that has no matching opening parenthesis, which will look like a typo to players. Please either remove the trailing `` or add the corresponding opening parenthesis.

```suggestion
        args.Player.SendInfoMessage(GetString("/spawnrate on 启用生成率修改"));
        args.Player.SendInfoMessage(GetString("/spawnrate off 关闭生成率修改"));
        args.Player.SendInfoMessage(GetString("/spawnrate rate [生成率] 设置怪物生成速率(越小越快)"));
        args.Player.SendInfoMessage(GetString("/spawnrate max [数量] 设置每次生成最大可生成数量"));
    }
```
</issue_to_address>

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.

@ACaiCat
Copy link
Member

ACaiCat commented Mar 18, 2026

解决了服务器因为刷怪产尸潮的问题

Copy link
Member

@ACaiCat ACaiCat left a comment

Choose a reason for hiding this comment

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

我觉得可能得加个配置限制一下?

@Controllerdestiny
Copy link
Contributor Author

我觉得可能得加个配置限制一下?

感觉在这种插件里加有点奇怪

@ACaiCat
Copy link
Member

ACaiCat commented Mar 18, 2026

我觉得可能得加个配置限制一下?

感觉在这种插件里加有点奇怪

有个小问题,就是spawnrate这个命令是不是和ts的冲

@Controllerdestiny
Copy link
Contributor Author

我觉得可能得加个配置限制一下?

感觉在这种插件里加有点奇怪

有个小问题,就是spawnrate这个命令是不是和ts的冲

@Controllerdestiny Controllerdestiny added this pull request to the merge queue Mar 18, 2026
Merged via the queue into master with commit 48b3f80 Mar 18, 2026
3 checks passed
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