Skip to content

Commit 5176288

Browse files
committedMay 1, 2024
feat(ri): multi roll
允许ri指令为复数单位同时生成先攻
1 parent 1dbaae9 commit 5176288

7 files changed

+102
-45
lines changed
 

‎Dice/DiceEvent.cpp

+94-21
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static unordered_map<int, string>RollDiceErr{
151151
};
152152
void DiceEvent::replyRollDiceErr(int err, const RD& rd) {
153153
switch (err) {
154-
case 0: break;
154+
case 0: return;
155155
case Value_Err:
156156
break;
157157
case Input_Err:
@@ -1558,7 +1558,7 @@ int DiceEvent::BasicOrder()
15581558
}
15591559
else if (action == "rou") {
15601560
readSkipSpace();
1561-
if (isdigit(static_cast<unsigned char>(strMsg[intMsgCnt]))) {
1561+
if (is_digit(strMsg[intMsgCnt])) {
15621562
if (game->is_gm(fromChat.uid)) {
15631563
if (int nFace = 100; !readNum(nFace) && nFace <= 100) {
15641564
set("face", nFace);
@@ -2219,7 +2219,7 @@ int DiceEvent::InnerOrder() {
22192219
}
22202220
long long llMemberQQ = stoll(QQNum);
22212221
set("member",getName(llMemberQQ, llGroup));
2222-
string strMainDice = readDice();
2222+
string strMainDice = readXDY();
22232223
if (strMainDice.empty()) {
22242224
replyMsg("strValueErr");
22252225
return -1;
@@ -2340,7 +2340,7 @@ int DiceEvent::InnerOrder() {
23402340
while (isspace(static_cast<unsigned char>(strLowerMessage[intMsgCnt])))
23412341
intMsgCnt++;
23422342
string strNum;
2343-
while (isdigit(static_cast<unsigned char>(strLowerMessage[intMsgCnt]))) {
2343+
while (is_digit(strLowerMessage[intMsgCnt])) {
23442344
strNum += strLowerMessage[intMsgCnt];
23452345
intMsgCnt++;
23462346
}
@@ -2495,13 +2495,16 @@ int DiceEvent::InnerOrder() {
24952495
set("table_item",readRest());
24962496
if (is_empty("table_item"))
24972497
replyMsg("strGMTableItemEmpty");
2498-
else if (auto game{ thisGame() }; game->table_del("先攻", get_str("table_item")))
2498+
else if (game->table_del("先攻", get_str("table_item"))) {
2499+
game->table_del("init_exp", get_str("table_item"));
24992500
replyMsg("strGMTableItemDel");
2501+
}
25002502
else
25012503
replyMsg("strGMTableItemNotFound");
25022504
}
25032505
else if (strCmd == "clr") {
25042506
game->reset("先攻");
2507+
game->reset("init_exp");
25052508
replyMsg("strGMTableClr");
25062509
}
25072510
return 1;
@@ -2798,7 +2801,7 @@ int DiceEvent::InnerOrder() {
27982801
while (isspace(static_cast<unsigned char>(strLowerMessage[intMsgCnt])))
27992802
intMsgCnt++;
28002803
string strNum;
2801-
while (isdigit(static_cast<unsigned char>(strLowerMessage[intMsgCnt]))) {
2804+
while (is_digit(strLowerMessage[intMsgCnt])) {
28022805
strNum += strLowerMessage[intMsgCnt];
28032806
intMsgCnt++;
28042807
}
@@ -2820,7 +2823,7 @@ int DiceEvent::InnerOrder() {
28202823
while (isspace(static_cast<unsigned char>(strLowerMessage[intMsgCnt])))
28212824
intMsgCnt++;
28222825
string strNum;
2823-
while (isdigit(static_cast<unsigned char>(strLowerMessage[intMsgCnt]))) {
2826+
while (is_digit(strLowerMessage[intMsgCnt])) {
28242827
strNum += strLowerMessage[intMsgCnt];
28252828
intMsgCnt++;
28262829
}
@@ -3539,7 +3542,7 @@ int DiceEvent::InnerOrder() {
35393542
string strTurnCnt = strMsg.substr(intMsgCnt, strMsg.find('#') - intMsgCnt);
35403543
//#能否识别有效
35413544
if (strTurnCnt.empty())intMsgCnt++;
3542-
else if ((strTurnCnt.length() == 1 && isdigit(static_cast<unsigned char>(strTurnCnt[0]))) || strTurnCnt ==
3545+
else if ((strTurnCnt.length() == 1 && is_digit(strTurnCnt[0])) || strTurnCnt ==
35433546
"10") {
35443547
intMsgCnt += strTurnCnt.length() + 1;
35453548
intTurnCnt = stoi(strTurnCnt);
@@ -3766,19 +3769,51 @@ int DiceEvent::InnerOrder() {
37663769
strinit += readDice();
37673770
}
37683771
else if (isRollDice()) {
3769-
strinit = readDice();
3770-
}
3771-
set("char",strip(readRest()));
3772-
if (is_empty("char")) {
3773-
set("char",idx_pc(*this));
3772+
if((strinit = readXDY()).empty())strinit = "D20";
37743773
}
3774+
string name{ strip(readRest()) };
37753775
RD initdice(strinit, 20);
37763776
if (const auto intFirstTimeRes = initdice.Roll()) {
37773777
replyRollDiceErr(intFirstTimeRes, initdice);
37783778
return 1;
37793779
}
3780-
sessions.get(fromChat)->table_add("先攻", initdice.intTotal, get_str("char"));
3781-
set("res",initdice.FormCompleteString());
3780+
auto game{ sessions.get(fromChat) };
3781+
if (size_t pos{ name.find('#') }; pos == string::npos) {
3782+
set("char", name.empty() ? name = idx_pc(*this) : name);
3783+
game->table_add("先攻", initdice.intTotal, name);
3784+
game->table_add("init_exp", initdice.strDice, name);
3785+
set("res", initdice.FormCompleteString());
3786+
}
3787+
else {
3788+
string strTurnCnt = name.substr(0, pos);
3789+
set("char", name = name.substr(pos + 1));
3790+
int cntInit = 1;
3791+
ShowList res;
3792+
if (!strTurnCnt.empty()) {
3793+
RD rdTurnCnt(strTurnCnt, 20);
3794+
if (const int intRdTurnCntRes = rdTurnCnt.Roll(); intRdTurnCntRes != 0) {
3795+
replyRollDiceErr(intRdTurnCntRes, rdTurnCnt);
3796+
return 1;
3797+
}
3798+
else if (rdTurnCnt.intTotal > 10) {
3799+
replyMsg("strRollTimeExceeded");
3800+
return 1;
3801+
}
3802+
else if (rdTurnCnt.intTotal <= 0) {
3803+
replyMsg("strRollTimeErr");
3804+
return 1;
3805+
}
3806+
cntInit = rdTurnCnt.intTotal;
3807+
}
3808+
game->table_add("init_exp", initdice.strDice, name);
3809+
int no = 0;
3810+
do {
3811+
res << to_string(++no) + ". " + initdice.FormCompleteString();
3812+
game->table_add("先攻", initdice.intTotal, name + to_string(no));
3813+
initdice.Roll();
3814+
} while (no < cntInit);
3815+
set("res", "\n" + res.show("\n"));
3816+
}
37823817
replyMsg("strRollInit");
37833818
return 1;
37843819
}
@@ -3811,14 +3846,14 @@ int DiceEvent::InnerOrder() {
38113846
string strSanCostSuc = SanCost.substr(0, SanCost.find('/'));
38123847
string strSanCostFail = SanCost.substr(SanCost.find('/') + 1);
38133848
for (const auto& character : strSanCostSuc) {
3814-
if (!isdigit(static_cast<unsigned char>(character)) && character != 'D' && character != 'd' && character !=
3849+
if (!is_digit(character) && character != 'D' && character != 'd' && character !=
38153850
'+' && character != '-') {
38163851
replyMsg("strSanCostInvalid");
38173852
return 1;
38183853
}
38193854
}
38203855
for (const auto& character : strSanCostFail) {
3821-
if (!isdigit(static_cast<unsigned char>(character)) && character != 'D' && character != 'd' && character !=
3856+
if (!is_digit(character) && character != 'D' && character != 'd' && character !=
38223857
'+' && character != '-') {
38233858
replyMsg("strSanCostInvalid");
38243859
return 1;
@@ -4088,7 +4123,7 @@ int DiceEvent::InnerOrder() {
40884123
}
40894124
//判定录入文本
40904125
else if (strLowerMessage.length() != intMsgCnt
4091-
&& !isdigit(static_cast<unsigned char>(strLowerMessage[intMsgCnt]))
4126+
&& !is_digit(strLowerMessage[intMsgCnt])
40924127
&& !isspace(static_cast<unsigned char>(strLowerMessage[intMsgCnt]))) {
40934128
if (string strVal{ trustedQQ(fromChat.uid) > 0 ? readUntilSpace() : filter_CQcode(readUntilSpace()) };
40944129
!pc->set(attr_name, strVal)) {
@@ -4158,6 +4193,7 @@ int DiceEvent::InnerOrder() {
41584193
res << attr + "" + tx->get_str("reason");
41594194
}
41604195
}
4196+
if (!is("cnt"))set("cnt", 0);
41614197
set("detail", res.show("\n"));
41624198
replyMsg("strStDetail");
41634199
}
@@ -4237,12 +4273,13 @@ int DiceEvent::InnerOrder() {
42374273
RD rdTurnCnt(strTurnCnt, intDefaultDice);
42384274
if (const int intRdTurnCntRes = rdTurnCnt.Roll(); intRdTurnCntRes != 0) {
42394275
replyRollDiceErr(intRdTurnCntRes, rdTurnCnt);
4276+
return 1;
42404277
}
4241-
if (rdTurnCnt.intTotal > 10) {
4278+
else if (rdTurnCnt.intTotal > 10) {
42424279
replyMsg("strRollTimeExceeded");
42434280
return 1;
42444281
}
4245-
if (rdTurnCnt.intTotal <= 0) {
4282+
else if (rdTurnCnt.intTotal <= 0) {
42464283
replyMsg("strRollTimeErr");
42474284
return 1;
42484285
}
@@ -4264,7 +4301,7 @@ int DiceEvent::InnerOrder() {
42644301
: strFirstDice.find('*'));
42654302
bool boolAdda10 = true;
42664303
for (auto i : strFirstDice) {
4267-
if (!isdigit(static_cast<unsigned char>(i))) {
4304+
if (!is_digit(i)) {
42684305
boolAdda10 = false;
42694306
break;
42704307
}
@@ -4675,6 +4712,42 @@ int DiceEvent::readNum(int& num)
46754712
num = stoi(strNum);
46764713
return 0;
46774714
}
4715+
string DiceEvent::readXDY()
4716+
{
4717+
string strDice;
4718+
while (isspace(static_cast<unsigned char>(strLowerMessage[intMsgCnt])))intMsgCnt++;
4719+
while (is_digit(strLowerMessage[intMsgCnt])
4720+
|| strLowerMessage[intMsgCnt] == 'd' || strLowerMessage[intMsgCnt] == 'k'
4721+
|| strLowerMessage[intMsgCnt] == 'p' || strLowerMessage[intMsgCnt] == 'b'
4722+
|| strLowerMessage[intMsgCnt] == '+' || strLowerMessage[intMsgCnt] == '-'
4723+
|| strLowerMessage[intMsgCnt] == 'x' || strLowerMessage[intMsgCnt] == '*' || strMsg[intMsgCnt] == '/')
4724+
{
4725+
strDice += strMsg[intMsgCnt];
4726+
intMsgCnt++;
4727+
}
4728+
if (!isNumeric(strDice))return strDice;
4729+
else intMsgCnt -= strDice.length();
4730+
return {};
4731+
}
4732+
string DiceEvent::readDice()
4733+
{
4734+
string strDice;
4735+
while (isspace(static_cast<unsigned char>(strLowerMessage[intMsgCnt])) || strLowerMessage[intMsgCnt] == '=' ||
4736+
strLowerMessage[intMsgCnt] == ':')intMsgCnt++;
4737+
while (is_digit(strLowerMessage[intMsgCnt])
4738+
|| strLowerMessage[intMsgCnt] == 'd' || strLowerMessage[intMsgCnt] == 'k'
4739+
|| strLowerMessage[intMsgCnt] == 'p' || strLowerMessage[intMsgCnt] == 'b'
4740+
|| strLowerMessage[intMsgCnt] == 'f'
4741+
|| strLowerMessage[intMsgCnt] == '+' || strLowerMessage[intMsgCnt] == '-'
4742+
|| strLowerMessage[intMsgCnt] == 'a'
4743+
|| strLowerMessage[intMsgCnt] == 'x' || strLowerMessage[intMsgCnt] == '*' || strMsg[intMsgCnt] == '/'
4744+
|| strLowerMessage[intMsgCnt] == '#')
4745+
{
4746+
strDice += strMsg[intMsgCnt];
4747+
intMsgCnt++;
4748+
}
4749+
return strDice;
4750+
}
46784751
string DiceEvent::readAttrName()
46794752
{
46804753
while (isspace(static_cast<unsigned char>(strMsg[intMsgCnt])))intMsgCnt++;

‎Dice/DiceEvent.h

+2-19
Original file line numberDiff line numberDiff line change
@@ -170,25 +170,8 @@ class DiceEvent : public AnysTable {
170170
}
171171

172172
//读取掷骰表达式
173-
string readDice()
174-
{
175-
string strDice;
176-
while (isspace(static_cast<unsigned char>(strLowerMessage[intMsgCnt])) || strLowerMessage[intMsgCnt] == '=' ||
177-
strLowerMessage[intMsgCnt] == ':')intMsgCnt++;
178-
while (isdigit(static_cast<unsigned char>(strLowerMessage[intMsgCnt]))
179-
|| strLowerMessage[intMsgCnt] == 'd' || strLowerMessage[intMsgCnt] == 'k'
180-
|| strLowerMessage[intMsgCnt] == 'p' || strLowerMessage[intMsgCnt] == 'b'
181-
|| strLowerMessage[intMsgCnt] == 'f'
182-
|| strLowerMessage[intMsgCnt] == '+' || strLowerMessage[intMsgCnt] == '-'
183-
|| strLowerMessage[intMsgCnt] == 'a'
184-
|| strLowerMessage[intMsgCnt] == 'x' || strLowerMessage[intMsgCnt] == '*' || strMsg[intMsgCnt] == '/'
185-
|| strLowerMessage[intMsgCnt] == '#')
186-
{
187-
strDice += strMsg[intMsgCnt];
188-
intMsgCnt++;
189-
}
190-
return strDice;
191-
}
173+
string readXDY();
174+
string readDice();
192175

193176
//读取含转义的表达式
194177
string readExp()

‎Dice/DiceSession.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ bool DiceSession::table_del(const string& tab, const string& item) {
114114
return false;
115115
}
116116

117-
bool DiceSession::table_add(const string& tab, int prior, const string& item) {
117+
bool DiceSession::table_add(const string& tab, const AttrVar& prior, const string& item) {
118118
if (!dict.count(tab))set(tab, AnysTable());
119119
get_obj(tab)->set(item,prior);
120120
update();

‎Dice/DiceSession.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class DiceSession: public AnysTable{
208208
}
209209

210210
bool table_del(const string&, const string&);
211-
bool table_add(const string&, int, const string&);
211+
bool table_add(const string&, const AttrVar& val, const string&);
212212
[[nodiscard]] string table_prior_show(const string& key) const;
213213

214214
//旁观指令

‎Dice/GlobalVar.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ const dict_ci<string> GlobalComment{
536536
};
537537
const dict_ci<> HelpDoc = {
538538
{"更新",R"(
539+
662:先攻批量生成
539540
661:优化game指令触发机制
540541
660:优化sample嵌套
541542
659:reply支持冷却/限额回复
@@ -868,7 +869,7 @@ const dict_ci<> HelpDoc = {
868869
{ "全牌堆列表","{list_all_deck}" },
869870
{ "扩展指令","{list_extern_order}" },
870871
{"先攻", "&ri"},
871-
{"ri", "先攻(群聊限定):.ri([加值])([昵称])\n.ri -1 某pc\t//自动记入先攻列表\n.ri +5 boss"},
872+
{"ri", "先攻(群聊限定):.ri([加值])([昵称])\n.ri-1 某pc //自动记入先攻列表\n.ri+5 3#木乃伊 //生成复数先攻值"},
872873
{"先攻列表", "&init"},
873874
{"init", "先攻列表:\n.init list\t//查看先攻列表\n.init clr\t//清除先攻列表\n.init del [项目名]\t//从先攻列表移除项目"},
874875
{"骰池", "&ww"},

‎Dice/GlobalVar.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Please Do not modify Dice_Build, Dice_Ver_Without_Build, DiceRequestHeader or Dice_Ver
3838
* To costum version info, please modify const Dice_Short_Ver or Dice_Full_Ver
3939
*/
40-
constexpr unsigned short Dice_Build = 661u;
40+
constexpr unsigned short Dice_Build = 662u;
4141
inline const std::string Dice_Ver_Without_Build = "2.7.0beta8";
4242
constexpr auto DiceRequestHeader = "Dice/2.7.0";
4343
inline const std::string Dice_Ver = Dice_Ver_Without_Build + "(" + std::to_string(Dice_Build) + ")";

‎Dice/STLExtern.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class PriorList{
348348
{
349349
auto [prior, item] = qItem.top();
350350
qItem.pop();
351-
res += "\n" + to_string(++index) + "." + item + ":" + to_string(prior);
351+
res += "\n" + to_string(++index) + "." + item + ": " + to_string(prior);
352352
}
353353
return res;
354354
}

0 commit comments

Comments
 (0)