forked from MrBesen/lolautoaccept
pick and ban working
This commit is contained in:
parent
9e0b15cff2
commit
5ac909e53a
|
@ -145,7 +145,7 @@ public:
|
||||||
void acceptMatch();
|
void acceptMatch();
|
||||||
void declineMatch();
|
void declineMatch();
|
||||||
ChampSelectSession getChampSelectSession();
|
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();
|
PlayerInfo getSelf();
|
||||||
std::vector<std::string> getLog();
|
std::vector<std::string> getLog();
|
||||||
|
|
||||||
|
|
|
@ -47,4 +47,11 @@ public:
|
||||||
private:
|
private:
|
||||||
void stopJoinThread();
|
void stopJoinThread();
|
||||||
void innerRun();
|
void innerRun();
|
||||||
|
|
||||||
|
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 champSelect();
|
||||||
};
|
};
|
|
@ -57,14 +57,11 @@ ClientAPI::ChampSelectSession ClientAPI::getChampSelectSession() {
|
||||||
return {};
|
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;
|
QJsonObject requestj;
|
||||||
requestj["championId"] = champid;
|
requestj["championId"] = champid;
|
||||||
requestj["actorCellId"] = actorcellid;
|
|
||||||
requestj["completed"] = completed;
|
requestj["completed"] = completed;
|
||||||
requestj["id"] = actionid;
|
requestj["id"] = actionid;
|
||||||
requestj["isAllyAction"] = true;
|
|
||||||
requestj["type"] = pick ? "pick" : "ban";
|
|
||||||
QJsonDocument requestdoc(requestj);
|
QJsonDocument requestdoc(requestj);
|
||||||
const std::string requeststr = requestdoc.toJson(QJsonDocument::JsonFormat::Compact).toStdString();
|
const std::string requeststr = requestdoc.toJson(QJsonDocument::JsonFormat::Compact).toStdString();
|
||||||
Log::debug << "requeststr: " << std::quoted(requeststr);
|
Log::debug << "requeststr: " << std::quoted(requeststr);
|
||||||
|
|
|
@ -100,55 +100,7 @@ void LolAutoAccept::innerRun() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(phase == ClientAPI::GameflowPhase::CHAMPSELECT) {
|
} else if(phase == ClientAPI::GameflowPhase::CHAMPSELECT) {
|
||||||
auto session = clientapi->getChampSelectSession();
|
champSelect();
|
||||||
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<const ClientAPI::ChampSelectAction*> 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";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
@ -156,13 +108,103 @@ void LolAutoAccept::innerRun() {
|
||||||
//if(dur.count() > 1e-5)
|
//if(dur.count() > 1e-5)
|
||||||
Log::info << "iteration took: " << (dur.count() * 1000) << " ms";
|
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));
|
std::this_thread::sleep_for(std::chrono::milliseconds(1200));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LolAutoAccept::ownactions_t LolAutoAccept::getOwnActions(int32_t cellid, const std::vector<ClientAPI::ChampSelectAction> 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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue