Class: Legion::Extensions::Agentic::Defense::Quicksand::Helpers::Pit

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_atObject (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_levelObject

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

#idObject (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

#saturationObject

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_idsObject (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

Returns:

  • (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

Returns:

  • (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_hObject



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_countObject



54
55
56
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/pit.rb', line 54

def trap_count
  @trap_ids.size
end