lolautoaccept/include/lolautoaccept.h

121 lines
3.3 KiB
C
Raw Permalink Normal View History

#pragma once
2022-04-21 00:47:57 +02:00
#include <thread>
2022-06-29 23:09:01 +02:00
#include <memory>
2022-07-04 00:30:00 +02:00
#include <mutex>
2022-06-29 23:09:01 +02:00
2023-02-26 13:50:57 +01:00
#include <QObject>
2022-07-09 01:01:51 +02:00
#include "blitzapi.h"
2022-06-29 23:09:01 +02:00
#include "clientapi.h"
2022-07-04 22:59:48 +02:00
#include "config.h"
#include "datadragon.h"
#include "runepage.h"
2022-07-10 15:56:09 +02:00
#include "runestyle.h"
2023-02-26 13:50:57 +01:00
class LolAutoAccept : public QObject {
Q_OBJECT
2022-04-24 14:06:27 +02:00
protected:
struct Stage {
2022-06-29 23:09:01 +02:00
Stage();
2022-04-24 14:06:27 +02:00
virtual ~Stage();
std::vector<uint32_t> champids; // not every stage has a champ
2022-04-24 14:06:27 +02:00
bool enabled = false;
2022-07-03 00:31:13 +02:00
uint32_t currentOffset = 0;
2022-04-24 21:04:36 +02:00
};
2022-07-04 00:30:00 +02:00
std::mutex stagesMutex; // protects stagesvector
2022-07-04 22:59:48 +02:00
std::vector<Stage> stages;
Position currentPosition = Position::INVALID;
2022-07-17 00:21:15 +02:00
bool currentPositionSet = false;
2022-07-29 00:05:22 +02:00
uint32_t lastPickedChamp = 0;
int32_t lastCellId = -1; // last cellid -> if changed -> reset
2022-07-04 22:59:48 +02:00
Config::RootConfig& config;
DataDragon& dd;
2022-04-20 00:54:10 +02:00
bool shouldrun = false;
2022-04-21 00:47:57 +02:00
std::thread lolaathread;
2022-04-20 00:54:10 +02:00
2022-06-29 23:09:01 +02:00
std::shared_ptr<ClientAPI> clientapi;
2022-07-09 01:01:51 +02:00
BlitzAPI blitzapi;
std::vector<RuneAspekt> runeaspekts;
2022-07-10 15:56:09 +02:00
std::vector<RuneStyle> runestyles;
2022-07-09 01:01:51 +02:00
2022-07-10 01:51:42 +02:00
bool nextApplyRunes = false;
2022-08-26 13:47:21 +02:00
bool smiteWarnEnabled = true;
2022-09-21 13:47:08 +02:00
bool autoWriteTextEnabled = false;
bool autoWriteTextDone = false;
2023-05-31 22:22:23 +02:00
QString autoWriteText;
2022-07-10 01:51:42 +02:00
2023-05-31 22:22:23 +02:00
QString chatid; // the chatid of the chat from the champselect
2022-08-26 02:12:25 +02:00
std::chrono::time_point<std::chrono::system_clock> lastMessageSent;
public:
2022-04-24 14:06:27 +02:00
enum class State {
LOBBY = 0,
2022-07-04 00:30:00 +02:00
BAN = 1,
PICK = 2,
2022-04-24 14:06:27 +02:00
};
2023-02-26 13:50:57 +01:00
enum class Status {
Off,
Running,
Failed
};
Q_ENUM(Status)
LolAutoAccept(Config::RootConfig& config, DataDragon& dd, QObject* parent = nullptr);
2023-02-26 13:50:57 +01:00
virtual ~LolAutoAccept();
2022-07-03 00:31:13 +02:00
void setChamps(const std::vector<uint32_t>& champs, State s);
2022-04-24 14:06:27 +02:00
void setEnabled(bool b, State s);
2022-08-26 13:47:21 +02:00
void setSmiteWarn(bool b);
2022-03-08 00:04:56 +01:00
2022-04-20 00:54:10 +02:00
bool init(); // returns true on success
void run();
2022-04-20 00:54:10 +02:00
void stop();
2023-02-26 13:50:57 +01:00
Status getStatus();
2022-04-21 00:47:57 +02:00
2022-07-04 22:59:48 +02:00
void reload(); // reload the config, when something was changed
2022-07-09 01:01:51 +02:00
const std::vector<RuneAspekt>& getRuneAspekts();
2022-07-10 15:56:09 +02:00
const std::vector<RuneStyle>& getRuneStyles();
2023-05-31 22:22:23 +02:00
void setAutoWriteText(bool enabled, const QString& text = {});
2022-07-09 01:01:51 +02:00
2023-02-26 13:50:57 +01:00
signals:
void statusChanged(LolAutoAccept::Status); // new status: 0 = off, 1 = on, 2 = failed
void positionChanged(Position);
2022-04-21 00:47:57 +02:00
private:
void stopJoinThread();
void innerRun();
void resetPickOffsets();
2022-07-03 00:31:13 +02:00
void resetAllOffsets();
2022-07-04 22:59:48 +02:00
void applyConfigToStage(Stage& stage, const Config::StageConfig& stageconf);
void loadPosition(Position pos);
2022-07-03 00:31:13 +02:00
uint32_t getChampOfState(State s);
void nextChampOfState(State s);
2022-07-02 13:21:09 +02:00
2022-07-03 14:50:43 +02:00
static bool isChampIntentofTeammate(uint32_t champid, const ClientAPI::ChampSelectSession& session);
2022-07-04 22:59:48 +02:00
static bool isChampBanned(uint32_t champid, const ClientAPI::ChampSelectSession& session);
2022-07-03 14:50:43 +02:00
2022-07-02 13:21:09 +02:00
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);
2022-07-03 14:50:43 +02:00
void banPhase(const ownactions_t& ownactions, const ClientAPI::ChampSelectSession& session);
void pickPhase(const ownactions_t& ownactions);
2022-07-03 14:50:43 +02:00
void phase(const ownactions_t& ownactions, ClientAPI::ChampSelectActionType type, State s, bool complete, std::function<bool(uint32_t)> filter = {});
2022-07-10 01:51:42 +02:00
static int32_t getBestRunePage(const std::vector<ClientAPI::RunePage>& allpages);
static int32_t getMatchingRunePage(const RunePage& rp, const std::vector<ClientAPI::RunePage>& allpages);
2022-07-02 13:21:09 +02:00
void champSelect();
2022-08-26 02:12:25 +02:00
void smiteWarning(const std::vector<ClientAPI::ChampSelectCell>& cells);
2023-05-31 22:22:23 +02:00
const QString& getChatid();
2022-08-26 02:12:25 +02:00
};
2023-02-26 13:50:57 +01:00
Q_DECLARE_METATYPE(LolAutoAccept::Status)