Class: Legion::Extensions::Agentic::Defense::Avalanche::Helpers::Cascade
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Defense::Avalanche::Helpers::Cascade
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb
Constant Summary
Constants included from Constants
Legion::Extensions::Agentic::Defense::Avalanche::Helpers::Constants::ACCUMULATION_RATE, Legion::Extensions::Agentic::Defense::Avalanche::Helpers::Constants::CASCADE_TYPES, Legion::Extensions::Agentic::Defense::Avalanche::Helpers::Constants::MAGNITUDE_LABELS, Legion::Extensions::Agentic::Defense::Avalanche::Helpers::Constants::MAX_CASCADE_HISTORY, Legion::Extensions::Agentic::Defense::Avalanche::Helpers::Constants::MAX_SNOWPACKS, Legion::Extensions::Agentic::Defense::Avalanche::Helpers::Constants::MELT_RATE, Legion::Extensions::Agentic::Defense::Avalanche::Helpers::Constants::SNOWPACK_TYPES, Legion::Extensions::Agentic::Defense::Avalanche::Helpers::Constants::STABILITY_LABELS, Legion::Extensions::Agentic::Defense::Avalanche::Helpers::Constants::TRIGGER_THRESHOLD
Instance Attribute Summary collapse
-
#cascade_type ⇒ Object
readonly
Returns the value of attribute cascade_type.
-
#debris ⇒ Object
Returns the value of attribute debris.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#magnitude ⇒ Object
Returns the value of attribute magnitude.
-
#propagation_speed ⇒ Object
Returns the value of attribute propagation_speed.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#trigger_source ⇒ Object
readonly
Returns the value of attribute trigger_source.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #add_debris(item) ⇒ Object
- #dissipate!(rate = 0.08) ⇒ Object
-
#initialize(cascade_type:, trigger_source:, magnitude:, propagation_speed: 0.5, debris: []) ⇒ Cascade
constructor
A new instance of Cascade.
- #magnitude_label ⇒ Object
- #propagate!(rate = 0.1) ⇒ Object
- #spent? ⇒ Boolean
- #to_h ⇒ Object
Methods included from Constants
Constructor Details
#initialize(cascade_type:, trigger_source:, magnitude:, propagation_speed: 0.5, debris: []) ⇒ Cascade
Returns a new instance of Cascade.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 17 def initialize(cascade_type:, trigger_source:, magnitude:, propagation_speed: 0.5, debris: [], **) raise ArgumentError, "unknown cascade_type: #{cascade_type}" unless Constants::CASCADE_TYPES.include?(cascade_type) @id = SecureRandom.uuid @cascade_type = cascade_type @trigger_source = trigger_source @magnitude = magnitude.clamp(0.0, 1.0) @propagation_speed = propagation_speed.clamp(0.0, 1.0) @debris = Array(debris).dup @active = true @started_at = Time.now.utc end |
Instance Attribute Details
#cascade_type ⇒ Object (readonly)
Returns the value of attribute cascade_type.
14 15 16 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 14 def cascade_type @cascade_type end |
#debris ⇒ Object
Returns the value of attribute debris.
15 16 17 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 15 def debris @debris end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 14 def id @id end |
#magnitude ⇒ Object
Returns the value of attribute magnitude.
15 16 17 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 15 def magnitude @magnitude end |
#propagation_speed ⇒ Object
Returns the value of attribute propagation_speed.
15 16 17 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 15 def propagation_speed @propagation_speed end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 14 def started_at @started_at end |
#trigger_source ⇒ Object (readonly)
Returns the value of attribute trigger_source.
14 15 16 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 14 def trigger_source @trigger_source end |
Instance Method Details
#active? ⇒ Boolean
41 42 43 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 41 def active? @active && @magnitude > 0.0 end |
#add_debris(item) ⇒ Object
53 54 55 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 53 def add_debris(item) @debris << item end |
#dissipate!(rate = 0.08) ⇒ Object
36 37 38 39 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 36 def dissipate!(rate = 0.08) @magnitude = (@magnitude - rate.abs).clamp(0.0, 1.0).round(10) @active = false if @magnitude <= 0.0 end |
#magnitude_label ⇒ Object
49 50 51 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 49 def magnitude_label Constants.label_for(:MAGNITUDE_LABELS, @magnitude) end |
#propagate!(rate = 0.1) ⇒ Object
30 31 32 33 34 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 30 def propagate!(rate = 0.1) return unless @active @magnitude = (@magnitude + rate.abs).clamp(0.0, 1.0).round(10) end |
#spent? ⇒ Boolean
45 46 47 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 45 def spent? !@active || @magnitude <= 0.0 end |
#to_h ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/cascade.rb', line 57 def to_h { id: @id, cascade_type: @cascade_type, trigger_source: @trigger_source, magnitude: @magnitude, magnitude_label: magnitude_label, propagation_speed: @propagation_speed, debris: @debris.dup, active: @active, started_at: @started_at } end |