1 /* 2 * The ManaPlus Client 3 * Copyright (C) 2004-2009 The Mana World Development Team 4 * Copyright (C) 2009-2010 The Mana Developers 5 * Copyright (C) 2011-2019 The ManaPlus Developers 6 * Copyright (C) 2019-2021 Andrei Karas 7 * 8 * This file is part of The ManaPlus Client. 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program. If not, see <http://www.gnu.org/licenses/>. 22 */ 23 24 #ifndef RESOURCES_ITEMINFO_H 25 #define RESOURCES_ITEMINFO_H 26 27 #include "enums/being/gender.h" 28 29 #include "enums/resources/item/itemdbtype.h" 30 31 #include "enums/simpletypes/beingtypeid.h" 32 33 #include "resources/cursors.h" 34 #include "resources/itemcolordata.h" 35 #include "resources/missileinfo.h" 36 #include "resources/soundinfo.h" 37 38 #include "resources/sprite/spritedisplay.h" 39 40 #include "utils/cast.h" 41 #include "utils/intmap.h" 42 43 struct ItemMenuItem; 44 45 // sprite, <itemfrom, itemto> 46 typedef std::map<int, IntMap> SpriteToItemMap; 47 typedef SpriteToItemMap::const_iterator SpriteToItemMapCIter; 48 49 /** 50 * Defines a class for storing item infos. This includes information used when 51 * the item is equipped. 52 */ 53 class ItemInfo final 54 { 55 public: 56 /** 57 * Constructor. 58 */ 59 ItemInfo(); 60 61 A_DELETE_COPY(ItemInfo) 62 63 ~ItemInfo(); 64 setId(const int id)65 void setId(const int id) noexcept2 66 { mId = id; } 67 getId()68 int getId() const noexcept2 A_WARN_UNUSED 69 { return mId; } 70 setName(const std::string & name)71 void setName(const std::string &name) noexcept2 72 { mName = name; } 73 getName()74 const std::string &getName() const noexcept2 A_WARN_UNUSED 75 { return mName; } 76 77 const std::string getName(const ItemColor color) 78 const A_WARN_UNUSED; 79 setNameEn(const std::string & name)80 void setNameEn(const std::string &name) noexcept2 81 { mNameEn = name; } 82 getNameEn()83 const std::string &getNameEn() const noexcept2 A_WARN_UNUSED 84 { return mNameEn; } 85 86 const std::string getNameEn(const ItemColor color) 87 const A_WARN_UNUSED; 88 89 const std::string getLink() const A_WARN_UNUSED; 90 setDisplay(const SpriteDisplay & display)91 void setDisplay(const SpriteDisplay &display) noexcept2 92 { mDisplay = display; } 93 getDisplay()94 const SpriteDisplay &getDisplay() const noexcept2 A_WARN_UNUSED 95 { return mDisplay; } 96 setDescription(const std::string & description)97 void setDescription(const std::string &description) noexcept2 98 { mDescription = description; } 99 getDescription()100 const std::string &getDescription() const noexcept2 A_WARN_UNUSED 101 { return mDescription; } 102 103 const std::string getDescription(const ItemColor color) 104 const A_WARN_UNUSED; 105 setEffect(const std::string & effect)106 void setEffect(const std::string &effect) noexcept2 107 { mEffect = effect; } 108 getEffect()109 const std::string &getEffect() const noexcept2 A_WARN_UNUSED 110 { return mEffect; } 111 setType(const ItemDbTypeT type)112 void setType(const ItemDbTypeT type) noexcept2 113 { mType = type; } 114 setUseButton(const std::string & str)115 void setUseButton(const std::string &str) noexcept2 116 { mUseButton = str; } 117 getUseButton()118 const std::string &getUseButton() const noexcept2 A_WARN_UNUSED 119 { return mUseButton; } 120 setUseButton2(const std::string & str)121 void setUseButton2(const std::string &str) noexcept2 122 { mUseButton2 = str; } 123 getUseButton2()124 const std::string &getUseButton2() const noexcept2 A_WARN_UNUSED 125 { return mUseButton2; } 126 getType()127 ItemDbTypeT getType() const noexcept2 A_WARN_UNUSED 128 { return mType; } 129 setWeight(const int weight)130 void setWeight(const int weight) noexcept2 131 { mWeight = weight; } 132 getWeight()133 int getWeight() const noexcept2 A_WARN_UNUSED 134 { return mWeight; } 135 getView()136 int getView() const noexcept2 A_WARN_UNUSED 137 { return mView; } 138 setView(const int view)139 void setView(const int view) noexcept2 140 { mView = view; } 141 142 void setSprite(const std::string &animationFile, 143 const GenderT gender, const int race); 144 145 const std::string &getSprite(const GenderT gender, 146 const BeingTypeId race) 147 const A_WARN_UNUSED; 148 149 void setAttackAction(const std::string &attackAction); 150 151 void setSkyAttackAction(const std::string &attackAction); 152 153 void setWaterAttackAction(const std::string &attackAction); 154 155 void setRideAttackAction(const std::string &attackAction); 156 157 // Handlers for seting and getting the string 158 // used for particles when attacking setMissileParticleFile(const std::string & s)159 void setMissileParticleFile(const std::string &s) noexcept2 160 { mMissile.particle = s; } 161 getMissile()162 MissileInfo &getMissile() noexcept2 A_WARN_UNUSED 163 { return mMissile; } 164 getMissileConst()165 const MissileInfo &getMissileConst() const noexcept2 A_WARN_UNUSED 166 { return mMissile; } 167 setHitEffectId(const int s)168 void setHitEffectId(const int s) noexcept2 169 { mHitEffectId = s; } 170 getHitEffectId()171 int getHitEffectId() const noexcept2 A_WARN_UNUSED 172 { return mHitEffectId; } 173 setCriticalHitEffectId(const int s)174 void setCriticalHitEffectId(const int s) noexcept2 175 { mCriticalHitEffectId = s; } 176 getCriticalHitEffectId()177 int getCriticalHitEffectId() const noexcept2 A_WARN_UNUSED 178 { return mCriticalHitEffectId; } 179 setMissEffectId(const int s)180 void setMissEffectId(const int s) noexcept2 181 { mMissEffectId = s; } 182 getMissEffectId()183 int getMissEffectId() const noexcept2 A_WARN_UNUSED 184 { return mMissEffectId; } 185 getAttackAction()186 const std::string &getAttackAction() const noexcept2 A_WARN_UNUSED 187 { return mAttackAction; } 188 getSkyAttackAction()189 const std::string &getSkyAttackAction() const noexcept2 A_WARN_UNUSED 190 { return mSkyAttackAction; } 191 getWaterAttackAction()192 const std::string &getWaterAttackAction() const noexcept2 A_WARN_UNUSED 193 { return mWaterAttackAction; } 194 getRideAttackAction()195 const std::string &getRideAttackAction() const noexcept2 A_WARN_UNUSED 196 { return mRideAttackAction; } 197 getAttackRange()198 int getAttackRange() const noexcept2 A_WARN_UNUSED 199 { return mAttackRange; } 200 setAttackRange(const int r)201 void setAttackRange(const int r) noexcept2 202 { mAttackRange = r; } 203 204 void addSound(const ItemSoundEvent::Type event, 205 const std::string &filename, 206 const int delay); 207 208 const SoundInfo &getSound(const ItemSoundEvent::Type event) 209 const A_WARN_UNUSED; 210 211 int getDrawBefore(const int direction) const A_WARN_UNUSED; 212 213 void setDrawBefore(const int direction, const int n); 214 215 int getDrawAfter(const int direction) const A_WARN_UNUSED; 216 217 void setDrawAfter(const int direction, const int n); 218 219 int getDrawPriority(const int direction) const A_WARN_UNUSED; 220 221 void setDrawPriority(const int direction, const int n); 222 getTags()223 const IntMap &getTags() const noexcept2 A_WARN_UNUSED 224 { return mTags; } 225 addTag(const int tag)226 void addTag(const int tag) 227 { mTags[tag] = 1; } 228 setRemoveSprites()229 void setRemoveSprites() noexcept2 230 { mIsRemoveSprites = true; } 231 isRemoveSprites()232 bool isRemoveSprites() const noexcept2 A_WARN_UNUSED 233 { return mIsRemoveSprites; } 234 setMaxFloorOffsetX(const int i)235 void setMaxFloorOffsetX(const int i) noexcept2 236 { maxFloorOffsetX = i; } 237 setMaxFloorOffsetY(const int i)238 void setMaxFloorOffsetY(const int i) noexcept2 239 { maxFloorOffsetY = i; } 240 getMaxFloorOffsetX()241 int getMaxFloorOffsetX() const noexcept2 A_WARN_UNUSED 242 { return maxFloorOffsetX; } 243 getMaxFloorOffsetY()244 int getMaxFloorOffsetY() const noexcept2 A_WARN_UNUSED 245 { return maxFloorOffsetY; } 246 247 bool isRemoveItemId(int id) const A_WARN_UNUSED; 248 setCardColor(const ItemColor color)249 void setCardColor(const ItemColor color) noexcept2 250 { mCardColor = color; } 251 getCardColor()252 ItemColor getCardColor() const noexcept2 253 { return mCardColor; } 254 255 int getReplaceToSpriteId(int id) const A_WARN_UNUSED; 256 257 IntMap *addReplaceSprite(const int sprite, 258 const int direction); 259 260 const SpriteToItemMap *getSpriteToItemReplaceMap(const int directions) 261 const A_WARN_UNUSED; 262 263 std::string getDyeColorsString(const ItemColor color) 264 const A_WARN_UNUSED; 265 266 std::string getDyeIconColorsString(const ItemColor color) 267 const A_WARN_UNUSED; 268 269 void setColorsList(const std::string &name); 270 271 void setIconColorsList(const std::string &name); 272 isHaveColors()273 bool isHaveColors() const noexcept2 A_WARN_UNUSED 274 { return !mColorsListName.empty(); } 275 isHaveIconColors()276 bool isHaveIconColors() const noexcept2 A_WARN_UNUSED 277 { return !mIconColorsListName.empty(); } 278 getColorsListName()279 std::string getColorsListName() const noexcept2 A_WARN_UNUSED 280 { return mColorsListName; } 281 getIconColorsListName()282 std::string getIconColorsListName() const noexcept2 A_WARN_UNUSED 283 { return mIconColorsListName; } 284 285 const std::string replaceColors(std::string str, 286 const ItemColor color) 287 const A_WARN_UNUSED; 288 setPickupCursor(const std::string & cursor)289 void setPickupCursor(const std::string &cursor) 290 { return setPickupCursor(Cursors::stringToCursor(cursor)); } 291 setPickupCursor(const CursorT & cursor)292 void setPickupCursor(const CursorT &cursor) noexcept2 293 { mPickupCursor = cursor; } 294 getPickupCursor()295 CursorT getPickupCursor() const noexcept2 A_WARN_UNUSED 296 { return mPickupCursor; } 297 setProtected(const bool b)298 void setProtected(const bool b) noexcept2 299 { mProtected = b; } 300 isProtected()301 bool isProtected() const noexcept2 A_WARN_UNUSED 302 { return mProtected; } 303 getColorsSize()304 int getColorsSize() const noexcept2 A_WARN_UNUSED 305 { return mColorsList != nullptr ? CAST_S32(mColorsList->size()) : 0; } 306 getIconColorsSize()307 int getIconColorsSize() const noexcept2 A_WARN_UNUSED 308 { 309 return mIconColorsList != nullptr ? 310 CAST_S32(mIconColorsList->size()) : 0; 311 } 312 313 std::string getColorName(const ItemColor idx) const; 314 std::string getColor(const ItemColor idx) const; 315 316 std::string getIconColorName(const ItemColor idx) const; 317 std::string getIconColor(const ItemColor idx) const; 318 getInventoryMenu()319 STD_VECTOR<ItemMenuItem> &getInventoryMenu() 320 { return mInventoryMenu; } getStorageMenu()321 STD_VECTOR<ItemMenuItem> &getStorageMenu() 322 { return mStorageMenu; } getCartMenu()323 STD_VECTOR<ItemMenuItem> &getCartMenu() 324 { return mCartMenu; } 325 getInventoryMenuConst()326 const STD_VECTOR<ItemMenuItem> &getInventoryMenuConst() const A_CONST 327 { return mInventoryMenu; } getStorageMenuConst()328 const STD_VECTOR<ItemMenuItem> &getStorageMenuConst() const A_CONST 329 { return mStorageMenu; } getCartMenuConst()330 const STD_VECTOR<ItemMenuItem> &getCartMenuConst() const A_CONST 331 { return mCartMenu; } 332 333 int mDrawBefore[10]; 334 int mDrawAfter[10]; 335 int mDrawPriority[10]; 336 337 private: 338 static void setSpriteOrder(int *const ptr, 339 const int direction, 340 const int n, 341 const int def) A_NONNULL(1); 342 343 SpriteDisplay mDisplay; /**< Display info (like icon) */ 344 MissileInfo mMissile; 345 std::string mName; 346 std::string mNameEn; 347 std::string mDescription; /**< Short description. */ 348 std::string mEffect; /**< Description of effects. */ 349 std::string mUseButton; 350 std::string mUseButton2; 351 ItemDbTypeT mType; /**< Item type. */ 352 int mWeight; /**< Weight in grams. */ 353 int mView; /**< Item ID of how this item looks. */ 354 int mId; /**< Item ID */ 355 bool mIsRemoveSprites; 356 // sprite, <itemfrom, itemto> [direction] 357 SpriteToItemMap *mSpriteToItemReplaceMap[10]; 358 359 STD_VECTOR<SpriteToItemMap*> mSpriteToItemReplaceList; 360 361 // Equipment related members. 362 /** Attack type, in case of weapon. 363 * See SpriteAction in spritedef.h for more info. 364 * Attack action sub-types (bow, sword, ...) are defined in items.xml. 365 */ 366 std::string mAttackAction; 367 std::string mSkyAttackAction; 368 std::string mWaterAttackAction; 369 std::string mRideAttackAction; 370 int mAttackRange; /**< Attack range, will be zero if non weapon. */ 371 372 // Particle to be shown when weapon attacks 373 std::string mMissileParticle; 374 375 /** Maps gender to sprite filenames. */ 376 std::map <int, std::string> mAnimationFiles; 377 378 /** Stores the names of sounds to be played at certain event. */ 379 std::map <ItemSoundEvent::Type, SoundInfoVect> mSounds; 380 std::map <int, int> mTags; 381 const std::map <ItemColor, ItemColorData> *mColorsList; 382 const std::map <ItemColor, ItemColorData> *mIconColorsList; 383 STD_VECTOR<ItemMenuItem> mInventoryMenu; 384 STD_VECTOR<ItemMenuItem> mStorageMenu; 385 STD_VECTOR<ItemMenuItem> mCartMenu; 386 std::string mColorsListName; 387 std::string mIconColorsListName; 388 ItemColor mCardColor; 389 int mHitEffectId; 390 int mCriticalHitEffectId; 391 int mMissEffectId; 392 int maxFloorOffsetX; 393 int maxFloorOffsetY; 394 CursorT mPickupCursor; 395 bool mProtected; 396 }; 397 398 #endif // RESOURCES_ITEMINFO_H 399