Merge pull request #363 from conde2/master

Fix protocol error #362
This commit is contained in:
Henrique Santiago 2013-10-20 17:24:19 -07:00
commit 3340e06da6
8 changed files with 67 additions and 20 deletions

View File

@ -23,7 +23,7 @@
#include "container.h" #include "container.h"
#include "item.h" #include "item.h"
Container::Container(int id, int capacity, const std::string& name, const ItemPtr& containerItem, bool hasParent) Container::Container(int id, int capacity, const std::string& name, const ItemPtr& containerItem, bool hasParent, bool isUnlocked, bool hasPages, int containerSize, int firstIndex)
{ {
m_id = id; m_id = id;
m_capacity = capacity; m_capacity = capacity;
@ -31,6 +31,10 @@ Container::Container(int id, int capacity, const std::string& name, const ItemPt
m_containerItem = containerItem; m_containerItem = containerItem;
m_hasParent = hasParent; m_hasParent = hasParent;
m_closed = false; m_closed = false;
m_unlocked = isUnlocked;
m_hasPages = hasPages;
m_size = containerSize;
m_firstIndex = firstIndex;
} }
ItemPtr Container::getItem(int slot) ItemPtr Container::getItem(int slot)
@ -51,12 +55,12 @@ void Container::onClose()
callLuaField("onClose"); callLuaField("onClose");
} }
void Container::onAddItem(const ItemPtr& item) void Container::onAddItem(const ItemPtr& item, int slot)
{ {
m_items.push_front(item); m_items.push_front(item);
updateItemsPositions(); updateItemsPositions();
callLuaField("onAddItem", 0, item); callLuaField("onAddItem", slot, item);
} }
ItemPtr Container::findItemById(uint itemId, int subType) ItemPtr Container::findItemById(uint itemId, int subType)

View File

@ -32,7 +32,7 @@
class Container : public LuaObject class Container : public LuaObject
{ {
protected: protected:
Container(int id, int capacity, const std::string& name, const ItemPtr& containerItem, bool hasParent); Container(int id, int capacity, const std::string& name, const ItemPtr& containerItem, bool hasParent, bool isUnlocked, bool hasPages, int containerSize, int firstIndex);
public: public:
ItemPtr getItem(int slot); ItemPtr getItem(int slot);
@ -45,12 +45,16 @@ public:
std::string getName() { return m_name; } std::string getName() { return m_name; }
bool hasParent() { return m_hasParent; } bool hasParent() { return m_hasParent; }
bool isClosed() { return m_closed; } bool isClosed() { return m_closed; }
bool isUnlocked() { return m_unlocked; }
bool hasPages() { return m_hasPages; }
int getSize() { return m_size; }
int getFirstIndex() { return m_firstIndex; }
ItemPtr findItemById(uint itemId, int subType); ItemPtr findItemById(uint itemId, int subType);
protected: protected:
void onOpen(const ContainerPtr& previousContainer); void onOpen(const ContainerPtr& previousContainer);
void onClose(); void onClose();
void onAddItem(const ItemPtr& item); void onAddItem(const ItemPtr& item, int slot);
void onAddItems(const std::vector<ItemPtr>& items); void onAddItems(const std::vector<ItemPtr>& items);
void onUpdateItem(int slot, const ItemPtr& item); void onUpdateItem(int slot, const ItemPtr& item);
void onRemoveItem(int slot); void onRemoveItem(int slot);
@ -66,6 +70,10 @@ private:
std::string m_name; std::string m_name;
bool m_hasParent; bool m_hasParent;
bool m_closed; bool m_closed;
bool m_unlocked;
bool m_hasPages;
int m_size;
int m_firstIndex;
std::deque<ItemPtr> m_items; std::deque<ItemPtr> m_items;
}; };

View File

@ -234,6 +234,11 @@ void Game::processGMActions(const std::vector<uint8>& actions)
g_lua.callGlobalField("g_game", "onGMActions", actions); g_lua.callGlobalField("g_game", "onGMActions", actions);
} }
void Game::processPlayerHelpers(int helpers)
{
g_lua.callGlobalField("g_game", "onPlayerHelpersUpdate", helpers);
}
void Game::processPing() void Game::processPing()
{ {
g_lua.callGlobalField("g_game", "onPing"); g_lua.callGlobalField("g_game", "onPing");
@ -268,10 +273,10 @@ void Game::processTalk(const std::string& name, int level, Otc::MessageMode mode
g_lua.callGlobalField("g_game", "onTalk", name, level, mode, text, channelId, pos); g_lua.callGlobalField("g_game", "onTalk", name, level, mode, text, channelId, pos);
} }
void Game::processOpenContainer(int containerId, const ItemPtr& containerItem, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items) void Game::processOpenContainer(int containerId, const ItemPtr& containerItem, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items, bool isUnlocked, bool hasPages, int containerSize, int firstIndex)
{ {
ContainerPtr previousContainer = getContainer(containerId); ContainerPtr previousContainer = getContainer(containerId);
ContainerPtr container = ContainerPtr(new Container(containerId, capacity, name, containerItem, hasParent)); ContainerPtr container = ContainerPtr(new Container(containerId, capacity, name, containerItem, hasParent, isUnlocked, hasPages, containerSize, firstIndex));
m_containers[containerId] = container; m_containers[containerId] = container;
container->onAddItems(items); container->onAddItems(items);
@ -296,7 +301,7 @@ void Game::processCloseContainer(int containerId)
container->onClose(); container->onClose();
} }
void Game::processContainerAddItem(int containerId, const ItemPtr& item) void Game::processContainerAddItem(int containerId, const ItemPtr& item, int slot)
{ {
ContainerPtr container = getContainer(containerId); ContainerPtr container = getContainer(containerId);
if(!container) { if(!container) {
@ -304,7 +309,7 @@ void Game::processContainerAddItem(int containerId, const ItemPtr& item)
return; return;
} }
container->onAddItem(item); container->onAddItem(item, slot);
} }
void Game::processContainerUpdateItem(int containerId, int slot, const ItemPtr& item) void Game::processContainerUpdateItem(int containerId, int slot, const ItemPtr& item)

View File

@ -73,14 +73,16 @@ protected:
void processAttackCancel(uint seq); void processAttackCancel(uint seq);
void processWalkCancel(Otc::Direction direction); void processWalkCancel(Otc::Direction direction);
void processPlayerHelpers(int helpers);
// message related // message related
void processTextMessage(Otc::MessageMode mode, const std::string& text); void processTextMessage(Otc::MessageMode mode, const std::string& text);
void processTalk(const std::string& name, int level, Otc::MessageMode mode, const std::string& text, int channelId, const Position& pos); void processTalk(const std::string& name, int level, Otc::MessageMode mode, const std::string& text, int channelId, const Position& pos);
// container related // container related
void processOpenContainer(int containerId, const ItemPtr& containerItem, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items); void processOpenContainer(int containerId, const ItemPtr& containerItem, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items, bool isUnlocked, bool hasPages, int containerSize, int firstIndex);
void processCloseContainer(int containerId); void processCloseContainer(int containerId);
void processContainerAddItem(int containerId, const ItemPtr& item); void processContainerAddItem(int containerId, const ItemPtr& item, int slot);
void processContainerUpdateItem(int containerId, int slot, const ItemPtr& item); void processContainerUpdateItem(int containerId, int slot, const ItemPtr& item);
void processContainerRemoveItem(int containerId, int slot); void processContainerRemoveItem(int containerId, int slot);

View File

@ -317,6 +317,10 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<Container>("getContainerItem", &Container::getContainerItem); g_lua.bindClassMemberFunction<Container>("getContainerItem", &Container::getContainerItem);
g_lua.bindClassMemberFunction<Container>("hasParent", &Container::hasParent); g_lua.bindClassMemberFunction<Container>("hasParent", &Container::hasParent);
g_lua.bindClassMemberFunction<Container>("isClosed", &Container::isClosed); g_lua.bindClassMemberFunction<Container>("isClosed", &Container::isClosed);
g_lua.bindClassMemberFunction<Container>("isUnlocked", &Container::isUnlocked);
g_lua.bindClassMemberFunction<Container>("hasPages", &Container::hasPages);
g_lua.bindClassMemberFunction<Container>("getSize", &Container::getSize);
g_lua.bindClassMemberFunction<Container>("getFirstIndex", &Container::getFirstIndex);
g_lua.registerClass<Thing>(); g_lua.registerClass<Thing>();
g_lua.bindClassMemberFunction<Thing>("setId", &Thing::setId); g_lua.bindClassMemberFunction<Thing>("setId", &Thing::setId);

View File

@ -102,6 +102,7 @@ namespace Proto {
GameServerCreatureSkull = 144, GameServerCreatureSkull = 144,
GameServerCreatureParty = 145, GameServerCreatureParty = 145,
GameServerCreatureUnpass = 146, GameServerCreatureUnpass = 146,
GameServerPlayerHelpers = 148,
GameServerEditText = 150, GameServerEditText = 150,
GameServerEditList = 151, GameServerEditList = 151,
GameServerPlayerDataBasic = 159, // 950 GameServerPlayerDataBasic = 159, // 950

View File

@ -125,6 +125,7 @@ public:
void addPosition(const OutputMessagePtr& msg, const Position& position); void addPosition(const OutputMessagePtr& msg, const Position& position);
private: private:
void parsePlayerHelpers(const InputMessagePtr& msg);
void parseMessage(const InputMessagePtr& msg); void parseMessage(const InputMessagePtr& msg);
void parsePendingGame(const InputMessagePtr& msg); void parsePendingGame(const InputMessagePtr& msg);
void parseEnterGame(const InputMessagePtr& msg); void parseEnterGame(const InputMessagePtr& msg);

View File

@ -323,6 +323,10 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg)
case Proto::GameServerEnterGame: case Proto::GameServerEnterGame:
parseEnterGame(msg); parseEnterGame(msg);
break; break;
// PROTOCOL>=1010
case Proto::GameServerPlayerHelpers:
parsePlayerHelpers(msg);
break;
// otclient ONLY // otclient ONLY
case Proto::GameServerExtendedOpcode: case Proto::GameServerExtendedOpcode:
parseExtendedOpcode(msg); parseExtendedOpcode(msg);
@ -379,6 +383,18 @@ void ProtocolGame::parseEnterGame(const InputMessagePtr& msg)
} }
} }
void ProtocolGame::parsePlayerHelpers(const InputMessagePtr& msg)
{
uint id = msg->getU32();
int helpers = msg->getU16();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
g_game.processPlayerHelpers(helpers);
else
g_logger.traceError("could not get creature");
}
void ProtocolGame::parseGMActions(const InputMessagePtr& msg) void ProtocolGame::parseGMActions(const InputMessagePtr& msg)
{ {
std::vector<uint8> actions; std::vector<uint8> actions;
@ -604,11 +620,16 @@ void ProtocolGame::parseOpenContainer(const InputMessagePtr& msg)
int capacity = msg->getU8(); int capacity = msg->getU8();
bool hasParent = (msg->getU8() != 0); bool hasParent = (msg->getU8() != 0);
bool isUnlocked = false;
bool hasPages = false;
int containerSize = 0;
int firstIndex = 0;
if(g_game.getFeature(Otc::GameContainerPagination)) { if(g_game.getFeature(Otc::GameContainerPagination)) {
msg->getU8(); // drag and drop isUnlocked = (msg->getU8() != 0); // drag and drop
msg->getU8(); // pagination hasPages = (msg->getU8() != 0); // pagination
msg->getU16(); // container size containerSize = msg->getU16(); // container size
msg->getU16(); // first index firstIndex = msg->getU16(); // first index
} }
int itemCount = msg->getU8(); int itemCount = msg->getU8();
@ -617,7 +638,7 @@ void ProtocolGame::parseOpenContainer(const InputMessagePtr& msg)
for(int i = 0; i < itemCount; i++) for(int i = 0; i < itemCount; i++)
items[i] = getItem(msg); items[i] = getItem(msg);
g_game.processOpenContainer(containerId, containerItem, name, capacity, hasParent, items); g_game.processOpenContainer(containerId, containerItem, name, capacity, hasParent, items, isUnlocked, hasPages, containerSize, firstIndex);
} }
void ProtocolGame::parseCloseContainer(const InputMessagePtr& msg) void ProtocolGame::parseCloseContainer(const InputMessagePtr& msg)
@ -629,11 +650,12 @@ void ProtocolGame::parseCloseContainer(const InputMessagePtr& msg)
void ProtocolGame::parseContainerAddItem(const InputMessagePtr& msg) void ProtocolGame::parseContainerAddItem(const InputMessagePtr& msg)
{ {
int containerId = msg->getU8(); int containerId = msg->getU8();
int slot = 0;
if(g_game.getFeature(Otc::GameContainerPagination)) { if(g_game.getFeature(Otc::GameContainerPagination)) {
msg->getU16(); // slot slot = msg->getU16(); // slot
} }
ItemPtr item = getItem(msg); ItemPtr item = getItem(msg);
g_game.processContainerAddItem(containerId, item); g_game.processContainerAddItem(containerId, item, slot);
} }
void ProtocolGame::parseContainerUpdateItem(const InputMessagePtr& msg) void ProtocolGame::parseContainerUpdateItem(const InputMessagePtr& msg)