Skip to content

Commit

Permalink
Merge branch 'mehah:main' into browser
Browse files Browse the repository at this point in the history
  • Loading branch information
OTArchive authored Nov 13, 2024
2 parents 8e80533 + c3aace1 commit a9dc380
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 47 deletions.
4 changes: 0 additions & 4 deletions src/client/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,6 @@ void Creature::walk(const Position& oldPos, const Position& newPos)
m_walkTimer.restart();
m_walkedPixels = 0;

if (++m_walkSteps == 0)
m_walkSteps = 1;

// no direction need to be changed when the walk ends
m_walkTurnDirection = Otc::InvalidDirection;

Expand Down Expand Up @@ -701,7 +698,6 @@ void Creature::terminateWalk()

const auto self = static_self_cast<Creature>();
m_walkFinishAnimEvent = g_dispatcher.scheduleEvent([self] {
self->m_walkSteps = 0;
self->m_walkAnimationPhase = 0;
self->m_walkFinishAnimEvent = nullptr;
}, g_game.getServerBeat());
Expand Down
4 changes: 0 additions & 4 deletions src/client/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class Creature : public Thing
void hideStaticSquare() { m_showStaticSquare = false; }

// walk related
int getWalkSteps() const { return m_walkSteps; }
void setWalkSteps(uint8_t step) { m_walkSteps = step; }
void turn(Otc::Direction direction);
void jump(int height, int duration);
void allowAppearWalk() { m_allowAppearWalk = true; }
Expand Down Expand Up @@ -294,8 +292,6 @@ class Creature : public Thing

uint8_t m_disableWalkAnimation{ 0 };

uint8_t m_walkSteps{ 0 };

// Mount Shader
uint8_t m_mountShaderId{ 0 };

Expand Down
59 changes: 21 additions & 38 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,19 +630,9 @@ void Game::safeLogout()
m_protocolGame->sendLogout();
}

bool Game::walk(const Otc::Direction direction, bool force)
bool Game::walk(const Otc::Direction direction)
{
static ScheduledEventPtr nextWalkSchedule = nullptr;

if (direction == Otc::InvalidDirection) {
if (nextWalkSchedule) {
nextWalkSchedule->cancel();
nextWalkSchedule = nullptr;
}
return false;
}

if (!canPerformGameAction())
if (!canPerformGameAction() || direction == Otc::InvalidDirection)
return false;

// must cancel auto walking, and wait next try
Expand All @@ -652,39 +642,32 @@ bool Game::walk(const Otc::Direction direction, bool force)
return false;
}

if (!force) {
if (nextWalkSchedule)
return false;
static ScheduledEventPtr nextWalkSchedule = nullptr;
static uint16_t steps = 0;
static Timer timer;

if (m_localPlayer->getWalkSteps() > 0) {
uint16_t delay = 0;
if (m_localPlayer->getWalkSteps() == 1) {
if (m_localPlayer->isWalking())
return false;

delay = m_walkFirstStepDelay;
} else if (direction != m_localPlayer->getDirection())
delay = m_walkTurnDelay;

if (delay > 0) {
nextWalkSchedule = g_dispatcher.scheduleEvent([this, direction] {
if (m_localPlayer) {
m_localPlayer->setWalkSteps(1);
walk(direction, true);
}

nextWalkSchedule = nullptr;
}, delay);
return false;
}
}
}
if (nextWalkSchedule) nextWalkSchedule->cancel();
nextWalkSchedule = g_dispatcher.scheduleEvent([this] {
nextWalkSchedule = nullptr;
steps = 0;
}, 150);

// check we can walk and add new walk event if false
if (!m_localPlayer->canWalk(direction)) {
return false;
}

if (steps == 1) {
if (timer.ticksElapsed() <= m_walkFirstStepDelay)
return false;
} else if (direction != m_localPlayer->getDirection()) {
if (timer.ticksElapsed() <= m_walkTurnDelay)
return false;
}

++steps;
timer.restart();

const auto& toPos = m_localPlayer->getPosition().translatedToDirection(direction);

// only do prewalks to walkable tiles (like grounds and not walls)
Expand Down
2 changes: 1 addition & 1 deletion src/client/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ class Game
void safeLogout();

// walk related
bool walk(const Otc::Direction direction, bool force = false);
bool walk(const Otc::Direction direction);
void autoWalk(const std::vector<Otc::Direction>& dirs, const Position& startPos);
void forceWalk(const Otc::Direction direction);
void turn(const Otc::Direction direction);
Expand Down
1 change: 1 addition & 0 deletions src/client/protocolcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ namespace Proto
GameServerMissleEffect = 133, // Anthem on 13.x
GameServerItemClasses = 134,
GameServerTrappers = 135,
GameServerCloseForgeWindow = 137,
GameServerCreatureData = 139,
GameServerCreatureHealth = 140,
GameServerCreatureLight = 141,
Expand Down
1 change: 1 addition & 0 deletions src/client/protocolgame.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class ProtocolGame : public Protocol
void parseCreatureMark(const InputMessagePtr& msg);
void parseTrappers(const InputMessagePtr& msg);
void addCreatureIcon(const InputMessagePtr& msg);
void parseCloseForgeWindow(const InputMessagePtr& msg);
void parseCreatureData(const InputMessagePtr& msg);
void parseCreatureHealth(const InputMessagePtr& msg);
void parseCreatureLight(const InputMessagePtr& msg);
Expand Down
8 changes: 8 additions & 0 deletions src/client/protocolgameparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg)
case Proto::GameServerTrappers:
parseTrappers(msg);
break;
case Proto::GameServerCloseForgeWindow:
parseCloseForgeWindow(msg);
break;
case Proto::GameServerCreatureData:
parseCreatureData(msg);
break;
Expand Down Expand Up @@ -1844,6 +1847,11 @@ void ProtocolGame::addCreatureIcon(const InputMessagePtr& msg)
// TODO: implement creature icons usage
}

void ProtocolGame::parseCloseForgeWindow(const InputMessagePtr& /*msg*/)
{
g_lua.callGlobalField("g_game", "onCloseForgeCloseWindows");
}

void ProtocolGame::parseCreatureData(const InputMessagePtr& msg)
{
const uint32_t creatureId = msg->getU32();
Expand Down

0 comments on commit a9dc380

Please sign in to comment.