Class: CEML::IncidentModel
- Inherits:
-
Struct
- Object
- Struct
- CEML::IncidentModel
- Includes:
- Redis::Objects
- Defined in:
- lib/ceml/models/incident_model.rb
Overview
:received, :recognized, :last_answer, :last_answer_recognized
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #add_castings(castings) ⇒ Object
- #expire ⇒ Object
- #release(player_id) ⇒ Object
- #run(cb_obj) ⇒ Object
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id
11 12 13 |
# File 'lib/ceml/models/incident_model.rb', line 11 def id @id end |
Class Method Details
Instance Method Details
#add_castings(castings) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/ceml/models/incident_model.rb', line 18 def add_castings(castings) castings.each do |rolename, folks| folks.each do |player| Player.new(player[:id]).touch(id) player_roles[player[:id]] = [rolename.to_sym] CEML.log 3, "#{player[:id]}: added as #{rolename.to_sym} (#{id})" end end end |
#expire ⇒ Object
34 35 36 37 38 |
# File 'lib/ceml/models/incident_model.rb', line 34 def expire # TODO: remove casting calls from waiting rooms bytecode.clear data.clear end |
#release(player_id) ⇒ Object
28 29 30 31 32 |
# File 'lib/ceml/models/incident_model.rb', line 28 def release(player_id) CEML.log 3, "#{player_id}: releasing from incident #{id}" Player.new(player_id).clear_incident(id) player_roles.delete(player_id) end |
#run(cb_obj) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ceml/models/incident_model.rb', line 47 def run(cb_obj) raise unless String === id # puts "RUNNING(#{id})" # running_lock.lock do , player_data = *data.value ||= { :id => id } player_data ||= {} players = [] CEML.log 3, ">>> #{player_roles.all.inspect} (#{id})" player_roles.each do |player_id, roles| CEML.log 3, "#{player_id}: casted as #{roles.inspect} -- #{id}: #{player_data[player_id].inspect}" player = { :id => player_id, :roles => Set.new(roles) } player[:roles] << :agents << :players << :both << :all << :each << :everyone << :them << :either player.merge! player_data[player_id] if player_data[player_id] p = Player.new(player_id) stored_player = p.data.value PLAYER_THREAD_FIELDS.each{ |x| stored_player.delete x } msg = p..value player.merge! msg if msg player.merge! stored_player if stored_player players << player end CEML::Incident.new(bytecode.value, id).run(players) do |player, meth, what| case meth.to_sym when :released, :finish, :replace release(player[:id]) end meth = "player_#{meth}" # cb_obj.log "[#{id}] #{meth}: #{player[:id]} #{what.inspect}" if cb_obj.respond_to? meth .update :player => player, :players => players, :id => id result = cb_obj.send(meth, , what) .delete :player .delete :players result end end players.each do |p| Player.new(p[:id])..value = p.like(:received, :recognized, :situation) player_data[p[:id]] = p.like *PLAYER_THREAD_FIELDS # PLAYER_THREAD_FIELDS.each{ |x| p.delete x } end # CEML.log 1, "Player data saving: #{player_data.inspect}" data.value = [, player_data] if next_run = players.map{ |p| p[:continue_at] }.compact.min redis.zadd 'ceml_continue_at', next_run, id end # end end |