Module: Gamefic::Plot::Entities
- Included in:
- Gamefic::Plot, Subplot
- Defined in:
- lib/gamefic/plot/entities.rb
Instance Method Summary collapse
-
#cast(cls, args = {}, &block) ⇒ Gamefic::Actor, Gamefic::Active
Cast an active entity.
- #destroy(entity) ⇒ Object
-
#entities ⇒ Array<Entity>
Get an array of entities associated with this plot.
-
#make(cls, args = {}, &block) ⇒ Gamefic::Entity
Make a new Entity with the provided properties.
-
#pick(description) ⇒ Gamefic::Entity
Pick an entity based on its description.
-
#players ⇒ Array<Character>
Get an array of players associated with this plot.
Instance Method Details
#cast(cls, args = {}, &block) ⇒ Gamefic::Actor, Gamefic::Active
Cast an active entity. This method is similar to make, but it also provides the plot’s playbook to the entity so it can perform actions. The entity should either be a kind of Gamefic::Actor or include the Gamefic::Active module.
31 32 33 34 35 |
# File 'lib/gamefic/plot/entities.rb', line 31 def cast cls, args = {}, &block ent = make cls, args, &block ent.playbooks.push playbook ent end |
#destroy(entity) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/gamefic/plot/entities.rb', line 37 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 |
#entities ⇒ Array<Entity>
Get an array of entities associated with this plot.
73 74 75 |
# File 'lib/gamefic/plot/entities.rb', line 73 def entities p_entities.clone end |
#make(cls, args = {}, &block) ⇒ Gamefic::Entity
Make a new Entity with the provided properties.
14 15 16 17 18 19 20 21 22 |
# 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 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.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/gamefic/plot/entities.rb', line 59 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 |
#players ⇒ Array<Character>
Get an array of players associated with this plot.
80 81 82 |
# File 'lib/gamefic/plot/entities.rb', line 80 def players p_players.clone end |