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 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<std::string> getLog();
|
||||
|
||||
|
|
|
@ -47,4 +47,11 @@ public:
|
|||
private:
|
||||
void stopJoinThread();
|
||||
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 {};
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -100,6 +100,82 @@ void LolAutoAccept::innerRun() {
|
|||
}
|
||||
}
|
||||
} else if(phase == ClientAPI::GameflowPhase::CHAMPSELECT) {
|
||||
champSelect();
|
||||
}
|
||||
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> dur = (end-start);
|
||||
//if(dur.count() > 1e-5)
|
||||
Log::info << "iteration took: " << (dur.count() * 1000) << " ms";
|
||||
|
||||
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;
|
||||
|
||||
|
@ -117,52 +193,18 @@ void LolAutoAccept::innerRun() {
|
|||
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);
|
||||
}
|
||||
}
|
||||
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 || 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(session.timer.phase == ClientAPI::ChampSelectPhase::PLANNING) {
|
||||
prepickPhase(ownactions);
|
||||
} else if(session.timer.phase == ClientAPI::ChampSelectPhase::BAN_PICK) {
|
||||
// ban and pick phase
|
||||
Log::info << "ban-pick phase";
|
||||
banPhase(ownactions);
|
||||
pickPhase(ownactions);
|
||||
} else if(session.timer.phase == ClientAPI::ChampSelectPhase::FINALIZATION) {
|
||||
// trade?
|
||||
Log::info << "trade phase";
|
||||
}
|
||||
}
|
||||
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> dur = (end-start);
|
||||
//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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue