diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/games/ptu/encounters_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/games/ptu/pokemon_controller.rb | 2 | ||||
-rw-r--r-- | app/javascript/stylesheets/core.css | 4 | ||||
-rw-r--r-- | app/models/ptu_pokemon.rb | 41 | ||||
-rw-r--r-- | app/views/games/ptu/encounters/index.html.erb | 16 | ||||
-rw-r--r-- | app/views/games/ptu/index.html.erb | 6 | ||||
-rw-r--r-- | app/views/games/ptu/pokemon/index.html.erb | 2 |
7 files changed, 57 insertions, 16 deletions
diff --git a/app/controllers/games/ptu/encounters_controller.rb b/app/controllers/games/ptu/encounters_controller.rb index a7da852..07d6c7f 100644 --- a/app/controllers/games/ptu/encounters_controller.rb +++ b/app/controllers/games/ptu/encounters_controller.rb @@ -1,6 +1,6 @@ class Games::Ptu::EncountersController < ApplicationController def index - @pokemons = PtuPokemon.all + @pokemons = PtuPokemon.all.order("name ASC") if params[:commit] @results = [] pokemon = PtuPokemon.find(params[:pokemon]) diff --git a/app/controllers/games/ptu/pokemon_controller.rb b/app/controllers/games/ptu/pokemon_controller.rb index e5329a7..1b88063 100644 --- a/app/controllers/games/ptu/pokemon_controller.rb +++ b/app/controllers/games/ptu/pokemon_controller.rb @@ -1,6 +1,6 @@ class Games::Ptu::PokemonController < ApplicationController def index - @pokemons = PtuPokemon.all + @pokemons = PtuPokemon.all.order("name ASC") end def show diff --git a/app/javascript/stylesheets/core.css b/app/javascript/stylesheets/core.css index ec06839..613e961 100644 --- a/app/javascript/stylesheets/core.css +++ b/app/javascript/stylesheets/core.css @@ -44,3 +44,7 @@ textarea { textarea:focus { @apply border-gray-700; } + +td { + @apply p-2 border border-gray-600; +} diff --git a/app/models/ptu_pokemon.rb b/app/models/ptu_pokemon.rb index a351701..6074fcd 100644 --- a/app/models/ptu_pokemon.rb +++ b/app/models/ptu_pokemon.rb @@ -17,7 +17,6 @@ class PtuPokemon < ApplicationRecord 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 @@ -28,22 +27,48 @@ class PtuPokemon < ApplicationRecord level: level, gender: gender, nature: nature.name, - stats: { + base_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, - } + }, + stats: {}, } + + # Adjust base stats for nature + hash[:base_stats][nature.raises.to_sym] += nature.raises.to_sym == :hp ? 1 : 2 + hash[:base_stats][nature.lowers.to_sym] -= nature.lowers.to_sym == :hp ? 1 : 2 + hash[:base_stats][nature.lowers.to_sym] = [1, hash[:base_stats][nature.lowers.to_sym]].max + + # e.g. [[:speed, 9], [:atk, 8], [:def, 8], [:spatk, 6], [:spdef, 6], [:hp, 5]] + sorted_base_stats = hash[:base_stats].sort_by { |_, v| -v } + + rank = 1 + # e.g. [1, 2, 2, 4, 4, 6] + rankings_array = sorted_base_stats.each_with_index.map { |a, i| sorted_base_stats[i - 1][1] == a[1] ? rank : (rank = i + 1) } + + # e.g. {:speed=>1, :atk=>2, :def=>2, :spatk=>4, :spdef=>4, :hp=>6} + base_stat_rankings = Hash[sorted_base_stats.map { |s| s[0] }.zip(rankings_array)] + + hash[:stats] = hash[:base_stats].deep_dup + points_to_assign = 10 + level points_to_assign.times do - stat = hash[:stats].keys.sample - hash[:stats][stat] += stat == :hp ? 1 : 2 + loop do + stat = hash[:stats].keys.sample + higher_base_stats = base_stat_rankings.select { |_, v| v < base_stat_rankings[stat] }.keys + if higher_base_stats.select { |s| hash[:stats][s] <= (hash[:stats][stat] + 1) }.any? + next + else + hash[:stats][stat] += 1 and break + end + end 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[:hit_points] = 10 + level + (hash[:stats][:hp] * 3) + hash end end diff --git a/app/views/games/ptu/encounters/index.html.erb b/app/views/games/ptu/encounters/index.html.erb index 4712a3c..3da5214 100644 --- a/app/views/games/ptu/encounters/index.html.erb +++ b/app/views/games/ptu/encounters/index.html.erb @@ -1,3 +1,5 @@ +<%= link_to "Back", games_ptu_path %> + <h1>Encounters</h1> <p>Use this page to generate random Pokemon for an encounter.</p> @@ -27,6 +29,7 @@ <th>Level</th> <th>Gender</th> <th>Nature</th> + <th>Hit Points</th> <th>HP</th> <th>ATK</th> <th>DEF</th> @@ -42,12 +45,13 @@ <td><%= result[:level] %></td> <td><%= result[:gender] %></td> <td><%= result[:nature] %></td> - <td><%= result[:stats][:hp] %></td> - <td><%= result[:stats][:atk] %></td> - <td><%= result[:stats][:def] %></td> - <td><%= result[:stats][:spatk] %></td> - <td><%= result[:stats][:spdef] %></td> - <td><%= result[:stats][:speed] %></td> + <td><%= result[:hit_points] %></td> + <td><%= result[:stats][:hp] %> (<%= result[:base_stats][:hp] %>)</td> + <td><%= result[:stats][:atk] %> (<%= result[:base_stats][:atk] %>)</td> + <td><%= result[:stats][:def] %> (<%= result[:base_stats][:def] %>)</td> + <td><%= result[:stats][:spatk] %> (<%= result[:base_stats][:spatk] %>)</td> + <td><%= result[:stats][:spdef] %> (<%= result[:base_stats][:spdef] %>)</td> + <td><%= result[:stats][:speed] %> (<%= result[:base_stats][:speed] %>)</td> </tr> <% end %> </tbody> diff --git a/app/views/games/ptu/index.html.erb b/app/views/games/ptu/index.html.erb new file mode 100644 index 0000000..d9b83e7 --- /dev/null +++ b/app/views/games/ptu/index.html.erb @@ -0,0 +1,6 @@ +<h1>PTU</h1> + +<ul> + <li><%= link_to "Pokemon", games_ptu_pokemon_index_path %></li> + <li><%= link_to "Encounters", games_ptu_encounters_path %></li> +</ul> diff --git a/app/views/games/ptu/pokemon/index.html.erb b/app/views/games/ptu/pokemon/index.html.erb index a1d7443..46d356e 100644 --- a/app/views/games/ptu/pokemon/index.html.erb +++ b/app/views/games/ptu/pokemon/index.html.erb @@ -1,3 +1,5 @@ +<%= link_to "Back", games_ptu_path %> + <h1>Pokemon</h1> <div class="my-4"><%= link_to "New", new_games_ptu_pokemon_path %></div> |