Added /timer command for enabling the timer after battle has started
This commit is contained in:
parent
cd9ea965bb
commit
9ca2a8746c
|
@ -98,6 +98,8 @@ makeCommand "pbv", (room, pokemon...) ->
|
||||||
else
|
else
|
||||||
room.announce('success', "<b>PBV:</b> #{messages.join('; ')}")
|
room.announce('success', "<b>PBV:</b> #{messages.join('; ')}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
findPokemonAtPBV = (pbv) ->
|
findPokemonAtPBV = (pbv) ->
|
||||||
messages = []
|
messages = []
|
||||||
counter = 0
|
counter = 0
|
||||||
|
|
|
@ -9,7 +9,7 @@ PokeBattle.events.on "errorMessage", (type, args...) ->
|
||||||
options =
|
options =
|
||||||
title: "Your login timed out!"
|
title: "Your login timed out!"
|
||||||
body: """To access the simulator, you need to
|
body: """To access the simulator, you need to
|
||||||
<a href="http://91.121.152.74/">login again</a>."""
|
<a href="https://battling.p-insurgence.com">login again</a>."""
|
||||||
$modal = PokeBattle.modal('modals/errors', options)
|
$modal = PokeBattle.modal('modals/errors', options)
|
||||||
$modal.find('.modal-footer button').first().focus()
|
$modal.find('.modal-footer button').first().focus()
|
||||||
PokeBattle.primus.end()
|
PokeBattle.primus.end()
|
||||||
|
@ -33,6 +33,8 @@ PokeBattle.events.on "errorMessage", (type, args...) ->
|
||||||
|
|
||||||
when e.FIND_BATTLE
|
when e.FIND_BATTLE
|
||||||
PokeBattle.events.trigger("findBattleCanceled")
|
PokeBattle.events.trigger("findBattleCanceled")
|
||||||
|
PokeBattle.events.trigger("findBattleCanceledUnranked")
|
||||||
|
PokeBattle.events.trigger("findBattleCanceledRandom")
|
||||||
|
|
||||||
# Show errors
|
# Show errors
|
||||||
[errors] = args
|
[errors] = args
|
||||||
|
|
|
@ -28,6 +28,17 @@ $ ->
|
||||||
Conditions.PRANKSTER_SWAGGER_CLAUSE
|
Conditions.PRANKSTER_SWAGGER_CLAUSE
|
||||||
Conditions.TIMED_BATTLE
|
Conditions.TIMED_BATTLE
|
||||||
]
|
]
|
||||||
|
createChallengeButton
|
||||||
|
eventName: "findBattleRandom"
|
||||||
|
button: $mainButtons.find('.find_battle_random')
|
||||||
|
clauses: [
|
||||||
|
Conditions.SLEEP_CLAUSE
|
||||||
|
Conditions.EVASION_CLAUSE
|
||||||
|
Conditions.SPECIES_CLAUSE
|
||||||
|
Conditions.OHKO_CLAUSE
|
||||||
|
Conditions.PRANKSTER_SWAGGER_CLAUSE
|
||||||
|
Conditions.TIMED_BATTLE
|
||||||
|
]
|
||||||
|
|
||||||
createChallengePaneNew
|
createChallengePaneNew
|
||||||
populate: $mainButtons.find('.find_battle_select_team')
|
populate: $mainButtons.find('.find_battle_select_team')
|
||||||
|
@ -45,6 +56,12 @@ $ ->
|
||||||
.addClass('icon-spinner spinner-anim')
|
.addClass('icon-spinner spinner-anim')
|
||||||
.removeClass("icon-earth")
|
.removeClass("icon-earth")
|
||||||
|
|
||||||
|
$mainButtons.find('.find_battle_random').on 'challenge', ->
|
||||||
|
$this = $(this)
|
||||||
|
$this.find('.find-icon')
|
||||||
|
.addClass('icon-spinner spinner-anim')
|
||||||
|
.removeClass("icon-earth")
|
||||||
|
|
||||||
$mainButtons.find('.display_credits').click ->
|
$mainButtons.find('.display_credits').click ->
|
||||||
$modal = PokeBattle.modal('modals/credits')
|
$modal = PokeBattle.modal('modals/credits')
|
||||||
$modal.find('.modal-footer button').first().focus()
|
$modal.find('.modal-footer button').first().focus()
|
||||||
|
@ -68,15 +85,28 @@ depressFindBattleUnranked = ->
|
||||||
.addClass("icon-earth")
|
.addClass("icon-earth")
|
||||||
$mainButtons.find('.find_battle_select_team .select').removeClass('disabled')
|
$mainButtons.find('.find_battle_select_team .select').removeClass('disabled')
|
||||||
|
|
||||||
|
depressFindBattleRandom = ->
|
||||||
|
$mainButtons = $('.main_buttons')
|
||||||
|
$button = $mainButtons.find('.find_battle_random')
|
||||||
|
$button.removeClass("disabled")
|
||||||
|
$button.find('.find-icon')
|
||||||
|
.removeClass("icon-spinner spinner-anim")
|
||||||
|
.addClass("icon-earth")
|
||||||
|
$mainButtons.find('.find_battle_select_team .select').removeClass('disabled')
|
||||||
|
|
||||||
$(window).load ->
|
$(window).load ->
|
||||||
$mainButtons = $('.main_buttons')
|
$mainButtons = $('.main_buttons')
|
||||||
PokeBattle.battles.on 'add', (battle) ->
|
PokeBattle.battles.on 'add', (battle) ->
|
||||||
if !battle.get('spectating')
|
if !battle.get('spectating')
|
||||||
depressFindBattle()
|
depressFindBattle()
|
||||||
depressFindBattleUnranked()
|
depressFindBattleUnranked()
|
||||||
|
depressFindBattleRandom()
|
||||||
|
|
||||||
PokeBattle.primus.on 'findBattleCanceled', depressFindBattle
|
PokeBattle.primus.on 'findBattleCanceled', depressFindBattle
|
||||||
PokeBattle.events.on 'findBattleCanceled', depressFindBattle
|
PokeBattle.events.on 'findBattleCanceled', depressFindBattle
|
||||||
|
|
||||||
PokeBattle.primus.on 'findBattleCanceledUnranked', depressFindBattleUnranked
|
PokeBattle.primus.on 'findBattleCanceledUnranked', depressFindBattleUnranked
|
||||||
PokeBattle.events.on 'findBattleCanceledUnranked', depressFindBattleUnranked
|
PokeBattle.events.on 'findBattleCanceledUnranked', depressFindBattleUnranked
|
||||||
|
|
||||||
|
PokeBattle.primus.on 'findBattleCanceledRandom', depressFindBattleRandom
|
||||||
|
PokeBattle.events.on 'findBattleCanceledRandom', depressFindBattleRandom
|
|
@ -58,13 +58,17 @@ class @challengePaneObject
|
||||||
format = defaultformat()
|
format = defaultformat()
|
||||||
# Toggle state when you press the button.
|
# Toggle state when you press the button.
|
||||||
if !$button.hasClass('disabled')
|
if !$button.hasClass('disabled')
|
||||||
team = getSelectedTeam()
|
if $eventName is "findBattleRandom"
|
||||||
unless team
|
teamJSON = []
|
||||||
alert("You need to create a team using the Teambuilder before you can battle.")
|
disableButtons()
|
||||||
PokeBattle.navigation.showTeambuilder()
|
else
|
||||||
return
|
team = getSelectedTeam()
|
||||||
disableButtons()
|
unless team
|
||||||
teamJSON = team.toNonNullJSON().pokemon
|
alert("You need to create a team using the Teambuilder before you can battle.")
|
||||||
|
PokeBattle.navigation.showTeambuilder()
|
||||||
|
return
|
||||||
|
disableButtons()
|
||||||
|
teamJSON = team.toNonNullJSON().pokemon
|
||||||
# Send the event
|
# Send the event
|
||||||
PokeBattle.primus.send($eventName, format, teamJSON, options.selectedAlt)
|
PokeBattle.primus.send($eventName, format, teamJSON, options.selectedAlt)
|
||||||
$button.addClass('disabled').trigger('challenge')
|
$button.addClass('disabled').trigger('challenge')
|
||||||
|
|
|
@ -13,6 +13,10 @@ block content
|
||||||
.button.big.find_battle
|
.button.big.find_battle
|
||||||
span.find-icon.icon-earth
|
span.find-icon.icon-earth
|
||||||
| Ranked battle
|
| Ranked battle
|
||||||
|
p
|
||||||
|
.button.big.find_battle_random
|
||||||
|
span.find-icon.icon-earth
|
||||||
|
| Random battle
|
||||||
.find_battle_select_team
|
.find_battle_select_team
|
||||||
.section
|
.section
|
||||||
.button.teambuilder_button
|
.button.teambuilder_button
|
||||||
|
|
|
@ -7697,14 +7697,19 @@
|
||||||
format = defaultformat();
|
format = defaultformat();
|
||||||
}
|
}
|
||||||
if (!$button.hasClass('disabled')) {
|
if (!$button.hasClass('disabled')) {
|
||||||
team = getSelectedTeam();
|
if ($eventName === "findBattleRandom") {
|
||||||
if (!team) {
|
teamJSON = [];
|
||||||
alert("You need to create a team using the Teambuilder before you can battle.");
|
disableButtons();
|
||||||
PokeBattle.navigation.showTeambuilder();
|
} else {
|
||||||
return;
|
team = getSelectedTeam();
|
||||||
|
if (!team) {
|
||||||
|
alert("You need to create a team using the Teambuilder before you can battle.");
|
||||||
|
PokeBattle.navigation.showTeambuilder();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
disableButtons();
|
||||||
|
teamJSON = team.toNonNullJSON().pokemon;
|
||||||
}
|
}
|
||||||
disableButtons();
|
|
||||||
teamJSON = team.toNonNullJSON().pokemon;
|
|
||||||
PokeBattle.primus.send($eventName, format, teamJSON, options.selectedAlt);
|
PokeBattle.primus.send($eventName, format, teamJSON, options.selectedAlt);
|
||||||
return $button.addClass('disabled').trigger('challenge');
|
return $button.addClass('disabled').trigger('challenge');
|
||||||
} else {
|
} else {
|
||||||
|
@ -11325,7 +11330,7 @@
|
||||||
}
|
}
|
||||||
options = {
|
options = {
|
||||||
title: "Your login timed out!",
|
title: "Your login timed out!",
|
||||||
body: "To access the simulator, you need to\n<a href=\"http://91.121.152.74/\">login again</a>."
|
body: "To access the simulator, you need to\n<a href=\"https://battling.p-insurgence.com\">login again</a>."
|
||||||
};
|
};
|
||||||
$modal = PokeBattle.modal('modals/errors', options);
|
$modal = PokeBattle.modal('modals/errors', options);
|
||||||
$modal.find('.modal-footer button').first().focus();
|
$modal.find('.modal-footer button').first().focus();
|
||||||
|
@ -11353,6 +11358,8 @@
|
||||||
return PokeBattle.primus.end();
|
return PokeBattle.primus.end();
|
||||||
case e.FIND_BATTLE:
|
case e.FIND_BATTLE:
|
||||||
PokeBattle.events.trigger("findBattleCanceled");
|
PokeBattle.events.trigger("findBattleCanceled");
|
||||||
|
PokeBattle.events.trigger("findBattleCanceledUnranked");
|
||||||
|
PokeBattle.events.trigger("findBattleCanceledRandom");
|
||||||
errors = args[0];
|
errors = args[0];
|
||||||
return alert(errors);
|
return alert(errors);
|
||||||
case e.BATTLE_DNE:
|
case e.BATTLE_DNE:
|
||||||
|
@ -11409,7 +11416,7 @@
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var depressFindBattle, depressFindBattleUnranked;
|
var depressFindBattle, depressFindBattleRandom, depressFindBattleUnranked;
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
var $mainButtons;
|
var $mainButtons;
|
||||||
|
@ -11427,6 +11434,11 @@
|
||||||
button: $mainButtons.find('.find_battle_non_ranked'),
|
button: $mainButtons.find('.find_battle_non_ranked'),
|
||||||
clauses: [Conditions.SLEEP_CLAUSE, Conditions.EVASION_CLAUSE, Conditions.SPECIES_CLAUSE, Conditions.OHKO_CLAUSE, Conditions.PRANKSTER_SWAGGER_CLAUSE, Conditions.TIMED_BATTLE]
|
clauses: [Conditions.SLEEP_CLAUSE, Conditions.EVASION_CLAUSE, Conditions.SPECIES_CLAUSE, Conditions.OHKO_CLAUSE, Conditions.PRANKSTER_SWAGGER_CLAUSE, Conditions.TIMED_BATTLE]
|
||||||
});
|
});
|
||||||
|
createChallengeButton({
|
||||||
|
eventName: "findBattleRandom",
|
||||||
|
button: $mainButtons.find('.find_battle_random'),
|
||||||
|
clauses: [Conditions.SLEEP_CLAUSE, Conditions.EVASION_CLAUSE, Conditions.SPECIES_CLAUSE, Conditions.OHKO_CLAUSE, Conditions.PRANKSTER_SWAGGER_CLAUSE, Conditions.TIMED_BATTLE]
|
||||||
|
});
|
||||||
createChallengePaneNew({
|
createChallengePaneNew({
|
||||||
populate: $mainButtons.find('.find_battle_select_team')
|
populate: $mainButtons.find('.find_battle_select_team')
|
||||||
});
|
});
|
||||||
|
@ -11440,6 +11452,11 @@
|
||||||
$this = $(this);
|
$this = $(this);
|
||||||
return $this.find('.find-icon').addClass('icon-spinner spinner-anim').removeClass("icon-earth");
|
return $this.find('.find-icon').addClass('icon-spinner spinner-anim').removeClass("icon-earth");
|
||||||
});
|
});
|
||||||
|
$mainButtons.find('.find_battle_random').on('challenge', function() {
|
||||||
|
var $this;
|
||||||
|
$this = $(this);
|
||||||
|
return $this.find('.find-icon').addClass('icon-spinner spinner-anim').removeClass("icon-earth");
|
||||||
|
});
|
||||||
return $mainButtons.find('.display_credits').click(function() {
|
return $mainButtons.find('.display_credits').click(function() {
|
||||||
var $modal;
|
var $modal;
|
||||||
$modal = PokeBattle.modal('modals/credits');
|
$modal = PokeBattle.modal('modals/credits');
|
||||||
|
@ -11465,19 +11482,31 @@
|
||||||
return $mainButtons.find('.find_battle_select_team .select').removeClass('disabled');
|
return $mainButtons.find('.find_battle_select_team .select').removeClass('disabled');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
depressFindBattleRandom = function() {
|
||||||
|
var $button, $mainButtons;
|
||||||
|
$mainButtons = $('.main_buttons');
|
||||||
|
$button = $mainButtons.find('.find_battle_random');
|
||||||
|
$button.removeClass("disabled");
|
||||||
|
$button.find('.find-icon').removeClass("icon-spinner spinner-anim").addClass("icon-earth");
|
||||||
|
return $mainButtons.find('.find_battle_select_team .select').removeClass('disabled');
|
||||||
|
};
|
||||||
|
|
||||||
$(window).load(function() {
|
$(window).load(function() {
|
||||||
var $mainButtons;
|
var $mainButtons;
|
||||||
$mainButtons = $('.main_buttons');
|
$mainButtons = $('.main_buttons');
|
||||||
PokeBattle.battles.on('add', function(battle) {
|
PokeBattle.battles.on('add', function(battle) {
|
||||||
if (!battle.get('spectating')) {
|
if (!battle.get('spectating')) {
|
||||||
depressFindBattle();
|
depressFindBattle();
|
||||||
return depressFindBattleUnranked();
|
depressFindBattleUnranked();
|
||||||
|
return depressFindBattleRandom();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
PokeBattle.primus.on('findBattleCanceled', depressFindBattle);
|
PokeBattle.primus.on('findBattleCanceled', depressFindBattle);
|
||||||
PokeBattle.events.on('findBattleCanceled', depressFindBattle);
|
PokeBattle.events.on('findBattleCanceled', depressFindBattle);
|
||||||
PokeBattle.primus.on('findBattleCanceledUnranked', depressFindBattleUnranked);
|
PokeBattle.primus.on('findBattleCanceledUnranked', depressFindBattleUnranked);
|
||||||
return PokeBattle.events.on('findBattleCanceledUnranked', depressFindBattleUnranked);
|
PokeBattle.events.on('findBattleCanceledUnranked', depressFindBattleUnranked);
|
||||||
|
PokeBattle.primus.on('findBattleCanceledRandom', depressFindBattleRandom);
|
||||||
|
return PokeBattle.events.on('findBattleCanceledRandom', depressFindBattleRandom);
|
||||||
});
|
});
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
|
@ -5315,14 +5315,19 @@
|
||||||
format = defaultformat();
|
format = defaultformat();
|
||||||
}
|
}
|
||||||
if (!$button.hasClass('disabled')) {
|
if (!$button.hasClass('disabled')) {
|
||||||
team = getSelectedTeam();
|
if ($eventName === "findBattleRandom") {
|
||||||
if (!team) {
|
teamJSON = [];
|
||||||
alert("You need to create a team using the Teambuilder before you can battle.");
|
disableButtons();
|
||||||
PokeBattle.navigation.showTeambuilder();
|
} else {
|
||||||
return;
|
team = getSelectedTeam();
|
||||||
|
if (!team) {
|
||||||
|
alert("You need to create a team using the Teambuilder before you can battle.");
|
||||||
|
PokeBattle.navigation.showTeambuilder();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
disableButtons();
|
||||||
|
teamJSON = team.toNonNullJSON().pokemon;
|
||||||
}
|
}
|
||||||
disableButtons();
|
|
||||||
teamJSON = team.toNonNullJSON().pokemon;
|
|
||||||
PokeBattle.primus.send($eventName, format, teamJSON, options.selectedAlt);
|
PokeBattle.primus.send($eventName, format, teamJSON, options.selectedAlt);
|
||||||
return $button.addClass('disabled').trigger('challenge');
|
return $button.addClass('disabled').trigger('challenge');
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
Query = require './queries'
|
Query = require './queries'
|
||||||
{Room} = require '../rooms'
|
{Room} = require '../rooms'
|
||||||
logger = require '../logger'
|
logger = require '../logger'
|
||||||
|
randomTeam = require('../randomTeams')
|
||||||
|
|
||||||
|
|
||||||
# Represents a single ongoing battle
|
# Represents a single ongoing battle
|
||||||
class @Battle extends Room
|
class @Battle extends Room
|
||||||
|
@ -41,7 +43,7 @@ class @Battle extends Room
|
||||||
action: (action) ->
|
action: (action) ->
|
||||||
@performMove(action.pokemon, action.move)
|
@performMove(action.pokemon, action.move)
|
||||||
|
|
||||||
constructor: (@id, @players, attributes = {}) ->
|
constructor: (@id, @players, attributes = {}, randomTeams = false) ->
|
||||||
super(@id)
|
super(@id)
|
||||||
# Number of pokemon on each side of the field
|
# Number of pokemon on each side of the field
|
||||||
@numActive = attributes.numActive || 1
|
@numActive = attributes.numActive || 1
|
||||||
|
@ -109,7 +111,13 @@ class @Battle extends Room
|
||||||
@playerIds.push(player.id)
|
@playerIds.push(player.id)
|
||||||
@playerNames.push(player.name)
|
@playerNames.push(player.name)
|
||||||
# TODO: Get the actual player object and use player.name
|
# TODO: Get the actual player object and use player.name
|
||||||
@teams[player.id] = new Team(this, player.id, player.name, player.team, @numActive)
|
if randomTeams
|
||||||
|
rteam2 = []
|
||||||
|
randomTeam.createTeam @format, @conditions, (rTeam, rteamName) ->
|
||||||
|
rteam2 = rTeam
|
||||||
|
@teams[player.id] = new Team(this, player.id, player.name, rteam2, @numActive)
|
||||||
|
else
|
||||||
|
@teams[player.id] = new Team(this, player.id, player.name, player.team, @numActive)
|
||||||
|
|
||||||
# Holds battle state information
|
# Holds battle state information
|
||||||
@replacing = false
|
@replacing = false
|
||||||
|
|
|
@ -4,10 +4,13 @@ alts = require('./alts')
|
||||||
auth = require('./auth')
|
auth = require('./auth')
|
||||||
ratings = require('./ratings')
|
ratings = require('./ratings')
|
||||||
errors = require('../shared/errors')
|
errors = require('../shared/errors')
|
||||||
|
conditions = require './conditions'
|
||||||
|
|
||||||
exports.Commands = Commands = {}
|
exports.Commands = Commands = {}
|
||||||
exports.HelpDescriptions = HelpDescriptions = {}
|
exports.HelpDescriptions = HelpDescriptions = {}
|
||||||
|
|
||||||
|
server_ = {}
|
||||||
|
|
||||||
desc = (description) ->
|
desc = (description) ->
|
||||||
desc.lastDescription = description
|
desc.lastDescription = description
|
||||||
|
|
||||||
|
@ -95,6 +98,7 @@ makeOwnerCommand = (commandNames..., func) ->
|
||||||
|
|
||||||
@executeCommand = (server, user, room, commandName, args...) ->
|
@executeCommand = (server, user, room, commandName, args...) ->
|
||||||
{args, callback} = parseArguments(args)
|
{args, callback} = parseArguments(args)
|
||||||
|
server_ = server
|
||||||
callback ||= ->
|
callback ||= ->
|
||||||
func = Commands[commandName]
|
func = Commands[commandName]
|
||||||
if !func
|
if !func
|
||||||
|
@ -348,3 +352,21 @@ makeOwnerCommand "eval", (user, room, next, pieces...) ->
|
||||||
catch e
|
catch e
|
||||||
user.error(errors.COMMAND_ERROR, room.name, "EVAL ERROR: #{e.message}")
|
user.error(errors.COMMAND_ERROR, room.name, "EVAL ERROR: #{e.message}")
|
||||||
next()
|
next()
|
||||||
|
|
||||||
|
desc "Makes the battle timed"
|
||||||
|
makeCommand "timer", (user, room, next) ->
|
||||||
|
controller = server_.findBattle(room.id)
|
||||||
|
isBattler = false
|
||||||
|
console.log(user.id)
|
||||||
|
player = room.getPlayer(user.id)
|
||||||
|
if 4 not in controller.battle.conditions and player != null
|
||||||
|
controller.battle.conditions.push(4)
|
||||||
|
conditions.attach(controller)
|
||||||
|
room.initTimer()
|
||||||
|
room.startingTimer()
|
||||||
|
room.onBeginTurn()
|
||||||
|
room.send
|
||||||
|
else if 4 in controller.battle.conditions
|
||||||
|
user.announce(room.name, "error", "The timer is already enabled!")
|
||||||
|
else if getPlayer == null
|
||||||
|
user.announce(room.name, "error", "You are not a battler!")
|
|
@ -211,29 +211,10 @@ createCondition Conditions.RATED_BATTLE,
|
||||||
createCondition Conditions.TIMED_BATTLE,
|
createCondition Conditions.TIMED_BATTLE,
|
||||||
attach:
|
attach:
|
||||||
initialize: ->
|
initialize: ->
|
||||||
@playerTimes = {}
|
@initTimer()
|
||||||
@lastActionTimes = {}
|
|
||||||
now = Date.now()
|
|
||||||
|
|
||||||
# Set up initial values
|
|
||||||
for id in @playerIds
|
|
||||||
@playerTimes[id] = now + @TEAM_PREVIEW_TIMER
|
|
||||||
|
|
||||||
# Set up timers and event listeners
|
|
||||||
check = () =>
|
|
||||||
@startBattle()
|
|
||||||
@sendUpdates()
|
|
||||||
@teamPreviewTimerId = setTimeout(check, @TEAM_PREVIEW_TIMER)
|
|
||||||
@once('end', => clearTimeout(@teamPreviewTimerId))
|
|
||||||
@once('start', => clearTimeout(@teamPreviewTimerId))
|
|
||||||
|
|
||||||
start: ->
|
start: ->
|
||||||
nowTime = Date.now()
|
@startingTimer()
|
||||||
for id in @playerIds
|
|
||||||
@playerTimes[id] = nowTime + @DEFAULT_TIMER
|
|
||||||
# Remove first turn since we'll be increasing it again.
|
|
||||||
@playerTimes[id] -= @TIMER_PER_TURN_INCREASE
|
|
||||||
@startTimer()
|
|
||||||
|
|
||||||
requestActions: (playerId) ->
|
requestActions: (playerId) ->
|
||||||
# If a player has selected a move, then there's an amount of time spent
|
# If a player has selected a move, then there's an amount of time spent
|
||||||
|
@ -258,11 +239,7 @@ createCondition Conditions.TIMED_BATTLE,
|
||||||
|
|
||||||
# Show players updated times
|
# Show players updated times
|
||||||
beginTurn: ->
|
beginTurn: ->
|
||||||
remainingTimes = []
|
@onBeginTurn()
|
||||||
for id in @playerIds
|
|
||||||
@addTime(id, @TIMER_PER_TURN_INCREASE)
|
|
||||||
remainingTimes.push(@timeRemainingFor(id))
|
|
||||||
@send('updateTimers', @id, remainingTimes)
|
|
||||||
|
|
||||||
continueTurn: ->
|
continueTurn: ->
|
||||||
for id in @playerIds
|
for id in @playerIds
|
||||||
|
@ -285,6 +262,38 @@ createCondition Conditions.TIMED_BATTLE,
|
||||||
TIMER_CAP: 3 * 60 * 1000 # three minutes
|
TIMER_CAP: 3 * 60 * 1000 # three minutes
|
||||||
TEAM_PREVIEW_TIMER: 1.5 * 60 * 1000 # 1 minute and 30 seconds
|
TEAM_PREVIEW_TIMER: 1.5 * 60 * 1000 # 1 minute and 30 seconds
|
||||||
|
|
||||||
|
initTimer: ->
|
||||||
|
@playerTimes = {}
|
||||||
|
@lastActionTimes = {}
|
||||||
|
now = Date.now()
|
||||||
|
|
||||||
|
# Set up initial values
|
||||||
|
for id in @playerIds
|
||||||
|
@playerTimes[id] = now + @TEAM_PREVIEW_TIMER
|
||||||
|
|
||||||
|
# Set up timers and event listeners
|
||||||
|
check = () =>
|
||||||
|
@startBattle()
|
||||||
|
@sendUpdates()
|
||||||
|
@teamPreviewTimerId = setTimeout(check, @TEAM_PREVIEW_TIMER)
|
||||||
|
@once('end', => clearTimeout(@teamPreviewTimerId))
|
||||||
|
@once('start', => clearTimeout(@teamPreviewTimerId))
|
||||||
|
|
||||||
|
startingTimer: ->
|
||||||
|
nowTime = Date.now()
|
||||||
|
for id in @playerIds
|
||||||
|
@playerTimes[id] = nowTime + @DEFAULT_TIMER
|
||||||
|
# Remove first turn since we'll be increasing it again.
|
||||||
|
@playerTimes[id] -= @TIMER_PER_TURN_INCREASE
|
||||||
|
@startTimer()
|
||||||
|
|
||||||
|
onBeginTurn: ->
|
||||||
|
remainingTimes = []
|
||||||
|
for id in @playerIds
|
||||||
|
@addTime(id, @TIMER_PER_TURN_INCREASE)
|
||||||
|
remainingTimes.push(@timeRemainingFor(id))
|
||||||
|
@send('updateTimers', @id, remainingTimes)
|
||||||
|
|
||||||
startTimer: (msecs) ->
|
startTimer: (msecs) ->
|
||||||
msecs ?= @DEFAULT_TIMER
|
msecs ?= @DEFAULT_TIMER
|
||||||
@timerId = setTimeout(@declareWinner.bind(this), msecs)
|
@timerId = setTimeout(@declareWinner.bind(this), msecs)
|
||||||
|
|
|
@ -283,7 +283,7 @@ CLIENT_VERSION = assets.getVersion()
|
||||||
if user.authority == auth.levels.OWNER
|
if user.authority == auth.levels.OWNER
|
||||||
teamArr = []
|
teamArr = []
|
||||||
for [1..number]
|
for [1..number]
|
||||||
randomTeam.createTeam format, (team) ->
|
randomTeam.createTeamBookshelf format, [], (team) ->
|
||||||
teamArr.push(team)
|
teamArr.push(team)
|
||||||
teams = new database.Teams(teamArr)
|
teams = new database.Teams(teamArr)
|
||||||
spark.send('receiveTeams', teams.toJSON())
|
spark.send('receiveTeams', teams.toJSON())
|
||||||
|
@ -383,9 +383,6 @@ CLIENT_VERSION = assets.getVersion()
|
||||||
callback(battleMetadata)
|
callback(battleMetadata)
|
||||||
|
|
||||||
spark.on 'findBattle', (format, team, altName=null) ->
|
spark.on 'findBattle', (format, team, altName=null) ->
|
||||||
console.log('find battle')
|
|
||||||
console.log(format)
|
|
||||||
console.log(team)
|
|
||||||
return unless _.isString(format)
|
return unless _.isString(format)
|
||||||
return unless _.isObject(team)
|
return unless _.isObject(team)
|
||||||
return unless !altName || _.isString(altName)
|
return unless !altName || _.isString(altName)
|
||||||
|
@ -394,7 +391,7 @@ CLIENT_VERSION = assets.getVersion()
|
||||||
if not valid
|
if not valid
|
||||||
user.error(errors.INVALID_ALT_NAME, "You do not own this alt")
|
user.error(errors.INVALID_ALT_NAME, "You do not own this alt")
|
||||||
else
|
else
|
||||||
validationErrors = server.queuePlayer(user.name, team, format, altName)
|
validationErrors = server.queuePlayer(user.name, team, format, altName, "ranked")
|
||||||
if validationErrors.length > 0
|
if validationErrors.length > 0
|
||||||
user.error(errors.FIND_BATTLE, validationErrors)
|
user.error(errors.FIND_BATTLE, validationErrors)
|
||||||
|
|
||||||
|
@ -411,7 +408,7 @@ CLIENT_VERSION = assets.getVersion()
|
||||||
if not valid
|
if not valid
|
||||||
user.error(errors.INVALID_ALT_NAME, "You do not own this alt")
|
user.error(errors.INVALID_ALT_NAME, "You do not own this alt")
|
||||||
else
|
else
|
||||||
validationErrors = server.queuePlayerunranked(user.name, team, format, altName)
|
validationErrors = server.queuePlayer(user.name, team, format, altName, "unranked")
|
||||||
if validationErrors.length > 0
|
if validationErrors.length > 0
|
||||||
user.error(errors.FIND_BATTLE, validationErrors)
|
user.error(errors.FIND_BATTLE, validationErrors)
|
||||||
|
|
||||||
|
@ -419,6 +416,23 @@ CLIENT_VERSION = assets.getVersion()
|
||||||
server.removePlayerunranked(user.name)
|
server.removePlayerunranked(user.name)
|
||||||
user.send("findBattleCanceledUnranked")
|
user.send("findBattleCanceledUnranked")
|
||||||
|
|
||||||
|
spark.on 'findBattleRandom', (format, team, altName=null) ->
|
||||||
|
return unless _.isString(format)
|
||||||
|
return unless _.isObject(team)
|
||||||
|
return unless !altName || _.isString(altName)
|
||||||
|
# Note: If altName == null, then isAltOwnedBy will return true
|
||||||
|
alts.isAltOwnedBy user.name, altName, (err, valid) ->
|
||||||
|
if not valid
|
||||||
|
user.error(errors.INVALID_ALT_NAME, "You do not own this alt")
|
||||||
|
else
|
||||||
|
validationErrors = server.queuePlayer(user.name, team, format, altName, "random")
|
||||||
|
if validationErrors.length > 0
|
||||||
|
user.error(errors.FIND_BATTLE, validationErrors)
|
||||||
|
|
||||||
|
spark.on 'cancelFindBattleRandom', ->
|
||||||
|
server.removePlayerrandom(user.name)
|
||||||
|
user.send("findBattleCanceledRandom")
|
||||||
|
|
||||||
spark.on 'sendMove', (battleId, moveName, slot, forTurn, options, callback) ->
|
spark.on 'sendMove', (battleId, moveName, slot, forTurn, options, callback) ->
|
||||||
return unless _.isString(moveName)
|
return unless _.isString(moveName)
|
||||||
return unless _.isFinite(slot)
|
return unless _.isFinite(slot)
|
||||||
|
@ -497,10 +511,20 @@ CLIENT_VERSION = assets.getVersion()
|
||||||
ratings.getRanks ratingKeys, (err, fullRanks) ->
|
ratings.getRanks ratingKeys, (err, fullRanks) ->
|
||||||
ranks = _.compact(fullRanks)
|
ranks = _.compact(fullRanks)
|
||||||
setTimeout(battleSearchUnranked, 5 * 1000)
|
setTimeout(battleSearchUnranked, 5 * 1000)
|
||||||
|
battleSearchRandom = ->
|
||||||
|
server.beginBattlesrandom (err, battleIds) ->
|
||||||
|
if err then return
|
||||||
|
for id in battleIds
|
||||||
|
battle = server.findBattle(id)
|
||||||
|
playerIds = battle.getPlayerIds()
|
||||||
|
ratingKeys = playerIds.map((id) -> battle.getPlayer(id).ratingKey)
|
||||||
|
ratings.getRanks ratingKeys, (err, fullRanks) ->
|
||||||
|
ranks = _.compact(fullRanks)
|
||||||
|
setTimeout(battleSearchRandom, 5 * 1000)
|
||||||
|
|
||||||
battleSearch()
|
battleSearch()
|
||||||
battleSearchUnranked()
|
battleSearchUnranked()
|
||||||
|
battleSearchRandom()
|
||||||
|
|
||||||
httpServer.listen(port)
|
httpServer.listen(port)
|
||||||
|
|
||||||
|
|
|
@ -7,46 +7,59 @@ Formats = FormatsClass.Formats()
|
||||||
pokemonArr = []
|
pokemonArr = []
|
||||||
hasmega = false
|
hasmega = false
|
||||||
|
|
||||||
createTeam = (format, next) ->
|
createTeamBookshelf = (format, requs, next) ->
|
||||||
|
createTeam format, requs, (mons, teamname) ->
|
||||||
|
team = {}
|
||||||
|
team.name = teamname
|
||||||
|
team.id = Math.floor(Math.random() * (10000000) + 10000000)
|
||||||
|
team.generation = Formats[format].generation
|
||||||
|
team.pokemon = mons
|
||||||
|
|
||||||
|
attributes = _.pick(team, 'id', 'name', 'generation')
|
||||||
|
attributes['trainer_id'] = 1
|
||||||
|
attributes['contents'] = JSON.stringify(mons)
|
||||||
|
|
||||||
|
Team = new database.Team(attributes)
|
||||||
|
next(Team)
|
||||||
|
|
||||||
|
createTeam = (format, requs, next) ->
|
||||||
pokemonArr = []
|
pokemonArr = []
|
||||||
hasmega = false
|
hasmega = false
|
||||||
|
|
||||||
conditions = Formats[format]
|
genTeam = ->
|
||||||
if conditions.tierBased == false
|
conditions = Formats[format]
|
||||||
console.log("PBV is not supported")
|
if conditions.tierBased == false
|
||||||
return
|
console.log("PBV is not supported")
|
||||||
#throw error
|
return
|
||||||
generation = conditions.generation.toUpperCase()
|
#throw error
|
||||||
for condNum in conditions.conditions
|
generation = conditions.generation.toUpperCase()
|
||||||
for conditionName, conditionNumber of FormatsClass.Conditions
|
for condNum in conditions.conditions
|
||||||
if conditionNumber is condNum
|
for conditionName, conditionNumber of FormatsClass.Conditions
|
||||||
if /TIER_/.test(conditionName)
|
if conditionNumber is condNum
|
||||||
tier = conditionName.replace /TIER_/, ""
|
if /TIER_/.test(conditionName)
|
||||||
break
|
tier = conditionName.replace /TIER_/, ""
|
||||||
getValidFormes generation, tier, (list) ->
|
break
|
||||||
if list.length < 6
|
getValidFormes generation, tier, (list) ->
|
||||||
console.log("Not enough pokemon in this tier to make a team")
|
if list.length < 6
|
||||||
return
|
console.log("Not enough pokemon in this tier to make a team")
|
||||||
team = {}
|
return
|
||||||
team.name = "Random" + tier
|
getPokemonArr = ->
|
||||||
team.id = Math.floor(Math.random() * (10000000) + 10000000)
|
if pokemonArr.length < 6
|
||||||
team.generation = conditions.generation
|
generatePokemon list, generation, (pkmn) ->
|
||||||
getPokemonArr = ->
|
pokemonArr.push(pkmn)
|
||||||
if pokemonArr.length < 6
|
getPokemonArr()
|
||||||
generatePokemon list, generation, (pkmn) ->
|
getPokemonArr()
|
||||||
pokemonArr.push(pkmn)
|
|
||||||
getPokemonArr()
|
|
||||||
getPokemonArr()
|
|
||||||
|
|
||||||
pokemonArr.splice(6)
|
pokemonArr.splice(6)
|
||||||
team.pokemon = pokemonArr
|
|
||||||
|
|
||||||
attributes = _.pick(team, 'id', 'name', 'generation')
|
err = require('./conditions').validateTeam(requs, pokemonArr, gen.GenerationJSON[generation])
|
||||||
attributes['trainer_id'] = 1
|
if err.length > 0
|
||||||
attributes['contents'] = JSON.stringify(team.pokemon)
|
console.log(err)
|
||||||
|
genTeam()
|
||||||
Team = new database.Team(attributes)
|
return
|
||||||
next(Team)
|
teamname = "Random" + tier
|
||||||
|
next(pokemonArr, teamname)
|
||||||
|
genTeam()
|
||||||
|
|
||||||
getValidFormes = (generation, tier, next) ->
|
getValidFormes = (generation, tier, next) ->
|
||||||
filteredlist = []
|
filteredlist = []
|
||||||
|
@ -228,4 +241,4 @@ determineIVs = (type) ->
|
||||||
ivObj.specialAttack = 30
|
ivObj.specialAttack = 30
|
||||||
return ivObj
|
return ivObj
|
||||||
|
|
||||||
module.exports = {createTeam}
|
module.exports = {createTeamBookshelf, createTeam}
|
||||||
|
|
|
@ -44,11 +44,14 @@ class @BattleServer
|
||||||
constructor: ->
|
constructor: ->
|
||||||
@queues = {}
|
@queues = {}
|
||||||
@unrankedqueues = {}
|
@unrankedqueues = {}
|
||||||
|
@randomqueues = {}
|
||||||
allformats = ConditionsFunc.Formats()
|
allformats = ConditionsFunc.Formats()
|
||||||
for format of allformats
|
for format of allformats
|
||||||
@queues[format] = new BattleQueue()
|
@queues[format] = new BattleQueue()
|
||||||
@unrankedqueues[format] = new BattleQueue()
|
@unrankedqueues[format] = new BattleQueue()
|
||||||
@unrankedqueues[format].setUnranked()
|
@unrankedqueues[format].setUnranked()
|
||||||
|
@randomqueues[format] = new BattleQueue()
|
||||||
|
@randomqueues[format].setUnranked()
|
||||||
@battles = {}
|
@battles = {}
|
||||||
|
|
||||||
# A hash mapping users to battles.
|
# A hash mapping users to battles.
|
||||||
|
@ -211,18 +214,26 @@ class @BattleServer
|
||||||
|
|
||||||
# Adds the player to the queue. Note that there is no validation on whether altName
|
# Adds the player to the queue. Note that there is no validation on whether altName
|
||||||
# is correct, so make
|
# is correct, so make
|
||||||
queuePlayer: (playerId, team, format = DEFAULT_FORMAT, altName) ->
|
queuePlayer: (playerId, team, format = DEFAULT_FORMAT, altName, queuetype) ->
|
||||||
if @isLockedDown()
|
if @isLockedDown()
|
||||||
err = ["The server is restarting after all battles complete. No new battles can start at this time."]
|
err = ["The server is restarting after all battles complete. No new battles can start at this time."]
|
||||||
else if format != DEFAULT_FORMAT
|
else if format != DEFAULT_FORMAT and queuetype is "ranked"
|
||||||
# TODO: Implement ratings for other formats
|
# TODO: Implement ratings for other formats
|
||||||
err = ["The server doesn't support this ladder at this time. Please ask for challenges instead."]
|
err = ["The server doesn't support this ladder at this time. Please ask for challenges instead."]
|
||||||
else
|
else
|
||||||
err = @validateTeam(team, format, FIND_BATTLE_CONDITIONS)
|
if queuetype isnt "random"
|
||||||
|
err = @validateTeam(team, format, FIND_BATTLE_CONDITIONS)
|
||||||
|
else
|
||||||
|
err = []
|
||||||
if err.length == 0
|
if err.length == 0
|
||||||
name = @users.get(playerId).name
|
name = @users.get(playerId).name
|
||||||
ratingKey = alts.uniqueId(playerId, altName)
|
ratingKey = alts.uniqueId(playerId, altName)
|
||||||
@queues[format].add(playerId, altName || name, team, ratingKey)
|
if queuetype is "ranked"
|
||||||
|
@queues[format].add(playerId, altName || name, team, ratingKey)
|
||||||
|
else if queuetype is "unranked"
|
||||||
|
@unrankedqueues[format].add(playerId, altName || name, team, ratingKey)
|
||||||
|
else if queuetype is "random"
|
||||||
|
@randomqueues[format].add(playerId, altName || name, team, ratingKey)
|
||||||
return err
|
return err
|
||||||
|
|
||||||
queuedPlayers: (format = DEFAULT_FORMAT) ->
|
queuedPlayers: (format = DEFAULT_FORMAT) ->
|
||||||
|
@ -253,16 +264,6 @@ class @BattleServer
|
||||||
#########################################################################################
|
#########################################################################################
|
||||||
# Adds the player to the queue. Note that there is no validation on whether altName
|
# Adds the player to the queue. Note that there is no validation on whether altName
|
||||||
# is correct, so make
|
# is correct, so make
|
||||||
queuePlayerunranked: (playerId, team, format = DEFAULT_FORMAT, altName) ->
|
|
||||||
if @isLockedDown()
|
|
||||||
err = ["The server is restarting after all battles complete. No new battles can start at this time."]
|
|
||||||
else
|
|
||||||
err = @validateTeam(team, format, FIND_BATTLE_CONDITIONS)
|
|
||||||
if err.length == 0
|
|
||||||
name = @users.get(playerId).name
|
|
||||||
ratingKey = alts.uniqueId(playerId, altName)
|
|
||||||
@unrankedqueues[format].add(playerId, altName || name, team, ratingKey)
|
|
||||||
return err
|
|
||||||
|
|
||||||
queuedPlayersunranked: (format = DEFAULT_FORMAT) ->
|
queuedPlayersunranked: (format = DEFAULT_FORMAT) ->
|
||||||
@unrankedqueues[format].queuedPlayers()
|
@unrankedqueues[format].queuedPlayers()
|
||||||
|
@ -289,9 +290,40 @@ class @BattleServer
|
||||||
return next(err) if err
|
return next(err) if err
|
||||||
next(null, _.flatten(battleIds))
|
next(null, _.flatten(battleIds))
|
||||||
return true
|
return true
|
||||||
|
#########################################################################################
|
||||||
|
# Adds the player to the queue. Note that there is no validation on whether altName
|
||||||
|
# is correct, so make
|
||||||
|
|
||||||
|
queuedPlayersrandom: (format = DEFAULT_FORMAT) ->
|
||||||
|
@randomqueues[format].queuedPlayers()
|
||||||
|
|
||||||
|
removePlayerrandom: (playerId, format = DEFAULT_FORMAT) ->
|
||||||
|
return false if format not of @randomqueues
|
||||||
|
@randomqueues[format].remove(playerId)
|
||||||
|
return true
|
||||||
|
|
||||||
|
beginBattlesrandom: (next) ->
|
||||||
|
allformats = ConditionsFunc.Formats()
|
||||||
|
array = for format in Object.keys(allformats)
|
||||||
|
do (format) => (callback) =>
|
||||||
|
@randomqueues[format].pairPlayers (err, pairs) =>
|
||||||
|
if err then console.log(err)
|
||||||
|
if err then return callback(err)
|
||||||
|
# Create a battle for each pair
|
||||||
|
battleIds = []
|
||||||
|
for pair in pairs
|
||||||
|
id = @createBattle(format, pair, FIND_BATTLE_CONDITIONS_UNRANKED, true)
|
||||||
|
battleIds.push(id)
|
||||||
|
callback(null, battleIds)
|
||||||
|
async.parallel array, (err, battleIds) ->
|
||||||
|
return next(err) if err
|
||||||
|
next(null, _.flatten(battleIds))
|
||||||
|
return true
|
||||||
|
|
||||||
|
|
||||||
#########################################################################################
|
#########################################################################################
|
||||||
# Creates a battle and returns its battleId
|
# Creates a battle and returns its battleId
|
||||||
createBattle: (rawFormat = DEFAULT_FORMAT, pair = [], conditions = []) ->
|
createBattle: (rawFormat = DEFAULT_FORMAT, pair = [], conditions = [], random = false) ->
|
||||||
allformats = ConditionsFunc.Formats()
|
allformats = ConditionsFunc.Formats()
|
||||||
format = allformats[rawFormat]
|
format = allformats[rawFormat]
|
||||||
generation = format.generation
|
generation = format.generation
|
||||||
|
@ -300,7 +332,7 @@ class @BattleServer
|
||||||
{BattleController} = require("../server/#{generation}/battle_controller")
|
{BattleController} = require("../server/#{generation}/battle_controller")
|
||||||
playerIds = pair.map((user) -> user.name)
|
playerIds = pair.map((user) -> user.name)
|
||||||
battleId = @generateBattleId(playerIds)
|
battleId = @generateBattleId(playerIds)
|
||||||
battle = new Battle(battleId, pair, format: rawFormat, conditions: _.clone(conditions))
|
battle = new Battle(battleId, pair, format: rawFormat, conditions: _.clone(conditions), random)
|
||||||
@battles[battleId] = new BattleController(battle)
|
@battles[battleId] = new BattleController(battle)
|
||||||
for player in pair
|
for player in pair
|
||||||
# Add user to spectators
|
# Add user to spectators
|
||||||
|
|
Loading…
Reference in New Issue