diff options
author | lapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-07-17 14:02:03 +0200 |
---|---|---|
committer | lapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-07-17 14:02:03 +0200 |
commit | f473f13585e1bc901bfeb05cd5a9bb35489595da (patch) | |
tree | 48d9f165c1c154ae5baefe9712b990f837edfd37 /source/items | |
parent | Fixed compilation on OS X and maybe *nix as well (diff) | |
download | cuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.tar cuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.tar.gz cuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.tar.bz2 cuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.tar.lz cuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.tar.xz cuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.tar.zst cuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.zip |
Diffstat (limited to 'source/items')
-rw-r--r-- | source/items/Item.cpp | 55 | ||||
-rw-r--r-- | source/items/Item.h | 19 | ||||
-rw-r--r-- | source/items/ItemFood.h | 55 |
3 files changed, 117 insertions, 12 deletions
diff --git a/source/items/Item.cpp b/source/items/Item.cpp index 3dd0a4218..ce72cf8b3 100644 --- a/source/items/Item.cpp +++ b/source/items/Item.cpp @@ -23,6 +23,7 @@ #include "ItemShovel.h"
#include "ItemSword.h"
#include "ItemDoor.h"
+#include "ItemFood.h"
#include "../blocks/Block.h"
@@ -109,6 +110,23 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemID) case E_ITEM_WOODEN_DOOR:
return new cItemDoorHandler(a_ItemID);
+ //FOOD:
+ case E_ITEM_BREAD:
+ case E_ITEM_COOKIE:
+ case E_ITEM_MELON_SLICE:
+ case E_ITEM_RAW_CHICKEN:
+ case E_ITEM_COOKED_CHICKEN:
+ case E_ITEM_RAW_BEEF:
+ case E_ITEM_RAW_MEAT:
+ case E_ITEM_STEAK:
+ case E_ITEM_COOKED_MEAT:
+ case E_ITEM_RAW_FISH:
+ case E_ITEM_COOKED_FISH:
+ case E_ITEM_RED_APPLE:
+ case E_ITEM_GOLDEN_APPLE:
+ case E_ITEM_ROTTEN_FLESH:
+ case E_ITEM_SPIDER_EYE:
+ return new cItemFoodHandler(a_ItemID);
default:
return new cItemHandler(a_ItemID);
break;
@@ -159,16 +177,6 @@ void cItemHandler::OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item }
-int cItemHandler::GetMaxStackSize()
-{
- return 64;
-}
-
-int cItemHandler::GetMaxDamage()
-{
- return 0;
-}
-
bool cItemHandler::IsTool()
{
return
@@ -230,4 +238,31 @@ void cItemHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, Handler->PlaceBlock(a_World, a_Player, GetBlockMeta(a_Item->m_ItemHealth), a_X, a_Y, a_Z, a_Dir);
if(a_Player->GetGameMode() == eGameMode_Survival)
a_Player->GetInventory().RemoveItem(cItem(a_Item->m_ItemID, 1));
+}
+
+bool cItemHandler::EatItem(cPlayer *a_Player, cItem *a_Item)
+{
+ FoodInfo Info = GetFoodInfo();
+
+ if(Info.FoodLevel > 0 || Info.Saturation > 0.f)
+ {
+ bool Success = a_Player->Feed(Info.FoodLevel, Info.Saturation);
+ if(Success && Info.PoisionChance > 0)
+ {
+ MTRand r1;
+ if((r1.randInt(100) - Info.PoisionChance) <= 0)
+ { //Unlucky guy :D
+ //TODO: Make player ill
+ }
+ }
+
+ return Success;
+ }
+
+ return false;
+}
+
+cItemHandler::FoodInfo cItemHandler::GetFoodInfo()
+{
+ return FoodInfo(0, 0.f);
}
\ No newline at end of file diff --git a/source/items/Item.h b/source/items/Item.h index 96f957fcf..0a38ce3c0 100644 --- a/source/items/Item.h +++ b/source/items/Item.h @@ -13,8 +13,23 @@ public: virtual bool OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir);
virtual void OnBlockDestroyed(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z);
virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item);
- virtual int GetMaxStackSize();
- virtual int GetMaxDamage();
+
+ struct FoodInfo
+ {
+ FoodInfo(short a_FoodLevel, float a_Saturation, char a_PoisionChance = 0)
+ {
+ FoodLevel = a_FoodLevel;
+ Saturation = a_Saturation;
+ PoisionChance = a_PoisionChance;
+ }
+ short FoodLevel;
+ float Saturation;
+ char PoisionChance; //0 - 100
+ };
+
+ virtual FoodInfo GetFoodInfo();
+
+ virtual bool EatItem(cPlayer *a_Player, cItem *a_Item);
virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir);
diff --git a/source/items/ItemFood.h b/source/items/ItemFood.h new file mode 100644 index 000000000..8998fd503 --- /dev/null +++ b/source/items/ItemFood.h @@ -0,0 +1,55 @@ +#pragma once
+
+#include "Item.h"
+
+
+class cItemFoodHandler : public cItemHandler
+{
+public:
+ cItemFoodHandler(int a_ItemID)
+ : cItemHandler(a_ItemID)
+ {
+ }
+
+ virtual bool IsFood() override
+ {
+ return true;
+ }
+
+ virtual FoodInfo GetFoodInfo() override
+ {
+ switch(m_ItemID)
+ {
+ case E_ITEM_BREAD:
+ return FoodInfo(5, 6.f);
+ case E_ITEM_COOKIE:
+ return FoodInfo(2, 0.4f);
+ case E_ITEM_MELON_SLICE:
+ return FoodInfo(2, 1.2f);
+ case E_ITEM_RAW_CHICKEN:
+ return FoodInfo(2, 1.2f, 30);
+ case E_ITEM_COOKED_CHICKEN:
+ return FoodInfo(6, 7.2f);
+ case E_ITEM_RAW_BEEF:
+ case E_ITEM_RAW_MEAT:
+ return FoodInfo(3, 1.8f);
+ case E_ITEM_STEAK:
+ case E_ITEM_COOKED_MEAT:
+ return FoodInfo(8, 12.8f);
+ case E_ITEM_RAW_FISH:
+ return FoodInfo(2, 1.2f);
+ case E_ITEM_COOKED_FISH:
+ return FoodInfo(5, 6.f);
+ case E_ITEM_RED_APPLE:
+ return FoodInfo(4, 2.4f);
+ case E_ITEM_GOLDEN_APPLE:
+ return FoodInfo(4, 9.6f);
+ case E_ITEM_ROTTEN_FLESH:
+ return FoodInfo(4, 0.8f, 80);
+ case E_ITEM_SPIDER_EYE:
+ return FoodInfo(2, 3.2f, 100);
+ }
+ return FoodInfo(0, 0.f);
+ }
+
+};
\ No newline at end of file |