StoneTool.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "StoneTool.h"
  2. #include "Block.h"
  3. StoneToolItemType::StoneToolItemType()
  4. : ItemType(ItemTypeEnum::STONE_TOOL,
  5. "StoneTool",
  6. new StoneToolLevelUpRule(),
  7. ItemTypeEnum::STONE_TOOL_BROKEN,
  8. ModelInfo("items.m3/stoneTool",
  9. "blocks.ltdb/stone.png",
  10. 6)) // TODO: correct model
  11. {}
  12. void StoneToolItemType::loadSuperItemSkill(
  13. 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 "
  18. "invalid skill";
  19. zReader->lese((char*)&skill->level, 4);
  20. zReader->lese((char*)&skill->xp, 4);
  21. zReader->lese((char*)&skill->maxXP, 4);
  22. }
  23. void StoneToolItemType::saveSuperItemSkill(
  24. const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const
  25. {
  26. const StoneToolSkill* skill = dynamic_cast<const StoneToolSkill*>(zSkill);
  27. if (!skill)
  28. throw "StoneToolItemType::saveSuperItemSkill was called with an "
  29. "invalid skill";
  30. zWriter->schreibe((char*)&skill->level, 4);
  31. zWriter->schreibe((char*)&skill->xp, 4);
  32. zWriter->schreibe((char*)&skill->maxXP, 4);
  33. }
  34. Item* StoneToolItemType::createItem() const
  35. {
  36. return createBasicItem(
  37. id, "Stone Tool", 100.f, 100.f, 100.f, 100.f, 0, 0, 0, 1, 1, 1);
  38. }
  39. ItemSkill* StoneToolItemType::createDefaultItemSkill() const
  40. {
  41. return new StoneToolSkill();
  42. }
  43. StoneToolLevelUpRule::StoneToolLevelUpRule()
  44. : ItemSkillLevelUpRule()
  45. {}
  46. void StoneToolLevelUpRule::applyOn(ItemSkill* zSkill)
  47. {
  48. StoneToolSkill* skill = dynamic_cast<StoneToolSkill*>(zSkill);
  49. if (!skill)
  50. throw "StoneToolLevelUpRule::applyOn was called with an invalid skill";
  51. if (skill->xp >= skill->maxXP)
  52. {
  53. skill->level++;
  54. skill->xp = 0;
  55. skill->maxXP = skill->maxXP * 1.5f;
  56. }
  57. }
  58. StoneToolSkill::StoneToolSkill()
  59. : ItemSkill(ItemTypeEnum::STONE_TOOL)
  60. {
  61. level = 1;
  62. xp = 0;
  63. maxXP = 10;
  64. }
  65. void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Block* zTarget)
  66. {
  67. if (zTarget && zTarget->getHardness() <= 2)
  68. {
  69. float damage
  70. = (1 + ((float)level / 10.f)) / (zTarget->getHardness() + 1);
  71. zTarget->setHP(zTarget->getHP() - damage);
  72. xp += damage / 20;
  73. zUsedItem->setHp(zUsedItem->getHp() - damage / 50);
  74. }
  75. }
  76. void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
  77. {
  78. // TODO
  79. }