Module: Gamefic::Standard::ImplicitTaking

Included in:
Character
Defined in:
lib/gamefic/standard/implicit_taking.rb

Overview

A mixin that provides a #have_or_take method to automate possession. Authors can use it to ensure that an actor is holding an entity as a prerequisite to doing something with it.

Instance Method Summary collapse

Instance Method Details

#have_or_take(entity) ⇒ Boolean Also known as: has_or_takes

True if the actor is already holding the entity or successfully takes possession of it.

Examples:

Actor needs to be holding the item to use it

respond :use, Item do |actor, item|
  if actor.have_or_take(item)
    actor.tell "You're using #{the item}."
  else
    actor.tell "You can't use #{the item}."
  end
end

Parameters:

  • entity (Gamefic::Entity)

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/gamefic/standard/implicit_taking.rb', line 24

def have_or_take(entity)
  execute(:take, entity) unless possessions.include?(entity)

  possessions.include?(entity)
end