Class: Legion::Extensions::Agentic::Homeostasis::Weathering::Helpers::WeatheringEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::Weathering::Helpers::WeatheringEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb
Constant Summary
Constants included
from Constants
Constants::BREAKDOWN_INTEGRITY, Constants::CRITICAL_INTEGRITY, Constants::DEFAULT_INTEGRITY, Constants::INTEGRITY_LABELS, Constants::MAX_EVENTS, Constants::MAX_STRESSORS, Constants::RECOVERY_RATE, Constants::STRESSOR_TYPES, Constants::TEMPERING_RATE, Constants::TEMPERING_THRESHOLD, Constants::WEAR_RATE, Constants::WEATHERING_LABELS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Constants
integrity_label, weathering_label
Constructor Details
Returns a new instance of WeatheringEngine.
14
15
16
17
18
19
20
21
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 14
def initialize
@stressors = []
@events = []
@integrity = Constants::DEFAULT_INTEGRITY
@tempering_level = 0.0
@total_wear = 0.0
@total_recovery = 0.0
end
|
Instance Attribute Details
#integrity ⇒ Object
Returns the value of attribute integrity.
12
13
14
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 12
def integrity
@integrity
end
|
#tempering_level ⇒ Object
Returns the value of attribute tempering_level.
12
13
14
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 12
def tempering_level
@tempering_level
end
|
#total_recovery ⇒ Object
Returns the value of attribute total_recovery.
12
13
14
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 12
def total_recovery
@total_recovery
end
|
#total_wear ⇒ Object
Returns the value of attribute total_wear.
12
13
14
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 12
def total_wear
@total_wear
end
|
Instance Method Details
#apply_stressor(stressor) ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 23
def apply_stressor(stressor)
prune_stressors
@stressors << stressor
record_event(:stressor_applied, stressor.to_h)
wear!(stressor.cumulative_impact)
temper!(stressor.cumulative_impact * Constants::TEMPERING_RATE) if stressor.manageable?
to_h
end
|
#breaking? ⇒ Boolean
60
61
62
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 60
def breaking?
@integrity <= Constants::BREAKDOWN_INTEGRITY
end
|
#effective_capacity ⇒ Object
52
53
54
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 52
def effective_capacity
(@integrity * (1.0 + (@tempering_level * 0.2))).clamp(0.0, 1.2).round(10)
end
|
#fragile? ⇒ Boolean
56
57
58
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 56
def fragile?
@integrity <= Constants::CRITICAL_INTEGRITY
end
|
#recover!(amount) ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 34
def recover!(amount)
amount = amount.clamp(0.0, 1.0)
delta = [amount * Constants::RECOVERY_RATE, 1.0 - @integrity].min
@integrity = (@integrity + delta).clamp(0.0, 1.0).round(10)
@total_recovery = (@total_recovery + delta).round(10)
record_event(:recovery, { amount: amount, delta: delta, integrity: @integrity })
to_h
end
|
#rest!(amount = 1.0) ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 43
def rest!(amount = 1.0)
amount = amount.clamp(0.0, 1.0)
delta = [amount * (Constants::RECOVERY_RATE * 5.0), 1.0 - @integrity].min
@integrity = (@integrity + delta).clamp(0.0, 1.0).round(10)
@total_recovery = (@total_recovery + delta).round(10)
record_event(:rest, { amount: amount, delta: delta, integrity: @integrity })
to_h
end
|
#stressor_count ⇒ Object
64
65
66
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 64
def stressor_count
@stressors.size
end
|
#to_h ⇒ Object
84
85
86
87
88
89
90
91
92
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 84
def to_h
{
integrity: @integrity.round(10),
tempering_level: @tempering_level.round(10),
effective_capacity: effective_capacity,
fragile: fragile?,
breaking: breaking?
}
end
|
#weathering_report ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/legion/extensions/agentic/homeostasis/weathering/helpers/weathering_engine.rb', line 68
def weathering_report
{
integrity: @integrity.round(10),
integrity_label: Constants.integrity_label(@integrity),
tempering_level: @tempering_level.round(10),
weathering_label: Constants.weathering_label(@tempering_level),
effective_capacity: effective_capacity,
total_wear: @total_wear.round(10),
total_recovery: @total_recovery.round(10),
stressor_count: @stressors.size,
fragile: fragile?,
breaking: breaking?,
recent_stressors: @stressors.last(5).map(&:to_h)
}
end
|