Merge branch '1-research-for-existing-issues-in-nostalrius-repo' into 'master'

Resolve "Research for existing issues in Nostalrius repo"

Closes #1

See merge request ErikasKontenis/Sabrehaven!21
This commit is contained in:
Erikas Kontenis 2019-12-30 14:41:57 +00:00
commit 0da6ba2269
10 changed files with 95 additions and 19 deletions

View File

@ -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

View File

@ -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

View File

@ -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) {

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}
}
}
}

View File

@ -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;

View File

@ -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)) {

View File

@ -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;