1
0
mirror of https://gitlab.com/Deukhoofd/BattleSim.git synced 2025-10-27 18:00:03 +00:00

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:
Deukhoofd
2016-04-11 20:01:11 +02:00
parent 03e1e7d440
commit cd9ea965bb
10 changed files with 5620 additions and 5282 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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 #

231
server/randomTeams.coffee Normal file
View File

@@ -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}