Sha256: e77f70d63026f975dd9d639d5c513f25f97e44b2394cf5b0114e37a7ca9fb3a4

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

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

  attr_writer :itemized

  attr_writer :sticky

  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

  # A message to be displayed in response to DROP actions when the entity is
  # sticky.
  #
  attr_accessor :sticky_message

  set_default itemized: true
  set_default sticky: false
  set_default portable: false

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

  # Sticky entities cannot be dropped with DROP actions
  #
  # @return [Boolean]
  def sticky?
    @sticky
  end

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

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

  # @param [Boolean]
  def attached= bool
    bool = false if parent.nil?
    @attached = bool
  end

  def parent= p
    self.attached = false unless p == 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.0.0 lib/gamefic-standard/entities/thing.rb