StoneTool.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "StoneTool.h"
  2. #include "Block.h"
  3. BrokenStoneToolItemType::BrokenStoneToolItemType()
  4. : ItemType(ID, "BrokenStoneTool", 0, 0, ModelInfo("itemCube", "blocks.ltdb/stone.png", 6)) // TODO: correct model
  5. {}
  6. Item* BrokenStoneToolItemType::createItem() const
  7. {
  8. return createBasicItem("Stone Tool", 100.f, 100.f, 100.f, 100.f, 0, 0, 0, 1, 0, 10);
  9. }
  10. StoneToolItemType::StoneToolItemType()
  11. : ItemType(ID, "StoneTool", new StoneToolLevelUpRule(), BrokenStoneToolItemType::INSTANCE, ModelInfo("items.m3/stoneTool", "blocks.ltdb/stone.png", 6)) // TODO: correct model
  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", 100.f, 100.f, 100.f, 100.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. zUsedItem->setHp(zUsedItem->getHp() - damage / 50);
  69. }
  70. }
  71. void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
  72. {
  73. // TODO
  74. }