- Initial food handling by cedeel
git-svn-id: http://mc-server.googlecode.com/svn/trunk@156 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
05ced6665b
commit
d7adbba59d
@ -784,51 +784,63 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
|
|||||||
switch( Item.m_ItemID )
|
switch( Item.m_ItemID )
|
||||||
{
|
{
|
||||||
case E_ITEM_APPLE:
|
case E_ITEM_APPLE:
|
||||||
m_Player->Heal( 4 ); // 2 hearts
|
//m_Player->Heal( 4 ); // 2 hearts
|
||||||
|
m_Player->Feed( 24 ); // 2 food bars
|
||||||
bEat = true;
|
bEat = true;
|
||||||
break;
|
break;
|
||||||
case E_ITEM_GOLDEN_APPLE:
|
case E_ITEM_GOLDEN_APPLE:
|
||||||
m_Player->Heal( 20 ); // 10 hearts
|
//m_Player->Heal( 20 ); // 10 hearts
|
||||||
|
m_Player->Feed(60); // 5 food
|
||||||
bEat = true;
|
bEat = true;
|
||||||
break;
|
break;
|
||||||
case E_ITEM_MUSHROOM_SOUP:
|
case E_ITEM_MUSHROOM_SOUP:
|
||||||
m_Player->Heal( 10 ); // 5 hearts
|
///m_Player->Heal( 10 ); // 5 hearts
|
||||||
|
m_Player->Feed( 48 ); // 4 food
|
||||||
bEat = true;
|
bEat = true;
|
||||||
break;
|
break;
|
||||||
case E_ITEM_BREAD:
|
case E_ITEM_BREAD:
|
||||||
m_Player->Heal( 5 ); // 2.5 hearts
|
//m_Player->Heal( 5 ); // 2.5 hearts
|
||||||
|
m_Player->Feed( 30 ); // 2.5 food
|
||||||
bEat = true;
|
bEat = true;
|
||||||
break;
|
break;
|
||||||
case E_ITEM_RAW_MEAT:
|
case E_ITEM_RAW_MEAT:
|
||||||
m_Player->Heal( 3 ); // 1.5 hearts
|
//m_Player->Heal( 3 ); // 1.5 hearts
|
||||||
|
m_Player->Feed( 18 ); // 1.5 food
|
||||||
bEat = true;
|
bEat = true;
|
||||||
break;
|
break;
|
||||||
case E_ITEM_COOKED_MEAT:
|
case E_ITEM_COOKED_MEAT:
|
||||||
m_Player->Heal( 8 ); // 4 hearts
|
//m_Player->Heal( 8 ); // 4 hearts
|
||||||
|
m_Player->Feed( 48 ); // 4 food
|
||||||
bEat = true;
|
bEat = true;
|
||||||
break;
|
break;
|
||||||
case E_ITEM_RAW_FISH:
|
case E_ITEM_RAW_FISH:
|
||||||
m_Player->Heal( 2 ); // 1 heart
|
//m_Player->Heal( 2 ); // 1 heart
|
||||||
|
m_Player->Feed( 12 ); // 1 food
|
||||||
bEat = true;
|
bEat = true;
|
||||||
break;
|
break;
|
||||||
case E_ITEM_COOKED_FISH:
|
case E_ITEM_COOKED_FISH:
|
||||||
m_Player->Heal( 5 ); // 2.5 hearts
|
//m_Player->Heal( 5 ); // 2.5 hearts
|
||||||
|
m_Player->Feed( 30 ); // 2.5 food
|
||||||
bEat = true;
|
bEat = true;
|
||||||
break;
|
break;
|
||||||
case E_ITEM_RAW_CHICKEN:
|
case E_ITEM_RAW_CHICKEN:
|
||||||
m_Player->Heal(3);
|
//m_Player->Heal(3);
|
||||||
|
m_Player->Feed( 12 ); // 1 food
|
||||||
bEat = true;
|
bEat = true;
|
||||||
break;
|
break;
|
||||||
case E_ITEM_COOKED_CHICKEN:
|
case E_ITEM_COOKED_CHICKEN:
|
||||||
m_Player->Heal( 8 );
|
//m_Player->Heal( 8 );
|
||||||
|
m_Player->Feed( 36 ); // 3 food
|
||||||
bEat = true;
|
bEat = true;
|
||||||
break;
|
break;
|
||||||
case E_ITEM_RAW_BEEF:
|
case E_ITEM_RAW_BEEF:
|
||||||
m_Player->Heal(3);
|
//m_Player->Heal(3);
|
||||||
|
m_Player->Feed( 18 ); // 1.5 food
|
||||||
bEat = true;
|
bEat = true;
|
||||||
break;
|
break;
|
||||||
case E_ITEM_STEAK:
|
case E_ITEM_STEAK:
|
||||||
m_Player->Heal( 8 );
|
//m_Player->Heal( 8 );
|
||||||
|
m_Player->Feed( 48 ); // 4 food
|
||||||
bEat = true;
|
bEat = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -1293,7 +1305,12 @@ void cClientHandle::Tick(float a_Dt)
|
|||||||
m_Player->GetInventory().SendWholeInventory( this );
|
m_Player->GetInventory().SendWholeInventory( this );
|
||||||
|
|
||||||
// Send health
|
// Send health
|
||||||
Send( cPacket_UpdateHealth( (short)m_Player->GetHealth() ) );
|
cPacket_UpdateHealth Health;
|
||||||
|
Health.m_Health = (short)m_Player->GetHealth();
|
||||||
|
Health.m_Food = m_Player->GetFood();
|
||||||
|
Health.m_Saturation = m_Player->GetFoodSaturation();
|
||||||
|
Send(Health);
|
||||||
|
//Send( cPacket_UpdateHealth( (short)m_Player->GetHealth() ) );
|
||||||
|
|
||||||
World->UnlockEntities();
|
World->UnlockEntities();
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ cPawn::cPawn()
|
|||||||
, m_FireDamageInterval(0.f)
|
, m_FireDamageInterval(0.f)
|
||||||
{
|
{
|
||||||
SetMaxHealth(20);
|
SetMaxHealth(20);
|
||||||
|
SetMaxFoodLevel(125);
|
||||||
}
|
}
|
||||||
|
|
||||||
cPawn::~cPawn()
|
cPawn::~cPawn()
|
||||||
@ -175,4 +176,10 @@ void cPawn::SetMaxHealth(short a_MaxHealth)
|
|||||||
m_Health = a_MaxHealth;
|
m_Health = a_MaxHealth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cPawn::SetMaxFoodLevel(short a_MaxFoodLevel)
|
||||||
|
{
|
||||||
|
m_MaxFoodLevel = a_MaxFoodLevel;
|
||||||
|
|
||||||
|
//Reset food level
|
||||||
|
m_FoodLevel = a_MaxFoodLevel;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "cEntity.h"
|
#include "cEntity.h"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
struct TakeDamageInfo //tolua_export
|
struct TakeDamageInfo //tolua_export
|
||||||
{ //tolua_export
|
{ //tolua_export
|
||||||
@ -37,9 +38,22 @@ public:
|
|||||||
virtual inline void SetMaxHealth(short a_MaxHealth);
|
virtual inline void SetMaxHealth(short a_MaxHealth);
|
||||||
virtual inline short GetMaxHealth() { return m_MaxHealth; }
|
virtual inline short GetMaxHealth() { return m_MaxHealth; }
|
||||||
|
|
||||||
|
//virtual inline void SetMaxFood(short a_MaxFood);
|
||||||
|
virtual inline short GetMaxFood() { return m_MaxFoodLevel/6; }
|
||||||
|
virtual inline short GetFood() { return m_FoodLevel/6; }
|
||||||
|
|
||||||
|
//virtual inline void SetMaxFoodSaturation(float a_MaxFoodSaturation);
|
||||||
|
virtual inline float GetMaxFoodSaturation() { return fmod(m_MaxFoodLevel, 6.f); }
|
||||||
|
virtual inline float GetFoodSaturation() { return fmod(m_FoodLevel, 6.f); }
|
||||||
|
|
||||||
|
virtual inline void SetMaxFoodLevel(short a_MaxFoodLevel);
|
||||||
|
virtual inline short GetMaxFoodLevel() { return m_MaxFoodLevel; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
short m_Health;
|
short m_Health;
|
||||||
|
short m_FoodLevel;
|
||||||
short m_MaxHealth;
|
short m_MaxHealth;
|
||||||
|
short m_MaxFoodLevel;
|
||||||
|
|
||||||
bool m_bBurnable;
|
bool m_bBurnable;
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const char* a_PlayerName)
|
|||||||
{
|
{
|
||||||
m_EntityType = E_PLAYER;
|
m_EntityType = E_PLAYER;
|
||||||
SetMaxHealth(20);
|
SetMaxHealth(20);
|
||||||
|
SetMaxFoodLevel(125);
|
||||||
m_Inventory = new cInventory( this );
|
m_Inventory = new cInventory( this );
|
||||||
cTimer t1;
|
cTimer t1;
|
||||||
m_LastPlayerListTime = t1.GetNowTime();
|
m_LastPlayerListTime = t1.GetNowTime();
|
||||||
@ -290,6 +291,22 @@ void cPlayer::Heal( int a_Health )
|
|||||||
|
|
||||||
cPacket_UpdateHealth Health;
|
cPacket_UpdateHealth Health;
|
||||||
Health.m_Health = m_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 );
|
m_ClientHandle->Send( Health );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -301,6 +318,8 @@ void cPlayer::TakeDamage( int a_Damage, cEntity* a_Instigator )
|
|||||||
|
|
||||||
cPacket_UpdateHealth Health;
|
cPacket_UpdateHealth Health;
|
||||||
Health.m_Health = m_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)
|
//TODO: Causes problems sometimes O.o (E.G. Disconnecting when attacked)
|
||||||
if(m_ClientHandle != 0)
|
if(m_ClientHandle != 0)
|
||||||
m_ClientHandle->Send( Health );
|
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_Health = (short)root.get("health", 0 ).asInt();
|
||||||
|
m_FoodLevel = (short)root.get("food", 0 ).asInt();
|
||||||
m_Inventory->LoadFromJson(root["inventory"]);
|
m_Inventory->LoadFromJson(root["inventory"]);
|
||||||
|
|
||||||
m_pState->LoadedWorldName = root.get("world", "world").asString();
|
m_pState->LoadedWorldName = root.get("world", "world").asString();
|
||||||
@ -804,6 +824,7 @@ bool cPlayer::SaveToDisk()
|
|||||||
root["rotation"] = JSON_PlayerRotation;
|
root["rotation"] = JSON_PlayerRotation;
|
||||||
root["inventory"] = JSON_Inventory;
|
root["inventory"] = JSON_Inventory;
|
||||||
root["health"] = m_Health;
|
root["health"] = m_Health;
|
||||||
|
root["food"] = m_FoodLevel;
|
||||||
root["world"] = GetWorld()->GetName();
|
root["world"] = GetWorld()->GetName();
|
||||||
|
|
||||||
Json::StyledWriter writer;
|
Json::StyledWriter writer;
|
||||||
|
@ -68,6 +68,7 @@ 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 );
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user