Skip to content

Commit

Permalink
* Fix spells and runes interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
jprzimba committed Jan 11, 2025
1 parent 7f4344f commit 05d55db
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
30 changes: 15 additions & 15 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void Combat::getCombatArea(const Position &centerPos, const Position &targetPos,
}

if (area) {
area->getList(centerPos, targetPos, list);
area->getList(centerPos, targetPos, list, getDirectionTo(targetPos, centerPos));
} else {
list.emplace_back(g_game().map.getOrCreateTile(targetPos));
}
Expand Down Expand Up @@ -261,18 +261,14 @@ ReturnValue Combat::canTargetCreature(const std::shared_ptr<Player> &player, con

ReturnValue Combat::canDoCombat(const std::shared_ptr<Creature> &caster, const std::shared_ptr<Tile> &tile, bool aggressive) {
if (tile->hasProperty(CONST_PROP_BLOCKPROJECTILE)) {
return RETURNVALUE_NOTENOUGHROOM;
return RETURNVALUE_CANNOTTHROW;
}
if (aggressive && tile->hasFlag(TILESTATE_PROTECTIONZONE)) {
return RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE;
}

if (tile->hasFlag(TILESTATE_FLOORCHANGE)) {
return RETURNVALUE_NOTENOUGHROOM;
}

if (tile->getTeleportItem()) {
return RETURNVALUE_NOTENOUGHROOM;
return RETURNVALUE_CANNOTTHROW;
}

if (caster) {
Expand Down Expand Up @@ -1945,7 +1941,9 @@ AreaCombat::~AreaCombat() {
clear();
}

void AreaCombat::getList(const Position &centerPos, const Position &targetPos, std::vector<std::shared_ptr<Tile>> &list) const {
void AreaCombat::getList(const Position &centerPos, const Position &targetPos, std::vector<std::shared_ptr<Tile>> &list, const Direction dir) const {
auto casterPos = getNextPosition(dir, targetPos);

const std::unique_ptr<MatrixArea> &area = getArea(centerPos, targetPos);
if (!area) {
return;
Expand All @@ -1957,17 +1955,19 @@ void AreaCombat::getList(const Position &centerPos, const Position &targetPos, s

const uint32_t rows = area->getRows();
const uint32_t cols = area->getCols();
list.reserve(rows * cols);

list.reserve(rows * cols);
Position tmpPos(targetPos.x - centerX, targetPos.y - centerY, targetPos.z);
for (uint32_t y = 0; y < rows; ++y, ++tmpPos.y, tmpPos.x -= cols) {
for (uint32_t x = 0; x < cols; ++x, ++tmpPos.x) {
if (area->getValue(y, x) != 0) {
if (g_game().isSightClear(targetPos, tmpPos, true)) {
list.emplace_back(g_game().map.getOrCreateTile(tmpPos));
}

for (uint32_t y = 0; y < rows; ++y) {
for (uint32_t x = 0; x < cols; ++x) {
if (area->getValue(y, x) != 0 && g_game().isSightClear(casterPos, tmpPos, true)) {
list.emplace_back(g_game().map.getOrCreateTile(tmpPos));
}
++tmpPos.x;
}
++tmpPos.y;
tmpPos.x -= cols;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/creatures/combat/combat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class AreaCombat {
// non-assignable
AreaCombat &operator=(const AreaCombat &) = delete;

void getList(const Position &centerPos, const Position &targetPos, std::vector<std::shared_ptr<Tile>> &list) const;
void getList(const Position &centerPos, const Position &targetPos, std::vector<std::shared_ptr<Tile>> &list, const Direction dir) const;

void setupArea(const std::list<uint32_t> &list, uint32_t rows);
void setupArea(int32_t length, int32_t spread);
Expand Down
7 changes: 0 additions & 7 deletions src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,6 @@ bool Spell::playerInstantSpellCheck(const std::shared_ptr<Player> &player, const

const auto &tile = g_game().map.getOrCreateTile(toPos);

ReturnValue ret = Combat::canDoCombat(player, tile, aggressive);
if (ret != RETURNVALUE_NOERROR) {
player->sendCancelMessage(ret);
g_game().addMagicEffect(player->getPosition(), CONST_ME_POFF);
return false;
}

if (blockingCreature && tile->getBottomVisibleCreature(player) != nullptr) {
player->sendCancelMessage(RETURNVALUE_NOTENOUGHROOM);
g_game().addMagicEffect(player->getPosition(), CONST_ME_POFF);
Expand Down

0 comments on commit 05d55db

Please sign in to comment.