Class: InternetHakai::ScenarioHandler
Overview
Constant Summary
collapse
- UNIQUE_BY_THREAD =
false
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from BaseHandler
clear, clearall, get_class, get_config, get_handler, get_instance, get_instance_thread, get_thread_id, #initialize, #on_create, set_config, set_thread_id, unique_by_thread?
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6
7
8
|
# File 'lib/internethakai/scenario_handler.rb', line 6
def config
@config
end
|
Instance Method Details
#close ⇒ Object
88
89
90
|
# File 'lib/internethakai/scenario_handler.rb', line 88
def close
@closed = true
end
|
#closed? ⇒ Boolean
85
86
87
|
# File 'lib/internethakai/scenario_handler.rb', line 85
def closed?
@closed
end
|
#complete? ⇒ Boolean
91
92
93
|
# File 'lib/internethakai/scenario_handler.rb', line 91
def complete?
@size <= 0
end
|
#create_scenario(process_id = '') ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/internethakai/scenario_handler.rb', line 17
def create_scenario process_id=''
o = Scenario::new(@config)
@size += 1
o.scenario_id = (@size.to_s + process_id).to_i
o.create_scenario
@scenarios[o.object_id] = o.size
@act_sum += o.size
o
end
|
#init(config) ⇒ Object
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/internethakai/scenario_handler.rb', line 7
def init config
@config = config
@size = 0
@closed = false
@max_request = @config['max_scenario']
@max_request_counter = @max_request
@act_sum = 0
@scenarios = Hash::new
@logger = BaseHandler::get_handler(@config["logger"])
end
|
#on_complete ⇒ Object
35
36
37
|
# File 'lib/internethakai/scenario_handler.rb', line 35
def on_complete
@on_complete_callback.call() if @on_complete_callback
end
|
#on_scenarios_created ⇒ Object
28
29
30
31
|
# File 'lib/internethakai/scenario_handler.rb', line 28
def on_scenarios_created
@loop_counter, @mod_counter = @act_sum.divmod(@max_request)
@queue = BaseHandler::get_handler(@config['queue'])
end
|
#on_turn_complete ⇒ Object
41
42
43
44
|
# File 'lib/internethakai/scenario_handler.rb', line 41
def on_turn_complete
@queue.add([@on_turn_complete_callback,[]]) if @on_turn_complete_callback
@logger.run('o', 2)
end
|
#quit_action(scenario_id) ⇒ Object
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
|
# File 'lib/internethakai/scenario_handler.rb', line 51
def quit_action scenario_id
@scenarios[scenario_id] -= 1
@max_request_counter -= 1
if @max_request_counter == 0
on_turn_complete
@max_request_counter = @max_request
@loop_counter -= 1
end
if(@scenarios[scenario_id]==0)
@size -= 1
if @config['infinity']
@scenarios[scenario_id] += 100
return
end
if @size==0
@logger.run("O", 2)
on_complete
end
end
end
|
#set_on_complete(&block) ⇒ Object
32
33
34
|
# File 'lib/internethakai/scenario_handler.rb', line 32
def set_on_complete &block
@on_complete_callback = block
end
|
#set_on_turn_complete(&block) ⇒ Object
38
39
40
|
# File 'lib/internethakai/scenario_handler.rb', line 38
def set_on_turn_complete &block
@on_turn_complete_callback = block
end
|
#silence ⇒ Object
45
46
47
48
49
|
# File 'lib/internethakai/scenario_handler.rb', line 45
def silence
def on_turn_complete
@queue.add([@on_turn_complete_callback,[]]) if @on_turn_complete_callback
end
end
|