Module: Gamefic::Plot::Entities

Included in:
Gamefic::Plot, Subplot
Defined in:
lib/gamefic/plot/entities.rb

Instance Method Summary collapse

Instance Method Details

#destroy(entity) ⇒ Object



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

def destroy entity
  if p_dynamic.include?(entity)
    p_entities.delete entity
    p_dynamic.delete entity
    p_players.delete entity
  end
  entity.parent = nil
end

#entitiesArray<Entity>

Get an array of entities associated with this plot.

Returns:



61
62
63
# File 'lib/gamefic/plot/entities.rb', line 61

def entities
  p_entities.clone
end

#make(cls, args = {}, &block) ⇒ Gamefic::Entity

Make a new Entity with the provided properties.

Examples:

Create an Entity

chair = make Entity, name: 'red chair'
chair.name #=> 'red chair'

Parameters:

  • cls (Class)

    The Class of the Entity to be created.

  • args (Hash) (defaults to: {})

    The entity’s properties.

Returns:



14
15
16
17
18
19
20
21
22
23
# File 'lib/gamefic/plot/entities.rb', line 14

def make cls, args = {}, &block
  ent = cls.new args, &block
  if ent.kind_of?(Entity) == false
    raise "Invalid entity class"
  end
  p_entities.push ent
  p_dynamic.push ent if running?
  ent.playbook = playbook if ent.kind_of?(Character)
  ent
end

#pick(description) ⇒ Gamefic::Entity

Pick an entity based on its description. The description provided must match exactly one entity; otherwise an error is raised.

Examples:

Select the Entity that matches the description

red_chair = make Entity, :name => 'red chair'
blue_chair make Entity, :name => 'blue chair'
pick "red chair" #=> red_chair
pick "blue chair" #=> blue_chair
pick "chair" #=> IndexError: description is ambiguous

Parameters:

  • description (String)

    The description of the entity

Returns:



47
48
49
50
51
52
53
54
55
56
# File 'lib/gamefic/plot/entities.rb', line 47

def pick(description)
  query = Gamefic::Query::Base.new
  result = query.match(description, entities)
  if result.objects.length == 0
    raise IndexError.new("Unable to find entity from '#{description}'")
  elsif result.objects.length > 1
    raise IndexError.new("Ambiguous entities found from '#{description}'")
  end
  result.objects[0]
end

#playersArray<Character>

Get an array of players associated with this plot.

Returns:



68
69
70
# File 'lib/gamefic/plot/entities.rb', line 68

def players
  p_players.clone
end