Class: CARPS::DM::Mod

Inherits:
Mod
  • Object
show all
Defined in:
lib/carps/mod/dm/mod.rb

Overview

Class for DM mods

Functions as a facade to the resource, mailer and reporter classes.

Subclasses should override schema and semantic_verifier

FIXME: This class is WAY too big

Instance Method Summary collapse

Methods inherited from Mod

#mailer=

Constructor Details

#initialize(resource) ⇒ Mod

Initialize with a resource manager



35
36
37
38
39
40
41
42
43
# File 'lib/carps/mod/dm/mod.rb', line 35

def initialize resource
   @resource = resource
   new_reporter
   @players = {}
   @npcs = {}
   @entities = {}
   @monikers = {}
   @mails = {}
end

Instance Method Details

#add_known_player(moniker, email) ⇒ Object

Add a player with a moniker



184
185
186
187
188
# File 'lib/carps/mod/dm/mod.rb', line 184

def add_known_player moniker, email
   @monikers[moniker] = email
   @mails[email] = moniker
   @entities[moniker] = :player
end

#add_player(email) ⇒ Object

Add a player



174
175
176
177
178
179
180
181
# File 'lib/carps/mod/dm/mod.rb', line 174

def add_player email
   valid = false
   until valid
      moniker = UI::question "Enter moniker for " + email
      valid = moniker_available? moniker
   end
   add_known_player moniker, email
end

#ask_everyoneObject

Ask a question of everyone



72
73
74
75
76
77
78
# File 'lib/carps/mod/dm/mod.rb', line 72

def ask_everyone
   edit = Editor.load
   question = edit.edit "# Enter question for everyone"
   @players.each_key do |player|
      @reporter.ask_player player, question
   end
end

#ask_player(player) ⇒ Object

Ask a question of the player



63
64
65
66
67
68
69
# File 'lib/carps/mod/dm/mod.rb', line 63

def ask_player player
   with_player player do
      edit = Editor.load
      question = edit.edit "# Enter question for #{player}"
      @reporter.ask_player player, question
   end
end

#check_mailObject

Check for mail



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/carps/mod/dm/mod.rb', line 225

def check_mail
   if mail = @mailer.check(Sheet::NewSheet)
      unless @mails.member? mail.from 
         add_player mail.from
      end
      with_valid_mail mail do |moniker|
         new_character_sheet moniker, Sheet::Player.new(self, moniker, mail.dump)
      end
   elsif mail = @mailer.check(Answers)
      with_valid_mail mail do |moniker|
         new_answer moniker, mail
      end
   end

   if mail
      true
   else
      puts "No new mail."
      false
   end

end

#create_global_reportObject

Create a report that all players will see



158
159
160
161
162
163
164
# File 'lib/carps/mod/dm/mod.rb', line 158

def create_global_report
   e = Editor.load
   global = e.edit "# Enter report for all players."
   @players.each_key do |player|
      @reporter.update_player player, global
   end
end

#delete_all_questionsObject

Delete all questions



93
94
95
# File 'lib/carps/mod/dm/mod.rb', line 93

def delete_all_questions
   @reporter.delete_all_questions
end

#delete_all_reportsObject

Delete all reports



98
99
100
# File 'lib/carps/mod/dm/mod.rb', line 98

def delete_all_reports
   @reporter.delete_reports
end

#delete_questions(player) ⇒ Object

Delete questions for a player



81
82
83
84
85
# File 'lib/carps/mod/dm/mod.rb', line 81

def delete_questions player
   with_player player do
      @reporter.delete_questions player
   end
end

#delete_report(player) ⇒ Object

Delete a player’s report



103
104
105
106
107
# File 'lib/carps/mod/dm/mod.rb', line 103

def delete_report player
   with_player player do
      @reporter.update_player player, ""
   end
end

#describe(name) ⇒ Object

Describe an entity



191
192
193
194
195
# File 'lib/carps/mod/dm/mod.rb', line 191

def describe name
   with_entity2 name,
      lambda {unsafe_describe_player name},
      lambda {unsafe_describe_npc name}
end

#edit_sheet(name) ⇒ Object

Edit a sheet



56
57
58
59
60
# File 'lib/carps/mod/dm/mod.rb', line 56

def edit_sheet name
   with_entity name do |char|
      editor.fill char
   end
end

#everyone_in(room) ⇒ Object

All players are in this room



110
111
112
# File 'lib/carps/mod/dm/mod.rb', line 110

def everyone_in room
   @resource.players_in @players.keys, room
end

#inspect_reportsObject

Inspect all turns



133
134
135
136
137
138
139
# File 'lib/carps/mod/dm/mod.rb', line 133

def inspect_reports
   turns = @reporter.player_turns @players.keys
   turns.each do |moniker, t|
      puts "Upcoming turn for " + moniker
      t.preview
   end
end

#inspect_turn(player) ⇒ Object

Inspect a player’s turn



142
143
144
145
146
147
# File 'lib/carps/mod/dm/mod.rb', line 142

def inspect_turn player
   with_player player do
      turn = @reporter.player_turn player
      turn.preview
   end
end

#invite(addr) ⇒ Object

Invite a new player



46
47
48
# File 'lib/carps/mod/dm/mod.rb', line 46

def invite addr
   @mailer.invite addr
end

#list_npcsObject

Describe all npcs



198
199
200
201
202
203
204
# File 'lib/carps/mod/dm/mod.rb', line 198

def list_npcs
   puts "The NPCs are:"
   @npcs.each_key do |npc|
      puts "\n#{npc}:"
      unsafe_describe_npc npc
   end
end

#list_playersObject

List all the players



217
218
219
220
221
222
# File 'lib/carps/mod/dm/mod.rb', line 217

def list_players
   puts "The players are:"
   @players.each_key do |player|
      unsafe_describe_player player
   end
end

#new_npc(type, name) ⇒ Object

Create a new npc



122
123
124
125
126
127
128
129
130
# File 'lib/carps/mod/dm/mod.rb', line 122

def new_npc type, name
   if moniker_available? name
      if char = @resource.new_npc(type)
         editor.validate char 
         @npcs[name] = char
         @entities[name] = :npc
      end
   end
end

#next_turnObject

Next turn



150
151
152
153
154
155
# File 'lib/carps/mod/dm/mod.rb', line 150

def next_turn
   # Save the game
   send_reports
   new_reporter
   save
end

#npc_stats(npc) ⇒ Object

Return npc stats



212
213
214
# File 'lib/carps/mod/dm/mod.rb', line 212

def npc_stats npc
   @npcs[npc]
end

#player_in(player, room) ⇒ Object

A player is in this room



115
116
117
118
119
# File 'lib/carps/mod/dm/mod.rb', line 115

def player_in player, room
   with_player player do
      @resource.player_in player, room
   end
end

#player_stats(player) ⇒ Object

Return player stats



207
208
209
# File 'lib/carps/mod/dm/mod.rb', line 207

def player_stats player
   @players[player]
end

#saveObject

Save the game



51
52
53
# File 'lib/carps/mod/dm/mod.rb', line 51

def save
   @mailer.save self
end

#sheet_updated(moniker) ⇒ Object

A sheet has been updated so inform the player



249
250
251
# File 'lib/carps/mod/dm/mod.rb', line 249

def sheet_updated moniker
   @reporter.sheet moniker, @players[moniker]
end

#tell(player) ⇒ Object

Edit the report for a player



167
168
169
170
171
# File 'lib/carps/mod/dm/mod.rb', line 167

def tell player
   with_player player do
      @reporter.edit player
   end
end

#update_player(player, report) ⇒ Object

Update a player’s report



88
89
90
# File 'lib/carps/mod/dm/mod.rb', line 88

def update_player player, report
   @reporter.update_player player, report
end