Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions BT/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ local blackboard = {
},
eleanorSpBeforeCast = 0,
eleanorTriedCastSkill = false,
ownerLastX = 0,
ownerLastY = 0,
---@type UserConfig
userConfig = require 'AI.USER_AI.config',
myCooldowns = {
Expand Down Expand Up @@ -798,4 +800,6 @@ function YggAI(myid)
end
end
tree()
blackboard.ownerLastX = ownerX
blackboard.ownerLastY = ownerY
end
4 changes: 2 additions & 2 deletions BT/nodes/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function M.executePatrol(bb)
bb.patrolX, bb.patrolY = GetV(V_POSITION, bb.myId)
bb.destX = CommandData.destX
bb.destY = CommandData.destY
if bb.destX ~= bb.patrolX and bb.patrolY ~= bb.destY then
if bb.destX ~= bb.patrolX or bb.patrolY ~= bb.destY then
Move(bb.myId, bb.destX, bb.destY)
return STATUS.RUNNING
end
Expand Down Expand Up @@ -243,7 +243,7 @@ end

function M.executeSkillGround(bb)
local x, y = GetV(V_POSITION, bb.myId)
if x ~= CommandData.destX and y ~= CommandData.destY then
if x ~= CommandData.destX or y ~= CommandData.destY then
if 0 == SkillGround(bb.myId, CommandData.skillLevel, CommandData.skillId, CommandData.destX, CommandData.destY) then
List.pushleft(ResCmdList, NoCommand)
return STATUS.FAILURE
Expand Down
2 changes: 1 addition & 1 deletion BT/nodes/enemy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function M.hasEnemyGroup(minEnemies, maxDistance)
local myEnemyX, myEnemyY = GetV(V_POSITION, bb.myEnemy)
local sumX, sumY = myEnemyX, myEnemyY
for _, enemy in ipairs(bb.myEnemies) do
if enemy ~= bb.myEnemy and IsEnemyAlive(bb.myId, bb.myEnemy) then
if enemy ~= bb.myEnemy and IsEnemyAlive(bb.myId, enemy) then
local enemyX, enemyY = GetV(V_POSITION, enemy)
if enemyX ~= -1 then
local distance = GetDistance(myEnemyX, myEnemyY, enemyX, enemyY)
Expand Down
23 changes: 23 additions & 0 deletions BT/nodes/homun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
---@field patrol Node
---@field attackAndChase Node
---@field follow Node
---@field followAhead Node
---@field checkHomunStuck Node
---@field lastTimePatrol number
---@field isAmistr Condition
Expand Down Expand Up @@ -86,6 +87,28 @@ function M.follow(bb)
return STATUS.SUCCESS
end

function M.followAhead(bb)
local ownerX, ownerY = GetV(V_POSITION, bb.myOwner)
if ownerX == -1 then
return STATUS.RUNNING
end

local dx = ownerX - bb.ownerLastX
local dy = ownerY - bb.ownerLastY
local len = math.sqrt(dx * dx + dy * dy)

if len > 0 and len <= 15 then
local aheadDist = bb.userConfig.followDistance
local targetX = math.floor(ownerX + (dx / len) * aheadDist)
local targetY = math.floor(ownerY + (dy / len) * aheadDist)
Move(bb.myId, targetX, targetY)
else
MoveToOwner(bb.myId)
end

return STATUS.RUNNING
end

function M.checkHomunStuck(bb)
local enemyTarget = GetV(V_TARGET, bb.myEnemy)
local enemyMotion = GetV(V_MOTION, bb.myEnemy)
Expand Down
5 changes: 5 additions & 0 deletions BT/nodes/owner.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---@class OwnerNode
---@field isMoving Condition
---@field isOwnerMoving Condition
---@field isNotMoving Condition
---@field isNotTooFar Condition
---@field isMovingAway Condition
Expand All @@ -18,6 +19,10 @@ function M.isMoving(bb)
return false
end

function M.isOwnerMoving(bb)
return GetV(V_MOTION, bb.myOwner) == MOTION_MOVE
end

function M.isNotMoving(bb)
local ownerMotion = GetV(V_MOTION, bb.myOwner)
if ownerMotion == MOTION_STAND then
Expand Down
2 changes: 1 addition & 1 deletion BT/nodes/service.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function M.checkIsAttackingOwner(bb)
return STATUS.SUCCESS
end
for pos, enemy in ipairs(bb.myEnemies) do
if IsEnemyAlive(bb.myId, bb.myEnemy) then
if IsEnemyAlive(bb.myId, enemy) then
if GetV(V_TARGET, enemy) == bb.myOwner then
bb.ownerBeingTarget = true
bb.myEnemy = table.remove(bb.myEnemies, pos)
Expand Down
10 changes: 9 additions & 1 deletion UTIL/Homun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ local function root(combat)
Unless(
Selector {
Unless(fightEnemy, ownerNodes.isMovingAway),
Condition(homunNodes.follow, ownerNodes.isMoving),
Condition(
function(bb)
if bb.userConfig.followAhead then
return homunNodes.followAhead(bb)
end
return homunNodes.follow(bb)
end,
ownerNodes.isOwnerMoving
),
Unless(
Selector {
patrolWhenOwnerIsSitting,
Expand Down
1 change: 1 addition & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
local myConfig = {
homunLevel = 175,
lifUseHeal = false,
followAhead = true,
maxEnemiesToSearch = 15,
followDistance = 3,
patrolDistance = 7,
Expand Down