Skip to content

Commit

Permalink
feat(ri): multi roll
Browse files Browse the repository at this point in the history
允许ri指令为复数单位同时生成先攻
  • Loading branch information
mystringEmpty committed May 1, 2024
1 parent 1dbaae9 commit 5176288
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 45 deletions.
115 changes: 94 additions & 21 deletions Dice/DiceEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static unordered_map<int, string>RollDiceErr{
};
void DiceEvent::replyRollDiceErr(int err, const RD& rd) {
switch (err) {
case 0: break;
case 0: return;
case Value_Err:
break;
case Input_Err:
Expand Down Expand Up @@ -1558,7 +1558,7 @@ int DiceEvent::BasicOrder()
}
else if (action == "rou") {
readSkipSpace();
if (isdigit(static_cast<unsigned char>(strMsg[intMsgCnt]))) {
if (is_digit(strMsg[intMsgCnt])) {
if (game->is_gm(fromChat.uid)) {
if (int nFace = 100; !readNum(nFace) && nFace <= 100) {
set("face", nFace);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2340,7 +2340,7 @@ int DiceEvent::InnerOrder() {
while (isspace(static_cast<unsigned char>(strLowerMessage[intMsgCnt])))
intMsgCnt++;
string strNum;
while (isdigit(static_cast<unsigned char>(strLowerMessage[intMsgCnt]))) {
while (is_digit(strLowerMessage[intMsgCnt])) {
strNum += strLowerMessage[intMsgCnt];
intMsgCnt++;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2798,7 +2801,7 @@ int DiceEvent::InnerOrder() {
while (isspace(static_cast<unsigned char>(strLowerMessage[intMsgCnt])))
intMsgCnt++;
string strNum;
while (isdigit(static_cast<unsigned char>(strLowerMessage[intMsgCnt]))) {
while (is_digit(strLowerMessage[intMsgCnt])) {
strNum += strLowerMessage[intMsgCnt];
intMsgCnt++;
}
Expand All @@ -2820,7 +2823,7 @@ int DiceEvent::InnerOrder() {
while (isspace(static_cast<unsigned char>(strLowerMessage[intMsgCnt])))
intMsgCnt++;
string strNum;
while (isdigit(static_cast<unsigned char>(strLowerMessage[intMsgCnt]))) {
while (is_digit(strLowerMessage[intMsgCnt])) {
strNum += strLowerMessage[intMsgCnt];
intMsgCnt++;
}
Expand Down Expand Up @@ -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<unsigned char>(strTurnCnt[0]))) || strTurnCnt ==
else if ((strTurnCnt.length() == 1 && is_digit(strTurnCnt[0])) || strTurnCnt ==
"10") {
intMsgCnt += strTurnCnt.length() + 1;
intTurnCnt = stoi(strTurnCnt);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<unsigned char>(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<unsigned char>(character)) && character != 'D' && character != 'd' && character !=
if (!is_digit(character) && character != 'D' && character != 'd' && character !=
'+' && character != '-') {
replyMsg("strSanCostInvalid");
return 1;
Expand Down Expand Up @@ -4088,7 +4123,7 @@ int DiceEvent::InnerOrder() {
}
//判定录入文本
else if (strLowerMessage.length() != intMsgCnt
&& !isdigit(static_cast<unsigned char>(strLowerMessage[intMsgCnt]))
&& !is_digit(strLowerMessage[intMsgCnt])
&& !isspace(static_cast<unsigned char>(strLowerMessage[intMsgCnt]))) {
if (string strVal{ trustedQQ(fromChat.uid) > 0 ? readUntilSpace() : filter_CQcode(readUntilSpace()) };
!pc->set(attr_name, strVal)) {
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -4264,7 +4301,7 @@ int DiceEvent::InnerOrder() {
: strFirstDice.find('*'));
bool boolAdda10 = true;
for (auto i : strFirstDice) {
if (!isdigit(static_cast<unsigned char>(i))) {
if (!is_digit(i)) {
boolAdda10 = false;
break;
}
Expand Down Expand Up @@ -4675,6 +4712,42 @@ int DiceEvent::readNum(int& num)
num = stoi(strNum);
return 0;
}
string DiceEvent::readXDY()
{
string strDice;
while (isspace(static_cast<unsigned char>(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<unsigned char>(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<unsigned char>(strMsg[intMsgCnt])))intMsgCnt++;
Expand Down
21 changes: 2 additions & 19 deletions Dice/DiceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,25 +170,8 @@ class DiceEvent : public AnysTable {
}

//读取掷骰表达式
string readDice()
{
string strDice;
while (isspace(static_cast<unsigned char>(strLowerMessage[intMsgCnt])) || strLowerMessage[intMsgCnt] == '=' ||
strLowerMessage[intMsgCnt] == ':')intMsgCnt++;
while (isdigit(static_cast<unsigned char>(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()
Expand Down
2 changes: 1 addition & 1 deletion Dice/DiceSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Dice/DiceSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

//旁观指令
Expand Down
3 changes: 2 additions & 1 deletion Dice/GlobalVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ const dict_ci<string> GlobalComment{
};
const dict_ci<> HelpDoc = {
{"更新",R"(
662:先攻批量生成
661:优化game指令触发机制
660:优化sample嵌套
659:reply支持冷却/限额回复
Expand Down Expand Up @@ -868,7 +869,7 @@ const dict_ci<> HelpDoc = {
{ "全牌堆列表","{list_all_deck}" },
{ "扩展指令","{list_extern_order}" },
{"先攻", "&ri"},
{"ri", "先攻(群聊限定):.ri([加值])([昵称])\n.ri -1 某pc\t//自动记入先攻列表\n.ri +5 boss"},
{"ri", "先攻(群聊限定):.ri([加值])([昵称])\n.ri-1 某pc //自动记入先攻列表\n.ri+5 3#木乃伊 //生成复数先攻值"},
{"先攻列表", "&init"},
{"init", "先攻列表:\n.init list\t//查看先攻列表\n.init clr\t//清除先攻列表\n.init del [项目名]\t//从先攻列表移除项目"},
{"骰池", "&ww"},
Expand Down
2 changes: 1 addition & 1 deletion Dice/GlobalVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) + ")";
Expand Down
2 changes: 1 addition & 1 deletion Dice/STLExtern.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5176288

Please sign in to comment.