Skip to content

Commit

Permalink
fixed levitate and parcel walking accuracy (otland#3681)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zbizu authored and Znote committed Nov 1, 2021
1 parent 31367d4 commit 663f3f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions data/spells/scripts/support/levitate.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
local function levitate(creature, parameter)
local fromPosition = creature:getPosition()
parameter = parameter:trim():lower()

if parameter == "up" and fromPosition.z ~= 8 or parameter == "down" and fromPosition.z ~= 7 then
local toPosition = creature:getPosition()
toPosition:getNextPosition(creature:getDirection())

local tile = Tile(parameter == "up" and Position(fromPosition.x, fromPosition.y, fromPosition.z - 1) or toPosition)
if not tile or not tile:getGround() and not tile:hasFlag(parameter == "up" and TILESTATE_IMMOVABLEBLOCKSOLID or TILESTATE_BLOCKSOLID) then
if not tile or not tile:getGround() and not tile:hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID) then
tile = Tile(toPosition.x, toPosition.y, toPosition.z + (parameter == "up" and -1 or 1))

if tile and tile:getGround() and not tile:hasFlag(bit.bor(TILESTATE_IMMOVABLEBLOCKSOLID, TILESTATE_FLOORCHANGE)) then
return creature:move(tile, bit.bor(FLAG_IGNOREBLOCKITEM, FLAG_IGNOREBLOCKCREATURE))
if tile and tile:getGround() and not tile:hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID) then
local fromPos = creature:getPosition()
local moved = creature:move(tile, bit.bor(FLAG_IGNOREBLOCKITEM, FLAG_IGNOREBLOCKCREATURE))

if moved == RETURNVALUE_NOERROR then
fromPos:sendMagicEffect(CONST_ME_TELEPORT)
end

return moved
end
end
end
Expand All @@ -25,6 +33,5 @@ function onCastSpell(creature, variant)
return false
end

creature:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
return true
end
4 changes: 2 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ ReturnValue Game::internalMoveCreature(Creature* creature, Direction direction,
Tile* tmpTile = map.getTile(currentPos.x, currentPos.y, currentPos.getZ() - 1);
if (tmpTile == nullptr || (tmpTile->getGround() == nullptr && !tmpTile->hasFlag(TILESTATE_BLOCKSOLID))) {
tmpTile = map.getTile(destPos.x, destPos.y, destPos.getZ() - 1);
if (tmpTile && tmpTile->getGround() && !tmpTile->hasFlag(TILESTATE_BLOCKSOLID)) {
if (tmpTile && tmpTile->getGround() && !tmpTile->hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID)) {
flags |= FLAG_IGNOREBLOCKITEM | FLAG_IGNOREBLOCKCREATURE;

if (!tmpTile->hasFlag(TILESTATE_FLOORCHANGE)) {
Expand All @@ -822,7 +822,7 @@ ReturnValue Game::internalMoveCreature(Creature* creature, Direction direction,
Tile* tmpTile = map.getTile(destPos.x, destPos.y, destPos.z);
if (tmpTile == nullptr || (tmpTile->getGround() == nullptr && !tmpTile->hasFlag(TILESTATE_BLOCKSOLID))) {
tmpTile = map.getTile(destPos.x, destPos.y, destPos.z + 1);
if (tmpTile && tmpTile->hasHeight(3)) {
if (tmpTile && tmpTile->hasHeight(3) && !tmpTile->hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID)) {
flags |= FLAG_IGNOREBLOCKITEM | FLAG_IGNOREBLOCKCREATURE;
player->setDirection(direction);
destPos.z++;
Expand Down

0 comments on commit 663f3f3

Please sign in to comment.