diff --git a/src/otclient/net/protocolcodes.h b/src/otclient/net/protocolcodes.h index 302544ba..7c1bac55 100644 --- a/src/otclient/net/protocolcodes.h +++ b/src/otclient/net/protocolcodes.h @@ -81,6 +81,12 @@ namespace Proto { LoginServerCharacterList = 100 }; + enum CreatureOpcode { + UnknownCreature = 97, + OutdatedCreature = 98, + Creature = 99 + }; + enum GameServerOpcodes { GameServerInitGame = 10, GameServerGMActions = 11, diff --git a/src/otclient/net/protocolgame.h b/src/otclient/net/protocolgame.h index e0c409fb..0d361735 100644 --- a/src/otclient/net/protocolgame.h +++ b/src/otclient/net/protocolgame.h @@ -162,7 +162,6 @@ private: void parseCreatureSkulls(InputMessage& msg); void parseCreatureShields(InputMessage& msg); void parseCreatureUnpass(InputMessage& msg); - void parseCreatureTurn(InputMessage& msg); void parseEditText(InputMessage& msg); void parseEditList(InputMessage& msg); void parsePlayerInfo(InputMessage& msg); @@ -209,6 +208,7 @@ private: void setTileDescription(InputMessage& msg, Position position); Outfit internalGetOutfit(InputMessage& msg); + CreaturePtr internalGetCreature(InputMessage& msg, int type = 0); ThingPtr internalGetThing(InputMessage& msg); ItemPtr internalGetItem(InputMessage& msg, int id = 0); diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index be932ee0..37bafd5b 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -455,11 +455,8 @@ void ProtocolGame::parseTileTransformThing(InputMessage& msg) Position pos = parsePosition(msg); int stackPos = msg.getU8(); - int thingId = msg.getU16(); - if(thingId == 0x0061 || thingId == 0x0062 || thingId == 0x0063) { - parseCreatureTurn(msg); - } else { - ThingPtr thing = internalGetItem(msg, thingId); + ThingPtr thing = internalGetThing(msg); + if(thing) { if(!g_map.removeThingByPos(pos, stackPos)) logTraceError("could not remove thing"); g_map.addThing(thing, pos, stackPos); @@ -502,11 +499,7 @@ void ProtocolGame::parseCreatureMove(InputMessage& msg) void ProtocolGame::parseOpenContainer(InputMessage& msg) { int containerId = msg.getU8(); -#if PROTOCOL>=920 ItemPtr containerItem = internalGetItem(msg); -#else - ItemPtr containerItem = Item::create(msg.getU16()); -#endif std::string name = msg.getString(); int capacity = msg.getU8(); bool hasParent = (msg.getU8() != 0); @@ -796,18 +789,6 @@ void ProtocolGame::parseCreatureUnpass(InputMessage& msg) logTraceError("could not get creature"); } -void ProtocolGame::parseCreatureTurn(InputMessage& msg) -{ - uint id = msg.getU32(); - Otc::Direction direction = (Otc::Direction)msg.getU8(); - - CreaturePtr creature = g_map.getCreatureById(id); - if(creature) - creature->turn(direction); - else - logTraceError("could not get creature"); -} - void ProtocolGame::parseEditText(InputMessage& msg) { uint id = msg.getU32(); @@ -998,6 +979,15 @@ void ProtocolGame::parseOpenChannel(InputMessage& msg) int channelId = msg.getU16(); std::string name = msg.getString(); +#if PROTOCOL>=944 + int joinedPlayers = msg.getU16(); + for(int i=0;i 0) // every creature name must start with a capital letter + // every creature name must start with a capital letter + if(name.length() > 0) name[0] = toupper(name[0]); - g_map.removeCreatureById(removeId); - if(id == m_localPlayer->getId()) creature = m_localPlayer; else if(creatureType == Proto::CreatureTypePlayer) @@ -1407,7 +1410,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg) bool passable = false; #if PROTOCOL>=854 - if(thingId == 0x0061) + if(!known) emblem = msg.getU8(); passable = (msg.getU8() == 0); @@ -1428,15 +1431,23 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg) if(creature == m_localPlayer && !m_localPlayer->isKnown()) m_localPlayer->setKnown(true); } + } else if(type == Proto::Creature) { + uint id = msg.getU32(); + Otc::Direction direction = (Otc::Direction)msg.getU8(); +#if PROTOCOL>=953 + msg.getU8(); // passable +#endif - thing = creature; - } else if(thingId == 0x0063) { // creature turn - parseCreatureTurn(msg); - } else { // item - thing = internalGetItem(msg, thingId); + creature = g_map.getCreatureById(id); + if(creature) + creature->turn(direction); + else + logTraceError("invalid creature"); + } else { + Fw::throwException("invalid creature opcode"); } - return thing; + return creature; } ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, int id)