natural_20 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +6 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +7 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +99 -0
  9. data/Rakefile +6 -0
  10. data/bin/compute_lights +19 -0
  11. data/bin/console +19 -0
  12. data/bin/nat20 +135 -0
  13. data/bin/nat20.cmd +3 -0
  14. data/bin/nat20author +104 -0
  15. data/bin/setup +8 -0
  16. data/char_classes/fighter.yml +45 -0
  17. data/char_classes/rogue.yml +54 -0
  18. data/characters/halfling_rogue.yml +46 -0
  19. data/characters/high_elf_fighter.yml +49 -0
  20. data/fixtures/battle_sim.yml +58 -0
  21. data/fixtures/battle_sim_2.yml +30 -0
  22. data/fixtures/battle_sim_3.yml +26 -0
  23. data/fixtures/battle_sim_4.yml +26 -0
  24. data/fixtures/battle_sim_objects.yml +101 -0
  25. data/fixtures/corridors.yml +24 -0
  26. data/fixtures/elf_rogue.yml +39 -0
  27. data/fixtures/halfling_rogue.yml +41 -0
  28. data/fixtures/high_elf_fighter.yml +49 -0
  29. data/fixtures/human_fighter.yml +48 -0
  30. data/fixtures/path_finding_test.yml +11 -0
  31. data/fixtures/path_finding_test_2.yml +15 -0
  32. data/fixtures/path_finding_test_3.yml +26 -0
  33. data/fixtures/thin_walls.yml +53 -0
  34. data/fixtures/traps.yml +25 -0
  35. data/game.yml +20 -0
  36. data/items/equipment.yml +101 -0
  37. data/items/objects.yml +73 -0
  38. data/items/weapons.yml +297 -0
  39. data/lib/natural_20.rb +68 -0
  40. data/lib/natural_20/actions/action.rb +40 -0
  41. data/lib/natural_20/actions/attack_action.rb +372 -0
  42. data/lib/natural_20/actions/concerns/action_damage.rb +14 -0
  43. data/lib/natural_20/actions/dash_action.rb +46 -0
  44. data/lib/natural_20/actions/disengage_action.rb +53 -0
  45. data/lib/natural_20/actions/dodge_action.rb +45 -0
  46. data/lib/natural_20/actions/escape_grapple_action.rb +97 -0
  47. data/lib/natural_20/actions/first_aid_action.rb +109 -0
  48. data/lib/natural_20/actions/grapple_action.rb +185 -0
  49. data/lib/natural_20/actions/ground_interact_action.rb +74 -0
  50. data/lib/natural_20/actions/help_action.rb +56 -0
  51. data/lib/natural_20/actions/hide_action.rb +53 -0
  52. data/lib/natural_20/actions/interact_action.rb +91 -0
  53. data/lib/natural_20/actions/inventory_action.rb +23 -0
  54. data/lib/natural_20/actions/look_action.rb +63 -0
  55. data/lib/natural_20/actions/move_action.rb +254 -0
  56. data/lib/natural_20/actions/multiattack_action.rb +41 -0
  57. data/lib/natural_20/actions/prone_action.rb +38 -0
  58. data/lib/natural_20/actions/short_rest_action.rb +53 -0
  59. data/lib/natural_20/actions/shove_action.rb +142 -0
  60. data/lib/natural_20/actions/stand_action.rb +47 -0
  61. data/lib/natural_20/actions/use_item_action.rb +57 -0
  62. data/lib/natural_20/ai_controller/path_compute.rb +140 -0
  63. data/lib/natural_20/ai_controller/standard.rb +288 -0
  64. data/lib/natural_20/battle.rb +544 -0
  65. data/lib/natural_20/battle_map.rb +843 -0
  66. data/lib/natural_20/cli/builder/fighter_builder.rb +104 -0
  67. data/lib/natural_20/cli/builder/rogue_builder.rb +62 -0
  68. data/lib/natural_20/cli/character_builder.rb +210 -0
  69. data/lib/natural_20/cli/commandline_ui.rb +612 -0
  70. data/lib/natural_20/cli/inventory_ui.rb +136 -0
  71. data/lib/natural_20/cli/map_renderer.rb +165 -0
  72. data/lib/natural_20/concerns/container.rb +32 -0
  73. data/lib/natural_20/concerns/entity.rb +1213 -0
  74. data/lib/natural_20/concerns/evaluator/entity_state_evaluator.rb +59 -0
  75. data/lib/natural_20/concerns/fighter_actions/second_wind_action.rb +51 -0
  76. data/lib/natural_20/concerns/fighter_class.rb +35 -0
  77. data/lib/natural_20/concerns/health_flavor.rb +27 -0
  78. data/lib/natural_20/concerns/lootable.rb +94 -0
  79. data/lib/natural_20/concerns/movement_helper.rb +195 -0
  80. data/lib/natural_20/concerns/multiattack.rb +54 -0
  81. data/lib/natural_20/concerns/navigation.rb +87 -0
  82. data/lib/natural_20/concerns/notable.rb +37 -0
  83. data/lib/natural_20/concerns/rogue_class.rb +26 -0
  84. data/lib/natural_20/controller.rb +11 -0
  85. data/lib/natural_20/die_roll.rb +331 -0
  86. data/lib/natural_20/event_manager.rb +288 -0
  87. data/lib/natural_20/item_library/base_item.rb +27 -0
  88. data/lib/natural_20/item_library/chest.rb +230 -0
  89. data/lib/natural_20/item_library/door_object.rb +189 -0
  90. data/lib/natural_20/item_library/ground.rb +124 -0
  91. data/lib/natural_20/item_library/healing_potion.rb +51 -0
  92. data/lib/natural_20/item_library/object.rb +153 -0
  93. data/lib/natural_20/item_library/pit_trap.rb +69 -0
  94. data/lib/natural_20/item_library/stone_wall.rb +18 -0
  95. data/lib/natural_20/npc.rb +173 -0
  96. data/lib/natural_20/player_character.rb +414 -0
  97. data/lib/natural_20/session.rb +168 -0
  98. data/lib/natural_20/utils/cover.rb +35 -0
  99. data/lib/natural_20/utils/ray_tracer.rb +90 -0
  100. data/lib/natural_20/utils/static_light_builder.rb +72 -0
  101. data/lib/natural_20/utils/weapons.rb +78 -0
  102. data/lib/natural_20/version.rb +4 -0
  103. data/locales/en.yml +304 -0
  104. data/maps/game_map.yml +168 -0
  105. data/natural_20.gemspec +46 -0
  106. data/npcs/goblin.yml +64 -0
  107. data/npcs/human_guard.yml +48 -0
  108. data/npcs/ogre.yml +61 -0
  109. data/npcs/owlbear.yml +55 -0
  110. data/npcs/wolf.yml +46 -0
  111. data/races/elf.yml +44 -0
  112. data/races/halfling.yml +22 -0
  113. data/races/human.yml +13 -0
  114. metadata +373 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5be1c9cb751acb1ca14c7fd56510c5cd3546319402847845d42340dcc56ee5c9
4
+ data.tar.gz: 6cb35a23e305f0218e21f2ad9e3b750df99436c3f8bdb9a5fa210ba1380c406a
5
+ SHA512:
6
+ metadata.gz: d84d618418d15c13d6845ce947331c0d0adf61e8be9ea8e6766da2aa239c063516c5d3871075aecfcf5099d84af8dcc1206548523ec5560c49573a30fbcef5f5
7
+ data.tar.gz: 7c7b48733c61254779b5037cd7ec95303faf4a1c1088f38ece602e4b665b31b6b98136b229387ae0bca0c315e71c35c77673a2824ecbfbd40e5d2116850d5187
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ savegame.yml
10
+ Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
14
+
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.3
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at joseph.dayo@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in natural_20.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Joseph Dayo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # Natural20
2
+
3
+ A Ruby toolkit to create your own text based DnD 5th Edition RPG games or to quickly
4
+ test drive certain creature encounters if you are a DM.
5
+
6
+ Features:
7
+ - Accurate DnD 5e ruleset implementation using the Open Game License
8
+ - Line of Sight computation with Lighting simulation (dim, dark areas)
9
+ - Simulation of doors, traps, treasure chests and cover
10
+ - Rudimentary AI and pathfinding
11
+ - Text based UI
12
+ - Easily extensible to incorporate in your own games
13
+
14
+ Supported Races:
15
+ - Human
16
+ - Elf
17
+ - Halfling
18
+ - More to come
19
+
20
+ Supported Classes;
21
+ - Fighter
22
+ - Rogue
23
+ - More to come
24
+
25
+ ## Installation
26
+
27
+ - Install ruby 2.5 or later
28
+
29
+ Add this line to your application's Gemfile if you plan to use the game engine in an adventure of your own otherwise you can just clone this repository locally using git clone:
30
+
31
+ ```ruby
32
+ gem 'natural_20'
33
+ ```
34
+
35
+ And then execute:
36
+
37
+ $ bundle install
38
+
39
+ Or install it yourself as:
40
+
41
+ $ gem install natural_20
42
+
43
+ ## Usage
44
+
45
+ To quickly try this out, clone this repository, in the working folder start the game engine it will
46
+ load the default adventure included in this repository:
47
+
48
+ ```
49
+ bin/nat20
50
+ ```
51
+
52
+ See below for a description of the adventure
53
+
54
+ ## Adventure Tutorial
55
+
56
+ The default adventure in this story is meant to showcase the game engine,
57
+ it contains a small dungeon with doors and traps as well as goblins and a dangerous owlbear.
58
+ you are to lead a party of 2 to steal the treasure behind one of those doors.
59
+
60
+ You can find the adventure specific files in the following locations:
61
+
62
+ char_classes/
63
+ characters/
64
+ items/
65
+ npcs/
66
+ races/
67
+ maps/game_map.yml
68
+ game.yml
69
+
70
+ These are all text readable for you to customize to your liking.
71
+
72
+ ## Creating your own adventures
73
+
74
+ You can generate a skeleton adventure using:
75
+
76
+ ```
77
+ nat20author
78
+ ```
79
+
80
+ A prompt based system will launch for you to create your own game.
81
+
82
+ ## Development
83
+
84
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
85
+
86
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
87
+
88
+ ## Contributing
89
+
90
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/natural_20. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/natural_20/blob/master/CODE_OF_CONDUCT.md).
91
+
92
+
93
+ ## License
94
+
95
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
96
+
97
+ ## Code of Conduct
98
+
99
+ Everyone interacting in the Natural20 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/natural_20/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "natural_20"
5
+
6
+ require 'optparse'
7
+
8
+ filename = ARGV[0]
9
+
10
+ options = {}
11
+ OptionParser.new do |opts|
12
+ opts.banner = "Usage: compute_lights battle_map.yml"
13
+
14
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
15
+ options[:verbose] = v
16
+ end
17
+ end.parse!
18
+
19
+ puts "#{filename} #{options.inspect}"
data/bin/console ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'natural_20'
5
+
6
+ require 'tty-prompt'
7
+ require 'json'
8
+ require 'pry-byebug'
9
+ require 'natural_20/cli/commandline_ui'
10
+
11
+ # You can add fixtures and/or initialization code here to make experimenting
12
+ # with your gem easier. You can also use a different console, if you like.
13
+
14
+ # (If you use this, don't forget to add pry to your Gemfile!)
15
+ # require "pry"
16
+ # Pry.start
17
+
18
+ require "irb"
19
+ IRB.start(__FILE__)
data/bin/nat20 ADDED
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'natural_20'
5
+
6
+ require 'tty-prompt'
7
+ require 'json'
8
+ require 'pry-byebug' if RUBY_ENGINE == 'ruby'
9
+ require 'natural_20/cli/commandline_ui'
10
+ require 'irb/completion'
11
+
12
+ @prompt = TTY::Prompt.new
13
+ @session = Natural20::Session.new_session
14
+
15
+ # event handlers
16
+ Natural20::EventManager.standard_cli
17
+
18
+ def t(token, options = {})
19
+ I18n.t(token, options)
20
+ end
21
+
22
+ def training_dummy
23
+ chosen_characters = @prompt.multi_select(t('select_character')) do |menu|
24
+ @session.load_characters.each do |character|
25
+ menu.choice character.name, character
26
+ end
27
+ end
28
+
29
+ map = Natural20::BattleMap.new(@session, 'maps/battle_sim')
30
+ battle = Natural20::Battle.new(@session, map)
31
+ command_line = CommandlineUI.new(battle, map)
32
+ command_line.battle_ui(chosen_characters)
33
+ end
34
+
35
+ def dice_roller
36
+ dice_roll_str = nil
37
+ loop do
38
+ dice_roll_str = @prompt.ask(t(:prompt_dice_roller))
39
+ dieRoll = Natural20::DieRoll.roll dice_roll_str
40
+ puts "#{dieRoll} = #{dieRoll.result}"
41
+ break unless dice_roll_str != 'q'
42
+ end
43
+ end
44
+
45
+ def new_game
46
+ return if @session.has_save_game? && @prompt.no?(t('save_already_present'))
47
+
48
+ controller = AiController::Standard.new
49
+ map = Natural20::BattleMap.new(@session, @session.game_properties[:starting_map])
50
+ battle = Natural20::Battle.new(@session, map, controller)
51
+ command_line = CommandlineUI.new(battle, map)
52
+
53
+ number_of_players = @session.game_properties[:players] || 1
54
+ chosen_characters = []
55
+ player_characters = @session.load_characters
56
+
57
+ number_of_players.times.each do |i|
58
+ loop do
59
+ character = @prompt.select(t('select_party_member', index: i + 1)) do |menu|
60
+ player_characters.each do |c|
61
+ next if chosen_characters.include?(c)
62
+
63
+ menu.choice "#{c.name} - #{c.description}", c
64
+ end
65
+ menu.choice t('character_builder'), :character_builder
66
+ end
67
+
68
+ if character == :character_builder
69
+ character = Natural20::CharacterBuilder.new(@prompt, @session, battle).build_character
70
+ end
71
+ chosen_characters << character
72
+ break
73
+ end
74
+ end
75
+
76
+ command_line.battle_ui(chosen_characters)
77
+ end
78
+
79
+ def continue_game
80
+ battle = @session.load_save
81
+ command_line = CommandlineUI.new(battle, battle.map)
82
+ command_line.game_loop
83
+ end
84
+
85
+ def settings
86
+ loop do
87
+ choice = @prompt.select(t('options.title')) do |menu|
88
+ menu.choice t('options.dice_roll'), 1
89
+ menu.choice t(:back)
90
+ end
91
+ case choice
92
+ when 1
93
+ result = @prompt.select(t('options.dice_roll')) do |q|
94
+ q.default @session.setting(:manual_dice_roll) ? 1 : 2
95
+ q.choice t('options.roll_dice_manually'), 1
96
+ q.choice t('options.automatic_roll'), 2
97
+ end
98
+ @session.update_settings(manual_dice_roll: result == 1)
99
+ else
100
+ break
101
+ end
102
+ end
103
+ end
104
+
105
+ def start
106
+ loop do
107
+ CommandlineUI.clear_screen
108
+ title_color = @session.game_properties.fetch(:title_color, :white).to_sym
109
+ @session.game_properties[:title]&.each do |title_line|
110
+ puts title_line&.colorize(title_color)
111
+ end
112
+ puts t('game_author', author: @session.game_properties[:author]) if @session.game_properties[:author]
113
+ puts ""
114
+ answer = @prompt.select(@session.game_properties[:description] || '') do |menu|
115
+ menu.choice 'New Adventure ...', 1
116
+ menu.choice 'Continue Game ...', 2 if @session.has_save_game?
117
+ menu.choice 'Settings', 3
118
+ menu.choice t(:exit), 4
119
+ end
120
+ case answer
121
+ when 4
122
+ exit(0)
123
+ when 3
124
+ settings
125
+ when 2
126
+ continue_game
127
+ when 1
128
+ new_game
129
+ else
130
+ break
131
+ end
132
+ end
133
+ end
134
+
135
+ start
data/bin/nat20.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+ bundle install
3
+ ruby bin\nat20
data/bin/nat20author ADDED
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'natural_20'
5
+
6
+ require 'tty-prompt'
7
+ require 'json'
8
+ require 'pry-byebug' if RUBY_ENGINE == 'ruby'
9
+ require 'natural_20/cli/commandline_ui'
10
+ require 'irb/completion'
11
+
12
+ @prompt = TTY::Prompt.new
13
+
14
+ game = {
15
+ starting_map: 'maps/game_map',
16
+ player_profiles: 'characters'
17
+ }
18
+
19
+ @prompt.say('This is the nat20 game authoring tool')
20
+ game[:name] = @prompt.ask('Enter a name for this game')
21
+ game[:title] = @prompt.multiline('Enter a banner title for this game')
22
+
23
+ game_map = {
24
+ name: game[:name],
25
+ description: "Map for #{game[:name]}",
26
+ map: {
27
+ illumination: 1.0,
28
+ base: [],
29
+ },
30
+ legend: {
31
+ g: {
32
+ name: 'Stivnux',
33
+ type: 'npc',
34
+ sub_type: 'goblin'
35
+ }
36
+ }
37
+
38
+ }
39
+
40
+ game[:description] = @prompt.ask('Enter a description for this game')
41
+ game[:players] = @prompt.ask('Enter number of party members (1-4)') do |q|
42
+ q.in('1-4')
43
+ end.to_i
44
+
45
+ spawn_locations = []
46
+
47
+ game[:players].times do |i|
48
+ game_map[:legend]["#{i + 1}".to_s] = {
49
+ name: "spawn_point_#{i + 1}",
50
+ type: 'spawn_point'
51
+ }
52
+ spawn_locations << [i, 0]
53
+ end
54
+
55
+ width = @prompt.ask('Enter map width') do |q|
56
+ q.in('8-30')
57
+ end.to_i
58
+
59
+ height = @prompt.ask('Enter map height') do |q|
60
+ q.in('8-30')
61
+ end.to_i
62
+
63
+ npc_location = [width / 2, height / 2]
64
+
65
+ game_map[:map][:meta] = height.times.map do |row|
66
+ width.times.map do |col|
67
+ if npc_location == [col, row]
68
+ 'g'
69
+ elsif spawn_locations.include?([col, row])
70
+ col + 1
71
+ else
72
+ '.'
73
+ end
74
+ end.join
75
+ end
76
+
77
+ game_map[:map][:base] = height.times.map do
78
+ width.times.map { '.' }.join
79
+ end
80
+
81
+ templates_root = File.expand_path(File.join(__dir__, '..'))
82
+
83
+ game_root_folder = game[:name]
84
+
85
+ raise "folder #{game_root_folder} already exists" if File.exist?(game_root_folder)
86
+
87
+ puts 'writing out generated files'
88
+
89
+ FileUtils.mkdir_p(game_root_folder)
90
+ FileUtils.mkdir_p(File.join(game_root_folder, 'maps'))
91
+
92
+ %w[char_classes characters items npcs races locales].each do |asset|
93
+ puts "copy #{File.join(templates_root, asset)} to #{File.join(game_root_folder, asset)}"
94
+ FileUtils.cp_r(File.join(templates_root, asset), File.join(game_root_folder, asset))
95
+ end
96
+
97
+ File.write(File.join(game_root_folder, 'game.yml'), game.to_yaml)
98
+ File.write(File.join(game_root_folder, 'maps', 'game_map.yml'), game_map.to_yaml)
99
+ FileUtils.cp_r(File.join(templates_root, 'maps', 'game_map.yml'),
100
+ File.join(game_root_folder, 'maps', 'sample_game_map.yml'))
101
+
102
+ puts "written #{File.join(game_root_folder, 'game.yml')}"
103
+
104
+ @prompt.keypress("Game generated, to run the game go to the '#{game_root_folder}' folder and type: nat20")