Class: Brawl::BotProxy
- Inherits:
-
Object
- Object
- Brawl::BotProxy
- Defined in:
- lib/brawl/bot_proxy.rb
Instance Attribute Summary collapse
-
#bot ⇒ Object
Returns the value of attribute bot.
-
#clock ⇒ Object
Returns the value of attribute clock.
-
#last_tick ⇒ Object
Returns the value of attribute last_tick.
-
#msg_log ⇒ Object
Returns the value of attribute msg_log.
Instance Method Summary collapse
- #add_proxy_methods ⇒ Object
- #code {|_self| ... } ⇒ Object
-
#initialize(params) ⇒ BotProxy
constructor
A new instance of BotProxy.
- #name ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(params) ⇒ BotProxy
Returns a new instance of BotProxy.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/brawl/bot_proxy.rb', line 7 def initialize(params) @clock = params[:clock] @bot = params[:bot] @code = params[:code] @last_tick = @clock.ticks @run = false add_proxy_methods end |
Instance Attribute Details
#bot ⇒ Object
Returns the value of attribute bot.
5 6 7 |
# File 'lib/brawl/bot_proxy.rb', line 5 def bot @bot end |
#clock ⇒ Object
Returns the value of attribute clock.
5 6 7 |
# File 'lib/brawl/bot_proxy.rb', line 5 def clock @clock end |
#last_tick ⇒ Object
Returns the value of attribute last_tick.
5 6 7 |
# File 'lib/brawl/bot_proxy.rb', line 5 def last_tick @last_tick end |
#msg_log ⇒ Object
Returns the value of attribute msg_log.
5 6 7 |
# File 'lib/brawl/bot_proxy.rb', line 5 def msg_log @msg_log end |
Instance Method Details
#add_proxy_methods ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/brawl/bot_proxy.rb', line 22 def add_proxy_methods # I'm sure there's a better way of doing this combined_methods = @bot.public_methods(false) combined_methods.concat BasicArenaObject.instance_methods(false) combined_methods.each do |method| next if method.to_s[0] == "_" singleton_class.send :define_method, method do |*params, &block| sleep(0.01) while @clock.ticks <= @last_tick @last_tick = @clock.ticks @bot.send method, *params, &block end end end |
#code {|_self| ... } ⇒ Object
55 56 57 |
# File 'lib/brawl/bot_proxy.rb', line 55 def code yield self end |
#name ⇒ Object
18 19 20 |
# File 'lib/brawl/bot_proxy.rb', line 18 def name @bot.name end |
#start ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/brawl/bot_proxy.rb', line 38 def start @run = true Thread.start { until @clock.state == :stopped || !@run || @health == 0 sleep(0.01) if @clock.state == :wait if @clock.state == :running instance_eval("Thread.start{$SAFE=3;#{@code}}.join") end end @run = false } end |
#stop ⇒ Object
51 52 53 |
# File 'lib/brawl/bot_proxy.rb', line 51 def stop @run = false end |