Skip to content

Commit

Permalink
Fixed various issues with consecutive battles
Browse files Browse the repository at this point in the history
These probably only affected local battles, and ought not to have been
a problem when every battle was initiated by the server, but it should
be more efficient in general now.
  • Loading branch information
varkor committed Feb 9, 2016
1 parent 1b7fda5 commit 57f6805
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions battle/scripts/functions/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ FunctionObject = {
if (details.drawing.canvas.hasOwnProperty("selector"))
canvas = document.querySelector(details.drawing.canvas.selector);
if (canvas === null) {
delete details.drawing.canvas.selector;
canvas = document.createElement("canvas");
if (document.body.childNodes.length > 0)
document.body.insertBefore(canvas, document.body.childNodes[0]);
Expand Down
1 change: 1 addition & 0 deletions battle/scripts/objects/general/BattleContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ function BattleContext (client) {
battleContext.state = {
kind : "inactive"
};
battleContext.draw();
battleContext.complete();
}
},
Expand Down
12 changes: 10 additions & 2 deletions battle/scripts/objects/unique/Relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ Relay = {
}
}
*/
var battle = BattleContext(true);
var battle;
if (typeof Battle !== "undefined" && Battle !== null) {
if (Battle.active) {
throw new Error("You can't trigger a battle when there is already one in progress!");
} else {
battle = Battle;
}
} else {
battle = BattleContext(true);
}
Relay.processes[identifier] = {
battle : battle
};
Expand All @@ -55,7 +64,6 @@ Relay = {
Battle = battle;
var callback = function (flags, trainers) {
data.callback(flags, trainers);
battle.destroy();
};
if (opponent.identification === 0) { /* Code for wild battles */
battle.random.seed = data.data.seed;
Expand Down
1 change: 1 addition & 0 deletions battle/scripts/objects/unique/Supervisor.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Supervisor = {
Supervisor.countdown(identifier, true);
var timer = Supervisor.processes[identifier].timer;
data.callback(flags, trainers, Supervisor.record(identifier));
battle.destroy();
delete Supervisor.processes[identifier];
};
if (!data.data.hasOwnProperty("seed"))
Expand Down
6 changes: 3 additions & 3 deletions battle/scripts/objects/unique/TrialServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
An object used to test out multiplayer battles, locally
To use:
TrialServer.begin();
TrialServer.NPCBattle();
TrialServer.trigger.NPCBattle();
*/
TrialServer = {
begin : function () {
Expand All @@ -13,7 +13,6 @@ TrialServer = {
}, 0);
};
// Initialise the Relay
Relay.identification = 3;
Relay.pass = function (message, data, identifier) {
setTimeout(function () {
TrialServer.pass(message, data, identifier); // We get emulation issues if we just assume we can directly invoke functions across the server-client gap
Expand All @@ -34,7 +33,7 @@ TrialServer = {
if (message === "relay") {
var response = Supervisor.receive(message, {
party : null, // TrialServer only supports one client at the moment
team : 3,
team : Game.player.identification,
data : data
}, identifier);
if (!response.success) {
Expand Down Expand Up @@ -89,6 +88,7 @@ TrialServer = {
"party" : Interface.buildParty(),
"money" : 10000
}));
Relay.identification = Game.player.identification;
Game.player.bag.add("Key Stones => Mega Bracelet");
Game.player.bag.add("Balls => Master");
Game.player.bag.add("Berries => Sitrus");
Expand Down

0 comments on commit 57f6805

Please sign in to comment.