From 73b8be0fef6603b5dd3a101c26a4947669068d5e Mon Sep 17 00:00:00 2001 From: bibo38 Date: Sat, 31 Oct 2015 16:24:45 +0100 Subject: Implemented the FireResistence potion effects. This not only provides fire resistence, but also prevents blaze fireballs. See #2556 --- Server/Plugins/APIDump/APIDesc.lua | 5 +++-- src/Entities/Entity.cpp | 6 +++--- src/Entities/Entity.h | 2 +- src/Entities/FireChargeEntity.cpp | 7 +++++-- src/Entities/Pawn.cpp | 18 ++++++++++++++++++ src/Entities/Pawn.h | 7 +++++++ 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 2fcd02a17..6bca605c8 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -1822,8 +1822,9 @@ a_Player:OpenWindow(Window); TakeDamage = { Return = "" }, KilledBy = { Return = "" }, GetHealth = { Return = "number" }, - AddEntityEffect = { Params = "EffectType, {{cEntityEffect}}", Return = "", Notes = "Applies an entity effect" }, - RemoveEntityEffect = { Params = "EffectType", Return = "", Notes = "Removes a currently applied entity effect" }, + AddEntityEffect = { Params = "{{cEntityEffect|EffectType}}, {{cEntityEffect}}", Return = "", Notes = "Applies an entity effect" }, + RemoveEntityEffect = { Params = "{{cEntityEffect|EffectType}}", Return = "", Notes = "Removes a currently applied entity effect" }, + HasEntityEffect = { Return = "bool", Params = "{{cEntityEffect|EffectType}}", Notes = "Returns true, if the supplied entity effect type is currently applied" } ClearEntityEffects = { Return = "", Notes = "Removes all currently applied entity effects" }, }, Inherits = "cEntity", diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index a70ac6d1a..68e2cb1df 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1104,7 +1104,7 @@ void cEntity::TickBurning(cChunk & a_Chunk) m_TicksSinceLastBurnDamage++; if (m_TicksSinceLastBurnDamage >= BURN_TICKS_PER_DAMAGE) { - if (!m_IsFireproof) + if (!IsFireproof()) { TakeDamage(dtOnFire, nullptr, BURN_DAMAGE, 0); } @@ -1175,7 +1175,7 @@ void cEntity::TickBurning(cChunk & a_Chunk) m_TicksSinceLastLavaDamage++; if (m_TicksSinceLastLavaDamage >= LAVA_TICKS_PER_DAMAGE) { - if (!m_IsFireproof) + if (!IsFireproof()) { TakeDamage(dtLavaContact, nullptr, LAVA_DAMAGE, 0); } @@ -1196,7 +1196,7 @@ void cEntity::TickBurning(cChunk & a_Chunk) m_TicksSinceLastFireDamage++; if (m_TicksSinceLastFireDamage >= FIRE_TICKS_PER_DAMAGE) { - if (!m_IsFireproof) + if (!IsFireproof()) { TakeDamage(dtFireContact, nullptr, FIRE_DAMAGE, 0); } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 0161db387..0f8297d73 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -367,7 +367,7 @@ public: /** Sets whether the entity is fireproof */ void SetIsFireproof(bool a_IsFireproof); - bool IsFireproof(void) const { return m_IsFireproof; } + virtual bool IsFireproof(void) const { return m_IsFireproof; } /** Puts the entity on fire for the specified amount of ticks */ void StartBurning(int a_TicksLeftBurning); diff --git a/src/Entities/FireChargeEntity.cpp b/src/Entities/FireChargeEntity.cpp index 10d83b8dd..0db4b66d3 100644 --- a/src/Entities/FireChargeEntity.cpp +++ b/src/Entities/FireChargeEntity.cpp @@ -46,6 +46,9 @@ void cFireChargeEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hi Destroy(); Explode(a_HitPos.Floor()); - // TODO: Some entities are immune to hits - a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning + if (!a_EntityHit.IsFireproof()) + { + // TODO Damage Entity with 5 damage(from http://minecraft.gamepedia.com/Blaze#Blaze_fireball) + a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning + } } diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 2cd0f2f0e..9045f8595 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -61,6 +61,15 @@ void cPawn::KilledBy(TakeDamageInfo & a_TDI) +bool cPawn::IsFireproof(void) const +{ + return super::IsFireproof() || HasEntityEffect(cEntityEffect::effFireResistance); +} + + + + + void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, double a_DistanceModifier) { // Check if the plugins allow the addition: @@ -98,6 +107,15 @@ void cPawn::RemoveEntityEffect(cEntityEffect::eType a_EffectType) +bool cPawn::HasEntityEffect(cEntityEffect::eType a_EffectType) const +{ + return m_EntityEffects.find(a_EffectType) != m_EntityEffects.end(); +} + + + + + void cPawn::ClearEntityEffects() { // Iterate through this entity's applied effects diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index e3e99651d..40ce9b2dd 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -23,6 +23,8 @@ public: virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void KilledBy(TakeDamageInfo & a_TDI) override; + virtual bool IsFireproof(void) const override; + // tolua_begin /** Applies an entity effect @@ -39,6 +41,11 @@ public: */ void RemoveEntityEffect(cEntityEffect::eType a_EffectType); + /** Returns true, if the entity effect is currently applied + @param a_EffectType The entity effect to check + */ + bool HasEntityEffect(cEntityEffect::eType a_EffectType) const; + /** Removes all currently applied entity effects (used when drinking milk) */ void ClearEntityEffects(void); -- cgit v1.2.3