Commit 678bc0159270e15ce6ae45b3b6bf0d11a8de1e8d

Authored by DarkGod
2 parents b11d7b23 24cd099d

Merge branch 'fix_hydra' into 'master'

Fix Hydra's Bite correctly selects up to two nearby foes

Currently Hydra's Bite is very likely to hit only one target even if there are two foes nearby.

See merge request !775
... ... @@ -3681,23 +3681,19 @@ newEntity{ base = "BASE_WHIP", define_as = "HYDRA_BITE",
3681 3681 special_on_hit = {desc=_t"hit up to two adjacent enemies",on_kill=1, fct=function(combat, who, target)
3682 3682 local o, item, inven_id = who:findInAllInventoriesBy("define_as", "HYDRA_BITE")
3683 3683 if not o or not who:getInven(inven_id).worn then return end
  3684 + if o.running == 1 then return end
  3685 + o.running = 1
3684 3686 local tgts = {}
3685 3687 local twohits=1
3686 3688 for _, c in pairs(util.adjacentCoords(who.x, who.y)) do
3687   - local targ = game.level.map(c[1], c[2], engine.Map.ACTOR)
3688   - if targ and targ ~= target and who:reactionToward(target) < 0 then tgts[#tgts+1] = targ end
  3689 + local targ = game.level.map(c[1], c[2], engine.Map.ACTOR)
  3690 + if targ and targ ~= target and who:reactionToward(target) < 0 then tgts[#tgts+1] = targ end
3689 3691 end
3690 3692 if #tgts == 0 then return end
3691   - local target1 = rng.table(tgts)
3692   - local target2 = rng.table(tgts)
3693   - local tries = 0
3694   - while target1 == target2 and tries < 100 do
3695   - local target2 = rng.table(tgts)
3696   - tries = tries + 1
3697   - end
3698   - if o.running == 1 then return end
3699   - o.running = 1
3700   - if tries >= 100 or #tgts==1 then twohits=nil end
  3693 + tgts = rng.tableSample(tgts, 2)
  3694 + local target1 = tgts[1]
  3695 + local target2 = tgts[2]
  3696 + if not target2 or target2 == target1 then twohits=nil end
3701 3697 if twohits then
3702 3698 who:logCombat(target1, "#Source#'s three headed flail lashes at #Target#%s!",who:canSee(target2) and (" and %s"):tformat(target2.name:capitalize()) or "")
3703 3699 else
... ...