1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #pragma once
- #include "ItemType.h"
- #include "Reader.h"
- #include "TypeRegistry.h"
- class ItemType;
- class BlockType;
- class StoneToolItemType;
- class Item : public virtual Framework::ReferenceCounter
- {
- protected:
- int itemTypeId;
- int blockTypeId;
- float hp; // an item will be removed once its hp reaches 0
- float maxHp;
- float durability; // an item will break into another item once its
- // durability reaches 0
- float maxDurability;
- bool eatable;
- bool placeable;
- bool equippable;
- bool solid;
- bool usable;
- Framework::Text name;
- std::function<bool(Item*, Entity*)> foodEffect;
- std::function<bool(const Item*, Entity*)> foodEffectDestroysItemTest;
- Item(int itemTypeId, Framework::Text name);
- public:
- void setHp(float hp);
- void setDurability(float durability);
- virtual void tick();
- void setFoodEffect(std::function<bool(Item*, Entity*)> foodEffect,
- std::function<bool(const Item*, Entity*)> destroysItemTest);
- const ItemType* zItemType() const;
- int getTypeId() const;
- virtual const BlockType* zPlacedBlockType() const;
- float getHp() const;
- float getDurability() const;
- bool isUsable() const;
- bool isEatable() const;
- bool isPlaceable() const;
- bool isEquippable() const;
- bool isSolid() const;
- void setMaxDurability(float maxDurability);
- float getMaxDurability() const;
- int getMaxStackSize() const;
- float getMaxHp() const;
- const Framework::Text& getName() const;
- virtual bool canBeStackedWith(const Item* zItem) const;
- virtual bool canBePlacedAt(
- int dimensionId, Framework::Vec3<int> worldPos) const;
- virtual void onPlaced();
- virtual Framework::Text getTooltipUIML() const;
- virtual void applyInventoryEffects(Entity* zTarget);
- virtual void removeInventoryEffects(Entity* zTarget);
- virtual void applyEquippedEffects(Entity* zTarget);
- virtual void removeEquippedEffects(Entity* zTarget);
- virtual bool applyFoodEffects(Entity* zTarget);
- virtual bool canApplyFoodEffectsFully(Entity* zTarget) const;
- friend ItemType;
- };
- class ItemJsonType : public TypeFactory<Item>
- {
- public:
- ItemJsonType();
- Item* createValue(Framework::JSON::JSONObject* zJson) const override;
- void fromJson(
- Item* zResult, Framework::JSON::JSONObject* zJson) const override;
- void toJson(
- Item* zObject, Framework::JSON::JSONObject* zResult) const override;
- JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override;
- };
|