Class: Legion::Extensions::Agentic::Defense::Quicksand::Helpers::Pit
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Defense::Quicksand::Helpers::Pit
- Defined in:
- lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#danger_level ⇒ Object
Returns the value of attribute danger_level.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#saturation ⇒ Object
Returns the value of attribute saturation.
-
#trap_ids ⇒ Object
readonly
Returns the value of attribute trap_ids.
Instance Method Summary collapse
- #add_trap(trap_id) ⇒ Object
- #deadly? ⇒ Boolean
- #drain!(rate: 0.1) ⇒ Object
-
#initialize(saturation: nil, danger_level: nil) ⇒ Pit
constructor
A new instance of Pit.
- #remove_trap(trap_id) ⇒ Object
- #safe? ⇒ Boolean
- #saturate!(rate: 0.1) ⇒ Object
- #to_h ⇒ Object
- #trap_count ⇒ Object
Constructor Details
#initialize(saturation: nil, danger_level: nil) ⇒ Pit
Returns a new instance of Pit.
13 14 15 16 17 18 19 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 13 def initialize(saturation: nil, danger_level: nil) @id = SecureRandom.uuid @saturation = (saturation || 0.5).to_f.clamp(0.0, 1.0).round(10) @danger_level = (danger_level || 0.3).to_f.clamp(0.0, 1.0).round(10) @trap_ids = [] @created_at = Time.now.utc end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 10 def created_at @created_at end |
#danger_level ⇒ Object
Returns the value of attribute danger_level.
11 12 13 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 11 def danger_level @danger_level end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 10 def id @id end |
#saturation ⇒ Object
Returns the value of attribute saturation.
11 12 13 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 11 def saturation @saturation end |
#trap_ids ⇒ Object (readonly)
Returns the value of attribute trap_ids.
10 11 12 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 10 def trap_ids @trap_ids end |
Instance Method Details
#add_trap(trap_id) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 21 def add_trap(trap_id) return :already_present if @trap_ids.include?(trap_id) @trap_ids << trap_id recalculate_danger! :added end |
#deadly? ⇒ Boolean
46 47 48 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 46 def deadly? @danger_level >= 0.8 end |
#drain!(rate: 0.1) ⇒ Object
41 42 43 44 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 41 def drain!(rate: 0.1) @saturation = (@saturation - rate.abs).clamp(0.0, 1.0).round(10) recalculate_danger! end |
#remove_trap(trap_id) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 29 def remove_trap(trap_id) return :not_found unless @trap_ids.include?(trap_id) @trap_ids.delete(trap_id) recalculate_danger! :removed end |
#safe? ⇒ Boolean
50 51 52 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 50 def safe? @danger_level < 0.2 end |
#saturate!(rate: 0.1) ⇒ Object
37 38 39 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 37 def saturate!(rate: 0.1) @saturation = (@saturation + rate.abs).clamp(0.0, 1.0).round(10) end |
#to_h ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 58 def to_h { id: @id, saturation: @saturation, danger_level: @danger_level, trap_count: trap_count, deadly: deadly?, safe: safe?, created_at: @created_at } end |
#trap_count ⇒ Object
54 55 56 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 54 def trap_count @trap_ids.size end |