ItemEntity.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "ItemEntity.h"
  2. #include "Game.h"
  3. #include "EntityChangedUpdate.h"
  4. ItemEntity::ItemEntity( Framework::Vec3<float> location, int dimensionId, int entityId )
  5. : Entity( ItemEntityType::INSTANCE, location, dimensionId, entityId )
  6. {
  7. ItemSlot* slot = new ItemSlot( __INT32_MAX__, 0, 0, 0, ANY_DIRECTION, 0 );
  8. addSlot( slot );
  9. faceOffset = { 0.f, 0.f, 0.f };
  10. maxHP = 10;
  11. currentHP = 10;
  12. stamina = 10;
  13. maxStamina = 10;
  14. hunger = 10;
  15. maxHunger = 10;
  16. thirst = 10;
  17. maxThirst = 10;
  18. targetDistanceLimit = 4;
  19. }
  20. void ItemEntity::tick( const Dimension* zDimension )
  21. {
  22. Framework::Vec3<float> pos = location;
  23. // TODO: add speed to next entity with free inventory
  24. Entity::tick( zDimension );
  25. if( pos != location )
  26. {
  27. Game::INSTANCE->requestWorldUpdate( new EntityChangedUpdate( id, (Framework::Vec3<int>)location, currentDimensionId ) );
  28. }
  29. }
  30. void ItemEntity::api( Framework::StreamReader* zRequest, NetworkResponse* zResponse )
  31. {
  32. }
  33. void ItemEntity::onFall( float collisionSpeed )
  34. {
  35. if( collisionSpeed >= 50.f )
  36. this->currentHP = 0;
  37. }
  38. ItemEntityType::ItemEntityType()
  39. : EntityType( ID )
  40. {}
  41. Entity* ItemEntityType::createEntity( Framework::Vec3<float> position, int dimensionId, int entityId ) const
  42. {
  43. return new ItemEntity( position, dimensionId, entityId );
  44. }