mythal 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config.yml +9 -0
- data/lib/mythal.rb +5 -24
- data/lib/mythal/cli.rb +21 -0
- data/lib/mythal/config.rb +23 -19
- data/lib/mythal/npc.rb +37 -10
- data/lib/mythal/stats.rb +88 -0
- data/lib/mythal/version.rb +1 -1
- metadata +4 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 229d18d0fee0f6ce08cfbdd6ad1dad60bdecc93b6fe61dfa3f23eee39015022e
         | 
| 4 | 
            +
              data.tar.gz: 209bc0b21ebdbc292389a5c97f52ffc549d0dca088bc2a1c34829393a2023cbf
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 0cfce4639aec18f639f64cf1b8dbd28ba95bdda11aac719ec578e5a65481a82ced89890efd73daff5994bfc6a38b9dc5670fe64580a638e4cdf34a728336a420
         | 
| 7 | 
            +
              data.tar.gz: 21bdab990e8455328552a8aa0f77d462dfe0c1529e82045c0458abf5da1ecc108225dd6e0fdd0527863fe15f2478fffac3e1ee1aae693d871ab9cd50eaaa75e1
         | 
    
        data/config.yml
    CHANGED
    
    | @@ -47,3 +47,12 @@ dnd_classes: | |
| 47 47 | 
             
              - monk
         | 
| 48 48 | 
             
              - warlock
         | 
| 49 49 | 
             
              - paladin
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            npc_stats_by_challenge_rating:
         | 
| 52 | 
            +
              'Headers': [proficiency_bonus, armor_class, hit_points, attack_bonus, damage_per_round, save_dc]
         | 
| 53 | 
            +
              '0': [2, 13, 1..6, 3, 1..2, 13]
         | 
| 54 | 
            +
              '1/8': [2, 13, 7..35, 3, 2..3, 13]
         | 
| 55 | 
            +
              '1/4': [2, 13, 36..49, 3, 4..5, 13]
         | 
| 56 | 
            +
              '1/2': [2, 13, 50..70, 3, 6..8, 13]
         | 
| 57 | 
            +
              '1': [2, 13, 71..85, 3, 9..14, 13]
         | 
| 58 | 
            +
              '2': [2, 13, 16..100, 3, 15..20, 13]
         | 
    
        data/lib/mythal.rb
    CHANGED
    
    | @@ -1,30 +1,11 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            module Mythal
         | 
| 2 | 
            +
            end
         | 
| 3 | 
            +
             | 
| 2 4 | 
             
            require "thor"
         | 
| 3 5 | 
             
            require "procto"
         | 
| 4 6 | 
             
            require "mythal/version"
         | 
| 5 7 | 
             
            require "mythal/config"
         | 
| 6 8 | 
             
            require "mythal/roll"
         | 
| 9 | 
            +
            require "mythal/stats"
         | 
| 7 10 | 
             
            require "mythal/npc"
         | 
| 8 | 
            -
             | 
| 9 | 
            -
            module Mythal
         | 
| 10 | 
            -
              class CLI < Thor
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                desc "roll", "roll some number of dice, plus modifiers e.g. 1d20, or 3d8 + 4"
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                def roll(*args)
         | 
| 15 | 
            -
                  puts Mythal::Roll.call(*args).message
         | 
| 16 | 
            -
                end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                desc "npc", "generate a random npc, e.g. 'a half-orc barbarian'"
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                def npc
         | 
| 21 | 
            -
                  puts Mythal::Npc.call(config: config)
         | 
| 22 | 
            -
                end
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                private
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                def config
         | 
| 27 | 
            -
                  @config ||= Mythal::Config.new
         | 
| 28 | 
            -
                end
         | 
| 29 | 
            -
              end
         | 
| 30 | 
            -
            end
         | 
| 11 | 
            +
            require "mythal/cli"
         | 
    
        data/lib/mythal/cli.rb
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            module Mythal
         | 
| 2 | 
            +
              class CLI < Thor
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                desc "roll", "roll some number of dice, plus modifiers e.g. 1d20, or 3d8 + 4"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                def roll(*args)
         | 
| 7 | 
            +
                  puts Mythal::Roll.call(*args).message
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                desc "npc", "generate a random npc, e.g. 'a half-orc barbarian'"
         | 
| 11 | 
            +
                method_option :challenge_rating, type: :string, aliases: "--cr"
         | 
| 12 | 
            +
                method_option :options, type: :hash, aliases: "-o"
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def npc
         | 
| 15 | 
            +
                  puts Mythal::Npc.call(
         | 
| 16 | 
            +
                    challenge_rating: options[:challenge_rating],
         | 
| 17 | 
            +
                    user_overrides: options[:options]&.transform_keys(&:to_sym),
         | 
| 18 | 
            +
                  ).message
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
    
        data/lib/mythal/config.rb
    CHANGED
    
    | @@ -3,32 +3,36 @@ require "pathname" | |
| 3 3 |  | 
| 4 4 | 
             
            module Mythal
         | 
| 5 5 | 
             
              class Config
         | 
| 6 | 
            -
                 | 
| 7 | 
            -
                   | 
| 8 | 
            -
                end
         | 
| 6 | 
            +
                class << self
         | 
| 7 | 
            +
                  attr_reader :settings
         | 
| 9 8 |  | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 9 | 
            +
                  def config
         | 
| 10 | 
            +
                    @config ||= YAML.load(File.read(config_file))
         | 
| 11 | 
            +
                  end
         | 
| 13 12 |  | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 13 | 
            +
                  def dnd_classes
         | 
| 14 | 
            +
                    config["dnd_classes"]
         | 
| 15 | 
            +
                  end
         | 
| 17 16 |  | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 17 | 
            +
                  def npc_stats_by_challenge_rating
         | 
| 18 | 
            +
                    config["npc_stats_by_challenge_rating"]
         | 
| 19 | 
            +
                  end
         | 
| 21 20 |  | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 21 | 
            +
                  def races
         | 
| 22 | 
            +
                    config["races"]
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  def traits
         | 
| 26 | 
            +
                    config["traits"]
         | 
| 27 | 
            +
                  end
         | 
| 25 28 |  | 
| 26 | 
            -
             | 
| 29 | 
            +
                  private
         | 
| 27 30 |  | 
| 28 | 
            -
             | 
| 31 | 
            +
                  attr_reader :user_overrides
         | 
| 29 32 |  | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 33 | 
            +
                  def config_file
         | 
| 34 | 
            +
                    Pathname.new(File.expand_path("../../../config.yml", __FILE__))
         | 
| 35 | 
            +
                  end
         | 
| 32 36 | 
             
                end
         | 
| 33 37 | 
             
              end
         | 
| 34 38 | 
             
            end
         | 
    
        data/lib/mythal/npc.rb
    CHANGED
    
    | @@ -2,32 +2,59 @@ module Mythal | |
| 2 2 | 
             
              class Npc
         | 
| 3 3 | 
             
                include Procto.call
         | 
| 4 4 |  | 
| 5 | 
            -
                def initialize( | 
| 6 | 
            -
                  @ | 
| 5 | 
            +
                def initialize(challenge_rating: "1/4", user_overrides: {})
         | 
| 6 | 
            +
                  @challenge_rating = challenge_rating
         | 
| 7 | 
            +
                  @user_overrides = user_overrides
         | 
| 7 8 | 
             
                end
         | 
| 8 9 |  | 
| 9 10 | 
             
                def call
         | 
| 10 | 
            -
                   | 
| 11 | 
            +
                  self
         | 
| 11 12 | 
             
                end
         | 
| 12 13 |  | 
| 13 | 
            -
                 | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 14 | 
            +
                def stats
         | 
| 15 | 
            +
                  @stats ||= Mythal::Stats.new(
         | 
| 16 | 
            +
                    challenge_rating: challenge_rating,
         | 
| 17 | 
            +
                    options: (user_overrides || {}),
         | 
| 18 | 
            +
                  )
         | 
| 19 | 
            +
                end
         | 
| 16 20 |  | 
| 17 21 | 
             
                def character_description
         | 
| 18 22 | 
             
                  trait + " " + race + " " + dnd_class
         | 
| 19 23 | 
             
                end
         | 
| 20 24 |  | 
| 21 | 
            -
                def  | 
| 22 | 
            -
                  config. | 
| 25 | 
            +
                def dnd_class
         | 
| 26 | 
            +
                  config.dnd_classes.sample
         | 
| 23 27 | 
             
                end
         | 
| 24 28 |  | 
| 25 29 | 
             
                def race
         | 
| 26 30 | 
             
                  config.races.sample
         | 
| 27 31 | 
             
                end
         | 
| 28 32 |  | 
| 29 | 
            -
                def  | 
| 30 | 
            -
                  config. | 
| 33 | 
            +
                def trait
         | 
| 34 | 
            +
                  config.traits.sample
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def message
         | 
| 38 | 
            +
                  <<~OUTPUT
         | 
| 39 | 
            +
                    ---
         | 
| 40 | 
            +
                    #{character_description}
         | 
| 41 | 
            +
                    ---
         | 
| 42 | 
            +
                    Armor Class: #{stats.armor_class}
         | 
| 43 | 
            +
                    Hit Points: #{stats.hit_points}
         | 
| 44 | 
            +
                    Attack: +#{stats.attack_bonus}
         | 
| 45 | 
            +
                    Damage: #{stats.damage_per_round} slashing
         | 
| 46 | 
            +
                    Speed: #{stats.speed}ft
         | 
| 47 | 
            +
                    Challenge Rating: #{stats.challenge_rating}
         | 
| 48 | 
            +
                    ---
         | 
| 49 | 
            +
                  OUTPUT
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                private
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                attr_reader :user_overrides, :challenge_rating
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                def config
         | 
| 57 | 
            +
                  Mythal::Config
         | 
| 31 58 | 
             
                end
         | 
| 32 59 | 
             
              end
         | 
| 33 60 | 
             
            end
         | 
    
        data/lib/mythal/stats.rb
    ADDED
    
    | @@ -0,0 +1,88 @@ | |
| 1 | 
            +
            module Mythal
         | 
| 2 | 
            +
              class Stats
         | 
| 3 | 
            +
                VALID_ATTRS = %i[
         | 
| 4 | 
            +
                  challenge_rating
         | 
| 5 | 
            +
                  proficiency_bonus
         | 
| 6 | 
            +
                  armor_class
         | 
| 7 | 
            +
                  hit_points
         | 
| 8 | 
            +
                  damage_per_round
         | 
| 9 | 
            +
                  attack_bonus
         | 
| 10 | 
            +
                  save_dc
         | 
| 11 | 
            +
                  speed
         | 
| 12 | 
            +
                  str
         | 
| 13 | 
            +
                  dex
         | 
| 14 | 
            +
                  con
         | 
| 15 | 
            +
                  int
         | 
| 16 | 
            +
                  wis
         | 
| 17 | 
            +
                  cha
         | 
| 18 | 
            +
                ]
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                VALID_CHALLENGE_RATINGS = %w[0 1/8 1/4 1/2 1 2]
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                attr_reader :challenge_rating, :options
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def initialize(challenge_rating: "1/4", options: {})
         | 
| 25 | 
            +
                  @challenge_rating = init_challenge_rating(challenge_rating)
         | 
| 26 | 
            +
                  @options = options
         | 
| 27 | 
            +
                  post_initialize
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def attributes
         | 
| 31 | 
            +
                  {
         | 
| 32 | 
            +
                    challenge_rating: challenge_rating,
         | 
| 33 | 
            +
                    proficiency_bonus: stats_by_cr["proficiency_bonus"],
         | 
| 34 | 
            +
                    armor_class: stats_by_cr["armor_class"],
         | 
| 35 | 
            +
                    hit_points: init_hit_points,
         | 
| 36 | 
            +
                    damage_per_round: init_damage_per_round,
         | 
| 37 | 
            +
                    attack_bonus: stats_by_cr["attack_bonus"],
         | 
| 38 | 
            +
                    save_dc: stats_by_cr["save_dc"],
         | 
| 39 | 
            +
                    speed: 30,
         | 
| 40 | 
            +
                    str: 15,
         | 
| 41 | 
            +
                    dex: 14,
         | 
| 42 | 
            +
                    con: 13,
         | 
| 43 | 
            +
                    int: 12,
         | 
| 44 | 
            +
                    wis: 10,
         | 
| 45 | 
            +
                    cha: 8,
         | 
| 46 | 
            +
                  }.merge(user_overrides)
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                private
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                def config
         | 
| 52 | 
            +
                  Mythal::Config
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                def init_damage_per_round
         | 
| 56 | 
            +
                  Range.new(*stats_by_cr["damage_per_round"].split("..").map(&:to_i)).to_a.sample
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                def stats_by_cr
         | 
| 60 | 
            +
                  @stats_by_cr ||= begin
         | 
| 61 | 
            +
                    raw_stats = config.npc_stats_by_challenge_rating
         | 
| 62 | 
            +
                    raw_stats["Headers"].zip(raw_stats[challenge_rating]).to_h
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                def init_challenge_rating(cr)
         | 
| 67 | 
            +
                  default_cr = "1/4"
         | 
| 68 | 
            +
                  return default_cr unless VALID_CHALLENGE_RATINGS.include?(cr)
         | 
| 69 | 
            +
                  cr
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                def init_hit_points
         | 
| 73 | 
            +
                  Range.new(*stats_by_cr["hit_points"].split("..").map(&:to_i)).to_a.sample
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                def user_overrides
         | 
| 77 | 
            +
                  options.select do |k, _v|
         | 
| 78 | 
            +
                    VALID_ATTRS.include?(k)
         | 
| 79 | 
            +
                  end
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                def post_initialize
         | 
| 83 | 
            +
                  attributes.each do |attr_name, attr_value|
         | 
| 84 | 
            +
                    define_singleton_method(attr_name) { attr_value }
         | 
| 85 | 
            +
                  end
         | 
| 86 | 
            +
                end
         | 
| 87 | 
            +
              end
         | 
| 88 | 
            +
            end
         | 
    
        data/lib/mythal/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: mythal
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - George Groh
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2018- | 
| 11 | 
            +
            date: 2018-12-09 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -114,9 +114,11 @@ files: | |
| 114 114 | 
             
            - config.yml
         | 
| 115 115 | 
             
            - exe/mythal
         | 
| 116 116 | 
             
            - lib/mythal.rb
         | 
| 117 | 
            +
            - lib/mythal/cli.rb
         | 
| 117 118 | 
             
            - lib/mythal/config.rb
         | 
| 118 119 | 
             
            - lib/mythal/npc.rb
         | 
| 119 120 | 
             
            - lib/mythal/roll.rb
         | 
| 121 | 
            +
            - lib/mythal/stats.rb
         | 
| 120 122 | 
             
            - lib/mythal/version.rb
         | 
| 121 123 | 
             
            - mythal.gemspec
         | 
| 122 124 | 
             
            homepage: https://github.com/Inglorion-G/mythal
         |