From 0e4cc5ea4476bddfd8a0b3578865bed2a3707fea Mon Sep 17 00:00:00 2001 From: nixnoxus Date: Sun, 3 Mar 2024 10:15:44 +0100 Subject: [PATCH] fix shoot_raech and self attack --- mods/ENTITIES/mcl_mobs/combat.lua | 46 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/combat.lua b/mods/ENTITIES/mcl_mobs/combat.lua index b92bfbec0..53735d211 100644 --- a/mods/ENTITIES/mcl_mobs/combat.lua +++ b/mods/ENTITIES/mcl_mobs/combat.lua @@ -57,9 +57,9 @@ function mob_class:log2(msg, object) local src = self.object if object then local dst = object - minetest.log("# " .. name(src) .. " " .. msg .. " " .. vector.distance(src:get_pos(), dst:get_pos()) .. " " .. name(dst)) + minetest.log("# " .. msg .. " " .. name(src) .. " > " .. name(dst) .. " dist:" .. vector.distance(src:get_pos(), dst:get_pos()) .. " self:" .. dump(src == dst)) else - minetest.log("# " .. name(src) .. " " .. msg .. " ") + minetest.log("# " .. msg .. " " .. name(src)) end end @@ -390,7 +390,8 @@ function mob_class:monster_attack() player = obj.object name = obj.name or "" end - if obj and obj.type == self.type and obj.passive == false and obj.state == "attack" and obj.attack then + if obj and obj.type == self.type and obj.passive == false and obj.state == "attack" and obj.attack and self.object ~= obj.attack then + self:log2("add blacklist",obj.attack) table.insert(blacklist_attack, obj.attack) end end @@ -416,8 +417,10 @@ function mob_class:monster_attack() end end + -- find specific mob to attack, failing that attack player/npc/animal if specific_attack(self.specific_attack, name) + and self.object ~= player and (type == "player" or ( type == "npc" and self.attack_npcs ) or (type == "animal" and self.attack_animals == true) or (self.extra_hostile and not self.attack_exception(player))) then @@ -446,12 +449,17 @@ function mob_class:monster_attack() end end if not min_player and #blacklist_attack > 0 then + self:log2("pre OOPS monster_attack -> do_attack", min_player) min_player=blacklist_attack[math.random(#blacklist_attack)] end -- attack player if min_player then - self:log2("monster_attack -> do_attack", min_player) - self:do_attack(min_player) + if self.object == min_player then + self:log2("OOPS monster_attack -> do_attack", min_player) + else + self:log2("monster_attack -> do_attack", min_player) + self:do_attack(min_player) + end end end @@ -576,6 +584,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir) return end + self:log2("on_punch", hitter) -- custom punch function if self.do_punch then @@ -841,14 +850,14 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir) and obj.owner ~= name then if obj.name == self.name then --minetest.log("on_punch0 -> do_attack") - obj:log2("on_punch[0] -> do_attack", hitter) + obj:log2("group on_punch[0] -> do_attack", hitter) obj:do_attack(hitter) elseif type(obj.group_attack) == "table" then for i=1, #obj.group_attack do if obj.group_attack[i] == self.name then obj._aggro = true --minetest.log("on_punch1 -> do_attack") - obj:log2("on_punch[1] -> do_attack", hitter) + obj:log2("group on_punch[1] -> do_attack", hitter) obj:do_attack(hitter) break end @@ -1029,7 +1038,7 @@ function mob_class:do_states_attack (dtime) end elseif self.attack_type == "dogfight" - or (self.attack_type == "dogshoot" and self:dogswitch(dtime) == 2) and (dist >= self.avoid_distance or not self.shooter_avoid_enemy) + or (self.attack_type == "dogshoot" and self:dogswitch(dtime) == 2 and (dist >= self.avoid_distance or not self.shooter_avoid_enemy)) or (self.attack_type == "dogshoot" and dist <= self.reach and self:dogswitch() == 0) then if self.fly @@ -1169,19 +1178,19 @@ function mob_class:do_states_attack (dtime) s2.y = s2.y + .5 if self:line_of_sight( p2, s2) == true then - minetest.log("shoot3 " .. self.reach .. " < " .. dist .. "<" .. self.shoot_reach + minetest.log("dogfight2 " .. dist .. "<" .. self.reach .. " sae:".. dump(self.shooter_avoid_enemy) .. " sa:" .. dump(self.shoot_arrow and true or false)) self:mob_sound("attack") - self:log2("do_state_attack", self.attack) -- punch player (or what player is attached to) local attached = self.attack:get_attach() if attached then self.attack = attached end + self:log2("do_state_attack", self.attack) self.attack:punch(self.object, 1.0, { full_punch_interval = 1.0, damage_groups = {fleshy = self.damage} @@ -1197,26 +1206,15 @@ function mob_class:do_states_attack (dtime) end end end - --[[ - elseif self.attack_type == "dogfight" - or (self.attack_type == "dogshoot" and self:dogswitch(dtime) == 2) and (dist >= self.avoid_distance or not self.shooter_avoid_enemy) - or (self.attack_type == "dogshoot" and dist <= self.reach and self:dogswitch() == 0) then - --]] - - --[[ - elseif dist < self.shoot_reach and (self.attack_type == "shoot" + elseif dist <= self.shoot_reach and (self.attack_type == "shoot" or (self.attack_type == "dogshoot" and self:dogswitch(dtime) == 1) - or (self.attack_type == "dogshoot" and (dist > self.reach or dist < self.avoid_distance and self.shooter_avoid_enemy) and self:dogswitch() == 0)) then - ]]-- - elseif self.attack_type == "shoot" - or (self.attack_type == "dogshoot" and self:dogswitch(dtime) == 1) - or (self.attack_type == "dogshoot" and (dist > self.reach or dist < self.avoid_distance and self.shooter_avoid_enemy) and self:dogswitch() == 0) then + or (self.attack_type == "dogshoot" and ((dist > self.reach or dist < self.avoid_distance) and self.shooter_avoid_enemy) and self:dogswitch() == 0)) then p.y = p.y - .5 s.y = s.y + .5 --#self:log2("shoot 3", object) - minetest.log("shoot3 " .. self.reach .. " < " .. dist .. "<" .. self.shoot_reach + minetest.log("shoot3 " .. dist .. "<=" .. self.shoot_reach .. " sae:".. dump(self.shooter_avoid_enemy) .. " sa:" .. dump(self.shoot_arrow and true or false)) local dist = vector.distance(p, s)