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
|
|
|
#ifndef GAME_H
|
|
|
|
#define GAME_H
|
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
#include "declarations.h"
|
2012-07-14 03:10:24 +02:00
|
|
|
#include "item.h"
|
2012-07-29 14:04:47 +02:00
|
|
|
#include "animatedtext.h"
|
|
|
|
#include "effect.h"
|
2012-07-29 05:34:40 +02:00
|
|
|
#include "creature.h"
|
|
|
|
#include "container.h"
|
|
|
|
#include "protocolgame.h"
|
|
|
|
#include "localplayer.h"
|
2012-07-14 03:10:24 +02:00
|
|
|
#include "outfit.h"
|
2012-01-09 06:23:39 +01:00
|
|
|
#include <framework/core/timer.h>
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-08-01 09:49:09 +02:00
|
|
|
#include <bitset>
|
|
|
|
|
2012-04-27 08:30:54 +02:00
|
|
|
typedef std::tuple<std::string, bool> Vip;
|
|
|
|
|
2012-06-22 05:14:13 +02:00
|
|
|
//@bindsingleton g_game
|
2011-08-15 16:11:24 +02:00
|
|
|
class Game
|
|
|
|
{
|
|
|
|
public:
|
2012-02-08 22:23:15 +01:00
|
|
|
Game();
|
|
|
|
|
2012-07-30 10:51:03 +02:00
|
|
|
void terminate();
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
private:
|
|
|
|
void resetGameStates();
|
|
|
|
|
|
|
|
protected:
|
2011-08-29 20:38:01 +02:00
|
|
|
void processConnectionError(const boost::system::error_code& error);
|
2012-02-08 22:23:15 +01:00
|
|
|
void processDisconnect();
|
|
|
|
void processPing();
|
2012-07-30 12:59:08 +02:00
|
|
|
void processPingBack(int elapsed);
|
2012-02-08 22:23:15 +01:00
|
|
|
|
|
|
|
void processLoginError(const std::string& error);
|
|
|
|
void processLoginAdvice(const std::string& message);
|
|
|
|
void processLoginWait(const std::string& message, int time);
|
|
|
|
|
2012-07-26 08:10:28 +02:00
|
|
|
void processGameStart();
|
2012-02-08 22:23:15 +01:00
|
|
|
void processGameEnd();
|
|
|
|
void processDeath(int penality);
|
|
|
|
|
2012-05-01 00:24:50 +02:00
|
|
|
void processGMActions(const std::vector<uint8>& actions);
|
2011-11-10 06:29:25 +01:00
|
|
|
void processInventoryChange(int slot, const ItemPtr& item);
|
2012-07-26 08:10:28 +02:00
|
|
|
void processAttackCancel(uint seq);
|
2012-01-09 06:23:39 +01:00
|
|
|
void processWalkCancel(Otc::Direction direction);
|
2011-08-30 17:12:57 +02:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
// message related
|
2012-07-26 11:12:20 +02:00
|
|
|
void processTextMessage(Otc::MessageMode mode, const std::string& text);
|
|
|
|
void processTalk(const std::string& name, int level, Otc::MessageMode mode, const std::string& text, int channelId, const Position& pos);
|
2012-02-09 04:45:19 +01:00
|
|
|
|
|
|
|
// container related
|
2012-05-12 06:52:16 +02:00
|
|
|
void processOpenContainer(int containerId, const ItemPtr& containerItem, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items);
|
2012-02-09 04:45:19 +01:00
|
|
|
void processCloseContainer(int containerId);
|
|
|
|
void processContainerAddItem(int containerId, const ItemPtr& item);
|
|
|
|
void processContainerUpdateItem(int containerId, int slot, const ItemPtr& item);
|
|
|
|
void processContainerRemoveItem(int containerId, int slot);
|
|
|
|
|
|
|
|
// channel related
|
2012-07-15 13:49:28 +02:00
|
|
|
void processChannelList(const std::vector<std::tuple<int, std::string> >& channelList);
|
2012-02-09 04:45:19 +01:00
|
|
|
void processOpenChannel(int channelId, const std::string& name);
|
|
|
|
void processOpenPrivateChannel(const std::string& name);
|
|
|
|
void processOpenOwnPrivateChannel(int channelId, const std::string& name);
|
|
|
|
void processCloseChannel(int channelId);
|
|
|
|
|
2012-05-01 00:24:50 +02:00
|
|
|
// rule violations
|
|
|
|
void processRuleViolationChannel(int channelId);
|
|
|
|
void processRuleViolationRemove(const std::string& name);
|
|
|
|
void processRuleViolationCancel(const std::string& name);
|
|
|
|
void processRuleViolationLock();
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
// vip related
|
|
|
|
void processVipAdd(uint id, const std::string& name, bool online);
|
|
|
|
void processVipStateChange(uint id, bool online);
|
|
|
|
|
2012-05-01 00:24:50 +02:00
|
|
|
// tutorial hint
|
|
|
|
void processTutorialHint(int id);
|
|
|
|
void processAutomapFlag(const Position& pos, int icon, const std::string& message);
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
// outfit
|
2012-07-15 13:49:28 +02:00
|
|
|
void 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
|
|
|
|
|
|
|
// npc trade
|
2012-07-15 13:49:28 +02:00
|
|
|
void processOpenNpcTrade(const std::vector<std::tuple<ItemPtr, std::string, int, int, int> >& items);
|
|
|
|
void processPlayerGoods(int money, const std::vector<std::tuple<ItemPtr, int> >& goods);
|
2012-02-09 04:45:19 +01:00
|
|
|
void processCloseNpcTrade();
|
|
|
|
|
|
|
|
// player trade
|
2012-05-01 04:59:17 +02:00
|
|
|
void processOwnTrade(const std::string& name, const std::vector<ItemPtr>& items);
|
|
|
|
void processCounterTrade(const std::string& name, const std::vector<ItemPtr>& items);
|
2012-02-09 04:45:19 +01:00
|
|
|
void processCloseTrade();
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
// edit text/list
|
2012-05-01 02:53:02 +02:00
|
|
|
void processEditText(uint id, int itemId, int maxLength, const std::string& text, const std::string& writter, const std::string& date);
|
|
|
|
void processEditList(uint id, int doorId, const std::string& text);
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
// questlog
|
2012-07-15 13:49:28 +02:00
|
|
|
void processQuestLog(const std::vector<std::tuple<int, std::string, bool> >& questList);
|
|
|
|
void processQuestLine(int questId, const std::vector<std::tuple<std::string, std::string> >& questMissions);
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-11-27 14:48:48 +01:00
|
|
|
// modal dialogs >= 970
|
|
|
|
void processModalDialog(uint32 id, std::string title, std::string message, int enterId, std::string enterText, int escapeId, std::string escapeText, std::vector<std::tuple<int, std::string> > choiceList);
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
friend class ProtocolGame;
|
|
|
|
friend class Map;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// login related
|
2012-06-20 07:41:00 +02:00
|
|
|
void loginWorld(const std::string& account, const std::string& password, const std::string& worldName, const std::string& worldHost, int worldPort, const std::string& characterName);
|
2012-02-08 22:23:15 +01:00
|
|
|
void cancelLogin();
|
|
|
|
void forceLogout();
|
|
|
|
void safeLogout();
|
|
|
|
|
2012-01-14 06:54:20 +01:00
|
|
|
// walk related
|
2012-08-29 17:41:04 +02:00
|
|
|
bool walk(Otc::Direction direction);
|
2012-03-23 21:36:58 +01:00
|
|
|
void autoWalk(const std::vector<Otc::Direction>& dirs);
|
2012-01-15 22:19:52 +01:00
|
|
|
void forceWalk(Otc::Direction direction);
|
2011-08-28 18:02:26 +02:00
|
|
|
void turn(Otc::Direction direction);
|
2012-02-08 22:23:15 +01:00
|
|
|
void stop();
|
2012-01-14 06:54:20 +01:00
|
|
|
|
|
|
|
// item related
|
2012-01-03 21:41:00 +01:00
|
|
|
void look(const ThingPtr& thing);
|
2012-02-08 22:23:15 +01:00
|
|
|
void move(const ThingPtr &thing, const Position& toPos, int count);
|
2012-04-26 02:15:48 +02:00
|
|
|
void moveToParentContainer(const ThingPtr& thing, int count);
|
2012-02-08 22:23:15 +01:00
|
|
|
void rotate(const ThingPtr& thing);
|
2012-01-03 23:27:31 +01:00
|
|
|
void use(const ThingPtr& thing);
|
2012-02-07 04:33:36 +01:00
|
|
|
void useWith(const ItemPtr& fromThing, const ThingPtr& toThing);
|
|
|
|
void useInventoryItem(int itemId);
|
|
|
|
void useInventoryItemWith(int itemId, const ThingPtr& toThing);
|
2012-01-14 06:54:20 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
// container related
|
2012-04-03 01:09:47 +02:00
|
|
|
void open(const ItemPtr& item, const ContainerPtr& previousContainer);
|
|
|
|
void openParent(const ContainerPtr& container);
|
|
|
|
void close(const ContainerPtr& container);
|
2012-02-08 22:23:15 +01:00
|
|
|
void refreshContainer();
|
2012-02-08 00:06:52 +01:00
|
|
|
|
2012-01-14 06:54:20 +01:00
|
|
|
// attack/follow related
|
2012-08-17 19:43:12 +02:00
|
|
|
void attack(CreaturePtr creature);
|
2012-02-08 22:23:15 +01:00
|
|
|
void cancelAttack() { attack(nullptr); }
|
2012-08-17 19:43:12 +02:00
|
|
|
void follow(CreaturePtr creature);
|
2012-02-08 22:23:15 +01:00
|
|
|
void cancelFollow() { follow(nullptr); }
|
|
|
|
void cancelAttackAndFollow();
|
2012-01-14 06:54:20 +01:00
|
|
|
|
|
|
|
// talk related
|
2012-01-07 22:10:06 +01:00
|
|
|
void talk(const std::string& message);
|
2012-07-26 11:12:20 +02:00
|
|
|
void talkChannel(Otc::MessageMode mode, int channelId, const std::string& message);
|
|
|
|
void talkPrivate(Otc::MessageMode mode, const std::string& receiver, const std::string& message);
|
2012-02-08 22:23:15 +01:00
|
|
|
|
|
|
|
// channel related
|
2012-02-02 23:29:44 +01:00
|
|
|
void openPrivateChannel(const std::string& receiver);
|
2012-01-14 06:54:20 +01:00
|
|
|
void requestChannels();
|
|
|
|
void joinChannel(int channelId);
|
|
|
|
void leaveChannel(int channelId);
|
|
|
|
void closeNpcChannel();
|
2012-02-08 22:23:15 +01:00
|
|
|
void openOwnChannel();
|
|
|
|
void inviteToOwnChannel(const std::string& name);
|
|
|
|
void excludeFromOwnChannel(const std::string& name);
|
2012-01-14 06:54:20 +01:00
|
|
|
|
|
|
|
// party related
|
2012-01-11 00:38:32 +01:00
|
|
|
void partyInvite(int creatureId);
|
|
|
|
void partyJoin(int creatureId);
|
|
|
|
void partyRevokeInvitation(int creatureId);
|
|
|
|
void partyPassLeadership(int creatureId);
|
|
|
|
void partyLeave();
|
|
|
|
void partyShareExperience(bool active);
|
2012-01-14 06:54:20 +01:00
|
|
|
|
|
|
|
// outfit related
|
2012-01-14 02:37:15 +01:00
|
|
|
void requestOutfit();
|
2012-02-08 22:23:15 +01:00
|
|
|
void changeOutfit(const Outfit& outfit);
|
2012-01-14 06:54:20 +01:00
|
|
|
|
|
|
|
// vip related
|
2012-01-04 15:30:28 +01:00
|
|
|
void addVip(const std::string& name);
|
|
|
|
void removeVip(int playerId);
|
2012-01-14 06:54:20 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
// fight modes related
|
|
|
|
void setChaseMode(Otc::ChaseModes chaseMode);
|
|
|
|
void setFightMode(Otc::FightModes fightMode);
|
|
|
|
void setSafeFight(bool on);
|
|
|
|
Otc::ChaseModes getChaseMode() { return m_chaseMode; }
|
|
|
|
Otc::FightModes getFightMode() { return m_fightMode; }
|
|
|
|
bool isSafeFight() { return m_safeFight; }
|
|
|
|
|
|
|
|
// npc trade related
|
2012-02-09 04:45:19 +01:00
|
|
|
void inspectNpcTrade(const ItemPtr& item);
|
|
|
|
void buyItem(const ItemPtr& item, int amount, bool ignoreCapacity, bool buyWithBackpack);
|
|
|
|
void sellItem(const ItemPtr& item, int amount, bool ignoreEquipped);
|
|
|
|
void closeNpcTrade();
|
2012-02-08 22:23:15 +01:00
|
|
|
|
|
|
|
// player trade related
|
2012-02-09 04:45:19 +01:00
|
|
|
void requestTrade(const ItemPtr& item, const CreaturePtr& creature);
|
|
|
|
void inspectTrade(bool counterOffer, int index);
|
|
|
|
void acceptTrade();
|
|
|
|
void rejectTrade();
|
2012-02-08 22:23:15 +01:00
|
|
|
|
|
|
|
// house window and editable items related
|
2012-02-09 04:45:19 +01:00
|
|
|
void editText(uint id, const std::string& text);
|
2012-05-01 02:53:02 +02:00
|
|
|
void editList(uint id, int doorId, const std::string& text);
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-05-01 00:24:50 +02:00
|
|
|
// reports
|
|
|
|
void reportBug(const std::string& comment);
|
|
|
|
void reportRuleVilation(const std::string& target, int reason, int action, const std::string& comment, const std::string& statement, int statementId, bool ipBanishment);
|
|
|
|
void debugReport(const std::string& a, const std::string& b, const std::string& c, const std::string& d);
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
// questlog related
|
2012-02-09 04:45:19 +01:00
|
|
|
void requestQuestLog();
|
|
|
|
void requestQuestLine(int questId);
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-05-12 13:55:22 +02:00
|
|
|
// 870 only
|
|
|
|
void equipItem(const ItemPtr& item);
|
|
|
|
void mount(bool mount);
|
|
|
|
|
|
|
|
// 910 only
|
2012-07-30 17:08:21 +02:00
|
|
|
void requestItemInfo(const ItemPtr& item, int index);
|
2012-11-27 14:48:48 +01:00
|
|
|
|
|
|
|
// >= 970 modal dialog
|
|
|
|
void answerModalDialog(int dialog, int button, int choice);
|
|
|
|
|
2012-05-12 13:55:22 +02:00
|
|
|
//void reportRuleViolation2();
|
2012-07-30 12:59:08 +02:00
|
|
|
void ping();
|
2012-05-12 13:55:22 +02:00
|
|
|
|
2012-05-29 00:04:44 +02:00
|
|
|
// dynamic support for game features
|
|
|
|
void enableFeature(Otc::GameFeature feature) { m_features.set(feature, true); }
|
|
|
|
void disableFeature(Otc::GameFeature feature) { m_features.set(feature, false); }
|
2012-07-26 18:41:13 +02:00
|
|
|
void setFeature(Otc::GameFeature feature, bool enabled) { m_features.set(feature, enabled); }
|
2012-05-29 00:04:44 +02:00
|
|
|
bool getFeature(Otc::GameFeature feature) { return m_features.test(feature); }
|
|
|
|
|
2012-07-26 08:10:28 +02:00
|
|
|
void setClientVersion(int version);
|
2012-07-31 06:09:55 +02:00
|
|
|
int getClientVersion() { return m_clientVersion; }
|
2012-05-29 00:04:44 +02:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
bool canPerformGameAction();
|
2012-01-06 20:25:27 +01:00
|
|
|
bool checkBotProtection();
|
|
|
|
|
2012-07-26 08:10:28 +02:00
|
|
|
bool isOnline() { return m_online; }
|
2012-01-07 06:10:02 +01:00
|
|
|
bool isDead() { return m_dead; }
|
2012-02-08 22:23:15 +01:00
|
|
|
bool isAttacking() { return !!m_attackingCreature; }
|
|
|
|
bool isFollowing() { return !!m_followingCreature; }
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-08-25 21:11:54 +02:00
|
|
|
int getPing() { return m_ping; }
|
2012-03-18 14:34:39 +01:00
|
|
|
ContainerPtr getContainer(int index) { return m_containers[index]; }
|
2012-04-03 01:09:47 +02:00
|
|
|
std::map<int, ContainerPtr> getContainers() { return m_containers; }
|
2012-04-27 08:30:54 +02:00
|
|
|
std::map<int, Vip> getVips() { return m_vips; }
|
2012-02-08 22:23:15 +01:00
|
|
|
CreaturePtr getAttackingCreature() { return m_attackingCreature; }
|
|
|
|
CreaturePtr getFollowingCreature() { return m_followingCreature; }
|
2012-07-26 08:10:28 +02:00
|
|
|
void setServerBeat(int beat) { m_serverBeat = beat; }
|
2011-12-28 12:26:52 +01:00
|
|
|
int getServerBeat() { return m_serverBeat; }
|
2012-07-26 08:10:28 +02:00
|
|
|
void setCanReportBugs(bool enable) { m_canReportBugs = enable; }
|
|
|
|
bool canReportBugs() { return m_canReportBugs; }
|
2011-08-15 23:02:52 +02:00
|
|
|
LocalPlayerPtr getLocalPlayer() { return m_localPlayer; }
|
2011-08-16 02:30:31 +02:00
|
|
|
ProtocolGamePtr getProtocolGame() { return m_protocolGame; }
|
2012-06-04 02:28:19 +02:00
|
|
|
std::string getCharacterName() { return m_characterName; }
|
2012-03-29 21:25:04 +02:00
|
|
|
std::string getWorldName() { return m_worldName; }
|
2012-05-01 00:24:50 +02:00
|
|
|
std::vector<uint8> getGMActions() { return m_gmActions; }
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-08-10 02:36:52 +02:00
|
|
|
std::string formatCreatureName(const std::string &name);
|
2012-08-25 00:59:33 +02:00
|
|
|
int findEmptyContainerId();
|
2012-08-10 02:36:52 +02:00
|
|
|
|
2012-06-04 02:28:19 +02:00
|
|
|
protected:
|
|
|
|
void enableBotCall() { m_denyBotCall = false; }
|
|
|
|
void disableBotCall() { m_denyBotCall = true; }
|
|
|
|
|
2011-08-15 16:11:24 +02:00
|
|
|
private:
|
2012-02-08 22:23:15 +01:00
|
|
|
void setAttackingCreature(const CreaturePtr& creature);
|
|
|
|
void setFollowingCreature(const CreaturePtr& creature);
|
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
LocalPlayerPtr m_localPlayer;
|
2012-02-08 22:23:15 +01:00
|
|
|
CreaturePtr m_attackingCreature;
|
|
|
|
CreaturePtr m_followingCreature;
|
2011-08-15 16:11:24 +02:00
|
|
|
ProtocolGamePtr m_protocolGame;
|
2012-03-18 14:34:39 +01:00
|
|
|
std::map<int, ContainerPtr> m_containers;
|
2012-04-27 08:30:54 +02:00
|
|
|
std::map<int, Vip> m_vips;
|
|
|
|
|
2012-07-26 08:10:28 +02:00
|
|
|
bool m_online;
|
2012-05-16 22:09:37 +02:00
|
|
|
bool m_denyBotCall;
|
2012-01-07 06:10:02 +01:00
|
|
|
bool m_dead;
|
2011-12-28 12:26:52 +01:00
|
|
|
int m_serverBeat;
|
2012-08-25 21:11:54 +02:00
|
|
|
int m_ping;
|
2012-07-26 08:10:28 +02:00
|
|
|
uint m_seq;
|
2012-02-08 00:06:52 +01:00
|
|
|
Otc::FightModes m_fightMode;
|
|
|
|
Otc::ChaseModes m_chaseMode;
|
|
|
|
bool m_safeFight;
|
2012-05-01 00:24:50 +02:00
|
|
|
bool m_canReportBugs;
|
|
|
|
std::vector<uint8> m_gmActions;
|
2012-06-04 02:28:19 +02:00
|
|
|
std::string m_characterName;
|
2012-03-29 21:25:04 +02:00
|
|
|
std::string m_worldName;
|
2012-05-29 00:04:44 +02:00
|
|
|
std::bitset<Otc::LastGameFeature> m_features;
|
2012-08-25 21:11:54 +02:00
|
|
|
ScheduledEventPtr m_pingEvent;
|
2012-07-31 06:09:55 +02:00
|
|
|
int m_clientVersion;
|
2011-08-15 16:11:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern Game g_game;
|
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
#endif
|