From d7adbba59d2372234a616b87f8b3b5a03888ddbc Mon Sep 17 00:00:00 2001 From: "mtilden@gmail.com" Date: Thu, 29 Dec 2011 15:31:48 +0000 Subject: - Initial food handling by cedeel git-svn-id: http://mc-server.googlecode.com/svn/trunk@156 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cPlayer.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source/cPlayer.cpp') diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp index 820b11f8b..baba0174a 100644 --- a/source/cPlayer.cpp +++ b/source/cPlayer.cpp @@ -81,6 +81,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const char* a_PlayerName) { m_EntityType = E_PLAYER; SetMaxHealth(20); + SetMaxFoodLevel(125); m_Inventory = new cInventory( this ); cTimer t1; m_LastPlayerListTime = t1.GetNowTime(); @@ -290,6 +291,22 @@ void cPlayer::Heal( int a_Health ) cPacket_UpdateHealth Health; Health.m_Health = m_Health; + Health.m_Food = GetFood(); + Health.m_Saturation = GetFoodSaturation(); + m_ClientHandle->Send( Health ); + } +} + +void cPlayer::Feed( short a_Food ) +{ + if( m_FoodLevel < GetMaxFoodLevel() ) + { + m_FoodLevel = MIN(a_Food + m_FoodLevel, GetMaxFoodLevel()); + + cPacket_UpdateHealth Health; + Health.m_Health = m_Health; + Health.m_Food = GetFood(); + Health.m_Saturation = GetFoodSaturation(); m_ClientHandle->Send( Health ); } } @@ -301,6 +318,8 @@ void cPlayer::TakeDamage( int a_Damage, cEntity* a_Instigator ) cPacket_UpdateHealth Health; Health.m_Health = m_Health; + Health.m_Food = GetFood(); + Health.m_Saturation = GetFoodSaturation(); //TODO: Causes problems sometimes O.o (E.G. Disconnecting when attacked) if(m_ClientHandle != 0) m_ClientHandle->Send( Health ); @@ -772,6 +791,7 @@ bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the cor } m_Health = (short)root.get("health", 0 ).asInt(); + m_FoodLevel = (short)root.get("food", 0 ).asInt(); m_Inventory->LoadFromJson(root["inventory"]); m_pState->LoadedWorldName = root.get("world", "world").asString(); @@ -804,6 +824,7 @@ bool cPlayer::SaveToDisk() root["rotation"] = JSON_PlayerRotation; root["inventory"] = JSON_Inventory; root["health"] = m_Health; + root["food"] = m_FoodLevel; root["world"] = GetWorld()->GetName(); Json::StyledWriter writer; -- cgit v1.2.3