126 "shop_buy_background.xml")),
138 mSellShopName(
serverConfig.getStringValue(
"sellShopName")),
141 mLastRequestTimeList(0),
142 mLastRequestTimeItem(0),
149 mEnableBuyingStore(false),
150 mEnableVending(false)
191 placer(0, 0,
mTabs, 8, 1).setPadding(3);
220 this,
"link announce");
263 const std::string &eventId =
event.getId();
264 if (eventId ==
"close")
270 else if (eventId ==
"yes")
274 else if (eventId ==
"no")
278 else if (eventId ==
"ignore")
283 else if (eventId ==
"announce")
296 else if (eventId ==
"delete")
316 else if (eventId ==
"tab_buy")
321 else if (eventId ==
"tab_sell")
326 else if (eventId ==
"publish")
357 STD_VECTOR<ShopItem*> items;
361 FOR_EACH (STD_VECTOR<ShopItem*>::iterator, it, oldItems)
368 if (cartItem ==
nullptr)
376 items.push_back(item);
385 else if (eventId ==
"rename")
389 _(
"Please enter new shop name"),
411 if (eventId ==
"add")
441 bool allowDel(
false);
442 bool allowAdd(
false);
548 std::ifstream shopFile;
557 if (stat(shopListName.c_str(), &statbuf) == 0 &&
558 S_ISREG(statbuf.st_mode))
560 shopFile.open(shopListName.c_str(), std::ios::in);
561 if (!shopFile.is_open())
564 shopListName.c_str())
569 while (shopFile.getline(line, 100))
572 const std::string str = line;
575 STD_VECTOR<int> tokens;
576 std::stringstream ss(str);
579 tokens.push_back(atoi(buf.c_str()));
581 if (tokens.size() == 5 && (tokens[0] != 0))
584 if ((tokens[1] != 0) && (tokens[2] != 0))
593 if ((tokens[3] != 0) && (tokens[4] != 0))
611 std::ofstream shopFile;
614 std::map<int, ShopItem*> mapItems;
616 shopFile.open(shopListName.c_str(), std::ios::binary);
617 if (!shopFile.is_open())
620 shopListName.c_str())
625 FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
629 mapItems[item->
getId()] = item;
633 FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
635 if ((*it) ==
nullptr)
637 const ShopItem *
const sellItem = *(it);
640 shopFile << sellItem->
getId();
641 if (buyItem !=
nullptr)
645 mapItems.erase(sellItem->
getId());
656 for (std::map<int, ShopItem*>::const_iterator mapIt = mapItems.begin(),
657 mapIt_fend = mapItems.end();
661 const ShopItem *
const buyItem = (*mapIt).second;
662 if (buyItem !=
nullptr)
664 shopFile << buyItem->
getId();
667 shopFile <<
"0 0" << std::endl;
684 data.append(
"Sell ");
696 STD_VECTOR<ShopItem*> items = list->
items();
698 FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
764 std::string
data(
"\302\202");
784 STD_VECTOR<ShopItem*> items = list->
items();
786 FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
796 if (item2 !=
nullptr)
862 if (
data.find(
"B1") == 0)
867 else if (
data.find(
"S1") == 0)
877 if (buyDialog !=
nullptr)
879 if (sellDialog !=
nullptr)
882 for (
size_t f = 0; f <
data.length(); f += 9)
884 if (f + 9 >
data.length())
890 if (buyDialog !=
nullptr && amount > 0)
898 if (sellDialog !=
nullptr)
916 if (shopItem !=
nullptr && amount <= 0)
920 if (buyDialog !=
nullptr)
941 const size_t idx =
data.find(
' ');
942 if (idx == std::string::npos)
952 _(
"error: player busy") + std::string(
" "),
962 std::stringstream ss(
data);
976 id = atoi(part1.c_str());
977 price = atoi(part2.c_str());
978 amount = atoi(part3.c_str());
995 if (item2 ==
nullptr ||
1001 _(
"error: Can't sell this item") + std::string(
" "),
1013 _(
"error: Can't buy this item") + std::string(
" "),
1047 _(
"Request for Trade"),
1075 if (counterTime == 0 || counterTime >
cur_time)
1077 else if (counterTime + 10 >
cur_time)
1085 const int mode)
const
1087 if (shopItem ==
nullptr)
1090 STD_VECTOR<ShopItem*> items;
1096 FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
1098 const ShopItem *
const item = *(it);
1099 if (item ==
nullptr)
1115 if ((
localPlayer ==
nullptr) || (shopItem ==
nullptr))
1123 for (
unsigned f = 0; f < inv->
getSize(); f ++)
1126 if ((item !=
nullptr) && item->
getId() == shopItem->
getId())
ActorManager * actorManager
#define fromBool(val, name)
Net::BuyingStoreHandler * buyingStoreHandler
Net::ChatHandler * chatHandler
#define reportAlways(...)
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
void enableShop(const bool b)
ShopItem * addItem(const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
void setMoney(const int amount)
static void distributeEvent(const bool b)
void addWhisper(const std::string &nick, const std::string &mes, const ChatMsgTypeT own)
bool getBoolValue(const std::string &key) const
void setValue(const std::string &key, const std::string &value)
int getIntValue(const std::string &key) const
Item * getItem(const int index) const
Item * findItem(const int itemId, const ItemColor color) const
static void showWindow(const ItemAmountWindowUsageT usage, Window *const parent, Item *const item, int maxRange, const int tag)
const std::string & getName() const
void setQuantity(const int quantity)
void setInvIndex(const int index)
ItemColor getColor() const
ItemTypeT getType() const
const ItemInfo & getInfo() const
void setRowHeight(const int n, const int h)
void addSelectionListener(SelectionListener *const selectionListener)
void updateStatus() const
virtual void create(const std::string &name, const int maxMoney, const bool flag, const std::vector< ShopItem * > &items) const =0
virtual void close() const =0
virtual void channelMessage(const std::string &channel, const std::string &text) const =0
virtual void privateMessage(const std::string &recipient, const std::string &text) const =0
virtual void request(const Being *const being) const
virtual void close() const =0
virtual void createShop(const std::string &name, const bool flag, const std::vector< ShopItem * > &items) const =0
void ignoreTrade(const std::string &name) const
void addItem(const Item *const item, const int price)
void setMoney(const int amount)
std::string serverConfigDir
void registerWindowForReset(Window *const window)
void setDisabled(const bool b)
ShopItem * addItemNoDup(const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
std::vector< ShopItem * > & items()
void del(const unsigned int i)
ShopItem * addItem(const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
int getNumberOfElements()
void setPriceCheck(const bool check)
void setDialog(EditDialog *const dialog)
void vendingEnabled(const bool b)
void sendMessage(const std::string &nick, std::string data, const bool random)
void giveList(const std::string &nick, const int mode)
ShopItems * mBuyShopItems
bool findShopItem(const ShopItem *const shopItem, const int mode) const
void updateButtonsAndLabels()
time_t mLastRequestTimeItem
ShopListBox * mCurrentShopItemList
void addSellItem(const Item *const item, const int amount, const int price)
ShopItems * mSellShopItems
time_t mLastRequestTimeList
void buyingStoreEnabled(const bool b)
void buyingStoreSlotsChanged(const int slots)
ShopListBox * mSellShopItemList
static bool checkFloodCounter(time_t &counterTime)
void action(const ActionEvent &event)
static void showList(const std::string &nick, std::string data)
static DialogList instances
void valueChanged(const SelectionEvent &event)
std::string mSellShopName
void announce(ShopItems *const list, const int mode)
ShopListBox * mBuyShopItemList
void processRequest(const std::string &nick, std::string data, const int mode)
CheckBox * mAnnounceLinks
static int sumAmount(const Item *const shopItem)
void vendingSlotsChanged(const int slots)
std::list< ShopWindow * > DialogList
void setVisible(Visible visible)
void addBuyItem(const Item *const item, const int amount, const int price)
void setShopName(const std::string &name)
void playGuiSound(const std::string &name)
void addAutoMoney(const std::string &nick, const int money)
void addAutoItem(const std::string &nick, Item *const item, const int amount)
static void distributeEvent(const bool b)
void setResizable(const bool resize)
ContainerPlacer getPlacer(const int x, const int y)
virtual void setVisible(Visible visible)
void setWindowName(const std::string &name)
int getOption(const std::string &name, const int def) const
void setCaption(const std::string &caption)
void setMinHeight(const int height)
void setMinWidth(const int width)
void enableVisibleSound(bool b)
void setCloseButton(const bool flag)
void setStickyButtonLock(const bool sticky)
Configuration serverConfig
const std::string TRADE_CHANNEL
const std::string DEFAULT_CURRENCY
#define FOR_EACH(type, iter, array)
const ItemColor ItemColor_one
const ItemColor ItemColor_zero
LocalPlayer * localPlayer
bool msg(InputEvent &event)
ServerTypeT getNetworkType()
Inventory * getInventory()
int32_t getAttribute(const AttributesT id)
Inventory * getCartInventory()
Net::VendingHandler * vendingHandler
Net::TradeHandler * tradeHandler
#define BLOCK_START(name)
PlayerRelationsManager playerRelations
ConfirmDialog * confirmDlg
SetupWindow * setupWindow
ShopRenameListener shopRenameListener
std::string tradePartnerName
static const std::string SOUND_TRADE
static const std::string SOUND_REQUEST
SoundManager soundManager
std::string strprintf(const char *const format,...)
unsigned int decodeStr(const std::string &str)
const std::string encodeStr(unsigned int value, const unsigned int size)
TradeWindow * tradeWindow