summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-07-11 20:49:20 +0300
committerAndrei Karas <akaras@inbox.ru>2013-07-11 20:52:50 +0300
commite36c735ce6569cd9c0e668632e59bcbe3280d507 (patch)
treeeb8fa3f8800d95bcd0c6b3c1ea314567f56debb4 /src
parentffd452cd1ee7d252355c259ca2bae1d40c0e97e9 (diff)
downloadplus-e36c735ce6569cd9c0e668632e59bcbe3280d507.tar.gz
plus-e36c735ce6569cd9c0e668632e59bcbe3280d507.tar.bz2
plus-e36c735ce6569cd9c0e668632e59bcbe3280d507.tar.xz
plus-e36c735ce6569cd9c0e668632e59bcbe3280d507.zip
Add chat command for gms for creating items.
New command: /createitems It will open creation window.
Diffstat (limited to 'src')
-rw-r--r--src/commands.cpp30
-rw-r--r--src/commands.h3
-rw-r--r--src/gui/buydialog.cpp30
-rw-r--r--src/gui/buydialog.h9
-rw-r--r--src/gui/itemamountwindow.cpp2
-rw-r--r--src/gui/textcommandeditor.cpp2
-rw-r--r--src/net/adminhandler.h3
-rw-r--r--src/net/ea/adminhandler.cpp16
-rw-r--r--src/net/ea/adminhandler.h3
-rw-r--r--src/resources/itemdb.cpp2
10 files changed, 92 insertions, 8 deletions
diff --git a/src/commands.cpp b/src/commands.cpp
index c83001cc1..e0bb195d0 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -33,6 +33,7 @@
#include "nullopenglgraphics.h"
#include "party.h"
+#include "gui/buydialog.h"
#include "gui/chatwindow.h"
#include "gui/helpwindow.h"
#include "gui/gui.h"
@@ -64,6 +65,8 @@
#include "resources/subimage.h"
#endif
+#include "resources/itemdb.h"
+#include "resources/iteminfo.h"
#include "resources/resourcemanager.h"
#include "utils/gettext.h"
@@ -1198,6 +1201,33 @@ impHandler1(testParticle)
player_node->setTestParticle(args);
}
+impHandler0(createItems)
+{
+ BuyDialog *const dialog = new BuyDialog();
+ const ItemDB::ItemInfos &items = ItemDB::getItemInfos();
+ FOR_EACH (ItemDB::ItemInfos::const_iterator, it, items)
+ {
+ const ItemInfo *const info = (*it).second;
+ const int id = info->getId();
+ if (id <= 0)
+ continue;
+
+ const int colors = info->getColorsSize();
+ if (!colors || serverVersion < 1)
+ {
+ dialog->addItem(id, 1, 100, 0);
+ }
+ else
+ {
+ for (int f = 0; f < colors; f ++)
+ {
+ if (!info->getColor(f).empty())
+ dialog->addItem(id, f, 100, 0);
+ }
+ }
+ }
+}
+
impHandler0(testsdlfont)
{
#if defined USE_OPENGL && defined DEBUG_SDLFONT
diff --git a/src/commands.h b/src/commands.h
index 4b0e2a0f8..933b5a918 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -124,6 +124,7 @@ namespace Commands
decHandler(disableAway);
decHandler(enableAway);
decHandler(testParticle);
+ decHandler(createItems);
void replaceVars(std::string &str);
} // namespace Commands
@@ -215,6 +216,7 @@ enum
COMMAND_SETHOME,
COMMAND_MAGICATTACK,
COMMAND_TEST_PARTICLE,
+ COMMAND_CREATEITEMS,
COMMAND_HACK,
END_COMMANDS
};
@@ -306,6 +308,7 @@ static const CommandInfo commands[] =
{"sethome", nullptr, Input::KEY_SET_HOME, false},
{"magicattack", nullptr, Input::KEY_MAGIC_ATTACK, false},
{"testparticle", &Commands::testParticle, -1, true},
+ {"createitems", &Commands::createItems, -1, false},
{"hack", &Commands::hack, -1, true}
};
diff --git a/src/gui/buydialog.cpp b/src/gui/buydialog.cpp
index a6d56e220..6c9cc0bd7 100644
--- a/src/gui/buydialog.cpp
+++ b/src/gui/buydialog.cpp
@@ -37,6 +37,7 @@
#include "gui/widgets/shoplistbox.h"
#include "gui/widgets/slider.h"
+#include "net/adminhandler.h"
#include "net/buysellhandler.h"
#include "net/net.h"
#include "net/npchandler.h"
@@ -188,6 +189,18 @@ class SortItemTypeFunctor final
BuyDialog::DialogList BuyDialog::instances;
+BuyDialog::BuyDialog() :
+ // TRANSLATORS: buy dialog name
+ Window(_("Create items"), false, nullptr, "buy.xml"),
+ gcn::ActionListener(),
+ gcn::SelectionListener(),
+ mNpcId(0), mMoney(0), mAmountItems(0), mMaxItems(0), mNick(),
+ mSortModel(nullptr),
+ mSortDropDown(nullptr)
+{
+ init();
+}
+
BuyDialog::BuyDialog(const int npcId) :
// TRANSLATORS: buy dialog name
Window(_("Buy"), false, nullptr, "buy.xml"),
@@ -210,7 +223,6 @@ BuyDialog::BuyDialog(std::string nick) :
mSortDropDown(new DropDown(this, mSortModel, false, false, this, "sort"))
{
init();
- logger->log("BuyDialog::BuyDialog nick:" + mNick);
}
void BuyDialog::init()
@@ -255,7 +267,8 @@ void BuyDialog::init()
// You may change this symbol if your language uses another.
mDecreaseButton = new Button(this, _("-"), "dec", this);
// TRANSLATORS: buy dialog button
- mBuyButton = new Button(this, _("Buy"), "buy", this);
+ mBuyButton = new Button(this, mNpcId == 0
+ ? _("Create") :_("Buy"), "buy", this);
// TRANSLATORS: buy dialog button
mQuitButton = new Button(this, _("Quit"), "quit", this);
// TRANSLATORS: buy dialog button
@@ -420,7 +433,13 @@ void BuyDialog::action(const gcn::ActionEvent &event)
}
else if (eventId == "buy" && mAmountItems > 0 && mAmountItems <= mMaxItems)
{
- if (mNpcId != -1)
+ if (!mNpcId)
+ {
+ const ShopItem *const item = mShopItems->at(selectedItem);
+ Net::getAdminHandler()->createItems(item->getId(),
+ mAmountItems, item->getColor());
+ }
+ else if (mNpcId != -1)
{
const ShopItem *const item = mShopItems->at(selectedItem);
Net::getNpcHandler()->buyItem(mNpcId, item->getId(),
@@ -444,7 +463,6 @@ void BuyDialog::action(const gcn::ActionEvent &event)
{
Net::getBuySellHandler()->sendBuyRequest(mNick,
item, mAmountItems);
-// logger->log("buy button mNick:" + mNick);
if (tradeWindow)
{
tradeWindow->addAutoMoney(mNick,
@@ -480,7 +498,9 @@ void BuyDialog::updateButtonsAndLabels()
const int itemPrice = item->getPrice();
// Calculate how many the player can afford
- if (itemPrice)
+ if (!mNpcId)
+ mMaxItems = 100;
+ else if (itemPrice)
mMaxItems = mMoney / itemPrice;
else
mMaxItems = 1;
diff --git a/src/gui/buydialog.h b/src/gui/buydialog.h
index 35cc2d8db..875184851 100644
--- a/src/gui/buydialog.h
+++ b/src/gui/buydialog.h
@@ -54,10 +54,19 @@ class BuyDialog final : public Window,
*
* @see Window::Window
*/
+ BuyDialog();
+
+ /**
+ * Constructor.
+ *
+ * @see Window::Window
+ */
explicit BuyDialog(const int npcId);
/**
* Constructor.
+ *
+ * @see Window::Window
*/
explicit BuyDialog(std::string nick);
diff --git a/src/gui/itemamountwindow.cpp b/src/gui/itemamountwindow.cpp
index 3df003bfb..61760f6d3 100644
--- a/src/gui/itemamountwindow.cpp
+++ b/src/gui/itemamountwindow.cpp
@@ -53,7 +53,7 @@ public:
ItemsModal() :
mStrings()
{
- std::map<int, ItemInfo*> items = ItemDB::getItemInfos();
+ const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos();
std::list<std::string> tempStrings;
for (std::map<int, ItemInfo*>::const_iterator
diff --git a/src/gui/textcommandeditor.cpp b/src/gui/textcommandeditor.cpp
index 449196ed8..029089704 100644
--- a/src/gui/textcommandeditor.cpp
+++ b/src/gui/textcommandeditor.cpp
@@ -57,7 +57,7 @@ public:
IconsModal() :
mStrings()
{
- std::map<int, ItemInfo*> items = ItemDB::getItemInfos();
+ const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos();
std::list<std::string> tempStrings;
for (std::map<int, ItemInfo*>::const_iterator
diff --git a/src/net/adminhandler.h b/src/net/adminhandler.h
index eca8ef4d0..7178aacae 100644
--- a/src/net/adminhandler.h
+++ b/src/net/adminhandler.h
@@ -58,6 +58,9 @@ class AdminHandler
virtual void warp(const std::string &map,
const int x, const int y) const = 0;
+
+ virtual void createItems(const int id, const int color,
+ const int amount) = 0;
};
} // namespace Net
diff --git a/src/net/ea/adminhandler.cpp b/src/net/ea/adminhandler.cpp
index 0d2245330..9e1956edd 100644
--- a/src/net/ea/adminhandler.cpp
+++ b/src/net/ea/adminhandler.cpp
@@ -28,6 +28,8 @@
#include "debug.h"
+extern int serverVersion;
+
namespace Ea
{
@@ -70,4 +72,18 @@ void AdminHandler::warp(const std::string &map, const int x, const int y) const
"@warp %s %d %d", map.c_str(), x, y), GENERAL_CHANNEL);
}
+void AdminHandler::createItems(const int id, const int color, const int amount)
+{
+ if (serverVersion < 1)
+ {
+ Net::getChatHandler()->talk(strprintf("@item %d %d",
+ id, amount), GENERAL_CHANNEL);
+ }
+ else
+ {
+ Net::getChatHandler()->talk(strprintf("@item %d %d %d",
+ id, color, amount), GENERAL_CHANNEL);
+ }
+}
+
} // namespace Ea
diff --git a/src/net/ea/adminhandler.h b/src/net/ea/adminhandler.h
index 7112bb75d..fb0ddfd0c 100644
--- a/src/net/ea/adminhandler.h
+++ b/src/net/ea/adminhandler.h
@@ -55,6 +55,9 @@ class AdminHandler : public Net::AdminHandler
virtual void warp(const std::string &map,
const int x, const int y) const override;
+
+ void createItems(const int id, const int color,
+ const int amount);
};
} // namespace Ea
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index a7310036d..8e5551af3 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -568,7 +568,7 @@ const ItemInfo &ItemDB::get(const std::string &name)
return *(i->second);
}
-const std::map<int, ItemInfo*> &ItemDB::getItemInfos()
+const ItemDB::ItemInfos &ItemDB::getItemInfos()
{
return mItemInfos;
}