Item.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include "Item.h"
  2. #include <Text.h>
  3. Item::Item(int itemTypeId, const char* name)
  4. : ReferenceCounter(),
  5. itemTypeId(itemTypeId),
  6. blockTypeId(0),
  7. hp(1),
  8. maxHp(1),
  9. durability(1),
  10. maxDurability(1),
  11. eatable(0),
  12. placeable(0),
  13. equippable(0),
  14. solid(1),
  15. usable(0),
  16. maxStackSize(50),
  17. name(name)
  18. {}
  19. void Item::setHp(float hp)
  20. {
  21. this->hp = hp;
  22. }
  23. void Item::tick() {}
  24. const ItemType* Item::zItemType() const
  25. {
  26. return StaticRegistry<ItemType>::INSTANCE.zElement(itemTypeId);
  27. }
  28. int Item::getTypeId() const
  29. {
  30. return itemTypeId;
  31. }
  32. const BlockType* Item::zPlacedBlockType() const
  33. {
  34. return StaticRegistry<BlockType>::INSTANCE.zElement(blockTypeId);
  35. }
  36. float Item::getHp() const
  37. {
  38. return hp;
  39. }
  40. float Item::getDurability() const
  41. {
  42. return durability;
  43. }
  44. bool Item::isUsable() const
  45. {
  46. return usable;
  47. }
  48. bool Item::isEatable() const
  49. {
  50. return eatable;
  51. }
  52. bool Item::isPlaceable() const
  53. {
  54. return placeable;
  55. }
  56. bool Item::isEquippable() const
  57. {
  58. return equippable;
  59. }
  60. bool Item::isSolid() const
  61. {
  62. return solid;
  63. }
  64. float Item::getMaxDurability() const
  65. {
  66. return maxDurability;
  67. }
  68. int Item::getMaxStackSize() const
  69. {
  70. return maxStackSize;
  71. }
  72. float Item::getMaxHp() const
  73. {
  74. return maxHp;
  75. }
  76. bool Item::canBeStackedWith(const Item* zItem) const
  77. {
  78. return itemTypeId == zItem->itemTypeId && durability == maxDurability
  79. && zItem->durability == zItem->maxDurability && maxHp == zItem->maxHp
  80. && eatable == zItem->eatable && placeable == zItem->placeable
  81. && equippable == zItem->eatable && solid == zItem->solid
  82. && usable == zItem->usable && maxStackSize == zItem->maxStackSize
  83. && name.istGleich(zItem->name);
  84. }
  85. void Item::onPlaced()
  86. {
  87. hp = 0;
  88. }
  89. Framework::Text Item::getTooltipUIML() const
  90. {
  91. return Framework::Text("<tip><text width=\"auto\" height=\"auto\">") + name
  92. + "</text></tip>";
  93. }
  94. void Item::applyInventoryEffects(Entity* zTarget) {}
  95. void Item::removeInventoryEffects(Entity* zTarget) {}
  96. void Item::applyEquippedEffects(Entity* zTarget) {}
  97. void Item::removeEquippedEffects(Entity* zTarget) {}
  98. void Item::applyFoodEffects(Entity* zTarget) {}