Check walk collisions in client side
This commit is contained in:
parent
773d58da01
commit
daea7cab65
|
@ -489,12 +489,44 @@ void Game::walk(Otc::Direction direction)
|
||||||
if(!m_localPlayer->canWalk(direction))
|
if(!m_localPlayer->canWalk(direction))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Position toPos = m_localPlayer->getPosition().translatedToDirection(direction);
|
||||||
|
TilePtr toTile = g_map.getTile(toPos);
|
||||||
// only do prewalks to walkable tiles (like grounds and not walls)
|
// only do prewalks to walkable tiles (like grounds and not walls)
|
||||||
TilePtr toTile = g_map.getTile(m_localPlayer->getPosition().translatedToDirection(direction));
|
|
||||||
if(toTile && toTile->isWalkable())
|
if(toTile && toTile->isWalkable())
|
||||||
m_localPlayer->preWalk(direction);
|
m_localPlayer->preWalk(direction);
|
||||||
else
|
// check walk to another floor (e.g: when above 3 parcels)
|
||||||
m_localPlayer->lockWalk(100);
|
else {
|
||||||
|
// check if can walk to a lower floor
|
||||||
|
auto canChangeFloorDown = [&] {
|
||||||
|
Position pos = toPos;
|
||||||
|
if(!pos.down())
|
||||||
|
return false;
|
||||||
|
toTile = g_map.getTile(pos);
|
||||||
|
if(toTile && toTile->hasElevation(3)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// check if can walk to a higher floor
|
||||||
|
auto canChangeFloorUp = [&] {
|
||||||
|
TilePtr fromTile = m_localPlayer->getTile();
|
||||||
|
if(!fromTile || !fromTile->hasElevation(3))
|
||||||
|
return false;
|
||||||
|
Position pos = toPos;
|
||||||
|
if(!pos.up())
|
||||||
|
return false;
|
||||||
|
toTile = g_map.getTile(pos);
|
||||||
|
if(!toTile || !toTile->isWalkable())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
if(canChangeFloorDown() || canChangeFloorUp()) {
|
||||||
|
m_localPlayer->lockWalk();
|
||||||
|
} else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
forceWalk(direction);
|
forceWalk(direction);
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "container.h"
|
#include "container.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "houses.h"
|
#include "houses.h"
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
#include <framework/core/clock.h>
|
#include <framework/core/clock.h>
|
||||||
#include <framework/core/eventdispatcher.h>
|
#include <framework/core/eventdispatcher.h>
|
||||||
|
@ -302,7 +303,9 @@ int Item::getSubType()
|
||||||
{
|
{
|
||||||
if(isSplash() || isFluidContainer())
|
if(isSplash() || isFluidContainer())
|
||||||
return m_countOrSubType;
|
return m_countOrSubType;
|
||||||
return 0;
|
if(g_game.getClientVersion() >= 900)
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Item::getCount()
|
int Item::getCount()
|
||||||
|
|
|
@ -513,3 +513,12 @@ bool Tile::canErase()
|
||||||
{
|
{
|
||||||
return m_walkingCreatures.empty() && m_effects.empty() && m_things.empty();
|
return m_walkingCreatures.empty() && m_effects.empty() && m_things.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Tile::hasElevation(int elevation)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
for(const ThingPtr& thing : m_things)
|
||||||
|
if(thing->getElevation() > 0)
|
||||||
|
count++;
|
||||||
|
return count >= elevation;
|
||||||
|
}
|
||||||
|
|
|
@ -102,6 +102,7 @@ public:
|
||||||
bool hasCreature();
|
bool hasCreature();
|
||||||
bool limitsFloorsView();
|
bool limitsFloorsView();
|
||||||
bool canErase();
|
bool canErase();
|
||||||
|
bool hasElevation(int elevation = 1);
|
||||||
|
|
||||||
void setFlags(tileflags_t flags) { m_flags |= (uint32)flags; }
|
void setFlags(tileflags_t flags) { m_flags |= (uint32)flags; }
|
||||||
uint32 getFlags() { return m_flags; }
|
uint32 getFlags() { return m_flags; }
|
||||||
|
|
Loading…
Reference in New Issue