update(servertool):可以修改npc生成速度,作用于单个玩家附近。#1114
Merged
Controllerdestiny merged 4 commits intomasterfrom Mar 18, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
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.Playerinstances as the key forPlayerSpawnRatesto avoid potential issues ifPlayerobjects are reused or their identity semantics change. - It would be safer to clear or remove entries from
PlayerSpawnRateswhen players disconnect to prevent the dictionary from growing indefinitely over a long-running server. - Since you subscribe to
On.Terraria.NPC.Spawner.GetSpawnRateinInitialize, 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
ACaiCat
approved these changes
Mar 18, 2026
Member
|
解决了服务器因为刷怪产尸潮的问题 |
Contributor
Author
感觉在这种插件里加有点奇怪 |
Member
有个小问题,就是spawnrate这个命令是不是和ts的冲 |
Contributor
Author
操 |
ACaiCat
approved these changes
Mar 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
添加插件
更新插件/修复BUG
其他
Summary by Sourcery
添加按玩家配置的 NPC 刷新率控制,并更新插件元数据和消息。
新增功能:
/spawnrate指令组(on/off/rate/max/help),并配套相应权限,用于在游戏内管理玩家的 NPC 刷新行为。改进项:
GetString辅助方法对“已修改客户端”警告消息进行本地化。1.3.0.1,并在初始化时注册 NPC 刷新率钩子。/spawnrate指令,并添加相应的更新日志条目。Original summary in English
Summary by Sourcery
Add per-player NPC spawn rate controls and update plugin metadata and messaging.
New Features:
Enhancements: