summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--src/extensions.h34
-rw-r--r--src/gui/chat.cpp1023
-rw-r--r--src/gui/inventorywindow.cpp6
-rw-r--r--src/gui/itemcontainer.cpp15
-rw-r--r--src/gui/itemcontainer.h3
-rw-r--r--src/gui/trade.cpp9
-rw-r--r--src/inventory.cpp29
-rw-r--r--src/inventory.h10
-rw-r--r--src/localplayer.cpp8
-rw-r--r--src/localplayer.h16
-rw-r--r--src/net/charserverhandler.cpp16
-rw-r--r--src/net/inventoryhandler.cpp106
-rw-r--r--src/net/protocol.h19
14 files changed, 716 insertions, 591 deletions
diff --git a/ChangeLog b/ChangeLog
index 99952782..bc9580fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2008-09-12 Lloyd Bryant ("Sanga") <sanga@aethyra.com>
+
+ * Changed default port for Aethyra to 21001
+ * Modified "/where" command to display X and Y coordinates
+ (Again - this was done on 2008-08-21, but the changes
+ were overwritten somehow)
+ * Added client support for Heal spell ("/cast heal")
+ * Added client support for Gather spell ("/cast gather")
+ * some changes to inventory system, to support the use of
+ "Kafra" storage (this is not yet operational - these
+ changes are only part of what's required to enable storage
+ in the client)
+
2008-09-04 Douglas Boffey ("Scraggy") <scraggy@aethyra.com>
* Added code to change colours in the chatlog
diff --git a/src/extensions.h b/src/extensions.h
new file mode 100644
index 00000000..5b95afc8
--- /dev/null
+++ b/src/extensions.h
@@ -0,0 +1,34 @@
+/*
+ * Aethyra
+ * Copyright 2008 Lloyd Bryant <sanga@aethyra.com>
+ *
+ * This file is part of the Aethyra project.
+ *
+ * Aethyra is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * Aethyra is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef _EXTENSIONS_
+#define _EXTENSIONS_
+
+struct EXTENSIONS
+{
+ bool aethyra_inventory;
+ bool aethyra_spells;
+ bool aethyra_misc;
+};
+
+extern struct EXTENSIONS extensions;
+#endif
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 8d9dac9d..918b4dbe 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -39,16 +39,15 @@
#include "../beingmanager.h"
#include "../recorder.h"
#include "../party.h"
+#include "../extensions.h"
#include "../net/messageout.h"
#include "../net/protocol.h"
#include "../utils/trim.h"
-ChatWindow::ChatWindow(Network *network):
- Window(""),
- mNetwork(network),
- mTmpVisible(false)
+ChatWindow::ChatWindow(Network * network):
+Window(""), mNetwork(network), mTmpVisible(false)
{
setWindowName("Chat");
@@ -65,10 +64,10 @@ ChatWindow::ChatWindow(Network *network):
mTextOutput->disableLinksAndUserColors();
mTextOutput->setMaxRow((int) config.getValue("ChatLogLength", 0));
mScrollArea = new ScrollArea(mTextOutput);
- mScrollArea->setPosition(
- mScrollArea->getFrameSize(), mScrollArea->getFrameSize());
- mScrollArea->setScrollPolicy(
- gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_ALWAYS);
+ mScrollArea->setPosition(mScrollArea->getFrameSize(),
+ mScrollArea->getFrameSize());
+ mScrollArea->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER,
+ gcn::ScrollArea::SHOW_ALWAYS);
mScrollArea->setOpaque(false);
add(mScrollArea);
@@ -96,81 +95,79 @@ ChatWindow::~ChatWindow()
}
void
-ChatWindow::logic()
+ ChatWindow::logic()
{
// todo: only do this when the size changes (updateWidgets?)
const gcn::Rectangle area = getChildrenArea();
mChatInput->setPosition(mChatInput->getFrameSize(),
- area.height - mChatInput->getHeight() -
- mChatInput->getFrameSize());
+ area.height - mChatInput->getHeight() -
+ mChatInput->getFrameSize());
mChatInput->setWidth(area.width - 2 * mChatInput->getFrameSize());
mScrollArea->setWidth(area.width - 2 * mScrollArea->getFrameSize());
mScrollArea->setHeight(area.height - 2 * mScrollArea->getFrameSize() -
- mChatInput->getHeight() - 5);
+ mChatInput->getHeight() - 5);
mScrollArea->logic();
}
-void
-ChatWindow::chatLog(std::string line, int own, bool ignoreRecord)
+void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord)
{
// Trim whitespace
trim(line);
CHATLOG tmp;
- tmp.own = own;
+ tmp.own = own;
tmp.nick = "";
tmp.text = line;
// Fix the owner of welcome message.
- if (line.substr(0, 7) == "Welcome")
- {
- own = BY_SERVER;
+ if (line.substr(0, 7) == "Welcome") {
+ own = BY_SERVER;
}
std::string::size_type pos = line.find(" : ");
if (pos != std::string::npos) {
- tmp.nick = line.substr(0, pos);
- tmp.text = line.substr(pos + 3);
+ tmp.nick = line.substr(0, pos);
+ tmp.text = line.substr(pos + 3);
}
std::string lineColor = "##C";
switch (own) {
- case BY_GM:
- tmp.nick += std::string("Global announcement: ");
- lineColor = "##G";
- break;
- case BY_PLAYER:
- tmp.nick += CAT_NORMAL;
- lineColor = "##Y";
- break;
- case BY_OTHER:
- tmp.nick += CAT_NORMAL;
- lineColor = "##C";
- break;
- case BY_SERVER:
- tmp.nick = "Server: ";
- tmp.text = line;
- lineColor = "##S";
- break;
- case BY_PARTY:
- tmp.nick += CAT_NORMAL;
- lineColor = "##P";
- break;
- case ACT_WHISPER:
- tmp.nick += CAT_WHISPER;
- lineColor = "##W";
- break;
- case ACT_IS:
- tmp.nick += CAT_IS;
- lineColor = "##I";
- break;
- case BY_LOGGER:
- tmp.nick = "";
- tmp.text = line;
- lineColor = "##L";
- break;
+ case BY_GM:
+ tmp.nick += std::string("Global announcement: ");
+ lineColor = "##G";
+ break;
+ case BY_PLAYER:
+ tmp.nick += CAT_NORMAL;
+ lineColor = "##Y";
+ break;
+ case BY_OTHER:
+ tmp.nick += CAT_NORMAL;
+ lineColor = "##C";
+ break;
+ case BY_SERVER:
+ tmp.nick = "Server: ";
+ tmp.text = line;
+ lineColor = "##S";
+ break;
+ case BY_PARTY:
+ tmp.nick += CAT_NORMAL;
+ lineColor = "##P";
+ break;
+ case ACT_WHISPER:
+ tmp.nick += CAT_WHISPER;
+ lineColor = "##W";
+ break;
+ case ACT_IS:
+ tmp.nick += CAT_IS;
+ lineColor = "##I";
+ break;
+ case BY_LOGGER:
+ tmp.nick = "";
+ tmp.text = line;
+ lineColor = "##L";
+ break;
}
// Get the current system time
@@ -179,411 +176,389 @@ ChatWindow::chatLog(std::string line, int own, bool ignoreRecord)
// Format the time string properly
std::stringstream timeStr;
- timeStr << "["
- << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
- << (int)(((t / 60) / 60) % 24)
- << ":"
- << (((t / 60) % 60 < 10) ? "0" : "")
- << (int)((t / 60) % 60)
- << "] ";
+ timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
+ << (int) (((t / 60) / 60) % 24)
+ << ":" << (((t / 60) % 60 < 10) ? "0" : "")
+ << (int) ((t / 60) % 60)
+ << "] ";
line = lineColor + timeStr.str() + tmp.nick + tmp.text;
// We look if the Vertical Scroll Bar is set at the max before
// adding a row, otherwise the max will always be a row higher
// at comparison.
- if (mScrollArea->getVerticalScrollAmount() == mScrollArea->getVerticalMaxScroll())
- {
- mTextOutput->addRow(line);
- mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll());
- }
- else
- {
- mTextOutput->addRow(line);
+ if (mScrollArea->getVerticalScrollAmount() ==
+ mScrollArea->getVerticalMaxScroll()) {
+ mTextOutput->addRow(line);
+ mScrollArea->setVerticalScrollAmount(mScrollArea->
+ getVerticalMaxScroll());
+ } else {
+ mTextOutput->addRow(line);
}
mRecorder->record(line.substr(3));
}
-void
-ChatWindow::chatLog(CHATSKILL act)
+void ChatWindow::chatLog(CHATSKILL act)
{
chatLog(const_msg(act), BY_SERVER);
}
-void
-ChatWindow::action(const gcn::ActionEvent &event)
+void ChatWindow::action(const gcn::ActionEvent & event)
{
- if (event.getId() == "chatinput")
- {
- std::string message = mChatInput->getText();
-
- if (!message.empty()) {
- // If message different from previous, put it in the history
- if (mHistory.empty() || message != mHistory.back()) {
- mHistory.push_back(message);
- }
-
- // Reset history iterator
- mCurHist = mHistory.end();
-
- // Send the message to the server
- chatSend(player_node->getName(), message);
-
- // Clear the text from the chat input
- mChatInput->setText("");
- }
- if (message.empty() || !mReturnToggles)
- {
- // Remove focus and hide input
- mFocusHandler->focusNone();
-
- // If the chatWindow is shown up because you want to send a message
- // It should hide now
- if (mTmpVisible)
- {
- setVisible(false);
- }
- }
+ if (event.getId() == "chatinput") {
+ std::string message = mChatInput->getText();
+
+ if (!message.empty()) {
+ // If message different from previous, put it in the history
+ if (mHistory.empty() || message != mHistory.back()) {
+ mHistory.push_back(message);
+ }
+ // Reset history iterator
+ mCurHist = mHistory.end();
+
+ // Send the message to the server
+ chatSend(player_node->getName(), message);
+
+ // Clear the text from the chat input
+ mChatInput->setText("");
+ }
+ if (message.empty() || !mReturnToggles) {
+ // Remove focus and hide input
+ mFocusHandler->focusNone();
+
+ // If the chatWindow is shown up because you want to send a message
+ // It should hide now
+ if (mTmpVisible) {
+ setVisible(false);
+ }
+ }
}
}
-void
-ChatWindow::requestChatFocus()
+void ChatWindow::requestChatFocus()
{
// Make sure chatWindow is visible
- if (!isVisible())
- {
- setVisible(true);
+ if (!isVisible()) {
+ setVisible(true);
- /*
- * This is used to hide chatWindow after sending the message. There is
- * a trick here, because setVisible will set mTmpVisible to false, you
- * have to put this sentence *after* setVisible, not before it
- */
- mTmpVisible = true;
+ /*
+ * This is used to hide chatWindow after sending the message. There is
+ * a trick here, because setVisible will set mTmpVisible to false, you
+ * have to put this sentence *after* setVisible, not before it
+ */
+ mTmpVisible = true;
}
-
// Give focus to the chat input
mChatInput->setVisible(true);
mChatInput->requestFocus();
}
-bool
-ChatWindow::isInputFocused()
+bool ChatWindow::isInputFocused()
{
return mChatInput->isFocused();
}
-void
-ChatWindow::chatSend(const std::string &nick, std::string msg)
+void ChatWindow::chatSend(const std::string & nick, std::string msg)
{
/* Some messages are managed client side, while others
* require server handling by proper packet. Probably
* those if elses should be replaced by protocol calls */
// Send party message
- if (msg.at(0) == mPartyPrefix)
- {
- msg.erase(0, 1);
- std::size_t length = msg.length() + 1;
-
- if (length == 0)
- {
- chatLog("Trying to send a blank party message.", BY_SERVER);
- return;
- }
- MessageOut outMsg(mNetwork);
-
- outMsg.writeInt16(CMSG_PARTY_MESSAGE);
- outMsg.writeInt16(length + 4);
- outMsg.writeString(msg, length);
- return;
+ if (msg.at(0) == mPartyPrefix) {
+ msg.erase(0, 1);
+ std::size_t length = msg.length() + 1;
+
+ if (length == 0) {
+ chatLog("Trying to send a blank party message.", BY_SERVER);
+ return;
+ }
+ MessageOut outMsg(mNetwork);
+
+ outMsg.writeInt16(CMSG_PARTY_MESSAGE);
+ outMsg.writeInt16(length + 4);
+ outMsg.writeString(msg, length);
+ return;
}
// Prepare ordinary message
if (msg.substr(0, 1) != "/") {
- msg = nick + " : " + msg;
+ msg = nick + " : " + msg;
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(CMSG_CHAT_MESSAGE);
- // Added + 1 in order to let eAthena parse admin commands correctly
- outMsg.writeInt16(msg.length() + 4 + 1);
- outMsg.writeString(msg, msg.length() + 1);
- return;
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CMSG_CHAT_MESSAGE);
+ // Added + 1 in order to let eAthena parse admin commands correctly
+ outMsg.writeInt16(msg.length() + 4 + 1);
+ outMsg.writeString(msg, msg.length() + 1);
+ return;
}
msg.erase(0, 1);
trim(msg);
std::size_t space = msg.find(" ");
std::string command = msg.substr(0, space);
- if (space == std::string::npos)
- {
- msg = "";
- }
- else
- {
- msg = msg.substr(space);
- trim(msg);
- }
-
- if (command == "announce")
- {
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(0x0099);
- outMsg.writeInt16(msg.length() + 4);
- outMsg.writeString(msg, msg.length());
- return;
- }
- if (command == "help")
- {
- std::size_t space = msg.find(" ");
- std::string msg1;
- if (space == std::string::npos)
- {
- msg1 = "";
- }
- else
- {
- msg1 = msg.substr(space + 1, msg.length());
- msg = msg.substr(0, space);
- }
- if (msg != "" && msg.at(0) == '/')
- {
- msg.erase(0, 1);
- }
- while (msg1 != "" && msg1.at(0) == ' ')
- {
- msg1.erase(0, 1);
- }
- help(msg, msg1);
- return;
- }
- if (command == "where")
- {
- chatLog(map_path, BY_SERVER);
- return;
- }
- if (command == "who")
- {
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(0x00c1);
- return;
- }
- if (command == "clear")
- {
- mTextOutput->clearRows();
- return;
- }
- if (command == "whisper")
- {
- std::string recvnick = "";
-
- if (msg.substr(0,1) == "\"")
- {
- const std::string::size_type pos = msg.find('"', 1);
- if (pos != std::string::npos) {
- recvnick = msg.substr(1, pos - 1);
- msg.erase(0, pos + 2);
- }
- }
- else
- {
- const std::string::size_type pos = msg.find(" ");
- if (pos != std::string::npos) {
- recvnick = msg.substr(0, pos);
- msg.erase(0, pos + 1);
- }
- }
-
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(CMSG_CHAT_WHISPER);
- outMsg.writeInt16(msg.length() + 28);
- outMsg.writeString(recvnick, 24);
- outMsg.writeString(msg, msg.length());
-
- chatLog("Whispering to " + recvnick + " : " + msg, BY_PLAYER);
- return;
- }
- if (command == "record")
- {
+ if (space == std::string::npos) {
+ msg = "";
+ } else {
+ msg = msg.substr(space);
+ trim(msg);
+ }
+
+ if (command == "announce") {
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(0x0099);
+ outMsg.writeInt16(msg.length() + 4);
+ outMsg.writeString(msg, msg.length());
+ return;
+ }
+ if (command == "help") {
+ std::size_t space = msg.find(" ");
+ std::string msg1;
+ if (space == std::string::npos) {
+ msg1 = "";
+ } else {
+ msg1 = msg.substr(space + 1, msg.length());
+ msg = msg.substr(0, space);
+ }
+ if (msg != "" && msg.at(0) == '/') {
+ msg.erase(0, 1);
+ }
+ while (msg1 != "" && msg1.at(0) == ' ') {
+ msg1.erase(0, 1);
+ }
+ help(msg, msg1);
+ return;
+ }
+ if (command == "where") {
+ // Display the current map, X, and Y
+ std::ostringstream where;
+ where << map_path << " " << player_node->mX << " " << player_node->mY;
+ chatLog(where.str(), BY_SERVER);
+ return;
+ }
+ if (command == "who") {
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(0x00c1);
+ return;
+ }
+ if (command == "clear") {
+ mTextOutput->clearRows();
+ return;
+ }
+ if (command == "whisper") {
+ std::string recvnick = "";
+
+ if (msg.substr(0, 1) == "\"") {
+ const std::string::size_type pos = msg.find('"', 1);
+ if (pos != std::string::npos) {
+ recvnick = msg.substr(1, pos - 1);
+ msg.erase(0, pos + 2);
+ }
+ } else {
+ const std::string::size_type pos = msg.find(" ");
+ if (pos != std::string::npos) {
+ recvnick = msg.substr(0, pos);
+ msg.erase(0, pos + 1);
+ }
+ }
+
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CMSG_CHAT_WHISPER);
+ outMsg.writeInt16(msg.length() + 28);
+ outMsg.writeString(recvnick, 24);
+ outMsg.writeString(msg, msg.length());
+
+ chatLog("Whispering to " + recvnick + " : " + msg, BY_PLAYER);
+ return;
+ }
+ if (command == "record") {
mRecorder->respond(msg);
- return;
- }
- if (command == "toggle")
- {
- if (msg == "")
- {
- chatLog(mReturnToggles ? "Return toggles chat."
- : "Message closes chat.", BY_SERVER);
- return;
- }
- msg = msg.substr(0, 1);
- if (msg == "1" || msg == "y" || msg == "t" || msg == "Y" || msg == "T")
- {
- chatLog("Return now toggles chat.", BY_SERVER);
- mReturnToggles = true;
- return;
- }
- if (msg == "0" || msg == "n" || msg == "f" || msg == "N" || msg == "F")
- {
- chatLog("Message now closes chat.", BY_SERVER);
- mReturnToggles = false;
- return;
- }
- chatLog("Options to /toggle are \"yes\", \"no\", \"true\", \"false\", "
- "\"1\", \"0\".", BY_SERVER);
- return;
- }
- if (command == "party")
- {
- if (msg == "")
- {
- chatLog("Unknown party command... Type \"/help\" party for more "
- "information.", BY_SERVER);
- return;
- }
- const std::string::size_type space = msg.find(" ");
- std::string rest = (space == std::string::npos ? ""
- : msg.substr(space + 1, msg.length()));
- if (rest != "")
- {
- msg = msg.substr(0, space);
- while (msg != "" && msg[0] == ' ')
- {
- msg = msg.substr(1, msg.length());
- }
- }
- party(msg, rest);
- return;
- }
- if (command == "present")
- {
- Beings &beings = beingManager->getAll();
- std::string response = "";
- for (BeingIterator bi = beings.begin(), be = beings.end();
- bi != be;
- ++bi)
- {
- if ((*bi)->getType() == Being::PLAYER)
- {
- if (response != "")
- {
- response += ", ";
- }
- response += (*bi)->getName();
- }
- }
- if (mRecorder->isRecording())
- {
- // Get the current system time
- time_t t;
- time(&t);
-
- // Format the time string properly
- std::stringstream timeStr;
- timeStr << "["
- << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
- << (int)(((t / 60) / 60) % 24)
- << ":"
- << (((t / 60) % 60 < 10) ? "0" : "")
- << (int)((t / 60) % 60)
- << "] ";
-
-
- mRecorder->record(timeStr.str() + "Present: " + response + ".");
- chatLog("Attendance written to record log.", BY_SERVER, true);
- }
- else
- {
- chatLog("Present: " + response, BY_SERVER);
- }
- return;
+ return;
+ }
+ if (command == "toggle") {
+ if (msg == "") {
+ chatLog(mReturnToggles ? "Return toggles chat."
+ : "Message closes chat.", BY_SERVER);
+ return;
+ }
+ msg = msg.substr(0, 1);
+ if (msg == "1" || msg == "y" || msg == "t" || msg == "Y" || msg == "T") {
+ chatLog("Return now toggles chat.", BY_SERVER);
+ mReturnToggles = true;
+ return;
+ }
+ if (msg == "0" || msg == "n" || msg == "f" || msg == "N" || msg == "F") {
+ chatLog("Message now closes chat.", BY_SERVER);
+ mReturnToggles = false;
+ return;
+ }
+ chatLog("Options to /toggle are \"yes\", \"no\", \"true\", \"false\", "
+ "\"1\", \"0\".", BY_SERVER);
+ return;
+ }
+ if (command == "party") {
+ if (msg == "") {
+ chatLog("Unknown party command... Type \"/help\" party for more "
+ "information.", BY_SERVER);
+ return;
+ }
+ const std::string::size_type space = msg.find(" ");
+ std::string rest = (space == std::string::npos ? ""
+ : msg.substr(space + 1, msg.length()));
+ if (rest != "") {
+ msg = msg.substr(0, space);
+ while (msg != "" && msg[0] == ' ') {
+ msg = msg.substr(1, msg.length());
+ }
+ }
+ party(msg, rest);
+ return;
+ }
+ if (command == "cast") {
+ /*
+ * This will eventually be replaced by a GUI, so
+ * we don't need to get too sophisticated
+ */
+ if (extensions.aethyra_spells) {
+ MessageOut outMsg(mNetwork);
+ if (msg == "heal") {
+ outMsg.writeInt16(0x03f3);
+ outMsg.writeInt16(0x01);
+ outMsg.writeInt32(0);
+ outMsg.writeInt8(0);
+ outMsg.writeInt8(0);
+ outMsg.writeString("", 24);
+ } else if (msg == "gather") {
+ outMsg.writeInt16(0x03f3);
+ outMsg.writeInt16(0x02);
+ outMsg.writeInt32(0);
+ outMsg.writeInt8(0);
+ outMsg.writeInt8(0);
+ outMsg.writeString("", 24);
+ } else {
+ chatLog("No such spell!", BY_SERVER);
+ }
+ } else {
+ chatLog("The current server doesn't support spells", BY_SERVER);
+ }
+ return;
+ }
+ if (command == "present") {
+ Beings & beings = beingManager->getAll();
+ std::string response = "";
+ for (BeingIterator bi = beings.begin(), be = beings.end();
+ bi != be; ++bi) {
+ if ((*bi)->getType() == Being::PLAYER) {
+ if (response != "") {
+ response += ", ";
+ }
+ response += (*bi)->getName();
+ }
+ }
+ if (mRecorder->isRecording()) {
+ // Get the current system time
+ time_t t;
+ time(&t);
+
+ // Format the time string properly
+ std::stringstream timeStr;
+ timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
+ << (int) (((t / 60) / 60) % 24)
+ << ":" << (((t / 60) % 60 < 10) ? "0" : "")
+ << (int) ((t / 60) % 60)
+ << "] ";
+
+
+ mRecorder->record(timeStr.str() + "Present: " + response + ".");
+ chatLog("Attendance written to record log.", BY_SERVER, true);
+ } else {
+ chatLog("Present: " + response, BY_SERVER);
+ }
+ return;
}
chatLog("Unknown command", BY_SERVER);
}
-std::string
-ChatWindow::const_msg(CHATSKILL act)
+std::string ChatWindow::const_msg(CHATSKILL act)
{
std::string msg;
if (act.success == SKILL_FAILED && act.skill == SKILL_BASIC) {
- switch (act.bskill) {
- case BSKILL_TRADE :
- msg = "Trade failed!";
- break;
- case BSKILL_EMOTE :
- msg = "Emote failed!";
- break;
- case BSKILL_SIT :
- msg = "Sit failed!";
- break;
- case BSKILL_CREATECHAT :
- msg = "Chat creating failed!";
- break;
- case BSKILL_JOINPARTY :
- msg = "Could not join party!";
- break;
- case BSKILL_SHOUT :
- msg = "Cannot shout!";
- break;
- }
-
- switch (act.reason) {
- case RFAIL_SKILLDEP :
- msg += " You have not yet reached a high enough level!";
- break;
- case RFAIL_INSUFHP :
- msg += " Insufficient HP!";
- break;
- case RFAIL_INSUFSP :
- msg += " Insufficient SP!";
- break;
- case RFAIL_NOMEMO :
- msg += " You have no memos!";
- break;
- case RFAIL_SKILLDELAY :
- msg += " You cannot do that right now!";
- break;
- case RFAIL_ZENY :
- msg += " Seems you need more Zeny... ;-)";
- break;
- case RFAIL_WEAPON :
- msg += " You cannot use this skill with that kind of weapon!";
- break;
- case RFAIL_REDGEM :
- msg += " You need another red gem!";
- break;
- case RFAIL_BLUEGEM :
- msg += " You need another blue gem!";
- break;
- case RFAIL_OVERWEIGHT :
- msg += " You're carrying to much to do this!";
- break;
- default :
- msg += " Huh? What's that?";
- break;
- }
+ switch (act.bskill) {
+ case BSKILL_TRADE:
+ msg = "Trade failed!";
+ break;
+ case BSKILL_EMOTE:
+ msg = "Emote failed!";
+ break;
+ case BSKILL_SIT:
+ msg = "Sit failed!";
+ break;
+ case BSKILL_CREATECHAT:
+ msg = "Chat creating failed!";
+ break;
+ case BSKILL_JOINPARTY:
+ msg = "Could not join party!";
+ break;
+ case BSKILL_SHOUT:
+ msg = "Cannot shout!";
+ break;
+ }
+
+ switch (act.reason) {
+ case RFAIL_SKILLDEP:
+ msg += " You have not yet reached a high enough level!";
+ break;
+ case RFAIL_INSUFHP:
+ msg += " Insufficient HP!";
+ break;
+ case RFAIL_INSUFSP:
+ msg += " Insufficient SP!";
+ break;
+ case RFAIL_NOMEMO:
+ msg += " You have no memos!";
+ break;
+ case RFAIL_SKILLDELAY:
+ msg += " You cannot do that right now!";
+ break;
+ case RFAIL_ZENY:
+ msg += " Seems you need more Zeny... ;-)";
+ break;
+ case RFAIL_WEAPON:
+ msg += " You cannot use this skill with that kind of weapon!";
+ break;
+ case RFAIL_REDGEM:
+ msg += " You need another red gem!";
+ break;
+ case RFAIL_BLUEGEM:
+ msg += " You need another blue gem!";
+ break;
+ case RFAIL_OVERWEIGHT:
+ msg += " You're carrying to much to do this!";
+ break;
+ default:
+ msg += " Huh? What's that?";
+ break;
+ }
} else {
- switch(act.skill) {
- case SKILL_WARP :
- msg = "Warp failed...";
- break;
- case SKILL_STEAL :
- msg = "Could not steal anything...";
- break;
- case SKILL_ENVENOM :
- msg = "Poison had no effect...";
- break;
- }
+ switch (act.skill) {
+ case SKILL_WARP:
+ msg = "Warp failed...";
+ break;
+ case SKILL_STEAL:
+ msg = "Could not steal anything...";
+ break;
+ case SKILL_ENVENOM:
+ msg = "Poison had no effect...";
+ break;
+ }
}
return msg;
}
-void
-ChatWindow::scroll(int amount)
+void ChatWindow::scroll(int amount)
{
if (!isVisible())
- return;
+ return;
int range = mScrollArea->getHeight() / 8 * amount;
gcn::Rectangle scr;
@@ -592,41 +567,34 @@ ChatWindow::scroll(int amount)
mTextOutput->showPart(scr);
}
-void
-ChatWindow::keyPressed(gcn::KeyEvent &event)
+void ChatWindow::keyPressed(gcn::KeyEvent & event)
{
if (event.getKey().getValue() == gcn::Key::DOWN &&
- mCurHist != mHistory.end())
- {
- // Move forward through the history
- HistoryIterator prevHist = mCurHist++;
- if (mCurHist != mHistory.end()) {
- mChatInput->setText(*mCurHist);
- mChatInput->setCaretPosition(mChatInput->getText().length());
- }
- else {
- mCurHist = prevHist;
- }
- }
- else if (event.getKey().getValue() == gcn::Key::UP &&
- mCurHist != mHistory.begin() && mHistory.size() > 0)
- {
- // Move backward through the history
- mCurHist--;
- mChatInput->setText(*mCurHist);
- mChatInput->setCaretPosition(mChatInput->getText().length());
+ mCurHist != mHistory.end()) {
+ // Move forward through the history
+ HistoryIterator prevHist = mCurHist++;
+ if (mCurHist != mHistory.end()) {
+ mChatInput->setText(*mCurHist);
+ mChatInput->setCaretPosition(mChatInput->getText().length());
+ } else {
+ mCurHist = prevHist;
+ }
+ } else if (event.getKey().getValue() == gcn::Key::UP &&
+ mCurHist != mHistory.begin() && mHistory.size() > 0) {
+ // Move backward through the history
+ mCurHist--;
+ mChatInput->setText(*mCurHist);
+ mChatInput->setCaretPosition(mChatInput->getText().length());
}
}
-void
-ChatWindow::setInputText(std::string input_str)
+void ChatWindow::setInputText(std::string input_str)
{
- mChatInput->setText(input_str + " ");
- requestChatFocus();
+ mChatInput->setText(input_str + " ");
+ requestChatFocus();
}
-void
-ChatWindow::setVisible(bool isVisible)
+void ChatWindow::setVisible(bool isVisible)
{
Window::setVisible(isVisible);
@@ -638,78 +606,64 @@ ChatWindow::setVisible(bool isVisible)
mTmpVisible = false;
}
-void
-ChatWindow::party(const std::string &command, const std::string &rest)
+void ChatWindow::party(const std::string & command, const std::string & rest)
{
- if (command == "prefix")
- {
- if (rest == "")
- {
- char temp[2] = ".";
- *temp = mPartyPrefix;
- chatLog("The current party prefix is " + std::string(temp),
- BY_SERVER);
- return;
- }
- if (rest.length() != 1)
- {
- chatLog("Party prefix must be one character long.", BY_SERVER);
- }
- else
- {
- if (rest == "/")
- {
- chatLog("Cannot use a '/' as the prefix.", BY_SERVER);
- }
- else
- {
- mPartyPrefix = rest.at(0);
- chatLog("Changing prefix to " + rest, BY_SERVER);
- }
- }
- return;
+ if (command == "prefix") {
+ if (rest == "") {
+ char temp[2] = ".";
+ *temp = mPartyPrefix;
+ chatLog("The current party prefix is " + std::string(temp),
+ BY_SERVER);
+ return;
+ }
+ if (rest.length() != 1) {
+ chatLog("Party prefix must be one character long.", BY_SERVER);
+ } else {
+ if (rest == "/") {
+ chatLog("Cannot use a '/' as the prefix.", BY_SERVER);
+ } else {
+ mPartyPrefix = rest.at(0);
+ chatLog("Changing prefix to " + rest, BY_SERVER);
+ }
+ }
+ return;
}
mParty->respond(command, rest);
}
-void
-ChatWindow::help(const std::string &msg1, const std::string &msg2)
+void ChatWindow::help(const std::string & msg1, const std::string & msg2)
{
chatLog("-- Help --", BY_SERVER);
- if (msg1 == "")
- {
- chatLog("/announce: Global announcement (GM only)", BY_SERVER);
- chatLog("/clear: Clears this window", BY_SERVER);
- chatLog("/help: Display this help.", BY_SERVER);
- mParty->help();
- chatLog("/present: Get list of players present", BY_SERVER);
- mRecorder->help();
- chatLog("/toggle: Determine whether <return> toggles the chat log.",
- BY_SERVER);
- chatLog("/where: Display map name", BY_SERVER);
- chatLog("/whisper <nick> <message>: Sends a private <message>"
- " to <nick>", BY_SERVER);
- chatLog("/who: Display number of online users", BY_SERVER);
- chatLog("For more information, type /help <command>", BY_SERVER);
- return;
- }
- if (msg1 == "announce")
- {
- chatLog("Command: /announce <msg>", BY_SERVER);
- chatLog("*** only available to a GM ***", BY_SERVER);
- chatLog("This command sends the message <msg> to "
- "all players currently online.", BY_SERVER);
- return;
- }
- if (msg1 == "clear")
- {
- chatLog("Command: /clear", BY_SERVER);
- chatLog("This command clears the chat log of previous chat.",
- BY_SERVER);
- return;
- }
- if (msg1 == "help")
- {
+ if (msg1 == "") {
+ chatLog("/announce: Global announcement (GM only)", BY_SERVER);
+ chatLog("/clear: Clears this window", BY_SERVER);
+ chatLog("/help: Display this help.", BY_SERVER);
+ mParty->help();
+ chatLog("/present: Get list of players present", BY_SERVER);
+ mRecorder->help();
+ chatLog("/toggle: Determine whether <return> toggles the chat log.",
+ BY_SERVER);
+ chatLog("/where: Display map name", BY_SERVER);
+ chatLog("/whisper <nick> <message>: Sends a private <message>"
+ " to <nick>", BY_SERVER);
+ chatLog("/who: Display number of online users", BY_SERVER);
+ chatLog("For more information, type /help <command>", BY_SERVER);
+ return;
+ }
+ if (msg1 == "announce") {
+ chatLog("Command: /announce <msg>", BY_SERVER);
+ chatLog("*** only available to a GM ***", BY_SERVER);
+ chatLog("This command sends the message <msg> to "
+ "all players currently online.", BY_SERVER);
+ return;
+ }
+ if (msg1 == "clear") {
+ chatLog("Command: /clear", BY_SERVER);
+ chatLog("This command clears the chat log of previous chat.",
+ BY_SERVER);
+ return;
+ }
+ if (msg1 == "help") {
chatLog("Command: /help", BY_SERVER);
chatLog("This command displays a list of all commands available.",
BY_SERVER);
@@ -717,58 +671,51 @@ ChatWindow::help(const std::string &msg1, const std::string &msg2)
chatLog("This command displays help on <command>.", BY_SERVER);
return;
}
- if (msg1 == "party")
- {
+ if (msg1 == "party") {
mParty->help(msg2);
- return;
- }
- if (msg1 == "present")
- {
- chatLog("Command: /present", BY_SERVER);
- chatLog("This command gets a list of players within hearing "
- "and sends it to either the record log if recording, or the "
- "chat log otherwise.", BY_SERVER);
- return;
- }
- if (msg1 == "record")
- {
+ return;
+ }
+ if (msg1 == "present") {
+ chatLog("Command: /present", BY_SERVER);
+ chatLog("This command gets a list of players within hearing "
+ "and sends it to either the record log if recording, or the "
+ "chat log otherwise.", BY_SERVER);
+ return;
+ }
+ if (msg1 == "record") {
mRecorder->help(msg2);
- return;
- }
- if (msg1 == "toggle")
- {
- chatLog("Command: /toggle <state>", BY_SERVER);
- chatLog("This command sets whether the return key should toggle the "
- "chat log, or whether the chat log turns off automatically.",
- BY_SERVER);
- chatLog("<state> can be one of \"1\", \"yes\", \"true\" to turn "
- "the toggle on, or \"0\", \"no\", \"false\" to turn the "
- "toggle off.", BY_SERVER);
- chatLog("Command: /toggle", BY_SERVER);
- chatLog("This command displays the return toggle status.", BY_SERVER);
- return;
- }
- if (msg1 == "where")
- {
- chatLog("Command: /where", BY_SERVER);
- chatLog("This command displays the name of the current map.",
- BY_SERVER);
- return;
- }
- if (msg1 == "whisper")
- {
- chatLog("Command: /whisper <nick> <msg>", BY_SERVER);
- chatLog("This command sends the message <msg> to <nick.", BY_SERVER);
- chatLog("If the <nick> has spaces in it, enclose it in "
- "double quotes (\").", BY_SERVER);
- return;
- }
- if (msg1 == "who")
- {
- chatLog("Command: /who", BY_SERVER);
- chatLog("This command displays the number of players currently "
- "online.", BY_SERVER);
- return;
+ return;
+ }
+ if (msg1 == "toggle") {
+ chatLog("Command: /toggle <state>", BY_SERVER);
+ chatLog("This command sets whether the return key should toggle the "
+ "chat log, or whether the chat log turns off automatically.",
+ BY_SERVER);
+ chatLog("<state> can be one of \"1\", \"yes\", \"true\" to turn "
+ "the toggle on, or \"0\", \"no\", \"false\" to turn the "
+ "toggle off.", BY_SERVER);
+ chatLog("Command: /toggle", BY_SERVER);
+ chatLog("This command displays the return toggle status.", BY_SERVER);
+ return;
+ }
+ if (msg1 == "where") {
+ chatLog("Command: /where", BY_SERVER);
+ chatLog("This command displays the name of the current map.",
+ BY_SERVER);
+ return;
+ }
+ if (msg1 == "whisper") {
+ chatLog("Command: /whisper <nick> <msg>", BY_SERVER);
+ chatLog("This command sends the message <msg> to <nick.", BY_SERVER);
+ chatLog("If the <nick> has spaces in it, enclose it in "
+ "double quotes (\").", BY_SERVER);
+ return;
+ }
+ if (msg1 == "who") {
+ chatLog("Command: /who", BY_SERVER);
+ chatLog("This command displays the number of players currently "
+ "online.", BY_SERVER);
+ return;
}
chatLog("Unknown command.", BY_SERVER);
chatLog("Type /help for a list of commands.", BY_SERVER);
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index b53fa43b..8866515f 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -57,7 +57,7 @@ InventoryWindow::InventoryWindow():
mUseButton = new Button("Use", "use", this);
mDropButton = new Button("Drop", "drop", this);
- mItems = new ItemContainer(player_node->getInventory());
+ mItems = new ItemContainer(player_node->getInventory(), 2);
mItems->addSelectionListener(this);
mInvenScroll = new ScrollArea(mItems);
@@ -94,8 +94,8 @@ void InventoryWindow::logic()
// Update weight information
mWeightLabel->setCaption(
- "Total Weight: " + toString(player_node->mTotalWeight) + " - "
- "Maximum Weight: " + toString(player_node->mMaxWeight));
+ "Total Weight: " + toString(player_node->mTotalWeight) + " - " +
+ "Maximum Weight: " + toString(player_node->mMaxWeight));
}
void InventoryWindow::action(const gcn::ActionEvent &event)
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index ce7337d2..186a2da6 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -31,6 +31,7 @@
#include "../item.h"
#include "../itemshortcut.h"
#include "../log.h"
+#include "../localplayer.h"
#include "../resources/image.h"
#include "../resources/iteminfo.h"
@@ -41,9 +42,10 @@
const int ItemContainer::gridWidth = 36; // item icon width + 4
const int ItemContainer::gridHeight = 42; // item icon height + 10
-ItemContainer::ItemContainer(Inventory *inventory):
+ItemContainer::ItemContainer(Inventory *inventory, int offset):
mInventory(inventory),
- mSelectedItem(NULL)
+ mSelectedItem(NULL),
+ mOffset(offset)
{
ResourceManager *resman = ResourceManager::getInstance();
@@ -94,10 +96,11 @@ ItemContainer::draw(gcn::Graphics *graphics)
}
/*
- * eAthena seems to start inventory from the 3rd slot. Still a mystery to
- * us why, make sure not to copy this oddity to our own server.
+ * mOffset is used to compensate for some weirdness that eAthena inherited from
+ * Ragnarok Online. Inventory slots and cart slots are +2 from their actual index,
+ * while storage slots are +1.
*/
- for (int i = 2; i < INVENTORY_SIZE; i++)
+ for (int i = mOffset; i < mInventory->getSize(); i++)
{
Item *item = mInventory->getItem(i);
@@ -194,7 +197,7 @@ ItemContainer::mousePressed(gcn::MouseEvent &event)
int columns = getWidth() / gridWidth;
int mx = event.getX();
int my = event.getY();
- int index = mx / gridWidth + ((my / gridHeight) * columns) + 2;
+ int index = mx / gridWidth + ((my / gridHeight) * columns) + mOffset;
itemShortcut->setItemSelected(-1);
// Fix for old server, it should be: if (index >= mMaxItems)
diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h
index 353ac51d..78301669 100644
--- a/src/gui/itemcontainer.h
+++ b/src/gui/itemcontainer.h
@@ -50,7 +50,7 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener,
/**
* Constructor. Initializes the graphic.
*/
- ItemContainer(Inventory *inventory);
+ ItemContainer(Inventory *inventory, int offset);
/**
* Destructor.
@@ -126,6 +126,7 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener,
Item *mSelectedItem;
int mMaxItems;
+ int mOffset;
std::list<gcn::SelectionListener*> mListeners;
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index 54544250..2831fc46 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -37,6 +37,7 @@
#include "../inventory.h"
#include "../item.h"
+#include "../localplayer.h"
#include "../net/messageout.h"
#include "../net/protocol.h"
@@ -48,8 +49,8 @@
TradeWindow::TradeWindow(Network *network):
Window("Trade: You"),
mNetwork(network),
- mMyInventory(new Inventory()),
- mPartnerInventory(new Inventory())
+ mMyInventory(new Inventory(INVENTORY_SIZE)),
+ mPartnerInventory(new Inventory(INVENTORY_SIZE))
{
setWindowName("Trade");
setDefaultSize(115, 197, 332, 209);
@@ -59,14 +60,14 @@ TradeWindow::TradeWindow(Network *network):
mCancelButton = new Button("Cancel", "cancel", this);
mTradeButton = new Button("Trade", "trade", this);
- mMyItemContainer = new ItemContainer(mMyInventory.get());
+ mMyItemContainer = new ItemContainer(mMyInventory.get(), 2);
mMyItemContainer->addSelectionListener(this);
mMyItemContainer->setPosition(2, 2);
mMyScroll = new ScrollArea(mMyItemContainer);
mMyScroll->setPosition(8, 8);
- mPartnerItemContainer = new ItemContainer(mPartnerInventory.get());
+ mPartnerItemContainer = new ItemContainer(mPartnerInventory.get(), 2);
mPartnerItemContainer->addSelectionListener(this);
mPartnerItemContainer->setPosition(2, 58);
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 20958c44..0b1b9613 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -36,15 +36,16 @@ struct SlotUsed : public std::unary_function<Item*, bool>
}
};
-Inventory::Inventory()
+Inventory::Inventory(int size):
+ mSize(size)
{
- mItems = new Item*[INVENTORY_SIZE];
- std::fill_n(mItems, INVENTORY_SIZE, (Item*) 0);
+ mItems = new Item*[mSize];
+ std::fill_n(mItems, mSize, (Item*) 0);
}
Inventory::~Inventory()
{
- for (int i = 0; i < INVENTORY_SIZE; i++)
+ for (int i = 0; i < mSize; i++)
delete mItems[i];
delete [] mItems;
@@ -52,7 +53,7 @@ Inventory::~Inventory()
Item* Inventory::getItem(int index) const
{
- if (index < 0 || index >= INVENTORY_SIZE)
+ if (index < 0 || index >= mSize)
return 0;
return mItems[index];
@@ -60,7 +61,7 @@ Item* Inventory::getItem(int index) const
Item* Inventory::findItem(int itemId) const
{
- for (int i = 0; i < INVENTORY_SIZE; i++)
+ for (int i = 0; i < mSize; i++)
{
if (mItems[i] && mItems[i]->getId() == itemId)
return mItems[i];
@@ -75,7 +76,7 @@ void Inventory::addItem(int id, int quantity, bool equipment)
void Inventory::setItem(int index, int id, int quantity, bool equipment)
{
- if (index < 0 || index >= INVENTORY_SIZE) {
+ if (index < 0 || index >= mSize) {
logger->log("Warning: invalid inventory index: %d", index);
return;
}
@@ -95,14 +96,14 @@ void Inventory::setItem(int index, int id, int quantity, bool equipment)
void Inventory::clear()
{
- for (int i = 0; i < INVENTORY_SIZE; i++) {
+ for (int i = 0; i < mSize; i++) {
removeItemAt(i);
}
}
void Inventory::removeItem(int id)
{
- for (int i = 0; i < INVENTORY_SIZE; i++) {
+ for (int i = 0; i < mSize; i++) {
if (mItems[i] && mItems[i]->getId() == id) {
removeItemAt(i);
}
@@ -117,7 +118,7 @@ void Inventory::removeItemAt(int index)
bool Inventory::contains(Item *item) const
{
- for (int i = 0; i < INVENTORY_SIZE; i++) {
+ for (int i = 0; i < mSize; i++) {
if (mItems[i] && mItems[i]->getId() == item->getId()) {
return true;
}
@@ -128,19 +129,19 @@ bool Inventory::contains(Item *item) const
int Inventory::getFreeSlot()
{
- Item **i = std::find_if(mItems + 2, mItems + INVENTORY_SIZE,
+ Item **i = std::find_if(mItems + 2, mItems + mSize,
std::not1(SlotUsed()));
- return (i == mItems + INVENTORY_SIZE) ? -1 : (i - mItems);
+ return (i == mItems + mSize) ? -1 : (i - mItems);
}
int Inventory::getNumberOfSlotsUsed()
{
- return count_if(mItems, mItems + INVENTORY_SIZE, SlotUsed());
+ return count_if(mItems, mItems + mSize, SlotUsed());
}
int Inventory::getLastUsedSlot()
{
- for (int i = INVENTORY_SIZE - 1; i >= 0; i--) {
+ for (int i = mSize - 1; i >= 0; i--) {
if (SlotUsed()(mItems[i])) {
return i;
}
diff --git a/src/inventory.h b/src/inventory.h
index 2e0dd792..42b0d86a 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -26,15 +26,13 @@
class Item;
-#define INVENTORY_SIZE 102
-
class Inventory
{
public:
/**
* Constructor.
*/
- Inventory();
+ Inventory(int size);
/**
* Destructor.
@@ -42,6 +40,11 @@ class Inventory
~Inventory();
/**
+ * Returns the size that this instance is configured for
+ */
+ int getSize() { return mSize; }
+
+ /**
* Returns the item at the specified index.
*/
Item* getItem(int index) const;
@@ -101,6 +104,7 @@ class Inventory
protected:
Item **mItems; /**< The holder of items */
+ int mSize; /**< The max number of inventory items */
};
#endif
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 7b0c2b8b..554c52a6 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -48,16 +48,18 @@ LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map):
mAttackRange(0),
mXp(0), mNetwork(0),
mTarget(NULL), mPickUpTarget(NULL),
- mTrading(false), mGoingToTarget(false),
- mLastAction(-1),
+ mTrading(false), mInStorage(false),
+ mGoingToTarget(false), mLastAction(-1),
mWalkingDir(0), mDestX(0), mDestY(0),
- mInventory(new Inventory)
+ mInventory(new Inventory(INVENTORY_SIZE)),
+ mStorage(new Inventory(STORAGE_SIZE))
{
}
LocalPlayer::~LocalPlayer()
{
delete mInventory;
+ delete mStorage;
}
void LocalPlayer::logic()
diff --git a/src/localplayer.h b/src/localplayer.h
index 64e6c5ad..1d865824 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -29,6 +29,9 @@
// TODO move into some sane place...
#define MAX_SLOT 2
+#define INVENTORY_SIZE 102
+#define STORAGE_SIZE 301
+
class FloorItem;
class Inventory;
class Item;
@@ -71,6 +74,11 @@ class LocalPlayer : public Player
Inventory* getInventory() const { return mInventory; }
/**
+ * Returns the player's storage
+ */
+ Inventory* getStorage() const { return mStorage; }
+
+ /**
* Equips an item.
*/
void equipItem(Item *item);
@@ -166,6 +174,12 @@ class LocalPlayer : public Player
void revive();
/**
+ * Accessors for mInStorage
+ */
+ bool getInStorage() { return mInStorage; }
+ void setInStorage(bool inStorage) { mInStorage = inStorage; }
+
+ /**
* Sets the amount of XP. Shows XP gaining effect if the player is on
* a map.
*/
@@ -210,6 +224,7 @@ class LocalPlayer : public Player
FloorItem *mPickUpTarget;
bool mTrading;
+ bool mInStorage; /**< Whether storage is currently accessible */
bool mGoingToTarget;
int mLastAction; /**< Time stamp of the last action, -1 if none. */
int mWalkingDir; /**< The direction the player is walking in. */
@@ -217,6 +232,7 @@ class LocalPlayer : public Player
int mDestY; /**< Y coordinate of destination. */
Inventory *mInventory;
+ Inventory *mStorage;
};
extern LocalPlayer *player_node;
diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp
index d3ad0d92..2af3fe07 100644
--- a/src/net/charserverhandler.cpp
+++ b/src/net/charserverhandler.cpp
@@ -32,10 +32,16 @@
#include "../log.h"
#include "../logindata.h"
#include "../main.h"
+#include "../extensions.h"
#include "../gui/ok_dialog.h"
#include "../gui/char_select.h"
+/*
+ * Yeah, this is a global. Get over it.
+ */
+struct EXTENSIONS extensions;
+
CharServerHandler::CharServerHandler():
mCharCreateDialog(0)
{
@@ -56,6 +62,7 @@ CharServerHandler::CharServerHandler():
void CharServerHandler::handleMessage(MessageIn *msg)
{
int slot;
+ int flags;
LocalPlayer *tempPlayer;
logger->log("CharServerHandler: Packet ID: %x, Length: %d",
@@ -63,8 +70,13 @@ void CharServerHandler::handleMessage(MessageIn *msg)
switch (msg->getId())
{
case 0x006b:
- // Skip length word and an additional mysterious 20 bytes
- msg->skip(2 + 20);
+ msg->skip(2); // Length word
+ flags = msg->readInt32(); // Aethyra extensions flags
+ logger->log("Server flags are: %x", flags);
+ extensions.aethyra_inventory = (bool)(flags & 0x01);
+ extensions.aethyra_spells = (bool)(flags & 0x02);
+ extensions.aethyra_misc = (bool)(flags & 0x04);
+ msg->skip(16); // Unused
// Derive number of characters from message length
n_character = (msg->getLength() - 24) / 106;
diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp
index 37ae5fb9..44a3256e 100644
--- a/src/net/inventoryhandler.cpp
+++ b/src/net/inventoryhandler.cpp
@@ -47,6 +47,12 @@ InventoryHandler::InventoryHandler()
SMSG_PLAYER_INVENTORY_REMOVE,
SMSG_PLAYER_INVENTORY_USE,
SMSG_ITEM_USE_RESPONSE,
+ SMSG_PLAYER_STORAGE_ITEMS,
+ SMSG_PLAYER_STORAGE_EQUIP,
+ SMSG_PLAYER_STORAGE_STATUS,
+ SMSG_PLAYER_STORAGE_ADD,
+ SMSG_PLAYER_STORAGE_REMOVE,
+ SMSG_PLAYER_STORAGE_CLOSE,
0
};
handledMessages = _messages;
@@ -56,32 +62,68 @@ void InventoryHandler::handleMessage(MessageIn *msg)
{
Sint32 number;
Sint16 index, amount, itemId, equipType, arrow;
+ Sint16 identified, cards[4], itemType;
Inventory *inventory = player_node->getInventory();
+ Inventory *storage = player_node->getStorage();
switch (msg->getId())
{
case SMSG_PLAYER_INVENTORY:
- // Only called on map load / warp. First reset all items
- // to not load them twice on map change.
- inventory->clear();
+ case SMSG_PLAYER_STORAGE_ITEMS:
+ case SMSG_PLAYER_STORAGE_EQUIP:
+ switch (msg->getId()) {
+ case SMSG_PLAYER_INVENTORY:
+ // Clear inventory - this will be a complete refresh
+ inventory->clear();
+ break;
+ case SMSG_PLAYER_STORAGE_ITEMS:
+ /*
+ * This packet will always be followed by a
+ * SMSG_PLAYER_STORAGE_EQUIP packet. The two packets
+ * together comprise a complete refresh of storage, so
+ * clear storage here
+ */
+ storage->clear();
+ logger->log("Received SMSG_PLAYER_STORAGE_ITEMS");
+ break;
+ default:
+ logger->log("Received SMSG_PLAYER_STORAGE_EQUIP");
+ break;
+ }
msg->readInt16(); // length
number = (msg->getLength() - 4) / 18;
for (int loop = 0; loop < number; loop++) {
index = msg->readInt16();
itemId = msg->readInt16();
- msg->readInt8(); // type
- msg->readInt8(); // identify flag
- amount = msg->readInt16();
+ itemType = msg->readInt8();
+ identified = msg->readInt8();
+ if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) {
+ amount = 1;
+ msg->readInt16(); // Equip Point?
+ } else {
+ amount = msg->readInt16();
+ }
arrow = msg->readInt16();
- msg->skip(8); // card (4 shorts)
+ if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) {
+ msg->readInt8(); // Attribute (broken)
+ msg->readInt8(); // Refine level
+ }
+ for (int i = 0; i < 4; i++)
+ cards[i] = msg->readInt16();
- inventory->setItem(index, itemId, amount, false);
+ if (msg->getId() == SMSG_PLAYER_INVENTORY) {
+ inventory->setItem(index, itemId, amount, false);
- // Trick because arrows are not considered equipment
- if (arrow & 0x8000) {
- if (Item *item = inventory->getItem(index))
- item->setEquipment(true);
+ // Trick because arrows are not considered equipment
+ if (arrow & 0x8000) {
+ if (Item *item = inventory->getItem(index))
+ item->setEquipment(true);
+ }
+ } else {
+ logger->log("Index:%d, ID:%d, Type:%d, Identified:%d, Qty:%d, Cards:%d, %d, %d, %d",
+ index, itemId, itemType, identified, amount, cards[0], cards[1], cards[2], cards[3]);
+ storage->setItem(index, itemId, amount, false);
}
}
break;
@@ -90,12 +132,13 @@ void InventoryHandler::handleMessage(MessageIn *msg)
index = msg->readInt16();
amount = msg->readInt16();
itemId = msg->readInt16();
- msg->readInt8(); // identify flag
+ identified = msg->readInt8();
msg->readInt8(); // attribute
msg->readInt8(); // refine
- msg->skip(8); // card
+ for (int i = 0; i < 4; i++)
+ cards[i] = msg->readInt16();
equipType = msg->readInt16();
- msg->readInt8(); // type
+ itemType = msg->readInt8();
if (msg->readInt8() > 0) {
chatWindow->chatLog("Unable to pick up item", BY_SERVER);
@@ -147,5 +190,38 @@ void InventoryHandler::handleMessage(MessageIn *msg)
item->setQuantity(amount);
}
break;
+
+ case SMSG_PLAYER_STORAGE_STATUS:
+ /*
+ * Basic slots used vs total slots info
+ * We don't really need this information, but this is
+ * the closest we get to an "Open Storage" packet
+ * from the server. It always comes after the two
+ * SMSG_PLAYER_STORAGE_... packets that update
+ * storage contents.
+ */
+ logger->log("Received SMSG_PLAYER_STORAGE_STATUS");
+ player_node->setInStorage(true);
+ break;
+
+ case SMSG_PLAYER_STORAGE_ADD:
+ /*
+ * Move an item into storage
+ */
+ break;
+
+ case SMSG_PLAYER_STORAGE_REMOVE:
+ /*
+ * Move an item out of storage
+ */
+ break;
+
+ case SMSG_PLAYER_STORAGE_CLOSE:
+ /*
+ * Storage access has been closed
+ */
+ player_node->setInStorage(false);
+ logger->log("Received SMSG_PLAYER_STORAGE_CLOSE");
+ break;
}
}
diff --git a/src/net/protocol.h b/src/net/protocol.h
index 53f245b5..7d5edf94 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -24,7 +24,9 @@
#ifndef _TMW_PROTOCOL_
#define _TMW_PROTOCOL_
-// Packets from server to client
+/*********************************
+ * Packets from server to client *
+ *********************************/
#define SMSG_LOGIN_SUCCESS 0x0073 /**< Contains starting location */
#define SMSG_SERVER_PING 0x007f /**< Contains server tick */
#define SMSG_PLAYER_UPDATE_1 0x01d8
@@ -104,7 +106,16 @@
#define SMSG_PARTY_UPDATE_COORDS 0x0107
#define SMSG_PARTY_MESSAGE 0x0109
-// Packets from client to server
+#define SMSG_PLAYER_STORAGE_ITEMS 0x01f0 /**< Item list for storage */
+#define SMSG_PLAYER_STORAGE_EQUIP 0x00a6 /**< Equipment list for storage */
+#define SMSG_PLAYER_STORAGE_STATUS 0x00f2 /**< Slots used and total slots */
+#define SMSG_PLAYER_STORAGE_ADD 0x00f4 /**< Add item/equip to storage */
+#define SMSG_PLAYER_STORAGE_REMOVE 0x00f6 /**< Remove item/equip from storage */
+#define SMSG_PLAYER_STORAGE_CLOSE 0x00f8 /**< Storage access closed */
+
+/**********************************
+ * Packets from client to server *
+ **********************************/
#define CMSG_CLIENT_PING 0x007e /**< Send to server with tick */
#define CMSG_TRADE_RESPONSE 0x00e6
#define CMSG_ITEM_PICKUP 0x009f
@@ -138,6 +149,10 @@
#define CMSG_PARTY_SETTINGS 0x0101
#define CMSG_PARTY_MESSAGE 0x0108
+#define CMSG_MOVE_TO_STORAGE 0x00f3 /** Move item to storage */
+#define CSMG_MOVE_FROM_STORAGE 0x00f5 /** Remove item from storage */
+#define CMSG_CLOSE_STORAGE 0x00f7 /** Request storage close */
+
/** Encodes coords and direction in 3 bytes data */
void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction);