|
@@ -6,7 +6,7 @@
|
|
|
ItemEntity::ItemEntity( Framework::Vec3<float> location, int dimensionId, int entityId )
|
|
|
: Entity( ItemEntityType::INSTANCE, location, dimensionId, entityId )
|
|
|
{
|
|
|
- ItemSlot* slot = new ItemSlot( __INT32_MAX__, 0, 0, 0, ANY_DIRECTION, 0 );
|
|
|
+ slot = new ItemSlot( __INT32_MAX__, 0, 0, 0, ANY_DIRECTION, 0 );
|
|
|
addSlot( slot );
|
|
|
faceOffset = { 0.f, 0.f, 0.f };
|
|
|
maxHP = 10;
|
|
@@ -24,6 +24,36 @@ void ItemEntity::tick( const Dimension* zDimension )
|
|
|
{
|
|
|
Framework::Vec3<float> pos = location;
|
|
|
// TODO: add speed to next entity with free inventory
|
|
|
+ Entity* zOther = Game::INSTANCE->zNearestEntity( currentDimensionId, location, [this]( Entity* zOther ) {
|
|
|
+ return zOther != this && zOther->numberOfAddableItems( slot->zStack(), NO_DIRECTION );
|
|
|
+ } );
|
|
|
+ bool found = 1;
|
|
|
+ if( zOther )
|
|
|
+ {
|
|
|
+ float d = location.abstand( zOther->getPosition() );
|
|
|
+ if( d < 0.5f )
|
|
|
+ {
|
|
|
+ // add items of this entity to the other entity
|
|
|
+ zOther->interactWith( this, NO_DIRECTION ).pullItems( slot->getNumberOfItems(), 0 );
|
|
|
+ if( slot->getNumberOfItems() == 0 )
|
|
|
+ onDeath();
|
|
|
+ }
|
|
|
+ else if( d < 3.f )
|
|
|
+ {
|
|
|
+ // accelerate towards of the other entity
|
|
|
+ speed += (zOther->getPosition() - location).normalize() * (20 / (d + 0.5f)) / 30.f;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ found = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ found = 0;
|
|
|
+ if( !found )
|
|
|
+ {
|
|
|
+ speed -= speed / 30.f;
|
|
|
+ if( speed.getLength() < 0.2f )
|
|
|
+ speed = { 0.f, 0.f, 0.f };
|
|
|
+ }
|
|
|
Entity::tick( zDimension );
|
|
|
if( pos != location )
|
|
|
{
|