diff --git a/data/lib/core/game.lua b/data/lib/core/game.lua index 12c7c92..fc900f7 100644 --- a/data/lib/core/game.lua +++ b/data/lib/core/game.lua @@ -55,6 +55,17 @@ function Game.isPlayerThere(position) return false end +function Game.isMonsterThere(position, monsterName) + local tile = Tile(position) + local creatures = tile:getCreatures() + for _, creature in ipairs(creatures) do + if creature:isMonster() and creature:getName():lower() == monsterName:lower() then + return creature + end + end + return nil +end + function Game.broadcastMessage(message, messageType) if messageType == nil then messageType = MESSAGE_STATUS_WARNING diff --git a/data/movements/scripts/nostalrius/234.lua b/data/movements/scripts/nostalrius/234.lua index e536b42..78e0196 100644 --- a/data/movements/scripts/nostalrius/234.lua +++ b/data/movements/scripts/nostalrius/234.lua @@ -1,10 +1,31 @@ function onRemoveItem(item, tileitem, position) - doRelocate({x = 33336, y = 31954, z = 15},{x = 33060, y = 31623, z = 15}) - doRelocate({x = 33340, y = 31954, z = 15},{x = 33066, y = 31623, z = 15}) - doRelocate({x = 33340, y = 31958, z = 15},{x = 33066, y = 31627, z = 15}) - doRelocate({x = 33336, y = 31958, z = 15},{x = 33060, y = 31627, z = 15}) - Game.sendMagicEffect({x = 33060, y = 31622, z = 15}, 14) - Game.sendMagicEffect({x = 33066, y = 31622, z = 15}, 14) - Game.sendMagicEffect({x = 33066, y = 31628, z = 15}, 14) - Game.sendMagicEffect({x = 33060, y = 31628, z = 15}, 14) -end + local demonsInRoomCount = 0; + local spectators = Game.getSpectators(Position(33063, 31624, 15), false, false, 20, 20, 20, 20) + for i = 1, #spectators do + local creature = spectators[i] + if creature:getName():lower() == "demon" then + demonsInRoomCount = demonsInRoomCount + 1 + end + end + + if (demonsInRoomCount <= 1) then + local demon1 = Game.isMonsterThere({x = 33336, y = 31954, z = 15}, "Demon") + local demon2 = Game.isMonsterThere({x = 33340, y = 31954, z = 15}, "Demon") + local demon3 = Game.isMonsterThere({x = 33340, y = 31958, z = 15}, "Demon") + local demon4 = Game.isMonsterThere({x = 33336, y = 31958, z = 15}, "Demon") + if demon1 ~= nil and demon2 ~= nil and demon3 ~= nil and demon4 ~= nil then + demon1:addHealth(-demon1:getMaxHealth()) + demon2:addHealth(-demon2:getMaxHealth()) + demon3:addHealth(-demon3:getMaxHealth()) + demon4:addHealth(-demon4:getMaxHealth()) + Game.createMonster("Demon", {x = 33060, y = 31623, z = 15}) + Game.createMonster("Demon", {x = 33066, y = 31623, z = 15}) + Game.createMonster("Demon", {x = 33066, y = 31627, z = 15}) + Game.createMonster("Demon", {x = 33060, y = 31627, z = 15}) + Game.sendMagicEffect({x = 33060, y = 31622, z = 15}, 14) + Game.sendMagicEffect({x = 33066, y = 31622, z = 15}, 14) + Game.sendMagicEffect({x = 33066, y = 31628, z = 15}, 14) + Game.sendMagicEffect({x = 33060, y = 31628, z = 15}, 14) + end + end +end \ No newline at end of file diff --git a/src/condition.cpp b/src/condition.cpp index 4d923d2..7487e6a 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -873,6 +873,10 @@ bool ConditionDamage::startCondition(Creature* creature) bool ConditionDamage::executeCondition(Creature* creature, int32_t) { if (conditionType == CONDITION_FIRE) { + if (creature->isImmune(CONDITION_FIRE)) { + return false; + } + const int32_t r_cycle = cycle; if (r_cycle) { if (count <= 0) { @@ -886,6 +890,10 @@ bool ConditionDamage::executeCondition(Creature* creature, int32_t) return false; } } else if (conditionType == CONDITION_POISON) { + if (creature->isImmune(CONDITION_POISON)) { + return false; + } + const int32_t r_cycle = cycle; if (r_cycle) { if (count <= 0) { @@ -904,6 +912,10 @@ bool ConditionDamage::executeCondition(Creature* creature, int32_t) return false; } } else if (conditionType == CONDITION_ENERGY) { + if (creature->isImmune(CONDITION_ENERGY)) { + return false; + } + const int32_t r_cycle = cycle; if (r_cycle) { if (count <= 0) { diff --git a/src/container.h b/src/container.h index 495c92f..2330c26 100644 --- a/src/container.h +++ b/src/container.h @@ -65,10 +65,10 @@ class Container : public Item, public Cylinder return this; } - virtual DepotLocker* getDepotLocker() { + virtual DepotLocker* getDepotLocker() override { return nullptr; } - virtual const DepotLocker* getDepotLocker() const { + virtual const DepotLocker* getDepotLocker() const override { return nullptr; } diff --git a/src/item.h b/src/item.h index e82a50f..87b2a04 100644 --- a/src/item.h +++ b/src/item.h @@ -32,6 +32,7 @@ class Container; class Depot; class Teleport; class Mailbox; +class DepotLocker; class Door; class MagicField; class BedItem; @@ -376,6 +377,12 @@ class Item : virtual public Thing virtual const Mailbox* getMailbox() const { return nullptr; } + virtual DepotLocker* getDepotLocker() { + return nullptr; + } + virtual const DepotLocker* getDepotLocker() const { + return nullptr; + } virtual Door* getDoor() { return nullptr; } diff --git a/src/mailbox.cpp b/src/mailbox.cpp index 8b21a45..31cd67f 100644 --- a/src/mailbox.cpp +++ b/src/mailbox.cpp @@ -114,7 +114,7 @@ bool Mailbox::sendItem(Item* item) const if (g_game.internalMoveItem(item->getParent(), depotLocker, INDEX_WHEREEVER, item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) { g_game.transformItem(item, item->getID() + 1); - player->onReceiveMail(); + player->onReceiveMail(town->getID()); return true; } } diff --git a/src/player.cpp b/src/player.cpp index 49bb168..50ab614 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -567,14 +567,14 @@ bool Player::canSeeCreature(const Creature* creature) const return true; } -void Player::onReceiveMail() const +void Player::onReceiveMail(uint32_t townId) const { - if (isNearDepotBox()) { + if (isNearDepotBox(townId)) { sendTextMessage(MESSAGE_EVENT_ADVANCE, "New mail has arrived."); } } -bool Player::isNearDepotBox() const +bool Player::isNearDepotBox(uint32_t townId) const { const Position& pos = getPosition(); for (int32_t cx = -1; cx <= 1; ++cx) { @@ -584,8 +584,10 @@ bool Player::isNearDepotBox() const continue; } - if (tile->hasFlag(TILESTATE_DEPOT)) { - return true; + if (DepotLocker* depotLocker = tile->getDepotLocker()) { + if (depotLocker->getDepotId() == townId) { + return true; + } } } } diff --git a/src/player.h b/src/player.h index 3f39f9c..f088f13 100644 --- a/src/player.h +++ b/src/player.h @@ -433,8 +433,8 @@ class Player final : public Creature, public Cylinder void removeConditionSuppressions(uint32_t conditions); DepotLocker* getDepotLocker(uint32_t depotId, bool autoCreate); - void onReceiveMail() const; - bool isNearDepotBox() const; + void onReceiveMail(uint32_t townId) const; + bool isNearDepotBox(uint32_t townId) const; bool canSee(const Position& pos) const final; bool canSeeCreature(const Creature* creature) const final; diff --git a/src/tile.cpp b/src/tile.cpp index 5b2afbb..6240678 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -212,6 +212,27 @@ Mailbox* Tile::getMailbox() const return nullptr; } +DepotLocker* Tile::getDepotLocker() const +{ + if (!hasFlag(TILESTATE_DEPOT)) { + return nullptr; + } + + if (ground && ground->getDepotLocker()) { + return ground->getDepotLocker(); + } + + if (const TileItemVector* items = getItemList()) { + for (auto it = items->rbegin(), end = items->rend(); it != end; ++it) { + if ((*it)->getDepotLocker()) { + return (*it)->getDepotLocker(); + } + } + } + return nullptr; +} + + BedItem* Tile::getBedItem() const { if (!hasFlag(TILESTATE_BED)) { diff --git a/src/tile.h b/src/tile.h index 99f3ffd..0b68759 100644 --- a/src/tile.h +++ b/src/tile.h @@ -29,6 +29,7 @@ class Creature; class Teleport; class Mailbox; +class DepotLocker; class MagicField; class QTreeLeafNode; class BedItem; @@ -169,6 +170,7 @@ class Tile : public Cylinder MagicField* getFieldItem() const; Teleport* getTeleportItem() const; Mailbox* getMailbox() const; + DepotLocker* getDepotLocker() const; BedItem* getBedItem() const; Creature* getTopCreature() const;