#include "ItemEntity.h" #include "Game.h" #include "EntityChangedUpdate.h" ItemEntity::ItemEntity( Framework::Vec3 location, int dimensionId, int entityId ) : Entity( ItemEntityType::INSTANCE, location, dimensionId, entityId ) { slot = new ItemSlot( __INT32_MAX__, 0, 0, 0, ANY_DIRECTION, 0 ); addSlot( slot ); faceOffset = { 0.f, 0.f, 0.f }; maxHP = 10; currentHP = 10; stamina = 10; maxStamina = 10; hunger = 10; maxHunger = 10; thirst = 10; maxThirst = 10; targetDistanceLimit = 4; } void ItemEntity::tick( const Dimension* zDimension ) { if( slot->zStack() == 0 && !removed ) throw "Illegal State exception"; // 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 ); } void ItemEntity::api( Framework::StreamReader* zRequest, NetworkResponse* zResponse ) { } void ItemEntity::onFall( float collisionSpeed ) { if( collisionSpeed >= 50.f ) this->currentHP = 0; } ItemEntityType::ItemEntityType() : EntityType( ID ) {} Entity* ItemEntityType::createEntity( Framework::Vec3 position, int dimensionId, int entityId ) const { return new ItemEntity( position, dimensionId, entityId ); }