Added Find Battle Unranked
This commit is contained in:
parent
398d23a0d6
commit
16ac69171d
|
@ -14,7 +14,7 @@ html, body
|
|||
margin 0
|
||||
font-size 100%
|
||||
normal-font()
|
||||
background $background-color url("//media.pokebattle.com/img/bg.png")
|
||||
background $background-color blue
|
||||
line-height normal
|
||||
|
||||
ul, ol
|
||||
|
|
|
@ -4,6 +4,57 @@ $ ->
|
|||
$mainButtons.on 'click', '.teambuilder_button', (e) ->
|
||||
PokeBattle.navigation.showTeambuilder()
|
||||
|
||||
challengeobjunranked =
|
||||
eventName: "findBattleunranked"
|
||||
populate: $mainButtons.find('.find_battle_select_team')
|
||||
button: $mainButtons.find('.find_battle_non_ranked')
|
||||
defaultClauses: [
|
||||
Conditions.SLEEP_CLAUSE
|
||||
Conditions.EVASION_CLAUSE
|
||||
Conditions.SPECIES_CLAUSE
|
||||
Conditions.OHKO_CLAUSE
|
||||
Conditions.PRANKSTER_SWAGGER_CLAUSE
|
||||
Conditions.UNRELEASED_BAN
|
||||
Conditions.TIMED_BATTLE
|
||||
]
|
||||
blockedClauses: true
|
||||
|
||||
challengeobj =
|
||||
eventName: "findBattle"
|
||||
populate: $mainButtons.find('.find_battle_select_team')
|
||||
button: $mainButtons.find('.find_battle')
|
||||
defaultClauses: [
|
||||
Conditions.SLEEP_CLAUSE
|
||||
Conditions.EVASION_CLAUSE
|
||||
Conditions.SPECIES_CLAUSE
|
||||
Conditions.OHKO_CLAUSE
|
||||
Conditions.PRANKSTER_SWAGGER_CLAUSE
|
||||
Conditions.UNRELEASED_BAN
|
||||
Conditions.RATED_BATTLE
|
||||
Conditions.TIMED_BATTLE
|
||||
]
|
||||
blockedClauses: true
|
||||
|
||||
challengepaneobjunranked = new challengePaneObject(challengeobjunranked)
|
||||
challengePaneArray.push(challengepaneobjunranked)
|
||||
challengepaneobj = new challengePaneObject(challengeobj)
|
||||
challengePaneArray.push(challengepaneobj)
|
||||
|
||||
createChallengePane
|
||||
eventName: "findBattleunranked"
|
||||
populate: $mainButtons.find('.find_battle_select_team')
|
||||
button: $mainButtons.find('.find_battle_non_ranked')
|
||||
defaultClauses: [
|
||||
Conditions.SLEEP_CLAUSE
|
||||
Conditions.EVASION_CLAUSE
|
||||
Conditions.SPECIES_CLAUSE
|
||||
Conditions.OHKO_CLAUSE
|
||||
Conditions.PRANKSTER_SWAGGER_CLAUSE
|
||||
Conditions.UNRELEASED_BAN
|
||||
Conditions.TIMED_BATTLE
|
||||
]
|
||||
blockedClauses: true
|
||||
|
||||
createChallengePane
|
||||
eventName: "findBattle"
|
||||
populate: $mainButtons.find('.find_battle_select_team')
|
||||
|
@ -26,6 +77,12 @@ $ ->
|
|||
.addClass('icon-spinner spinner-anim')
|
||||
.removeClass("icon-earth")
|
||||
|
||||
$mainButtons.find('.find_battle_non_ranked').on 'challenge', ->
|
||||
$this = $(this)
|
||||
$this.find('.find-icon')
|
||||
.addClass('icon-spinner spinner-anim')
|
||||
.removeClass("icon-earth")
|
||||
|
||||
$mainButtons.find('.display_credits').click ->
|
||||
$modal = PokeBattle.modal('modals/credits')
|
||||
$modal.find('.modal-footer button').first().focus()
|
||||
|
@ -40,11 +97,24 @@ depressFindBattle = ->
|
|||
.addClass("icon-earth")
|
||||
$mainButtons.find('.find_battle_select_team .select').removeClass('disabled')
|
||||
|
||||
depressFindBattleUnranked = ->
|
||||
$mainButtons = $('.main_buttons')
|
||||
$button = $mainButtons.find('.find_battle_non_ranked')
|
||||
$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 ->
|
||||
$mainButtons = $('.main_buttons')
|
||||
PokeBattle.battles.on 'add', (battle) ->
|
||||
if !battle.get('spectating')
|
||||
depressFindBattle()
|
||||
depressFindBattleUnranked()
|
||||
|
||||
PokeBattle.primus.on 'findBattleCanceled', depressFindBattle
|
||||
PokeBattle.events.on 'findBattleCanceled', depressFindBattle
|
||||
|
||||
PokeBattle.primus.on 'findBattleCanceledUnranked', depressFindBattleUnranked
|
||||
PokeBattle.events.on 'findBattleCanceledUnranked', depressFindBattleUnranked
|
|
@ -1,5 +1,16 @@
|
|||
# eventName should be one of "challenge" or "find battle"
|
||||
# opts may include whether to enable clauses, for example
|
||||
@challengePaneArray = []
|
||||
|
||||
class @challengePaneObject
|
||||
constructor: (@object) ->
|
||||
@event = @object.eventName
|
||||
@button = @object.button
|
||||
@populate = @object.populate
|
||||
@clauses = @object.defaultClauses
|
||||
@blockedClauses = @object.blockedClauses
|
||||
|
||||
|
||||
@createChallengePane = (opts) ->
|
||||
$wrapper = opts.populate
|
||||
$button = opts.button
|
||||
|
@ -18,7 +29,7 @@
|
|||
|
||||
selectedTeamId = null
|
||||
selectedAlt = null
|
||||
|
||||
$PaneArray = @challengePaneArray
|
||||
getSelectedTeam = ->
|
||||
PokeBattle.TeamStore.get(selectedTeamId) || PokeBattle.TeamStore.at(0)
|
||||
|
||||
|
@ -70,11 +81,13 @@
|
|||
|
||||
# Implement finding battle/challenging
|
||||
$button.on 'click.challenge', ->
|
||||
thisChallenge = _.find($PaneArray, (butt) -> butt.button.selector is $button.selector)
|
||||
console.log(thisChallenge)
|
||||
# Start requesting for notify permission here
|
||||
PokeBattle.requestNotifyPermission()
|
||||
|
||||
format = $selectFormat.data('format')
|
||||
|
||||
if typeof format == "undefined" and typeof personId == "undefined"
|
||||
format = $('.select-format').data('format')
|
||||
# Toggle state when you press the button.
|
||||
if !$button.hasClass('disabled')
|
||||
team = getSelectedTeam()
|
||||
|
@ -90,7 +103,7 @@
|
|||
$clauses = $wrapper.find('input:checked[type="checkbox"]')
|
||||
clauses = []
|
||||
$clauses.each(-> clauses.push(parseInt($(this).val(), 10)))
|
||||
PokeBattle.primus.send(eventName, personId, format, teamJSON, clauses, selectedAlt)
|
||||
PokeBattle.primus.send(eventName, personId, format, teamJSON, thisChallenge.clauses, selectedAlt)
|
||||
else
|
||||
PokeBattle.primus.send(eventName, format, teamJSON, selectedAlt)
|
||||
$button.addClass('disabled').trigger('challenge')
|
||||
|
|
|
@ -161,7 +161,7 @@ class @BattleView extends Backbone.View
|
|||
team = $this.data('team')
|
||||
slot = $this.data('slot')
|
||||
pokemon = @model.getPokemon(team, slot)
|
||||
@pokemonPopover($this, pokemon)
|
||||
#@pokemonPopover($this, pokemon)
|
||||
@renderTimers()
|
||||
this
|
||||
|
||||
|
@ -278,6 +278,8 @@ class @BattleView extends Backbone.View
|
|||
$newPokemon.attr('data-slot', slot)
|
||||
$newPokemon.removeClass('hidden')
|
||||
@pokemonPopover($newSprite, pokemon)
|
||||
|
||||
pokemon.set('beeninbattle', true)
|
||||
|
||||
@cannedText('SENT_OUT', player, player, slot)
|
||||
|
||||
|
|
|
@ -6,9 +6,13 @@ block content
|
|||
.chat
|
||||
.main_buttons
|
||||
.section
|
||||
.button.big.find_battle
|
||||
.button.big.find_battle_non_ranked
|
||||
span.find-icon.icon-earth
|
||||
| Find battle
|
||||
p
|
||||
.button.big.find_battle
|
||||
span.find-icon.icon-earth
|
||||
| Ranked battle
|
||||
.find_battle_select_team
|
||||
.section
|
||||
.button.teambuilder_button
|
||||
|
|
|
@ -4,7 +4,7 @@ html
|
|||
meta(http-equiv="X-UA-Compatible", content="IE=Edge")
|
||||
meta(name="viewport", content="width=device-width, initial-scale=1.0, user-scalable=0")
|
||||
title PokeBattle
|
||||
link(rel="icon", type="image/png", href="//media.pokebattle.com/img/favicon.png")
|
||||
link(rel="icon", type="image/png", href="../Sprites/favicon.png")
|
||||
link(rel="stylesheet", href=asset_path("css/vendor.css"))
|
||||
link(rel="stylesheet", href=asset_path("css/main.css"))
|
||||
body(class = bodyClass)
|
||||
|
|
|
@ -9,17 +9,32 @@ each team in [ yourTeam, opponentTeam ]
|
|||
.pokemon_icons
|
||||
- var teamvisible = team.collection.parents[0].get('visibleteam')
|
||||
- var isdef = typeof teamvisible
|
||||
if isdef != 'undefined' && teamvisible
|
||||
- var orig = team.get('pokemon')
|
||||
- var teamPokemon = team.getRandomOrder()
|
||||
- for (var i = 0, len = teamPokemon.length; i < len; i += 1)
|
||||
- var pokemon = teamPokemon[i]
|
||||
if pokemon
|
||||
.icon_wrapper
|
||||
- var origpkmn = orig.findWhere({species: pokemon.species});
|
||||
- var faintClass = (origpkmn.isFainted() ? 'fainted' : '')
|
||||
- var style = window.PokemonIconBackground(origpkmn)
|
||||
- var orig = team.get('pokemon')
|
||||
- var teamPokemon = team.getRandomOrder()
|
||||
- for (var i = 0, len = teamPokemon.length; i < len; i += 1)
|
||||
- var pokemon = teamPokemon[i]
|
||||
if pokemon
|
||||
.icon_wrapper
|
||||
- var origpkmn = orig.findWhere({species: pokemon.species});
|
||||
- var faintClass = (origpkmn.isFainted() ? 'fainted' : '')
|
||||
- var style = window.PokemonIconBackground(origpkmn)
|
||||
if isdef != 'undefined' && teamvisible
|
||||
a.pokemon_icon(href=window.PokemonIconBackground(origpkmn), target="_blank", class = faintClass, style = style, data-team = teamIndex, data-slot = i)
|
||||
if !origpkmn.isFainted()
|
||||
.pokemon_hp_background
|
||||
.pokemon_hp(style="height: " + (origpkmn.getSpecies().id) + "%", class=origpkmn.getHPColor())
|
||||
else
|
||||
- var hasbeeninbattle = origpkmn.get('beeninbattle')
|
||||
if hasbeeninbattle == true
|
||||
- console.log('hasbeeninbattle')
|
||||
a.pokemon_icon(href=window.PokemonIconBackground(origpkmn), target="_blank", class = faintClass, style = style, data-team = teamIndex, data-slot = i)
|
||||
if !origpkmn.isFainted()
|
||||
.pokemon_hp_background
|
||||
.pokemon_hp(style="height: " + (origpkmn.getSpecies().id) + "%", class=origpkmn.getHPColor())
|
||||
else
|
||||
- console.log('hasnoybeeninbattle')
|
||||
- var newstyle = "background:url('../Sprites/Icons/iconempty.png')!important; background-size: cover!important;"
|
||||
a.pokemon_icon(href="", target="_blank", class = faintClass, style = newstyle, data-team = teamIndex, data-slot = i)
|
||||
if !origpkmn.isFainted()
|
||||
.pokemon_hp_background
|
||||
.pokemon_hp(style="height: " + (origpkmn.getSpecies().id) + "%", class=origpkmn.getHPColor())
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 301 B |
Binary file not shown.
After Width: | Height: | Size: 597 B |
|
@ -6,7 +6,7 @@
|
|||
.red{color:#dc4e48}
|
||||
.yellow{color:#b92}
|
||||
.grey{color:#999}
|
||||
html,body{color:#333332;padding:0;margin:0;font-size:100%;font-family:'proxima-nova','Helvetica Neue',Calibri,'Droid Sans',Helvetica,Arial,sans-serif;background:#f3f3f3 url("//media.pokebattle.com/img/bg.png");line-height:normal}
|
||||
html,body{color:#333332;padding:0;margin:0;font-size:100%;font-family:'proxima-nova','Helvetica Neue',Calibri,'Droid Sans',Helvetica,Arial,sans-serif;background:#f3f3f3 #00f;line-height:normal}
|
||||
ul,ol{list-style:none}
|
||||
ul,ol,p{margin:0;padding:0}
|
||||
#content{position:absolute;top:0;left:150px;right:0;bottom:0;-webkit-box-shadow:0 0 10px #000;box-shadow:0 0 10px #000}
|
||||
|
|
|
@ -3146,8 +3146,7 @@
|
|||
$this = $(el);
|
||||
team = $this.data('team');
|
||||
slot = $this.data('slot');
|
||||
pokemon = _this.model.getPokemon(team, slot);
|
||||
return _this.pokemonPopover($this, pokemon);
|
||||
return pokemon = _this.model.getPokemon(team, slot);
|
||||
};
|
||||
})(this));
|
||||
this.renderTimers();
|
||||
|
@ -3338,6 +3337,7 @@
|
|||
$newPokemon.attr('data-slot', slot);
|
||||
$newPokemon.removeClass('hidden');
|
||||
this.pokemonPopover($newSprite, pokemon);
|
||||
pokemon.set('beeninbattle', true);
|
||||
this.cannedText('SENT_OUT', player, player, slot);
|
||||
if (this.skip != null) {
|
||||
$oldPokemon.css({
|
||||
|
@ -7476,8 +7476,24 @@
|
|||
(function() {
|
||||
var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
this.challengePaneArray = [];
|
||||
|
||||
this.challengePaneObject = (function() {
|
||||
function challengePaneObject(object) {
|
||||
this.object = object;
|
||||
this.event = this.object.eventName;
|
||||
this.button = this.object.button;
|
||||
this.populate = this.object.populate;
|
||||
this.clauses = this.object.defaultClauses;
|
||||
this.blockedClauses = this.object.blockedClauses;
|
||||
}
|
||||
|
||||
return challengePaneObject;
|
||||
|
||||
})();
|
||||
|
||||
this.createChallengePane = function(opts) {
|
||||
var $accept, $button, $buttons, $checkboxes, $format, $reject, $selectFormat, $wrapper, acceptEventName, altCreatedEvent, blockedClauses, cancelChallenge, cancelEventName, capitalizedEventName, defaultClauses, disableButtons, enableButtons, eventName, generation, getSelectedTeam, isAttachedToDom, personId, rejectEventName, renderCurrentTeam, selectedAlt, selectedTeamId, teamUpdated, toggleAltInput, _ref;
|
||||
var $PaneArray, $accept, $button, $buttons, $checkboxes, $format, $reject, $selectFormat, $wrapper, acceptEventName, altCreatedEvent, blockedClauses, cancelChallenge, cancelEventName, capitalizedEventName, defaultClauses, disableButtons, enableButtons, eventName, generation, getSelectedTeam, isAttachedToDom, personId, rejectEventName, renderCurrentTeam, selectedAlt, selectedTeamId, teamUpdated, toggleAltInput, _ref;
|
||||
$wrapper = opts.populate;
|
||||
$button = opts.button;
|
||||
$accept = opts.acceptButton || $();
|
||||
|
@ -7494,6 +7510,7 @@
|
|||
blockedClauses = (_ref = opts.blockedClauses) != null ? _ref : false;
|
||||
selectedTeamId = null;
|
||||
selectedAlt = null;
|
||||
$PaneArray = this.challengePaneArray;
|
||||
getSelectedTeam = function() {
|
||||
return PokeBattle.TeamStore.get(selectedTeamId) || PokeBattle.TeamStore.at(0);
|
||||
};
|
||||
|
@ -7554,9 +7571,16 @@
|
|||
}));
|
||||
$selectFormat = $wrapper.find(".select-format");
|
||||
$button.on('click.challenge', function() {
|
||||
var $clauses, clauses, format, team, teamJSON;
|
||||
var $clauses, clauses, format, team, teamJSON, thisChallenge;
|
||||
thisChallenge = _.find($PaneArray, function(butt) {
|
||||
return butt.button.selector === $button.selector;
|
||||
});
|
||||
console.log(thisChallenge);
|
||||
PokeBattle.requestNotifyPermission();
|
||||
format = $selectFormat.data('format');
|
||||
if (typeof format === "undefined" && typeof personId === "undefined") {
|
||||
format = $('.select-format').data('format');
|
||||
}
|
||||
if (!$button.hasClass('disabled')) {
|
||||
team = getSelectedTeam();
|
||||
if (!team) {
|
||||
|
@ -7572,7 +7596,7 @@
|
|||
$clauses.each(function() {
|
||||
return clauses.push(parseInt($(this).val(), 10));
|
||||
});
|
||||
PokeBattle.primus.send(eventName, personId, format, teamJSON, clauses, selectedAlt);
|
||||
PokeBattle.primus.send(eventName, personId, format, teamJSON, thisChallenge.clauses, selectedAlt);
|
||||
} else {
|
||||
PokeBattle.primus.send(eventName, format, teamJSON, selectedAlt);
|
||||
}
|
||||
|
@ -11062,14 +11086,39 @@
|
|||
}).call(this);
|
||||
|
||||
(function() {
|
||||
var depressFindBattle;
|
||||
var depressFindBattle, depressFindBattleUnranked;
|
||||
|
||||
$(function() {
|
||||
var $mainButtons;
|
||||
var $mainButtons, challengeobj, challengeobjunranked, challengepaneobj, challengepaneobjunranked;
|
||||
$mainButtons = $('.main_buttons');
|
||||
$mainButtons.on('click', '.teambuilder_button', function(e) {
|
||||
return PokeBattle.navigation.showTeambuilder();
|
||||
});
|
||||
challengeobjunranked = {
|
||||
eventName: "findBattleunranked",
|
||||
populate: $mainButtons.find('.find_battle_select_team'),
|
||||
button: $mainButtons.find('.find_battle_non_ranked'),
|
||||
defaultClauses: [Conditions.SLEEP_CLAUSE, Conditions.EVASION_CLAUSE, Conditions.SPECIES_CLAUSE, Conditions.OHKO_CLAUSE, Conditions.PRANKSTER_SWAGGER_CLAUSE, Conditions.UNRELEASED_BAN, Conditions.TIMED_BATTLE],
|
||||
blockedClauses: true
|
||||
};
|
||||
challengeobj = {
|
||||
eventName: "findBattle",
|
||||
populate: $mainButtons.find('.find_battle_select_team'),
|
||||
button: $mainButtons.find('.find_battle'),
|
||||
defaultClauses: [Conditions.SLEEP_CLAUSE, Conditions.EVASION_CLAUSE, Conditions.SPECIES_CLAUSE, Conditions.OHKO_CLAUSE, Conditions.PRANKSTER_SWAGGER_CLAUSE, Conditions.UNRELEASED_BAN, Conditions.RATED_BATTLE, Conditions.TIMED_BATTLE],
|
||||
blockedClauses: true
|
||||
};
|
||||
challengepaneobjunranked = new challengePaneObject(challengeobjunranked);
|
||||
challengePaneArray.push(challengepaneobjunranked);
|
||||
challengepaneobj = new challengePaneObject(challengeobj);
|
||||
challengePaneArray.push(challengepaneobj);
|
||||
createChallengePane({
|
||||
eventName: "findBattleunranked",
|
||||
populate: $mainButtons.find('.find_battle_select_team'),
|
||||
button: $mainButtons.find('.find_battle_non_ranked'),
|
||||
defaultClauses: [Conditions.SLEEP_CLAUSE, Conditions.EVASION_CLAUSE, Conditions.SPECIES_CLAUSE, Conditions.OHKO_CLAUSE, Conditions.PRANKSTER_SWAGGER_CLAUSE, Conditions.UNRELEASED_BAN, Conditions.TIMED_BATTLE],
|
||||
blockedClauses: true
|
||||
});
|
||||
createChallengePane({
|
||||
eventName: "findBattle",
|
||||
populate: $mainButtons.find('.find_battle_select_team'),
|
||||
|
@ -11082,6 +11131,11 @@
|
|||
$this = $(this);
|
||||
return $this.find('.find-icon').addClass('icon-spinner spinner-anim').removeClass("icon-earth");
|
||||
});
|
||||
$mainButtons.find('.find_battle_non_ranked').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() {
|
||||
var $modal;
|
||||
$modal = PokeBattle.modal('modals/credits');
|
||||
|
@ -11098,16 +11152,28 @@
|
|||
return $mainButtons.find('.find_battle_select_team .select').removeClass('disabled');
|
||||
};
|
||||
|
||||
depressFindBattleUnranked = function() {
|
||||
var $button, $mainButtons;
|
||||
$mainButtons = $('.main_buttons');
|
||||
$button = $mainButtons.find('.find_battle_non_ranked');
|
||||
$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() {
|
||||
var $mainButtons;
|
||||
$mainButtons = $('.main_buttons');
|
||||
PokeBattle.battles.on('add', function(battle) {
|
||||
if (!battle.get('spectating')) {
|
||||
return depressFindBattle();
|
||||
depressFindBattle();
|
||||
return depressFindBattleUnranked();
|
||||
}
|
||||
});
|
||||
PokeBattle.primus.on('findBattleCanceled', depressFindBattle);
|
||||
return PokeBattle.events.on('findBattleCanceled', depressFindBattle);
|
||||
PokeBattle.events.on('findBattleCanceled', depressFindBattle);
|
||||
PokeBattle.primus.on('findBattleCanceledUnranked', depressFindBattleUnranked);
|
||||
return PokeBattle.events.on('findBattleCanceledUnranked', depressFindBattleUnranked);
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2872,8 +2872,7 @@
|
|||
$this = $(el);
|
||||
team = $this.data('team');
|
||||
slot = $this.data('slot');
|
||||
pokemon = _this.model.getPokemon(team, slot);
|
||||
return _this.pokemonPopover($this, pokemon);
|
||||
return pokemon = _this.model.getPokemon(team, slot);
|
||||
};
|
||||
})(this));
|
||||
this.renderTimers();
|
||||
|
@ -3064,6 +3063,7 @@
|
|||
$newPokemon.attr('data-slot', slot);
|
||||
$newPokemon.removeClass('hidden');
|
||||
this.pokemonPopover($newSprite, pokemon);
|
||||
pokemon.set('beeninbattle', true);
|
||||
this.cannedText('SENT_OUT', player, player, slot);
|
||||
if (this.skip != null) {
|
||||
$oldPokemon.css({
|
||||
|
@ -5208,8 +5208,24 @@
|
|||
(function() {
|
||||
var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
this.challengePaneArray = [];
|
||||
|
||||
this.challengePaneObject = (function() {
|
||||
function challengePaneObject(object) {
|
||||
this.object = object;
|
||||
this.event = this.object.eventName;
|
||||
this.button = this.object.button;
|
||||
this.populate = this.object.populate;
|
||||
this.clauses = this.object.defaultClauses;
|
||||
this.blockedClauses = this.object.blockedClauses;
|
||||
}
|
||||
|
||||
return challengePaneObject;
|
||||
|
||||
})();
|
||||
|
||||
this.createChallengePane = function(opts) {
|
||||
var $accept, $button, $buttons, $checkboxes, $format, $reject, $selectFormat, $wrapper, acceptEventName, altCreatedEvent, blockedClauses, cancelChallenge, cancelEventName, capitalizedEventName, defaultClauses, disableButtons, enableButtons, eventName, generation, getSelectedTeam, isAttachedToDom, personId, rejectEventName, renderCurrentTeam, selectedAlt, selectedTeamId, teamUpdated, toggleAltInput, _ref;
|
||||
var $PaneArray, $accept, $button, $buttons, $checkboxes, $format, $reject, $selectFormat, $wrapper, acceptEventName, altCreatedEvent, blockedClauses, cancelChallenge, cancelEventName, capitalizedEventName, defaultClauses, disableButtons, enableButtons, eventName, generation, getSelectedTeam, isAttachedToDom, personId, rejectEventName, renderCurrentTeam, selectedAlt, selectedTeamId, teamUpdated, toggleAltInput, _ref;
|
||||
$wrapper = opts.populate;
|
||||
$button = opts.button;
|
||||
$accept = opts.acceptButton || $();
|
||||
|
@ -5226,6 +5242,7 @@
|
|||
blockedClauses = (_ref = opts.blockedClauses) != null ? _ref : false;
|
||||
selectedTeamId = null;
|
||||
selectedAlt = null;
|
||||
$PaneArray = this.challengePaneArray;
|
||||
getSelectedTeam = function() {
|
||||
return PokeBattle.TeamStore.get(selectedTeamId) || PokeBattle.TeamStore.at(0);
|
||||
};
|
||||
|
@ -5286,9 +5303,16 @@
|
|||
}));
|
||||
$selectFormat = $wrapper.find(".select-format");
|
||||
$button.on('click.challenge', function() {
|
||||
var $clauses, clauses, format, team, teamJSON;
|
||||
var $clauses, clauses, format, team, teamJSON, thisChallenge;
|
||||
thisChallenge = _.find($PaneArray, function(butt) {
|
||||
return butt.button.selector === $button.selector;
|
||||
});
|
||||
console.log(thisChallenge);
|
||||
PokeBattle.requestNotifyPermission();
|
||||
format = $selectFormat.data('format');
|
||||
if (typeof format === "undefined" && typeof personId === "undefined") {
|
||||
format = $('.select-format').data('format');
|
||||
}
|
||||
if (!$button.hasClass('disabled')) {
|
||||
team = getSelectedTeam();
|
||||
if (!team) {
|
||||
|
@ -5304,7 +5328,7 @@
|
|||
$clauses.each(function() {
|
||||
return clauses.push(parseInt($(this).val(), 10));
|
||||
});
|
||||
PokeBattle.primus.send(eventName, personId, format, teamJSON, clauses, selectedAlt);
|
||||
PokeBattle.primus.send(eventName, personId, format, teamJSON, thisChallenge.clauses, selectedAlt);
|
||||
} else {
|
||||
PokeBattle.primus.send(eventName, format, teamJSON, selectedAlt);
|
||||
}
|
||||
|
|
|
@ -383,8 +383,6 @@ var teamIndex = (team === yourTeam ? yourIndex : 1 - yourIndex)
|
|||
buf.push("<div" + (jade.attrs({ "class": [('bg-faded-blue'),('fill-' + leftOrRight)] }, {"class":true})) + "><div" + (jade.attrs({ "class": [(leftOrRight)] }, {"class":true})) + "><div class=\"owner_name\">" + (jade.escape(null == (jade.interp = team.get('owner')) ? "" : jade.interp)) + "</div><div class=\"battle-timer frozen-timer hidden\"></div><div class=\"battle-timer remaining-timer\"></div><div class=\"pokemon_icons\">");
|
||||
var teamvisible = team.collection.parents[0].get('visibleteam')
|
||||
var isdef = typeof teamvisible
|
||||
if ( isdef != 'undefined' && teamvisible)
|
||||
{
|
||||
var orig = team.get('pokemon')
|
||||
var teamPokemon = team.getRandomOrder()
|
||||
for (var i = 0, len = teamPokemon.length; i < len; i += 1)
|
||||
|
@ -396,13 +394,38 @@ buf.push("<div class=\"icon_wrapper\">");
|
|||
var origpkmn = orig.findWhere({species: pokemon.species});
|
||||
var faintClass = (origpkmn.isFainted() ? 'fainted' : '')
|
||||
var style = window.PokemonIconBackground(origpkmn)
|
||||
if ( isdef != 'undefined' && teamvisible)
|
||||
{
|
||||
buf.push("<a" + (jade.attrs({ 'href':(window.PokemonIconBackground(origpkmn)), 'target':("_blank"), 'style':(style), 'data-team':(teamIndex), 'data-slot':(i), "class": [('pokemon_icon'),(faintClass)] }, {"class":true,"href":true,"target":true,"style":true,"data-team":true,"data-slot":true})) + "></a>");
|
||||
if ( !origpkmn.isFainted())
|
||||
{
|
||||
buf.push("<div class=\"pokemon_hp_background\"><div" + (jade.attrs({ 'style':("height: " + (origpkmn.getSpecies().id) + "%"), "class": [('pokemon_hp'),(origpkmn.getHPColor())] }, {"class":true,"style":true})) + "></div></div>");
|
||||
}
|
||||
buf.push("</div>");
|
||||
}
|
||||
else
|
||||
{
|
||||
var hasbeeninbattle = origpkmn.get('beeninbattle')
|
||||
if ( hasbeeninbattle == true)
|
||||
{
|
||||
console.log('hasbeeninbattle')
|
||||
buf.push("<a" + (jade.attrs({ 'href':(window.PokemonIconBackground(origpkmn)), 'target':("_blank"), 'style':(style), 'data-team':(teamIndex), 'data-slot':(i), "class": [('pokemon_icon'),(faintClass)] }, {"class":true,"href":true,"target":true,"style":true,"data-team":true,"data-slot":true})) + "></a>");
|
||||
if ( !origpkmn.isFainted())
|
||||
{
|
||||
buf.push("<div class=\"pokemon_hp_background\"><div" + (jade.attrs({ 'style':("height: " + (origpkmn.getSpecies().id) + "%"), "class": [('pokemon_hp'),(origpkmn.getHPColor())] }, {"class":true,"style":true})) + "></div></div>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log('hasnoybeeninbattle')
|
||||
var newstyle = "background:url('../Sprites/Icons/iconempty.png')!important; background-size: cover!important;"
|
||||
buf.push("<a" + (jade.attrs({ 'href':(""), 'target':("_blank"), 'style':(newstyle), 'data-team':(teamIndex), 'data-slot':(i), "class": [('pokemon_icon'),(faintClass)] }, {"class":true,"href":true,"target":true,"style":true,"data-team":true,"data-slot":true})) + "></a>");
|
||||
if ( !origpkmn.isFainted())
|
||||
{
|
||||
buf.push("<div class=\"pokemon_hp_background\"><div" + (jade.attrs({ 'style':("height: " + (origpkmn.getSpecies().id) + "%"), "class": [('pokemon_hp'),(origpkmn.getHPColor())] }, {"class":true,"style":true})) + "></div></div>");
|
||||
}
|
||||
}
|
||||
}
|
||||
buf.push("</div>");
|
||||
}
|
||||
}
|
||||
buf.push("</div></div></div>");
|
||||
|
@ -418,8 +441,6 @@ var teamIndex = (team === yourTeam ? yourIndex : 1 - yourIndex)
|
|||
buf.push("<div" + (jade.attrs({ "class": [('bg-faded-blue'),('fill-' + leftOrRight)] }, {"class":true})) + "><div" + (jade.attrs({ "class": [(leftOrRight)] }, {"class":true})) + "><div class=\"owner_name\">" + (jade.escape(null == (jade.interp = team.get('owner')) ? "" : jade.interp)) + "</div><div class=\"battle-timer frozen-timer hidden\"></div><div class=\"battle-timer remaining-timer\"></div><div class=\"pokemon_icons\">");
|
||||
var teamvisible = team.collection.parents[0].get('visibleteam')
|
||||
var isdef = typeof teamvisible
|
||||
if ( isdef != 'undefined' && teamvisible)
|
||||
{
|
||||
var orig = team.get('pokemon')
|
||||
var teamPokemon = team.getRandomOrder()
|
||||
for (var i = 0, len = teamPokemon.length; i < len; i += 1)
|
||||
|
@ -431,13 +452,38 @@ buf.push("<div class=\"icon_wrapper\">");
|
|||
var origpkmn = orig.findWhere({species: pokemon.species});
|
||||
var faintClass = (origpkmn.isFainted() ? 'fainted' : '')
|
||||
var style = window.PokemonIconBackground(origpkmn)
|
||||
if ( isdef != 'undefined' && teamvisible)
|
||||
{
|
||||
buf.push("<a" + (jade.attrs({ 'href':(window.PokemonIconBackground(origpkmn)), 'target':("_blank"), 'style':(style), 'data-team':(teamIndex), 'data-slot':(i), "class": [('pokemon_icon'),(faintClass)] }, {"class":true,"href":true,"target":true,"style":true,"data-team":true,"data-slot":true})) + "></a>");
|
||||
if ( !origpkmn.isFainted())
|
||||
{
|
||||
buf.push("<div class=\"pokemon_hp_background\"><div" + (jade.attrs({ 'style':("height: " + (origpkmn.getSpecies().id) + "%"), "class": [('pokemon_hp'),(origpkmn.getHPColor())] }, {"class":true,"style":true})) + "></div></div>");
|
||||
}
|
||||
buf.push("</div>");
|
||||
}
|
||||
else
|
||||
{
|
||||
var hasbeeninbattle = origpkmn.get('beeninbattle')
|
||||
if ( hasbeeninbattle == true)
|
||||
{
|
||||
console.log('hasbeeninbattle')
|
||||
buf.push("<a" + (jade.attrs({ 'href':(window.PokemonIconBackground(origpkmn)), 'target':("_blank"), 'style':(style), 'data-team':(teamIndex), 'data-slot':(i), "class": [('pokemon_icon'),(faintClass)] }, {"class":true,"href":true,"target":true,"style":true,"data-team":true,"data-slot":true})) + "></a>");
|
||||
if ( !origpkmn.isFainted())
|
||||
{
|
||||
buf.push("<div class=\"pokemon_hp_background\"><div" + (jade.attrs({ 'style':("height: " + (origpkmn.getSpecies().id) + "%"), "class": [('pokemon_hp'),(origpkmn.getHPColor())] }, {"class":true,"style":true})) + "></div></div>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log('hasnoybeeninbattle')
|
||||
var newstyle = "background:url('../Sprites/Icons/iconempty.png')!important; background-size: cover!important;"
|
||||
buf.push("<a" + (jade.attrs({ 'href':(""), 'target':("_blank"), 'style':(newstyle), 'data-team':(teamIndex), 'data-slot':(i), "class": [('pokemon_icon'),(faintClass)] }, {"class":true,"href":true,"target":true,"style":true,"data-team":true,"data-slot":true})) + "></a>");
|
||||
if ( !origpkmn.isFainted())
|
||||
{
|
||||
buf.push("<div class=\"pokemon_hp_background\"><div" + (jade.attrs({ 'style':("height: " + (origpkmn.getSpecies().id) + "%"), "class": [('pokemon_hp'),(origpkmn.getHPColor())] }, {"class":true,"style":true})) + "></div></div>");
|
||||
}
|
||||
}
|
||||
}
|
||||
buf.push("</div>");
|
||||
}
|
||||
}
|
||||
buf.push("</div></div></div>");
|
||||
|
|
|
@ -269,7 +269,6 @@ class @Move
|
|||
weatherModifier: (battle, user, target) ->
|
||||
# TODO: This is wrong.
|
||||
type = @getType(battle, user, target)
|
||||
console.log(type)
|
||||
if type == 'Fire' && battle.hasWeather(Weather.SUN)
|
||||
0x1800
|
||||
else if type == 'Fire' && battle.hasWeather(Weather.RAIN)
|
||||
|
@ -280,8 +279,6 @@ class @Move
|
|||
0x800
|
||||
else if type == 'Dark' && battle.hasWeather(Weather.MOON)
|
||||
0x159A
|
||||
else if type == 'Ghost' && battle.hasWeather(Weather.MOON)
|
||||
0x159A
|
||||
else if type == 'Fairy' && battle.hasWeather(Weather.MOON)
|
||||
0xC00
|
||||
else
|
||||
|
|
|
@ -12,322 +12,321 @@ ConditionHash = {}
|
|||
createCondition = (condition, effects = {}) ->
|
||||
ConditionHash[condition] = effects
|
||||
|
||||
# Attaches each condition to the Battle facade.
|
||||
@attach = (battleFacade) ->
|
||||
battle = battleFacade.battle
|
||||
for condition in battle.conditions
|
||||
if condition not of ConditionHash
|
||||
throw new Error("Undefined condition: #{condition}")
|
||||
hash = ConditionHash[condition] || {}
|
||||
# Attach each condition's event listeners
|
||||
for eventName, callback of hash.attach
|
||||
battle.on(eventName, callback)
|
||||
|
||||
# Extend battle with each function
|
||||
# TODO: Attach to prototype, and only once.
|
||||
for funcName, funcRef of hash.extend
|
||||
battle[funcName] = funcRef
|
||||
|
||||
for funcName, funcRef of hash.extendFacade
|
||||
battleFacade[funcName] = funcRef
|
||||
|
||||
# validates an entire team
|
||||
@validateTeam = (conditions, team, genData) ->
|
||||
errors = []
|
||||
for condition in conditions
|
||||
if condition not of ConditionHash
|
||||
throw new Error("Undefined condition: #{condition}")
|
||||
validator = ConditionHash[condition].validateTeam
|
||||
continue if !validator
|
||||
errors.push(validator(team, genData)...)
|
||||
return errors
|
||||
|
||||
# validates a single pokemon
|
||||
@validatePokemon = (conditions, pokemon, genData, prefix) ->
|
||||
errors = []
|
||||
for condition in conditions
|
||||
if condition not of ConditionHash
|
||||
throw new Error("Undefined condition: #{condition}")
|
||||
validator = ConditionHash[condition].validatePokemon
|
||||
continue if !validator
|
||||
errors.push(validator(pokemon, genData, prefix)...)
|
||||
return errors
|
||||
|
||||
createPBVCondition = (totalPBV) ->
|
||||
createCondition Conditions["PBV_#{totalPBV}"],
|
||||
validateTeam: (team, genData) ->
|
||||
errors = []
|
||||
if pbv.determinePBV(genData, team) > totalPBV
|
||||
errors.push "Total team PBV cannot surpass #{totalPBV}."
|
||||
if team.length != 6
|
||||
errors.push "Your team must have 6 pokemon."
|
||||
return errors
|
||||
|
||||
validatePokemon: (pokemon, genData, prefix) ->
|
||||
errors = []
|
||||
MAX_INDIVIDUAL_PBV = Math.floor(totalPBV / 3)
|
||||
individualPBV = pbv.determinePBV(genData, pokemon)
|
||||
|
||||
if individualPBV > MAX_INDIVIDUAL_PBV
|
||||
errors.push "#{prefix}: This Pokemon's PBV is #{individualPBV}. Individual
|
||||
PBVs cannot go over 1/3 the total (over #{MAX_INDIVIDUAL_PBV} PBV)."
|
||||
|
||||
return errors
|
||||
|
||||
createPBVCondition(1000)
|
||||
createPBVCondition(500)
|
||||
|
||||
createTierCondition = (conditionName, tier) ->
|
||||
createCondition Conditions[conditionName],
|
||||
validateTeam: (team, genData) ->
|
||||
errors = []
|
||||
tierdata = Tiers[tier]
|
||||
teamtier = tiering.determineTier(genData, team)
|
||||
if teamtier.tierRank > tierdata.tierRank
|
||||
errors.push "Your team tier may not exceed the #{tierdata.humanName} tier"
|
||||
if team.length != 6
|
||||
errors.push "Your team must have 6 pokemon."
|
||||
return errors
|
||||
|
||||
for key, val of Tiers
|
||||
createTierCondition("TIER_#{key}", key)
|
||||
|
||||
createCondition Conditions.SLEEP_CLAUSE,
|
||||
attach:
|
||||
initialize: ->
|
||||
for team in @getTeams()
|
||||
for p in team.pokemon
|
||||
p.attach(@getAttachment("SleepClause"))
|
||||
|
||||
createCondition Conditions.SPECIES_CLAUSE,
|
||||
validateTeam: (team, genData) ->
|
||||
errors = []
|
||||
species = team.map((p) -> p.species)
|
||||
species.sort()
|
||||
for i in [1...species.length]
|
||||
speciesName = species[i - 1]
|
||||
if speciesName == species[i]
|
||||
errors.push("Cannot have the same species: #{speciesName}")
|
||||
while speciesName == species[i]
|
||||
i++
|
||||
return errors
|
||||
|
||||
createCondition Conditions.EVASION_CLAUSE,
|
||||
validatePokemon: (pokemon, genData, prefix) ->
|
||||
{moves, ability} = pokemon
|
||||
errors = []
|
||||
|
||||
# Check evasion abilities
|
||||
if ability in [ "Moody" ]
|
||||
errors.push("#{prefix}: #{ability} is banned under Evasion Clause.")
|
||||
|
||||
# Check evasion moves
|
||||
for moveName in moves || []
|
||||
move = genData.MoveData[moveName]
|
||||
continue if !move
|
||||
if move.primaryBoostStats? && move.primaryBoostStats.evasion > 0 &&
|
||||
move.primaryBoostTarget == 'self'
|
||||
errors.push("#{prefix}: #{moveName} is banned under Evasion Clause.")
|
||||
|
||||
return errors
|
||||
|
||||
createCondition Conditions.OHKO_CLAUSE,
|
||||
validatePokemon: (pokemon, genData, prefix) ->
|
||||
{moves} = pokemon
|
||||
errors = []
|
||||
|
||||
# Check OHKO moves
|
||||
for moveName in moves || []
|
||||
move = genData.MoveData[moveName]
|
||||
continue if !move
|
||||
if "ohko" in move.flags
|
||||
errors.push("#{prefix}: #{moveName} is banned under One-Hit KO Clause.")
|
||||
|
||||
return errors
|
||||
|
||||
createCondition Conditions.PRANKSTER_SWAGGER_CLAUSE,
|
||||
validatePokemon: (pokemon, genData, prefix) ->
|
||||
errors = []
|
||||
if "Swagger" in pokemon.moves && "Prankster" == pokemon.ability
|
||||
errors.push("#{prefix}: A Pokemon can't have both Prankster and Swagger.")
|
||||
return errors
|
||||
|
||||
createCondition Conditions.UNRELEASED_BAN,
|
||||
validatePokemon: (pokemon, genData, prefix) ->
|
||||
# Check for unreleased items
|
||||
errors = []
|
||||
if pokemon.item && genData.ItemData[pokemon.item]?.unreleased
|
||||
errors.push("#{prefix}: The item '#{pokemon.item}' is unreleased.")
|
||||
# Check for unreleased abilities
|
||||
forme = genData.FormeData[pokemon.species][pokemon.forme || "default"]
|
||||
if forme.unreleasedHidden && pokemon.ability == forme.hiddenAbility &&
|
||||
forme.hiddenAbility not in forme.abilities
|
||||
errors.push("#{prefix}: The ability #{pokemon.ability} is unreleased.")
|
||||
# Check for unreleased Pokemon
|
||||
if forme.unreleased
|
||||
errors.push("#{prefix}: The Pokemon #{pokemon.species} is unreleased.")
|
||||
return errors
|
||||
|
||||
createCondition Conditions.RATED_BATTLE,
|
||||
attach:
|
||||
end: (winnerId) ->
|
||||
return if !winnerId
|
||||
index = @getPlayerIndex(winnerId)
|
||||
loserId = @playerIds[1 - index]
|
||||
ratings = require './ratings'
|
||||
|
||||
winner = @getPlayer(winnerId)
|
||||
loser = @getPlayer(loserId)
|
||||
|
||||
winnerId = winner.ratingKey
|
||||
loserId = loser.ratingKey
|
||||
|
||||
ratings.getRatings [ winnerId, loserId ], (err, oldRatings) =>
|
||||
ratings.updatePlayers winnerId, loserId, ratings.results.WIN, (err, result) =>
|
||||
return @message "An error occurred updating rankings :(" if err
|
||||
|
||||
oldRating = Math.floor(oldRatings[0])
|
||||
newRating = Math.floor(result[0])
|
||||
@cannedText('RATING_UPDATE', index, oldRating, newRating)
|
||||
|
||||
oldRating = Math.floor(oldRatings[1])
|
||||
newRating = Math.floor(result[1])
|
||||
@cannedText('RATING_UPDATE', 1 - index, oldRating, newRating)
|
||||
|
||||
@emit('ratingsUpdated')
|
||||
@sendUpdates()
|
||||
|
||||
createCondition Conditions.TIMED_BATTLE,
|
||||
attach:
|
||||
initialize: ->
|
||||
@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))
|
||||
|
||||
start: ->
|
||||
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()
|
||||
|
||||
requestActions: (playerId) ->
|
||||
# If a player has selected a move, then there's an amount of time spent
|
||||
# between move selection and requesting another action that was "lost".
|
||||
# We grant this back here.
|
||||
if @lastActionTimes[playerId]
|
||||
now = Date.now()
|
||||
leftoverTime = now - @lastActionTimes[playerId]
|
||||
delete @lastActionTimes[playerId]
|
||||
@addTime(playerId, leftoverTime)
|
||||
# In either case, we tell people that this player's timer resumes.
|
||||
@send('resumeTimer', @id, @getPlayerIndex(playerId))
|
||||
|
||||
addAction: (playerId, action) ->
|
||||
# Record the last action for use
|
||||
@lastActionTimes[playerId] = Date.now()
|
||||
@recalculateTimers()
|
||||
|
||||
undoCompletedRequest: (playerId) ->
|
||||
delete @lastActionTimes[playerId]
|
||||
@recalculateTimers()
|
||||
|
||||
# Show players updated times
|
||||
beginTurn: ->
|
||||
remainingTimes = []
|
||||
for id in @playerIds
|
||||
@addTime(id, @TIMER_PER_TURN_INCREASE)
|
||||
remainingTimes.push(@timeRemainingFor(id))
|
||||
@send('updateTimers', @id, remainingTimes)
|
||||
|
||||
continueTurn: ->
|
||||
for id in @playerIds
|
||||
@send('pauseTimer', @id, @getPlayerIndex(id))
|
||||
|
||||
spectateBattle: (user) ->
|
||||
playerId = user.name
|
||||
remainingTimes = (@timeRemainingFor(id) for id in @playerIds)
|
||||
user.send('updateTimers', @id, remainingTimes)
|
||||
|
||||
# Pause timer for players who have already chosen a move.
|
||||
if @hasCompletedRequests(playerId)
|
||||
index = @getPlayerIndex(playerId)
|
||||
timeSinceLastAction = Date.now() - @lastActionTimes[playerId]
|
||||
user.send('pauseTimer', @id, index, timeSinceLastAction)
|
||||
|
||||
extend:
|
||||
DEFAULT_TIMER: 3 * 60 * 1000 # three minutes
|
||||
TIMER_PER_TURN_INCREASE: 15 * 1000 # fifteen seconds
|
||||
TIMER_CAP: 3 * 60 * 1000 # three minutes
|
||||
TEAM_PREVIEW_TIMER: 1.5 * 60 * 1000 # 1 minute and 30 seconds
|
||||
|
||||
startTimer: (msecs) ->
|
||||
msecs ?= @DEFAULT_TIMER
|
||||
@timerId = setTimeout(@declareWinner.bind(this), msecs)
|
||||
@once('end', => clearTimeout(@timerId))
|
||||
|
||||
addTime: (id, msecs) ->
|
||||
@playerTimes[id] += msecs
|
||||
remainingTime = @timeRemainingFor(id)
|
||||
if remainingTime > @TIMER_CAP
|
||||
diff = remainingTime - @TIMER_CAP
|
||||
@playerTimes[id] -= diff
|
||||
@recalculateTimers()
|
||||
@playerTimes[id]
|
||||
|
||||
recalculateTimers: ->
|
||||
playerTimes = for id in @playerIds
|
||||
if @lastActionTimes[id] then Infinity else @timeRemainingFor(id)
|
||||
leastTime = Math.min(playerTimes...)
|
||||
clearTimeout(@timerId)
|
||||
if 0 < leastTime < Infinity
|
||||
@timerId = setTimeout(@declareWinner.bind(this), leastTime)
|
||||
else if leastTime <= 0
|
||||
@declareWinner()
|
||||
|
||||
timeRemainingFor: (playerId) ->
|
||||
endTime = @playerTimes[playerId]
|
||||
nowTime = @lastActionTimes[playerId] || Date.now()
|
||||
return endTime - nowTime
|
||||
|
||||
playersWithLeastTime: ->
|
||||
losingIds = []
|
||||
leastTimeRemaining = Infinity
|
||||
for id in @playerIds
|
||||
timeRemaining = @timeRemainingFor(id)
|
||||
if timeRemaining < leastTimeRemaining
|
||||
losingIds = [ id ]
|
||||
leastTimeRemaining = timeRemaining
|
||||
else if timeRemaining == leastTimeRemaining
|
||||
losingIds.push(id)
|
||||
return losingIds
|
||||
|
||||
declareWinner: ->
|
||||
loserIds = @playersWithLeastTime()
|
||||
loserId = @rng.choice(loserIds, "timer")
|
||||
index = @getPlayerIndex(loserId)
|
||||
winnerIndex = 1 - index
|
||||
@timerWin(winnerIndex)
|
||||
|
||||
timerWin: (winnerIndex) ->
|
||||
@tell(Protocol.TIMER_WIN, winnerIndex)
|
||||
@emit('end', @playerIds[winnerIndex])
|
||||
@sendUpdates()
|
||||
|
||||
|
||||
# Attaches each condition to the Battle facade.
|
||||
@attach = (battleFacade) ->
|
||||
battle = battleFacade.battle
|
||||
for condition in battle.conditions
|
||||
if condition not of ConditionHash
|
||||
throw new Error("Undefined condition: #{condition}")
|
||||
hash = ConditionHash[condition] || {}
|
||||
# Attach each condition's event listeners
|
||||
for eventName, callback of hash.attach
|
||||
battle.on(eventName, callback)
|
||||
|
||||
# Extend battle with each function
|
||||
# TODO: Attach to prototype, and only once.
|
||||
for funcName, funcRef of hash.extend
|
||||
battle[funcName] = funcRef
|
||||
|
||||
for funcName, funcRef of hash.extendFacade
|
||||
battleFacade[funcName] = funcRef
|
||||
|
||||
# validates an entire team
|
||||
@validateTeam = (conditions, team, genData) ->
|
||||
errors = []
|
||||
for condition in conditions
|
||||
if condition not of ConditionHash
|
||||
throw new Error("Undefined condition: #{condition}")
|
||||
validator = ConditionHash[condition].validateTeam
|
||||
continue if !validator
|
||||
errors.push(validator(team, genData)...)
|
||||
return errors
|
||||
|
||||
# validates a single pokemon
|
||||
@validatePokemon = (conditions, pokemon, genData, prefix) ->
|
||||
errors = []
|
||||
for condition in conditions
|
||||
if condition not of ConditionHash
|
||||
throw new Error("Undefined condition: #{condition}")
|
||||
validator = ConditionHash[condition].validatePokemon
|
||||
continue if !validator
|
||||
errors.push(validator(pokemon, genData, prefix)...)
|
||||
return errors
|
||||
|
||||
createPBVCondition = (totalPBV) ->
|
||||
createCondition Conditions["PBV_#{totalPBV}"],
|
||||
validateTeam: (team, genData) ->
|
||||
errors = []
|
||||
if pbv.determinePBV(genData, team) > totalPBV
|
||||
errors.push "Total team PBV cannot surpass #{totalPBV}."
|
||||
if team.length != 6
|
||||
errors.push "Your team must have 6 pokemon."
|
||||
return errors
|
||||
|
||||
validatePokemon: (pokemon, genData, prefix) ->
|
||||
errors = []
|
||||
MAX_INDIVIDUAL_PBV = Math.floor(totalPBV / 3)
|
||||
individualPBV = pbv.determinePBV(genData, pokemon)
|
||||
|
||||
if individualPBV > MAX_INDIVIDUAL_PBV
|
||||
errors.push "#{prefix}: This Pokemon's PBV is #{individualPBV}. Individual
|
||||
PBVs cannot go over 1/3 the total (over #{MAX_INDIVIDUAL_PBV} PBV)."
|
||||
|
||||
return errors
|
||||
|
||||
createPBVCondition(1000)
|
||||
createPBVCondition(500)
|
||||
|
||||
createTierCondition = (conditionName, tier) ->
|
||||
createCondition Conditions[conditionName],
|
||||
validateTeam: (team, genData) ->
|
||||
errors = []
|
||||
tierdata = Tiers[tier]
|
||||
teamtier = tiering.determineTier(genData, team)
|
||||
if teamtier.tierRank > tierdata.tierRank
|
||||
errors.push "Your team tier may not exceed the #{tierdata.humanName} tier"
|
||||
if team.length != 6
|
||||
errors.push "Your team must have 6 pokemon."
|
||||
return errors
|
||||
|
||||
for key, val of Tiers
|
||||
createTierCondition("TIER_#{key}", key)
|
||||
|
||||
createCondition Conditions.SLEEP_CLAUSE,
|
||||
attach:
|
||||
initialize: ->
|
||||
for team in @getTeams()
|
||||
for p in team.pokemon
|
||||
p.attach(@getAttachment("SleepClause"))
|
||||
|
||||
createCondition Conditions.SPECIES_CLAUSE,
|
||||
validateTeam: (team, genData) ->
|
||||
errors = []
|
||||
species = team.map((p) -> p.species)
|
||||
species.sort()
|
||||
for i in [1...species.length]
|
||||
speciesName = species[i - 1]
|
||||
if speciesName == species[i]
|
||||
errors.push("Cannot have the same species: #{speciesName}")
|
||||
while speciesName == species[i]
|
||||
i++
|
||||
return errors
|
||||
|
||||
createCondition Conditions.EVASION_CLAUSE,
|
||||
validatePokemon: (pokemon, genData, prefix) ->
|
||||
{moves, ability} = pokemon
|
||||
errors = []
|
||||
|
||||
# Check evasion abilities
|
||||
if ability in [ "Moody" ]
|
||||
errors.push("#{prefix}: #{ability} is banned under Evasion Clause.")
|
||||
|
||||
# Check evasion moves
|
||||
for moveName in moves || []
|
||||
move = genData.MoveData[moveName]
|
||||
continue if !move
|
||||
if move.primaryBoostStats? && move.primaryBoostStats.evasion > 0 &&
|
||||
move.primaryBoostTarget == 'self'
|
||||
errors.push("#{prefix}: #{moveName} is banned under Evasion Clause.")
|
||||
|
||||
return errors
|
||||
|
||||
createCondition Conditions.OHKO_CLAUSE,
|
||||
validatePokemon: (pokemon, genData, prefix) ->
|
||||
{moves} = pokemon
|
||||
errors = []
|
||||
|
||||
# Check OHKO moves
|
||||
for moveName in moves || []
|
||||
move = genData.MoveData[moveName]
|
||||
continue if !move
|
||||
if "ohko" in move.flags
|
||||
errors.push("#{prefix}: #{moveName} is banned under One-Hit KO Clause.")
|
||||
|
||||
return errors
|
||||
|
||||
createCondition Conditions.PRANKSTER_SWAGGER_CLAUSE,
|
||||
validatePokemon: (pokemon, genData, prefix) ->
|
||||
errors = []
|
||||
if "Swagger" in pokemon.moves && "Prankster" == pokemon.ability
|
||||
errors.push("#{prefix}: A Pokemon can't have both Prankster and Swagger.")
|
||||
return errors
|
||||
|
||||
createCondition Conditions.UNRELEASED_BAN,
|
||||
validatePokemon: (pokemon, genData, prefix) ->
|
||||
# Check for unreleased items
|
||||
errors = []
|
||||
if pokemon.item && genData.ItemData[pokemon.item]?.unreleased
|
||||
errors.push("#{prefix}: The item '#{pokemon.item}' is unreleased.")
|
||||
# Check for unreleased abilities
|
||||
forme = genData.FormeData[pokemon.species][pokemon.forme || "default"]
|
||||
if forme.unreleasedHidden && pokemon.ability == forme.hiddenAbility &&
|
||||
forme.hiddenAbility not in forme.abilities
|
||||
errors.push("#{prefix}: The ability #{pokemon.ability} is unreleased.")
|
||||
# Check for unreleased Pokemon
|
||||
if forme.unreleased
|
||||
errors.push("#{prefix}: The Pokemon #{pokemon.species} is unreleased.")
|
||||
return errors
|
||||
|
||||
createCondition Conditions.RATED_BATTLE,
|
||||
attach:
|
||||
end: (winnerId) ->
|
||||
return if !winnerId
|
||||
index = @getPlayerIndex(winnerId)
|
||||
loserId = @playerIds[1 - index]
|
||||
ratings = require './ratings'
|
||||
|
||||
winner = @getPlayer(winnerId)
|
||||
loser = @getPlayer(loserId)
|
||||
|
||||
winnerId = winner.ratingKey
|
||||
loserId = loser.ratingKey
|
||||
|
||||
ratings.getRatings [ winnerId, loserId ], (err, oldRatings) =>
|
||||
ratings.updatePlayers winnerId, loserId, ratings.results.WIN, (err, result) =>
|
||||
return @message "An error occurred updating rankings :(" if err
|
||||
|
||||
oldRating = Math.floor(oldRatings[0])
|
||||
newRating = Math.floor(result[0])
|
||||
@cannedText('RATING_UPDATE', index, oldRating, newRating)
|
||||
|
||||
oldRating = Math.floor(oldRatings[1])
|
||||
newRating = Math.floor(result[1])
|
||||
@cannedText('RATING_UPDATE', 1 - index, oldRating, newRating)
|
||||
|
||||
@emit('ratingsUpdated')
|
||||
@sendUpdates()
|
||||
|
||||
createCondition Conditions.TIMED_BATTLE,
|
||||
attach:
|
||||
initialize: ->
|
||||
@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))
|
||||
|
||||
start: ->
|
||||
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()
|
||||
|
||||
requestActions: (playerId) ->
|
||||
# If a player has selected a move, then there's an amount of time spent
|
||||
# between move selection and requesting another action that was "lost".
|
||||
# We grant this back here.
|
||||
if @lastActionTimes[playerId]
|
||||
now = Date.now()
|
||||
leftoverTime = now - @lastActionTimes[playerId]
|
||||
delete @lastActionTimes[playerId]
|
||||
@addTime(playerId, leftoverTime)
|
||||
# In either case, we tell people that this player's timer resumes.
|
||||
@send('resumeTimer', @id, @getPlayerIndex(playerId))
|
||||
|
||||
addAction: (playerId, action) ->
|
||||
# Record the last action for use
|
||||
@lastActionTimes[playerId] = Date.now()
|
||||
@recalculateTimers()
|
||||
|
||||
undoCompletedRequest: (playerId) ->
|
||||
delete @lastActionTimes[playerId]
|
||||
@recalculateTimers()
|
||||
|
||||
# Show players updated times
|
||||
beginTurn: ->
|
||||
remainingTimes = []
|
||||
for id in @playerIds
|
||||
@addTime(id, @TIMER_PER_TURN_INCREASE)
|
||||
remainingTimes.push(@timeRemainingFor(id))
|
||||
@send('updateTimers', @id, remainingTimes)
|
||||
|
||||
continueTurn: ->
|
||||
for id in @playerIds
|
||||
@send('pauseTimer', @id, @getPlayerIndex(id))
|
||||
|
||||
spectateBattle: (user) ->
|
||||
playerId = user.name
|
||||
remainingTimes = (@timeRemainingFor(id) for id in @playerIds)
|
||||
user.send('updateTimers', @id, remainingTimes)
|
||||
|
||||
# Pause timer for players who have already chosen a move.
|
||||
if @hasCompletedRequests(playerId)
|
||||
index = @getPlayerIndex(playerId)
|
||||
timeSinceLastAction = Date.now() - @lastActionTimes[playerId]
|
||||
user.send('pauseTimer', @id, index, timeSinceLastAction)
|
||||
|
||||
extend:
|
||||
DEFAULT_TIMER: 3 * 60 * 1000 # three minutes
|
||||
TIMER_PER_TURN_INCREASE: 15 * 1000 # fifteen seconds
|
||||
TIMER_CAP: 3 * 60 * 1000 # three minutes
|
||||
TEAM_PREVIEW_TIMER: 1.5 * 60 * 1000 # 1 minute and 30 seconds
|
||||
|
||||
startTimer: (msecs) ->
|
||||
msecs ?= @DEFAULT_TIMER
|
||||
@timerId = setTimeout(@declareWinner.bind(this), msecs)
|
||||
@once('end', => clearTimeout(@timerId))
|
||||
|
||||
addTime: (id, msecs) ->
|
||||
@playerTimes[id] += msecs
|
||||
remainingTime = @timeRemainingFor(id)
|
||||
if remainingTime > @TIMER_CAP
|
||||
diff = remainingTime - @TIMER_CAP
|
||||
@playerTimes[id] -= diff
|
||||
@recalculateTimers()
|
||||
@playerTimes[id]
|
||||
|
||||
recalculateTimers: ->
|
||||
playerTimes = for id in @playerIds
|
||||
if @lastActionTimes[id] then Infinity else @timeRemainingFor(id)
|
||||
leastTime = Math.min(playerTimes...)
|
||||
clearTimeout(@timerId)
|
||||
if 0 < leastTime < Infinity
|
||||
@timerId = setTimeout(@declareWinner.bind(this), leastTime)
|
||||
else if leastTime <= 0
|
||||
@declareWinner()
|
||||
|
||||
timeRemainingFor: (playerId) ->
|
||||
endTime = @playerTimes[playerId]
|
||||
nowTime = @lastActionTimes[playerId] || Date.now()
|
||||
return endTime - nowTime
|
||||
|
||||
playersWithLeastTime: ->
|
||||
losingIds = []
|
||||
leastTimeRemaining = Infinity
|
||||
for id in @playerIds
|
||||
timeRemaining = @timeRemainingFor(id)
|
||||
if timeRemaining < leastTimeRemaining
|
||||
losingIds = [ id ]
|
||||
leastTimeRemaining = timeRemaining
|
||||
else if timeRemaining == leastTimeRemaining
|
||||
losingIds.push(id)
|
||||
return losingIds
|
||||
|
||||
declareWinner: ->
|
||||
loserIds = @playersWithLeastTime()
|
||||
loserId = @rng.choice(loserIds, "timer")
|
||||
index = @getPlayerIndex(loserId)
|
||||
winnerIndex = 1 - index
|
||||
@timerWin(winnerIndex)
|
||||
|
||||
timerWin: (winnerIndex) ->
|
||||
@tell(Protocol.TIMER_WIN, winnerIndex)
|
||||
@emit('end', @playerIds[winnerIndex])
|
||||
@sendUpdates()
|
||||
|
||||
createCondition Conditions.TEAM_PREVIEW,
|
||||
attach:
|
||||
initialize: ->
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{_} = require('underscore')
|
||||
{Formats} = require('../shared/conditions')
|
||||
ConditionsFunc = require('../shared/conditions')
|
||||
config = require('../knexfile')[process.env.NODE_ENV || 'development']
|
||||
|
||||
knex = require('knex')(config)
|
||||
|
@ -39,7 +39,8 @@ Battle = bookshelf.Model.extend
|
|||
@get('name') || @getPlayerNames().join(' vs. ') || 'Untitled'
|
||||
|
||||
getFormat: ->
|
||||
Formats[@get('format')].humanName
|
||||
allformats = ConditionsFunc.Formats()
|
||||
allformats[@get('format')].humanName
|
||||
|
||||
getPlayerNames: ->
|
||||
# players is denormalized. It's an array with a comma delimiter.
|
||||
|
|
|
@ -88,6 +88,8 @@ class @Attachment.Livewire extends @TeamAttachment
|
|||
|
||||
#On switch in
|
||||
switchIn: (pokemon) ->
|
||||
if pokemon.isFainted()
|
||||
return
|
||||
#if pokemon is part electric and not immune to ground, remove livewire. Also if has ground and is not immune to ground
|
||||
if (pokemon.hasType("Electric") && !pokemon.isImmune("Ground")) || (pokemon.hasType("Ground") && !pokemon.isImmune("Ground"))
|
||||
@team.unattach(@constructor)
|
||||
|
|
|
@ -798,12 +798,12 @@
|
|||
"Fighting"
|
||||
],
|
||||
"stats": {
|
||||
"attack": 165,
|
||||
"attack": 155,
|
||||
"defense": 100,
|
||||
"hp": 65,
|
||||
"specialAttack": 70,
|
||||
"specialDefense": 60,
|
||||
"speed": 130
|
||||
"specialAttack": 80,
|
||||
"specialDefense": 70,
|
||||
"speed": 120
|
||||
},
|
||||
"abilities": [
|
||||
"Technician"
|
||||
|
@ -6259,6 +6259,7 @@
|
|||
"Psychic"
|
||||
],
|
||||
"weight": 3,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 145,
|
||||
"tier": [ "OU" ]
|
||||
}
|
||||
|
@ -8206,19 +8207,18 @@
|
|||
"Steel"
|
||||
],
|
||||
"stats": {
|
||||
"attack": 145,
|
||||
"defense": 125,
|
||||
"attack": 155,
|
||||
"defense": 100,
|
||||
"hp": 65,
|
||||
"specialAttack": 60,
|
||||
"specialDefense": 85,
|
||||
"speed": 105
|
||||
"specialAttack": 80,
|
||||
"specialDefense": 70,
|
||||
"speed": 120
|
||||
},
|
||||
"abilities": [
|
||||
"Moxie"
|
||||
],
|
||||
"isBattleOnly": true,
|
||||
"weight": 700,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 1001,
|
||||
"tier": [ "Uber" ]
|
||||
}
|
||||
|
@ -10770,6 +10770,7 @@
|
|||
"Grass"
|
||||
],
|
||||
"weight": 50,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 150,
|
||||
"tier": [ "OU" ]
|
||||
}
|
||||
|
@ -12977,6 +12978,7 @@
|
|||
],
|
||||
"weight": 2500,
|
||||
"pokeBattleValue": 130,
|
||||
"unreleased": true,
|
||||
"tier": [ "UU" ]
|
||||
}
|
||||
},
|
||||
|
@ -13904,6 +13906,7 @@
|
|||
"Psychic"
|
||||
],
|
||||
"weight": 856,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 140,
|
||||
"tier": [ "OU" ]
|
||||
}
|
||||
|
@ -14699,6 +14702,7 @@
|
|||
"types": [
|
||||
"Dark"
|
||||
],
|
||||
"unreleased": true,
|
||||
"weight": 505,
|
||||
"pokeBattleValue": 1001,
|
||||
"tier": [ "Uber" ]
|
||||
|
@ -15598,6 +15602,7 @@
|
|||
"Psychic"
|
||||
],
|
||||
"weight": 608,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 1001,
|
||||
"tier": [ "Uber" ]
|
||||
},
|
||||
|
@ -15693,6 +15698,7 @@
|
|||
"Psychic"
|
||||
],
|
||||
"weight": 608,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 200,
|
||||
"tier": [ "Uber" ]
|
||||
},
|
||||
|
@ -15732,6 +15738,7 @@
|
|||
],
|
||||
"weight": 608,
|
||||
"pokeBattleValue": 200,
|
||||
"unreleased": true,
|
||||
"tier": [ "Uber" ]
|
||||
}
|
||||
},
|
||||
|
@ -16066,6 +16073,7 @@
|
|||
}
|
||||
},
|
||||
"pokeBattleValue": 155,
|
||||
"unreleased": true,
|
||||
"tier": [ "OU" ]
|
||||
},
|
||||
"mega": {
|
||||
|
@ -31349,6 +31357,7 @@
|
|||
"Fighting"
|
||||
],
|
||||
"weight": 485,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 175,
|
||||
"tier": [ "OU" ]
|
||||
},
|
||||
|
@ -31438,6 +31447,7 @@
|
|||
"Fighting"
|
||||
],
|
||||
"weight": 485,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 175,
|
||||
"tier": [ "OU" ]
|
||||
}
|
||||
|
@ -32623,6 +32633,7 @@
|
|||
"Dragon",
|
||||
"Ice"
|
||||
],
|
||||
"unreleased": true,
|
||||
"weight": 3250,
|
||||
"pokeBattleValue": 180,
|
||||
"tier": [ "OU" ]
|
||||
|
@ -33052,6 +33063,7 @@
|
|||
"Flying"
|
||||
],
|
||||
"weight": 680,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 180,
|
||||
"tier": [ "Uber" ]
|
||||
},
|
||||
|
@ -33148,6 +33160,7 @@
|
|||
"Flying"
|
||||
],
|
||||
"weight": 680,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 175,
|
||||
"tier": [ "OU" ]
|
||||
}
|
||||
|
@ -33606,6 +33619,7 @@
|
|||
"Psychic"
|
||||
],
|
||||
"weight": 400,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 165,
|
||||
"tier": [ "OU" ]
|
||||
},
|
||||
|
@ -33627,8 +33641,8 @@
|
|||
],
|
||||
"isBattleOnly": true,
|
||||
"weight": 520,
|
||||
"pokeBattleValue": 1001,
|
||||
"tier": [ "Uber" ]
|
||||
"pokeBattleValue": 190,
|
||||
"tier": [ "OU"]
|
||||
}
|
||||
},
|
||||
"Latios": {
|
||||
|
@ -33730,6 +33744,7 @@
|
|||
"Dragon",
|
||||
"Psychic"
|
||||
],
|
||||
"unreleased": true,
|
||||
"weight": 600,
|
||||
"pokeBattleValue": 175,
|
||||
"tier": [ "OU" ]
|
||||
|
@ -33752,8 +33767,8 @@
|
|||
],
|
||||
"isBattleOnly": true,
|
||||
"weight": 700,
|
||||
"pokeBattleValue": 1001,
|
||||
"tier": [ "Uber" ]
|
||||
"pokeBattleValue": 190,
|
||||
"tier": [ "OU" ]
|
||||
}
|
||||
},
|
||||
"Leafeon": {
|
||||
|
@ -39046,6 +39061,7 @@
|
|||
"Psychic"
|
||||
],
|
||||
"weight": 3,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 130,
|
||||
"tier": [ "UU" ]
|
||||
}
|
||||
|
@ -44893,6 +44909,7 @@
|
|||
"Water"
|
||||
],
|
||||
"weight": 31,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 80,
|
||||
"tier": [ "Unsorted" ]
|
||||
}
|
||||
|
@ -52850,8 +52867,9 @@
|
|||
"Grass"
|
||||
],
|
||||
"weight": 21,
|
||||
"pokeBattleValue": 140,
|
||||
"tier": [ "OU" ]
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 130,
|
||||
"tier": [ "UU" ]
|
||||
},
|
||||
"sky": {
|
||||
"abilities": [
|
||||
|
@ -52915,6 +52933,7 @@
|
|||
"Flying"
|
||||
],
|
||||
"weight": 52,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 335,
|
||||
"tier": [ "Uber" ]
|
||||
}
|
||||
|
@ -60197,6 +60216,7 @@
|
|||
"Fighting"
|
||||
],
|
||||
"weight": 2600,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 160,
|
||||
"tier": [ "OU" ]
|
||||
}
|
||||
|
@ -61197,6 +61217,7 @@
|
|||
"Flying"
|
||||
],
|
||||
"weight": 630,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 160,
|
||||
"tier": [ "OU" ]
|
||||
},
|
||||
|
@ -61291,6 +61312,7 @@
|
|||
"Flying"
|
||||
],
|
||||
"weight": 630,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 170,
|
||||
"tier": [ "OU" ]
|
||||
}
|
||||
|
@ -62387,12 +62409,12 @@
|
|||
"Fire"
|
||||
],
|
||||
"stats": {
|
||||
"attack": 85,
|
||||
"defense": 78,
|
||||
"attack": 90,
|
||||
"defense": 88,
|
||||
"hp": 78,
|
||||
"specialAttack": 160,
|
||||
"specialDefense": 109,
|
||||
"speed": 125
|
||||
"specialDefense": 110,
|
||||
"speed": 109
|
||||
},
|
||||
"abilities": [
|
||||
"Hubris"
|
||||
|
@ -63118,6 +63140,7 @@
|
|||
"types": [
|
||||
"Psychic"
|
||||
],
|
||||
"unreleased": true,
|
||||
"weight": 3,
|
||||
"pokeBattleValue": 130,
|
||||
"tier": [ "UU" ]
|
||||
|
@ -64309,6 +64332,7 @@
|
|||
"Fighting"
|
||||
],
|
||||
"weight": 2000,
|
||||
"unreleased": true,
|
||||
"pokeBattleValue": 130,
|
||||
"tier": [ "UU" ]
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 407,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Absorb Bulb": {
|
||||
|
@ -55,6 +56,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 397,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Aguav Berry": {
|
||||
|
@ -81,6 +83,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 409,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Amaze Mulch": {
|
||||
|
@ -193,6 +196,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 398,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
|
||||
|
@ -204,7 +208,8 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 404,
|
||||
"type": "megastone"
|
||||
"type": "megastone",
|
||||
"unreleased": true
|
||||
}, "Belue Berry": {
|
||||
"description": "No competitive use.",
|
||||
"flingPower": 10,
|
||||
|
@ -213,6 +218,7 @@
|
|||
"type": "Electric"
|
||||
},
|
||||
"spriteId": 166,
|
||||
|
||||
"type": "berries"
|
||||
},
|
||||
"Berry Juice": {
|
||||
|
@ -259,6 +265,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 404,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
}, "Black Belt": {
|
||||
"description": "The holder's Fighting-type attacks have their power multiplied by 1.2.",
|
||||
|
@ -382,7 +389,6 @@
|
|||
"Bug Gem": {
|
||||
"description": "The holder's first successful Bug-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 342,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -455,6 +461,7 @@
|
|||
"mega-x"
|
||||
],
|
||||
"spriteId": 390,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Charizardite Y": {
|
||||
|
@ -619,7 +626,6 @@
|
|||
"Custap Berry": {
|
||||
"description": "The holder moves first in its priority bracket if it has 1/4 or less of its maximum HP. Single use.",
|
||||
"flingPower": 10,
|
||||
"unreleased": true,
|
||||
"naturalGift": {
|
||||
"power": 100,
|
||||
"type": "Ghost"
|
||||
|
@ -648,7 +654,6 @@
|
|||
"Dark Gem": {
|
||||
"description": "The holder's first successful Dark-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 346,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -782,6 +787,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 404,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
}, "Douse Drive": {
|
||||
"description": "The holder's Techno Blast is Water type.",
|
||||
|
@ -804,7 +810,6 @@
|
|||
"Dragon Gem": {
|
||||
"description": "The holder's first successful Dragon-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 345,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -885,7 +890,6 @@
|
|||
"Electric Gem": {
|
||||
"description": "The holder's first successful Electric-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 334,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -950,7 +954,6 @@
|
|||
"Fairy Gem": {
|
||||
"description": "The holder's first successful Fairy-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 425,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -979,7 +982,6 @@
|
|||
}, "Fighting Gem": {
|
||||
"description": "The holder's first successful Fighting-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 337,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -996,7 +998,6 @@
|
|||
"Fire Gem": {
|
||||
"description": "The holder's first successful Fire-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 332,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -1048,7 +1049,6 @@
|
|||
"Flying Gem": {
|
||||
"description": "The holder's first successful Flying-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": false,
|
||||
"spriteId": 340,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -1102,6 +1102,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 404,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Ganlon Berry": {
|
||||
|
@ -1122,6 +1123,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 413,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Gardevoirite": {
|
||||
|
@ -1132,6 +1134,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 387,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Gengarite": {
|
||||
|
@ -1153,7 +1156,6 @@
|
|||
"Ghost Gem": {
|
||||
"description": "The holder's first successful Ghost-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 344,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -1194,7 +1196,6 @@
|
|||
"Grass Gem": {
|
||||
"description": "The holder's first successful Grass-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 335,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -1248,7 +1249,6 @@
|
|||
"Ground Gem": {
|
||||
"description": "The holder's first successful Ground-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 339,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -1272,6 +1272,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 406,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"HP Up": {
|
||||
|
@ -1372,6 +1373,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 396,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Hyper Potion": {
|
||||
|
@ -1393,7 +1395,6 @@
|
|||
"Ice Gem": {
|
||||
"description": "The holder's first successful Ice-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 336,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -1471,6 +1472,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 405,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Kasib Berry": {
|
||||
|
@ -1646,6 +1648,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 404,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Love Ball": {
|
||||
|
@ -1662,6 +1665,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 403,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Luck Incense": {
|
||||
|
@ -1741,6 +1745,7 @@
|
|||
"description": "No competitive use. Evolves Magmar into Magmortar when traded.",
|
||||
"flingPower": 80,
|
||||
"spriteId": 306,
|
||||
"unreleased": true,
|
||||
"type": "misc"
|
||||
},
|
||||
"Magnet": {
|
||||
|
@ -1777,6 +1782,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 412,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Maranga Berry": {
|
||||
|
@ -1859,6 +1865,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 395,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
}, "Meganiumite": {
|
||||
"description": "If the holder is a Meganium, this item allows it to Mega Evolve into Mega Meganium in battle.",
|
||||
|
@ -1868,6 +1875,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 404,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Mental Herb": {
|
||||
|
@ -1927,7 +1935,6 @@
|
|||
"Micle Berry": {
|
||||
"description": "The holder's next move has its accuracy multiplied by 1.2 when it has 1/4 or less of its maximum HP. Single use.",
|
||||
"flingPower": 10,
|
||||
"unreleased": true,
|
||||
"naturalGift": {
|
||||
"power": 100,
|
||||
"type": "Rock"
|
||||
|
@ -1941,6 +1948,7 @@
|
|||
"Milotic",
|
||||
"mega"
|
||||
],
|
||||
"unreleased": true,
|
||||
"spriteId": 404,
|
||||
"type": "megastone"
|
||||
}, "Miltankite": {
|
||||
|
@ -2237,6 +2245,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 401,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Pixie Plate": {
|
||||
|
@ -2260,7 +2269,6 @@
|
|||
"Poison Gem": {
|
||||
"description": "The holder's first successful Poison-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 338,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -2373,7 +2381,6 @@
|
|||
"Psychic Gem": {
|
||||
"description": "The holder's first successful Psychic-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 341,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -2621,7 +2628,6 @@
|
|||
"Rock Gem": {
|
||||
"description": "The holder's first successful Rock-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 343,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -2748,6 +2754,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 400,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Scope Lens": {
|
||||
|
@ -2783,6 +2790,7 @@
|
|||
"mega"
|
||||
],
|
||||
"spriteId": 404,
|
||||
"unreleased": true,
|
||||
"type": "megastone"
|
||||
},
|
||||
"Shed Shell": {
|
||||
|
@ -3001,7 +3009,6 @@
|
|||
"Steel Gem": {
|
||||
"description": "The holder's first successful Steel-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 347,
|
||||
"type": "misc"
|
||||
},
|
||||
|
@ -3227,7 +3234,6 @@
|
|||
"Water Gem": {
|
||||
"description": "The holder's first successful Water-type attack has its power multiplied by 1.3. Single use.",
|
||||
"flingPower": 0,
|
||||
"unreleased": true,
|
||||
"spriteId": 333,
|
||||
"type": "misc"
|
||||
},
|
||||
|
|
|
@ -357,6 +357,23 @@ CLIENT_VERSION = assets.getVersion()
|
|||
server.removePlayer(user.name)
|
||||
user.send("findBattleCanceled")
|
||||
|
||||
spark.on 'findBattleunranked', (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.queuePlayerunranked(user.name, team, format, altName)
|
||||
if validationErrors.length > 0
|
||||
user.error(errors.FIND_BATTLE, validationErrors)
|
||||
|
||||
spark.on 'cancelFindBattleunranked', ->
|
||||
server.removePlayerunranked(user.name)
|
||||
user.send("findBattleCanceledUnranked")
|
||||
|
||||
spark.on 'sendMove', (battleId, moveName, slot, forTurn, options, callback) ->
|
||||
return unless _.isString(moveName)
|
||||
return unless _.isFinite(slot)
|
||||
|
@ -425,7 +442,20 @@ CLIENT_VERSION = assets.getVersion()
|
|||
lobby.message(message)
|
||||
setTimeout(battleSearch, 5 * 1000)
|
||||
|
||||
battleSearchUnranked = ->
|
||||
server.beginBattlesunranked (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(battleSearchUnranked, 5 * 1000)
|
||||
|
||||
|
||||
battleSearch()
|
||||
battleSearchUnranked()
|
||||
|
||||
httpServer.listen(port)
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ class @BattleQueue
|
|||
@newPlayers = []
|
||||
@recentlyMatched = {}
|
||||
@length = 0
|
||||
@ranked = true
|
||||
|
||||
# Adds a player to the queue.
|
||||
# "name" can either be the real name, or an alt
|
||||
|
@ -40,6 +41,9 @@ class @BattleQueue
|
|||
@newPlayers.push(player)
|
||||
@length += 1
|
||||
return true
|
||||
|
||||
setUnranked: ->
|
||||
@ranked = false
|
||||
|
||||
remove: (playerIds) ->
|
||||
playerIds = Array(playerIds) if playerIds not instanceof Array
|
||||
|
@ -71,23 +75,26 @@ class @BattleQueue
|
|||
# An internal function which loads ratings for newly queued players
|
||||
# and removes them from the newly queued list
|
||||
updateNewPlayers: (next) ->
|
||||
ratingKeys = (queued.player.ratingKey for queued in @newPlayers)
|
||||
return next(null) if ratingKeys.length == 0
|
||||
if @ranked == true
|
||||
ratingKeys = (queued.player.ratingKey for queued in @newPlayers)
|
||||
return next(null) if ratingKeys.length == 0
|
||||
|
||||
ratings.getRatings ratingKeys, (err, returnedRatings) =>
|
||||
if err then return next(err)
|
||||
|
||||
ratings.setActive ratingKeys, (err) =>
|
||||
ratings.getRatings ratingKeys, (err, returnedRatings) =>
|
||||
if err then return next(err)
|
||||
|
||||
# Update the ratings in the player objects
|
||||
for rating, i in returnedRatings
|
||||
continue unless @hasUserId(@newPlayers[i].player.id)
|
||||
@newPlayers[i].rating = rating
|
||||
ratings.setActive ratingKeys, (err) =>
|
||||
if err then return next(err)
|
||||
|
||||
# reset the new players list, we're done
|
||||
@newPlayers.splice(0, @newPlayers.length)
|
||||
next(null)
|
||||
# Update the ratings in the player objects
|
||||
for rating, i in returnedRatings
|
||||
continue unless @hasUserId(@newPlayers[i].player.id)
|
||||
@newPlayers[i].rating = rating
|
||||
|
||||
# reset the new players list, we're done
|
||||
@newPlayers.splice(0, @newPlayers.length)
|
||||
next(null)
|
||||
else
|
||||
next(null)
|
||||
|
||||
# Returns an array of pairs. Each pair is a queue object that contains
|
||||
# a player and team key, corresponding to the player socket and player's team.
|
||||
|
@ -98,7 +105,8 @@ class @BattleQueue
|
|||
if err then return next(err, null)
|
||||
|
||||
sortedPlayers = (queued for id, queued of @queue)
|
||||
sortedPlayers.sort((a, b) -> a.rating - b.rating)
|
||||
if @ranked
|
||||
sortedPlayers.sort((a, b) -> a.rating - b.rating)
|
||||
|
||||
alreadyMatched = (false for [0...sortedPlayers.length])
|
||||
|
||||
|
@ -115,20 +123,19 @@ class @BattleQueue
|
|||
rightPlayer = right.player
|
||||
|
||||
# Continue if these two players already played
|
||||
continue if @hasRecentlyMatched(leftPlayer.id, rightPlayer.id)
|
||||
|
||||
continue if @hasRecentlyMatched(leftPlayer.id, rightPlayer.id) and @ranked
|
||||
# If the rating difference is too large break out, we have no possible match for left
|
||||
break unless left.intersectsWith(right)
|
||||
|
||||
# Everything checks out, so make the pair and break out
|
||||
pairs.push([leftPlayer, rightPlayer])
|
||||
@remove([leftPlayer.id, rightPlayer.id])
|
||||
@addRecentMatch(leftPlayer.id, rightPlayer.id)
|
||||
@addRecentMatch(leftPlayer.id, rightPlayer.id) if @ranked
|
||||
alreadyMatched[leftIdx] = alreadyMatched[rightIdx] = true
|
||||
break
|
||||
|
||||
# Expand the range of all unmatched players
|
||||
queued.range += RANGE_INCREMENT for id, queued of @queue
|
||||
|
||||
# Return the list of paired players
|
||||
|
||||
next(null, pairs)
|
||||
|
|
|
@ -30,14 +30,28 @@ FIND_BATTLE_CONDITIONS = [
|
|||
Conditions.UNRELEASED_BAN
|
||||
]
|
||||
|
||||
FIND_BATTLE_CONDITIONS_UNRANKED = [
|
||||
Conditions.TEAM_PREVIEW
|
||||
Conditions.TIMED_BATTLE
|
||||
Conditions.SLEEP_CLAUSE
|
||||
Conditions.EVASION_CLAUSE
|
||||
Conditions.SPECIES_CLAUSE
|
||||
Conditions.PRANKSTER_SWAGGER_CLAUSE
|
||||
Conditions.OHKO_CLAUSE
|
||||
Conditions.UNRELEASED_BAN
|
||||
]
|
||||
|
||||
MAX_NICKNAME_LENGTH = 15
|
||||
|
||||
class @BattleServer
|
||||
constructor: ->
|
||||
@queues = {}
|
||||
@unrankedqueues = {}
|
||||
allformats = ConditionsFunc.Formats()
|
||||
for format of allformats
|
||||
@queues[format] = new BattleQueue()
|
||||
@unrankedqueues[format] = new BattleQueue()
|
||||
@unrankedqueues[format].setUnranked()
|
||||
@battles = {}
|
||||
|
||||
# A hash mapping users to battles.
|
||||
|
@ -239,7 +253,46 @@ class @BattleServer
|
|||
return next(err) if err
|
||||
next(null, _.flatten(battleIds))
|
||||
return true
|
||||
#########################################################################################
|
||||
# Adds the player to the queue. Note that there is no validation on whether altName
|
||||
# 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) ->
|
||||
@unrankedqueues[format].queuedPlayers()
|
||||
|
||||
removePlayerunranked: (playerId, format = DEFAULT_FORMAT) ->
|
||||
return false if format not of @unrankedqueues
|
||||
@unrankedqueues[format].remove(playerId)
|
||||
return true
|
||||
|
||||
beginBattlesunranked: (next) ->
|
||||
allformats = ConditionsFunc.Formats()
|
||||
array = for format in Object.keys(allformats)
|
||||
do (format) => (callback) =>
|
||||
@unrankedqueues[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)
|
||||
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
|
||||
createBattle: (rawFormat = DEFAULT_FORMAT, pair = [], conditions = []) ->
|
||||
allformats = ConditionsFunc.Formats()
|
||||
|
|
Loading…
Reference in New Issue