tibia-client/src/otclient/net/protocolgameparse.cpp

1149 lines
34 KiB
C++
Raw Normal View History

2011-08-28 15:17:58 +02:00
/*
2012-01-02 17:58:37 +01:00
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
2011-08-28 15:17:58 +02:00
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
2011-08-15 16:11:24 +02:00
#include "protocolgame.h"
2011-08-15 23:02:52 +02:00
#include <otclient/core/localplayer.h>
2011-08-31 17:03:33 +02:00
#include <otclient/core/thingstype.h>
2011-08-15 16:11:24 +02:00
#include <otclient/core/game.h>
#include <otclient/core/map.h>
#include <otclient/core/item.h>
2011-08-15 16:11:24 +02:00
#include <otclient/core/effect.h>
2011-11-08 02:44:30 +01:00
#include <otclient/core/missile.h>
2011-08-31 22:22:57 +02:00
#include <otclient/core/tile.h>
#include <otclient/luascript/luavaluecasts.h>
#include <framework/core/eventdispatcher.h>
2011-08-15 16:11:24 +02:00
void ProtocolGame::parseMessage(InputMessage& msg)
{
try {
while(!msg.eof()) {
2012-01-12 20:20:18 +01:00
int opt = msg.getU8();
switch(opt) {
case Proto::GameServerInitGame:
parseInitGame(msg);
2011-08-15 16:11:24 +02:00
break;
2012-01-10 03:55:56 +01:00
case Proto::GameServerGMActions:
2011-08-15 16:11:24 +02:00
parseGMActions(msg);
break;
case Proto::GameServerLoginError:
parseLoginError(msg);
2011-08-15 16:11:24 +02:00
break;
case Proto::GameServerLoginAdvice:
2011-08-15 16:11:24 +02:00
parseFYIMessage(msg);
break;
case Proto::GameServerLoginWait:
2011-08-15 16:11:24 +02:00
parseWaitList(msg);
break;
case Proto::GameServerPing:
2011-08-15 16:11:24 +02:00
parsePing(msg);
break;
//case Proto::GameServerChallange:
case Proto::GameServerDead:
2011-08-15 16:11:24 +02:00
parseDeath(msg);
break;
case Proto::GameServerFullMap:
2011-08-15 16:11:24 +02:00
parseMapDescription(msg);
break;
case Proto::GameServerMapTopRow:
2011-08-15 16:11:24 +02:00
parseMoveNorth(msg);
break;
case Proto::GameServerMapRightRow:
2011-08-15 16:11:24 +02:00
parseMoveEast(msg);
break;
case Proto::GameServerMapBottomRow:
2011-08-15 16:11:24 +02:00
parseMoveSouth(msg);
break;
case Proto::GameServerMapLeftRow:
2011-08-15 16:11:24 +02:00
parseMoveWest(msg);
break;
case Proto::GameServerTileData:
2011-08-15 16:11:24 +02:00
parseUpdateTile(msg);
break;
case Proto::GameServerCreateOnMap:
2011-08-15 16:11:24 +02:00
parseTileAddThing(msg);
break;
case Proto::GameServerChangeOnMap:
2011-08-15 16:11:24 +02:00
parseTileTransformThing(msg);
break;
case Proto::GameServerDeleteOnMap:
2011-08-15 16:11:24 +02:00
parseTileRemoveThing(msg);
break;
case Proto::GameServerMoveCreature:
2011-08-15 16:11:24 +02:00
parseCreatureMove(msg);
break;
case Proto::GameServerOpenContainer:
2011-08-15 16:11:24 +02:00
parseOpenContainer(msg);
break;
case Proto::GameServerCloseContainer:
2011-08-15 16:11:24 +02:00
parseCloseContainer(msg);
break;
case Proto::GameServerCreateContainer:
2011-08-15 16:11:24 +02:00
parseContainerAddItem(msg);
break;
case Proto::GameServerChangeInContainer:
2011-08-15 16:11:24 +02:00
parseContainerUpdateItem(msg);
break;
case Proto::GameServerDeleteInContainer:
2011-08-15 16:11:24 +02:00
parseContainerRemoveItem(msg);
break;
case Proto::GameServerSetInventory:
2011-08-15 16:11:24 +02:00
parseAddInventoryItem(msg);
break;
case Proto::GameServerDeleteInventory:
2011-08-15 16:11:24 +02:00
parseRemoveInventoryItem(msg);
break;
case Proto::GameServerNpcOffer:
2011-08-15 16:11:24 +02:00
parseOpenShopWindow(msg);
break;
case Proto::GameServerPlayerGoods:
2011-08-15 16:11:24 +02:00
parsePlayerCash(msg);
break;
case Proto::GameServerCloseNpcTrade:
2011-08-15 16:11:24 +02:00
parseCloseShopWindow(msg);
break;
case Proto::GameServerOwnOffer:
2011-08-15 16:11:24 +02:00
parseSafeTradeRequest(msg);
break;
case Proto::GameServerCounterOffer:
2011-08-15 16:11:24 +02:00
parseSafeTradeRequest(msg);
break;
case Proto::GameServerCloseTrade:
2011-08-15 16:11:24 +02:00
parseSafeTradeClose(msg);
break;
case Proto::GameServerAmbient:
2011-08-15 16:11:24 +02:00
parseWorldLight(msg);
break;
case Proto::GameServerGraphicalEffect:
2011-08-15 16:11:24 +02:00
parseMagicEffect(msg);
break;
case Proto::GameServerTextEffect:
2011-08-15 16:11:24 +02:00
parseAnimatedText(msg);
break;
case Proto::GameServerMissleEffect:
2011-11-12 07:24:32 +01:00
parseDistanceMissile(msg);
2011-08-15 16:11:24 +02:00
break;
case Proto::GameServerMarkCreature:
2011-08-15 16:11:24 +02:00
parseCreatureSquare(msg);
break;
//case Proto::GameServerTrappers
case Proto::GameServerCreatureHealth:
2011-08-15 16:11:24 +02:00
parseCreatureHealth(msg);
break;
case Proto::GameServerCreatureLight:
2011-08-15 16:11:24 +02:00
parseCreatureLight(msg);
break;
case Proto::GameServerCreatureOutfit:
2011-08-15 16:11:24 +02:00
parseCreatureOutfit(msg);
break;
case Proto::GameServerCreatureSpeed:
2011-08-15 16:11:24 +02:00
parseCreatureSpeed(msg);
break;
case Proto::GameServerCreatureSkull:
2011-08-15 16:11:24 +02:00
parseCreatureSkulls(msg);
break;
case Proto::GameServerCreatureParty:
2011-08-15 16:11:24 +02:00
parseCreatureShields(msg);
break;
// case Proto::GameServerCreatureUnpass
case Proto::GameServerEditText:
2011-08-15 16:11:24 +02:00
parseItemTextWindow(msg);
break;
case Proto::GameServerEditList:
2011-08-15 16:11:24 +02:00
parseHouseTextWindow(msg);
break;
case Proto::GameServerPlayerData:
2011-08-15 16:11:24 +02:00
parsePlayerStats(msg);
break;
case Proto::GameServerPlayerSkills:
2011-08-15 16:11:24 +02:00
parsePlayerSkills(msg);
break;
case Proto::GameServerPlayerState:
2011-08-15 16:11:24 +02:00
parsePlayerIcons(msg);
break;
case Proto::GameServerClearTarget:
2011-08-15 16:11:24 +02:00
parsePlayerCancelAttack(msg);
break;
//case Proto::GameServerSpellDelay:
//case Proto::GameServerSpellGroupDelay:
case Proto::GameServerTalk:
2011-08-15 16:11:24 +02:00
parseCreatureSpeak(msg);
break;
case Proto::GameServerChannels:
2011-08-15 16:11:24 +02:00
parseChannelList(msg);
break;
case Proto::GameServerOpenChannel:
2011-08-15 16:11:24 +02:00
parseOpenChannel(msg);
break;
2012-02-02 23:29:44 +01:00
case Proto::GameServerOpenPrivateChannel:
parseOpenPrivateChannel(msg);
2011-08-15 16:11:24 +02:00
break;
case Proto::GameServerRuleViolationChannel:
msg.getU16();
break;
case Proto::GameServerRuleViolationRemove:
msg.getString();
break;
case Proto::GameServerRuleViolationCancel:
msg.getString();
break;
case Proto::GameServerRuleViolationLock:
2011-08-15 16:11:24 +02:00
break;
case Proto::GameServerOpenOwnChannel:
2012-02-02 23:29:44 +01:00
parseCreateOwnPrivateChannel(msg);
2011-08-15 16:11:24 +02:00
break;
case Proto::GameServerCloseChannel:
2012-02-02 23:29:44 +01:00
parseCloseChannel(msg);
2011-08-15 16:11:24 +02:00
break;
case Proto::GameServerMessage:
2011-08-15 16:11:24 +02:00
parseTextMessage(msg);
break;
case Proto::GameServerSnapBack:
2011-08-15 16:11:24 +02:00
parseCancelWalk(msg);
break;
//case Proto::GameServerWait:
case Proto::GameServerTopFloor:
2011-08-15 16:11:24 +02:00
parseFloorChangeUp(msg);
break;
case Proto::GameServerBottomFloor:
2011-08-15 16:11:24 +02:00
parseFloorChangeDown(msg);
break;
case Proto::GameServerOutfit:
2011-08-15 16:11:24 +02:00
parseOutfitWindow(msg);
break;
case Proto::GameServerBuddyData:
2011-08-15 16:11:24 +02:00
parseVipState(msg);
break;
case Proto::GameServerBuddyLogin:
2011-08-15 16:11:24 +02:00
parseVipLogin(msg);
break;
case Proto::GameServerBuddyLogout:
2011-08-15 16:11:24 +02:00
parseVipLogout(msg);
break;
case Proto::GameServerTutorialHint:
2011-08-15 16:11:24 +02:00
parseShowTutorial(msg);
break;
case Proto::GameServerAutomapFlag:
2011-08-15 16:11:24 +02:00
parseAddMarker(msg);
break;
case Proto::GameServerQuestLog:
2011-08-15 16:11:24 +02:00
parseQuestList(msg);
break;
case Proto::GameServerQuestLine:
2011-08-15 16:11:24 +02:00
parseQuestPartList(msg);
break;
//case Proto::GameServerChannelEvent:
//case Proto::GameServerObjectInfo:
//case Proto::GameServerPlayerInventory:
2011-08-15 16:11:24 +02:00
default:
Fw::throwException("unknown opt byte ", (int)opt);
2011-08-15 16:11:24 +02:00
break;
}
2011-08-15 16:11:24 +02:00
}
} catch(Exception& e) {
logTraceError(e.what());
2011-08-15 16:11:24 +02:00
}
}
void ProtocolGame::parseInitGame(InputMessage& msg)
2011-08-15 16:11:24 +02:00
{
2012-01-12 20:20:18 +01:00
uint playerId = msg.getU32();
2012-01-07 23:24:29 +01:00
int serverBeat = msg.getU16();
2011-08-15 23:02:52 +02:00
int playerCanReportBugs = msg.getU8();
2011-08-15 16:11:24 +02:00
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
2011-08-15 23:02:52 +02:00
m_localPlayer->setId(playerId);
m_localPlayer->setCanReportBugs(playerCanReportBugs);
g_game.processGameStart(m_localPlayer, serverBeat);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseGMActions(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
for(int i = 0; i < Proto::NumViolationReasons; ++i)
2011-08-15 16:11:24 +02:00
msg.getU8();
}
void ProtocolGame::parseLoginError(InputMessage& msg)
2011-08-15 16:11:24 +02:00
{
std::string error = msg.getString();
2012-01-09 06:23:39 +01:00
g_game.processLoginError(error);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseFYIMessage(InputMessage& msg)
{
msg.getString(); // message
}
void ProtocolGame::parseWaitList(InputMessage& msg)
{
msg.getString(); // message
msg.getU8();// + 1 // time
}
void ProtocolGame::parsePing(InputMessage&)
{
sendPing();
}
2011-09-02 02:28:24 +02:00
void ProtocolGame::parseDeath(InputMessage& msg)
2011-08-15 16:11:24 +02:00
{
#if PROTOCOL==862
2011-09-02 02:28:24 +02:00
msg.getU8(); // 100 is a fair death. < 100 is a unfair death.
#endif
2012-01-09 06:23:39 +01:00
g_game.processDeath();
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseMapDescription(InputMessage& msg)
{
2011-08-15 23:02:52 +02:00
Position pos = parsePosition(msg);
2011-08-30 03:34:00 +02:00
g_map.setCentralPosition(pos);
2012-01-30 19:18:10 +01:00
setMapDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseMoveNorth(InputMessage& msg)
{
2011-08-30 03:34:00 +02:00
Position pos = g_map.getCentralPosition();
pos.y--;
2012-01-30 19:18:10 +01:00
setMapDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z, Otc::AWARE_X_TILES, 1);
2011-08-30 03:34:00 +02:00
g_map.setCentralPosition(pos);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseMoveEast(InputMessage& msg)
{
2011-08-30 03:34:00 +02:00
Position pos = g_map.getCentralPosition();
pos.x++;
2012-01-30 19:18:10 +01:00
setMapDescription(msg, pos.x + Otc::AWARE_X_RIGHT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z, 1, Otc::AWARE_Y_TILES);
2011-08-30 03:34:00 +02:00
g_map.setCentralPosition(pos);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseMoveSouth(InputMessage& msg)
{
2011-08-30 03:34:00 +02:00
Position pos = g_map.getCentralPosition();
pos.y++;
2012-01-30 19:18:10 +01:00
setMapDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y + Otc::AWARE_Y_BOTTOM_TILES, pos.z, Otc::AWARE_X_TILES, 1);
2011-08-30 03:34:00 +02:00
g_map.setCentralPosition(pos);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseMoveWest(InputMessage& msg)
{
2011-08-30 03:34:00 +02:00
Position pos = g_map.getCentralPosition();
pos.x--;
2012-01-30 19:18:10 +01:00
setMapDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z, 1, Otc::AWARE_Y_TILES);
2011-08-30 03:34:00 +02:00
g_map.setCentralPosition(pos);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseUpdateTile(InputMessage& msg)
{
Position tilePos = parsePosition(msg);
2012-01-12 20:20:18 +01:00
int thingId = msg.getU16(true);
2011-08-15 16:11:24 +02:00
if(thingId == 0xFF01) {
msg.getU16();
2012-01-09 06:23:39 +01:00
} else {
2011-08-15 16:11:24 +02:00
setTileDescription(msg, tilePos);
msg.getU16();
}
}
void ProtocolGame::parseTileAddThing(InputMessage& msg)
{
Position pos = parsePosition(msg);
2012-01-12 20:20:18 +01:00
int stackPos = msg.getU8();
ThingPtr thing = internalGetThing(msg);
2011-08-31 22:22:57 +02:00
g_map.addThing(thing, pos, stackPos);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseTileTransformThing(InputMessage& msg)
{
Position pos = parsePosition(msg);
2012-01-12 20:20:18 +01:00
int stackPos = msg.getU8();
2011-08-15 16:11:24 +02:00
2012-01-12 20:20:18 +01:00
int thingId = msg.getU16();
assert(thingId != 0);
2011-08-15 16:11:24 +02:00
if(thingId == 0x0061 || thingId == 0x0062 || thingId == 0x0063) {
parseCreatureTurn(msg);
2012-01-12 20:20:18 +01:00
} else {
ThingPtr thing = internalGetItem(msg, thingId);
2012-01-08 16:42:23 +01:00
g_map.removeThingByPos(pos, stackPos);
2011-08-31 22:22:57 +02:00
g_map.addThing(thing, pos, stackPos);
2011-08-15 16:11:24 +02:00
}
}
void ProtocolGame::parseTileRemoveThing(InputMessage& msg)
{
Position pos = parsePosition(msg);
2012-01-12 20:20:18 +01:00
int stackPos = msg.getU8();
2012-01-08 16:42:23 +01:00
g_map.removeThingByPos(pos, stackPos);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseCreatureMove(InputMessage& msg)
{
Position oldPos = parsePosition(msg);
2012-01-12 20:20:18 +01:00
int oldStackpos = msg.getU8();
Position newPos = parsePosition(msg);
2012-01-30 01:00:12 +01:00
ThingPtr thing = g_map.getThing(oldPos, oldStackpos);
2011-12-28 12:00:09 +01:00
if(!thing) {
2012-01-09 06:23:39 +01:00
logTraceError("could not get thing");
2011-12-28 12:00:09 +01:00
return;
}
2011-08-31 22:22:57 +02:00
CreaturePtr creature = thing->asCreature();
2011-12-28 12:00:09 +01:00
if(!creature) {
2012-01-09 06:23:39 +01:00
logTraceError("thing is not a creature");
2011-12-28 12:00:09 +01:00
return;
}
2011-11-05 21:34:49 +01:00
// update map tiles
g_map.removeThing(thing);
g_map.addThing(thing, newPos);
2012-01-09 06:23:39 +01:00
g_game.processCreatureMove(creature, oldPos, newPos);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseOpenContainer(InputMessage& msg)
{
2012-01-12 20:25:58 +01:00
int containerId = msg.getU8();
int itemId = msg.getU16();
std::string name = msg.getString();
int capacity = msg.getU8();
bool hasParent = (msg.getU8() != 0);
int itemCount = msg.getU8();
2012-01-20 03:33:11 +01:00
std::vector<ItemPtr> items;
items.reserve(itemCount);
2012-01-12 20:25:58 +01:00
for(int i = 0; i < itemCount; i++) {
ItemPtr item = internalGetItem(msg);
2012-01-20 03:33:11 +01:00
items.push_back(item);
2012-01-12 20:25:58 +01:00
}
2012-01-20 03:33:11 +01:00
g_lua.callGlobalField("Game", "onContainerOpen", containerId, itemId, name, capacity, hasParent, items);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseCloseContainer(InputMessage& msg)
{
2012-01-12 20:25:58 +01:00
int containerId = msg.getU8();
g_lua.callGlobalField("Game", "onContainerClose", containerId);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseContainerAddItem(InputMessage& msg)
{
2012-01-12 20:25:58 +01:00
int containerId = msg.getU8();
ItemPtr item = internalGetItem(msg);
2012-01-13 01:31:39 +01:00
g_game.processContainerAddItem(containerId, item);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseContainerUpdateItem(InputMessage& msg)
{
2012-01-12 20:25:58 +01:00
int containerId = msg.getU8();
int slot = msg.getU8();
ItemPtr item = internalGetItem(msg);
g_lua.callGlobalField("Game", "onContainerUpdateItem", containerId, slot, item);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseContainerRemoveItem(InputMessage& msg)
{
2012-01-12 20:25:58 +01:00
int containerId = msg.getU8();
int slot = msg.getU8();
2012-01-13 01:31:39 +01:00
g_lua.callGlobalField("Game", "onContainerRemoveItem", containerId, slot);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseAddInventoryItem(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
int slot = msg.getU8();
ItemPtr item = internalGetItem(msg);
2012-01-09 06:23:39 +01:00
g_game.processInventoryChange(slot, item);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseRemoveInventoryItem(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
int slot = msg.getU8();
2012-01-09 06:23:39 +01:00
g_game.processInventoryChange(slot, ItemPtr());
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseOpenShopWindow(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
int listCount = msg.getU8();
for(int i = 0; i < listCount; ++i) {
2011-08-15 16:11:24 +02:00
msg.getU16(); // item id
msg.getU8(); // runecharges
msg.getString(); // item name
msg.getU32(); // weight
msg.getU32(); // buy price
msg.getU32(); // sell price
}
}
void ProtocolGame::parsePlayerCash(InputMessage& msg)
{
msg.getU32();
2012-01-12 20:20:18 +01:00
int size = msg.getU8();
2011-08-15 16:11:24 +02:00
for(int i = 0; i < size; i++) {
msg.getU16(); // itemid
msg.getU8(); // runecharges
}
}
void ProtocolGame::parseCloseShopWindow(InputMessage&)
{
}
void ProtocolGame::parseSafeTradeRequest(InputMessage& msg)
{
msg.getString(); // name
2012-01-12 20:20:18 +01:00
int count = msg.getU8();
2011-08-15 16:11:24 +02:00
2012-01-12 20:20:18 +01:00
for(int i = 0; i < count; i++)
internalGetItem(msg);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseSafeTradeClose(InputMessage&)
{
}
void ProtocolGame::parseWorldLight(InputMessage& msg)
{
Light light;
light.intensity = msg.getU8();
light.color = msg.getU8();
g_map.setLight(light);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseMagicEffect(InputMessage& msg)
{
2011-08-31 22:22:57 +02:00
Position pos = parsePosition(msg);
int effectId = msg.getU8();
2011-08-15 16:11:24 +02:00
EffectPtr effect = EffectPtr(new Effect());
effect->setId(effectId);
2011-12-07 20:58:09 +01:00
g_map.addThing(effect, pos);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseAnimatedText(InputMessage& msg)
{
2011-12-26 12:53:16 +01:00
Position position = parsePosition(msg);
2012-01-12 20:20:18 +01:00
int color = msg.getU8();
2011-12-26 12:53:16 +01:00
std::string text = msg.getString();
AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText);
animatedText->setColor(color);
animatedText->setText(text);
g_map.addThing(animatedText, position);
2011-08-15 16:11:24 +02:00
}
2011-11-12 07:24:32 +01:00
void ProtocolGame::parseDistanceMissile(InputMessage& msg)
2011-08-15 16:11:24 +02:00
{
2011-11-08 02:44:30 +01:00
Position fromPos = parsePosition(msg);
Position toPos = parsePosition(msg);
int shotId = msg.getU8();
2012-01-30 01:00:12 +01:00
MissilePtr missile = MissilePtr(new Missile());
missile->setId(shotId);
missile->setPath(fromPos, toPos);
g_map.addThing(missile, fromPos);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseCreatureSquare(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
uint id = msg.getU32();
int color = msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
2012-02-08 03:11:57 +01:00
creature->addTimedSquare(color);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseCreatureHealth(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
uint id = msg.getU32();
int healthPercent = msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->setHealthPercent(healthPercent);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseCreatureLight(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
uint id = msg.getU32();
Light light;
light.intensity = msg.getU8();
light.color = msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->setLight(light);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseCreatureOutfit(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
uint id = msg.getU32();
Outfit outfit = internalGetOutfit(msg);
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->setOutfit(outfit);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseCreatureSpeed(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
uint id = msg.getU32();
int speed = msg.getU16();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->setSpeed(speed);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseCreatureSkulls(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
uint id = msg.getU32();
int skull = msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->setSkull(skull);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseCreatureShields(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
uint id = msg.getU32();
int shield = msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->setShield(shield);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseCreatureTurn(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
uint id = msg.getU32();
Otc::Direction direction = (Otc::Direction)msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
2011-12-28 12:00:09 +01:00
creature->turn(direction);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseItemTextWindow(InputMessage& msg)
{
msg.getU32(); // windowId
msg.getU16(); // itemid
msg.getU16(); // max length
msg.getString(); // text
msg.getString(); // writter
msg.getString(); // date
}
void ProtocolGame::parseHouseTextWindow(InputMessage& msg)
{
msg.getU8(); // unknown
msg.getU32(); // windowId
msg.getString(); // text
}
void ProtocolGame::parsePlayerStats(InputMessage& msg)
{
double health = msg.getU16();
double maxHealth = msg.getU16();
double freeCapacity = msg.getU32() / 100.0;
double experience = msg.getU32();
double level = msg.getU16();
double levelPercent = msg.getU8();
double mana = msg.getU16();
double maxMana = msg.getU16();
double magicLevel = msg.getU8();
double magicLevelPercent = msg.getU8();
double soul = msg.getU8();
double stamina = msg.getU16();
g_game.processPlayerStats(health, maxHealth, freeCapacity, experience, level, levelPercent, mana, maxMana, magicLevel, magicLevelPercent, soul, stamina);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parsePlayerSkills(InputMessage& msg)
{
2011-11-03 23:14:56 +01:00
for(int skill = 0; skill < Otc::LastSkill; skill++) {
int values[Otc::LastSkillType];
for(int skillType = 0; skillType < Otc::LastSkillType; skillType++) {
values[skillType] = msg.getU8();
m_localPlayer->setSkill((Otc::Skill)skill, (Otc::SkillType)skillType, values[skillType]);
}
2012-01-09 06:23:39 +01:00
g_lua.callGlobalField("Game", "onSkillChange", skill, values[Otc::SkillLevel], values[Otc::SkillPercent]);
2011-11-03 23:14:56 +01:00
}
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parsePlayerIcons(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
int icons = msg.getU16();
m_localPlayer->setIcons((Otc::PlayerIcons)icons);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parsePlayerCancelAttack(InputMessage& msg)
{
2012-01-05 15:24:38 +01:00
msg.getU32(); // unknown
2012-01-09 06:23:39 +01:00
g_game.processAttackCancel();
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseCreatureSpeak(InputMessage& msg)
{
msg.getU32(); // unkSpeak
2011-12-29 18:45:59 +01:00
std::string name = msg.getString();
int level = msg.getU16();
2012-02-03 01:25:18 +01:00
int serverType = msg.getU8();
2011-12-07 16:33:00 +01:00
int channelId = 0;
Position creaturePos;
2011-08-15 16:11:24 +02:00
2012-02-03 01:25:18 +01:00
switch(serverType) {
case Proto::ServerSpeakSay:
case Proto::ServerSpeakWhisper:
case Proto::ServerSpeakYell:
case Proto::ServerSpeakMonsterSay:
case Proto::ServerSpeakMonsterYell:
case Proto::ServerSpeakPrivateNpcToPlayer:
2011-12-29 18:45:59 +01:00
creaturePos = parsePosition(msg);
2011-08-15 16:11:24 +02:00
break;
2012-02-03 01:25:18 +01:00
case Proto::ServerSpeakChannelYellow:
case Proto::ServerSpeakChannelWhite:
case Proto::ServerSpeakChannelRed:
case Proto::ServerSpeakChannelRed2:
case Proto::ServerSpeakChannelOrange:
2011-12-29 18:45:59 +01:00
channelId = msg.getU16();
2011-08-15 16:11:24 +02:00
break;
2012-02-03 01:25:18 +01:00
case Proto::ServerSpeakPrivate:
case Proto::ServerSpeakPrivatePlayerToNpc:
case Proto::ServerSpeakBroadcast:
case Proto::ServerSpeakPrivateRed:
2011-08-15 16:11:24 +02:00
break;
2012-02-03 01:25:18 +01:00
case Proto::ServerSpeakRVRChannel:
2012-01-08 16:42:23 +01:00
msg.getU32();
break;
2011-08-15 16:11:24 +02:00
default:
2012-02-03 01:25:18 +01:00
logTraceError("unknown speak type ", serverType);
2011-08-15 16:11:24 +02:00
break;
}
2011-12-29 18:45:59 +01:00
std::string message = msg.getString();
2012-02-03 01:25:18 +01:00
Otc::SpeakType type = Proto::translateSpeakTypeFromServer(serverType);
2011-11-04 00:34:32 +01:00
2012-02-03 01:25:18 +01:00
g_game.processCreatureSpeak(name, level, type, message, channelId, creaturePos);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseChannelList(InputMessage& msg)
{
int count = msg.getU8();
std::vector<std::tuple<int, std::string> > channelList(count);
for(int i = 0; i < count; i++) {
int id = msg.getU16();
std::string name = msg.getString();
channelList.push_back(std::make_tuple(id, name));
2011-08-15 16:11:24 +02:00
}
2012-01-09 06:23:39 +01:00
g_lua.callGlobalField("Game", "onChannelList", channelList);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseOpenChannel(InputMessage& msg)
{
int channelId = msg.getU16();
std::string name = msg.getString();
2012-01-09 06:23:39 +01:00
g_lua.callGlobalField("Game", "onOpenChannel", channelId, name);
2011-08-15 16:11:24 +02:00
}
2012-02-02 23:29:44 +01:00
void ProtocolGame::parseOpenPrivateChannel(InputMessage& msg)
2011-08-15 16:11:24 +02:00
{
2012-02-02 23:29:44 +01:00
std::string name = msg.getString();
g_lua.callGlobalField("Game", "onOpenPrivateChannel", name);
2011-08-15 16:11:24 +02:00
}
2012-02-02 23:29:44 +01:00
void ProtocolGame::parseCreateOwnPrivateChannel(InputMessage& msg)
2011-08-15 16:11:24 +02:00
{
2012-02-02 23:29:44 +01:00
int id = msg.getU16(); // channel id
std::string name = msg.getString(); // channel name
g_lua.callGlobalField("Game", "onOpenOwnPrivateChannel", id, name);
2011-08-15 16:11:24 +02:00
}
2012-02-02 23:29:44 +01:00
void ProtocolGame::parseCloseChannel(InputMessage& msg)
2011-08-15 16:11:24 +02:00
{
2012-02-02 23:29:44 +01:00
int id = msg.getU16(); // channel id
g_lua.callGlobalField("Game", "onCloseChannel", id);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseTextMessage(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
int type = msg.getU8();
2012-01-08 21:11:50 +01:00
std::string typeDesc = Proto::translateTextMessageType(type);
2011-08-15 16:11:24 +02:00
std::string message = msg.getString();
2011-08-30 17:12:57 +02:00
2012-01-09 06:23:39 +01:00
g_game.processTextMessage(typeDesc, message);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseCancelWalk(InputMessage& msg)
{
Otc::Direction direction = (Otc::Direction)msg.getU8();
2012-01-09 06:23:39 +01:00
g_game.processWalkCancel(direction);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseFloorChangeUp(InputMessage& msg)
{
2011-08-30 03:34:00 +02:00
Position pos = g_map.getCentralPosition();
2011-08-15 23:02:52 +02:00
pos.z--;
2011-08-15 16:11:24 +02:00
2012-01-12 20:20:18 +01:00
int skip = 0;
2012-01-30 19:18:10 +01:00
if(pos.z == Otc::SEA_FLOOR)
for(int i = Otc::SEA_FLOOR - Otc::AWARE_UNDEGROUND_FLOOR_RANGE; i >= 0; i--)
setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, i, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, 8 - i, &skip);
else if(pos.z > Otc::SEA_FLOOR)
setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z - Otc::AWARE_UNDEGROUND_FLOOR_RANGE, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, 3, &skip);
2011-08-15 23:02:52 +02:00
2011-08-30 03:34:00 +02:00
pos.x++;
pos.y++;
g_map.setCentralPosition(pos);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseFloorChangeDown(InputMessage& msg)
{
2011-08-30 03:34:00 +02:00
Position pos = g_map.getCentralPosition();
pos.z++;
2011-08-15 16:11:24 +02:00
2011-08-15 23:02:52 +02:00
int skip = 0;
2012-01-30 19:18:10 +01:00
if(pos.z == Otc::UNDERGROUND_FLOOR) {
2011-08-15 23:02:52 +02:00
int j, i;
2012-01-30 19:18:10 +01:00
for(i = pos.z, j = -1; i <= pos.z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE; ++i, --j)
setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, i, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, j, &skip);
2011-08-15 16:11:24 +02:00
}
2012-01-30 19:18:10 +01:00
else if(pos.z > Otc::UNDERGROUND_FLOOR && pos.z < Otc::MAX_Z-1)
setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, -3, &skip);
2011-08-15 16:11:24 +02:00
2011-08-30 03:34:00 +02:00
pos.x--;
pos.y--;
g_map.setCentralPosition(pos);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseOutfitWindow(InputMessage& msg)
{
2011-11-14 23:32:55 +01:00
Outfit outfit = internalGetOutfit(msg);
typedef std::tuple<int, std::string, int> OutfitInfo;
std::vector<OutfitInfo> outfitList;
2011-08-15 16:11:24 +02:00
2011-11-14 23:32:55 +01:00
uint8 outfitCount = msg.getU8();
2011-08-15 16:11:24 +02:00
for(int i = 0; i < outfitCount; i++) {
2011-11-14 23:32:55 +01:00
uint16 outfitId = msg.getU16();
std::string outfitName = msg.getString();
uint8 outfitAddons = msg.getU8();
outfitList.push_back(OutfitInfo(outfitId, outfitName, outfitAddons));
2011-08-15 16:11:24 +02:00
}
2011-11-14 23:32:55 +01:00
CreaturePtr creature = CreaturePtr(new Creature);
2012-01-30 01:00:12 +01:00
creature->setDirection(Otc::South);
2011-11-14 23:32:55 +01:00
creature->setOutfit(outfit);
2012-01-09 06:23:39 +01:00
g_lua.callGlobalField("Game", "onOpenOutfitWindow", creature, outfitList);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseVipState(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
uint id = msg.getU32();
2011-09-02 06:29:00 +02:00
std::string name = msg.getString();
bool online = msg.getU8() != 0;
2012-01-09 06:23:39 +01:00
g_lua.callGlobalField("Game", "onAddVip", id, name, online);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseVipLogin(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
uint id = msg.getU32();
2011-09-02 06:29:00 +02:00
2012-01-09 06:23:39 +01:00
g_lua.callGlobalField("Game", "onVipStateChange", id, true);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseVipLogout(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
uint id = msg.getU32();
2011-09-02 06:29:00 +02:00
2012-01-09 06:23:39 +01:00
g_lua.callGlobalField("Game", "onVipStateChange", id, false);
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::parseShowTutorial(InputMessage& msg)
{
msg.getU8(); // tutorial id
}
void ProtocolGame::parseAddMarker(InputMessage& msg)
{
parsePosition(msg); // position
msg.getU8(); // icon
msg.getString(); // message
}
void ProtocolGame::parseQuestList(InputMessage& msg)
{
2012-01-12 20:20:18 +01:00
int questsCount = msg.getU16();
for(int i = 0; i < questsCount; i++) {
2011-08-15 16:11:24 +02:00
msg.getU16(); // quest id
msg.getString(); // quest name
msg.getU8(); // quest state
}
}
void ProtocolGame::parseQuestPartList(InputMessage& msg)
{
msg.getU16(); // quest id
2012-01-12 20:20:18 +01:00
int missionCount = msg.getU8();
for(int i = 0; i < missionCount; i++) {
2011-08-15 16:11:24 +02:00
msg.getString(); // quest name
msg.getString(); // quest description
}
}
void ProtocolGame::setMapDescription(InputMessage& msg, int32 x, int32 y, int32 z, int32 width, int32 height)
{
int startz, endz, zstep, skip = 0;
2012-01-30 19:18:10 +01:00
if(z > Otc::SEA_FLOOR) {
startz = z - Otc::AWARE_UNDEGROUND_FLOOR_RANGE;
endz = std::min(z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE, (int)Otc::MAX_Z);
2011-08-15 16:11:24 +02:00
zstep = 1;
}
else {
2012-01-30 19:18:10 +01:00
startz = Otc::SEA_FLOOR;
2011-08-15 16:11:24 +02:00
endz = 0;
zstep = -1;
}
for(int nz = startz; nz != endz + zstep; nz += zstep)
setFloorDescription(msg, x, y, nz, width, height, z - nz, &skip);
}
void ProtocolGame::setFloorDescription(InputMessage& msg, int32 x, int32 y, int32 z, int32 width, int32 height, int32 offset, int32* skipTiles)
{
2012-01-12 20:20:18 +01:00
int skip = *skipTiles;
2011-08-15 16:11:24 +02:00
2012-01-12 20:20:18 +01:00
for(int nx = 0; nx < width; nx++) {
for(int ny = 0; ny < height; ny++) {
2012-01-30 19:18:10 +01:00
Position tilePos(x + nx + offset, y + ny + offset, z);
// clean pre stored tiles
g_map.cleanTile(tilePos);
2011-08-15 16:11:24 +02:00
if(skip == 0) {
2012-01-12 20:20:18 +01:00
int tileOpt = msg.getU16(true);
2011-08-15 16:11:24 +02:00
if(tileOpt >= 0xFF00)
skip = (msg.getU16() & 0xFF);
else {
2012-01-30 19:18:10 +01:00
setTileDescription(msg, tilePos);
2011-08-15 16:11:24 +02:00
skip = (msg.getU16() & 0xFF);
}
}
else
skip--;
}
}
*skipTiles = skip;
}
void ProtocolGame::setTileDescription(InputMessage& msg, Position position)
{
g_map.cleanTile(position);
2011-08-31 22:22:57 +02:00
int stackPos = 0;
while(true) {
2012-01-12 20:20:18 +01:00
int inspectTileId = msg.getU16(true);
2011-08-15 16:11:24 +02:00
if(inspectTileId >= 0xFF00)
return;
else {
2011-08-31 22:22:57 +02:00
if(stackPos >= 10)
2012-01-09 19:45:13 +01:00
logTraceError("too many things, stackpos=", stackPos, " pos=", position);
2011-08-15 16:11:24 +02:00
ThingPtr thing = internalGetThing(msg);
2012-01-12 20:20:18 +01:00
if(thing)
2012-02-08 05:20:14 +01:00
g_map.addThing(thing, position, -1);
2011-08-15 16:11:24 +02:00
}
2011-08-31 22:22:57 +02:00
stackPos++;
2011-08-15 16:11:24 +02:00
}
}
2011-08-15 23:02:52 +02:00
Outfit ProtocolGame::internalGetOutfit(InputMessage& msg)
{
Outfit outfit;
2012-01-12 20:20:18 +01:00
int id = msg.getU16();
2012-01-10 01:36:18 +01:00
if(id != 0) {
outfit.setCategory(ThingsType::Creature);
2012-01-12 20:20:18 +01:00
int head = msg.getU8();
int body = msg.getU8();
int legs = msg.getU8();
int feet = msg.getU8();
int addons = msg.getU8();
2011-11-13 09:46:19 +01:00
2012-01-10 01:36:18 +01:00
outfit.setId(id);
2011-11-13 09:46:19 +01:00
outfit.setHead(head);
outfit.setBody(body);
outfit.setLegs(legs);
outfit.setFeet(feet);
outfit.setAddons(addons);
2011-08-15 23:02:52 +02:00
}
else {
2012-01-12 20:20:18 +01:00
int id = msg.getU16();
2012-01-10 01:36:18 +01:00
if(id == 0) {
outfit.setCategory(ThingsType::Effect);
outfit.setId(13);
}
else {
outfit.setCategory(ThingsType::Item);
outfit.setId(id);
}
2011-08-15 23:02:52 +02:00
}
return outfit;
}
2011-08-15 16:11:24 +02:00
ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
{
ThingPtr thing;
2012-01-12 20:20:18 +01:00
int thingId = msg.getU16();
assert(thingId != 0);
2011-08-15 16:11:24 +02:00
if(thingId == 0x0061 || thingId == 0x0062) { // add new creature
CreaturePtr creature;
2011-08-15 16:11:24 +02:00
if(thingId == 0x0062) { //creature is known
2012-01-12 20:20:18 +01:00
uint id = msg.getU32();
CreaturePtr knownCreature = g_map.getCreatureById(id);
if(knownCreature)
creature = knownCreature;
else
2012-01-30 01:00:12 +01:00
logTraceError("server said that a creature is known, but it's not");
2012-01-09 06:23:39 +01:00
} else if(thingId == 0x0061) { //creature is not known
2012-01-12 20:20:18 +01:00
uint removeId = msg.getU32();
uint id = msg.getU32();
std::string name = msg.getString();
if(name.length() > 0) // every creature name must start with a capital letter
2011-12-21 05:43:51 +01:00
name[0] = toupper(name[0]);
2011-08-26 23:34:16 +02:00
g_map.removeCreatureById(removeId);
2012-01-09 06:23:39 +01:00
if(id == m_localPlayer->getId())
creature = m_localPlayer;
else if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId)
2012-01-09 06:23:39 +01:00
creature = PlayerPtr(new Player);
else if(id >= Proto::MonsterStartId && id < Proto::MonsterEndId)
2012-01-09 06:23:39 +01:00
creature = MonsterPtr(new Monster);
else if(id >= Proto::NpcStartId && id < Proto::NpcEndId)
2012-01-09 06:23:39 +01:00
creature = NpcPtr(new Npc);
else
2012-01-09 06:23:39 +01:00
logTraceError("creature id is invalid");
creature->setId(id);
creature->setName(name);
2012-01-30 01:00:12 +01:00
g_map.addCreature(creature);
2011-08-15 16:11:24 +02:00
}
uint8 healthPercent = msg.getU8();
Otc::Direction direction = (Otc::Direction)msg.getU8();
Outfit outfit = internalGetOutfit(msg);
Light light;
light.intensity = msg.getU8();
light.color = msg.getU8();
2012-01-12 20:20:18 +01:00
int speed = msg.getU16();
int skull = msg.getU8();
int shield = msg.getU8();
2011-08-15 16:11:24 +02:00
int emblem = -1;
2011-08-15 16:11:24 +02:00
if(thingId == 0x0061) // emblem is sent only in packet type 0x61
emblem = msg.getU8();
2011-12-30 15:15:23 +01:00
bool passable = (msg.getU8() == 0);
2012-01-09 06:23:39 +01:00
if(creature) {
creature->setHealthPercent(healthPercent);
creature->setDirection(direction);
creature->setOutfit(outfit);
creature->setLight(light);
creature->setSpeed(speed);
creature->setSkull(skull);
creature->setShield(shield);
if(emblem != -1)
creature->setEmblem(emblem);
2012-01-09 06:23:39 +01:00
creature->setPassable(passable);
2012-01-19 05:12:53 +01:00
creature->setDirection(direction);
2012-01-17 06:36:25 +01:00
// now that the local player is known, we can schedule login event
if(creature == m_localPlayer && !m_localPlayer->isKnown()) {
2012-01-17 06:36:25 +01:00
m_localPlayer->setKnown(true);
g_dispatcher.addEvent([] { g_game.processLogin(); });
2012-01-17 06:36:25 +01:00
}
2012-01-09 06:23:39 +01:00
}
2011-08-15 16:11:24 +02:00
thing = creature;
2012-01-09 06:23:39 +01:00
} else if(thingId == 0x0063) { // creature turn
2011-08-15 16:11:24 +02:00
parseCreatureTurn(msg);
2012-01-09 06:23:39 +01:00
} else // item
2011-08-15 16:11:24 +02:00
thing = internalGetItem(msg, thingId);
return thing;
}
2012-01-12 20:20:18 +01:00
ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, int id)
2011-08-15 16:11:24 +02:00
{
2012-01-12 20:20:18 +01:00
if(id == 0)
2011-08-15 16:11:24 +02:00
id = msg.getU16();
2012-01-09 06:23:39 +01:00
ItemPtr item = Item::create(id);
if(item->isStackable() || item->isFluidContainer() || item->isFluid())
item->setCountOrSubType(msg.getU8());
2011-08-15 16:11:24 +02:00
return item;
}
Position ProtocolGame::parsePosition(InputMessage& msg)
{
uint16 x = msg.getU16();
uint16 y = msg.getU16();
uint8 z = msg.getU8();
return Position(x, y, z);
}