StoneTool.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. zReader->lese((char*)&skill->level, 4);
  18. zReader->lese((char*)&skill->xp, 4);
  19. zReader->lese((char*)&skill->maxXP, 4);
  20. }
  21. void StoneToolItemType::saveSuperItemSkill(
  22. const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const
  23. {
  24. const StoneToolSkill* skill = dynamic_cast<const StoneToolSkill*>(zSkill);
  25. zWriter->schreibe((char*)&skill->level, 4);
  26. zWriter->schreibe((char*)&skill->xp, 4);
  27. zWriter->schreibe((char*)&skill->maxXP, 4);
  28. }
  29. Item* StoneToolItemType::createItem() const
  30. {
  31. return createBasicItem(
  32. id, "Stone Tool", 100.f, 100.f, 100.f, 100.f, 0, 0, 0, 1, 1, 1);
  33. }
  34. ItemSkill* StoneToolItemType::createDefaultItemSkill() const
  35. {
  36. return new StoneToolSkill();
  37. }
  38. StoneToolLevelUpRule::StoneToolLevelUpRule()
  39. : ItemSkillLevelUpRule()
  40. {}
  41. void StoneToolLevelUpRule::applyOn(ItemSkill* zSkill)
  42. {
  43. StoneToolSkill* skill = dynamic_cast<StoneToolSkill*>(zSkill);
  44. if (skill->xp >= skill->maxXP)
  45. {
  46. skill->level++;
  47. skill->xp = 0;
  48. skill->maxXP = skill->maxXP * 1.5f;
  49. }
  50. }
  51. StoneToolSkill::StoneToolSkill()
  52. : ItemSkill(ItemTypeEnum::STONE_TOOL)
  53. {
  54. level = 1;
  55. xp = 0;
  56. maxXP = 10;
  57. }
  58. void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Block* zTarget)
  59. {
  60. if (zActor->getStamina() > 0.0001f)
  61. {
  62. if (zTarget && zTarget->getHardness() <= 2)
  63. {
  64. float damage
  65. = (1 + ((float)level / 10.f)) / (zTarget->getHardness() + 1);
  66. zTarget->setHP(zTarget->getHP() - damage);
  67. xp += damage / 20;
  68. zActor->setStamina(zActor->getStamina() - 0.0001f);
  69. zUsedItem->setHp(zUsedItem->getHp() - damage / 50);
  70. }
  71. else
  72. {
  73. zActor->setStamina(zActor->getStamina() - 0.0001f);
  74. zUsedItem->setHp(zUsedItem->getHp() - 0.001f);
  75. }
  76. }
  77. }
  78. void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
  79. {
  80. // TODO
  81. }