Ashtar
ShadowRealm.online
- Joined
- May 1, 2009
- Messages
- 312
- Reaction score
- 102
hello guys, i wanna know if its possible to send via mailbox a custom parcel that i created with name "Staff Parcel", id=3920...
I know i have to edit mailbox.cpp and mailbox.h but i have no idea what should i edit, can someone help me please :S?
this is my mailbox.cpp
and this is my mailbox.h
i will rep++ any help anyway.
Thanks for your time
I know i have to edit mailbox.cpp and mailbox.h but i have no idea what should i edit, can someone help me please :S?
this is my mailbox.cpp
Code:
#include "otpch.h"
#include "otpch.h"
#include "mailbox.h"
#include "player.h"
#include "iologindata.h"
#include "depot.h"
#include "town.h"
#include "configmanager.h"
#include "game.h"
extern ConfigManager g_config;
extern Game g_game;
ReturnValue Mailbox::__queryAdd(int32_t index, const Thing* thing, uint32_t count,
uint32_t flags) const
{
if(const Item* item = thing->getItem())
{
if(canSend(item))
return RET_NOERROR;
}
return RET_NOTPOSSIBLE;
}
ReturnValue Mailbox::__queryMaxCount(int32_t index, const Thing* thing, uint32_t count, uint32_t& maxQueryCount,
uint32_t flags) const
{
maxQueryCount = std::max((uint32_t)1, count);
return RET_NOERROR;
}
void Mailbox::__addThing(Creature* actor, int32_t index, Thing* thing)
{
Item* item = thing->getItem();
if(!item)
return;
if(canSend(item))
sendItem(actor, item);
}
bool Mailbox::sendItem(Creature* actor, Item* item)
{
uint32_t depotId = 0;
std::string name;
if(!getRecipient(item, name, depotId) || name.empty() || !depotId)
return false;
return IOLoginData::getInstance()->playerMail(actor, name, depotId, item);
}
bool Mailbox::getDepotId(const std::string& townString, uint32_t& depotId)
{
Town* town = Towns::getInstance()->getTown(townString);
if(!town)
return false;
IntegerVec disabledTowns = vectorAtoi(explodeString(g_config.getString(ConfigManager::MAILBOX_DISABLED_TOWNS), ","));
if(disabledTowns[0] != -1)
{
for(IntegerVec::iterator it = disabledTowns.begin(); it != disabledTowns.end(); ++it)
{
if(town->getID() == uint32_t(*it))
return false;
}
}
depotId = town->getID();
return true;
}
bool Mailbox::getRecipient(Item* item, std::string& name, uint32_t& depotId)
{
if(!item)
return false;
if(item->getID() == ITEM_PARCEL) /**We need to get the text from the label incase its a parcel**/
{
if(Container* parcel = item->getContainer())
{
for(ItemList::const_iterator cit = parcel->getItems(); cit != parcel->getEnd(); ++cit)
{
if((*cit)->getID() == ITEM_LABEL && !(*cit)->getText().empty())
{
item = (*cit);
break;
}
}
}
}
else if(item->getID() != ITEM_LETTER) /**The item is somehow not a parcel or letter**/
{
std::cout << "[Error - Mailbox::getReciver] Trying to get receiver from unkown item with id: " << item->getID() << "!" << std::endl;
return false;
}
if(!item || item->getText().empty()) /**No label/letter found or its empty.**/
return false;
std::istringstream iss(item->getText(), std::istringstream::in);
uint32_t curLine = 0;
std::string tmp, townString;
while(getline(iss, tmp, '\n') && curLine < 2)
{
if(curLine == 0)
name = tmp;
else if(curLine == 1)
townString = tmp;
++curLine;
}
trimString(name);
if(townString.empty())
return false;
trimString(townString);
return getDepotId(townString, depotId);
}
and this is my mailbox.h
Code:
#ifndef __MAILBOX__
#define __MAILBOX__
#include "const.h"
#include "cylinder.h"
#include "item.h"
class Mailbox : public Item, public Cylinder
{
public:
Mailbox(uint16_t type): Item(type) {}
virtual ~Mailbox() {}
virtual Mailbox* getMailbox() {return this;}
virtual const Mailbox* getMailbox() const {return this;}
//cylinder implementations
virtual Cylinder* getParent() {return Item::getParent();}
virtual const Cylinder* getParent() const {return Item::getParent();}
virtual bool isRemoved() const {return Item::isRemoved();}
virtual Position getPosition() const {return Item::getPosition();}
virtual Tile* getTile() {return Item::getTile();}
virtual const Tile* getTile() const {return Item::getTile();}
virtual Item* getItem() {return this;}
virtual const Item* getItem() const {return this;}
virtual Creature* getCreature() {return NULL;}
virtual const Creature* getCreature() const {return NULL;}
virtual ReturnValue __queryAdd(int32_t index, const Thing* thing, uint32_t count,
uint32_t flags) const;
virtual ReturnValue __queryMaxCount(int32_t index, const Thing* thing, uint32_t count,
uint32_t& maxQueryCount, uint32_t flags) const;
virtual ReturnValue __queryRemove(const Thing* thing, uint32_t count, uint32_t flags) const {return RET_NOTPOSSIBLE;}
virtual Cylinder* __queryDestination(int32_t& index, const Thing* thing, Item** destItem,
uint32_t& flags) {return this;}
virtual void __addThing(Creature* actor, Thing* thing) {__addThing(actor, 0, thing);}
virtual void __addThing(Creature* actor, int32_t index, Thing* thing);
virtual void __updateThing(Thing* thing, uint16_t itemId, uint32_t count) {}
virtual void __replaceThing(uint32_t index, Thing* thing) {}
virtual void __removeThing(Thing* thing, uint32_t count) {}
virtual void postAddNotification(Creature* actor, Thing* thing, const Cylinder* oldParent,
int32_t index, cylinderlink_t link = LINK_OWNER)
{if(getParent()) getParent()->postAddNotification(actor, thing,
oldParent, index, LINK_PARENT);}
virtual void postRemoveNotification(Creature* actor, Thing* thing, const Cylinder* newParent,
int32_t index, bool isCompleteRemoval, cylinderlink_t link = LINK_OWNER)
{if(getParent()) getParent()->postRemoveNotification(actor, thing,
newParent, index, isCompleteRemoval, LINK_PARENT);}
bool canSend(const Item* item) const {return (item->getID() == ITEM_PARCEL || item->getID() == ITEM_LETTER);}
bool sendItem(Creature* actor, Item* item);
bool getDepotId(const std::string& townString, uint32_t& depotId);
bool getRecipient(Item* item, std::string& name, uint32_t& depotId);
};
#endif
i will rep++ any help anyway.
Thanks for your time