| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- #pragma once
- #include <Maybe.h>
- #include <Vec3.h>
- #include <Writer.h>
- #include <Zeit.h>
- #include "Inventory.h"
- #include "ItemSkill.h"
- #include "ModelInfo.h"
- #include "NetworkMessage.h"
- #include "UIObservable.h"
- class EntityType;
- class Dimension;
- class ActionTarget
- {
- private:
- Framework::Vec3<int> blockPos;
- Direction targetBlockSide;
- int entityId;
- public:
- ActionTarget(Framework::Vec3<int> blockPos, Direction blockSide);
- ActionTarget(int entityId);
- bool isBlock(Framework::Vec3<int> blockPos, Direction blockSide) const;
- bool isEntity(int entityId) const;
- bool useItemSkillOnTarget(
- Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem);
- bool interactItemSkillOnTarget(
- Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem);
- bool placeBlock(Entity* zActor, Item* zItem);
- static void toMessage(
- const ActionTarget* zTarget, int dimensionId, NetworkMessage* zMsg);
- static void save(ActionTarget* zTarget, Framework::StreamWriter* zWriter);
- static ActionTarget* load(Framework::StreamReader* zReader);
- };
- class MovementFlags
- {
- public:
- static const int SNEAKING = 0x00001;
- static const int SPRINTING = 0x00002;
- static const int FLYING = 0x00004;
- static const int JUMPING = 0x00008;
- static const int WALK_FORWARD = 0x00010;
- static const int WALK_BACKWARD = 0x00020;
- static const int WALK_LEFT = 0x00040;
- static const int WALK_RIGHT = 0x00080;
- static const int ROTATE_LEFT = 0x00100;
- static const int ROTATE_RIGHT = 0x00200;
- static const int GROUND_CONTACT = 0x01000;
- static const int ROTATE_TO_FACE = 0x02000;
- };
- class Entity : public Inventory
- {
- private:
- UIObservable statusBarObservable;
- float stamina;
- float hunger;
- float currentHP;
- float thirst;
- int chatSecurityLevel;
- Framework::Punkt lastChunkCenter;
- int lastDimensionId;
- Framework::Maybe<Framework::Punkt> lastSavedChunkCenter;
- protected:
- float maxHP;
- float maxStamina;
- float maxHunger;
- float maxThirst;
- float targetDistanceLimit;
- float maxMovementSpeed;
- Framework::Vec3<float> speed;
- Framework::Vec3<float> faceDir;
- Framework::Vec3<float> faceOffset;
- Framework::RCArray<ItemSkill> skills;
- ActionTarget* target;
- int typeId;
- bool removed;
- float gravityMultiplier;
- float jumpSpeed;
- int id;
- double placeBlockCooldown;
- Framework::Critical cs;
- Framework::Vec3<float> boundingBox;
- float rotation;
- int movementFlags;
- bool* collisionMap;
- int collisionMapLength;
- virtual void onDeath(
- Entity* zActor, Item* zUsedItem, ItemSkill* zUsedSkill);
- virtual bool useItem(int typeId, ItemStack* zStack, bool left);
- Entity(int typeId,
- Framework::Vec3<float> location,
- int dimensionId,
- int entityId);
- void calculateTarget(const Item* zItem);
- void notifyStatusBarObservers(NetworkMessage* msg);
- ItemSkill* zSkill(int itemType);
- void calcBlockCollision(int& x, int& y, int& xl, int& yl);
- bool isCollidingWithBlock(const Dimension* zDimension);
- bool isCollidingWithBlock(
- const Dimension* zDimension, int x, int y, int xl, int yl);
- public:
- virtual void prepareTick(const Dimension* zDimension, double seconds);
- virtual void tick(const Dimension* zDimension, double seconds);
- virtual void api(Framework::StreamReader* zRequest,
- NetworkMessage* zResponse,
- Entity* zSource);
- virtual void onTargetChange();
- virtual bool interact(Item* zItem, Entity* zActor);
- virtual void onFall(float collisionSpeed);
- virtual Framework::XML::Element* getTargetUIML() const;
- void setChatSecurityLevel(int level);
- void setPosition(Framework::Vec3<float> pos);
- virtual void takeDamage(
- Entity* zSource, Item* zUsedItem, ItemSkill* zUsedSkill, float damage);
- void setHP(
- Entity* zActor, Item* zUsedItem, ItemSkill* zUsedSkill, float hp);
- void setStamina(float stamina);
- void setHunger(float hunger);
- void setThirst(float thirst);
- void setGravityMultiplier(float multiplier);
- void setJumpSpeed(float speed);
- float getMaxHP() const;
- float getCurrentHP() const;
- float getStamina() const;
- float getMaxStamina() const;
- float getHunger() const;
- float getMaxHunger() const;
- float getThirst() const;
- float getMaxThirst() const;
- Framework::Vec3<float> getSpeed() const;
- Framework::Vec3<float> getFaceDir() const;
- Framework::Vec3<float> getPosition() const;
- float getGravityMultiplier() const;
- float getJumpSpeed() const;
- bool isRemoved() const;
- const EntityType* zType() const;
- const ActionTarget* zTarget() const;
- int getId() const;
- virtual bool hasDefaultModel() const;
- virtual ModelInfo* zSpecialModel() const;
- float getMaxSpeed() const;
- bool isMoving() const;
- int getChatSecurityLevel() const;
- Framework::Maybe<Framework::Punkt> getLastSavedChunkCenter() const;
- void setLastSavedChunkCenter(Framework::Punkt pos);
- void setRemoved();
- double getHitDistance(Framework::Vec3<float> rayOrigin,
- Framework::Vec3<float> rayDirection) const;
- float getRotation() const;
- friend EntityType;
- };
|