Otclient 1.0  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"
26 #include <framework/ui/uimanager.h>
27 #include "container.h"
28 #include "creature.h"
29 #include "localplayer.h"
30 #include "luavaluecasts.h"
31 #include "map.h"
32 #include "protocolcodes.h"
33 #include "protocolgame.h"
34 #include "statictext.h"
35 #include "tile.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(static_cast<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  const 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, const std::string& title, const std::string& message, const std::vector<std::tuple<int, std::string> >
516  & buttonList, int enterButton, int escapeButton, const std::vector<std::tuple<int, std::string> >
517  & choiceList, bool priority)
518 {
519  g_lua.callGlobalField("g_game", "onModalDialog", id, title, message, buttonList, enterButton, escapeButton, choiceList, priority);
520 }
521 
523 {
524  if(isAttacking() && (seq == 0 || m_seq == seq))
525  cancelAttack();
526 }
527 
529 {
530  m_localPlayer->cancelWalk(direction);
531 }
532 
533 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)
534 {
535  if(m_protocolGame || isOnline())
536  stdext::throw_exception("Unable to login into a world while already online or logging.");
537 
538  if(m_protocolVersion == 0)
539  stdext::throw_exception("Must set a valid game protocol version before logging.");
540 
541  // reset the new game state
542  resetGameStates();
543 
544  m_localPlayer = LocalPlayerPtr(new LocalPlayer);
545  m_localPlayer->setName(characterName);
546 
547  m_protocolGame = ProtocolGamePtr(new ProtocolGame);
548  m_protocolGame->login(account, password, worldHost, static_cast<uint16>(worldPort), characterName, authenticatorToken, sessionKey);
549  m_characterName = characterName;
550  m_worldName = worldName;
551 }
552 
554 {
555  // send logout even if the game has not started yet, to make sure that the player doesn't stay logged there
556  if(m_protocolGame)
557  m_protocolGame->sendLogout();
558 
560 }
561 
563 {
564  if(!isOnline())
565  return;
566 
567  m_protocolGame->sendLogout();
569 }
570 
572 {
573  if(!isOnline())
574  return;
575 
576  m_protocolGame->sendLogout();
577 }
578 
579 bool Game::walk(const Otc::Direction direction)
580 {
581  if(!canPerformGameAction())
582  return false;
583 
584  // must cancel follow before any new walk
585  if(isFollowing())
586  cancelFollow();
587 
588  // must cancel auto walking, and wait next try
589  if(m_localPlayer->isAutoWalking() || m_localPlayer->isServerWalking()) {
590  m_protocolGame->sendStop();
591  if(m_localPlayer->isAutoWalking())
592  m_localPlayer->stopAutoWalk();
593  return false;
594  }
595 
596  // check we can walk and add new walk event if false
597  if(!m_localPlayer->canWalk(direction)) {
598  if(m_lastWalkDir != direction) {
599  // must add a new walk event
600  if(m_walkEvent) {
601  m_walkEvent->cancel();
602  m_walkEvent = nullptr;
603  }
604 
605  const float ticks = std::max<float>(m_localPlayer->getStepTicksLeft(), 1);
606  m_walkEvent = g_dispatcher.scheduleEvent([=] { walk(direction); }, ticks);
607  }
608  return false;
609  }
610 
611  Position toPos = m_localPlayer->getPosition().translatedToDirection(direction);
612  TilePtr toTile = g_map.getTile(toPos);
613 
614  // only do prewalks to walkable tiles (like grounds and not walls)
615  if(toTile && toTile->isWalkable()) {
616  m_localPlayer->preWalk(direction);
617  } else {
618  // check if can walk to a lower floor
619  auto canChangeFloorDown = [&]() -> bool {
620  Position pos = toPos;
621  if(!pos.down())
622  return false;
623 
624  // check walk to another floor (e.g: when above 3 parcels)
625  TilePtr toTile = g_map.getTile(pos);
626  if(toTile && toTile->hasElevation(3))
627  return true;
628 
629  return false;
630  };
631 
632  // check if can walk to a higher floor
633  auto canChangeFloorUp = [&]() -> bool {
634  TilePtr fromTile = m_localPlayer->getTile();
635  if(!fromTile || !fromTile->hasElevation(3))
636  return false;
637 
638  Position pos = toPos;
639  if(!pos.up())
640 
641  return false;
642  TilePtr toTile = g_map.getTile(pos);
643  if(!toTile || !toTile->isWalkable())
644  return false;
645 
646  return true;
647  };
648 
649  if(!(canChangeFloorDown() || canChangeFloorUp() || !toTile || toTile->isEmpty()))
650  return false;
651 
652  m_localPlayer->lockWalk();
653  }
654 
655  m_localPlayer->stopAutoWalk();
656 
657  g_lua.callGlobalField("g_game", "onWalk", direction);
658 
659  forceWalk(direction);
660 
661  m_lastWalkDir = direction;
662 
663  return true;
664 }
665 
666 void Game::autoWalk(std::vector<Otc::Direction> dirs)
667 {
668  if(!canPerformGameAction())
669  return;
670 
671  // protocol limits walk path up to 255 directions
672  if(dirs.size() > 127) {
673  g_logger.error("Auto walk path too great, the maximum number of directions is 127");
674  return;
675  }
676 
677  if(dirs.empty())
678  return;
679 
680  // must cancel follow before any new walk
681  if(isFollowing())
682  cancelFollow();
683 
684  const auto it = dirs.begin();
685  const Otc::Direction direction = *it;
686  if(!m_localPlayer->canWalk(direction))
687  return;
688 
689  TilePtr toTile = g_map.getTile(m_localPlayer->getPosition().translatedToDirection(direction));
690  if(toTile && toTile->isWalkable() && !m_localPlayer->isServerWalking()) {
691  m_localPlayer->preWalk(direction);
692 
694  forceWalk(direction);
695  dirs.erase(it);
696  }
697  }
698 
699  g_lua.callGlobalField("g_game", "onAutoWalk", dirs);
700 
701  m_protocolGame->sendAutoWalk(dirs);
702 }
703 
705 {
706  if(!canPerformGameAction())
707  return;
708 
709  switch(direction) {
710  case Otc::North:
711  m_protocolGame->sendWalkNorth();
712  break;
713  case Otc::East:
714  m_protocolGame->sendWalkEast();
715  break;
716  case Otc::South:
717  m_protocolGame->sendWalkSouth();
718  break;
719  case Otc::West:
720  m_protocolGame->sendWalkWest();
721  break;
722  case Otc::NorthEast:
723  m_protocolGame->sendWalkNorthEast();
724  break;
725  case Otc::SouthEast:
726  m_protocolGame->sendWalkSouthEast();
727  break;
728  case Otc::SouthWest:
729  m_protocolGame->sendWalkSouthWest();
730  break;
731  case Otc::NorthWest:
732  m_protocolGame->sendWalkNorthWest();
733  break;
734  default:
735  break;
736  }
737 
738  g_lua.callGlobalField("g_game", "onForceWalk", direction);
739 }
740 
741 void Game::turn(Otc::Direction direction)
742 {
743  if(!canPerformGameAction())
744  return;
745 
746  switch(direction) {
747  case Otc::North:
748  m_protocolGame->sendTurnNorth();
749  break;
750  case Otc::East:
751  m_protocolGame->sendTurnEast();
752  break;
753  case Otc::South:
754  m_protocolGame->sendTurnSouth();
755  break;
756  case Otc::West:
757  m_protocolGame->sendTurnWest();
758  break;
759  default:
760  break;
761  }
762 }
763 
765 {
766  if(!canPerformGameAction())
767  return;
768 
769  if(isFollowing())
770  cancelFollow();
771 
772  m_protocolGame->sendStop();
773 }
774 
775 void Game::look(const ThingPtr& thing, bool isBattleList)
776 {
777  if(!canPerformGameAction() || !thing)
778  return;
779 
780  if(thing->isCreature() && isBattleList && m_protocolVersion >= 961)
781  m_protocolGame->sendLookCreature(thing->getId());
782  else
783  m_protocolGame->sendLook(thing->getPosition(), thing->getId(), thing->getStackPos());
784 }
785 
786 void Game::move(const ThingPtr& thing, const Position& toPos, int count)
787 {
788  if(count <= 0)
789  count = 1;
790 
791  if(!canPerformGameAction() || !thing || thing->getPosition() == toPos)
792  return;
793 
794  uint id = thing->getId();
795  if(thing->isCreature()) {
796  CreaturePtr creature = thing->static_self_cast<Creature>();
797  id = Proto::Creature;
798  }
799 
800  m_protocolGame->sendMove(thing->getPosition(), id, thing->getStackPos(), toPos, count);
801 }
802 
803 void Game::moveToParentContainer(const ThingPtr& thing, int count)
804 {
805  if(!canPerformGameAction() || !thing || count <= 0)
806  return;
807 
808  const Position position = thing->getPosition();
809  move(thing, Position(position.x, position.y, 254), count);
810 }
811 
812 void Game::rotate(const ThingPtr& thing)
813 {
814  if(!canPerformGameAction() || !thing)
815  return;
816 
817  m_protocolGame->sendRotateItem(thing->getPosition(), thing->getId(), thing->getStackPos());
818 }
819 
820 void Game::use(const ThingPtr& thing)
821 {
822  if(!canPerformGameAction() || !thing)
823  return;
824 
825  Position pos = thing->getPosition();
826  if(!pos.isValid()) // virtual item
827  pos = Position(0xFFFF, 0, 0); // inventory item
828 
829  // some items, e.g. parcel, are not set as containers but they are.
830  // always try to use these items in free container slots.
831  m_protocolGame->sendUseItem(pos, thing->getId(), thing->getStackPos(), findEmptyContainerId());
832 }
833 
834 void Game::useInventoryItem(int itemId)
835 {
837  return;
838 
839  const Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
840 
841  m_protocolGame->sendUseItem(pos, itemId, 0, 0);
842 }
843 
844 void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
845 {
846  if(!canPerformGameAction() || !item || !toThing)
847  return;
848 
849  Position pos = item->getPosition();
850  if(!pos.isValid()) // virtual item
851  pos = Position(0xFFFF, 0, 0); // means that is an item in inventory
852 
853  if(toThing->isCreature())
854  m_protocolGame->sendUseOnCreature(pos, item->getId(), item->getStackPos(), toThing->getId());
855  else
856  m_protocolGame->sendUseItemWith(pos, item->getId(), item->getStackPos(), toThing->getPosition(), toThing->getId(), toThing->getStackPos());
857 }
858 
859 void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing)
860 {
861  if(!canPerformGameAction() || !toThing)
862  return;
863 
864  const Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
865 
866  if(toThing->isCreature())
867  m_protocolGame->sendUseOnCreature(pos, itemId, 0, toThing->getId());
868  else
869  m_protocolGame->sendUseItemWith(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackPos());
870 }
871 
873 {
874  for(auto& it : m_containers) {
875  const ContainerPtr& container = it.second;
876 
877  if(container) {
878  ItemPtr item = container->findItemById(itemId, subType);
879  if(item != nullptr)
880  return item;
881  }
882  }
883  return nullptr;
884 }
885 
886 int Game::open(const ItemPtr& item, const ContainerPtr& previousContainer)
887 {
888  if(!canPerformGameAction() || !item)
889  return -1;
890 
891  const int id = previousContainer ? previousContainer->getId() : findEmptyContainerId();
892  m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackPos(), id);
893  return id;
894 }
895 
896 void Game::openParent(const ContainerPtr& container)
897 {
898  if(!canPerformGameAction() || !container)
899  return;
900 
901  m_protocolGame->sendUpContainer(container->getId());
902 }
903 
904 void Game::close(const ContainerPtr& container)
905 {
906  if(!canPerformGameAction() || !container)
907  return;
908 
909  m_protocolGame->sendCloseContainer(container->getId());
910 }
911 
912 void Game::refreshContainer(const ContainerPtr& container)
913 {
914  if(!canPerformGameAction())
915  return;
916  m_protocolGame->sendRefreshContainer(container->getId());
917 }
918 
919 void Game::attack(CreaturePtr creature)
920 {
921  if(!canPerformGameAction() || creature == m_localPlayer)
922  return;
923 
924  // cancel when attacking again
925  if(creature && creature == m_attackingCreature)
926  creature = nullptr;
927 
928  if(creature && isFollowing())
929  cancelFollow();
930 
931  setAttackingCreature(creature);
932  m_localPlayer->stopAutoWalk();
933 
934  if(m_protocolVersion >= 963) {
935  if(creature)
936  m_seq = creature->getId();
937  } else
938  ++m_seq;
939 
940  m_protocolGame->sendAttack(creature ? creature->getId() : 0, m_seq);
941 
943 }
944 
945 void Game::follow(CreaturePtr creature)
946 {
947  if(!canPerformGameAction() || creature == m_localPlayer)
948  return;
949 
950  // cancel when following again
951  if(creature && creature == m_followingCreature)
952  creature = nullptr;
953 
954  if(creature && isAttacking())
955  cancelAttack();
956 
957  setFollowingCreature(creature);
958  m_localPlayer->stopAutoWalk();
959 
960  if(m_protocolVersion >= 963) {
961  if(creature)
962  m_seq = creature->getId();
963  } else
964  ++m_seq;
965 
966  m_protocolGame->sendFollow(creature ? creature->getId() : 0, m_seq);
967 }
968 
970 {
971  if(!canPerformGameAction())
972  return;
973 
974  if(isFollowing())
975  setFollowingCreature(nullptr);
976  if(isAttacking())
977  setAttackingCreature(nullptr);
978 
979  m_localPlayer->stopAutoWalk();
980 
981  m_protocolGame->sendCancelAttackAndFollow();
982 
983  g_lua.callGlobalField("g_game", "onCancelAttackAndFollow");
984 }
985 
986 void Game::talk(const std::string& message)
987 {
988  if(!canPerformGameAction() || message.empty())
989  return;
990  talkChannel(Otc::MessageSay, 0, message);
991 }
992 
993 void Game::talkChannel(Otc::MessageMode mode, int channelId, const std::string& message)
994 {
995  if(!canPerformGameAction() || message.empty())
996  return;
997  m_protocolGame->sendTalk(mode, channelId, "", message);
998 }
999 
1000 void Game::talkPrivate(Otc::MessageMode mode, const std::string& receiver, const std::string& message)
1001 {
1002  if(!canPerformGameAction() || receiver.empty() || message.empty())
1003  return;
1004  m_protocolGame->sendTalk(mode, 0, receiver, message);
1005 }
1006 
1007 void Game::openPrivateChannel(const std::string& receiver)
1008 {
1009  if(!canPerformGameAction() || receiver.empty())
1010  return;
1011  m_protocolGame->sendOpenPrivateChannel(receiver);
1012 }
1013 
1015 {
1016  if(!canPerformGameAction())
1017  return;
1018  m_protocolGame->sendRequestChannels();
1019 }
1020 
1021 void Game::joinChannel(int channelId)
1022 {
1023  if(!canPerformGameAction())
1024  return;
1025  m_protocolGame->sendJoinChannel(channelId);
1026 }
1027 
1028 void Game::leaveChannel(int channelId)
1029 {
1030  if(!canPerformGameAction())
1031  return;
1032  m_protocolGame->sendLeaveChannel(channelId);
1033 }
1034 
1036 {
1037  if(!canPerformGameAction())
1038  return;
1039  m_protocolGame->sendCloseNpcChannel();
1040 }
1041 
1043 {
1044  if(!canPerformGameAction())
1045  return;
1046  m_protocolGame->sendOpenOwnChannel();
1047 }
1048 
1049 void Game::inviteToOwnChannel(const std::string& name)
1050 {
1051  if(!canPerformGameAction() || name.empty())
1052  return;
1053  m_protocolGame->sendInviteToOwnChannel(name);
1054 }
1055 
1056 void Game::excludeFromOwnChannel(const std::string& name)
1057 {
1058  if(!canPerformGameAction() || name.empty())
1059  return;
1060  m_protocolGame->sendExcludeFromOwnChannel(name);
1061 }
1062 
1063 void Game::partyInvite(int creatureId)
1064 {
1065  if(!canPerformGameAction())
1066  return;
1067  m_protocolGame->sendInviteToParty(creatureId);
1068 }
1069 
1070 void Game::partyJoin(int creatureId)
1071 {
1072  if(!canPerformGameAction())
1073  return;
1074  m_protocolGame->sendJoinParty(creatureId);
1075 }
1076 
1077 void Game::partyRevokeInvitation(int creatureId)
1078 {
1079  if(!canPerformGameAction())
1080  return;
1081  m_protocolGame->sendRevokeInvitation(creatureId);
1082 }
1083 
1084 void Game::partyPassLeadership(int creatureId)
1085 {
1086  if(!canPerformGameAction())
1087  return;
1088  m_protocolGame->sendPassLeadership(creatureId);
1089 }
1090 
1092 {
1093  if(!canPerformGameAction())
1094  return;
1095  m_protocolGame->sendLeaveParty();
1096 }
1097 
1099 {
1100  if(!canPerformGameAction())
1101  return;
1102  m_protocolGame->sendShareExperience(active);
1103 }
1104 
1106 {
1107  if(!canPerformGameAction())
1108  return;
1109  m_protocolGame->sendRequestOutfit();
1110 }
1111 
1112 void Game::changeOutfit(const Outfit& outfit)
1113 {
1114  if(!canPerformGameAction())
1115  return;
1116  m_protocolGame->sendChangeOutfit(outfit);
1117 }
1118 
1119 void Game::addVip(const std::string& name)
1120 {
1121  if(!canPerformGameAction() || name.empty())
1122  return;
1123  m_protocolGame->sendAddVip(name);
1124 }
1125 
1126 void Game::removeVip(int playerId)
1127 {
1128  if(!canPerformGameAction())
1129  return;
1130 
1131  const auto it = m_vips.find(playerId);
1132  if(it == m_vips.end())
1133  return;
1134  m_vips.erase(it);
1135  m_protocolGame->sendRemoveVip(playerId);
1136 }
1137 
1138 void Game::editVip(int playerId, const std::string& description, int iconId, bool notifyLogin)
1139 {
1140  if(!canPerformGameAction())
1141  return;
1142 
1143  const auto it = m_vips.find(playerId);
1144  if(it == m_vips.end())
1145  return;
1146 
1147  std::get<2>(m_vips[playerId]) = description;
1148  std::get<3>(m_vips[playerId]) = iconId;
1149  std::get<4>(m_vips[playerId]) = notifyLogin;
1150 
1152  m_protocolGame->sendEditVip(playerId, description, iconId, notifyLogin);
1153 }
1154 
1156 {
1157  if(!canPerformGameAction())
1158  return;
1159  if(m_chaseMode == chaseMode)
1160  return;
1161  m_chaseMode = chaseMode;
1162  m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
1163  g_lua.callGlobalField("g_game", "onChaseModeChange", chaseMode);
1164 }
1165 
1167 {
1168  if(!canPerformGameAction())
1169  return;
1170  if(m_fightMode == fightMode)
1171  return;
1172  m_fightMode = fightMode;
1173  m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
1174  g_lua.callGlobalField("g_game", "onFightModeChange", fightMode);
1175 }
1176 
1177 void Game::setSafeFight(bool on)
1178 {
1179  if(!canPerformGameAction())
1180  return;
1181  if(m_safeFight == on)
1182  return;
1183  m_safeFight = on;
1184  m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
1185  g_lua.callGlobalField("g_game", "onSafeFightChange", on);
1186 }
1187 
1189 {
1190  if(!canPerformGameAction())
1191  return;
1193  return;
1194  if(m_pvpMode == pvpMode)
1195  return;
1196  m_pvpMode = pvpMode;
1197  m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight, m_pvpMode);
1198  g_lua.callGlobalField("g_game", "onPVPModeChange", pvpMode);
1199 }
1200 
1202 {
1203  if(!canPerformGameAction())
1204  return;
1206  return;
1207  if(m_unjustifiedPoints == unjustifiedPoints)
1208  return;
1209 
1210  m_unjustifiedPoints = unjustifiedPoints;
1211  g_lua.callGlobalField("g_game", "onUnjustifiedPointsChange", unjustifiedPoints);
1212 }
1213 
1214 void Game::setOpenPvpSituations(int openPvpSituations)
1215 {
1216  if(!canPerformGameAction())
1217  return;
1218  if(m_openPvpSituations == openPvpSituations)
1219  return;
1220 
1221  m_openPvpSituations = openPvpSituations;
1222  g_lua.callGlobalField("g_game", "onOpenPvpSituationsChange", openPvpSituations);
1223 }
1224 
1225 
1227 {
1228  if(!canPerformGameAction() || !item)
1229  return;
1230  m_protocolGame->sendInspectNpcTrade(item->getId(), item->getCount());
1231 }
1232 
1233 void Game::buyItem(const ItemPtr& item, int amount, bool ignoreCapacity, bool buyWithBackpack)
1234 {
1235  if(!canPerformGameAction() || !item)
1236  return;
1237  m_protocolGame->sendBuyItem(item->getId(), item->getCountOrSubType(), amount, ignoreCapacity, buyWithBackpack);
1238 }
1239 
1240 void Game::sellItem(const ItemPtr& item, int amount, bool ignoreEquipped)
1241 {
1242  if(!canPerformGameAction() || !item)
1243  return;
1244  m_protocolGame->sendSellItem(item->getId(), item->getSubType(), amount, ignoreEquipped);
1245 }
1246 
1248 {
1249  if(!canPerformGameAction())
1250  return;
1251  m_protocolGame->sendCloseNpcTrade();
1252 }
1253 
1254 void Game::requestTrade(const ItemPtr& item, const CreaturePtr& creature)
1255 {
1256  if(!canPerformGameAction() || !item || !creature)
1257  return;
1258  m_protocolGame->sendRequestTrade(item->getPosition(), item->getId(), item->getStackPos(), creature->getId());
1259 }
1260 
1261 void Game::inspectTrade(bool counterOffer, int index)
1262 {
1263  if(!canPerformGameAction())
1264  return;
1265  m_protocolGame->sendInspectTrade(counterOffer, index);
1266 }
1267 
1269 {
1270  if(!canPerformGameAction())
1271  return;
1272  m_protocolGame->sendAcceptTrade();
1273 }
1274 
1276 {
1277  if(!canPerformGameAction())
1278  return;
1279  m_protocolGame->sendRejectTrade();
1280 }
1281 
1282 void Game::editText(uint id, const std::string& text)
1283 {
1284  if(!canPerformGameAction())
1285  return;
1286  m_protocolGame->sendEditText(id, text);
1287 }
1288 
1289 void Game::editList(uint id, int doorId, const std::string& text)
1290 {
1291  if(!canPerformGameAction())
1292  return;
1293  m_protocolGame->sendEditList(id, doorId, text);
1294 }
1295 
1296 void Game::openRuleViolation(const std::string& reporter)
1297 {
1298  if(!canPerformGameAction())
1299  return;
1300  m_protocolGame->sendOpenRuleViolation(reporter);
1301 }
1302 
1303 void Game::closeRuleViolation(const std::string& reporter)
1304 {
1305  if(!canPerformGameAction())
1306  return;
1307  m_protocolGame->sendCloseRuleViolation(reporter);
1308 }
1309 
1311 {
1312  if(!canPerformGameAction())
1313  return;
1314  m_protocolGame->sendCancelRuleViolation();
1315 }
1316 
1317 void Game::reportBug(const std::string& comment)
1318 {
1319  if(!canPerformGameAction())
1320  return;
1321  m_protocolGame->sendBugReport(comment);
1322 }
1323 
1324 void Game::reportRuleViolation(const std::string& target, int reason, int action, const std::string& comment, const std::string& statement, int statementId, bool ipBanishment)
1325 {
1326  if(!canPerformGameAction())
1327  return;
1328  m_protocolGame->sendRuleViolation(target, reason, action, comment, statement, statementId, ipBanishment);
1329 }
1330 
1331 void Game::debugReport(const std::string& a, const std::string& b, const std::string& c, const std::string& d)
1332 {
1333  m_protocolGame->sendDebugReport(a, b, c, d);
1334 }
1335 
1337 {
1338  if(!canPerformGameAction())
1339  return;
1340  m_protocolGame->sendRequestQuestLog();
1341 }
1342 
1343 void Game::requestQuestLine(int questId)
1344 {
1345  if(!canPerformGameAction())
1346  return;
1347  m_protocolGame->sendRequestQuestLine(questId);
1348 }
1349 
1350 void Game::equipItem(const ItemPtr& item)
1351 {
1352  if(!canPerformGameAction())
1353  return;
1354  m_protocolGame->sendEquipItem(item->getId(), item->getCountOrSubType());
1355 }
1356 
1357 void Game::mount(bool mount)
1358 {
1359  if(!canPerformGameAction())
1360  return;
1361  m_protocolGame->sendMountStatus(mount);
1362 }
1363 
1364 void Game::requestItemInfo(const ItemPtr& item, int index)
1365 {
1366  if(!canPerformGameAction())
1367  return;
1368  m_protocolGame->sendRequestItemInfo(item->getId(), item->getSubType(), index);
1369 }
1370 
1371 void Game::answerModalDialog(uint32 dialog, int button, int choice)
1372 {
1373  if(!canPerformGameAction())
1374  return;
1375  m_protocolGame->sendAnswerModalDialog(dialog, button, choice);
1376 }
1377 
1378 void Game::browseField(const Position& position)
1379 {
1380  if(!canPerformGameAction())
1381  return;
1382  m_protocolGame->sendBrowseField(position);
1383 }
1384 
1385 void Game::seekInContainer(int cid, int index)
1386 {
1387  if(!canPerformGameAction())
1388  return;
1389  m_protocolGame->sendSeekInContainer(cid, index);
1390 }
1391 
1392 void Game::buyStoreOffer(int offerId, int productType, const std::string& name)
1393 {
1394  if(!canPerformGameAction())
1395  return;
1396  m_protocolGame->sendBuyStoreOffer(offerId, productType, name);
1397 }
1398 
1399 void Game::requestTransactionHistory(int page, int entriesPerPage)
1400 {
1401  if(!canPerformGameAction())
1402  return;
1403  m_protocolGame->sendRequestTransactionHistory(page, entriesPerPage);
1404 }
1405 
1406 void Game::requestStoreOffers(const std::string& categoryName, int serviceType)
1407 {
1408  if(!canPerformGameAction())
1409  return;
1410  m_protocolGame->sendRequestStoreOffers(categoryName, serviceType);
1411 }
1412 
1413 void Game::openStore(int serviceType, const std::string& category)
1414 {
1415  if(!canPerformGameAction())
1416  return;
1417  m_protocolGame->sendOpenStore(serviceType, category);
1418 }
1419 
1420 void Game::transferCoins(const std::string& recipient, int amount)
1421 {
1422  if(!canPerformGameAction())
1423  return;
1424  m_protocolGame->sendTransferCoins(recipient, amount);
1425 }
1426 
1427 void Game::openTransactionHistory(int entriesPerPage)
1428 {
1429  if(!canPerformGameAction())
1430  return;
1431  m_protocolGame->sendOpenTransactionHistory(entriesPerPage);
1432 }
1433 
1435 {
1436  if(!m_protocolGame || !m_protocolGame->isConnected())
1437  return;
1438 
1439  if(m_pingReceived != m_pingSent)
1440  return;
1441 
1442  m_denyBotCall = false;
1443  m_protocolGame->sendPing();
1444  m_denyBotCall = true;
1445  ++m_pingSent;
1446  m_pingTimer.restart();
1447 }
1448 
1449 void Game::changeMapAwareRange(int xrange, int yrange)
1450 {
1451  if(!canPerformGameAction())
1452  return;
1453 
1454  m_protocolGame->sendChangeMapAwareRange(xrange, yrange);
1455 }
1456 
1458 {
1459 #ifdef BOT_PROTECTION
1460  // accepts calls comming from a stacktrace containing only C++ functions,
1461  // if the stacktrace contains a lua function, then only accept if the engine is processing an input event
1462  if(m_denyBotCall && g_lua.isInCppCallback() && !g_app.isOnInputEvent()) {
1463  g_logger.error(g_lua.traceback("caught a lua call to a bot protected game function, the call was cancelled"));
1464  return false;
1465  }
1466 #endif
1467  return true;
1468 }
1469 
1471 {
1472  // we can only perform game actions if we meet these conditions:
1473  // - the game is online
1474  // - the local player exists
1475  // - the local player is not dead
1476  // - we have a game protocol
1477  // - the game protocol is connected
1478  // - its not a bot action
1479  return m_online && m_localPlayer && !m_localPlayer->isDead() && !m_dead && m_protocolGame && m_protocolGame->isConnected() && checkBotProtection();
1480 }
1481 
1482 void Game::setProtocolVersion(int version)
1483 {
1484  if(m_protocolVersion == version)
1485  return;
1486 
1487  if(isOnline())
1488  stdext::throw_exception("Unable to change protocol version while online");
1489 
1490  if(version != 0 && (version < 740 || version > 1099))
1491  stdext::throw_exception(stdext::format("Protocol version %d not supported", version));
1492 
1493  m_protocolVersion = version;
1494 
1495  Proto::buildMessageModesMap(version);
1496 
1497  g_lua.callGlobalField("g_game", "onProtocolVersionChange", version);
1498 }
1499 
1500 void Game::setClientVersion(int version)
1501 {
1502  if(m_clientVersion == version)
1503  return;
1504 
1505  if(isOnline())
1506  stdext::throw_exception("Unable to change client version while online");
1507 
1508  if(version != 0 && (version < 740 || version > 1099))
1509  stdext::throw_exception(stdext::format("Client version %d not supported", version));
1510 
1511  m_features.reset();
1513 
1514  if(version >= 770) {
1518  }
1519 
1520  if(version >= 780) {
1527  }
1528 
1529  if(version >= 790) {
1531  }
1532 
1533  if(version >= 840) {
1537  }
1538 
1539  if(version >= 841) {
1542  }
1543 
1544  if(version >= 854) {
1546  }
1547 
1548  if(version >= 860) {
1550  }
1551 
1552  if(version >= 862) {
1554  }
1555 
1556  if(version >= 870) {
1560  }
1561 
1562  if(version >= 910) {
1570  }
1571 
1572  if(version >= 940) {
1574  }
1575 
1576  if(version >= 953) {
1579  }
1580 
1581  if(version >= 960) {
1584  }
1585 
1586  if(version >= 963) {
1588  }
1589 
1590  if(version >= 980) {
1593  }
1594 
1595  if(version >= 981) {
1598  }
1599 
1600  if(version >= 984) {
1603  }
1604 
1605  if(version >= 1000) {
1608  }
1609 
1610  if(version >= 1035) {
1613  }
1614 
1615  if(version >= 1036) {
1618  }
1619 
1620  if(version >= 1038) {
1622  }
1623 
1624  if(version >= 1050) {
1626  }
1627 
1628  if(version >= 1053) {
1630  }
1631 
1632  if(version >= 1054) {
1634  }
1635 
1636  if(version >= 1055) {
1638  }
1639 
1640  if(version >= 1057) {
1642  }
1643 
1644  if(version >= 1061) {
1646  }
1647 
1648  if(version >= 1071) {
1650  }
1651 
1652  if(version >= 1072) {
1654  }
1655 
1656  if(version >= 1074) {
1658  }
1659 
1660  if(version >= 1080) {
1662  }
1663 
1664  if(version >= 1092) {
1666  }
1667 
1668  if(version >= 1093) {
1670  }
1671 
1672  if(version >= 1094) {
1674  }
1675 
1676  m_clientVersion = version;
1677 
1678  g_lua.callGlobalField("g_game", "onClientVersionChange", version);
1679 }
1680 
1681 void Game::setAttackingCreature(const CreaturePtr& creature)
1682 {
1683  if(creature != m_attackingCreature) {
1684  const CreaturePtr oldCreature = m_attackingCreature;
1685  m_attackingCreature = creature;
1686 
1687  g_lua.callGlobalField("g_game", "onAttackingCreatureChange", creature, oldCreature);
1688  }
1689 }
1690 
1691 void Game::setFollowingCreature(const CreaturePtr& creature)
1692 {
1693  const CreaturePtr oldCreature = m_followingCreature;
1694  m_followingCreature = creature;
1695 
1696  g_lua.callGlobalField("g_game", "onFollowingCreatureChange", creature, oldCreature);
1697 }
1698 
1699 std::string Game::formatCreatureName(const std::string& name)
1700 {
1701  std::string formatedName = name;
1702  if(getFeature(Otc::GameFormatCreatureName) && name.length() > 0) {
1703  bool upnext = true;
1704  for(char& i : formatedName) {
1705  const char ch = i;
1706  if(upnext) {
1707  i = stdext::upchar(ch);
1708  upnext = false;
1709  }
1710  if(ch == ' ')
1711  upnext = true;
1712  }
1713  }
1714 
1715  return formatedName;
1716 }
1717 
1719 {
1720  int id = -1;
1721  while(m_containers[++id] != nullptr);
1722 
1723  return id;
1724 }
1725 
1727 {
1728  if(m_clientCustomOs >= 0)
1729  return m_clientCustomOs;
1730 
1731  if(g_app.getOs() == "windows")
1732  return 10;
1733 
1734  if(g_app.getOs() == "mac")
1735  return 12;
1736 
1737  // linux
1738  return 11;
1739 }
Otc::GameThingMarks
@ GameThingMarks
Definition: const.h:406
Game::openRuleViolation
void openRuleViolation(const std::string &reporter)
Definition: game.cpp:1296
Game::findEmptyContainerId
int findEmptyContainerId()
Definition: game.cpp:1718
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:415
Protocol::disconnect
void disconnect()
Definition: protocol.cpp:50
Creature::getId
uint32 getId() override
Definition: creature.h:82
Game::editList
void editList(uint id, int doorId, const std::string &text)
Definition: game.cpp:1289
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:775
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:533
Game::cancelRuleViolation
void cancelRuleViolation()
Definition: game.cpp:1310
ProtocolGame::sendCancelAttackAndFollow
void sendCancelAttackAndFollow()
Definition: protocolgamesend.cpp:683
Otc::GameAttackSeq
@ GameAttackSeq
Definition: const.h:397
stdext::timer::restart
void restart()
Definition: time.h:42
Map::requestDrawing
void requestDrawing(const Position &pos, const Otc::RequestDrawFlags reDrawFlags, const bool force=false, const bool isLocalPlayer=false)
Definition: map.cpp:84
Game::close
void close(const ContainerPtr &container)
Definition: game.cpp:904
Game::processQuestLine
static void processQuestLine(int questId, const std::vector< std::tuple< std::string, std::string > > &questMissions)
Definition: game.cpp:510
eventdispatcher.h
Game::rejectTrade
void rejectTrade()
Definition: game.cpp:1275
Game::processWalkCancel
void processWalkCancel(Otc::Direction direction)
Definition: game.cpp:528
Game::safeLogout
void safeLogout()
Definition: game.cpp:571
Game::leaveChannel
void leaveChannel(int channelId)
Definition: game.cpp:1028
LocalPlayer::cancelWalk
void cancelWalk(Otc::Direction direction=Otc::InvalidDirection)
Definition: localplayer.cpp:126
g_map
Map g_map
Definition: map.cpp:36
Game::processOpenChannel
static void processOpenChannel(int channelId, const std::string &name)
Definition: game.cpp:367
LocalPlayer::canWalk
bool canWalk(Otc::Direction direction)
Definition: localplayer.cpp:65
Game::mount
void mount(bool mount)
Definition: game.cpp:1357
ProtocolGame::sendLeaveParty
void sendLeaveParty()
Definition: protocolgamesend.cpp:643
Game::processTextMessage
static void processTextMessage(Otc::MessageMode mode, const std::string &text)
Definition: game.cpp:287
Otc::GameNewSpeedLaw
@ GameNewSpeedLaw
Definition: const.h:401
Game::browseField
void browseField(const Position &position)
Definition: game.cpp:1378
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:84
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:1303
Game::processLogin
static void processLogin()
Definition: game.cpp:164
Game::inspectNpcTrade
void inspectNpcTrade(const ItemPtr &item)
Definition: game.cpp:1226
Game::processDeath
void processDeath(int deathType, int penality)
Definition: game.cpp:231
Game::isAttacking
bool isAttacking()
Definition: game.h:329
ProtocolGame::sendWalkSouthEast
void sendWalkSouthEast()
Definition: protocolgamesend.cpp:240
Otc::North
@ North
Definition: const.h:184
ProtocolGame::sendJoinChannel
void sendJoinChannel(int channelId)
Definition: protocolgamesend.cpp:525
Game::processEditList
static void processEditList(uint id, int doorId, const std::string &text)
Definition: game.cpp:500
Otc::ChaseModes
ChaseModes
Definition: const.h:233
ProtocolGame::sendCloseNpcChannel
void sendCloseNpcChannel()
Definition: protocolgamesend.cpp:572
ProtocolGame::sendLeaveChannel
void sendLeaveChannel(int channelId)
Definition: protocolgamesend.cpp:533
Game::processQuestLog
static 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:1049
Game::processDisconnect
void processDisconnect()
Definition: game.cpp:128
Position::x
int x
Definition: position.h:265
ProtocolGame
Definition: protocolgame.h:31
ProtocolGame::sendPing
void sendPing()
Definition: protocolgamesend.cpp:139
Game::setClientVersion
void setClientVersion(int version)
Definition: game.cpp:1500
LocalPlayer::lockWalk
void lockWalk(int millis=250)
Definition: localplayer.cpp:60
Game::processRuleViolationChannel
static void processRuleViolationChannel(int channelId)
Definition: game.cpp:387
Game::setProtocolVersion
void setProtocolVersion(int version)
Definition: game.cpp:1482
Game::isFollowing
bool isFollowing()
Definition: game.h:330
Otc::GamePlayerAddons
@ GamePlayerAddons
Definition: const.h:409
LocalPlayer
Definition: localplayer.h:29
ProtocolGame::sendCancelRuleViolation
void sendCancelRuleViolation()
Definition: protocolgamesend.cpp:565
Item::getId
uint32 getId() override
Definition: item.h:97
Game::requestItemInfo
void requestItemInfo(const ItemPtr &item, int index)
Definition: game.cpp:1364
g_dispatcher
EventDispatcher g_dispatcher
Definition: eventdispatcher.cpp:28
Otc::GameChannelPlayerList
@ GameChannelPlayerList
Definition: const.h:378
Tile::isWalkable
bool isWalkable(bool ignoreCreatures=false)
Definition: tile.cpp:528
Position::isValid
bool isValid() const
Definition: position.h:196
Game::move
void move(const ThingPtr &thing, const Position &toPos, int count)
Definition: game.cpp:786
uint32
uint32_t uint32
Definition: types.h:35
Game::stop
void stop()
Definition: game.cpp:764
Creature::setDirection
void setDirection(Otc::Direction direction)
Definition: creature.cpp:672
luavaluecasts.h
Creature
Definition: creature.h:37
Game::processInventoryChange
void processInventoryChange(int slot, const ItemPtr &item)
Definition: game.cpp:354
Otc::GameLoginPending
@ GameLoginPending
Definition: const.h:400
ProtocolGame::sendSeekInContainer
void sendSeekInContainer(int cid, int index)
Definition: protocolgamesend.cpp:854
Game::processTutorialHint
static void processTutorialHint(int id)
Definition: game.cpp:419
LocalPlayer::stopWalk
void stopWalk() override
Definition: localplayer.cpp:228
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:417
LuaInterface::callGlobalField
void callGlobalField(const std::string &global, const std::string &field, const T &... args)
Definition: luainterface.h:445
Game::processPlayerGoods
static void processPlayerGoods(int money, const std::vector< std::tuple< ItemPtr, int > > &goods)
Definition: game.cpp:470
Game::cancelFollow
void cancelFollow()
Definition: game.h:198
Game::processEditText
static 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:428
Otc::GameEnhancedAnimations
@ GameEnhancedAnimations
Definition: const.h:424
Game::openParent
void openParent(const ContainerPtr &container)
Definition: game.cpp:896
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:562
Game::processGMActions
void processGMActions(const std::vector< uint8 > &actions)
Definition: game.cpp:239
Game::setPVPMode
void setPVPMode(Otc::PVPModes pvpMode)
Definition: game.cpp:1188
Game::processLoginToken
static 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:391
Otc::GameAccountNames
@ GameAccountNames
Definition: const.h:369
Game::openPrivateChannel
void openPrivateChannel(const std::string &receiver)
Definition: game.cpp:1007
Game::processAddAutomapFlag
static void processAddAutomapFlag(const Position &pos, int icon, const std::string &message)
Definition: game.cpp:424
Otc::FightBalanced
@ FightBalanced
Definition: const.h:229
Game::setFightMode
void setFightMode(Otc::FightModes fightMode)
Definition: game.cpp:1166
Game::turn
void turn(Otc::Direction direction)
Definition: game.cpp:741
Game::useInventoryItem
void useInventoryItem(int itemId)
Definition: game.cpp:834
Otc::MessageSay
@ MessageSay
Definition: const.h:310
Game::useWith
void useWith(const ItemPtr &item, const ThingPtr &toThing)
Definition: game.cpp:844
Otc::GameExtendedClientPing
@ GameExtendedClientPing
Definition: const.h:392
Map::getTile
const TilePtr & getTile(const Position &pos)
Definition: map.cpp:358
Game::requestOutfit
void requestOutfit()
Definition: game.cpp:1105
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:430
Otc::GameIdleAnimations
@ GameIdleAnimations
Definition: const.h:436
Proto::Creature
@ Creature
Definition: protocolcodes.h:40
Game::processCloseTrade
static void processCloseTrade()
Definition: game.cpp:490
Game::processLoginAdvice
static void processLoginAdvice(const std::string &message)
Definition: game.cpp:149
LocalPlayer::setInventoryItem
void setInventoryItem(Otc::InventorySlot inventory, const ItemPtr &item)
Definition: localplayer.cpp:454
Otc::ReDrawThing
@ ReDrawThing
Definition: const.h:56
Game::processOpenOwnPrivateChannel
static void processOpenOwnPrivateChannel(int channelId, const std::string &name)
Definition: game.cpp:377
Game::equipItem
void equipItem(const ItemPtr &item)
Definition: game.cpp:1350
Game::processLoginError
static 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:553
g_game
Game g_game
Definition: game.cpp:37
Position::y
int y
Definition: position.h:266
ProtocolGame::sendRotateItem
void sendRotateItem(const Position &pos, int thingId, int stackpos)
Definition: protocolgamesend.cpp:421
Game::isConnectionOk
bool isConnectionOk()
Definition: game.h:331
ProtocolGame::sendWalkWest
void sendWalkWest()
Definition: protocolgamesend.cpp:219
Otc::GamePlayerMounts
@ GamePlayerMounts
Definition: const.h:379
Game::partyInvite
void partyInvite(int creatureId)
Definition: game.cpp:1063
Otc::GameProtocolChecksum
@ GameProtocolChecksum
Definition: const.h:368
ProtocolGame::sendAnswerModalDialog
void sendAnswerModalDialog(uint32 dialog, int button, int choice)
Definition: protocolgamesend.cpp:833
Otc::GameBaseSkillU16
@ GameBaseSkillU16
Definition: const.h:418
Otc::GameChallengeOnLogin
@ GameChallengeOnLogin
Definition: const.h:370
CreaturePtr
stdext::shared_object_ptr< Creature > CreaturePtr
Definition: declarations.h:63
stdext::format
std::string format()
Definition: format.h:84
Game::processCloseNpcTrade
static void processCloseNpcTrade()
Definition: game.cpp:475
Map::resetAwareRange
void resetAwareRange()
Definition: map.cpp:62
stdext::time
ticks_t time()
Definition: time.cpp:33
Otc::GameMessageSizeCheck
@ GameMessageSizeCheck
Definition: const.h:426
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:384
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:872
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:394
Game::processRemoveAutomapFlag
static void processRemoveAutomapFlag(const Position &pos, int icon, const std::string &message)
Definition: game.cpp:429
Otc::GameMessageStatements
@ GameMessageStatements
Definition: const.h:410
creature.h
Otc::GameOGLInformation
@ GameOGLInformation
Definition: const.h:425
ProtocolGame::sendFollow
void sendFollow(uint creatureId, uint seq)
Definition: protocolgamesend.cpp:601
Game::enableBotCall
void enableBotCall()
Definition: game.h:357
Game::requestStoreOffers
void requestStoreOffers(const std::string &categoryName, int serviceType=0)
Definition: game.cpp:1406
Proto::buildMessageModesMap
void buildMessageModesMap(int version)
Definition: protocolcodes.cpp:29
Game::open
int open(const ItemPtr &item, const ContainerPtr &previousContainer)
Definition: game.cpp:886
Otc::GameLooktypeU16
@ GameLooktypeU16
Definition: const.h:407
LocalPlayer::preWalk
void preWalk(Otc::Direction direction)
Definition: localplayer.cpp:107
Otc::NorthEast
@ NorthEast
Definition: const.h:188
uint16
uint16_t uint16
Definition: types.h:36
Otc::GameForceFirstAutoWalkStep
@ GameForceFirstAutoWalkStep
Definition: const.h:402
Game::partyShareExperience
void partyShareExperience(bool active)
Definition: game.cpp:1098
Otc::GameSpritesU32
@ GameSpritesU32
Definition: const.h:385
ProtocolGame::sendTurnWest
void sendTurnWest()
Definition: protocolgamesend.cpp:282
Game::partyJoin
void partyJoin(int creatureId)
Definition: game.cpp:1070
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:1254
Otc::GameNameOnNpcTrade
@ GameNameOnNpcTrade
Definition: const.h:372
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:434
Otc::GameExperienceBonus
@ GameExperienceBonus
Definition: const.h:431
Game::requestQuestLine
void requestQuestLine(int questId)
Definition: game.cpp:1343
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:183
Game::processEnterGame
void processEnterGame()
Definition: game.cpp:176
LocalPlayer::stopAutoWalk
void stopAutoWalk()
Definition: localplayer.cpp:218
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:429
Game::buyItem
void buyItem(const ItemPtr &item, int amount, bool ignoreCapacity, bool buyWithBackpack)
Definition: game.cpp:1233
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:308
ProtocolGame::sendInspectNpcTrade
void sendInspectNpcTrade(int itemId, int count)
Definition: protocolgamesend.cpp:310
Otc::GameTotalCapacity
@ GameTotalCapacity
Definition: const.h:375
Game::requestQuestLog
void requestQuestLog()
Definition: game.cpp:1336
Otc::GameNewOutfitProtocol
@ GameNewOutfitProtocol
Definition: const.h:414
Otc::GamePlayerMarket
@ GamePlayerMarket
Definition: const.h:384
Game::use
void use(const ThingPtr &thing)
Definition: game.cpp:820
g_logger
Logger g_logger
Definition: logger.cpp:35
Game::isOnline
bool isOnline()
Definition: game.h:326
ProtocolGame::sendLookCreature
void sendLookCreature(uint creatureId)
Definition: protocolgamesend.cpp:476
Otc::WhiteDove
@ WhiteDove
Definition: const.h:239
g_lua
LuaInterface g_lua
Definition: luainterface.cpp:31
Game::answerModalDialog
void answerModalDialog(uint32 dialog, int button, int choice)
Definition: game.cpp:1371
Game::setUnjustifiedPoints
void setUnjustifiedPoints(UnjustifiedPoints unjustifiedPoints)
Definition: game.cpp:1201
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:187
Game::closeNpcChannel
void closeNpcChannel()
Definition: game.cpp:1035
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:377
Otc::GameBrowseField
@ GameBrowseField
Definition: const.h:423
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:1155
LocalPlayer::isServerWalking
bool isServerWalking()
Definition: localplayer.h:96
Otc::GameContainerPagination
@ GameContainerPagination
Definition: const.h:405
Position
Definition: position.h:33
Game::inspectTrade
void inspectTrade(bool counterOffer, int index)
Definition: game.cpp:1261
ProtocolGame::sendRequestQuestLog
void sendRequestQuestLog()
Definition: protocolgamesend.cpp:796
Creature::setName
void setName(const std::string &name)
Definition: creature.cpp:640
Game::follow
void follow(CreaturePtr creature)
Definition: game.cpp:945
Otc::GameAdditionalSkills
@ GameAdditionalSkills
Definition: const.h:441
Game::acceptTrade
void acceptTrade()
Definition: game.cpp:1268
ProtocolGame::sendRequestTrade
void sendRequestTrade(const Position &pos, int thingId, int stackpos, uint creatureId)
Definition: protocolgamesend.cpp:352
Otc::GameUnjustifiedPoints
@ GameUnjustifiedPoints
Definition: const.h:433
Game::talkPrivate
void talkPrivate(Otc::MessageMode mode, const std::string &receiver, const std::string &message)
Definition: game.cpp:1000
Otc::GameSpellList
@ GameSpellList
Definition: const.h:390
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:46
Game::processCloseContainer
void processCloseContainer(int containerId)
Definition: game.cpp:313
Game::forceWalk
void forceWalk(Otc::Direction direction)
Definition: game.cpp:704
map.h
Otc::GamePlayerStamina
@ GamePlayerStamina
Definition: const.h:408
Game::processModalDialog
static void processModalDialog(uint32 id, const std::string &title, const std::string &message, const std::vector< std::tuple< int, std::string > > &buttonList, int enterButton, int escapeButton, const std::vector< std::tuple< int, std::string > > &choiceList, bool priority)
Definition: game.cpp:515
Otc::DontChase
@ DontChase
Definition: const.h:234
Game::getFeature
bool getFeature(Otc::GameFeature feature)
Definition: game.h:312
ProtocolGame::sendAttack
void sendAttack(uint creatureId, uint seq)
Definition: protocolgamesend.cpp:591
Otc::GameAuthenticator
@ GameAuthenticator
Definition: const.h:432
ProtocolGame::sendPingBack
void sendPingBack()
Definition: protocolgamesend.cpp:150
Tile::hasElevation
bool hasElevation(int elevation=1)
Definition: tile.cpp:624
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:993
Protocol::isConnected
bool isConnected()
Definition: protocol.cpp:58
Otc::PVPModes
PVPModes
Definition: const.h:238
Game::openOwnChannel
void openOwnChannel()
Definition: game.cpp:1042
Otc::GameNewFluids
@ GameNewFluids
Definition: const.h:412
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
ProtocolGame::sendRejectTrade
void sendRejectTrade()
Definition: protocolgamesend.cpp:379
Otc::GameWritableDate
@ GameWritableDate
Definition: const.h:416
Item::getSubType
int getSubType()
Definition: item.cpp:244
Otc::GameIngameStoreServiceType
@ GameIngameStoreServiceType
Definition: const.h:440
Otc::SouthEast
@ SouthEast
Definition: const.h:189
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:419
Otc::GameItemAnimationPhase
@ GameItemAnimationPhase
Definition: const.h:382
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:1413
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:1138
ProtocolGame::sendEquipItem
void sendEquipItem(int itemId, int countOrSubType)
Definition: protocolgamesend.cpp:289
Game::processRuleViolationLock
static void processRuleViolationLock()
Definition: game.cpp:402
Otc::GameHideNpcNames
@ GameHideNpcNames
Definition: const.h:420
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:1240
ProtocolGame::sendLook
void sendLook(const Position &position, int thingId, int stackpos)
Definition: protocolgamesend.cpp:466
Otc::South
@ South
Definition: const.h:186
Otc::GameSkillsBase
@ GameSkillsBase
Definition: const.h:376
Otc::GameOfflineTrainingTime
@ GameOfflineTrainingTime
Definition: const.h:387
Thing::getStackPos
int getStackPos()
Definition: thing.cpp:99
Game::excludeFromOwnChannel
void excludeFromOwnChannel(const std::string &name)
Definition: game.cpp:1056
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:1247
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:232
Game::refreshContainer
void refreshContainer(const ContainerPtr &container)
Definition: game.cpp:912
Otc::InventorySlot
InventorySlot
Definition: const.h:131
Game::enableFeature
void enableFeature(Otc::GameFeature feature)
Definition: game.h:309
Game::partyRevokeInvitation
void partyRevokeInvitation(int creatureId)
Definition: game.cpp:1077
Game::processOpenPrivateChannel
static void processOpenPrivateChannel(const std::string &name)
Definition: game.cpp:372
Otc::NorthWest
@ NorthWest
Definition: const.h:191
Game::talk
void talk(const std::string &message)
Definition: game.cpp:986
Game::processChannelList
static 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:1214
Game::changeMapAwareRange
void changeMapAwareRange(int xrange, int yrange)
Definition: game.cpp:1449
Game::transferCoins
void transferCoins(const std::string &recipient, int amount)
Definition: game.cpp:1420
Creature::isDead
bool isDead()
Definition: creature.h:128
Game::processRuleViolationRemove
static void processRuleViolationRemove(const std::string &name)
Definition: game.cpp:392
Otc::GameIngameStoreHighlights
@ GameIngameStoreHighlights
Definition: const.h:439
Game::partyLeave
void partyLeave()
Definition: game.cpp:1091
Game::formatCreatureName
std::string formatCreatureName(const std::string &name)
Definition: game.cpp:1699
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:374
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:1177
uimanager.h
Otc::GamePurseSlot
@ GamePurseSlot
Definition: const.h:388
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:185
stdext::timer::elapsed_millis
ticks_t elapsed_millis()
Definition: time.h:40
Otc::GamePenalityOnDeath
@ GamePenalityOnDeath
Definition: const.h:371
Game::buyStoreOffer
void buyStoreOffer(int offerId, int productType, const std::string &name="")
Definition: game.cpp:1392
Otc::GamePlayerStateU16
@ GamePlayerStateU16
Definition: const.h:413
Game::processCounterTrade
static void processCounterTrade(const std::string &name, const std::vector< ItemPtr > &items)
Definition: game.cpp:485
Otc::GameDoubleFreeCapacity
@ GameDoubleFreeCapacity
Definition: const.h:373
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:1014
Game::getOs
int getOs()
Definition: game.cpp:1726
Vip
std::tuple< std::string, uint, std::string, int, bool > Vip
Definition: game.h:59
Game::processVipStateChange
void processVipStateChange(uint id, uint status)
Definition: game.cpp:413
Game::processGameEnd
void processGameEnd()
Definition: game.cpp:211
Game::cancelAttack
void cancelAttack()
Definition: game.h:196
Game::openTransactionHistory
void openTransactionHistory(int entriesPerPage)
Definition: game.cpp:1427
Game::reportBug
void reportBug(const std::string &comment)
Definition: game.cpp:1317
ProtocolGame::sendTurnEast
void sendTurnEast()
Definition: protocolgamesend.cpp:268
game.h
Otc::GameCreatureEmblems
@ GameCreatureEmblems
Definition: const.h:381
Game::processRuleViolationCancel
static void processRuleViolationCancel(const std::string &name)
Definition: game.cpp:397
Game::changeOutfit
void changeOutfit(const Outfit &outfit)
Definition: game.cpp:1112
Game::disableBotCall
void disableBotCall()
Definition: game.h:358
Otc::GameMessageLevel
@ GameMessageLevel
Definition: const.h:411
Otc::GamePreviewState
@ GamePreviewState
Definition: const.h:427
Game::processGameStart
void processGameStart()
Definition: game.cpp:182
Thing::setPosition
void setPosition(const Position &position)
Definition: thing.cpp:53
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:1126
ProtocolGame::sendChangeOutfit
void sendChangeOutfit(const Outfit &outfit)
Definition: protocolgamesend.cpp:705
Game::getContainer
ContainerPtr getContainer(int index)
Definition: game.h:334
Otc::GameDeathType
@ GameDeathType
Definition: const.h:435
ProtocolGame::sendCloseNpcTrade
void sendCloseNpcTrade()
Definition: protocolgamesend.cpp:345
protocolgame.h
Game::processTalk
static 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:438
Thing::getPosition
Position getPosition()
Definition: thing.h:46
Game::canPerformGameAction
bool canPerformGameAction()
Definition: game.cpp:1470
Game::processUpdateNeeded
static void processUpdateNeeded(const std::string &signature)
Definition: game.cpp:139
Item::getCount
int getCount()
Definition: item.cpp:253
Game::cancelAttackAndFollow
void cancelAttackAndFollow()
Definition: game.cpp:969
Otc::FightModes
FightModes
Definition: const.h:227
ProtocolGame::sendOpenStore
void sendOpenStore(int serviceType, const std::string &category)
Definition: protocolgamesend.cpp:907
Game::processAttackCancel
void processAttackCancel(uint seq)
Definition: game.cpp:522
Game::seekInContainer
void seekInContainer(int cid, int index)
Definition: game.cpp:1385
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:222
tile.h
Event::cancel
void cancel()
Definition: event.cpp:49
Creature::setOutfit
void setOutfit(const Outfit &outfit)
Definition: creature.cpp:678
Creature::getStepTicksLeft
float getStepTicksLeft()
Definition: creature.h:104
Otc::GamePremiumExpiration
@ GamePremiumExpiration
Definition: const.h:422
Game::joinChannel
void joinChannel(int channelId)
Definition: game.cpp:1021
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:574
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:1399
Game::rotate
void rotate(const ThingPtr &thing)
Definition: game.cpp:812
Game::editText
void editText(uint id, const std::string &text)
Definition: game.cpp:1282
Otc::GameFormatCreatureName
@ GameFormatCreatureName
Definition: const.h:389
ProtocolGame::sendRequestChannels
void sendRequestChannels()
Definition: protocolgamesend.cpp:518
Game::checkBotProtection
bool checkBotProtection()
Definition: game.cpp:1457
Game::processLoginWait
static 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:803
Game::attack
void attack(CreaturePtr creature)
Definition: game.cpp:919
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:1324
Game::processPlayerHelpers
static void processPlayerHelpers(int helpers)
Definition: game.cpp:245
Game::ping
void ping()
Definition: game.cpp:1434
Game::useInventoryItemWith
void useInventoryItemWith(int itemId, const ThingPtr &toThing)
Definition: game.cpp:859
Game::walk
bool walk(Otc::Direction direction)
Definition: game.cpp:579
Game::processOwnTrade
static 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:1331
Game::autoWalk
void autoWalk(std::vector< Otc::Direction > dirs)
Definition: game.cpp:666
Game::processOpenNpcTrade
static 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:105
Otc::SouthWest
@ SouthWest
Definition: const.h:190
Item::getCountOrSubType
int getCountOrSubType()
Definition: item.h:94
Otc::GameEnvironmentEffect
@ GameEnvironmentEffect
Definition: const.h:380
Game::addVip
void addVip(const std::string &name)
Definition: game.cpp:1119
ProtocolGame::sendWalkSouth
void sendWalkSouth()
Definition: protocolgamesend.cpp:212
LocalPlayer::setPendingGame
void setPendingGame(bool pending)
Definition: localplayer.h:58
Game::processCloseChannel
static 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:1084
application.h
ProtocolGame::sendRefreshContainer
void sendRefreshContainer(int containerId)
Definition: protocolgamesend.cpp:690
Game
Definition: game.h:62