applying runes working
This commit is contained in:
parent
4bcdf80fab
commit
c03b123af0
|
@ -13,7 +13,8 @@ public:
|
|||
struct ChampionInfo {
|
||||
std::vector<uint32_t> skillorder;
|
||||
std::vector<uint32_t> runes;
|
||||
uint32_t primaryRune = 0;
|
||||
uint32_t primaryRuneStyle = 0;
|
||||
uint32_t secondaryRuneStyle = 0;
|
||||
|
||||
// items?
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ protected:
|
|||
BlitzAPI blitzapi;
|
||||
std::vector<RuneAspekt> runeaspekts;
|
||||
|
||||
bool nextApplyRunes = false;
|
||||
|
||||
public:
|
||||
enum class State {
|
||||
LOBBY = 0,
|
||||
|
@ -81,5 +83,6 @@ private:
|
|||
void banPhase(const ownactions_t& ownactions, const ClientAPI::ChampSelectSession& session);
|
||||
void pickPhase(const ownactions_t& ownactions);
|
||||
void phase(const ownactions_t& ownactions, ClientAPI::ChampSelectActionType type, State s, bool complete, std::function<bool(uint32_t)> filter = {});
|
||||
static int32_t getBestRunePage(const std::vector<ClientAPI::RunePage>& allpages);
|
||||
void champSelect();
|
||||
};
|
|
@ -18,8 +18,6 @@ BlitzAPI::BlitzAPI() : RestClient("https://league-champion-aggregate.iesdev.com/
|
|||
|
||||
BlitzAPI::ChampionInfo::ChampionInfo() {}
|
||||
BlitzAPI::ChampionInfo::ChampionInfo(const QJsonObject& json) {
|
||||
primaryRune = getValue<uint32_t>(json, "primaryRune");
|
||||
|
||||
// kill order stuff
|
||||
auto skillordersref = json["skillOrders"];
|
||||
if(skillordersref.isArray()) {
|
||||
|
@ -43,20 +41,36 @@ BlitzAPI::ChampionInfo::ChampionInfo(const QJsonObject& json) {
|
|||
}
|
||||
|
||||
// runes
|
||||
// TODO: create a diffrent algorithm to choose wich runes should be picked, insted of just the first one
|
||||
QJsonValue runesarrref = json["runes"];
|
||||
if(runesarrref.isArray()) {
|
||||
QJsonArray runesarr = runesarrref.toArray();
|
||||
runes.reserve(runesarr.size());
|
||||
runes.resize(9, 0);// a list of runes, that are taken (the first one is a speare for the primary one)
|
||||
for(auto it : runesarr) {
|
||||
if(!it.isObject()) continue;
|
||||
|
||||
QJsonObject rune = it.toObject();
|
||||
auto runeid = rune["runeId"];
|
||||
if(runeid.isDouble()) {
|
||||
runes.push_back(runeid.toDouble());
|
||||
uint32_t index = rune["index"].toInt();
|
||||
if(index <= 7) {
|
||||
if(runes.at(index+1) == 0) { // index not set yet
|
||||
auto runeid = rune["runeId"];
|
||||
if(runeid.isDouble()) {
|
||||
runes.at(index+1) = runeid.toDouble();
|
||||
Log::debug << "found rune: index: " << index << " +1 set to: " << runes.at(index+1);
|
||||
|
||||
if(index == 0) {
|
||||
primaryRuneStyle = rune["treeId"].toInt();
|
||||
} else if(index == 3) {
|
||||
secondaryRuneStyle = rune["treeId"].toInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add the primary rune
|
||||
runes.at(0) = getValue<uint32_t>(json, "primaryRune");
|
||||
}
|
||||
|
||||
BlitzAPI::ChampionInfo BlitzAPI::getChampionInfo(uint32_t championID, Position p, uint32_t enemyChampionID) {
|
||||
|
|
|
@ -184,7 +184,7 @@ std::vector<ClientAPI::RunePage> ClientAPI::getAllRunePages() {
|
|||
std::vector<RunePage> out;
|
||||
out.reserve(arr.size());
|
||||
for(auto it : arr) {
|
||||
if(!it.isObject()) {
|
||||
if(it.isObject()) {
|
||||
out.push_back((RunePage) it.toObject());
|
||||
}
|
||||
}
|
||||
|
@ -205,7 +205,6 @@ bool ClientAPI::selectRunePage(uint64_t id) {
|
|||
bool ClientAPI::editRunePage(const RunePage& page) {
|
||||
QJsonObject pagereq;
|
||||
|
||||
pagereq["id"] = (int) page.id;
|
||||
pagereq["name"] = QString::fromStdString(page.name);
|
||||
pagereq["primaryStyleId"] = (int) page.primaryStyleID;
|
||||
pagereq["subStyleId"] = (int) page.subStyleID;
|
||||
|
@ -218,7 +217,9 @@ bool ClientAPI::editRunePage(const RunePage& page) {
|
|||
pagereq["selectedPerkIds"] = selected;
|
||||
|
||||
QJsonDocument reqdoc(pagereq);
|
||||
QJsonDocument doc = request("lol-perks/v1/pages", Method::POST, reqdoc.toJson().toStdString());
|
||||
const std::string requestdocstr = reqdoc.toJson(QJsonDocument::JsonFormat::Compact).toStdString();
|
||||
Log::info << "requeststr: " << requestdocstr;
|
||||
QJsonDocument doc = request("lol-perks/v1/pages/" + std::to_string(page.id), Method::PUT, requestdocstr);
|
||||
|
||||
if(doc.isEmpty()) return true; // ok
|
||||
|
||||
|
|
|
@ -84,8 +84,7 @@ const std::vector<RuneAspekt>& LolAutoAccept::getRuneAspekts() {
|
|||
}
|
||||
|
||||
void LolAutoAccept::applyRunes() {
|
||||
// TODO
|
||||
Log::warn << "LolAutoAccept::applyRunes() not implemented";
|
||||
nextApplyRunes = true;
|
||||
}
|
||||
|
||||
void LolAutoAccept::stopJoinThread() {
|
||||
|
@ -282,6 +281,30 @@ void LolAutoAccept::phase(const ownactions_t& ownactions, ClientAPI::ChampSelect
|
|||
}
|
||||
}
|
||||
|
||||
int32_t LolAutoAccept::getBestRunePage(const std::vector<ClientAPI::RunePage>& pages) {
|
||||
Log::debug << "searching RunePages: " << pages.size();
|
||||
for(uint32_t i = 0; i < pages.size(); ++i) {
|
||||
Log::debug << i << ": " << pages[i].id << " " << pages[i].name << " " << pages[i].isCurrent;
|
||||
}
|
||||
|
||||
// search for a rune page with a name that starts with "AA: "
|
||||
for(uint32_t i = 0; i < pages.size(); ++i) {
|
||||
const ClientAPI::RunePage& rp = pages.at(i);
|
||||
if(rp.name.size() >= 4 && rp.name.substr(4) == "AA: ") {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
// search for a selected rune page
|
||||
for(uint32_t i = 0; i < pages.size(); ++i) {
|
||||
const ClientAPI::RunePage& rp = pages.at(i);
|
||||
if(rp.isCurrent) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void LolAutoAccept::champSelect() {
|
||||
auto session = clientapi->getChampSelectSession();
|
||||
int32_t cellid = session.localPlayerCellId;
|
||||
|
@ -312,8 +335,8 @@ void LolAutoAccept::champSelect() {
|
|||
// update runes
|
||||
if(onRuneschange) {
|
||||
auto champinfo = blitzapi.getChampionInfo(pickedChamp, pos); // TODO: add detection for enemy champ
|
||||
Log::info << "champinfo aquired: " << champinfo.runes.size() << " runes primary: " << champinfo.primaryRune;
|
||||
onRuneschange(champinfo.runes, champinfo.primaryRune, 0); //
|
||||
Log::info << "champinfo aquired: " << champinfo.runes.size() << " runes primary style: " << champinfo.primaryRuneStyle;
|
||||
onRuneschange(champinfo.runes, champinfo.primaryRuneStyle, champinfo.secondaryRuneStyle); //
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,4 +366,40 @@ void LolAutoAccept::champSelect() {
|
|||
} else if(session.timer.phase == ClientAPI::ChampSelectPhase::FINALIZATION) {
|
||||
// trade?
|
||||
}
|
||||
|
||||
if(nextApplyRunes) {
|
||||
nextApplyRunes = false;
|
||||
Log::note << "apply runes";
|
||||
|
||||
// choose page
|
||||
auto pages = clientapi->getAllRunePages();
|
||||
int32_t pageoffset = getBestRunePage(pages);
|
||||
|
||||
if(pageoffset < 0) {
|
||||
Log::warn << "no rune page found!";
|
||||
return;
|
||||
}
|
||||
ClientAPI::RunePage& rp = pages.at(pageoffset);
|
||||
Log::info << "replace runepage id: " << rp.id << " old-name: " << rp.name;
|
||||
|
||||
auto champinfo = blitzapi.getChampionInfo(pickedChamp, pos);
|
||||
|
||||
Log::info << "fetched champion info runes: " << champinfo.runes.size();
|
||||
|
||||
ClientAPI::RunePage newpage;
|
||||
newpage.id = rp.id;
|
||||
newpage.name = "AA: " + std::to_string(pickedChamp) + " " + toString(pos); // TODO: resolve champname? add role?
|
||||
newpage.selectedPerkIDs = champinfo.runes;
|
||||
newpage.primaryStyleID = champinfo.primaryRuneStyle;
|
||||
newpage.subStyleID = champinfo.secondaryRuneStyle;
|
||||
clientapi->editRunePage(newpage);
|
||||
|
||||
//select runepage
|
||||
if(!rp.isCurrent) {
|
||||
Log::info << "page is not selected, selecting now (id: " << newpage.id << ')';
|
||||
clientapi->selectRunePage(newpage.id);
|
||||
}
|
||||
|
||||
Log::info << "runepage done";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ QByteArray RestClient::requestRaw(const std::string& url, Method m, const std::s
|
|||
headerlist = curl_slist_append(headerlist, "Content-Type: application/json");
|
||||
break;
|
||||
case Method::PUT:
|
||||
curl_easy_setopt(curl, CURLOPT_PUT, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); // to use the POSTFIELDS (do not use CURLOPT_PUT, it does not support POSTFIELDS)
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
|
||||
headerlist = curl_slist_append(headerlist, "Content-Type: application/json");
|
||||
break;
|
||||
|
|
|
@ -208,6 +208,22 @@
|
|||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>applyRunesBtn</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>applyRunes()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>349</x>
|
||||
<y>571</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>476</x>
|
||||
<y>577</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<signal>requestTabChange(int)</signal>
|
||||
|
@ -215,5 +231,6 @@
|
|||
<slot>tabtoggled(Position, LolAutoAccept::State, bool)</slot>
|
||||
<slot>tabchanged(Position, LolAutoAccept::State)</slot>
|
||||
<slot>toggleMainswitch(bool)</slot>
|
||||
<slot>applyRunes()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
|
Loading…
Reference in New Issue
Block a user