Class: Legion::Extensions::Agentic::Homeostasis::Furnace::Helpers::FurnaceEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::Furnace::Helpers::FurnaceEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb
Constant Summary
Constants included
from Constants
Constants::ALLOY_TYPES, Constants::COOL_RATE, Constants::DESTROY_THRESHOLD, Constants::HEAT_RATE, Constants::MAX_ALLOY_HISTORY, Constants::MAX_CRUCIBLES, Constants::MAX_ORES, Constants::ORE_TYPES, Constants::PURITY_LABELS, Constants::SMELT_THRESHOLD, Constants::TEMPERATURE_LABELS
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#add_ore(ore_type:, domain:, content:, purity: 0.5, impurity: nil, ore_id: nil) ⇒ Object
-
#cool_all!(rate: Constants::COOL_RATE) ⇒ Object
-
#cool_crucible(crucible_id:, rate: Constants::COOL_RATE) ⇒ Object
-
#create_crucible(capacity: 10, crucible_id: nil, temperature: 0.0) ⇒ Object
-
#furnace_report ⇒ Object
-
#heat_crucible(crucible_id:, rate: Constants::HEAT_RATE) ⇒ Object
-
#hottest_crucibles(limit: 10) ⇒ Object
-
#initialize ⇒ FurnaceEngine
constructor
A new instance of FurnaceEngine.
-
#load_ore(ore_id:, crucible_id:) ⇒ Object
-
#purest_ores(limit: 10) ⇒ Object
-
#smelt(crucible_id:, alloy_type: nil) ⇒ Object
Methods included from Constants
label_for
Constructor Details
Returns a new instance of FurnaceEngine.
14
15
16
17
18
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 14
def initialize
@ores = {}
@crucibles = {}
@alloy_history = []
end
|
Instance Attribute Details
#alloy_history ⇒ Object
Returns the value of attribute alloy_history.
12
13
14
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 12
def alloy_history
@alloy_history
end
|
#crucibles ⇒ Object
Returns the value of attribute crucibles.
12
13
14
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 12
def crucibles
@crucibles
end
|
#ores ⇒ Object
Returns the value of attribute ores.
12
13
14
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 12
def ores
@ores
end
|
Instance Method Details
#add_ore(ore_type:, domain:, content:, purity: 0.5, impurity: nil, ore_id: nil) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 20
def add_ore(ore_type:, domain:, content:, purity: 0.5, impurity: nil, ore_id: nil)
return { added: false, reason: :ore_store_full, max: Constants::MAX_ORES } if @ores.size >= Constants::MAX_ORES
ore = Ore.new(
ore_type: ore_type,
domain: domain,
content: content,
purity: purity,
impurity: impurity,
ore_id: ore_id
)
@ores[ore.ore_id] = ore
{ added: true, ore_id: ore.ore_id, ore: ore.to_h }
end
|
#cool_all!(rate: Constants::COOL_RATE) ⇒ Object
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 105
def cool_all!(rate: Constants::COOL_RATE)
count = 0
@crucibles.each_value do |crucible|
next if crucible.temperature <= 0.0
crucible.cool!(rate)
count += 1
end
{ cooled: count, total: @crucibles.size }
end
|
#cool_crucible(crucible_id:, rate: Constants::COOL_RATE) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 71
def cool_crucible(crucible_id:, rate: Constants::COOL_RATE)
crucible = @crucibles[crucible_id]
return { cooled: false, reason: :not_found } unless crucible
before = crucible.temperature
crucible.cool!(rate)
{
cooled: true,
crucible_id: crucible_id,
before: before.round(10),
after: crucible.temperature.round(10),
label: crucible.temperature_label
}
end
|
#create_crucible(capacity: 10, crucible_id: nil, temperature: 0.0) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 35
def create_crucible(capacity: 10, crucible_id: nil, temperature: 0.0)
return { created: false, reason: :crucible_store_full, max: Constants::MAX_CRUCIBLES } if @crucibles.size >= Constants::MAX_CRUCIBLES
crucible = Crucible.new(capacity: capacity, crucible_id: crucible_id, temperature: temperature)
@crucibles[crucible.crucible_id] = crucible
{ created: true, crucible_id: crucible.crucible_id, crucible: crucible.to_h }
end
|
#furnace_report ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 130
def furnace_report
ore_count = @ores.size
crucible_count = @crucibles.size
alloy_count = @alloy_history.size
avg_purity = ore_count.positive? ? (@ores.values.sum(&:purity) / ore_count).round(10) : 0.0
avg_temp = crucible_count.positive? ? (@crucibles.values.sum(&:temperature) / crucible_count).round(10) : 0.0
optimal_count = @crucibles.count { |_, c| c.optimal? }
overheated_count = @crucibles.count { |_, c| c.overheated? }
{
ore_count: ore_count,
crucible_count: crucible_count,
alloy_count: alloy_count,
avg_ore_purity: avg_purity,
avg_temperature: avg_temp,
optimal_crucibles: optimal_count,
overheated_crucibles: overheated_count,
ore_capacity: Constants::MAX_ORES,
crucible_capacity: Constants::MAX_CRUCIBLES
}
end
|
#heat_crucible(crucible_id:, rate: Constants::HEAT_RATE) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 54
def heat_crucible(crucible_id:, rate: Constants::HEAT_RATE)
crucible = @crucibles[crucible_id]
return { heated: false, reason: :not_found } unless crucible
before = crucible.temperature
crucible.heat!(rate)
{
heated: true,
crucible_id: crucible_id,
before: before.round(10),
after: crucible.temperature.round(10),
label: crucible.temperature_label,
overheated: crucible.overheated?
}
end
|
#hottest_crucibles(limit: 10) ⇒ Object
123
124
125
126
127
128
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 123
def hottest_crucibles(limit: 10)
@crucibles.values
.sort_by { |c| -c.temperature }
.first(limit)
.map(&:to_h)
end
|
#load_ore(ore_id:, crucible_id:) ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 43
def load_ore(ore_id:, crucible_id:)
ore = @ores[ore_id]
crucible = @crucibles[crucible_id]
return { loaded: false, reason: :ore_not_found } unless ore
return { loaded: false, reason: :crucible_not_found } unless crucible
result = crucible.load_ore(ore_id)
result.merge(ore_id: ore_id, crucible_id: crucible_id)
end
|
#purest_ores(limit: 10) ⇒ Object
116
117
118
119
120
121
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 116
def purest_ores(limit: 10)
@ores.values
.sort_by { |o| -o.purity }
.first(limit)
.map(&:to_h)
end
|
#smelt(crucible_id:, alloy_type: nil) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 87
def smelt(crucible_id:, alloy_type: nil)
crucible = @crucibles[crucible_id]
return { smelted: false, reason: :not_found } unless crucible
if crucible.overheated?
destroy_crucible_contents!(crucible)
return { smelted: false, reason: :overheated, crucible_id: crucible_id }
end
result = crucible.smelt!(@ores, alloy_type: alloy_type)
if result[:smelted]
@alloy_history << result[:alloy]
@alloy_history.shift while @alloy_history.size > MAX_ALLOY_HISTORY
remove_smelted_ores!(result.dig(:alloy, :source_ore_ids) || [])
end
result.merge(crucible_id: crucible_id)
end
|