]> git.lizzy.rs Git - Crafter.git/blob - mods/mob/api/timers.lua
Implement first prototype of pathfinding
[Crafter.git] / mods / mob / api / timers.lua
1 mobs.create_timer_functions = function(def,mob_register)
2         --this controls how fast the mob punches
3         mob_register.manage_punch_timer = function(self,dtime)
4                 if self.punch_timer > 0 then
5                         self.punch_timer = self.punch_timer - dtime
6                 end
7                 --this controls how fast you can punch the mob (punched timer reset)
8                 if self.punched_timer > 0 then
9                         --print(self.punched_timer)
10                         self.punched_timer = self.punched_timer - dtime
11                 end
12         end
13
14         --this controls the hostile state
15         if def.hostile == true or def.attacked_hostile == true then
16                 if def.hostile_cooldown == true then
17                         mob_register.manage_hostile_timer = function(self,dtime)
18                                 if self.hostile_timer > 0 then
19                                         self.hostile_timer = self.hostile_timer - dtime
20                                 end
21                                 if self.hostile_timer <= 0 then
22                                         self.hostile = false
23                                 end
24                         end
25                 end
26         end
27
28         mob_register.manage_hurt_color_timer = function(self,dtime)
29                 if self.hurt_color_timer > 0 then
30                         self.hurt_color_timer = self.hurt_color_timer - dtime
31                         if self.hurt_color_timer  <= 0 then
32                                 self.hurt_color_timer = 0
33                                 self.object:set_texture_mod("")
34                         end
35                 end
36         end
37
38         mob_register.manage_explode_timer = function(self,dtime)
39                 self.tnt_timer = self.tnt_timer - dtime
40                 self.tnt_tick_timer = self.tnt_tick_timer  - dtime
41                 if self.tnt_tick_timer <= 0 and not self.dead then
42                         self.tnt_tick_timer = self.explosion_blink_timer
43                         self.tnt_mod_state = math.abs(self.tnt_mod_state-1)
44                         if self.tnt_mod_state == 0 then
45                                 self.object:set_texture_mod("")
46                         else
47                                 self.object:set_texture_mod("^[colorize:"..self.explosion_blink_color..":130")
48                         end
49                         --print(self.object:get_texture_mod())
50                         --self.object:set_texture_mod("^[colorize:red:130")
51                 end
52                 if self.tnt_timer <= 0 and not self.dead then
53                         
54                         self.object:set_texture_mod("^[colorize:red:130")
55                         
56                         local pos = self.object:get_pos()
57                         self.object:remove()
58                         tnt(pos,self.explosion_power)
59                 end
60         end
61
62         mob_register.manage_projectile_timer = function(self,dtime)
63                 self.projectile_timer = self.projectile_timer - dtime
64         end
65
66         if def.friendly_in_daylight then
67                 mob_register.handle_friendly_in_daylight_timer = function(self,dtime)
68                         self.friendly_in_daylight_timer = self.friendly_in_daylight_timer + dtime
69                         if self.friendly_in_daylight_timer >= 2 then
70                                 self.friendly_in_daylight_timer = 0
71                                 local pos = self.object:get_pos()
72                                 if minetest.get_node_light(pos) >= 13 then --1 greater than torch light
73                                         if self.following == false then
74                                                 self.hostile = false
75                                         end
76                                 else
77                                         self.hostile = true
78                                 end
79                         end
80                 end
81         end
82
83         --this stops the pig from flying into the air
84         mob_register.manage_jump_timer = function(self,dtime)
85                 if self.jump_timer > 0 then
86                         self.jump_timer = self.jump_timer - dtime
87                 end
88         end
89         return(mob_register)
90 end