2011-08-28 15:17:58 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
|
|
|
*
|
|
|
|
* 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>
|
2011-08-29 16:14:21 +02:00
|
|
|
#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>
|
2011-11-19 01:12:17 +01:00
|
|
|
#include <otclient/luascript/luavaluecasts.h>
|
2011-08-29 16:14:21 +02:00
|
|
|
#include <framework/core/eventdispatcher.h>
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
void ProtocolGame::parseMessage(InputMessage& msg)
|
|
|
|
{
|
2011-12-01 23:25:32 +01:00
|
|
|
try {
|
|
|
|
while(!msg.eof()) {
|
|
|
|
uint8 opt = msg.getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2011-12-01 23:25:32 +01:00
|
|
|
switch(opt) {
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerInitGame:
|
2011-08-15 16:11:24 +02:00
|
|
|
parsePlayerLogin(msg);
|
|
|
|
break;
|
|
|
|
case 0x0B:
|
|
|
|
parseGMActions(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerLoginError:
|
2011-11-11 21:26:10 +01:00
|
|
|
parseLoginError(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerLoginAdvice:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseFYIMessage(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerLoginWait:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseWaitList(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerPing:
|
2011-08-15 16:11:24 +02:00
|
|
|
parsePing(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
//case Otc::GameServerChallange:
|
|
|
|
case Otc::GameServerDead:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseDeath(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerFullMap:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseMapDescription(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerMapTopRow:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseMoveNorth(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerMapRightRow:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseMoveEast(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerMapBottomRow:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseMoveSouth(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerMapLeftRow:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseMoveWest(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerTileData:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseUpdateTile(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerCreateOnMap:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseTileAddThing(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerChangeOnMap:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseTileTransformThing(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerDeleteOnMap:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseTileRemoveThing(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerMoveCreature:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureMove(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerOpenContainer:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseOpenContainer(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerCloseContainer:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCloseContainer(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerCreateContainer:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseContainerAddItem(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerChangeInContainer:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseContainerUpdateItem(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerDeleteInContainer:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseContainerRemoveItem(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerSetInventory:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseAddInventoryItem(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerDeleteInventory:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseRemoveInventoryItem(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerNpcOffer:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseOpenShopWindow(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerPlayerGoods:
|
2011-08-15 16:11:24 +02:00
|
|
|
parsePlayerCash(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerCloseNpcTrade:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCloseShopWindow(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerOwnOffer:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseSafeTradeRequest(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerCounterOffer:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseSafeTradeRequest(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerCloseTrade:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseSafeTradeClose(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerAmbient:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseWorldLight(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerGraphicalEffect:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseMagicEffect(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerTextEffect:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseAnimatedText(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerMissleEffect:
|
2011-11-12 07:24:32 +01:00
|
|
|
parseDistanceMissile(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerMarkCreature:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureSquare(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
//case Otc::GameServerTrappers
|
|
|
|
case Otc::GameServerCreatureHealth:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureHealth(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerCreatureLight:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureLight(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerCreatureOutfit:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureOutfit(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerCreatureSpeed:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureSpeed(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerCreatureSkull:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureSkulls(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerCreatureParty:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureShields(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
// case Otc::GameServerCreatureUnpass
|
|
|
|
case Otc::GameServerEditText:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseItemTextWindow(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerEditList:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseHouseTextWindow(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerPlayerData:
|
2011-08-15 16:11:24 +02:00
|
|
|
parsePlayerStats(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerPlayerSkills:
|
2011-08-15 16:11:24 +02:00
|
|
|
parsePlayerSkills(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerPlayerState:
|
2011-08-15 16:11:24 +02:00
|
|
|
parsePlayerIcons(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerClearTarget:
|
2011-08-15 16:11:24 +02:00
|
|
|
parsePlayerCancelAttack(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
//case Otc::GameServerSpellDelay:
|
|
|
|
//case Otc::GameServerSpellGroupDelay:
|
|
|
|
case Otc::GameServerTalk:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatureSpeak(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerChannels:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseChannelList(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerOpenChannel:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseOpenChannel(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerPrivateChannel:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseOpenPrivatePlayerChat(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerRuleViolation:
|
|
|
|
case Otc::GameServerRuleViolation1:
|
|
|
|
case Otc::GameServerRuleViolation2:
|
|
|
|
case Otc::GameServerRuleViolation3:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseOpenRuleViolation(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerOpenOwnChannel:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCreatePrivateChannel(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerCloseChannel:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseClosePrivateChannel(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerMessage:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseTextMessage(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerSnapBack:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseCancelWalk(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
//case Otc::GameServerWait:
|
|
|
|
case Otc::GameServerTopFloor:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseFloorChangeUp(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerBottomFloor:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseFloorChangeDown(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerOutfit:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseOutfitWindow(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerBuddyData:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseVipState(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerBuddyLogin:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseVipLogin(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerBuddyLogout:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseVipLogout(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerTutorialHint:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseShowTutorial(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerAutomapFlag:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseAddMarker(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerQuestLog:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseQuestList(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
case Otc::GameServerQuestLine:
|
2011-08-15 16:11:24 +02:00
|
|
|
parseQuestPartList(msg);
|
|
|
|
break;
|
2011-08-31 18:49:51 +02:00
|
|
|
//case Otc::GameServerChannelEvent:
|
|
|
|
//case Otc::GameServerObjectInfo:
|
|
|
|
//case Otc::GameServerPlayerInventory:
|
2011-08-15 16:11:24 +02:00
|
|
|
default:
|
2011-12-03 22:41:37 +01:00
|
|
|
Fw::throwException("unknown opt byte ", (int)opt);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2011-12-01 23:25:32 +01:00
|
|
|
}
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
2011-12-01 23:25:32 +01:00
|
|
|
} catch(Exception& e) {
|
|
|
|
logTraceError(e.what());
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parsePlayerLogin(InputMessage& msg)
|
|
|
|
{
|
2011-08-15 23:02:52 +02:00
|
|
|
int playerId = msg.getU32();
|
|
|
|
int playerDrawSpeed = msg.getU16();
|
|
|
|
int playerCanReportBugs = msg.getU8();
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
|
2011-08-15 23:02:52 +02:00
|
|
|
m_localPlayer->setId(playerId);
|
|
|
|
m_localPlayer->setDrawSpeed(playerDrawSpeed);
|
|
|
|
m_localPlayer->setCanReportBugs(playerCanReportBugs);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseGMActions(InputMessage& msg)
|
|
|
|
{
|
|
|
|
for(uint8 i = 0; i < 28; ++i)
|
|
|
|
msg.getU8();
|
|
|
|
}
|
|
|
|
|
2011-11-11 21:26:10 +01:00
|
|
|
void ProtocolGame::parseLoginError(InputMessage& msg)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
|
|
|
std::string error = msg.getString();
|
2011-11-11 21:26:10 +01:00
|
|
|
g_dispatcher.addEvent(std::bind(&Game::processLoginError, &g_game, 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
|
|
|
{
|
2011-09-02 02:28:24 +02:00
|
|
|
msg.getU8(); // 100 is a fair death. < 100 is a unfair death.
|
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);
|
2011-08-17 06:45:55 +02:00
|
|
|
setMapDescription(msg, pos.x - 8, pos.y - 6, pos.z, 18, 14);
|
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--;
|
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
setMapDescription(msg, pos.x - 8, pos.y - 6, pos.z, 18, 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++;
|
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
setMapDescription(msg, pos.x + 9, pos.y - 6, pos.z, 1, 14);
|
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++;
|
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
setMapDescription(msg, pos.x - 8, pos.y + 7, pos.z, 18, 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--;
|
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
setMapDescription(msg, pos.x - 8, pos.y - 6, pos.z, 1, 14);
|
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)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
logDebug("PARSE UPDATE TILE!");
|
|
|
|
|
2011-08-15 16:11:24 +02:00
|
|
|
Position tilePos = parsePosition(msg);
|
|
|
|
uint16 thingId = msg.getU16(true);
|
|
|
|
if(thingId == 0xFF01) {
|
|
|
|
msg.getU16();
|
2011-08-17 06:45:55 +02:00
|
|
|
/*msg->AddByte(0);
|
|
|
|
msg->AddByte(0xFF);*/
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
setTileDescription(msg, tilePos);
|
|
|
|
msg.getU16();
|
2011-08-17 06:45:55 +02:00
|
|
|
/*msg->AddByte(0x01);
|
|
|
|
msg->AddByte(0xFF);*/
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseTileAddThing(InputMessage& msg)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
Position pos = parsePosition(msg);
|
2011-08-31 22:22:57 +02:00
|
|
|
uint8 stackPos = msg.getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
Position pos = parsePosition(msg);
|
2011-08-31 22:22:57 +02:00
|
|
|
uint8 stackPos = msg.getU8();
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
uint16 thingId = msg.getU16();
|
|
|
|
if(thingId == 0x0061 || thingId == 0x0062 || thingId == 0x0063) {
|
2011-08-17 06:45:55 +02:00
|
|
|
parseCreatureTurn(msg);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-08-17 06:45:55 +02:00
|
|
|
ThingPtr thing = internalGetItem(msg, thingId);
|
2011-08-31 22:22:57 +02:00
|
|
|
g_map.removeThing(pos, stackPos);
|
|
|
|
g_map.addThing(thing, pos, stackPos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseTileRemoveThing(InputMessage& msg)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
Position pos = parsePosition(msg);
|
2011-08-31 22:22:57 +02:00
|
|
|
uint8 stackPos = msg.getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2011-08-31 22:22:57 +02:00
|
|
|
g_map.removeThing(pos, stackPos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseCreatureMove(InputMessage& msg)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
Position oldPos = parsePosition(msg);
|
|
|
|
uint8 oldStackpos = msg.getU8();
|
|
|
|
Position newPos = parsePosition(msg);
|
|
|
|
|
2011-08-31 22:22:57 +02:00
|
|
|
ThingPtr thing = g_map.getTile(oldPos)->getThing(oldStackpos);
|
|
|
|
assert(thing);
|
|
|
|
CreaturePtr creature = thing->asCreature();
|
|
|
|
assert(creature);
|
|
|
|
creature->walk(newPos);
|
2011-11-05 21:34:49 +01:00
|
|
|
|
|
|
|
// update map tiles
|
|
|
|
g_map.removeThing(thing);
|
|
|
|
g_map.addThing(thing, newPos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseOpenContainer(InputMessage& msg)
|
|
|
|
{
|
|
|
|
msg.getU8(); // cid
|
|
|
|
msg.getU16(); // itemid
|
|
|
|
msg.getString(); // name
|
|
|
|
msg.getU8(); // capacity
|
|
|
|
msg.getU8(); // hasParent
|
|
|
|
uint8 size = msg.getU8(); // size
|
|
|
|
|
|
|
|
for(uint32 i = 0; i < size; i++)
|
|
|
|
internalGetItem(msg, 0xFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseCloseContainer(InputMessage& msg)
|
|
|
|
{
|
|
|
|
msg.getU8(); // cid
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseContainerAddItem(InputMessage& msg)
|
|
|
|
{
|
|
|
|
msg.getU8(); // cid
|
|
|
|
internalGetItem(msg, 0xFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseContainerUpdateItem(InputMessage& msg)
|
|
|
|
{
|
|
|
|
msg.getU8(); // cid
|
|
|
|
msg.getU8(); // slot
|
|
|
|
internalGetItem(msg, 0xFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseContainerRemoveItem(InputMessage& msg)
|
|
|
|
{
|
|
|
|
msg.getU8(); // cid
|
|
|
|
msg.getU8(); // slot
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseAddInventoryItem(InputMessage& msg)
|
|
|
|
{
|
2011-11-10 06:29:25 +01:00
|
|
|
uint8 slot = msg.getU8();
|
|
|
|
ItemPtr item = internalGetItem(msg, 0xFFFF);
|
2011-11-11 21:26:10 +01:00
|
|
|
g_dispatcher.addEvent(std::bind(&Game::processInventoryChange, &g_game, slot, item));
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseRemoveInventoryItem(InputMessage& msg)
|
|
|
|
{
|
2011-11-10 06:29:25 +01:00
|
|
|
uint8 slot = msg.getU8();
|
2011-11-11 21:26:10 +01:00
|
|
|
g_dispatcher.addEvent(std::bind(&Game::processInventoryChange, &g_game, slot, ItemPtr()));
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseOpenShopWindow(InputMessage& msg)
|
|
|
|
{
|
|
|
|
uint8 listCount = msg.getU8();
|
|
|
|
for(uint8 i = 0; i < listCount; ++i) {
|
|
|
|
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();
|
|
|
|
uint8 size = msg.getU8();
|
|
|
|
|
|
|
|
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
|
|
|
|
uint8 count = msg.getU8();
|
|
|
|
|
|
|
|
for(uint8 i = 0; i < count; i++)
|
|
|
|
internalGetItem(msg, 0xFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseSafeTradeClose(InputMessage&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseWorldLight(InputMessage& msg)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
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());
|
2011-08-31 22:22:57 +02:00
|
|
|
effect->setId(effectId);
|
2011-11-07 18:20:13 +01:00
|
|
|
effect->startAnimation();
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-08-31 22:22:57 +02:00
|
|
|
TilePtr tile = g_map.getTile(pos);
|
|
|
|
tile->addEffect(effect);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseAnimatedText(InputMessage& msg)
|
|
|
|
{
|
|
|
|
parsePosition(msg); // textPos
|
|
|
|
msg.getU8(); // color
|
|
|
|
msg.getString(); // text
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
MissilePtr shot = MissilePtr(new Missile());
|
|
|
|
shot->setId(shotId);
|
|
|
|
shot->setPath(fromPos, toPos);
|
|
|
|
g_map.addThing(shot, fromPos);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseCreatureSquare(InputMessage& msg)
|
|
|
|
{
|
2011-11-13 23:23:21 +01:00
|
|
|
uint32 id = msg.getU32();
|
|
|
|
uint8 color = msg.getU8();
|
|
|
|
|
|
|
|
CreaturePtr creature = g_map.getCreatureById(id);
|
|
|
|
if(creature)
|
|
|
|
creature->setSquareColor(color);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseCreatureHealth(InputMessage& msg)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
uint32 id = msg.getU32();
|
|
|
|
uint8 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)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
uint32 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)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
uint32 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)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
uint32 id = msg.getU32();
|
|
|
|
uint16 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)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
uint32 id = msg.getU32();
|
|
|
|
uint8 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)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
uint32 id = msg.getU32();
|
|
|
|
uint8 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)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
uint32 id = msg.getU32();
|
2011-08-28 18:02:26 +02:00
|
|
|
Otc::Direction direction = (Otc::Direction)msg.getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
|
|
|
CreaturePtr creature = g_map.getCreatureById(id);
|
|
|
|
if(creature)
|
|
|
|
creature->setDirection(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)
|
|
|
|
{
|
2011-11-03 20:26:53 +01:00
|
|
|
m_localPlayer->setStatistic(Otc::Health, msg.getU16());
|
|
|
|
m_localPlayer->setStatistic(Otc::MaxHealth, msg.getU16());
|
2011-11-04 00:10:12 +01:00
|
|
|
|
|
|
|
g_dispatcher.addEvent([=] {
|
|
|
|
g_lua.callGlobalField("Game", "onHealthChange", m_localPlayer->getStatistic(Otc::Health), m_localPlayer->getStatistic(Otc::MaxHealth));
|
|
|
|
});
|
|
|
|
|
2011-11-13 23:23:21 +01:00
|
|
|
m_localPlayer->setStatistic(Otc::FreeCapacity, msg.getU32() / 100.0);
|
|
|
|
|
|
|
|
g_dispatcher.addEvent([=] {
|
|
|
|
g_lua.callGlobalField("Game", "onFreeCapacityChange", m_localPlayer->getStatistic(Otc::FreeCapacity));
|
|
|
|
});
|
|
|
|
|
2011-11-03 20:26:53 +01:00
|
|
|
m_localPlayer->setStatistic(Otc::Experience, msg.getU32());
|
|
|
|
m_localPlayer->setStatistic(Otc::Level, msg.getU16());
|
|
|
|
m_localPlayer->setStatistic(Otc::LevelPercent, msg.getU8());
|
2011-11-13 23:23:21 +01:00
|
|
|
|
2011-11-03 20:26:53 +01:00
|
|
|
m_localPlayer->setStatistic(Otc::Mana, msg.getU16());
|
|
|
|
m_localPlayer->setStatistic(Otc::MaxMana, msg.getU16());
|
2011-11-04 00:10:12 +01:00
|
|
|
|
|
|
|
g_dispatcher.addEvent([=] {
|
|
|
|
g_lua.callGlobalField("Game", "onManaChange", m_localPlayer->getStatistic(Otc::Mana), m_localPlayer->getStatistic(Otc::MaxMana));
|
|
|
|
});
|
|
|
|
|
2011-11-03 20:26:53 +01:00
|
|
|
m_localPlayer->setStatistic(Otc::MagicLevel, msg.getU8());
|
|
|
|
m_localPlayer->setStatistic(Otc::MagicLevelPercent, msg.getU8());
|
2011-11-13 23:23:21 +01:00
|
|
|
|
2011-11-03 20:26:53 +01:00
|
|
|
m_localPlayer->setStatistic(Otc::Soul, msg.getU8());
|
2011-11-13 23:23:21 +01:00
|
|
|
|
|
|
|
g_dispatcher.addEvent([=] {
|
|
|
|
g_lua.callGlobalField("Game", "onSoulChange", m_localPlayer->getStatistic(Otc::Soul));
|
|
|
|
});
|
|
|
|
|
2011-11-03 20:26:53 +01:00
|
|
|
m_localPlayer->setStatistic(Otc::Stamina, msg.getU16());
|
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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_dispatcher.addEvent([=] {
|
2011-11-04 00:34:32 +01:00
|
|
|
g_lua.callGlobalField("Game", "onSkillUpdate", 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)
|
|
|
|
{
|
|
|
|
msg.getU16(); // icons
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parsePlayerCancelAttack(InputMessage& msg)
|
|
|
|
{
|
|
|
|
msg.getU32();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseCreatureSpeak(InputMessage& msg)
|
|
|
|
{
|
|
|
|
msg.getU32(); // unkSpeak
|
2011-09-01 19:47:38 +02:00
|
|
|
std::string name = msg.getString(); // name
|
2011-11-19 01:12:17 +01:00
|
|
|
int level = msg.getU16(); // level
|
|
|
|
int type = msg.getU8();
|
2011-12-07 01:49:34 +01:00
|
|
|
int channelId = 0;
|
2011-11-19 01:12:17 +01:00
|
|
|
Position creaturePos;
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
switch(type) {
|
2011-08-28 18:02:26 +02:00
|
|
|
case Otc::SpeakSay:
|
|
|
|
case Otc::SpeakWhisper:
|
|
|
|
case Otc::SpeakYell:
|
|
|
|
case Otc::SpeakMonsterSay:
|
|
|
|
case Otc::SpeakMonsterYell:
|
|
|
|
case Otc::SpeakPrivateNpcToPlayer:
|
2011-11-19 01:12:17 +01:00
|
|
|
creaturePos = parsePosition(msg); // creaturePos
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2011-08-28 18:02:26 +02:00
|
|
|
case Otc::SpeakChannelRed:
|
|
|
|
case Otc::SpeakChannelOrange:
|
|
|
|
case Otc::SpeakChannelYellow:
|
|
|
|
case Otc::SpeakChannelWhite:
|
2011-11-19 01:12:17 +01:00
|
|
|
channelId = msg.getU16(); // channelId
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
2011-08-28 18:02:26 +02:00
|
|
|
case Otc::SpeakPrivate:
|
|
|
|
case Otc::SpeakPrivatePlayerToNpc:
|
|
|
|
case Otc::SpeakBroadcast:
|
|
|
|
case Otc::SpeakPrivateRed:
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
|
|
|
default:
|
2011-12-01 23:25:32 +01:00
|
|
|
logTraceError("unknown speak type ", type);
|
2011-08-15 16:11:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-01 19:47:38 +02:00
|
|
|
std::string message = msg.getString(); // message
|
2011-11-04 00:34:32 +01:00
|
|
|
|
|
|
|
g_dispatcher.addEvent([=] {
|
2011-11-19 01:12:17 +01:00
|
|
|
g_lua.callGlobalField("Game", "onCreatureSpeak", name, level, type, message, channelId, creaturePos);
|
2011-11-04 00:34:32 +01:00
|
|
|
});
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseChannelList(InputMessage& msg)
|
|
|
|
{
|
2011-11-19 01:12:17 +01:00
|
|
|
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
|
|
|
}
|
2011-11-19 01:12:17 +01:00
|
|
|
|
|
|
|
g_dispatcher.addEvent([=] {
|
|
|
|
g_lua.callGlobalField("Game", "onChannelList", channelList);
|
|
|
|
});
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseOpenChannel(InputMessage& msg)
|
|
|
|
{
|
2011-11-19 01:12:17 +01:00
|
|
|
int channelId = msg.getU16();
|
|
|
|
std::string name = msg.getString();
|
|
|
|
|
|
|
|
g_dispatcher.addEvent([=] {
|
|
|
|
g_lua.callGlobalField("Game", "onOpenChannel", channelId, name);
|
|
|
|
});
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseOpenPrivatePlayerChat(InputMessage& msg)
|
|
|
|
{
|
|
|
|
msg.getString(); // name
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseOpenRuleViolation(InputMessage& msg)
|
|
|
|
{
|
|
|
|
msg.getU16(); // a
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseCreatePrivateChannel(InputMessage& msg)
|
|
|
|
{
|
|
|
|
msg.getU16(); // channel id
|
|
|
|
msg.getString(); // channel name
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseClosePrivateChannel(InputMessage& msg)
|
|
|
|
{
|
|
|
|
msg.getU16(); // channel id
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseTextMessage(InputMessage& msg)
|
|
|
|
{
|
2011-09-04 19:21:42 +02:00
|
|
|
uint8 type = msg.getU8();
|
2011-08-15 16:11:24 +02:00
|
|
|
std::string message = msg.getString();
|
2011-08-30 17:12:57 +02:00
|
|
|
|
2011-09-04 19:21:42 +02:00
|
|
|
g_dispatcher.addEvent(std::bind(&Game::processTextMessage, &g_game, type, message));
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseCancelWalk(InputMessage& msg)
|
|
|
|
{
|
2011-08-28 18:02:26 +02:00
|
|
|
Otc::Direction direction = (Otc::Direction)msg.getU8();
|
2011-08-30 16:37:48 +02:00
|
|
|
m_localPlayer->cancelWalk(direction);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseFloorChangeUp(InputMessage& msg)
|
|
|
|
{
|
2011-12-01 23:25:32 +01:00
|
|
|
logTraceDebug("this function has never been tested.");
|
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
|
|
|
|
|
|
|
int32 skip = 0;
|
2011-08-30 03:34:00 +02:00
|
|
|
if(pos.z == 7)
|
2011-08-15 16:11:24 +02:00
|
|
|
for(int32 i = 5; i >= 0; i--)
|
2011-08-15 23:02:52 +02:00
|
|
|
setFloorDescription(msg, pos.x - 8, pos.y - 6, i, 18, 14, 8 - i, &skip);
|
2011-08-30 03:34:00 +02:00
|
|
|
else if(pos.z > 7)
|
2011-08-15 23:02:52 +02:00
|
|
|
setFloorDescription(msg, pos.x - 8, pos.y - 6, pos.z - 2, 18, 14, 3, &skip);
|
|
|
|
|
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-12-01 23:25:32 +01:00
|
|
|
logTraceDebug("this function has never been tested.");
|
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;
|
|
|
|
if(pos.z == 8) {
|
|
|
|
int j, i;
|
|
|
|
for(i = pos.z, j = -1; i < pos.z + 3; ++i, --j)
|
|
|
|
setFloorDescription(msg, pos.x - 8, pos.y - 6, i, 18, 14, j, &skip);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
2011-08-15 23:02:52 +02:00
|
|
|
else if(pos.z > 8 && pos.z < 14)
|
|
|
|
setFloorDescription(msg, pos.x - 8, pos.y - 6, pos.z + 2, 18, 14, -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);
|
|
|
|
creature->setXPattern(2);
|
|
|
|
creature->setOutfit(outfit);
|
|
|
|
|
|
|
|
g_dispatcher.addEvent([=] {
|
|
|
|
g_lua.callGlobalField("Game", "onOpenOutfitWindow", creature, outfitList);
|
|
|
|
});
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseVipState(InputMessage& msg)
|
|
|
|
{
|
2011-10-27 00:19:41 +02:00
|
|
|
int id = msg.getU32();
|
2011-09-02 06:29:00 +02:00
|
|
|
std::string name = msg.getString();
|
|
|
|
bool online = msg.getU8() != 0;
|
|
|
|
|
|
|
|
g_dispatcher.addEvent([=] {
|
|
|
|
g_lua.callGlobalField("Game", "onAddVip", id, name, online);
|
|
|
|
});
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseVipLogin(InputMessage& msg)
|
|
|
|
{
|
2011-10-27 00:19:41 +02:00
|
|
|
int id = msg.getU32();
|
2011-09-02 06:29:00 +02:00
|
|
|
|
|
|
|
g_dispatcher.addEvent([=] {
|
|
|
|
g_lua.callGlobalField("Game", "onVipStateChange", id, true);
|
|
|
|
});
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseVipLogout(InputMessage& msg)
|
|
|
|
{
|
2011-10-27 00:19:41 +02:00
|
|
|
int id = msg.getU32();
|
2011-09-02 06:29:00 +02:00
|
|
|
|
|
|
|
g_dispatcher.addEvent([=] {
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
uint16 questsCount = msg.getU16();
|
|
|
|
for(uint16 i = 0; i < questsCount; i++) {
|
|
|
|
msg.getU16(); // quest id
|
|
|
|
msg.getString(); // quest name
|
|
|
|
msg.getU8(); // quest state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::parseQuestPartList(InputMessage& msg)
|
|
|
|
{
|
|
|
|
msg.getU16(); // quest id
|
|
|
|
uint8 missionCount = msg.getU8();
|
|
|
|
for(uint8 i = 0; i < missionCount; i++) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
if(z > 7) {
|
|
|
|
startz = z - 2;
|
|
|
|
endz = (15 < z+2) ? 15 : z+2;
|
|
|
|
zstep = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
startz = 7;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
int32 skip = *skipTiles;
|
|
|
|
|
|
|
|
for(int32 nx = 0; nx < width; nx++) {
|
|
|
|
for(int32 ny = 0; ny < height; ny++) {
|
|
|
|
if(skip == 0) {
|
|
|
|
uint16 tileOpt = msg.getU16(true);
|
|
|
|
if(tileOpt >= 0xFF00)
|
|
|
|
skip = (msg.getU16() & 0xFF);
|
|
|
|
else {
|
|
|
|
Position pos(x + nx + offset, y + ny + offset, z);
|
|
|
|
setTileDescription(msg, pos);
|
|
|
|
skip = (msg.getU16() & 0xFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
skip--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*skipTiles = skip;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolGame::setTileDescription(InputMessage& msg, Position position)
|
|
|
|
{
|
2011-08-17 06:45:55 +02:00
|
|
|
g_map.cleanTile(position);
|
|
|
|
|
2011-08-31 22:22:57 +02:00
|
|
|
int stackPos = 0;
|
2011-12-01 23:25:32 +01:00
|
|
|
while(true) {
|
2011-08-15 16:11:24 +02:00
|
|
|
uint16 inspectTileId = msg.getU16(true);
|
|
|
|
if(inspectTileId >= 0xFF00)
|
|
|
|
return;
|
|
|
|
else {
|
2011-08-31 22:22:57 +02:00
|
|
|
if(stackPos >= 10)
|
2011-12-01 23:25:32 +01:00
|
|
|
logTraceWarning("too many things");
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
ThingPtr thing = internalGetThing(msg);
|
2011-08-31 23:41:04 +02:00
|
|
|
g_map.addThing(thing, position, 255);
|
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;
|
|
|
|
|
2011-11-13 09:46:19 +01:00
|
|
|
uint16 type = msg.getU16();
|
|
|
|
if(type != 0) {
|
|
|
|
uint8 head = msg.getU8();
|
|
|
|
uint8 body = msg.getU8();
|
|
|
|
uint8 legs = msg.getU8();
|
|
|
|
uint8 feet = msg.getU8();
|
|
|
|
uint8 addons = msg.getU8();
|
|
|
|
|
|
|
|
outfit.setType(type);
|
|
|
|
outfit.setHead(head);
|
|
|
|
outfit.setBody(body);
|
|
|
|
outfit.setLegs(legs);
|
|
|
|
outfit.setFeet(feet);
|
|
|
|
outfit.setAddons(addons);
|
2011-08-15 23:02:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-11-13 09:46:19 +01:00
|
|
|
uint16 type = msg.getU16();
|
|
|
|
outfit.setType(type);
|
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;
|
|
|
|
|
|
|
|
uint16 thingId = msg.getU16();
|
|
|
|
if(thingId == 0x0061 || thingId == 0x0062) { // add new creature
|
|
|
|
CreaturePtr creature = CreaturePtr(new Creature);
|
|
|
|
|
|
|
|
if(thingId == 0x0062) { //creature is known
|
2011-08-17 06:45:55 +02:00
|
|
|
uint32 id = msg.getU32();
|
|
|
|
|
|
|
|
CreaturePtr knownCreature = g_map.getCreatureById(id);
|
|
|
|
if(knownCreature)
|
|
|
|
creature = knownCreature;
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
else if(thingId == 0x0061) { //creature is not known
|
2011-08-26 23:34:16 +02:00
|
|
|
uint32 removeId = msg.getU32();
|
2011-08-17 06:45:55 +02:00
|
|
|
uint32 id = msg.getU32();
|
|
|
|
std::string name = msg.getString();
|
|
|
|
|
2011-08-26 23:34:16 +02:00
|
|
|
g_map.removeCreatureById(removeId);
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
if(m_localPlayer->getId() == id)
|
|
|
|
creature = m_localPlayer->asCreature();
|
2011-08-17 06:45:55 +02:00
|
|
|
|
|
|
|
creature->setId(id);
|
|
|
|
creature->setName(name);
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2011-08-17 06:45:55 +02:00
|
|
|
uint8 healthPercent = msg.getU8();
|
2011-08-28 18:02:26 +02:00
|
|
|
Otc::Direction direction = (Otc::Direction)msg.getU8();
|
2011-08-17 06:45:55 +02:00
|
|
|
Outfit outfit = internalGetOutfit(msg);
|
|
|
|
|
|
|
|
Light light;
|
|
|
|
light.intensity = msg.getU8();
|
|
|
|
light.color = msg.getU8();
|
|
|
|
|
|
|
|
uint16 speed = msg.getU16();
|
|
|
|
uint8 skull = msg.getU8();
|
|
|
|
uint8 shield = msg.getU8();
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-08-17 06:45:55 +02:00
|
|
|
uint8 emblem = 0;
|
2011-08-15 16:11:24 +02:00
|
|
|
if(thingId == 0x0061) // emblem is sent only in packet type 0x61
|
2011-08-17 06:45:55 +02:00
|
|
|
emblem = msg.getU8();
|
|
|
|
|
|
|
|
bool impassable = (msg.getU8() == 0); // impassable
|
|
|
|
|
|
|
|
creature->setHealthPercent(healthPercent);
|
|
|
|
creature->setDirection(direction);
|
|
|
|
creature->setOutfit(outfit);
|
|
|
|
creature->setLight(light);
|
|
|
|
creature->setSpeed(speed);
|
|
|
|
creature->setSkull(skull);
|
|
|
|
creature->setShield(shield);
|
|
|
|
creature->setEmblem(emblem);
|
|
|
|
creature->setImpassable(impassable);
|
2011-08-30 16:37:48 +02:00
|
|
|
creature->cancelWalk(direction);
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
thing = creature;
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
// login event is generated the first time that local player gets known
|
|
|
|
if(!g_game.isOnline() && creature == m_localPlayer) {
|
|
|
|
// this event must be scheduled because the entire map description is not known yet
|
|
|
|
g_dispatcher.addEvent(std::bind(&Game::processLogin, &g_game, m_localPlayer));
|
|
|
|
}
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
else if(thingId == 0x0063) { // creature turn
|
|
|
|
parseCreatureTurn(msg);
|
|
|
|
}
|
|
|
|
else // item
|
|
|
|
thing = internalGetItem(msg, thingId);
|
|
|
|
|
|
|
|
return thing;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, uint16 id)
|
|
|
|
{
|
|
|
|
ItemPtr item = ItemPtr(new Item());
|
|
|
|
|
|
|
|
if(id == 0xFFFF)
|
|
|
|
id = msg.getU16();
|
|
|
|
item->setId(id);
|
|
|
|
|
2011-12-02 03:29:05 +01:00
|
|
|
ThingType *itemType = item->getType();
|
|
|
|
if(itemType->properties[ThingType::IsStackable] || itemType->properties[ThingType::IsFluidContainer] || itemType->properties[ThingType::IsFluid])
|
2011-11-08 02:44:30 +01:00
|
|
|
item->setData(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);
|
|
|
|
}
|