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 #3328

Merged
merged 27 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
170fb45
Update combat.cpp
kaleohanopahala Jan 10, 2025
ef36473
Update combat.hpp
kaleohanopahala Jan 10, 2025
a208603
Code format - (Clang-format)
github-actions[bot] Jan 10, 2025
0d810a4
Update spells.cpp
kaleohanopahala Jan 10, 2025
552a88a
fix sonar warning
kaleohanopahala Jan 10, 2025
2ec6aaa
Merge branch 'main' into spells
majestyotbr Jan 12, 2025
a9b57e1
Merge branch 'main' into spells
kaleohanopahala Jan 19, 2025
95308ec
Merge branch 'main' into spells
kaleohanopahala Jan 23, 2025
26d0654
Fix XmasGame issue report.
kaleohanopahala Jan 25, 2025
f84a028
Fix magic wall rune
kaleohanopahala Jan 25, 2025
8f2adb6
Lua code format - (Stylua)
github-actions[bot] Jan 25, 2025
1444c22
fix wild growth rune
kaleohanopahala Jan 25, 2025
bc3287e
Lua code format - (Stylua)
github-actions[bot] Jan 25, 2025
dbef42a
fix a mistake
kaleohanopahala Jan 25, 2025
e9f55c7
Merge branch 'main' into spells
kaleohanopahala Jan 25, 2025
425753a
Update magic_wall.lua
kaleohanopahala Jan 26, 2025
18b8459
Update wild_growth.lua
kaleohanopahala Jan 26, 2025
4bf1fdb
Merge branch 'main' into spells
kaleohanopahala Jan 26, 2025
c9f59d9
Merge branch 'main' into spells
kaleohanopahala Jan 29, 2025
f570cc9
Merge branch 'main' into spells
kaleohanopahala Jan 30, 2025
d3a84e1
Merge branch 'main' into spells
murilo09 Feb 4, 2025
430f8e7
Fix Throw on magic walls.
kaleohanopahala Feb 6, 2025
648f754
fix condition check
kaleohanopahala Feb 6, 2025
99f4b52
Merge branch 'main' into spells
kaleohanopahala Feb 7, 2025
89b24fa
fix
kaleohanopahala Feb 7, 2025
c2a5465
Merge branch 'main' into spells
kaleohanopahala Feb 8, 2025
c7332be
Merge branch 'main' into spells
kaleohanopahala Feb 8, 2025
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
18 changes: 15 additions & 3 deletions data/scripts/runes/magic_wall.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
function onCreateMagicWall(creature, position)
local tile = Tile(position)
if tile and tile:getTopCreature() and not tile:getTopCreature():isPlayer() then
if not tile then
return false
end

if tile:hasFlag(TILESTATE_FLOORCHANGE) then
return false
end

if tile:getTopCreature() and not tile:getTopCreature():isPlayer() then
return false
end

local magicWall
if Game.getWorldType() == WORLD_TYPE_NO_PVP then
magicWall = ITEM_MAGICWALL_SAFE
else
magicWall = ITEM_MAGICWALL
end

local item = Game.createItem(magicWall, 1, position)
item:setDuration(16, 24)
item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, string.format("Casted by: %s", creature:getName()))
if item then
item:setDuration(16, 24)
item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, string.format("Casted by: %s", creature:getName()))
end
end

local combat = Combat()
Expand Down
18 changes: 15 additions & 3 deletions data/scripts/runes/wild_growth.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
function onCreateWildGrowth(creature, position)
local tile = Tile(position)
if tile and tile:getTopCreature() and not tile:getTopCreature():isPlayer() then
if not tile then
return false
end

if tile:hasFlag(TILESTATE_FLOORCHANGE) then
return false
end

if tile:getTopCreature() and not tile:getTopCreature():isPlayer() then
return false
end

local wildGrowth
if Game.getWorldType() == WORLD_TYPE_NO_PVP then
wildGrowth = ITEM_WILDGROWTH_SAFE
else
wildGrowth = ITEM_WILDGROWTH
end

local item = Game.createItem(wildGrowth, 1, position)
item:setDuration(30, 60)
item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, string.format("Casted by: %s", creature:getName()))
if item then
item:setDuration(30)
item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, string.format("Casted by: %s", creature:getName()))
end
end

local combat = Combat()
Expand Down
50 changes: 38 additions & 12 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 @@ -252,19 +252,33 @@ 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 (!aggressive) {
return RETURNVALUE_NOERROR;
}

if (tile->hasProperty(CONST_PROP_BLOCKPROJECTILE)) {
return RETURNVALUE_NOTENOUGHROOM;
bool canThrow = false;

if (const auto fieldList = tile->getItemList()) {
for (const auto &findfield : *fieldList) {
if (findfield && (findfield->getID() == ITEM_MAGICWALL || findfield->getID() == ITEM_MAGICWALL_SAFE)) {
canThrow = true;
break;
}
}
}

if (!canThrow) {
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 @@ -1886,7 +1900,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 @@ -1898,17 +1914,27 @@ 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) {

for (uint32_t y = 0; y < rows; ++y) {
for (uint32_t x = 0; x < cols; ++x) {
if (area->getValue(y, x) != 0) {
if (g_game().isSightClear(targetPos, tmpPos, true)) {
std::shared_ptr<Tile> tile = g_game().map.getTile(tmpPos);
if (tile && tile->hasFlag(TILESTATE_FLOORCHANGE)) {
++tmpPos.x;
continue;
}

if (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