summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-04-07 22:20:14 -0400
committerDavid Gay <david@davidgay.org>2021-04-07 22:20:14 -0400
commitb1d335e65bfcd813c3565257f8c18f22cdac08dc (patch)
tree90746516cc5fda892345a38a60d66c8b4da19fe2 /app/models
parent5fc450ebd4249efc15e41b1b152a214697f5f415 (diff)
Hacked together Pokemon generator
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ptu_pokemon.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/app/models/ptu_pokemon.rb b/app/models/ptu_pokemon.rb
index c34d32a..a351701 100644
--- a/app/models/ptu_pokemon.rb
+++ b/app/models/ptu_pokemon.rb
@@ -14,4 +14,36 @@ class PtuPokemon < ApplicationRecord
"No gender"
end
end
+
+ def random_stat_hash(level: 1)
+ nature = PtuNature.find(PtuNature.pluck(:id).sample)
+ points_to_assign = 10 + level
+ if self.male_chance
+ gender = 1 + rand(100) <= self.male_chance ? "Male" : "Female"
+ else
+ gender = "No gender"
+ end
+ hash = {
+ name: self.name,
+ level: level,
+ gender: gender,
+ nature: nature.name,
+ stats: {
+ hp: self.base_hp,
+ atk: self.base_atk,
+ def: self.base_def,
+ spatk: self.base_spatk,
+ spdef: self.base_spdef,
+ speed: self.base_speed,
+ }
+ }
+ points_to_assign.times do
+ stat = hash[:stats].keys.sample
+ hash[:stats][stat] += stat == :hp ? 1 : 2
+ end
+ hash[:stats][nature.raises.to_sym] += nature.raises.to_sym == :hp ? 1 : 2
+ hash[:stats][nature.lowers.to_sym] -= nature.lowers.to_sym == :hp ? 1 : 2
+ hash[:stats][nature.lowers.to_sym] = [1, hash[:stats][nature.lowers.to_sym]].max
+ hash
+ end
end