Shovel.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "Shovel.h"
  2. #include "Game.h"
  3. ShovelToolItemType::ShovelToolItemType() // TODO: add broken Shovel
  4. : BasicToolItemType(ItemTypeEnum::SHOVEL,
  5. "Shovel",
  6. new ShovelToolLevelUpRule(),
  7. 0,
  8. ModelInfo("tools.m3/shovel", "tools.ltdb/stonehoe.png", 1)) // use same texture as hoe
  9. {}
  10. Item* ShovelToolItemType::createItem() const
  11. {
  12. return new BasicToolItem(ItemTypeEnum::SHOVEL, "Shovel");
  13. }
  14. ItemSkill* ShovelToolItemType::createDefaultItemSkill() const
  15. {
  16. return new ShovelToolSkill();
  17. }
  18. void ShovelToolItemType::loadSuperItemSkill(
  19. ItemSkill* zSkill, Framework::StreamReader* zReader) const
  20. {
  21. ShovelToolSkill* skill = dynamic_cast<ShovelToolSkill*>(zSkill);
  22. zReader->lese((char*)&skill->level, 4);
  23. zReader->lese((char*)&skill->xp, 4);
  24. zReader->lese((char*)&skill->maxXP, 4);
  25. }
  26. void ShovelToolItemType::saveSuperItemSkill(
  27. const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const
  28. {
  29. const ShovelToolSkill* skill = dynamic_cast<const ShovelToolSkill*>(zSkill);
  30. zWriter->schreibe((char*)&skill->level, 4);
  31. zWriter->schreibe((char*)&skill->xp, 4);
  32. zWriter->schreibe((char*)&skill->maxXP, 4);
  33. }
  34. ShovelToolLevelUpRule::ShovelToolLevelUpRule()
  35. : ItemSkillLevelUpRule()
  36. {}
  37. void ShovelToolLevelUpRule::applyOn(ItemSkill* zSkill)
  38. {
  39. ShovelToolSkill* skill = dynamic_cast<ShovelToolSkill*>(zSkill);
  40. if (skill->xp >= skill->maxXP)
  41. {
  42. skill->level++;
  43. skill->xp = 0;
  44. skill->maxXP = skill->maxXP * 2;
  45. }
  46. }
  47. ShovelToolSkill::ShovelToolSkill()
  48. : ItemSkill(ItemTypeEnum::SHOVEL),
  49. level(1),
  50. xp(0.f),
  51. maxXP(10.f)
  52. {}
  53. void ShovelToolSkill::use(Entity* zActor, Item* zUsedItem, Block* zTarget)
  54. {
  55. if (zActor->getStamina() > 0.0001f)
  56. {
  57. if (zTarget->zBlockType()->getId() == BlockTypeEnum::DIRT
  58. || zTarget->zBlockType()->getId() == BlockTypeEnum::GRAVEL
  59. || zTarget->zBlockType()->getId() == BlockTypeEnum::SAND)
  60. {
  61. float damage
  62. = (2 + ((float)level / 3.f)) / (zTarget->getHardness() + 1);
  63. zTarget->setHP(zTarget->getHP() - damage);
  64. xp += damage / 20;
  65. zActor->setStamina(zActor->getStamina() - 0.0001f);
  66. zUsedItem->setHp(zUsedItem->getHp() - damage / 50);
  67. }
  68. else
  69. {
  70. zActor->setStamina(zActor->getStamina() - 0.0001f);
  71. zUsedItem->setHp(zUsedItem->getHp() - 0.001f);
  72. }
  73. }
  74. }
  75. void ShovelToolSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
  76. {
  77. // an Shovel can not be used on an entity
  78. }