Make mob punching time based

This commit is contained in:
jordan4ibanez 2021-04-22 20:20:56 -04:00
parent e1812b2cdb
commit 8530e6ee36
2 changed files with 59 additions and 69 deletions

View File

@ -685,8 +685,6 @@ mobs.mob_step = function(self, dtime)
end
-- can mob be pushed, if so calculate direction -- do this last (overrides everything)
if self.pushable then
mobs.collision(self)

View File

@ -80,6 +80,12 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
end
end
--don't do damage until pause timer resets
if self.pause_timer > 0 then
print(self.pause_timer)
return
end
-- error checking when mod profiling is enabled
if not tool_capabilities then
@ -93,6 +99,7 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
-- punch interval
local weapon = hitter:get_wielded_item()
local punch_interval = 1.4
-- exhaust attacker
@ -105,23 +112,9 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
local armor = self.object:get_armor_groups() or {}
local tmp
-- quick error check in case it ends up 0 (serialize.h check test)
if tflp == 0 then
tflp = 0.2
end
--calculate damage groups
for group,_ in pairs( (tool_capabilities.damage_groups or {}) ) do
tmp = tflp / (tool_capabilities.full_punch_interval or 1.4)
if tmp < 0 then
tmp = 0.0
elseif tmp > 1 then
tmp = 1.0
end
damage = damage + (tool_capabilities.damage_groups[group] or 0)
* tmp * ((armor[group] or 0) / 100.0)
damage = damage + (tool_capabilities.damage_groups[group] or 0) * ((armor[group] or 0) / 100.0)
end
if weapon then
@ -200,9 +193,7 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
-- die = true
--end
-- knock back effect (only on full punch)
if tflp >= punch_interval then
-- knock back effect
local velocity = self.object:get_velocity()
--2d direction
@ -252,9 +243,10 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
--add velocity breaks momentum - use set velocity
self.object:set_velocity(dir)
--0.4 seconds until you can hurt the mob again
self.pause_timer = 0.4
end
end -- END if damage
-- END if damage
-- if skittish then run away
--[[