1
0

Refactored item-eating from cClientHandle into cPlayer

git-svn-id: http://mc-server.googlecode.com/svn/trunk@519 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-05-29 19:56:07 +00:00
parent 9d6a5b9ce0
commit 322ba59c3a
3 changed files with 73 additions and 83 deletions

View File

@ -981,77 +981,7 @@ void cClientHandle::HandleBlockPlace(cPacket_BlockPlace * a_Packet)
a_Packet->m_PosX, a_Packet->m_PosY, a_Packet->m_PosZ a_Packet->m_PosX, a_Packet->m_PosY, a_Packet->m_PosZ
); );
// Hacked in edible items go!~ if (m_Player->EatItem(Item.m_ItemID))
// TODO: Handle hunger
bool bEat = false;
bool isDoor = false;
switch (Item.m_ItemID)
{
case E_ITEM_APPLE:
//m_Player->Heal(4); // 2 hearts
m_Player->Feed(24); // 2 food bars
bEat = true;
break;
case E_ITEM_GOLDEN_APPLE:
//m_Player->Heal(20); // 10 hearts
m_Player->Feed(60); // 5 food
bEat = true;
break;
case E_ITEM_MUSHROOM_SOUP:
///m_Player->Heal(10); // 5 hearts
m_Player->Feed(48); // 4 food
bEat = true;
break;
case E_ITEM_BREAD:
//m_Player->Heal(5); // 2.5 hearts
m_Player->Feed(30); // 2.5 food
bEat = true;
break;
case E_ITEM_RAW_MEAT:
//m_Player->Heal(3); // 1.5 hearts
m_Player->Feed(18); // 1.5 food
bEat = true;
break;
case E_ITEM_COOKED_MEAT:
//m_Player->Heal(8); // 4 hearts
m_Player->Feed(48); // 4 food
bEat = true;
break;
case E_ITEM_RAW_FISH:
//m_Player->Heal(2); // 1 heart
m_Player->Feed(12); // 1 food
bEat = true;
break;
case E_ITEM_COOKED_FISH:
//m_Player->Heal(5); // 2.5 hearts
m_Player->Feed(30); // 2.5 food
bEat = true;
break;
case E_ITEM_RAW_CHICKEN:
//m_Player->Heal(3);
m_Player->Feed(12); // 1 food
bEat = true;
break;
case E_ITEM_COOKED_CHICKEN:
//m_Player->Heal(8);
m_Player->Feed(36); // 3 food
bEat = true;
break;
case E_ITEM_RAW_BEEF:
//m_Player->Heal(3);
m_Player->Feed(18); // 1.5 food
bEat = true;
break;
case E_ITEM_STEAK:
//m_Player->Heal(8);
m_Player->Feed(48); // 4 food
bEat = true;
break;
default:
break;
};
if (bEat)
{ {
m_Player->GetInventory().RemoveItem(Item); m_Player->GetInventory().RemoveItem(Item);
return; return;
@ -1062,6 +992,7 @@ void cClientHandle::HandleBlockPlace(cPacket_BlockPlace * a_Packet)
// clicked in air // clicked in air
return; return;
} }
bool isDoor = false;
//TODO: Wrong Blocks! //TODO: Wrong Blocks!
int ClickedBlock = (int)m_Player->GetWorld()->GetBlock(a_Packet->m_PosX, a_Packet->m_PosY, a_Packet->m_PosZ); int ClickedBlock = (int)m_Player->GetWorld()->GetBlock(a_Packet->m_PosX, a_Packet->m_PosY, a_Packet->m_PosZ);

View File

@ -305,10 +305,17 @@ void cPlayer::Heal( int a_Health )
} }
} }
void cPlayer::Feed( short a_Food )
bool cPlayer::Feed(short a_Food)
{ {
if( m_FoodLevel < GetMaxFoodLevel() ) if (m_FoodLevel >= GetMaxFoodLevel())
{ {
return false;
}
m_FoodLevel = MIN(a_Food + m_FoodLevel, GetMaxFoodLevel()); m_FoodLevel = MIN(a_Food + m_FoodLevel, GetMaxFoodLevel());
cPacket_UpdateHealth Health; cPacket_UpdateHealth Health;
@ -316,9 +323,13 @@ void cPlayer::Feed( short a_Food )
Health.m_Food = GetFood(); Health.m_Food = GetFood();
Health.m_Saturation = GetFoodSaturation(); Health.m_Saturation = GetFoodSaturation();
m_ClientHandle->Send( Health ); m_ClientHandle->Send( Health );
} return true;
} }
void cPlayer::TakeDamage( int a_Damage, cEntity* a_Instigator ) void cPlayer::TakeDamage( int a_Damage, cEntity* a_Instigator )
{ {
if ( !(m_GameMode == 1) ) { if ( !(m_GameMode == 1) ) {
@ -985,3 +996,46 @@ void cPlayer::UseEquippedItem()
bool cPlayer::EatItem(int a_ItemType)
{
// TODO: Handle hunger
switch (a_ItemType)
{
case E_ITEM_APPLE: return Feed(24); // 2 food bars
case E_ITEM_GOLDEN_APPLE: return Feed(60); // 5 food
case E_ITEM_MUSHROOM_SOUP: return Feed(48); // 4 food
case E_ITEM_BREAD: return Feed(30); // 2.5 food
case E_ITEM_RAW_MEAT: return Feed(18); // 1.5 food
case E_ITEM_COOKED_MEAT: return Feed(48); // 4 food
case E_ITEM_RAW_FISH: return Feed(12); // 1 food
case E_ITEM_COOKED_FISH: return Feed(30); // 2.5 food
case E_ITEM_COOKED_CHICKEN: return Feed(36); // 3 food
case E_ITEM_RAW_BEEF: return Feed(18); // 1.5 food
case E_ITEM_STEAK: return Feed(48); // 4 food
case E_ITEM_RAW_CHICKEN:
{
if (!Feed(12)) // 1 food
{
return false;
}
// TODO: A random chance to get food-poisoned
return true;
}
case E_ITEM_ROTTEN_FLESH:
{
if (!Feed(24))
{
return false;
}
// TODO: Food-poisoning
return true;
}
}
return false;
}

View File

@ -81,7 +81,10 @@ public:
void TossItem( bool a_bDraggingItem, int a_Amount = 1 ); //tolua_export void TossItem( bool a_bDraggingItem, int a_Amount = 1 ); //tolua_export
void Heal( int a_Health ); //tolua_export void Heal( int a_Health ); //tolua_export
void Feed( short a_Food );
/// Returns true if any food has been consumed, false if player "full"
bool Feed(short a_Food);
void TakeDamage( int a_Damage, cEntity* a_Instigator ); //tolua_export void TakeDamage( int a_Damage, cEntity* a_Instigator ); //tolua_export
void KilledBy( cEntity* a_Killer ); //tolua_export void KilledBy( cEntity* a_Killer ); //tolua_export
void Respawn(); //tolua_export void Respawn(); //tolua_export
@ -97,8 +100,10 @@ public:
const AString & GetLoadedWorldName() { return m_LoadedWorldName; } const AString & GetLoadedWorldName() { return m_LoadedWorldName; }
void UseEquippedItem(); void UseEquippedItem(void);
/// Returns true if the item type is edible && it has been consumed, false otherwise
bool EatItem(int a_ItemType);
protected: protected:
virtual void Destroyed(); virtual void Destroyed();