Skip to content

抽离技能回复处理器并调整牌堆展示与相关测试#37

Merged
llsccm merged 2 commits into
devfrom
feat/quanbian
Jul 18, 2026
Merged

抽离技能回复处理器并调整牌堆展示与相关测试#37
llsccm merged 2 commits into
devfrom
feat/quanbian

Conversation

@llsccm

@llsccm llsccm commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • 新功能

    • 支持更多技能操作回复及牌堆顶观看场景。
    • 优化公共牌堆牌面展示,可将已知牌定位至牌顶并避免重复调整。
    • 增强相关牌堆、手牌与技能状态的同步处理。
  • 界面优化

    • 缩小长中文牌面中的花色字形。
    • 暗牌数量超过一张时仅显示数量,提升显示简洁度。
  • 文档

    • 补充技能操作回复、牌堆顶观看及牌面排序规则说明。
  • 测试

    • 新增技能回复、牌堆展示、牌面移动与重复同步场景的测试覆盖。

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

新增技能回复消息处理器并接入分派,扩展牌堆明牌定位与同区移动归一化逻辑,补充协议文档、测试及少量界面和调试输出调整。

Changes

技能回复分派与处理

Layer / File(s) Summary
技能回复处理器与消息接入
src/handler/CGsRoleSpellOptRep.js, src/handler/index.js, src/logic.js, docs/protocols/CGsRoleSpellOptRep.md
新增 handleRoleSpellOptRep,按 TypeSpellID 更新 spell state、先手、武将和牌区展示,并由 logic 统一委托处理。
技能回复行为测试
tests/tracker/roleSpellOptRep.test.ts
覆盖 Type 44、Type 72、捷悟与鹰视牌区展示、非公开类型及底部方向逆序行为。

牌堆端点明牌与定位

Layer / File(s) Summary
牌堆明牌定位与重复同步
src/tracker/runtime/trackerController.ts, src/handler/GsCRoleOptTargetNtf.js, tests/tracker/roleOptTargetNtf.test.ts, tests/tracker/trackerController.test.ts, docs/protocols/CGsRoleOptTargetNtf-7011.md
增加端点重定位、牌序解释和默认牌顶位置处理;权变目标通知使用这些参数,重复明牌同步不再重复添加或重排。
权变同区移动归一化
src/handler/PubGsCMoveCard.js, tests/tracker/pubGsCMoveCard.test.ts
根据起止端点、区域、移动类型和 SpellID=7011 将同区展示的位置统一为牌顶,并覆盖显式及缺省位置字段。

界面与调试输出

Layer / File(s) Summary
显示与调试调整
html/iframe.html, src/tracker/view/cardButton.ts, src/index.js
缩小长中文牌面花色字形,调整多张暗牌按钮文案,并过滤指定消息类型的调试输出。

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
Loading
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
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title Check ✅ Passed Title check skipped as CodeRabbit has written the PR title.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/quanbian

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot changed the title @pr 抽离技能回复处理器并调整牌堆展示与相关测试 Jul 18, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 047b9a8 and 4c8fa2a.

📒 Files selected for processing (16)
  • docs/protocols/CGsRoleSpellOptRep.md
  • docs/protocols/GsCRoleOptTargetNtf-7011.md
  • html/iframe.html
  • src/handler/CGsRoleSpellOptRep.js
  • src/handler/GsCRoleOptTargetNtf.js
  • src/handler/PubGsCMoveCard.js
  • src/handler/index.js
  • src/index.js
  • src/logic.js
  • src/tracker/gameState.ts
  • src/tracker/runtime/trackerController.ts
  • src/tracker/view/cardButton.ts
  • tests/tracker/pubGsCMoveCard.test.ts
  • tests/tracker/roleOptTargetNtf.test.ts
  • tests/tracker/roleSpellOptRep.test.ts
  • tests/tracker/trackerController.test.ts

Comment thread docs/protocols/CGsRoleSpellOptRep.md Outdated
Comment thread src/handler/CGsRoleSpellOptRep.js
@llsccm
llsccm marked this pull request as ready for review July 18, 2026 06:58

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

显式与隐式端点处理存在逻辑冲突,导致牌堆落点不一致。

目前的翻转逻辑仅在 hasExplicitPositiontrue 时执行,这会造成隐式的“牌顶”和显式的“牌顶”最终落点相反:

  • 当未携带 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4c8fa2a and 4d8cfcb.

📒 Files selected for processing (5)
  • docs/protocols/CGsRoleSpellOptRep.md
  • src/handler/PubGsCMoveCard.js
  • src/index.js
  • src/logic.js
  • src/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

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.

1 participant