Class: Gamefic::Subplot

Inherits:
Object
  • Object
show all
Includes:
Stage
Defined in:
lib/gamefic/subplot.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Stage

#stage

Constructor Details

#initialize(plot, introduce: nil) ⇒ Subplot



29
30
31
32
33
34
35
# File 'lib/gamefic/subplot.rb', line 29

def initialize plot, introduce: nil
  @plot = plot
  @concluded = false
  stage &self.class.start_proc unless self.class.start_proc.nil?
  playbook.freeze
  self.introduce introduce unless introduce.nil?
end

Instance Attribute Details

#denied_messageObject



54
55
56
# File 'lib/gamefic/subplot.rb', line 54

def denied_message
  @denied_message ||= 'You are already involved in another subplot.'
end

#plotObject (readonly)

Returns the value of attribute plot.



8
9
10
# File 'lib/gamefic/subplot.rb', line 8

def plot
  @plot
end

Class Method Details

.start_procObject



18
19
20
# File 'lib/gamefic/subplot.rb', line 18

def start_proc
  @start_proc
end

Instance Method Details

#concludeObject



71
72
73
74
75
76
77
78
79
# File 'lib/gamefic/subplot.rb', line 71

def conclude
  @concluded = true
  entities.each { |e|
    destroy e
  }
  players.each { |p|
    exeunt p
  }
end

#concluded?Boolean



81
82
83
# File 'lib/gamefic/subplot.rb', line 81

def concluded?
  @concluded
end

#default_conclusionObject



41
42
43
# File 'lib/gamefic/subplot.rb', line 41

def default_conclusion
  plot.default_conclusion
end

#default_sceneObject



37
38
39
# File 'lib/gamefic/subplot.rb', line 37

def default_scene
  plot.default_scene
end

#exeunt(player) ⇒ Object



66
67
68
69
# File 'lib/gamefic/subplot.rb', line 66

def exeunt player
  player.playbook = plot.playbook
  p_players.delete player
end

#introduce(player) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/gamefic/subplot.rb', line 58

def introduce player
  if plot.subbed?(player)
    player.tell denied_message
  else
    super
  end
end

#playbookObject



45
46
47
# File 'lib/gamefic/subplot.rb', line 45

def playbook
  @playbook ||= plot.playbook.dup
end

#readyObject



85
86
87
88
89
90
91
# File 'lib/gamefic/subplot.rb', line 85

def ready
  conclude if players.empty?
  return if concluded?
  playbook.freeze
  call_ready
  call_player_ready
end

#running?Boolean

HACK: Always assume subplots are running for the sake of entity destruction



50
51
52
# File 'lib/gamefic/subplot.rb', line 50

def running?
  true
end

#updateObject



93
94
95
96
# File 'lib/gamefic/subplot.rb', line 93

def update
  call_player_update
  call_update
end