Axe.cpp 2.5 KB

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