抽离技能回复处理器并调整牌堆展示与相关测试#37
Conversation
📝 WalkthroughWalkthrough新增技能回复消息处理器并接入分派,扩展牌堆明牌定位与同区移动归一化逻辑,补充协议文档、测试及少量界面和调试输出调整。 Changes技能回复分派与处理
牌堆端点明牌与定位
界面与调试输出
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client as CGsRoleSpellOptRep
participant Logic as logic
participant Handler as handleRoleSpellOptRep
participant Game as Game
participant Tracker as tracker
Client->>Logic: dispatch skill response
Logic->>Handler: handleRoleSpellOptRep(msg)
Handler->>Game: update spell state or first hand
Handler->>Tracker: reveal cards in protocol zone
sequenceDiagram
participant Target as GsCRoleOptTargetNtf
participant Reveal as revealTrackerCardsInZone
participant Controller as TrackerController
participant Pile as pile
Target->>Reveal: provide Params and pile endpoint
Reveal->>Controller: set reposition and cardIDsTopFirst
Controller->>Pile: place known cards at top
Controller->>Pile: skip duplicate placement
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/tracker/runtime/trackerController.ts (1)
90-113: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value优化底部端点的比对性能。
在进行
POSITION_BOTTOM比对时,可以通过下标直接在原数组上倒序映射,避免使用[...cards].reverse()带来的额外数组分配与就地反转开销。♻️ 建议的代码重构
function hasCardsAtPublicPosition( zoneCards: Card[], cards: Card[], position: PublicPosition ): boolean { if (cards.length === 0 || zoneCards.length < cards.length) return false if (position === POSITION_TOP) { const offset = zoneCards.length - cards.length return cards.every((card, index) => zoneCards[offset + index] === card) } if (position === POSITION_BOTTOM) { - const expectedCards = [...cards].reverse() - return expectedCards.every((card, index) => zoneCards[index] === card) + const len = cards.length + return cards.every((_, index) => zoneCards[index] === cards[len - 1 - index]) } return false }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/tracker/runtime/trackerController.ts` around lines 90 - 113, 优化 hasCardsAtPublicPosition 中 POSITION_BOTTOM 分支的比较逻辑,直接按下标将 cards 倒序映射到 zoneCards,移除 [...cards].reverse() 产生的临时数组,同时保持现有底部端点匹配结果不变。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/protocols/CGsRoleSpellOptRep.md`:
- Line 47: 更新文档中的“牌堆明牌同步”入口引用,将 trackerController.ts 的 revealTrackerCards
替换为鹰视处理器实际调用的 revealTrackerCardsInZone,避免指向下层实现。
In `@src/handler/CGsRoleSpellOptRep.js`:
- Around line 23-34: 在 Type 72 的处理分支中增加 SpellID === 0 的限制,仅当该消息的 SpellID 为 0
时才执行 getSpellState(3731)、合并 Datas 并调用 setSpellState;其他 Type 72 消息应跳过状态更新。
---
Nitpick comments:
In `@src/tracker/runtime/trackerController.ts`:
- Around line 90-113: 优化 hasCardsAtPublicPosition 中 POSITION_BOTTOM
分支的比较逻辑,直接按下标将 cards 倒序映射到 zoneCards,移除 [...cards].reverse()
产生的临时数组,同时保持现有底部端点匹配结果不变。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d922fc3e-f7e2-4bc4-b707-d7ee455b5214
📒 Files selected for processing (16)
docs/protocols/CGsRoleSpellOptRep.mddocs/protocols/GsCRoleOptTargetNtf-7011.mdhtml/iframe.htmlsrc/handler/CGsRoleSpellOptRep.jssrc/handler/GsCRoleOptTargetNtf.jssrc/handler/PubGsCMoveCard.jssrc/handler/index.jssrc/index.jssrc/logic.jssrc/tracker/gameState.tssrc/tracker/runtime/trackerController.tssrc/tracker/view/cardButton.tstests/tracker/pubGsCMoveCard.test.tstests/tracker/roleOptTargetNtf.test.tstests/tracker/roleSpellOptRep.test.tstests/tracker/trackerController.test.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/tracker/runtime/trackerController.ts (1)
668-676: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win显式与隐式端点处理存在逻辑冲突,导致牌堆落点不一致。
目前的翻转逻辑仅在
hasExplicitPosition为true时执行,这会造成隐式的“牌顶”和显式的“牌顶”最终落点相反:
- 当未携带
pos时(隐式),position默认为POSITION_TOP,跳过翻转,最终落点为POSITION_TOP。- 当显式传入
POSITION_TOP时,触发翻转,最终落点变为POSITION_BOTTOM。由于外层 Handler(如
CGsRoleSpellOptRep.js)通常已经负责将协议值映射为正确的内部常量(例如传入POSITION_BOTTOM),在此处再次对内部常量进行翻转不仅会破坏 Handler 的映射,还会导致显式与隐式语义割裂。建议移除此处的方向交换逻辑,由调用方(Handler)统一保证传入正确的内部常量。🐛 修复建议
const hasExplicitPosition = protocolZone.pos !== undefined && protocolZone.pos !== null // 未携带 pos 的看牌消息默认表示牌顶;只有协议显式端点才需要做方向翻转。 let position = hasExplicitPosition ? protocolZone.pos : POSITION_TOP - // 协议牌堆端点和 Zone.add/remove 的内部端点约定相反,进入记牌器前先交换方向。 - if (normalizedZone === 1 && hasExplicitPosition) { - if (position === POSITION_BOTTOM) position = POSITION_TOP - else if (position === POSITION_TOP) position = POSITION_BOTTOM - } return {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/tracker/runtime/trackerController.ts` around lines 668 - 676, Remove the direction-swapping block from the position handling around hasExplicitPosition in the tracker controller. Preserve the default POSITION_TOP for messages without pos and use protocolZone.pos directly for explicit values, relying on the upstream handlers to provide the correct internal endpoint constant.
🧹 Nitpick comments (1)
src/logic.js (1)
436-455: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value清理不再使用的注释代码。
保留大段被注释的废弃代码会降低代码的可读性和维护性。既然这部分功能“目前不适配”且已经被停用,建议直接将其删除,依赖版本控制系统来追溯历史代码。
♻️ 建议的修改
- // 权变花色 目前不适配 - // if ( - // Game.currentID == SeatID && - // Game.getSeatUI(Game.currentID)?.seat?.HasSkill(7011) && - // msg.useType == 1 && - // msg.fromZone != 1 && - // !msg.isSend - // ) { - // if (!Game.spellSpace[7011]) Game.spellSpace[7011] = { count: 0, color: new Set() } - - // if (CardConfig.GetInstance().getCard(msg.CardID).type != 3) Game.spellSpace[7011].count++ - - // Game.spellSpace[7011].color.add(CardConfig.GetInstance().getCardColor(msg.CardID)) - - // setSuitRecord( - // Array.from(Game.spellSpace[7011].color).join(''), - // '[' + Game.spellSpace[7011].count + ']' - // ) - // }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/logic.js` around lines 436 - 455, Remove the entire commented-out “权变花色” block near setSuitRecord, including its disabled condition and spellSpace update logic; retain surrounding active logic unchanged and rely on version control for the obsolete implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/tracker/runtime/trackerController.ts`:
- Around line 668-676: Remove the direction-swapping block from the position
handling around hasExplicitPosition in the tracker controller. Preserve the
default POSITION_TOP for messages without pos and use protocolZone.pos directly
for explicit values, relying on the upstream handlers to provide the correct
internal endpoint constant.
---
Nitpick comments:
In `@src/logic.js`:
- Around line 436-455: Remove the entire commented-out “权变花色” block near
setSuitRecord, including its disabled condition and spellSpace update logic;
retain surrounding active logic unchanged and rely on version control for the
obsolete implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a25a2813-0428-4b5b-84de-efa9eaa2ffd7
📒 Files selected for processing (5)
docs/protocols/CGsRoleSpellOptRep.mdsrc/handler/PubGsCMoveCard.jssrc/index.jssrc/logic.jssrc/tracker/runtime/trackerController.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/index.js
- src/handler/PubGsCMoveCard.js
- docs/protocols/CGsRoleSpellOptRep.md
Summary by CodeRabbit
新功能
界面优化
文档
测试