Skip to content

Commit

Permalink
feat(rule): rule set
Browse files Browse the repository at this point in the history
重做ruleset 指令设置game规则
  • Loading branch information
mystringEmpty committed Jun 8, 2024
1 parent 04f650d commit 055d5c0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 49 deletions.
94 changes: 49 additions & 45 deletions Dice/DiceEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ AttrGetters MsgIndexs{
if (AttrVar game{ sessions.get_if(*obj)} ) {
return obj->at("game") = game;
}
return AttrVar();
else return game;
}},
};

Expand Down Expand Up @@ -2289,50 +2289,6 @@ int DiceEvent::InnerOrder() {
}
return 1;
}
else if (pref5 == "rules") {
intMsgCnt += 5;
while (isspace(static_cast<unsigned char>(strMsg[intMsgCnt])))
intMsgCnt++;
if (strMsg.length() == intMsgCnt) {
replyHelp("rules");
return 1;
}
if (strLowerMessage.substr(intMsgCnt, 3) == "set") {
intMsgCnt += 3;
while (isspace(static_cast<unsigned char>(strMsg[intMsgCnt])) || strMsg[intMsgCnt] == ':')
intMsgCnt++;
string strDefaultRule = strMsg.substr(intMsgCnt);
if (strDefaultRule.empty()) {
getUser(fromChat.uid).rmConf("默认规则");
replyMsg("strRuleReset");
}
else {
for (auto& n : strDefaultRule)
n = toupper(static_cast<unsigned char>(n));
getUser(fromChat.uid).setConf("默认规则", strDefaultRule);
replyMsg("strRuleSet");
}
}
else {
string strSearch = strMsg.substr(intMsgCnt);
for (auto& n : strSearch)
n = toupper(static_cast<unsigned char>(n));
if (auto rule{ getGameRule() }; GetRule::get(*rule, strSearch, strReply)) {
reply();
}
else if (getUser(fromChat.uid).is("默认规则") && strSearch.find(':') == string::npos &&
GetRule::get(getUser(fromChat.uid).get_str("默认规则"), strSearch, strReply)) {
reply();
}
else if (GetRule::analyze(strSearch, strReply)) {
reply();
}
else {
reply(getMsg("strRuleErr") + strReply);
}
}
return 1;
}
else if (string pref4{ strLowerMessage.substr(intMsgCnt, 4) }; pref4 == "coc6") {
intMsgCnt += 4;
if (strLowerMessage[intMsgCnt] == 's')
Expand Down Expand Up @@ -2612,6 +2568,54 @@ int DiceEvent::InnerOrder() {
replyMsg("strNameGenerator");
return 1;
}
else if (pref4 == "rule") {
intMsgCnt += 4;
while (isspace(static_cast<unsigned char>(strMsg[intMsgCnt])))
intMsgCnt++;
if (strMsg.length() == intMsgCnt) {
replyHelp("rule");
return 1;
}
if (strLowerMessage.substr(intMsgCnt, 3) == "set") {
intMsgCnt += 3;
while (isspace(static_cast<unsigned char>(strMsg[intMsgCnt])) || strMsg[intMsgCnt] == ':')
intMsgCnt++;
string strDefaultRule = strMsg.substr(intMsgCnt);
auto game{ thisGame() };
if (strDefaultRule.empty()) {
if (game)game->reset("rule");
else getUser(fromChat.uid).rmConf("默认规则");
replyMsg("strRuleReset");
}
else {
set("rule", strDefaultRule);
if (game)game->set("rule", strDefaultRule);
else getUser(fromChat.uid).setConf("默认规则", strDefaultRule);
replyMsg("strRuleSet");
}
}
else if (strLowerMessage[intMsgCnt] == 's') {
++intMsgCnt;
string strSearch = readRest();
for (auto& n : strSearch)
n = toupper(static_cast<unsigned char>(n));
if (auto rule{ getGameRule() }; GetRule::get(*rule, strSearch, strReply)) {
reply();
}
else if (getUser(fromChat.uid).is("默认规则") && strSearch.find(':') == string::npos &&
GetRule::get(getUser(fromChat.uid).get_str("默认规则"), strSearch, strReply)) {
reply();
}
else if (GetRule::analyze(strSearch, strReply)) {
reply();
}
else {
reply(getMsg("strRuleErr") + strReply);
}
}
else replyHelp("rule");
return 1;
}
else if (pref4 == "send") {
intMsgCnt += 4;
readSkipSpace();
Expand Down
2 changes: 1 addition & 1 deletion Dice/GetRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace GetRule
}
if (temp == getMsg("strRequestNoResponse"))
{
des = getMsg("strRuleNotFound");
des = getMsg("strRuleNotFound", AttrVars{ {"item",itemName } });
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions Dice/GlobalVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,12 @@ const dict_ci<string> PlainMsg
{"strSetPropSuccess", "已为{pc}录入{cnt}条属性√"},
{"strPropCleared", "已清空{char}的所有属性√"},
{"strRuleReset", "已重置默认规则√"},
{"strRuleSet", "已设置默认规则√"},
{"strRuleSet", "{self}已设置默认规则{rule}"},
{"strRuleErr", "规则数据获取失败,具体信息:\n"},
{"strRulesFailedErr", "请求失败,{self}无法连接数据库×"},
{"strPropDeleted", "已删除{pc}的{attr}√"},
{"strPropNotFound", "属性{attr}不存在×"},
{"strRuleNotFound", "{self}未找到对应的规则信息×"},
{"strRuleNotFound", "{self}未找到对应的规则词条{item}×"},
{"strProp", "{pc}的{attr}为{val}"},
{"strPropList", "{nick}的{char}属性列表为:{show}"},
//{"strStErr", "格式错误:请参考.help st获取.st命令的使用方法"},
Expand Down Expand Up @@ -683,7 +683,7 @@ const dict_ci<> HelpDoc = {
{"bot",".bot on/off开启/静默骰子(限群管理)\n.bot无视静默状态,只要插件开启且不在黑名单总是有效"},
{"规则速查","&rules"},
{"规则","&rules"},
{"rules","规则速查:.rules ([规则]):[待查词条] 或.rules set [规则]\n.rules 跳跃 //复数规则有相同词条时,择一返回\n.rules COC大失败 //coc默认搜寻coc7的词条,dnd默认搜寻3r\n.rules dnd语言\n.rules set dnd //设置后优先查询dnd同名词条,无参数则清除设置"},
{"rule","规则速查:.rules ([规则]):[待查词条] 或.rule set [规则]\n.rules 跳跃 //复数规则有相同词条时,择一返回\n.rules COC:大失败 //coc默认搜寻coc7的词条,dnd默认搜寻3r\n.rules dnd:语言\n.ruleset dnd //设置后优先查询dnd同名词条,无参数则清除设置"},
{"掷骰","&r"},
{"rd","&r"},
{"r","掷骰:.r [掷骰表达式] ([掷骰原因]) [掷骰表达式]:([掷骰轮数]#)[骰子个数]d骰子面数(p[惩罚骰个数])(k[取点数最大的骰子数])不带参数时视为掷一个默认骰\n合法参数要求掷骰轮数1-10,奖惩骰个数1-9,个数范围1-100,面数范围1-1000\n.r3#d\t//3轮掷骰\n.rh心理学 暗骰\n.rs1D10+1D6+3 沙鹰伤害\t//rs省略单个骰子的点数,直接给结果"},
Expand Down

0 comments on commit 055d5c0

Please sign in to comment.