Skip to content

Commit af0caa0

Browse files
author
siriusdemon
committed
support black rebirth flame
1 parent d405b6b commit af0caa0

12 files changed

+160
-9
lines changed

coffeestory.cpp

+135-9
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,47 @@ static std::vector<cv::Mat> redCubePotential() {
170170
}
171171

172172

173+
static std::vector<cv::Mat> blackFlame() {
174+
int plus = 103;
175+
int left = 600 + 2;
176+
int right = 730;
177+
int top = 367 + plus;
178+
int bottom = 534 + plus;
179+
180+
// Define the region of interest
181+
std::vector<int> region{ left, top, right, bottom };
182+
ScreenshotCapture& capture = ScreenshotCapture::Instance();
183+
cv::Mat flame = capture.capture(region);
184+
185+
int ma = 5;
186+
int interval = 9;
187+
188+
// Extracting lines
189+
cv::Mat line1 = flame(cv::Rect(0, 0, flame.cols, interval));
190+
cv::Mat line2 = flame(cv::Rect(0, interval + ma, flame.cols, interval));
191+
cv::Mat line3 = flame(cv::Rect(0, interval * 2 + 2 * ma, flame.cols, interval));
192+
cv::Mat line4 = flame(cv::Rect(0, interval * 3 + ma * 3, flame.cols, interval));
193+
cv::Mat line5 = flame(cv::Rect(0, interval * 4 + ma * 4, flame.cols, interval));
194+
cv::Mat line6 = flame(cv::Rect(0, interval * 5 + ma * 5, flame.cols, interval));
195+
196+
return std::vector<cv::Mat>{line1, line2, line3, line4, line5, line6};
197+
}
198+
199+
200+
// rebirth flame
201+
std::unordered_map<std::string, std::pair<std::string, int>> flameImageHub = {
202+
{"boss", {"flame/boss.png", 30}},
203+
{"att", {"flame/att.png", 30}},
204+
{"matt", {"flame/matt.png", 30}},
205+
{"dex", {"flame/dex.png", 30}},
206+
{"str", {"flame/str.png", 30}},
207+
{"int", {"flame/int.png", 30}},
208+
{"luk", {"flame/luk.png", 30}},
209+
{"all", {"flame/all.png", 50}},
210+
{"hp", {"flame/hp.png", 50}},
211+
{"dmg", {"flame/dmg.png", 50}}
212+
};
213+
173214

174215
std::unordered_map<std::string, std::pair<std::string, int>> imageHub = {
175216
{"boss", {"potential/boss.png", 30}},
@@ -191,8 +232,13 @@ std::unordered_map<std::string, std::pair<std::string, int>> imageHub = {
191232

192233
std::unordered_map<std::string, cv::Mat> LoadedHub;
193234

194-
static void load_hub() {
195-
for (const auto& pair : imageHub) {
235+
236+
static void load_hub(bool flame) {
237+
std::unordered_map<std::string, std::pair<std::string, int>>& images = imageHub;
238+
if (flame) {
239+
images = flameImageHub;
240+
}
241+
for (const auto& pair : images) {
196242
const std::string& key = pair.first;
197243
const std::string& path = pair.second.first;
198244
int width = pair.second.second;
@@ -254,6 +300,69 @@ static void rollBlueCude() {
254300
msleep(2000);
255301
}
256302

303+
static void rollBlackRebirthFlame() {
304+
leftclick(683, 633);
305+
msleep(200);
306+
pressEnter();
307+
msleep(200);
308+
pressEnter();
309+
msleep(200);
310+
pressEnter();
311+
msleep(2000);
312+
}
313+
314+
static void matchFlame(int times, const std::vector<Rule>& groups) {
315+
for (int i = 0; i < times; ++i) {
316+
// got new lines
317+
std::vector<cv::Mat> lines = blackFlame();
318+
std::vector<std::string> texts;
319+
320+
// Convert images to texts
321+
for (const auto& line : lines) {
322+
texts.push_back(img2text(line));
323+
}
324+
325+
// Filter out "unknown" texts
326+
texts.erase(std::remove(texts.begin(), texts.end(), "unknown"), texts.end());
327+
328+
// merge the texts;
329+
std::string str;
330+
for (auto& text : texts) {
331+
str += text;
332+
str += "\t";
333+
}
334+
335+
printf("[%d/%d]: %s\n", i + 1, times, str.c_str());
336+
337+
338+
// Iterate through each group
339+
for (const auto& group : groups) {
340+
int hit = group.hit;
341+
const std::vector<std::string>& keys = group.key;
342+
int count = 0;
343+
344+
for (const std::string& text : texts) {
345+
if (std::find(keys.begin(), keys.end(), text) != keys.end()) {
346+
count++;
347+
}
348+
}
349+
350+
if (count >= hit) {
351+
std::cout << "match! ";
352+
for (const auto& key : keys) {
353+
std::cout << key << " ";
354+
}
355+
std::cout << std::endl;
356+
return;
357+
}
358+
}
359+
360+
// Call reset function
361+
rollBlackRebirthFlame();
362+
}
363+
364+
}
365+
257366

258367
static void match(int times, const std::vector<Rule>& groups, bool is_red = false) {
259368
auto potential = is_red ? redCubePotential : blueCubePotential;
@@ -304,6 +413,7 @@ static void match(int times, const std::vector<Rule>& groups, bool is_red = fals
304413
void helpinfo() {
305414
printf("Usage: \n");
306415
printf("coffeestory [red/blue] [times] [target] \n");
416+
printf("coffeestory flame [times] [target] \n");
307417
}
308418

309419

@@ -313,30 +423,46 @@ int main(int argc, char* argv[]) {
313423
return 0;
314424
}
315425
reset_maple();
316-
// Load the image hub
317-
load_hub();
318-
319426
std::string kind = argv[1];
427+
428+
bool flame = false;
320429
bool is_red = false;
321430
if (kind == "red") {
322431
is_red = true;
432+
load_hub(false);
323433
}
324434
else if (kind == "blue") {
325435
is_red = false;
436+
load_hub(false);
437+
}
438+
else if (kind == "flame") {
439+
flame = true;
440+
load_hub(true);
326441
}
327442
else {
328443
helpinfo();
329444
return 0;
330445
}
446+
447+
// Load the image hub
331448
int times = std::stoi(argv[2]);
332449
std::string target = argv[3];
333-
if (auto p = Rules.find(target); p != Rules.end()) {
334-
match(times, p->second, is_red);
450+
if (!flame) {
451+
if (auto p = Rules.find(target); p != Rules.end()) {
452+
match(times, p->second, is_red);
453+
}
454+
else {
455+
std::cout << "target not found! " << target << std::endl;
456+
}
335457
}
336458
else {
337-
std::cout << "target not found! " << target << std::endl;
459+
if (auto p = FlameRules.find(target); p != FlameRules.end()) {
460+
matchFlame(times, p->second);
461+
}
462+
else {
463+
std::cout << "target not found! " << target << std::endl;
464+
}
338465
}
339466

340467
return 0;
341468
}
342-

coffeestory.h

+25
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ struct Rule {
1313

1414
using RuleMap = std::map<std::string, std::vector<Rule>>;
1515

16+
17+
// rebirth flame
18+
RuleMap FlameRules = {
19+
// normal armor
20+
{"allatt", {{2, {"att", "all"}}}},
21+
{"hpatt", {{2, {"att", "hp"}}}},
22+
{"lukatt", {{2, {"att", "luk", "all"}}}},
23+
{"dexatt", {{2, {"att", "dex", "all"}}}},
24+
{"intatt", {{2, {"att", "int", "all"}}}},
25+
{"stratt", {{2, {"att", "str", "all"}}}},
26+
{"lukatt3", {{3, {"att", "luk", "all"}}}},
27+
{"dexatt3", {{3, {"att", "dex", "all"}}}},
28+
{"intatt3", {{3, {"att", "int", "all"}}}},
29+
{"stratt3", {{3, {"att", "str", "all"}}}},
30+
{"lukarm3", {{3, {"att", "boss", "dmg", "all", "luk"}}}},
31+
{"dexarm3", {{3, {"att", "boss", "dmg", "all", "dex"}}}},
32+
{"intarm3", {{3, {"att", "boss", "dmg", "all", "int"}}}},
33+
{"strarm3", {{3, {"att", "boss", "dmg", "all", "str"}}}},
34+
{"hparm3", {{3, {"att", "boss", "dmg", "all", "hp"}}}},
35+
{"allarm3", {{3, {"att", "boss", "dmg", "all"}}}},
36+
{"arm2", {{2, {"att", "boss", "dmg"}}}},
37+
{"arm3", {{3, {"att", "boss", "dmg"}}}},
38+
};
39+
40+
1641
RuleMap Rules = {
1742
// cd hat
1843
{"cd1", {{1, {"cd"}}}},

flame/all.png

3.45 KB
Loading

flame/att.png

3.45 KB
Loading

flame/boss.png

3.45 KB
Loading

flame/dex.png

3.45 KB
Loading

flame/dmg.png

3.45 KB
Loading

flame/hp.png

3.45 KB
Loading

flame/int.png

3.45 KB
Loading

flame/luk.png

3.45 KB
Loading

flame/matt.png

3.45 KB
Loading

flame/str.png

3.45 KB
Loading

0 commit comments

Comments
 (0)