StoneTool.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "StoneTool.h"
  2. #include "Block.h"
  3. #include "Player.h"
  4. StoneToolItemType::StoneToolItemType()
  5. : ItemType(ItemTypeEnum::STONE_TOOL,
  6. "StoneTool",
  7. new StoneToolLevelUpRule(),
  8. ItemTypeEnum::STONE_TOOL_BROKEN,
  9. ModelInfo("items.m3/stoneTool",
  10. "blocks.ltdb/stone.png",
  11. 6)) // TODO: correct model
  12. {}
  13. void StoneToolItemType::loadSuperItemSkill(
  14. ItemSkill* zSkill, Framework::StreamReader* zReader) const
  15. {
  16. StoneToolSkill* skill = dynamic_cast<StoneToolSkill*>(zSkill);
  17. if (!skill)
  18. throw "StoneToolItemType::loadSuperItemSkill was called with an "
  19. "invalid skill";
  20. zReader->lese((char*)&skill->level, 4);
  21. zReader->lese((char*)&skill->xp, 4);
  22. zReader->lese((char*)&skill->maxXP, 4);
  23. }
  24. void StoneToolItemType::saveSuperItemSkill(
  25. const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const
  26. {
  27. const StoneToolSkill* skill = dynamic_cast<const StoneToolSkill*>(zSkill);
  28. if (!skill)
  29. throw "StoneToolItemType::saveSuperItemSkill was called with an "
  30. "invalid skill";
  31. zWriter->schreibe((char*)&skill->level, 4);
  32. zWriter->schreibe((char*)&skill->xp, 4);
  33. zWriter->schreibe((char*)&skill->maxXP, 4);
  34. }
  35. Item* StoneToolItemType::createItem() const
  36. {
  37. return createBasicItem(
  38. id, "Stone Tool", 100.f, 100.f, 100.f, 100.f, 0, 0, 0, 1, 1, 1);
  39. }
  40. ItemSkill* StoneToolItemType::createDefaultItemSkill() const
  41. {
  42. return new StoneToolSkill();
  43. }
  44. StoneToolLevelUpRule::StoneToolLevelUpRule()
  45. : ItemSkillLevelUpRule()
  46. {}
  47. void StoneToolLevelUpRule::applyOn(ItemSkill* zSkill)
  48. {
  49. StoneToolSkill* skill = dynamic_cast<StoneToolSkill*>(zSkill);
  50. if (!skill)
  51. throw "StoneToolLevelUpRule::applyOn was called with an invalid skill";
  52. if (skill->xp >= skill->maxXP)
  53. {
  54. skill->level++;
  55. skill->xp = 0;
  56. skill->maxXP = skill->maxXP * 1.5f;
  57. }
  58. }
  59. StoneToolSkill::StoneToolSkill()
  60. : ItemSkill(ItemTypeEnum::STONE_TOOL)
  61. {
  62. level = 1;
  63. xp = 0;
  64. maxXP = 10;
  65. }
  66. void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Block* zTarget)
  67. {
  68. if (zActor->getStamina() > 0.0001f)
  69. {
  70. if (zTarget && zTarget->getHardness() <= 2)
  71. {
  72. float damage
  73. = (1 + ((float)level / 10.f)) / (zTarget->getHardness() + 1);
  74. zTarget->setHP(zTarget->getHP() - damage);
  75. xp += damage / 20;
  76. zActor->setStamina(zActor->getStamina() - 0.0001f);
  77. zUsedItem->setHp(zUsedItem->getHp() - damage / 50);
  78. }
  79. else
  80. {
  81. zActor->setStamina(zActor->getStamina() - 0.0001f);
  82. zUsedItem->setHp(zUsedItem->getHp() - 0.001f);
  83. }
  84. }
  85. }
  86. void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
  87. {
  88. // TODO
  89. }