StoneTool.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "StoneTool.h"
  2. #include "Block.h"
  3. BrokenStoneToolItemType::BrokenStoneToolItemType()
  4. : ItemType(ID, "BrokenStoneTool", 0, 0)
  5. {}
  6. Item* BrokenStoneToolItemType::createItem() const
  7. {
  8. return createBasicItem("Stone Tool", 0.f, 0.f, 0.f, 0.f, 0, 0, 0, 1, 0, 10);
  9. }
  10. StoneToolItemType::StoneToolItemType()
  11. : ItemType(ID, "StoneTool", new StoneToolLevelUpRule(), BrokenStoneToolItemType::INSTANCE)
  12. {}
  13. void StoneToolItemType::loadSuperItemSkill(ItemSkill* zSkill, Framework::StreamReader* zReader) const
  14. {
  15. StoneToolSkill* skill = dynamic_cast<StoneToolSkill*>(zSkill);
  16. if (!skill)
  17. throw "StoneToolItemType::loadSuperItemSkill was called with an invalid skill";
  18. zReader->lese((char*)&skill->level, 4);
  19. zReader->lese((char*)&skill->xp, 4);
  20. zReader->lese((char*)&skill->maxXP, 4);
  21. }
  22. void StoneToolItemType::saveSuperItemSkill(const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const
  23. {
  24. const StoneToolSkill* skill = dynamic_cast<const StoneToolSkill*>(zSkill);
  25. if (!skill)
  26. throw "StoneToolItemType::saveSuperItemSkill was called with an invalid skill";
  27. zWriter->schreibe((char*)&skill->level, 4);
  28. zWriter->schreibe((char*)&skill->xp, 4);
  29. zWriter->schreibe((char*)&skill->maxXP, 4);
  30. }
  31. Item* StoneToolItemType::createItem() const
  32. {
  33. return createBasicItem("Stone Tool", 0.f, 0.f, 10.f, 10.f, 0, 0, 0, 1, 1, 1);
  34. }
  35. ItemSkill* StoneToolItemType::createDefaultItemSkill() const
  36. {
  37. return new StoneToolSkill();
  38. }
  39. StoneToolLevelUpRule::StoneToolLevelUpRule()
  40. : ItemSkillLevelUpRule()
  41. {}
  42. void StoneToolLevelUpRule::applyOn(ItemSkill* zSkill)
  43. {
  44. StoneToolSkill* skill = dynamic_cast<StoneToolSkill*>(zSkill);
  45. if (!skill)
  46. throw "StoneToolLevelUpRule::applyOn was called with an invalid skill";
  47. if (skill->xp >= skill->maxXP)
  48. {
  49. skill->level++;
  50. skill->xp = 0;
  51. skill->maxXP = skill->maxXP * 1.5f;
  52. }
  53. }
  54. StoneToolSkill::StoneToolSkill()
  55. : ItemSkill(StoneToolItemType::INSTANCE)
  56. {
  57. level = 1;
  58. xp = 0;
  59. maxXP = 10;
  60. }
  61. void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Block* zTarget)
  62. {
  63. if (zTarget && zTarget->getHardness() <= 2)
  64. {
  65. float damage = (1 + ((float)level / 10.f)) / (zTarget->getHardness() + 1);
  66. zTarget->setHP(zTarget->getHP() - damage);
  67. xp += damage / 20;
  68. }
  69. }
  70. void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
  71. {
  72. // TODO
  73. }