void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { if ((a_TDI.DamageType != dtInVoid) && (a_TDI.DamageType != dtPlugin)) { if (IsGameModeCreative()) { // No damage / health in creative mode if not void or plugin damage return; } } if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer())) { cPlayer* Attacker = (cPlayer*) a_TDI.Attacker; if ((m_Team != NULL) && (m_Team == Attacker->m_Team)) { if (!m_Team->AllowsFriendlyFire()) { // Friendly fire is disabled return; } } } super::DoTakeDamage(a_TDI); // Any kind of damage adds food exhaustion AddFoodExhaustion(0.3f); SendHealth(); }
void cPlayer::Heal(int a_Health) { if (m_Health < GetMaxHealth()) { m_Health = (short)std::min((int)a_Health + m_Health, (int)GetMaxHealth()); SendHealth(); } }
void cPlayer::HandleFood(void) { // Ref.: http://www.minecraftwiki.net/wiki/Hunger // Remember the food level before processing, for later comparison int LastFoodLevel = m_FoodLevel; // Heal or damage, based on the food level, using the m_FoodTickTimer: if ((m_FoodLevel > 17) || (m_FoodLevel <= 0)) { m_FoodTickTimer++; if (m_FoodTickTimer >= 80) { m_FoodTickTimer = 0; if (m_FoodLevel >= 17) { // Regenerate health from food, incur 3 pts of food exhaustion: Heal(1); m_FoodExhaustionLevel += 3; } else if (m_FoodLevel <= 0) { // Damage from starving TakeDamage(dtStarving, NULL, 1, 1, 0); } } } // Apply food poisoning food exhaustion: if (m_FoodPoisonedTicksRemaining > 0) { m_FoodPoisonedTicksRemaining--; m_FoodExhaustionLevel += 0.025; // 0.5 per second = 0.025 per tick } // Apply food exhaustion that has accumulated: if (m_FoodExhaustionLevel >= 4) { m_FoodExhaustionLevel -= 4; if (m_FoodSaturationLevel >= 1) { m_FoodSaturationLevel -= 1; } else { m_FoodLevel = std::max(m_FoodLevel - 1, 0); } } if (m_FoodLevel != LastFoodLevel) { SendHealth(); } }
void cPlayer::FoodPoison(int a_NumTicks) { bool HasBeenFoodPoisoned = (m_FoodPoisonedTicksRemaining > 0); m_FoodPoisonedTicksRemaining = std::max(m_FoodPoisonedTicksRemaining, a_NumTicks); if (!HasBeenFoodPoisoned) { // TODO: Send the poisoning indication to the client - how? SendHealth(); } }
bool cPlayer::Feed(int a_Food, double a_Saturation) { if (m_FoodLevel >= MAX_FOOD_LEVEL) { return false; } m_FoodLevel = std::min(a_Food + m_FoodLevel, (int)MAX_FOOD_LEVEL); m_FoodSaturationLevel = std::min(m_FoodSaturationLevel + a_Saturation, (double)m_FoodLevel); SendHealth(); return true; }
void cPlayer::SetFoodLevel(int a_FoodLevel) { int FoodLevel = Clamp(a_FoodLevel, 0, MAX_FOOD_LEVEL); if (cRoot::Get()->GetPluginManager()->CallHookPlayerFoodLevelChange(*this, FoodLevel)) { m_FoodSaturationLevel = 5.0; return; } m_FoodLevel = FoodLevel; SendHealth(); }
void cPlayer::FoodPoison(int a_NumTicks) { bool HasBeenFoodPoisoned = (m_FoodPoisonedTicksRemaining > 0); m_FoodPoisonedTicksRemaining = std::max(m_FoodPoisonedTicksRemaining, a_NumTicks); if (!HasBeenFoodPoisoned) { m_World->BroadcastRemoveEntityEffect(*this, E_EFFECT_HUNGER); SendHealth(); } else { m_World->BroadcastEntityEffect(*this, E_EFFECT_HUNGER, 0, 400); // Give the player the "Hunger" effect for 20 seconds. } }
void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { if (m_GameMode == eGameMode_Creative) { // No damage / health in creative mode return; } super::DoTakeDamage(a_TDI); // Any kind of damage adds food exhaustion AddFoodExhaustion(0.3f); SendHealth(); }
void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { if (a_TDI.DamageType != dtInVoid) { if (IsGameModeCreative()) { // No damage / health in creative mode return; } } super::DoTakeDamage(a_TDI); // Any kind of damage adds food exhaustion AddFoodExhaustion(0.3f); SendHealth(); }
bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { if ((a_TDI.DamageType != dtInVoid) && (a_TDI.DamageType != dtPlugin)) { if (IsGameModeCreative()) { // No damage / health in creative mode if not void or plugin damage return false; } } if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer())) { cPlayer * Attacker = (cPlayer *)a_TDI.Attacker; if ((m_Team != NULL) && (m_Team == Attacker->m_Team)) { if (!m_Team->AllowsFriendlyFire()) { // Friendly fire is disabled return false; } } } if (super::DoTakeDamage(a_TDI)) { // Any kind of damage adds food exhaustion AddFoodExhaustion(0.3f); SendHealth(); m_Stats.AddValue(statDamageTaken, (StatValue)floor(a_TDI.FinalDamage * 10 + 0.5)); return true; } return false; }
void cPlayer::SetFoodLevel(int a_FoodLevel) { m_FoodLevel = std::max(0, std::min(a_FoodLevel, (int)MAX_FOOD_LEVEL)); SendHealth(); }
void cPlayer::Heal(int a_Health) { super::Heal(a_Health); SendHealth(); }
void cPlayer::HandleFood(void) { // Ref.: http://www.minecraftwiki.net/wiki/Hunger if (IsGameModeCreative()) { // Hunger is disabled for Creative return; } // Remember the food level before processing, for later comparison int LastFoodLevel = m_FoodLevel; // Heal or damage, based on the food level, using the m_FoodTickTimer: if ((m_FoodLevel > 17) || (m_FoodLevel <= 0)) { m_FoodTickTimer++; if (m_FoodTickTimer >= 80) { m_FoodTickTimer = 0; if (m_FoodLevel >= 17) { // Regenerate health from food, incur 3 pts of food exhaustion: Heal(1); m_FoodExhaustionLevel += 3; } else if ((m_FoodLevel <= 0) && (m_Health > 1)) { // Damage from starving TakeDamage(dtStarving, NULL, 1, 1, 0); } } } // Apply food poisoning food exhaustion: if (m_FoodPoisonedTicksRemaining > 0) { m_FoodPoisonedTicksRemaining--; m_FoodExhaustionLevel += 0.025; // 0.5 per second = 0.025 per tick } else { m_World->BroadcastRemoveEntityEffect(*this, E_EFFECT_HUNGER); // Remove the "Hunger" effect. } // Apply food exhaustion that has accumulated: if (m_FoodExhaustionLevel >= 4) { m_FoodExhaustionLevel -= 4; if (m_FoodSaturationLevel >= 1) { m_FoodSaturationLevel -= 1; } else { m_FoodLevel = std::max(m_FoodLevel - 1, 0); } } if (m_FoodLevel != LastFoodLevel) { SendHealth(); } }