-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. Bug fixes
- Loading branch information
Showing
6 changed files
with
129 additions
and
11 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
*Dice! QQ dice robot for TRPG game | ||
*Copyright (C) 2018 w4123溯洄 | ||
* | ||
*This program is free software: you can redistribute it and/or modify it under the terms | ||
*of the GNU Affero General Public License as published by the Free Software Foundation, | ||
*either version 3 of the License, or (at your option) any later version. | ||
* | ||
*This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
*without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
*See the GNU Affero General Public License for more details. | ||
* | ||
*You should have received a copy of the GNU Affero General Public License along with this | ||
*program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#include "InitList.h" | ||
#include <string> | ||
#include <map> | ||
#include <vector> | ||
#include <algorithm> | ||
using namespace std; | ||
|
||
|
||
void Initlist::insert(long long group, int value, string nickname) | ||
{ | ||
if (!mpInitlist.count(group)) | ||
{ | ||
mpInitlist[group] = vector<INIT>{ INIT{ nickname,value } }; | ||
} | ||
else | ||
{ | ||
for(auto it = mpInitlist[group].begin();it != mpInitlist[group].end();++it) | ||
{ | ||
if (it->strNickName == nickname) | ||
{ | ||
it->intValue = value; | ||
return; | ||
} | ||
} | ||
mpInitlist[group].push_back(INIT{ nickname,value }); | ||
} | ||
} | ||
|
||
void Initlist::show(long long group, std::string &strMAns) | ||
{ | ||
if (!mpInitlist.count(group)||mpInitlist[group].empty()) | ||
{ | ||
strMAns = "错误:请先使用.ri指令投掷先攻值"; | ||
return; | ||
} | ||
strMAns = "先攻顺序:"; | ||
sort(mpInitlist[group].begin(), mpInitlist[group].end(), INIT()); | ||
int i = 1; | ||
for (auto it = mpInitlist[group].begin(); it != mpInitlist[group].end(); ++it) | ||
{ | ||
strMAns += '\n' + to_string(i) + "." + it->strNickName + " " + to_string(it->intValue); | ||
++i; | ||
} | ||
} | ||
|
||
bool Initlist::clear(long long group) | ||
{ | ||
if (mpInitlist.count(group)) | ||
{ | ||
mpInitlist.erase(group); | ||
return true; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
*Dice! QQ dice robot for TRPG game | ||
*Copyright (C) 2018 w4123ËÝä§ | ||
* | ||
*This program is free software: you can redistribute it and/or modify it under the terms | ||
*of the GNU Affero General Public License as published by the Free Software Foundation, | ||
*either version 3 of the License, or (at your option) any later version. | ||
* | ||
*This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
*without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
*See the GNU Affero General Public License for more details. | ||
* | ||
*You should have received a copy of the GNU Affero General Public License along with this | ||
*program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#pragma once | ||
#ifndef __INIT__ | ||
#define __INIT__ | ||
#include <string> | ||
#include <map> | ||
#include <vector> | ||
|
||
struct INIT { | ||
std::string strNickName; | ||
int intValue; | ||
bool operator()(INIT first, INIT second) const { | ||
return first.intValue>second.intValue; | ||
} | ||
}; | ||
|
||
class Initlist | ||
{ | ||
std::map<long long, std::vector<INIT>> mpInitlist; | ||
public: | ||
void insert(long long group, int value, std::string nickname); | ||
void show(long long group, std::string &strMAns); | ||
bool clear(long long group); | ||
}; | ||
|
||
|
||
#endif /*__INIT__*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters