int MWBotWin::oilGameEscape() { qDebug() << "oil game escape"; QWebElement blk, tlm; blk = frm->findFirstElement("div#neftlenin_alert_mission div.content-block div.actions button.button div.c"); tlm = blk.findFirst("span.suspicion span.price_escape"); int need = 0; if (!tlm.isNull()) { need = tlm.toPlainText().toInt(); } qDebug() << "need" << need << "susp"; if (need == 0) { log(trUtf8("Патруль пройден успешно"),"neft.png"); fightResult(); clickElement(blk); } else { tlm = frm->findFirstElement("div.pipeline-actions table td.mc div.progress i.counter"); int susp = tlm.toPlainText().toInt(); if (!checkSusp(susp, need)) { clickElement(blk); log(trUtf8("Уходим от патруля за %0 подозрительности").arg(need),"neft.png"); doPause(2); } } return need; }
FightBox MWBotWin::getDuelResult() { FightBox res; int mylife; int enlife; QWebElement elm; res.enemy = getStat("div.fighter2","td.fighter2-cell"); clickElement("i.icon.icon-forward"); // forward button mylife = frm->findFirstElement("span#fighter1-life").toPlainText().split("/").first().trimmed().toInt(); enlife = frm->findFirstElement("span#fighter2-life").toPlainText().split("/").first().trimmed().toInt(); res.result = (mylife > 0) ? 1 : ((enlife > 0) ? 0 : 2); // duel result (0,1,2 = lose,win,draw) res.items = getDuelResultMain(); elm = frm->findFirstElement("div.backlink div.button div.c"); if (!elm.isNull()) { clickElement(elm); } res.items.append(getDuelResultExtra()); return res; }
void MWBotWin::checkPolice() { QWebElement elm = frm->findFirstElement("a.bubble span.text"); if (elm.toPlainText().contains(trUtf8("Задержан за бои"))) { loadPath(QStringList() << "square" << "police"); getFastRes(); if (!opt.police.fine || (info.ore < 5)) { if (state.botWork) start(); log(trUtf8("Вы задержаны. Бот остановлен")); } else { clickElement("form#fine-form div.button div.c"); log(trUtf8("Заплачен штраф в полиции")); } if (opt.police.relations && (info.ore > 20)) { elm = frm->findFirstElement("form.police-relations div.button div.c"); if (!elm.isNull()) { clickElement("form.police-relations div.button div.c"); log(trUtf8("Связи в полиции продлены")); } } } }
/** * Event handler */ int poll_event(Control* ui_tree) { SDL_Event e; while (SDL_PollEvent(&e) != 0) { switch (e.type) { case (SDL_QUIT): return 1; case (SDL_MOUSEBUTTONUP): return clickElement(ui_tree, e.button.x, e.button.y); break; default: break; } } SDL_Delay(15); return 0; }
FightBox MWBotWin::getGroupResult() { FightBox res; QWebElement elm; QString str; elm = frm->findFirstElement("form#fightGroupForm h3 div.group2"); str = elm.toPlainText(); res.enemy.name = str.split("(").first().trimmed(); res.enemy.type = elm.findFirst("i").attribute("class"); res.enemy.level = -1; res.result = str.contains("(0/") ? 1 : 0; res.items = getGroupResultMain(); elm = frm->findFirstElement("td.log div.result div.button div.c"); if (!elm.isNull()) { clickElement(elm); } res.items.append(getDuelResultExtra()); return res; }
/** * Find the element in the ui_tree containing the point x, y */ int clickElement(Control* ui_tree, int x, int y) { Link* head = ui_tree->children_head; int ret = -1; if ((ui_tree->x <= x) && (ui_tree->x + ui_tree->width >= x) && (ui_tree->y <= y) && (ui_tree->y + ui_tree->height >= y)) { if (head == NULL) { return ui_tree->on_select(ui_tree); } while ((ret == -1) && (head != NULL )) { ret = clickElement(head->value, x - ui_tree->x, y - ui_tree->y); head = head->next; } if (ret == -1) { return 0; } } return ret; }
void MWBotWin::atkRat() { QWebElement elm; setBusy(true); // go to page loadPath(QStringList() << "square" << "metro"); // select dark/normal rats elm = frm->findFirstElement("div.metro-branch div.metro-rats-light__dark-block"); if (!elm.isNull()) { log(trUtf8("Dark/Normal select"),"bug.png"); if (opt.ratk.dark) { elm = frm->findFirstElement("a.f[href='/metro/select/1/']"); } else { elm = frm->findFirstElement("a.f[href='/metro/select/0/']"); } elm = elm.findFirst("div.c"); if (elm.isNull()) { log(trUtf8("DEBUG: Rat selection error")); return; } clickElement(elm); } // check timer & atk rat int time = getRatTimer(); if (opt.ratk.ratlev > opt.ratk.maxlev) { elm = frm->findFirstElement("div#action-rat-fight div small small.dashedlink"); if (elm.isNull()) { time = 60; } else { time = elm.attribute("timer").toInt() + 60; } opt.ratk.time = QDateTime::currentDateTime().addSecs(time); opt.ratk.ratlev = 1; log(trUtf8("Хватит крыс. Ждём обвала. До обвала <b>%0</b> мин.").arg(time/60 + 1),"rat.png"); } else if (time < 1) { log(trUtf8("Уровень крысы: <b>%0</b>").arg(opt.ratk.ratlev),"rat.png"); restoreHP(); clickElement("div#action-rat-fight div.button-big div.c"); clickElement("div#welcome-rat button.button div.c"); if (opt.ratk.ratlev % 5 == 0) { groupFight(); } else { fightResult(); } getRatTimer(); } else { time += 30 + random() % 30; opt.ratk.time = QDateTime::currentDateTime().addSecs(time); log(trUtf8("До следующей крысы <b>%0</b> мин.").arg(time/60 + 1),"rat.png"); } // take tails prize elm = frm->findFirstElement("div.metro-branch table.collectbar td.actions button.button"); if (!elm.isNull()) { if (!elm.classes().contains("disabled")) { elm = elm.findFirst("div.c"); clickElement(elm); log(trUtf8("Получен приз за крысинные хвосты"),"rattail.png"); } } setBusy(false); }
void MWBotWin::doTaxi() { if (curTime.date().dayOfWeek() != 1) return; if (opt.taxi.time > curTime) return; QWebElement elm; QWebElement sub; int time; int count; int loop; setBusy(true); loadPage("arbat"); // check taxi chest and take it elm = frm->findFirstElement("div.auto-bombila table.collectbar td.actions button.button"); if (elm.isNull()) { count = 0; } else { count = elm.classes().contains("disabled") ? 0 : 1; } if (count) { sub = elm.findFirst("div.c"); clickElement(sub); log(trUtf8("Забран сундук бомбилы"),"chest.png"); } // check taxi timer, send a car & charge it if it needs elm = frm->findFirstElement("div.auto-bombila table.process td#cooldown"); if (elm.styleProperty("display",QWebElement::ComputedStyle) == "none") { time = 0; } else { time = elm.attribute("timer").toInt(); } if (time != 0) { time += (30 + (random() % 30)); opt.taxi.time = curTime.addSecs(time); log(trUtf8("До следующей бомбилки %0 сек").arg(time),"taxi.png"); } else { do { loop = 0; elm= frm->findFirstElement("div.auto-bombila table.action button.ride-button span.f div.c"); clickElement(elm); elm = frm->findFirstElement("div.alert.alert-error h2#alert-title"); if (elm.isNull()) { elm = frm->findFirstElement("div.auto-bombila table.process td#cooldown"); time = elm.attribute("timer").toInt(); time += 30 + random() % 30; opt.taxi.time = curTime.addSecs(time); log(trUtf8("Авто отправлено бомбить. До следующего раза %0 сек").arg(time),"taxi.png"); } else { elm = frm->findFirstElement("div.alert.alert-error div.actions div.button div.c"); sub = elm.findFirst("span"); count = sub.toPlainText().remove("\"").toInt(); getFastRes(); if (sub.classes().contains("ruda")) { count = (info.ore >= count) ? 1 : 0; } else if (sub.classes().contains("oil")) { count = (info.oil >= count) ? 1 : 0; } else { count = 0; } if (count) { clickElement(elm); log(trUtf8("Машина заправлена"),"taxi.png"); loop = 1; } else { time = 15 * 60; opt.taxi.time = curTime.addSecs(time); log(trUtf8("Не хватает ресурсов для заправки. Ждём 15 мин"),"taxi.png"); } } } while (loop); } setBusy(false); }
void MWBotWin::atackOil() { setBusy(true); int time; int susp; int need; int type; int work; int idx; QWebElement elm,blk,tlm; curTime = QDateTime::currentDateTime(); getFastRes(); if (info.level < 10) { opt.oil.time = curTime.addDays(1); log(trUtf8("Нефтепровод доступен только с 10 уровня"),"neft.png"); } else { restoreHP(); loadPath(QStringList() << "tverskaya" << "neftlenin"); while (opt.oil.time < curTime) { restoreHP(); curTime = QDateTime::currentDateTime(); elm = frm->findFirstElement("div#neftlenin_alert_win"); if (elm.styleProperty("display",QWebElement::ComputedStyle).trimmed() != "none") { // already win elm = elm.findFirst("div.object div.data span.restartNeft"); time = elm.attribute("timer").toInt() + 60 + (random() % 30); opt.oil.time = QDateTime::currentDateTime().addSecs(time); log(trUtf8("Нефтепровод будет доступен через %0 сек").arg(time),"neft.png"); } else { // current suspicion tlm = frm->findFirstElement("div.pipeline-actions table td.mc div.progress i.counter"); susp = tlm.toPlainText().toInt(); // detect event type idx = 0; type = -1; do { if (oilType[idx].type == 0) { type = 0; } else { elm = frm->findFirstElement(oilType[idx].query); if (!elm.isNull() && (elm.styleProperty("display",QWebElement::ComputedStyle).trimmed() != "none")) { type = oilType[idx].type; } } idx++; } while (type < 0); // qDebug() << type; switch (type) { case preFight: // start fight if (!checkSusp(susp, 30)) { elm = frm->findFirstElement("div#pipeline-scroll div.enemy-place.fight div.action button.button div.c"); clickElement(elm); } break; case preGame: // start event elm = frm->findFirstElement("div#pipeline-scroll div.enemy-place.mission div.action button.button div.c"); clickElement(elm); break; case preBoss: // start boss if (!checkSusp(susp, 30)) { elm = frm->findFirstElement("div#pipeline-scroll div.enemy-place.fightboss div.action button.button div.c"); clickElement(elm); } break; case evDuel: // go duel elm = frm->findFirstElement("div#neftlenin_alert_d div.action button.button.first div.c"); // кнопка старта need = elm.findFirst("span.suspicion").toPlainText().remove("\"").toInt(); // надо подозрительности if (!checkSusp(susp, need)) { clickElement(elm); fightResult(); } break; case evGroup: // go group fight elm = frm->findFirstElement("div#neftlenin_alert_g div.action button.button.first div.c"); need = elm.findFirst("span.suspicion").toPlainText().remove("\"").toInt(); if (!checkSusp(susp, need)) { clickElement(elm); groupFight(); } break; case evBoss: // go boss elm = frm->findFirstElement("div#neftlenin_alert_b div.action.buttion.button.first div.c"); need = elm.findFirst("span.suspicion").toPlainText().remove("\"").toInt(); if (!checkSusp(susp, need)) { clickElement(elm); groupFight(); } break; case evGamePrepare: // start event timer elm = frm->findFirstElement("div#neftlenin_alert_prem_first div.action button.button div.c"); clickElement(elm); break; case evGameTimer: // event timer elm = frm->findFirstElement("div#neftlenin_alert_prem div.progress-wrapper span.timeleft"); need = elm.attribute("timer").toInt() + 15 + random() % 15; opt.oil.time = curTime.addSecs(need); log(trUtf8("До завершения задания %0 сек").arg(need),"neft.png"); break; case evGame: // event game log(trUtf8("Начало игры на нефтепроводе"),"neft.png"); elm = frm->findFirstElement("div#neftlenin_alert_mission div.game-process div.progress-block"); work = 1; while (work) { blk = elm.findFirst("div.step-block.active"); // блок с кубиками if (blk.isNull()) { need = oilGameEscape(); // проигрыш или выигрыш work = 0; } else { tlm = blk.findFirst("div.enemy-dice span.dice"); // текущий кубик need = tlm.classes().filter("dice-").first().remove("dice-").toInt(); // число на кубике //qDebug() << "cube" << need; if (need == 0) { qDebug() << "some error"; work = 0; opt.oil.time.addMonths(1); } else if (need <= opt.oil.diceMax) { // кликаем tlm = blk.findFirst("div.action button.button div.c"); clickElement(tlm); } else { // убегаем oilGameEscape(); work = 0; } } } break; default: log(trUtf8("DEBUG : oilpipe unknown situation"),"bug.png"); qDebug() << "unknown situation"; opt.oil.time = curTime.addMonths(1); break; } } } } setBusy(false); }