feat(coffee): 增加咖啡 1-1 关卡无限刷每周都市活力功能#128
Conversation
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
审阅者指南(Reviewer's Guide)重构了现有的自动咖啡动作以复用共享工具函数,改进了遗留咖啡模式的健壮性和可配置性,并引入了新的 ROI 标注工具,用于支持为新的 1-1 周回流程编写基于图像的自动化脚本。 使用共享工具的遗留咖啡自动模式时序图sequenceDiagram
actor Player
participant MaaPipeline
participant AutoMakeCoffee
participant Common_utils
participant Controller
Player->>MaaPipeline: start MakeCoffee task
MaaPipeline->>AutoMakeCoffee: run(context, argv)
AutoMakeCoffee->>AutoMakeCoffee: parse custom_action_param
AutoMakeCoffee->>AutoMakeCoffee: _run_evict(context, controller, make_count, check_freq, start_template, star_template, claim_template)
loop for each round
AutoMakeCoffee->>Common_utils: click_rect(controller, select_level_target, delay, count, hold)
Common_utils->>Controller: post_touch_down/post_touch_up
AutoMakeCoffee->>Controller: post_screencap
Controller-->>Common_utils: cached_image
Common_utils-->>AutoMakeCoffee: get_image result
AutoMakeCoffee->>Common_utils: match_template_in_region(img, start_roi, start_template, min_similarity)
alt start button found
AutoMakeCoffee->>Common_utils: click_rect(controller, start_button_rect, delay, count, hold)
end
loop wait for sales goal
AutoMakeCoffee->>Common_utils: click_rect(controller, click_roi, delay, count, hold)
AutoMakeCoffee->>Controller: post_screencap
Controller-->>Common_utils: cached_image
Common_utils-->>AutoMakeCoffee: get_image result
AutoMakeCoffee->>Common_utils: match_template_in_region(img, star_roi, star_template, min_similarity)
alt star reached
AutoMakeCoffee->>Common_utils: click_rect(controller, exit_roi, delay, count, hold)
end
end
loop wait for claim button
AutoMakeCoffee->>Controller: post_screencap
Controller-->>Common_utils: cached_image
Common_utils-->>AutoMakeCoffee: get_image result
AutoMakeCoffee->>Common_utils: match_template_in_region(img, claim_roi, claim_template, min_similarity)
alt claim found
AutoMakeCoffee->>Common_utils: click_rect(controller, claim_button_rect, delay, count, hold)
end
end
AutoMakeCoffee->>Controller: post_key_down(key_f)
AutoMakeCoffee->>Controller: post_key_up(key_f)
end
AutoMakeCoffee-->>MaaPipeline: RunResult(success)
MaaPipeline-->>Player: report automation finished
更新后的 AutoMakeCoffee 与新 RoiMarker 工具的类图classDiagram
class AutoMakeCoffee {
-start_template
-star_template
-claim_template
+run(context, argv)
+_run_evict(context, controller, make_count, check_freq, start_template, star_template, claim_template)
}
class Common_utils {
+get_image(controller)
+click_rect(controller, rect, delay, count, hold)
+match_template_in_region(img, region, template, min_similarity, green_mask)
}
class RoiMarker {
-image_path
-labels
-scale
-image
-display_base
-window_name
-rois
-current_label_index
-dragging
-drag_start
-drag_end
+run()
+current_label()
+_on_mouse(event, x, y, flags, param)
+_scaled_rect_to_original(start, end)
+_render()
+_original_rect_to_scaled(roi)
+_next_label()
+_undo()
+_save()
}
class mark_roi_module {
+parse_args()
+main()
}
AutoMakeCoffee ..> Common_utils : uses
mark_roi_module ..> RoiMarker : instantiates
mark_roi_module ..> Common_utils : independent module
RoiMarker ..> cv2 : uses
AutoMakeCoffee ..> AgentServer : registered_as_custom_action
文件级变更
与关联 Issue 的对应情况评估
可能关联的 Issues
提示与命令与 Sourcery 交互
自定义你的体验访问你的 控制面板 以:
获取帮助Original review guide in EnglishReviewer's GuideRefactors the existing auto coffee action to reuse shared utility functions, improves robustness and configurability of the legacy coffee mode, and introduces a new ROI marking tool to support authoring image-based automation for the new 1-1 farming flow. Sequence diagram for legacy coffee auto mode with shared utilitiessequenceDiagram
actor Player
participant MaaPipeline
participant AutoMakeCoffee
participant Common_utils
participant Controller
Player->>MaaPipeline: start MakeCoffee task
MaaPipeline->>AutoMakeCoffee: run(context, argv)
AutoMakeCoffee->>AutoMakeCoffee: parse custom_action_param
AutoMakeCoffee->>AutoMakeCoffee: _run_evict(context, controller, make_count, check_freq, start_template, star_template, claim_template)
loop for each round
AutoMakeCoffee->>Common_utils: click_rect(controller, select_level_target, delay, count, hold)
Common_utils->>Controller: post_touch_down/post_touch_up
AutoMakeCoffee->>Controller: post_screencap
Controller-->>Common_utils: cached_image
Common_utils-->>AutoMakeCoffee: get_image result
AutoMakeCoffee->>Common_utils: match_template_in_region(img, start_roi, start_template, min_similarity)
alt start button found
AutoMakeCoffee->>Common_utils: click_rect(controller, start_button_rect, delay, count, hold)
end
loop wait for sales goal
AutoMakeCoffee->>Common_utils: click_rect(controller, click_roi, delay, count, hold)
AutoMakeCoffee->>Controller: post_screencap
Controller-->>Common_utils: cached_image
Common_utils-->>AutoMakeCoffee: get_image result
AutoMakeCoffee->>Common_utils: match_template_in_region(img, star_roi, star_template, min_similarity)
alt star reached
AutoMakeCoffee->>Common_utils: click_rect(controller, exit_roi, delay, count, hold)
end
end
loop wait for claim button
AutoMakeCoffee->>Controller: post_screencap
Controller-->>Common_utils: cached_image
Common_utils-->>AutoMakeCoffee: get_image result
AutoMakeCoffee->>Common_utils: match_template_in_region(img, claim_roi, claim_template, min_similarity)
alt claim found
AutoMakeCoffee->>Common_utils: click_rect(controller, claim_button_rect, delay, count, hold)
end
end
AutoMakeCoffee->>Controller: post_key_down(key_f)
AutoMakeCoffee->>Controller: post_key_up(key_f)
end
AutoMakeCoffee-->>MaaPipeline: RunResult(success)
MaaPipeline-->>Player: report automation finished
Class diagram for updated AutoMakeCoffee and new RoiMarker toolclassDiagram
class AutoMakeCoffee {
-start_template
-star_template
-claim_template
+run(context, argv)
+_run_evict(context, controller, make_count, check_freq, start_template, star_template, claim_template)
}
class Common_utils {
+get_image(controller)
+click_rect(controller, rect, delay, count, hold)
+match_template_in_region(img, region, template, min_similarity, green_mask)
}
class RoiMarker {
-image_path
-labels
-scale
-image
-display_base
-window_name
-rois
-current_label_index
-dragging
-drag_start
-drag_end
+run()
+current_label()
+_on_mouse(event, x, y, flags, param)
+_scaled_rect_to_original(start, end)
+_render()
+_original_rect_to_scaled(roi)
+_next_label()
+_undo()
+_save()
}
class mark_roi_module {
+parse_args()
+main()
}
AutoMakeCoffee ..> Common_utils : uses
mark_roi_module ..> RoiMarker : instantiates
mark_roi_module ..> Common_utils : independent module
RoiMarker ..> cv2 : uses
AutoMakeCoffee ..> AgentServer : registered_as_custom_action
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我发现了两个问题,并给出了一些整体性的反馈:
_run_evict中的 ROI 和按键常量(例如select_level_target、click_roi、key_f = 70)目前是硬编码的;建议将它们移到共享的配置/JSON 或具名常量中,这样可以在不修改逻辑代码的前提下复用并调整这些值。- 新的
mark_roi.py工具在脚本中直接内嵌了默认标签和缩放比例处理;如果你计划在其他功能中复用它,建议通过小型配置或预设配置集来参数化这些内容,以避免在新增 ROI 工作流时需要直接改动脚本本身。
提供给 AI Agents 的提示
Please address the comments from this code review:
## Overall Comments
- `_run_evict` 中的 ROI 和按键常量(例如 `select_level_target`、`click_roi`、`key_f = 70`)目前是硬编码的;建议将它们移到共享的配置/JSON 或具名常量中,这样可以在不修改逻辑代码的前提下复用并调整这些值。
- 新的 `mark_roi.py` 工具在脚本中直接内嵌了默认标签和缩放比例处理;如果你计划在其他功能中复用它,建议通过小型配置或预设配置集来参数化这些内容,以避免在新增 ROI 工作流时需要直接改动脚本本身。
## Individual Comments
### Comment 1
<location path="tools/mark_roi.py" line_range="23-32" />
<code_context>
+
+
+class RoiMarker:
+ def __init__(self, image_path: Path, labels: list[str], scale: float):
+ self.image_path = image_path
+ self.labels = labels
+ self.scale = scale
+ image = cv2.imread(str(image_path), cv2.IMREAD_COLOR)
+ if image is None:
+ raise FileNotFoundError(f"无法读取图片: {image_path}")
+ self.image = image
+
+ self.display_base = cv2.resize(
+ self.image,
+ None,
</code_context>
<issue_to_address>
**issue (bug_risk):** 验证 `scale`,以避免无效或退化的缩放操作。
来自 CLI 的 `scale` 会被直接传递给 `cv2.resize`,因此像 `--scale 0` 或负数这样的值会导致 OpenCV 报错或产生未定义行为。请对其进行校验(例如强制 `scale > 0`),并在发现非法值时尽早以清晰的错误信息失败,而不是依赖 `cv2.resize` 间接暴露问题。
</issue_to_address>
### Comment 2
<location path="tools/mark_roi.py" line_range="192" />
<code_context>
+ {"label": str(item["label"]), "roi": item["roi"]}
+ for item in self.rois
+ ]
+ output_json.write_text(json.dumps(data, ensure_ascii=False, indent=4) + "\n")
+ cv2.imwrite(str(output_image), self._render())
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** 建议在写入 JSON 时显式使用 `encoding='utf-8'`。
由于该 JSON 可能包含非 ASCII 标签,显式调用 `write_text(..., encoding="utf-8")` 可以避免依赖平台默认编码,并确保在不同环境下稳定输出 UTF-8。
Suggested implementation:
```python
data = [
{"label": str(item["label"]), "roi": item["roi"]}
for item in self.rois
]
output_json.write_text(
json.dumps(data, ensure_ascii=False, indent=4) + "\n",
encoding="utf-8",
)
cv2.imwrite(str(output_image), self._render())
```
如果 `json` 尚未在 `tools/mark_roi.py` 顶部导入,请在其他导入语句旁添加 `import json`。
</issue_to_address>帮我变得更有用!请在每条评论上点击 👍 或 👎,你的反馈将帮助我改进代码审查。
Original comment in English
Hey - I've found 2 issues, and left some high level feedback:
- The ROI and key-code constants in
_run_evict(e.g.select_level_target,click_roi,key_f = 70) are currently hardcoded; consider moving them into a shared config/JSON or named constants so they can be reused and adjusted without touching the logic. - The new
mark_roi.pytool embeds default labels and scale handling directly in the script; if you plan to reuse it for other features, consider parameterizing these via a small config or preset profiles to avoid needing to modify the script when adding new ROI workflows.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The ROI and key-code constants in `_run_evict` (e.g. `select_level_target`, `click_roi`, `key_f = 70`) are currently hardcoded; consider moving them into a shared config/JSON or named constants so they can be reused and adjusted without touching the logic.
- The new `mark_roi.py` tool embeds default labels and scale handling directly in the script; if you plan to reuse it for other features, consider parameterizing these via a small config or preset profiles to avoid needing to modify the script when adding new ROI workflows.
## Individual Comments
### Comment 1
<location path="tools/mark_roi.py" line_range="23-32" />
<code_context>
+
+
+class RoiMarker:
+ def __init__(self, image_path: Path, labels: list[str], scale: float):
+ self.image_path = image_path
+ self.labels = labels
+ self.scale = scale
+ image = cv2.imread(str(image_path), cv2.IMREAD_COLOR)
+ if image is None:
+ raise FileNotFoundError(f"无法读取图片: {image_path}")
+ self.image = image
+
+ self.display_base = cv2.resize(
+ self.image,
+ None,
</code_context>
<issue_to_address>
**issue (bug_risk):** Validate `scale` to avoid invalid or degenerate resize operations.
`scale` from the CLI is passed directly to `cv2.resize`, so values like `--scale 0` or negatives will cause OpenCV errors or undefined behavior. Please validate (e.g., enforce `scale > 0`) and fail fast with a clear error instead of relying on `cv2.resize` to surface this indirectly.
</issue_to_address>
### Comment 2
<location path="tools/mark_roi.py" line_range="192" />
<code_context>
+ {"label": str(item["label"]), "roi": item["roi"]}
+ for item in self.rois
+ ]
+ output_json.write_text(json.dumps(data, ensure_ascii=False, indent=4) + "\n")
+ cv2.imwrite(str(output_image), self._render())
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider using `encoding='utf-8'` explicitly when writing JSON.
Since this JSON may include non-ASCII labels, explicitly calling `write_text(..., encoding="utf-8")` will avoid relying on platform defaults and ensure consistent UTF-8 output across environments.
Suggested implementation:
```python
data = [
{"label": str(item["label"]), "roi": item["roi"]}
for item in self.rois
]
output_json.write_text(
json.dumps(data, ensure_ascii=False, indent=4) + "\n",
encoding="utf-8",
)
cv2.imwrite(str(output_image), self._render())
```
If `json` is not already imported at the top of `tools/mark_roi.py`, add `import json` alongside the other imports.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| def __init__(self, image_path: Path, labels: list[str], scale: float): | ||
| self.image_path = image_path | ||
| self.labels = labels | ||
| self.scale = scale | ||
| image = cv2.imread(str(image_path), cv2.IMREAD_COLOR) | ||
| if image is None: | ||
| raise FileNotFoundError(f"无法读取图片: {image_path}") | ||
| self.image = image | ||
|
|
||
| self.display_base = cv2.resize( |
There was a problem hiding this comment.
issue (bug_risk): 验证 scale,以避免无效或退化的缩放操作。
来自 CLI 的 scale 会被直接传递给 cv2.resize,因此像 --scale 0 或负数这样的值会导致 OpenCV 报错或产生未定义行为。请对其进行校验(例如强制 scale > 0),并在发现非法值时尽早以清晰的错误信息失败,而不是依赖 cv2.resize 间接暴露问题。
Original comment in English
issue (bug_risk): Validate scale to avoid invalid or degenerate resize operations.
scale from the CLI is passed directly to cv2.resize, so values like --scale 0 or negatives will cause OpenCV errors or undefined behavior. Please validate (e.g., enforce scale > 0) and fail fast with a clear error instead of relying on cv2.resize to surface this indirectly.
| {"label": str(item["label"]), "roi": item["roi"]} | ||
| for item in self.rois | ||
| ] | ||
| output_json.write_text(json.dumps(data, ensure_ascii=False, indent=4) + "\n") |
There was a problem hiding this comment.
suggestion (bug_risk): 建议在写入 JSON 时显式使用 encoding='utf-8'。
由于该 JSON 可能包含非 ASCII 标签,显式调用 write_text(..., encoding="utf-8") 可以避免依赖平台默认编码,并确保在不同环境下稳定输出 UTF-8。
Suggested implementation:
data = [
{"label": str(item["label"]), "roi": item["roi"]}
for item in self.rois
]
output_json.write_text(
json.dumps(data, ensure_ascii=False, indent=4) + "\n",
encoding="utf-8",
)
cv2.imwrite(str(output_image), self._render())如果 json 尚未在 tools/mark_roi.py 顶部导入,请在其他导入语句旁添加 import json。
Original comment in English
suggestion (bug_risk): Consider using encoding='utf-8' explicitly when writing JSON.
Since this JSON may include non-ASCII labels, explicitly calling write_text(..., encoding="utf-8") will avoid relying on platform defaults and ensure consistent UTF-8 output across environments.
Suggested implementation:
data = [
{"label": str(item["label"]), "roi": item["roi"]}
for item in self.rois
]
output_json.write_text(
json.dumps(data, ensure_ascii=False, indent=4) + "\n",
encoding="utf-8",
)
cv2.imwrite(str(output_image), self._render())If json is not already imported at the top of tools/mark_roi.py, add import json alongside the other imports.
* feat(make_coffee): 增加做咖啡平民版 平民版做咖啡1-1,无需白藏娜娜莉 优化做咖啡入口逻辑,在店长特供对话附近可进入界面. Refs: #128 * fix: 去除冗余引用 * fix: 去除冗余引用并显式捕获错误 * fix: 修改PrintT传入正确参数
* feat(make_coffee): 增加做咖啡平民版 平民版做咖啡1-1,无需白藏娜娜莉 优化做咖啡入口逻辑,在店长特供对话附近可进入界面. Refs: 1bananachicken#128 * fix: 去除冗余引用 * fix: 去除冗余引用并显式捕获错误 * fix: 修改PrintT传入正确参数
* feat(make_coffee): 增加做咖啡平民版 平民版做咖啡1-1,无需白藏娜娜莉 优化做咖啡入口逻辑,在店长特供对话附近可进入界面. Refs: 1bananachicken#128 * fix: 去除冗余引用 * fix: 去除冗余引用并显式捕获错误 * fix: 修改PrintT传入正确参数
* feat(make_coffee): 增加做咖啡平民版 平民版做咖啡1-1,无需白藏娜娜莉 优化做咖啡入口逻辑,在店长特供对话附近可进入界面. Refs: 1bananachicken#128 * fix: 去除冗余引用 * fix: 去除冗余引用并显式捕获错误 * fix: 修改PrintT传入正确参数
关联 Issue
Resolves #92
改动概览
新增咖啡 1-1 关卡的自动化循环任务,用于高效消耗每周都市活力:
auto_coffee_1_1_farm.py:自动重复挑战咖啡 1-1 关卡流程说明
关键特性
Summary by Sourcery
重构咖啡自动制作(coffee auto-make)动作以使用共享工具并提升健壮性,并新增用于在截图上标记 ROI 区域的辅助工具。
增强功能:
click_rect辅助函数,以支持可配置的点击次数和按住时长,从而实现更灵活的交互。杂项/维护:
mark_roi开发者工具,用于在截图上以交互方式标注并导出 ROI 定义。Original summary in English
Summary by Sourcery
Refactor the coffee auto-make action to use shared utilities and improve robustness, and add a helper tool for marking ROI regions on screenshots.
Enhancements:
Chores: