Permalink
Browse files

ArmsモジュールをEretheal::CombatActorモジュールにリネームした。

  • Loading branch information...
1 parent 9fe1307 commit 45f194cb07d3253894d5fd24455284c594f02ced @sakomoko committed Dec 31, 2012
View
63 app/lib/arms.rb
@@ -1,63 +0,0 @@
-module Arms
- extend ActiveSupport::Memoizable
-
- attr_reader :action
- attr_accessor :formula
-
- def initialize
- super
- @formula = Eretheal::Formula.new
- end
-
- def max_hp
- formula.max_hp self
- end
-
- def max_mp
- formula.max_mp self
- end
-
- def attack_speed_with_weapon
- speed = 0
- if self.class.to_s.downcase.to_sym.in?([:character]) && self.equip.weapon
- speed += self.equip.weapon.item.speed
- end
- self.speed + speed
- end
-
- def attack_speed_with_magic
- formula.speed self.total_int
- end
-
- def speed
- formula.speed self.total_agi
- end
-
- def weapon_item_type
- if self.respond_to? :equip
- if self.equip.weapon
- return self.equip.weapon.item.item_type.key
- end
- return 'fist'
- end
- end
-
- def action=(action)
- raise unless action.is_a? Action
- @action = action
- end
-
- [:total_dex, :total_agi, :total_int, :total_vit, :total_str, :total_mnd].each do |key|
- status = key.to_s.slice(6,3)
- define_method(key) do
- bonus = 0
- if self.respond_to? :equip
- self.equip.each do |key, b|
- bonus += b.item.send("add_" << status)
- end
- end
- self.send(status) + bonus
- end
- memoize key
- end
-end
View
65 app/lib/eretheal/combat_actor.rb
@@ -0,0 +1,65 @@
+module Eretheal
+ module CombatActor
+ extend ActiveSupport::Memoizable
+
+ attr_reader :action
+ attr_accessor :formula
+
+ def initialize
+ super
+ @formula = Eretheal::Formula.new
+ end
+
+ def max_hp
+ formula.max_hp self
+ end
+
+ def max_mp
+ formula.max_mp self
+ end
+
+ def attack_speed_with_weapon
+ speed = 0
+ if self.class.to_s.downcase.to_sym.in?([:character]) && self.equip.weapon
+ speed += self.equip.weapon.item.speed
+ end
+ self.speed + speed
+ end
+
+ def attack_speed_with_magic
+ formula.speed self.total_int
+ end
+
+ def speed
+ formula.speed self.total_agi
+ end
+
+ def weapon_item_type
+ if self.respond_to? :equip
+ if self.equip.weapon
+ return self.equip.weapon.item.item_type.key
+ end
+ return 'fist'
+ end
+ end
+
+ def action=(action)
+ raise unless action.is_a? Action
+ @action = action
+ end
+
+ [:total_dex, :total_agi, :total_int, :total_vit, :total_str, :total_mnd].each do |key|
+ status = key.to_s.slice(6,3)
+ define_method(key) do
+ bonus = 0
+ if self.respond_to? :equip
+ self.equip.each do |key, b|
+ bonus += b.item.send("add_" << status)
+ end
+ end
+ self.send(status) + bonus
+ end
+ memoize key
+ end
+ end
+end
View
2 app/models/character.rb
@@ -2,7 +2,7 @@ class Character
include Mongoid::Document
include Mongoid::Paranoia
include Mongoid::Timestamps
- include Arms
+ include Eretheal::CombatActor
belongs_to :user, index: true
belongs_to :job, index: true
View
2 app/models/enemy.rb
@@ -1,6 +1,6 @@
class Enemy
include Mongoid::Document
- include Arms
+ include Eretheal::CombatActor
field :name, type: String
field :development_type, type: String
View
2 spec/lib/arms_spec.rb → spec/lib/eretheal/combat_actor_spec.rb
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-describe Arms do
+describe Eretheal::CombatActor do
subject { Enemy }
let(:character) { FactoryGirl.create :character, equip: FactoryGirl.create(:equip) }

0 comments on commit 45f194c

Please sign in to comment.