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: spells and runes interactions #3241

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
30 changes: 15 additions & 15 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,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 @@ -253,18 +253,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 @@ -1882,7 +1878,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 @@ -1894,17 +1892,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 @@ -155,7 +155,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
8 changes: 0 additions & 8 deletions src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,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
Loading