dnt ban ally champions

This commit is contained in:
mrbesen 2022-07-03 14:50:43 +02:00
parent 9e95bd6562
commit 4feb5dc7ae
Signed by untrusted user: MrBesen
GPG Key ID: 596B2350DCD67504
3 changed files with 37 additions and 13 deletions

View File

@ -52,11 +52,13 @@ private:
uint32_t getChampOfState(State s);
void nextChampOfState(State s);
static bool isChampIntentofTeammate(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);
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);
void phase(const ownactions_t& ownactions, ClientAPI::ChampSelectActionType type, State s, bool complete, std::function<bool(uint32_t)> filter = {});
void champSelect();
};

View File

@ -123,7 +123,7 @@ uint32_t LolAutoAccept::getChampOfState(State s) {
assert(((int) s) >= 0 && s <= State::PICK);
auto stage = stages[(int) s];
int size = stage->champids.size();
uint32_t size = stage->champids.size();
if(stage->currentOffset >= size) {
// no champ to try left
Log::warn << "no champ left at stage: " << (int) s;
@ -138,7 +138,7 @@ void LolAutoAccept::nextChampOfState(State s) {
assert(((int) s) >= 0 && s <= State::PICK);
auto stage = stages[(int) s];
int size = stage->champids.size();
uint32_t size = stage->champids.size();
stage->currentOffset++;
@ -152,6 +152,16 @@ void LolAutoAccept::nextChampOfState(State s) {
}
}
bool LolAutoAccept::isChampIntentofTeammate(uint32_t champid, const ClientAPI::ChampSelectSession& session) {
for(const ClientAPI::ChampSelectCell& player : session.myTeam) {
if(player.championID == (int32_t) champid || player.championPickIntentID == (int32_t) champid) {
Log::info << "player " << player.cellID << " @ " << player.position << " wants to play " << champid;
return true;
}
}
return false;
}
LolAutoAccept::ownactions_t LolAutoAccept::getOwnActions(int32_t cellid, const std::vector<ClientAPI::ChampSelectAction> actions) {
ownactions_t out;
for(const auto& it : actions) {
@ -169,26 +179,37 @@ void LolAutoAccept::prepickPhase(const ownactions_t& ownactions) {
phase(ownactions, ClientAPI::ChampSelectActionType::PICK, State::PREPICK, false);
}
void LolAutoAccept::banPhase(const ownactions_t& ownactions) {
phase(ownactions, ClientAPI::ChampSelectActionType::BAN, State::BAN, true);
void LolAutoAccept::banPhase(const ownactions_t& ownactions, const ClientAPI::ChampSelectSession& session) {
phase(ownactions, ClientAPI::ChampSelectActionType::BAN, State::BAN, true, [session](uint32_t champid) {
return !isChampIntentofTeammate(champid, session);
});
}
void LolAutoAccept::pickPhase(const ownactions_t& ownactions) {
phase(ownactions, ClientAPI::ChampSelectActionType::PICK, State::PICK, true);
}
void LolAutoAccept::phase(const ownactions_t& ownactions, ClientAPI::ChampSelectActionType type, State s, bool complete) {
Log::note << type << " phase";
void LolAutoAccept::phase(const ownactions_t& ownactions, ClientAPI::ChampSelectActionType type, State s, bool complete, std::function<bool(uint32_t)> filter) {
for(auto it : ownactions) {
if(it.type == type) {
Log::info << type << " action anvailable: " << it.id << " champid: " << it.championID;
uint32_t champid = getChampOfState(s);
if(it.championID != champid || !it.completed) {
if(filter) {
// filter says no
if(!filter(champid)) {
nextChampOfState(s);
return;
}
}
if(it.championID != (int32_t) champid || !it.completed) {
// try to prepick a champion
Log::info << "try to pick champ: " << champid;
clientapi->setChampSelectAction(it.id, champid, complete);
nextChampOfState(s);
if(!clientapi->setChampSelectAction(it.id, champid, complete)) {
nextChampOfState(s);
}
return;
}
}
@ -221,10 +242,9 @@ void LolAutoAccept::champSelect() {
if(session.timer.phase == ClientAPI::ChampSelectPhase::PLANNING) {
prepickPhase(ownactions);
} else if(session.timer.phase == ClientAPI::ChampSelectPhase::BAN_PICK) {
banPhase(ownactions);
banPhase(ownactions, session);
pickPhase(ownactions);
} else if(session.timer.phase == ClientAPI::ChampSelectPhase::FINALIZATION) {
// trade?
Log::info << "trade phase";
}
}

View File

@ -93,6 +93,8 @@ void StageSettings::removeChamp() {
Log::trace << "remove champ";
int row = ui->championList->currentRow(); // what if no row is selected?
delete ui->championList->takeItem(row);
emit championsChanged();
}
void StageSettings::moved() {