Class: Termfront::Mission::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/termfront/mission/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.campaignObject



63
64
65
# File 'lib/termfront/mission/base.rb', line 63

def campaign
  @campaign ||= []
end

.register(klass) ⇒ Object



71
72
73
# File 'lib/termfront/mission/base.rb', line 71

def register(klass)
  campaign << klass
end

.register_wavesfight(klass) ⇒ Object



75
76
77
# File 'lib/termfront/mission/base.rb', line 75

def register_wavesfight(klass)
  wavesfight << klass
end

.wavesfightObject



67
68
69
# File 'lib/termfront/mission/base.rb', line 67

def wavesfight
  @wavesfight ||= []
end

Instance Method Details

#briefingObject

Raises:

  • (NotImplementedError)


13
# File 'lib/termfront/mission/base.rb', line 13

def briefing  = raise(NotImplementedError)

#build_enemies(difficulty_index) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/termfront/mission/base.rb', line 50

def build_enemies(difficulty_index)
  enemies = enemy_defs.map do |ed|
    type = ed[4]
    Enemy::Base.build(type, ed, difficulty_index)
  end
  if difficulty_index
    extra = Enemy::Base::DIFFICULTIES[difficulty_index][:extra_enemies]
    enemies += Enemy::Base.generate_extras(enemy_defs, extra, difficulty_index)
  end
  enemies
end

#build_mapObject



42
43
44
# File 'lib/termfront/mission/base.rb', line 42

def build_map
  Map.new(map_data)
end

#build_terminalsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/termfront/mission/base.rb', line 27

def build_terminals
  terminal_ids = event_definitions.filter_map do |event|
    trigger = event[:trigger]
    trigger[:terminal_id] if trigger[:type] == :terminal_used
  end.uniq

  map_data.each_with_index.filter_map do |row, y|
    row.chars.each_with_index.filter_map do |cell, x|
      next unless cell == "*"

      { id: (terminal_ids.shift || :"terminal_#{x}_#{y}"), x: x + 0.5, y: y + 0.5 }
    end
  end.flatten
end

#build_weaponsObject



46
47
48
# File 'lib/termfront/mission/base.rb', line 46

def build_weapons
  weapon_defs.map { |type, ammo| Weapon::Base.build(type, ammo) }
end

#enemy_defsObject

Raises:

  • (NotImplementedError)


17
# File 'lib/termfront/mission/base.rb', line 17

def enemy_defs  = raise(NotImplementedError)

#event_definitionsObject



23
24
25
# File 'lib/termfront/mission/base.rb', line 23

def event_definitions
  @event_definitions ||= EventLoader.load_file(events_path)
end

#events_pathObject



19
20
21
# File 'lib/termfront/mission/base.rb', line 19

def events_path
  File.expand_path("../../../data/events/#{id}.json", __dir__)
end

#idObject



6
7
8
9
10
# File 'lib/termfront/mission/base.rb', line 6

def id
  self.class.name.split("::").last
    .gsub(/([a-z0-9])([A-Z])/, '\1_\2')
    .downcase
end

#map_dataObject

Raises:

  • (NotImplementedError)


14
# File 'lib/termfront/mission/base.rb', line 14

def map_data  = raise(NotImplementedError)

#nameObject

Raises:

  • (NotImplementedError)


12
# File 'lib/termfront/mission/base.rb', line 12

def name      = raise(NotImplementedError)

#spawnObject

Raises:

  • (NotImplementedError)


15
# File 'lib/termfront/mission/base.rb', line 15

def spawn     = raise(NotImplementedError)

#weapon_defsObject

Raises:

  • (NotImplementedError)


16
# File 'lib/termfront/mission/base.rb', line 16

def weapon_defs = raise(NotImplementedError)