Otclient  14/8/2020
game.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #include "game.h"
24 #include "localplayer.h"
25 #include "map.h"
26 #include "tile.h"
27 #include "creature.h"
28 #include "container.h"
29 #include "statictext.h"
31 #include <framework/ui/uimanager.h>
33 #include "luavaluecasts.h"
34 #include "protocolgame.h"
35 #include "protocolcodes.h"
36 
38 
40 {
41  m_protocolVersion = 0;
42  m_clientCustomOs = -1;
43  m_clientVersion = 0;
44  m_online = false;
45  m_denyBotCall = false;
46  m_dead = false;
47  m_serverBeat = 50;
48  m_seq = 0;
49  m_ping = -1;
50  m_pingDelay = 1000;
51  m_canReportBugs = false;
52  m_fightMode = Otc::FightBalanced;
53  m_chaseMode = Otc::DontChase;
54  m_pvpMode = Otc::WhiteDove;
55  m_safeFight = true;
56 }
57 
58 void Game::init()
59 {
60  resetGameStates();
61 }
62 
64 {
65  resetGameStates();
66  m_protocolGame = nullptr;
67 }
68 
69 void Game::resetGameStates()
70 {
71  m_online = false;
72  m_denyBotCall = false;
73  m_dead = false;
74  m_serverBeat = 50;
75  m_seq = 0;
76  m_ping = -1;
77  m_canReportBugs = false;
78  m_fightMode = Otc::FightBalanced;
79  m_chaseMode = Otc::DontChase;
80  m_pvpMode = Otc::WhiteDove;
81  m_safeFight = true;
82  m_followingCreature = nullptr;
83  m_attackingCreature = nullptr;
84  m_localPlayer = nullptr;
85  m_pingSent = 0;
86  m_pingReceived = 0;
87  m_unjustifiedPoints = UnjustifiedPoints();
88 
89  for(auto& it : m_containers) {
90  const ContainerPtr& container = it.second;
91  if(container)
92  container->onClose();
93  }
94 
95  if(m_pingEvent) {
96  m_pingEvent->cancel();
97  m_pingEvent = nullptr;
98  }
99 
100  if(m_walkEvent) {
101  m_walkEvent->cancel();
102  m_walkEvent = nullptr;
103  }
104 
105  if(m_checkConnectionEvent) {
106  m_checkConnectionEvent->cancel();
107  m_checkConnectionEvent = nullptr;
108  }
109 
110  m_containers.clear();
111  m_vips.clear();
112  m_gmActions.clear();
114 }
115 
116 void Game::processConnectionError(const boost::system::error_code& ec)
117 {
118  // connection errors only have meaning if we still have a protocol
119  if(m_protocolGame) {
120  // eof = end of file, a clean disconnect
121  if(ec != asio::error::eof)
122  g_lua.callGlobalField("g_game", "onConnectionError", ec.message(), ec.value());
123 
125  }
126 }
127 
129 {
130  if(isOnline())
131  processGameEnd();
132 
133  if(m_protocolGame) {
134  m_protocolGame->disconnect();
135  m_protocolGame = nullptr;
136  }
137 }
138 
139 void Game::processUpdateNeeded(const std::string& signature)
140 {
141  g_lua.callGlobalField("g_game", "onUpdateNeeded", signature);
142 }
143 
144 void Game::processLoginError(const std::string& error)
145 {
146  g_lua.callGlobalField("g_game", "onLoginError", error);
147 }
148 
149 void Game::processLoginAdvice(const std::string& message)
150 {
151  g_lua.callGlobalField("g_game", "onLoginAdvice", message);
152 }
153 
154 void Game::processLoginWait(const std::string& message, int time)
155 {
156  g_lua.callGlobalField("g_game", "onLoginWait", message, time);
157 }
158 
159 void Game::processLoginToken(bool unknown)
160 {
161  g_lua.callGlobalField("g_game", "onLoginToken", unknown);
162 }
163 
165 {
166  g_lua.callGlobalField("g_game", "onLogin");
167 }
168 
170 {
171  m_localPlayer->setPendingGame(true);
172  g_lua.callGlobalField("g_game", "onPendingGame");
173  m_protocolGame->sendEnterGame();
174 }
175 
177 {
178  m_localPlayer->setPendingGame(false);
179  g_lua.callGlobalField("g_game", "onEnterGame");
180 }
181 
183 {
184  m_online = true;
185 
186  // synchronize fight modes with the server
187  m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
188 
189  // NOTE: the entire map description and local player information is not known yet (bot call is allowed here)
190  enableBotCall();
191  g_lua.callGlobalField("g_game", "onGameStart");
192  disableBotCall();
193 
195  m_pingEvent = g_dispatcher.scheduleEvent([this] {
196  g_game.ping();
197  }, m_pingDelay);
198  }
199 
200  m_checkConnectionEvent = g_dispatcher.cycleEvent([this] {
201  if(!g_game.isConnectionOk() && !m_connectionFailWarned) {
202  g_lua.callGlobalField("g_game", "onConnectionFailing", true);
203  m_connectionFailWarned = true;
204  } else if(g_game.isConnectionOk() && m_connectionFailWarned) {
205  g_lua.callGlobalField("g_game", "onConnectionFailing", false);
206  m_connectionFailWarned = false;
207  }
208  }, 1000);
209 }
210 
212 {
213  m_online = false;
214  g_lua.callGlobalField("g_game", "onGameEnd");
215 
216  if(m_connectionFailWarned) {
217  g_lua.callGlobalField("g_game", "onConnectionFailing", false);
218  m_connectionFailWarned = false;
219  }
220 
221  // reset game state
222  resetGameStates();
223 
224  m_worldName = "";
225  m_characterName = "";
226 
227  // clean map creatures
229 }
230 
231 void Game::processDeath(int deathType, int penality)
232 {
233  m_dead = true;
234  m_localPlayer->stopWalk();
235 
236  g_lua.callGlobalField("g_game", "onDeath", deathType, penality);
237 }
238 
239 void Game::processGMActions(const std::vector<uint8>& actions)
240 {
241  m_gmActions = actions;
242  g_lua.callGlobalField("g_game", "onGMActions", actions);
243 }
244 
245 void Game::processPlayerHelpers(int helpers)
246 {
247  g_lua.callGlobalField("g_game", "onPlayerHelpersUpdate", helpers);
248 }
249 
250 void Game::processPlayerModes(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeMode, Otc::PVPModes pvpMode)
251 {
252  m_fightMode = fightMode;
253  m_chaseMode = chaseMode;
254  m_safeFight = safeMode;
255  m_pvpMode = pvpMode;
256 
257  g_lua.callGlobalField("g_game", "onFightModeChange", fightMode);
258  g_lua.callGlobalField("g_game", "onChaseModeChange", chaseMode);
259  g_lua.callGlobalField("g_game", "onSafeFightChange", safeMode);
260  g_lua.callGlobalField("g_game", "onPVPModeChange", pvpMode);
261 }
262 
264 {
265  g_lua.callGlobalField("g_game", "onPing");
266  enableBotCall();
267  m_protocolGame->sendPingBack();
268  disableBotCall();
269 }
270 
272 {
273  m_pingReceived++;
274 
275  if(m_pingReceived == m_pingSent)
276  m_ping = m_pingTimer.elapsed_millis();
277  else
278  g_logger.error("got an invalid ping from server");
279 
280  g_lua.callGlobalField("g_game", "onPingBack", m_ping);
281 
282  m_pingEvent = g_dispatcher.scheduleEvent([this] {
283  g_game.ping();
284  }, m_pingDelay);
285 }
286 
287 void Game::processTextMessage(Otc::MessageMode mode, const std::string& text)
288 {
289  g_lua.callGlobalField("g_game", "onTextMessage", mode, text);
290 }
291 
292 void Game::processTalk(const std::string& name, int level, Otc::MessageMode mode, const std::string& text, int channelId, const Position& pos)
293 {
294  g_lua.callGlobalField("g_game", "onTalk", name, level, mode, text, channelId, pos);
295 }
296 
297 void Game::processOpenContainer(int containerId, const ItemPtr& containerItem, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items, bool isUnlocked, bool hasPages, int containerSize, int firstIndex)
298 {
299  ContainerPtr previousContainer = getContainer(containerId);
300  ContainerPtr container = ContainerPtr(new Container(containerId, capacity, name, containerItem, hasParent, isUnlocked, hasPages, containerSize, firstIndex));
301  m_containers[containerId] = container;
302  container->onAddItems(items);
303 
304  // we might want to close a container here
305  enableBotCall();
306  container->onOpen(previousContainer);
307  disableBotCall();
308 
309  if(previousContainer)
310  previousContainer->onClose();
311 }
312 
313 void Game::processCloseContainer(int containerId)
314 {
315  ContainerPtr container = getContainer(containerId);
316  if(!container) {
317  return;
318  }
319 
320  m_containers[containerId] = nullptr;
321  container->onClose();
322 }
323 
324 void Game::processContainerAddItem(int containerId, const ItemPtr& item, int slot)
325 {
326  ContainerPtr container = getContainer(containerId);
327  if(!container) {
328  return;
329  }
330 
331  container->onAddItem(item, slot);
332 }
333 
334 void Game::processContainerUpdateItem(int containerId, int slot, const ItemPtr& item)
335 {
336  ContainerPtr container = getContainer(containerId);
337  if(!container) {
338  return;
339  }
340 
341  container->onUpdateItem(slot, item);
342 }
343 
344 void Game::processContainerRemoveItem(int containerId, int slot, const ItemPtr& lastItem)
345 {
346  ContainerPtr container = getContainer(containerId);
347  if(!container) {
348  return;
349  }
350 
351  container->onRemoveItem(slot, lastItem);
352 }
353 
354 void Game::processInventoryChange(int slot, const ItemPtr& item)
355 {
356  if(item)
357  item->setPosition(Position(65535, slot, 0));
358 
359  m_localPlayer->setInventoryItem((Otc::InventorySlot)slot, item);
360 }
361 
362 void Game::processChannelList(const std::vector<std::tuple<int, std::string> >& channelList)
363 {
364  g_lua.callGlobalField("g_game", "onChannelList", channelList);
365 }
366 
367 void Game::processOpenChannel(int channelId, const std::string& name)
368 {
369  g_lua.callGlobalField("g_game", "onOpenChannel", channelId, name);
370 }
371 
372 void Game::processOpenPrivateChannel(const std::string& name)
373 {
374  g_lua.callGlobalField("g_game", "onOpenPrivateChannel", name);
375 }
376 
377 void Game::processOpenOwnPrivateChannel(int channelId, const std::string& name)
378 {
379  g_lua.callGlobalField("g_game", "onOpenOwnPrivateChannel", channelId, name);
380 }
381 
382 void Game::processCloseChannel(int channelId)
383 {
384  g_lua.callGlobalField("g_game", "onCloseChannel", channelId);
385 }
386 
388 {
389  g_lua.callGlobalField("g_game", "onRuleViolationChannel", channelId);
390 }
391 
392 void Game::processRuleViolationRemove(const std::string& name)
393 {
394  g_lua.callGlobalField("g_game", "onRuleViolationRemove", name);
395 }
396 
397 void Game::processRuleViolationCancel(const std::string& name)
398 {
399  g_lua.callGlobalField("g_game", "onRuleViolationCancel", name);
400 }
401 
403 {
404  g_lua.callGlobalField("g_game", "onRuleViolationLock");
405 }
406 
407 void Game::processVipAdd(uint id, const std::string& name, uint status, const std::string& description, int iconId, bool notifyLogin)
408 {
409  m_vips[id] = Vip(name, status, description, iconId, notifyLogin);
410  g_lua.callGlobalField("g_game", "onAddVip", id, name, status, description, iconId, notifyLogin);
411 }
412 
414 {
415  std::get<1>(m_vips[id]) = status;
416  g_lua.callGlobalField("g_game", "onVipStateChange", id, status);
417 }
418 
420 {
421  g_lua.callGlobalField("g_game", "onTutorialHint", id);
422 }
423 
424 void Game::processAddAutomapFlag(const Position& pos, int icon, const std::string& message)
425 {
426  g_lua.callGlobalField("g_game", "onAddAutomapFlag", pos, icon, message);
427 }
428 
429 void Game::processRemoveAutomapFlag(const Position& pos, int icon, const std::string& message)
430 {
431  g_lua.callGlobalField("g_game", "onRemoveAutomapFlag", pos, icon, message);
432 }
433 
434 void Game::processOpenOutfitWindow(const Outfit& currentOutfit, const std::vector<std::tuple<int, std::string, int> >& outfitList,
435  const std::vector<std::tuple<int, std::string> >& mountList)
436 {
437  // create virtual creature outfit
438  CreaturePtr virtualOutfitCreature = CreaturePtr(new Creature);
439  virtualOutfitCreature->setDirection(Otc::South);
440 
441  Outfit outfit = currentOutfit;
442  outfit.setMount(0);
443  virtualOutfitCreature->setOutfit(outfit);
444 
445  // creature virtual mount outfit
446  CreaturePtr virtualMountCreature = nullptr;
448  {
449  virtualMountCreature = CreaturePtr(new Creature);
450  virtualMountCreature->setDirection(Otc::South);
451 
452  Outfit mountOutfit;
453  mountOutfit.setId(0);
454 
455  int mount = currentOutfit.getMount();
456  if(mount > 0)
457  mountOutfit.setId(mount);
458 
459  virtualMountCreature->setOutfit(mountOutfit);
460  }
461 
462  g_lua.callGlobalField("g_game", "onOpenOutfitWindow", virtualOutfitCreature, outfitList, virtualMountCreature, mountList);
463 }
464 
465 void Game::processOpenNpcTrade(const std::vector<std::tuple<ItemPtr, std::string, int, int, int> >& items)
466 {
467  g_lua.callGlobalField("g_game", "onOpenNpcTrade", items);
468 }
469 
470 void Game::processPlayerGoods(int money, const std::vector<std::tuple<ItemPtr, int> >& goods)
471 {
472  g_lua.callGlobalField("g_game", "onPlayerGoods", money, goods);
473 }
474 
476 {
477  g_lua.callGlobalField("g_game", "onCloseNpcTrade");
478 }
479 
480 void Game::processOwnTrade(const std::string& name, const std::vector<ItemPtr>& items)
481 {
482  g_lua.callGlobalField("g_game", "onOwnTrade", name, items);
483 }
484 
485 void Game::processCounterTrade(const std::string& name, const std::vector<ItemPtr>& items)
486 {
487  g_lua.callGlobalField("g_game", "onCounterTrade", name, items);
488 }
489 
491 {
492  g_lua.callGlobalField("g_game", "onCloseTrade");
493 }
494 
495 void Game::processEditText(uint id, int itemId, int maxLength, const std::string& text, const std::string& writer, const std::string& date)
496 {
497  g_lua.callGlobalField("g_game", "onEditText", id, itemId, maxLength, text, writer, date);
498 }
499 
500 void Game::processEditList(uint id, int doorId, const std::string& text)
501 {
502  g_lua.callGlobalField("g_game", "onEditList", id, doorId, text);
503 }
504 
505 void Game::processQuestLog(const std::vector<std::tuple<int, std::string, bool> >& questList)
506 {
507  g_lua.callGlobalField("g_game", "onQuestLog", questList);
508 }
509 
510 void Game::processQuestLine(int questId, const std::vector<std::tuple<std::string, std::string> >& questMissions)
511 {
512  g_lua.callGlobalField("g_game", "onQuestLine", questId, questMissions);
513 }
514 
515 void Game::processModalDialog(uint32 id, std::string title, std::string message, std::vector<std::tuple<int, std::string> > buttonList, int enterButton, int escapeButton, std::vector<std::tuple<int, std::string> > choiceList, bool priority)
516 {
517  g_lua.callGlobalField("g_game", "onModalDialog", id, title, message, buttonList, enterButton, escapeButton, choiceList, priority);
518 }
519 
521 {
522  if(isAttacking() && (seq == 0 || m_seq == seq))
523  cancelAttack();
524 }
525 
527 {
528  m_localPlayer->cancelWalk(direction);
529 }
530 
531 void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldName, const std::string& worldHost, int worldPort, const std::string& characterName, const std::string& authenticatorToken, const std::string& sessionKey)
532 {
533  if(m_protocolGame || isOnline())
534  stdext::throw_exception("Unable to login into a world while already online or logging.");
535 
536  if(m_protocolVersion == 0)
537  stdext::throw_exception("Must set a valid game protocol version before logging.");
538 
539  // reset the new game state
540  resetGameStates();
541 
542  m_localPlayer = LocalPlayerPtr(new LocalPlayer);
543  m_localPlayer->setName(characterName);
544 
545  m_protocolGame = ProtocolGamePtr(new ProtocolGame);
546  m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName, authenticatorToken, sessionKey);
547  m_characterName = characterName;
548  m_worldName = worldName;
549 }
550 
552 {
553  // send logout even if the game has not started yet, to make sure that the player doesn't stay logged there
554  if(m_protocolGame)
555  m_protocolGame->sendLogout();
556 
558 }
559 
561 {
562  if(!isOnline())
563  return;
564 
565  m_protocolGame->sendLogout();
567 }
568 
570 {
571  if(!isOnline())
572  return;
573 
574  m_protocolGame->sendLogout();
575 }
576 
577 bool Game::walk(Otc::Direction direction, bool dash)
578 {
579  if(!canPerformGameAction())
580  return false;
581 
582  // must cancel follow before any new walk
583  if(isFollowing())
584  cancelFollow();
585 
586  // must cancel auto walking, and wait next try
587  if(m_localPlayer->isAutoWalking() || m_localPlayer->isServerWalking()) {
588  m_protocolGame->sendStop();
589  if(m_localPlayer->isAutoWalking())
590  m_localPlayer->stopAutoWalk();
591  return false;
592  }
593 
594  if(dash) {
595  if(m_localPlayer->isWalking() && m_dashTimer.ticksElapsed() < std::max<int>(m_localPlayer->getStepDuration(false, direction) - m_ping, 30))
596  return false;
597  }
598  else {
599  // check we can walk and add new walk event if false
600  if(!m_localPlayer->canWalk(direction)) {
601  if(m_lastWalkDir != direction) {
602  // must add a new walk event
603  float ticks = m_localPlayer->getStepTicksLeft();
604  if(ticks <= 0) { ticks = 1; }
605 
606  if(m_walkEvent) {
607  m_walkEvent->cancel();
608  m_walkEvent = nullptr;
609  }
610  m_walkEvent = g_dispatcher.scheduleEvent([=] { walk(direction, false); }, ticks);
611  }
612  return false;
613  }
614  }
615 
616  Position toPos = m_localPlayer->getPosition().translatedToDirection(direction);
617  TilePtr toTile = g_map.getTile(toPos);
618  // only do prewalks to walkable tiles (like grounds and not walls)
619  if(toTile && toTile->isWalkable()) {
620  m_localPlayer->preWalk(direction);
621  // check walk to another floor (e.g: when above 3 parcels)
622  } else {
623  // check if can walk to a lower floor
624  auto canChangeFloorDown = [&]() -> bool {
625  Position pos = toPos;
626  if(!pos.down())
627  return false;
628  TilePtr toTile = g_map.getTile(pos);
629  if(toTile && toTile->hasElevation(3))
630  return true;
631  return false;
632  };
633 
634  // check if can walk to a higher floor
635  auto canChangeFloorUp = [&]() -> bool {
636  TilePtr fromTile = m_localPlayer->getTile();
637  if(!fromTile || !fromTile->hasElevation(3))
638  return false;
639  Position pos = toPos;
640  if(!pos.up())
641  return false;
642  TilePtr toTile = g_map.getTile(pos);
643  if(!toTile || !toTile->isWalkable())
644  return false;
645  return true;
646  };
647 
648  if(canChangeFloorDown() || canChangeFloorUp() ||
649  (!toTile || toTile->isEmpty())) {
650  m_localPlayer->lockWalk();
651  } else
652  return false;
653  }
654 
655  m_localPlayer->stopAutoWalk();
656 
657  if(getClientVersion() <= 740) {
658  const TilePtr& fromTile = g_map.getTile(m_localPlayer->getPosition());
659  if (fromTile && toTile && (toTile->getElevation() - 1 > fromTile->getElevation()))
660  return false;
661  }
662 
663  g_lua.callGlobalField("g_game", "onWalk", direction, dash);
664 
665  forceWalk(direction);
666  if(dash)
667  m_dashTimer.restart();
668 
669  m_lastWalkDir = direction;
670  return true;
671 }
672 
674 {
675  return walk(direction, true);
676 }
677 
678 void Game::autoWalk(std::vector<Otc::Direction> dirs)
679 {
680  if(!canPerformGameAction())
681  return;
682 
683  // protocol limits walk path up to 255 directions
684  if(dirs.size() > 127) {
685  g_logger.error("Auto walk path too great, the maximum number of directions is 127");
686  return;
687  }
688 
689  if(dirs.empty())
690  return;
691 
692  // must cancel follow before any new walk
693  if(isFollowing())
694  cancelFollow();
695 
696  auto it = dirs.begin();
697  Otc::Direction direction = *it;
698  if(!m_localPlayer->canWalk(direction))
699  return;
700 
701  TilePtr toTile = g_map.getTile(m_localPlayer->getPosition().translatedToDirection(direction));
702  if(toTile && toTile->isWalkable() && !m_localPlayer->isServerWalking()) {
703  m_localPlayer->preWalk(direction);
704 
706  forceWalk(direction);
707  dirs.erase(it);
708  }
709  }
710 
711  g_lua.callGlobalField("g_game", "onAutoWalk", dirs);
712 
713  m_protocolGame->sendAutoWalk(dirs);
714 }
715 
717 {
718  if(!canPerformGameAction())
719  return;
720 
721  switch(direction) {
722  case Otc::North:
723  m_protocolGame->sendWalkNorth();
724  break;
725  case Otc::East:
726  m_protocolGame->sendWalkEast();
727  break;
728  case Otc::South:
729  m_protocolGame->sendWalkSouth();
730  break;
731  case Otc::West:
732  m_protocolGame->sendWalkWest();
733  break;
734  case Otc::NorthEast:
735  m_protocolGame->sendWalkNorthEast();
736  break;
737  case Otc::SouthEast:
738  m_protocolGame->sendWalkSouthEast();
739  break;
740  case Otc::SouthWest:
741  m_protocolGame->sendWalkSouthWest();
742  break;
743  case Otc::NorthWest:
744  m_protocolGame->sendWalkNorthWest();
745  break;
746  default:
747  break;
748  }
749 
750  g_lua.callGlobalField("g_game", "onForceWalk", direction);
751 }
752 
753 void Game::turn(Otc::Direction direction)
754 {
755  if(!canPerformGameAction())
756  return;
757 
758  switch(direction) {
759  case Otc::North:
760  m_protocolGame->sendTurnNorth();
761  break;
762  case Otc::East:
763  m_protocolGame->sendTurnEast();
764  break;
765  case Otc::South:
766  m_protocolGame->sendTurnSouth();
767  break;
768  case Otc::West:
769  m_protocolGame->sendTurnWest();
770  break;
771  default:
772  break;
773  }
774 }
775 
777 {
778  if(!canPerformGameAction())
779  return;
780 
781  if(isFollowing())
782  cancelFollow();
783 
784  m_protocolGame->sendStop();
785 }
786 
787 void Game::look(const ThingPtr& thing, bool isBattleList)
788 {
789  if(!canPerformGameAction() || !thing)
790  return;
791 
792  if(thing->isCreature() && isBattleList && m_protocolVersion >= 961)
793  m_protocolGame->sendLookCreature(thing->getId());
794  else
795  m_protocolGame->sendLook(thing->getPosition(), thing->getId(), thing->getStackPos());
796 }
797 
798 void Game::move(const ThingPtr& thing, const Position& toPos, int count)
799 {
800  if(count <= 0)
801  count = 1;
802 
803  if(!canPerformGameAction() || !thing || thing->getPosition() == toPos)
804  return;
805 
806  uint id = thing->getId();
807  if(thing->isCreature()) {
808  CreaturePtr creature = thing->static_self_cast<Creature>();
809  id = Proto::Creature;
810  }
811 
812  m_protocolGame->sendMove(thing->getPosition(), id, thing->getStackPos(), toPos, count);
813 }
814 
815 void Game::moveToParentContainer(const ThingPtr& thing, int count)
816 {
817  if(!canPerformGameAction() || !thing || count <= 0)
818  return;
819 
820  Position position = thing->getPosition();
821  move(thing, Position(position.x, position.y, 254), count);
822 }
823 
824 void Game::rotate(const ThingPtr& thing)
825 {
826  if(!canPerformGameAction() || !thing)
827  return;
828 
829  m_protocolGame->sendRotateItem(thing->getPosition(), thing->getId(), thing->getStackPos());
830 }
831 
832 void Game::use(const ThingPtr& thing)
833 {
834  if(!canPerformGameAction() || !thing)
835  return;
836 
837  Position pos = thing->getPosition();
838  if(!pos.isValid()) // virtual item
839  pos = Position(0xFFFF, 0, 0); // inventory item
840 
841  // some items, e.g. parcel, are not set as containers but they are.
842  // always try to use these items in free container slots.
843  m_protocolGame->sendUseItem(pos, thing->getId(), thing->getStackPos(), findEmptyContainerId());
844 }
845 
846 void Game::useInventoryItem(int itemId)
847 {
849  return;
850 
851  Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
852 
853  m_protocolGame->sendUseItem(pos, itemId, 0, 0);
854 }
855 
856 void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
857 {
858  if(!canPerformGameAction() || !item || !toThing)
859  return;
860 
861  Position pos = item->getPosition();
862  if(!pos.isValid()) // virtual item
863  pos = Position(0xFFFF, 0, 0); // means that is an item in inventory
864 
865  if(toThing->isCreature())
866  m_protocolGame->sendUseOnCreature(pos, item->getId(), item->getStackPos(), toThing->getId());
867  else
868  m_protocolGame->sendUseItemWith(pos, item->getId(), item->getStackPos(), toThing->getPosition(), toThing->getId(), toThing->getStackPos());
869 }
870 
871 void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing)
872 {
873  if(!canPerformGameAction() || !toThing)
874  return;
875 
876  Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
877 
878  if(toThing->isCreature())
879  m_protocolGame->sendUseOnCreature(pos, itemId, 0, toThing->getId());
880  else
881  m_protocolGame->sendUseItemWith(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackPos());
882 }
883 
885 {
886  for(auto& it : m_containers) {
887  const ContainerPtr& container = it.second;
888 
889  if(container) {
890  ItemPtr item = container->findItemById(itemId, subType);
891  if(item != nullptr)
892  return item;
893  }
894  }
895  return nullptr;
896 }
897 
898 int Game::open(const ItemPtr& item, const ContainerPtr& previousContainer)
899 {
900  if(!canPerformGameAction() || !item)
901  return -1;
902 
903  int id = 0;
904  if(!previousContainer)
905  id = findEmptyContainerId();
906  else
907  id = previousContainer->getId();
908 
909  m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackPos(), id);
910  return id;
911 }
912 
913 void Game::openParent(const ContainerPtr& container)
914 {
915  if(!canPerformGameAction() || !container)
916  return;
917 
918  m_protocolGame->sendUpContainer(container->getId());
919 }
920 
921 void Game::close(const ContainerPtr& container)
922 {
923  if(!canPerformGameAction() || !container)
924  return;
925 
926  m_protocolGame->sendCloseContainer(container->getId());
927 }
928 
929 void Game::refreshContainer(const ContainerPtr& container)
930 {
931  if(!canPerformGameAction())
932  return;
933  m_protocolGame->sendRefreshContainer(container->getId());
934 }
935 
936 void Game::attack(CreaturePtr creature)
937 {
938  if(!canPerformGameAction() || creature == m_localPlayer)
939  return;
940 
941  // cancel when attacking again
942  if(creature && creature == m_attackingCreature)
943  creature = nullptr;
944 
945  if(creature && isFollowing())
946  cancelFollow();
947 
948  setAttackingCreature(creature);
949  m_localPlayer->stopAutoWalk();
950 
951  if(m_protocolVersion >= 963) {
952  if(creature)
953  m_seq = creature->getId();
954  } else
955  m_seq++;
956 
957  m_protocolGame->sendAttack(creature ? creature->getId() : 0, m_seq);
958 }
959 
960 void Game::follow(CreaturePtr creature)
961 {
962  if(!canPerformGameAction() || creature == m_localPlayer)
963  return;
964 
965  // cancel when following again
966  if(creature && creature == m_followingCreature)
967  creature = nullptr;
968 
969  if(creature && isAttacking())
970  cancelAttack();
971 
972  setFollowingCreature(creature);
973  m_localPlayer->stopAutoWalk();
974 
975  if(m_protocolVersion >= 963) {
976  if(creature)
977  m_seq = creature->getId();
978  } else
979  m_seq++;
980 
981  m_protocolGame->sendFollow(creature ? creature->getId() : 0, m_seq);
982 }
983 
985 {
986  if(!canPerformGameAction())
987  return;
988 
989  if(isFollowing())
990  setFollowingCreature(nullptr);
991  if(isAttacking())
992  setAttackingCreature(nullptr);
993 
994  m_localPlayer->stopAutoWalk();
995 
996  m_protocolGame->sendCancelAttackAndFollow();
997 
998  g_lua.callGlobalField("g_game", "onCancelAttackAndFollow");
999 }
1000 
1001 void Game::talk(const std::string& message)
1002 {
1003  if(!canPerformGameAction() || message.empty())
1004  return;
1005  talkChannel(Otc::MessageSay, 0, message);
1006 }
1007 
1008 void Game::talkChannel(Otc::MessageMode mode, int channelId, const std::string& message)
1009 {
1010  if(!canPerformGameAction() || message.empty())
1011  return;
1012  m_protocolGame->sendTalk(mode, channelId, "", message);
1013 }
1014 
1015 void Game::talkPrivate(Otc::MessageMode mode, const std::string& receiver, const std::string& message)
1016 {
1017  if(!canPerformGameAction() || receiver.empty() || message.empty())
1018  return;
1019  m_protocolGame->sendTalk(mode, 0, receiver, message);
1020 }
1021 
1022 void Game::openPrivateChannel(const std::string& receiver)
1023 {
1024  if(!canPerformGameAction() || receiver.empty())
1025  return;
1026  m_protocolGame->sendOpenPrivateChannel(receiver);
1027 }
1028 
1030 {
1031  if(!canPerformGameAction())
1032  return;
1033  m_protocolGame->sendRequestChannels();
1034 }
1035 
1036 void Game::joinChannel(int channelId)
1037 {
1038  if(!canPerformGameAction())
1039  return;
1040  m_protocolGame->sendJoinChannel(channelId);
1041 }
1042 
1043 void Game::leaveChannel(int channelId)
1044 {
1045  if(!canPerformGameAction())
1046  return;
1047  m_protocolGame->sendLeaveChannel(channelId);
1048 }
1049 
1051 {
1052  if(!canPerformGameAction())
1053  return;
1054  m_protocolGame->sendCloseNpcChannel();
1055 }
1056 
1058 {
1059  if(!canPerformGameAction())
1060  return;
1061  m_protocolGame->sendOpenOwnChannel();
1062 }
1063 
1064 void Game::inviteToOwnChannel(const std::string& name)
1065 {
1066  if(!canPerformGameAction() || name.empty())
1067  return;
1068  m_protocolGame->sendInviteToOwnChannel(name);
1069 }
1070 
1071 void Game::excludeFromOwnChannel(const std::string& name)
1072 {
1073  if(!canPerformGameAction() || name.empty())
1074  return;
1075  m_protocolGame->sendExcludeFromOwnChannel(name);
1076 }
1077 
1078 void Game::partyInvite(int creatureId)
1079 {
1080  if(!canPerformGameAction())
1081  return;
1082  m_protocolGame->sendInviteToParty(creatureId);
1083 }
1084 
1085 void Game::partyJoin(int creatureId)
1086 {
1087  if(!canPerformGameAction())
1088  return;
1089  m_protocolGame->sendJoinParty(creatureId);
1090 }
1091 
1092 void Game::partyRevokeInvitation(int creatureId)
1093 {
1094  if(!canPerformGameAction())
1095  return;
1096  m_protocolGame->sendRevokeInvitation(creatureId);
1097 }
1098 
1099 void Game::partyPassLeadership(int creatureId)
1100 {
1101  if(!canPerformGameAction())
1102  return;
1103  m_protocolGame->sendPassLeadership(creatureId);
1104 }
1105 
1107 {
1108  if(!canPerformGameAction())
1109  return;
1110  m_protocolGame->sendLeaveParty();
1111 }
1112 
1114 {
1115  if(!canPerformGameAction())
1116  return;
1117  m_protocolGame->sendShareExperience(active);
1118 }
1119 
1121 {
1122  if(!canPerformGameAction())
1123  return;
1124  m_protocolGame->sendRequestOutfit();
1125 }
1126 
1127 void Game::changeOutfit(const Outfit& outfit)
1128 {
1129  if(!canPerformGameAction())
1130  return;
1131  m_protocolGame->sendChangeOutfit(outfit);
1132 }
1133 
1134 void Game::addVip(const std::string& name)
1135 {
1136  if(!canPerformGameAction() || name.empty())
1137  return;
1138  m_protocolGame->sendAddVip(name);
1139 }
1140 
1141 void Game::removeVip(int playerId)
1142 {
1143  if(!canPerformGameAction())
1144  return;
1145 
1146  auto it = m_vips.find(playerId);
1147  if(it == m_vips.end())
1148  return;
1149  m_vips.erase(it);
1150  m_protocolGame->sendRemoveVip(playerId);
1151 }
1152 
1153 void Game::editVip(int playerId, const std::string& description, int iconId, bool notifyLogin)
1154 {
1155  if(!canPerformGameAction())
1156  return;
1157 
1158  auto it = m_vips.find(playerId);
1159  if(it == m_vips.end())
1160  return;
1161 
1162  std::get<2>(m_vips[playerId]) = description;
1163  std::get<3>(m_vips[playerId]) = iconId;
1164  std::get<4>(m_vips[playerId]) = notifyLogin;
1165 
1167  m_protocolGame->sendEditVip(playerId, description, iconId, notifyLogin);
1168 }
1169 
1171 {
1172  if(!canPerformGameAction())
1173  return;
1174  if(m_chaseMode == chaseMode)
1175  return;
1176  m_chaseMode = chaseMode;
1177  m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
1178  g_lua.callGlobalField("g_game", "onChaseModeChange", chaseMode);
1179 }
1180 
1182 {
1183  if(!canPerformGameAction())
1184  return;
1185  if(m_fightMode == fightMode)
1186  return;
1187  m_fightMode = fightMode;
1188  m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
1189  g_lua.callGlobalField("g_game", "onFightModeChange", fightMode);
1190 }
1191 
1192 void Game::setSafeFight(bool on)
1193 {
1194  if(!canPerformGameAction())
1195  return;
1196  if(m_safeFight == on)
1197  return;
1198  m_safeFight = on;
1199  m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
1200  g_lua.callGlobalField("g_game", "onSafeFightChange", on);
1201 }
1202 
1204 {
1205  if(!canPerformGameAction())
1206  return;
1208  return;
1209  if(m_pvpMode == pvpMode)
1210  return;
1211  m_pvpMode = pvpMode;
1212  m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
1213  g_lua.callGlobalField("g_game", "onPVPModeChange", pvpMode);
1214 }
1215 
1217 {
1218  if(!canPerformGameAction())
1219  return;
1221  return;
1222  if(m_unjustifiedPoints == unjustifiedPoints)
1223  return;
1224 
1225  m_unjustifiedPoints = unjustifiedPoints;
1226  g_lua.callGlobalField("g_game", "onUnjustifiedPointsChange", unjustifiedPoints);
1227 }
1228 
1229 void Game::setOpenPvpSituations(int openPvpSituations)
1230 {
1231  if(!canPerformGameAction())
1232  return;
1233  if(m_openPvpSituations == openPvpSituations)
1234  return;
1235 
1236  m_openPvpSituations = openPvpSituations;
1237  g_lua.callGlobalField("g_game", "onOpenPvpSituationsChange", openPvpSituations);
1238 }
1239 
1240 
1242 {
1243  if(!canPerformGameAction() || !item)
1244  return;
1245  m_protocolGame->sendInspectNpcTrade(item->getId(), item->getCount());
1246 }
1247 
1248 void Game::buyItem(const ItemPtr& item, int amount, bool ignoreCapacity, bool buyWithBackpack)
1249 {
1250  if(!canPerformGameAction() || !item)
1251  return;
1252  m_protocolGame->sendBuyItem(item->getId(), item->getCountOrSubType(), amount, ignoreCapacity, buyWithBackpack);
1253 }
1254 
1255 void Game::sellItem(const ItemPtr& item, int amount, bool ignoreEquipped)
1256 {
1257  if(!canPerformGameAction() || !item)
1258  return;
1259  m_protocolGame->sendSellItem(item->getId(), item->getSubType(), amount, ignoreEquipped);
1260 }
1261 
1263 {
1264  if(!canPerformGameAction())
1265  return;
1266  m_protocolGame->sendCloseNpcTrade();
1267 }
1268 
1269 void Game::requestTrade(const ItemPtr& item, const CreaturePtr& creature)
1270 {
1271  if(!canPerformGameAction() || !item || !creature)
1272  return;
1273  m_protocolGame->sendRequestTrade(item->getPosition(), item->getId(), item->getStackPos(), creature->getId());
1274 }
1275 
1276 void Game::inspectTrade(bool counterOffer, int index)
1277 {
1278  if(!canPerformGameAction())
1279  return;
1280  m_protocolGame->sendInspectTrade(counterOffer, index);
1281 }
1282 
1284 {
1285  if(!canPerformGameAction())
1286  return;
1287  m_protocolGame->sendAcceptTrade();
1288 }
1289 
1291 {
1292  if(!canPerformGameAction())
1293  return;
1294  m_protocolGame->sendRejectTrade();
1295 }
1296 
1297 void Game::editText(uint id, const std::string& text)
1298 {
1299  if(!canPerformGameAction())
1300  return;
1301  m_protocolGame->sendEditText(id, text);
1302 }
1303 
1304 void Game::editList(uint id, int doorId, const std::string& text)
1305 {
1306  if(!canPerformGameAction())
1307  return;
1308  m_protocolGame->sendEditList(id, doorId, text);
1309 }
1310 
1311 void Game::openRuleViolation(const std::string& reporter)
1312 {
1313  if(!canPerformGameAction())
1314  return;
1315  m_protocolGame->sendOpenRuleViolation(reporter);
1316 }
1317 
1318 void Game::closeRuleViolation(const std::string& reporter)
1319 {
1320  if(!canPerformGameAction())
1321  return;
1322  m_protocolGame->sendCloseRuleViolation(reporter);
1323 }
1324 
1326 {
1327  if(!canPerformGameAction())
1328  return;
1329  m_protocolGame->sendCancelRuleViolation();
1330 }
1331 
1332 void Game::reportBug(const std::string& comment)
1333 {
1334  if(!canPerformGameAction())
1335  return;
1336  m_protocolGame->sendBugReport(comment);
1337 }
1338 
1339 void Game::reportRuleViolation(const std::string& target, int reason, int action, const std::string& comment, const std::string& statement, int statementId, bool ipBanishment)
1340 {
1341  if(!canPerformGameAction())
1342  return;
1343  m_protocolGame->sendRuleViolation(target, reason, action, comment, statement, statementId, ipBanishment);
1344 }
1345 
1346 void Game::debugReport(const std::string& a, const std::string& b, const std::string& c, const std::string& d)
1347 {
1348  m_protocolGame->sendDebugReport(a, b, c, d);
1349 }
1350 
1352 {
1353  if(!canPerformGameAction())
1354  return;
1355  m_protocolGame->sendRequestQuestLog();
1356 }
1357 
1358 void Game::requestQuestLine(int questId)
1359 {
1360  if(!canPerformGameAction())
1361  return;
1362  m_protocolGame->sendRequestQuestLine(questId);
1363 }
1364 
1365 void Game::equipItem(const ItemPtr& item)
1366 {
1367  if(!canPerformGameAction())
1368  return;
1369  m_protocolGame->sendEquipItem(item->getId(), item->getCountOrSubType());
1370 }
1371 
1372 void Game::mount(bool mount)
1373 {
1374  if(!canPerformGameAction())
1375  return;
1376  m_protocolGame->sendMountStatus(mount);
1377 }
1378 
1379 void Game::requestItemInfo(const ItemPtr& item, int index)
1380 {
1381  if(!canPerformGameAction())
1382  return;
1383  m_protocolGame->sendRequestItemInfo(item->getId(), item->getSubType(), index);
1384 }
1385 
1386 void Game::answerModalDialog(uint32 dialog, int button, int choice)
1387 {
1388  if(!canPerformGameAction())
1389  return;
1390  m_protocolGame->sendAnswerModalDialog(dialog, button, choice);
1391 }
1392 
1393 void Game::browseField(const Position& position)
1394 {
1395  if(!canPerformGameAction())
1396  return;
1397  m_protocolGame->sendBrowseField(position);
1398 }
1399 
1400 void Game::seekInContainer(int cid, int index)
1401 {
1402  if(!canPerformGameAction())
1403  return;
1404  m_protocolGame->sendSeekInContainer(cid, index);
1405 }
1406 
1407 void Game::buyStoreOffer(int offerId, int productType, const std::string& name)
1408 {
1409  if(!canPerformGameAction())
1410  return;
1411  m_protocolGame->sendBuyStoreOffer(offerId, productType, name);
1412 }
1413 
1414 void Game::requestTransactionHistory(int page, int entriesPerPage)
1415 {
1416  if(!canPerformGameAction())
1417  return;
1418  m_protocolGame->sendRequestTransactionHistory(page, entriesPerPage);
1419 }
1420 
1421 void Game::requestStoreOffers(const std::string& categoryName, int serviceType)
1422 {
1423  if(!canPerformGameAction())
1424  return;
1425  m_protocolGame->sendRequestStoreOffers(categoryName, serviceType);
1426 }
1427 
1428 void Game::openStore(int serviceType, const std::string& category)
1429 {
1430  if(!canPerformGameAction())
1431  return;
1432  m_protocolGame->sendOpenStore(serviceType, category);
1433 }
1434 
1435 void Game::transferCoins(const std::string& recipient, int amount)
1436 {
1437  if(!canPerformGameAction())
1438  return;
1439  m_protocolGame->sendTransferCoins(recipient, amount);
1440 }
1441 
1442 void Game::openTransactionHistory(int entriesPerPage)
1443 {
1444  if(!canPerformGameAction())
1445  return;
1446  m_protocolGame->sendOpenTransactionHistory(entriesPerPage);
1447 }
1448 
1450 {
1451  if(!m_protocolGame || !m_protocolGame->isConnected())
1452  return;
1453 
1454  if(m_pingReceived != m_pingSent)
1455  return;
1456 
1457  m_denyBotCall = false;
1458  m_protocolGame->sendPing();
1459  m_denyBotCall = true;
1460  m_pingSent++;
1461  m_pingTimer.restart();
1462 }
1463 
1464 void Game::changeMapAwareRange(int xrange, int yrange)
1465 {
1466  if(!canPerformGameAction())
1467  return;
1468  m_protocolGame->sendChangeMapAwareRange(xrange, yrange);
1469 }
1470 
1472 {
1473 #ifdef BOT_PROTECTION
1474  // accepts calls comming from a stacktrace containing only C++ functions,
1475  // if the stacktrace contains a lua function, then only accept if the engine is processing an input event
1476  if(m_denyBotCall && g_lua.isInCppCallback() && !g_app.isOnInputEvent()) {
1477  g_logger.error(g_lua.traceback("caught a lua call to a bot protected game function, the call was cancelled"));
1478  return false;
1479  }
1480 #endif
1481  return true;
1482 }
1483 
1485 {
1486  // we can only perform game actions if we meet these conditions:
1487  // - the game is online
1488  // - the local player exists
1489  // - the local player is not dead
1490  // - we have a game protocol
1491  // - the game protocol is connected
1492  // - its not a bot action
1493  return m_online && m_localPlayer && !m_localPlayer->isDead() && !m_dead && m_protocolGame && m_protocolGame->isConnected() && checkBotProtection();
1494 }
1495 
1496 void Game::setProtocolVersion(int version)
1497 {
1498  if(m_protocolVersion == version)
1499  return;
1500 
1501  if(isOnline())
1502  stdext::throw_exception("Unable to change protocol version while online");
1503 
1504  if(version != 0 && (version < 740 || version > 1099))
1505  stdext::throw_exception(stdext::format("Protocol version %d not supported", version));
1506 
1507  m_protocolVersion = version;
1508 
1509  Proto::buildMessageModesMap(version);
1510 
1511  g_lua.callGlobalField("g_game", "onProtocolVersionChange", version);
1512 }
1513 
1514 void Game::setClientVersion(int version)
1515 {
1516  if(m_clientVersion == version)
1517  return;
1518 
1519  if(isOnline())
1520  stdext::throw_exception("Unable to change client version while online");
1521 
1522  if(version != 0 && (version < 740 || version > 1099))
1523  stdext::throw_exception(stdext::format("Client version %d not supported", version));
1524 
1525  m_features.reset();
1527 
1528  if(version >= 770) {
1532  }
1533 
1534  if(version >= 780) {
1541  }
1542 
1543  if(version >= 790) {
1545  }
1546 
1547  if(version >= 840) {
1551  }
1552 
1553  if(version >= 841) {
1556  }
1557 
1558  if(version >= 854) {
1560  }
1561 
1562  if(version >= 860) {
1564  }
1565 
1566  if(version >= 862) {
1568  }
1569 
1570  if(version >= 870) {
1574  }
1575 
1576  if(version >= 910) {
1584  }
1585 
1586  if(version >= 940) {
1588  }
1589 
1590  if(version >= 953) {
1593  }
1594 
1595  if(version >= 960) {
1598  }
1599 
1600  if(version >= 963) {
1602  }
1603 
1604  if(version >= 980) {
1607  }
1608 
1609  if(version >= 981) {
1612  }
1613 
1614  if(version >= 984) {
1617  }
1618 
1619  if(version >= 1000) {
1622  }
1623 
1624  if(version >= 1035) {
1627  }
1628 
1629  if(version >= 1036) {
1632  }
1633 
1634  if(version >= 1038) {
1636  }
1637 
1638  if(version >= 1050) {
1640  }
1641 
1642  if(version >= 1053) {
1644  }
1645 
1646  if(version >= 1054) {
1648  }
1649 
1650  if(version >= 1055) {
1652  }
1653 
1654  if(version >= 1057) {
1656  }
1657 
1658  if(version >= 1061) {
1660  }
1661 
1662  if(version >= 1071) {
1664  }
1665 
1666  if(version >= 1072) {
1668  }
1669 
1670  if(version >= 1074) {
1672  }
1673 
1674  if(version >= 1080) {
1676  }
1677 
1678  if(version >= 1092) {
1680  }
1681 
1682  if(version >= 1093) {
1684  }
1685 
1686  if(version >= 1094) {
1688  }
1689 
1690  m_clientVersion = version;
1691 
1692  g_lua.callGlobalField("g_game", "onClientVersionChange", version);
1693 }
1694 
1695 void Game::setAttackingCreature(const CreaturePtr& creature)
1696 {
1697  if(creature != m_attackingCreature) {
1698  CreaturePtr oldCreature = m_attackingCreature;
1699  m_attackingCreature = creature;
1700 
1701  g_lua.callGlobalField("g_game", "onAttackingCreatureChange", creature, oldCreature);
1702  }
1703 }
1704 
1705 void Game::setFollowingCreature(const CreaturePtr& creature)
1706 {
1707  CreaturePtr oldCreature = m_followingCreature;
1708  m_followingCreature = creature;
1709 
1710  g_lua.callGlobalField("g_game", "onFollowingCreatureChange", creature, oldCreature);
1711 }
1712 
1713 std::string Game::formatCreatureName(const std::string& name)
1714 {
1715  std::string formatedName = name;
1716  if(getFeature(Otc::GameFormatCreatureName) && name.length() > 0) {
1717  bool upnext = true;
1718  for(char &i: formatedName) {
1719  char ch = i;
1720  if(upnext) {
1721  i = stdext::upchar(ch);
1722  upnext = false;
1723  }
1724  if(ch == ' ')
1725  upnext = true;
1726  }
1727  }
1728  return formatedName;
1729 }
1730 
1732 {
1733  int id = 0;
1734  while(m_containers[id] != nullptr)
1735  id++;
1736  return id;
1737 }
1738 
1740 {
1741  if(m_clientCustomOs >= 0)
1742  return m_clientCustomOs;
1743 
1744  if(g_app.getOs() == "windows")
1745  return 10;
1746  else if(g_app.getOs() == "mac")
1747  return 12;
1748  else // linux
1749  return 11;
1750 }
Otc::GameThingMarks
@ GameThingMarks
Definition: const.h:384
Game::openRuleViolation
void openRuleViolation(const std::string &reporter)
Definition: game.cpp:1311
Game::findEmptyContainerId
int findEmptyContainerId()
Definition: game.cpp:1731
protocolcodes.h
Position::translatedToDirection
Position translatedToDirection(Otc::Direction direction)
Definition: position.h:41
ProtocolGame::sendWalkSouthWest
void sendWalkSouthWest()
Definition: protocolgamesend.cpp:247
Outfit::getMount
int getMount() const
Definition: outfit.h:60
Otc::GamePVPMode
@ GamePVPMode
Definition: const.h:393
Protocol::disconnect
void disconnect()
Definition: protocol.cpp:50
Game::editList
void editList(uint id, int doorId, const std::string &text)
Definition: game.cpp:1304
ProtocolGame::sendChangeMapAwareRange
void sendChangeMapAwareRange(int xrange, int yrange)
Definition: protocolgamesend.cpp:939
Game::look
void look(const ThingPtr &thing, bool isBattleList=false)
Definition: game.cpp:787
Game::loginWorld
void loginWorld(const std::string &account, const std::string &password, const std::string &worldName, const std::string &worldHost, int worldPort, const std::string &characterName, const std::string &authenticatorToken, const std::string &sessionKey)
Definition: game.cpp:531
Game::cancelRuleViolation
void cancelRuleViolation()
Definition: game.cpp:1325
ProtocolGame::sendCancelAttackAndFollow
void sendCancelAttackAndFollow()
Definition: protocolgamesend.cpp:683
Otc::GameAttackSeq
@ GameAttackSeq
Definition: const.h:375
stdext::timer::restart
void restart()
Definition: time.h:42
Game::close
void close(const ContainerPtr &container)
Definition: game.cpp:921
Game::processQuestLine
void processQuestLine(int questId, const std::vector< std::tuple< std::string, std::string > > &questMissions)
Definition: game.cpp:510
Game::processModalDialog
void processModalDialog(uint32 id, std::string title, std::string message, std::vector< std::tuple< int, std::string > > buttonList, int enterButton, int escapeButton, std::vector< std::tuple< int, std::string > > choiceList, bool priority)
Definition: game.cpp:515
eventdispatcher.h
Game::rejectTrade
void rejectTrade()
Definition: game.cpp:1290
Game::processWalkCancel
void processWalkCancel(Otc::Direction direction)
Definition: game.cpp:526
Game::safeLogout
void safeLogout()
Definition: game.cpp:569
Game::leaveChannel
void leaveChannel(int channelId)
Definition: game.cpp:1043
LocalPlayer::cancelWalk
void cancelWalk(Otc::Direction direction=Otc::InvalidDirection)
Definition: localplayer.cpp:139
g_map
Map g_map
Definition: map.cpp:36
Game::processOpenChannel
void processOpenChannel(int channelId, const std::string &name)
Definition: game.cpp:367
Creature::getId
uint32 getId()
Definition: creature.h:81
LocalPlayer::canWalk
bool canWalk(Otc::Direction direction)
Definition: localplayer.cpp:65
Game::mount
void mount(bool mount)
Definition: game.cpp:1372
ProtocolGame::sendLeaveParty
void sendLeaveParty()
Definition: protocolgamesend.cpp:643
Game::processTextMessage
void processTextMessage(Otc::MessageMode mode, const std::string &text)
Definition: game.cpp:287
Otc::GameNewSpeedLaw
@ GameNewSpeedLaw
Definition: const.h:379
Game::browseField
void browseField(const Position &position)
Definition: game.cpp:1393
Item::getId
uint32 getId()
Definition: item.h:97
ProtocolGame::sendExcludeFromOwnChannel
void sendExcludeFromOwnChannel(const std::string &name)
Definition: protocolgamesend.cpp:675
Game::processOpenOutfitWindow
void processOpenOutfitWindow(const Outfit &currentOutfit, const std::vector< std::tuple< int, std::string, int > > &outfitList, const std::vector< std::tuple< int, std::string > > &mountList)
Definition: game.cpp:434
Thing::getTile
const TilePtr & getTile()
Definition: thing.cpp:62
LocalPlayer::stopWalk
void stopWalk()
Definition: localplayer.cpp:240
ProtocolGame::sendBugReport
void sendBugReport(const std::string &comment)
Definition: protocolgamesend.cpp:763
Game::processPing
void processPing()
Definition: game.cpp:263
Game::closeRuleViolation
void closeRuleViolation(const std::string &reporter)
Definition: game.cpp:1318
Game::processLogin
void processLogin()
Definition: game.cpp:164
Timer::ticksElapsed
ticks_t ticksElapsed()
Definition: timer.cpp:33
Game::inspectNpcTrade
void inspectNpcTrade(const ItemPtr &item)
Definition: game.cpp:1241
Game::processDeath
void processDeath(int deathType, int penality)
Definition: game.cpp:231
Game::isAttacking
bool isAttacking()
Definition: game.h:327
ProtocolGame::sendWalkSouthEast
void sendWalkSouthEast()
Definition: protocolgamesend.cpp:240
Otc::North
@ North
Definition: const.h:162
ProtocolGame::sendJoinChannel
void sendJoinChannel(int channelId)
Definition: protocolgamesend.cpp:525
Game::processEditList
void processEditList(uint id, int doorId, const std::string &text)
Definition: game.cpp:500
Otc::ChaseModes
ChaseModes
Definition: const.h:211
ProtocolGame::sendCloseNpcChannel
void sendCloseNpcChannel()
Definition: protocolgamesend.cpp:572
ProtocolGame::sendLeaveChannel
void sendLeaveChannel(int channelId)
Definition: protocolgamesend.cpp:533
Game::processQuestLog
void processQuestLog(const std::vector< std::tuple< int, std::string, bool > > &questList)
Definition: game.cpp:505
Game::inviteToOwnChannel
void inviteToOwnChannel(const std::string &name)
Definition: game.cpp:1064
Game::processDisconnect
void processDisconnect()
Definition: game.cpp:128
Position::x
int x
Definition: position.h:243
ProtocolGame
Definition: protocolgame.h:31
ProtocolGame::sendPing
void sendPing()
Definition: protocolgamesend.cpp:139
Game::setClientVersion
void setClientVersion(int version)
Definition: game.cpp:1514
LocalPlayer::lockWalk
void lockWalk(int millis=250)
Definition: localplayer.cpp:60
Game::processRuleViolationChannel
void processRuleViolationChannel(int channelId)
Definition: game.cpp:387
Game::setProtocolVersion
void setProtocolVersion(int version)
Definition: game.cpp:1496
Game::isFollowing
bool isFollowing()
Definition: game.h:328
Otc::GamePlayerAddons
@ GamePlayerAddons
Definition: const.h:387
LocalPlayer
Definition: localplayer.h:29
ProtocolGame::sendCancelRuleViolation
void sendCancelRuleViolation()
Definition: protocolgamesend.cpp:565
Game::requestItemInfo
void requestItemInfo(const ItemPtr &item, int index)
Definition: game.cpp:1379
g_dispatcher
EventDispatcher g_dispatcher
Definition: eventdispatcher.cpp:28
Otc::GameChannelPlayerList
@ GameChannelPlayerList
Definition: const.h:356
Tile::isWalkable
bool isWalkable(bool ignoreCreatures=false)
Definition: tile.cpp:475
Position::isValid
bool isValid() const
Definition: position.h:182
Game::move
void move(const ThingPtr &thing, const Position &toPos, int count)
Definition: game.cpp:798
uint32
uint32_t uint32
Definition: types.h:35
Game::stop
void stop()
Definition: game.cpp:776
Creature::setDirection
void setDirection(Otc::Direction direction)
Definition: creature.cpp:659
luavaluecasts.h
Creature::isWalking
bool isWalking()
Definition: creature.h:121
Creature
Definition: creature.h:37
Game::processInventoryChange
void processInventoryChange(int slot, const ItemPtr &item)
Definition: game.cpp:354
Otc::GameLoginPending
@ GameLoginPending
Definition: const.h:378
ProtocolGame::sendSeekInContainer
void sendSeekInContainer(int cid, int index)
Definition: protocolgamesend.cpp:854
Game::processTutorialHint
void processTutorialHint(int id)
Definition: game.cpp:419
ProtocolGame::sendOpenOwnChannel
void sendOpenOwnChannel()
Definition: protocolgamesend.cpp:660
ProtocolGame::sendUseOnCreature
void sendUseOnCreature(const Position &pos, int thingId, int stackpos, uint creatureId)
Definition: protocolgamesend.cpp:410
Otc::GameAdditionalVipInfo
@ GameAdditionalVipInfo
Definition: const.h:395
LuaInterface::callGlobalField
void callGlobalField(const std::string &global, const std::string &field, const T &... args)
Definition: luainterface.h:445
Game::processPlayerGoods
void processPlayerGoods(int money, const std::vector< std::tuple< ItemPtr, int > > &goods)
Definition: game.cpp:470
Game::cancelFollow
void cancelFollow()
Definition: game.h:196
Game::processEditText
void processEditText(uint id, int itemId, int maxLength, const std::string &text, const std::string &writer, const std::string &date)
Definition: game.cpp:495
Otc::GameLoginPacketEncryption
@ GameLoginPacketEncryption
Definition: const.h:406
Otc::GameEnhancedAnimations
@ GameEnhancedAnimations
Definition: const.h:402
Game::openParent
void openParent(const ContainerPtr &container)
Definition: game.cpp:913
ProtocolGame::sendBuyItem
void sendBuyItem(int itemId, int subType, int amount, bool ignoreCapacity, bool buyWithBackpack)
Definition: protocolgamesend.cpp:319
Game::forceLogout
void forceLogout()
Definition: game.cpp:560
Game::processGMActions
void processGMActions(const std::vector< uint8 > &actions)
Definition: game.cpp:239
Game::setPVPMode
void setPVPMode(Otc::PVPModes pvpMode)
Definition: game.cpp:1203
Game::processLoginToken
void processLoginToken(bool unknown)
Definition: game.cpp:159
Logger::error
void error(const std::string &what)
Definition: logger.h:54
Otc::GameClientPing
@ GameClientPing
Definition: const.h:369
Otc::GameAccountNames
@ GameAccountNames
Definition: const.h:347
Game::openPrivateChannel
void openPrivateChannel(const std::string &receiver)
Definition: game.cpp:1022
Game::getClientVersion
int getClientVersion()
Definition: game.h:316
Game::processAddAutomapFlag
void processAddAutomapFlag(const Position &pos, int icon, const std::string &message)
Definition: game.cpp:424
Otc::FightBalanced
@ FightBalanced
Definition: const.h:207
Game::setFightMode
void setFightMode(Otc::FightModes fightMode)
Definition: game.cpp:1181
Game::turn
void turn(Otc::Direction direction)
Definition: game.cpp:753
Game::useInventoryItem
void useInventoryItem(int itemId)
Definition: game.cpp:846
Otc::MessageSay
@ MessageSay
Definition: const.h:288
Game::useWith
void useWith(const ItemPtr &item, const ThingPtr &toThing)
Definition: game.cpp:856
Otc::GameExtendedClientPing
@ GameExtendedClientPing
Definition: const.h:370
Map::getTile
const TilePtr & getTile(const Position &pos)
Definition: map.cpp:310
Game::requestOutfit
void requestOutfit()
Definition: game.cpp:1120
ProtocolGame::sendMove
void sendMove(const Position &fromPos, int thingId, int stackpos, const Position &toPos, int count)
Definition: protocolgamesend.cpp:298
Otc::GameContentRevision
@ GameContentRevision
Definition: const.h:408
Otc::GameIdleAnimations
@ GameIdleAnimations
Definition: const.h:414
Proto::Creature
@ Creature
Definition: protocolcodes.h:40
Game::processCloseTrade
void processCloseTrade()
Definition: game.cpp:490
Game::processLoginAdvice
void processLoginAdvice(const std::string &message)
Definition: game.cpp:149
LocalPlayer::setInventoryItem
void setInventoryItem(Otc::InventorySlot inventory, const ItemPtr &item)
Definition: localplayer.cpp:479
Game::processOpenOwnPrivateChannel
void processOpenOwnPrivateChannel(int channelId, const std::string &name)
Definition: game.cpp:377
Game::equipItem
void equipItem(const ItemPtr &item)
Definition: game.cpp:1365
Game::processLoginError
void processLoginError(const std::string &error)
Definition: game.cpp:144
ProtocolGame::sendPassLeadership
void sendPassLeadership(uint creatureId)
Definition: protocolgamesend.cpp:635
Game::cancelLogin
void cancelLogin()
Definition: game.cpp:551
g_game
Game g_game
Definition: game.cpp:37
Position::y
int y
Definition: position.h:244
ProtocolGame::sendRotateItem
void sendRotateItem(const Position &pos, int thingId, int stackpos)
Definition: protocolgamesend.cpp:421
Game::isConnectionOk
bool isConnectionOk()
Definition: game.h:329
Game::walk
bool walk(Otc::Direction direction, bool dash=false)
Definition: game.cpp:577
ProtocolGame::sendWalkWest
void sendWalkWest()
Definition: protocolgamesend.cpp:219
Otc::GamePlayerMounts
@ GamePlayerMounts
Definition: const.h:357
Game::partyInvite
void partyInvite(int creatureId)
Definition: game.cpp:1078
Otc::GameProtocolChecksum
@ GameProtocolChecksum
Definition: const.h:346
ProtocolGame::sendAnswerModalDialog
void sendAnswerModalDialog(uint32 dialog, int button, int choice)
Definition: protocolgamesend.cpp:833
Otc::GameBaseSkillU16
@ GameBaseSkillU16
Definition: const.h:396
Otc::GameChallengeOnLogin
@ GameChallengeOnLogin
Definition: const.h:348
CreaturePtr
stdext::shared_object_ptr< Creature > CreaturePtr
Definition: declarations.h:63
stdext::format
std::string format()
Definition: format.h:82
Game::processCloseNpcTrade
void processCloseNpcTrade()
Definition: game.cpp:475
Map::resetAwareRange
void resetAwareRange()
Definition: map.cpp:689
stdext::time
ticks_t time()
Definition: time.cpp:33
Otc::GameMessageSizeCheck
@ GameMessageSizeCheck
Definition: const.h:404
ProtocolGame::sendAddVip
void sendAddVip(const std::string &name)
Definition: protocolgamesend.cpp:736
ProtocolGame::sendDebugReport
void sendDebugReport(const std::string &a, const std::string &b, const std::string &c, const std::string &d)
Definition: protocolgamesend.cpp:785
LuaInterface::traceback
std::string traceback(const std::string &errorMessage="", int level=0)
Definition: luainterface.cpp:380
Game::Game
Game()
Definition: game.cpp:39
ProtocolGame::sendInviteToOwnChannel
void sendInviteToOwnChannel(const std::string &name)
Definition: protocolgamesend.cpp:667
Game::processPendingGame
void processPendingGame()
Definition: game.cpp:169
Game::findItemInContainers
ItemPtr findItemInContainers(uint itemId, int subType)
Definition: game.cpp:884
ProtocolGame::sendRuleViolation
void sendRuleViolation(const std::string &target, int reason, int action, const std::string &comment, const std::string &statement, int statementId, bool ipBanishment)
Definition: protocolgamesend.cpp:771
Otc::GameDoubleSkills
@ GameDoubleSkills
Definition: const.h:372
Game::processRemoveAutomapFlag
void processRemoveAutomapFlag(const Position &pos, int icon, const std::string &message)
Definition: game.cpp:429
Otc::GameMessageStatements
@ GameMessageStatements
Definition: const.h:388
creature.h
Otc::GameOGLInformation
@ GameOGLInformation
Definition: const.h:403
ProtocolGame::sendFollow
void sendFollow(uint creatureId, uint seq)
Definition: protocolgamesend.cpp:601
Game::enableBotCall
void enableBotCall()
Definition: game.h:355
Game::requestStoreOffers
void requestStoreOffers(const std::string &categoryName, int serviceType=0)
Definition: game.cpp:1421
Proto::buildMessageModesMap
void buildMessageModesMap(int version)
Definition: protocolcodes.cpp:29
Game::open
int open(const ItemPtr &item, const ContainerPtr &previousContainer)
Definition: game.cpp:898
Otc::GameLooktypeU16
@ GameLooktypeU16
Definition: const.h:385
LocalPlayer::preWalk
void preWalk(Otc::Direction direction)
Definition: localplayer.cpp:118
Otc::NorthEast
@ NorthEast
Definition: const.h:166
uint16
uint16_t uint16
Definition: types.h:36
Otc::GameForceFirstAutoWalkStep
@ GameForceFirstAutoWalkStep
Definition: const.h:380
Game::partyShareExperience
void partyShareExperience(bool active)
Definition: game.cpp:1113
Otc::GameSpritesU32
@ GameSpritesU32
Definition: const.h:363
ProtocolGame::sendTurnWest
void sendTurnWest()
Definition: protocolgamesend.cpp:282
Game::partyJoin
void partyJoin(int creatureId)
Definition: game.cpp:1085
ProtocolGame::sendRequestOutfit
void sendRequestOutfit()
Definition: protocolgamesend.cpp:698
Game::init
void init()
Definition: game.cpp:58
Game::requestTrade
void requestTrade(const ItemPtr &item, const CreaturePtr &creature)
Definition: game.cpp:1269
Otc::GameNameOnNpcTrade
@ GameNameOnNpcTrade
Definition: const.h:350
ProtocolGame::sendOpenTransactionHistory
void sendOpenTransactionHistory(int entriesPerPage)
Definition: protocolgamesend.cpp:929
ProtocolGame::sendBuyStoreOffer
void sendBuyStoreOffer(int offerId, int productType, const std::string &name)
Definition: protocolgamesend.cpp:866
Otc::GameSessionKey
@ GameSessionKey
Definition: const.h:412
Otc::GameExperienceBonus
@ GameExperienceBonus
Definition: const.h:409
Game::requestQuestLine
void requestQuestLine(int questId)
Definition: game.cpp:1358
Game::processContainerRemoveItem
void processContainerRemoveItem(int containerId, int slot, const ItemPtr &lastItem)
Definition: game.cpp:344
ProtocolGame::sendTurnNorth
void sendTurnNorth()
Definition: protocolgamesend.cpp:261
ProtocolGame::sendCloseContainer
void sendCloseContainer(int containerId)
Definition: protocolgamesend.cpp:431
ProtocolGame::sendSellItem
void sendSellItem(int itemId, int subType, int amount, bool ignoreEquipped)
Definition: protocolgamesend.cpp:331
ProtocolGame::sendShareExperience
void sendShareExperience(bool active)
Definition: protocolgamesend.cpp:650
Otc::Direction
Direction
Definition: const.h:161
Game::processEnterGame
void processEnterGame()
Definition: game.cpp:176
LocalPlayer::stopAutoWalk
void stopAutoWalk()
Definition: localplayer.cpp:230
ProtocolGame::sendRequestItemInfo
void sendRequestItemInfo(int itemId, int subType, int index)
Definition: protocolgamesend.cpp:823
localplayer.h
Outfit
Definition: outfit.h:29
ProtocolGame::sendStop
void sendStop()
Definition: protocolgamesend.cpp:226
ProtocolGame::sendEditVip
void sendEditVip(uint playerId, const std::string &description, int iconId, bool notifyLogin)
Definition: protocolgamesend.cpp:752
ProtocolGame::sendRequestStoreOffers
void sendRequestStoreOffers(const std::string &categoryName, int serviceType)
Definition: protocolgamesend.cpp:894
Otc::GameClientVersion
@ GameClientVersion
Definition: const.h:407
Game::buyItem
void buyItem(const ItemPtr &item, int amount, bool ignoreCapacity, bool buyWithBackpack)
Definition: game.cpp:1248
ProtocolGame::sendChangeFightModes
void sendChangeFightModes(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeFight, Otc::PVPModes pvpMode)
Definition: protocolgamesend.cpp:579
EventDispatcher::cycleEvent
ScheduledEventPtr cycleEvent(const std::function< void()> &callback, int delay)
Definition: eventdispatcher.cpp:93
uint
unsigned int uint
Definition: types.h:31
Otc::MessageMode
MessageMode
Definition: const.h:286
ProtocolGame::sendInspectNpcTrade
void sendInspectNpcTrade(int itemId, int count)
Definition: protocolgamesend.cpp:310
Otc::GameTotalCapacity
@ GameTotalCapacity
Definition: const.h:353
Game::requestQuestLog
void requestQuestLog()
Definition: game.cpp:1351
Otc::GameNewOutfitProtocol
@ GameNewOutfitProtocol
Definition: const.h:392
Otc::GamePlayerMarket
@ GamePlayerMarket
Definition: const.h:362
Game::use
void use(const ThingPtr &thing)
Definition: game.cpp:832
g_logger
Logger g_logger
Definition: logger.cpp:35
Game::isOnline
bool isOnline()
Definition: game.h:324
ProtocolGame::sendLookCreature
void sendLookCreature(uint creatureId)
Definition: protocolgamesend.cpp:476
Otc::WhiteDove
@ WhiteDove
Definition: const.h:217
g_lua
LuaInterface g_lua
Definition: luainterface.cpp:31
Game::answerModalDialog
void answerModalDialog(uint32 dialog, int button, int choice)
Definition: game.cpp:1386
Game::setUnjustifiedPoints
void setUnjustifiedPoints(UnjustifiedPoints unjustifiedPoints)
Definition: game.cpp:1216
ProtocolGame::sendEditList
void sendEditList(uint id, int doorId, const std::string &text)
Definition: protocolgamesend.cpp:456
ProtocolGame::sendAutoWalk
void sendAutoWalk(const std::vector< Otc::Direction > &path)
Definition: protocolgamesend.cpp:157
container.h
Otc::West
@ West
Definition: const.h:165
Game::closeNpcChannel
void closeNpcChannel()
Definition: game.cpp:1050
ProtocolGame::sendRemoveVip
void sendRemoveVip(uint playerId)
Definition: protocolgamesend.cpp:744
Game::processOpenContainer
void processOpenContainer(int containerId, const ItemPtr &containerItem, const std::string &name, int capacity, bool hasParent, const std::vector< ItemPtr > &items, bool isUnlocked, bool hasPages, int containerSize, int firstIndex)
Definition: game.cpp:297
Otc::GamePlayerRegenerationTime
@ GamePlayerRegenerationTime
Definition: const.h:355
Otc::GameBrowseField
@ GameBrowseField
Definition: const.h:401
ProtocolGame::sendCloseRuleViolation
void sendCloseRuleViolation(const std::string &reporter)
Definition: protocolgamesend.cpp:557
Outfit::setId
void setId(int id)
Definition: outfit.h:41
ProtocolGame::sendWalkEast
void sendWalkEast()
Definition: protocolgamesend.cpp:205
ProtocolGame::sendWalkNorthEast
void sendWalkNorthEast()
Definition: protocolgamesend.cpp:233
Game::setChaseMode
void setChaseMode(Otc::ChaseModes chaseMode)
Definition: game.cpp:1170
LocalPlayer::isServerWalking
bool isServerWalking()
Definition: localplayer.h:96
Otc::GameContainerPagination
@ GameContainerPagination
Definition: const.h:383
Position
Definition: position.h:33
Game::inspectTrade
void inspectTrade(bool counterOffer, int index)
Definition: game.cpp:1276
ProtocolGame::sendRequestQuestLog
void sendRequestQuestLog()
Definition: protocolgamesend.cpp:796
Creature::setName
void setName(const std::string &name)
Definition: creature.cpp:631
Game::follow
void follow(CreaturePtr creature)
Definition: game.cpp:960
Otc::GameAdditionalSkills
@ GameAdditionalSkills
Definition: const.h:419
Tile::getElevation
int getElevation() const
Definition: tile.cpp:604
Game::acceptTrade
void acceptTrade()
Definition: game.cpp:1283
ProtocolGame::sendRequestTrade
void sendRequestTrade(const Position &pos, int thingId, int stackpos, uint creatureId)
Definition: protocolgamesend.cpp:352
Otc::GameUnjustifiedPoints
@ GameUnjustifiedPoints
Definition: const.h:411
Game::talkPrivate
void talkPrivate(Otc::MessageMode mode, const std::string &receiver, const std::string &message)
Definition: game.cpp:1015
Otc::GameSpellList
@ GameSpellList
Definition: const.h:368
Container
Definition: container.h:32
ProtocolGame::sendInviteToParty
void sendInviteToParty(uint creatureId)
Definition: protocolgamesend.cpp:611
Outfit::setMount
void setMount(int mount)
Definition: outfit.h:48
ThingCategoryItem
@ ThingCategoryItem
Definition: thingtype.h:43
Game::processCloseContainer
void processCloseContainer(int containerId)
Definition: game.cpp:313
Game::forceWalk
void forceWalk(Otc::Direction direction)
Definition: game.cpp:716
map.h
Otc::GamePlayerStamina
@ GamePlayerStamina
Definition: const.h:386
Timer::restart
void restart()
Definition: timer.cpp:27
Otc::DontChase
@ DontChase
Definition: const.h:212
Game::getFeature
bool getFeature(Otc::GameFeature feature)
Definition: game.h:310
ProtocolGame::sendAttack
void sendAttack(uint creatureId, uint seq)
Definition: protocolgamesend.cpp:591
Otc::GameAuthenticator
@ GameAuthenticator
Definition: const.h:410
ProtocolGame::sendPingBack
void sendPingBack()
Definition: protocolgamesend.cpp:150
Tile::hasElevation
bool hasElevation(int elevation=1)
Definition: tile.cpp:613
LocalPlayer::isAutoWalking
bool isAutoWalking()
Definition: localplayer.h:95
ProtocolGame::sendAcceptTrade
void sendAcceptTrade()
Definition: protocolgamesend.cpp:372
Game::talkChannel
void talkChannel(Otc::MessageMode mode, int channelId, const std::string &message)
Definition: game.cpp:1008
Protocol::isConnected
bool isConnected()
Definition: protocol.cpp:58
Otc::PVPModes
PVPModes
Definition: const.h:216
Game::openOwnChannel
void openOwnChannel()
Definition: game.cpp:1057
Otc::GameNewFluids
@ GameNewFluids
Definition: const.h:390
ProtocolGame::sendWalkNorth
void sendWalkNorth()
Definition: protocolgamesend.cpp:198
ProtocolGame::sendWalkNorthWest
void sendWalkNorthWest()
Definition: protocolgamesend.cpp:254
ProtocolGame::sendOpenRuleViolation
void sendOpenRuleViolation(const std::string &reporter)
Definition: protocolgamesend.cpp:549
Game::dashWalk
bool dashWalk(Otc::Direction direction)
Definition: game.cpp:673
ProtocolGame::sendRejectTrade
void sendRejectTrade()
Definition: protocolgamesend.cpp:379
Otc::GameWritableDate
@ GameWritableDate
Definition: const.h:394
Item::getSubType
int getSubType()
Definition: item.cpp:240
Otc::GameIngameStoreServiceType
@ GameIngameStoreServiceType
Definition: const.h:418
Otc::SouthEast
@ SouthEast
Definition: const.h:167
Game::processConnectionError
void processConnectionError(const boost::system::error_code &ec)
Definition: game.cpp:116
ProtocolGame::sendTurnSouth
void sendTurnSouth()
Definition: protocolgamesend.cpp:275
Otc::GameCreatureIcons
@ GameCreatureIcons
Definition: const.h:397
Otc::GameItemAnimationPhase
@ GameItemAnimationPhase
Definition: const.h:360
g_app
ConsoleApplication g_app
Definition: consoleapplication.cpp:32
ProtocolGame::sendTalk
void sendTalk(Otc::MessageMode mode, int channelId, const std::string &receiver, const std::string &message)
Definition: protocolgamesend.cpp:484
ProtocolGame::sendInspectTrade
void sendInspectTrade(bool counterOffer, int index)
Definition: protocolgamesend.cpp:363
Game::openStore
void openStore(int serviceType=0, const std::string &category="")
Definition: game.cpp:1428
stdext::throw_exception
void throw_exception(const std::string &what)
Throws a generic exception.
Definition: exception.h:43
Game::editVip
void editVip(int playerId, const std::string &description, int iconId, bool notifyLogin)
Definition: game.cpp:1153
ProtocolGame::sendEquipItem
void sendEquipItem(int itemId, int countOrSubType)
Definition: protocolgamesend.cpp:289
Game::processRuleViolationLock
void processRuleViolationLock()
Definition: game.cpp:402
Otc::GameHideNpcNames
@ GameHideNpcNames
Definition: const.h:398
Game::processContainerAddItem
void processContainerAddItem(int containerId, const ItemPtr &item, int slot)
Definition: game.cpp:324
Game::sellItem
void sellItem(const ItemPtr &item, int amount, bool ignoreEquipped)
Definition: game.cpp:1255
ProtocolGame::sendLook
void sendLook(const Position &position, int thingId, int stackpos)
Definition: protocolgamesend.cpp:466
Otc::South
@ South
Definition: const.h:164
Otc::GameSkillsBase
@ GameSkillsBase
Definition: const.h:354
Otc::GameOfflineTrainingTime
@ GameOfflineTrainingTime
Definition: const.h:365
Thing::getStackPos
int getStackPos()
Definition: thing.cpp:76
Game::excludeFromOwnChannel
void excludeFromOwnChannel(const std::string &name)
Definition: game.cpp:1071
Game::processVipAdd
void processVipAdd(uint id, const std::string &name, uint status, const std::string &description, int iconId, bool notifyLogin)
Definition: game.cpp:407
Game::closeNpcTrade
void closeNpcTrade()
Definition: game.cpp:1262
ProtocolGame::sendRevokeInvitation
void sendRevokeInvitation(uint creatureId)
Definition: protocolgamesend.cpp:627
Game::processPingBack
void processPingBack()
Definition: game.cpp:271
Game::terminate
void terminate()
Definition: game.cpp:63
ProtocolGame::sendMountStatus
void sendMountStatus(bool mount)
Definition: protocolgamesend.cpp:724
Application::getOs
std::string getOs()
Definition: application.cpp:172
Position::down
bool down(int n=1)
Definition: position.h:216
Game::refreshContainer
void refreshContainer(const ContainerPtr &container)
Definition: game.cpp:929
Otc::InventorySlot
InventorySlot
Definition: const.h:109
Game::enableFeature
void enableFeature(Otc::GameFeature feature)
Definition: game.h:307
Game::partyRevokeInvitation
void partyRevokeInvitation(int creatureId)
Definition: game.cpp:1092
Game::processOpenPrivateChannel
void processOpenPrivateChannel(const std::string &name)
Definition: game.cpp:372
Otc::NorthWest
@ NorthWest
Definition: const.h:169
Game::talk
void talk(const std::string &message)
Definition: game.cpp:1001
Game::processChannelList
void processChannelList(const std::vector< std::tuple< int, std::string > > &channelList)
Definition: game.cpp:362
ContainerPtr
stdext::shared_object_ptr< Container > ContainerPtr
Definition: declarations.h:62
Game::setOpenPvpSituations
void setOpenPvpSituations(int openPvpSituations)
Definition: game.cpp:1229
Game::changeMapAwareRange
void changeMapAwareRange(int xrange, int yrange)
Definition: game.cpp:1464
Game::transferCoins
void transferCoins(const std::string &recipient, int amount)
Definition: game.cpp:1435
Creature::isDead
bool isDead()
Definition: creature.h:124
Game::processRuleViolationRemove
void processRuleViolationRemove(const std::string &name)
Definition: game.cpp:392
Otc::GameIngameStoreHighlights
@ GameIngameStoreHighlights
Definition: const.h:417
Game::partyLeave
void partyLeave()
Definition: game.cpp:1106
Game::formatCreatureName
std::string formatCreatureName(const std::string &name)
Definition: game.cpp:1713
ProtocolGame::sendBrowseField
void sendBrowseField(const Position &position)
Definition: protocolgamesend.cpp:843
ProtocolGame::sendUseItemWith
void sendUseItemWith(const Position &fromPos, int itemId, int fromStackPos, const Position &toPos, int toThingId, int toStackPos)
Definition: protocolgamesend.cpp:397
Otc::GameDoubleExperience
@ GameDoubleExperience
Definition: const.h:352
stdext::shared_object_ptr
Definition: shared_object.h:39
ProtocolGame::sendTransferCoins
void sendTransferCoins(const std::string &recipient, int amount)
Definition: protocolgamesend.cpp:920
ProtocolGame::sendJoinParty
void sendJoinParty(uint creatureId)
Definition: protocolgamesend.cpp:619
Game::processContainerUpdateItem
void processContainerUpdateItem(int containerId, int slot, const ItemPtr &item)
Definition: game.cpp:334
Game::setSafeFight
void setSafeFight(bool on)
Definition: game.cpp:1192
uimanager.h
Otc::GamePurseSlot
@ GamePurseSlot
Definition: const.h:366
ProtocolGame::sendOpenPrivateChannel
void sendOpenPrivateChannel(const std::string &receiver)
Definition: protocolgamesend.cpp:541
ProtocolGame::sendRequestTransactionHistory
void sendRequestTransactionHistory(int page, int entriesPerPage)
Definition: protocolgamesend.cpp:879
Otc::East
@ East
Definition: const.h:163
stdext::timer::elapsed_millis
ticks_t elapsed_millis()
Definition: time.h:40
Otc::GamePenalityOnDeath
@ GamePenalityOnDeath
Definition: const.h:349
Game::buyStoreOffer
void buyStoreOffer(int offerId, int productType, const std::string &name="")
Definition: game.cpp:1407
Otc::GamePlayerStateU16
@ GamePlayerStateU16
Definition: const.h:391
Game::processCounterTrade
void processCounterTrade(const std::string &name, const std::vector< ItemPtr > &items)
Definition: game.cpp:485
Otc::GameDoubleFreeCapacity
@ GameDoubleFreeCapacity
Definition: const.h:351
LuaInterface::isInCppCallback
bool isInCppCallback()
Definition: luainterface.h:200
ProtocolGame::sendEditText
void sendEditText(uint id, const std::string &text)
Definition: protocolgamesend.cpp:447
Game::requestChannels
void requestChannels()
Definition: game.cpp:1029
Game::getOs
int getOs()
Definition: game.cpp:1739
Vip
std::tuple< std::string, uint, std::string, int, bool > Vip
Definition: game.h:58
Game::processVipStateChange
void processVipStateChange(uint id, uint status)
Definition: game.cpp:413
Game::processGameEnd
void processGameEnd()
Definition: game.cpp:211
Creature::getStepDuration
int getStepDuration(bool ignoreDiagonal=false, Otc::Direction dir=Otc::InvalidDirection)
Definition: creature.cpp:855
Game::cancelAttack
void cancelAttack()
Definition: game.h:194
Game::openTransactionHistory
void openTransactionHistory(int entriesPerPage)
Definition: game.cpp:1442
Game::reportBug
void reportBug(const std::string &comment)
Definition: game.cpp:1332
ProtocolGame::sendTurnEast
void sendTurnEast()
Definition: protocolgamesend.cpp:268
game.h
Otc::GameCreatureEmblems
@ GameCreatureEmblems
Definition: const.h:359
Game::processRuleViolationCancel
void processRuleViolationCancel(const std::string &name)
Definition: game.cpp:397
Game::changeOutfit
void changeOutfit(const Outfit &outfit)
Definition: game.cpp:1127
Game::disableBotCall
void disableBotCall()
Definition: game.h:356
Otc::GameMessageLevel
@ GameMessageLevel
Definition: const.h:389
Otc::GamePreviewState
@ GamePreviewState
Definition: const.h:405
Game::processGameStart
void processGameStart()
Definition: game.cpp:182
Thing::setPosition
void setPosition(const Position &position)
Definition: thing.cpp:36
ProtocolGame::sendRequestQuestLine
void sendRequestQuestLine(int questId)
Definition: protocolgamesend.cpp:803
LocalPlayerPtr
stdext::shared_object_ptr< LocalPlayer > LocalPlayerPtr
Definition: declarations.h:67
Game::removeVip
void removeVip(int playerId)
Definition: game.cpp:1141
ProtocolGame::sendChangeOutfit
void sendChangeOutfit(const Outfit &outfit)
Definition: protocolgamesend.cpp:705
Game::getContainer
ContainerPtr getContainer(int index)
Definition: game.h:332
Otc::GameDeathType
@ GameDeathType
Definition: const.h:413
ProtocolGame::sendCloseNpcTrade
void sendCloseNpcTrade()
Definition: protocolgamesend.cpp:345
protocolgame.h
Game::processTalk
void processTalk(const std::string &name, int level, Otc::MessageMode mode, const std::string &text, int channelId, const Position &pos)
Definition: game.cpp:292
ProtocolGame::sendEnterGame
void sendEnterGame()
Definition: protocolgamesend.cpp:125
statictext.h
Otc::GameIngameStore
@ GameIngameStore
Definition: const.h:416
Thing::getPosition
Position getPosition()
Definition: thing.h:45
Game::canPerformGameAction
bool canPerformGameAction()
Definition: game.cpp:1484
Game::processUpdateNeeded
void processUpdateNeeded(const std::string &signature)
Definition: game.cpp:139
Item::getCount
int getCount()
Definition: item.cpp:249
Game::cancelAttackAndFollow
void cancelAttackAndFollow()
Definition: game.cpp:984
Otc::FightModes
FightModes
Definition: const.h:205
ProtocolGame::sendOpenStore
void sendOpenStore(int serviceType, const std::string &category)
Definition: protocolgamesend.cpp:907
Game::processAttackCancel
void processAttackCancel(uint seq)
Definition: game.cpp:520
Game::seekInContainer
void seekInContainer(int cid, int index)
Definition: game.cpp:1400
EventDispatcher::scheduleEvent
ScheduledEventPtr scheduleEvent(const std::function< void()> &callback, int delay)
Definition: eventdispatcher.cpp:82
Position::up
bool up(int n=1)
Definition: position.h:207
tile.h
Event::cancel
void cancel()
Definition: event.cpp:49
Creature::setOutfit
void setOutfit(const Outfit &outfit)
Definition: creature.cpp:665
Creature::getStepTicksLeft
float getStepTicksLeft()
Definition: creature.h:101
Otc::GamePremiumExpiration
@ GamePremiumExpiration
Definition: const.h:400
Game::joinChannel
void joinChannel(int channelId)
Definition: game.cpp:1036
ProtocolGame::login
void login(const std::string &accountName, const std::string &accountPassword, const std::string &host, uint16 port, const std::string &characterName, const std::string &authenticatorToken, const std::string &sessionKey)
Definition: protocolgame.cpp:29
Tile::isEmpty
bool isEmpty()
Definition: tile.cpp:551
ProtocolGamePtr
stdext::shared_object_ptr< ProtocolGame > ProtocolGamePtr
Definition: declarations.h:94
ProtocolGame::sendUseItem
void sendUseItem(const Position &position, int itemId, int stackpos, int index)
Definition: protocolgamesend.cpp:386
UnjustifiedPoints
Definition: game.h:39
Game::requestTransactionHistory
void requestTransactionHistory(int page, int entriesPerPage)
Definition: game.cpp:1414
Game::rotate
void rotate(const ThingPtr &thing)
Definition: game.cpp:824
Game::editText
void editText(uint id, const std::string &text)
Definition: game.cpp:1297
Otc::GameFormatCreatureName
@ GameFormatCreatureName
Definition: const.h:367
ProtocolGame::sendRequestChannels
void sendRequestChannels()
Definition: protocolgamesend.cpp:518
Game::checkBotProtection
bool checkBotProtection()
Definition: game.cpp:1471
Game::processLoginWait
void processLoginWait(const std::string &message, int time)
Definition: game.cpp:154
ProtocolGame::sendLogout
void sendLogout()
Definition: protocolgamesend.cpp:132
Game::moveToParentContainer
void moveToParentContainer(const ThingPtr &thing, int count)
Definition: game.cpp:815
Game::attack
void attack(CreaturePtr creature)
Definition: game.cpp:936
g_things
ThingTypeManager g_things
Definition: thingtypemanager.cpp:38
Game::reportRuleViolation
void reportRuleViolation(const std::string &target, int reason, int action, const std::string &comment, const std::string &statement, int statementId, bool ipBanishment)
Definition: game.cpp:1339
Game::processPlayerHelpers
void processPlayerHelpers(int helpers)
Definition: game.cpp:245
Game::ping
void ping()
Definition: game.cpp:1449
Game::useInventoryItemWith
void useInventoryItemWith(int itemId, const ThingPtr &toThing)
Definition: game.cpp:871
Game::processOwnTrade
void processOwnTrade(const std::string &name, const std::vector< ItemPtr > &items)
Definition: game.cpp:480
Game::debugReport
void debugReport(const std::string &a, const std::string &b, const std::string &c, const std::string &d)
Definition: game.cpp:1346
Game::autoWalk
void autoWalk(std::vector< Otc::Direction > dirs)
Definition: game.cpp:678
Game::processOpenNpcTrade
void processOpenNpcTrade(const std::vector< std::tuple< ItemPtr, std::string, int, int, int > > &items)
Definition: game.cpp:465
Map::cleanDynamicThings
void cleanDynamicThings()
Definition: map.cpp:87
Otc::SouthWest
@ SouthWest
Definition: const.h:168
Item::getCountOrSubType
int getCountOrSubType()
Definition: item.h:94
Otc::GameEnvironmentEffect
@ GameEnvironmentEffect
Definition: const.h:358
Game::addVip
void addVip(const std::string &name)
Definition: game.cpp:1134
ProtocolGame::sendWalkSouth
void sendWalkSouth()
Definition: protocolgamesend.cpp:212
LocalPlayer::setPendingGame
void setPendingGame(bool pending)
Definition: localplayer.h:58
Game::processCloseChannel
void processCloseChannel(int channelId)
Definition: game.cpp:382
Game::processPlayerModes
void processPlayerModes(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeMode, Otc::PVPModes pvpMode)
Definition: game.cpp:250
ProtocolGame::sendUpContainer
void sendUpContainer(int containerId)
Definition: protocolgamesend.cpp:439
ThingTypeManager::isValidDatId
bool isValidDatId(uint16 id, ThingCategory category)
Definition: thingtypemanager.h:75
stdext::upchar
char upchar(char c)
Definition: string.cpp:231
Game::partyPassLeadership
void partyPassLeadership(int creatureId)
Definition: game.cpp:1099
application.h
ProtocolGame::sendRefreshContainer
void sendRefreshContainer(int containerId)
Definition: protocolgamesend.cpp:690
Game
Definition: game.h:61