Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ItemがStatusAdjustment,StatusCoefficientモデルを持つようになった。

  • Loading branch information...
commit fee98316f65518aeaadad6d6f8cfb1c83d469865 1 parent 3df433c
@sakomoko authored
View
4 app/lib/eretheal/combat_actor.rb
@@ -53,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
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/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
3  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
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
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
4 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
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
Please sign in to comment.
Something went wrong with that request. Please try again.