improved damage

This commit is contained in:
Alexsandro Percy 2023-06-18 22:14:27 -03:00
parent ca979a9490
commit 0509ddfe1c

View file

@ -65,6 +65,8 @@ function airutils.on_activate(self, staticdata, dtime_s)
else else
self.inv = inv self.inv = inv
end end
airutils.setText(self, self.infotext)
end end
function airutils.on_step(self,dtime,colinfo) function airutils.on_step(self,dtime,colinfo)
@ -458,10 +460,34 @@ function airutils.logic(self)
self._last_vel = self.object:get_velocity() self._last_vel = self.object:get_velocity()
end end
local function damage_vehicle(self, toolcaps, ttime, damage)
for group,_ in pairs( (toolcaps.damage_groups or {}) ) do
local tmp = ttime / (toolcaps.full_punch_interval or 1.4)
if tmp < 0 then
tmp = 0.0
elseif tmp > 1 then
tmp = 1.0
end
damage = damage + (toolcaps.damage_groups[group] or 0) * tmp
self.hp_max = self.hp_max - damage
airutils.setText(self, self.infotext)
end
end
function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage) function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage)
if self.hp_max <= 0 then if self.hp_max <= 0 then
airutils.destroy(self, true) airutils.destroy(self, true)
end end
airutils.setText(self, self.infotext)
-- lets permit destroying on the air
local is_flying = not self.colinfo.touching_ground
if is_flying and not puncher:is_player() then
damage_vehicle(self, toolcaps, ttime, damage)
end
--end
if not puncher or not puncher:is_player() then if not puncher or not puncher:is_player() then
return return
@ -531,7 +557,7 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage)
and toolcaps.damage_groups.fleshy and item_name ~= airutils.fuel then and toolcaps.damage_groups.fleshy and item_name ~= airutils.fuel then
--airutils.hurt(self,toolcaps.damage_groups.fleshy - 1) --airutils.hurt(self,toolcaps.damage_groups.fleshy - 1)
--airutils.make_sound(self,'hit') --airutils.make_sound(self,'hit')
self.hp_max = self.hp_max - 10 damage_vehicle(self, toolcaps, ttime, damage)
minetest.sound_play(self._collision_sound, { minetest.sound_play(self._collision_sound, {
object = self.object, object = self.object,
max_hear_distance = 5, max_hear_distance = 5,