Sha256: a9c05eece11c1ee071aaad082ec77e825b3ea2092c3dbbac4ab4ba812aaf4a7b

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

class Thing < Gamefic::Entity
  include Grammar::Attributes

  attr_writer :itemized

  attr_writer :portable

  # An optional description to use when itemizing entities in room
  # descriptions. The locale_description will be used instead of adding
  # the entity's name to a list.
  #
  attr_accessor :locale_description

  set_default itemized: true
  set_default portable: false

  # Itemized entities are automatically listed in room descriptions.
  #
  # @return [Boolean]
  def itemized?
    @itemized
  end

  # Portable entities can be taken with TAKE actions.
  #
  # @return [Boolean]
  def portable?
    @portable
  end

  # @return [Boolean]
  def attached?
    @attached ||= false
  end

  # @param bool [Boolean]
  def attached= bool
    @attached = if parent.nil?
      # @todo Log attachment failure
      false
    else
      bool
    end
  end

  def parent= new_parent
    self.attached = false unless new_parent == parent
    super
  end

  # The entity's parent room (i.e., the closest ascendant that is a Room).
  #
  # @return [Room]
  def room
    p = parent
    until p.is_a?(Room) or p.nil?
      p = p.parent
    end
    p
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gamefic-standard-2.1.0 lib/gamefic-standard/entities/thing.rb