RPG::UsableItem::Damage

The data class for damage.

Superclass

Referrer

Attributes

type

The type of damage.

element_id

The element ID.

formula

The formula.

variance

The degree of variability.

critical

Critical hit (true/false).

Method

none?

Determines whether the damage type is [None]. Returns true if the value of type is 0.

to_hp?

Determines whether there is an effect on HP. Returns true if the value of type is 1, 3, or 5.

to_mp?

Determines whether there is an effect on MP. Returns true if the value of type is 2, 4, or 6.

recover?

Determines whether there is recovery. Returns true if the value of type is 3 or 4.

drain?

Determines whether there is draining. Returns true if the value of type is 5 or 6.

sign

The damage sign. Returns -1 if recovery, otherwise returns 1.

eval(a, b, v)

Evaluates the formula. The action-side battler, target-side battler, and in-game variable array ($game_variables) are specified by a, b, and v, respectively.

Returns a negative value if recovery.

Definition

class RPG::UsableItem::Damage
  def initialize
    @type = 0
    @element_id = 0
    @formula = '0'
    @variance = 20
    @critical = false
  end
  def none?
    @type == 0
  end
  def to_hp?
    [1,3,5].include?(@type)
  end
  def to_mp?
    [2,4,6].include?(@type)
  end
  def recover?
    [3,4].include?(@type)
  end
  def drain?
    [5,6].include?(@type)
  end
  def sign
    recover? ? -1 : 1
  end
  def eval(a, b, v)
    [Kernel.eval(@formula), 0].max * sign rescue 0
  end
  attr_accessor :type
  attr_accessor :element_id
  attr_accessor :formula
  attr_accessor :variance
  attr_accessor :critical
end