gemwarrior 0.8.2 → 0.8.3
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/bin/gemwarrior +0 -0
- data/data/fantasy_names.yml +4223 -0
- data/gemwarrior.gemspec +1 -1
- data/lib/gemwarrior/entities/player.rb +24 -33
- data/lib/gemwarrior/game.rb +2 -1
- data/lib/gemwarrior/misc/name_generator.rb +168 -0
- data/lib/gemwarrior/misc/wordlist.rb +1 -1
- data/lib/gemwarrior/{misc/version.rb → version.rb} +1 -1
- metadata +7 -7
data/gemwarrior.gemspec
CHANGED
|
@@ -3,33 +3,25 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative 'creature'
|
|
5
5
|
require_relative '../battle'
|
|
6
|
+
require_relative '../misc/name_generator'
|
|
6
7
|
require_relative '../misc/player_levels'
|
|
7
8
|
require_relative '../misc/wordlist'
|
|
8
9
|
|
|
9
10
|
module Gemwarrior
|
|
10
11
|
class Player < Creature
|
|
11
12
|
include PlayerLevels
|
|
12
|
-
|
|
13
|
-
# CONSTANTS
|
|
14
|
-
## CHARACTER ATTRIBUTES
|
|
15
|
-
CHAR_UPPER_POOL = (65..90).map{ |i| i.chr }
|
|
16
|
-
CHAR_LOWER_POOL = (97..122).map{ |i| i.chr }
|
|
17
|
-
CHAR_LOWER_VOWEL_POOL = ['a','e','i','o','u','y']
|
|
18
|
-
|
|
19
|
-
FACE_DESC = ['smooth', 'tired', 'ruddy', 'moist', 'shocked', 'handsome', '5 o\'clock-shadowed']
|
|
20
|
-
HANDS_DESC = ['worn', 'balled into fists', 'relaxed', 'cracked', 'tingly', 'mom\'s spaghetti']
|
|
21
|
-
MOOD_DESC = ['calm', 'excited', 'depressed', 'tense', 'lackadaisical', 'angry', 'positive']
|
|
22
|
-
|
|
13
|
+
|
|
23
14
|
attr_accessor :stam_cur, :stam_max, :cur_coords,
|
|
24
|
-
:god_mode, :beast_mode
|
|
25
|
-
|
|
15
|
+
:god_mode, :beast_mode, :use_wordnik
|
|
16
|
+
|
|
26
17
|
def initialize(options)
|
|
27
18
|
self.name = generate_name
|
|
28
19
|
self.description = options.fetch(:description)
|
|
20
|
+
self.use_wordnik = options.fetch(:use_wordnik)
|
|
29
21
|
|
|
30
|
-
self.face = generate_face
|
|
31
|
-
self.hands = generate_hands
|
|
32
|
-
self.mood = generate_mood
|
|
22
|
+
self.face = generate_face(use_wordnik)
|
|
23
|
+
self.hands = generate_hands(use_wordnik)
|
|
24
|
+
self.mood = generate_mood(use_wordnik)
|
|
33
25
|
|
|
34
26
|
self.level = options.fetch(:level)
|
|
35
27
|
self.xp = options.fetch(:xp)
|
|
@@ -49,7 +41,7 @@ module Gemwarrior
|
|
|
49
41
|
self.cur_coords = options.fetch(:cur_coords)
|
|
50
42
|
|
|
51
43
|
self.god_mode = options.fetch(:god_mode)
|
|
52
|
-
self.beast_mode = options.fetch(:beast_mode)
|
|
44
|
+
self.beast_mode = options.fetch(:beast_mode)
|
|
53
45
|
end
|
|
54
46
|
|
|
55
47
|
def check_self(debug_mode = false, show_pic = true)
|
|
@@ -125,8 +117,12 @@ module Gemwarrior
|
|
|
125
117
|
|
|
126
118
|
def modify_name
|
|
127
119
|
print "Enter new name: "
|
|
120
|
+
|
|
128
121
|
new_name = gets.chomp!
|
|
129
|
-
|
|
122
|
+
|
|
123
|
+
if new_name.length <= 0
|
|
124
|
+
return "You continue on as #{name}."
|
|
125
|
+
elsif new_name.length < 3 || new_name.length > 10
|
|
130
126
|
return "'#{new_name}' is an invalid length. Make it between 3 and 10 characters, please."
|
|
131
127
|
else
|
|
132
128
|
name_to_add = ""
|
|
@@ -135,7 +131,6 @@ module Gemwarrior
|
|
|
135
131
|
self.name = name_to_add
|
|
136
132
|
return "New name, '#{name}', accepted."
|
|
137
133
|
end
|
|
138
|
-
return nil
|
|
139
134
|
end
|
|
140
135
|
|
|
141
136
|
def list_inventory
|
|
@@ -245,26 +240,22 @@ module Gemwarrior
|
|
|
245
240
|
|
|
246
241
|
# INIT
|
|
247
242
|
def generate_name
|
|
248
|
-
|
|
249
|
-
letter_max = rand(5..10)
|
|
250
|
-
default_name[0] = CHAR_UPPER_POOL[rand(0..25)]
|
|
251
|
-
default_name[1] = CHAR_LOWER_VOWEL_POOL[rand(0..5)]
|
|
252
|
-
2.upto(letter_max) do |i|
|
|
253
|
-
default_name[i] = CHAR_LOWER_POOL[rand(0..25)]
|
|
254
|
-
end
|
|
255
|
-
return default_name.join
|
|
243
|
+
NameGenerator.new('fantasy').generate_name
|
|
256
244
|
end
|
|
257
245
|
|
|
258
|
-
def generate_face
|
|
259
|
-
|
|
246
|
+
def generate_face(use_wordnik)
|
|
247
|
+
face_descriptors = WordList.new(use_wordnik, 'adjective')
|
|
248
|
+
face_descriptors.get_random_value
|
|
260
249
|
end
|
|
261
250
|
|
|
262
|
-
def generate_hands
|
|
263
|
-
|
|
251
|
+
def generate_hands(use_wordnik)
|
|
252
|
+
hand_descriptors = WordList.new(use_wordnik, 'adjective')
|
|
253
|
+
hand_descriptors.get_random_value
|
|
264
254
|
end
|
|
265
255
|
|
|
266
|
-
def generate_mood
|
|
267
|
-
|
|
256
|
+
def generate_mood(use_wordnik)
|
|
257
|
+
mood_descriptors = WordList.new(use_wordnik, 'adjective')
|
|
258
|
+
mood_descriptors.get_random_value
|
|
268
259
|
end
|
|
269
260
|
end
|
|
270
261
|
end
|
data/lib/gemwarrior/game.rb
CHANGED
|
@@ -53,7 +53,8 @@ module Gemwarrior
|
|
|
53
53
|
:cur_coords => world.location_coords_by_name('Home'),
|
|
54
54
|
|
|
55
55
|
:god_mode => options.fetch(:god_mode),
|
|
56
|
-
:beast_mode => options.fetch(:beast_mode)
|
|
56
|
+
:beast_mode => options.fetch(:beast_mode),
|
|
57
|
+
:use_wordnik => options.fetch(:use_wordnik)
|
|
57
58
|
})
|
|
58
59
|
|
|
59
60
|
# create the console
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# lib/gemwarrior/misc/name_generator.rb
|
|
2
|
+
# NameGenerator Ruby class (translated from name_generator.js)
|
|
3
|
+
# written and released to the public domain by drow <drow@bin.sh>
|
|
4
|
+
# http://creativecommons.org/publicdomain/zero/1.0/
|
|
5
|
+
|
|
6
|
+
require 'yaml'
|
|
7
|
+
|
|
8
|
+
class NameGenerator
|
|
9
|
+
attr_accessor :name_set, :type, :chain_cache
|
|
10
|
+
|
|
11
|
+
def initialize(type)
|
|
12
|
+
self.type = type
|
|
13
|
+
self.name_set = get_name_set(self.type)
|
|
14
|
+
self.chain_cache = {}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# load sample names
|
|
18
|
+
def get_name_set(type)
|
|
19
|
+
names = []
|
|
20
|
+
names_data = YAML.load_file("data/#{type}_names.yml")
|
|
21
|
+
names_data.each do |n|
|
|
22
|
+
names.push(n)
|
|
23
|
+
end
|
|
24
|
+
return names
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# generator function
|
|
28
|
+
def generate_name
|
|
29
|
+
chain = nil
|
|
30
|
+
|
|
31
|
+
if (chain = markov_chain(self.type))
|
|
32
|
+
return markov_name(chain)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
return ''
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# generate multiple
|
|
39
|
+
def generate_names(count = 1)
|
|
40
|
+
list = []
|
|
41
|
+
|
|
42
|
+
for i in 1..count
|
|
43
|
+
list.push(generate_name)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
return list
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# get markov chain by type
|
|
50
|
+
def markov_chain(type)
|
|
51
|
+
chain = nil
|
|
52
|
+
|
|
53
|
+
if (chain = chain_cache[type])
|
|
54
|
+
return chain
|
|
55
|
+
else
|
|
56
|
+
if (list = name_set)
|
|
57
|
+
chain = nil
|
|
58
|
+
if (chain = construct_chain(list))
|
|
59
|
+
chain_cache[type] = chain
|
|
60
|
+
return chain
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
return false
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# construct markov chain from list of names
|
|
69
|
+
def construct_chain(list)
|
|
70
|
+
chain = {}
|
|
71
|
+
|
|
72
|
+
for i in 0..list.length-1
|
|
73
|
+
names = list[i].split(/\s+/)
|
|
74
|
+
chain = incr_chain(chain, 'parts', names.length)
|
|
75
|
+
|
|
76
|
+
for j in 0..names.length-1
|
|
77
|
+
name = names[j].nil? ? [] : names[j]
|
|
78
|
+
chain = incr_chain(chain, 'name_len', name.length)
|
|
79
|
+
|
|
80
|
+
c = name[0, 1]
|
|
81
|
+
chain = incr_chain(chain, 'initial', c)
|
|
82
|
+
|
|
83
|
+
string = name[1..name.length]
|
|
84
|
+
last_c = c
|
|
85
|
+
|
|
86
|
+
while string.length > 0 do
|
|
87
|
+
c = string[0, 1]
|
|
88
|
+
chain = incr_chain(chain, last_c, c)
|
|
89
|
+
|
|
90
|
+
string = string[1..string.length]
|
|
91
|
+
last_c = c
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
return scale_chain(chain)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def incr_chain(chain, key, token)
|
|
100
|
+
if chain[key]
|
|
101
|
+
if chain[key][token]
|
|
102
|
+
chain[key][token] += 1
|
|
103
|
+
else
|
|
104
|
+
chain[key][token] = 1
|
|
105
|
+
end
|
|
106
|
+
else
|
|
107
|
+
chain[key] = {}
|
|
108
|
+
chain[key][token] = 1
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
return chain
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def scale_chain(chain)
|
|
115
|
+
table_len = {}
|
|
116
|
+
|
|
117
|
+
chain.each do |key, subkey|
|
|
118
|
+
table_len[key] = 0
|
|
119
|
+
|
|
120
|
+
subkey.each do |subkey, value|
|
|
121
|
+
count = value
|
|
122
|
+
weighted = (count ** 1.3).floor
|
|
123
|
+
|
|
124
|
+
chain[key][subkey] = weighted
|
|
125
|
+
table_len[key] += weighted
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
chain['table_len'] = table_len
|
|
130
|
+
|
|
131
|
+
return chain
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# construct name from markov chain
|
|
135
|
+
def markov_name(chain)
|
|
136
|
+
parts = select_link(chain, 'parts')
|
|
137
|
+
names = []
|
|
138
|
+
|
|
139
|
+
for i in 0..parts-1
|
|
140
|
+
name_len = select_link(chain, 'name_len')
|
|
141
|
+
c = select_link(chain, 'initial')
|
|
142
|
+
name = c
|
|
143
|
+
last_c = c
|
|
144
|
+
|
|
145
|
+
while name.length < name_len do
|
|
146
|
+
c = select_link(chain, last_c)
|
|
147
|
+
name += c
|
|
148
|
+
last_c = c
|
|
149
|
+
end
|
|
150
|
+
names.push(name)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
return names.join(' ')
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def select_link(chain, key)
|
|
157
|
+
len = chain['table_len'][key]
|
|
158
|
+
idx = (rand() * len).floor
|
|
159
|
+
|
|
160
|
+
t = 0
|
|
161
|
+
chain[key].each do |chain_key, chain_value|
|
|
162
|
+
t += chain_value
|
|
163
|
+
return chain_key if (idx < t)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
return '-'
|
|
167
|
+
end
|
|
168
|
+
end
|
|
@@ -6,7 +6,7 @@ require 'json'
|
|
|
6
6
|
|
|
7
7
|
module Gemwarrior
|
|
8
8
|
class WordList
|
|
9
|
-
|
|
9
|
+
STATIC_ADJECTIVE_VALUES = [
|
|
10
10
|
'5 o\'clock-shadowed', 'angry', 'aristocratic', 'calm', 'choice', 'clinical', 'cracked', 'depressed', 'dingy', 'excited', 'ginormous', 'handsome', 'hydrothermal', 'lackadaisical', 'man-sized', 'moist', 'non-venomous', 'picaresque', 'positive', 'relaxed', 'ruddy', 'smooth', 'shocked', 'sticky', 'tense', 'tingly', 'tired', 'toneless', 'unpolished', 'worn'
|
|
11
11
|
]
|
|
12
12
|
STATIC_NOUN_VALUES = [
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gemwarrior
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Chadwick
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-06-
|
|
11
|
+
date: 2015-06-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: os
|
|
@@ -185,6 +185,7 @@ files:
|
|
|
185
185
|
- README.md
|
|
186
186
|
- Rakefile
|
|
187
187
|
- bin/gemwarrior
|
|
188
|
+
- data/fantasy_names.yml
|
|
188
189
|
- data/locations.yml
|
|
189
190
|
- gemwarrior.gemspec
|
|
190
191
|
- lib/gemwarrior/arena.rb
|
|
@@ -241,10 +242,11 @@ files:
|
|
|
241
242
|
- lib/gemwarrior/inventory.rb
|
|
242
243
|
- lib/gemwarrior/misc/animation.rb
|
|
243
244
|
- lib/gemwarrior/misc/music.rb
|
|
245
|
+
- lib/gemwarrior/misc/name_generator.rb
|
|
244
246
|
- lib/gemwarrior/misc/player_levels.rb
|
|
245
|
-
- lib/gemwarrior/misc/version.rb
|
|
246
247
|
- lib/gemwarrior/misc/wordlist.rb
|
|
247
248
|
- lib/gemwarrior/repl.rb
|
|
249
|
+
- lib/gemwarrior/version.rb
|
|
248
250
|
- lib/gemwarrior/world.rb
|
|
249
251
|
- spec/rubywarrior_spec.rb
|
|
250
252
|
- spec/spec_helper.rb
|
|
@@ -268,10 +270,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
268
270
|
version: '0'
|
|
269
271
|
requirements: []
|
|
270
272
|
rubyforge_project:
|
|
271
|
-
rubygems_version: 2.4.
|
|
273
|
+
rubygems_version: 2.4.6
|
|
272
274
|
signing_key:
|
|
273
275
|
specification_version: 4
|
|
274
276
|
summary: RPG as RubyGem
|
|
275
|
-
test_files:
|
|
276
|
-
- spec/rubywarrior_spec.rb
|
|
277
|
-
- spec/spec_helper.rb
|
|
277
|
+
test_files: []
|