2011-08-28 15:17:58 +02:00
|
|
|
/*
|
2012-01-02 17:58:37 +01:00
|
|
|
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
2011-08-28 15:17:58 +02:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2011-08-15 16:11:24 +02:00
|
|
|
#include "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"
|
|
|
|
#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-01-08 19:29:41 +01:00
|
|
|
#include <otclient/luascript/luavaluecasts.h>
|
|
|
|
#include <otclient/net/protocolgame.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-02-08 22:23:15 +01:00
|
|
|
resetGameStates();
|
2011-08-16 02:30:31 +02:00
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::resetGameStates()
|
2011-08-30 01:20:30 +02:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
m_dead = false;
|
|
|
|
m_serverBeat = 50;
|
|
|
|
m_fightMode = Otc::FightBalanced;
|
|
|
|
m_chaseMode = Otc::DontChase;
|
|
|
|
m_safeFight = true;
|
|
|
|
m_followingCreature = nullptr;
|
|
|
|
m_attackingCreature = nullptr;
|
2011-08-30 01:20:30 +02:00
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::processConnectionError(const boost::system::error_code& error)
|
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
|
|
|
|
if(error != asio::error::eof)
|
|
|
|
g_lua.callGlobalField("g_game", "onConnectionError", error.message());
|
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-02-08 22:23:15 +01:00
|
|
|
if(isOnline()) {
|
2012-02-08 23:58:27 +01:00
|
|
|
// only process logout event if the player is known
|
2012-02-08 22:23:15 +01:00
|
|
|
if(m_localPlayer->isKnown())
|
|
|
|
processLogout();
|
2011-12-03 22:41:37 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
m_localPlayer = nullptr;
|
|
|
|
|
|
|
|
processGameEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_protocolGame) {
|
|
|
|
m_protocolGame->disconnect();
|
|
|
|
m_protocolGame = nullptr;
|
|
|
|
}
|
2011-08-29 20:38:01 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-02-08 00:54:33 +01:00
|
|
|
void Game::processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat)
|
2011-08-15 23:02:52 +02:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
// reset the new game state
|
|
|
|
resetGameStates();
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
m_localPlayer = localPlayer;
|
2012-01-09 06:23:39 +01:00
|
|
|
m_serverBeat = serverBeat;
|
|
|
|
|
2012-02-08 00:06:52 +01:00
|
|
|
// synchronize fight modes with the server
|
2012-02-08 22:23:15 +01:00
|
|
|
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
|
2012-02-08 00:06:52 +01:00
|
|
|
|
2012-02-08 00:54:33 +01:00
|
|
|
// NOTE: the entire map description and local player informations is not known yet
|
2012-02-08 22:23:15 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onGameStart");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processGameEnd()
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onGameEnd");
|
|
|
|
|
2012-02-08 23:58:27 +01:00
|
|
|
// reset game state
|
2012-02-08 22:23:15 +01:00
|
|
|
resetGameStates();
|
2012-02-08 00:54:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processLogin()
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
// the game could be offline if the login was canceled
|
2012-02-08 00:54:33 +01:00
|
|
|
if(!isOnline())
|
|
|
|
return;
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
// by now the local player must be known
|
|
|
|
g_lua.callGlobalField("g_game", "onLogin", m_localPlayer);
|
2011-08-15 23:02:52 +02:00
|
|
|
}
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
void Game::processLogout()
|
2011-08-15 23:02:52 +02:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onLogout", m_localPlayer);
|
2011-08-15 23:02:52 +02:00
|
|
|
}
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::processDeath(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
|
|
|
|
|
|
|
g_lua.callGlobalField("g_game","onDeath", penality);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processPing()
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onPing");
|
2012-01-07 06:10:02 +01:00
|
|
|
}
|
|
|
|
|
2012-01-25 15:56:17 +01:00
|
|
|
void Game::processTextMessage(const std::string& type, const std::string& message)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
g_lua.callGlobalField("g_game","onTextMessage", type, message);
|
2012-01-25 15:56:17 +01:00
|
|
|
}
|
|
|
|
|
2012-02-03 01:25:18 +01:00
|
|
|
void Game::processCreatureSpeak(const std::string& name, int level, Otc::SpeakType type, const std::string& message, int channelId, const Position& creaturePos)
|
2012-01-08 19:29:41 +01:00
|
|
|
{
|
2012-02-03 01:25:18 +01:00
|
|
|
if(creaturePos.isValid() && (type == Otc::SpeakSay || type == Otc::SpeakWhisper || type == Otc::SpeakYell || type == Otc::SpeakMonsterSay || type == Otc::SpeakMonsterYell)) {
|
2012-01-08 19:29:41 +01:00
|
|
|
StaticTextPtr staticText = StaticTextPtr(new StaticText);
|
|
|
|
staticText->addMessage(name, type, message);
|
|
|
|
g_map.addThing(staticText, creaturePos);
|
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onCreatureSpeak", name, level, type, message, channelId, creaturePos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processOpenContainer(int containerId, int itemId, const std::string& name, int capacity, bool hasParent, const std::vector< ItemPtr >& items)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onOpenContainer", containerId, itemId, name, capacity, hasParent, items);
|
2012-01-08 19:29:41 +01:00
|
|
|
}
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
void Game::processCloseContainer(int containerId)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onCloseContainer", containerId);
|
|
|
|
}
|
|
|
|
|
2012-01-12 20:25:58 +01:00
|
|
|
void Game::processContainerAddItem(int containerId, const ItemPtr& item)
|
|
|
|
{
|
2012-02-08 23:58:27 +01:00
|
|
|
item->setPosition(Position(65535, containerId + 0x40, 0));
|
2012-02-08 22:23:15 +01:00
|
|
|
g_lua.callGlobalField("g_game", "onContainerAddItem", containerId, item);
|
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)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onContainerUpdateItem", containerId, slot, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processContainerRemoveItem(int containerId, int slot)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onContainerRemoveItem", containerId, slot);
|
|
|
|
}
|
|
|
|
|
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-02-08 22:23:15 +01:00
|
|
|
g_lua.callGlobalField("g_game","onInventoryChange", slot, item);
|
2011-11-10 06:29:25 +01:00
|
|
|
}
|
|
|
|
|
2012-01-09 06:23:39 +01:00
|
|
|
void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos)
|
|
|
|
{
|
2012-01-20 16:00:24 +01:00
|
|
|
// animate walk
|
2012-01-30 19:18:10 +01:00
|
|
|
if(oldPos.isInRange(newPos, 1, 1))
|
2012-01-25 15:56:17 +01:00
|
|
|
creature->walk(oldPos, newPos);
|
2012-01-20 16:00:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processCreatureTeleport(const CreaturePtr& creature)
|
|
|
|
{
|
|
|
|
// stop walking on creature teleports
|
|
|
|
creature->stopWalk();
|
2012-01-25 03:16:04 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
// locks the walk for a while when teleporting
|
2012-01-25 03:16:04 +01:00
|
|
|
if(creature == m_localPlayer)
|
|
|
|
m_localPlayer->lockWalk();
|
2012-01-09 06:23:39 +01:00
|
|
|
}
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
void Game::processChannelList(const std::vector<std::tuple<int, std::string>>& channelList)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processVipAdd(uint id, const std::string& name, bool online)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onAddVip", id, name, online);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processVipStateChange(uint id, bool online)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onVipStateChange", id, online);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processOpenOutfitWindow(const Outfit& currentOufit, const std::vector<std::tuple<int, std::string, int>>& outfitList)
|
|
|
|
{
|
|
|
|
CreaturePtr virtualCreature = CreaturePtr(new Creature);
|
|
|
|
virtualCreature->setDirection(Otc::South);
|
|
|
|
virtualCreature->setOutfit(currentOufit);
|
|
|
|
|
|
|
|
g_lua.callGlobalField("g_game", "onOpenOutfitWindow", virtualCreature, outfitList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processOpenNpcTrade(const std::vector<std::tuple<ItemPtr, std::string, int, int, int>>& items)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onOpenNpcTrade", items);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processPlayerGoods(int money, const std::vector<std::tuple<ItemPtr, int>>& goods)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onPlayerGoods", goods);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processCloseNpcTrade()
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onCloseNpcTrade");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processOpenTrade(const std::string& name, const std::vector<ItemPtr>& items)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onOpenTrade", name, items);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processCloseTrade()
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onCloseTrade");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processEditText(int id, int itemId, int maxLength, const std::string& text, const std::string& writter, const std::string& date)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onEditText", id, itemId, maxLength, text, writter, date);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processEditList(int listId, int id, const std::string& text)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onEditList", listId, id, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processQuestLog(const std::vector<std::tuple<int, std::string, bool>>& questList)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onQuestLog", questList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::processQuestLine(int questId, const std::vector<std::tuple<std::string, std::string>>& questMissions)
|
|
|
|
{
|
|
|
|
g_lua.callGlobalField("g_game", "onQuestLine", questId, questMissions);
|
|
|
|
}
|
|
|
|
|
2012-01-07 06:10:02 +01:00
|
|
|
void Game::processAttackCancel()
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(isAttacking())
|
|
|
|
setAttackingCreature(nullptr);
|
2012-01-07 06:10:02 +01:00
|
|
|
}
|
|
|
|
|
2012-01-09 06:23:39 +01:00
|
|
|
void Game::processWalkCancel(Otc::Direction direction)
|
|
|
|
{
|
2012-01-19 05:12:53 +01:00
|
|
|
m_localPlayer->cancelWalk(direction);
|
2012-01-09 06:23:39 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldHost, int worldPort, const std::string& characterName)
|
|
|
|
{
|
2012-03-18 21:59:00 +01:00
|
|
|
if(m_protocolGame || isOnline()) {
|
|
|
|
logTraceError("unable to login into a world while already online or logging");
|
|
|
|
return;
|
|
|
|
}
|
2012-02-08 22:23:15 +01:00
|
|
|
m_protocolGame = ProtocolGamePtr(new ProtocolGame);
|
|
|
|
m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-18 21:59:00 +01:00
|
|
|
//m_protocolGame->sendLogout();
|
2012-02-08 22:23:15 +01:00
|
|
|
processDisconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::safeLogout()
|
|
|
|
{
|
|
|
|
if(!isOnline())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_protocolGame->sendLogout();
|
|
|
|
}
|
|
|
|
|
2011-08-28 18:02:26 +02:00
|
|
|
void Game::walk(Otc::Direction direction)
|
2011-08-17 06:45:55 +02:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction())
|
2011-11-03 17:26:17 +01:00
|
|
|
return;
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
if(isFollowing())
|
2012-01-15 22:19:52 +01:00
|
|
|
cancelFollow();
|
|
|
|
|
|
|
|
if(!m_localPlayer->canWalk(direction))
|
2012-01-07 23:24:29 +01:00
|
|
|
return;
|
2012-01-05 15:24:38 +01:00
|
|
|
|
2012-02-02 22:20:34 +01:00
|
|
|
// only do prewalks to walkable tiles
|
2012-01-30 19:18:10 +01:00
|
|
|
TilePtr toTile = g_map.getTile(m_localPlayer->getPosition().translatedToDirection(direction));
|
2012-01-20 16:00:24 +01:00
|
|
|
if(toTile && toTile->isWalkable())
|
|
|
|
m_localPlayer->preWalk(direction);
|
|
|
|
else
|
|
|
|
m_localPlayer->lockWalk();
|
|
|
|
|
2012-01-15 22:19:52 +01:00
|
|
|
forceWalk(direction);
|
|
|
|
}
|
2011-08-17 06:45:55 +02:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::walkPath(const std::vector<Otc::Direction>& dir)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(isFollowing())
|
|
|
|
cancelFollow();
|
|
|
|
|
|
|
|
m_protocolGame->sendWalkPath(dir);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-02-08 22:23:15 +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-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || !thing || thing->getPosition() == toPos || count <= 0)
|
2012-01-13 01:31:39 +01:00
|
|
|
return;
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
m_localPlayer->lockWalk();
|
|
|
|
|
|
|
|
m_protocolGame->sendMove(thing->getPosition(), thing->getId(), thing->getStackpos(), toPos, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::rotate(const ThingPtr& thing)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction() || !thing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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
|
|
|
|
pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
|
|
|
|
|
2012-01-19 05:12:53 +01:00
|
|
|
m_localPlayer->lockWalk();
|
|
|
|
|
2012-02-07 04:33:36 +01:00
|
|
|
m_protocolGame->sendUseItem(pos, thing->getId(), thing->getStackpos(), 0);
|
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-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || !g_thingsType.isValidItemId(itemId))
|
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_localPlayer->lockWalk();
|
|
|
|
|
|
|
|
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
|
|
|
|
pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
|
2012-01-19 05:12:53 +01:00
|
|
|
|
2012-02-07 04:33:36 +01:00
|
|
|
m_localPlayer->lockWalk();
|
2012-01-17 23:48:31 +01:00
|
|
|
|
2012-02-07 04:33:36 +01:00
|
|
|
if(CreaturePtr creature = toThing->asCreature())
|
|
|
|
m_protocolGame->sendUseOnCreature(pos, item->getId(), item->getStackpos(), creature->getId());
|
|
|
|
else
|
2012-02-08 22:23:15 +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-19 05:12:53 +01:00
|
|
|
m_localPlayer->lockWalk();
|
|
|
|
|
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-02-07 04:33:36 +01:00
|
|
|
if(CreaturePtr creature = toThing->asCreature())
|
2012-01-17 23:48:31 +01:00
|
|
|
m_protocolGame->sendUseOnCreature(pos, itemId, 0, creature->getId());
|
2012-02-07 04:33:36 +01:00
|
|
|
else
|
2012-02-08 22:23:15 +01:00
|
|
|
m_protocolGame->sendUseItemWith(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackpos());
|
2012-01-17 23:28:55 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::open(const ItemPtr& item, int containerId)
|
2012-01-20 02:12:26 +01:00
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || !item)
|
2012-01-20 02:12:26 +01:00
|
|
|
return;
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackpos(), containerId);
|
2012-01-20 02:12:26 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::upContainer(int containerId)
|
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-02-08 22:23:15 +01:00
|
|
|
m_protocolGame->sendUpContainer(containerId);
|
2012-02-08 00:06:52 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::refreshContainer()
|
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-02-08 22:23:15 +01:00
|
|
|
m_protocolGame->sendRefreshContainer();
|
2012-02-08 00:06:52 +01:00
|
|
|
}
|
|
|
|
|
2012-01-04 14:02:35 +01:00
|
|
|
void Game::attack(const CreaturePtr& creature)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || creature == m_localPlayer || creature == m_attackingCreature)
|
2012-01-04 14:02:35 +01:00
|
|
|
return;
|
|
|
|
|
2012-01-19 05:12:53 +01:00
|
|
|
m_localPlayer->lockWalk();
|
|
|
|
|
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);
|
|
|
|
m_protocolGame->sendAttack(creature ? creature->getId() : 0);
|
2012-01-05 15:24:38 +01:00
|
|
|
}
|
|
|
|
|
2012-01-04 14:02:35 +01:00
|
|
|
void Game::follow(const CreaturePtr& creature)
|
|
|
|
{
|
2012-02-08 22:23:15 +01:00
|
|
|
if(!canPerformGameAction() || creature == m_localPlayer || creature == m_followingCreature)
|
2012-01-04 14:02:35 +01:00
|
|
|
return;
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
m_localPlayer->lockWalk();
|
|
|
|
|
|
|
|
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);
|
|
|
|
m_protocolGame->sendFollow(creature ? creature->getId() : 0);
|
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;
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
m_localPlayer->lockWalk();
|
2012-01-04 14:02:35 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
setAttackingCreature(nullptr);
|
|
|
|
setFollowingCreature(nullptr);
|
|
|
|
m_protocolGame->sendCancelAttackAndFollow();
|
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-02-03 01:25:18 +01:00
|
|
|
talkChannel(Otc::SpeakSay, 0, message);
|
2012-01-07 22:10:06 +01:00
|
|
|
}
|
|
|
|
|
2012-02-03 01:25:18 +01:00
|
|
|
void Game::talkChannel(Otc::SpeakType speakType, 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-02-03 01:25:18 +01:00
|
|
|
m_protocolGame->sendTalk(speakType, channelId, "", message);
|
2011-11-03 17:26:17 +01:00
|
|
|
}
|
|
|
|
|
2012-02-03 01:25:18 +01:00
|
|
|
void Game::talkPrivate(Otc::SpeakType speakType, 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-02-03 01:25:18 +01:00
|
|
|
m_protocolGame->sendTalk(speakType, 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;
|
|
|
|
m_protocolGame->sendShareExperience(active, 0);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
m_protocolGame->sendRemoveVip(playerId);
|
|
|
|
}
|
2012-01-06 20:25:27 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
void Game::setChaseMode(Otc::ChaseModes chaseMode)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_chaseMode = chaseMode;
|
|
|
|
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::setFightMode(Otc::FightModes fightMode)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_fightMode = fightMode;
|
|
|
|
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::setSafeFight(bool on)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_safeFight = on;
|
|
|
|
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
m_protocolGame->sendBuyItem(item->getId(), item->getCount(), amount, ignoreCapacity, buyWithBackpack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::sellItem(const ItemPtr& item, int amount, bool ignoreEquipped)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction() || !item)
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendSellItem(item->getId(), item->getCount(), amount, ignoreEquipped);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::closeNpcTrade()
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendCloseNpcTrade();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::requestTrade(const ItemPtr& item, const CreaturePtr& creature)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendRequestTrade(item->getPosition(), item->getId(), item->getStackpos(), creature->getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::editList(int listId, uint id, const std::string& text)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendEditList(listId, id, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::requestQuestLog()
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendRequestQuestLog();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::requestQuestLine(int questId)
|
|
|
|
{
|
|
|
|
if(!canPerformGameAction())
|
|
|
|
return;
|
|
|
|
m_protocolGame->sendRequestQuestLine(questId);
|
|
|
|
}
|
|
|
|
|
2012-01-06 20:25:27 +01:00
|
|
|
bool Game::checkBotProtection()
|
|
|
|
{
|
2012-02-05 23:42:35 +01: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-01-06 20:25:27 +01:00
|
|
|
if(g_lua.isInCppCallback() && !g_ui.isOnInputEvent()) {
|
2012-01-07 02:48:16 +01:00
|
|
|
logError("caught a lua call to a bot protected game function, the call was canceled");
|
2012-01-06 20:25:27 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
2012-02-08 22:23:15 +01:00
|
|
|
|
|
|
|
bool Game::canPerformGameAction()
|
|
|
|
{
|
|
|
|
// we can only perform game actions if we meet these conditions:
|
|
|
|
// - the local player exists
|
|
|
|
// - the local player is known
|
|
|
|
// - the local player is not dead
|
|
|
|
// - we have a game protocol
|
|
|
|
// - the game protocol is connected
|
|
|
|
// - its not a bot action
|
|
|
|
return m_localPlayer && m_localPlayer->isKnown() && !m_dead && m_protocolGame && m_protocolGame->isConnected() && checkBotProtection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::setAttackingCreature(const CreaturePtr& creature)
|
|
|
|
{
|
|
|
|
if(m_attackingCreature) {
|
|
|
|
m_attackingCreature->hideStaticSquare();
|
|
|
|
m_attackingCreature = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(creature) {
|
|
|
|
creature->showStaticSquare(Fw::red);
|
|
|
|
m_attackingCreature = creature;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_lua.callGlobalField("g_game", "onAttackingCreatureChange", creature);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::setFollowingCreature(const CreaturePtr& creature)
|
|
|
|
{
|
|
|
|
if(m_followingCreature) {
|
|
|
|
m_followingCreature->hideStaticSquare();
|
|
|
|
m_followingCreature = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(creature) {
|
|
|
|
creature->showStaticSquare(Fw::green);
|
|
|
|
m_followingCreature = creature;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_lua.callGlobalField("g_game", "onFollowingCreatureChange", creature);
|
|
|
|
}
|