Added framework for random team generation, added admin buttons to generate teams, changed authorization to use different forums depending on test or production
This commit is contained in:
parent
03e1e7d440
commit
cd9ea965bb
|
@ -23,9 +23,13 @@ class @TeambuilderView extends Backbone.View
|
|||
'click .add_pokemon': 'addNewPokemonEvent'
|
||||
'click .save_team': 'saveTeam'
|
||||
|
||||
'click .random-team-admin a': 'randomTeamTierChange'
|
||||
'click .getrandomteams': 'getRandomTeams'
|
||||
|
||||
initialize: (attributes) =>
|
||||
@selectedPokemon = 0
|
||||
@selectedTeam = null
|
||||
@randomformatadmin = window.DEFAULT_FORMAT
|
||||
|
||||
@render()
|
||||
|
||||
|
@ -159,17 +163,18 @@ class @TeambuilderView extends Backbone.View
|
|||
format = $link.data('format')
|
||||
team = @getSelectedTeam()
|
||||
realformat = window.PokeBattle.conditions.Formats_[format]
|
||||
console.log(team.hasPBV())
|
||||
console.log(team.hasTier())
|
||||
if realformat.tierBased and team.hasPBV()
|
||||
console.log('this')
|
||||
else if !realformat.tierBased and team.hasTier()
|
||||
console.log('that')
|
||||
if format != team.get('generation')
|
||||
team.set('generation', format)
|
||||
@renderTeam()
|
||||
@dirty() # renderTeam() removes dirty, so call it again
|
||||
|
||||
randomTeamTierChange: (e) =>
|
||||
@$("#currentselectedrandomadminformat")[0].innerHTML = e.currentTarget.text
|
||||
@randomformatadmin = e.currentTarget.dataset.format
|
||||
getRandomTeams: (e) =>
|
||||
number = parseInt(e.currentTarget.textContent, 10)
|
||||
PokeBattle.primus.send('getRandomTeamsAdmin', @randomformatadmin, number)
|
||||
|
||||
setSelectedPokemonIndex: (index) =>
|
||||
pokemon = @getSelectedTeam().at(index)
|
||||
@selectedPokemon = index
|
||||
|
|
|
@ -11,5 +11,16 @@ if window.PokeBattle.username == "Deukhoofd" || window.PokeBattle.username == "t
|
|||
h5 Admin Commands
|
||||
.button.get-teams Get all teams
|
||||
br
|
||||
| Get teams from user
|
||||
input(type=text)
|
||||
| Get Random teams
|
||||
- var allformats = window.PokeBattle.conditions.Formats()
|
||||
.dropdown.random-team-admin
|
||||
.current-format-random-admin.button.dropdown-toggle(data-toggle="dropdown")
|
||||
a#currentselectedrandomadminformat(href="#", data-format="#{allformats[window.DEFAULT_FORMAT].name}") #{allformats[window.DEFAULT_FORMAT].humanName}
|
||||
ul.dropdown-menu(role='menu')
|
||||
for format in allformats
|
||||
li
|
||||
a(href="#", data-format="#{format.name}") #{format.humanName}
|
||||
.button.getrandomteams 1
|
||||
.button.getrandomteams 5
|
||||
.button.getrandomteams 10
|
||||
.button.getrandomteams 25
|
|
@ -6364,6 +6364,8 @@
|
|||
this.setSelectedTeam = __bind(this.setSelectedTeam, this);
|
||||
this.getSelectedPokemon = __bind(this.getSelectedPokemon, this);
|
||||
this.setSelectedPokemonIndex = __bind(this.setSelectedPokemonIndex, this);
|
||||
this.getRandomTeams = __bind(this.getRandomTeams, this);
|
||||
this.randomTeamTierChange = __bind(this.randomTeamTierChange, this);
|
||||
this.changeTeamFormat = __bind(this.changeTeamFormat, this);
|
||||
this.saveTeam = __bind(this.saveTeam, this);
|
||||
this.addNewPokemon = __bind(this.addNewPokemon, this);
|
||||
|
@ -6408,12 +6410,15 @@
|
|||
'click .go_back': 'goBackToOverview',
|
||||
'click .pokemon_list li': 'clickPokemon',
|
||||
'click .add_pokemon': 'addNewPokemonEvent',
|
||||
'click .save_team': 'saveTeam'
|
||||
'click .save_team': 'saveTeam',
|
||||
'click .random-team-admin a': 'randomTeamTierChange',
|
||||
'click .getrandomteams': 'getRandomTeams'
|
||||
};
|
||||
|
||||
TeambuilderView.prototype.initialize = function(attributes) {
|
||||
this.selectedPokemon = 0;
|
||||
this.selectedTeam = null;
|
||||
this.randomformatadmin = window.DEFAULT_FORMAT;
|
||||
this.render();
|
||||
this.listenTo(PokeBattle.TeamStore, 'reset', this.resetTeams);
|
||||
this.listenTo(PokeBattle.TeamStore, 'add', this.addNewTeam);
|
||||
|
@ -6594,13 +6599,6 @@
|
|||
format = $link.data('format');
|
||||
team = this.getSelectedTeam();
|
||||
realformat = window.PokeBattle.conditions.Formats_[format];
|
||||
console.log(team.hasPBV());
|
||||
console.log(team.hasTier());
|
||||
if (realformat.tierBased && team.hasPBV()) {
|
||||
console.log('this');
|
||||
} else if (!realformat.tierBased && team.hasTier()) {
|
||||
console.log('that');
|
||||
}
|
||||
if (format !== team.get('generation')) {
|
||||
team.set('generation', format);
|
||||
this.renderTeam();
|
||||
|
@ -6608,6 +6606,17 @@
|
|||
}
|
||||
};
|
||||
|
||||
TeambuilderView.prototype.randomTeamTierChange = function(e) {
|
||||
this.$("#currentselectedrandomadminformat")[0].innerHTML = e.currentTarget.text;
|
||||
return this.randomformatadmin = e.currentTarget.dataset.format;
|
||||
};
|
||||
|
||||
TeambuilderView.prototype.getRandomTeams = function(e) {
|
||||
var number;
|
||||
number = parseInt(e.currentTarget.textContent, 10);
|
||||
return PokeBattle.primus.send('getRandomTeamsAdmin', this.randomformatadmin, number);
|
||||
};
|
||||
|
||||
TeambuilderView.prototype.setSelectedPokemonIndex = function(index) {
|
||||
var pokemon;
|
||||
pokemon = this.getSelectedTeam().at(index);
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1083,7 +1083,7 @@ var locals_ = (locals || {}),team = locals_.team,window = locals_.window;buf.pus
|
|||
this["JST"]["teambuilder/teams"] = function anonymous(locals
|
||||
/**/) {
|
||||
var buf = [];
|
||||
var locals_ = (locals || {}),teams = locals_.teams,window = locals_.window,text = locals_.text;buf.push("<h2>Your teams</h2><div class=\"teambuilder_teams clearfix\">");
|
||||
var locals_ = (locals || {}),teams = locals_.teams,window = locals_.window;buf.push("<h2>Your teams</h2><div class=\"teambuilder_teams clearfix\">");
|
||||
// iterate teams
|
||||
;(function(){
|
||||
var $$obj = teams;
|
||||
|
@ -1109,7 +1109,32 @@ buf.push(null == (jade.interp = window.JST['teambuilder/team']({team: team, wind
|
|||
buf.push("</div><div class=\"button button_blue add-new-team\">Add new team</div><div class=\"button import-team\">Import</div>");
|
||||
if ( window.PokeBattle.username == "Deukhoofd" || window.PokeBattle.username == "thesuzerain")
|
||||
{
|
||||
buf.push("<div class=\"Team-Admin\"><h5>Admin Commands</h5><div class=\"button get-teams\">Get all teams</div><br/>Get teams from user<input" + (jade.attrs({ 'type':(text) }, {"type":true})) + "/></div>");
|
||||
buf.push("<div class=\"Team-Admin\"><h5>Admin Commands</h5><div class=\"button get-teams\">Get all teams</div><br/>Get Random teams");
|
||||
var allformats = window.PokeBattle.conditions.Formats()
|
||||
buf.push("<div class=\"dropdown random-team-admin\"><div data-toggle=\"dropdown\" class=\"current-format-random-admin button dropdown-toggle\"><a" + (jade.attrs({ 'id':('currentselectedrandomadminformat'), 'href':("#"), 'data-format':("" + (allformats[window.DEFAULT_FORMAT].name) + "") }, {"href":true,"data-format":true})) + ">" + (jade.escape((jade.interp = allformats[window.DEFAULT_FORMAT].humanName) == null ? '' : jade.interp)) + "</a></div><ul role=\"menu\" class=\"dropdown-menu\">");
|
||||
// iterate allformats
|
||||
;(function(){
|
||||
var $$obj = allformats;
|
||||
if ('number' == typeof $$obj.length) {
|
||||
|
||||
for (var $index = 0, $$l = $$obj.length; $index < $$l; $index++) {
|
||||
var format = $$obj[$index];
|
||||
|
||||
buf.push("<li><a" + (jade.attrs({ 'href':("#"), 'data-format':("" + (format.name) + "") }, {"href":true,"data-format":true})) + ">" + (jade.escape((jade.interp = format.humanName) == null ? '' : jade.interp)) + "</a></li>");
|
||||
}
|
||||
|
||||
} else {
|
||||
var $$l = 0;
|
||||
for (var $index in $$obj) {
|
||||
$$l++; var format = $$obj[$index];
|
||||
|
||||
buf.push("<li><a" + (jade.attrs({ 'href':("#"), 'data-format':("" + (format.name) + "") }, {"href":true,"data-format":true})) + ">" + (jade.escape((jade.interp = format.humanName) == null ? '' : jade.interp)) + "</a></li>");
|
||||
}
|
||||
|
||||
}
|
||||
}).call(this);
|
||||
|
||||
buf.push("</ul><div class=\"button getrandomteams\">1</div><div class=\"button getrandomteams\">5</div><div class=\"button getrandomteams\">10</div><div class=\"button getrandomteams\">25</div></div></div>");
|
||||
};return buf.join("");
|
||||
};
|
||||
|
||||
|
|
|
@ -59,7 +59,11 @@ exports.middleware = -> (req, res, next) ->
|
|||
base64payload = new Buffer(payload).toString('base64')
|
||||
urlencoded = encodeURIComponent(base64payload)
|
||||
crypted = crypto.createHmac('SHA256', secretstring).update(base64payload).digest('hex')
|
||||
return res.redirect("http://forums.p-insurgence.com/session/sso_provider?sso=" + urlencoded + "&sig=" + crypted)
|
||||
console.log(req.headers.host)
|
||||
if req.headers.host is "91.121.152.74:8000"
|
||||
return res.redirect("http://91.121.152.74/session/sso_provider?sso=" + urlencoded + "&sig=" + crypted)
|
||||
else
|
||||
return res.redirect("https://forums.p-insurgence.com/session/sso_provider?sso=" + urlencoded + "&sig=" + crypted)
|
||||
|
||||
exports.matchToken = (req, id, token, next) ->
|
||||
hmac = crypto.createHmac('sha256', config.SECRET_KEY)
|
||||
|
|
|
@ -48,6 +48,8 @@ for gen, i in @ALL_GENERATIONS
|
|||
AbilityMap = {}
|
||||
TypeMap = {}
|
||||
|
||||
RandomList = []
|
||||
|
||||
if gen is 'in'
|
||||
maxLevel = 120
|
||||
else
|
||||
|
@ -68,6 +70,11 @@ for gen, i in @ALL_GENERATIONS
|
|||
for ability in abilities
|
||||
AbilityMap[ability] ?= []
|
||||
AbilityMap[ability].push([pokemonName, formeName])
|
||||
#Add random list
|
||||
randomMapData = formeData
|
||||
randomMapData.Name = pokemonName
|
||||
randomMapData.Forme = formeName
|
||||
RandomList.push(randomMapData)
|
||||
|
||||
AbilityList = Object.keys(AbilityData)
|
||||
MoveList = Object.keys(MoveData)
|
||||
|
@ -88,6 +95,7 @@ for gen, i in @ALL_GENERATIONS
|
|||
AbilityMap : AbilityMap
|
||||
TypeMap : TypeMap
|
||||
maxLevel : maxLevel
|
||||
RandomList : RandomList
|
||||
|
||||
# Now add moves for every generation
|
||||
for gen in @ALL_GENERATIONS
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -19,6 +19,7 @@ config = require('./config')
|
|||
alts = require('./alts')
|
||||
replays = require('./replays')
|
||||
modify = require('./modify')
|
||||
randomTeam = require('./randomTeams')
|
||||
learnsets = require '../shared/learnsets'
|
||||
|
||||
|
||||
|
@ -277,6 +278,15 @@ CLIENT_VERSION = assets.getVersion()
|
|||
return
|
||||
.catch (err) ->
|
||||
console.error(err)
|
||||
|
||||
spark.on 'getRandomTeamsAdmin', (format, number) ->
|
||||
if user.authority == auth.levels.OWNER
|
||||
teamArr = []
|
||||
for [1..number]
|
||||
randomTeam.createTeam format, (team) ->
|
||||
teamArr.push(team)
|
||||
teams = new database.Teams(teamArr)
|
||||
spark.send('receiveTeams', teams.toJSON())
|
||||
|
||||
####################
|
||||
# PRIVATE MESSAGES #
|
||||
|
|
|
@ -0,0 +1,231 @@
|
|||
gen = require './generations'
|
||||
{_} = require 'underscore'
|
||||
database = require('./database')
|
||||
|
||||
FormatsClass = require '../shared/conditions'
|
||||
Formats = FormatsClass.Formats()
|
||||
pokemonArr = []
|
||||
hasmega = false
|
||||
|
||||
createTeam = (format, next) ->
|
||||
pokemonArr = []
|
||||
hasmega = false
|
||||
|
||||
conditions = Formats[format]
|
||||
if conditions.tierBased == false
|
||||
console.log("PBV is not supported")
|
||||
return
|
||||
#throw error
|
||||
generation = conditions.generation.toUpperCase()
|
||||
for condNum in conditions.conditions
|
||||
for conditionName, conditionNumber of FormatsClass.Conditions
|
||||
if conditionNumber is condNum
|
||||
if /TIER_/.test(conditionName)
|
||||
tier = conditionName.replace /TIER_/, ""
|
||||
break
|
||||
getValidFormes generation, tier, (list) ->
|
||||
if list.length < 6
|
||||
console.log("Not enough pokemon in this tier to make a team")
|
||||
return
|
||||
team = {}
|
||||
team.name = "Random" + tier
|
||||
team.id = Math.floor(Math.random() * (10000000) + 10000000)
|
||||
team.generation = conditions.generation
|
||||
getPokemonArr = ->
|
||||
if pokemonArr.length < 6
|
||||
generatePokemon list, generation, (pkmn) ->
|
||||
pokemonArr.push(pkmn)
|
||||
getPokemonArr()
|
||||
getPokemonArr()
|
||||
|
||||
pokemonArr.splice(6)
|
||||
team.pokemon = pokemonArr
|
||||
|
||||
attributes = _.pick(team, 'id', 'name', 'generation')
|
||||
attributes['trainer_id'] = 1
|
||||
attributes['contents'] = JSON.stringify(team.pokemon)
|
||||
|
||||
Team = new database.Team(attributes)
|
||||
next(Team)
|
||||
|
||||
getValidFormes = (generation, tier, next) ->
|
||||
filteredlist = []
|
||||
fullList = gen.GenerationJSON[generation].RandomList
|
||||
for pok in fullList
|
||||
thistier = pok.tier[0]
|
||||
#If tier is correct and has random moves to choose from
|
||||
if thistier == tier and _.has pok, "randomMoves"
|
||||
filteredlist.push(pok)
|
||||
next(filteredlist)
|
||||
|
||||
|
||||
generatePokemon = (list, generation, next) ->
|
||||
|
||||
tryGenerate = ->
|
||||
#Generate a random pokemon
|
||||
pokemon = list[Math.floor(Math.random() * (list.length))]
|
||||
|
||||
for teamMember in pokemonArr
|
||||
#reject if we already have this species
|
||||
if pokemon.Name is teamMember.species
|
||||
tryGenerate()
|
||||
return
|
||||
#reject if we already have a mega
|
||||
if /mega/.test(pokemon.Forme) and hasmega
|
||||
tryGenerate()
|
||||
return
|
||||
|
||||
Obj = {}
|
||||
Obj.species = pokemon.Name
|
||||
#Generate moves through different function
|
||||
possibleMoves = pokemon.randomMoves
|
||||
Obj.moves = generateMoves(possibleMoves)
|
||||
|
||||
#Get forme
|
||||
if pokemon.isBattleOnly
|
||||
#gotta give it a megastone if it's a mega
|
||||
if /mega/.test(pokemon.Forme)
|
||||
itemList = gen.GenerationJSON[generation].ItemData
|
||||
for item, itemdata of itemList
|
||||
if _.has itemdata, "mega"
|
||||
if itemdata.mega[0] is pokemon.Name and itemdata.mega[1] is pokemon.Forme
|
||||
Obj.item = item
|
||||
hasmega = true
|
||||
break
|
||||
#gotta handle itembased mons
|
||||
if pokemon.isItemBased
|
||||
itemList = gen.GenerationJSON[generation].ItemData
|
||||
for item, itemdata of itemList
|
||||
if _.has itemdata, "itemForme"
|
||||
if itemdata.itemForme[0] is pokemon.Name and itemdata.itemForme[1] is pokemon.Forme
|
||||
Obj.item = item
|
||||
break
|
||||
|
||||
Obj.forme = "default"
|
||||
pokemon = gen.GenerationJSON[generation].FormeData[pokemon.Name]["default"]
|
||||
else
|
||||
Obj.forme = pokemon.Forme
|
||||
|
||||
#Assign ability
|
||||
abiInt = 0
|
||||
if _.has pokemon, "hiddenAbility"
|
||||
abiInt = 1
|
||||
abilityRan = Math.floor(Math.random() * (pokemon.abilities.length + abiInt))
|
||||
if abilityRan is pokemon.abilities.length
|
||||
Obj.ability = pokemon.hiddenAbility
|
||||
else
|
||||
Obj.ability = pokemon.abilities[abilityRan]
|
||||
|
||||
natureArray = ["Hardy","Lonely","Brave","Adamant","Naughty","Bold","Docile","Relaxed","Impish","Lax","Timid","Hasty","Serious","Jolly","Naive","Modest","Mild","Quiet","Bashful","Rash","Calm","Gentle","Sassy","Careful","Quirky"]
|
||||
Obj.nature = natureArray[Math.floor(Math.random() * (natureArray.length))]
|
||||
|
||||
Obj.level = gen.GenerationJSON[generation].maxLevel
|
||||
Obj.happiness = 100
|
||||
|
||||
Obj.evs = { hp: 84, specialAttack:85, speed:84, attack:85,defense:85,specialDefense:85 }
|
||||
|
||||
#determine if a move is Hidden Power, to determine IVs
|
||||
hiddenPower = "none"
|
||||
integer = 0
|
||||
for pmove in Obj.moves
|
||||
if /Hidden Power/.test(pmove)
|
||||
hiddenPower = pmove.replace /Hidden Power /, ""
|
||||
Obj.moves[integer] = "Hidden Power"
|
||||
integer = integer + 1
|
||||
Obj.ivs = determineIVs(hiddenPower)
|
||||
|
||||
next(Obj)
|
||||
tryGenerate()
|
||||
|
||||
generateMoves = (possibleMoves) ->
|
||||
movesArr = []
|
||||
while movesArr.length < 4
|
||||
if movesArr.length is 0
|
||||
moveIndex = Math.floor(Math.random() * (possibleMoves.length))
|
||||
movesArr.push(possibleMoves[moveIndex])
|
||||
else
|
||||
generateMove = ->
|
||||
moveIndex = Math.floor(Math.random() * (possibleMoves.length))
|
||||
movename = possibleMoves[moveIndex]
|
||||
#We reject the move if it's not defined
|
||||
if typeof movename == "undefined"
|
||||
generateMove()
|
||||
return
|
||||
#We reject the move if we aleady have it
|
||||
for movething in movesArr
|
||||
if movething is movename
|
||||
generateMove()
|
||||
return
|
||||
#We reject the move if we already have Hidden Power
|
||||
if /Hidden Power/.test(movename)
|
||||
for movething in movesArr
|
||||
if /Hidden Power/.test(movething)
|
||||
generateMove()
|
||||
return
|
||||
movesArr.push(movename)
|
||||
generateMove()
|
||||
movesArr.splice(4)
|
||||
return movesArr
|
||||
|
||||
determineIVs = (type) ->
|
||||
ivObj = {
|
||||
hp: 31,
|
||||
attack: 31,
|
||||
defense: 31,
|
||||
specialAttack: 31,
|
||||
specialDefense: 31,
|
||||
speed: 31
|
||||
}
|
||||
switch type
|
||||
when "none" then return ivObj
|
||||
when "Bug"
|
||||
ivObj.speed = 30
|
||||
ivObj.specialDefense = 30
|
||||
when "Dark" then return ivObj
|
||||
when "Dragon"
|
||||
ivObj.hp = 30
|
||||
when "Electric"
|
||||
ivObj.specialAttack = 30
|
||||
when "Fighting"
|
||||
ivObj.defense = 30
|
||||
ivObj.specialDefense = 30
|
||||
ivObj.specialAttack = 30
|
||||
ivObj.speed = 30
|
||||
when "Fire"
|
||||
ivObj.attack = 30
|
||||
ivObj.speed = 30
|
||||
ivObj.specialAttack = 30
|
||||
when "Flying"
|
||||
ivObj.speed = 30
|
||||
ivObj.specialDefense = 30
|
||||
ivObj.specialAttack = 30
|
||||
when "Ghost"
|
||||
ivObj.attack = 30
|
||||
ivObj.specialDefense = 30
|
||||
when "Grass"
|
||||
ivObj.hp = 30
|
||||
ivObj.specialAttack = 30
|
||||
when "Ground"
|
||||
ivObj.specialDefense = 30
|
||||
ivObj.specialAttack = 30
|
||||
when "Ice"
|
||||
ivObj.speed = 30
|
||||
when "Poison"
|
||||
ivObj.defense = 30
|
||||
ivObj.specialDefense = 30
|
||||
ivObj.specialAttack = 30
|
||||
when "Psychic"
|
||||
ivObj.hp = 30
|
||||
ivObj.speed = 30
|
||||
when "Rock"
|
||||
ivObj.defense = 30
|
||||
ivObj.speed = 30
|
||||
ivObj.specialDefense = 30
|
||||
when "Steel"
|
||||
ivObj.specialDefense = 30
|
||||
when "Water"
|
||||
ivObj.speed = 30
|
||||
ivObj.specialAttack = 30
|
||||
return ivObj
|
||||
|
||||
module.exports = {createTeam}
|
Loading…
Reference in New Issue