From 24cd099ddfb0a63e34d7fd02f3bab38a2e6e6411 Mon Sep 17 00:00:00 2001
From: yutio888 <yutio888@qq.com>
Date: Tue, 3 Aug 2021 08:38:18 +0800
Subject: [PATCH] Hydra's Bite correctly selects up to two nearby foes

---
 .../data/general/objects/world-artifacts.lua  | 20 ++++++++-----------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/game/modules/tome/data/general/objects/world-artifacts.lua b/game/modules/tome/data/general/objects/world-artifacts.lua
index 8a0fde05b5..d17d1ffd92 100644
--- a/game/modules/tome/data/general/objects/world-artifacts.lua
+++ b/game/modules/tome/data/general/objects/world-artifacts.lua
@@ -3681,23 +3681,19 @@ newEntity{ base = "BASE_WHIP", define_as = "HYDRA_BITE",
 		special_on_hit = {desc=_t"hit up to two adjacent enemies",on_kill=1, fct=function(combat, who, target)
 				local o, item, inven_id = who:findInAllInventoriesBy("define_as", "HYDRA_BITE")
 				if not o or not who:getInven(inven_id).worn then return end
+				if o.running == 1 then return end
+				o.running = 1
 				local tgts = {}
 				local twohits=1
 				for _, c in pairs(util.adjacentCoords(who.x, who.y)) do
-				local targ = game.level.map(c[1], c[2], engine.Map.ACTOR)
-				if targ and targ ~= target and who:reactionToward(target) < 0 then tgts[#tgts+1] = targ end
+					local targ = game.level.map(c[1], c[2], engine.Map.ACTOR)
+					if targ and targ ~= target and who:reactionToward(target) < 0 then tgts[#tgts+1] = targ end
 				end
 				if #tgts == 0 then return end
-					local target1 = rng.table(tgts)
-					local target2 = rng.table(tgts)
-					local tries = 0
-				while target1 == target2 and tries < 100 do
-					local target2 = rng.table(tgts)
-					tries = tries + 1
-				end
-				if o.running == 1 then return end
-				o.running = 1
-				if tries >= 100 or #tgts==1 then twohits=nil end
+				tgts = rng.tableSample(tgts, 2)
+			    local target1 = tgts[1]
+				local target2 = tgts[2]
+				if not target2 or target2 == target1 then twohits=nil end
 				if twohits then
 					who:logCombat(target1, "#Source#'s three headed flail lashes at #Target#%s!",who:canSee(target2) and (" and %s"):tformat(target2.name:capitalize()) or "")
 				else
-- 
GitLab