Class: Core::Game::NPC::Behaviour
Instance Attribute Summary collapse
-
#init ⇒ Object
readonly
Returns the value of attribute init.
-
#motion ⇒ Object
readonly
Returns the value of attribute motion.
-
#trigger ⇒ Object
readonly
Returns the value of attribute trigger.
-
#update ⇒ Object
readonly
Returns the value of attribute update.
Instance Method Summary collapse
- #exec_task(task, other = nil) ⇒ Object
-
#initialize(npc, init, trigger, motion, update) ⇒ Behaviour
constructor
A new instance of Behaviour.
- #on_init ⇒ Object
- #on_trigger(other) ⇒ Object
- #on_update ⇒ Object
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
#init ⇒ Object (readonly)
Returns the value of attribute init.
9 10 11 |
# File 'lib/game/npc/behaviour.rb', line 9 def init @init end |
#motion ⇒ Object (readonly)
Returns the value of attribute motion.
9 10 11 |
# File 'lib/game/npc/behaviour.rb', line 9 def motion @motion end |
#trigger ⇒ Object (readonly)
Returns the value of attribute trigger.
9 10 11 |
# File 'lib/game/npc/behaviour.rb', line 9 def trigger @trigger end |
#update ⇒ Object (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_init ⇒ Object
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_update ⇒ Object
29 30 31 32 |
# File 'lib/game/npc/behaviour.rb', line 29 def on_update exec_task(@update) exec_task(@motion) end |