Class: Core::Game::NPC::Behaviour

Inherits:
Object
  • Object
show all
Defined in:
lib/game/npc/behaviour.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(npc, init, trigger, motion, update) ⇒ Behaviour

Returns a new instance of Behaviour.



11
12
13
14
15
16
17
# File 'lib/game/npc/behaviour.rb', line 11

def initialize(npc, init, trigger, motion, update)
  @self = npc
  @init = init
  @trigger = trigger
  @motion = motion
  @update = update
end

Instance Attribute Details

#initObject (readonly)

Returns the value of attribute init.



9
10
11
# File 'lib/game/npc/behaviour.rb', line 9

def init
  @init
end

#motionObject (readonly)

Returns the value of attribute motion.



9
10
11
# File 'lib/game/npc/behaviour.rb', line 9

def motion
  @motion
end

#triggerObject (readonly)

Returns the value of attribute trigger.



9
10
11
# File 'lib/game/npc/behaviour.rb', line 9

def trigger
  @trigger
end

#updateObject (readonly)

Returns the value of attribute update.



9
10
11
# File 'lib/game/npc/behaviour.rb', line 9

def update
  @update
end

Instance Method Details

#exec_task(task, other = nil) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/game/npc/behaviour.rb', line 34

def exec_task(task, other=nil)
  task.execute(@self, other) if !task.finished?
  if task.finished?
    if task.remove?
      task = nil
    end
  end
end

#on_initObject



19
20
21
22
23
# File 'lib/game/npc/behaviour.rb', line 19

def on_init
  exec_task(@init)
  @self.goal.reset
  exec_task(@motion)
end

#on_trigger(other) ⇒ Object



25
26
27
# File 'lib/game/npc/behaviour.rb', line 25

def on_trigger(other)
  exec_task(@trigger, other)
end

#on_updateObject



29
30
31
32
# File 'lib/game/npc/behaviour.rb', line 29

def on_update
  exec_task(@update)
  exec_task(@motion)
end