Skip to content

Commit

Permalink
Add feature for prewalk and lower option delays for better experience
Browse files Browse the repository at this point in the history
  • Loading branch information
nekiro committed Jan 14, 2025
1 parent d1a9cec commit cde710e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 24 deletions.
6 changes: 3 additions & 3 deletions modules/client_options/data_options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,23 @@ return {
end
},
walkTurnDelay = {
value = 250,
value = 100,
action = function(value, options, controller, panels, extraWidgets)
panels.generalPanel:recursiveGetChildById('walkTurnDelay'):setText(string.format(
'Walk delay after turn: %sms',
value))
end
},
walkTeleportDelay = {
value = 250,
value = 50,
action = function(value, options, controller, panels, extraWidgets)
panels.generalPanel:recursiveGetChildById('walkTeleportDelay'):setText(string.format(
'Walk delay after teleport: %sms',
value))
end
},
walkStairsDelay = {
value = 250,
value = 50,
action = function(value, options, controller, panels, extraWidgets)
panels.generalPanel:recursiveGetChildById('walkStairsDelay'):setText(string.format(
'Walk delay after floor change: %sms',
Expand Down
5 changes: 3 additions & 2 deletions modules/game_features/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ controller:registerEvents(g_game, {
-- g_game.enableFeature(GameNegativeOffset)
-- g_game.enableFeature(GameWingsAurasEffectsShader)
-- g_game.enableFeature(GameAllowCustomBotScripts)


g_game.enableFeature(GameAllowPreWalk)
g_game.enableFeature(GameFormatCreatureName)

if version >= 750 then
Expand Down Expand Up @@ -226,7 +227,7 @@ controller:registerEvents(g_game, {
end

if version >= 1314 then
g_game.disableFeature(GameTournamentPackets)
g_game.disableFeature(GameTournamentPackets)
g_game.enableFeature(GameDynamicForgeVariables)
end

Expand Down
48 changes: 31 additions & 17 deletions modules/game_walk/walk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,21 @@ function walk(dir)

nextWalkDir = nil

local toPos = Position.translatedToDirection(player:getPosition(), dir)
local toTile = g_map.getTile(toPos)
if toTile and toTile:isWalkable() then
if not player:isPreWalking() then
player:preWalk(dir)
end
else
-- check for stairs/elevation steps
if not canChangeFloorDown(toPos) and not canChangeFloorUp(toPos) then
return false
end
if g_game.getFeature(GameAllowPreWalk) then
local toPos = Position.translatedToDirection(player:getPosition(), dir)
local toTile = g_map.getTile(toPos)
if toTile and toTile:isWalkable() then
if not player:isPreWalking() then
player:preWalk(dir)
end
else
-- check for stairs/elevation steps
if not canChangeFloorDown(toPos) and not canChangeFloorUp(toPos) then
return false
end

player:lockWalk(200)
player:lockWalk(200)
end
end

g_game.walk(dir)
Expand Down Expand Up @@ -234,21 +236,31 @@ end

function addWalkEvent(dir, delay)
cancelWalkEvent()
walkEvent = scheduleEvent(function()

local function walkCallback()
if g_keyboard.getModifiers() ~= KeyboardNoModifier then
return
end

local direction = smartWalkDir or dir
walk(direction)
end, delay or 10)
end

if delay and delay == 0 then
walkEvent = addEvent(walkCallback)
return
end

walkEvent = scheduleEvent(walkCallback, delay or 10)
end

function cancelWalkEvent()
if walkEvent then
removeEvent(walkEvent)
walkEvent = nil
end

nextWalkDir = nil
end

-- events
Expand All @@ -268,10 +280,12 @@ end

function onWalkFinish(player)
if nextWalkDir then
addWalkEvent(nextWalkDir)
if not g_game.getFeature(GameAllowPreWalk) then
walk(nextWalkDir)
else
addWalkEvent(nextWalkDir)
end
end

nextWalkDir = nil
end

function onCancelWalk(player)
Expand Down
5 changes: 3 additions & 2 deletions modules/gamelib/const.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ DirectionString = {
[SouthEast] = "South East",
[SouthWest] = "South West",
[NorthWest] = "North West"
}
}

FightOffensive = 1
FightBalanced = 2
FightDefensive = 3
Expand Down Expand Up @@ -214,6 +214,7 @@ GameWingsAurasEffectsShader = 118
GameForgeConvergence = 119
GameAllowCustomBotScripts = 120
GameColorizedLootValue = 121
GameAllowPreWalk = 122

TextColors = {
red = '#f55e5e', -- '#c83200'
Expand Down
1 change: 1 addition & 0 deletions src/client/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ namespace Otc
GameForgeConvergence = 119,
GameAllowCustomBotScripts = 120,
GameColorizedLootValue = 121,
GameAllowPreWalk = 122,
LastGameFeature
};

Expand Down

0 comments on commit cde710e

Please sign in to comment.