rpg-tools 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/.yardopts +3 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +20 -0
- data/README.textile +28 -0
- data/Rakefile +27 -0
- data/app/models/tools/check_roll.rb +82 -0
- data/app/models/tools/die.rb +35 -0
- data/app/models/tools/throw.rb +71 -0
- data/config/locales/en.yml +11 -0
- data/lib/generators/rpg_tools/install_generator.rb +21 -0
- data/lib/generators/rpg_tools/templates/initializer.rb +3 -0
- data/lib/rpg_tools.rb +11 -0
- data/lib/rpg_tools/engine.rb +11 -0
- data/rpg_tools.gemspec +30 -0
- data/spec/dummy/Gemfile +6 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +60 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +191 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/public/stylesheets/scaffold.css +56 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/models/tools/check_roll_spec.rb +116 -0
- data/spec/models/tools/die_spec.rb +29 -0
- data/spec/models/tools/throw_spec.rb +55 -0
- data/spec/rpg_tools_spec.rb +7 -0
- data/spec/spec_helper.rb +36 -0
- metadata +216 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Eduardo Casanova Cuesta
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
h1. RPG Tools
|
2
|
+
|
3
|
+
#TODO
|
4
|
+
|
5
|
+
h2. Installation
|
6
|
+
|
7
|
+
Add to your Gemfile:
|
8
|
+
<pre><code>
|
9
|
+
gem 'rpg_tools'
|
10
|
+
</code></pre>
|
11
|
+
Then run:
|
12
|
+
<pre><code>
|
13
|
+
bundle update
|
14
|
+
</code></pre>
|
15
|
+
|
16
|
+
h2. Using RPG Tools. API
|
17
|
+
|
18
|
+
#TODO
|
19
|
+
|
20
|
+
h2. License
|
21
|
+
|
22
|
+
Copyright (c) 2011 Eduardo Casanova Cuesta
|
23
|
+
|
24
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
25
|
+
|
26
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
27
|
+
|
28
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'bundler'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
require 'rake'
|
9
|
+
require 'rake/rdoctask'
|
10
|
+
|
11
|
+
require 'rspec/core'
|
12
|
+
require 'rspec/core/rake_task'
|
13
|
+
|
14
|
+
RSpec::Core::RakeTask.new(:spec)
|
15
|
+
|
16
|
+
task :default => :spec
|
17
|
+
|
18
|
+
Rake::RDocTask.new do |rdoc|
|
19
|
+
rdoc.rdoc_dir = 'rdoc'
|
20
|
+
rdoc.title = "Fuzion RPG"
|
21
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
22
|
+
rdoc.rdoc_files.include('README.rdoc')
|
23
|
+
rdoc.rdoc_files.include('lib/**/*.rb', 'app/**/*.rb')
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1,82 @@
|
|
1
|
+
class Tools::CheckRoll
|
2
|
+
|
3
|
+
attr_accessor :throw, :threshold, :rolling_chances, :greater_than_threshold, :equal_than_threshold
|
4
|
+
attr_reader :result
|
5
|
+
def initialize throw, threshold, rolling_chances=1, greater_than_threshold=true, equal_than_threshold=true
|
6
|
+
@throw = throw
|
7
|
+
@threshold = threshold
|
8
|
+
@rolling_chances = rolling_chances
|
9
|
+
@greater_than_threshold = greater_than_threshold
|
10
|
+
@equal_than_threshold = equal_than_threshold
|
11
|
+
end
|
12
|
+
|
13
|
+
#[true/false,best_rolled]
|
14
|
+
def roll
|
15
|
+
return @result if @result
|
16
|
+
best_rolled = 0
|
17
|
+
@rolling_chances.times do
|
18
|
+
rolled_throw = @throw.roll 1,true #Detailed throw
|
19
|
+
best_rolled = rolled_throw if rolled_throw[0] > best_rolled[0]
|
20
|
+
end
|
21
|
+
@result = [compare(best_rolled[0], @threshold),best_rolled]
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
def reroll
|
26
|
+
@result = nil
|
27
|
+
roll
|
28
|
+
end
|
29
|
+
|
30
|
+
def is_successful?
|
31
|
+
roll if @result.blank?
|
32
|
+
return @result[0]
|
33
|
+
end
|
34
|
+
|
35
|
+
def result
|
36
|
+
[@result[0],@result[1][0]]
|
37
|
+
end
|
38
|
+
|
39
|
+
def detailed_result
|
40
|
+
@result
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_s
|
44
|
+
string = "#{@throw.to_s} #{I18n.t('rpg_tools.check_roll.must_be')} #{comparatives_text} #{@threshold}."
|
45
|
+
if @result
|
46
|
+
string << " #{I18n.t('rpg_tools.check_roll.already_checked')}"
|
47
|
+
string << " #{@result[0] ? I18n.t('rpg_tools.check_roll.success') : I18n.t('rpg_tools.check_roll.failure')}"
|
48
|
+
string << " (#{@result[1][0]})."
|
49
|
+
end
|
50
|
+
string
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def compare rolled_throw, threshold
|
56
|
+
gtt = @greater_than_threshold
|
57
|
+
ett = @equal_than_threshold
|
58
|
+
if gtt and ett
|
59
|
+
return rolled_throw >= threshold
|
60
|
+
elsif gtt and !ett
|
61
|
+
return rolled_throw > threshold
|
62
|
+
elsif !gtt and !ett
|
63
|
+
return rolled_throw < threshold
|
64
|
+
elsif !gtt and ett
|
65
|
+
return rolled_throw <= threshold
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def comparatives_text
|
70
|
+
gtt = @greater_than_threshold
|
71
|
+
ett = @equal_than_threshold
|
72
|
+
if gtt and ett
|
73
|
+
return I18n.t 'rpg_tools.check_roll.greater_and_equal'
|
74
|
+
elsif gtt and !ett
|
75
|
+
return I18n.t 'rpg_tools.check_roll.greater'
|
76
|
+
elsif !gtt and !ett
|
77
|
+
return I18n.t 'rpg_tools.check_roll.less'
|
78
|
+
elsif !gtt and ett
|
79
|
+
return I18n.t 'rpg_tools.check_roll.less_and_equal'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Tools::Die
|
2
|
+
attr_accessor :sides
|
3
|
+
|
4
|
+
def initialize sides=20
|
5
|
+
@sides = sides
|
6
|
+
end
|
7
|
+
|
8
|
+
# Rolls the die and returns result as +Fixnum+ if rolls==1 or as +Array+ of +Fixnum+
|
9
|
+
# if rolls>1.
|
10
|
+
def roll rolls=1
|
11
|
+
return simple_roll if rolls==1
|
12
|
+
results = Array.new
|
13
|
+
rolls.times do
|
14
|
+
results << simple_roll
|
15
|
+
end
|
16
|
+
return results
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns the die as a string with the format Dx, where x is the number of sides. Example "D6", "D20", "D100", etc.
|
20
|
+
def to_s
|
21
|
+
return "D#{@sides}"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Return true if the dice are equal, i.e. they have the same number of sides.
|
25
|
+
def eql? die
|
26
|
+
return false if die==nil or die.sides!=@sides
|
27
|
+
return true
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def simple_roll
|
33
|
+
1 + rand(sides)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class Tools::Throw
|
2
|
+
attr_accessor :dice, :offset
|
3
|
+
|
4
|
+
def initialize dice, offset=0
|
5
|
+
@dice = dice.sort_by{|die| die.sides}
|
6
|
+
@offset = offset
|
7
|
+
end
|
8
|
+
|
9
|
+
# Rolls the dice, add the offset and returns result as +Fixnum+ if rolls==1 or as
|
10
|
+
# +Array+ of +Fixnum+ if rolls>1.
|
11
|
+
def roll rolls=1, detailed=false
|
12
|
+
return simple_roll if rolls==1 and !detailed
|
13
|
+
return detailed_roll if rolls==1 and detailed
|
14
|
+
results = Array.new
|
15
|
+
rolls.times do
|
16
|
+
results << simple_roll if !detailed
|
17
|
+
results << detailed_roll if detailed
|
18
|
+
end
|
19
|
+
return results
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns the dice as a string with the format aDx,bDy,cDz+n, where a,b,c are the number of dice,
|
23
|
+
# x,y,z are the number of sides and n the offset. Example "D6,D20,D100+8", etc.
|
24
|
+
def to_s
|
25
|
+
throw_dice_number = Array.new
|
26
|
+
throw_dice = Array.new
|
27
|
+
temp_dice = dice.sort_by{|die| die.sides}
|
28
|
+
last_die = nil
|
29
|
+
temp_dice.each do |temp_die|
|
30
|
+
if !temp_die.eql? last_die
|
31
|
+
last_die = temp_die
|
32
|
+
throw_dice << temp_die
|
33
|
+
throw_dice_number << temp_dice.count{|die| die.eql? temp_die}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
throw_string = ""
|
37
|
+
throw_dice.each_index do |i|
|
38
|
+
throw_string << "," if i>0
|
39
|
+
throw_string << throw_dice_number[i].to_s + throw_dice[i].to_s
|
40
|
+
end
|
41
|
+
throw_string << "+" if @offset>0
|
42
|
+
throw_string << "#{@offset}" if @offset!=0
|
43
|
+
return throw_string
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def simple_roll
|
49
|
+
total = 0
|
50
|
+
dice.each do |die|
|
51
|
+
total+= die.roll
|
52
|
+
end
|
53
|
+
total += offset
|
54
|
+
return total
|
55
|
+
end
|
56
|
+
|
57
|
+
def detailed_roll
|
58
|
+
results = Array.new
|
59
|
+
total = 0
|
60
|
+
dice.each do |die|
|
61
|
+
roll = die.roll
|
62
|
+
total+= roll
|
63
|
+
results << roll
|
64
|
+
end
|
65
|
+
total += offset
|
66
|
+
detailed_throw = Array.new
|
67
|
+
detailed_throw[0] = total
|
68
|
+
detailed_throw[1] = results
|
69
|
+
return detailed_throw
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
en:
|
2
|
+
rpg_tools:
|
3
|
+
check_roll:
|
4
|
+
already_checked: "Has already been rolled with"
|
5
|
+
failure: "failure"
|
6
|
+
greater: "greater than"
|
7
|
+
greater_and_equal: "greater or equal to"
|
8
|
+
less: "less than"
|
9
|
+
less_and_equal: "less or equal to"
|
10
|
+
must_be: "must be"
|
11
|
+
success: "succes"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class RPG_Tools::InstallGenerator < Rails::Generators::Base #:nodoc:
|
2
|
+
include Rails::Generators::Migration
|
3
|
+
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
require 'rails/generators/active_record'
|
7
|
+
|
8
|
+
def self.next_migration_number(dirname)
|
9
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_initializer_file
|
13
|
+
template 'initializer.rb', 'config/initializers/rpg_tools.rb'
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_migration_file
|
17
|
+
require 'rake'
|
18
|
+
Rails.application.load_tasks
|
19
|
+
Rake::Task['rpg_tools_engine:install:migrations'].invoke
|
20
|
+
end
|
21
|
+
end
|
data/lib/rpg_tools.rb
ADDED
data/rpg_tools.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "rpg-tools"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.authors = ["Eduardo Casanova Cuesta"]
|
5
|
+
s.summary = "Some tools useful when creating a RPG: Die, Throw and CheckRoll."
|
6
|
+
s.description = "Some tools useful when creating a RPG: Die, Throw and CheckRoll."
|
7
|
+
s.email = "ecasanovac@gmail.com"
|
8
|
+
s.homepage = "https://github.com/roendal/rpg-tools"
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
|
11
|
+
# Gem dependencies
|
12
|
+
#
|
13
|
+
s.add_runtime_dependency('rails', '~> 3.0.0')
|
14
|
+
|
15
|
+
# Development Gem dependencies
|
16
|
+
#
|
17
|
+
# Testing database
|
18
|
+
s.add_development_dependency('sqlite3-ruby')
|
19
|
+
# Debugging
|
20
|
+
if RUBY_VERSION < '1.9'
|
21
|
+
s.add_development_dependency('ruby-debug', '~> 0.10.3')
|
22
|
+
end
|
23
|
+
# Specs
|
24
|
+
s.add_development_dependency('rspec-rails', '~> 2.6.1')
|
25
|
+
# Fixtures
|
26
|
+
s.add_development_dependency('factory_girl', '~> 1.3.2')
|
27
|
+
# Integration testing
|
28
|
+
s.add_development_dependency('capybara', '~> 1.0.1')
|
29
|
+
end
|
30
|
+
|
data/spec/dummy/Gemfile
ADDED
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|