fix onReceiveMail notification:

https://github.com/TwistedScorpio/Nostalrius/issues/53
This commit is contained in:
ErikasKontenis 2019-12-29 20:24:02 +02:00
parent a58e99cace
commit b0f1fd5239
7 changed files with 42 additions and 10 deletions

View File

@ -65,10 +65,10 @@ class Container : public Item, public Cylinder
return this; return this;
} }
virtual DepotLocker* getDepotLocker() { virtual DepotLocker* getDepotLocker() override {
return nullptr; return nullptr;
} }
virtual const DepotLocker* getDepotLocker() const { virtual const DepotLocker* getDepotLocker() const override {
return nullptr; return nullptr;
} }

View File

@ -32,6 +32,7 @@ class Container;
class Depot; class Depot;
class Teleport; class Teleport;
class Mailbox; class Mailbox;
class DepotLocker;
class Door; class Door;
class MagicField; class MagicField;
class BedItem; class BedItem;
@ -376,6 +377,12 @@ class Item : virtual public Thing
virtual const Mailbox* getMailbox() const { virtual const Mailbox* getMailbox() const {
return nullptr; return nullptr;
} }
virtual DepotLocker* getDepotLocker() {
return nullptr;
}
virtual const DepotLocker* getDepotLocker() const {
return nullptr;
}
virtual Door* getDoor() { virtual Door* getDoor() {
return nullptr; return nullptr;
} }

View File

@ -114,7 +114,7 @@ bool Mailbox::sendItem(Item* item) const
if (g_game.internalMoveItem(item->getParent(), depotLocker, INDEX_WHEREEVER, if (g_game.internalMoveItem(item->getParent(), depotLocker, INDEX_WHEREEVER,
item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) { item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) {
g_game.transformItem(item, item->getID() + 1); g_game.transformItem(item, item->getID() + 1);
player->onReceiveMail(); player->onReceiveMail(town->getID());
return true; return true;
} }
} }

View File

@ -567,14 +567,14 @@ bool Player::canSeeCreature(const Creature* creature) const
return true; 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."); sendTextMessage(MESSAGE_EVENT_ADVANCE, "New mail has arrived.");
} }
} }
bool Player::isNearDepotBox() const bool Player::isNearDepotBox(uint32_t townId) const
{ {
const Position& pos = getPosition(); const Position& pos = getPosition();
for (int32_t cx = -1; cx <= 1; ++cx) { for (int32_t cx = -1; cx <= 1; ++cx) {
@ -584,8 +584,10 @@ bool Player::isNearDepotBox() const
continue; continue;
} }
if (tile->hasFlag(TILESTATE_DEPOT)) { if (DepotLocker* depotLocker = tile->getDepotLocker()) {
return true; if (depotLocker->getDepotId() == townId) {
return true;
}
} }
} }
} }

View File

@ -433,8 +433,8 @@ class Player final : public Creature, public Cylinder
void removeConditionSuppressions(uint32_t conditions); void removeConditionSuppressions(uint32_t conditions);
DepotLocker* getDepotLocker(uint32_t depotId, bool autoCreate); DepotLocker* getDepotLocker(uint32_t depotId, bool autoCreate);
void onReceiveMail() const; void onReceiveMail(uint32_t townId) const;
bool isNearDepotBox() const; bool isNearDepotBox(uint32_t townId) const;
bool canSee(const Position& pos) const final; bool canSee(const Position& pos) const final;
bool canSeeCreature(const Creature* creature) const final; bool canSeeCreature(const Creature* creature) const final;

View File

@ -212,6 +212,27 @@ Mailbox* Tile::getMailbox() const
return nullptr; 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 BedItem* Tile::getBedItem() const
{ {
if (!hasFlag(TILESTATE_BED)) { if (!hasFlag(TILESTATE_BED)) {

View File

@ -29,6 +29,7 @@
class Creature; class Creature;
class Teleport; class Teleport;
class Mailbox; class Mailbox;
class DepotLocker;
class MagicField; class MagicField;
class QTreeLeafNode; class QTreeLeafNode;
class BedItem; class BedItem;
@ -169,6 +170,7 @@ class Tile : public Cylinder
MagicField* getFieldItem() const; MagicField* getFieldItem() const;
Teleport* getTeleportItem() const; Teleport* getTeleportItem() const;
Mailbox* getMailbox() const; Mailbox* getMailbox() const;
DepotLocker* getDepotLocker() const;
BedItem* getBedItem() const; BedItem* getBedItem() const;
Creature* getTopCreature() const; Creature* getTopCreature() const;