Skip to content

Commit

Permalink
Illegal battles now count as failures to Supervisor
Browse files Browse the repository at this point in the history
This makes illegal battles easier to deal with as you don’t get any
confusing false positives.
  • Loading branch information
varkor committed Feb 29, 2016
1 parent deab539 commit 5a15957
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
20 changes: 12 additions & 8 deletions battle/scripts/objects/general/BattleContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,14 +668,14 @@ function BattleContext (client) {
},
beginOnline : function (seed, alliedTrainers, opposingTrainers, settings, callback) {
battleContext.random.seed = seed;
battleContext.initiate(alliedTrainers, opposingTrainers, settings, callback);
return battleContext.initiate(alliedTrainers, opposingTrainers, settings, callback);
},
beginWildBattle : function (alliedTrainers, pokes, settings, callback) {
pokes = wrapArray(pokes);
battleContext.initiate(alliedTrainers, trainer.newWildTrainer(pokes), settings, callback);
return battleContext.initiate(alliedTrainers, trainer.newWildTrainer(pokes), settings, callback);
},
beginTrainerBattle : function (alliedTrainers, opposingTrainers, settings, callback) {
battleContext.initiate(alliedTrainers, opposingTrainers, settings, callback);
return battleContext.initiate(alliedTrainers, opposingTrainers, settings, callback);
},
initiate : function (alliedTrainers, opposingTrainers, settings, callback) {
if (!battleContext.active) {
Expand Down Expand Up @@ -726,8 +726,9 @@ function BattleContext (client) {
});
}
}
}))
return;
})) {
return false; // The battle was illegal and thus could not be initiated
}
if (foreach(battleContext.opposingTrainers, function (participant) {
participant.display.visible = true;
participant.megaEvolution = false;
Expand All @@ -752,17 +753,20 @@ function BattleContext (client) {
}; }(newPoke)});
}
}
}))
return;
})) {
return false; // The battle was illegal and thus could not be initiated
}
battleContext.active = true;
if (!battleContext.process) {
Display.state.load(Display.state.save());
battleContext.load(alliedTrainers, opposingTrainers, settings);
} else {
battleContext.begin();
}
} else
return true; // The battle could be initiated successfully
} else {
throw new Error("You've tried to start a battle when one is already in progress!");
}
},
begin : function () {
battleContext.state = {
Expand Down
10 changes: 7 additions & 3 deletions battle/scripts/objects/unique/Supervisor.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,16 @@ let Supervisor = {
if (typeof data.data.parameters !== "object")
return unsuccessful("The parameter `data.data.parameters` should have been an object, but had type `" + (typeof data.data.parameters) + "`.");
battle.random.seed = data.data.seed;
var illegalBattle;
if (teamA.identification === 0) { /* Code for wild battles */
battle.beginWildBattle(teamB, teamA.party.pokemon, data.data.parameters, callback);
illegalBattle = !battle.beginWildBattle(teamB, teamA.party.pokemon, data.data.parameters, callback);
} else if (teamB.identification === 0) {
battle.beginWildBattle(teamA, teamB.party.pokemon, data.data.parameters, callback);
illegalBattle = !battle.beginWildBattle(teamA, teamB.party.pokemon, data.data.parameters, callback);
} else {
battle.beginOnline(data.data.seed, teamA, teamB, data.data.parameters, callback);
illegalBattle = !battle.beginOnline(data.data.seed, teamA, teamB, data.data.parameters, callback);
}
if (illegalBattle) {
return unsuccessful("The battle was illegal in some form (probably due to one of the trainers not having any valid Pokémon).");
}
foreach(data.parties, function (party) {
Supervisor.send(party, "initiate", {
Expand Down

0 comments on commit 5a15957

Please sign in to comment.