lolautoaccept/include/clientapi.h

241 lines
5.5 KiB
C++

#pragma once
#include "clientaccess.h"
#include "datadragonimagecache.h"
#include "memoryimagecache.h"
#include "position.h"
#include "restclient.h"
#include "runeaspekt.h"
#include "runepage.h"
#include "runestyle.h"
class ClientAPI : public RestClient {
Q_OBJECT
public:
enum class ReadyCheckState : uint32_t {
INVALID = 0,
NONE,
INPROGRESS,
Accepted,
DECLINED
};
static ReadyCheckState toReadyCheckState(const QJsonObject& json);
enum class GameflowPhase : uint32_t {
NONE = 0,
LOBBY,
MATCHMAKING,
CHECKEDINTOTOURNAMENT,
READYCHECK,
CHAMPSELECT,
GAMESTART,
FAILEDTOLAUNCH,
INPROGRESS,
RECONNECT,
WAITINGFORSTATS,
PREENDOFGAME,
ENDOFGAME,
TERMINATEDINERROR,
};
static GameflowPhase toGameflowPhase(const QString&);
enum class ChampSelectPhase : uint32_t {
INVALID = 0,
GAME_STARTING,
PLANNING,
BAN_PICK,
FINALIZATION
};
static ChampSelectPhase toChampSelectPhase(const QString& str);
enum class ChampSelectActionType : uint32_t {
INVALID = 0,
BAN,
PICK,
TEN_BANS_REVEAL,
};
static ChampSelectActionType toChampSelectActionType(const QString& str);
struct TimerInfo {
int64_t adjustedTimeLeftInPhase = 0;
int64_t internalNowInEpochMs = 0;
bool isefinite = false;
ChampSelectPhase phase = ChampSelectPhase::INVALID;
int64_t totalTimeInPhase = 0;
bool valid = false;
TimerInfo();
explicit TimerInfo(const QJsonObject& json);
};
struct PlayerInfo {
int64_t summonerid = 0; // to test validity -> test if this is not null
QString gameName;
QString name;
QString statusMessage;
// lol specific
QString puuid;
uint32_t level = 0;
};
struct ChampSelectAction {
int32_t actorCellID = -1;
int32_t championID = 0;
int32_t id = 0;
bool completed = false;
bool isAllyAction = true;
bool isInProgress = false;
ChampSelectActionType type = ChampSelectActionType::INVALID;
ChampSelectAction();
explicit ChampSelectAction(const QJsonObject& json);
};
struct ChampSelectCell {
Position position = Position::INVALID;
int32_t cellID = 0;
int32_t championID = 0;
int32_t championPickIntentID = 0;
int64_t summonerID = 0;
int64_t spell1Id = 0; // 4 = flash, 6 = ghost, 7 = heal, 11 = smite, 12 = teleport, 13 = klarheitz, 14 = ignite, 32 = snowball
int64_t spell2Id = 0;
ChampSelectCell();
explicit ChampSelectCell(const QJsonObject& json);
};
static std::vector<ChampSelectCell> loadAllInfos(const QJsonArray& arr);
struct ChampSelectSession {
std::vector<ChampSelectAction> actions;
int32_t counter = 0; // ??
int64_t gameid = 0;
bool allowDuplicatePick = false;
bool allowRerolling = false;
bool allowSkinSelection = true;
bool hasSimultaneousBans = true;
bool hasSimultaneousPicks = false;
bool isCustomGame = false;
bool isSpectating = false;
bool skipChampionSelect = false;
int32_t rerollsRemaining = 0;
int32_t localPlayerCellId = 0;
std::vector<ChampSelectCell> myTeam;
std::vector<ChampSelectCell> theirTeam;
TimerInfo timer;
// std::vector<> trades; // TODO
ChampSelectSession();
explicit ChampSelectSession(const QJsonObject& json);
operator bool();
};
struct RunePage {
uint64_t id = 0;
uint64_t lastmodified = 0;
QString name;
bool isDeleteable = true;
bool isEditable = true;
bool isActive = false; // what is the difference between active and current????
bool isCurrent = false;
bool isValid = true;
uint32_t order = 0; // position in the ui
::RunePage runepage;
RunePage();
explicit RunePage(const QJsonObject& json);
};
struct Message {
QString body;
QString fromId;
QString fromPid;
int64_t fromSummonerId;
QString id;
bool isHistorical;
QString timestamp;
QString type; // known types: chat (1:1), customGame, championSelect, groupchat
Message();
explicit Message(const QJsonObject& json);
};
struct Conversation {
QString gameName;
QString gameTag;
QString id;
bool isMuted;
std::shared_ptr<Message> lastMessage;
QString name;
QString password;
QString pid;
QString targetRegion;
QString type;
int64_t unreadMessageCount;
Conversation();
explicit Conversation(const QJsonObject& json);
};
ClientAPI(const ClientAccess& access);
~ClientAPI();
ReadyCheckState getReadyCheckState();
GameflowPhase getGameflowPhase();
void acceptMatch();
void declineMatch();
ChampSelectSession getChampSelectSession();
bool setChampSelectAction(int32_t actionid, int32_t champid, bool completed);
PlayerInfo getSelf();
void dodge();
std::vector<int32_t> getBannableChampIDs();
std::vector<int32_t> getPickableChampIDs();
TimerInfo getTimerInfo();
// chats
std::vector<Conversation> getAllConversations();
Message sendMessage(const QString& chatid, const QString& messagebody);
// rune stuff
RunePage getCurrentRunePage();
std::vector<RunePage> getAllRunePages();
bool selectRunePage(uint64_t id);
bool editRunePage(const RunePage& page);
bool createRunePage(const RunePage& page);
bool deleteRunePage(uint64_t id);
std::vector<RuneAspekt> getAllRuneAspekts();
std::vector<RuneStyle> getAllRuneStyles();
const QString& getRuneStyleByID(uint32_t id);
QPixmap getImageResource(QString path);
private:
ClientAccess access;
MemoryImageCache memImageCache;
DataDragonImageCache imageCache;
};
#define DEFINEOPERATOR(CLASS) \
std::ostream& operator<<(std::ostream&, const ClientAPI::CLASS&); \
QDebug operator<<(QDebug, const ClientAPI::CLASS&);
DEFINEOPERATOR(ReadyCheckState)
DEFINEOPERATOR(GameflowPhase)
DEFINEOPERATOR(ChampSelectPhase)
DEFINEOPERATOR(ChampSelectActionType)
#undef DEFINEOPERATOR