Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
36a83c6
fixes
mehah Feb 3, 2025
05894f2
Update localplayer.h
mehah Feb 3, 2025
bc2704e
Update localplayer.cpp
mehah Feb 3, 2025
2928194
fix autowalk
mehah Feb 4, 2025
911ceba
Update protocolgameparse.cpp
mehah Feb 4, 2025
41fdd73
fix
mehah Feb 4, 2025
cabfca7
Update protocolgameparse.cpp
mehah Feb 4, 2025
e40f885
Update localplayer.cpp
mehah Feb 4, 2025
25f767c
Merge branch 'main' into fix_newwalking
Nottinghster Feb 4, 2025
5cc34c8
improve
mehah Feb 5, 2025
b861943
improve
mehah Feb 5, 2025
ffbbf15
fix autowalk
mehah Feb 5, 2025
3098a14
Update walk.lua
mehah Feb 5, 2025
0a849cb
Update walk.lua
mehah Feb 5, 2025
92d23cb
Update walk.lua
mehah Feb 5, 2025
c87ffa6
Update walk.lua
mehah Feb 5, 2025
f778224
Update walk.lua
mehah Feb 5, 2025
d8706ce
Update walk.lua
mehah Feb 5, 2025
d5982e9
Update localplayer.cpp
mehah Feb 5, 2025
b533a77
cleanup
mehah Feb 5, 2025
25d5ebf
IMPROVE
mehah Feb 5, 2025
c4f957a
update
mehah Feb 6, 2025
ffdc248
update
mehah Feb 6, 2025
4d6ed37
Revert "update"
mehah Feb 6, 2025
932d513
improve
mehah Feb 6, 2025
615064a
Update localplayer.cpp
mehah Feb 6, 2025
ada38c8
update
mehah Feb 6, 2025
a82480e
Update localplayer.h
mehah Feb 6, 2025
756c2ce
Update walk.lua
mehah Feb 6, 2025
109e968
Update walk.lua
mehah Feb 6, 2025
0597ebd
improve relative ping
mehah Feb 6, 2025
987bb23
update
mehah Feb 6, 2025
0ed1159
Update localplayer.cpp
mehah Feb 7, 2025
49ba8e2
update
mehah Feb 7, 2025
c9f2dbd
update
mehah Feb 7, 2025
079317f
fixes
mehah Feb 7, 2025
9bc25ce
improve
mehah Feb 7, 2025
220aca1
update
mehah Feb 7, 2025
65412b3
fixes
mehah Feb 8, 2025
6635d14
Merge branch 'main' into fix_newwalking
Nottinghster Feb 10, 2025
9e5f3de
fixes
mehah Feb 10, 2025
d1cd460
cleanup
mehah Feb 10, 2025
a86e163
Update game.cpp
mehah Feb 10, 2025
80df75c
Update game.cpp
mehah Feb 10, 2025
23a403b
Update protocolgamesend.cpp
mehah Feb 10, 2025
46e2cd7
Update walk.lua
mehah Feb 10, 2025
d5439f4
update
mehah Feb 10, 2025
f5edff1
Update walk.lua
mehah Feb 10, 2025
0abfc3d
Update walk.lua
mehah Feb 10, 2025
3de7e05
Update localplayer.h
mehah Feb 10, 2025
fd22ad8
Update walk.lua
mehah Feb 10, 2025
c44514a
Update localplayer.cpp
mehah Feb 10, 2025
f950421
update
mehah Feb 11, 2025
5664424
Update localplayer.cpp
mehah Feb 11, 2025
742b893
improve
mehah Feb 11, 2025
a7b6a7d
update
mehah Feb 11, 2025
0b878ee
Update creature.cpp
mehah Feb 11, 2025
e4e8cad
update
mehah Feb 11, 2025
4107cf2
Update localplayer.cpp
mehah Feb 11, 2025
5e67185
update
mehah Feb 11, 2025
b6734a9
fixes
mehah Feb 12, 2025
c6e163c
init
mehah Feb 12, 2025
ad5c837
update
mehah Feb 12, 2025
c8ac958
Update localplayer.cpp
mehah Feb 12, 2025
7fafaef
Update localplayer.cpp
mehah Feb 12, 2025
0e19cb3
update
mehah Feb 12, 2025
716a328
Update localplayer.cpp
mehah Feb 12, 2025
e5497dc
Update localplayer.cpp
mehah Feb 12, 2025
e6c6689
Update localplayer.cpp
mehah Feb 12, 2025
70708ab
Update localplayer.cpp
mehah Feb 12, 2025
ac16984
Update localplayer.cpp
mehah Feb 12, 2025
e81a1fa
Update localplayer.cpp
mehah Feb 12, 2025
bd01f48
Update game.h
mehah Feb 12, 2025
9af251c
Revert "Update game.h"
mehah Feb 12, 2025
cfc8475
Update localplayer.cpp
mehah Feb 12, 2025
b707b59
Update localplayer.cpp
mehah Feb 12, 2025
ba5d324
fixes
mehah Feb 13, 2025
92bdab2
Update localplayer.cpp
mehah Feb 13, 2025
d5ff094
Update localplayer.cpp
mehah Feb 13, 2025
c675ecb
Update localplayer.cpp
mehah Feb 13, 2025
31eb839
update
mehah Feb 13, 2025
a2e7b6e
getWalkMaxSteps
mehah Feb 13, 2025
d017c23
Update luafunctions.cpp
mehah Feb 13, 2025
c1410ec
Update localplayer.cpp
mehah Feb 13, 2025
6b68d47
update
mehah Feb 13, 2025
7793335
fixes
mehah Feb 13, 2025
70e4eba
Update localplayer.cpp
mehah Feb 13, 2025
d7ee36e
update
mehah Feb 14, 2025
c5259ae
Update game.cpp
mehah Feb 14, 2025
a531694
update
mehah Feb 14, 2025
a356049
Update localplayer.h
mehah Feb 14, 2025
84e724e
Update creature.cpp
mehah Feb 14, 2025
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
2 changes: 1 addition & 1 deletion meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2713,7 +2713,7 @@ function Tile:isFullyOpaque() end
function Tile:isLookPossible() end

---@return boolean
function Tile:hasCreature() end
function Tile:hasCreatures() end

---@return boolean
function Tile:isEmpty() end
Expand Down
1 change: 1 addition & 0 deletions modules/game_features/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ controller:registerEvents(g_game, {

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

if version >= 750 then
g_game.enableFeature(GameSoul)
Expand Down
115 changes: 66 additions & 49 deletions modules/game_walk/walk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,31 @@ local smartWalkDirs = {}
local smartWalkDir = nil
local walkEvent = nil
local lastTurn = 0
local lastCancelWalkTime = 0
local nextWalkDir = nil
local lastCancelWalkTime = 0


local keys = {
{ "Up", North },
{ "Right", East },
{ "Down", South },
{ "Left", West },
{ "Numpad8", North },
{ "Numpad9", NorthEast },
{ "Numpad6", East },
{ "Numpad3", SouthEast },
{ "Numpad2", South },
{ "Numpad1", SouthWest },
{ "Numpad4", West },
{ "Numpad7", NorthWest },
}

local turnKeys = {
{ "Ctrl+Up", North },
{ "Ctrl+Right", East },
{ "Ctrl+Down", South },
{ "Ctrl+Left", West },
}

WalkController = Controller:new()

Expand Down Expand Up @@ -37,23 +60,32 @@ end
--- Makes the player walk in the given direction.
local function walk(dir)
local player = g_game.getLocalPlayer()
if not player or g_game.isDead() or player:isDead() or player:isWalkLocked() then
cancelWalkEvent()
if not player or g_game.isDead() or player:isDead() then
return
end

if not player:canWalk(dir) then
nextWalkDir = dir
if player:isWalkLocked() then
nextWalkDir = nil
return
end

if g_game.isFollowing() then
g_game.cancelFollow()
end

if player:isAutoWalking() then
player:stopAutoWalk()
local isAutoWalking = player:isAutoWalking()
if isAutoWalking or player:isServerWalking() then
g_game.stop()
if isAutoWalking then
player:stopAutoWalk()
end
player:lockWalk(player:getStepDuration() + 50)
return
end

if not player:canWalk() then
nextWalkDir = dir
return
end

nextWalkDir = nil
Expand All @@ -75,20 +107,16 @@ local function walk(dir)
end

--- Adds a walk event with an optional delay.
local function addWalkEvent(dir, delay)
if os.time() - lastCancelWalkTime > 10 then
local function addWalkEvent(dir)
if os.time() - lastCancelWalkTime > 20 then
cancelWalkEvent()
lastCancelWalkTime = os.time()
end

local function walkCallback()
if g_keyboard.getModifiers() ~= KeyboardNoModifier then
return
walkEvent = addEvent(function()
if g_keyboard.getModifiers() == KeyboardNoModifier then
walk(smartWalkDir or dir)
end
walk(smartWalkDir or dir)
end

walkEvent = delay == 0 and addEvent(walkCallback) or scheduleEvent(walkCallback, delay or 5)
end)
end

--- Initiates a smart walk in the given direction.
Expand Down Expand Up @@ -138,8 +166,8 @@ local function turn(dir, repeated)

cancelWalkEvent()

local TURN_DELAY_REPEATED = 1000
local TURN_DELAY_DEFAULT = 200
local TURN_DELAY_REPEATED = 150
local TURN_DELAY_DEFAULT = 50

local delay = repeated and TURN_DELAY_REPEATED or TURN_DELAY_DEFAULT

Expand All @@ -155,35 +183,13 @@ end
local function bindKeys()
modules.game_interface.getRootPanel():setAutoRepeatDelay(200)

local keys = {
{ "Up", North },
{ "Right", East },
{ "Down", South },
{ "Left", West },
{ "Numpad8", North },
{ "Numpad9", NorthEast },
{ "Numpad6", East },
{ "Numpad3", SouthEast },
{ "Numpad2", South },
{ "Numpad1", SouthWest },
{ "Numpad4", West },
{ "Numpad7", NorthWest },
}

for _, keyDir in ipairs(keys) do
bindWalkKey(keyDir[1], keyDir[2])
end

local turnKeys = {
{ "Ctrl+Up", North },
{ "Ctrl+Right", East },
{ "Ctrl+Down", South },
{ "Ctrl+Left", West },
}
for _, keyDir in ipairs(keys) do bindWalkKey(keyDir[1], keyDir[2]) end
for _, keyDir in ipairs(turnKeys) do bindTurnKey(keyDir[1], keyDir[2]) end
end

for _, keyDir in ipairs(turnKeys) do
bindTurnKey(keyDir[1], keyDir[2])
end
local function unbindKeys()
for _, keyDir in ipairs(keys) do unbindWalkKey(keyDir[1]) end
for _, keyDir in ipairs(turnKeys) do unbindTurnKey(keyDir[1]) end
end

--- Handles player teleportation events.
Expand All @@ -192,10 +198,12 @@ local function onTeleport(player, newPos, oldPos)
return
end

local offsetX, offsetY, offsetZ = Position.offsetX(newPos, oldPos), Position.offsetY(newPos, oldPos),
Position.offsetZ(newPos, oldPos)
local offsetX, offsetY, offsetZ =
Position.offsetX(newPos, oldPos), Position.offsetY(newPos, oldPos), Position.offsetZ(newPos, oldPos)

local TELEPORT_DELAY = g_settings.getNumber("walkTeleportDelay")
local STAIRS_DELAY = g_settings.getNumber("walkStairsDelay")

local delay = (offsetX >= 3 or offsetY >= 3 or offsetZ >= 2) and TELEPORT_DELAY or STAIRS_DELAY
player:lockWalk(delay)
end
Expand All @@ -211,6 +219,9 @@ local function onWalkFinish(player)
end
end

local function onAutoWalk(player)
end

--- Handles cancellation of a walking event.
local function onCancelWalk(player)
player:lockWalk(50)
Expand All @@ -221,16 +232,22 @@ function WalkController:onInit()
bindKeys()
end

function WalkController:onTerminate()
unbindKeys()
end

--- Sets up game-related events for the WalkController.
function WalkController:onGameStart()
self:registerEvents(g_game, {
onGameStart = onGameStart,
onTeleport = onTeleport,
onAutoWalk = onAutoWalk
})

self:registerEvents(LocalPlayer, {
onCancelWalk = onCancelWalk,
onWalkFinish = onWalkFinish,
onAutoWalk = onAutoWalk
})

modules.game_interface.getRootPanel().onFocusChange = stopSmartWalk
Expand Down
1 change: 1 addition & 0 deletions modules/gamelib/const.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ GameAllowCustomBotScripts = 120
GameColorizedLootValue = 121
GameAllowPreWalk = 122
GamePlayerFamiliars = 123
GameLatencyAdaptiveCamera = 124

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 @@ -552,6 +552,7 @@ namespace Otc
GameColorizedLootValue = 121,
GameAllowPreWalk = 122,
GamePlayerFamiliars = 123,
GameLatencyAdaptiveCamera = 124,
LastGameFeature
};

Expand Down
25 changes: 19 additions & 6 deletions src/client/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void Creature::drawInformation(const MapPosInfo& mapRect, const Point& dest, con
DEFAULT_COLOR(96, 96, 96),
NPC_COLOR(0x66, 0xcc, 0xff);

if (isDead() || !canBeSeen() || !(drawFlags & Otc::DrawCreatureInfo) || !mapRect.isInRange(m_position))
if (isDead() || !canBeSeen() || !(drawFlags & Otc::DrawCreatureInfo) || !mapRect.isInRange(getPosition()))
return;

if (g_gameConfig.isDrawingInformationByWidget()) {
Expand Down Expand Up @@ -628,7 +628,8 @@ void Creature::updateWalkingTile()

if (newWalkingTile) {
newWalkingTile->addWalkingCreature(self);
g_map.notificateTileUpdate(newWalkingTile->getPosition(), self, Otc::OPERATION_CLEAN);
if (isLocalPlayer())
g_map.notificateTileUpdate(newWalkingTile->getPosition(), self, Otc::OPERATION_CLEAN);
}

m_walkingTile = newWalkingTile;
Expand All @@ -642,6 +643,7 @@ void Creature::nextWalkUpdate()

// do the update
updateWalk();
onWalking();

if (!m_walking) return;

Expand Down Expand Up @@ -918,9 +920,11 @@ uint16_t Creature::getStepDuration(const bool ignoreDiagonal, const Otc::Directi
return 0;

const auto& tilePos = dir == Otc::InvalidDirection ?
m_lastStepToPosition : m_position.translatedToDirection(dir);
m_lastStepToPosition : getPosition().translatedToDirection(dir);

const auto& tile = g_map.getTile(tilePos.isValid() ? tilePos : m_position);
const auto& tile = g_map.getTile(tilePos.isValid() ? tilePos : getPosition());

const int serverBeat = g_game.getServerBeat();

int groundSpeed = 0;
if (tile) groundSpeed = tile->getGroundSpeed();
Expand All @@ -937,7 +941,6 @@ uint16_t Creature::getStepDuration(const bool ignoreDiagonal, const Otc::Directi
} else stepDuration /= m_speed;

if (g_gameConfig.isForcingNewWalkingFormula() || g_game.getClientVersion() >= 860) {
const int serverBeat = g_game.getServerBeat();
stepDuration = ((stepDuration + serverBeat - 1) / serverBeat) * serverBeat;
}

Expand All @@ -951,7 +954,17 @@ uint16_t Creature::getStepDuration(const bool ignoreDiagonal, const Otc::Directi
: 2);
}

return ignoreDiagonal ? m_stepCache.duration : m_stepCache.getDuration(m_lastStepDirection);
auto duration = ignoreDiagonal ? m_stepCache.duration : m_stepCache.getDuration(m_lastStepDirection);

if (isLocalPlayer() && g_game.getFeature(Otc::GameLatencyAdaptiveCamera) && static_self_cast<LocalPlayer>()->isPreWalking()) {
if (m_lastMapDuration == -1)
m_lastMapDuration = ((g_game.mapUpdatedAt() + 9) / 10) * 10;

// stabilizes camera transition with server response time to keep movement fluid.
duration = std::max<int>(duration, m_lastMapDuration);
}

return duration;
}

Point Creature::getDisplacement() const
Expand Down
5 changes: 4 additions & 1 deletion src/client/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ minHeight,

protected:
virtual void terminateWalk();
virtual void onWalking() {};
void updateWalkOffset(uint8_t totalPixelsWalked);
void updateWalk();

Expand All @@ -202,7 +203,8 @@ minHeight,
Otc::Direction m_direction{ Otc::South };

Timer m_walkTimer;
Position m_lastStepToPosition;

int16_t m_lastMapDuration = -1;

private:
void nextWalkUpdate();
Expand Down Expand Up @@ -245,6 +247,7 @@ minHeight,
CachedText m_name;
CachedStep m_stepCache;

Position m_lastStepToPosition;
Position m_lastStepFromPosition;
Position m_oldPosition;

Expand Down
13 changes: 8 additions & 5 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void Game::resetGameStates()
m_serverBeat = 50;
m_seq = 0;
m_ping = -1;
m_walkTicks = 0;
m_mapUpdatedAt = 0;
m_mapUpdateTimer = { true, Timer{} };
setCanReportBugs(false);
m_fightMode = Otc::FightBalanced;
m_chaseMode = Otc::DontChase;
Expand Down Expand Up @@ -671,12 +672,12 @@ void Game::autoWalk(const std::vector<Otc::Direction>& dirs, const Position& sta

const Otc::Direction direction = *dirs.begin();
if (const auto& toTile = g_map.getTile(startPos.translatedToDirection(direction))) {
if (startPos == m_localPlayer->m_lastPrewalkDestination && toTile->isWalkable() && m_localPlayer->canWalk(direction, true)) {
if (m_localPlayer->isPreWalking() && startPos == m_localPlayer->getPosition() && toTile->isWalkable() && !m_localPlayer->isWalking() && m_localPlayer->canWalk(true)) {
m_localPlayer->preWalk(direction);
}
}

g_lua.callGlobalField("g_game", "onAutoWalk", dirs);
g_lua.callGlobalField("g_game", "onAutoWalk", m_localPlayer, dirs);
m_protocolGame->sendAutoWalk(dirs);
}

Expand All @@ -685,8 +686,10 @@ void Game::forceWalk(const Otc::Direction direction)
if (!canPerformGameAction())
return;

m_walkTimer.restart();
m_walkTicks = -1;
if (m_mapUpdateTimer.first || m_localPlayer->m_preWalks.size() == 1) {
m_mapUpdateTimer.second.restart();
m_mapUpdateTimer.first = false;
}

switch (direction) {
case Otc::North:
Expand Down
Loading
Loading