Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent teleportation #3143

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
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
20 changes: 9 additions & 11 deletions src/game/movement/teleport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,27 @@ void Teleport::addThing(int32_t, const std::shared_ptr<Thing> &thing) {
// Prevent infinity loop
if (checkInfinityLoop(destTile)) {
const Position &pos = getPosition();
g_logger().warn("[Teleport:addThing] - "
"Infinity loop teleport at position: {}",
pos.toString());
g_logger().warn("[Teleport:addThing] - Infinity loop teleport at position: {}", pos.toString());
return;
}

const MagicEffectClasses effect = Item::items[id].magicEffect;

if (const std::shared_ptr<Creature> &creature = thing->getCreature()) {
if (const auto &creature = thing->getCreature()) {
Position origPos = creature->getPosition();
g_game().internalCreatureTurn(creature, origPos.x > destPos.x ? DIRECTION_WEST : DIRECTION_EAST);
g_dispatcher().addWalkEvent([=] {
g_game().map.moveCreature(creature, destTile);
if (effect != CONST_ME_NONE) {
g_game().addMagicEffect(origPos, effect);
g_game().addMagicEffect(destTile->getPosition(), effect);
}
});
g_game().map.moveCreature(creature, destTile);

if (effect != CONST_ME_NONE) {
g_game().addMagicEffect(origPos, effect);
g_game().addMagicEffect(destTile->getPosition(), effect);
}
} else if (const auto &item = thing->getItem()) {
if (effect != CONST_ME_NONE) {
g_game().addMagicEffect(destTile->getPosition(), effect);
g_game().addMagicEffect(item->getPosition(), effect);
}

g_game().internalMoveItem(getTile(), destTile, INDEX_WHEREEVER, item, item->getItemCount(), nullptr);
}
}
Expand Down
Loading