forked from MrBesen/lolautoaccept
smite warning
This commit is contained in:
parent
0d43798a1c
commit
58795ad66e
|
@ -97,6 +97,8 @@ public:
|
||||||
int32_t championID = 0;
|
int32_t championID = 0;
|
||||||
int32_t championPickIntentID = 0;
|
int32_t championPickIntentID = 0;
|
||||||
int64_t summonerID = 0;
|
int64_t summonerID = 0;
|
||||||
|
int64_t spell1Id = 0; // 4 = flash, 6 = ghost, 7 = heal, 11 = smite, 12 = teleport, 14 = ignite
|
||||||
|
int64_t spell2Id = 0;
|
||||||
|
|
||||||
ChampSelectCell();
|
ChampSelectCell();
|
||||||
explicit ChampSelectCell(const QJsonObject& json);
|
explicit ChampSelectCell(const QJsonObject& json);
|
||||||
|
@ -148,6 +150,37 @@ public:
|
||||||
explicit RunePage(const QJsonObject& json);
|
explicit RunePage(const QJsonObject& json);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Message {
|
||||||
|
std::string body;
|
||||||
|
std::string fromId;
|
||||||
|
std::string fromPid;
|
||||||
|
int64_t fromSummonerId;
|
||||||
|
std::string id;
|
||||||
|
bool isHistorical;
|
||||||
|
std::string timestamp;
|
||||||
|
std::string type; // known types: chat (1:1), customGame, championSelect, groupchat
|
||||||
|
|
||||||
|
Message();
|
||||||
|
explicit Message(const QJsonObject& json);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Conversation {
|
||||||
|
std::string gameName;
|
||||||
|
std::string gameTag;
|
||||||
|
std::string id;
|
||||||
|
bool isMuted;
|
||||||
|
std::shared_ptr<Message> lastMessage;
|
||||||
|
std::string name;
|
||||||
|
std::string password;
|
||||||
|
std::string pid;
|
||||||
|
std::string targetRegion;
|
||||||
|
std::string type;
|
||||||
|
int64_t unreadMessageCount;
|
||||||
|
|
||||||
|
Conversation();
|
||||||
|
explicit Conversation(const QJsonObject& json);
|
||||||
|
};
|
||||||
|
|
||||||
ClientAPI(const ClientAccess& access);
|
ClientAPI(const ClientAccess& access);
|
||||||
~ClientAPI();
|
~ClientAPI();
|
||||||
|
|
||||||
|
@ -164,6 +197,10 @@ public:
|
||||||
|
|
||||||
TimerInfo getTimerInfo();
|
TimerInfo getTimerInfo();
|
||||||
|
|
||||||
|
// chats
|
||||||
|
std::vector<Conversation> getAllConversations();
|
||||||
|
Message sendMessage(const std::string& chatid, const std::string& messagebody);
|
||||||
|
|
||||||
// rune stuff
|
// rune stuff
|
||||||
RunePage getCurrentRunePage();
|
RunePage getCurrentRunePage();
|
||||||
std::vector<RunePage> getAllRunePages();
|
std::vector<RunePage> getAllRunePages();
|
||||||
|
|
|
@ -49,6 +49,9 @@ protected:
|
||||||
|
|
||||||
bool nextApplyRunes = false;
|
bool nextApplyRunes = false;
|
||||||
|
|
||||||
|
std::string chatid; // the chatid of the chat from the champselect
|
||||||
|
std::chrono::time_point<std::chrono::system_clock> lastMessageSent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class State {
|
enum class State {
|
||||||
LOBBY = 0,
|
LOBBY = 0,
|
||||||
|
@ -96,5 +99,7 @@ private:
|
||||||
static int32_t getBestRunePage(const std::vector<ClientAPI::RunePage>& allpages);
|
static int32_t getBestRunePage(const std::vector<ClientAPI::RunePage>& allpages);
|
||||||
static int32_t getMatchingRunePage(const RunePage& rp, const std::vector<ClientAPI::RunePage>& allpages);
|
static int32_t getMatchingRunePage(const RunePage& rp, const std::vector<ClientAPI::RunePage>& allpages);
|
||||||
void champSelect();
|
void champSelect();
|
||||||
|
void smiteWarning(const std::vector<ClientAPI::ChampSelectCell>& cells);
|
||||||
|
const std::string& getChatid();
|
||||||
void applyRunes_internal(uint32_t champid, Position pos);
|
void applyRunes_internal(uint32_t champid, Position pos);
|
||||||
};
|
};
|
||||||
|
|
|
@ -148,6 +148,53 @@ ClientAPI::TimerInfo ClientAPI::getTimerInfo() {
|
||||||
return (TimerInfo) obj;
|
return (TimerInfo) obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<ClientAPI::Conversation> ClientAPI::getAllConversations() {
|
||||||
|
std::vector<Conversation> out;
|
||||||
|
QJsonDocument doc = request("lol-chat/v1/conversations");
|
||||||
|
if(doc.isArray()) {
|
||||||
|
QJsonArray arr = doc.array();
|
||||||
|
out.reserve(arr.size());
|
||||||
|
|
||||||
|
for(auto elem : arr) {
|
||||||
|
if(elem.isObject()) {
|
||||||
|
out.push_back((Conversation) elem.toObject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientAPI::Message ClientAPI::sendMessage(const std::string& chatid, const std::string& messagebody) {
|
||||||
|
QJsonObject requestj;
|
||||||
|
requestj["body"] = QString::fromStdString(messagebody);
|
||||||
|
QJsonDocument requestdoc(requestj);
|
||||||
|
const std::string requeststr = requestdoc.toJson(QJsonDocument::JsonFormat::Compact).toStdString();
|
||||||
|
Log::debug << "requeststr: " << requeststr;
|
||||||
|
QJsonDocument doc = request("lol-chat/v1/conversations/" + chatid + "/messages", Method::POST, requeststr);
|
||||||
|
|
||||||
|
std::string error;
|
||||||
|
if(doc.isObject()) {
|
||||||
|
QJsonObject obj = doc.object();
|
||||||
|
auto errref = obj["errorCode"];
|
||||||
|
auto msgref = obj["message"];
|
||||||
|
if(errref.isString()) {
|
||||||
|
error = errref.toString().toStdString() + " ";
|
||||||
|
}
|
||||||
|
if(msgref.isString()) {
|
||||||
|
error += msgref.toString().toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(error.empty()) {
|
||||||
|
return (Message) obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::note << "send message error: " << error;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ClientAPI::RunePage ClientAPI::getCurrentRunePage() {
|
ClientAPI::RunePage ClientAPI::getCurrentRunePage() {
|
||||||
QJsonDocument doc = request("lol-perks/v1/currentpage");
|
QJsonDocument doc = request("lol-perks/v1/currentpage");
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,8 @@ ClientAPI::ChampSelectCell::ChampSelectCell(const QJsonObject& json) {
|
||||||
championID = getValue<int32_t>(json, "championId");
|
championID = getValue<int32_t>(json, "championId");
|
||||||
championPickIntentID = getValue<int32_t>(json, "championPickIntent");
|
championPickIntentID = getValue<int32_t>(json, "championPickIntent");
|
||||||
summonerID = getValue<int32_t>(json, "summonerId");
|
summonerID = getValue<int32_t>(json, "summonerId");
|
||||||
|
spell1Id = getValue<int64_t>(json, "spell1Id", 0);
|
||||||
|
spell2Id = getValue<int64_t>(json, "spell2Id", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ClientAPI::ChampSelectCell> ClientAPI::loadAllInfos(const QJsonArray& arr) {
|
std::vector<ClientAPI::ChampSelectCell> ClientAPI::loadAllInfos(const QJsonArray& arr) {
|
||||||
|
@ -226,10 +228,42 @@ RuneAspekt::RuneAspekt(const QJsonObject& json) {
|
||||||
iconPath = getValue<std::string>(json, "iconPath");
|
iconPath = getValue<std::string>(json, "iconPath");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClientAPI::Message::Message() {}
|
||||||
|
ClientAPI::Message::Message(const QJsonObject& json) {
|
||||||
|
body = getValue<std::string>(json, "body");
|
||||||
|
fromId = getValue<std::string>(json, "fromId");
|
||||||
|
fromPid = getValue<std::string>(json, "fromPid");
|
||||||
|
fromSummonerId = getValue<int64_t>(json, "fromSummonerId");
|
||||||
|
id = getValue<std::string>(json, "id");
|
||||||
|
isHistorical = getValue<bool>(json, "isHistorical", true);
|
||||||
|
timestamp = getValue<std::string>(json, "timestamp");
|
||||||
|
type = getValue<std::string>(json, "type");
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientAPI::Conversation::Conversation() {}
|
||||||
|
ClientAPI::Conversation::Conversation(const QJsonObject& json) : lastMessage(nullptr) {
|
||||||
|
gameName = getValue<std::string>(json, "gameName");
|
||||||
|
gameTag = getValue<std::string>(json, "gameTag");
|
||||||
|
id = getValue<std::string>(json, "id");
|
||||||
|
isMuted = getValue<bool>(json, "isMuted");
|
||||||
|
name = getValue<std::string>(json, "name");
|
||||||
|
password = getValue<std::string>(json, "password");
|
||||||
|
pid = getValue<std::string>(json, "pid");
|
||||||
|
targetRegion = getValue<std::string>(json, "targetRegion");
|
||||||
|
type = getValue<std::string>(json, "type");
|
||||||
|
unreadMessageCount = getValue<int64_t>(json, "unreadMessageCount");
|
||||||
|
|
||||||
|
auto msgref = json["lastMessage"];
|
||||||
|
if(msgref.isObject()) {
|
||||||
|
lastMessage = std::make_shared<Message>(msgref.toObject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define PRINTENUM(ENUMNAME) \
|
#define PRINTENUM(ENUMNAME) \
|
||||||
std::ostream& operator<<(std::ostream& str, const ClientAPI:: ENUMNAME & state) { \
|
std::ostream& operator<<(std::ostream& str, const ClientAPI:: ENUMNAME & state) { \
|
||||||
assert(((int) state) < ENUMNAME ## NamesCount); \
|
assert(((uint32_t) state) < ENUMNAME ## NamesCount); \
|
||||||
return str << ENUMNAME ## Names[(int) state] << " (" << (int) state << ')'; \
|
return str << ENUMNAME ## Names[(uint32_t) state] << " (" << (uint32_t) state << ')'; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -238,7 +272,8 @@ PRINTENUM(GameflowPhase)
|
||||||
PRINTENUM(ChampSelectPhase)
|
PRINTENUM(ChampSelectPhase)
|
||||||
PRINTENUM(ChampSelectActionType)
|
PRINTENUM(ChampSelectActionType)
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& str, const Position & state) { \
|
// not using macro because its not in ClientAPI
|
||||||
assert(((int) state) < PositionNamesCount); \
|
std::ostream& operator<<(std::ostream& str, const Position & state) {
|
||||||
return str << PositionNames[(int) state] << " (" << (int) state << ')'; \
|
assert(((uint32_t) state) < PositionNamesCount);
|
||||||
|
return str << PositionNames[(uint32_t) state] << " (" << (uint32_t) state << ')';
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,9 @@ void LolAutoAccept::stopJoinThread() {
|
||||||
void LolAutoAccept::innerRun() {
|
void LolAutoAccept::innerRun() {
|
||||||
shouldrun = true;
|
shouldrun = true;
|
||||||
|
|
||||||
|
auto convs = clientapi->getAllConversations();
|
||||||
|
Log::info << "got " << convs.size() << " conversations";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while(shouldrun) {
|
while(shouldrun) {
|
||||||
uint32_t extrasleep = 800;
|
uint32_t extrasleep = 800;
|
||||||
|
@ -199,6 +202,7 @@ void LolAutoAccept::resetAllOffsets() {
|
||||||
currentPosition = Position::INVALID;
|
currentPosition = Position::INVALID;
|
||||||
currentPositionSet = false;
|
currentPositionSet = false;
|
||||||
lastPickedChamp = 0;
|
lastPickedChamp = 0;
|
||||||
|
chatid.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LolAutoAccept::resetRunes() {
|
void LolAutoAccept::resetRunes() {
|
||||||
|
@ -424,6 +428,9 @@ void LolAutoAccept::champSelect() {
|
||||||
pickPhase(ownactions);
|
pickPhase(ownactions);
|
||||||
} else if(session.timer.phase == ClientAPI::ChampSelectPhase::FINALIZATION) {
|
} else if(session.timer.phase == ClientAPI::ChampSelectPhase::FINALIZATION) {
|
||||||
// trade?
|
// trade?
|
||||||
|
|
||||||
|
// check for smite
|
||||||
|
smiteWarning(session.myTeam);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nextApplyRunes) {
|
if(nextApplyRunes) {
|
||||||
|
@ -431,6 +438,46 @@ void LolAutoAccept::champSelect() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LolAutoAccept::smiteWarning(const std::vector<ClientAPI::ChampSelectCell>& cells) {
|
||||||
|
uint32_t smiteCount = 0;
|
||||||
|
for(const ClientAPI::ChampSelectCell& member : cells) {
|
||||||
|
Log::info << "position: " << member.position << " spells: " << member.spell1Id << " " << member.spell2Id;
|
||||||
|
smiteCount += (member.spell1Id == 11 || member.spell2Id == 11);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(smiteCount != 1) {
|
||||||
|
// check timeout
|
||||||
|
std::chrono::time_point<std::chrono::system_clock> currenttime = std::chrono::system_clock::now();
|
||||||
|
if((currenttime - lastMessageSent) < std::chrono::seconds(2)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::info << "smite warning: " << smiteCount;
|
||||||
|
const std::string& chatid = getChatid();
|
||||||
|
if(!chatid.empty()) {
|
||||||
|
clientapi->sendMessage(chatid, "smite");
|
||||||
|
lastMessageSent = currenttime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& LolAutoAccept::getChatid() {
|
||||||
|
if(chatid.empty()) {
|
||||||
|
std::vector<ClientAPI::Conversation> convs = clientapi->getAllConversations();
|
||||||
|
Log::info << "got " << convs.size() << " conversations";
|
||||||
|
|
||||||
|
for(const ClientAPI::Conversation& conv : convs) {
|
||||||
|
Log::info << " id: " << conv.id << " type: " << conv.type << " name: " << conv.name << " gameName: " << conv.gameName;
|
||||||
|
if(conv.type == "championSelect" && conv.name.empty()) {
|
||||||
|
Log::info << "groupchat found";
|
||||||
|
chatid = conv.id;
|
||||||
|
return chatid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return chatid; //might be empty string
|
||||||
|
}
|
||||||
|
|
||||||
void LolAutoAccept::applyRunes_internal(uint32_t champid, Position pos) {
|
void LolAutoAccept::applyRunes_internal(uint32_t champid, Position pos) {
|
||||||
nextApplyRunes = false;
|
nextApplyRunes = false;
|
||||||
Log::note << "apply runes";
|
Log::note << "apply runes";
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 96d10d6e72ddaffd8b688db5ef2705e38aff3a75
|
Subproject commit 5bf9e688b125ac042292d8f554711d7337fe88c0
|
Loading…
Reference in New Issue