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 end
-- can mob be pushed, if so calculate direction -- do this last (overrides everything) -- can mob be pushed, if so calculate direction -- do this last (overrides everything)
if self.pushable then if self.pushable then
mobs.collision(self) mobs.collision(self)

View File

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