BasicTool.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "BasicTool.h"
  2. BasicToolItem::BasicToolItem(int itemTypeId, const char *name)
  3. : Item(itemTypeId, name)
  4. {
  5. hp = 10.f;
  6. maxHp = 10.f;
  7. durability = 10.f;
  8. maxDurability = 10.f;
  9. usable = 1;
  10. }
  11. void BasicToolItem::updateBasedOnUsedMaterial() {
  12. float basicDurability = 10.f;
  13. float headDurabilityModifier = 1.f;
  14. float rodDurabilityModifier = 1.f;
  15. // TODO: adjust durability modifier based on material
  16. float currentDurability = durability / maxDurability;
  17. maxDurability
  18. = basicDurability * headDurabilityModifier * rodDurabilityModifier;
  19. durability = currentDurability * maxDurability;
  20. }
  21. void BasicToolItem::setHeadMaterial(int headMaterial)
  22. {
  23. this->headMaterial = headMaterial;
  24. }
  25. void BasicToolItem::setRodMaterial(int rodMaterial)
  26. {
  27. this->rodMaterial = rodMaterial;
  28. }
  29. BasicToolItemType::BasicToolItemType(int id,
  30. const char* name,
  31. ItemSkillLevelUpRule* levelUpRule,
  32. int brokenTypeId,
  33. ModelInfo model)
  34. : ItemType(id, name, levelUpRule, brokenTypeId, model)
  35. {}
  36. void BasicToolItemType::loadSuperItem(
  37. Item* zItem, Framework::StreamReader* zReader) const
  38. {
  39. ItemType::loadSuperItem(zItem, zReader);
  40. BasicToolItem* item = dynamic_cast<BasicToolItem*>(zItem);
  41. zReader->lese((char*)&item->headMaterial, 4);
  42. zReader->lese((char*)&item->rodMaterial, 4);
  43. }
  44. void BasicToolItemType::saveSuperItem(
  45. const Item* zItem, Framework::StreamWriter* zWriter) const
  46. {
  47. ItemType::saveSuperItem(zItem, zWriter);
  48. const BasicToolItem* item = dynamic_cast<const BasicToolItem*>(zItem);
  49. zWriter->schreibe((char*)&item->headMaterial, 4);
  50. zWriter->schreibe((char*)&item->rodMaterial, 4);
  51. }