- Joined
- Feb 10, 2022
- Posts
- 5
So for my take on Pokemon, I was thinking about how to make pokemon breeding more useful in-game (to split the game into three parts--research, gym contest/battles, breeding), and repurposing the contest stats as less effective, but breedable EVs was an idea I really liked. This idea actually started as "hey, let's make contest stats breedable" and then morphed into the EV idea, so some of the scripts don't really make sense when put together and need some more fine tweaking.
But I'm bringing this up now for two things:
1. Feedback on the idea. I've already installed ways to speed up egg hatching, but if the idea sparks anything you'd like to suggest, feel free.
2. Feedback on the code. I'm a python escapee and I'm mostly just brute-forcing my way through my code right now. Suggestions and advice to shrink and compact it would be amazing.
The first edits in order of the scripts are in Trainer. I haven't actually tested these much, more that it just doesn't seem to crash when I try it.
I added Cool thru Cute, but I included the other three to give you an idea where I added it in.
This code I believe adds in an empty 0 for the stats? I'm basically just copying whatever EVs do.
And then I believe this should be calling whatever I put into the trainer file.
This is my code edit to add them to actual stats. As you'll notice, I currently have them reduced to 1/8th, half as effective as EVs. Feel free to change that, but I like that you still get more out of training your pokemon. It also makes it easier to give a higher cap.
This is how I'm currently rolling CVs. There's a switch that gets higher as you progress in the game, giving wild pokemon higher rolls (same with IVs). This is where I'm primarily looking for coding help. I tried looking at how natures work in stats to make it shorter, but I couldn't get it work at all, so I brute forced it. Thankfully some saint told me about cases, but elsif works just as well lol.
It rolls a random number beween 0-32, adds the relative modifier, and then makes sure none of them are below zero. I wonder if there's a way to shortcut rand(33) so that you can change it easily all at once? Like how I have the nature modifiers set as variables. Oh, I guess you could do rand(x) and let you set x. That's smart, smart.
Now the crux of the original code, the breeding. This could also easily be cleaned up. It was the first thing I wrote and was still when I was expecting to do 252/252 stats like IVs, so it's only intended to pass two and that's it. I'll probably need to bump this up a bit and maybe add the reroll based on nature, which means I'll need to clean up that code before I can optimize this one.
If you made it this far, tell me why Croagunk is the best poison type
But I'm bringing this up now for two things:
1. Feedback on the idea. I've already installed ways to speed up egg hatching, but if the idea sparks anything you'd like to suggest, feel free.
2. Feedback on the code. I'm a python escapee and I'm mostly just brute-forcing my way through my code right now. Suggestions and advice to shrink and compact it would be amazing.
The first edits in order of the scripts are in Trainer. I haven't actually tested these much, more that it just doesn't seem to crash when I try it.
Trainer edit 1, under SCHEMA:
"Nature" => [:nature, "e", :Nature],
"IV" => [:iv, "uUUUUU"],
"EV" => [:ev, "uUUUUU"],
"Cool" => [:cool, "u"],
"Beauty" => [:beauty, "u"],
"Tough" => [:tough, "u"],
"Smart" => [:smart, "u"],
"Cute" => [:cute, "u"],
I added Cool thru Cute, but I included the other three to give you an idea where I added it in.
This code I believe adds in an empty 0 for the stats? I'm basically just copying whatever EVs do.
Trainer, under Initialize:
@pokemon.each do |pkmn|
GameData::Stat.each_main do |s|
pkmn[:iv][s.id] ||= 0 if pkmn[:iv]
pkmn[:ev][s.id] ||= 0 if pkmn[:ev]
pkmn[:cool] ||= 0 if pkmn[:cool]
pkmn[:beauty] ||= 0 if pkmn[:beauty]
pkmn[:tough] ||= 0 if pkmn[:tough]
pkmn[:smart] ||= 0 if pkmn[:smart]
pkmn[:cute] ||= 0 if pkmn[:cute]
And then I believe this should be calling whatever I put into the trainer file.
Trainer, def to_trainer:
pkmn.cool = pkmn_data[:cool]
pkmn.beauty = pkmn_data[:beauty]
pkmn.tough = pkmn_data[:tough]
pkmn.cute = pkmn_data[:cute]
pkmn.smart = pkmn_data[:smart]
pkmn.happiness = pkmn_data[:happiness] if pkmn_data[:happiness]
pkmn.name = pkmn_data[:name] if pkmn_data[:name] && !pkmn_data[:name].empty?
This is my code edit to add them to actual stats. As you'll notice, I currently have them reduced to 1/8th, half as effective as EVs. Feel free to change that, but I like that you still get more out of training your pokemon. It also makes it easier to give a higher cap.
Pokemon:
# @return [Integer] the specified stat of this Pokémon (not used for total HP)
def calcStat(base, level, iv, ev, nat, con)
return ((((base * 2 + iv + (ev / 4) + (con / 8)) * level / 100).floor + 5) * nat / 100).floor
end
# Recalculates this Pokémon's stats.
def calc_stats
base_stats = self.baseStats
this_level = self.level
this_IV = self.calcIV
# Format stat multipliers due to nature
nature_mod = {}
GameData::Stat.each_main { |s| nature_mod[s.id] = 100 }
this_nature = self.nature_for_stats
if this_nature
this_nature.stat_changes.each { |change| nature_mod[change[0]] += change[1] }
end
# Contest Stats Adding
contest_mod = {}
GameData::Stat.each_main { |s| contest_mod[s.id] = 0 }
contest_mod[:ATTACK] += @cool
contest_mod[:DEFENSE] += @tough
contest_mod[:SPECIAL_ATTACK] += @beauty
contest_mod[:SPECIAL_DEFENSE] += @smart
contest_mod[:SPEED] += @cute
# Calculate stats
stats = {}
GameData::Stat.each_main do |s|
if s.id == :HP
stats[s.id] = calcHP(base_stats[s.id], this_level, this_IV[s.id], @ev[s.id])
else
stats[s.id] = calcStat(base_stats[s.id], this_level, this_IV[s.id], @ev[s.id], nature_mod[s.id], contest_mod[s.id])
end
end
hpDiff = @totalhp - @hp
@totalhp = stats[:HP]
@hp = @totalhp - hpDiff
@attack = stats[:ATTACK]
@defense = stats[:DEFENSE]
@spatk = stats[:SPECIAL_ATTACK]
@spdef = stats[:SPECIAL_DEFENSE]
@speed = stats[:SPEED]
end
This is how I'm currently rolling CVs. There's a switch that gets higher as you progress in the game, giving wild pokemon higher rolls (same with IVs). This is where I'm primarily looking for coding help. I tried looking at how natures work in stats to make it shorter, but I couldn't get it work at all, so I brute forced it. Thankfully some saint told me about cases, but elsif works just as well lol.
It rolls a random number beween 0-32, adds the relative modifier, and then makes sure none of them are below zero. I wonder if there's a way to shortcut rand(33) so that you can change it easily all at once? Like how I have the nature modifiers set as variables. Oh, I guess you could do rand(x) and let you set x. That's smart, smart.
Overworld_EncounterModifiers:
Events.onWildPokemonCreate += proc { |_sender, e|
pokemon = e[0]
cv_switch = $game_variables[100]
case cv_switch
when 1
nature_positive = 32
nature_neutral = 8
nature_negative = -8
when 2
nature_positive = 64
nature_neutral = 16
nature_negative = 0
when 3
nature_positive = 128
nature_neutral = 32
nature_negative = 8
when 4
nature_positive = 220
nature_neutral = 64
nature_negative = 16
else
nature_positive = 16
nature_neutral = 0
nature_negative = -16
end
# Format stat multipliers due to nature
case pokemon.nature_id
when :ADAMANT
pokemon.cool = [(rand(33) + nature_positive), 0].max
pokemon.beauty = [(rand(33) + nature_negative), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :BASHFUL
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :BOLD
pokemon.cool = [(rand(33) + nature_negative), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_positive), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :BRAVE
pokemon.cool = [(rand(33) + nature_positive), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_negative), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :CALM
pokemon.cool = [(rand(33) + nature_negative), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_positive), 0].max
when :CAREFUL
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_negative), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_positive), 0].max
when :DOCILE
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :GENTLE
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_negative), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_positive), 0].max
when :HARDY
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :HASTY
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_negative), 0].max
pokemon.cute = [(rand(33) + nature_positive), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :IMPISH
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_positive), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_negative), 0].max
when :JOLLY
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_negative), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_positive), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :LAX
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_positive), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_negative), 0].max
when :LONELY
pokemon.cool = [(rand(33) + nature_positive), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_negative), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :MILD
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_positive), 0].max
pokemon.tough = [(rand(33) + nature_negative), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :MODEST
pokemon.cool = [(rand(33) + nature_negative), 0].max
pokemon.beauty = [(rand(33) + nature_positive), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :NAIVE
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_negative), 0].max
pokemon.smart = [(rand(33) + nature_positive), 0].max
when :NAUGHTY
pokemon.cool = [(rand(33) + nature_positive), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_negative), 0].max
when :QUIET
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_positive), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_negative), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :QUIRKY
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :RASH
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_positive), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_negative), 0].max
when :RELAXED
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_positive), 0].max
pokemon.cute = [(rand(33) + nature_negative), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :SASSY
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_negative), 0].max
pokemon.smart = [(rand(33) + nature_positive), 0].max
when :SERIOUS
pokemon.cool = [(rand(33) + nature_neutral), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_neutral), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
when :TIMID
pokemon.cool = [(rand(33) + nature_negative), 0].max
pokemon.beauty = [(rand(33) + nature_neutral), 0].max
pokemon.tough = [(rand(33) + nature_neutral), 0].max
pokemon.cute = [(rand(33) + nature_positive), 0].max
pokemon.smart = [(rand(33) + nature_neutral), 0].max
end
pokemon.sheen = pokemon.cool + pokemon.beauty + pokemon.tough + pokemon.cute + pokemon.smart
}
Now the crux of the original code, the breeding. This could also easily be cleaned up. It was the first thing I wrote and was still when I was expecting to do 252/252 stats like IVs, so it's only intended to pass two and that's it. I'll probably need to bump this up a bit and maybe add the reroll based on nature, which means I'll need to clean up that code before I can optimize this one.
Overworld_Daycare, between inheriting IVs and nature:
# Inheriting contest Values
cvspassed = 2
statspassed = []
num = 0
egg.cool = father.cool and statspassed.push(0) and num +=1 if father.hasItem?(:REDSCARF)
egg.beauty = father.beauty and statspassed.push(1) and num +=1 if father.hasItem?(:BLUESCARF)
egg.tough = father.tough and statspassed.push(2) and num +=1 if father.hasItem?(:YELLOWSCARF)
egg.cute = father.cute and statspassed.push(3) and num +=1 if father.hasItem?(:PINKSCARF)
egg.smart = father.smart and statspassed.push(4) and num +=1 if father.hasItem?(:GREENSCARF)
egg.cool = mother.cool and statspassed.push(0) and num +=1 if mother.hasItem?(:REDSCARF)
egg.beauty = mother.beauty and statspassed.push(1) and num +=1 if mother.hasItem?(:BLUESCARF)
egg.tough = mother.tough and statspassed.push(2) and num +=1 if mother.hasItem?(:YELLOWSCARF)
egg.cute = mother.cute and statspassed.push(3) and num +=1 if mother.hasItem?(:PINKSCARF)
egg.smart = mother.smart and statspassed.push(4) and num +=1 if mother.hasItem?(:GREENSCARF)
r = rand(2)
loop do
roll = rand(5)
while statspassed.include?(roll) do
roll = rand(5)
end
if r == 0
if roll == 0
egg.cool = father.cool
statspassed.push(0)
elsif roll == 1
egg.beauty = father.beauty
statspassed.push(1)
elsif roll == 2
egg.tough = father.tough
statspassed.push(2)
elsif roll == 3
egg.cute = father.cute
statspassed.push(3)
elsif roll == 4
egg.smart = father.smart
statspassed.push(4)
end
elsif r == 1
if roll == 0
egg.cool = mother.cool
statspassed.push(0)
elsif roll == 1
egg.beauty = mother.beauty
statspassed.push(1)
elsif roll == 2
egg.tough = mother.tough
statspassed.push(2)
elsif roll == 3
egg.cute = mother.cute
statspassed.push(3)
elsif roll == 4
egg.smart = mother.smart
statspassed.push(4)
end
end
num += 1
r = (r+1)%2
break if num>=cvspassed
end
If you made it this far, tell me why Croagunk is the best poison type
Upvote
0