Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: sakomoko/Eretheal
base: ac6176fd51
...
head fork: sakomoko/Eretheal
compare: eb21616afd
Checking mergeability… Don't worry, you can still create the pull request.
  • 9 commits
  • 25 files changed
  • 0 commit comments
  • 1 contributor
View
1  Gemfile
@@ -6,6 +6,7 @@ gem 'rails', '~> 3.2'
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem "mongoid", "~> 3"
+gem "mongoid_slug"
gem "haml-rails"
gem 'devise'
gem 'mongoid-tree', :require => 'mongoid/tree'
View
5 Gemfile.lock
@@ -126,6 +126,9 @@ GEM
rspec (>= 2.9)
mongoid-tree (1.0.1)
mongoid (>= 3.0, <= 4.0)
+ mongoid_slug (2.0.1)
+ mongoid (~> 3.0)
+ stringex (~> 1.4)
moped (1.3.2)
multi_json (1.5.0)
named_let (0.1.3)
@@ -216,6 +219,7 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
+ stringex (1.5.1)
thin (1.5.0)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
@@ -257,6 +261,7 @@ DEPENDENCIES
mongoid (~> 3)
mongoid-rspec
mongoid-tree
+ mongoid_slug
named_let
rails (~> 3.2)
rails_admin
View
7 app/lib/eretheal/combat_actor.rb
@@ -5,8 +5,7 @@ module CombatActor
attr_reader :action
attr_accessor :formula
- def initialize
- super
+ def set_up
@formula = Eretheal::Formula.new
end
@@ -54,7 +53,9 @@ def action=(action)
bonus = 0
if self.respond_to? :equip
self.equip.each do |key, b|
- bonus += b.item.send("add_" << status)
+ if b.item.status_adjustment
+ bonus += b.item.status_adjustment.send(status)
+ end
end
end
self.send(status) + bonus
View
1  app/lib/eretheal/formula.rb
@@ -14,6 +14,7 @@ class Formula
end
def speed(parameter)
+ return 1 if parameter < 1
((parameter + (10 / parameter)) * 0.4).to_i
end
View
3  app/models/attribute.rb
@@ -1,7 +1,8 @@
class Attribute
include Mongoid::Document
+ include Mongoid::Slug
field :name, :type => String
field :key, :type => String
- has_many :item_types
+ slug :key
end
View
6 app/models/character.rb
@@ -9,10 +9,10 @@ class Character
has_and_belongs_to_many :skills, index: true
before_create :set_default_documents
+ after_initialize :set_up
- embeds_one :candy
-
- embeds_one :equip
+ embeds_one :candy, autobuild: true
+ embeds_one :equip, autobuild: true
embeds_one :position
embeds_many :assigned_skills
View
2  app/models/enemy.rb
@@ -38,4 +38,6 @@ class Enemy
attr_accessor :level
+ after_initialize :set_up
+
end
View
10 app/models/equip_category.rb
@@ -0,0 +1,10 @@
+class EquipCategory
+ include Mongoid::Document
+ include Mongoid::Slug
+
+ field :key, type: String
+ field :name, type: String
+ field :equip, type: Boolean, default: 1
+
+ slug :key
+end
View
10 app/models/inventory_item.rb
@@ -13,8 +13,8 @@ class InventoryItem
field :sort, :type => Integer, :default => 0
def equip
- return false unless self.item.item_type.equip?
- category = self.item.item_type.category
+ return false unless self.item.item_type.equip_category.equip?
+ category = self.item.item_type.equip_category.key
if category == 'weapon' && self.item.two_handed?
self.character.equip.shield = nil
elsif category == 'shield' && self.character.equip.weapon && self.character.equip.weapon.item.two_handed?
@@ -25,8 +25,8 @@ def equip
end
def unequip
- return false if !self.item.item_type.equip? || !self.equipping?
- category = self.item.item_type.category
+ return false if !self.item.item_type.equip_category.equip? || !self.equipping?
+ category = self.item.item_type.equip_category.key
self.character.equip.send category + '=', nil
self.character.unmemoize_all
true
@@ -44,7 +44,7 @@ def remove(num = 1)
def equipping?
equip = self.character.equip
- category = self.item.item_type.category
+ category = self.item.item_type.equip_category.key
if equip.respond_to? category
equipping = equip.send(category)
return true if equipping && equipping.id == self.id
View
20 app/models/item.rb
@@ -1,29 +1,18 @@
class Item
include Mongoid::Document
include Mongoid::Paranoia
- include Mongoid::Timestamps
belongs_to :item_type
+ embeds_one :status_adjustment
+ embeds_one :status_coefficient
+
+ accepts_nested_attributes_for :status_adjustment, :status_coefficient
field :name, :type => String
field :power, :type => Integer, :default => 0
field :speed, :type => Integer, :default => 0
field :weight, :type => Integer, :default => 0
field :color, :type => String
- field :hit, :type => Integer, :default => 0
- field :avoid, :type => Integer, :default => 0
- field :magi, :type => Integer, :default => 0
- field :magi_def, :type => Integer, :default => 0
-
- field :add_dex, :type => Integer, :default => 0
- field :add_agi, :type => Integer, :default => 0
- field :add_vit, :type => Integer, :default => 0
- field :add_str, :type => Integer, :default => 0
- field :add_int, :type => Integer, :default => 0
- field :add_mnd, :type => Integer, :default => 0
-
- field :add_hp, :type => Integer, :default => 0
- field :add_hp, :type => Integer, :default => 0
field :two_handed, :type => Boolean, :default => 0
@@ -35,5 +24,4 @@ class Item
field :demand, :type => Integer, :default => 5
-
end
View
6 app/models/item_type.rb
@@ -1,10 +1,12 @@
class ItemType
include Mongoid::Document
+ include Mongoid::Slug
+
field :key, :type => String
field :name, :type => String
- field :category, :type => String
field :range, :type => Integer, :default => 0
- field :equip, :type => Boolean, :default => false
+ slug :key
+ belongs_to :equip_category, index: true
belongs_to :attribute, index: true
end
View
13 app/models/message.rb
@@ -0,0 +1,13 @@
+class Message
+ include Mongoid::Document
+ include Mongoid::Slug
+
+ field :key, type: String
+ field :body, type: String
+ field :level, type: Integer, default: 1
+
+ slug :key
+
+ validates_uniqueness_of :key
+ validates_presence_of :key
+end
View
6 app/models/status_adjustment.rb
@@ -1,14 +1,12 @@
class StatusAdjustment
include Mongoid::Document
- embedded_in :skill
-
field :dmg, :type => Integer, :default => 0
- field :def, :type => Integer, :default => 0
+ field :defence, :type => Integer, :default => 0
field :hit, :type => Integer, :default => 0
field :avoid, :type => Integer, :default => 0
field :magi, :type => Integer, :default => 0
- field :magi_def, :type => Integer, :default => 0
+ field :magi_defence, :type => Integer, :default => 0
field :dex, :type => Integer, :default => 0
field :agi, :type => Integer, :default => 0
View
14 app/models/status_coefficient.rb
@@ -1,12 +1,10 @@
class StatusCoefficient
include Mongoid::Document
- embedded_in :skill
-
- field :dex, :type => Float
- field :agi, :type => Float
- field :int, :type => Float
- field :vit, :type => Float
- field :str, :type => Float
- field :mnd, :type => Float
+ field :dex, :type => Float, :default => 1
+ field :agi, :type => Float, :default => 1
+ field :int, :type => Float, :default => 1
+ field :vit, :type => Float, :default => 1
+ field :str, :type => Float, :default => 1
+ field :mnd, :type => Float, :default => 1
end
View
9 app/models/system_message.rb
@@ -1,9 +0,0 @@
-class SystemMessage
- include Mongoid::Document
-
- field :key, :type => String
- field :message, :type => String
- field :level, :type => Integer, :default => 1
- field :class, :type => String
-
-end
View
18 spec/factories.rb
@@ -56,6 +56,9 @@
character
item
num 1
+ factory :inventory_sword_item do
+ association :item, factory: :sword_item
+ end
end
factory :item do
@@ -97,38 +100,33 @@
factory :item_type do
key 'item'
name 'Item'
- category 'item'
range 0
- equip false
+ association :equip_category, factory: :item_category
factory :sword_type do
key 'sword'
name 'Sword'
- category 'weapon'
range 2
- equip true
+ association :equip_category, factory: :weapon_category
end
factory :spear_type do
key 'spear'
name 'Spear'
- category 'weapon'
range 2
- equip true
+ association :equip_category, factory: :weapon_category
end
factory :cloth_armor_type do
key 'cloth_armor'
name 'ClothArmor'
- category 'armor'
- equip true
+ association :equip_category, factory: :armor_category
end
factory :shield_type do
key 'shield'
name 'Shield'
- category 'shield'
- equip true
+ association :equip_category, factory: :shield_category
end
end
View
41 spec/factories/equip_categories.rb
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :equip_category do
+ equip true
+
+ factory :item_category do
+ key 'item'
+ name '道具'
+ equip false
+ end
+
+ factory :weapon_category do
+ key 'weapon'
+ name '武器'
+ end
+
+ factory :bullet_category do
+ key 'bullet'
+ name '矢弾'
+ end
+
+ factory :armor_category do
+ key 'armor'
+ name ''
+ end
+
+ factory :shield_category do
+ key 'shield'
+ name ''
+ end
+
+ factory :material_category do
+ key 'material'
+ name '素材'
+ equip false
+ end
+
+ end
+end
View
22 spec/factories/status_adjustment.rb
@@ -0,0 +1,22 @@
+FactoryGirl.define do
+ factory :status_adjustment do
+ dmg 0
+ defence 0
+ hit 0
+ avoid 0
+ magi 0
+ magi_defence 0
+ dex 0
+ agi 0
+ int 0
+ vit 0
+ str 0
+ mnd 0
+ hp 0
+ mp 0
+
+ factory :dex_adjustment do
+ dex 1
+ end
+ end
+end
View
3  spec/lib/action_spec.rb
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
describe Action do
+
let(:skill) { FactoryGirl.create :skill }
let(:inventory_item) { FactoryGirl.create :inventory_item }
it 'SkillクラスがActionモジュールをインクルードしていること' do
skill.is_a?(Action).should be_true
end
- it 'InventoryItemクラスがACtionモジュールをインクルードしていること' do
+ it 'InventoryItemクラスがActionモジュールをインクルードしていること' do
inventory_item.is_a?(Action).should be_true
end
end
View
4 spec/lib/eretheal/combat_actor_spec.rb
@@ -4,8 +4,8 @@
let(:character) { FactoryGirl.create :character, equip: FactoryGirl.create(:equip) }
let(:enemy) { FactoryGirl.create :enemy }
- let(:sword) { FactoryGirl.create :inventory_item, item: FactoryGirl.create(:sword_item, speed: -1, add_dex: 1), character: character}
- let(:armor) { FactoryGirl.create :inventory_item, item: FactoryGirl.create(:armor_item, add_vit: 1), character: character}
+ let(:sword) { FactoryGirl.create :inventory_item, item: FactoryGirl.create(:sword_item, speed: -1, status_adjustment: FactoryGirl.create(:status_adjustment, dex: 1)), character: character}
+ let(:armor) { FactoryGirl.create :inventory_item, item: FactoryGirl.create(:armor_item, status_adjustment: FactoryGirl.create(:status_adjustment, vit: 1)), character: character}
before do
sword.equip
armor.equip
View
7 spec/lib/eretheal/formula_spec.rb
@@ -3,8 +3,8 @@
let(:formula) { Eretheal::Formula.new }
let(:character) { FactoryGirl.create :character, equip: FactoryGirl.create(:equip) }
let(:enemy) { FactoryGirl.create :enemy }
- let(:sword) { FactoryGirl.create :inventory_item, item: FactoryGirl.create(:sword_item, speed: -1, add_dex: 1), character: character}
- let(:armor) { FactoryGirl.create :inventory_item, item: FactoryGirl.create(:armor_item, add_vit: 1), character: character}
+ let(:sword) { FactoryGirl.create :inventory_item, item: FactoryGirl.create(:sword_item, speed: -1, status_adjustment: FactoryGirl.create(:status_adjustment, dex: 1)), character: character}
+ let(:armor) { FactoryGirl.create :inventory_item, item: FactoryGirl.create(:armor_item, status_adjustment: FactoryGirl.create(:status_adjustment, vit: 1)), character: character}
before do
sword.equip
armor.equip
@@ -19,5 +19,8 @@
context 'スピード値が整数として得られること' do
it { formula.speed(6).should be_integer }
+ context 'パラメータがゼロの場合は1が返ること' do
+ it { formula.speed(0).should eq 1 }
+ end
end
end
View
22 spec/models/equip_category_spec.rb
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+require 'spec_helper'
+
+describe EquipCategory do
+ let(:weapon_category) { FactoryGirl.create(:weapon_category) }
+ describe 'keyからドキュメントを探すことができること' do
+ before do
+ weapon_category
+ end
+ it { EquipCategory.find('weapon').should eq weapon_category }
+ end
+
+ describe '装備品かどうかを真偽できること' do
+ subject { weapon_category }
+ it { should be_equip }
+
+ context '対象が素材のとき' do
+ subject { FactoryGirl.create(:material_category) }
+ it { should_not be_equip }
+ end
+ end
+end
View
13 spec/models/inventory_item_spec.rb
@@ -7,10 +7,10 @@
let(:equip) { pc.equip }
let(:inventory_item) { FactoryGirl.create :inventory_item, character: pc }
- context '武器Aを装備したとき' do
+ context 'DEX+1の武器Aを装備したとき' do
+ let(:inventory_item) { FactoryGirl.create :inventory_sword_item, character: pc }
before do
- inventory_item.item.item_type = FactoryGirl.create :sword_type
- inventory_item.item.add_dex = 1
+ inventory_item.item.status_adjustment = FactoryGirl.create :dex_adjustment
end
it { inventory_item.equip.should be_true }
it '武器として装備されていること' do
@@ -150,11 +150,12 @@
end
end
- describe 'Inventory_Item#unequip' do
+ describe 'InventoryItem#unequip' do
let(:pc) { FactoryGirl.create(:character, equip: FactoryGirl.create(:equip)) }
- let(:inventory_item) { FactoryGirl.create :inventory_item, item: FactoryGirl.create(:sword_item, add_dex: 1), character: pc }
- context '装備しているソードを外すとき' do
+ let(:inventory_item) { FactoryGirl.create :inventory_sword_item, character: pc }
+ context '装備しているソード(DEX+1)を外すとき' do
before do
+ inventory_item.item.status_adjustment = FactoryGirl.create :dex_adjustment
inventory_item.equip
pc.total_dex
inventory_item.unequip
View
16 spec/models/item_type_spec.rb
@@ -2,17 +2,11 @@
require 'spec_helper'
describe ItemType do
- context 'アイテムAを装備可能かどうか診断したとき' do
- subject { item }
- context '装備可能なアイテムであれば' do
- let(:item) { FactoryGirl.create :item, :item_type => FactoryGirl.create(:sword_type) }
- its(:item_type) { should be_equip }
+ describe 'keyからアイテムタイプを探すことができる' do
+ let(:sword_type) { FactoryGirl.create :sword_type }
+ before do
+ sword_type
end
-
- context '装備可能なアイテムでなければ' do
- let(:item) { FactoryGirl.create :item, :item_type => FactoryGirl.create(:item_type) }
- its(:item_type) { should_not be_equip }
- end
-
+ it { ItemType.find('sword').should eq sword_type }
end
end
View
2  spec/models/system_message_spec.rb → spec/models/message_spec.rb
@@ -1,5 +1,5 @@
require 'spec_helper'
-describe SystemMessage do
+describe Message do
pending "add some examples to (or delete) #{__FILE__}"
end

No commit comments for this range

Something went wrong with that request. Please try again.