diff options
author | madmaxoft <github@xoft.cz> | 2013-07-28 19:15:03 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-07-28 19:15:03 +0200 |
commit | 4746d2251c6204118e710c818d78b89c356a7427 (patch) | |
tree | 2573e0b5e70b04aebc35d5da034c8449ff696f3d /source/Items | |
parent | ProtoProxy now properly waits for both sides to establish encryption (diff) | |
download | cuberite-4746d2251c6204118e710c818d78b89c356a7427.tar cuberite-4746d2251c6204118e710c818d78b89c356a7427.tar.gz cuberite-4746d2251c6204118e710c818d78b89c356a7427.tar.bz2 cuberite-4746d2251c6204118e710c818d78b89c356a7427.tar.lz cuberite-4746d2251c6204118e710c818d78b89c356a7427.tar.xz cuberite-4746d2251c6204118e710c818d78b89c356a7427.tar.zst cuberite-4746d2251c6204118e710c818d78b89c356a7427.zip |
Diffstat (limited to '')
-rw-r--r-- | source/Items/ItemFood.h | 66 | ||||
-rw-r--r-- | source/Items/ItemHandler.cpp | 15 | ||||
-rw-r--r-- | source/Items/ItemHandler.h | 17 |
3 files changed, 51 insertions, 47 deletions
diff --git a/source/Items/ItemFood.h b/source/Items/ItemFood.h index d4c0a012a..4ec2f7a36 100644 --- a/source/Items/ItemFood.h +++ b/source/Items/ItemFood.h @@ -4,53 +4,53 @@ #include "ItemHandler.h"
-class cItemFoodHandler : public cItemHandler
+
+
+
+class cItemFoodHandler :
+ public cItemHandler
{
+ typedef cItemHandler super;
+
public:
cItemFoodHandler(int a_ItemType)
- : cItemHandler(a_ItemType)
+ : super(a_ItemType)
{
}
- virtual bool IsFood() override
+
+ virtual bool IsFood(void) override
{
return true;
}
- virtual FoodInfo GetFoodInfo() override
+
+ virtual FoodInfo GetFoodInfo(void) override
{
switch(m_ItemType)
{
- 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_PORKCHOP:
- return FoodInfo(3, 1.8f);
- case E_ITEM_STEAK:
- case E_ITEM_COOKED_PORKCHOP:
- 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);
+ case E_ITEM_BREAD: return FoodInfo(5, 6);
+ case E_ITEM_COOKIE: return FoodInfo(2, 0.4);
+ case E_ITEM_MELON_SLICE: return FoodInfo(2, 1.2);
+ case E_ITEM_RAW_CHICKEN: return FoodInfo(2, 1.2, 30);
+ case E_ITEM_COOKED_CHICKEN: return FoodInfo(6, 7.2);
+ case E_ITEM_RAW_BEEF: return FoodInfo(3, 1.8);
+ case E_ITEM_RAW_PORKCHOP: return FoodInfo(3, 1.8);
+ case E_ITEM_STEAK: return FoodInfo(8, 12.8);
+ case E_ITEM_COOKED_PORKCHOP: return FoodInfo(8, 12.8);
+ case E_ITEM_RAW_FISH: return FoodInfo(2, 1.2);
+ case E_ITEM_COOKED_FISH: return FoodInfo(5, 6);
+ case E_ITEM_RED_APPLE: return FoodInfo(4, 2.4);
+ case E_ITEM_GOLDEN_APPLE: return FoodInfo(4, 9.6);
+ case E_ITEM_ROTTEN_FLESH: return FoodInfo(4, 0.8, 80);
+ case E_ITEM_SPIDER_EYE: return FoodInfo(2, 3.2, 100);
}
+ LOGWARNING("%s: Unknown food item (%d), returning zero nutrition", __FUNCTION__, m_ItemType);
return FoodInfo(0, 0.f);
}
-};
\ No newline at end of file +};
+
+
+
+
diff --git a/source/Items/ItemHandler.cpp b/source/Items/ItemHandler.cpp index d99457029..acb6b6371 100644 --- a/source/Items/ItemHandler.cpp +++ b/source/Items/ItemHandler.cpp @@ -4,6 +4,7 @@ #include "../Item.h"
#include "../World.h"
#include "../Player.h"
+#include "../FastRandom.h"
// Handlers:
#include "ItemBed.h"
@@ -465,15 +466,17 @@ bool cItemHandler::EatItem(cPlayer * a_Player, cItem * a_Item) {
FoodInfo Info = GetFoodInfo();
- if(Info.FoodLevel > 0 || Info.Saturation > 0.f)
+ if ((Info.FoodLevel > 0) || (Info.Saturation > 0.f))
{
bool Success = a_Player->Feed(Info.FoodLevel, Info.Saturation);
- if(Success && Info.PoisionChance > 0)
+
+ // If consumed and there's chance of foodpoisoning, do it:
+ if (Success && (Info.PoisonChance > 0))
{
- MTRand r1;
- if((r1.randInt(100) - Info.PoisionChance) <= 0)
- { //Unlucky guy :D
- //TODO: Make player ill
+ cFastRandom r1;
+ if ((r1.NextInt(100, a_Player->GetUniqueID()) - Info.PoisonChance) <= 0)
+ {
+ a_Player->FoodPoison(300);
}
}
diff --git a/source/Items/ItemHandler.h b/source/Items/ItemHandler.h index 0c141dea0..f7985327a 100644 --- a/source/Items/ItemHandler.h +++ b/source/Items/ItemHandler.h @@ -38,16 +38,17 @@ public: struct FoodInfo
{
- FoodInfo(short a_FoodLevel, float a_Saturation, char a_PoisionChance = 0)
+ int FoodLevel;
+ double Saturation;
+ int PoisonChance; // 0 - 100, in percent. 0 = no chance of poisoning, 100 = sure poisoning
+
+ FoodInfo(int a_FoodLevel, double a_Saturation, int a_PoisonChance = 0) :
+ FoodLevel(a_FoodLevel),
+ Saturation(a_Saturation),
+ PoisonChance(a_PoisonChance)
{
- FoodLevel = a_FoodLevel;
- Saturation = a_Saturation;
- PoisionChance = a_PoisionChance;
}
- short FoodLevel;
- float Saturation;
- char PoisionChance; //0 - 100
- };
+ } ;
/// Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance)
virtual FoodInfo GetFoodInfo();
|