Oskar1121

Untitled

Oct 9th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.99 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////
  2. // OpenTibia - an opensource roleplaying game
  3. ////////////////////////////////////////////////////////////////////////
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ////////////////////////////////////////////////////////////////////////
  17.  
  18. #ifndef __PLAYER__
  19. #define __PLAYER__
  20.  
  21. #include "otsystem.h"
  22. #include "enums.h"
  23.  
  24. #include "creature.h"
  25. #include "cylinder.h"
  26.  
  27. #include "container.h"
  28. #include "depot.h"
  29.  
  30. #include "outfit.h"
  31. #include "vocation.h"
  32. #include "group.h"
  33.  
  34. #include "protocolgame.h"
  35. #include "ioguild.h"
  36. #include "party.h"
  37. #include "npc.h"
  38. #include "offer.h"
  39.  
  40. class House;
  41. class NetworkMessage;
  42. class Weapon;
  43. class ProtocolGame;
  44. class Npc;
  45. class Party;
  46. class SchedulerTask;
  47. class Quest;
  48.  
  49. enum skillsid_t
  50. {
  51. SKILL_LEVEL = 0,
  52. SKILL_TRIES = 1,
  53. SKILL_PERCENT = 2
  54. };
  55.  
  56. enum playerinfo_t
  57. {
  58. PLAYERINFO_LEVEL,
  59. PLAYERINFO_LEVELPERCENT,
  60. PLAYERINFO_HEALTH,
  61. PLAYERINFO_MAXHEALTH,
  62. PLAYERINFO_MANA,
  63. PLAYERINFO_MAXMANA,
  64. PLAYERINFO_MAGICLEVEL,
  65. PLAYERINFO_MAGICLEVELPERCENT,
  66. PLAYERINFO_SOUL,
  67. };
  68.  
  69. enum freeslot_t
  70. {
  71. SLOT_TYPE_NONE,
  72. SLOT_TYPE_INVENTORY,
  73. SLOT_TYPE_CONTAINER
  74. };
  75.  
  76. enum chaseMode_t
  77. {
  78. CHASEMODE_STANDSTILL,
  79. CHASEMODE_FOLLOW,
  80. };
  81.  
  82. enum fightMode_t
  83. {
  84. FIGHTMODE_ATTACK,
  85. FIGHTMODE_BALANCED,
  86. FIGHTMODE_DEFENSE
  87. };
  88.  
  89. enum secureMode_t
  90. {
  91. SECUREMODE_ON,
  92. SECUREMODE_OFF
  93. };
  94.  
  95. enum tradestate_t
  96. {
  97. TRADE_NONE,
  98. TRADE_INITIATED,
  99. TRADE_ACCEPT,
  100. TRADE_ACKNOWLEDGE,
  101. TRADE_TRANSFER
  102. };
  103.  
  104. enum AccountManager_t
  105. {
  106. MANAGER_NONE,
  107. MANAGER_NEW,
  108. MANAGER_ACCOUNT,
  109. MANAGER_NAMELOCK
  110. };
  111.  
  112. enum GamemasterCondition_t
  113. {
  114. GAMEMASTER_INVISIBLE = 0,
  115. GAMEMASTER_IGNORE = 1,
  116. GAMEMASTER_TELEPORT = 2
  117. };
  118.  
  119. enum Exhaust_t
  120. {
  121. EXHAUST_COMBAT = 1,
  122. EXHAUST_HEALING = 2,
  123. EXHAUST_TARGET = 3,
  124. EXHAUST_WEAPON = 4,
  125. EXHAUST_SPELLS = 5
  126. };
  127.  
  128. typedef std::set<uint32_t> VIPListSet;
  129. typedef std::vector<std::pair<uint32_t, Container*> > ContainerVector;
  130. typedef std::map<uint32_t, std::pair<Depot*, bool> > DepotMap;
  131. typedef std::map<uint32_t, uint32_t> MuteCountMap;
  132. typedef std::list<std::string> LearnedInstantSpellList;
  133. typedef std::list<uint32_t> InvitedToGuildsList;
  134. typedef std::list<Party*> PartyList;
  135.  
  136. #define SPEED_MAX 1500
  137. #define SPEED_MIN 10
  138. #define STAMINA_MAX (42 * 60 * 60 * 1000)
  139. #define STAMINA_MULTIPLIER (60 * 1000)
  140.  
  141. class Player : public Creature, public Cylinder
  142. {
  143. public:
  144. #ifdef __ENABLE_SERVER_DIAGNOSTIC__
  145. static uint32_t playerCount;
  146. #endif
  147. Player(const std::string& name, ProtocolGame* p);
  148. virtual ~Player();
  149.  
  150. virtual Player* getPlayer() {return this;}
  151. virtual const Player* getPlayer() const {return this;}
  152.  
  153. static MuteCountMap muteCountMap;
  154.  
  155. virtual const std::string& getName() const {return name;}
  156. virtual const std::string& getNameDescription() const {return nameDescription;}
  157. virtual std::string getDescription(int32_t lookDistance) const;
  158.  
  159. const std::string& getSpecialDescription() const {return specialDescription;}
  160. void setSpecialDescription(const std::string& desc) {specialDescription = desc;}
  161.  
  162. void manageAccount(const std::string& text);
  163. bool isAccountManager() const {return (accountManager != MANAGER_NONE);}
  164. void kickPlayer(bool displayEffect, bool forceLogout);
  165.  
  166. void setGUID(uint32_t _guid) {guid = _guid;}
  167. uint32_t getGUID() const {return guid;}
  168.  
  169. static AutoList<Player> autoList;
  170. virtual uint32_t rangeId() {return 0x10000000;}
  171.  
  172. void addList();
  173. void removeList();
  174.  
  175. static uint64_t getExpForLevel(uint32_t lv)
  176. {
  177. lv--;
  178. return ((50ULL * lv * lv * lv) - (150ULL * lv * lv) + (400ULL * lv)) / 3ULL;
  179. }
  180.  
  181. uint32_t getPromotionLevel() const {return promotionLevel;}
  182. void setPromotionLevel(uint32_t pLevel);
  183.  
  184. bool changeOutfit(Outfit_t outfit, bool checkList);
  185. void hasRequestedOutfit(bool v) {requestedOutfit = v;}
  186.  
  187. Vocation* getVocation() const {return vocation;}
  188. int32_t getPlayerInfo(playerinfo_t playerinfo) const;
  189.  
  190. void setParty(Party* _party) {party = _party;}
  191. Party* getParty() const {return party;}
  192. PartyShields_t getPartyShield(const Creature* creature) const;
  193. bool isInviting(const Player* player) const;
  194. bool isPartner(const Player* player) const;
  195. void sendPlayerPartyIcons(Player* player);
  196. bool addPartyInvitation(Party* party);
  197. bool removePartyInvitation(Party* party);
  198. void clearPartyInvitations();
  199.  
  200. uint32_t getGuildId() const {return guildId;}
  201. void setGuildId(uint32_t newId) {guildId = newId;}
  202. uint32_t getRankId() const {return rankId;}
  203. void setRankId(uint32_t newId) {rankId = newId;}
  204.  
  205. GuildLevel_t getGuildLevel() const {return guildLevel;}
  206. bool setGuildLevel(GuildLevel_t newLevel, uint32_t rank = 0);
  207.  
  208. const std::string& getGuildName() const {return guildName;}
  209. void setGuildName(const std::string& newName) {guildName = newName;}
  210. const std::string& getRankName() const {return rankName;}
  211. void setRankName(const std::string& newName) {rankName = newName;}
  212.  
  213. const std::string& getGuildNick() const {return guildNick;}
  214. void setGuildNick(const std::string& newNick) {guildNick = newNick;}
  215.  
  216. bool isGuildInvited(uint32_t guildId) const;
  217. void leaveGuild();
  218.  
  219. void setFlags(uint64_t flags) {if(group) group->setFlags(flags);}
  220. bool hasFlag(PlayerFlags value) const {return group != NULL && group->hasFlag(value);}
  221. void setCustomFlags(uint64_t flags) {if(group) group->setCustomFlags(flags);}
  222. bool hasCustomFlag(PlayerCustomFlags value) const {return group != NULL && group->hasCustomFlag(value);}
  223.  
  224. void addBlessing(int16_t blessing) {blessings += blessing;}
  225. bool hasBlessing(int16_t value) const {return (blessings & ((int16_t)1 << value));}
  226. uint16_t getBlessings() const;
  227.  
  228. OperatingSystem_t getOperatingSystem() const {return operatingSystem;}
  229. void setOperatingSystem(OperatingSystem_t clientOs) {operatingSystem = clientOs;}
  230. uint32_t getClientVersion() const {return clientVersion;}
  231. void setClientVersion(uint32_t version) {clientVersion = version;}
  232.  
  233. bool hasClient() const {return client;}
  234. bool isVirtual() const {return (getID() == 0);}
  235. void disconnect() {if(client) client->disconnect();}
  236. uint32_t getIP() const;
  237. bool canOpenCorpse(uint32_t ownerId);
  238.  
  239. Container* getContainer(uint32_t cid);
  240. int32_t getContainerID(const Container* container) const;
  241.  
  242. void addContainer(uint32_t cid, Container* container);
  243. void closeContainer(uint32_t cid);
  244.  
  245. virtual bool setStorage(const uint32_t key, const std::string& value);
  246. virtual void eraseStorage(const uint32_t key);
  247.  
  248. void generateReservedStorage();
  249. bool transferMoneyTo(const std::string& name, uint64_t amount);
  250. void increaseCombatValues(int32_t& min, int32_t& max, bool useCharges, bool countWeapon);
  251.  
  252. void setGroupId(int32_t newId);
  253. int32_t getGroupId() const {return groupId;}
  254. void setGroup(Group* newGroup);
  255. Group* getGroup() const {return group;}
  256.  
  257. virtual bool isGhost() const {return hasCondition(CONDITION_GAMEMASTER, GAMEMASTER_INVISIBLE) || hasFlag(PlayerFlag_CannotBeSeen);}
  258.  
  259. void switchSaving() {saving = !saving;}
  260. bool isSaving() const {return saving;}
  261.  
  262. uint32_t getIdleTime() const {return idleTime;}
  263. void setIdleTime(uint32_t amount) {idleTime = amount;}
  264.  
  265. bool checkLoginDelay(uint32_t playerId) const;
  266. bool isTrading() const {return tradePartner;}
  267.  
  268. uint32_t getAccount() const {return accountId;}
  269. std::string getAccountName() const {return account;}
  270. uint16_t getAccess() const {return group ? group->getAccess() : 0;}
  271. uint16_t getGhostAccess() const {return group ? group->getGhostAccess() : 0;}
  272.  
  273. bool isPremium() const;
  274. int32_t getPremiumDays() const {return premiumDays;}
  275.  
  276. uint32_t getLevel() const {return level;}
  277. uint64_t getExperience() const {return experience;}
  278. uint32_t getMagicLevel() const {return getPlayerInfo(PLAYERINFO_MAGICLEVEL);}
  279. uint64_t getSpentMana() const {return manaSpent;}
  280.  
  281. uint32_t getVocationId() const {return vocation_id;}
  282. void setVocation(uint32_t vocId);
  283. uint16_t getSex(bool full) const {return full ? sex : sex % 2;}
  284. void setSex(uint16_t);
  285.  
  286. uint64_t getStamina() const {return hasFlag(PlayerFlag_HasInfiniteStamina) ? STAMINA_MAX : stamina;}
  287. void setStamina(uint64_t value) {stamina = std::min((uint64_t)STAMINA_MAX, (uint64_t)std::max((uint64_t)0, value));}
  288. uint32_t getStaminaMinutes() const {return (uint32_t)(getStamina() / (uint64_t)STAMINA_MULTIPLIER);}
  289. void setStaminaMinutes(uint32_t value) {setStamina((uint64_t)(value * STAMINA_MULTIPLIER));}
  290. void useStamina(int64_t value) {stamina = std::min((int64_t)STAMINA_MAX, (int64_t)std::max((int64_t)0, ((int64_t)stamina + value)));}
  291. uint64_t getSpentStamina() {return (uint64_t)STAMINA_MAX - stamina;}
  292.  
  293. int64_t getLastLoad() const {return lastLoad;}
  294. time_t getLastLogin() const {return lastLogin;}
  295. time_t getLastLogout() const {return lastLogout;}
  296.  
  297. Position getLoginPosition() const {return loginPosition;}
  298.  
  299. uint32_t getTown() const {return town;}
  300. void setTown(uint32_t _town) {town = _town;}
  301.  
  302. virtual bool isPushable() const;
  303. virtual int32_t getThrowRange() const {return 1;}
  304.  
  305. bool isMuted(uint16_t channelId, SpeakClasses type, uint32_t& time);
  306. void addMessageBuffer();
  307. void removeMessageBuffer();
  308.  
  309. double getCapacity() const {return capacity;}
  310. void setCapacity(double newCapacity) {capacity = newCapacity;}
  311.  
  312. double getFreeCapacity() const
  313. {
  314. if(hasFlag(PlayerFlag_CannotPickupItem))
  315. return 0.00;
  316. else if(hasFlag(PlayerFlag_HasInfiniteCapacity))
  317. return 10000.00;
  318.  
  319. return std::max(0.00, capacity - inventoryWeight);
  320. }
  321.  
  322. virtual int32_t getSoul() const {return getPlayerInfo(PLAYERINFO_SOUL);}
  323. virtual int32_t getMaxHealth() const {return getPlayerInfo(PLAYERINFO_MAXHEALTH);}
  324. virtual int32_t getMaxMana() const {return getPlayerInfo(PLAYERINFO_MAXMANA);}
  325. int32_t getSoulMax() const {return soulMax;}
  326.  
  327. Item* getInventoryItem(slots_t slot) const;
  328. Item* getEquippedItem(slots_t slot) const;
  329.  
  330. bool isItemAbilityEnabled(slots_t slot) const {return inventoryAbilities[slot];}
  331. void setItemAbility(slots_t slot, bool enabled) {inventoryAbilities[slot] = enabled;}
  332.  
  333. int32_t getVarSkill(skills_t skill) const {return varSkills[skill];}
  334. void setVarSkill(skills_t skill, int32_t modifier) {varSkills[skill] += modifier;}
  335.  
  336. int32_t getVarStats(stats_t stat) const {return varStats[stat];}
  337. void setVarStats(stats_t stat, int32_t modifier);
  338. int32_t getDefaultStats(stats_t stat);
  339.  
  340. void setConditionSuppressions(uint32_t conditions, bool remove);
  341.  
  342. uint32_t getLossPercent(lossTypes_t lossType) const {return lossPercent[lossType];}
  343. void setLossPercent(lossTypes_t lossType, uint32_t newPercent) {lossPercent[lossType] = newPercent;}
  344.  
  345. Depot* getDepot(uint32_t depotId, bool autoCreateDepot);
  346. bool addDepot(Depot* depot, uint32_t depotId);
  347. void useDepot(uint32_t depotId, bool value);
  348.  
  349. virtual bool canSee(const Position& pos) const;
  350. virtual bool canSeeCreature(const Creature* creature) const;
  351. virtual bool canWalkthrough(const Creature* creature) const;
  352.  
  353. virtual bool canSeeInvisibility() const {return hasFlag(PlayerFlag_CanSenseInvisibility);}
  354.  
  355. virtual RaceType_t getRace() const {return RACE_BLOOD;}
  356.  
  357. //safe-trade functions
  358. void setTradeState(tradestate_t state) {tradeState = state;}
  359. tradestate_t getTradeState() {return tradeState;}
  360. Item* getTradeItem() {return tradeItem;}
  361.  
  362. void doDepositMoney(uint64_t amount)
  363. {
  364. balance += amount;
  365.  
  366. sendGoods();
  367. }
  368. void doWithdrawMoney(uint64_t amount)
  369. {
  370. if(amount > balance)
  371. balance = 0;
  372. else
  373. balance -= amount;
  374.  
  375. sendGoods();
  376. }
  377.  
  378. //shop functions
  379. void setShopOwner(Npc* owner, int32_t onBuy, int32_t onSell, ShopInfoList offer)
  380. {
  381. shopOwner = owner;
  382. purchaseCallback = onBuy;
  383. saleCallback = onSell;
  384. shopOffer = offer;
  385. }
  386.  
  387. Npc* getShopOwner(int32_t& onBuy, int32_t& onSell)
  388. {
  389. onBuy = purchaseCallback;
  390. onSell = saleCallback;
  391. return shopOwner;
  392. }
  393.  
  394. const Npc* getShopOwner(int32_t& onBuy, int32_t& onSell) const
  395. {
  396. onBuy = purchaseCallback;
  397. onSell = saleCallback;
  398. return shopOwner;
  399. }
  400.  
  401. //V.I.P. functions
  402. void notifyLogIn(Player* loginPlayer);
  403. void notifyLogOut(Player* logoutPlayer);
  404. bool removeVIP(uint32_t guid);
  405. bool addVIP(uint32_t guid, std::string& name, bool isOnline, bool internal = false);
  406.  
  407. //follow functions
  408. virtual bool setFollowCreature(Creature* creature, bool fullPathSearch = false);
  409.  
  410. //follow events
  411. virtual void onFollowCreature(const Creature* creature);
  412.  
  413. //walk events
  414. virtual void onWalk(Direction& dir);
  415. virtual void onWalkAborted();
  416. virtual void onWalkComplete();
  417. uint64_t getBalance() const { return balance; }
  418. uint64_t getPremiumBalance() const { return premiumPoints; }
  419.  
  420. void updatePremiumPoints(uint64_t, bool);
  421.  
  422. void stopWalk();
  423. void openShopWindow();
  424. void closeShopWindow(Npc* npc = NULL, int32_t onBuy = -1, int32_t onSell = -1);
  425. bool canShopItem(uint16_t itemId, uint8_t subType, ShopEvent_t event);
  426.  
  427. void setChaseMode(chaseMode_t mode);
  428. void setFightMode(fightMode_t mode) {fightMode = mode;}
  429. void setSecureMode(secureMode_t mode) {secureMode = mode;}
  430. secureMode_t getSecureMode() const {return secureMode;}
  431.  
  432. //combat functions
  433. virtual bool setAttackedCreature(Creature* creature);
  434. bool isImmune(CombatType_t type) const;
  435. bool isImmune(ConditionType_t type) const;
  436. bool hasShield() const;
  437. virtual bool isAttackable() const;
  438.  
  439. virtual void changeHealth(int32_t healthChange);
  440. virtual void changeMana(int32_t manaChange);
  441. void changeSoul(int32_t soulChange);
  442.  
  443. bool isPzLocked() const {return pzLocked;}
  444. void setPzLocked(bool v) {pzLocked = v;}
  445. virtual BlockType_t blockHit(Creature* attacker, CombatType_t combatType, int32_t& damage,
  446. bool checkDefense = false, bool checkArmor = false);
  447. virtual void doAttacking(uint32_t interval);
  448. virtual bool hasExtraSwing() {return lastAttack > 0 && ((OTSYS_TIME() - lastAttack) >= getAttackSpeed());}
  449. int32_t getShootRange() const {return shootRange;}
  450.  
  451. int32_t getSkill(skills_t skilltype, skillsid_t skillinfo) const;
  452. bool getAddAttackSkill() const {return addAttackSkillPoint;}
  453. BlockType_t getLastAttackBlockType() const {return lastAttackBlockType;}
  454.  
  455. Item* getWeapon(bool ignoreAmmo = false);
  456. virtual WeaponType_t getWeaponType();
  457. int32_t getWeaponSkill(const Item* item) const;
  458. void getShieldAndWeapon(const Item* &shield, const Item* &weapon) const;
  459.  
  460. virtual void drainHealth(Creature* attacker, CombatType_t combatType, int32_t damage);
  461. virtual void drainMana(Creature* attacker, CombatType_t combatType, int32_t damage);
  462.  
  463. void addExperience(uint64_t exp);
  464. void removeExperience(uint64_t exp, bool updateStats = true);
  465. void addManaSpent(uint64_t amount, bool useMultiplier = true);
  466. void addSkillAdvance(skills_t skill, uint32_t count, bool useMultiplier = true);
  467. bool addUnjustifiedKill(const Player* attacked);
  468.  
  469. virtual int32_t getArmor() const;
  470. virtual int32_t getDefense() const;
  471. virtual float getAttackFactor() const;
  472. virtual float getDefenseFactor() const;
  473.  
  474. void addExhaust(uint32_t ticks, Exhaust_t type);
  475. void addInFightTicks(bool pzLock = false);
  476. void addDefaultRegeneration(uint32_t addTicks);
  477.  
  478. virtual double getGainedExperience(Creature* attacker) const;
  479.  
  480. //combat event functions
  481. virtual void onAddCondition(ConditionType_t type, bool hadCondition);
  482. virtual void onAddCombatCondition(ConditionType_t type, bool hadCondition);
  483. virtual void onEndCondition(ConditionType_t type);
  484. virtual void onCombatRemoveCondition(const Creature* attacker, Condition* condition);
  485. virtual void onTickCondition(ConditionType_t type, int32_t interval, bool& _remove);
  486. virtual void onAttackedCreature(Creature* target);
  487. virtual void onSummonAttackedCreature(Creature* summon, Creature* target);
  488. virtual void onAttacked();
  489. virtual void onAttackedCreatureDrain(Creature* target, int32_t points);
  490. virtual void onSummonAttackedCreatureDrain(Creature* summon, Creature* target, int32_t points);
  491. virtual void onTargetCreatureGainHealth(Creature* target, int32_t points);
  492. virtual bool onKilledCreature(Creature* target, uint32_t& flags);
  493. virtual void onGainExperience(double& gainExp, bool fromMonster, bool multiplied);
  494. virtual void onGainSharedExperience(double& gainExp, bool fromMonster, bool multiplied);
  495. virtual void onAttackedCreatureBlockHit(Creature* target, BlockType_t blockType);
  496. virtual void onBlockHit(BlockType_t blockType);
  497. virtual void onChangeZone(ZoneType_t zone);
  498. virtual void onAttackedCreatureChangeZone(ZoneType_t zone);
  499. virtual void onIdleStatus();
  500. virtual void onPlacedCreature();
  501.  
  502. virtual void getCreatureLight(LightInfo& light) const;
  503. Skulls_t getSkull() const;
  504. Skulls_t getSkullClient(const Creature* creature) const;
  505.  
  506. bool hasAttacked(const Player* attacked) const;
  507. void addAttacked(const Player* attacked);
  508. void clearAttacked() {attackedSet.clear();}
  509.  
  510. time_t getSkullEnd() const {return skullEnd;}
  511. void setSkullEnd(time_t _time, bool login, Skulls_t _skull);
  512.  
  513. bool addOutfit(uint32_t outfitId, uint32_t addons);
  514. bool removeOutfit(uint32_t outfitId, uint32_t addons);
  515.  
  516. bool canWearOutfit(uint32_t outfitId, uint32_t addons);
  517. bool canLogout(bool checkInfight);
  518.  
  519. //tile
  520. //send methods
  521. void sendAddTileItem(const Tile* tile, const Position& pos, const Item* item)
  522. {if(client) client->sendAddTileItem(tile, pos, tile->getClientIndexOfThing(this, item), item);}
  523. void sendUpdateTileItem(const Tile* tile, const Position& pos, const Item* oldItem, const Item* newItem)
  524. {if(client) client->sendUpdateTileItem(tile, pos, tile->getClientIndexOfThing(this, oldItem), newItem);}
  525. void sendRemoveTileItem(const Tile* tile, const Position& pos, uint32_t stackpos, const Item* item)
  526. {if(client) client->sendRemoveTileItem(tile, pos, stackpos);}
  527. void sendUpdateTile(const Tile* tile, const Position& pos)
  528. {if(client) client->sendUpdateTile(tile, pos);}
  529.  
  530. void sendChannelMessage(std::string author, std::string text, SpeakClasses type, uint8_t channel)
  531. {if(client) client->sendChannelMessage(author, text, type, channel);}
  532. void sendCreatureAppear(const Creature* creature)
  533. {if(client) client->sendAddCreature(creature, creature->getPosition(), creature->getTile()->getClientIndexOfThing(
  534. this, creature));}
  535. void sendCreatureDisappear(const Creature* creature, uint32_t stackpos)
  536. {if(client) client->sendRemoveCreature(creature, creature->getPosition(), stackpos);}
  537. void sendCreatureMove(const Creature* creature, const Tile* newTile, const Position& newPos,
  538. const Tile* oldTile, const Position& oldPos, uint32_t oldStackpos, bool teleport)
  539. {if(client) client->sendMoveCreature(creature, newTile, newPos, newTile->getClientIndexOfThing(
  540. this, creature), oldTile, oldPos, oldStackpos, teleport);}
  541.  
  542. void sendCreatureTurn(const Creature* creature)
  543. {if(client) client->sendCreatureTurn(creature, creature->getTile()->getClientIndexOfThing(this, creature));}
  544. void sendCreatureSay(const Creature* creature, SpeakClasses type, const std::string& text, Position* pos = NULL)
  545. {if(client) client->sendCreatureSay(creature, type, text, pos);}
  546. void sendCreatureSquare(const Creature* creature, SquareColor_t color)
  547. {if(client) client->sendCreatureSquare(creature, color);}
  548. void sendCreatureChangeOutfit(const Creature* creature, const Outfit_t& outfit)
  549. {if(client) client->sendCreatureOutfit(creature, outfit);}
  550. void sendCreatureChangeVisible(const Creature* creature, Visible_t visible);
  551. void sendCreatureLight(const Creature* creature)
  552. {if(client) client->sendCreatureLight(creature);}
  553. void sendCreatureShield(const Creature* creature)
  554. {if(client) client->sendCreatureShield(creature);}
  555.  
  556. //container
  557. void sendAddContainerItem(const Container* container, const Item* item);
  558. void sendUpdateContainerItem(const Container* container, uint8_t slot, const Item* oldItem, const Item* newItem);
  559. void sendRemoveContainerItem(const Container* container, uint8_t slot, const Item* item);
  560. void sendContainer(uint32_t cid, const Container* container, bool hasParent)
  561. {if(client) client->sendContainer(cid, container, hasParent);}
  562.  
  563. //inventory
  564. void sendAddInventoryItem(slots_t slot, const Item* item)
  565. {if(client) client->sendAddInventoryItem(slot, item);}
  566. void sendUpdateInventoryItem(slots_t slot, const Item* oldItem, const Item* newItem)
  567. {if(client) client->sendUpdateInventoryItem(slot, newItem);}
  568. void sendRemoveInventoryItem(slots_t slot, const Item* item)
  569. {if(client) client->sendRemoveInventoryItem(slot);}
  570.  
  571. //event methods
  572. virtual void onUpdateTileItem(const Tile* tile, const Position& pos, const Item* oldItem,
  573. const ItemType& oldType, const Item* newItem, const ItemType& newType);
  574. virtual void onRemoveTileItem(const Tile* tile, const Position& pos,
  575. const ItemType& iType, const Item* item);
  576.  
  577. virtual void onCreatureAppear(const Creature* creature);
  578. virtual void onCreatureDisappear(const Creature* creature, bool isLogout);
  579. virtual void onCreatureMove(const Creature* creature, const Tile* newTile, const Position& newPos,
  580. const Tile* oldTile, const Position& oldPos, bool teleport);
  581.  
  582. virtual void onAttackedCreatureDisappear(bool isLogout);
  583. virtual void onFollowCreatureDisappear(bool isLogout);
  584.  
  585. //cylinder implementations
  586. virtual Cylinder* getParent() {return Creature::getParent();}
  587. virtual const Cylinder* getParent() const {return Creature::getParent();}
  588. virtual bool isRemoved() const {return Creature::isRemoved();}
  589. virtual Position getPosition() const {return Creature::getPosition();}
  590. virtual Tile* getTile() {return Creature::getTile();}
  591. virtual const Tile* getTile() const {return Creature::getTile();}
  592. virtual Item* getItem() {return NULL;}
  593. virtual const Item* getItem() const {return NULL;}
  594. virtual Creature* getCreature() {return this;}
  595. virtual const Creature* getCreature() const {return this;}
  596.  
  597. //container
  598. void onAddContainerItem(const Container* container, const Item* item);
  599. void onUpdateContainerItem(const Container* container, uint8_t slot,
  600. const Item* oldItem, const ItemType& oldType, const Item* newItem, const ItemType& newType);
  601. void onRemoveContainerItem(const Container* container, uint8_t slot, const Item* item);
  602.  
  603. void onCloseContainer(const Container* container);
  604. void onSendContainer(const Container* container);
  605. void autoCloseContainers(const Container* container);
  606.  
  607. //inventory
  608. void onAddInventoryItem(slots_t slot, Item* item) {}
  609. void onUpdateInventoryItem(slots_t slot, Item* oldItem, const ItemType& oldType,
  610. Item* newItem, const ItemType& newType);
  611. void onRemoveInventoryItem(slots_t slot, Item* item);
  612.  
  613. void sendAnimatedText(const Position& pos, uint8_t color, std::string text) const
  614. {if(client) client->sendAnimatedText(pos,color,text);}
  615. void sendCancel(const std::string& msg) const
  616. {if(client) client->sendCancel(msg);}
  617. void sendCancelMessage(ReturnValue message) const;
  618. void sendCancelTarget() const
  619. {if(client) client->sendCancelTarget();}
  620. void sendCancelWalk() const
  621. {if(client) client->sendCancelWalk();}
  622. void sendChangeSpeed(const Creature* creature, uint32_t newSpeed) const
  623. {if(client) client->sendChangeSpeed(creature, newSpeed);}
  624. void sendCreatureHealth(const Creature* creature) const
  625. {if(client) client->sendCreatureHealth(creature);}
  626. void sendDistanceShoot(const Position& from, const Position& to, uint8_t type) const
  627. {if(client) client->sendDistanceShoot(from, to, type);}
  628. void sendHouseWindow(House* house, uint32_t listId) const;
  629. void sendOutfitWindow() const {if(client) client->sendOutfitWindow();}
  630. void sendQuests() const {if(client) client->sendQuests();}
  631. void sendQuestInfo(Quest* quest) const {if(client) client->sendQuestInfo(quest);}
  632. void sendCreatureSkull(const Creature* creature) const
  633. {if(client) client->sendCreatureSkull(creature);}
  634. void sendFYIBox(std::string message)
  635. {if(client) client->sendFYIBox(message);}
  636. void sendCreatePrivateChannel(uint16_t channelId, const std::string& channelName)
  637. {if(client) client->sendCreatePrivateChannel(channelId, channelName);}
  638. void sendClosePrivate(uint16_t channelId) const
  639. {if(client) client->sendClosePrivate(channelId);}
  640. void sendIcons() const;
  641. void sendMagicEffect(const Position& pos, uint16_t type) const
  642. {if(client) client->sendMagicEffect(pos, type);}
  643. void sendStats();
  644. void sendSkills() const
  645. {if(client) client->sendSkills();}
  646. void sendTextMessage(MessageClasses type, const std::string& message) const
  647. {if(client) client->sendTextMessage(type, message);}
  648. void sendReLoginWindow() const
  649. {if(client) client->sendReLoginWindow();}
  650. void sendTextWindow(Item* item, uint16_t maxLen, bool canWrite) const
  651. {if(client) client->sendTextWindow(windowTextId, item, maxLen, canWrite);}
  652. void sendTextWindow(uint32_t itemId, const std::string& text) const
  653. {if(client) client->sendTextWindow(windowTextId, itemId, text);}
  654. void sendToChannel(Creature* creature, SpeakClasses type, const std::string& text, uint16_t channelId, uint32_t time = 0) const
  655. {if(client) client->sendToChannel(creature, type, text, channelId, time);}
  656. void sendShop() const
  657. {if(client) client->sendShop(shopOffer);}
  658. void sendGoods() const
  659. {if(client) client->sendGoods(shopOffer);}
  660. void sendCloseShop() const
  661. {if(client) client->sendCloseShop();}
  662. void sendTradeItemRequest(const Player* player, const Item* item, bool ack) const
  663. {if(client) client->sendTradeItemRequest(player, item, ack);}
  664. void sendTradeClose() const
  665. {if(client) client->sendCloseTrade();}
  666. void sendWorldLight(LightInfo& lightInfo)
  667. {if(client) client->sendWorldLight(lightInfo);}
  668. void sendChannelsDialog()
  669. {if(client) client->sendChannelsDialog();}
  670. void sendOpenPrivateChannel(const std::string& receiver)
  671. {if(client) client->sendOpenPrivateChannel(receiver);}
  672. void sendOutfitWindow()
  673. {if(client) client->sendOutfitWindow();}
  674. void sendCloseContainer(uint32_t cid)
  675. {if(client) client->sendCloseContainer(cid);}
  676. void sendChannel(uint16_t channelId, const std::string& channelName)
  677. {if(client) client->sendChannel(channelId, channelName);}
  678. void sendRuleViolationsChannel(uint16_t channelId)
  679. {if(client) client->sendRuleViolationsChannel(channelId);}
  680. void sendRemoveReport(const std::string& name)
  681. {if(client) client->sendRemoveReport(name);}
  682. void sendLockRuleViolation()
  683. {if(client) client->sendLockRuleViolation();}
  684. void sendRuleViolationCancel(const std::string& name)
  685. {if(client) client->sendRuleViolationCancel(name);}
  686. void sendTutorial(uint8_t tutorialId)
  687. {if(client) client->sendTutorial(tutorialId);}
  688. void sendAddMarker(const Position& pos, MapMarks_t markType, const std::string& desc)
  689. {if (client) client->sendAddMarker(pos, markType, desc);}
  690.  
  691. void sendMarketOffer(OfferVector& offerVector, UpdateType_t type, double size) const
  692. { if (client) client->sendMarketOffer(offerVector, type, size); }
  693. void sendRemoveOffer(uint16_t id) const
  694. { if (client) client->sendRemoveOffer(id); }
  695. void sendUpdateOffer(uint16_t id, uint16_t count) const
  696. { if (client) client->sendUpdateOffer(id, count); }
  697. void sendMarketStatus(UpdateType_t id) const
  698. { if (client) client->sendMarketStatus(id); }
  699.  
  700. void sendCritical() const;
  701.  
  702. void receivePing() {lastPong = OTSYS_TIME();}
  703. virtual void onThink(uint32_t interval);
  704. uint32_t getAttackSpeed();
  705.  
  706. virtual void postAddNotification(Creature* actor, Thing* thing, const Cylinder* oldParent,
  707. int32_t index, cylinderlink_t link = LINK_OWNER);
  708. virtual void postRemoveNotification(Creature* actor, Thing* thing, const Cylinder* newParent,
  709. int32_t index, bool isCompleteRemoval, cylinderlink_t link = LINK_OWNER);
  710.  
  711. void setNextAction(int64_t time) {if(time > nextAction) {nextAction = time;}}
  712. bool canDoAction() const {return nextAction <= OTSYS_TIME();}
  713. uint32_t getNextActionTime() const;
  714.  
  715. Item* getWriteItem(uint32_t& _windowTextId, uint16_t& _maxWriteLen);
  716. void setWriteItem(Item* item, uint16_t _maxWriteLen = 0);
  717.  
  718. House* getEditHouse(uint32_t& _windowTextId, uint32_t& _listId);
  719. void setEditHouse(House* house, uint32_t listId = 0);
  720.  
  721. void learnInstantSpell(const std::string& name);
  722. void unlearnInstantSpell(const std::string& name);
  723. bool hasLearnedInstantSpell(const std::string& name) const;
  724.  
  725. VIPListSet VIPList;
  726. ContainerVector containerVec;
  727. InvitedToGuildsList invitedToGuildsList;
  728. ConditionList storedConditionList;
  729. DepotMap depots;
  730.  
  731. uint32_t marriage;
  732. uint64_t balance;
  733. double rates[SKILL__LAST + 1];
  734. Container transferContainer;
  735.  
  736. protected:
  737. void checkTradeState(const Item* item);
  738.  
  739. bool gainExperience(double& gainExp, bool fromMonster);
  740. bool rateExperience(double& gainExp, bool fromMonster);
  741. void updateBaseSpeed()
  742. {
  743. if(!hasFlag(PlayerFlag_SetMaxSpeed))
  744. baseSpeed = vocation->getBaseSpeed() + (2 * (level - 1));
  745. else
  746. baseSpeed = SPEED_MAX;
  747. }
  748.  
  749. void updateInventoryWeight();
  750. void updateInventoryGoods(uint32_t itemId);
  751. void updateItemsLight(bool internal = false);
  752.  
  753. void setNextWalkActionTask(SchedulerTask* task);
  754. void setNextWalkTask(SchedulerTask* task);
  755. void setNextActionTask(SchedulerTask* task);
  756.  
  757. virtual bool onDeath();
  758. virtual Item* createCorpse(DeathList deathList);
  759.  
  760. virtual void dropCorpse(DeathList deathList);
  761. virtual void dropLoot(Container* corpse);
  762.  
  763. //cylinder implementations
  764. virtual ReturnValue __queryAdd(int32_t index, const Thing* thing, uint32_t count,
  765. uint32_t flags) const;
  766. virtual ReturnValue __queryMaxCount(int32_t index, const Thing* thing, uint32_t count, uint32_t& maxQueryCount,
  767. uint32_t flags) const;
  768. virtual ReturnValue __queryRemove(const Thing* thing, uint32_t count, uint32_t flags) const;
  769. virtual Cylinder* __queryDestination(int32_t& index, const Thing* thing, Item** destItem,
  770. uint32_t& flags);
  771.  
  772. virtual void __addThing(Creature* actor, Thing* thing);
  773. virtual void __addThing(Creature* actor, int32_t index, Thing* thing);
  774.  
  775. virtual void __updateThing(Thing* thing, uint16_t itemId, uint32_t count);
  776. virtual void __replaceThing(uint32_t index, Thing* thing);
  777.  
  778. virtual void __removeThing(Thing* thing, uint32_t count);
  779.  
  780. virtual Thing* __getThing(uint32_t index) const;
  781. virtual int32_t __getIndexOfThing(const Thing* thing) const;
  782. virtual int32_t __getFirstIndex() const;
  783. virtual int32_t __getLastIndex() const;
  784. virtual uint32_t __getItemTypeCount(uint16_t itemId, int32_t subType = -1,
  785. bool itemCount = true) const;
  786. virtual std::map<uint32_t, uint32_t>& __getAllItemTypeCount(std::map<uint32_t,
  787. uint32_t>& countMap, bool itemCount = true) const;
  788.  
  789. virtual void __internalAddThing(Thing* thing);
  790. virtual void __internalAddThing(uint32_t index, Thing* thing);
  791.  
  792. uint32_t getVocAttackSpeed() const {return vocation->getAttackSpeed();}
  793. virtual int32_t getStepSpeed() const
  794. {
  795. if(getSpeed() > SPEED_MAX)
  796. return SPEED_MAX;
  797.  
  798. if(getSpeed() < SPEED_MIN)
  799. return SPEED_MIN;
  800.  
  801. return getSpeed();
  802. }
  803.  
  804. virtual uint32_t getDamageImmunities() const {return damageImmunities;}
  805. virtual uint32_t getConditionImmunities() const {return conditionImmunities;}
  806. virtual uint32_t getConditionSuppressions() const {return conditionSuppressions;}
  807.  
  808. virtual uint16_t getLookCorpse() const;
  809. virtual uint64_t getLostExperience() const;
  810.  
  811. virtual void getPathSearchParams(const Creature* creature, FindPathParams& fpp) const;
  812. static uint32_t getPercentLevel(uint64_t count, uint64_t nextLevelCount);
  813.  
  814. bool isPromoted(uint32_t pLevel = 1) const {return promotionLevel >= pLevel;}
  815. bool hasCapacity(const Item* item, uint32_t count) const;
  816.  
  817. private:
  818. bool talkState[13];
  819. bool inventoryAbilities[11];
  820. bool pzLocked;
  821. bool saving;
  822. bool isConnecting;
  823. bool requestedOutfit;
  824. bool outfitAttributes;
  825. bool addAttackSkillPoint;
  826.  
  827. OperatingSystem_t operatingSystem;
  828. AccountManager_t accountManager;
  829. PlayerSex_t managerSex;
  830. BlockType_t lastAttackBlockType;
  831. chaseMode_t chaseMode;
  832. fightMode_t fightMode;
  833. secureMode_t secureMode;
  834. tradestate_t tradeState;
  835. GuildLevel_t guildLevel;
  836.  
  837. int16_t blessings;
  838. uint16_t maxWriteLen;
  839. uint16_t sex;
  840.  
  841. int32_t premiumDays;
  842. int32_t soul;
  843. int32_t soulMax;
  844. int32_t vocation_id;
  845. int32_t groupId;
  846. int32_t managerNumber, managerNumber2;
  847. int32_t purchaseCallback;
  848. int32_t saleCallback;
  849. int32_t varSkills[SKILL_LAST + 1];
  850. int32_t varStats[STAT_LAST + 1];
  851. int32_t messageBuffer;
  852. int32_t bloodHitCount;
  853. int32_t shieldBlockCount;
  854. int32_t shootRange;
  855.  
  856. uint32_t premiumPoints;
  857. uint32_t clientVersion;
  858. uint32_t messageTicks;
  859. uint32_t idleTime;
  860. uint32_t accountId;
  861. uint32_t lastIP;
  862. uint32_t level;
  863. uint32_t levelPercent;
  864. uint32_t magLevel;
  865. uint32_t magLevelPercent;
  866. uint32_t damageImmunities;
  867. uint32_t conditionImmunities;
  868. uint32_t conditionSuppressions;
  869. uint32_t condition; //?
  870. uint32_t nextStepEvent;
  871. uint32_t actionTaskEvent;
  872. uint32_t walkTaskEvent;
  873. uint32_t lossPercent[LOSS_LAST + 1];
  874. uint32_t skills[SKILL_LAST + 1][3];
  875. uint32_t guid;
  876. uint32_t editListId;
  877. uint32_t windowTextId;
  878. uint32_t guildId;
  879. uint32_t rankId;
  880. uint32_t promotionLevel;
  881. uint32_t town;
  882.  
  883. time_t skullEnd;
  884. time_t lastLogin;
  885. time_t lastLogout;
  886. int64_t lastLoad;
  887. int64_t lastPong;
  888. int64_t lastPing;
  889. int64_t nextAction;
  890. uint64_t stamina;
  891. uint64_t experience;
  892. uint64_t manaSpent;
  893. uint64_t lastAttack;
  894. uint64_t lastEffect;
  895.  
  896. double inventoryWeight;
  897. double capacity;
  898. char managerChar[100];
  899.  
  900. std::string managerString, managerString2;
  901. std::string account, password;
  902. std::string name, nameDescription, specialDescription;
  903. std::string guildName, rankName, guildNick;
  904.  
  905. Position loginPosition;
  906. LightInfo itemsLight;
  907.  
  908. Vocation* vocation;
  909. ProtocolGame* client;
  910. SchedulerTask* walkTask;
  911. Party* party;
  912. Group* group;
  913. Item* inventory[11];
  914. Player* tradePartner;
  915. Item* tradeItem;
  916. Item* writeItem;
  917. House* editHouse;
  918. Npc* shopOwner;
  919.  
  920. typedef std::set<uint32_t> AttackedSet;
  921. AttackedSet attackedSet;
  922. ShopInfoList shopOffer;
  923. PartyList invitePartyList;
  924. OutfitMap outfits;
  925. LearnedInstantSpellList learnedInstantSpellList;
  926.  
  927. friend class Game;
  928. friend class LuaScriptInterface;
  929. friend class Npc;
  930. friend class Map;
  931. friend class Actions;
  932. friend class IOLoginData;
  933. friend class ProtocolGame;
  934. };
  935. #endif
Advertisement
Add Comment
Please, Sign In to add comment