From 5ac909e53a003cbebb2c90dc94aa7214022dbabd Mon Sep 17 00:00:00 2001 From: mrbesen Date: Sat, 2 Jul 2022 13:21:09 +0200 Subject: [PATCH] pick and ban working --- include/clientapi.h | 2 +- include/lolautoaccept.h | 7 ++ src/clientapi.cpp | 5 +- src/lolautoaccept.cpp | 154 +++++++++++++++++++++++++--------------- 4 files changed, 107 insertions(+), 61 deletions(-) diff --git a/include/clientapi.h b/include/clientapi.h index 9ce8d87..4171f79 100644 --- a/include/clientapi.h +++ b/include/clientapi.h @@ -145,7 +145,7 @@ public: void acceptMatch(); void declineMatch(); ChampSelectSession getChampSelectSession(); - bool setChampSelectAction(int32_t actionid, int32_t actorcellid, int32_t champid, bool completed, bool pick); + bool setChampSelectAction(int32_t actionid, int32_t champid, bool completed); PlayerInfo getSelf(); std::vector getLog(); diff --git a/include/lolautoaccept.h b/include/lolautoaccept.h index dd254aa..499b4a4 100644 --- a/include/lolautoaccept.h +++ b/include/lolautoaccept.h @@ -47,4 +47,11 @@ public: private: void stopJoinThread(); void innerRun(); + + using ownactions_t = std::vector; + ownactions_t getOwnActions(int32_t cellid, const std::vector actions); + void prepickPhase(const ownactions_t& ownactions); + void banPhase(const ownactions_t& ownactions); + void pickPhase( const ownactions_t& ownactions); + void champSelect(); }; \ No newline at end of file diff --git a/src/clientapi.cpp b/src/clientapi.cpp index 372ed20..bc6c112 100644 --- a/src/clientapi.cpp +++ b/src/clientapi.cpp @@ -57,14 +57,11 @@ ClientAPI::ChampSelectSession ClientAPI::getChampSelectSession() { return {}; } -bool ClientAPI::setChampSelectAction(int32_t actionid, int32_t actorcellid, int32_t champid, bool completed, bool pick) { +bool ClientAPI::setChampSelectAction(int32_t actionid, int32_t champid, bool completed) { QJsonObject requestj; requestj["championId"] = champid; - requestj["actorCellId"] = actorcellid; requestj["completed"] = completed; requestj["id"] = actionid; - requestj["isAllyAction"] = true; - requestj["type"] = pick ? "pick" : "ban"; QJsonDocument requestdoc(requestj); const std::string requeststr = requestdoc.toJson(QJsonDocument::JsonFormat::Compact).toStdString(); Log::debug << "requeststr: " << std::quoted(requeststr); diff --git a/src/lolautoaccept.cpp b/src/lolautoaccept.cpp index 34a2bf6..e42d746 100644 --- a/src/lolautoaccept.cpp +++ b/src/lolautoaccept.cpp @@ -100,55 +100,7 @@ void LolAutoAccept::innerRun() { } } } else if(phase == ClientAPI::GameflowPhase::CHAMPSELECT) { - auto session = clientapi->getChampSelectSession(); - int32_t cellid = session.localPlayerCellId; - - // find own cellid info - const ClientAPI::ChampSelectCell* me = nullptr; - for(const auto& it : session.myTeam) { - if(it.cellID == cellid) { - me = ⁢ - break; - } - } - - ClientAPI::Position pos = me ? me->position : ClientAPI::Position::INVALID; - - Log::info << "cellid: " << cellid << " position: " << pos << " counter: " << session.counter << " timer: timeleftip: " << session.timer.adjustedTimeLeftInPhase << " totaltimephase: " << session.timer.totalTimeInPhase; - - // find actions for own cell - std::vector ownactions; - for(const auto& it : session.actions) { - if(it.actorCellID == cellid) { - Log::debug << "ownaction: champid: " << it.championID << " completed: " << it.completed << " type: " << it.type; - ownactions.push_back(&it); - } - } - Log::note << "ownactions: " << ownactions.size(); - - // try to prepick champ - Log::info << "champselectphase: " << session.timer.phase; - if(session.timer.phase == ClientAPI::ChampSelectPhase::PLANNING || session.timer.phase == ClientAPI::ChampSelectPhase::BAN_PICK) { - Log::info << "prepick phase"; - for(auto it : ownactions) { - if(it->type == ClientAPI::ChampSelectActionType::PICK) { - Log::info << "pick action anvailable: " << it->id << "champid: " << it->championID; - if(it->championID == 0) { - // try to prepick a champion - uint32_t champid = stages.at((int) State::PREPICK)->champid; - Log::info << "try to prepick champ: " << champid; - clientapi->setChampSelectAction(it->id, cellid, champid, false, true); - break; - } - } - } - } else if(session.timer.phase == ClientAPI::ChampSelectPhase::BAN_PICK) { - // ban and pick phase - Log::info << "ban-pick phase"; - } else if(session.timer.phase == ClientAPI::ChampSelectPhase::FINALIZATION) { - // trade? - Log::info << "trade phase"; - } + champSelect(); } auto end = std::chrono::high_resolution_clock::now(); @@ -156,13 +108,103 @@ void LolAutoAccept::innerRun() { //if(dur.count() > 1e-5) Log::info << "iteration took: " << (dur.count() * 1000) << " ms"; - /* - auto logs = clientapi->getLog(); - for(const auto& l : logs) { - Log::note << "APILog: " << l; - } - */ - std::this_thread::sleep_for(std::chrono::milliseconds(1200)); } } + +LolAutoAccept::ownactions_t LolAutoAccept::getOwnActions(int32_t cellid, const std::vector actions) { + ownactions_t out; + for(const auto& it : actions) { + if(it.actorCellID == cellid) { + Log::debug << "ownaction: id: " << it.id << " champid: " << it.championID << " completed: " << it.completed << " type: " << it.type; + if(!it.completed) { // completed cant be interacted anyways, so just ignore them. + out.push_back(it); + } + } + } + return out; +} + +void LolAutoAccept::prepickPhase(const ownactions_t& ownactions) { + Log::info << "prepick phase"; + for(auto it : ownactions) { + if(it.type == ClientAPI::ChampSelectActionType::PICK) { + Log::info << "pre-pick action anvailable: " << it.id << " champid: " << it.championID; + if(it.championID == 0) { + // try to prepick a champion + uint32_t champid = stages.at((int) State::PREPICK)->champid; + Log::info << "try to prepick champ: " << champid; + clientapi->setChampSelectAction(it.id, champid, false); + break; + } + } + } +} + +void LolAutoAccept::banPhase(const ownactions_t& ownactions) { + Log::info << "ban phase"; + + for(auto it : ownactions) { + if(it.type == ClientAPI::ChampSelectActionType::BAN) { + Log::info << "ban action anvailable: " << it.id << " champid: " << it.championID; + if(it.championID == 0) { + // try to ban a champion + uint32_t champid = stages.at((int) State::BAN)->champid; + Log::info << "try to ban champ: " << champid; + clientapi->setChampSelectAction(it.id, champid, true); + return; + } + } + } +} + +void LolAutoAccept::pickPhase(const ownactions_t& ownactions) { + Log::info << "pick phase"; + + for(auto it : ownactions) { + if(it.type == ClientAPI::ChampSelectActionType::PICK) { + Log::info << "pick action anvailable: " << it.id << " champid: " << it.championID; + uint32_t champid = stages.at((int) State::PICK)->champid; + if(it.championID != champid || !it.completed) { + // try to prepick a champion + Log::info << "try to pick champ: " << champid; + clientapi->setChampSelectAction(it.id, champid, true); + return; + } + } + } +} + +void LolAutoAccept::champSelect() { + auto session = clientapi->getChampSelectSession(); + int32_t cellid = session.localPlayerCellId; + + // find own cellid info + const ClientAPI::ChampSelectCell* me = nullptr; + for(const auto& it : session.myTeam) { + if(it.cellID == cellid) { + me = ⁢ + break; + } + } + + ClientAPI::Position pos = me ? me->position : ClientAPI::Position::INVALID; + + Log::info << "cellid: " << cellid << " position: " << pos << " counter: " << session.counter << " timer: timeleftip: " << session.timer.adjustedTimeLeftInPhase << " totaltimephase: " << session.timer.totalTimeInPhase; + + // find actions for own cell + auto ownactions = getOwnActions(cellid, session.actions); + Log::note << "ownactions: " << ownactions.size(); + + // try to prepick champ + Log::info << "champselectphase: " << session.timer.phase; + if(session.timer.phase == ClientAPI::ChampSelectPhase::PLANNING) { + prepickPhase(ownactions); + } else if(session.timer.phase == ClientAPI::ChampSelectPhase::BAN_PICK) { + banPhase(ownactions); + pickPhase(ownactions); + } else if(session.timer.phase == ClientAPI::ChampSelectPhase::FINALIZATION) { + // trade? + Log::info << "trade phase"; + } +}