Added class GameData::Stat

This commit is contained in:
Maruno17
2021-03-04 22:59:48 +00:00
parent 934e38662a
commit ff0c2f00c8
46 changed files with 1301 additions and 1202 deletions

View File

@@ -262,7 +262,7 @@ end
def pbBugContestScore(pkmn)
levelscore = pkmn.level * 4
ivscore = 0
pkmn.iv.each { |iv| ivscore += iv.to_f / Pokemon::IV_STAT_LIMIT }
pkmn.iv.each_value { |iv| ivscore += iv.to_f / Pokemon::IV_STAT_LIMIT }
ivscore = (ivscore * 100).floor
hpscore = (100.0 * pkmn.hp / pkmn.totalhp).floor
catch_rate = pkmn.species_data.catch_rate

View File

@@ -26,53 +26,55 @@ class PBPokemon
@move2 = move2 ? move2 : 0
@move3 = move3 ? move3 : 0
@move4 = move4 ? move4 : 0
# TODO: Stat changes (what is @ev here? Seems to be a set of bit flags
# indicating each stat that should have EVs put into it. Could change it).
@ev = ev
end
# This method is how each Pokémon is compiled from the PBS files listing
# Battle Tower/Cup Pokémon.
def self.fromInspected(str)
insp=str.gsub(/^\s+/,"").gsub(/\s+$/,"")
pieces=insp.split(/\s*;\s*/)
species = (GameData::Species.exists?(pieces[0])) ? GameData::Species.get(pieces[0]).id : nil
item = (GameData::Item.exists?(pieces[1])) ? GameData::Item.get(pieces[1]).id : nil
nature = (GameData::Nature.exists?(pieces[2])) ? GameData::Nature.get(pieces[2]).id : nil
ev=pieces[3].split(/\s*,\s*/)
evvalue=0
for i in 0...6
next if !ev[i]||ev[i]==""
evupcase=ev[i].upcase
evvalue|=0x01 if evupcase=="HP"
evvalue|=0x02 if evupcase=="ATK"
evvalue|=0x04 if evupcase=="DEF"
evvalue|=0x08 if evupcase=="SPD"
evvalue|=0x10 if evupcase=="SA"
evvalue|=0x20 if evupcase=="SD"
ev = pieces[3].split(/\s*,\s*/)
ev_array = []
ev.each do |stat|
case stat.upcase
when "HP" then ev_array.push(:HP)
when "ATK" then ev_array.push(:ATTACK)
when "DEF" then ev_array.push(:DEFENSE)
when "SA", "SPATK" then ev_array.push(:SPECIAL_ATTACK)
when "SD", "SPDEF" then ev_array.push(:SPECIAL_DEFENSE)
when "SPD" then ev_array.push(:SPEED)
end
end
moves=pieces[4].split(/\s*,\s*/)
moveid=[]
for i in 0...4
for i in 0...Pokemon::MAX_MOVES
move_data = GameData::Move.try_get(moves[i])
moveid.push(move_data.id) if move_data
end
moveid=[GameData::Move.get(1)] if moveid.length==0
return self.new(species, item, nature, moveid[0], moveid[1], moveid[2], moveid[3], evvalue)
return self.new(species, item, nature, moveid[0], moveid[1], moveid[2], moveid[3], ev_array)
end
def self.fromPokemon(pokemon)
evvalue=0
evvalue|=0x01 if pokemon.ev[0]>60
evvalue|=0x02 if pokemon.ev[1]>60
evvalue|=0x04 if pokemon.ev[2]>60
evvalue|=0x08 if pokemon.ev[3]>60
evvalue|=0x10 if pokemon.ev[4]>60
evvalue|=0x20 if pokemon.ev[5]>60
mov1 = (pokemon.moves[0]) ? pokemon.moves[0].id : nil
mov2 = (pokemon.moves[1]) ? pokemon.moves[1].id : nil
mov3 = (pokemon.moves[2]) ? pokemon.moves[2].id : nil
mov4 = (pokemon.moves[3]) ? pokemon.moves[3].id : nil
ev_array = []
GameData::Stat.each_main do |s|
ev_array.push(s.id) if pokemon.ev[s.id] > 60
end
return self.new(pokemon.species,pokemon.item_id,pokemon.nature,
mov1,mov2,mov3,mov4,evvalue)
mov1,mov2,mov3,mov4,ev_array)
end
# Unused.
def self.constFromStr(mod,str)
maxconst=0
for constant in mod.constants
@@ -86,10 +88,12 @@ class PBPokemon
return 0
end
# Unused.
def self.fromString(str)
return self.fromstring(str)
end
# Unused.
def self.fromstring(str)
s=str.split(/\s*,\s*/)
species=GameData::Species.get(s[1]).id
@@ -99,15 +103,12 @@ class PBPokemon
move2=(s.length>=12) ? GameData::Move.get(s[5]).id : nil
move3=(s.length>=13) ? GameData::Move.get(s[6]).id : nil
move4=(s.length>=14) ? GameData::Move.get(s[7]).id : nil
ev=0
slen=s.length-6
ev|=0x01 if s[slen].to_i>0
ev|=0x02 if s[slen+1].to_i>0
ev|=0x04 if s[slen+2].to_i>0
ev|=0x08 if s[slen+3].to_i>0
ev|=0x10 if s[slen+4].to_i>0
ev|=0x20 if s[slen+5].to_i>0
return self.new(species,item,nature,move1,move2,move3,move4,ev)
slen = s.length - 6
ev_array = []
GameData::Stat.each_main do |s|
ev_array.push(s.id) if s[slen + s.pbs_order].to_i > 0
end
return self.new(species,item,nature,move1,move2,move3,move4,ev_array)
end
=begin
@@ -129,12 +130,10 @@ class PBPokemon
c1=GameData::Species.get(@species).id.to_s
c2=(@item) ? GameData::Item.get(@item).id.to_s : ""
c3=(@nature) ? GameData::Nature.get(@nature).id.to_s : ""
evlist=""
for i in 0...@ev
if ((@ev&(1<<i))!=0)
evlist+="," if evlist.length>0
evlist+=["HP","ATK","DEF","SPD","SA","SD"][i]
end
evlist = ""
@ev.each do |stat|
evlist += "," if evlist != ""
evlist += stat.real_name_brief
end
c4=(@move1) ? GameData::Move.get(@move1).id_to_s : ""
c5=(@move2) ? GameData::Move.get(@move2).id_to_s : ""
@@ -143,6 +142,7 @@ class PBPokemon
return "#{c1};#{c2};#{c3};#{evlist};#{c4},#{c5},#{c6},#{c7}"
end
# Unused.
def tocompact
return "#{species},#{item},#{nature},#{move1},#{move2},#{move3},#{move4},#{ev}"
end
@@ -164,15 +164,10 @@ class PBPokemon
pokemon.moves[1] = Pokemon::Move.new(self.convertMove(@move2))
pokemon.moves[2] = Pokemon::Move.new(self.convertMove(@move3))
pokemon.moves[3] = Pokemon::Move.new(self.convertMove(@move4))
evcount=0
for i in 0...6
evcount+=1 if ((@ev&(1<<i))!=0)
end
evperstat=(evcount==0) ? 0 : Pokemon::EV_LIMIT/evcount
for i in 0...6
pokemon.iv[i]=iv
pokemon.ev[i]=((@ev&(1<<i))!=0) ? evperstat : 0
if ev.length > 0
ev.each { |stat| pokemon.ev[stat] = Pokemon::EV_LIMIT / ev.length }
end
GameData::Stat.each_main { |s| pokemon.iv[s.id] = iv }
pokemon.calcStats
return pokemon
end

View File

@@ -390,7 +390,7 @@ class StandardRestriction
return false if speciesBlacklist.include?(pkmn.species)
# Species with total base stat 600 or more are banned
bst = 0
pkmn.baseStats.each { |s| bst += s }
pkmn.baseStats.each_value { |s| bst += s }
return false if bst >= 600
# Is valid
return true

View File

@@ -269,7 +269,8 @@ def pbRandomPokemonFromRule(rule,trainer)
next if r<7 && evolutions(species).length>0
break
end
ev=rand(63)+1
ev = []
GameData::Stat.each_main { |s| ev.push(s.id) if rand(100) < 50 }
nature = nil
keys = GameData::Nature::DATA.keys
loop do
@@ -281,8 +282,9 @@ def pbRandomPokemonFromRule(rule,trainer)
raised_emphasis = false
lowered_emphasis = false
nature_data.stat_changes.each do |change|
raised_emphasis = true if change[1] > 0 && ((ev >> change[0]) & 1) != 0
lowered_emphasis = true if change[1] < 0 && ((ev >> change[0]) & 1) != 0
next if !ev.include?(change[0])
raised_emphasis = true if change[1] > 0
lowered_emphasis = true if change[1] < 0
end
next if rand(10) < 6 && !raised_emphasis
next if rand(10) < 9 && lowered_emphasis
@@ -340,18 +342,12 @@ def pbRandomPokemonFromRule(rule,trainer)
next if species != :CLAMPERL
when :THICKCLUB
next if species != :CUBONE && species != :MAROWAK
end
if item == :LIECHIBERRY && (ev&0x02)==0
next if rand(2)==0
ev|=0x02
end
if item == :SALACBERRY && (ev&0x08)==0
next if rand(2)==0
ev|=0x08
end
if item == :PETAYABERRY && (ev&0x10)==0
next if rand(2)==0
ev|=0x10
when :LIECHIBERRY
ev.push(:ATTACK) if !ev.include?(:ATTACK) && rand(100) < 50
when :SALACBERRY
ev.push(:SPEED) if !ev.include?(:SPEED) && rand(100) < 50
when :PETAYABERRY
ev.push(:SPECIAL_ATTACK) if !ev.include?(:SPECIAL_ATTACK) && rand(100) < 50
end
break
end
@@ -414,11 +410,11 @@ def pbRandomPokemonFromRule(rule,trainer)
hasSpecial=true if d.category==1
end
end
if !hasPhysical && (ev&0x02)!=0
if !hasPhysical && ev.include?(:ATTACK)
# No physical attack, but emphasizes Attack
next if rand(10)<8
end
if !hasSpecial && (ev&0x10)!=0
if !hasSpecial && ev.include?(:SPECIAL_ATTACK)
# No special attack, but emphasizes Special Attack
next if rand(10)<8
end
@@ -429,12 +425,12 @@ def pbRandomPokemonFromRule(rule,trainer)
############
# Moves accepted
if hasPhysical && !hasSpecial
ev&=~0x10 if rand(10)<8 # Deemphasize Special Attack
ev|=0x02 if rand(10)<8 # Emphasize Attack
ev.push(:ATTACK) if rand(10)<8
ev.delete(:SPECIAL_ATTACK) if rand(10)<8
end
if !hasPhysical && hasSpecial
ev|=0x10 if rand(10)<8 # Emphasize Special Attack
ev&=~0x02 if rand(10)<8 # Deemphasize Attack
ev.delete(:ATTACK) if rand(10)<8
ev.push(:SPECIAL_ATTACK) if rand(10)<8
end
item = :LEFTOVERS if !hasNormal && item == :SILKSCARF
moves=newmoves
@@ -1100,16 +1096,11 @@ def isBattlePokemonDuplicate(pk,pk2)
# Accept as same if moves are same and there are four moves each
return true if moves1[Pokemon::MAX_MOVES - 1]
end
return true if pk.item==pk2.item &&
pk.nature==pk2.nature &&
pk.ev[0]==pk2.ev[0] &&
pk.ev[1]==pk2.ev[1] &&
pk.ev[2]==pk2.ev[2] &&
pk.ev[3]==pk2.ev[3] &&
pk.ev[4]==pk2.ev[4] &&
pk.ev[5]==pk2.ev[5]
return false
same_evs = true
GameData::Stat.each_main { |s| same_evs = false if pk.ev[s.id] != pk2.ev[s.id] }
return pk.item==pk2.item && pk.nature==pk2.nature && same_evs
end
return false
end
def pbRemoveDuplicates(party)