forked from mtcontrib/mobs_redo
tweak attack functions to use line of sight better
This commit is contained in:
parent
bdfce20c28
commit
a089d27db8
42
api.lua
42
api.lua
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
mobs = {}
|
mobs = {}
|
||||||
mobs.mod = "redo"
|
mobs.mod = "redo"
|
||||||
mobs.version = "20180504"
|
mobs.version = "20180505"
|
||||||
|
|
||||||
|
|
||||||
-- Intllib
|
-- Intllib
|
||||||
@ -1384,25 +1384,21 @@ local monster_attack = function(self)
|
|||||||
and (type == "player" or type == "npc"
|
and (type == "player" or type == "npc"
|
||||||
or (type == "animal" and self.attack_animals == true)) then
|
or (type == "animal" and self.attack_animals == true)) then
|
||||||
|
|
||||||
s = self.object:get_pos()
|
|
||||||
p = player:get_pos()
|
p = player:get_pos()
|
||||||
sp = s
|
sp = s
|
||||||
|
|
||||||
|
dist = get_distance(p, s)
|
||||||
|
|
||||||
-- aim higher to make looking up hills more realistic
|
-- aim higher to make looking up hills more realistic
|
||||||
p.y = p.y + 1
|
p.y = p.y + 1
|
||||||
sp.y = sp.y + 1
|
sp.y = sp.y + 1
|
||||||
|
|
||||||
dist = get_distance(p, s)
|
|
||||||
|
|
||||||
if dist < self.view_range then
|
-- choose closest player to attack
|
||||||
-- field of view check goes here
|
if dist < min_dist
|
||||||
|
and line_of_sight(self, sp, p, 2) == true then
|
||||||
-- choose closest player to attack
|
min_dist = dist
|
||||||
if line_of_sight(self, sp, p, 2) == true
|
min_player = player
|
||||||
and dist < min_dist then
|
|
||||||
min_dist = dist
|
|
||||||
min_player = player
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1435,10 +1431,16 @@ local npc_attack = function(self)
|
|||||||
if obj and obj.type == "monster" then
|
if obj and obj.type == "monster" then
|
||||||
|
|
||||||
p = obj.object:get_pos()
|
p = obj.object:get_pos()
|
||||||
|
sp = s
|
||||||
|
|
||||||
dist = get_distance(p, s)
|
dist = get_distance(p, s)
|
||||||
|
|
||||||
if dist < min_dist then
|
-- aim higher to make looking up hills more realistic
|
||||||
|
p.y = p.y + 1
|
||||||
|
sp.y = sp.y + 1
|
||||||
|
|
||||||
|
if dist < min_dist
|
||||||
|
and line_of_sight(self, sp, p, 2) == true then
|
||||||
min_dist = dist
|
min_dist = dist
|
||||||
min_player = obj.object
|
min_player = obj.object
|
||||||
end
|
end
|
||||||
@ -1512,7 +1514,6 @@ local runaway_from = function(self)
|
|||||||
if name ~= "" and name ~= self.name
|
if name ~= "" and name ~= self.name
|
||||||
and specific_runaway(self.runaway_from, name) then
|
and specific_runaway(self.runaway_from, name) then
|
||||||
|
|
||||||
s = self.object:get_pos()
|
|
||||||
p = player:get_pos()
|
p = player:get_pos()
|
||||||
sp = s
|
sp = s
|
||||||
|
|
||||||
@ -1522,15 +1523,12 @@ local runaway_from = function(self)
|
|||||||
|
|
||||||
dist = get_distance(p, s)
|
dist = get_distance(p, s)
|
||||||
|
|
||||||
if dist < self.view_range then
|
|
||||||
-- field of view check goes here
|
|
||||||
|
|
||||||
-- choose closest player/mpb to runaway from
|
-- choose closest player/mpb to runaway from
|
||||||
if line_of_sight(self, sp, p, 2) == true
|
if dist < min_dist
|
||||||
and dist < min_dist then
|
and line_of_sight(self, sp, p, 2) == true then
|
||||||
min_dist = dist
|
min_dist = dist
|
||||||
min_player = player
|
min_player = player
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user