Class: Gamefic::Standard::Portal

Inherits:
Thing
  • Object
show all
Defined in:
lib/gamefic/standard/entities/portal.rb

Overview

An entity that provides access from one room to another.

Direct Known Subclasses

Door

Instance Attribute Summary collapse

Attributes included from Standardized

#itemized, #locale_description, #portable

Instance Method Summary collapse

Methods included from Standardized

#attached=, #attached?, #itemized?, #parent=, #portable?, #room

Instance Attribute Details

#destinationGamefic::Entity

Returns:

  • (Gamefic::Entity)


9
10
11
# File 'lib/gamefic/standard/entities/portal.rb', line 9

def destination
  @destination
end

#directionDirection?

Get the ordinal direction of this Portal Portals have distinct direction and name properties so games can display a bare compass direction for exits, e.g., “south” vs. “the southern door.”

A portal’s destination can also be nil, in which case it can be referenced in commands by its destination, e.g., “go to the house.”

Returns:



21
22
23
# File 'lib/gamefic/standard/entities/portal.rb', line 21

def direction
  @direction
end

#type_nameObject

A description of the portal type for generating automatic names, e.g., “the northern exit”



55
56
57
# File 'lib/gamefic/standard/entities/portal.rb', line 55

def type_name
  @type_name ||= 'exit'
end

Instance Method Details

#instructionObject



44
45
46
# File 'lib/gamefic/standard/entities/portal.rb', line 44

def instruction
  direction || (destination ? "to #{destination.definitely}" : name)
end

#nameObject



39
40
41
42
# File 'lib/gamefic/standard/entities/portal.rb', line 39

def name
  @name ||
    (direction ? "#{type_name} #{direction.name}" : destination.name)
end

#reverseRoom? Also known as: find_reverse

Find the portal in the destination that returns to this portal’s parent

Returns:



26
27
28
29
30
31
32
# File 'lib/gamefic/standard/entities/portal.rb', line 26

def reverse
  return nil if destination.nil?

  destination.children.that_are(Portal).find do |portal|
    portal.destination == parent
  end
end

#synonymsObject



48
49
50
# File 'lib/gamefic/standard/entities/portal.rb', line 48

def synonyms
  "#{super} #{@destination} #{@direction} #{!direction.nil? ? direction.synonyms : ''}"
end