-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity.lua
175 lines (156 loc) · 5.12 KB
/
entity.lua
1
2
3
4
5
6
7
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
local rad = math.rad
local random = water_life.random
local function update_nametag(self)
if not self or not self.object then return end
self.object:set_nametag_attributes({
color = '#ff7373',
text = tostring(math.floor(self.hp))..
"%hp "..tostring(math.floor(self.hunger)).."%st",
})
end
-- the eagle itself
minetest.register_entity('aerotest:eagle',{
physical = true,
collisionbox = {-0.3,0,-0.3,0.3,0.8,0.3},
visual = "mesh",
visual_size = {x = 2, y = 2},
mesh = "aerotest_eagle.b3d",
textures = {"aerotest_eagle.png"},
makes_footstep_sound = false,
timeout=-5, -- 24h
buoyancy = 0.7,
static_save = false,
view_range = water_life.abo*12,
max_hp = 100,
hunger = 100,
xhaust = 100,
max_speed = 1,
jump_height = 2,
owner = "",
drops = {
{name = "default:diamond", chance = 10, min = 1, max = 1,},
{name = "water_life:meat_raw", chance = 2, min = 1, max = 2,},
},
animation = {
idle={range={x=0,y=89},speed=10,loop=true},
start={range={x=90,y=127},speed=20,loop=true},
land={range={x=142,y=90},speed=-10,loop=false},
fly={range={x=143,y=163},speed=20,loop=true},
glide={range={x=165,y=185},speed=20,loop=true},
},
sounds = {cry="aerotest_eagle"},
action = "idle",
attack={range=0.8,damage_groups={fleshy=7}},
on_step = mobkit.stepfunc,
on_activate=mobkit.actfunc,
get_staticdata = mobkit.statfunc,
logic = function(self)
self.hunger = mobkit.recall(self,"hunger") or 100
self.xhaust = mobkit.recall(self,"xhaust") or 100
if (self.action == "fly" or self.action == "glide") and aerotest.arrows then
local eagle = self.object:get_pos()
local attacker = aerotest.find_attacker(eagle,3)
if attacker then
mobkit.clear_queue_low(self)
mobkit.clear_queue_high(self)
aerotest.hq_hunt(self,50,attacker)
end
end
if self.hp <= 0 or self.hunger <= -25 then
mobkit.clear_queue_high(self)
water_life.handle_drops(self)
mobkit.hq_die(self)
return
end
if mobkit.timer(self,aerotest.hunt_intervall) and aerotest.hunter then
if self.action == "fly" or self.action == "glide" then
local gotone = aerotest.look_for_prey(self)
if gotone then
mobkit.clear_queue_low(self)
mobkit.clear_queue_high(self)
aerotest.hq_hunt(self,1,gotone)
end
end
end
if mobkit.timer(self,1) then
if self.action == "fly" or self.action == "glide" then
local player = mobkit.get_nearby_player(self)
if player and player:is_player() then
local center = player:get_pos()
local eagle = self.object:get_pos()
center.y = eagle.y
if vector.distance(center,eagle) > (water_life.abo*16-10) then
mobkit.clear_queue_low(self)
mobkit.clear_queue_high(self)
aerotest.hq_keepinrange(self,10,center)
end
end
end
local meal = random(100)
if (meal > self.hunger) and aerotest.hunter then
local gotone = aerotest.look_for_prey(self)
if gotone then
mobkit.clear_queue_low(self)
mobkit.clear_queue_high(self)
aerotest.hq_hunt(self,10,gotone)
end
end
if water_life.radar_debug then
update_nametag(self)
end
if random(100) < 2 then mobkit.make_sound(self,'cry') end
local pos = self.object:get_pos()
local plyr = mobkit.get_nearby_player(self)
if self.action == "idle" and plyr and
vector.distance(pos,plyr:get_pos()) < 8 and not water_life.radar_debug then
mobkit.clear_queue_low(self)
mobkit.clear_queue_high(self)
aerotest.hq_takeoff(self,rad(random(360)),10) --panic takeoff
end
if vector.length(self.object:get_velocity()) < 2 and
self.action ~= "idle" and self.action ~= "search" then
mobkit.clear_queue_low(self)
mobkit.clear_queue_high(self)
mobkit.hurt(self,5)
if water_life.radar_debug then
update_nametag(self)
end
aerotest.hq_idle(self,1)
end
mobkit.remember(self,"hunger",self.hunger)
mobkit.remember(self,"xhaust",self.xhaust)
end
if mobkit.is_queue_empty_high(self) then
if self.action == "idle" then
if self.isinliquid then
local yaw = self.object:get_yaw()
aerotest.hq_takeoff(self,yaw,5)
elseif not self.isonground then
aerotest.hq_climb(self,1)
else
aerotest.hq_idle(self,1)
end
else
aerotest.hq_climb(self,1)
end
end
end,
on_punch=function(self, puncher, time_from_last_punch, tool_capabilities, dir)
if mobkit.is_alive(self) then
local obj = self.object
if time_from_last_punch < 1 then
return
end
local hvel = vector.multiply(vector.normalize({x=dir.x,y=0,z=dir.z}),4)
self.object:set_velocity({x=hvel.x,y=2,z=hvel.z})
mobkit.hurt(self,tool_capabilities.damage_groups.fleshy or 1)
if water_life.radar_debug then
update_nametag(obj)
end
if self.isonground or self.isinliquid then
mobkit.clear_queue_high(self)
aerotest.hq_takeoff(self,rad(random(360)),20,6)
end
end
end,
})