Skip to content

Commit

Permalink
Merge branch 'MaaAssistantArknights:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinT3Hu authored Jan 22, 2024
2 parents 0ad252c + 8e90f98 commit 967f485
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 30 deletions.
8 changes: 4 additions & 4 deletions docs/glossary/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ char_475_akafyu|赤冬|Akafuyu|アカフユ|아카후유
char_476_blkngt|夜半|Blacknight|ブラックナイト|블랙나이트
char_478_kirara|绮良|Kirara|キララ|키라라
char_486_takila|龙舌兰|Tequila|テキーラ|테킬라
char_488_buildr|青枳|Poncirus||폰사이러스
char_488_buildr|青枳|Poncirus|ポンシラス|폰사이러스
char_489_serum|蚀清|Corroserum|コロセラム|코로세럼
char_492_quercu|夏栎|Quercus|クエルクス|퀘르쿠스
char_493_firwhl|火哨|Firewhistle|ファイヤーホイッスル|파이어휘슬
Expand Down Expand Up @@ -233,7 +233,7 @@ char_4071_peper|明椒|Paprika|パプリカ|파프리카
char_4078_bdhkgt|截云|Jieyun|ジエユン|지에윈
char_4083_chimes|铎铃|Wind Chimes|ウィンドチャイム|윈드차임스
char_4102_threye|凛视|Valarqvin||
char_4106_bryota|苍苔|Bryophyta||브라이오피타
char_4106_bryota|苍苔|Bryophyta|ブライオファイタ|브라이오피타
char_4104_coldst|冰酿|Coldshot||

ID|中文|English|日本語|한국어
Expand Down Expand Up @@ -290,15 +290,15 @@ char_485_pallas|帕拉斯|Pallas|パラス|팔라스
char_1012_skadi2|浊心斯卡蒂|Skadi the Corrupting Heart|濁心スカジ|스카디 더 커럽팅 하트
char_1013_chen2|假日威龙陈|Ch'en the Holungday|遊龍チェン|첸 더 홀룽데이
char_1014_nearl2|耀骑士临光|Nearl the Radiant Knight|耀騎士ニアール|니어 더 래디언트 나이트
char_1016_agoat2|纯烬艾雅法拉|Eyjafjalla the Hvít Aska||에이야퍄들라 더 크비트 아스카
char_1016_agoat2|纯烬艾雅法拉|Eyjafjalla the Hvít Aska|純燼エイヤフィヤトラ|에이야퍄들라 더 크비트 아스카
char_1020_reed2|焰影苇草|Reed the Flame Shadow|焔影リード|리드 더 플레임 섀도우
char_1023_ghost2|归溟幽灵鲨|Specter the Unchained|帰溟スペクター|스펙터 디 언체인드
char_1026_gvial2|百炼嘉维尔|Gavial the Invincible|百錬ガヴィル|가비알 디 인빈서블
char_1028_texas2|缄默德克萨斯|Texas the Omertosa|血掟テキサス|텍사스 디 오메르토사
char_1029_yato2|麒麟R夜刀|Kirin R Yato|キリンRヤトウ|키린R 야토
char_1031_slent2|淬羽赫默|Silence the Paradigmatic|淬羽サイレンス|사일런스 더 패러디그매틱
char_1032_excu2|圣约送葬人|Executor the Ex Foedere|聖約イクゼキュター|이그제큐터 디 엑스 포에데레
char_1033_swire2|琳琅诗怀雅|Swire the Elegant Wit||스와이어 디 엘리건트 위트
char_1033_swire2|琳琅诗怀雅|Swire the Elegant Wit|琳琅スワイヤー|스와이어 디 엘리건트 위트
char_1034_jesca2|涤火杰西卡|Jessica the Liberated||
char_2012_typhon|提丰|Typhon||
char_2013_cerber|刻俄柏|Ceobe|ケオベ|케오베
Expand Down
9 changes: 8 additions & 1 deletion src/MaaCore/Task/BattleHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ bool asst::BattleHelper::update_deployment(bool init, const cv::Mat& reusable)
}

BattlefieldMatcher oper_analyzer(image);
oper_analyzer.set_object_of_interest({ .deployment = true });

// 保全要识别开局费用,先用init判断了,之后别的地方要用的话再做cache
if (init) {
oper_analyzer.set_object_of_interest({ .deployment = true, .oper_cost = true });
}
else {
oper_analyzer.set_object_of_interest({ .deployment = true });
}
auto oper_result_opt = oper_analyzer.analyze();
if (!oper_result_opt) {
check_in_battle(image);
Expand Down
53 changes: 45 additions & 8 deletions src/MaaCore/Task/SSS/SSSBattleProcessTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,43 @@ bool asst::SSSBattleProcessTask::set_stage_name(const std::string& stage_name)
return true;
}

bool asst::SSSBattleProcessTask::update_deployment_with_skip(const cv::Mat& reusable)
{
const auto now = std::chrono::steady_clock::now();
const std::vector<DeploymentOper> old_deployment_opers = m_cur_deployment_opers;
static auto last_same_time = now;
static auto last_skip_time = now;
static auto interval_time = 0;

if (std::chrono::duration_cast<std::chrono::milliseconds>(now - last_skip_time).count() < interval_time) {
Log.trace("Passed without update deployment");
sleep(interval_time);
return true;
}
last_skip_time = now;

if (!update_deployment(false, reusable)) {
return false;
}

if (ranges::equal(
m_cur_deployment_opers, old_deployment_opers,
[](const DeploymentOper& oper1, const DeploymentOper& oper2) { return oper1.name == oper2.name; })) {
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - last_same_time).count() > 30000) {
// 30s 能回 60 费,基本上已经到了挂机的时候,放缓检查的速度
Log.trace("30s is unchanged and the waiting time is extended to 5s");
interval_time = 5000;
}
}
else {
last_same_time = now;
Log.trace("Changed, the waiting time is reset to 0s");
interval_time = 0;
}

return true;
}

bool asst::SSSBattleProcessTask::do_derived_action(const battle::copilot::Action& action, size_t index)
{
LogTraceFunction;
Expand All @@ -45,7 +82,7 @@ bool asst::SSSBattleProcessTask::do_derived_action(const battle::copilot::Action

switch (action.type) {
case battle::copilot::ActionType::DrawCard:
return draw_card();
return draw_card() && update_deployment();
case battle::copilot::ActionType::CheckIfStartOver:
return check_if_start_over(action);
default:
Expand All @@ -63,10 +100,6 @@ bool asst::SSSBattleProcessTask::do_strategic_action(const cv::Mat& reusable)
return true;
}

if (m_sss_combat_data.draw_as_possible && draw_card(false, image)) {
image = ctrler()->get_image();
}

if (check_and_do_strategy(image)) {
image = ctrler()->get_image();
}
Expand All @@ -75,6 +108,10 @@ bool asst::SSSBattleProcessTask::do_strategic_action(const cv::Mat& reusable)
// image = ctrler()->get_image();
}

if (m_sss_combat_data.draw_as_possible && draw_card(false, image)) {
// image = ctrler()->get_image();
}

return true;
}

Expand Down Expand Up @@ -129,7 +166,7 @@ bool asst::SSSBattleProcessTask::check_and_do_strategy(const cv::Mat& reusable)
}

cv::Mat image = reusable.empty() ? ctrler()->get_image() : reusable;
if (!update_deployment(false, image)) {
if (!update_deployment_with_skip(image)) {
return false;
}

Expand Down Expand Up @@ -157,7 +194,7 @@ bool asst::SSSBattleProcessTask::check_and_do_strategy(const cv::Mat& reusable)
}
m_all_cores.erase(strategy.core);
// 部署完,画面会发生变化,所以直接返回,后续逻辑交给下次循环处理
return deploy_oper(strategy.core, strategy.location, strategy.direction);
return deploy_oper(strategy.core, strategy.location, strategy.direction) && update_deployment();
}

bool skip = false;
Expand All @@ -174,7 +211,7 @@ bool asst::SSSBattleProcessTask::check_and_do_strategy(const cv::Mat& reusable)
if (available_iter != tool_men.cend()) {
--quantity;
// 部署完,画面会发生变化,所以直接返回,后续逻辑交给下次循环处理
return deploy_oper(available_iter->name, strategy.location, strategy.direction);
return deploy_oper(available_iter->name, strategy.location, strategy.direction) && update_deployment();
}

auto not_available_iter =
Expand Down
1 change: 1 addition & 0 deletions src/MaaCore/Task/SSS/SSSBattleProcessTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace asst
virtual bool need_to_wait_until_end() const noexcept override { return true; }
virtual bool wait_until_start(bool weak = true) override;

bool update_deployment_with_skip(const cv::Mat& reusable = cv::Mat());
bool check_and_do_strategy(const cv::Mat& reusable = cv::Mat());
bool check_if_start_over(const battle::copilot::Action& action);
bool draw_card(bool with_retry = true, const cv::Mat& reusable = cv::Mat());
Expand Down
6 changes: 4 additions & 2 deletions src/MaaCore/Vision/Battle/BattlefieldMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ std::vector<battle::DeploymentOper> BattlefieldMatcher::deployment_analyze() con
Log.error("oper is available, but with cooling");
}

Rect cost_rect = correct_rect(flag_res.rect.move(cost_move), m_image);
oper.cost = oper_cost_analyze(cost_rect);
if (m_object_of_interest.oper_cost) {
Rect cost_rect = correct_rect(flag_res.rect.move(cost_move), m_image);
oper.cost = oper_cost_analyze(cost_rect);
}

oper.index = index++;

Expand Down
1 change: 1 addition & 0 deletions src/MaaCore/Vision/Battle/BattlefieldMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace asst
bool costs = false;
// bool in_detail = false;
bool speed_button = false;
bool oper_cost = false;
};

struct Result
Expand Down
110 changes: 110 additions & 0 deletions src/MaaWpfGui/Helper/DataHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// <copyright file="DataHelper.cs" company="MaaAssistantArknights">
// MaaWpfGui - A part of the MaaCoreArknights project
// Copyright (C) 2021 MistEO and Contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY
// </copyright>

using System;

Check warning on line 14 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using System.Collections.Generic;

Check warning on line 15 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using System.IO;

Check warning on line 16 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using System.Linq;

Check warning on line 17 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using Newtonsoft.Json;

Check warning on line 18 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using Newtonsoft.Json.Linq;

Check warning on line 19 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed

namespace MaaWpfGui.Helper
{

Check notice on line 22 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use preferred namespace body style

Convert to file-scoped namespace
public static class DataHelper
{
// 储存角色信息的字典
public static Dictionary<string, CharacterInfo> Characters { get; }

Check notice on line 26 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Member can be made private (non-private accessibility)

Property 'Characters' can be made private

static DataHelper()
{
Characters = new Dictionary<string, CharacterInfo>();

const string FilePath = "resource/battle_data.json";
if (!File.Exists(FilePath))
{
return;
}

string jsonText = File.ReadAllText(FilePath);
var characterData = JsonConvert.DeserializeObject<Dictionary<string, CharacterInfo>>(JObject.Parse(jsonText)["chars"]?.ToString() ?? string.Empty);

foreach (var pair in characterData)
{
Characters.Add(pair.Key, pair.Value);
}
}

public static CharacterInfo GetCharacterByNameOrAlias(string characterName)
{
return Characters.Values.FirstOrDefault(
character =>
new[]
{
character?.Name,
character?.NameEn,
character?.NameJp,
character?.NameKr,
character?.NameTw,
}.Any(name => name.Equals(characterName, StringComparison.OrdinalIgnoreCase)));
}

public static string GetLocalizedCharacterName(string characterName, string language)
{
var characterInfo = GetCharacterByNameOrAlias(characterName);
if (characterInfo?.Name == null)
{
return null;
}

return language switch
{
"zh-cn" => characterInfo.Name,
"zh-tw" => characterInfo.NameTw ?? characterInfo.Name,
"en-us" => characterInfo.NameEn ?? characterInfo.Name,
"ja-jp" => characterInfo.NameJp ?? characterInfo.Name,
"ko-kr" => characterInfo.NameKr ?? characterInfo.Name,
_ => characterInfo.Name,
};
}

public class CharacterInfo

Check notice on line 80 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Class is never instantiated (non-private accessibility)

Class 'CharacterInfo' is never instantiated
{
[JsonProperty("name")]
public string Name { get; set; }

Check warning on line 83 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property accessor is never used (non-private accessibility)

Auto-property accessor 'Name.set' is never used

[JsonProperty("name_en")]
public string NameEn { get; set; }

Check warning on line 86 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property accessor is never used (non-private accessibility)

Auto-property accessor 'NameEn.set' is never used

[JsonProperty("name_jp")]
public string NameJp { get; set; }

Check warning on line 89 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property accessor is never used (non-private accessibility)

Auto-property accessor 'NameJp.set' is never used

[JsonProperty("name_kr")]
public string NameKr { get; set; }

Check warning on line 92 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property accessor is never used (non-private accessibility)

Auto-property accessor 'NameKr.set' is never used

[JsonProperty("name_tw")]
public string NameTw { get; set; }

Check warning on line 95 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property accessor is never used (non-private accessibility)

Auto-property accessor 'NameTw.set' is never used

[JsonProperty("position")]
public string Position { get; set; }

Check notice on line 98 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Type member is never used (non-private accessibility)

Property 'Position' is never used

[JsonProperty("profession")]
public string Profession { get; set; }

Check notice on line 101 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Type member is never used (non-private accessibility)

Property 'Profession' is never used

[JsonProperty("rangeId")]
public List<string> RangeId { get; set; }

Check notice on line 104 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Type member is never used (non-private accessibility)

Property 'RangeId' is never used

[JsonProperty("rarity")]
public int Rarity { get; set; }

Check notice on line 107 in src/MaaWpfGui/Helper/DataHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Type member is never used (non-private accessibility)

Property 'Rarity' is never used
}
}
}
5 changes: 3 additions & 2 deletions src/MaaWpfGui/Res/Localizations/en-us.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@
<system:String x:Key="RoguelikeLastReward">Fight to obtain starting rewards, reach the third floor then exit</system:String>
<system:String x:Key="StartingSquad">Starting Squad</system:String>
<system:String x:Key="StartingRoles">Starting Roles</system:String>
<system:String x:Key="StartingCoreChar">Starting Operator (CN name only)</system:String>
<system:String x:Key="StartingCoreCharTip">Only supports the CN name of a single operator, default if not filled.</system:String>
<system:String x:Key="StartingCoreChar">Starting Operator (single)</system:String>
<system:String x:Key="StartingCoreCharTip">If not filled out, the default policy will be used.</system:String>
<system:String x:Key="RoguelikeStartingCoreCharNotFound">The agent entered「{0}」is not in battle_data. Check that the name entered is correct, or check the maa resource version.</system:String>
<system:String x:Key="RoguelikeStartWithEliteTwo">Repeat for「Starting Operator」Elite 2</system:String>
<system:String x:Key="RoguelikeOnlyStartWithEliteTwo">Only Repeat for「Starting Operator」Elite 2, No Battle</system:String>
<system:String x:Key="RoguelikeUseSupportUnit">Select 「Starting Operator」 from support unit list</system:String>
Expand Down
5 changes: 3 additions & 2 deletions src/MaaWpfGui/Res/Localizations/ja-jp.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@
<system:String x:Key="RoguelikeLastReward">序盤の報酬を得るために戦い、3階到着後終了</system:String>
<system:String x:Key="StartingSquad">最初の分隊</system:String>
<system:String x:Key="StartingRoles">最初の職業</system:String>
<system:String x:Key="StartingCoreChar">最初のオペレーター(一人だけ、中国名のみを入力可能)</system:String>
<system:String x:Key="StartingCoreCharTip">一人のオペレーターの中国名のみをサポートします。入力されていない場合はデフォルトになります。</system:String>
<system:String x:Key="StartingCoreChar">最初のオペレーター(一人だけ)</system:String>
<system:String x:Key="StartingCoreCharTip">記入がない場合はデフォルトの方針を使用します。</system:String>
<system:String x:Key="RoguelikeStartingCoreCharNotFound">入力のスタッフ「{0}」がbattle_dataにありません。入力の名前が正しいか、maaリソースのバージョンをチェックしてください。</system:String>
<system:String x:Key="RoguelikeStartWithEliteTwo">「最初のオペレーター」直接昇進</system:String>
<system:String x:Key="RoguelikeOnlyStartWithEliteTwo">指定オペレーターの昇進招集までリセマラし、戦闘を行わない</system:String>
<system:String x:Key="RoguelikeUseSupportUnit">「最初のオペレーター」をサポートから選択</system:String>
Expand Down
5 changes: 3 additions & 2 deletions src/MaaWpfGui/Res/Localizations/ko-kr.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@
<system:String x:Key="StartingSquad">시작 분대</system:String>
<system:String x:Key="StartingRoles">모집 조합</system:String>
<system:String x:Key="StartingCoreChar">시작 오퍼레이터 (1명)</system:String>
<system:String x:Key="StartingCoreCharTip">단일 오퍼레이터의 중국어 이름만 지원하며, 입력하지 않으면 기본값이 선택됩니다.</system:String>
<system:String x:Key="RoguelikeStartWithEliteTwo">시작 오퍼레이터 2정예화까지 반복</system:String>
<system:String x:Key="StartingCoreCharTip">작성하지 않으면 기본 정책이 사용됩니다.</system:String>
<system:String x:Key="RoguelikeStartingCoreCharNotFound">입력한 하프「{0}」는 battle_data에 없습니다. 입력한 이름이 올바른지 확인하거나 maa 리소스 버전을 확인하십시오.</system:String>
<system:String x:Key="RoguelikeStartWithEliteTwo">시초 에 간부 가 직진 하다</system:String>
<system:String x:Key="RoguelikeOnlyStartWithEliteTwo">시작 오퍼레이터 2정예화까지 반복(전투 X)</system:String>
<system:String x:Key="RoguelikeUseSupportUnit">시작 오퍼레이터로 지원 유닛 사용</system:String>
<system:String x:Key="RoguelikeUseNonFriendSupport">친구가 아니어도 지원 유닛 사용</system:String>
Expand Down
3 changes: 2 additions & 1 deletion src/MaaWpfGui/Res/Localizations/zh-cn.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
<system:String x:Key="StartingSquad">开局分队</system:String>
<system:String x:Key="StartingRoles">开局职业组</system:String>
<system:String x:Key="StartingCoreChar">开局干员 (单个)</system:String>
<system:String x:Key="StartingCoreCharTip">仅支持单个干员中文名,不填写则默认选择。</system:String>
<system:String x:Key="StartingCoreCharTip">不填写则使用默认策略。</system:String>
<system:String x:Key="RoguelikeStartingCoreCharNotFound">输入的干员「{0}」未在 battle_data 中,请检查输入的名称是否正确,或检查 maa 资源版本。</system:String>
<system:String x:Key="RoguelikeStartWithEliteTwo">凹「开局干员」直升精二</system:String>
<system:String x:Key="RoguelikeOnlyStartWithEliteTwo">只凹「开局干员」直升精二,不进行作战</system:String>
<system:String x:Key="RoguelikeUseSupportUnit">「开局干员」使用助战</system:String>
Expand Down
3 changes: 2 additions & 1 deletion src/MaaWpfGui/Res/Localizations/zh-tw.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
<system:String x:Key="StartingSquad">開局分隊</system:String>
<system:String x:Key="StartingRoles">開局職業組</system:String>
<system:String x:Key="StartingCoreChar">開局幹員(單個)</system:String>
<system:String x:Key="StartingCoreCharTip">僅支持單個幹員中文名,不填寫則預設選擇。</system:String>
<system:String x:Key="StartingCoreCharTip">不填寫則使用預設策略。</system:String>
<system:String x:Key="RoguelikeStartingCoreCharNotFound">輸入的幹員「{0}」未在 battle_data 中,請檢查輸入的名稱是否正確,或檢查 maa 資源版本。</system:String>
<system:String x:Key="RoguelikeStartWithEliteTwo">凹「開局幹員」直升精二</system:String>
<system:String x:Key="RoguelikeOnlyStartWithEliteTwo">只凹「開局幹員」直升精二,不進行作戰</system:String>
<system:String x:Key="RoguelikeUseSupportUnit">「開局幹員」使用助戰</system:String>
Expand Down
Loading

0 comments on commit 967f485

Please sign in to comment.