Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.93 KB | None | 0 0
  1. /**
  2.  * Tibia GIMUD Server - a free and open-source MMORPG server emulator
  3.  * Copyright (C) 2017  Alejandro Mujica <alejandrodemujica@gmail.com>
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License along
  16.  * with this program; if not, write to the Free Software Foundation, Inc.,
  17.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18.  */
  19.  
  20. #ifndef FS_ITEMS_H_4E2221634ABA45FE85BA50F710669B3C
  21. #define FS_ITEMS_H_4E2221634ABA45FE85BA50F710669B3C
  22.  
  23. #include "const.h"
  24. #include "enums.h"
  25. #include "position.h"
  26. #include "fileloader.h"
  27.  
  28. enum SlotPositionBits : uint32_t {
  29.     SLOTP_WHEREEVER = 0xFFFFFFFF,
  30.     SLOTP_HEAD = 1 << 0,
  31.     SLOTP_NECKLACE = 1 << 1,
  32.     SLOTP_BACKPACK = 1 << 2,
  33.     SLOTP_ARMOR = 1 << 3,
  34.     SLOTP_RIGHT = 1 << 4,
  35.     SLOTP_LEFT = 1 << 5,
  36.     SLOTP_LEGS = 1 << 6,
  37.     SLOTP_FEET = 1 << 7,
  38.     SLOTP_RING = 1 << 8,
  39.     SLOTP_AMMO = 1 << 9,
  40.     SLOTP_DEPOT = 1 << 10,
  41.     SLOTP_TWO_HAND = 1 << 11,
  42.     SLOTP_HAND = (SLOTP_LEFT | SLOTP_RIGHT)
  43. };
  44.  
  45. enum ItemTypes_t {
  46.     ITEM_TYPE_NONE,
  47.     ITEM_TYPE_DEPOT,
  48.     ITEM_TYPE_MAILBOX,
  49.     ITEM_TYPE_CONTAINER,
  50.     ITEM_TYPE_DOOR,
  51.     ITEM_TYPE_MAGICFIELD,
  52.     ITEM_TYPE_TELEPORT,
  53.     ITEM_TYPE_BED,
  54.     ITEM_TYPE_KEY,
  55.     ITEM_TYPE_RUNE,
  56.     ITEM_TYPE_CHEST,
  57.     ITEM_TYPE_QUIVER,
  58.     ITEM_TYPE_LAST
  59. };
  60.  
  61. enum itemgroup_t {
  62.     ITEM_GROUP_NONE,
  63.  
  64.     ITEM_GROUP_GROUND,
  65.     ITEM_GROUP_WEAPON,
  66.     ITEM_GROUP_AMMUNITION,
  67.     ITEM_GROUP_ARMOR,
  68.     ITEM_GROUP_CHARGES,
  69.     ITEM_GROUP_TELEPORT,
  70.     ITEM_GROUP_MAGICFIELD,
  71.     ITEM_GROUP_WRITEABLE,
  72.     ITEM_GROUP_KEY,
  73.     ITEM_GROUP_SPLASH,
  74.     ITEM_GROUP_FLUID,
  75.     ITEM_GROUP_DOOR,
  76.     ITEM_GROUP_DEPRECATED,
  77.     ITEM_GROUP_QUIVER,
  78.     ITEM_GROUP_LAST
  79. };
  80.  
  81. struct Abilities {
  82.     uint32_t healthGain = 0;
  83.     uint32_t healthTicks = 0;
  84.     uint32_t manaGain = 0;
  85.     uint32_t manaTicks = 0;
  86.  
  87.     uint32_t conditionImmunities = 0;
  88.     uint32_t conditionSuppressions = 0;
  89.  
  90.     //stats modifiers
  91.     int32_t stats[STAT_LAST + 1] = { 0 };
  92.     int32_t statsPercent[STAT_LAST + 1] = { 0 };
  93.  
  94.     //extra skill modifiers
  95.     int32_t skills[SKILL_LAST + 1] = { 0 };
  96.  
  97.     int32_t speed = 0;
  98.  
  99.     // field damage abilities modifiers
  100.     int16_t fieldAbsorbPercent[COMBAT_COUNT] = { 0 };
  101.  
  102.     //damage abilities modifiers
  103.     int16_t absorbPercent[COMBAT_COUNT] = { 0 };
  104.  
  105.     bool manaShield = false;
  106.     bool invisible = false;
  107.     bool regeneration = false;
  108. };
  109.  
  110. class ConditionDamage;
  111.  
  112. class ItemType
  113. {
  114.     public:
  115.         ItemType() = default;
  116.  
  117.         //non-copyable
  118.         ItemType(const ItemType& other) = delete;
  119.         ItemType& operator=(const ItemType& other) = delete;
  120.  
  121.         ItemType(ItemType&& other) = default;
  122.         ItemType& operator=(ItemType&& other) = default;
  123.  
  124.         bool isGroundTile() const {
  125.             return group == ITEM_GROUP_GROUND;
  126.         }
  127.         bool isContainer() const {
  128.             return type == ITEM_TYPE_CONTAINER;
  129.         }
  130.         bool isChest() const {
  131.             return type == ITEM_TYPE_CHEST;
  132.         }
  133.         bool isSplash() const {
  134.             return group == ITEM_GROUP_SPLASH;
  135.         }
  136.         bool isFluidContainer() const {
  137.             return group == ITEM_GROUP_FLUID;
  138.         }
  139.         bool isDoor() const {
  140.             return (type == ITEM_TYPE_DOOR);
  141.         }
  142.         bool isMagicField() const {
  143.             return (type == ITEM_TYPE_MAGICFIELD);
  144.         }
  145.         bool isTeleport() const {
  146.             return (type == ITEM_TYPE_TELEPORT);
  147.         }
  148.         bool isKey() const {
  149.             return (type == ITEM_TYPE_KEY);
  150.         }
  151.         bool isDepot() const {
  152.             return (type == ITEM_TYPE_DEPOT);
  153.         }
  154.         bool isMailbox() const {
  155.             return (type == ITEM_TYPE_MAILBOX);
  156.         }
  157.         bool isBed() const {
  158.             return (type == ITEM_TYPE_BED);
  159.         }
  160.         bool isRune() const {
  161.             return type == ITEM_TYPE_RUNE;
  162.         }
  163.         bool hasSubType() const {
  164.             return (isFluidContainer() || isSplash() || stackable || charges != 0);
  165.         }
  166.         bool isQuiver() const {
  167.             return type == ITEM_TYPE_QUIVER;
  168.         }
  169.  
  170.         Abilities& getAbilities() {
  171.             if (!abilities) {
  172.                 abilities.reset(new Abilities());
  173.             }
  174.             return *abilities;
  175.         }
  176.  
  177.         std::string getPluralName() const {
  178.             if (!pluralName.empty()) {
  179.                 return pluralName;
  180.             }
  181.  
  182.             if (showCount == 0) {
  183.                 return name;
  184.             }
  185.  
  186.             std::string str;
  187.             str.reserve(name.length() + 1);
  188.             str.assign(name);
  189.             str += 's';
  190.             return str;
  191.         }
  192.  
  193.         itemgroup_t group = ITEM_GROUP_NONE;
  194.         ItemTypes_t type = ITEM_TYPE_NONE;
  195.         uint16_t id = 0;
  196.         bool stackable = false;
  197.  
  198.         std::string name;
  199.         std::string article;
  200.         std::string pluralName;
  201.         std::string description;
  202.         std::string runeSpellName;
  203.         std::string vocationString;
  204.  
  205.         std::unique_ptr<Abilities> abilities;
  206.         std::unique_ptr<ConditionDamage> conditionDamage;
  207.  
  208.         uint32_t weight = 0;
  209.         uint32_t decayTime = 0;
  210.         uint32_t wieldInfo = 0;
  211.         uint32_t minReqLevel = 0;
  212.         uint32_t minReqMagicLevel = 0;
  213.         uint32_t charges = 0;
  214.         int32_t attackStrength = 0;
  215.         int32_t attackVariation = 0;
  216.         int32_t manaConsumption = 0;
  217.         int32_t vocations = 0;
  218.         int32_t decayTo = -1;
  219.         int32_t attack = 0;
  220.         int32_t defense = 0;
  221.         int32_t extraDefense = 0;
  222.         int32_t armor = 0;
  223.         int32_t rotateTo = 0;
  224.         int32_t runeMagLevel = 0;
  225.         int32_t runeLevel = 0;
  226.         int32_t nutrition = 0;
  227.         int32_t destroyTarget = 0;
  228.  
  229.         CombatType_t combatType = COMBAT_NONE;
  230.         CombatType_t damageType = COMBAT_NONE;
  231.  
  232.         uint16_t transformToOnUse = 0;
  233.         uint16_t transformToFree = 0;
  234.         uint16_t disguiseId = 0;
  235.         uint16_t destroyTo = 0;
  236.         uint16_t maxTextLen = 0;
  237.         uint16_t writeOnceItemId = 0;
  238.         uint16_t transformEquipTo = 0;
  239.         uint16_t transformDeEquipTo = 0;
  240.         uint16_t maxItems = 8;
  241.         uint16_t slotPosition = SLOTP_RIGHT | SLOTP_LEFT | SLOTP_AMMO;
  242.         uint16_t speed = 0;
  243.  
  244.         MagicEffectClasses magicEffect = CONST_ME_NONE;
  245.         Direction bedPartnerDir = DIRECTION_NONE;
  246.         WeaponType_t weaponType = WEAPON_NONE;
  247.         Ammo_t ammoType = AMMO_NONE;
  248.         ShootType_t shootType = CONST_ANI_NONE;
  249.         RaceType_t corpseType = RACE_NONE;
  250.         FluidTypes_t fluidSource = FLUID_NONE;
  251.  
  252.         uint8_t fragility = 0;
  253.         uint8_t alwaysOnTopOrder = 0;
  254.         uint8_t lightLevel = 0;
  255.         uint8_t lightColor = 0;
  256.         uint8_t shootRange = 1;
  257.         uint8_t weaponSpecialEffect = 0;
  258.  
  259.         bool collisionEvent = false;
  260.         bool separationEvent = false;
  261.         bool useEvent = false;
  262.         bool multiUseEvent = false;
  263.         bool distUse = false;
  264.         bool disguise = false;
  265.         bool forceUse = false;
  266.         bool changeUse = false;
  267.         bool destroy = false;
  268.         bool corpse = false;
  269.         bool hasHeight = false;
  270.         bool walkStack = true;
  271.         bool blockSolid = false;
  272.         bool blockPickupable = false;
  273.         bool blockProjectile = false;
  274.         bool blockPathFind = false;
  275.         bool allowPickupable = true;
  276.         bool showDuration = false;
  277.         bool showCharges = false;
  278.         bool showAttributes = false;
  279.         bool replaceable = true;
  280.         bool pickupable = false;
  281.         bool rotatable = false;
  282.         bool useable = false;
  283.         bool moveable = true;
  284.         bool alwaysOnTop = false;
  285.         bool canReadText = false;
  286.         bool canWriteText = false;
  287.         bool isVertical = false;
  288.         bool isHorizontal = false;
  289.         bool isHangable = false;
  290.         bool allowDistRead = false;
  291.         bool lookThrough = false;
  292.         bool stopTime = false;
  293.         bool showCount = true;
  294. };
  295.  
  296. class Items
  297. {
  298.     public:
  299.         using nameMap = std::unordered_multimap<std::string, uint16_t>;
  300.  
  301.         Items();
  302.  
  303.         // non-copyable
  304.         Items(const Items&) = delete;
  305.         Items& operator=(const Items&) = delete;
  306.  
  307.         bool reload();
  308.         void clear();
  309.  
  310.         const ItemType& operator[](size_t id) const {
  311.             return getItemType(id);
  312.         }
  313.         const ItemType& getItemType(size_t id) const;
  314.         ItemType& getItemType(size_t id);
  315.  
  316.         uint16_t getItemIdByName(const std::string& name);
  317.  
  318.         bool loadItems();
  319.  
  320.         inline size_t size() const {
  321.             return items.size();
  322.         }
  323.  
  324.         nameMap nameToItems;
  325.  
  326.     protected:
  327.         std::vector<ItemType> items;
  328. };
  329. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement