mirror of
https://github.com/ElCeejo/creatura.git
synced 2025-03-15 04:11:24 +00:00
Use tflp
This commit is contained in:
parent
40f842d9f3
commit
5f48a07665
2 changed files with 18 additions and 34 deletions
24
api.lua
24
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)
|
||||
|
|
28
mob_meta.lua
28
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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue