summaryrefslogtreecommitdiff
path: root/src/playerinfo.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-06-23 12:21:55 +0300
committerAndrei Karas <akaras@inbox.ru>2013-06-23 17:36:25 +0300
commit4c57a567eec8b3df0b0009b5520d647cccb83338 (patch)
tree6677639ab67b1209532d20d0ebffa52e4227cdc8 /src/playerinfo.cpp
parenta685e41954590525f5a9f215dbd37a286ae2bd37 (diff)
downloadmanaverse-4c57a567eec8b3df0b0009b5520d647cccb83338.tar.gz
manaverse-4c57a567eec8b3df0b0009b5520d647cccb83338.tar.bz2
manaverse-4c57a567eec8b3df0b0009b5520d647cccb83338.tar.xz
manaverse-4c57a567eec8b3df0b0009b5520d647cccb83338.zip
Add support for protecting items.
Protected item cant be selled, traded, dropped, used. Protect/unprotect item can be from context menu.
Diffstat (limited to 'src/playerinfo.cpp')
-rw-r--r--src/playerinfo.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp
index 673e6f8cf..f2e933a24 100644
--- a/src/playerinfo.cpp
+++ b/src/playerinfo.cpp
@@ -22,6 +22,7 @@
#include "playerinfo.h"
#include "client.h"
+#include "configuration.h"
#include "depricatedevent.h"
#include "inventory.h"
#include "depricatedlistener.h"
@@ -53,6 +54,7 @@ signed char mSpecialRechargeUpdateNeeded = 0;
bool mTrading = false;
int mLevelProgress = 0;
+std::set<int> mProtectedItems;
// --- Triggers ---------------------------------------------------------------
@@ -313,6 +315,13 @@ void deinit()
clearInventory();
}
+void loadData()
+{
+ mProtectedItems.clear();
+ splitToIntSet(mProtectedItems,
+ serverConfig.getStringValue("protectedItems"), ',');
+}
+
void clear()
{
mData.mSkills.clear();
@@ -344,4 +353,38 @@ void stateChange(const int state)
}
}
+static void saveProtectedItems()
+{
+ std::string str;
+ std::set<int>::const_iterator it = mProtectedItems.begin();
+ std::set<int>::const_iterator it_end = mProtectedItems.end();
+ if (it != it_end)
+ str.append(toString(*it));
+ ++ it;
+ while (it != it_end)
+ {
+ str.append(",").append(toString(*it));
+ ++ it;
+ }
+ serverConfig.setValue("protectedItems", str);
+ serverConfig.write();
+}
+
+void protectItem(const int id)
+{
+ mProtectedItems.insert(id);
+ saveProtectedItems();
+}
+
+void unprotectItem(const int id)
+{
+ mProtectedItems.erase(id);
+ saveProtectedItems();
+}
+
+bool isItemProtected(const int id)
+{
+ return mProtectedItems.find(id) != mProtectedItems.end();
+}
+
} // namespace PlayerInfo