Module: Natural20::Notable

Included in:
ItemLibrary::Object, Npc
Defined in:
lib/natural_20/concerns/notable.rb

Overview

Concerns used for objects that can have notes

Instance Method Summary collapse

Instance Method Details

#list_notes(entity, perception, highlight: false) ⇒ Array

List notes on object

Parameters:

Returns:

  • (Array)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/natural_20/concerns/notable.rb', line 8

def list_notes(entity, perception, highlight: false)
  @properties[:notes]&.map do |note|
    next if highlight && !note[:highlight]
    next if note[:if].presence && !eval_if(note[:if])

    perception_dc = note[:perception_dc] || 0
    if perception >= perception_dc
      note_language = note[:language].presence

      result = if note_language
                 note_content = if entity.languages.include?(note_language)
                                  note[:note]
                                else
                                  '???'
                                end
                 t('perception.note_with_language', note_language: note_language, note: note_content)
               else
                 note[:note]
               end

      if perception_dc.positive?
        t('perception.passed', note: result)
      else
        result
      end
    end
  end&.compact || []
end