reaname and cleanup many stuff

This commit is contained in:
Eduardo Bart
2012-02-08 19:23:15 -02:00
parent d4ce3c5354
commit 175f97b98f
31 changed files with 1274 additions and 1001 deletions

View File

@@ -107,12 +107,19 @@ protected:
Outfit m_outfit;
Light m_light;
int m_speed;
uint8 m_skull, m_shield, m_emblem;
TexturePtr m_skullTexture, m_shieldTexture, m_emblemTexture;
bool m_showShieldTexture, m_shieldBlink;
uint8 m_skull;
uint8 m_shield;
uint8 m_emblem;
TexturePtr m_skullTexture;
TexturePtr m_shieldTexture;
TexturePtr m_emblemTexture;
bool m_showShieldTexture;
bool m_shieldBlink;
bool m_passable;
Color m_timedSquareColor, m_staticSquareColor;
bool m_showTimedSquare, m_showStaticSquare;
Color m_timedSquareColor;
Color m_staticSquareColor;
bool m_showTimedSquare;
bool m_showStaticSquare;
FontPtr m_informationFont;
Color m_informationColor;

View File

@@ -33,99 +33,117 @@
Game g_game;
void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldHost, int worldPort, const std::string& characterName)
Game::Game()
{
resetGameStates();
}
void Game::resetGameStates()
{
m_dead = false;
m_protocolGame = ProtocolGamePtr(new ProtocolGame);
m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName);
}
void Game::cancelLogin()
{
if(m_protocolGame)
m_protocolGame->sendLogout();
processLogout();
}
void Game::forceLogout()
{
if(!isOnline())
return;
m_protocolGame->sendLogout();
processLogout();
}
void Game::safeLogout()
{
if(!isOnline())
return;
m_protocolGame->sendLogout();
}
void Game::processLoginError(const std::string& error)
{
g_lua.callGlobalField("Game", "onLoginError", error);
m_serverBeat = 50;
m_fightMode = Otc::FightBalanced;
m_chaseMode = Otc::DontChase;
m_safeFight = true;
m_followingCreature = nullptr;
m_attackingCreature = nullptr;
}
void Game::processConnectionError(const boost::system::error_code& error)
{
// 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("Game", "onConnectionError", error.message());
g_lua.callGlobalField("g_game", "onConnectionError", error.message());
processLogout();
processDisconnect();
}
}
void Game::processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat)
{
m_localPlayer = localPlayer;
m_serverBeat = serverBeat;
// synchronize fight modes with the server
m_fightMode = Otc::FightBalanced;
m_chaseMode = Otc::DontChase;
m_safeFight = true;
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
// NOTE: the entire map description and local player informations is not known yet
g_lua.callGlobalField("Game", "onGameStart");
}
void Game::processLogin()
{
if(!isOnline())
return;
g_lua.callGlobalField("Game", "onLogin", m_localPlayer);
}
void Game::processLogout()
void Game::processDisconnect()
{
if(isOnline()) {
g_lua.callGlobalField("Game", "onLogout", m_localPlayer);
// only process logout event if a previous the player is known
if(m_localPlayer->isKnown())
processLogout();
m_localPlayer = nullptr;
g_lua.callGlobalField("Game", "onGameEnd");
processGameEnd();
}
if(m_protocolGame) {
m_protocolGame->disconnect();
m_protocolGame = nullptr;
}
//g_map.save();
}
void Game::processDeath()
void Game::processLoginError(const std::string& error)
{
g_lua.callGlobalField("g_game", "onLoginError", error);
}
void Game::processLoginAdvice(const std::string& message)
{
g_lua.callGlobalField("Game," "onLoginAdvice", message);
}
void Game::processLoginWait(const std::string& message, int time)
{
g_lua.callGlobalField("g_game", "onLoginWait", message, time);
}
void Game::processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat)
{
// reset the new game state
resetGameStates();
m_localPlayer = localPlayer;
m_serverBeat = serverBeat;
// synchronize fight modes with the server
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
// NOTE: the entire map description and local player informations is not known yet
g_lua.callGlobalField("g_game", "onGameStart");
}
void Game::processGameEnd()
{
g_lua.callGlobalField("g_game", "onGameEnd");
// reset game states
resetGameStates();
}
void Game::processLogin()
{
// the game could be offline if the login was canceled
if(!isOnline())
return;
// by now the local player must be known
g_lua.callGlobalField("g_game", "onLogin", m_localPlayer);
}
void Game::processLogout()
{
g_lua.callGlobalField("g_game", "onLogout", m_localPlayer);
}
void Game::processDeath(int penality)
{
m_dead = true;
m_localPlayer->stopWalk();
g_lua.callGlobalField("Game","onDeath");
g_lua.callGlobalField("g_game","onDeath", penality);
}
void Game::processPing()
{
m_protocolGame->sendPingResponse();
g_lua.callGlobalField("g_game", "onPing");
}
void Game::processPlayerStats(double health, double maxHealth,
@@ -139,7 +157,7 @@ void Game::processPlayerStats(double health, double maxHealth,
m_localPlayer->getMaxHealth() != maxHealth) {
m_localPlayer->setStatistic(Otc::Health, health);
m_localPlayer->setStatistic(Otc::MaxHealth, maxHealth);
g_lua.callGlobalField("Game", "onHealthChange", health, maxHealth);
g_lua.callGlobalField("g_game", "onHealthChange", health, maxHealth);
// cannot walk while dying
if(health == 0) {
@@ -151,49 +169,49 @@ void Game::processPlayerStats(double health, double maxHealth,
if(m_localPlayer->getStatistic(Otc::FreeCapacity) != freeCapacity) {
m_localPlayer->setStatistic(Otc::FreeCapacity, freeCapacity);
g_lua.callGlobalField("Game", "onFreeCapacityChange", freeCapacity);
g_lua.callGlobalField("g_game", "onFreeCapacityChange", freeCapacity);
}
if(m_localPlayer->getStatistic(Otc::Experience) != experience) {
m_localPlayer->setStatistic(Otc::Experience, experience);
g_lua.callGlobalField("Game", "onExperienceChange", experience);
g_lua.callGlobalField("g_game", "onExperienceChange", experience);
}
if(m_localPlayer->getStatistic(Otc::Level) != level ||
m_localPlayer->getStatistic(Otc::LevelPercent) != levelPercent) {
m_localPlayer->setStatistic(Otc::Level, level);
m_localPlayer->setStatistic(Otc::LevelPercent, levelPercent);
g_lua.callGlobalField("Game", "onLevelChange", level, levelPercent);
g_lua.callGlobalField("g_game", "onLevelChange", level, levelPercent);
}
if(m_localPlayer->getStatistic(Otc::Mana) != mana ||
m_localPlayer->getStatistic(Otc::MaxMana) != maxMana) {
m_localPlayer->setStatistic(Otc::Mana, mana);
m_localPlayer->setStatistic(Otc::MaxMana, maxMana);
g_lua.callGlobalField("Game", "onManaChange", mana, maxMana);
g_lua.callGlobalField("g_game", "onManaChange", mana, maxMana);
}
if(m_localPlayer->getStatistic(Otc::MagicLevel) != magicLevel ||
m_localPlayer->getStatistic(Otc::MagicLevelPercent) != magicLevelPercent) {
m_localPlayer->setStatistic(Otc::MagicLevel, magicLevel);
m_localPlayer->setStatistic(Otc::MagicLevelPercent, magicLevelPercent);
g_lua.callGlobalField("Game", "onMagicLevelChange", magicLevel, magicLevelPercent);
g_lua.callGlobalField("g_game", "onMagicLevelChange", magicLevel, magicLevelPercent);
}
if(m_localPlayer->getStatistic(Otc::Soul) != soul) {
m_localPlayer->setStatistic(Otc::Soul, soul);
g_lua.callGlobalField("Game", "onSoulChange", soul);
g_lua.callGlobalField("g_game", "onSoulChange", soul);
}
if(m_localPlayer->getStatistic(Otc::Stamina) != stamina) {
m_localPlayer->setStatistic(Otc::Stamina, stamina);
g_lua.callGlobalField("Game", "onStaminaChange", stamina);
g_lua.callGlobalField("g_game", "onStaminaChange", stamina);
}
}
void Game::processTextMessage(const std::string& type, const std::string& message)
{
g_lua.callGlobalField("Game","onTextMessage", type, message);
g_lua.callGlobalField("g_game","onTextMessage", type, message);
}
void Game::processCreatureSpeak(const std::string& name, int level, Otc::SpeakType type, const std::string& message, int channelId, const Position& creaturePos)
@@ -204,7 +222,12 @@ void Game::processCreatureSpeak(const std::string& name, int level, Otc::SpeakTy
g_map.addThing(staticText, creaturePos);
}
g_lua.callGlobalField("Game", "onCreatureSpeak", name, level, type, message, channelId, creaturePos);
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);
}
void Game::processContainerAddItem(int containerId, const ItemPtr& item)
@@ -212,7 +235,7 @@ void Game::processContainerAddItem(int containerId, const ItemPtr& item)
if(item)
item->setPosition(Position(65535, containerId + 0x40, 0));
g_lua.callGlobalField("Game", "onContainerAddItem", containerId, item);
g_lua.callGlobalField("g_game", "onContainerAddItem", containerId, item);
}
void Game::processInventoryChange(int slot, const ItemPtr& item)
@@ -220,7 +243,7 @@ void Game::processInventoryChange(int slot, const ItemPtr& item)
if(item)
item->setPosition(Position(65535, slot, 0));
g_lua.callGlobalField("Game","onInventoryChange", slot, item);
g_lua.callGlobalField("g_game","onInventoryChange", slot, item);
}
void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos)
@@ -235,14 +258,15 @@ void Game::processCreatureTeleport(const CreaturePtr& creature)
// stop walking on creature teleports
creature->stopWalk();
// locks the walk for a while when teleporting
if(creature == m_localPlayer)
m_localPlayer->lockWalk();
}
void Game::processAttackCancel()
{
if(m_localPlayer->isAttacking())
m_localPlayer->setAttackingCreature(nullptr);
if(isAttacking())
setAttackingCreature(nullptr);
}
void Game::processWalkCancel(Otc::Direction direction)
@@ -250,12 +274,44 @@ void Game::processWalkCancel(Otc::Direction direction)
m_localPlayer->cancelWalk(direction);
}
void Game::walk(Otc::Direction direction)
void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldHost, int worldPort, const std::string& characterName)
{
if(!isOnline() || !m_localPlayer->isKnown() || isDead() || !checkBotProtection())
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;
if(m_localPlayer->isFollowing())
m_protocolGame->sendLogout();
processDisconnect();
}
void Game::safeLogout()
{
if(!isOnline())
return;
m_protocolGame->sendLogout();
}
void Game::walk(Otc::Direction direction)
{
if(!canPerformGameAction())
return;
if(isFollowing())
cancelFollow();
if(!m_localPlayer->canWalk(direction))
@@ -271,9 +327,20 @@ void Game::walk(Otc::Direction direction)
forceWalk(direction);
}
void Game::walkPath(const std::vector<Otc::Direction>& dir)
{
if(!canPerformGameAction())
return;
if(isFollowing())
cancelFollow();
m_protocolGame->sendWalkPath(dir);
}
void Game::forceWalk(Otc::Direction direction)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
switch(direction) {
@@ -306,7 +373,7 @@ void Game::forceWalk(Otc::Direction direction)
void Game::turn(Otc::Direction direction)
{
if(!isOnline())
if(!canPerformGameAction())
return;
switch(direction) {
@@ -325,25 +392,46 @@ void Game::turn(Otc::Direction direction)
}
}
void Game::look(const ThingPtr& thing)
void Game::stop()
{
if(!isOnline() || !thing || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendLookAt(thing->getPosition(), thing->getId(), thing->getStackpos());
if(isFollowing())
cancelFollow();
m_protocolGame->sendStop();
}
void Game::open(const ItemPtr& item, int containerId)
void Game::look(const ThingPtr& thing)
{
if(!isOnline() || !item || !checkBotProtection())
if(!canPerformGameAction() || !thing)
return;
m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackpos(), containerId);
m_protocolGame->sendLook(thing->getPosition(), thing->getId(), thing->getStackpos());
}
void Game::move(const ThingPtr& thing, const Position& toPos, int count)
{
if(!canPerformGameAction() || !thing || thing->getPosition() == toPos || count <= 0)
return;
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());
}
void Game::use(const ThingPtr& thing)
{
if(!isOnline() || !thing || !checkBotProtection())
if(!canPerformGameAction() || !thing)
return;
Position pos = thing->getPosition();
@@ -357,7 +445,7 @@ void Game::use(const ThingPtr& thing)
void Game::useInventoryItem(int itemId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction() || !g_thingsType.isValidItemId(itemId))
return;
Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
@@ -368,7 +456,7 @@ void Game::useInventoryItem(int itemId)
void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
{
if(!isOnline() || !item || !toThing || !checkBotProtection())
if(!canPerformGameAction() || !item || !toThing)
return;
Position pos = item->getPosition();
@@ -380,12 +468,12 @@ void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
if(CreaturePtr creature = toThing->asCreature())
m_protocolGame->sendUseOnCreature(pos, item->getId(), item->getStackpos(), creature->getId());
else
m_protocolGame->sendUseItemEx(pos, item->getId(), item->getStackpos(), toThing->getPosition(), toThing->getId(), toThing->getStackpos());
m_protocolGame->sendUseItemWith(pos, item->getId(), item->getStackpos(), toThing->getPosition(), toThing->getId(), toThing->getStackpos());
}
void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing)
{
if(!isOnline() || !toThing || !checkBotProtection())
if(!canPerformGameAction() || !toThing)
return;
m_localPlayer->lockWalk();
@@ -395,212 +483,207 @@ void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing)
if(CreaturePtr creature = toThing->asCreature())
m_protocolGame->sendUseOnCreature(pos, itemId, 0, creature->getId());
else
m_protocolGame->sendUseItemEx(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackpos());
m_protocolGame->sendUseItemWith(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackpos());
}
void Game::move(const ThingPtr& thing, const Position& toPos, int count)
void Game::open(const ItemPtr& item, int containerId)
{
if(!isOnline() || !thing || !checkBotProtection() || thing->getPosition() == toPos || count <= 0)
if(!canPerformGameAction() || !item)
return;
m_localPlayer->lockWalk();
m_protocolGame->sendThrow(thing->getPosition(), thing->getId(), thing->getStackpos(), toPos, count);
m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackpos(), containerId);
}
void Game::setChaseMode(Otc::ChaseModes chaseMode)
void Game::upContainer(int containerId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_chaseMode = chaseMode;
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
m_protocolGame->sendUpContainer(containerId);
}
void Game::setFightMode(Otc::FightModes fightMode)
void Game::refreshContainer()
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_fightMode = fightMode;
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
}
void Game::setSafeFight(bool on)
{
if(!isOnline() || !checkBotProtection())
return;
m_safeFight = on;
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
m_protocolGame->sendRefreshContainer();
}
void Game::attack(const CreaturePtr& creature)
{
if(!isOnline() || !creature || !checkBotProtection())
if(!canPerformGameAction() || creature == m_localPlayer || creature == m_attackingCreature)
return;
m_localPlayer->lockWalk();
if(m_localPlayer->isFollowing())
if(creature && isFollowing())
cancelFollow();
m_localPlayer->setAttackingCreature(creature);
m_protocolGame->sendAttack(creature->getId());
}
void Game::cancelAttack()
{
m_localPlayer->lockWalk();
m_localPlayer->setAttackingCreature(nullptr);
m_protocolGame->sendAttack(0);
setAttackingCreature(creature);
m_protocolGame->sendAttack(creature ? creature->getId() : 0);
}
void Game::follow(const CreaturePtr& creature)
{
if(!isOnline() || !creature || !checkBotProtection())
if(!canPerformGameAction() || creature == m_localPlayer || creature == m_followingCreature)
return;
if(m_localPlayer->isAttacking())
m_localPlayer->lockWalk();
if(creature && isAttacking())
cancelAttack();
m_localPlayer->setFollowingCreature(creature);
m_protocolGame->sendFollow(creature->getId());
setFollowingCreature(creature);
m_protocolGame->sendFollow(creature ? creature->getId() : 0);
}
void Game::cancelFollow()
void Game::cancelAttackAndFollow()
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_localPlayer->setFollowingCreature(nullptr);
m_protocolGame->sendFollow(0);
}
m_localPlayer->lockWalk();
void Game::rotate(const ThingPtr& thing)
{
if(!isOnline() || !thing || !checkBotProtection())
return;
m_protocolGame->sendRotateItem(thing->getPosition(), thing->getId(), thing->getStackpos());
setAttackingCreature(nullptr);
setFollowingCreature(nullptr);
m_protocolGame->sendCancelAttackAndFollow();
}
void Game::talk(const std::string& message)
{
if(!canPerformGameAction() || message.empty())
return;
talkChannel(Otc::SpeakSay, 0, message);
}
void Game::talkChannel(Otc::SpeakType speakType, int channelId, const std::string& message)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction() || message.empty())
return;
m_protocolGame->sendTalk(speakType, channelId, "", message);
}
void Game::talkPrivate(Otc::SpeakType speakType, const std::string& receiver, const std::string& message)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction() || receiver.empty() || message.empty())
return;
m_protocolGame->sendTalk(speakType, 0, receiver, message);
}
void Game::openPrivateChannel(const std::string& receiver)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction() || receiver.empty())
return;
m_protocolGame->sendOpenPrivateChannel(receiver);
}
void Game::requestChannels()
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendGetChannels();
m_protocolGame->sendRequestChannels();
}
void Game::joinChannel(int channelId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendJoinChannel(channelId);
}
void Game::leaveChannel(int channelId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendLeaveChannel(channelId);
}
void Game::closeNpcChannel()
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendCloseNpcChannel();
}
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);
}
void Game::partyInvite(int creatureId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendInviteToParty(creatureId);
}
void Game::partyJoin(int creatureId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendJoinParty(creatureId);
}
void Game::partyRevokeInvitation(int creatureId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendRevokeInvitation(creatureId);
}
void Game::partyPassLeadership(int creatureId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendPassLeadership(creatureId);
}
void Game::partyLeave()
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendLeaveParty();
}
void Game::partyShareExperience(bool active)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendShareExperience(active, 0);
}
void Game::requestOutfit()
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendGetOutfit();
m_protocolGame->sendRequestOutfit();
}
void Game::setOutfit(const Outfit& outfit)
void Game::changeOutfit(const Outfit& outfit)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendSetOutfit(outfit);
m_protocolGame->sendChangeOutfit(outfit);
}
void Game::addVip(const std::string& name)
{
if(!isOnline() || name.empty() || !checkBotProtection())
if(!canPerformGameAction() || name.empty())
return;
m_protocolGame->sendAddVip(name);
}
@@ -612,9 +695,38 @@ void Game::removeVip(int playerId)
m_protocolGame->sendRemoveVip(playerId);
}
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);
}
bool Game::checkBotProtection()
{
#ifdef BOT_PROTECTION
// 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
if(g_lua.isInCppCallback() && !g_ui.isOnInputEvent()) {
logError("caught a lua call to a bot protected game function, the call was canceled");
return false;
@@ -622,3 +734,45 @@ bool Game::checkBotProtection()
#endif
return true;
}
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);
}

View File

@@ -32,20 +32,87 @@
class Game
{
public:
void loginWorld(const std::string& account,
const std::string& password,
const std::string& worldHost, int worldPort,
const std::string& characterName);
void cancelLogin();
void logout(bool force);
void forceLogout();
void safeLogout();
void processLoginError(const std::string& error);
Game();
private:
void resetGameStates();
protected:
/*
void parseMapDescription(InputMessage& msg);
void parseMapMoveNorth(InputMessage& msg);
void parseMapMoveEast(InputMessage& msg);
void parseMapMoveSouth(InputMessage& msg);
void parseMapMoveWest(InputMessage& msg);
void parseUpdateTile(InputMessage& msg);
void parseTileAddThing(InputMessage& msg);
void parseTileTransformThing(InputMessage& msg);
void parseTileRemoveThing(InputMessage& msg);
void parseCreatureMove(InputMessage& msg);
void parseOpenContainer(InputMessage& msg);
void parseCloseContainer(InputMessage& msg);
void parseContainerAddItem(InputMessage& msg);
void parseContainerUpdateItem(InputMessage& msg);
void parseContainerRemoveItem(InputMessage& msg);
void parseAddInventoryItem(InputMessage& msg);
void parseRemoveInventoryItem(InputMessage& msg);
void parseNpcOffer(InputMessage& msg);
void parsePlayerCash(InputMessage& msg);
void parseCloseShopWindow(InputMessage&);
void parseWorldLight(InputMessage& msg);
void parseMagicEffect(InputMessage& msg);
void parseAnimatedText(InputMessage& msg);
void parseDistanceMissile(InputMessage& msg);
void parseCreatureSquare(InputMessage& msg);
void parseCreatureHealth(InputMessage& msg);
void parseCreatureLight(InputMessage& msg);
void parseCreatureOutfit(InputMessage& msg);
void parseCreatureSpeed(InputMessage& msg);
void parseCreatureSkulls(InputMessage& msg);
void parseCreatureShields(InputMessage& msg);
void parseCreatureTurn(InputMessage& msg);
void parseItemTextWindow(InputMessage& msg);
void parseHouseTextWindow(InputMessage& msg);
void parsePlayerStats(InputMessage& msg);
void parsePlayerSkills(InputMessage& msg);
void parsePlayerIcons(InputMessage& msg);
void parsePlayerCancelAttack(InputMessage& msg);
void parseCreatureSpeak(InputMessage& msg);
void parseCloseChannel(InputMessage& msg);
void parseSafeTradeRequest(InputMessage& msg);
void parseSafeTradeClose(InputMessage&);
void parseTextMessage(InputMessage& msg);
void parseCancelWalk(InputMessage& msg);
void parseFloorChangeUp(InputMessage& msg);
void parseFloorChangeDown(InputMessage& msg);
void parseOutfitWindow(InputMessage& msg);
void parseShowTutorial(InputMessage& msg);
void parseAddMarker(InputMessage& msg);
*/
void processConnectionError(const boost::system::error_code& error);
void processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat);
void processDisconnect();
void processPing();
void processLoginError(const std::string& error);
void processLoginAdvice(const std::string& message);
void processLoginWait(const std::string& message, int time);
void processLogin();
void processLogout();
void processDeath();
void processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat);
void processGameEnd();
void processDeath(int penality);
void processPlayerStats(double health, double maxHealth,
double freeCapacity, double experience,
double level, double levelPercent,
@@ -54,51 +121,84 @@ public:
double soul, double stamina);
void processTextMessage(const std::string& type, const std::string& message);
void processCreatureSpeak(const std::string& name, int level, Otc::SpeakType type, const std::string& message, int channelId, const Position& creaturePos);
void processOpenContainer(int containerId, int itemId, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items);
void processContainerAddItem(int containerId, const ItemPtr& item);
void processInventoryChange(int slot, const ItemPtr& item);
void processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos);
void processCreatureTeleport(const CreaturePtr& creature);
void processAttackCancel();
void processWalkCancel(Otc::Direction direction);
// processChannelList
// processOpenChannel
// processOpenPrivateChannel
// processOpenOwnPrivateChannel
// vip
// processVipList
// processVipLogin
// processVipLogout
// processQuestLog
// processQuestLine
friend class ProtocolGame;
friend class Map;
public:
// login related
void loginWorld(const std::string& account,
const std::string& password,
const std::string& worldHost, int worldPort,
const std::string& characterName);
void cancelLogin();
void forceLogout();
void safeLogout();
// walk related
void walk(Otc::Direction direction);
void walkPath(const std::vector<Otc::Direction>& dir);
void forceWalk(Otc::Direction direction);
void turn(Otc::Direction direction);
void stop();
// item related
void look(const ThingPtr& thing);
void open(const ItemPtr& item, int containerId);
void move(const ThingPtr &thing, const Position& toPos, int count);
void rotate(const ThingPtr& thing);
void use(const ThingPtr& thing);
void useWith(const ItemPtr& fromThing, const ThingPtr& toThing);
void useInventoryItem(int itemId);
void useInventoryItemWith(int itemId, const ThingPtr& toThing);
void move(const ThingPtr &thing, const Position& toPos, int count);
// fight tatics 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; }
// container related
void open(const ItemPtr& item, int containerId);
void upContainer(int containerId);
void refreshContainer();
// attack/follow related
void attack(const CreaturePtr& creature);
void cancelAttack();
void cancelAttack() { attack(nullptr); }
void follow(const CreaturePtr& creature);
void cancelFollow();
void rotate(const ThingPtr& thing);
void cancelFollow() { follow(nullptr); }
void cancelAttackAndFollow();
// talk related
void talk(const std::string& message);
void talkChannel(Otc::SpeakType speakType, int channelId, const std::string& message);
void talkPrivate(Otc::SpeakType speakType, const std::string& receiver, const std::string& message);
// channel related
void openPrivateChannel(const std::string& receiver);
void requestChannels();
void joinChannel(int channelId);
void leaveChannel(int channelId);
void closeNpcChannel();
void openOwnChannel();
void inviteToOwnChannel(const std::string& name);
void excludeFromOwnChannel(const std::string& name);
// party related
void partyInvite(int creatureId);
@@ -110,30 +210,65 @@ public:
// outfit related
void requestOutfit();
void setOutfit(const Outfit& outfit);
void changeOutfit(const Outfit& outfit);
// vip related
void addVip(const std::string& name);
void removeVip(int playerId);
// 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
//void inspectNpcTrade();
//void buyItem();
//void sellItem();
//void closeNpcTrade();
// player trade related
//void requestTrade();
//void inspectTrade();
//void acceptTrade();
//void rejectTrade();
// house window and editable items related
//void editText();
//void editList();
// questlog related
//void requestQuestLog();
//void requestQuestLogLine();
bool canPerformGameAction();
bool checkBotProtection();
bool isOnline() { return !!m_localPlayer; }
bool isDead() { return m_dead; }
bool isAttacking() { return !!m_attackingCreature; }
bool isFollowing() { return !!m_followingCreature; }
void setServerBeat(int serverBeat) { m_serverBeat = serverBeat; }
CreaturePtr getAttackingCreature() { return m_attackingCreature; }
CreaturePtr getFollowingCreature() { return m_followingCreature; }
int getServerBeat() { return m_serverBeat; }
LocalPlayerPtr getLocalPlayer() { return m_localPlayer; }
ProtocolGamePtr getProtocolGame() { return m_protocolGame; }
int getProtocolVersion() { return PROTOCOL; }
private:
void setAttackingCreature(const CreaturePtr& creature);
void setFollowingCreature(const CreaturePtr& creature);
LocalPlayerPtr m_localPlayer;
CreaturePtr m_attackingCreature;
CreaturePtr m_followingCreature;
ProtocolGamePtr m_protocolGame;
bool m_dead;
int m_serverBeat;
Otc::FightModes m_fightMode;
Otc::ChaseModes m_chaseMode;
bool m_safeFight;

View File

@@ -28,7 +28,6 @@
LocalPlayer::LocalPlayer()
{
m_preWalking = false;
m_canReportBugs = false;
m_known = false;
m_walkLocked = false;
m_lastPrewalkDone = true;
@@ -158,34 +157,4 @@ void LocalPlayer::terminateWalk()
m_preWalking = false;
}
void LocalPlayer::setAttackingCreature(const CreaturePtr& creature)
{
// clear current attacking creature
if(m_attackingCreature) {
m_attackingCreature->hideStaticSquare();
m_attackingCreature = nullptr;
}
// set the new attacking creature
if(creature) {
creature->showStaticSquare(Fw::red);
m_attackingCreature = creature;
}
g_lua.callGlobalField("Game", "onSetAttackingCreature", creature);
}
void LocalPlayer::setFollowingCreature(const CreaturePtr& creature)
{
// clear current following creature
if(m_followingCreature) {
m_followingCreature->hideStaticSquare();
m_followingCreature = nullptr;
}
// set the new attacking creature
if(creature) {
creature->showStaticSquare(Fw::green);
m_followingCreature = creature;
}
}

View File

@@ -34,24 +34,16 @@ class LocalPlayer : public Player
public:
LocalPlayer();
void setCanReportBugs(uint8 canReportBugs) { m_canReportBugs = (canReportBugs != 0); }
void setSkill(Otc::Skill skill, Otc::SkillType skillType, int value) { m_skills[skill][skillType] = value; }
void setStatistic(Otc::Statistic statistic, double value) { m_statistics[statistic] = value; }
void setAttackingCreature(const CreaturePtr& creature);
void setFollowingCreature(const CreaturePtr& creature);
void setIcons(int icons) { m_icons = icons; }
void setKnown(bool known) { m_known = known; }
bool getCanReportBugs() { return m_canReportBugs; }
int getSkill(Otc::Skill skill, Otc::SkillType skillType) { return m_skills[skill][skillType]; }
double getStatistic(Otc::Statistic statistic) { return m_statistics[statistic]; }
CreaturePtr getAttackingCreature() { return m_attackingCreature; }
CreaturePtr getFollowingCreature() { return m_followingCreature; }
int getIcons() { return m_icons; }
bool isKnown() { return m_known; }
bool isAttacking() { return m_attackingCreature != nullptr; }
bool isFollowing() { return m_followingCreature != nullptr; }
bool isPreWalking() { return m_preWalking; }
void unlockWalk() { m_walkLocked = false; }
@@ -90,10 +82,7 @@ private:
Position m_lastPrewalkDestionation;
Timer m_walkLockTimer;
bool m_canReportBugs;
bool m_known;
CreaturePtr m_attackingCreature;
CreaturePtr m_followingCreature;
int m_icons;
int m_skills[Otc::LastSkill][Otc::LastSkillType];
double m_statistics[Otc::LastStatistic];

View File

@@ -175,9 +175,10 @@ bool Map::removeThing(const ThingPtr& thing)
return false;
if(MissilePtr missile = thing->asMissile()) {
auto it = std::find(m_floorMissiles[missile->getPosition().z].begin(), m_floorMissiles[missile->getPosition().z].end(), missile);
if(it != m_floorMissiles[missile->getPosition().z].end()) {
m_floorMissiles[missile->getPosition().z].erase(it);
int z = missile->getPosition().z;
auto it = std::find(m_floorMissiles[z].begin(), m_floorMissiles[z].end(), missile);
if(it != m_floorMissiles[z].end()) {
m_floorMissiles[z].erase(it);
return true;
}
} else if(AnimatedTextPtr animatedText = thing->asAnimatedText()) {

View File

@@ -51,6 +51,7 @@ public:
uint16 getFirstItemId() { return 100; }
uint16 getMaxItemid() { return m_things[Item].size() + 99; }
bool isValidItemId(int id) { return id >= getFirstItemId() && id <= getMaxItemid(); }
private:
uint32 m_signature;

View File

@@ -76,6 +76,71 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction("g_map", "removeCreatureById", std::bind(&Map::removeCreatureById, &g_map, _1));
g_lua.bindClassStaticFunction("g_map", "getSpectators", std::bind(&Map::getSpectators, &g_map, _1, _2));
g_lua.registerStaticClass("g_game");
g_lua.bindClassStaticFunction("g_game", "loginWorld", std::bind(&Game::loginWorld, &g_game, _1, _2, _3, _4, _5));
g_lua.bindClassStaticFunction("g_game", "cancelLogin", std::bind(&Game::cancelLogin, &g_game));
g_lua.bindClassStaticFunction("g_game", "forceLogout", std::bind(&Game::forceLogout, &g_game));
g_lua.bindClassStaticFunction("g_game", "safeLogout", std::bind(&Game::safeLogout, &g_game));
g_lua.bindClassStaticFunction("g_game", "walk", std::bind(&Game::walk, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "walkPath", std::bind(&Game::walkPath, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "forceWalk", std::bind(&Game::forceWalk, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "turn", std::bind(&Game::turn, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "stop", std::bind(&Game::stop, &g_game));
g_lua.bindClassStaticFunction("g_game", "look", std::bind(&Game::look, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "move", std::bind(&Game::move, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction("g_game", "rotate", std::bind(&Game::rotate, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "use", std::bind(&Game::use, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "useWith", std::bind(&Game::useWith, &g_game, _1, _2));
g_lua.bindClassStaticFunction("g_game", "useInventoryItem", std::bind(&Game::useInventoryItem, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "useInventoryItemWith", std::bind(&Game::useInventoryItemWith, &g_game, _1, _2));
g_lua.bindClassStaticFunction("g_game", "open", std::bind(&Game::open, &g_game, _1, _2));
g_lua.bindClassStaticFunction("g_game", "upContainer", std::bind(&Game::upContainer, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "refreshContainer", std::bind(&Game::refreshContainer, &g_game));
g_lua.bindClassStaticFunction("g_game", "attack", std::bind(&Game::attack, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "cancelAttack", std::bind(&Game::cancelAttack, &g_game));
g_lua.bindClassStaticFunction("g_game", "follow", std::bind(&Game::follow, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "cancelFollow", std::bind(&Game::cancelFollow, &g_game));
g_lua.bindClassStaticFunction("g_game", "cancelAttackAndFollow", std::bind(&Game::cancelAttackAndFollow, &g_game));
g_lua.bindClassStaticFunction("g_game", "talk", std::bind(&Game::talk, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction("g_game", "talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction("g_game", "openPrivateChannel", std::bind(&Game::openPrivateChannel, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "requestChannels", std::bind(&Game::requestChannels, &g_game));
g_lua.bindClassStaticFunction("g_game", "joinChannel", std::bind(&Game::joinChannel, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "leaveChannel", std::bind(&Game::leaveChannel, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "closeNpcChannel", std::bind(&Game::closeNpcChannel, &g_game));
g_lua.bindClassStaticFunction("g_game", "openOwnChannel", std::bind(&Game::openOwnChannel, &g_game));
g_lua.bindClassStaticFunction("g_game", "inviteToOwnChannel", std::bind(&Game::inviteToOwnChannel, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "excludeFromOwnChannel", std::bind(&Game::excludeFromOwnChannel, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "partyInvite", std::bind(&Game::partyInvite, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "partyJoin", std::bind(&Game::partyJoin, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "partyRevokeInvitation", std::bind(&Game::partyRevokeInvitation, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "partyPassLeadership", std::bind(&Game::partyPassLeadership, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "partyLeave", std::bind(&Game::partyLeave, &g_game));
g_lua.bindClassStaticFunction("g_game", "partyShareExperience", std::bind(&Game::partyShareExperience, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "requestOutfit", std::bind(&Game::requestOutfit, &g_game));
g_lua.bindClassStaticFunction("g_game", "changeOutfit", std::bind(&Game::changeOutfit, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "addVip", std::bind(&Game::addVip, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "removeVip", std::bind(&Game::removeVip, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "setChaseMode", std::bind(&Game::setChaseMode, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "setFightMode", std::bind(&Game::setFightMode, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "setSafeFight", std::bind(&Game::setSafeFight, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "getChaseMode", std::bind(&Game::getChaseMode, &g_game));
g_lua.bindClassStaticFunction("g_game", "getFightMode", std::bind(&Game::getFightMode, &g_game));
g_lua.bindClassStaticFunction("g_game", "isSafeFight", std::bind(&Game::isSafeFight, &g_game));
g_lua.bindClassStaticFunction("g_game", "canPerformGameAction", std::bind(&Game::canPerformGameAction, &g_game));
g_lua.bindClassStaticFunction("g_game", "checkBotProtection", std::bind(&Game::checkBotProtection, &g_game));
g_lua.bindClassStaticFunction("g_game", "isOnline", std::bind(&Game::isOnline, &g_game));
g_lua.bindClassStaticFunction("g_game", "isDead", std::bind(&Game::isDead, &g_game));
g_lua.bindClassStaticFunction("g_game", "isAttacking", std::bind(&Game::isAttacking, &g_game));
g_lua.bindClassStaticFunction("g_game", "isFollowing", std::bind(&Game::isFollowing, &g_game));
g_lua.bindClassStaticFunction("g_game", "getAttackingCreature", std::bind(&Game::getAttackingCreature, &g_game));
g_lua.bindClassStaticFunction("g_game", "getFollowingCreature", std::bind(&Game::getFollowingCreature, &g_game));
g_lua.bindClassStaticFunction("g_game", "getServerBeat", std::bind(&Game::getServerBeat, &g_game));
g_lua.bindClassStaticFunction("g_game", "getLocalPlayer", std::bind(&Game::getLocalPlayer, &g_game));
g_lua.bindClassStaticFunction("g_game", "getProtocolGame", std::bind(&Game::getProtocolGame, &g_game));
g_lua.bindClassStaticFunction("g_game", "getProtocolVersion", std::bind(&Game::getProtocolVersion, &g_game));
g_lua.bindGlobalFunction("getOufitColor", Outfit::getColor);
g_lua.registerClass<ProtocolLogin, Protocol>();
@@ -148,8 +213,6 @@ void OTClient::registerLuaFunctions()
g_lua.registerClass<Npc, Creature>();
g_lua.registerClass<Monster, Creature>();
g_lua.registerClass<LocalPlayer, Player>();
g_lua.bindClassMemberFunction<LocalPlayer>("getAttackingCreature", &LocalPlayer::getAttackingCreature);
g_lua.bindClassMemberFunction<LocalPlayer>("getFollowingCreature", &LocalPlayer::getFollowingCreature);
g_lua.bindClassMemberFunction<LocalPlayer>("getHealth", &LocalPlayer::getHealth);
g_lua.bindClassMemberFunction<LocalPlayer>("getMaxHealth", &LocalPlayer::getMaxHealth);
g_lua.bindClassMemberFunction<LocalPlayer>("getFreeCapacity", &LocalPlayer::getFreeCapacity);
@@ -187,59 +250,6 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Tile>("isEmpty", &Tile::isEmpty);
g_lua.bindClassMemberFunction<Tile>("isClickable", &Tile::isClickable);
g_lua.registerClass<Map>();
g_lua.registerClass<Game>();
g_lua.bindClassStaticFunction<Game>("loginWorld", std::bind(&Game::loginWorld, &g_game, _1, _2, _3, _4, _5));
g_lua.bindClassStaticFunction<Game>("safeLogout", std::bind(&Game::safeLogout, &g_game));
g_lua.bindClassStaticFunction<Game>("forceLogout", std::bind(&Game::forceLogout, &g_game));
g_lua.bindClassStaticFunction<Game>("cancelLogin", std::bind(&Game::cancelLogin, &g_game));
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
g_lua.bindClassStaticFunction<Game>("requestOutfit", std::bind(&Game::requestOutfit, &g_game));
g_lua.bindClassStaticFunction<Game>("requestChannels", std::bind(&Game::requestChannels, &g_game));
g_lua.bindClassStaticFunction<Game>("joinChannel", std::bind(&Game::joinChannel, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("leaveChannel", std::bind(&Game::leaveChannel, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("closeNpcChannel", std::bind(&Game::closeNpcChannel, &g_game));
g_lua.bindClassStaticFunction<Game>("openPrivateChannel", std::bind(&Game::openPrivateChannel, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("setOutfit", std::bind(&Game::setOutfit, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("look", std::bind(&Game::look, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("open", std::bind(&Game::open, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("use", std::bind(&Game::use, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("useInventoryItem", std::bind(&Game::useInventoryItem, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("useWith", std::bind(&Game::useWith, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("useInventoryItemWith", std::bind(&Game::useInventoryItemWith, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("move", std::bind(&Game::move, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction<Game>("turn", std::bind(&Game::turn, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("walk", std::bind(&Game::walk, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("forceWalk", std::bind(&Game::forceWalk, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("setChaseMode", std::bind(&Game::setChaseMode, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("setFightMode", std::bind(&Game::setFightMode, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("setSafeFight", std::bind(&Game::setSafeFight, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("getChaseMode", std::bind(&Game::getChaseMode, &g_game));
g_lua.bindClassStaticFunction<Game>("getFightMode", std::bind(&Game::getFightMode, &g_game));
g_lua.bindClassStaticFunction<Game>("isSafeFight", std::bind(&Game::isSafeFight, &g_game));
g_lua.bindClassStaticFunction<Game>("attack", std::bind(&Game::attack, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("cancelAttack", std::bind(&Game::cancelAttack, &g_game));
g_lua.bindClassStaticFunction<Game>("follow", std::bind(&Game::follow, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("cancelFollow", std::bind(&Game::cancelFollow, &g_game));
g_lua.bindClassStaticFunction<Game>("rotate", std::bind(&Game::rotate, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("partyInvite", std::bind(&Game::partyInvite, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("partyJoin", std::bind(&Game::partyJoin, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("partyRevokeInvitation", std::bind(&Game::partyRevokeInvitation, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("partyPassLeadership", std::bind(&Game::partyPassLeadership, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("partyLeave", std::bind(&Game::partyLeave, &g_game));
g_lua.bindClassStaticFunction<Game>("partyShareExperience", std::bind(&Game::partyShareExperience, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("addVip", std::bind(&Game::addVip, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("removeVip", std::bind(&Game::removeVip, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("talk", std::bind(&Game::talk, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction<Game>("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction<Game>("getLocalPlayer", std::bind(&Game::getLocalPlayer, &g_game));
g_lua.bindClassStaticFunction<Game>("getProtocolVersion", std::bind(&Game::getProtocolVersion, &g_game));
g_lua.bindClassStaticFunction<Game>("getProtocolGame", std::bind(&Game::getProtocolGame, &g_game));
g_lua.registerClass<UIItem, UIWidget>();
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); });
g_lua.bindClassMemberFunction<UIItem>("setItemId", &UIItem::setItemId);

View File

@@ -54,7 +54,7 @@ namespace Proto {
#endif
enum OsTypes {
OsWindow = 1,
OsWindows = 1,
OsLinux = 2,
OsMac = 3,
OsBrowser = 4
@@ -75,13 +75,13 @@ namespace Proto {
GameServerLoginWait = 22,
GameServerPing = 30,
GameServerChallange = 31,
GameServerDead = 40,
GameServerDeath = 40,
GameServerFullMap = 100,
GameServerMapTopRow = 101,
GameServerMapRightRow = 102,
GameServerMapBottomRow = 103,
GameServerMapLeftRow = 104,
GameServerTileData = 105,
GameServerUpdateTile = 105,
GameServerCreateOnMap = 106,
GameServerChangeOnMap = 107,
GameServerDeleteOnMap = 108,
@@ -130,15 +130,15 @@ namespace Proto {
GameServerRuleViolationLock = 177, // deprecated in last tibia
GameServerOpenOwnChannel = 178,
GameServerCloseChannel = 179,
GameServerMessage = 180,
GameServerSnapBack = 181,
GameServerTextMessage = 180,
GameServerCancelWalk = 181,
GameServerWait = 182,
GameServerTopFloor = 190,
GameServerBottomFloor = 191,
GameServerFloorChangeUp = 190,
GameServerFloorChangeDown = 191,
GameServerOutfit = 200,
GameServerBuddyData = 210,
GameServerBuddyLogin = 211,
GameServerBuddyLogout = 212,
GameServerVipAdd = 210,
GameServerVipLogin = 211,
GameServerVipLogout = 212,
GameServerTutorialHint = 220,
GameServerAutomapFlag = 221,
GameServerQuestLog = 240,
@@ -151,48 +151,48 @@ namespace Proto {
enum ClientOpts {
ClientEnterAccount = 1,
ClientEnterGame = 10,
ClientQuitGame = 20,
ClientPingBack = 30,
ClientGoPath = 100,
ClientGoNorth = 101,
ClientGoEast = 102,
ClientGoSouth = 103,
ClientGoWest = 104,
ClientLeaveGame = 20,
ClientPingResponse = 30,
ClientWalkPath = 100,
ClientWalkNorth = 101,
ClientWalkEast = 102,
ClientWalkSouth = 103,
ClientWalkWest = 104,
ClientStop = 105,
ClientGoNorthEast = 106,
ClientGoSouthEast = 107,
ClientGoSouthWest = 108,
ClientGoNorthWest = 109,
ClientRotateNorth = 111,
ClientRotateEast = 112,
ClientRotateSouth = 113,
ClientRotateWest = 114,
ClientEquipObject = 119,
ClientMoveObject = 120,
ClientWalkNorthEast = 106,
ClientWalkSouthEast = 107,
ClientWalkSouthWest = 108,
ClientWalkNorthWest = 109,
ClientTurnNorth = 111,
ClientTurnEast = 112,
ClientTurnSouth = 113,
ClientTurnWest = 114,
//ClientEquipObject = 119,
ClientMove = 120,
ClientInspectNpcTrade = 121,
ClientBuyObject = 122,
ClientSellObject = 123,
ClientBuyItem = 122,
ClientSellItem = 123,
ClientCloseNpcTrade = 124,
ClientTradeObject = 125,
ClientRequestTrade = 125,
ClientInspectTrade = 126,
ClientAcceptTrade = 127,
ClientRejectTrade = 128,
ClientUseObject = 130,
ClientUseTwoObjects = 131,
ClientUseItem = 130,
ClientUseItemWith = 131,
ClientUseOnCreature = 132,
ClientTurnObject = 133,
ClientRotateItem = 133,
ClientCloseContainer = 135,
ClientUpContainer = 136,
ClientEditText = 137,
ClientEditList = 138,
ClientLook = 140,
ClientTalk = 150,
ClientGetChannels = 151,
ClientRequestChannels = 151,
ClientJoinChannel = 152,
ClientLeaveChannel = 153,
ClientOpenPrivateChannel = 154,
ClientCloseNpcChannel = 158,
ClientSetTactics = 160,
ClientChangeFightModes = 160,
ClientAttack = 161,
ClientFollow = 162,
ClientInviteToParty = 163,
@@ -202,22 +202,22 @@ namespace Proto {
ClientLeaveParty = 167,
ClientShareExperience = 168,
ClientDisbandParty = 169,
ClientOpenChannel = 170,
ClientInviteToChannel = 171,
ClientExcludeFromChannel = 172,
ClientCancel = 190,
ClientOpenOwnChannel = 170,
ClientInviteToOwnChannel = 171,
ClientExcludeFromOwnChannel = 172,
ClientCancelAttackAndFollow = 190,
ClientRefreshContainer = 202,
ClientGetOutfit = 210,
ClientSetOutfit = 211,
ClientMount = 212,
ClientAddBuddy = 220,
ClientRemoveBuddy = 221,
ClientBugReport = 230,
ClientErrorFileEntry = 232,
ClientGetQuestLog = 240,
ClientGetQuestLine = 241,
ClientRuleViolationReport = 242,
ClientGetObjectInfo = 243
ClientRequestOutfit = 210,
ClientChangeOutfit = 211,
//ClientMount = 212,
ClientAddVip = 220,
ClientRemoveVip = 221,
//ClientBugReport = 230,
//ClientErrorFileEntry = 232,
ClientRequestQuestLog = 240,
ClientRequestQuestLine = 241,
//ClientRuleViolationReport = 242,
//ClientGetObjectInfo = 243
};
enum ServerSpeakType {

View File

@@ -41,12 +41,13 @@ public:
void onError(const boost::system::error_code& error);
void sendLogout();
void sendPing();
void sendPingResponse();
void sendWalkPath(const std::vector<Otc::Direction>& path);
void sendWalkNorth();
void sendWalkEast();
void sendWalkSouth();
void sendWalkWest();
void sendStopAutowalk();
void sendStop();
void sendWalkNorthEast();
void sendWalkSouthEast();
void sendWalkSouthWest();
@@ -55,31 +56,31 @@ public:
void sendTurnEast();
void sendTurnSouth();
void sendTurnWest();
void sendThrow(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count);
void sendLookInShop(int thingId, int count);
void sendPlayerPurchase(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack);
void sendPlayerSale(int thingId, int count, int amount, bool ignoreEquipped);
void sendCloseShop();
void sendMove(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count);
void sendInspectNpcTrade(int thingId, int count);
void sendBuyItem(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack);
void sendSellItem(int thingId, int count, int amount, bool ignoreEquipped);
void sendCloseNpcTrade();
void sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId);
void sendLookInTrade(bool counterOffer, int index);
void sendInspectTrade(bool counterOffer, int index);
void sendAcceptTrade();
void sendRejectTrade();
void sendUseItem(const Position& position, int itemId, int stackpos, int index);
void sendUseItemEx(const Position& fromPos, int itemId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos);
void sendUseItemWith(const Position& fromPos, int itemId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos);
void sendUseOnCreature(const Position& pos, int thingId, int stackpos, uint creatureId);
void sendRotateItem(const Position& pos, int thingId, int stackpos);
void sendCloseContainer(int containerId);
void sendUpContainer(int containerId);
void sendTextWindow(uint windowTextId, const std::string& text);
void sendHouseWindow(int doorId, uint id, const std::string& text);
void sendLookAt(const Position& position, int thingId, int stackpos);
void sendEditText(uint textId, const std::string& text);
void sendEditList(int listId, uint id, const std::string& text);
void sendLook(const Position& position, int thingId, int stackpos);
void sendTalk(Otc::SpeakType speakType, int channelId, const std::string& receiver, const std::string& message);
void sendGetChannels();
void sendRequestChannels();
void sendJoinChannel(int channelId);
void sendLeaveChannel(int channelId);
void sendOpenPrivateChannel(const std::string& receiver);
void sendCloseNpcChannel();
void sendFightTatics(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeFight);
void sendChangeFightModes(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeFight);
void sendAttack(uint creatureId);
void sendFollow(uint creatureId);
void sendInviteToParty(uint creatureId);
@@ -88,17 +89,17 @@ public:
void sendPassLeadership(uint creatureId);
void sendLeaveParty();
void sendShareExperience(bool active, int unknown);
void sendOpenChannel(int channelId);
void sendInviteToChannel(const std::string& name);
void sendExcludeFromChannel(const std::string& name);
void sendCancel();
void sendUpdateContainer();
void sendGetOutfit();
void sendSetOutfit(const Outfit& outfit);
void sendOpenOwnChannel();
void sendInviteToOwnChannel(const std::string& name);
void sendExcludeFromOwnChannel(const std::string& name);
void sendCancelAttackAndFollow();
void sendRefreshContainer();
void sendRequestOutfit();
void sendChangeOutfit(const Outfit& outfit);
void sendAddVip(const std::string& name);
void sendRemoveVip(uint playerId);
void sendGetQuestLog();
void sendGetQuestLine(int questId);
void sendRequestQuestLog();
void sendRequestQuestLine(int questLine);
private:
void sendLoginPacket(uint timestamp, uint8 unknown);
@@ -109,16 +110,15 @@ private:
void parseInitGame(InputMessage& msg);
void parseGMActions(InputMessage& msg);
void parseLoginError(InputMessage& msg);
void parseFYIMessage(InputMessage& msg);
void parseWaitList(InputMessage& msg);
void parseLoginAdvice(InputMessage& msg);
void parseLoginWait(InputMessage& msg);
void parsePing(InputMessage&);
void parseDeath(InputMessage& msg);
void parseCanReportBugs(InputMessage& msg);
void parseMapDescription(InputMessage& msg);
void parseMoveNorth(InputMessage& msg);
void parseMoveEast(InputMessage& msg);
void parseMoveSouth(InputMessage& msg);
void parseMoveWest(InputMessage& msg);
void parseMapMoveNorth(InputMessage& msg);
void parseMapMoveEast(InputMessage& msg);
void parseMapMoveSouth(InputMessage& msg);
void parseMapMoveWest(InputMessage& msg);
void parseUpdateTile(InputMessage& msg);
void parseTileAddThing(InputMessage& msg);
void parseTileTransformThing(InputMessage& msg);
@@ -131,7 +131,7 @@ private:
void parseContainerRemoveItem(InputMessage& msg);
void parseAddInventoryItem(InputMessage& msg);
void parseRemoveInventoryItem(InputMessage& msg);
void parseOpenShopWindow(InputMessage& msg);
void parseNpcOffer(InputMessage& msg);
void parsePlayerCash(InputMessage& msg);
void parseCloseShopWindow(InputMessage&);
void parseWorldLight(InputMessage& msg);
@@ -156,7 +156,7 @@ private:
void parseChannelList(InputMessage& msg);
void parseOpenChannel(InputMessage& msg);
void parseOpenPrivateChannel(InputMessage& msg);
void parseCreateOwnPrivateChannel(InputMessage& msg);
void parseOpenOwnPrivateChannel(InputMessage& msg);
void parseCloseChannel(InputMessage& msg);
void parseSafeTradeRequest(InputMessage& msg);
void parseSafeTradeClose(InputMessage&);
@@ -164,14 +164,14 @@ private:
void parseCancelWalk(InputMessage& msg);
void parseFloorChangeUp(InputMessage& msg);
void parseFloorChangeDown(InputMessage& msg);
void parseOutfitWindow(InputMessage& msg);
void parseVipState(InputMessage& msg);
void parseOutfit(InputMessage& msg);
void parseVipAdd(InputMessage& msg);
void parseVipLogin(InputMessage& msg);
void parseVipLogout(InputMessage& msg);
void parseShowTutorial(InputMessage& msg);
void parseAddMarker(InputMessage& msg);
void parseQuestList(InputMessage& msg);
void parseQuestPartList(InputMessage& msg);
void parseTutorialHint(InputMessage& msg);
void parseAutomapFlag(InputMessage& msg);
void parseQuestLog(InputMessage& msg);
void parseQuestLine(InputMessage& msg);
void setMapDescription(InputMessage& msg, int x, int y, int z, int width, int height);
void setFloorDescription(InputMessage& msg, int x, int y, int z, int width, int height, int offset, int* skipTiles);

View File

@@ -50,34 +50,34 @@ void ProtocolGame::parseMessage(InputMessage& msg)
parseLoginError(msg);
break;
case Proto::GameServerLoginAdvice:
parseFYIMessage(msg);
parseLoginAdvice(msg);
break;
case Proto::GameServerLoginWait:
parseWaitList(msg);
parseLoginWait(msg);
break;
case Proto::GameServerPing:
parsePing(msg);
break;
//case Proto::GameServerChallange:
case Proto::GameServerDead:
case Proto::GameServerDeath:
parseDeath(msg);
break;
case Proto::GameServerFullMap:
parseMapDescription(msg);
break;
case Proto::GameServerMapTopRow:
parseMoveNorth(msg);
parseMapMoveNorth(msg);
break;
case Proto::GameServerMapRightRow:
parseMoveEast(msg);
parseMapMoveEast(msg);
break;
case Proto::GameServerMapBottomRow:
parseMoveSouth(msg);
parseMapMoveSouth(msg);
break;
case Proto::GameServerMapLeftRow:
parseMoveWest(msg);
parseMapMoveWest(msg);
break;
case Proto::GameServerTileData:
case Proto::GameServerUpdateTile:
parseUpdateTile(msg);
break;
case Proto::GameServerCreateOnMap:
@@ -114,7 +114,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
parseRemoveInventoryItem(msg);
break;
case Proto::GameServerNpcOffer:
parseOpenShopWindow(msg);
parseNpcOffer(msg);
break;
case Proto::GameServerPlayerGoods:
parsePlayerCash(msg);
@@ -210,47 +210,47 @@ void ProtocolGame::parseMessage(InputMessage& msg)
case Proto::GameServerRuleViolationLock:
break;
case Proto::GameServerOpenOwnChannel:
parseCreateOwnPrivateChannel(msg);
parseOpenOwnPrivateChannel(msg);
break;
case Proto::GameServerCloseChannel:
parseCloseChannel(msg);
break;
case Proto::GameServerMessage:
case Proto::GameServerTextMessage:
parseTextMessage(msg);
break;
case Proto::GameServerSnapBack:
case Proto::GameServerCancelWalk:
parseCancelWalk(msg);
break;
//case Proto::GameServerWait:
case Proto::GameServerTopFloor:
case Proto::GameServerFloorChangeUp:
parseFloorChangeUp(msg);
break;
case Proto::GameServerBottomFloor:
case Proto::GameServerFloorChangeDown:
parseFloorChangeDown(msg);
break;
case Proto::GameServerOutfit:
parseOutfitWindow(msg);
parseOutfit(msg);
break;
case Proto::GameServerBuddyData:
parseVipState(msg);
case Proto::GameServerVipAdd:
parseVipAdd(msg);
break;
case Proto::GameServerBuddyLogin:
case Proto::GameServerVipLogin:
parseVipLogin(msg);
break;
case Proto::GameServerBuddyLogout:
case Proto::GameServerVipLogout:
parseVipLogout(msg);
break;
case Proto::GameServerTutorialHint:
parseShowTutorial(msg);
parseTutorialHint(msg);
break;
case Proto::GameServerAutomapFlag:
parseAddMarker(msg);
parseAutomapFlag(msg);
break;
case Proto::GameServerQuestLog:
parseQuestList(msg);
parseQuestLog(msg);
break;
case Proto::GameServerQuestLine:
parseQuestPartList(msg);
parseQuestLine(msg);
break;
//case Proto::GameServerChannelEvent:
//case Proto::GameServerObjectInfo:
@@ -269,16 +269,17 @@ void ProtocolGame::parseInitGame(InputMessage& msg)
{
uint playerId = msg.getU32();
int serverBeat = msg.getU16();
int playerCanReportBugs = msg.getU8();
msg.getU8(); // can report bugs, ignored
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
m_localPlayer->setId(playerId);
m_localPlayer->setCanReportBugs(playerCanReportBugs);
g_game.processGameStart(m_localPlayer, serverBeat);
}
void ProtocolGame::parseGMActions(InputMessage& msg)
{
// not used
for(int i = 0; i < Proto::NumViolationReasons; ++i)
msg.getU8();
}
@@ -286,31 +287,37 @@ void ProtocolGame::parseGMActions(InputMessage& msg)
void ProtocolGame::parseLoginError(InputMessage& msg)
{
std::string error = msg.getString();
g_game.processLoginError(error);
}
void ProtocolGame::parseFYIMessage(InputMessage& msg)
void ProtocolGame::parseLoginAdvice(InputMessage& msg)
{
msg.getString(); // message
std::string message = msg.getString();
g_game.processLoginAdvice(message);
}
void ProtocolGame::parseWaitList(InputMessage& msg)
void ProtocolGame::parseLoginWait(InputMessage& msg)
{
msg.getString(); // message
msg.getU8();// + 1 // time
std::string message = msg.getString();
int time = msg.getU8();
g_game.processLoginWait(message, time);
}
void ProtocolGame::parsePing(InputMessage&)
{
sendPing();
g_game.processPing();
}
void ProtocolGame::parseDeath(InputMessage& msg)
{
int penality = 100;
#if PROTOCOL==862
msg.getU8(); // 100 is a fair death. < 100 is a unfair death.
penality = msg.getU8();
#endif
g_game.processDeath();
g_game.processDeath(penality);
}
void ProtocolGame::parseMapDescription(InputMessage& msg)
@@ -320,7 +327,7 @@ void ProtocolGame::parseMapDescription(InputMessage& msg)
setMapDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES);
}
void ProtocolGame::parseMoveNorth(InputMessage& msg)
void ProtocolGame::parseMapMoveNorth(InputMessage& msg)
{
Position pos = g_map.getCentralPosition();
pos.y--;
@@ -329,7 +336,7 @@ void ProtocolGame::parseMoveNorth(InputMessage& msg)
g_map.setCentralPosition(pos);
}
void ProtocolGame::parseMoveEast(InputMessage& msg)
void ProtocolGame::parseMapMoveEast(InputMessage& msg)
{
Position pos = g_map.getCentralPosition();
pos.x++;
@@ -338,7 +345,7 @@ void ProtocolGame::parseMoveEast(InputMessage& msg)
g_map.setCentralPosition(pos);
}
void ProtocolGame::parseMoveSouth(InputMessage& msg)
void ProtocolGame::parseMapMoveSouth(InputMessage& msg)
{
Position pos = g_map.getCentralPosition();
pos.y++;
@@ -347,7 +354,7 @@ void ProtocolGame::parseMoveSouth(InputMessage& msg)
g_map.setCentralPosition(pos);
}
void ProtocolGame::parseMoveWest(InputMessage& msg)
void ProtocolGame::parseMapMoveWest(InputMessage& msg)
{
Position pos = g_map.getCentralPosition();
pos.x--;
@@ -383,12 +390,12 @@ void ProtocolGame::parseTileTransformThing(InputMessage& msg)
int stackPos = msg.getU8();
int thingId = msg.getU16();
assert(thingId != 0);
if(thingId == 0x0061 || thingId == 0x0062 || thingId == 0x0063) {
parseCreatureTurn(msg);
} else {
ThingPtr thing = internalGetItem(msg, thingId);
g_map.removeThingByPos(pos, stackPos);
if(!g_map.removeThingByPos(pos, stackPos))
logTraceError("could not remove thing");
g_map.addThing(thing, pos, stackPos);
}
}
@@ -398,7 +405,8 @@ void ProtocolGame::parseTileRemoveThing(InputMessage& msg)
Position pos = parsePosition(msg);
int stackPos = msg.getU8();
g_map.removeThingByPos(pos, stackPos);
if(!g_map.removeThingByPos(pos, stackPos))
logTraceError("could not remove thing");
}
void ProtocolGame::parseCreatureMove(InputMessage& msg)
@@ -420,7 +428,8 @@ void ProtocolGame::parseCreatureMove(InputMessage& msg)
}
// update map tiles
g_map.removeThing(thing);
if(!g_map.removeThing(thing))
logTraceError("could not remove thing");
g_map.addThing(thing, newPos);
g_game.processCreatureMove(creature, oldPos, newPos);
@@ -435,20 +444,17 @@ void ProtocolGame::parseOpenContainer(InputMessage& msg)
bool hasParent = (msg.getU8() != 0);
int itemCount = msg.getU8();
std::vector<ItemPtr> items;
items.reserve(itemCount);
for(int i = 0; i < itemCount; i++) {
ItemPtr item = internalGetItem(msg);
items.push_back(item);
}
std::vector<ItemPtr> items(itemCount);
for(int i = 0; i < itemCount; i++)
items[i] = internalGetItem(msg);
g_lua.callGlobalField("Game", "onContainerOpen", containerId, itemId, name, capacity, hasParent, items);
g_game.processOpenContainer(containerId, itemId, name, capacity, hasParent, items);
}
void ProtocolGame::parseCloseContainer(InputMessage& msg)
{
int containerId = msg.getU8();
g_lua.callGlobalField("Game", "onContainerClose", containerId);
g_lua.callGlobalField("g_game", "onContainerClose", containerId);
}
void ProtocolGame::parseContainerAddItem(InputMessage& msg)
@@ -463,14 +469,14 @@ void ProtocolGame::parseContainerUpdateItem(InputMessage& msg)
int containerId = msg.getU8();
int slot = msg.getU8();
ItemPtr item = internalGetItem(msg);
g_lua.callGlobalField("Game", "onContainerUpdateItem", containerId, slot, item);
g_lua.callGlobalField("g_game", "onContainerUpdateItem", containerId, slot, item);
}
void ProtocolGame::parseContainerRemoveItem(InputMessage& msg)
{
int containerId = msg.getU8();
int slot = msg.getU8();
g_lua.callGlobalField("Game", "onContainerRemoveItem", containerId, slot);
g_lua.callGlobalField("g_game", "onContainerRemoveItem", containerId, slot);
}
void ProtocolGame::parseAddInventoryItem(InputMessage& msg)
@@ -486,7 +492,7 @@ void ProtocolGame::parseRemoveInventoryItem(InputMessage& msg)
g_game.processInventoryChange(slot, ItemPtr());
}
void ProtocolGame::parseOpenShopWindow(InputMessage& msg)
void ProtocolGame::parseNpcOffer(InputMessage& msg)
{
int listCount = msg.getU8();
for(int i = 0; i < listCount; ++i) {
@@ -699,7 +705,7 @@ void ProtocolGame::parsePlayerSkills(InputMessage& msg)
m_localPlayer->setSkill((Otc::Skill)skill, (Otc::SkillType)skillType, values[skillType]);
}
g_lua.callGlobalField("Game", "onSkillChange", skill, values[Otc::SkillLevel], values[Otc::SkillPercent]);
g_lua.callGlobalField("g_game", "onSkillChange", skill, values[Otc::SkillLevel], values[Otc::SkillPercent]);
}
}
@@ -769,7 +775,7 @@ void ProtocolGame::parseChannelList(InputMessage& msg)
channelList.push_back(std::make_tuple(id, name));
}
g_lua.callGlobalField("Game", "onChannelList", channelList);
g_lua.callGlobalField("g_game", "onChannelList", channelList);
}
void ProtocolGame::parseOpenChannel(InputMessage& msg)
@@ -777,29 +783,29 @@ void ProtocolGame::parseOpenChannel(InputMessage& msg)
int channelId = msg.getU16();
std::string name = msg.getString();
g_lua.callGlobalField("Game", "onOpenChannel", channelId, name);
g_lua.callGlobalField("g_game", "onOpenChannel", channelId, name);
}
void ProtocolGame::parseOpenPrivateChannel(InputMessage& msg)
{
std::string name = msg.getString();
g_lua.callGlobalField("Game", "onOpenPrivateChannel", name);
g_lua.callGlobalField("g_game", "onOpenPrivateChannel", name);
}
void ProtocolGame::parseCreateOwnPrivateChannel(InputMessage& msg)
void ProtocolGame::parseOpenOwnPrivateChannel(InputMessage& msg)
{
int id = msg.getU16(); // channel id
std::string name = msg.getString(); // channel name
g_lua.callGlobalField("Game", "onOpenOwnPrivateChannel", id, name);
g_lua.callGlobalField("g_game", "onOpenOwnPrivateChannel", id, name);
}
void ProtocolGame::parseCloseChannel(InputMessage& msg)
{
int id = msg.getU16(); // channel id
g_lua.callGlobalField("Game", "onCloseChannel", id);
g_lua.callGlobalField("g_game", "onCloseChannel", id);
}
void ProtocolGame::parseTextMessage(InputMessage& msg)
@@ -855,7 +861,7 @@ void ProtocolGame::parseFloorChangeDown(InputMessage& msg)
g_map.setCentralPosition(pos);
}
void ProtocolGame::parseOutfitWindow(InputMessage& msg)
void ProtocolGame::parseOutfit(InputMessage& msg)
{
Outfit outfit = internalGetOutfit(msg);
@@ -875,45 +881,45 @@ void ProtocolGame::parseOutfitWindow(InputMessage& msg)
creature->setDirection(Otc::South);
creature->setOutfit(outfit);
g_lua.callGlobalField("Game", "onOpenOutfitWindow", creature, outfitList);
g_lua.callGlobalField("g_game", "onOpenOutfitWindow", creature, outfitList);
}
void ProtocolGame::parseVipState(InputMessage& msg)
void ProtocolGame::parseVipAdd(InputMessage& msg)
{
uint id = msg.getU32();
std::string name = msg.getString();
bool online = msg.getU8() != 0;
g_lua.callGlobalField("Game", "onAddVip", id, name, online);
g_lua.callGlobalField("g_game", "onAddVip", id, name, online);
}
void ProtocolGame::parseVipLogin(InputMessage& msg)
{
uint id = msg.getU32();
g_lua.callGlobalField("Game", "onVipStateChange", id, true);
g_lua.callGlobalField("g_game", "onVipStateChange", id, true);
}
void ProtocolGame::parseVipLogout(InputMessage& msg)
{
uint id = msg.getU32();
g_lua.callGlobalField("Game", "onVipStateChange", id, false);
g_lua.callGlobalField("g_game", "onVipStateChange", id, false);
}
void ProtocolGame::parseShowTutorial(InputMessage& msg)
void ProtocolGame::parseTutorialHint(InputMessage& msg)
{
msg.getU8(); // tutorial id
}
void ProtocolGame::parseAddMarker(InputMessage& msg)
void ProtocolGame::parseAutomapFlag(InputMessage& msg)
{
parsePosition(msg); // position
msg.getU8(); // icon
msg.getString(); // message
}
void ProtocolGame::parseQuestList(InputMessage& msg)
void ProtocolGame::parseQuestLog(InputMessage& msg)
{
int questsCount = msg.getU16();
for(int i = 0; i < questsCount; i++) {
@@ -923,7 +929,7 @@ void ProtocolGame::parseQuestList(InputMessage& msg)
}
}
void ProtocolGame::parseQuestPartList(InputMessage& msg)
void ProtocolGame::parseQuestLine(InputMessage& msg)
{
msg.getU16(); // quest id
int missionCount = msg.getU8();

View File

@@ -25,320 +25,333 @@
void ProtocolGame::sendLoginPacket(uint timestamp, uint8 unknown)
{
OutputMessage oMsg;
OutputMessage msg;
oMsg.addU8(Proto::ClientEnterGame);
oMsg.addU16(Proto::OsLinux);
oMsg.addU16(Proto::ClientVersion);
msg.addU8(Proto::ClientEnterGame);
oMsg.addU8(0); // first RSA byte must be 0
#ifdef WIN32
msg.addU16(Proto::OsWindows);
#else
msg.addU16(Proto::OsLinux);
#endif
msg.addU16(Proto::ClientVersion);
msg.addU8(0); // first RSA byte must be 0
// xtea key
generateXteaKey();
oMsg.addU32(m_xteaKey[0]);
oMsg.addU32(m_xteaKey[1]);
oMsg.addU32(m_xteaKey[2]);
oMsg.addU32(m_xteaKey[3]);
msg.addU32(m_xteaKey[0]);
msg.addU32(m_xteaKey[1]);
msg.addU32(m_xteaKey[2]);
msg.addU32(m_xteaKey[3]);
oMsg.addU8(0); // is gm set?
oMsg.addString(m_accountName);
oMsg.addString(m_characterName);
oMsg.addString(m_accountPassword);
msg.addU8(0); // is gm set?
msg.addString(m_accountName);
msg.addString(m_characterName);
msg.addString(m_accountPassword);
oMsg.addU32(timestamp);
oMsg.addU8(unknown);
msg.addU32(timestamp);
msg.addU8(unknown);
// complete the 128 bytes for rsa encryption with zeros
oMsg.addPaddingBytes(128 - (29 + m_accountName.length() + m_characterName.length() + m_accountPassword.length()));
msg.addPaddingBytes(128 - (29 + m_accountName.length() + m_characterName.length() + m_accountPassword.length()));
// encrypt with RSA
Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, Proto::RSA);
Rsa::encrypt((char*)msg.getBuffer() + 6 + msg.getMessageSize() - 128, 128, Proto::RSA);
send(oMsg);
send(msg);
enableXteaEncryption();
}
void ProtocolGame::sendLogout()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientQuitGame);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientLeaveGame);
send(msg);
}
void ProtocolGame::sendPing()
void ProtocolGame::sendPingResponse()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientPingBack);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientPingResponse);
send(msg);
}
// autowalk
void ProtocolGame::sendWalkPath(const std::vector<Otc::Direction>& path)
{
OutputMessage msg;
msg.addU8(path.size());
for(Otc::Direction dir : path)
msg.addU8(dir);
send(msg);
}
void ProtocolGame::sendWalkNorth()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoNorth);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientWalkNorth);
send(msg);
}
void ProtocolGame::sendWalkEast()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoEast);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientWalkEast);
send(msg);
}
void ProtocolGame::sendWalkSouth()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoSouth);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientWalkSouth);
send(msg);
}
void ProtocolGame::sendWalkWest()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoWest);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientWalkWest);
send(msg);
}
void ProtocolGame::sendStopAutowalk()
void ProtocolGame::sendStop()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientStop);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientStop);
send(msg);
}
void ProtocolGame::sendWalkNorthEast()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoNorthEast);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientWalkNorthEast);
send(msg);
}
void ProtocolGame::sendWalkSouthEast()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoSouthEast);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientWalkSouthEast);
send(msg);
}
void ProtocolGame::sendWalkSouthWest()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoSouthWest);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientWalkSouthWest);
send(msg);
}
void ProtocolGame::sendWalkNorthWest()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoNorthWest);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientWalkNorthWest);
send(msg);
}
void ProtocolGame::sendTurnNorth()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRotateNorth);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientTurnNorth);
send(msg);
}
void ProtocolGame::sendTurnEast()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRotateEast);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientTurnEast);
send(msg);
}
void ProtocolGame::sendTurnSouth()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRotateSouth);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientTurnSouth);
send(msg);
}
void ProtocolGame::sendTurnWest()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRotateWest);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientTurnWest);
send(msg);
}
void ProtocolGame::sendThrow(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count)
void ProtocolGame::sendMove(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientMoveObject);
addPosition(oMsg, fromPos);
oMsg.addU16(thingId);
oMsg.addU8(stackpos);
addPosition(oMsg, toPos);
oMsg.addU8(count);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientMove);
addPosition(msg, fromPos);
msg.addU16(thingId);
msg.addU8(stackpos);
addPosition(msg, toPos);
msg.addU8(count);
send(msg);
}
void ProtocolGame::sendLookInShop(int thingId, int count)
void ProtocolGame::sendInspectNpcTrade(int thingId, int count)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientInspectNpcTrade);
oMsg.addU16(thingId);
oMsg.addU8(count);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientInspectNpcTrade);
msg.addU16(thingId);
msg.addU8(count);
send(msg);
}
void ProtocolGame::sendPlayerPurchase(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack)
void ProtocolGame::sendBuyItem(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientBuyObject);
oMsg.addU16(thingId);
oMsg.addU8(count);
oMsg.addU8(amount);
oMsg.addU8(ignoreCapacity ? 0x01 : 0x00);
oMsg.addU8(buyWithBackpack ? 0x01 : 0x00);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientBuyItem);
msg.addU16(thingId);
msg.addU8(count);
msg.addU8(amount);
msg.addU8(ignoreCapacity ? 0x01 : 0x00);
msg.addU8(buyWithBackpack ? 0x01 : 0x00);
send(msg);
}
void ProtocolGame::sendPlayerSale(int thingId, int count, int amount, bool ignoreEquipped)
void ProtocolGame::sendSellItem(int thingId, int count, int amount, bool ignoreEquipped)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientSellObject);
oMsg.addU16(thingId);
oMsg.addU8(count);
oMsg.addU8(amount);
oMsg.addU8(ignoreEquipped ? 0x01 : 0x00);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientSellItem);
msg.addU16(thingId);
msg.addU8(count);
msg.addU8(amount);
msg.addU8(ignoreEquipped ? 0x01 : 0x00);
send(msg);
}
void ProtocolGame::sendCloseShop()
void ProtocolGame::sendCloseNpcTrade()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientCloseNpcTrade);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientCloseNpcTrade);
send(msg);
}
void ProtocolGame::sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientTradeObject);
addPosition(oMsg, pos);
oMsg.addU16(thingId);
oMsg.addU8(stackpos);
oMsg.addU32(playerId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientRequestTrade);
addPosition(msg, pos);
msg.addU16(thingId);
msg.addU8(stackpos);
msg.addU32(playerId);
send(msg);
}
void ProtocolGame::sendLookInTrade(bool counterOffer, int index)
void ProtocolGame::sendInspectTrade(bool counterOffer, int index)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientInspectTrade);
oMsg.addU8(counterOffer ? 0x01 : 0x00);
oMsg.addU8(index);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientInspectTrade);
msg.addU8(counterOffer ? 0x01 : 0x00);
msg.addU8(index);
send(msg);
}
void ProtocolGame::sendAcceptTrade()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientAcceptTrade);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientAcceptTrade);
send(msg);
}
void ProtocolGame::sendRejectTrade()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRejectTrade);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientRejectTrade);
send(msg);
}
void ProtocolGame::sendUseItem(const Position& position, int itemId, int stackpos, int index)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientUseObject);
addPosition(oMsg, position);
oMsg.addU16(itemId);
oMsg.addU8(stackpos);
oMsg.addU8(index);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientUseItem);
addPosition(msg, position);
msg.addU16(itemId);
msg.addU8(stackpos);
msg.addU8(index);
send(msg);
}
void ProtocolGame::sendUseItemEx(const Position& fromPos, int itemId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos)
void ProtocolGame::sendUseItemWith(const Position& fromPos, int itemId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientUseTwoObjects);
addPosition(oMsg, fromPos);
oMsg.addU16(itemId);
oMsg.addU8(fromStackpos);
addPosition(oMsg, toPos);
oMsg.addU16(toThingId);
oMsg.addU8(toStackpos);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientUseItemWith);
addPosition(msg, fromPos);
msg.addU16(itemId);
msg.addU8(fromStackpos);
addPosition(msg, toPos);
msg.addU16(toThingId);
msg.addU8(toStackpos);
send(msg);
}
void ProtocolGame::sendUseOnCreature(const Position& pos, int thingId, int stackpos, uint creatureId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientUseOnCreature);
addPosition(oMsg, pos);
oMsg.addU16(thingId);
oMsg.addU8(stackpos);
oMsg.addU32(creatureId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientUseOnCreature);
addPosition(msg, pos);
msg.addU16(thingId);
msg.addU8(stackpos);
msg.addU32(creatureId);
send(msg);
}
void ProtocolGame::sendRotateItem(const Position& pos, int thingId, int stackpos)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientTurnObject);
addPosition(oMsg, pos);
oMsg.addU16(thingId);
oMsg.addU8(stackpos);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientRotateItem);
addPosition(msg, pos);
msg.addU16(thingId);
msg.addU8(stackpos);
send(msg);
}
void ProtocolGame::sendCloseContainer(int containerId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientCloseContainer);
oMsg.addU8(containerId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientCloseContainer);
msg.addU8(containerId);
send(msg);
}
void ProtocolGame::sendUpContainer(int containerId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientUpContainer);
oMsg.addU8(containerId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientUpContainer);
msg.addU8(containerId);
send(msg);
}
void ProtocolGame::sendTextWindow(uint windowTextId, const std::string& text)
void ProtocolGame::sendEditText(uint textId, const std::string& text)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientEditText);
oMsg.addU32(windowTextId);
oMsg.addString(text);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientEditText);
msg.addU32(textId);
msg.addString(text);
send(msg);
}
void ProtocolGame::sendHouseWindow(int doorId, uint id, const std::string& text)
void ProtocolGame::sendEditList(int listId, uint id, const std::string& text)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientEditList);
oMsg.addU8(doorId);
oMsg.addU32(id);
oMsg.addString(text);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientEditList);
msg.addU8(listId);
msg.addU32(id);
msg.addString(text);
send(msg);
}
void ProtocolGame::sendLookAt(const Position& position, int thingId, int stackpos)
void ProtocolGame::sendLook(const Position& position, int thingId, int stackpos)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientLook);
addPosition(oMsg, position);
oMsg.addU16(thingId);
oMsg.addU8(stackpos);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientLook);
addPosition(msg, position);
msg.addU16(thingId);
msg.addU8(stackpos);
send(msg);
}
void ProtocolGame::sendTalk(Otc::SpeakType speakType, int channelId, const std::string& receiver, const std::string& message)
@@ -348,239 +361,227 @@ void ProtocolGame::sendTalk(Otc::SpeakType speakType, int channelId, const std::
int serverSpeakType = Proto::translateSpeakTypeToServer(speakType);
OutputMessage oMsg;
oMsg.addU8(Proto::ClientTalk);
oMsg.addU8(serverSpeakType);
OutputMessage msg;
msg.addU8(Proto::ClientTalk);
msg.addU8(serverSpeakType);
switch(serverSpeakType) {
case Proto::ServerSpeakPrivate:
case Proto::ServerSpeakPrivateRed:
oMsg.addString(receiver);
msg.addString(receiver);
break;
case Proto::ServerSpeakChannelYellow:
case Proto::ServerSpeakChannelRed:
oMsg.addU16(channelId);
msg.addU16(channelId);
break;
}
oMsg.addString(message);
send(oMsg);
msg.addString(message);
send(msg);
}
void ProtocolGame::sendGetChannels()
void ProtocolGame::sendRequestChannels()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGetChannels);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientRequestChannels);
send(msg);
}
void ProtocolGame::sendJoinChannel(int channelId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientJoinChannel);
oMsg.addU16(channelId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientJoinChannel);
msg.addU16(channelId);
send(msg);
}
void ProtocolGame::sendLeaveChannel(int channelId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientLeaveChannel);
oMsg.addU16(channelId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientLeaveChannel);
msg.addU16(channelId);
send(msg);
}
void ProtocolGame::sendOpenPrivateChannel(const std::string& receiver)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientOpenPrivateChannel);
oMsg.addString(receiver);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientOpenPrivateChannel);
msg.addString(receiver);
send(msg);
}
// removed from game
// process report
// gm closes report
// cancel report
void ProtocolGame::sendCloseNpcChannel()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientCloseNpcChannel);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientCloseNpcChannel);
send(msg);
}
void ProtocolGame::sendFightTatics(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeFight)
void ProtocolGame::sendChangeFightModes(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeFight)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientSetTactics);
oMsg.addU8(fightMode);
oMsg.addU8(chaseMode);
oMsg.addU8(safeFight ? 0x01: 0x00);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientChangeFightModes);
msg.addU8(fightMode);
msg.addU8(chaseMode);
msg.addU8(safeFight ? 0x01: 0x00);
send(msg);
}
void ProtocolGame::sendAttack(uint creatureId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientAttack);
oMsg.addU32(creatureId);
oMsg.addU32(0);
oMsg.addU32(0);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientAttack);
msg.addU32(creatureId);
msg.addU32(0);
msg.addU32(0);
send(msg);
}
void ProtocolGame::sendFollow(uint creatureId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientFollow);
oMsg.addU32(creatureId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientFollow);
msg.addU32(creatureId);
send(msg);
}
void ProtocolGame::sendInviteToParty(uint creatureId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientInviteToParty);
oMsg.addU32(creatureId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientInviteToParty);
msg.addU32(creatureId);
send(msg);
}
void ProtocolGame::sendJoinParty(uint creatureId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientJoinParty);
oMsg.addU32(creatureId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientJoinParty);
msg.addU32(creatureId);
send(msg);
}
void ProtocolGame::sendRevokeInvitation(uint creatureId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRevokeInvitation);
oMsg.addU32(creatureId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientRevokeInvitation);
msg.addU32(creatureId);
send(msg);
}
void ProtocolGame::sendPassLeadership(uint creatureId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientPassLeadership);
oMsg.addU32(creatureId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientPassLeadership);
msg.addU32(creatureId);
send(msg);
}
void ProtocolGame::sendLeaveParty()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientLeaveParty);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientLeaveParty);
send(msg);
}
void ProtocolGame::sendShareExperience(bool active, int unknown)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientShareExperience);
oMsg.addU8(active ? 0x01 : 0x00);
oMsg.addU8(unknown);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientShareExperience);
msg.addU8(active ? 0x01 : 0x00);
msg.addU8(unknown);
send(msg);
}
void ProtocolGame::sendOpenChannel(int channelId)
void ProtocolGame::sendOpenOwnChannel()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientOpenChannel);
oMsg.addU16(channelId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientOpenOwnChannel);
send(msg);
}
void ProtocolGame::sendInviteToChannel(const std::string& name)
void ProtocolGame::sendInviteToOwnChannel(const std::string& name)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientInviteToChannel);
oMsg.addString(name);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientInviteToOwnChannel);
msg.addString(name);
send(msg);
}
void ProtocolGame::sendExcludeFromChannel(const std::string& name)
void ProtocolGame::sendExcludeFromOwnChannel(const std::string& name)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientExcludeFromChannel);
oMsg.addString(name);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientExcludeFromOwnChannel);
msg.addString(name);
send(msg);
}
void ProtocolGame::sendCancel()
void ProtocolGame::sendCancelAttackAndFollow()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientCancel);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientCancelAttackAndFollow);
send(msg);
}
// update tile (not used)
void ProtocolGame::sendUpdateContainer()
void ProtocolGame::sendRefreshContainer()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRefreshContainer);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientRefreshContainer);
send(msg);
}
void ProtocolGame::sendGetOutfit()
void ProtocolGame::sendRequestOutfit()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGetOutfit);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientRequestOutfit);
send(msg);
}
void ProtocolGame::sendSetOutfit(const Outfit& outfit)
void ProtocolGame::sendChangeOutfit(const Outfit& outfit)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientSetOutfit);
OutputMessage msg;
msg.addU8(Proto::ClientChangeOutfit);
oMsg.addU16(outfit.getId());
oMsg.addU8(outfit.getHead());
oMsg.addU8(outfit.getBody());
oMsg.addU8(outfit.getLegs());
oMsg.addU8(outfit.getFeet());
oMsg.addU8(outfit.getAddons());
msg.addU16(outfit.getId());
msg.addU8(outfit.getHead());
msg.addU8(outfit.getBody());
msg.addU8(outfit.getLegs());
msg.addU8(outfit.getFeet());
msg.addU8(outfit.getAddons());
send(oMsg);
send(msg);
}
void ProtocolGame::sendAddVip(const std::string& name)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientAddBuddy);
oMsg.addString(name);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientAddVip);
msg.addString(name);
send(msg);
}
void ProtocolGame::sendRemoveVip(uint playerId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRemoveBuddy);
oMsg.addU32(playerId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientRemoveVip);
msg.addU32(playerId);
send(msg);
}
// bug report
// violation window
// debug assert
void ProtocolGame::sendGetQuestLog()
void ProtocolGame::sendRequestQuestLog()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGetQuestLog);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientRequestQuestLog);
send(msg);
}
void ProtocolGame::sendGetQuestLine(int questId)
void ProtocolGame::sendRequestQuestLine(int questLine)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGetQuestLine);
oMsg.addU16(questId);
send(oMsg);
OutputMessage msg;
msg.addU8(Proto::ClientRequestQuestLine);
msg.addU16(questLine);
send(msg);
}
void ProtocolGame::addPosition(OutputMessage& msg, const Position& position)