Class: Legion::Extensions::Agentic::Homeostasis::Furnace::Helpers::FurnaceEngine

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFurnaceEngine

Returns a new instance of FurnaceEngine.



12
13
14
15
16
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 12

def initialize
  @ores         = {}
  @crucibles    = {}
  @alloy_history = []
end

Instance Attribute Details

#alloy_historyObject (readonly)

Returns the value of attribute alloy_history.



10
11
12
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 10

def alloy_history
  @alloy_history
end

#cruciblesObject (readonly)

Returns the value of attribute crucibles.



10
11
12
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 10

def crucibles
  @crucibles
end

#oresObject (readonly)

Returns the value of attribute ores.



10
11
12
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 10

def ores
  @ores
end

Instance Method Details

#add_ore(ore_type:, domain:, content:, purity: 0.5, impurity: nil, ore_id: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 18

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



102
103
104
105
106
107
108
109
110
111
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 102

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



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 69

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



33
34
35
36
37
38
39
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 33

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_reportObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 127

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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 52

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



120
121
122
123
124
125
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 120

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



41
42
43
44
45
46
47
48
49
50
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 41

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



113
114
115
116
117
118
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 113

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



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/furnace_engine.rb', line 85

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]
    remove_smelted_ores!(result.dig(:alloy, :source_ore_ids) || [])
  end
  result.merge(crucible_id: crucible_id)
end