lolautoaccept/include/lolautoaccept.h

127 lines
3.5 KiB
C++

#pragma once
#include <thread>
#include <memory>
#include <mutex>
#include <QObject>
#include "blitzapi.h"
#include "clientapi.h"
#include "config.h"
#include "datadragon.h"
#include "runepage.h"
#include "runestyle.h"
class LolAutoAccept : public QObject {
Q_OBJECT
protected:
struct Stage {
Stage();
virtual ~Stage();
std::vector<uint32_t> champids; // not every stage has a champ
bool enabled = false;
uint32_t currentOffset = 0;
};
std::mutex stagesMutex; // protects stagesvector
std::vector<Stage> stages;
Position currentPosition = Position::INVALID;
bool currentPositionSet = false;
uint32_t lastPickedChamp = 0;
int32_t lastCellId = -1; // last cellid -> if changed -> reset
Config::RootConfig& config;
DataDragon& dd;
bool shouldrun = false;
std::thread lolaathread;
std::shared_ptr<ClientAPI> clientapi;
BlitzAPI blitzapi;
std::vector<RuneAspekt> runeaspekts;
std::vector<RuneStyle> runestyles;
ClientAPI::GameflowPhase lastPhase;
bool dodgeNow = false;
bool nextApplyRunes = false;
bool smiteWarnEnabled = true;
bool autoWriteTextEnabled = false;
bool autoWriteTextDone = false;
QString autoWriteText;
QString chatid; // the chatid of the chat from the champselect
std::chrono::time_point<std::chrono::system_clock> lastMessageSent;
public:
enum class State {
LOBBY = 0,
BAN = 1,
PICK = 2,
};
enum class Status {
Off,
Running,
Failed
};
Q_ENUM(Status)
LolAutoAccept(Config::RootConfig& config, DataDragon& dd, QObject* parent = nullptr);
virtual ~LolAutoAccept();
void setChamps(const std::vector<uint32_t>& champs, State s);
void setEnabled(bool b, State s);
void setSmiteWarn(bool b);
bool init(); // returns true on success
void run();
void stop();
Status getStatus();
void reload(); // reload the config, when something was changed
const std::vector<RuneAspekt>& getRuneAspekts();
const std::vector<RuneStyle>& getRuneStyles();
void setAutoWriteText(bool enabled, const QString& text = {});
public slots:
void dodge();
signals:
void statusChanged(LolAutoAccept::Status); // new status: 0 = off, 1 = on, 2 = failed
void positionChanged(Position);
void dodgePossible(bool); // true = the dodge button is available
private:
void stopJoinThread();
void innerRun();
void resetPickOffsets();
void resetAllOffsets();
void applyConfigToStage(Stage& stage, const Config::StageConfig& stageconf);
void loadPosition(Position pos);
uint32_t getChampOfState(State s);
void nextChampOfState(State s);
static bool isChampIntentofTeammate(uint32_t champid, const ClientAPI::ChampSelectSession& session);
static bool isChampBanned(uint32_t champid, const ClientAPI::ChampSelectSession& session);
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, 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);
static int32_t getMatchingRunePage(const RunePage& rp, const std::vector<ClientAPI::RunePage>& allpages);
void champSelect();
void smiteWarning(const std::vector<ClientAPI::ChampSelectCell>& cells);
const QString& getChatid();
};
Q_DECLARE_METATYPE(LolAutoAccept::Status)