Consolidated food effects into EatItem, added all fish type FoodInfos. (#3875)
* Consolidated food effects into EatItem, added all fish types. * Changed type of NumFishInfos to satisfy clang. * Removed unused call for a_Item in EatItem
This commit is contained in:
parent
8fbb9dbf53
commit
10d42a2452
@ -25,8 +25,23 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual FoodInfo GetFoodInfo(void) override
|
virtual FoodInfo GetFoodInfo(const cItem * a_Item) override
|
||||||
{
|
{
|
||||||
|
static const FoodInfo RawFishInfos[] =
|
||||||
|
{
|
||||||
|
FoodInfo(2, 0.4), // Raw fish
|
||||||
|
FoodInfo(2, 0.2), // Raw salmon
|
||||||
|
FoodInfo(1, 0.2), // Clownfish
|
||||||
|
FoodInfo(1, 0.2), // Pufferfish
|
||||||
|
};
|
||||||
|
static const FoodInfo CookedFishInfos[] =
|
||||||
|
{
|
||||||
|
FoodInfo(5, 6.0), // Cooked fish
|
||||||
|
FoodInfo(6, 9.6), // Cooked salmon
|
||||||
|
};
|
||||||
|
static const short NumRawFishInfos = sizeof(RawFishInfos) / sizeof(FoodInfo);
|
||||||
|
static const short NumCookedFishInfos = sizeof(CookedFishInfos) / sizeof(FoodInfo);
|
||||||
|
|
||||||
switch (m_ItemType)
|
switch (m_ItemType)
|
||||||
{
|
{
|
||||||
// Please keep alpha-sorted.
|
// Please keep alpha-sorted.
|
||||||
@ -37,7 +52,15 @@ public:
|
|||||||
// Carrots handled in ItemSeeds
|
// Carrots handled in ItemSeeds
|
||||||
case E_ITEM_CHORUS_FRUIT: return FoodInfo(4, 2.4);
|
case E_ITEM_CHORUS_FRUIT: return FoodInfo(4, 2.4);
|
||||||
case E_ITEM_COOKED_CHICKEN: return FoodInfo(6, 7.2);
|
case E_ITEM_COOKED_CHICKEN: return FoodInfo(6, 7.2);
|
||||||
case E_ITEM_COOKED_FISH: return FoodInfo(5, 6); // TODO: Add other fish types
|
case E_ITEM_COOKED_FISH:
|
||||||
|
{
|
||||||
|
if (a_Item->m_ItemDamage >= NumCookedFishInfos)
|
||||||
|
{
|
||||||
|
LOGWARNING("Unknown cooked fish type '%d'", a_Item->m_ItemDamage);
|
||||||
|
return FoodInfo(0, 0);
|
||||||
|
}
|
||||||
|
return CookedFishInfos[a_Item->m_ItemDamage];
|
||||||
|
}
|
||||||
case E_ITEM_COOKED_MUTTON: return FoodInfo(6, 9.6);
|
case E_ITEM_COOKED_MUTTON: return FoodInfo(6, 9.6);
|
||||||
case E_ITEM_COOKED_PORKCHOP: return FoodInfo(8, 12.8);
|
case E_ITEM_COOKED_PORKCHOP: return FoodInfo(8, 12.8);
|
||||||
case E_ITEM_COOKED_RABBIT: return FoodInfo(5, 6);
|
case E_ITEM_COOKED_RABBIT: return FoodInfo(5, 6);
|
||||||
@ -53,7 +76,15 @@ public:
|
|||||||
case E_ITEM_RED_APPLE: return FoodInfo(4, 2.4);
|
case E_ITEM_RED_APPLE: return FoodInfo(4, 2.4);
|
||||||
case E_ITEM_RAW_BEEF: return FoodInfo(3, 1.8);
|
case E_ITEM_RAW_BEEF: return FoodInfo(3, 1.8);
|
||||||
case E_ITEM_RAW_CHICKEN: return FoodInfo(2, 1.2);
|
case E_ITEM_RAW_CHICKEN: return FoodInfo(2, 1.2);
|
||||||
case E_ITEM_RAW_FISH: return FoodInfo(2, 1.2);
|
case E_ITEM_RAW_FISH:
|
||||||
|
{
|
||||||
|
if (a_Item->m_ItemDamage >= NumRawFishInfos)
|
||||||
|
{
|
||||||
|
LOGWARNING("Unknown raw fish type '%d'", a_Item->m_ItemDamage);
|
||||||
|
return FoodInfo(0, 0);
|
||||||
|
}
|
||||||
|
return RawFishInfos[a_Item->m_ItemDamage];
|
||||||
|
}
|
||||||
case E_ITEM_RAW_MUTTON: return FoodInfo(2, 1.2);
|
case E_ITEM_RAW_MUTTON: return FoodInfo(2, 1.2);
|
||||||
case E_ITEM_RAW_PORKCHOP: return FoodInfo(3, 1.8);
|
case E_ITEM_RAW_PORKCHOP: return FoodInfo(3, 1.8);
|
||||||
case E_ITEM_RAW_RABBIT: return FoodInfo(3, 1.8);
|
case E_ITEM_RAW_RABBIT: return FoodInfo(3, 1.8);
|
||||||
@ -65,46 +96,6 @@ public:
|
|||||||
return FoodInfo(0, 0.f);
|
return FoodInfo(0, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool GetEatEffect(cEntityEffect::eType & a_EffectType, int & a_EffectDurationTicks, short & a_EffectIntensity, float & a_Chance) override
|
|
||||||
{
|
|
||||||
switch (m_ItemType)
|
|
||||||
{
|
|
||||||
case E_ITEM_RAW_CHICKEN:
|
|
||||||
{
|
|
||||||
a_EffectType = cEntityEffect::effHunger;
|
|
||||||
a_EffectDurationTicks = 600;
|
|
||||||
a_EffectIntensity = 0;
|
|
||||||
a_Chance = 0.3f;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case E_ITEM_ROTTEN_FLESH:
|
|
||||||
{
|
|
||||||
a_EffectType = cEntityEffect::effHunger;
|
|
||||||
a_EffectDurationTicks = 600;
|
|
||||||
a_EffectIntensity = 0;
|
|
||||||
a_Chance = 0.8f;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case E_ITEM_SPIDER_EYE:
|
|
||||||
{
|
|
||||||
a_EffectType = cEntityEffect::effPoison;
|
|
||||||
a_EffectDurationTicks = 100;
|
|
||||||
a_EffectIntensity = 0;
|
|
||||||
a_Chance = 1.0f;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case E_ITEM_POISONOUS_POTATO:
|
|
||||||
{
|
|
||||||
a_EffectType = cEntityEffect::effPoison;
|
|
||||||
a_EffectDurationTicks = 100;
|
|
||||||
a_EffectIntensity = 0;
|
|
||||||
a_Chance = 0.6f;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||||
{
|
{
|
||||||
if (!super::EatItem(a_Player, a_Item))
|
if (!super::EatItem(a_Player, a_Item))
|
||||||
@ -125,6 +116,45 @@ public:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case E_ITEM_RAW_FISH:
|
||||||
|
{
|
||||||
|
if (a_Item->m_ItemDamage == E_META_RAW_FISH_PUFFERFISH)
|
||||||
|
{
|
||||||
|
a_Player->AddEntityEffect(cEntityEffect::effHunger, 20 * 15, 2);
|
||||||
|
a_Player->AddEntityEffect(cEntityEffect::effNausea, 20 * 15, 1);
|
||||||
|
a_Player->AddEntityEffect(cEntityEffect::effPoison, 20 * 60, 3);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case E_ITEM_RAW_CHICKEN:
|
||||||
|
{
|
||||||
|
if (GetRandomProvider().RandBool(0.3))
|
||||||
|
{
|
||||||
|
a_Player->AddEntityEffect(cEntityEffect::effHunger, 600, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case E_ITEM_ROTTEN_FLESH:
|
||||||
|
{
|
||||||
|
if (GetRandomProvider().RandBool(0.8))
|
||||||
|
{
|
||||||
|
a_Player->AddEntityEffect(cEntityEffect::effHunger, 600, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case E_ITEM_SPIDER_EYE:
|
||||||
|
{
|
||||||
|
a_Player->AddEntityEffect(cEntityEffect::effPoison, 100, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case E_ITEM_POISONOUS_POTATO:
|
||||||
|
{
|
||||||
|
if (GetRandomProvider().RandBool(0.6))
|
||||||
|
{
|
||||||
|
a_Player->AddEntityEffect(cEntityEffect::effPoison, 100, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,10 @@ public:
|
|||||||
|
|
||||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||||
{
|
{
|
||||||
// Feed the player:
|
if (!super::EatItem(a_Player, a_Item))
|
||||||
FoodInfo Info = GetFoodInfo();
|
{
|
||||||
a_Player->Feed(Info.FoodLevel, Info.Saturation);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Add the effects:
|
// Add the effects:
|
||||||
a_Player->AddEntityEffect(cEntityEffect::effAbsorption, 2400, 0);
|
a_Player->AddEntityEffect(cEntityEffect::effAbsorption, 2400, 0);
|
||||||
@ -36,22 +37,16 @@ public:
|
|||||||
a_Player->AddEntityEffect(cEntityEffect::effFireResistance, 6000, 0);
|
a_Player->AddEntityEffect(cEntityEffect::effFireResistance, 6000, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
a_Player->GetInventory().RemoveOneEquippedItem();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual FoodInfo GetFoodInfo(void) override
|
virtual FoodInfo GetFoodInfo(const cItem * a_Item) override
|
||||||
{
|
{
|
||||||
|
UNUSED(a_Item);
|
||||||
return FoodInfo(4, 9.6);
|
return FoodInfo(4, 9.6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual bool GetEatEffect(cEntityEffect::eType & a_EffectType, int & a_EffectDurationTicks, short & a_EffectIntensity, float & a_Chance) override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -826,41 +826,17 @@ bool cItemHandler::GetPlacementBlockTypeMeta(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cItemHandler::GetEatEffect(cEntityEffect::eType & a_EffectType, int & a_EffectDurationTicks, short & a_EffectIntensity, float & a_Chance)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cItemHandler::EatItem(cPlayer * a_Player, cItem * a_Item)
|
bool cItemHandler::EatItem(cPlayer * a_Player, cItem * a_Item)
|
||||||
{
|
{
|
||||||
UNUSED(a_Item);
|
|
||||||
if (!a_Player->IsGameModeCreative())
|
if (!a_Player->IsGameModeCreative())
|
||||||
{
|
{
|
||||||
a_Player->GetInventory().RemoveOneEquippedItem();
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
FoodInfo Info = GetFoodInfo();
|
FoodInfo Info = GetFoodInfo(a_Item);
|
||||||
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);
|
return a_Player->Feed(Info.FoodLevel, Info.Saturation);
|
||||||
|
|
||||||
// Give effects
|
|
||||||
cEntityEffect::eType EffectType;
|
|
||||||
int EffectDurationTicks;
|
|
||||||
short EffectIntensity;
|
|
||||||
float Chance;
|
|
||||||
if (Success && GetEatEffect(EffectType, EffectDurationTicks, EffectIntensity, Chance))
|
|
||||||
{
|
|
||||||
if (GetRandomProvider().RandBool(Chance))
|
|
||||||
{
|
|
||||||
a_Player->AddEntityEffect(EffectType, EffectDurationTicks, EffectIntensity, Chance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Success;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -869,8 +845,9 @@ bool cItemHandler::EatItem(cPlayer * a_Player, cItem * a_Item)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cItemHandler::FoodInfo cItemHandler::GetFoodInfo()
|
cItemHandler::FoodInfo cItemHandler::GetFoodInfo(const cItem * a_Item)
|
||||||
{
|
{
|
||||||
|
UNUSED(a_Item);
|
||||||
return FoodInfo(0, 0);
|
return FoodInfo(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,10 +127,7 @@ public:
|
|||||||
} ;
|
} ;
|
||||||
|
|
||||||
/** Returns the FoodInfo for this item. (FoodRecovery and Saturation) */
|
/** Returns the FoodInfo for this item. (FoodRecovery and Saturation) */
|
||||||
virtual FoodInfo GetFoodInfo();
|
virtual FoodInfo GetFoodInfo(const cItem * a_Item);
|
||||||
|
|
||||||
/** If this function returns true, it sets the arguments to a effect who will be activated when you eat the item. */
|
|
||||||
virtual bool GetEatEffect(cEntityEffect::eType & a_EffectType, int & a_EffectDurationTicks, short & a_EffectIntensity, float & a_Chance);
|
|
||||||
|
|
||||||
/** Lets the player eat a selected item. Returns true if the player ate the item */
|
/** Lets the player eat a selected item. Returns true if the player ate the item */
|
||||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item);
|
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item);
|
||||||
|
@ -33,8 +33,9 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual FoodInfo GetFoodInfo(void) override
|
virtual FoodInfo GetFoodInfo(const cItem * a_Item) override
|
||||||
{
|
{
|
||||||
|
UNUSED(a_Item);
|
||||||
switch (m_ItemType)
|
switch (m_ItemType)
|
||||||
{
|
{
|
||||||
case E_ITEM_CARROT: return FoodInfo(3, 3.6);
|
case E_ITEM_CARROT: return FoodInfo(3, 3.6);
|
||||||
|
@ -169,10 +169,13 @@ void cWolf::ReceiveNearbyFightInfo(AString a_PlayerID, cPawn * a_Opponent, bool
|
|||||||
|
|
||||||
void cWolf::OnRightClicked(cPlayer & a_Player)
|
void cWolf::OnRightClicked(cPlayer & a_Player)
|
||||||
{
|
{
|
||||||
|
const cItem & EquippedItem = a_Player.GetEquippedItem();
|
||||||
|
const int EquippedItemType = EquippedItem.m_ItemType;
|
||||||
|
|
||||||
if (!IsTame() && !IsAngry())
|
if (!IsTame() && !IsAngry())
|
||||||
{
|
{
|
||||||
// If the player is holding a bone, try to tame the wolf:
|
// If the player is holding a bone, try to tame the wolf:
|
||||||
if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_BONE)
|
if (EquippedItemType == E_ITEM_BONE)
|
||||||
{
|
{
|
||||||
if (!a_Player.IsGameModeCreative())
|
if (!a_Player.IsGameModeCreative())
|
||||||
{
|
{
|
||||||
@ -199,7 +202,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
|
|||||||
else if (IsTame())
|
else if (IsTame())
|
||||||
{
|
{
|
||||||
// Feed the wolf, restoring its health, or dye its collar:
|
// Feed the wolf, restoring its health, or dye its collar:
|
||||||
switch (a_Player.GetEquippedItem().m_ItemType)
|
switch (EquippedItemType)
|
||||||
{
|
{
|
||||||
case E_ITEM_RAW_BEEF:
|
case E_ITEM_RAW_BEEF:
|
||||||
case E_ITEM_STEAK:
|
case E_ITEM_STEAK:
|
||||||
@ -211,7 +214,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
|
|||||||
{
|
{
|
||||||
if (m_Health < m_MaxHealth)
|
if (m_Health < m_MaxHealth)
|
||||||
{
|
{
|
||||||
Heal(ItemHandler(a_Player.GetEquippedItem().m_ItemType)->GetFoodInfo().FoodLevel);
|
Heal(ItemHandler(EquippedItemType)->GetFoodInfo(&EquippedItem).FoodLevel);
|
||||||
if (!a_Player.IsGameModeCreative())
|
if (!a_Player.IsGameModeCreative())
|
||||||
{
|
{
|
||||||
a_Player.GetInventory().RemoveOneEquippedItem();
|
a_Player.GetInventory().RemoveOneEquippedItem();
|
||||||
@ -223,7 +226,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
|
|||||||
{
|
{
|
||||||
if (a_Player.GetUUID() == m_OwnerUUID) // Is the player the owner of the dog?
|
if (a_Player.GetUUID() == m_OwnerUUID) // Is the player the owner of the dog?
|
||||||
{
|
{
|
||||||
SetCollarColor(a_Player.GetEquippedItem().m_ItemDamage);
|
SetCollarColor(EquippedItem.m_ItemDamage);
|
||||||
if (!a_Player.IsGameModeCreative())
|
if (!a_Player.IsGameModeCreative())
|
||||||
{
|
{
|
||||||
a_Player.GetInventory().RemoveOneEquippedItem();
|
a_Player.GetInventory().RemoveOneEquippedItem();
|
||||||
|
Loading…
Reference in New Issue
Block a user