mirror of
https://github.com/edubart/otclient.git
synced 2025-10-17 13:03:27 +02:00
More walk control optimization and fixes:
* Finished off the walking control optimization! (Should be smooth controlling now). * Fixed issue #151 * Fixed an issue with the character list. * Fixed a bug in the g_keyboard.isKeySetPressed function.
This commit is contained in:
@@ -89,6 +89,8 @@ public:
|
||||
Position getLastStepFromPosition() { return m_lastStepFromPosition; }
|
||||
Position getLastStepToPosition() { return m_lastStepToPosition; }
|
||||
float getStepProgress() { return m_walkTimer.ticksElapsed() / getStepDuration(); }
|
||||
float getStepTicksLeft() { return getStepDuration() - m_walkTimer.ticksElapsed(); }
|
||||
ticks_t getWalkTicksElapsed() { return m_walkTimer.ticksElapsed(); }
|
||||
double getSpeedFormula(Otc::SpeedFormula formula) { return m_speedFormula[formula]; }
|
||||
bool hasSpeedFormula();
|
||||
std::array<double, Otc::LastSpeedFormula> getSpeedFormulaArray() { return m_speedFormula; }
|
||||
|
@@ -76,6 +76,11 @@ void Game::resetGameStates()
|
||||
m_pingEvent = nullptr;
|
||||
}
|
||||
|
||||
if(m_walkEvent) {
|
||||
m_walkEvent->cancel();
|
||||
m_walkEvent = nullptr;
|
||||
}
|
||||
|
||||
m_containers.clear();
|
||||
m_vips.clear();
|
||||
m_gmActions.clear();
|
||||
@@ -501,8 +506,21 @@ bool Game::walk(Otc::Direction direction)
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!m_localPlayer->canWalk(direction))
|
||||
// must add a new walk event
|
||||
if(!m_localPlayer->canWalk(direction)) {
|
||||
if(m_lastWalkDir != direction) {
|
||||
float ticks = m_localPlayer->getStepTicksLeft();
|
||||
if(ticks < 0)
|
||||
ticks = 0;
|
||||
|
||||
if(m_walkEvent) {
|
||||
m_walkEvent->cancel();
|
||||
m_walkEvent = nullptr;
|
||||
}
|
||||
m_walkEvent = g_dispatcher.scheduleEvent([=] { walk(direction); }, ticks);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Position toPos = m_localPlayer->getPosition().translatedToDirection(direction);
|
||||
TilePtr toTile = g_map.getTile(toPos);
|
||||
@@ -546,6 +564,7 @@ bool Game::walk(Otc::Direction direction)
|
||||
g_lua.callGlobalField("g_game", "onWalk", direction);
|
||||
|
||||
forceWalk(direction);
|
||||
m_lastWalkDir = direction;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -307,6 +307,7 @@ private:
|
||||
uint m_seq;
|
||||
Otc::FightModes m_fightMode;
|
||||
Otc::ChaseModes m_chaseMode;
|
||||
Otc::Direction m_lastWalkDir;
|
||||
bool m_safeFight;
|
||||
bool m_canReportBugs;
|
||||
std::vector<uint8> m_gmActions;
|
||||
@@ -314,6 +315,7 @@ private:
|
||||
std::string m_worldName;
|
||||
std::bitset<Otc::LastGameFeature> m_features;
|
||||
ScheduledEventPtr m_pingEvent;
|
||||
ScheduledEventPtr m_walkEvent;
|
||||
int m_protocolVersion;
|
||||
int m_clientVersion;
|
||||
};
|
||||
|
@@ -364,6 +364,10 @@ void OTClient::registerLuaFunctions()
|
||||
g_lua.bindClassMemberFunction<Creature>("setOutfit", &Creature::setOutfit);
|
||||
g_lua.bindClassMemberFunction<Creature>("getOutfit", &Creature::getOutfit);
|
||||
g_lua.bindClassMemberFunction<Creature>("getDirection", &Creature::getDirection);
|
||||
g_lua.bindClassMemberFunction<Creature>("getStepDuration", &Creature::getStepDuration);
|
||||
g_lua.bindClassMemberFunction<Creature>("getStepProgress", &Creature::getStepProgress);
|
||||
g_lua.bindClassMemberFunction<Creature>("getWalkTicksElapsed", &Creature::getWalkTicksElapsed);
|
||||
g_lua.bindClassMemberFunction<Creature>("getStepTicksLeft", &Creature::getStepTicksLeft);
|
||||
g_lua.bindClassMemberFunction<Creature>("setDirection", &Creature::setDirection);
|
||||
g_lua.bindClassMemberFunction<Creature>("setSkullTexture", &Creature::setSkullTexture);
|
||||
g_lua.bindClassMemberFunction<Creature>("setShieldTexture", &Creature::setShieldTexture);
|
||||
|
@@ -433,15 +433,17 @@ ThingPtr Tile::getTopMoveThing()
|
||||
return m_things[0];
|
||||
}
|
||||
|
||||
ThingPtr Tile::getTopMultiUseThing()
|
||||
ThingPtr Tile::getTopMultiUseThing(bool ignoreCreature)
|
||||
{
|
||||
// this is related to classic controls, getting top item, forceuse or creature
|
||||
// this is related to classic controls, getting top item, forceuse for creature
|
||||
if(isEmpty())
|
||||
return nullptr;
|
||||
|
||||
for(uint i = 0; i < m_things.size(); ++i) {
|
||||
ThingPtr thing = m_things[i];
|
||||
if(thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature())) {
|
||||
if(thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop())) {
|
||||
if(thing->isCreature() && ignoreCreature)
|
||||
continue;
|
||||
if(i > 0 && thing->isSplash())
|
||||
return m_things[i-1];
|
||||
return thing;
|
||||
@@ -450,8 +452,11 @@ ThingPtr Tile::getTopMultiUseThing()
|
||||
|
||||
for(uint i = 0; i < m_things.size(); ++i) {
|
||||
ThingPtr thing = m_things[i];
|
||||
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnTop() && !thing->isCreature())
|
||||
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnTop()) {
|
||||
if(thing->isCreature() && ignoreCreature)
|
||||
continue;
|
||||
return thing;
|
||||
}
|
||||
}
|
||||
|
||||
return m_things[0];
|
||||
|
@@ -81,7 +81,7 @@ public:
|
||||
ThingPtr getTopUseThing();
|
||||
CreaturePtr getTopCreature();
|
||||
ThingPtr getTopMoveThing();
|
||||
ThingPtr getTopMultiUseThing();
|
||||
ThingPtr getTopMultiUseThing(bool ignoreCreature = true);
|
||||
|
||||
const Position& getPosition() { return m_position; }
|
||||
int getDrawElevation() { return m_drawElevation; }
|
||||
|
Reference in New Issue
Block a user