Class: Gamefic::Plot

Inherits:
Object show all
Includes:
Host, Snapshot, Scriptable, Serialize, World
Defined in:
lib/gamefic/plot.rb,
lib/gamefic/plot/darkroom.rb

Overview

Create and restore plot snapshots.

Defined Under Namespace

Modules: Host, Snapshot Classes: Darkroom

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Serialize

instances, #serialized_class, string_to_constant, #to_serial

Methods included from Host

#branch, #in_subplot?, #subplots, #subplots_featuring

Methods included from Snapshot

#restore, #save

Methods included from Scriptable

included, #stage, #theater

Methods included from World::Players

#make_player_character, #player_class, #players, #set_player_class

Methods included from World::Commands

#actions, #disambiguate, #get_default_query, #interpret, #meta, #override, #parse, #playbook, #respond, #set_default_query, #validate, #verbs

Methods included from World::Entities

#cast, #destroy, #entities, #make, #pick, #players

Methods included from World::Scenes

#conclusion, #custom, #default_conclusion, #default_scene, #introduce, #introduction, #multiple_choice, #multiple_scene, #pause, #question, #scene_classes, #yes_or_no

Methods included from World::Callbacks

#before_player_update, #before_player_update_procs, #on_player_conclude, #on_player_ready, #on_player_update, #on_ready, #on_update, #player_conclude_procs, #player_ready_procs, #player_update_procs, #ready_procs, #update_procs

Constructor Details

#initialize(metadata: {}) ⇒ Plot

Returns a new instance of Plot.

Parameters:

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


31
32
33
34
35
# File 'lib/gamefic/plot.rb', line 31

def initialize metadata: {}
   = 
  run_scripts
  @static = [self] + scene_classes + entities
end

Instance Attribute Details

#metadataHash (readonly)

Returns:



17
18
19
# File 'lib/gamefic/plot.rb', line 17

def 
  
end

#staticObject (readonly)

Returns the value of attribute static.



19
20
21
# File 'lib/gamefic/plot.rb', line 19

def static
  @static
end

Instance Method Details

#readyObject

Prepare the Plot for the next turn of gameplay. This method is typically called by the Engine that manages game execution.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gamefic/plot.rb', line 48

def ready
  playbook.freeze
  call_ready
  call_player_ready
  subplots.each { |s| s.ready }
  players.each do |p|
    p.state.replace(
      p.scene.state
      .merge({
        messages: p.messages,
        last_prompt: p.last_prompt,
        last_input: p.last_input,
        queue: p.queue
      })
      .merge(p.state)
    )
    p.output.replace(p.state)
    p.state.clear
  end
end

#syntaxesArray<Syntax>

Get an Array of the Plot’s current Syntaxes.

Returns:



40
41
42
# File 'lib/gamefic/plot.rb', line 40

def syntaxes
  playbook.syntaxes
end

#tell(entities, message) ⇒ Object

Send a message to a group of entities.

Parameters:



98
99
100
101
102
# File 'lib/gamefic/plot.rb', line 98

def tell entities, message
  entities.each { |entity|
    entity.tell message
  }
end

#updateObject

Update the Plot’s current turn of gameplay. This method is typically called by the Engine that manages game execution.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/gamefic/plot.rb', line 73

def update
  entities.each { |e| e.flush }
  call_before_player_update
  players.each do |p|
    p.performed nil
    next unless p.scene
    p.last_input = p.queue.last
    p.last_prompt = p.scene.prompt
    p.scene.update
    if p.scene.is_a?(Scene::Conclusion)
      player_conclude_procs.each do |proc|
        proc.call p
      end
    end
  end
  call_player_update
  call_update
  subplots.delete_if(&:concluded?)
  subplots.each(&:update)
end