From 12e9c2c6d038ac996a3189ec3ee8619b3d56228a Mon Sep 17 00:00:00 2001 From: epCode <64379263+epCode@users.noreply.github.com> Date: Thu, 13 Oct 2022 16:41:45 -0700 Subject: [PATCH 1/3] make all hostile mobs attack a little more strategically. --- mods/ENTITIES/mcl_mobs/api.lua | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index a4b74a237..49c151a32 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2039,8 +2039,24 @@ local monster_attack = function(self) local type, name = "", "" local min_dist = self.view_range + 1 local objs = minetest.get_objects_inside_radius(s, self.view_range) + local blacklist_attack = {} for n = 1, #objs do + if not objs[n]:is_player() then + obj = objs[n]:get_luaentity() + + if obj then + player = obj.object + name = obj.name or "" + end + if name == self.name and obj.state == "attack" and obj.attack then + table.insert(blacklist_attack, obj.attack) + end + end + end + + for n = 1, #objs do + if objs[n]:is_player() then if mcl_mobs.invis[ objs[n]:get_player_name() ] or (not object_in_range(self, objs[n])) then @@ -2058,6 +2074,7 @@ local monster_attack = function(self) type = obj.type name = obj.name or "" end + end -- find specific mob to attack, failing that attack player/npc/animal @@ -2074,16 +2091,24 @@ local monster_attack = function(self) p.y = p.y + 1 sp.y = sp.y + 1 - + local attacked_p = false + for c=1, #blacklist_attack do + if blacklist_attack[c] == player then + attacked_p = true + end + end -- choose closest player to attack if dist < min_dist + and not attacked_p and line_of_sight(self, sp, p, 2) == true then min_dist = dist min_player = player end end end - + if not min_player then + min_player=blacklist_attack[math.random(#blacklist_attack)] + end -- attack player if min_player then do_attack(self, min_player) From b27c81cea45606ba2746df586c006a1bc1a366d9 Mon Sep 17 00:00:00 2001 From: epCode <64379263+epCode@users.noreply.github.com> Date: Thu, 13 Oct 2022 16:53:01 -0700 Subject: [PATCH 2/3] make mobs coordinate attacks with all other similar alliances. --- mods/ENTITIES/mcl_mobs/api.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 49c151a32..87d8d7372 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2049,7 +2049,7 @@ local monster_attack = function(self) player = obj.object name = obj.name or "" end - if name == self.name and obj.state == "attack" and obj.attack then + if obj.type = self.type and obj.passive == false and obj.state == "attack" and obj.attack then table.insert(blacklist_attack, obj.attack) end end From 27ac33387827657554d86a485b7796e0f0dac249 Mon Sep 17 00:00:00 2001 From: epCode <64379263+epCode@users.noreply.github.com> Date: Thu, 13 Oct 2022 16:59:32 -0700 Subject: [PATCH 3/3] fix syntax crash --- mods/ENTITIES/mcl_mobs/api.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 87d8d7372..186fd0473 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2049,7 +2049,7 @@ local monster_attack = function(self) player = obj.object name = obj.name or "" end - if obj.type = self.type and obj.passive == false and obj.state == "attack" and obj.attack then + if obj.type == self.type and obj.passive == false and obj.state == "attack" and obj.attack then table.insert(blacklist_attack, obj.attack) end end