Skip to content

Commit

Permalink
ZMove bans (#1599)
Browse files Browse the repository at this point in the history
  • Loading branch information
VeteranPadgett authored and turbedi committed Jan 15, 2017
1 parent 4dc9a09 commit 11b1ce6
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/BattleServer/battlebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void BattleBase::init(const BattlePlayer &p1, const BattlePlayer &p2, const Chal
restricted[1] = p2.restrictedPokes;
bannedPokes[0] = p1.bannedPokes.split(", ");
bannedPokes[1] = p2.bannedPokes.split(", ");
bannedZMoves = p1.bannedZMoves.split(", ");
ratings[0] = p1.rating;
ratings[1] = p2.rating;
winMessage[0] = p1.win;
Expand Down Expand Up @@ -975,6 +976,9 @@ bool BattleBase::validChoice(const BattleChoice &b)
return true;
}

QString move = MoveInfo::Name(this->move(player, b.attackSlot()));
int item = this->poke(b.slot()).item();

if (b.attackingChoice()){
/* It's an attack, we check the target is valid */
if (b.target() < 0 || b.target() >= numberOfSlots())
Expand All @@ -998,6 +1002,9 @@ bool BattleBase::validChoice(const BattleChoice &b)
return false;
}
}
if (bannedZMoves.contains(move) && item >= 3000 && item <= 3017) {
return false;
}
}
return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/BattleServer/battlebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ protected slots:
QString loseMessage[2];
QString tieMessage[2];
QStringList bannedPokes[2];
QStringList bannedZMoves;
bool allowIllegal;

/* timers */
Expand Down
4 changes: 2 additions & 2 deletions src/Server/battlecommunicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ void BattleCommunicator::startBattle(Player *p1, Player *p2, const ChallengeInfo
Tier & t = TierMachine::obj()->tier(tier);

BattlePlayer pb1(p1->name(), p1->id(), p1->rating(team1.tier), p1->avatar(), p1->winningMessage(), p1->losingMessage(),
p1->tieMessage(), t.getMaxLevel(), t.restricted(team1), t.maxRestrictedPokes, t.numberOfPokemons, t.getBannedPokes(), t.allowIllegal == "true");
p1->tieMessage(), t.getMaxLevel(), t.restricted(team1), t.maxRestrictedPokes, t.numberOfPokemons, t.getBannedPokes(), t.allowIllegal == "true", t.getBannedZMoves(true));
BattlePlayer pb2(p2->name(), p2->id(), p2->rating(team2.tier), p2->avatar(), p2->winningMessage(), p2->losingMessage(),
p2->tieMessage(), t.getMaxLevel(), t.restricted(team2), t.maxRestrictedPokes, t.numberOfPokemons, t.getBannedPokes(), t.allowIllegal == "true");
p2->tieMessage(), t.getMaxLevel(), t.restricted(team2), t.maxRestrictedPokes, t.numberOfPokemons, t.getBannedPokes(), t.allowIllegal == "true", t.getBannedZMoves(true));
relay->startBattle(id, pb1, pb2, c, team1, team2);
} else {
BattlePlayer pb1(p1->name(), p1->id(), p1->rating(team1.tier), p1->avatar(), p1->winningMessage(), p1->losingMessage(),
Expand Down
30 changes: 30 additions & 0 deletions src/Server/tier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ void Tier::loadFromXml(const QDomElement &elem)
last_count_time = 0;

importBannedMoves(elem.attribute("moves"));
importBannedZMoves(elem.attribute("zmoves"));
importBannedItems(elem.attribute("items"));
importBannedPokes(elem.attribute("pokemons"));
importBannedAbilities(elem.attribute("abilities", ""));
Expand Down Expand Up @@ -1027,6 +1028,7 @@ QDomElement & Tier::toXml(QDomElement &dest) const {
dest.setAttribute("mode", mode);
dest.setAttribute("displayOrder", displayOrder);
dest.setAttribute("moves", getBannedMoves());
dest.setAttribute("zmoves", getBannedZMoves());
dest.setAttribute("items", getBannedItems());
dest.setAttribute("abilities", getBannedAbilities());
dest.setAttribute("pokemons", getBannedPokes());
Expand Down Expand Up @@ -1105,6 +1107,19 @@ QString Tier::getBannedMoves() const
return bannedMovesS.join(", ");
}

QString Tier::getBannedZMoves(bool parentNeeded) const
{
QStringList bannedZMovesS;
foreach(int zmove, bannedZMoves) {
bannedZMovesS.append(MoveInfo::Name(zmove));
}
if (parent && parentNeeded) {
bannedZMovesS.append(parent->getBannedZMoves());
}
bannedZMovesS.sort();
return bannedZMovesS.join(", ");
}

QString Tier::getBannedAbilities() const
{
QStringList bannedAbilitiesS;
Expand Down Expand Up @@ -1175,6 +1190,20 @@ void Tier::importBannedMoves(const QString &s)
}
}

void Tier::importBannedZMoves(const QString &s)
{
bannedZMoves.clear();
if (s.length() == 0)
return;
QStringList zmoves = s.split(",");
foreach(QString zmove, zmoves) {
int num = MoveInfo::Number(zmove.trimmed());

if (num != 0)
bannedZMoves.insert(num);
}
}

void Tier::importBannedAbilities(const QString &s)
{
bannedAbilities.clear();
Expand Down Expand Up @@ -1347,6 +1376,7 @@ Tier *Tier::dataClone() const
t.banParentS = banParentS;
t.bannedItems = bannedItems;
t.bannedMoves = bannedMoves;
t.bannedZMoves = bannedZMoves;
t.bannedAbilities = bannedAbilities;
t.bannedPokes = bannedPokes;
t.restrictedPokes = restrictedPokes;
Expand Down
3 changes: 3 additions & 0 deletions src/Server/tier.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ class Tier : public TierNode
QString getBannedPokes(bool parentNeeded = false) const;
QString getRestrictedPokes() const;
QString getBannedMoves() const;
QString getBannedZMoves(bool parentNeeded = false) const;
QString getBannedItems() const;
QString getBannedAbilities() const;
int getGeneration();
int getSubGeneration();
void importBannedPokes(const QString &);
void importRestrictedPokes(const QString &);
void importBannedMoves(const QString &);
void importBannedZMoves(const QString &);
void importBannedItems(const QString &);
void importBannedAbilities(const QString &);

Expand Down Expand Up @@ -196,6 +198,7 @@ class Tier : public TierNode
Tier *parent;
QSet<int> bannedItems;
QSet<int> bannedMoves;
QSet<int> bannedZMoves;
QSet<int> bannedAbilities;
QSet<Pokemon::uniqueId> bannedPokes;
QSet<Pokemon::uniqueId> restrictedPokes;
Expand Down
3 changes: 3 additions & 0 deletions src/Server/tierwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void TierWindow::openTierEdit(Tier *t)
helper->addConfigHelper(new ConfigSpin("Max number of pokemon", t->numberOfPokemons, 1, 6));
helper->addConfigHelper(new ConfigLine("Pokemon", pokemons));
helper->addConfigHelper(new ConfigLine("Moves", moves));
helper->addConfigHelper(new ConfigLine("ZMoves", zmoves));
helper->addConfigHelper(new ConfigLine("Items", items));
helper->addConfigHelper(new ConfigLine("Abilities", abilities));
helper->addConfigHelper(new ConfigSpin("Max number of restricted pokemon", t->maxRestrictedPokes, 0, 6));
Expand All @@ -167,6 +168,7 @@ void TierWindow::openTierEdit(Tier *t)

pokemons = t->getBannedPokes();
moves = t->getBannedMoves();
zmoves = t->getBannedZMoves();
items = t->getBannedItems();
abilities = t->getBannedAbilities();
restrPokemons = t->getRestrictedPokes();
Expand Down Expand Up @@ -274,6 +276,7 @@ void TierWindow::updateTier()
currentTier->importBannedItems(items);
currentTier->importBannedPokes(pokemons);
currentTier->importBannedMoves(moves);
currentTier->importBannedZMoves(zmoves);
currentTier->importBannedAbilities(abilities);
currentTier->importRestrictedPokes(restrPokemons);

Expand Down
2 changes: 1 addition & 1 deletion src/Server/tierwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private slots:
void clearCurrentEdit();
/* Data used to configure categories / tiers */
QString parent;
QString pokemons, restrPokemons, moves, items, abilities;
QString pokemons, restrPokemons, moves, zmoves, items, abilities;
TierCategory *currentTierCat;
Tier *currentTier;
Type currentType;
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/PokemonInfo/battlestructs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,12 +1130,12 @@ DataStream & operator << (DataStream &out, const ChallengeInfo & c) {
}

DataStream & operator >> (DataStream &in, BattlePlayer & c) {
in >> c.id >> c.name >> c.avatar >> c.rating >> c.win >> c.lose >> c.tie >> c.restrictedCount >> c.restrictedPokes >> c.teamCount >> c.maxlevel >> c.bannedPokes >> c.allowIllegal;
in >> c.id >> c.name >> c.avatar >> c.rating >> c.win >> c.lose >> c.tie >> c.restrictedCount >> c.restrictedPokes >> c.teamCount >> c.maxlevel >> c.bannedPokes >> c.allowIllegal >> c.bannedZMoves;
return in;
}

DataStream & operator << (DataStream &out, const BattlePlayer & c) {
out << c.id << c.name << c.avatar << c.rating << c.win << c.lose << c.tie << c.restrictedCount << c.restrictedPokes << c.teamCount << c.maxlevel << c.bannedPokes << c.allowIllegal;
out << c.id << c.name << c.avatar << c.rating << c.win << c.lose << c.tie << c.restrictedCount << c.restrictedPokes << c.teamCount << c.maxlevel << c.bannedPokes << c.allowIllegal << c.bannedZMoves;
return out;
}

Expand Down
5 changes: 3 additions & 2 deletions src/libraries/PokemonInfo/battlestructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,12 @@ struct BattlePlayer
quint8 teamCount;
QString bannedPokes;
bool allowIllegal;
QString bannedZMoves;
BattlePlayer(){}
BattlePlayer(const QString &name, int id, int rating=0, int avatar=0, const QString &win="", const QString &lose="",
const QString &tie="", int maxlevel=100, int restrictedPokes=0, int restrictedCount=0, int teamCount=6, const QString &bannedPokes="", bool allowIllegal = false)
const QString &tie="", int maxlevel=100, int restrictedPokes=0, int restrictedCount=0, int teamCount=6, const QString &bannedPokes="", bool allowIllegal = false, const QString &bannedZMoves="")
: name(name), win(win), lose(lose), tie(tie), rating(rating), avatar(avatar), id(id), maxlevel(maxlevel),
restrictedPokes(restrictedPokes), restrictedCount(restrictedCount), teamCount(teamCount), bannedPokes(bannedPokes), allowIllegal(allowIllegal){}
restrictedPokes(restrictedPokes), restrictedCount(restrictedCount), teamCount(teamCount), bannedPokes(bannedPokes), allowIllegal(allowIllegal), bannedZMoves(bannedZMoves){}
};

DataStream & operator >> (DataStream &in, BattlePlayer &p);
Expand Down

0 comments on commit 11b1ce6

Please sign in to comment.