mirror of
https://github.com/ErikasKontenis/SabrehavenServer.git
synced 2025-11-29 15:56:50 +01:00
commit newest tfs branch only for compare
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Tibia GIMUD Server - a free and open-source MMORPG server emulator
|
||||
* Copyright (C) 2019 Sabrehaven and Mark Samman <mark.samman@gmail.com>
|
||||
* The Forgotten Server - a free and open-source MMORPG server emulator
|
||||
* Copyright (C) 2019 Mark Samman <mark.samman@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -21,9 +21,7 @@
|
||||
|
||||
#include "mailbox.h"
|
||||
#include "game.h"
|
||||
#include "player.h"
|
||||
#include "iologindata.h"
|
||||
#include "town.h"
|
||||
|
||||
extern Game g_game;
|
||||
|
||||
@@ -93,30 +91,22 @@ void Mailbox::postRemoveNotification(Thing* thing, const Cylinder* newParent, in
|
||||
bool Mailbox::sendItem(Item* item) const
|
||||
{
|
||||
std::string receiver;
|
||||
std::string townName;
|
||||
if (!getDestination(item, receiver, townName)) {
|
||||
if (!getReceiver(item, receiver)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (receiver.empty() || townName.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Town* town = g_game.map.towns.getTown(townName);
|
||||
if (!town) {
|
||||
/**No need to continue if its still empty**/
|
||||
if (receiver.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player* player = g_game.getPlayerByName(receiver);
|
||||
if (player) {
|
||||
DepotLocker* depotLocker = player->getDepotLocker(town->getID(), true);
|
||||
if (depotLocker) {
|
||||
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(town->getID());
|
||||
return true;
|
||||
}
|
||||
if (g_game.internalMoveItem(item->getParent(), player->getInbox(), INDEX_WHEREEVER,
|
||||
item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) {
|
||||
g_game.transformItem(item, item->getID() + 1);
|
||||
player->onReceiveMail();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
Player tmpPlayer(nullptr);
|
||||
@@ -124,30 +114,25 @@ bool Mailbox::sendItem(Item* item) const
|
||||
return false;
|
||||
}
|
||||
|
||||
DepotLocker* depotLocker = tmpPlayer.getDepotLocker(town->getID(), true);
|
||||
if (depotLocker) {
|
||||
if (g_game.internalMoveItem(item->getParent(), depotLocker, INDEX_WHEREEVER,
|
||||
item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) {
|
||||
g_game.transformItem(item, item->getID() + 1);
|
||||
IOLoginData::savePlayer(&tmpPlayer);
|
||||
return true;
|
||||
}
|
||||
if (g_game.internalMoveItem(item->getParent(), tmpPlayer.getInbox(), INDEX_WHEREEVER,
|
||||
item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) {
|
||||
g_game.transformItem(item, item->getID() + 1);
|
||||
IOLoginData::savePlayer(&tmpPlayer);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Mailbox::getDestination(Item* item, std::string& name, std::string& town) const
|
||||
bool Mailbox::getReceiver(Item* item, std::string& name) const
|
||||
{
|
||||
const Container* container = item->getContainer();
|
||||
if (container) {
|
||||
for (Item* containerItem : container->getItemList()) {
|
||||
if (containerItem->getID() == ITEM_LABEL && getDestination(containerItem, name, town)) {
|
||||
if (containerItem->getID() == ITEM_LABEL && getReceiver(containerItem, name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -156,24 +141,8 @@ bool Mailbox::getDestination(Item* item, std::string& name, std::string& town) c
|
||||
return false;
|
||||
}
|
||||
|
||||
std::istringstream iss(text, std::istringstream::in);
|
||||
std::string temp;
|
||||
uint32_t currentLine = 1;
|
||||
|
||||
while (getline(iss, temp, '\n')) {
|
||||
if (currentLine == 1) {
|
||||
name = temp;
|
||||
} else if (currentLine == 2) {
|
||||
town = temp;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
++currentLine;
|
||||
}
|
||||
|
||||
name = getFirstLine(text);
|
||||
trimString(name);
|
||||
trimString(town);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user