picking and banning of multiple champions working

This commit is contained in:
mrbesen 2022-07-03 12:01:51 +02:00
parent 4de7c57a46
commit 9e95bd6562
Signed by untrusted user: MrBesen
GPG Key ID: 596B2350DCD67504
3 changed files with 54 additions and 41 deletions

View File

@ -49,12 +49,14 @@ private:
void innerRun();
void resetAllOffsets();
uint32_t getNextChampOfState(State s);
uint32_t getChampOfState(State s);
void nextChampOfState(State s);
using ownactions_t = std::vector<ClientAPI::ChampSelectAction>;
ownactions_t getOwnActions(int32_t cellid, const std::vector<ClientAPI::ChampSelectAction> actions);
void prepickPhase(const ownactions_t& ownactions);
void banPhase(const ownactions_t& ownactions);
void pickPhase( const ownactions_t& ownactions);
void pickPhase(const ownactions_t& ownactions);
void phase(const ownactions_t& ownactions, ClientAPI::ChampSelectActionType type, State s, bool complete);
void champSelect();
};

View File

@ -64,11 +64,24 @@ bool ClientAPI::setChampSelectAction(int32_t actionid, int32_t champid, bool com
requestj["id"] = actionid;
QJsonDocument requestdoc(requestj);
const std::string requeststr = requestdoc.toJson(QJsonDocument::JsonFormat::Compact).toStdString();
Log::debug << "requeststr: " << std::quoted(requeststr);
Log::debug << "requeststr: " << requeststr;
QJsonDocument doc = request("lol-champ-select/v1/session/actions/" + std::to_string(actionid), Method::PATCH, requeststr);
Log::info << "patching action: " << actionid << " result: " << doc.toJson().toStdString();
return true;
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();
}
}
Log::note << "patching action: " << actionid << " error: " << error;
return error.empty();
}
ClientAPI::PlayerInfo ClientAPI::getSelf() {

View File

@ -76,6 +76,7 @@ void LolAutoAccept::stopJoinThread() {
if(lolaathread.joinable()) {
lolaathread.join();
}
resetAllOffsets();
}
void LolAutoAccept::innerRun() {
@ -118,20 +119,37 @@ void LolAutoAccept::resetAllOffsets() {
}
}
uint32_t LolAutoAccept::getNextChampOfState(State s) {
uint32_t LolAutoAccept::getChampOfState(State s) {
assert(((int) s) >= 0 && s <= State::PICK);
auto stage = stages[(int) s];
int size = stage->champids.size();
if(size >= stage->currentOffset) {
if(stage->currentOffset >= size) {
// no champ to try left
Log::warn << "no champ left at stage: " << (int) s;
Log::warn << "stage size: " << stage->champids.size();
stage->currentOffset = 0;
return 0;
}
return stage->champids[stage->currentOffset++];
return stage->champids[stage->currentOffset];
}
void LolAutoAccept::nextChampOfState(State s) {
assert(((int) s) >= 0 && s <= State::PICK);
auto stage = stages[(int) s];
int size = stage->champids.size();
stage->currentOffset++;
if(stage->currentOffset >= size) {
// no champ to try left
Log::warn << "no champ left at stage: " << (int) s;
Log::warn << "stage size: " << stage->champids.size();
stage->currentOffset = 0;
return;
}
}
LolAutoAccept::ownactions_t LolAutoAccept::getOwnActions(int32_t cellid, const std::vector<ClientAPI::ChampSelectAction> actions) {
@ -148,49 +166,29 @@ LolAutoAccept::ownactions_t LolAutoAccept::getOwnActions(int32_t cellid, const s
}
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 = getNextChampOfState(State::PREPICK);
Log::info << "try to prepick champ: " << champid;
clientapi->setChampSelectAction(it.id, champid, false);
break;
}
}
}
phase(ownactions, ClientAPI::ChampSelectActionType::PICK, State::PREPICK, false);
}
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 = getNextChampOfState(State::BAN);
Log::info << "try to ban champ: " << champid;
clientapi->setChampSelectAction(it.id, champid, true);
return;
}
}
}
phase(ownactions, ClientAPI::ChampSelectActionType::BAN, State::BAN, true);
}
void LolAutoAccept::pickPhase(const ownactions_t& ownactions) {
Log::info << "pick phase";
phase(ownactions, ClientAPI::ChampSelectActionType::PICK, State::PICK, true);
}
void LolAutoAccept::phase(const ownactions_t& ownactions, ClientAPI::ChampSelectActionType type, State s, bool complete) {
Log::note << type << " phase";
for(auto it : ownactions) {
if(it.type == ClientAPI::ChampSelectActionType::PICK) {
Log::info << "pick action anvailable: " << it.id << " champid: " << it.championID;
uint32_t champid = getNextChampOfState(State::PICK);
if(it.type == type) {
Log::info << type << " action anvailable: " << it.id << " champid: " << it.championID;
uint32_t champid = getChampOfState(s);
if(it.championID != champid || !it.completed) {
// try to prepick a champion
Log::info << "try to pick champ: " << champid;
clientapi->setChampSelectAction(it.id, champid, true);
clientapi->setChampSelectAction(it.id, champid, complete);
nextChampOfState(s);
return;
}
}