PlayerHand.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "PlayerHand.h"
  2. #include "Block.h"
  3. #include "Entity.h"
  4. PlayerHandItemType::PlayerHandItemType()
  5. : ItemType()
  6. {
  7. setName("PlayerHand");
  8. setMaxStackSize(0);
  9. }
  10. Item* PlayerHandItemType::createItem() const
  11. {
  12. return 0; // there is no player hand item
  13. }
  14. ItemSkill* PlayerHandItemType::createDefaultItemSkill() const
  15. {
  16. return new PlayerHandSkill();
  17. }
  18. void PlayerHandItemType::levelUpItemSkill(ItemSkill* zSkill) const {}
  19. PlayerHandSkill::PlayerHandSkill()
  20. : ItemSkill()
  21. {
  22. setXp(0.f);
  23. setMaxXp(1.f);
  24. setLevel(1.f);
  25. }
  26. bool PlayerHandSkill::use(Entity* zActor, Item* zUsedItem, Block* zTarget)
  27. {
  28. if (zActor->getStamina() > 0.001f)
  29. {
  30. if (zTarget && zTarget->getHardness() <= 1)
  31. {
  32. zActor->setStamina(zActor->getStamina() - 0.001f);
  33. zTarget->setHP(zTarget->getHP() - 1 / (zTarget->getHardness() + 1));
  34. }
  35. else
  36. {
  37. zActor->setStamina(zActor->getStamina() - 0.001f);
  38. zActor->setHP(zActor->getCurrentHP() - 0.01f);
  39. }
  40. }
  41. return false; // item was not changed
  42. }
  43. bool PlayerHandSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
  44. {
  45. // TODO: make damage on the entity
  46. return false; // item was not changed
  47. }