diff --git a/game/engine/Actor.lua b/game/engine/Actor.lua index 6e59f35c0010deeda8a9a9ee3baee01105032060..9238bcb66e1d857a68761fa8eabf97c517af7950 100644 --- a/game/engine/Actor.lua +++ b/game/engine/Actor.lua @@ -264,3 +264,13 @@ function _M:attr(prop, v, fix) end end end + +--- Are we within a certain distance of the target +-- @param x the spot we test for near-ness +-- @param y the spot we test for near-ness +-- @param radius how close we should be (defaults to 1) +function _M:isNear(x, y, radius) + radius = radius or 1 + if math.floor(core.fov.distance(self.x, self.y, x, y)) > radius then return false end + return true +end diff --git a/game/engine/ai/special_movements.lua b/game/engine/ai/special_movements.lua new file mode 100644 index 0000000000000000000000000000000000000000..f2cdac544e1e463741242d2c40f3dfb9f6dc049e --- /dev/null +++ b/game/engine/ai/special_movements.lua @@ -0,0 +1,39 @@ +-- Defines some special movement AIs + +-- Ghoul AI: move, pause, move pause, ... +newAI("move_ghoul", function(self) + if self.ai_target.actor then + if not rng.percent(self.ai_state.pause_chance or 30) then + local tx, ty = self:aiSeeTargetPos(self.ai_target.actor) + return self:moveDirection(tx, ty) + else + self:useEnergy() + return true + end + end +end) + +-- Snake AI: move in the general direction but "slide" along +newAI("move_snake", function(self) + if self.ai_target.actor then + local tx, ty = self:aiSeeTargetPos(self.ai_target.actor) + -- We we are in striking distance, strike! + if self:isNear(tx, ty) then + return self:moveDirection(tx, ty) + else + local rd = rng.range(1, 3) + if rd == 1 then + -- nothing, we move in the coerct direction + elseif rd == 2 then + -- move to the left + local dir = util.getDir(tx, ty, self.x, self.y) + tx, ty = util.coordAddDir(self.x, self.y, dir_sides[dir].left) + elseif rd == 3 then + -- move to the right + local dir = util.getDir(tx, ty, self.x, self.y) + tx, ty = util.coordAddDir(self.x, self.y, dir_sides[dir].right) + end + return self:moveDirection(tx, ty) + end + end +end) diff --git a/game/engine/ai/talented.lua b/game/engine/ai/talented.lua index 6eaecce96c833cf32fa749359b3e92545f37825e..cabdc8f611e8e97f3fb591322a5a384f8138ba5c 100644 --- a/game/engine/ai/talented.lua +++ b/game/engine/ai/talented.lua @@ -30,7 +30,7 @@ newAI("dumb_talented_simple", function(self) self:runAI("dumb_talented") end if not self.energy.used then - self:runAI(self.ai_move or "move_simple") + self:runAI(self.ai_state.ai_move or "move_simple") end return true end diff --git a/game/modules/tome/data/general/npcs/ghoul.lua b/game/modules/tome/data/general/npcs/ghoul.lua index 42966fc6a6127137f40ca9bade328cb532654382..59770931ffcf81680e921c8270f43e28871e0b79 100644 --- a/game/modules/tome/data/general/npcs/ghoul.lua +++ b/game/modules/tome/data/general/npcs/ghoul.lua @@ -10,7 +10,7 @@ newEntity{ body = { INVEN = 10, MAINHAND=1, OFFHAND=1, BODY=1 }, drops = resolvers.drops{chance=70, nb=1, {type="money"}, {} }, autolevel = "ghoul", - ai = "dumb_talented_simple", ai_state = { talent_in=2, }, + ai = "dumb_talented_simple", ai_state = { talent_in=2, ai_move="move_ghoul", }, energy = { mod=1 }, stats = { str=14, dex=12, mag=10, con=12 }, @@ -56,7 +56,7 @@ newEntity{ base = "BASE_NPC_GHOUL", rarity = 10, max_life = resolvers.rngavg(90,100), combat_armor = 3, combat_def = 10, - ai_state = { talent_in=2, }, + ai_state = { talent_in=2, ai_pause=20 }, combat = { dam=10, atk=8, apr=4, dammod={str=0.6} }, diff --git a/game/modules/tome/data/general/npcs/snake.lua b/game/modules/tome/data/general/npcs/snake.lua index 4bfe228535d47b4d880f3c57c9439a4e713415fb..14773b503fdf2d0dee5d604f712ca6b205fd14cc 100644 --- a/game/modules/tome/data/general/npcs/snake.lua +++ b/game/modules/tome/data/general/npcs/snake.lua @@ -9,7 +9,7 @@ newEntity{ max_stamina = 110, autolevel = "warrior", - ai = "dumb_talented_simple", ai_state = { talent_in=3, }, + ai = "dumb_talented_simple", ai_state = { talent_in=3, ai_move="move_snake" }, energy = { mod=1.3 }, stats = { str=14, dex=23, mag=5, con=5 }, combat_armor = 1, combat_def = 1,