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