Class: Lotu::StalkerSystem
- Inherits:
-
BaseSystem
- Object
- BaseSystem
- Lotu::StalkerSystem
- Defined in:
- lib/lotu/systems/stalker_system.rb
Instance Method Summary collapse
-
#initialize(user, opts = {}) ⇒ StalkerSystem
constructor
A new instance of StalkerSystem.
- #to_s ⇒ Object
- #update ⇒ Object
Methods inherited from BaseSystem
Constructor Details
#initialize(user, opts = {}) ⇒ StalkerSystem
Returns a new instance of StalkerSystem.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/lotu/systems/stalker_system.rb', line 4 def initialize(user, opts={}) super default_opts = { :stalk => [Actor], :ticks_per_update => 30 } opts = default_opts.merge!(opts) @ticks = 0 @ticks_per_update = opts[:ticks_per_update] @stalked = {} opts[:stalk].each do |type| @stalked[type] = 0 end end |
Instance Method Details
#to_s ⇒ Object
29 30 31 32 33 |
# File 'lib/lotu/systems/stalker_system.rb', line 29 def to_s @stalked.map do |type, count| "#{type}: #{count}" end end |
#update ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/lotu/systems/stalker_system.rb', line 19 def update @ticks += 1 if @ticks >= @ticks_per_update @stalked.each_key do |type| @stalked[type] = ObjectSpace.each_object(type).count end @ticks = 0 end end |