From 5f48a07665577c814c7eac389fb3f30ff748489b Mon Sep 17 00:00:00 2001 From: ElCeejo Date: Mon, 26 Sep 2022 00:43:47 -0700 Subject: [PATCH] Use tflp --- api.lua | 24 +++++++++++++----------- mob_meta.lua | 28 +++++----------------------- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/api.lua b/api.lua index 06fbd12..85b5b0b 100644 --- a/api.lua +++ b/api.lua @@ -449,18 +449,20 @@ function creatura.basic_punch_func(self, puncher, tflp, tool_caps, dir) and contains_val(self.immune_to, tool_name)) then return end - self:apply_knockback(dir, 12) - if not tool_caps - or not tool_caps.damage_groups - or not tool_caps.damage_groups.fleshy then - tool_caps = { - damage_groups = { - fleshy = 2 - }, - full_punch_interval = 1.4 - } + local damage = 0 + local armor_grps = self.object:get_armor_groups() or self.armor_groups or {} + for group, val in pairs(tool_caps.damage_groups or {}) do + local dmg_x = tflp / (tool_caps.full_punch_interval or 1.4) + damage = damage + val * clamp(dmg_x, 0, 1) * ((armor_grps[group] or 0) / 100.0) + end + if damage > 0 then + local dist = vec_dist(self.object:get_pos(), puncher:get_pos()) + dir.y = 0.2 + if self.touching_ground then + self:apply_knockback(dir, (damage / dist) * 8) + end + self:hurt(damage) end - self:hurt(tool_caps.damage_groups.fleshy) if add_wear then local wear = floor((tool_caps.full_punch_interval / 75) * 9000) tool:add_wear(wear) diff --git a/mob_meta.lua b/mob_meta.lua index 4ebc855..588aeec 100644 --- a/mob_meta.lua +++ b/mob_meta.lua @@ -219,11 +219,7 @@ end function mob:apply_knockback(dir, power) if not dir then return end power = power or 6 - if not self.touching_ground then - power = power * 0.8 - end local knockback = vec_multi(dir, power) - knockback.y = abs(power * 0.22) self.object:add_velocity(knockback) end @@ -1000,25 +996,11 @@ function mob:_physics() --and not move_data.func and move_data.gravity ~= 0 then local vel = self.object:get_velocity() - if on_ground then - local nvel = vector.multiply(vel, 0.2) - if nvel.x < 0.2 - and nvel.z < 0.2 then - nvel.x = 0 - nvel.z = 0 - end - nvel.y = vel.y - self.object:set_velocity(nvel) - else - local nvel = vector.multiply(vel, 0.1) - if nvel.x < 0.2 - and nvel.z < 0.2 then - nvel.x = 0 - nvel.z = 0 - end - nvel.y = vel.y - self.object:set_velocity(nvel) - end + local friction = self.dtime * 10 + if friction > 0.5 then friction = 0.5 end + if not on_ground then friction = 0.25 end + local nvel = {x = vel.x * (1 - friction), y = vel.y, z = vel.z * (1 - friction)} + self.object:set_velocity(nvel) end end