2011-08-28 15:17:58 +02:00
|
|
|
/*
|
2015-03-04 15:36:51 +01:00
|
|
|
* Copyright (c) 2010-2015 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 "game.h"
|
2011-08-15 23:02:52 +02:00
|
|
|
#include "localplayer.h"
|
2011-12-30 19:14:50 +01:00
|
|
|
#include "map.h"
|
|
|
|
#include "tile.h"
|
2012-01-17 23:48:31 +01:00
|
|
|
#include "creature.h"
|
2012-04-03 01:09:47 +02:00
|
|
|
#include "container.h"
|
2012-01-17 23:48:31 +01:00
|
|
|
#include "statictext.h"
|
2011-11-10 06:29:25 +01:00
|
|
|
#include <framework/core/eventdispatcher.h>
|
2012-01-05 13:48:10 +01:00
|
|
|
#include <framework/ui/uimanager.h>
|
2012-07-14 03:10:24 +02:00
|
|
|
#include <framework/core/application.h>
|
|
|
|
#include "luavaluecasts.h"
|
|
|
|
#include "protocolgame.h"
|
2012-07-26 11:12:20 +02:00
|
|
|
#include "protocolcodes.h"
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
Game g_game;
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
Game::Game()
|
2011-08-16 02:30:31 +02:00
|
|
|
{
|
2012-12-28 12:05:45 +01:00
|
|
|
m_protocolVersion = 0;
|
2013-01-09 20:29:58 +01:00
|
|
|
m_clientCustomOs = -1;
|
2012-12-28 14:34:36 +01:00
|
|
|
m_clientVersion = 0;
|
2013-01-08 19:21:54 +01:00
|
|
|
m_online = false;
|
|
|
|
m_denyBotCall = false;
|
|
|
|
m_dead = false;
|
|
|
|
m_serverBeat = 50;
|
|
|
|
m_seq = 0;
|
|
|
|
m_ping = -1;
|
2013-02-24 21:26:19 +01:00
|
|
|
m_pingDelay = 1000;
|
2013-01-08 19:21:54 +01:00
|
|
|
m_canReportBugs = false;
|
|
|
|
m_fightMode = Otc::FightBalanced;
|
|
|
|
m_chaseMode = Otc::DontChase;
|
2013-11-19 00:50:00 +01:00
|
|
|
m_pvpMode = Otc::WhiteDove;
|
2013-01-08 19:21:54 +01:00
|
|
|
m_safeFight = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::init()
|
|
|
|
{
|
|
|
|
resetGameStates();
|
2011-08-16 02:30:31 +02:00
|
|
|
}
|
|
|
|
|
2012-07-30 10:51:03 +02:00
|
|
|
void Game::terminate()
|
|
|
|
{
|
|
|
|
resetGameStates();
|
|
|
|
m_protocolGame = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::resetGameStates()
|
2011-08-30 01:20:30 +02:00
|
|
|
{
|
2012-07-26 08:10:28 +02:00
|
|
|
m_online = false;
|
2012-05-16 22:09:37 +02:00
|
|
|
m_denyBotCall = false;
|
2012-02-08 22:23:15 +01:00
|
|
|
m_dead = false;
|
|
|
|
m_serverBeat = 50;
|
2012-07-26 08:10:28 +02:00
|
|
|
m_seq = 0;
|
2012-08-25 21:11:54 +02:00
|
|
|
m_ping = -1;
|
2012-05-01 00:24:50 +02:00
|
|
|
m_canReportBugs = false;
|
2012-02-08 22:23:15 +01:00
|
|
|
m_fightMode = Otc::FightBalanced;
|
|
|
|
m_chaseMode = Otc::DontChase;
|
2013-11-19 00:50:00 +01:00
|
|
|
m_pvpMode = Otc::WhiteDove;
|
2012-02-08 22:23:15 +01:00
|
|
|
m_safeFight = true;
|
|
|
|
m_followingCreature = nullptr;
|
|
|
|
m_attackingCreature = nullptr;
|
2012-05-11 21:25:29 +02:00
|
|
|
m_localPlayer = nullptr;
|
2013-02-24 21:26:19 +01:00
|
|
|
m_pingSent = 0;
|
|
|
|
m_pingReceived = 0;
|
2015-01-18 15:14:07 +01:00
|
|
|
m_unjustifiedPoints = UnjustifiedPoints();
|
2012-04-03 16:15:11 +02:00
|
|
|
|
2012-04-05 22:51:06 +02:00
|
|
|
for(auto& it : m_containers) {
|
|
|
|
const ContainerPtr& container = it.second;
|
|
|
|
if(container)
|
2012-06-05 18:59:32 +02:00
|
|
|
container->onClose();
|
2012-04-05 22:51:06 +02:00
|
|
|
}
|
2012-08-25 21:11:54 +02:00
|
|
|
|
|
|
|
if(m_pingEvent) {
|
|
|
|
m_pingEvent->cancel();
|
|
|
|
m_pingEvent = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-12-30 07:14:49 +01:00
|
|
|
if(m_walkEvent) {
|
|
|
|
m_walkEvent->cancel();
|
|
|
|
m_walkEvent = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-03-14 00:55:20 +01:00
|
|
|
if(m_checkConnectionEvent) {
|
|
|
|
m_checkConnectionEvent->cancel();
|
|
|
|
m_checkConnectionEvent = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-03-31 15:43:01 +02:00
|
|
|
m_containers.clear();
|
2012-04-27 08:30:54 +02:00
|
|
|
m_vips.clear();
|
2012-05-01 00:24:50 +02:00
|
|
|
m_gmActions.clear();
|
2013-01-09 20:29:58 +01:00
|
|
|
g_map.resetAwareRange();
|
2011-08-30 01:20:30 +02:00
|
|
|
}
|
|
|
|
|
2012-07-10 00:45:34 +02:00
|
|
|
void Game::processConnectionError(const boost::system::error_code& ec)
|
2011-08-29 20:38:01 +02:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
// connection errors only have meaning if we still have a protocol
|
|
|
|
if(m_protocolGame) {
|
|
|
|
// eof = end of file, a clean disconnect
|
2012-07-10 00:45:34 +02:00
|
|
|
if(ec != asio::error::eof)
|
|
|
|
g_lua.callGlobalField("g_game", "onConnectionError", ec.message(), ec.value());
|
2011-08-30 01:20:30 +02:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
processDisconnect();
|
|
|
|
}
|
2012-02-08 03:11:57 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::processDisconnect()
|
2012-02-08 03:11:57 +01:00
|
|
|
{
|
2012-05-11 21:25:29 +02:00
|
|
|
if(isOnline())
|
2012-02-08 22:23:15 +01:00
|
|
|
processGameEnd();
|
|
|
|
|
|
|
|
if(m_protocolGame) {
|
|
|
|
m_protocolGame->disconnect();
|
|
|
|
m_protocolGame = nullptr;
|
|
|
|
}
|
2011-08-29 20:38:01 +02:00
|
|
|
}
|
|
|
|
|
2013-01-09 20:29:58 +01:00
|
|
|
void Game::processUpdateNeeded(const std::string& signature)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onUpdateNeeded", signature);
|
|
|
|
}
|
|
|
|
|
2011-08-30 01:20:30 +02:00
|
|
|
void Game::processLoginError(const std::string& error)
|
2011-08-16 02:30:31 +02:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onLoginError", error);
|
2011-08-29 20:38:01 +02:00
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::processLoginAdvice(const std::string& message)
|
2011-08-29 20:38:01 +02:00
|
|
|
{
|
2012-02-08 23:58:27 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onLoginAdvice", message);
|
2012-02-08 22:23:15 +01:00
|
|
|
}
|
2011-08-29 20:38:01 +02:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::processLoginWait(const std::string& message, int time)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onLoginWait", message, time);
|
2011-08-16 02:30:31 +02:00
|
|
|
}
|
|
|
|
|
2015-01-18 15:14:07 +01:00
|
|
|
void Game::processLoginToken(bool unknown)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onLoginToken", unknown);
|
|
|
|
}
|
|
|
|
|
2013-01-17 21:24:41 +01:00
|
|
|
void Game::processLogin()
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onLogin");
|
|
|
|
}
|
|
|
|
|
2012-12-28 12:05:45 +01:00
|
|
|
void Game::processPendingGame()
|
|
|
|
{
|
|
|
|
m_localPlayer->setPendingGame(true);
|
|
|
|
g_lua.callGlobalField("g_game", "onPendingGame");
|
2013-01-17 21:24:41 +01:00
|
|
|
m_protocolGame->sendEnterGame();
|
2012-12-28 12:05:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processEnterGame()
|
|
|
|
{
|
|
|
|
m_localPlayer->setPendingGame(false);
|
|
|
|
g_lua.callGlobalField("g_game", "onEnterGame");
|
|
|
|
}
|
|
|
|
|
2012-07-26 08:10:28 +02:00
|
|
|
void Game::processGameStart()
|
2011-08-15 23:02:52 +02:00
|
|
|
{
|
2012-07-26 08:10:28 +02:00
|
|
|
m_online = true;
|
2012-01-09 06:23:39 +01:00
|
|
|
|
2012-02-08 00:06:52 +01:00
|
|
|
// synchronize fight modes with the server
|
2013-11-19 00:50:00 +01:00
|
|
|
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
|
2012-02-08 00:06:52 +01:00
|
|
|
|
2012-05-16 22:09:37 +02:00
|
|
|
// NOTE: the entire map description and local player information is not known yet (bot call is allowed here)
|
|
|
|
enableBotCall();
|
2012-02-08 22:23:15 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onGameStart");
|
2012-05-16 22:09:37 +02:00
|
|
|
disableBotCall();
|
2012-08-25 21:11:54 +02:00
|
|
|
|
2013-01-09 20:29:58 +01:00
|
|
|
if(g_game.getFeature(Otc::GameClientPing) || g_game.getFeature(Otc::GameExtendedClientPing)) {
|
2013-02-24 21:26:19 +01:00
|
|
|
m_pingEvent = g_dispatcher.scheduleEvent([this] {
|
|
|
|
g_game.ping();
|
|
|
|
}, m_pingDelay);
|
2012-08-25 21:11:54 +02:00
|
|
|
}
|
2013-03-14 00:55:20 +01:00
|
|
|
|
|
|
|
m_checkConnectionEvent = g_dispatcher.cycleEvent([this] {
|
|
|
|
if(!g_game.isConnectionOk() && !m_connectionFailWarned) {
|
|
|
|
g_lua.callGlobalField("g_game", "onConnectionFailing", true);
|
|
|
|
m_connectionFailWarned = true;
|
|
|
|
} else if(g_game.isConnectionOk() && m_connectionFailWarned) {
|
|
|
|
g_lua.callGlobalField("g_game", "onConnectionFailing", false);
|
|
|
|
m_connectionFailWarned = false;
|
|
|
|
}
|
|
|
|
}, 1000);
|
2012-02-08 22:23:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processGameEnd()
|
|
|
|
{
|
2013-01-25 21:28:44 +01:00
|
|
|
m_online = false;
|
2012-02-08 22:23:15 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onGameEnd");
|
|
|
|
|
2013-03-14 00:55:20 +01:00
|
|
|
if(m_connectionFailWarned) {
|
|
|
|
g_lua.callGlobalField("g_game", "onConnectionFailing", false);
|
|
|
|
m_connectionFailWarned = false;
|
|
|
|
}
|
|
|
|
|
2012-02-08 23:58:27 +01:00
|
|
|
// reset game state
|
2012-02-08 22:23:15 +01:00
|
|
|
resetGameStates();
|
2012-03-19 18:54:47 +01:00
|
|
|
|
2012-06-04 02:28:19 +02:00
|
|
|
m_worldName = "";
|
|
|
|
m_characterName = "";
|
|
|
|
|
2012-03-19 18:54:47 +01:00
|
|
|
// clean map creatures
|
|
|
|
g_map.cleanDynamicThings();
|
2012-02-08 00:54:33 +01:00
|
|
|
}
|
|
|
|
|
2015-03-07 06:09:00 +01:00
|
|
|
void Game::processDeath(int deathType, int penality)
|
2012-01-07 06:10:02 +01:00
|
|
|
{
|
|
|
|
m_dead = true;
|
2012-01-25 15:56:17 +01:00
|
|
|
m_localPlayer->stopWalk();
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2015-03-07 06:09:00 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onDeath", deathType, penality);
|
2012-05-01 00:24:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processGMActions(const std::vector<uint8>& actions)
|
|
|
|
{
|
|
|
|
m_gmActions = actions;
|
|
|
|
g_lua.callGlobalField("g_game", "onGMActions", actions);
|
|
|
|
}
|
|
|
|
|
2013-10-20 22:31:20 +02:00
|
|
|
void Game::processPlayerHelpers(int helpers)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onPlayerHelpersUpdate", helpers);
|
|
|
|
}
|
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
void Game::processPlayerModes(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeMode, Otc::PVPModes pvpMode)
|
2013-11-11 02:31:59 +01:00
|
|
|
{
|
|
|
|
m_fightMode = fightMode;
|
|
|
|
m_chaseMode = chaseMode;
|
|
|
|
m_safeFight = safeMode;
|
2013-11-19 00:50:00 +01:00
|
|
|
m_pvpMode = pvpMode;
|
2013-11-11 02:31:59 +01:00
|
|
|
|
|
|
|
g_lua.callGlobalField("g_game", "onFightModeChange", fightMode);
|
|
|
|
g_lua.callGlobalField("g_game", "onChaseModeChange", chaseMode);
|
|
|
|
g_lua.callGlobalField("g_game", "onSafeFightChange", safeMode);
|
2013-11-19 00:50:00 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onPVPModeChange", pvpMode);
|
2013-11-11 02:31:59 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::processPing()
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onPing");
|
2013-01-08 19:21:54 +01:00
|
|
|
enableBotCall();
|
|
|
|
m_protocolGame->sendPingBack();
|
|
|
|
disableBotCall();
|
2012-01-07 06:10:02 +01:00
|
|
|
}
|
|
|
|
|
2013-02-24 21:26:19 +01:00
|
|
|
void Game::processPingBack()
|
2012-07-30 12:59:08 +02:00
|
|
|
{
|
2013-02-24 21:26:19 +01:00
|
|
|
m_pingReceived++;
|
|
|
|
|
|
|
|
if(m_pingReceived == m_pingSent)
|
|
|
|
m_ping = m_pingTimer.elapsed_millis();
|
|
|
|
else
|
|
|
|
g_logger.error("got an invalid ping from server");
|
|
|
|
|
|
|
|
g_lua.callGlobalField("g_game", "onPingBack", m_ping);
|
|
|
|
|
|
|
|
m_pingEvent = g_dispatcher.scheduleEvent([this] {
|
|
|
|
g_game.ping();
|
|
|
|
}, m_pingDelay);
|
2012-07-30 12:59:08 +02:00
|
|
|
}
|
|
|
|
|
2012-07-26 11:12:20 +02:00
|
|
|
void Game::processTextMessage(Otc::MessageMode mode, const std::string& text)
|
2012-01-25 15:56:17 +01:00
|
|
|
{
|
2012-07-26 11:12:20 +02:00
|
|
|
g_lua.callGlobalField("g_game", "onTextMessage", mode, text);
|
2012-01-25 15:56:17 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 11:12:20 +02:00
|
|
|
void Game::processTalk(const std::string& name, int level, Otc::MessageMode mode, const std::string& text, int channelId, const Position& pos)
|
2012-01-08 19:29:41 +01:00
|
|
|
{
|
2012-07-26 11:12:20 +02:00
|
|
|
g_lua.callGlobalField("g_game", "onTalk", name, level, mode, text, channelId, pos);
|
2012-02-08 22:23:15 +01:00
|
|
|
}
|
|
|
|
|
2013-10-21 00:21:20 +02:00
|
|
|
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)
|
2012-02-08 22:23:15 +01:00
|
|
|
{
|
2012-04-03 01:09:47 +02:00
|
|
|
ContainerPtr previousContainer = getContainer(containerId);
|
2013-10-21 00:21:20 +02:00
|
|
|
ContainerPtr container = ContainerPtr(new Container(containerId, capacity, name, containerItem, hasParent, isUnlocked, hasPages, containerSize, firstIndex));
|
2012-04-03 01:09:47 +02:00
|
|
|
m_containers[containerId] = container;
|
2012-06-05 18:59:32 +02:00
|
|
|
container->onAddItems(items);
|
2012-04-03 01:09:47 +02:00
|
|
|
|
2012-08-18 07:04:01 +02:00
|
|
|
// we might want to close a container here
|
|
|
|
enableBotCall();
|
2012-06-05 18:59:32 +02:00
|
|
|
container->onOpen(previousContainer);
|
2012-08-18 07:04:01 +02:00
|
|
|
disableBotCall();
|
|
|
|
|
2012-04-03 01:09:47 +02:00
|
|
|
if(previousContainer)
|
2012-06-05 18:59:32 +02:00
|
|
|
previousContainer->onClose();
|
2012-01-08 19:29:41 +01:00
|
|
|
}
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
void Game::processCloseContainer(int containerId)
|
|
|
|
{
|
2012-04-03 01:09:47 +02:00
|
|
|
ContainerPtr container = getContainer(containerId);
|
|
|
|
if(!container) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-05 22:51:06 +02:00
|
|
|
m_containers[containerId] = nullptr;
|
2012-06-05 18:59:32 +02:00
|
|
|
container->onClose();
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
2013-10-21 00:21:20 +02:00
|
|
|
void Game::processContainerAddItem(int containerId, const ItemPtr& item, int slot)
|
2012-01-12 20:25:58 +01:00
|
|
|
{
|
2012-04-03 01:09:47 +02:00
|
|
|
ContainerPtr container = getContainer(containerId);
|
|
|
|
if(!container) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-21 00:21:20 +02:00
|
|
|
container->onAddItem(item, slot);
|
2012-01-12 20:25:58 +01:00
|
|
|
}
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
void Game::processContainerUpdateItem(int containerId, int slot, const ItemPtr& item)
|
|
|
|
{
|
2012-04-03 01:09:47 +02:00
|
|
|
ContainerPtr container = getContainer(containerId);
|
|
|
|
if(!container) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-05 18:59:32 +02:00
|
|
|
container->onUpdateItem(slot, item);
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
2014-07-15 23:19:08 +02:00
|
|
|
void Game::processContainerRemoveItem(int containerId, int slot, const ItemPtr& lastItem)
|
2012-02-09 04:45:19 +01:00
|
|
|
{
|
2012-04-03 01:09:47 +02:00
|
|
|
ContainerPtr container = getContainer(containerId);
|
|
|
|
if(!container) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-15 23:19:08 +02:00
|
|
|
container->onRemoveItem(slot, lastItem);
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
2011-11-10 06:29:25 +01:00
|
|
|
void Game::processInventoryChange(int slot, const ItemPtr& item)
|
|
|
|
{
|
2012-01-03 21:41:00 +01:00
|
|
|
if(item)
|
2012-01-30 01:00:12 +01:00
|
|
|
item->setPosition(Position(65535, slot, 0));
|
2012-01-03 21:41:00 +01:00
|
|
|
|
2012-07-18 08:04:57 +02:00
|
|
|
m_localPlayer->setInventoryItem((Otc::InventorySlot)slot, item);
|
2011-11-10 06:29:25 +01:00
|
|
|
}
|
|
|
|
|
2012-07-15 13:49:28 +02:00
|
|
|
void Game::processChannelList(const std::vector<std::tuple<int, std::string> >& channelList)
|
2012-02-09 04:45:19 +01:00
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onChannelList", channelList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processOpenChannel(int channelId, const std::string& name)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onOpenChannel", channelId, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processOpenPrivateChannel(const std::string& name)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onOpenPrivateChannel", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processOpenOwnPrivateChannel(int channelId, const std::string& name)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onOpenOwnPrivateChannel", channelId, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processCloseChannel(int channelId)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onCloseChannel", channelId);
|
|
|
|
}
|
|
|
|
|
2012-05-01 00:24:50 +02:00
|
|
|
void Game::processRuleViolationChannel(int channelId)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onRuleViolationChannel", channelId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processRuleViolationRemove(const std::string& name)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onRuleViolationRemove", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processRuleViolationCancel(const std::string& name)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onRuleViolationCancel", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processRuleViolationLock()
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onRuleViolationLock");
|
|
|
|
}
|
|
|
|
|
2014-01-14 23:15:01 +01:00
|
|
|
void Game::processVipAdd(uint id, const std::string& name, uint status, const std::string& description, int iconId, bool notifyLogin)
|
2012-02-09 04:45:19 +01:00
|
|
|
{
|
2014-01-14 23:15:01 +01:00
|
|
|
m_vips[id] = Vip(name, status, description, iconId, notifyLogin);
|
|
|
|
g_lua.callGlobalField("g_game", "onAddVip", id, name, status, description, iconId, notifyLogin);
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
2012-12-26 14:56:06 +01:00
|
|
|
void Game::processVipStateChange(uint id, uint status)
|
2012-02-09 04:45:19 +01:00
|
|
|
{
|
2012-12-26 14:56:06 +01:00
|
|
|
std::get<1>(m_vips[id]) = status;
|
|
|
|
g_lua.callGlobalField("g_game", "onVipStateChange", id, status);
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
2012-05-01 00:24:50 +02:00
|
|
|
void Game::processTutorialHint(int id)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onTutorialHint", id);
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:36:27 +01:00
|
|
|
void Game::processAddAutomapFlag(const Position& pos, int icon, const std::string& message)
|
2012-05-01 00:24:50 +02:00
|
|
|
{
|
2013-01-29 21:36:27 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onAddAutomapFlag", pos, icon, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processRemoveAutomapFlag(const Position& pos, int icon, const std::string& message)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onRemoveAutomapFlag", pos, icon, message);
|
2012-05-01 00:24:50 +02:00
|
|
|
}
|
|
|
|
|
2012-07-15 13:49:28 +02:00
|
|
|
void Game::processOpenOutfitWindow(const Outfit& currentOufit, const std::vector<std::tuple<int, std::string, int> >& outfitList,
|
|
|
|
const std::vector<std::tuple<int, std::string> >& mountList)
|
2012-02-09 04:45:19 +01:00
|
|
|
{
|
2012-07-15 13:49:28 +02:00
|
|
|
// create virtual creature outfit
|
|
|
|
CreaturePtr virtualOutfitCreature = CreaturePtr(new Creature);
|
|
|
|
virtualOutfitCreature->setDirection(Otc::South);
|
2012-07-26 13:18:49 +02:00
|
|
|
|
|
|
|
Outfit outfit = currentOufit;
|
|
|
|
outfit.setMount(0);
|
|
|
|
virtualOutfitCreature->setOutfit(outfit);
|
2012-02-09 04:45:19 +01:00
|
|
|
|
2012-07-15 13:49:28 +02:00
|
|
|
// creature virtual mount outfit
|
2012-07-16 16:39:08 +02:00
|
|
|
CreaturePtr virtualMountCreature = nullptr;
|
|
|
|
if(getFeature(Otc::GamePlayerMounts))
|
|
|
|
{
|
|
|
|
virtualMountCreature = CreaturePtr(new Creature);
|
|
|
|
virtualMountCreature->setDirection(Otc::South);
|
2012-08-22 16:21:02 +02:00
|
|
|
|
|
|
|
Outfit mountOutfit;
|
|
|
|
mountOutfit.setId(0);
|
|
|
|
|
|
|
|
int mount = currentOufit.getMount();
|
|
|
|
if(mount > 0)
|
|
|
|
mountOutfit.setId(mount);
|
|
|
|
|
|
|
|
virtualMountCreature->setOutfit(mountOutfit);
|
2012-07-16 16:39:08 +02:00
|
|
|
}
|
2012-07-15 13:49:28 +02:00
|
|
|
|
|
|
|
g_lua.callGlobalField("g_game", "onOpenOutfitWindow", virtualOutfitCreature, outfitList, virtualMountCreature, mountList);
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
2012-07-15 13:49:28 +02:00
|
|
|
void Game::processOpenNpcTrade(const std::vector<std::tuple<ItemPtr, std::string, int, int, int> >& items)
|
2012-02-09 04:45:19 +01:00
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onOpenNpcTrade", items);
|
|
|
|
}
|
|
|
|
|
2012-07-15 13:49:28 +02:00
|
|
|
void Game::processPlayerGoods(int money, const std::vector<std::tuple<ItemPtr, int> >& goods)
|
2012-02-09 04:45:19 +01:00
|
|
|
{
|
2012-04-04 22:18:24 +02:00
|
|
|
g_lua.callGlobalField("g_game", "onPlayerGoods", money, goods);
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processCloseNpcTrade()
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onCloseNpcTrade");
|
|
|
|
}
|
|
|
|
|
2012-05-01 04:59:17 +02:00
|
|
|
void Game::processOwnTrade(const std::string& name, const std::vector<ItemPtr>& items)
|
2012-02-09 04:45:19 +01:00
|
|
|
{
|
2012-05-01 04:59:17 +02:00
|
|
|
g_lua.callGlobalField("g_game", "onOwnTrade", name, items);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processCounterTrade(const std::string& name, const std::vector<ItemPtr>& items)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onCounterTrade", name, items);
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processCloseTrade()
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onCloseTrade");
|
|
|
|
}
|
|
|
|
|
2013-12-25 15:10:59 +01:00
|
|
|
void Game::processEditText(uint id, int itemId, int maxLength, const std::string& text, const std::string& writer, const std::string& date)
|
2012-02-09 04:45:19 +01:00
|
|
|
{
|
2013-12-25 15:10:59 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onEditText", id, itemId, maxLength, text, writer, date);
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
2012-05-01 02:53:02 +02:00
|
|
|
void Game::processEditList(uint id, int doorId, const std::string& text)
|
2012-02-09 04:45:19 +01:00
|
|
|
{
|
2012-05-01 02:53:02 +02:00
|
|
|
g_lua.callGlobalField("g_game", "onEditList", id, doorId, text);
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
2012-07-15 13:49:28 +02:00
|
|
|
void Game::processQuestLog(const std::vector<std::tuple<int, std::string, bool> >& questList)
|
2012-02-09 04:45:19 +01:00
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onQuestLog", questList);
|
|
|
|
}
|
|
|
|
|
2012-07-15 13:49:28 +02:00
|
|
|
void Game::processQuestLine(int questId, const std::vector<std::tuple<std::string, std::string> >& questMissions)
|
2012-02-09 04:45:19 +01:00
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onQuestLine", questId, questMissions);
|
|
|
|
}
|
|
|
|
|
2013-11-18 18:58:15 +01:00
|
|
|
void Game::processModalDialog(uint32 id, std::string title, std::string message, std::vector<std::tuple<int, std::string> > buttonList, int enterButton, int escapeButton, std::vector<std::tuple<int, std::string> > choiceList, bool priority)
|
2012-11-27 14:48:48 +01:00
|
|
|
{
|
2013-11-18 18:58:15 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onModalDialog", id, title, message, buttonList, enterButton, escapeButton, choiceList, priority);
|
2012-11-27 14:48:48 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 08:10:28 +02:00
|
|
|
void Game::processAttackCancel(uint seq)
|
2012-01-07 06:10:02 +01:00
|
|
|
{
|
2012-07-26 08:10:28 +02:00
|
|
|
if(isAttacking() && (seq == 0 || m_seq == seq))
|
2012-08-17 19:43:12 +02:00
|
|
|
cancelAttack();
|
2012-01-07 06:10:02 +01:00
|
|
|
}
|
|
|
|
|
2012-01-09 06:23:39 +01:00
|
|
|
void Game::processWalkCancel(Otc::Direction direction)
|
|
|
|
{
|
2012-06-03 21:28:17 +02:00
|
|
|
m_localPlayer->cancelWalk(direction);
|
2012-01-09 06:23:39 +01:00
|
|
|
}
|
|
|
|
|
2015-01-27 23:44:37 +01:00
|
|
|
void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldName, const std::string& worldHost, int worldPort, const std::string& characterName, const std::string& authenticatorToken, const std::string& sessionKey)
|
2012-02-08 22:23:15 +01:00
|
|
|
{
|
2012-07-18 01:49:21 +02:00
|
|
|
if(m_protocolGame || isOnline())
|
|
|
|
stdext::throw_exception("Unable to login into a world while already online or logging.");
|
|
|
|
|
2012-12-28 12:05:45 +01:00
|
|
|
if(m_protocolVersion == 0)
|
2012-07-18 01:49:21 +02:00
|
|
|
stdext::throw_exception("Must set a valid game protocol version before logging.");
|
2012-03-29 21:25:04 +02:00
|
|
|
|
2012-07-26 08:10:28 +02:00
|
|
|
// reset the new game state
|
|
|
|
resetGameStates();
|
|
|
|
|
|
|
|
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
|
2012-07-31 05:53:15 +02:00
|
|
|
m_localPlayer->setName(characterName);
|
2012-07-26 08:10:28 +02:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
m_protocolGame = ProtocolGamePtr(new ProtocolGame);
|
2015-01-27 23:44:37 +01:00
|
|
|
m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName, authenticatorToken, sessionKey);
|
2012-06-04 02:28:19 +02:00
|
|
|
m_characterName = characterName;
|
2012-03-29 21:25:04 +02:00
|
|
|
m_worldName = worldName;
|
2012-02-08 22:23:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::cancelLogin()
|
|
|
|
{
|
|
|
|
// send logout even if the game has not started yet, to make sure that the player doesn't stay logged there
|
|
|
|
if(m_protocolGame)
|
|
|
|
m_protocolGame->sendLogout();
|
|
|
|
|
|
|
|
processDisconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::forceLogout()
|
|
|
|
{
|
|
|
|
if(!isOnline())
|
|
|
|
return;
|
|
|
|
|
2012-03-19 18:54:47 +01:00
|
|
|
m_protocolGame->sendLogout();
|
2012-02-08 22:23:15 +01:00
|
|
|
processDisconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::safeLogout()
|
|
|
|
{
|
|
|
|
if(!isOnline())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_protocolGame->sendLogout();
|
|
|
|
}
|
|
|
|
|
2014-11-03 03:12:14 +01:00
|
|
|
bool Game::walk(Otc::Direction direction, bool dash)
|
2011-08-17 06:45:55 +02:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-08-29 17:41:04 +02:00
|
|
|
return false;
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-06-03 21:28:17 +02:00
|
|
|
// must cancel follow before any new walk
|
2012-02-08 22:23:15 +01:00
|
|
|
if(isFollowing())
|
2012-01-15 22:19:52 +01:00
|
|
|
cancelFollow();
|
|
|
|
|
2013-01-31 03:50:20 +01:00
|
|
|
// must cancel auto walking, and wait next try
|
|
|
|
if(m_localPlayer->isAutoWalking() || m_localPlayer->isServerWalking()) {
|
2012-06-03 21:28:17 +02:00
|
|
|
m_protocolGame->sendStop();
|
2013-01-31 03:50:20 +01:00
|
|
|
if(m_localPlayer->isAutoWalking())
|
|
|
|
m_localPlayer->stopAutoWalk();
|
2012-08-29 17:41:04 +02:00
|
|
|
return false;
|
2012-06-03 17:49:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-03 03:12:14 +01:00
|
|
|
if(dash) {
|
|
|
|
if(m_localPlayer->isWalking() && m_dashTimer.ticksElapsed() < std::max<int>(m_localPlayer->getStepDuration(false, direction) - m_ping, 30))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// check we can walk and add new walk event if false
|
|
|
|
if(!m_localPlayer->canWalk(direction)) {
|
|
|
|
if(m_lastWalkDir != direction) {
|
|
|
|
// must add a new walk event
|
|
|
|
float ticks = m_localPlayer->getStepTicksLeft();
|
|
|
|
if(ticks <= 0) { ticks = 1; }
|
|
|
|
|
|
|
|
if(m_walkEvent) {
|
|
|
|
m_walkEvent->cancel();
|
|
|
|
m_walkEvent = nullptr;
|
|
|
|
}
|
|
|
|
m_walkEvent = g_dispatcher.scheduleEvent([=] { walk(direction, false); }, ticks);
|
2012-12-30 07:14:49 +01:00
|
|
|
}
|
2014-11-03 03:12:14 +01:00
|
|
|
return false;
|
2012-12-30 07:14:49 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-05 15:24:38 +01:00
|
|
|
|
2012-08-02 03:33:56 +02:00
|
|
|
Position toPos = m_localPlayer->getPosition().translatedToDirection(direction);
|
|
|
|
TilePtr toTile = g_map.getTile(toPos);
|
2012-06-03 21:28:17 +02:00
|
|
|
// only do prewalks to walkable tiles (like grounds and not walls)
|
2013-01-31 03:50:20 +01:00
|
|
|
if(toTile && toTile->isWalkable()) {
|
2012-01-20 16:00:24 +01:00
|
|
|
m_localPlayer->preWalk(direction);
|
2012-08-02 03:33:56 +02:00
|
|
|
// check walk to another floor (e.g: when above 3 parcels)
|
2013-01-31 03:50:20 +01:00
|
|
|
} else {
|
2012-08-02 03:33:56 +02:00
|
|
|
// check if can walk to a lower floor
|
2012-08-03 07:58:48 +02:00
|
|
|
auto canChangeFloorDown = [&]() -> bool {
|
2012-08-02 03:33:56 +02:00
|
|
|
Position pos = toPos;
|
|
|
|
if(!pos.down())
|
|
|
|
return false;
|
2012-08-03 05:05:13 +02:00
|
|
|
TilePtr toTile = g_map.getTile(pos);
|
|
|
|
if(toTile && toTile->hasElevation(3))
|
2012-08-02 03:33:56 +02:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
// check if can walk to a higher floor
|
2012-08-03 07:58:48 +02:00
|
|
|
auto canChangeFloorUp = [&]() -> bool {
|
2012-08-02 03:33:56 +02:00
|
|
|
TilePtr fromTile = m_localPlayer->getTile();
|
|
|
|
if(!fromTile || !fromTile->hasElevation(3))
|
|
|
|
return false;
|
|
|
|
Position pos = toPos;
|
|
|
|
if(!pos.up())
|
|
|
|
return false;
|
2012-08-03 05:05:13 +02:00
|
|
|
TilePtr toTile = g_map.getTile(pos);
|
2012-08-02 03:33:56 +02:00
|
|
|
if(!toTile || !toTile->isWalkable())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2012-08-03 05:05:13 +02:00
|
|
|
if(canChangeFloorDown() || canChangeFloorUp() ||
|
|
|
|
(!toTile || toTile->isEmpty())) {
|
2012-08-02 03:33:56 +02:00
|
|
|
m_localPlayer->lockWalk();
|
|
|
|
} else
|
2012-08-29 17:41:04 +02:00
|
|
|
return false;
|
2012-08-02 03:33:56 +02:00
|
|
|
}
|
2012-01-20 16:00:24 +01:00
|
|
|
|
2013-01-22 13:01:30 +01:00
|
|
|
m_localPlayer->stopAutoWalk();
|
2013-01-08 16:32:37 +01:00
|
|
|
|
2014-11-03 03:12:14 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onWalk", direction, dash);
|
2012-08-18 05:30:40 +02:00
|
|
|
|
|
|
|
forceWalk(direction);
|
2014-11-03 03:12:14 +01:00
|
|
|
if(dash)
|
|
|
|
m_dashTimer.restart();
|
|
|
|
|
2012-12-30 07:14:49 +01:00
|
|
|
m_lastWalkDir = direction;
|
2012-08-29 17:41:04 +02:00
|
|
|
return true;
|
2012-01-15 22:19:52 +01:00
|
|
|
}
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2013-02-26 20:37:02 +01:00
|
|
|
bool Game::dashWalk(Otc::Direction direction)
|
|
|
|
{
|
2014-11-03 03:12:14 +01:00
|
|
|
return walk(direction, true);
|
2013-02-26 20:37:02 +01:00
|
|
|
}
|
|
|
|
|
2012-12-29 18:41:14 +01:00
|
|
|
void Game::autoWalk(std::vector<Otc::Direction> dirs)
|
2012-02-08 22:23:15 +01:00
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
|
2012-06-03 21:28:17 +02:00
|
|
|
// protocol limits walk path up to 255 directions
|
2012-07-05 06:07:39 +02:00
|
|
|
if(dirs.size() > 127) {
|
|
|
|
g_logger.error("Auto walk path too great, the maximum number of directions is 127");
|
2012-06-03 17:49:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:07:39 +02:00
|
|
|
if(dirs.size() == 0)
|
2012-03-23 21:36:58 +01:00
|
|
|
return;
|
|
|
|
|
2012-06-03 21:28:17 +02:00
|
|
|
// must cancel follow before any new walk
|
2012-02-08 22:23:15 +01:00
|
|
|
if(isFollowing())
|
|
|
|
cancelFollow();
|
|
|
|
|
2013-01-18 06:27:29 +01:00
|
|
|
auto it = dirs.begin();
|
|
|
|
Otc::Direction direction = *it;
|
2013-03-14 00:55:20 +01:00
|
|
|
if(!m_localPlayer->canWalk(direction))
|
|
|
|
return;
|
2013-01-18 06:27:29 +01:00
|
|
|
|
2013-03-14 00:55:20 +01:00
|
|
|
TilePtr toTile = g_map.getTile(m_localPlayer->getPosition().translatedToDirection(direction));
|
|
|
|
if(toTile && toTile->isWalkable() && !m_localPlayer->isServerWalking()) {
|
|
|
|
m_localPlayer->preWalk(direction);
|
|
|
|
|
|
|
|
if(getFeature(Otc::GameForceFirstAutoWalkStep)) {
|
|
|
|
forceWalk(direction);
|
|
|
|
dirs.erase(it);
|
2012-12-29 18:41:14 +01:00
|
|
|
}
|
2012-08-02 09:58:49 +02:00
|
|
|
}
|
2012-07-05 06:07:39 +02:00
|
|
|
|
2012-07-30 16:03:58 +02:00
|
|
|
g_lua.callGlobalField("g_game", "onAutoWalk", dirs);
|
2012-08-18 05:30:40 +02:00
|
|
|
|
|
|
|
m_protocolGame->sendAutoWalk(dirs);
|
2012-02-08 22:23:15 +01:00
|
|
|
}
|
|
|
|
|
2012-01-15 22:19:52 +01:00
|
|
|
void Game::forceWalk(Otc::Direction direction)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-26 18:23:47 +01:00
|
|
|
return;
|
|
|
|
|
2011-08-17 06:45:55 +02:00
|
|
|
switch(direction) {
|
2011-08-28 18:02:26 +02:00
|
|
|
case Otc::North:
|
2011-08-17 06:45:55 +02:00
|
|
|
m_protocolGame->sendWalkNorth();
|
|
|
|
break;
|
2011-08-28 18:02:26 +02:00
|
|
|
case Otc::East:
|
2011-08-17 06:45:55 +02:00
|
|
|
m_protocolGame->sendWalkEast();
|
|
|
|
break;
|
2011-08-28 18:02:26 +02:00
|
|
|
case Otc::South:
|
2011-08-17 06:45:55 +02:00
|
|
|
m_protocolGame->sendWalkSouth();
|
|
|
|
break;
|
2011-08-28 18:02:26 +02:00
|
|
|
case Otc::West:
|
2011-08-17 06:45:55 +02:00
|
|
|
m_protocolGame->sendWalkWest();
|
|
|
|
break;
|
2011-08-29 07:54:28 +02:00
|
|
|
case Otc::NorthEast:
|
|
|
|
m_protocolGame->sendWalkNorthEast();
|
|
|
|
break;
|
|
|
|
case Otc::SouthEast:
|
|
|
|
m_protocolGame->sendWalkSouthEast();
|
|
|
|
break;
|
|
|
|
case Otc::SouthWest:
|
|
|
|
m_protocolGame->sendWalkSouthWest();
|
|
|
|
break;
|
|
|
|
case Otc::NorthWest:
|
|
|
|
m_protocolGame->sendWalkNorthWest();
|
|
|
|
break;
|
2012-02-20 03:27:08 +01:00
|
|
|
default:
|
|
|
|
break;
|
2011-08-17 06:45:55 +02:00
|
|
|
}
|
2012-07-09 13:37:47 +02:00
|
|
|
|
|
|
|
g_lua.callGlobalField("g_game", "onForceWalk", direction);
|
2011-08-17 06:45:55 +02:00
|
|
|
}
|
|
|
|
|
2011-08-28 18:02:26 +02:00
|
|
|
void Game::turn(Otc::Direction direction)
|
2011-08-17 06:45:55 +02:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2011-08-17 06:45:55 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch(direction) {
|
2011-08-28 18:02:26 +02:00
|
|
|
case Otc::North:
|
2011-08-17 06:45:55 +02:00
|
|
|
m_protocolGame->sendTurnNorth();
|
|
|
|
break;
|
2011-08-28 18:02:26 +02:00
|
|
|
case Otc::East:
|
2011-08-17 06:45:55 +02:00
|
|
|
m_protocolGame->sendTurnEast();
|
|
|
|
break;
|
2011-08-28 18:02:26 +02:00
|
|
|
case Otc::South:
|
2011-08-17 06:45:55 +02:00
|
|
|
m_protocolGame->sendTurnSouth();
|
|
|
|
break;
|
2011-08-28 18:02:26 +02:00
|
|
|
case Otc::West:
|
2011-08-17 06:45:55 +02:00
|
|
|
m_protocolGame->sendTurnWest();
|
|
|
|
break;
|
2012-02-20 03:27:08 +01:00
|
|
|
default:
|
|
|
|
break;
|
2011-08-17 06:45:55 +02:00
|
|
|
}
|
|
|
|
}
|
2011-11-03 17:26:17 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::stop()
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(isFollowing())
|
|
|
|
cancelFollow();
|
|
|
|
|
|
|
|
m_protocolGame->sendStop();
|
|
|
|
}
|
|
|
|
|
2012-01-03 21:41:00 +01:00
|
|
|
void Game::look(const ThingPtr& thing)
|
2011-12-30 19:14:50 +01:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || !thing)
|
2012-01-04 14:02:35 +01:00
|
|
|
return;
|
|
|
|
|
2012-12-28 12:05:45 +01:00
|
|
|
if(thing->isCreature() && m_protocolVersion >= 961)
|
2012-08-29 17:09:05 +02:00
|
|
|
m_protocolGame->sendLookCreature(thing->getId());
|
|
|
|
else
|
2013-01-20 17:09:14 +01:00
|
|
|
m_protocolGame->sendLook(thing->getPosition(), thing->getId(), thing->getStackPos());
|
2012-01-03 01:10:39 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::move(const ThingPtr& thing, const Position& toPos, int count)
|
2012-01-13 01:31:39 +01:00
|
|
|
{
|
2012-08-02 14:13:01 +02:00
|
|
|
if(count <= 0)
|
|
|
|
count = 1;
|
|
|
|
|
|
|
|
if(!canPerformGameAction() || !thing || thing->getPosition() == toPos)
|
2012-01-13 01:31:39 +01:00
|
|
|
return;
|
|
|
|
|
2012-08-02 14:13:01 +02:00
|
|
|
uint id = thing->getId();
|
|
|
|
if(thing->isCreature()) {
|
|
|
|
CreaturePtr creature = thing->static_self_cast<Creature>();
|
|
|
|
id = Proto::Creature;
|
|
|
|
}
|
|
|
|
|
2013-01-20 17:09:14 +01:00
|
|
|
m_protocolGame->sendMove(thing->getPosition(), id, thing->getStackPos(), toPos, count);
|
2012-02-08 22:23:15 +01:00
|
|
|
}
|
|
|
|
|
2012-04-26 02:15:48 +02:00
|
|
|
void Game::moveToParentContainer(const ThingPtr& thing, int count)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction() || !thing || count <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Position position = thing->getPosition();
|
|
|
|
move(thing, Position(position.x, position.y, 254), count);
|
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::rotate(const ThingPtr& thing)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction() || !thing)
|
|
|
|
return;
|
|
|
|
|
2013-01-20 17:09:14 +01:00
|
|
|
m_protocolGame->sendRotateItem(thing->getPosition(), thing->getId(), thing->getStackPos());
|
2012-01-13 01:31:39 +01:00
|
|
|
}
|
|
|
|
|
2012-01-03 23:27:31 +01:00
|
|
|
void Game::use(const ThingPtr& thing)
|
2012-01-04 14:02:35 +01:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || !thing)
|
2012-01-04 14:02:35 +01:00
|
|
|
return;
|
|
|
|
|
2012-02-07 04:33:36 +01:00
|
|
|
Position pos = thing->getPosition();
|
|
|
|
if(!pos.isValid()) // virtual item
|
2013-01-22 01:40:46 +01:00
|
|
|
pos = Position(0xFFFF, 0, 0); // inventory item
|
2012-02-07 04:33:36 +01:00
|
|
|
|
2013-01-22 01:40:46 +01:00
|
|
|
// some items, e.g. parcel, are not set as containers but they are.
|
2012-08-25 00:59:33 +02:00
|
|
|
// always try to use these items in free container slots.
|
2013-01-20 17:09:14 +01:00
|
|
|
m_protocolGame->sendUseItem(pos, thing->getId(), thing->getStackPos(), findEmptyContainerId());
|
2012-01-04 14:02:35 +01:00
|
|
|
}
|
|
|
|
|
2012-02-07 04:33:36 +01:00
|
|
|
void Game::useInventoryItem(int itemId)
|
2012-01-12 00:10:44 +01:00
|
|
|
{
|
2012-07-20 07:45:11 +02:00
|
|
|
if(!canPerformGameAction() || !g_things.isValidDatId(itemId, ThingCategoryItem))
|
2012-01-12 00:10:44 +01:00
|
|
|
return;
|
|
|
|
|
2012-02-07 04:33:36 +01:00
|
|
|
Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
|
|
|
|
|
|
|
|
m_protocolGame->sendUseItem(pos, itemId, 0, 0);
|
|
|
|
}
|
2012-02-07 04:02:06 +01:00
|
|
|
|
2012-02-07 04:33:36 +01:00
|
|
|
void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || !item || !toThing)
|
2012-01-17 23:48:31 +01:00
|
|
|
return;
|
|
|
|
|
2012-02-07 04:33:36 +01:00
|
|
|
Position pos = item->getPosition();
|
|
|
|
if(!pos.isValid()) // virtual item
|
2015-01-27 10:11:27 +01:00
|
|
|
pos = Position(0xFFFF, 0, 0); // means that is an item in inventory
|
2012-01-19 05:12:53 +01:00
|
|
|
|
2014-01-25 22:14:01 +01:00
|
|
|
m_protocolGame->sendUseItemWith(pos, item->getId(), item->getStackPos(), toThing->getPosition(), toThing->getId(), toThing->getStackPos());
|
2012-01-12 00:10:44 +01:00
|
|
|
}
|
|
|
|
|
2012-02-07 04:33:36 +01:00
|
|
|
void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing)
|
2012-01-14 06:54:20 +01:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || !toThing)
|
2012-01-14 06:54:20 +01:00
|
|
|
return;
|
|
|
|
|
2012-01-17 23:53:06 +01:00
|
|
|
Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
|
2012-01-17 23:28:55 +01:00
|
|
|
|
2012-07-29 05:34:40 +02:00
|
|
|
if(toThing->isCreature())
|
|
|
|
m_protocolGame->sendUseOnCreature(pos, itemId, 0, toThing->getId());
|
2012-02-07 04:33:36 +01:00
|
|
|
else
|
2013-01-20 17:09:14 +01:00
|
|
|
m_protocolGame->sendUseItemWith(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackPos());
|
2012-01-17 23:28:55 +01:00
|
|
|
}
|
|
|
|
|
2013-10-04 04:09:54 +02:00
|
|
|
ItemPtr Game::findItemInContainers(uint itemId, int subType)
|
|
|
|
{
|
|
|
|
for(auto& it : m_containers) {
|
|
|
|
const ContainerPtr& container = it.second;
|
|
|
|
|
|
|
|
if(container) {
|
|
|
|
ItemPtr item = container->findItemById(itemId, subType);
|
|
|
|
if(item != nullptr)
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-01-09 20:29:58 +01:00
|
|
|
int Game::open(const ItemPtr& item, const ContainerPtr& previousContainer)
|
2012-01-20 02:12:26 +01:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || !item)
|
2013-01-09 20:29:58 +01:00
|
|
|
return -1;
|
2012-01-20 02:12:26 +01:00
|
|
|
|
2012-04-03 01:09:47 +02:00
|
|
|
int id = 0;
|
2012-08-25 00:59:33 +02:00
|
|
|
if(!previousContainer)
|
|
|
|
id = findEmptyContainerId();
|
|
|
|
else
|
2012-04-03 01:09:47 +02:00
|
|
|
id = previousContainer->getId();
|
|
|
|
|
2013-01-20 17:09:14 +01:00
|
|
|
m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackPos(), id);
|
2013-01-09 20:29:58 +01:00
|
|
|
return id;
|
2012-01-20 02:12:26 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 01:09:47 +02:00
|
|
|
void Game::openParent(const ContainerPtr& container)
|
2012-02-08 00:06:52 +01:00
|
|
|
{
|
2012-04-27 09:28:06 +02:00
|
|
|
if(!canPerformGameAction() || !container)
|
2012-02-08 00:06:52 +01:00
|
|
|
return;
|
2012-04-03 01:09:47 +02:00
|
|
|
|
|
|
|
m_protocolGame->sendUpContainer(container->getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::close(const ContainerPtr& container)
|
|
|
|
{
|
2012-04-27 09:28:06 +02:00
|
|
|
if(!canPerformGameAction() || !container)
|
2012-04-03 01:09:47 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_protocolGame->sendCloseContainer(container->getId());
|
2012-02-08 00:06:52 +01:00
|
|
|
}
|
|
|
|
|
2012-12-29 18:41:14 +01:00
|
|
|
void Game::refreshContainer(const ContainerPtr& container)
|
2012-02-08 00:06:52 +01:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-02-08 00:06:52 +01:00
|
|
|
return;
|
2012-12-29 18:41:14 +01:00
|
|
|
m_protocolGame->sendRefreshContainer(container->getId());
|
2012-02-08 00:06:52 +01:00
|
|
|
}
|
|
|
|
|
2012-08-17 19:43:12 +02:00
|
|
|
void Game::attack(CreaturePtr creature)
|
2012-01-04 14:02:35 +01:00
|
|
|
{
|
2012-06-03 22:05:35 +02:00
|
|
|
if(!canPerformGameAction() || creature == m_localPlayer)
|
2012-01-04 14:02:35 +01:00
|
|
|
return;
|
|
|
|
|
2012-08-17 19:43:12 +02:00
|
|
|
// cancel when attacking again
|
|
|
|
if(creature && creature == m_attackingCreature)
|
|
|
|
creature = nullptr;
|
2012-06-03 22:05:35 +02:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
if(creature && isFollowing())
|
2012-01-07 23:24:29 +01:00
|
|
|
cancelFollow();
|
2012-01-05 15:24:38 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
setAttackingCreature(creature);
|
2013-01-22 13:01:30 +01:00
|
|
|
m_localPlayer->stopAutoWalk();
|
2012-08-29 17:09:05 +02:00
|
|
|
|
2012-12-28 12:05:45 +01:00
|
|
|
if(m_protocolVersion >= 963) {
|
2012-08-29 17:41:04 +02:00
|
|
|
if(creature)
|
|
|
|
m_seq = creature->getId();
|
|
|
|
} else
|
2012-08-29 17:09:05 +02:00
|
|
|
m_seq++;
|
|
|
|
|
2012-08-17 19:43:12 +02:00
|
|
|
m_protocolGame->sendAttack(creature ? creature->getId() : 0, m_seq);
|
2012-01-05 15:24:38 +01:00
|
|
|
}
|
|
|
|
|
2012-08-17 19:43:12 +02:00
|
|
|
void Game::follow(CreaturePtr creature)
|
2012-01-04 14:02:35 +01:00
|
|
|
{
|
2012-08-17 19:43:12 +02:00
|
|
|
if(!canPerformGameAction() || creature == m_localPlayer)
|
2012-01-04 14:02:35 +01:00
|
|
|
return;
|
|
|
|
|
2012-08-17 19:43:12 +02:00
|
|
|
// cancel when following again
|
|
|
|
if(creature && creature == m_followingCreature)
|
|
|
|
creature = nullptr;
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
if(creature && isAttacking())
|
2012-01-07 23:24:29 +01:00
|
|
|
cancelAttack();
|
2012-01-05 15:24:38 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
setFollowingCreature(creature);
|
2013-01-22 13:01:30 +01:00
|
|
|
m_localPlayer->stopAutoWalk();
|
2012-08-29 17:09:05 +02:00
|
|
|
|
2012-12-28 12:05:45 +01:00
|
|
|
if(m_protocolVersion >= 963) {
|
2012-08-29 17:41:04 +02:00
|
|
|
if(creature)
|
|
|
|
m_seq = creature->getId();
|
|
|
|
} else
|
2012-08-29 17:09:05 +02:00
|
|
|
m_seq++;
|
|
|
|
|
2012-08-17 19:43:12 +02:00
|
|
|
m_protocolGame->sendFollow(creature ? creature->getId() : 0, m_seq);
|
2012-01-04 14:02:35 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::cancelAttackAndFollow()
|
2012-01-05 15:24:38 +01:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-30 01:00:12 +01:00
|
|
|
return;
|
|
|
|
|
2013-01-06 16:04:49 +01:00
|
|
|
if(isFollowing())
|
|
|
|
setFollowingCreature(nullptr);
|
|
|
|
if(isAttacking())
|
|
|
|
setAttackingCreature(nullptr);
|
|
|
|
|
2013-01-22 13:01:30 +01:00
|
|
|
m_localPlayer->stopAutoWalk();
|
2013-01-08 16:32:37 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
m_protocolGame->sendCancelAttackAndFollow();
|
2013-01-06 16:04:49 +01:00
|
|
|
|
|
|
|
g_lua.callGlobalField("g_game", "onCancelAttackAndFollow");
|
2012-01-03 23:27:31 +01:00
|
|
|
}
|
|
|
|
|
2012-01-07 22:10:06 +01:00
|
|
|
void Game::talk(const std::string& message)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || message.empty())
|
|
|
|
return;
|
2012-07-26 11:12:20 +02:00
|
|
|
talkChannel(Otc::MessageSay, 0, message);
|
2012-01-07 22:10:06 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 11:12:20 +02:00
|
|
|
void Game::talkChannel(Otc::MessageMode mode, int channelId, const std::string& message)
|
2011-11-03 17:26:17 +01:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || message.empty())
|
2011-11-03 17:26:17 +01:00
|
|
|
return;
|
2012-07-26 11:12:20 +02:00
|
|
|
m_protocolGame->sendTalk(mode, channelId, "", message);
|
2011-11-03 17:26:17 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 11:12:20 +02:00
|
|
|
void Game::talkPrivate(Otc::MessageMode mode, const std::string& receiver, const std::string& message)
|
2011-11-03 17:26:17 +01:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || receiver.empty() || message.empty())
|
2011-11-03 17:26:17 +01:00
|
|
|
return;
|
2012-07-26 11:12:20 +02:00
|
|
|
m_protocolGame->sendTalk(mode, 0, receiver, message);
|
2011-11-03 17:26:17 +01:00
|
|
|
}
|
2011-11-14 23:32:55 +01:00
|
|
|
|
2012-02-02 23:29:44 +01:00
|
|
|
void Game::openPrivateChannel(const std::string& receiver)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || receiver.empty())
|
2012-02-02 23:29:44 +01:00
|
|
|
return;
|
|
|
|
m_protocolGame->sendOpenPrivateChannel(receiver);
|
|
|
|
}
|
|
|
|
|
2012-01-14 06:54:20 +01:00
|
|
|
void Game::requestChannels()
|
2012-01-05 13:48:10 +01:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-05 13:48:10 +01:00
|
|
|
return;
|
2012-02-08 22:23:15 +01:00
|
|
|
m_protocolGame->sendRequestChannels();
|
2012-01-14 06:54:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::joinChannel(int channelId)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-14 06:54:20 +01:00
|
|
|
return;
|
|
|
|
m_protocolGame->sendJoinChannel(channelId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::leaveChannel(int channelId)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-14 06:54:20 +01:00
|
|
|
return;
|
|
|
|
m_protocolGame->sendLeaveChannel(channelId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::closeNpcChannel()
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-14 06:54:20 +01:00
|
|
|
return;
|
|
|
|
m_protocolGame->sendCloseNpcChannel();
|
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::openOwnChannel()
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendOpenOwnChannel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::inviteToOwnChannel(const std::string& name)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction() || name.empty())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendInviteToOwnChannel(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::excludeFromOwnChannel(const std::string& name)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction() || name.empty())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendExcludeFromOwnChannel(name);
|
|
|
|
}
|
2012-01-05 13:48:10 +01:00
|
|
|
|
2012-01-14 06:54:20 +01:00
|
|
|
void Game::partyInvite(int creatureId)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-14 06:54:20 +01:00
|
|
|
return;
|
2012-01-05 13:48:10 +01:00
|
|
|
m_protocolGame->sendInviteToParty(creatureId);
|
|
|
|
}
|
|
|
|
|
2012-01-11 00:38:32 +01:00
|
|
|
void Game::partyJoin(int creatureId)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-11 00:38:32 +01:00
|
|
|
return;
|
|
|
|
m_protocolGame->sendJoinParty(creatureId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::partyRevokeInvitation(int creatureId)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-11 00:38:32 +01:00
|
|
|
return;
|
|
|
|
m_protocolGame->sendRevokeInvitation(creatureId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::partyPassLeadership(int creatureId)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-11 00:38:32 +01:00
|
|
|
return;
|
|
|
|
m_protocolGame->sendPassLeadership(creatureId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::partyLeave()
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-11 00:38:32 +01:00
|
|
|
return;
|
|
|
|
m_protocolGame->sendLeaveParty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::partyShareExperience(bool active)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-11 00:38:32 +01:00
|
|
|
return;
|
2012-07-26 08:10:28 +02:00
|
|
|
m_protocolGame->sendShareExperience(active);
|
2012-01-11 00:38:32 +01:00
|
|
|
}
|
|
|
|
|
2012-01-14 02:37:15 +01:00
|
|
|
void Game::requestOutfit()
|
2011-11-14 23:32:55 +01:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-04 15:30:28 +01:00
|
|
|
return;
|
2012-02-08 22:23:15 +01:00
|
|
|
m_protocolGame->sendRequestOutfit();
|
2011-11-14 23:32:55 +01:00
|
|
|
}
|
2011-11-16 18:33:43 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::changeOutfit(const Outfit& outfit)
|
2011-11-16 18:33:43 +01:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-04 15:30:28 +01:00
|
|
|
return;
|
2012-02-08 22:23:15 +01:00
|
|
|
m_protocolGame->sendChangeOutfit(outfit);
|
2011-11-16 18:33:43 +01:00
|
|
|
}
|
2012-01-04 15:30:28 +01:00
|
|
|
|
|
|
|
void Game::addVip(const std::string& name)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || name.empty())
|
2012-01-04 15:30:28 +01:00
|
|
|
return;
|
|
|
|
m_protocolGame->sendAddVip(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::removeVip(int playerId)
|
|
|
|
{
|
2012-02-09 04:45:19 +01:00
|
|
|
if(!canPerformGameAction())
|
2012-01-04 15:30:28 +01:00
|
|
|
return;
|
2013-07-28 07:05:46 +02:00
|
|
|
|
2013-03-02 21:01:29 +01:00
|
|
|
auto it = m_vips.find(playerId);
|
|
|
|
if(it == m_vips.end())
|
|
|
|
return;
|
|
|
|
m_vips.erase(it);
|
2012-01-04 15:30:28 +01:00
|
|
|
m_protocolGame->sendRemoveVip(playerId);
|
|
|
|
}
|
2012-01-06 20:25:27 +01:00
|
|
|
|
2014-01-14 23:15:01 +01:00
|
|
|
void Game::editVip(int playerId, const std::string& description, int iconId, bool notifyLogin)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto it = m_vips.find(playerId);
|
|
|
|
if(it == m_vips.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::get<2>(m_vips[playerId]) = description;
|
|
|
|
std::get<3>(m_vips[playerId]) = iconId;
|
|
|
|
std::get<4>(m_vips[playerId]) = notifyLogin;
|
|
|
|
|
|
|
|
if(getFeature(Otc::GameAdditionalVipInfo))
|
|
|
|
m_protocolGame->sendEditVip(playerId, description, iconId, notifyLogin);
|
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::setChaseMode(Otc::ChaseModes chaseMode)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
2012-06-07 13:52:17 +02:00
|
|
|
if(m_chaseMode == chaseMode)
|
|
|
|
return;
|
2012-02-08 22:23:15 +01:00
|
|
|
m_chaseMode = chaseMode;
|
2013-11-19 00:50:00 +01:00
|
|
|
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
|
2012-06-07 13:52:17 +02:00
|
|
|
g_lua.callGlobalField("g_game", "onChaseModeChange", chaseMode);
|
2012-02-08 22:23:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::setFightMode(Otc::FightModes fightMode)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
2012-06-07 13:52:17 +02:00
|
|
|
if(m_fightMode == fightMode)
|
|
|
|
return;
|
2012-02-08 22:23:15 +01:00
|
|
|
m_fightMode = fightMode;
|
2013-11-19 00:50:00 +01:00
|
|
|
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
|
2012-06-07 13:52:17 +02:00
|
|
|
g_lua.callGlobalField("g_game", "onFightModeChange", fightMode);
|
2012-02-08 22:23:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::setSafeFight(bool on)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
2012-06-07 13:52:17 +02:00
|
|
|
if(m_safeFight == on)
|
|
|
|
return;
|
2012-02-08 22:23:15 +01:00
|
|
|
m_safeFight = on;
|
2013-11-19 00:50:00 +01:00
|
|
|
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
|
2012-06-07 13:52:17 +02:00
|
|
|
g_lua.callGlobalField("g_game", "onSafeFightChange", on);
|
2012-02-08 22:23:15 +01:00
|
|
|
}
|
|
|
|
|
2013-11-19 00:50:00 +01:00
|
|
|
void Game::setPVPMode(Otc::PVPModes pvpMode)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
2013-11-19 01:09:31 +01:00
|
|
|
if(!getFeature(Otc::GamePVPMode))
|
2013-11-19 00:55:42 +01:00
|
|
|
return;
|
2013-11-19 00:50:00 +01:00
|
|
|
if(m_pvpMode == pvpMode)
|
|
|
|
return;
|
|
|
|
m_pvpMode = pvpMode;
|
|
|
|
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
|
|
|
|
g_lua.callGlobalField("g_game", "onPVPModeChange", pvpMode);
|
|
|
|
}
|
|
|
|
|
2015-01-18 15:14:07 +01:00
|
|
|
void Game::setUnjustifiedPoints(UnjustifiedPoints unjustifiedPoints)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
if(!getFeature(Otc::GameUnjustifiedPoints))
|
|
|
|
return;
|
|
|
|
if(m_unjustifiedPoints == unjustifiedPoints)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_unjustifiedPoints = unjustifiedPoints;
|
|
|
|
g_lua.callGlobalField("g_game", "onUnjustifiedPointsChange", unjustifiedPoints);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::setOpenPvpSituations(int openPvpSituations)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
if(m_openPvpSituations == openPvpSituations)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_openPvpSituations = openPvpSituations;
|
|
|
|
g_lua.callGlobalField("g_game", "onOpenPvpSituationsChange", openPvpSituations);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
void Game::inspectNpcTrade(const ItemPtr& item)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction() || !item)
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendInspectNpcTrade(item->getId(), item->getCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::buyItem(const ItemPtr& item, int amount, bool ignoreCapacity, bool buyWithBackpack)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction() || !item)
|
|
|
|
return;
|
2012-12-30 12:32:09 +01:00
|
|
|
m_protocolGame->sendBuyItem(item->getId(), item->getCountOrSubType(), amount, ignoreCapacity, buyWithBackpack);
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::sellItem(const ItemPtr& item, int amount, bool ignoreEquipped)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction() || !item)
|
|
|
|
return;
|
2012-04-28 01:51:46 +02:00
|
|
|
m_protocolGame->sendSellItem(item->getId(), item->getSubType(), amount, ignoreEquipped);
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::closeNpcTrade()
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendCloseNpcTrade();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::requestTrade(const ItemPtr& item, const CreaturePtr& creature)
|
|
|
|
{
|
2012-04-27 09:28:06 +02:00
|
|
|
if(!canPerformGameAction() || !item || !creature)
|
2012-02-09 04:45:19 +01:00
|
|
|
return;
|
2013-01-20 17:09:14 +01:00
|
|
|
m_protocolGame->sendRequestTrade(item->getPosition(), item->getId(), item->getStackPos(), creature->getId());
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::inspectTrade(bool counterOffer, int index)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendInspectTrade(counterOffer, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::acceptTrade()
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendAcceptTrade();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::rejectTrade()
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendRejectTrade();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::editText(uint id, const std::string& text)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendEditText(id, text);
|
|
|
|
}
|
|
|
|
|
2012-05-01 02:53:02 +02:00
|
|
|
void Game::editList(uint id, int doorId, const std::string& text)
|
2012-02-09 04:45:19 +01:00
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
2012-05-01 02:53:02 +02:00
|
|
|
m_protocolGame->sendEditList(id, doorId, text);
|
2012-02-09 04:45:19 +01:00
|
|
|
}
|
|
|
|
|
2013-01-27 10:44:15 +01:00
|
|
|
void Game::openRuleViolation(const std::string& reporter)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendOpenRuleViolation(reporter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::closeRuleViolation(const std::string& reporter)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendCloseRuleViolation(reporter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::cancelRuleViolation()
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendCancelRuleViolation();
|
|
|
|
}
|
|
|
|
|
2012-05-01 00:24:50 +02:00
|
|
|
void Game::reportBug(const std::string& comment)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendBugReport(comment);
|
|
|
|
}
|
|
|
|
|
2012-12-29 18:41:14 +01:00
|
|
|
void Game::reportRuleViolation(const std::string& target, int reason, int action, const std::string& comment, const std::string& statement, int statementId, bool ipBanishment)
|
2012-05-01 00:24:50 +02:00
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
2012-12-29 18:41:14 +01:00
|
|
|
m_protocolGame->sendRuleViolation(target, reason, action, comment, statement, statementId, ipBanishment);
|
2012-05-01 00:24:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::debugReport(const std::string& a, const std::string& b, const std::string& c, const std::string& d)
|
|
|
|
{
|
|
|
|
m_protocolGame->sendDebugReport(a, b, c, d);
|
|
|
|
}
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
void Game::requestQuestLog()
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendRequestQuestLog();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::requestQuestLine(int questId)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendRequestQuestLine(questId);
|
|
|
|
}
|
|
|
|
|
2012-05-12 13:55:22 +02:00
|
|
|
void Game::equipItem(const ItemPtr& item)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendEquipItem(item->getId(), item->getCountOrSubType());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::mount(bool mount)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
2012-07-15 13:58:51 +02:00
|
|
|
m_protocolGame->sendMountStatus(mount);
|
2012-05-12 13:55:22 +02:00
|
|
|
}
|
|
|
|
|
2012-07-30 17:08:21 +02:00
|
|
|
void Game::requestItemInfo(const ItemPtr& item, int index)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendRequestItemInfo(item->getId(), item->getSubType(), index);
|
|
|
|
}
|
|
|
|
|
2012-11-27 14:48:48 +01:00
|
|
|
void Game::answerModalDialog(int dialog, int button, int choice)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendAnswerModalDialog(dialog, button, choice);
|
|
|
|
}
|
|
|
|
|
2014-07-15 23:19:08 +02:00
|
|
|
void Game::browseField(const Position& position)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendBrowseField(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::seekInContainer(int cid, int index)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendSeekInContainer(cid, index);
|
|
|
|
}
|
|
|
|
|
2015-10-24 17:46:53 +02:00
|
|
|
void Game::buyStoreOffer(int offerId, int productType, const std::string& name)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendBuyStoreOffer(offerId, productType, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::requestTransactionHistory(int page, int entriesPerPage)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendRequestTransactionHistory(page, entriesPerPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::requestStoreOffers(const std::string& categoryName)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendRequestStoreOffers(categoryName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::openStore()
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendOpenStore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::transferCoins(const std::string& recipient, int amount)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendTransferCoins(recipient, amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::openTransactionHistory(int entriesPerPage)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendOpenTransactionHistory(entriesPerPage);
|
|
|
|
}
|
|
|
|
|
2012-07-30 12:59:08 +02:00
|
|
|
void Game::ping()
|
|
|
|
{
|
|
|
|
if(!m_protocolGame || !m_protocolGame->isConnected())
|
|
|
|
return;
|
|
|
|
|
2013-02-24 21:26:19 +01:00
|
|
|
if(m_pingReceived != m_pingSent)
|
|
|
|
return;
|
|
|
|
|
2012-07-30 12:59:08 +02:00
|
|
|
m_denyBotCall = false;
|
|
|
|
m_protocolGame->sendPing();
|
|
|
|
m_denyBotCall = true;
|
2013-02-24 21:26:19 +01:00
|
|
|
m_pingSent++;
|
|
|
|
m_pingTimer.restart();
|
2012-07-30 12:59:08 +02:00
|
|
|
}
|
|
|
|
|
2013-01-09 20:29:58 +01:00
|
|
|
void Game::changeMapAwareRange(int xrange, int yrange)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendChangeMapAwareRange(xrange, yrange);
|
|
|
|
}
|
|
|
|
|
2012-01-06 20:25:27 +01:00
|
|
|
bool Game::checkBotProtection()
|
|
|
|
{
|
2012-06-04 02:28:19 +02:00
|
|
|
#ifdef BOT_PROTECTION
|
2012-02-08 22:23:15 +01:00
|
|
|
// accepts calls comming from a stacktrace containing only C++ functions,
|
|
|
|
// if the stacktrace contains a lua function, then only accept if the engine is processing an input event
|
2012-06-20 02:15:56 +02:00
|
|
|
if(m_denyBotCall && g_lua.isInCppCallback() && !g_app.isOnInputEvent()) {
|
2012-07-19 20:54:24 +02:00
|
|
|
g_logger.error(g_lua.traceback("caught a lua call to a bot protected game function, the call was cancelled"));
|
2012-01-06 20:25:27 +01:00
|
|
|
return false;
|
|
|
|
}
|
2012-06-04 02:28:19 +02:00
|
|
|
#endif
|
2012-01-06 20:25:27 +01:00
|
|
|
return true;
|
|
|
|
}
|
2012-02-08 22:23:15 +01:00
|
|
|
|
|
|
|
bool Game::canPerformGameAction()
|
|
|
|
{
|
|
|
|
// we can only perform game actions if we meet these conditions:
|
2012-07-26 08:10:28 +02:00
|
|
|
// - the game is online
|
2012-02-08 22:23:15 +01:00
|
|
|
// - the local player exists
|
|
|
|
// - the local player is not dead
|
|
|
|
// - we have a game protocol
|
|
|
|
// - the game protocol is connected
|
|
|
|
// - its not a bot action
|
2015-07-19 10:33:55 +02:00
|
|
|
return m_online && m_localPlayer && !m_localPlayer->isDead() && !m_dead && m_protocolGame && m_protocolGame->isConnected() && checkBotProtection();
|
2012-02-08 22:23:15 +01:00
|
|
|
}
|
|
|
|
|
2012-12-28 12:05:45 +01:00
|
|
|
void Game::setProtocolVersion(int version)
|
2012-05-29 00:04:44 +02:00
|
|
|
{
|
2012-12-28 12:05:45 +01:00
|
|
|
if(m_protocolVersion == version)
|
2012-07-31 06:09:55 +02:00
|
|
|
return;
|
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
if(isOnline())
|
2012-12-28 12:05:45 +01:00
|
|
|
stdext::throw_exception("Unable to change protocol version while online");
|
2012-05-29 00:04:44 +02:00
|
|
|
|
2015-10-24 17:46:53 +02:00
|
|
|
if(version != 0 && (version < 740 || version > 1082))
|
2012-07-18 01:49:21 +02:00
|
|
|
stdext::throw_exception(stdext::format("Protocol version %d not supported", version));
|
2012-05-29 00:04:44 +02:00
|
|
|
|
2014-08-03 00:02:28 +02:00
|
|
|
m_protocolVersion = version;
|
|
|
|
|
|
|
|
Proto::buildMessageModesMap(version);
|
|
|
|
|
|
|
|
g_lua.callGlobalField("g_game", "onProtocolVersionChange", version);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::setClientVersion(int version)
|
|
|
|
{
|
|
|
|
if(m_clientVersion == version)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(isOnline())
|
|
|
|
stdext::throw_exception("Unable to change client version while online");
|
|
|
|
|
2015-10-24 17:46:53 +02:00
|
|
|
if(version != 0 && (version < 740 || version > 1082))
|
2014-08-03 00:02:28 +02:00
|
|
|
stdext::throw_exception(stdext::format("Client version %d not supported", version));
|
|
|
|
|
2012-05-29 00:04:44 +02:00
|
|
|
m_features.reset();
|
2012-08-15 01:58:25 +02:00
|
|
|
enableFeature(Otc::GameFormatCreatureName);
|
2012-05-29 00:04:44 +02:00
|
|
|
|
2014-07-29 21:11:17 +02:00
|
|
|
if(version >= 770) {
|
2013-12-26 21:31:55 +01:00
|
|
|
enableFeature(Otc::GameLooktypeU16);
|
|
|
|
enableFeature(Otc::GameMessageStatements);
|
2014-12-29 18:08:13 +01:00
|
|
|
enableFeature(Otc::GameLoginPacketEncryption);
|
2013-12-25 15:10:59 +01:00
|
|
|
}
|
2013-10-04 04:09:54 +02:00
|
|
|
|
2014-07-29 21:11:17 +02:00
|
|
|
if(version >= 780) {
|
2013-10-04 04:09:54 +02:00
|
|
|
enableFeature(Otc::GamePlayerAddons);
|
|
|
|
enableFeature(Otc::GamePlayerStamina);
|
|
|
|
enableFeature(Otc::GameNewFluids);
|
|
|
|
enableFeature(Otc::GameMessageLevel);
|
|
|
|
enableFeature(Otc::GamePlayerStateU16);
|
2014-07-29 21:11:17 +02:00
|
|
|
enableFeature(Otc::GameNewOutfitProtocol);
|
2013-10-04 04:09:54 +02:00
|
|
|
}
|
|
|
|
|
2014-01-21 23:13:07 +01:00
|
|
|
if(version >= 790) {
|
|
|
|
enableFeature(Otc::GameWritableDate);
|
|
|
|
}
|
|
|
|
|
2013-02-27 13:01:51 +01:00
|
|
|
if(version >= 840) {
|
|
|
|
enableFeature(Otc::GameProtocolChecksum);
|
|
|
|
enableFeature(Otc::GameAccountNames);
|
2013-12-04 16:01:51 +01:00
|
|
|
enableFeature(Otc::GameDoubleFreeCapacity);
|
2013-02-27 13:01:51 +01:00
|
|
|
}
|
|
|
|
|
2014-01-17 22:41:58 +01:00
|
|
|
if(version >= 841) {
|
|
|
|
enableFeature(Otc::GameChallengeOnLogin);
|
2014-12-29 18:08:13 +01:00
|
|
|
enableFeature(Otc::GameMessageSizeCheck);
|
2012-07-18 08:04:57 +02:00
|
|
|
}
|
|
|
|
|
2013-10-07 21:32:13 +02:00
|
|
|
if(version >= 854) {
|
2012-07-18 01:49:21 +02:00
|
|
|
enableFeature(Otc::GameCreatureEmblems);
|
2012-05-29 00:04:44 +02:00
|
|
|
}
|
|
|
|
|
2013-01-09 20:29:58 +01:00
|
|
|
if(version >= 860) {
|
|
|
|
enableFeature(Otc::GameAttackSeq);
|
|
|
|
}
|
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
if(version >= 862) {
|
2012-05-29 00:04:44 +02:00
|
|
|
enableFeature(Otc::GamePenalityOnDeath);
|
|
|
|
}
|
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
if(version >= 870) {
|
2012-05-29 00:04:44 +02:00
|
|
|
enableFeature(Otc::GameDoubleExperience);
|
|
|
|
enableFeature(Otc::GamePlayerMounts);
|
2012-08-19 11:46:24 +02:00
|
|
|
enableFeature(Otc::GameSpellList);
|
2012-05-29 00:04:44 +02:00
|
|
|
}
|
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
if(version >= 910) {
|
2012-05-29 00:04:44 +02:00
|
|
|
enableFeature(Otc::GameNameOnNpcTrade);
|
|
|
|
enableFeature(Otc::GameTotalCapacity);
|
|
|
|
enableFeature(Otc::GameSkillsBase);
|
2012-07-18 01:49:21 +02:00
|
|
|
enableFeature(Otc::GamePlayerRegenerationTime);
|
2012-05-29 00:04:44 +02:00
|
|
|
enableFeature(Otc::GameChannelPlayerList);
|
|
|
|
enableFeature(Otc::GameEnvironmentEffect);
|
|
|
|
enableFeature(Otc::GameItemAnimationPhase);
|
|
|
|
}
|
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
if(version >= 940) {
|
2012-07-17 16:36:27 +02:00
|
|
|
enableFeature(Otc::GamePlayerMarket);
|
|
|
|
}
|
|
|
|
|
2012-08-25 21:11:54 +02:00
|
|
|
if(version >= 953) {
|
2012-07-18 08:04:57 +02:00
|
|
|
enableFeature(Otc::GamePurseSlot);
|
2012-08-25 21:11:54 +02:00
|
|
|
enableFeature(Otc::GameClientPing);
|
2012-07-18 08:04:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(version >= 960) {
|
|
|
|
enableFeature(Otc::GameSpritesU32);
|
|
|
|
enableFeature(Otc::GameOfflineTrainingTime);
|
|
|
|
}
|
|
|
|
|
2014-01-14 23:15:01 +01:00
|
|
|
if(version >= 963) {
|
|
|
|
enableFeature(Otc::GameAdditionalVipInfo);
|
|
|
|
}
|
|
|
|
|
2014-12-29 18:08:13 +01:00
|
|
|
if(version >= 980) {
|
|
|
|
enableFeature(Otc::GamePreviewState);
|
|
|
|
enableFeature(Otc::GameClientVersion);
|
|
|
|
}
|
|
|
|
|
2014-11-02 20:50:37 +01:00
|
|
|
if(version >= 981) {
|
2012-12-26 14:56:06 +01:00
|
|
|
enableFeature(Otc::GameLoginPending);
|
|
|
|
enableFeature(Otc::GameNewSpeedLaw);
|
|
|
|
}
|
|
|
|
|
2014-07-15 23:19:08 +02:00
|
|
|
if(version >= 984) {
|
2014-11-02 20:50:37 +01:00
|
|
|
enableFeature(Otc::GameContainerPagination);
|
2014-07-15 23:19:08 +02:00
|
|
|
enableFeature(Otc::GameBrowseField);
|
|
|
|
}
|
|
|
|
|
2013-11-11 02:31:59 +01:00
|
|
|
if(version >= 1000) {
|
2014-11-02 20:50:37 +01:00
|
|
|
enableFeature(Otc::GameThingMarks);
|
2013-11-11 02:31:59 +01:00
|
|
|
enableFeature(Otc::GamePVPMode);
|
|
|
|
}
|
|
|
|
|
2014-12-29 18:08:13 +01:00
|
|
|
if(version >= 1035) {
|
2014-03-12 06:39:20 +01:00
|
|
|
enableFeature(Otc::GameDoubleSkills);
|
|
|
|
enableFeature(Otc::GameBaseSkillU16);
|
2014-02-24 19:33:29 +01:00
|
|
|
}
|
2014-03-12 06:39:20 +01:00
|
|
|
|
|
|
|
if(version >= 1036) {
|
|
|
|
enableFeature(Otc::GameCreatureIcons);
|
|
|
|
enableFeature(Otc::GameHideNpcNames);
|
|
|
|
}
|
2014-08-03 00:02:28 +02:00
|
|
|
|
2014-06-29 16:25:01 +02:00
|
|
|
if(version >= 1038) {
|
2014-06-23 17:20:12 +02:00
|
|
|
enableFeature(Otc::GamePremiumExpiration);
|
2014-06-23 17:04:30 +02:00
|
|
|
}
|
2014-03-12 06:39:20 +01:00
|
|
|
|
2014-08-03 00:02:28 +02:00
|
|
|
if(version >= 1050) {
|
|
|
|
enableFeature(Otc::GameEnhancedAnimations);
|
|
|
|
}
|
2012-12-28 12:05:45 +01:00
|
|
|
|
2015-01-18 15:14:07 +01:00
|
|
|
if(version >= 1053) {
|
|
|
|
enableFeature(Otc::GameUnjustifiedPoints);
|
|
|
|
}
|
|
|
|
|
2014-12-29 18:08:13 +01:00
|
|
|
if(version >= 1054) {
|
|
|
|
enableFeature(Otc::GameExperienceBonus);
|
|
|
|
}
|
|
|
|
|
2015-03-07 06:09:00 +01:00
|
|
|
if(version >= 1055) {
|
|
|
|
enableFeature(Otc::GameDeathType);
|
|
|
|
}
|
|
|
|
|
2015-08-27 00:49:43 +02:00
|
|
|
if(version >= 1057) {
|
|
|
|
enableFeature(Otc::GameIdleAnimations);
|
|
|
|
}
|
|
|
|
|
2014-12-29 18:08:13 +01:00
|
|
|
if(version >= 1061) {
|
|
|
|
enableFeature(Otc::GameOGLInformation);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(version >= 1071) {
|
|
|
|
enableFeature(Otc::GameContentRevision);
|
|
|
|
}
|
|
|
|
|
2015-01-18 15:14:07 +01:00
|
|
|
if(version >= 1072) {
|
|
|
|
enableFeature(Otc::GameAuthenticator);
|
|
|
|
}
|
|
|
|
|
2015-01-27 23:44:37 +01:00
|
|
|
if(version >= 1074) {
|
|
|
|
enableFeature(Otc::GameSessionKey);
|
|
|
|
}
|
|
|
|
|
2015-10-24 17:46:53 +02:00
|
|
|
if(version >= 1080) {
|
|
|
|
enableFeature(Otc::GameIngameStore);
|
|
|
|
}
|
|
|
|
|
2012-12-28 12:05:45 +01:00
|
|
|
m_clientVersion = version;
|
|
|
|
|
2012-07-26 08:10:28 +02:00
|
|
|
g_lua.callGlobalField("g_game", "onClientVersionChange", version);
|
2012-05-29 00:04:44 +02:00
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::setAttackingCreature(const CreaturePtr& creature)
|
|
|
|
{
|
2014-06-02 00:04:56 +02:00
|
|
|
if(creature != m_attackingCreature) {
|
|
|
|
CreaturePtr oldCreature = m_attackingCreature;
|
|
|
|
m_attackingCreature = creature;
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2014-06-02 00:04:56 +02:00
|
|
|
g_lua.callGlobalField("g_game", "onAttackingCreatureChange", creature, oldCreature);
|
|
|
|
}
|
2012-02-08 22:23:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::setFollowingCreature(const CreaturePtr& creature)
|
|
|
|
{
|
2012-03-30 00:46:44 +02:00
|
|
|
CreaturePtr oldCreature = m_followingCreature;
|
|
|
|
m_followingCreature = creature;
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-03-30 00:46:44 +02:00
|
|
|
g_lua.callGlobalField("g_game", "onFollowingCreatureChange", creature, oldCreature);
|
2012-06-03 22:05:35 +02:00
|
|
|
}
|
2012-08-10 02:36:52 +02:00
|
|
|
|
|
|
|
std::string Game::formatCreatureName(const std::string& name)
|
|
|
|
{
|
|
|
|
std::string formatedName = name;
|
2013-01-09 20:29:58 +01:00
|
|
|
if(getFeature(Otc::GameFormatCreatureName) && name.length() > 0) {
|
|
|
|
bool upnext = true;
|
|
|
|
for(uint i=0;i<formatedName.length();++i) {
|
|
|
|
char ch = formatedName[i];
|
|
|
|
if(upnext) {
|
|
|
|
formatedName[i] = stdext::upchar(ch);
|
|
|
|
upnext = false;
|
|
|
|
}
|
|
|
|
if(ch == ' ')
|
|
|
|
upnext = true;
|
|
|
|
}
|
|
|
|
}
|
2012-08-10 02:36:52 +02:00
|
|
|
return formatedName;
|
|
|
|
}
|
2012-08-25 00:59:33 +02:00
|
|
|
|
|
|
|
int Game::findEmptyContainerId()
|
|
|
|
{
|
|
|
|
int id = 0;
|
|
|
|
while(m_containers[id] != nullptr)
|
|
|
|
id++;
|
|
|
|
return id;
|
|
|
|
}
|
2013-01-09 20:29:58 +01:00
|
|
|
|
|
|
|
int Game::getOs()
|
|
|
|
{
|
|
|
|
if(m_clientCustomOs >= 0)
|
|
|
|
return m_clientCustomOs;
|
|
|
|
|
|
|
|
if(g_app.getOs() == "windows")
|
|
|
|
return 10;
|
|
|
|
else if(g_app.getOs() == "mac")
|
|
|
|
return 12;
|
2013-01-17 21:24:41 +01:00
|
|
|
else // linux
|
|
|
|
return 11;
|
2013-01-09 20:29:58 +01:00
|
|
|
}
|