trainers rematch

This commit is contained in:
infinitefusion
2021-08-01 13:45:50 -04:00
parent 960867dc7d
commit cd5a2caf94
20 changed files with 276 additions and 204 deletions

View File

@@ -1,23 +1,50 @@
#
#
#
# class RematchTrainer
# attr_reader :id
# attr_reader :nbTimesRematched
class RematchTrainer
attr_reader :id
attr_reader :nbTimesRematched
def initialize(id)
@id = id
@nbTimesRematched = 0
end
def incrementNbTimes()
@nbTimesRematched += 1
end
def removeNbTimes()
@nbTimesRematched -= 1
end
end
#Methods called from elsewhere in the code
#
# def initialize(id)
# @id = id
# @nbTimesRematched = 0
# end
# called from pbEndOfBattle
#
# def incrementNbTimes()
# @nbTimesRematched += 1
# end
#
# def removeNbTimes()
# @nbTimesRematched -= 1
# end
# end
def incrNbRematches(trainerId)
$PokemonGlobal.rematchedTrainers.each do |key, trainer|
if(trainer.id == trainerId)
trainer.incrementNbTimes()
end
end
end
# called from Trainer.to_trainer
def getNumberRematch(trainerId)
if $PokemonGlobal.rematchedTrainers == nil
$PokemonGlobal.rematchedTrainers = Hash.new
addNewTrainerRematch(trainerId)
end
trainer = $PokemonGlobal.rematchedTrainers[trainerId.to_sym]
if trainer == nil
addNewTrainerRematch(trainerId)
return 0
end
return (trainer.nbTimesRematched)
end
#
#
#
@@ -37,186 +64,169 @@
# # nb = (level/10).ceil
#
#
# def addNewTrainerRematch(trainerId)
# #$PokemonGlobal.rematchedTrainers[:trainerId]
# newTrainer = RematchTrainer.new(trainerId)
# $PokemonGlobal.rematchedTrainers[trainerId.to_sym] = newTrainer
#
# end
#
#
# def getNumberRematch(trainerId)
# if $PokemonGlobal.rematchedTrainers == nil
# $PokemonGlobal.rematchedTrainers = Hash.new
# addNewTrainerRematch(trainerId)
# end
# trainer = $PokemonGlobal.rematchedTrainers[trainerId.to_sym]
# if trainer == nil
# addNewTrainerRematch(trainerId)
# return 0
# end
# return (trainer.nbTimesRematched)
# end
#
#
#
# def getNumberRematchOld(trainerId)
# if $PokemonGlobal.rematchedTrainers == nil
# $PokemonGlobal.rematchedTrainers = Hash.new
# addNewTrainerRematch(trainerId)
# end
#
# $PokemonGlobal.rematchedTrainers.each do |key, trainer|
# if(trainer.id == trainerId)
# return (trainer.nbTimesRematched)
# end
# end
# addNewTrainerRematch(trainerId)
# return 0
# end
#
# def incrNbRematches(trainerId)
# $PokemonGlobal.rematchedTrainers.each do |key, trainer|
# if(trainer.id == trainerId)
# trainer.incrementNbTimes()
# end
# end
# end
#
# def getRematchLevel(originalLevel,nbRematch)
# levelCap = getLevelCap(originalLevel,$Trainer.numbadges)
# expRate = getLevelRate(originalLevel)
# levelIncr =0
# for i in 0..nbRematch
# if i % expRate == 0
# levelIncr += 1
# end
# end
# newLevel = originalLevel + levelIncr
# #printDebugRematchInfo(nbRematch,expRate,newLevel,levelCap,originalLevel)
# return (newLevel < levelCap) ? newLevel : levelCap
# end
#
# def getLevelRate(originalLevel)
# return 2 + (originalLevel/20).ceil
# end
#
# def getLevelCap(originalLevel,nbBadges)
# return 100 if $game_switches[599] #no cap in battle arena
# cap = originalLevel + nbBadges +2
# return cap < 100 ? cap : 100
# end
#
#
# def decreaseRematchNumber(trainerId)
# $PokemonGlobal.rematchedTrainers.each do |key, trainer|
# if(trainer.id == trainerId)
# trainer.removeNbTimes()
# return
# end
# end
# end
#
#
# def evolveRematchPokemon(nbRematch,species)
# if(nbRematch >= 10 && $Trainer.numbadges >= 3)
# evospecies=getEvolution(species)
# return species if evospecies == -1
# if(nbRematch >= 20 && $Trainer.numbadges >= 8)
# secondEvoSpecies=getEvolution(evospecies)
# return secondEvoSpecies == -1 ? evospecies : secondEvoSpecies
# end
# return evospecies
# end
# return species
# end
#
# def getEvolution(species)
# if species >= Settings::NB_POKEMON
# pokemon = PokeBattle_Pokemon.new(species,1)
# body = getBasePokemonID(species)
# head = getBasePokemonID(species,false)
# ret_evoB = pbGetEvolvedFormData(body)
# ret_evoH = pbGetEvolvedFormData(head)
#
# evoBody = ret_evoB.any? ? ret_evoB[0][2] : -1
# evoHead = ret_evoH.any? ? ret_evoH[0][2] : -1
#
# return -1 if isNegativeOrNull(evoBody) && isNegativeOrNull(evoHead)
# return body*Settings::NB_POKEMON+evoHead if isNegativeOrNull(evoBody) #only head evolves
# return evoBody*Settings::NB_POKEMON + head if isNegativeOrNull(evoHead) #only body evolves
# return evoBody*Settings::NB_POKEMON+evoHead #both evolve
# else
# evo = pbGetEvolvedFormData(species)
# return evo.any? ? evo[0][2] : -1
# end
# end
#
#
def addNewTrainerRematch(trainerId)
#$PokemonGlobal.rematchedTrainers[:trainerId]
newTrainer = RematchTrainer.new(trainerId)
$PokemonGlobal.rematchedTrainers[trainerId.to_sym] = newTrainer
end
def getNumberRematchOld(trainerId)
if $PokemonGlobal.rematchedTrainers == nil
$PokemonGlobal.rematchedTrainers = Hash.new
addNewTrainerRematch(trainerId)
end
$PokemonGlobal.rematchedTrainers.each do |key, trainer|
if(trainer.id == trainerId)
return (trainer.nbTimesRematched)
end
end
addNewTrainerRematch(trainerId)
return 0
end
def getRematchLevel(originalLevel,nbRematch)
levelCap = getLevelCap(originalLevel,$Trainer.numbadges)
expRate = getLevelRate(originalLevel)
levelIncr =0
for i in 0..nbRematch
if i % expRate == 0
levelIncr += 1
end
end
newLevel = originalLevel + levelIncr
#printDebugRematchInfo(nbRematch,expRate,newLevel,levelCap,originalLevel)
return (newLevel < levelCap) ? newLevel : levelCap
end
def getLevelRate(originalLevel)
return 2 + (originalLevel/20).ceil
end
def getLevelCap(originalLevel,nbBadges)
return 100 if $game_switches[599] #no cap in battle arena
cap = originalLevel + nbBadges +2
return cap < 100 ? cap : 100
end
def decreaseRematchNumber(trainerId)
$PokemonGlobal.rematchedTrainers.each do |key, trainer|
if(trainer.id == trainerId)
trainer.removeNbTimes()
return
end
end
end
def evolveRematchPokemon(nbRematch,species)
if(nbRematch >= 10 && $Trainer.numbadges >= 3)
evospecies=getEvolution(species)
return species if evospecies == -1
if(nbRematch >= 20 && $Trainer.numbadges >= 8)
secondEvoSpecies=getEvolution(evospecies)
return secondEvoSpecies == -1 ? evospecies : secondEvoSpecies
end
return evospecies
end
return species
end
def getEvolution(species)
if species >= Settings::NB_POKEMON
pokemon = PokeBattle_Pokemon.new(species,1)
body = getBasePokemonID(species)
head = getBasePokemonID(species,false)
ret_evoB = pbGetEvolvedFormData(body)
ret_evoH = pbGetEvolvedFormData(head)
evoBody = ret_evoB.any? ? ret_evoB[0][2] : -1
evoHead = ret_evoH.any? ? ret_evoH[0][2] : -1
return -1 if isNegativeOrNull(evoBody) && isNegativeOrNull(evoHead)
return body*Settings::NB_POKEMON+evoHead if isNegativeOrNull(evoBody) #only head evolves
return evoBody*Settings::NB_POKEMON + head if isNegativeOrNull(evoHead) #only body evolves
return evoBody*Settings::NB_POKEMON+evoHead #both evolve
else
evo = pbGetEvolvedFormData(species)
return evo.any? ? evo[0][2] : -1
end
end
def getFusionSpecies(body,head)
id = body * Settings::NB_POKEMON + head
return GameData::Species.get(id).species
end
#
# def evolveHead(species)
# if species <= Settings::NB_POKEMON
# evo = getEvolution(species)
# return evo == -1 ? species : evo
# end
# head = getBasePokemonID(species,false)
# body = getBasePokemonID(species)
# headEvo = getEvolution(head)
# return headEvo == -1 ? species : getFusionSpecies(body,headEvo)
# end
#
# def evolveBody(species)
# if species <= Settings::NB_POKEMON
# evo = getEvolution(species)
# return evo == -1 ? species : evo
# end
# head = getBasePokemonID(species,false)
# body = getBasePokemonID(species)
# bodyEvo = getEvolution(body)
# return bodyEvo == -1 ? species : getFusionSpecies(bodyEvo,head)
# end
#
#
# def getCorrectEvolvedSpecies(pokemon)
# if pokemon.species >= Settings::NB_POKEMON
# body = getBasePokemonID(pokemon.species)
# head = getBasePokemonID(pokemon.species,false)
# ret1=-1;ret2=-1
# for form in pbGetEvolvedFormData(body)
# retB=yield pokemon,form[0],form[1],form[2]
# break if retB>0
# end
# for form in pbGetEvolvedFormData(head)
# retH=yield pokemon,form[0],form[1],form[2]
# break if retH>0
# end
# return ret if ret == retB && ret == retH
# return fixEvolutionOverflow(retB,retH,pokemon.species)
# else
# for form in pbGetEvolvedFormData(pokemon.species)
# newspecies=form[2]
# end
# return newspecies;
# end
#
# end
#
#
# def printDebugRematchInfo(nbRematch,expRate,newLevel,levelCap,originalLevel)
# info = ""
# info << "total rematched trainers: "+ $PokemonGlobal.rematchedTrainers.length.to_s + "\n"
#
# info << "nb times: "+ nbRematch.to_s + "\n"
# info << "lvl up every " + expRate.to_s + " times" + "\n"
# info << "original level: " << originalLevel.to_s + "\n"
# info << "new level: " + newLevel.to_s + "\n"
# info << "level cap: "+ levelCap.to_s
# print info
# end
def evolveHead(species)
if species <= Settings::NB_POKEMON
evo = getEvolution(species)
return evo == -1 ? species : evo
end
head = getBasePokemonID(species,false)
body = getBasePokemonID(species)
headEvo = getEvolution(head)
return headEvo == -1 ? species : getFusionSpecies(body,headEvo)
end
def evolveBody(species)
if species <= Settings::NB_POKEMON
evo = getEvolution(species)
return evo == -1 ? species : evo
end
head = getBasePokemonID(species,false)
body = getBasePokemonID(species)
bodyEvo = getEvolution(body)
return bodyEvo == -1 ? species : getFusionSpecies(bodyEvo,head)
end
def getCorrectEvolvedSpecies(pokemon)
if pokemon.species >= Settings::NB_POKEMON
body = getBasePokemonID(pokemon.species)
head = getBasePokemonID(pokemon.species,false)
ret1=-1;ret2=-1
for form in pbGetEvolvedFormData(body)
retB=yield pokemon,form[0],form[1],form[2]
break if retB>0
end
for form in pbGetEvolvedFormData(head)
retH=yield pokemon,form[0],form[1],form[2]
break if retH>0
end
return ret if ret == retB && ret == retH
return fixEvolutionOverflow(retB,retH,pokemon.species)
else
for form in pbGetEvolvedFormData(pokemon.species)
newspecies=form[2]
end
return newspecies;
end
end
def printDebugRematchInfo(nbRematch,expRate,newLevel,levelCap,originalLevel)
info = ""
info << "total rematched trainers: "+ $PokemonGlobal.rematchedTrainers.length.to_s + "\n"
info << "nb times: "+ nbRematch.to_s + "\n"
info << "lvl up every " + expRate.to_s + " times" + "\n"
info << "original level: " << originalLevel.to_s + "\n"
info << "new level: " + newLevel.to_s + "\n"
info << "level cap: "+ levelCap.to_s
print info
end
#
#
#