From 51762885fd497eb48416e337697a316e49da4ea3 Mon Sep 17 00:00:00 2001 From: "string.Empty" Date: Wed, 1 May 2024 16:16:24 +0800 Subject: [PATCH] feat(ri): multi roll MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 允许ri指令为复数单位同时生成先攻 --- Dice/DiceEvent.cpp | 115 +++++++++++++++++++++++++++++++++++-------- Dice/DiceEvent.h | 21 +------- Dice/DiceSession.cpp | 2 +- Dice/DiceSession.h | 2 +- Dice/GlobalVar.cpp | 3 +- Dice/GlobalVar.h | 2 +- Dice/STLExtern.hpp | 2 +- 7 files changed, 102 insertions(+), 45 deletions(-) diff --git a/Dice/DiceEvent.cpp b/Dice/DiceEvent.cpp index acf2d96d..6d766359 100644 --- a/Dice/DiceEvent.cpp +++ b/Dice/DiceEvent.cpp @@ -151,7 +151,7 @@ static unordered_mapRollDiceErr{ }; void DiceEvent::replyRollDiceErr(int err, const RD& rd) { switch (err) { - case 0: break; + case 0: return; case Value_Err: break; case Input_Err: @@ -1558,7 +1558,7 @@ int DiceEvent::BasicOrder() } else if (action == "rou") { readSkipSpace(); - if (isdigit(static_cast(strMsg[intMsgCnt]))) { + if (is_digit(strMsg[intMsgCnt])) { if (game->is_gm(fromChat.uid)) { if (int nFace = 100; !readNum(nFace) && nFace <= 100) { set("face", nFace); @@ -2219,7 +2219,7 @@ int DiceEvent::InnerOrder() { } long long llMemberQQ = stoll(QQNum); set("member",getName(llMemberQQ, llGroup)); - string strMainDice = readDice(); + string strMainDice = readXDY(); if (strMainDice.empty()) { replyMsg("strValueErr"); return -1; @@ -2340,7 +2340,7 @@ int DiceEvent::InnerOrder() { while (isspace(static_cast(strLowerMessage[intMsgCnt]))) intMsgCnt++; string strNum; - while (isdigit(static_cast(strLowerMessage[intMsgCnt]))) { + while (is_digit(strLowerMessage[intMsgCnt])) { strNum += strLowerMessage[intMsgCnt]; intMsgCnt++; } @@ -2495,13 +2495,16 @@ int DiceEvent::InnerOrder() { set("table_item",readRest()); if (is_empty("table_item")) replyMsg("strGMTableItemEmpty"); - else if (auto game{ thisGame() }; game->table_del("ȹ", get_str("table_item"))) + else if (game->table_del("ȹ", get_str("table_item"))) { + game->table_del("init_exp", get_str("table_item")); replyMsg("strGMTableItemDel"); + } else replyMsg("strGMTableItemNotFound"); } else if (strCmd == "clr") { game->reset("ȹ"); + game->reset("init_exp"); replyMsg("strGMTableClr"); } return 1; @@ -2798,7 +2801,7 @@ int DiceEvent::InnerOrder() { while (isspace(static_cast(strLowerMessage[intMsgCnt]))) intMsgCnt++; string strNum; - while (isdigit(static_cast(strLowerMessage[intMsgCnt]))) { + while (is_digit(strLowerMessage[intMsgCnt])) { strNum += strLowerMessage[intMsgCnt]; intMsgCnt++; } @@ -2820,7 +2823,7 @@ int DiceEvent::InnerOrder() { while (isspace(static_cast(strLowerMessage[intMsgCnt]))) intMsgCnt++; string strNum; - while (isdigit(static_cast(strLowerMessage[intMsgCnt]))) { + while (is_digit(strLowerMessage[intMsgCnt])) { strNum += strLowerMessage[intMsgCnt]; intMsgCnt++; } @@ -3539,7 +3542,7 @@ int DiceEvent::InnerOrder() { string strTurnCnt = strMsg.substr(intMsgCnt, strMsg.find('#') - intMsgCnt); //#ܷʶЧ if (strTurnCnt.empty())intMsgCnt++; - else if ((strTurnCnt.length() == 1 && isdigit(static_cast(strTurnCnt[0]))) || strTurnCnt == + else if ((strTurnCnt.length() == 1 && is_digit(strTurnCnt[0])) || strTurnCnt == "10") { intMsgCnt += strTurnCnt.length() + 1; intTurnCnt = stoi(strTurnCnt); @@ -3766,19 +3769,51 @@ int DiceEvent::InnerOrder() { strinit += readDice(); } else if (isRollDice()) { - strinit = readDice(); - } - set("char",strip(readRest())); - if (is_empty("char")) { - set("char",idx_pc(*this)); + if((strinit = readXDY()).empty())strinit = "D20"; } + string name{ strip(readRest()) }; RD initdice(strinit, 20); if (const auto intFirstTimeRes = initdice.Roll()) { replyRollDiceErr(intFirstTimeRes, initdice); return 1; } - sessions.get(fromChat)->table_add("ȹ", initdice.intTotal, get_str("char")); - set("res",initdice.FormCompleteString()); + auto game{ sessions.get(fromChat) }; + if (size_t pos{ name.find('#') }; pos == string::npos) { + set("char", name.empty() ? name = idx_pc(*this) : name); + game->table_add("ȹ", initdice.intTotal, name); + game->table_add("init_exp", initdice.strDice, name); + set("res", initdice.FormCompleteString()); + } + else { + string strTurnCnt = name.substr(0, pos); + set("char", name = name.substr(pos + 1)); + int cntInit = 1; + ShowList res; + if (!strTurnCnt.empty()) { + RD rdTurnCnt(strTurnCnt, 20); + if (const int intRdTurnCntRes = rdTurnCnt.Roll(); intRdTurnCntRes != 0) { + replyRollDiceErr(intRdTurnCntRes, rdTurnCnt); + return 1; + } + else if (rdTurnCnt.intTotal > 10) { + replyMsg("strRollTimeExceeded"); + return 1; + } + else if (rdTurnCnt.intTotal <= 0) { + replyMsg("strRollTimeErr"); + return 1; + } + cntInit = rdTurnCnt.intTotal; + } + game->table_add("init_exp", initdice.strDice, name); + int no = 0; + do { + res << to_string(++no) + ". " + initdice.FormCompleteString(); + game->table_add("ȹ", initdice.intTotal, name + to_string(no)); + initdice.Roll(); + } while (no < cntInit); + set("res", "\n" + res.show("\n")); + } replyMsg("strRollInit"); return 1; } @@ -3811,14 +3846,14 @@ int DiceEvent::InnerOrder() { string strSanCostSuc = SanCost.substr(0, SanCost.find('/')); string strSanCostFail = SanCost.substr(SanCost.find('/') + 1); for (const auto& character : strSanCostSuc) { - if (!isdigit(static_cast(character)) && character != 'D' && character != 'd' && character != + if (!is_digit(character) && character != 'D' && character != 'd' && character != '+' && character != '-') { replyMsg("strSanCostInvalid"); return 1; } } for (const auto& character : strSanCostFail) { - if (!isdigit(static_cast(character)) && character != 'D' && character != 'd' && character != + if (!is_digit(character) && character != 'D' && character != 'd' && character != '+' && character != '-') { replyMsg("strSanCostInvalid"); return 1; @@ -4088,7 +4123,7 @@ int DiceEvent::InnerOrder() { } //ж¼ı else if (strLowerMessage.length() != intMsgCnt - && !isdigit(static_cast(strLowerMessage[intMsgCnt])) + && !is_digit(strLowerMessage[intMsgCnt]) && !isspace(static_cast(strLowerMessage[intMsgCnt]))) { if (string strVal{ trustedQQ(fromChat.uid) > 0 ? readUntilSpace() : filter_CQcode(readUntilSpace()) }; !pc->set(attr_name, strVal)) { @@ -4158,6 +4193,7 @@ int DiceEvent::InnerOrder() { res << attr + " " + tx->get_str("reason"); } } + if (!is("cnt"))set("cnt", 0); set("detail", res.show("\n")); replyMsg("strStDetail"); } @@ -4237,12 +4273,13 @@ int DiceEvent::InnerOrder() { RD rdTurnCnt(strTurnCnt, intDefaultDice); if (const int intRdTurnCntRes = rdTurnCnt.Roll(); intRdTurnCntRes != 0) { replyRollDiceErr(intRdTurnCntRes, rdTurnCnt); + return 1; } - if (rdTurnCnt.intTotal > 10) { + else if (rdTurnCnt.intTotal > 10) { replyMsg("strRollTimeExceeded"); return 1; } - if (rdTurnCnt.intTotal <= 0) { + else if (rdTurnCnt.intTotal <= 0) { replyMsg("strRollTimeErr"); return 1; } @@ -4264,7 +4301,7 @@ int DiceEvent::InnerOrder() { : strFirstDice.find('*')); bool boolAdda10 = true; for (auto i : strFirstDice) { - if (!isdigit(static_cast(i))) { + if (!is_digit(i)) { boolAdda10 = false; break; } @@ -4675,6 +4712,42 @@ int DiceEvent::readNum(int& num) num = stoi(strNum); return 0; } +string DiceEvent::readXDY() +{ + string strDice; + while (isspace(static_cast(strLowerMessage[intMsgCnt])))intMsgCnt++; + while (is_digit(strLowerMessage[intMsgCnt]) + || strLowerMessage[intMsgCnt] == 'd' || strLowerMessage[intMsgCnt] == 'k' + || strLowerMessage[intMsgCnt] == 'p' || strLowerMessage[intMsgCnt] == 'b' + || strLowerMessage[intMsgCnt] == '+' || strLowerMessage[intMsgCnt] == '-' + || strLowerMessage[intMsgCnt] == 'x' || strLowerMessage[intMsgCnt] == '*' || strMsg[intMsgCnt] == '/') + { + strDice += strMsg[intMsgCnt]; + intMsgCnt++; + } + if (!isNumeric(strDice))return strDice; + else intMsgCnt -= strDice.length(); + return {}; +} +string DiceEvent::readDice() +{ + string strDice; + while (isspace(static_cast(strLowerMessage[intMsgCnt])) || strLowerMessage[intMsgCnt] == '=' || + strLowerMessage[intMsgCnt] == ':')intMsgCnt++; + while (is_digit(strLowerMessage[intMsgCnt]) + || strLowerMessage[intMsgCnt] == 'd' || strLowerMessage[intMsgCnt] == 'k' + || strLowerMessage[intMsgCnt] == 'p' || strLowerMessage[intMsgCnt] == 'b' + || strLowerMessage[intMsgCnt] == 'f' + || strLowerMessage[intMsgCnt] == '+' || strLowerMessage[intMsgCnt] == '-' + || strLowerMessage[intMsgCnt] == 'a' + || strLowerMessage[intMsgCnt] == 'x' || strLowerMessage[intMsgCnt] == '*' || strMsg[intMsgCnt] == '/' + || strLowerMessage[intMsgCnt] == '#') + { + strDice += strMsg[intMsgCnt]; + intMsgCnt++; + } + return strDice; +} string DiceEvent::readAttrName() { while (isspace(static_cast(strMsg[intMsgCnt])))intMsgCnt++; diff --git a/Dice/DiceEvent.h b/Dice/DiceEvent.h index bba849e5..25eabac7 100644 --- a/Dice/DiceEvent.h +++ b/Dice/DiceEvent.h @@ -170,25 +170,8 @@ class DiceEvent : public AnysTable { } //ȡʽ - string readDice() - { - string strDice; - while (isspace(static_cast(strLowerMessage[intMsgCnt])) || strLowerMessage[intMsgCnt] == '=' || - strLowerMessage[intMsgCnt] == ':')intMsgCnt++; - while (isdigit(static_cast(strLowerMessage[intMsgCnt])) - || strLowerMessage[intMsgCnt] == 'd' || strLowerMessage[intMsgCnt] == 'k' - || strLowerMessage[intMsgCnt] == 'p' || strLowerMessage[intMsgCnt] == 'b' - || strLowerMessage[intMsgCnt] == 'f' - || strLowerMessage[intMsgCnt] == '+' || strLowerMessage[intMsgCnt] == '-' - || strLowerMessage[intMsgCnt] == 'a' - || strLowerMessage[intMsgCnt] == 'x' || strLowerMessage[intMsgCnt] == '*' || strMsg[intMsgCnt] == '/' - || strLowerMessage[intMsgCnt] == '#') - { - strDice += strMsg[intMsgCnt]; - intMsgCnt++; - } - return strDice; - } + string readXDY(); + string readDice(); //ȡתıʽ string readExp() diff --git a/Dice/DiceSession.cpp b/Dice/DiceSession.cpp index da563d65..1c1c53b0 100644 --- a/Dice/DiceSession.cpp +++ b/Dice/DiceSession.cpp @@ -114,7 +114,7 @@ bool DiceSession::table_del(const string& tab, const string& item) { return false; } -bool DiceSession::table_add(const string& tab, int prior, const string& item) { +bool DiceSession::table_add(const string& tab, const AttrVar& prior, const string& item) { if (!dict.count(tab))set(tab, AnysTable()); get_obj(tab)->set(item,prior); update(); diff --git a/Dice/DiceSession.h b/Dice/DiceSession.h index 391b6201..d59fd360 100644 --- a/Dice/DiceSession.h +++ b/Dice/DiceSession.h @@ -208,7 +208,7 @@ class DiceSession: public AnysTable{ } bool table_del(const string&, const string&); - bool table_add(const string&, int, const string&); + bool table_add(const string&, const AttrVar& val, const string&); [[nodiscard]] string table_prior_show(const string& key) const; //Թָ diff --git a/Dice/GlobalVar.cpp b/Dice/GlobalVar.cpp index 19eabf12..785d8183 100644 --- a/Dice/GlobalVar.cpp +++ b/Dice/GlobalVar.cpp @@ -536,6 +536,7 @@ const dict_ci GlobalComment{ }; const dict_ci<> HelpDoc = { {"",R"( +662:ȹ 661:Żgameָ 660:ŻsampleǶ 659:reply֧ȴ/޶ظ @@ -868,7 +869,7 @@ const dict_ci<> HelpDoc = { { "ȫƶб","{list_all_deck}" }, { "չָ","{list_extern_order}" }, {"ȹ", "&ri"}, - {"ri", "ȹȺ޶.ri([ֵ])([dz])\n.ri -1 ijpc\t//Զȹб\n.ri +5 boss"}, + {"ri", "ȹȺ޶.ri([ֵ])([dz])\n.ri-1 ijpc //Զȹб\n.ri+5 3#ľ //ɸȹֵ"}, {"ȹб", "&init"}, {"init", "ȹб\n.init list\t//鿴ȹб\n.init clr\t//ȹб\n.init del [Ŀ]\t//ȹбƳĿ"}, {"", "&ww"}, diff --git a/Dice/GlobalVar.h b/Dice/GlobalVar.h index a02ed0db..400e9af2 100644 --- a/Dice/GlobalVar.h +++ b/Dice/GlobalVar.h @@ -37,7 +37,7 @@ * Please Do not modify Dice_Build, Dice_Ver_Without_Build, DiceRequestHeader or Dice_Ver * To costum version info, please modify const Dice_Short_Ver or Dice_Full_Ver */ -constexpr unsigned short Dice_Build = 661u; +constexpr unsigned short Dice_Build = 662u; inline const std::string Dice_Ver_Without_Build = "2.7.0beta8"; constexpr auto DiceRequestHeader = "Dice/2.7.0"; inline const std::string Dice_Ver = Dice_Ver_Without_Build + "(" + std::to_string(Dice_Build) + ")"; diff --git a/Dice/STLExtern.hpp b/Dice/STLExtern.hpp index c1632cc8..544f0466 100644 --- a/Dice/STLExtern.hpp +++ b/Dice/STLExtern.hpp @@ -348,7 +348,7 @@ class PriorList{ { auto [prior, item] = qItem.top(); qItem.pop(); - res += "\n" + to_string(++index) + "." + item + ":" + to_string(prior); + res += "\n" + to_string(++index) + "." + item + ": " + to_string(prior); } return res; }