Skip to content

Commit 11b1ce6

Browse files
VeteranPadgettturbedi
authored andcommitted
ZMove bans (#1599)
1 parent 4dc9a09 commit 11b1ce6

File tree

9 files changed

+52
-7
lines changed

9 files changed

+52
-7
lines changed

src/BattleServer/battlebase.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void BattleBase::init(const BattlePlayer &p1, const BattlePlayer &p2, const Chal
3636
restricted[1] = p2.restrictedPokes;
3737
bannedPokes[0] = p1.bannedPokes.split(", ");
3838
bannedPokes[1] = p2.bannedPokes.split(", ");
39+
bannedZMoves = p1.bannedZMoves.split(", ");
3940
ratings[0] = p1.rating;
4041
ratings[1] = p2.rating;
4142
winMessage[0] = p1.win;
@@ -975,6 +976,9 @@ bool BattleBase::validChoice(const BattleChoice &b)
975976
return true;
976977
}
977978

979+
QString move = MoveInfo::Name(this->move(player, b.attackSlot()));
980+
int item = this->poke(b.slot()).item();
981+
978982
if (b.attackingChoice()){
979983
/* It's an attack, we check the target is valid */
980984
if (b.target() < 0 || b.target() >= numberOfSlots())
@@ -998,6 +1002,9 @@ bool BattleBase::validChoice(const BattleChoice &b)
9981002
return false;
9991003
}
10001004
}
1005+
if (bannedZMoves.contains(move) && item >= 3000 && item <= 3017) {
1006+
return false;
1007+
}
10011008
}
10021009
return true;
10031010
}

src/BattleServer/battlebase.h

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ protected slots:
189189
QString loseMessage[2];
190190
QString tieMessage[2];
191191
QStringList bannedPokes[2];
192+
QStringList bannedZMoves;
192193
bool allowIllegal;
193194

194195
/* timers */

src/Server/battlecommunicator.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ void BattleCommunicator::startBattle(Player *p1, Player *p2, const ChallengeInfo
6262
Tier & t = TierMachine::obj()->tier(tier);
6363

6464
BattlePlayer pb1(p1->name(), p1->id(), p1->rating(team1.tier), p1->avatar(), p1->winningMessage(), p1->losingMessage(),
65-
p1->tieMessage(), t.getMaxLevel(), t.restricted(team1), t.maxRestrictedPokes, t.numberOfPokemons, t.getBannedPokes(), t.allowIllegal == "true");
65+
p1->tieMessage(), t.getMaxLevel(), t.restricted(team1), t.maxRestrictedPokes, t.numberOfPokemons, t.getBannedPokes(), t.allowIllegal == "true", t.getBannedZMoves(true));
6666
BattlePlayer pb2(p2->name(), p2->id(), p2->rating(team2.tier), p2->avatar(), p2->winningMessage(), p2->losingMessage(),
67-
p2->tieMessage(), t.getMaxLevel(), t.restricted(team2), t.maxRestrictedPokes, t.numberOfPokemons, t.getBannedPokes(), t.allowIllegal == "true");
67+
p2->tieMessage(), t.getMaxLevel(), t.restricted(team2), t.maxRestrictedPokes, t.numberOfPokemons, t.getBannedPokes(), t.allowIllegal == "true", t.getBannedZMoves(true));
6868
relay->startBattle(id, pb1, pb2, c, team1, team2);
6969
} else {
7070
BattlePlayer pb1(p1->name(), p1->id(), p1->rating(team1.tier), p1->avatar(), p1->winningMessage(), p1->losingMessage(),

src/Server/tier.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ void Tier::loadFromXml(const QDomElement &elem)
940940
last_count_time = 0;
941941

942942
importBannedMoves(elem.attribute("moves"));
943+
importBannedZMoves(elem.attribute("zmoves"));
943944
importBannedItems(elem.attribute("items"));
944945
importBannedPokes(elem.attribute("pokemons"));
945946
importBannedAbilities(elem.attribute("abilities", ""));
@@ -1027,6 +1028,7 @@ QDomElement & Tier::toXml(QDomElement &dest) const {
10271028
dest.setAttribute("mode", mode);
10281029
dest.setAttribute("displayOrder", displayOrder);
10291030
dest.setAttribute("moves", getBannedMoves());
1031+
dest.setAttribute("zmoves", getBannedZMoves());
10301032
dest.setAttribute("items", getBannedItems());
10311033
dest.setAttribute("abilities", getBannedAbilities());
10321034
dest.setAttribute("pokemons", getBannedPokes());
@@ -1105,6 +1107,19 @@ QString Tier::getBannedMoves() const
11051107
return bannedMovesS.join(", ");
11061108
}
11071109

1110+
QString Tier::getBannedZMoves(bool parentNeeded) const
1111+
{
1112+
QStringList bannedZMovesS;
1113+
foreach(int zmove, bannedZMoves) {
1114+
bannedZMovesS.append(MoveInfo::Name(zmove));
1115+
}
1116+
if (parent && parentNeeded) {
1117+
bannedZMovesS.append(parent->getBannedZMoves());
1118+
}
1119+
bannedZMovesS.sort();
1120+
return bannedZMovesS.join(", ");
1121+
}
1122+
11081123
QString Tier::getBannedAbilities() const
11091124
{
11101125
QStringList bannedAbilitiesS;
@@ -1175,6 +1190,20 @@ void Tier::importBannedMoves(const QString &s)
11751190
}
11761191
}
11771192

1193+
void Tier::importBannedZMoves(const QString &s)
1194+
{
1195+
bannedZMoves.clear();
1196+
if (s.length() == 0)
1197+
return;
1198+
QStringList zmoves = s.split(",");
1199+
foreach(QString zmove, zmoves) {
1200+
int num = MoveInfo::Number(zmove.trimmed());
1201+
1202+
if (num != 0)
1203+
bannedZMoves.insert(num);
1204+
}
1205+
}
1206+
11781207
void Tier::importBannedAbilities(const QString &s)
11791208
{
11801209
bannedAbilities.clear();
@@ -1347,6 +1376,7 @@ Tier *Tier::dataClone() const
13471376
t.banParentS = banParentS;
13481377
t.bannedItems = bannedItems;
13491378
t.bannedMoves = bannedMoves;
1379+
t.bannedZMoves = bannedZMoves;
13501380
t.bannedAbilities = bannedAbilities;
13511381
t.bannedPokes = bannedPokes;
13521382
t.restrictedPokes = restrictedPokes;

src/Server/tier.h

+3
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,15 @@ class Tier : public TierNode
126126
QString getBannedPokes(bool parentNeeded = false) const;
127127
QString getRestrictedPokes() const;
128128
QString getBannedMoves() const;
129+
QString getBannedZMoves(bool parentNeeded = false) const;
129130
QString getBannedItems() const;
130131
QString getBannedAbilities() const;
131132
int getGeneration();
132133
int getSubGeneration();
133134
void importBannedPokes(const QString &);
134135
void importRestrictedPokes(const QString &);
135136
void importBannedMoves(const QString &);
137+
void importBannedZMoves(const QString &);
136138
void importBannedItems(const QString &);
137139
void importBannedAbilities(const QString &);
138140

@@ -196,6 +198,7 @@ class Tier : public TierNode
196198
Tier *parent;
197199
QSet<int> bannedItems;
198200
QSet<int> bannedMoves;
201+
QSet<int> bannedZMoves;
199202
QSet<int> bannedAbilities;
200203
QSet<Pokemon::uniqueId> bannedPokes;
201204
QSet<Pokemon::uniqueId> restrictedPokes;

src/Server/tierwindow.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void TierWindow::openTierEdit(Tier *t)
159159
helper->addConfigHelper(new ConfigSpin("Max number of pokemon", t->numberOfPokemons, 1, 6));
160160
helper->addConfigHelper(new ConfigLine("Pokemon", pokemons));
161161
helper->addConfigHelper(new ConfigLine("Moves", moves));
162+
helper->addConfigHelper(new ConfigLine("ZMoves", zmoves));
162163
helper->addConfigHelper(new ConfigLine("Items", items));
163164
helper->addConfigHelper(new ConfigLine("Abilities", abilities));
164165
helper->addConfigHelper(new ConfigSpin("Max number of restricted pokemon", t->maxRestrictedPokes, 0, 6));
@@ -167,6 +168,7 @@ void TierWindow::openTierEdit(Tier *t)
167168

168169
pokemons = t->getBannedPokes();
169170
moves = t->getBannedMoves();
171+
zmoves = t->getBannedZMoves();
170172
items = t->getBannedItems();
171173
abilities = t->getBannedAbilities();
172174
restrPokemons = t->getRestrictedPokes();
@@ -274,6 +276,7 @@ void TierWindow::updateTier()
274276
currentTier->importBannedItems(items);
275277
currentTier->importBannedPokes(pokemons);
276278
currentTier->importBannedMoves(moves);
279+
currentTier->importBannedZMoves(zmoves);
277280
currentTier->importBannedAbilities(abilities);
278281
currentTier->importRestrictedPokes(restrPokemons);
279282

src/Server/tierwindow.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private slots:
4545
void clearCurrentEdit();
4646
/* Data used to configure categories / tiers */
4747
QString parent;
48-
QString pokemons, restrPokemons, moves, items, abilities;
48+
QString pokemons, restrPokemons, moves, zmoves, items, abilities;
4949
TierCategory *currentTierCat;
5050
Tier *currentTier;
5151
Type currentType;

src/libraries/PokemonInfo/battlestructs.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1130,12 +1130,12 @@ DataStream & operator << (DataStream &out, const ChallengeInfo & c) {
11301130
}
11311131

11321132
DataStream & operator >> (DataStream &in, BattlePlayer & c) {
1133-
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;
1133+
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;
11341134
return in;
11351135
}
11361136

11371137
DataStream & operator << (DataStream &out, const BattlePlayer & c) {
1138-
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;
1138+
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;
11391139
return out;
11401140
}
11411141

src/libraries/PokemonInfo/battlestructs.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,12 @@ struct BattlePlayer
575575
quint8 teamCount;
576576
QString bannedPokes;
577577
bool allowIllegal;
578+
QString bannedZMoves;
578579
BattlePlayer(){}
579580
BattlePlayer(const QString &name, int id, int rating=0, int avatar=0, const QString &win="", const QString &lose="",
580-
const QString &tie="", int maxlevel=100, int restrictedPokes=0, int restrictedCount=0, int teamCount=6, const QString &bannedPokes="", bool allowIllegal = false)
581+
const QString &tie="", int maxlevel=100, int restrictedPokes=0, int restrictedCount=0, int teamCount=6, const QString &bannedPokes="", bool allowIllegal = false, const QString &bannedZMoves="")
581582
: name(name), win(win), lose(lose), tie(tie), rating(rating), avatar(avatar), id(id), maxlevel(maxlevel),
582-
restrictedPokes(restrictedPokes), restrictedCount(restrictedCount), teamCount(teamCount), bannedPokes(bannedPokes), allowIllegal(allowIllegal){}
583+
restrictedPokes(restrictedPokes), restrictedCount(restrictedCount), teamCount(teamCount), bannedPokes(bannedPokes), allowIllegal(allowIllegal), bannedZMoves(bannedZMoves){}
583584
};
584585

585586
DataStream & operator >> (DataStream &in, BattlePlayer &p);

0 commit comments

Comments
 (0)