Class: Hengband::Item
- Inherits:
-
Object
- Object
- Hengband::Item
- Includes:
- Comparable
- Defined in:
- lib/hengband/item.rb
Constant Summary collapse
- RE_HEADER =
/\w\) /
- RE_NUMBER =
/\d+([本巻服冊着振足枚つ個]|切れ)の /
- RE_NAME =
/(?<name>.+?) ?/
- RE_BOW =
/\(x(?<bow_pow>\d+)\) ?/
- RE_DICE =
/\((?<dice_num>\d+)d(?<dice_val>\d+)\) ?/
- RE_OFFENSE =
/\((?<off_acc>[+-]\d+)(,(?<off_dam>[+-]\d+))?\) ?/
- RE_DEFENSE =
/\[((?<def_base>\d+),)?(?<def_plus>[+-]\d+)\] ?/
- RE_PVAL =
/\((?<pval>[+-]\d+).*?\) ?/
- RE_FLAGS =
/\{(?<flags>.*?)\}/
- UNIDENTIFIED =
/\{特別製|高級品|上質|並\}/
- REXP_ITEM =
/#{RE_HEADER}#{RE_NUMBER}?#{RE_NAME }#{RE_BOW}?#{RE_DICE}?#{RE_OFFENSE}?#{RE_DEFENSE}?#{RE_PVAL}?#{RE_FLAGS}?$/
- TYPES =
[:weapon, :shield, :bow, :ring, :neck, :light, :armor, :cloak, :head, :hands, :feet, :other]
Instance Attribute Summary collapse
-
#bow_pow ⇒ Object
readonly
Returns the value of attribute bow_pow.
-
#def_base ⇒ Object
readonly
Returns the value of attribute def_base.
-
#def_plus ⇒ Object
readonly
Returns the value of attribute def_plus.
-
#dice_num ⇒ Object
readonly
Returns the value of attribute dice_num.
-
#dice_val ⇒ Object
readonly
Returns the value of attribute dice_val.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#off_acc ⇒ Object
readonly
Returns the value of attribute off_acc.
-
#off_dam ⇒ Object
readonly
Returns the value of attribute off_dam.
-
#pval ⇒ Object
readonly
Returns the value of attribute pval.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #damage ⇒ Object
- #defence ⇒ Object
- #defence? ⇒ Boolean
-
#initialize(line) ⇒ Item
constructor
A new instance of Item.
- #to_s ⇒ Object
Constructor Details
#initialize(line) ⇒ Item
Returns a new instance of Item.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/hengband/item.rb', line 41 def initialize(line) @line = line.chomp REXP_ITEM.match(@line) do |m| @name = m[:name] @bow_pow = m[:bow_pow] && m[:bow_pow].to_i @dice_num = m[:dice_num] && m[:dice_num].to_i @dice_val = m[:dice_val] && m[:dice_val].to_i @off_acc = m[:off_acc] && m[:off_acc].to_i @off_dam = m[:off_dam] && m[:off_dam].to_i @def_base = m[:def_base] && m[:def_base].to_i @def_plus = m[:def_plus] && m[:def_plus].to_i @pval = m[:pval] && m[:pval].to_i @flags = parse_flags(m[:flags]) @type = guess_type(@name) end end |
Instance Attribute Details
#bow_pow ⇒ Object (readonly)
Returns the value of attribute bow_pow.
58 59 60 |
# File 'lib/hengband/item.rb', line 58 def bow_pow @bow_pow end |
#def_base ⇒ Object (readonly)
Returns the value of attribute def_base.
58 59 60 |
# File 'lib/hengband/item.rb', line 58 def def_base @def_base end |
#def_plus ⇒ Object (readonly)
Returns the value of attribute def_plus.
58 59 60 |
# File 'lib/hengband/item.rb', line 58 def def_plus @def_plus end |
#dice_num ⇒ Object (readonly)
Returns the value of attribute dice_num.
58 59 60 |
# File 'lib/hengband/item.rb', line 58 def dice_num @dice_num end |
#dice_val ⇒ Object (readonly)
Returns the value of attribute dice_val.
58 59 60 |
# File 'lib/hengband/item.rb', line 58 def dice_val @dice_val end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
57 58 59 |
# File 'lib/hengband/item.rb', line 57 def flags @flags end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
57 58 59 |
# File 'lib/hengband/item.rb', line 57 def line @line end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
57 58 59 |
# File 'lib/hengband/item.rb', line 57 def name @name end |
#off_acc ⇒ Object (readonly)
Returns the value of attribute off_acc.
58 59 60 |
# File 'lib/hengband/item.rb', line 58 def off_acc @off_acc end |
#off_dam ⇒ Object (readonly)
Returns the value of attribute off_dam.
58 59 60 |
# File 'lib/hengband/item.rb', line 58 def off_dam @off_dam end |
#pval ⇒ Object (readonly)
Returns the value of attribute pval.
58 59 60 |
# File 'lib/hengband/item.rb', line 58 def pval @pval end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
57 58 59 |
# File 'lib/hengband/item.rb', line 57 def type @type end |
Class Method Details
.parse_file(path) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hengband/item.rb', line 21 def self.parse_file(path) in_list = false File.open(path, "r:euc-jp:utf-8"){|f| f.read}.lines.map{|line| case line when /\[キャラクタの装備\]/ in_list = true nil when UNIDENTIFIED nil when REXP_ITEM Item.new(line) if in_list when /\[博物館のアイテム\]/ in_list = false nil else #$stderr.puts line.encode("utf-8") end }.compact end |
Instance Method Details
#<=>(other) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/hengband/item.rb', line 82 def <=>(other) if @type != other.type TYPES.index(@type).to_i - TYPES.index(other.type).to_i else case when defence? other.defence - self.defence when @type == :weapon other.damage - self.damage else 0 end end end |
#damage ⇒ Object
72 73 74 |
# File 'lib/hengband/item.rb', line 72 def damage @dice_num and (@dice_num * (@dice_val/2.0) + @off_dam) end |
#defence ⇒ Object
64 65 66 |
# File 'lib/hengband/item.rb', line 64 def defence @def_plus and (@def_base + @def_plus) end |
#defence? ⇒ Boolean
68 69 70 |
# File 'lib/hengband/item.rb', line 68 def defence? [:shield, :armor, :cloak, :head, :hands, :feet].include? @type end |
#to_s ⇒ Object
76 77 78 79 80 |
# File 'lib/hengband/item.rb', line 76 def to_s [ @name, " ", ("{r#{flags[:res].join}}" unless flags[:res].empty?), ].join end |