From c1692a2e3be114c2807fdaaea0fa4fcd3d4bbc5d Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 6 Jun 2014 00:16:33 -0700 Subject: Added classes for splash potions and wither skulls --- src/Entities/ProjectileEntity.cpp | 4 ++++ src/Entities/SplashPotionEntity.cpp | 37 ++++++++++++++++++++++++++++++++++ src/Entities/SplashPotionEntity.h | 34 +++++++++++++++++++++++++++++++ src/Entities/WitherSkullEntity.cpp | 40 +++++++++++++++++++++++++++++++++++++ src/Entities/WitherSkullEntity.h | 34 +++++++++++++++++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 src/Entities/SplashPotionEntity.cpp create mode 100644 src/Entities/SplashPotionEntity.h create mode 100644 src/Entities/WitherSkullEntity.cpp create mode 100644 src/Entities/WitherSkullEntity.h (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 95c494569..ee3890f23 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -18,9 +18,11 @@ #include "ThrownEnderPearlEntity.h" #include "ExpBottleEntity.h" #include "ThrownSnowballEntity.h" +#include "SplashPotionEntity.h" #include "FireChargeEntity.h" #include "FireworkEntity.h" #include "GhastFireballEntity.h" +#include "WitherSkullEntity.h" @@ -250,6 +252,8 @@ cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, case pkGhastFireball: return new cGhastFireballEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkFireCharge: return new cFireChargeEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkExpBottle: return new cExpBottleEntity (a_Creator, a_X, a_Y, a_Z, Speed); + case pkSplashPotion: return new cSplashPotionEntity (a_Creator, a_X, a_Y, a_Z, Speed); + case pkWitherSkull: return new cWitherSkullEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkFirework: { if (a_Item.m_FireworkItem.m_Colours.empty()) diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp new file mode 100644 index 000000000..c6be2baf7 --- /dev/null +++ b/src/Entities/SplashPotionEntity.cpp @@ -0,0 +1,37 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "SplashPotionEntity.h" +#include "../World.h" + + + + + +cSplashPotionEntity::cSplashPotionEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cSplashPotionEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + // TODO: Apply potion effect to entities nearby + Destroy(); +} + + + + + +void cSplashPotionEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + a_EntityHit.TakeDamage(dtRangedAttack, this, 0, 1); + + // TODO: Apply potion effect to entity and others nearby + + Destroy(true); +} diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h new file mode 100644 index 000000000..d82a7bfcd --- /dev/null +++ b/src/Entities/SplashPotionEntity.h @@ -0,0 +1,34 @@ +// +// SplashPotionEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cSplashPotionEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cSplashPotionEntity); + + cSplashPotionEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + +} ; // tolua_export diff --git a/src/Entities/WitherSkullEntity.cpp b/src/Entities/WitherSkullEntity.cpp new file mode 100644 index 000000000..ea78bba5d --- /dev/null +++ b/src/Entities/WitherSkullEntity.cpp @@ -0,0 +1,40 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "WitherSkullEntity.h" +#include "../World.h" + + + + + +cWitherSkullEntity::cWitherSkullEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cWitherSkullEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + // TODO: Explode + // TODO: Apply wither effect to entities nearby + Destroy(); +} + + + + + +void cWitherSkullEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + // TODO: If entity is Ender Crystal, destroy it + a_EntityHit.TakeDamage(dtRangedAttack, this, 0, 1); + + // TODO: Explode + // TODO: Apply wither effect to entity and others nearby + + Destroy(true); +} diff --git a/src/Entities/WitherSkullEntity.h b/src/Entities/WitherSkullEntity.h new file mode 100644 index 000000000..85ba55d4d --- /dev/null +++ b/src/Entities/WitherSkullEntity.h @@ -0,0 +1,34 @@ +// +// WitherSkullEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cWitherSkullEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cWitherSkullEntity); + + cWitherSkullEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + +} ; // tolua_export -- cgit v1.2.3 From 87b1bfaf2aa62bf600293d11d0b3c73cfe9f9e33 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 6 Jun 2014 00:17:49 -0700 Subject: Moved Effects.h to EntityEffects.h, added initial impl --- src/Entities/Effects.h | 30 ------------------------ src/Entities/EntityEffects.cpp | 25 ++++++++++++++++++++ src/Entities/EntityEffects.h | 53 ++++++++++++++++++++++++++++++++++++++++++ src/Entities/Pawn.cpp | 25 ++++++++++++++++++++ src/Entities/Pawn.h | 7 ++++++ src/Entities/Player.cpp | 6 ++--- 6 files changed, 113 insertions(+), 33 deletions(-) delete mode 100644 src/Entities/Effects.h create mode 100644 src/Entities/EntityEffects.cpp create mode 100644 src/Entities/EntityEffects.h (limited to 'src/Entities') diff --git a/src/Entities/Effects.h b/src/Entities/Effects.h deleted file mode 100644 index baf3302fb..000000000 --- a/src/Entities/Effects.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -// tolua_begin -enum ENUM_ENTITY_EFFECT -{ - E_EFFECT_SPEED = 1, - E_EFFECT_SLOWNESS = 2, - E_EFFECT_HASTE = 3, - E_EFFECT_MINING_FATIGUE = 4, - E_EFFECT_STENGTH = 5, - E_EFFECT_INSTANT_HEALTH = 6, - E_EFFECT_INSTANT_DAMAGE = 7, - E_EFFECT_JUMP_BOOST = 8, - E_EFFECT_NAUSEA = 9, - E_EFFECT_REGENERATION = 10, - E_EFFECT_RESISTANCE = 11, - E_EFFECT_FIRE_RESISTANCE = 12, - E_EFFECT_WATER_BREATHING = 13, - E_EFFECT_INVISIBILITY = 14, - E_EFFECT_BLINDNESS = 15, - E_EFFECT_NIGHT_VISION = 16, - E_EFFECT_HUNGER = 17, - E_EFFECT_WEAKNESS = 18, - E_EFFECT_POISON = 19, - E_EFFECT_WITHER = 20, - E_EFFECT_HEALTH_BOOST = 21, - E_EFFECT_ABSORPTION = 22, - E_EFFECT_SATURATION = 23, -} ; -// tolua_end diff --git a/src/Entities/EntityEffects.cpp b/src/Entities/EntityEffects.cpp new file mode 100644 index 000000000..3aa3fd1ed --- /dev/null +++ b/src/Entities/EntityEffects.cpp @@ -0,0 +1,25 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "EntityEffects.h" + + + + + +cEntityEffect::cEntityEffect(): + m_Ticks(0), + m_Intensity(0) +{ + +} + + + + + +cEntityEffect::cEntityEffect(int a_Ticks, short a_Intensity): + m_Ticks(a_Ticks), + m_Intensity(a_Intensity) +{ + +} diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h new file mode 100644 index 000000000..6ddd86b01 --- /dev/null +++ b/src/Entities/EntityEffects.h @@ -0,0 +1,53 @@ +#pragma once + +// tolua_begin +class cEntityEffect { +public: + + /** All types of entity effects (numbers correspond to IDs) */ + enum eType + { + efSpeed = 1, + efSlowness = 2, + efHaste = 3, + efMiningFatigue = 4, + efStrength = 5, + efInstantHealth = 6, + efInstantDamage = 7, + efJumpBoost = 8, + efNausia = 9, + efRegeneration = 10, + efResistance = 11, + efFireResistance = 12, + efWaterBreathing = 13, + efInvisibility = 14, + efBlindness = 15, + efNightVision = 16, + efHunger = 17, + efWeakness = 18, + efPoison = 19, + efWither = 20, + efHealthBoost = 21, + efAbsorption = 22, + efSaturation = 23, + } ; + + /** The duration of the effect */ + int m_Ticks; + + /** How strong the effect will be applied */ + short m_Intensity; + + /** + * An empty entity effect + */ + cEntityEffect(); + + /** + * An entity effect + * @param a_Ticks The duration of the effect + * @param a_Intensity How strong the effect will be applied + */ + cEntityEffect(int a_Ticks, short a_Intensity); +}; +// tolua_end diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index fffefd538..e1ddca27e 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -10,6 +10,7 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) : cEntity(a_EntityType, 0, 0, 0, a_Width, a_Height) , m_bBurnable(true) + , m_EntityEffects(std::map()) { } @@ -17,3 +18,27 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) +void cPawn::Tick(float a_Dt, cChunk & a_Chunk) +{ + + + super::Tick(a_Dt, a_Chunk); +} + + + + + +void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) +{ + m_EntityEffects[a_EffectType] = a_Effect; +} + + + + + +void cPawn::RemoveEntityEffect(cEntityEffect::eType a_EffectType) +{ + m_EntityEffects.erase(a_EffectType); +} diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index e76337d86..7824a06f8 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -2,6 +2,7 @@ #pragma once #include "Entity.h" +#include "EntityEffects.h" @@ -18,9 +19,15 @@ public: CLASS_PROTODEF(cPawn); cPawn(eEntityType a_EntityType, double a_Width, double a_Height); + + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + + void AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect); + void RemoveEntityEffect(cEntityEffect::eType a_EffectType); protected: bool m_bBurnable; + std::map m_EntityEffects; } ; // tolua_export diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index fdc0bb390..035973a16 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -584,12 +584,12 @@ void cPlayer::FoodPoison(int a_NumTicks) m_FoodPoisonedTicksRemaining = std::max(m_FoodPoisonedTicksRemaining, a_NumTicks); if (!HasBeenFoodPoisoned) { - m_World->BroadcastRemoveEntityEffect(*this, E_EFFECT_HUNGER); + m_World->BroadcastRemoveEntityEffect(*this, cEntityEffect::efHunger); SendHealth(); } else { - m_World->BroadcastEntityEffect(*this, E_EFFECT_HUNGER, 0, 400); // Give the player the "Hunger" effect for 20 seconds. + m_World->BroadcastEntityEffect(*this, cEntityEffect::efHunger, 0, 400); // Give the player the "Hunger" effect for 20 seconds. } } @@ -1930,7 +1930,7 @@ void cPlayer::HandleFood(void) } else { - m_World->BroadcastRemoveEntityEffect(*this, E_EFFECT_HUNGER); // Remove the "Hunger" effect. + m_World->BroadcastRemoveEntityEffect(*this, cEntityEffect::efHunger); // Remove the "Hunger" effect. } // Apply food exhaustion that has accumulated: -- cgit v1.2.3 From aa7b3f33b939e6a43af713549e7b3bf28d0f5ab5 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 6 Jun 2014 19:09:33 -0700 Subject: cPawn: Remove unused m_bBurnable --- src/Entities/Pawn.cpp | 1 - src/Entities/Pawn.h | 1 - 2 files changed, 2 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index e1ddca27e..13934d943 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -9,7 +9,6 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) : cEntity(a_EntityType, 0, 0, 0, a_Width, a_Height) - , m_bBurnable(true) , m_EntityEffects(std::map()) { } diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index 7824a06f8..a954f4a70 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -26,7 +26,6 @@ public: void RemoveEntityEffect(cEntityEffect::eType a_EffectType); protected: - bool m_bBurnable; std::map m_EntityEffects; } ; // tolua_export -- cgit v1.2.3 From 90145a95144a7895fe9a2d7bb1d5c7a192f3a0ad Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 6 Jun 2014 20:02:39 -0700 Subject: Added iterator on tick to manage entity effect duration --- src/Entities/Pawn.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 13934d943..95d1b113e 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -19,7 +19,22 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) void cPawn::Tick(float a_Dt, cChunk & a_Chunk) { - + // Iterate through this entity's applied effects + for (std::map::iterator iter = m_EntityEffects.begin(); + iter != m_EntityEffects.end(); + ++iter) + { + // Reduce the effect's duration + iter->second.m_Ticks--; + + // Remove effect if duration has elapsed + if (iter->second.m_Ticks <= 0) + { + RemoveEntityEffect(iter->first); + } + + // TODO: Check for discrepancies between client and server effect values + } super::Tick(a_Dt, a_Chunk); } @@ -31,6 +46,7 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk) void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) { m_EntityEffects[a_EffectType] = a_Effect; + //m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.m_Intensity, a_Effect.m_Ticks); } @@ -40,4 +56,5 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_E void cPawn::RemoveEntityEffect(cEntityEffect::eType a_EffectType) { m_EntityEffects.erase(a_EffectType); + //m_World->BroadcastRemoveEntityEffect(*this, a_EffectType); } -- cgit v1.2.3 From 481f05b011230cba42901df939306b803bd670b6 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 6 Jun 2014 21:48:20 -0700 Subject: Entity effects: Added handlers for entity effects Implemented hunger, instant health, damage, poison, regen Added "template" entity effect implementations --- src/Entities/Pawn.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++++++++ src/Entities/Pawn.h | 2 ++ src/Entities/Player.cpp | 51 +++++++++++++++++++------- src/Entities/Player.h | 3 ++ 4 files changed, 138 insertions(+), 13 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 95d1b113e..1d2542d58 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -24,6 +24,9 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk) iter != m_EntityEffects.end(); ++iter) { + // Apply entity effect + HandleEntityEffects(iter->first, iter->second); + // Reduce the effect's duration iter->second.m_Ticks--; @@ -58,3 +61,95 @@ void cPawn::RemoveEntityEffect(cEntityEffect::eType a_EffectType) m_EntityEffects.erase(a_EffectType); //m_World->BroadcastRemoveEntityEffect(*this, a_EffectType); } + + + + + +void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) +{ + switch (a_EffectType) + { + // Default effect behaviors + case cEntityEffect::efInstantHealth: + { + // Base heal = 6, doubles for every increase in intensity + Heal(6 * std::pow(2, a_Effect.GetIntensity())); + + // TODO: Harms undead + return; + } + case cEntityEffect::efInstantDamage: + { + // Base damage = 6, doubles for every increase in intensity + int damage = 6 * std::pow(2, a_Effect.GetIntensity()); + TakeDamage(dtPotionOfHarming, a_Effect.GetUser(), damage, 0); + + // TODO: Heals undead + return; + } + case cEntityEffect::efStrength: + { + // TODO: Implement me! + return; + } + case cEntityEffect::efWeakness: + { + // Damage reduction = 0.5 damage, multiplied by potion level (Weakness II = 1 damage) + //double dmg_reduc = 0.5 * (a_Effect.GetIntensity() + 1); + + // TODO: Implement me! + // TODO: Weakened villager zombies can be turned back to villagers with the god apple + return; + } + case cEntityEffect::efRegeneration: + { + // Regen frequency = 50 ticks, divided by potion level (Regen II = 25 ticks) + int frequency = std::floor(50.0 / (double)(a_Effect.GetIntensity() + 1)); + + static short counter = 0; + if (++counter >= frequency) + { + Heal(1); + counter = 0; + } + + // TODO: Doesn't effect undead + return; + } + case cEntityEffect::efPoison: + { + // Poison frequency = 25 ticks, divided by potion level (Poison II = 25 ticks) + int frequency = std::floor(25.0 / (double)(a_Effect.GetIntensity() + 1)); + + static short counter = 0; + if (++counter >= frequency) + { + // Cannot take poison damage when health is at 1 + if (GetHealth() > 1) + { + TakeDamage(dtPoisoning, a_Effect.GetUser(), 1, 0); + } + counter = 0; + } + + // TODO: Doesn't effect undead or spiders + return; + } + case cEntityEffect::efFireResistance: + { + // TODO: Implement me! + return; + } + case cEntityEffect::efSpeed: + { + // TODO: Implement me! + return; + } + case cEntityEffect::efSlowness: + { + // TODO: Implement me! + return; + } + } +} diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index a954f4a70..f7d7213ff 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -27,6 +27,8 @@ public: protected: std::map m_EntityEffects; + + virtual void HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect); } ; // tolua_export diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 035973a16..95ee8b39d 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -584,12 +584,11 @@ void cPlayer::FoodPoison(int a_NumTicks) m_FoodPoisonedTicksRemaining = std::max(m_FoodPoisonedTicksRemaining, a_NumTicks); if (!HasBeenFoodPoisoned) { - m_World->BroadcastRemoveEntityEffect(*this, cEntityEffect::efHunger); SendHealth(); } else { - m_World->BroadcastEntityEffect(*this, cEntityEffect::efHunger, 0, 400); // Give the player the "Hunger" effect for 20 seconds. + AddEntityEffect(cEntityEffect::efHunger, cEntityEffect(0, 400)); // Give the player the "Hunger" effect for 20 seconds. } } @@ -1887,6 +1886,43 @@ void cPlayer::TickBurning(cChunk & a_Chunk) +void cPlayer::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) +{ + switch (a_EffectType) + { + // Effects whose behaviors are overridden + case cEntityEffect::efMiningFatigue: + { + // TODO: Implement me! + return; + } + case cEntityEffect::efHunger: + { + m_FoodExhaustionLevel += 0.025; // 0.5 per second = 0.025 per tick + return; + } + case cEntityEffect::efSaturation: + { + // Increase saturation 1 per tick, adds 1 for every increase in level + m_FoodSaturationLevel += (1 + a_Effect.GetIntensity()); + return; + } + + // Client-side-only effects + case cEntityEffect::efNausia: + case cEntityEffect::efNightVision: + { + return; + } + } + + super::HandleEntityEffects(a_EffectType, a_Effect); +} + + + + + void cPlayer::HandleFood(void) { // Ref.: http://www.minecraftwiki.net/wiki/Hunger @@ -1921,17 +1957,6 @@ void cPlayer::HandleFood(void) } } } - - // 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, cEntityEffect::efHunger); // Remove the "Hunger" effect. - } // Apply food exhaustion that has accumulated: if (m_FoodExhaustionLevel >= 4) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index b2142a18b..88f732096 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -526,6 +526,9 @@ protected: /** Stops players from burning in creative mode */ virtual void TickBurning(cChunk & a_Chunk) override; + /** Called each tick to handle entity effects*/ + virtual void HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) override; + /** Called in each tick to handle food-related processing */ void HandleFood(void); -- cgit v1.2.3 From 2123173202554487386697625342b7ba21744960 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 6 Jun 2014 21:55:23 -0700 Subject: Player: Removed food-poisoning-specific code, set duration to 30 seconds http://minecraft.gamepedia.com/Hunger#Behavior --- src/Entities/Player.cpp | 21 +-------------------- src/Entities/Player.h | 7 +------ 2 files changed, 2 insertions(+), 26 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 95ee8b39d..3a1ebf3f9 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -40,7 +40,6 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_FoodSaturationLevel(5) , m_FoodTickTimer(0) , m_FoodExhaustionLevel(0) - , m_FoodPoisonedTicksRemaining(0) , m_LastJumpHeight(0) , m_LastGroundHeight(0) , m_bTouchGround(false) @@ -551,15 +550,6 @@ void cPlayer::SetFoodExhaustionLevel(double a_FoodExhaustionLevel) -void cPlayer::SetFoodPoisonedTicksRemaining(int a_FoodPoisonedTicksRemaining) -{ - m_FoodPoisonedTicksRemaining = a_FoodPoisonedTicksRemaining; -} - - - - - bool cPlayer::Feed(int a_Food, double a_Saturation) { if (m_FoodLevel >= MAX_FOOD_LEVEL) @@ -580,16 +570,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation) void cPlayer::FoodPoison(int a_NumTicks) { - bool HasBeenFoodPoisoned = (m_FoodPoisonedTicksRemaining > 0); - m_FoodPoisonedTicksRemaining = std::max(m_FoodPoisonedTicksRemaining, a_NumTicks); - if (!HasBeenFoodPoisoned) - { - SendHealth(); - } - else - { - AddEntityEffect(cEntityEffect::efHunger, cEntityEffect(0, 400)); // Give the player the "Hunger" effect for 20 seconds. - } + AddEntityEffect(cEntityEffect::efHunger, cEntityEffect(0, a_NumTicks)); } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 88f732096..83114a4dd 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -267,7 +267,6 @@ public: double GetFoodSaturationLevel (void) const { return m_FoodSaturationLevel; } int GetFoodTickTimer (void) const { return m_FoodTickTimer; } double GetFoodExhaustionLevel (void) const { return m_FoodExhaustionLevel; } - int GetFoodPoisonedTicksRemaining(void) const { return m_FoodPoisonedTicksRemaining; } /** Returns true if the player is satiated, i. e. their foodlevel is at the max and they cannot eat anymore */ bool IsSatiated(void) const { return (m_FoodLevel >= MAX_FOOD_LEVEL); } @@ -276,7 +275,6 @@ public: void SetFoodSaturationLevel (double a_FoodSaturationLevel); void SetFoodTickTimer (int a_FoodTickTimer); void SetFoodExhaustionLevel (double a_FoodExhaustionLevel); - void SetFoodPoisonedTicksRemaining(int a_FoodPoisonedTicksRemaining); /** Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed, false if player "full" */ bool Feed(int a_Food, double a_Saturation); @@ -287,7 +285,7 @@ public: m_FoodExhaustionLevel += a_Exhaustion; } - /** Starts the food poisoning for the specified amount of ticks; if already foodpoisoned, sets FoodPoisonedTicksRemaining to the larger of the two */ + /** Starts the food poisoning for the specified amount of ticks */ void FoodPoison(int a_NumTicks); /** Returns true if the player is currently in the process of eating the currently equipped item */ @@ -442,9 +440,6 @@ protected: /** A "buffer" which adds up hunger before it is substracted from m_FoodSaturationLevel or m_FoodLevel. Each action adds a little */ double m_FoodExhaustionLevel; - /** Number of ticks remaining for the foodpoisoning effect; zero if not foodpoisoned */ - int m_FoodPoisonedTicksRemaining; - float m_LastJumpHeight; float m_LastGroundHeight; bool m_bTouchGround; -- cgit v1.2.3 From a9a4c9c6b25438aaebdeef03c323e9aa4a0348c2 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 6 Jun 2014 23:05:29 -0700 Subject: EntityEffect: read-only getters, added user and distance modifier fields User: the pawn that uses or produces the entity effect (drinks/throws a potion) Distance modifier: the potency modifier from splash potion effectivity radius --- src/Entities/EntityEffects.cpp | 14 +++++++++----- src/Entities/EntityEffects.h | 30 +++++++++++++++++++++++++----- src/Entities/Player.cpp | 2 +- 3 files changed, 35 insertions(+), 11 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffects.cpp b/src/Entities/EntityEffects.cpp index 3aa3fd1ed..c74463bfa 100644 --- a/src/Entities/EntityEffects.cpp +++ b/src/Entities/EntityEffects.cpp @@ -1,14 +1,16 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "EntityEffects.h" - +#include "Pawn.h" cEntityEffect::cEntityEffect(): m_Ticks(0), - m_Intensity(0) + m_Intensity(0), + m_User(NULL), + m_DistanceModifier(1) { } @@ -17,9 +19,11 @@ cEntityEffect::cEntityEffect(): -cEntityEffect::cEntityEffect(int a_Ticks, short a_Intensity): +cEntityEffect::cEntityEffect(int a_Ticks, short a_Intensity, cPawn *a_User, double a_DistanceModifier): m_Ticks(a_Ticks), - m_Intensity(a_Intensity) + m_Intensity(a_Intensity), + m_User(a_User), + m_DistanceModifier(a_DistanceModifier) { -} +} \ No newline at end of file diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h index 6ddd86b01..2bda2e104 100644 --- a/src/Entities/EntityEffects.h +++ b/src/Entities/EntityEffects.h @@ -1,5 +1,7 @@ #pragma once +class cPawn; + // tolua_begin class cEntityEffect { public: @@ -35,8 +37,14 @@ public: /** The duration of the effect */ int m_Ticks; - /** How strong the effect will be applied */ - short m_Intensity; + /** Returns how strong the effect will be applied */ + short GetIntensity() { return m_Intensity; } + + /** Returns the pawn that used this entity effect */ + cPawn *GetUser() { return m_User; } + + /** Returns the distance modifier for affecting potency */ + double GetDistanceModifier() { return m_DistanceModifier; } /** * An empty entity effect @@ -45,9 +53,21 @@ public: /** * An entity effect - * @param a_Ticks The duration of the effect - * @param a_Intensity How strong the effect will be applied + * @param a_Ticks The duration of the effect + * @param a_Intensity How strong the effect will be applied + * @param a_User The pawn that used this entity effect + * @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */ - cEntityEffect(int a_Ticks, short a_Intensity); + cEntityEffect(int a_Ticks, short a_Intensity, cPawn *a_User, double a_DistanceModifier = 1); + +private: + /** How strong the effect will be applied */ + short m_Intensity; + + /** The pawn that used this entity effect */ + cPawn *m_User; + + /** The distance modifier for affecting potency */ + double m_DistanceModifier; }; // tolua_end diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 3a1ebf3f9..d075957fe 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -570,7 +570,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation) void cPlayer::FoodPoison(int a_NumTicks) { - AddEntityEffect(cEntityEffect::efHunger, cEntityEffect(0, a_NumTicks)); + AddEntityEffect(cEntityEffect::efHunger, cEntityEffect(0, a_NumTicks, NULL)); } -- cgit v1.2.3 From e98ffccd80ae05d09b40d5edd407428515b14406 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 7 Jun 2014 00:54:03 -0700 Subject: Pawn: Enabled entity effect broadcast, added typedef Typedef'd std::map to tEffectMap --- src/Entities/Pawn.cpp | 7 ++++--- src/Entities/Pawn.h | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 1d2542d58..1f93e59fa 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Pawn.h" +#include "../World.h" @@ -20,7 +21,7 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) void cPawn::Tick(float a_Dt, cChunk & a_Chunk) { // Iterate through this entity's applied effects - for (std::map::iterator iter = m_EntityEffects.begin(); + for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end(); ++iter) { @@ -49,7 +50,7 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk) void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) { m_EntityEffects[a_EffectType] = a_Effect; - //m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.m_Intensity, a_Effect.m_Ticks); + m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), a_Effect.m_Ticks); } @@ -59,7 +60,7 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_E void cPawn::RemoveEntityEffect(cEntityEffect::eType a_EffectType) { m_EntityEffects.erase(a_EffectType); - //m_World->BroadcastRemoveEntityEffect(*this, a_EffectType); + m_World->BroadcastRemoveEntityEffect(*this, a_EffectType); } diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index f7d7213ff..1a897c958 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -26,7 +26,8 @@ public: void RemoveEntityEffect(cEntityEffect::eType a_EffectType); protected: - std::map m_EntityEffects; + typedef std::map tEffectMap; + tEffectMap m_EntityEffects; virtual void HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect); } ; // tolua_export -- cgit v1.2.3 From 615152eb8c6c88083f7b9eac57ec07147f34a6d6 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 7 Jun 2014 02:02:20 -0700 Subject: Pawn.cpp: fixed effect iterator BAD_ACCESS Erasure was occurring before the iterator increased, causing a bad access. Solved by storing map pairs in variables and manually updating iterator before erasure. Fixed mix-up in function arguments on food poisoning --- src/Entities/Pawn.cpp | 21 +++++++++++++-------- src/Entities/Player.cpp | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 1f93e59fa..93f6a69bc 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -10,7 +10,7 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) : cEntity(a_EntityType, 0, 0, 0, a_Width, a_Height) - , m_EntityEffects(std::map()) + , m_EntityEffects(tEffectMap()) { } @@ -21,20 +21,25 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) void cPawn::Tick(float a_Dt, cChunk & a_Chunk) { // Iterate through this entity's applied effects - for (tEffectMap::iterator iter = m_EntityEffects.begin(); - iter != m_EntityEffects.end(); - ++iter) + for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();) { + // Copies values to prevent pesky wrong accesses and erasures + cEntityEffect::eType effect_type = iter->first; + cEntityEffect &effect_values = iter->second; + // Apply entity effect - HandleEntityEffects(iter->first, iter->second); + HandleEntityEffects(effect_type, effect_values); // Reduce the effect's duration - iter->second.m_Ticks--; + effect_values.m_Ticks--; + + // Iterates (must be called before any possible erasure) + ++iter; // Remove effect if duration has elapsed - if (iter->second.m_Ticks <= 0) + if (effect_values.m_Ticks <= 0) { - RemoveEntityEffect(iter->first); + RemoveEntityEffect(effect_type); } // TODO: Check for discrepancies between client and server effect values diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index d075957fe..67449f800 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -570,7 +570,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation) void cPlayer::FoodPoison(int a_NumTicks) { - AddEntityEffect(cEntityEffect::efHunger, cEntityEffect(0, a_NumTicks, NULL)); + AddEntityEffect(cEntityEffect::efHunger, cEntityEffect(a_NumTicks, 0, NULL)); } -- cgit v1.2.3 From 1eb04a48ee3ec4114adc4334e6fbcc7561834025 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 7 Jun 2014 13:45:00 -0700 Subject: Implemented milk, added documentation to Pawn.h --- src/Entities/Pawn.cpp | 20 ++++++++++++++++++++ src/Entities/Pawn.h | 15 +++++++++++++++ src/Entities/Player.cpp | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 93f6a69bc..4c840e6e1 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -72,6 +72,26 @@ void cPawn::RemoveEntityEffect(cEntityEffect::eType a_EffectType) +void cPawn::ClearEntityEffects() +{ + // Iterate through this entity's applied effects + for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();) + { + // Copy values to prevent pesky wrong erasures + cEntityEffect::eType effect_type = iter->first; + + // Iterates (must be called before any possible erasure) + ++iter; + + // Remove effect + RemoveEntityEffect(effect_type); + } +} + + + + + void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) { switch (a_EffectType) diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index 1a897c958..857488901 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -22,13 +22,28 @@ public: virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + /** Applies an entity effect + * @param a_EffectType The entity effect to apply + * @param a_Effect The parameters of the effect + */ void AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect); + + /** Removes a currently applied entity effect + * @param a_EffectType The entity effect to remove + */ void RemoveEntityEffect(cEntityEffect::eType a_EffectType); + + /** Removes all currently applied entity effects (used when drinking milk) */ + void ClearEntityEffects(); protected: typedef std::map tEffectMap; tEffectMap m_EntityEffects; + /** Applies entity effect effects + * @param a_EffectType The selected entity effect + * @param a_Effect The parameters of the selected entity effect + */ virtual void HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect); } ; // tolua_export diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 67449f800..b4b344584 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -552,7 +552,7 @@ void cPlayer::SetFoodExhaustionLevel(double a_FoodExhaustionLevel) bool cPlayer::Feed(int a_Food, double a_Saturation) { - if (m_FoodLevel >= MAX_FOOD_LEVEL) + if (IsSatiated()) { return false; } -- cgit v1.2.3 From 2185c72c2ca2d66b238d7d3234c173bd820d32ac Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 7 Jun 2014 16:32:37 -0700 Subject: Implemented drinkable potions, noeffect entity effect, Clears entity effects on death --- src/Entities/EntityEffects.h | 1 + src/Entities/Pawn.cpp | 14 ++++++++++++++ src/Entities/Pawn.h | 1 + 3 files changed, 16 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h index 2bda2e104..137eb6480 100644 --- a/src/Entities/EntityEffects.h +++ b/src/Entities/EntityEffects.h @@ -9,6 +9,7 @@ public: /** All types of entity effects (numbers correspond to IDs) */ enum eType { + efNoEffect = 0, efSpeed = 1, efSlowness = 2, efHaste = 3, diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 4c840e6e1..5cf270006 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -52,8 +52,22 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk) +void cPawn::KilledBy(cEntity *a_Killer) +{ + ClearEntityEffects(); +} + + + + + void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) { + if (a_EffectType == cEntityEffect::efNoEffect) + { + return; + } + m_EntityEffects[a_EffectType] = a_Effect; m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), a_Effect.m_Ticks); } diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index 857488901..47fb691f4 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -21,6 +21,7 @@ public: cPawn(eEntityType a_EntityType, double a_Width, double a_Height); virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void KilledBy(cEntity * a_Killer) override; /** Applies an entity effect * @param a_EffectType The entity effect to apply -- cgit v1.2.3 From 8eceaf9b0cadbc253e46cdcbf8a7b5e8d6070846 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 7 Jun 2014 18:48:33 -0700 Subject: Player: made healing instantaneous --- src/Entities/Entity.h | 2 +- src/Entities/Player.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 2df66e353..b8f1f4c1c 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -315,7 +315,7 @@ public: virtual void Killed(cEntity * a_Victim) {} /// Heals the specified amount of HPs - void Heal(int a_HitPoints); + virtual void Heal(int a_HitPoints); /// Returns the health of this entity int GetHealth(void) const { return m_Health; } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 83114a4dd..3aba3289d 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -261,7 +261,7 @@ public: void TossPickup(const cItem & a_Item); /** Heals the player by the specified amount of HPs (positive only); sends health update */ - void Heal(int a_Health); + virtual void Heal(int a_Health) override; int GetFoodLevel (void) const { return m_FoodLevel; } double GetFoodSaturationLevel (void) const { return m_FoodSaturationLevel; } -- cgit v1.2.3 From 5803094d7d0a852568c45c450dc2cc52e6c7d681 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 7 Jun 2014 19:58:41 -0700 Subject: Entity: only fire critical hit if damage type is physical --- src/Entities/Entity.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index ee7ce06ac..ba829bf6b 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -310,7 +310,8 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) cPlayer * Player = (cPlayer *)a_TDI.Attacker; // IsOnGround() only is false if the player is moving downwards - if (!Player->IsOnGround()) // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain) + // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain) + if (!Player->IsOnGround() && (a_TDI.DamageType == dtAttack || a_TDI.DamageType == dtArrowAttack)) { a_TDI.FinalDamage += 2; m_World->BroadcastEntityAnimation(*this, 4); // Critical hit -- cgit v1.2.3 From 58f35af6e71f11844b9c6c1d1ebd2d7390439cca Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 7 Jun 2014 21:56:01 -0700 Subject: Added splash potion functionality --- src/Entities/EntityEffects.h | 4 +++ src/Entities/Pawn.cpp | 7 +++-- src/Entities/ProjectileEntity.cpp | 2 -- src/Entities/SplashPotionEntity.cpp | 58 +++++++++++++++++++++++++++++++++---- src/Entities/SplashPotionEntity.h | 30 +++++++++++++++++-- 5 files changed, 87 insertions(+), 14 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h index 137eb6480..e6b5bdd5d 100644 --- a/src/Entities/EntityEffects.h +++ b/src/Entities/EntityEffects.h @@ -47,6 +47,10 @@ public: /** Returns the distance modifier for affecting potency */ double GetDistanceModifier() { return m_DistanceModifier; } + void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; } + void SetUser(cPawn *a_User) { m_User = a_User; } + void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; } + /** * An empty entity effect */ diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 5cf270006..5cd493a06 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -69,7 +69,8 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_E } m_EntityEffects[a_EffectType] = a_Effect; - m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), a_Effect.m_Ticks); + m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), + a_Effect.m_Ticks * a_Effect.GetDistanceModifier()); } @@ -114,7 +115,7 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect case cEntityEffect::efInstantHealth: { // Base heal = 6, doubles for every increase in intensity - Heal(6 * std::pow(2, a_Effect.GetIntensity())); + Heal(6 * std::pow(2, a_Effect.GetIntensity()) * a_Effect.GetDistanceModifier()); // TODO: Harms undead return; @@ -123,7 +124,7 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect { // Base damage = 6, doubles for every increase in intensity int damage = 6 * std::pow(2, a_Effect.GetIntensity()); - TakeDamage(dtPotionOfHarming, a_Effect.GetUser(), damage, 0); + TakeDamage(dtPotionOfHarming, a_Effect.GetUser(), damage * a_Effect.GetDistanceModifier(), 0); // TODO: Heals undead return; diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index ee3890f23..664f929f6 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -18,7 +18,6 @@ #include "ThrownEnderPearlEntity.h" #include "ExpBottleEntity.h" #include "ThrownSnowballEntity.h" -#include "SplashPotionEntity.h" #include "FireChargeEntity.h" #include "FireworkEntity.h" #include "GhastFireballEntity.h" @@ -252,7 +251,6 @@ cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, case pkGhastFireball: return new cGhastFireballEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkFireCharge: return new cFireChargeEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkExpBottle: return new cExpBottleEntity (a_Creator, a_X, a_Y, a_Z, Speed); - case pkSplashPotion: return new cSplashPotionEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkWitherSkull: return new cWitherSkullEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkFirework: { diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index c6be2baf7..5dcea2385 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -1,14 +1,17 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "SplashPotionEntity.h" -#include "../World.h" +#include "Player.h" -cSplashPotionEntity::cSplashPotionEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +cSplashPotionEntity::cSplashPotionEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed, cEntityEffect::eType a_EntityEffectType, cEntityEffect a_EntityEffect, int a_PotionName) : + super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), + m_EntityEffectType(a_EntityEffectType), + m_EntityEffect(a_EntityEffect), + m_PotionName(a_PotionName) { SetSpeed(a_Speed); } @@ -19,7 +22,7 @@ super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) void cSplashPotionEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { - // TODO: Apply potion effect to entities nearby + Splash(a_HitPos); Destroy(); } @@ -30,8 +33,51 @@ void cSplashPotionEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace void cSplashPotionEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { a_EntityHit.TakeDamage(dtRangedAttack, this, 0, 1); + Splash(a_HitPos); + Destroy(true); +} + + + + + +void cSplashPotionEntity::Splash(const Vector3d & a_HitPos) +{ + cSplashPotionCallback Callback(a_HitPos, m_EntityEffectType, m_EntityEffect); + m_World->ForEachPlayer(Callback); + // TODO: Should be for each pawn - // TODO: Apply potion effect to entity and others nearby + m_World->BroadcastSoundParticleEffect(2002, a_HitPos.x, a_HitPos.y, a_HitPos.z, m_PotionName); +} + + + + + +cSplashPotionEntity::cSplashPotionCallback::cSplashPotionCallback(const Vector3d & a_HitPos, cEntityEffect::eType &a_EntityEffectType, cEntityEffect &a_EntityEffect): + m_HitPos(a_HitPos), + m_EntityEffectType(a_EntityEffectType), + m_EntityEffect(a_EntityEffect) +{ - Destroy(true); +} + + + + + +bool cSplashPotionEntity::cSplashPotionCallback::Item(cPlayer * a_Player) +{ + double distance_splash = (a_Player->GetPosition() - m_HitPos).Length(); + if (distance_splash < 20) + { + // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash. + // TODO: better equation + double reduction = -0.25 * distance_splash + 1.0; + if (reduction < 0) reduction = 0; + + m_EntityEffect.SetDistanceModifier(reduction); + a_Player->AddEntityEffect(m_EntityEffectType, m_EntityEffect); + } + return false; } diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h index d82a7bfcd..b64b668a5 100644 --- a/src/Entities/SplashPotionEntity.h +++ b/src/Entities/SplashPotionEntity.h @@ -5,7 +5,8 @@ #pragma once #include "ProjectileEntity.h" - +#include "EntityEffects.h" +#include "../World.h" @@ -13,7 +14,7 @@ // tolua_begin class cSplashPotionEntity : -public cProjectileEntity + public cProjectileEntity { typedef cProjectileEntity super; @@ -23,7 +24,7 @@ public: CLASS_PROTODEF(cSplashPotionEntity); - cSplashPotionEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + cSplashPotionEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed, cEntityEffect::eType a_EntityEffectType, cEntityEffect a_EntityEffect, int a_PotionName); protected: @@ -31,4 +32,27 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + /** Splashes the potion, fires its particle effects and sounds + * @param a_HitPos The position where the potion will splash + */ + void Splash(const Vector3d & a_HitPos); + + cEntityEffect::eType m_EntityEffectType; + cEntityEffect m_EntityEffect; + int m_PotionName; + + class cSplashPotionCallback : + public cPlayerListCallback + { + public: + cSplashPotionCallback(const Vector3d & a_HitPos, cEntityEffect::eType &a_EntityEffectType, cEntityEffect &a_EntityEffect); + + virtual bool Item(cPlayer * a_Player) override; + + private: + const Vector3d &m_HitPos; + cEntityEffect::eType &m_EntityEffectType; + cEntityEffect &m_EntityEffect; + }; + } ; // tolua_export -- cgit v1.2.3 From 73cea7065db458da7704917788ac80b75e042d6e Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 8 Jun 2014 03:27:22 -0700 Subject: Entity effect type: use 'eff' as a prefix instead of 'ef' --- src/Entities/EntityEffects.h | 48 +++++++++++++++++++------------------- src/Entities/Pawn.cpp | 20 ++++++++-------- src/Entities/Player.cpp | 12 +++++----- src/Entities/WitherSkullEntity.cpp | 2 +- 4 files changed, 41 insertions(+), 41 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h index e6b5bdd5d..26d2c92e5 100644 --- a/src/Entities/EntityEffects.h +++ b/src/Entities/EntityEffects.h @@ -9,30 +9,30 @@ public: /** All types of entity effects (numbers correspond to IDs) */ enum eType { - efNoEffect = 0, - efSpeed = 1, - efSlowness = 2, - efHaste = 3, - efMiningFatigue = 4, - efStrength = 5, - efInstantHealth = 6, - efInstantDamage = 7, - efJumpBoost = 8, - efNausia = 9, - efRegeneration = 10, - efResistance = 11, - efFireResistance = 12, - efWaterBreathing = 13, - efInvisibility = 14, - efBlindness = 15, - efNightVision = 16, - efHunger = 17, - efWeakness = 18, - efPoison = 19, - efWither = 20, - efHealthBoost = 21, - efAbsorption = 22, - efSaturation = 23, + effNoEffect = 0, + effSpeed = 1, + effSlowness = 2, + effHaste = 3, + effMiningFatigue = 4, + effStrength = 5, + effInstantHealth = 6, + effInstantDamage = 7, + effJumpBoost = 8, + effNausea = 9, + effRegeneration = 10, + effResistance = 11, + effFireResistance = 12, + effWaterBreathing = 13, + effInvisibility = 14, + effBlindness = 15, + effNightVision = 16, + effHunger = 17, + effWeakness = 18, + effPoison = 19, + effWither = 20, + effHealthBoost = 21, + effAbsorption = 22, + effSaturation = 23, } ; /** The duration of the effect */ diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 5cd493a06..a1f24138d 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -63,7 +63,7 @@ void cPawn::KilledBy(cEntity *a_Killer) void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) { - if (a_EffectType == cEntityEffect::efNoEffect) + if (a_EffectType == cEntityEffect::effNoEffect) { return; } @@ -112,7 +112,7 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect switch (a_EffectType) { // Default effect behaviors - case cEntityEffect::efInstantHealth: + case cEntityEffect::effInstantHealth: { // Base heal = 6, doubles for every increase in intensity Heal(6 * std::pow(2, a_Effect.GetIntensity()) * a_Effect.GetDistanceModifier()); @@ -120,7 +120,7 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect // TODO: Harms undead return; } - case cEntityEffect::efInstantDamage: + case cEntityEffect::effInstantDamage: { // Base damage = 6, doubles for every increase in intensity int damage = 6 * std::pow(2, a_Effect.GetIntensity()); @@ -129,12 +129,12 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect // TODO: Heals undead return; } - case cEntityEffect::efStrength: + case cEntityEffect::effStrength: { // TODO: Implement me! return; } - case cEntityEffect::efWeakness: + case cEntityEffect::effWeakness: { // Damage reduction = 0.5 damage, multiplied by potion level (Weakness II = 1 damage) //double dmg_reduc = 0.5 * (a_Effect.GetIntensity() + 1); @@ -143,7 +143,7 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect // TODO: Weakened villager zombies can be turned back to villagers with the god apple return; } - case cEntityEffect::efRegeneration: + case cEntityEffect::effRegeneration: { // Regen frequency = 50 ticks, divided by potion level (Regen II = 25 ticks) int frequency = std::floor(50.0 / (double)(a_Effect.GetIntensity() + 1)); @@ -158,7 +158,7 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect // TODO: Doesn't effect undead return; } - case cEntityEffect::efPoison: + case cEntityEffect::effPoison: { // Poison frequency = 25 ticks, divided by potion level (Poison II = 25 ticks) int frequency = std::floor(25.0 / (double)(a_Effect.GetIntensity() + 1)); @@ -177,17 +177,17 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect // TODO: Doesn't effect undead or spiders return; } - case cEntityEffect::efFireResistance: + case cEntityEffect::effFireResistance: { // TODO: Implement me! return; } - case cEntityEffect::efSpeed: + case cEntityEffect::effSpeed: { // TODO: Implement me! return; } - case cEntityEffect::efSlowness: + case cEntityEffect::effSlowness: { // TODO: Implement me! return; diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index b4b344584..6bceab26f 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -570,7 +570,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation) void cPlayer::FoodPoison(int a_NumTicks) { - AddEntityEffect(cEntityEffect::efHunger, cEntityEffect(a_NumTicks, 0, NULL)); + AddEntityEffect(cEntityEffect::effHunger, cEntityEffect(a_NumTicks, 0, NULL)); } @@ -1872,17 +1872,17 @@ void cPlayer::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffe switch (a_EffectType) { // Effects whose behaviors are overridden - case cEntityEffect::efMiningFatigue: + case cEntityEffect::effMiningFatigue: { // TODO: Implement me! return; } - case cEntityEffect::efHunger: + case cEntityEffect::effHunger: { m_FoodExhaustionLevel += 0.025; // 0.5 per second = 0.025 per tick return; } - case cEntityEffect::efSaturation: + case cEntityEffect::effSaturation: { // Increase saturation 1 per tick, adds 1 for every increase in level m_FoodSaturationLevel += (1 + a_Effect.GetIntensity()); @@ -1890,8 +1890,8 @@ void cPlayer::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffe } // Client-side-only effects - case cEntityEffect::efNausia: - case cEntityEffect::efNightVision: + case cEntityEffect::effNausea: + case cEntityEffect::effNightVision: { return; } diff --git a/src/Entities/WitherSkullEntity.cpp b/src/Entities/WitherSkullEntity.cpp index ea78bba5d..03e36a3f4 100644 --- a/src/Entities/WitherSkullEntity.cpp +++ b/src/Entities/WitherSkullEntity.cpp @@ -8,7 +8,7 @@ cWitherSkullEntity::cWitherSkullEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +super(pkWitherSkull, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) { SetSpeed(a_Speed); } -- cgit v1.2.3 From 68011a004a83adc793f0df563cc924c5a2b7dddc Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 8 Jun 2014 17:17:30 -0700 Subject: Removed long function wrapping --- src/Entities/Pawn.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index a1f24138d..297b4afda 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -69,8 +69,7 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_E } m_EntityEffects[a_EffectType] = a_Effect; - m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), - a_Effect.m_Ticks * a_Effect.GetDistanceModifier()); + m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), a_Effect.m_Ticks * a_Effect.GetDistanceModifier()); } -- cgit v1.2.3 From 52abd90a28736ca07ad4b2df1259f3b54fd74c9d Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 8 Jun 2014 18:14:34 -0700 Subject: Applies splash potion effects to mobs as well as players --- src/Entities/SplashPotionEntity.cpp | 15 +++++++++------ src/Entities/SplashPotionEntity.h | 5 +++-- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index 5dcea2385..e8bb0a420 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -1,7 +1,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "SplashPotionEntity.h" -#include "Player.h" +#include "Pawn.h" @@ -44,8 +44,7 @@ void cSplashPotionEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_ void cSplashPotionEntity::Splash(const Vector3d & a_HitPos) { cSplashPotionCallback Callback(a_HitPos, m_EntityEffectType, m_EntityEffect); - m_World->ForEachPlayer(Callback); - // TODO: Should be for each pawn + m_World->ForEachEntity(Callback); m_World->BroadcastSoundParticleEffect(2002, a_HitPos.x, a_HitPos.y, a_HitPos.z, m_PotionName); } @@ -66,9 +65,9 @@ cSplashPotionEntity::cSplashPotionCallback::cSplashPotionCallback(const Vector3d -bool cSplashPotionEntity::cSplashPotionCallback::Item(cPlayer * a_Player) +bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity) { - double distance_splash = (a_Player->GetPosition() - m_HitPos).Length(); + double distance_splash = (a_Entity->GetPosition() - m_HitPos).Length(); if (distance_splash < 20) { // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash. @@ -77,7 +76,11 @@ bool cSplashPotionEntity::cSplashPotionCallback::Item(cPlayer * a_Player) if (reduction < 0) reduction = 0; m_EntityEffect.SetDistanceModifier(reduction); - a_Player->AddEntityEffect(m_EntityEffectType, m_EntityEffect); + + if (a_Entity->IsMob() || a_Entity->IsPlayer()) + { + ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect); + } } return false; } diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h index b64b668a5..0f84e6387 100644 --- a/src/Entities/SplashPotionEntity.h +++ b/src/Entities/SplashPotionEntity.h @@ -7,6 +7,7 @@ #include "ProjectileEntity.h" #include "EntityEffects.h" #include "../World.h" +#include "Entity.h" @@ -42,12 +43,12 @@ protected: int m_PotionName; class cSplashPotionCallback : - public cPlayerListCallback + public cEntityCallback { public: cSplashPotionCallback(const Vector3d & a_HitPos, cEntityEffect::eType &a_EntityEffectType, cEntityEffect &a_EntityEffect); - virtual bool Item(cPlayer * a_Player) override; + virtual bool Item(cEntity *a_Entity) override; private: const Vector3d &m_HitPos; -- cgit v1.2.3 From 2574573c883fd7b5d19d19547f34dbef6820b5ea Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 8 Jun 2014 18:44:20 -0700 Subject: Monster: added IsUndead(), undead-specific entity effects --- src/Entities/Pawn.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 297b4afda..fee595e54 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -115,8 +115,6 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect { // Base heal = 6, doubles for every increase in intensity Heal(6 * std::pow(2, a_Effect.GetIntensity()) * a_Effect.GetDistanceModifier()); - - // TODO: Harms undead return; } case cEntityEffect::effInstantDamage: @@ -124,8 +122,6 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect // Base damage = 6, doubles for every increase in intensity int damage = 6 * std::pow(2, a_Effect.GetIntensity()); TakeDamage(dtPotionOfHarming, a_Effect.GetUser(), damage * a_Effect.GetDistanceModifier(), 0); - - // TODO: Heals undead return; } case cEntityEffect::effStrength: @@ -154,7 +150,6 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect counter = 0; } - // TODO: Doesn't effect undead return; } case cEntityEffect::effPoison: @@ -173,7 +168,6 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect counter = 0; } - // TODO: Doesn't effect undead or spiders return; } case cEntityEffect::effFireResistance: -- cgit v1.2.3 From 814cdca054bec5826b491f6d9d9867ce587d2def Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 8 Jun 2014 21:51:55 -0700 Subject: Added wither damage type, wither entity effect. --- src/Entities/Entity.cpp | 1 + src/Entities/Pawn.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index ba829bf6b..06833e1ba 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -432,6 +432,7 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType) case dtStarving: case dtInVoid: case dtPoisoning: + case dtWithering: case dtPotionOfHarming: case dtFalling: case dtLightning: diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index fee595e54..51ffc46b2 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -154,7 +154,7 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect } case cEntityEffect::effPoison: { - // Poison frequency = 25 ticks, divided by potion level (Poison II = 25 ticks) + // Poison frequency = 25 ticks, divided by potion level (Poison II = 12 ticks) int frequency = std::floor(25.0 / (double)(a_Effect.GetIntensity() + 1)); static short counter = 0; @@ -170,6 +170,20 @@ void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect return; } + case cEntityEffect::effWither: + { + // Poison frequency = 40 ticks, divided by effect level (Wither II = 20 ticks) + int frequency = std::floor(25.0 / (double)(a_Effect.GetIntensity() + 1)); + + static short counter = 0; + if (++counter >= frequency) + { + TakeDamage(dtWither, a_Effect.GetUser(), 1, 0); + counter = 0; + } + //TODO: " withered away> + return; + } case cEntityEffect::effFireResistance: { // TODO: Implement me! -- cgit v1.2.3 From 71b4c4949087860ab9962d6545a0ad2eb9c0ee5a Mon Sep 17 00:00:00 2001 From: archshift Date: Wed, 11 Jun 2014 16:21:47 -0700 Subject: Cave spider now poisons its victim, added IsPawn function to Entity --- src/Entities/Entity.h | 1 + src/Entities/SplashPotionEntity.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index b8f1f4c1c..b5d5cc34c 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -158,6 +158,7 @@ public: bool IsPlayer (void) const { return (m_EntityType == etPlayer); } bool IsPickup (void) const { return (m_EntityType == etPickup); } bool IsMob (void) const { return (m_EntityType == etMonster); } + bool IsPawn (void) const { return (IsMob() || IsPlayer()); } bool IsFallingBlock(void) const { return (m_EntityType == etFallingBlock); } bool IsMinecart (void) const { return (m_EntityType == etMinecart); } bool IsBoat (void) const { return (m_EntityType == etBoat); } diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index e8bb0a420..5574ea53c 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -77,7 +77,7 @@ bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity) m_EntityEffect.SetDistanceModifier(reduction); - if (a_Entity->IsMob() || a_Entity->IsPlayer()) + if (a_Entity->IsPawn()) { ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect); } -- cgit v1.2.3 From 5b2b6e06150b6299d1e19374be092c0858b0e3a8 Mon Sep 17 00:00:00 2001 From: archshift Date: Thu, 12 Jun 2014 19:50:02 -0700 Subject: Pawn: renamed HandleEntityEffects to HandleEntityEffect Exported entity effect functions for ToLua and documented them in APIDesc.lua --- src/Entities/Pawn.cpp | 4 ++-- src/Entities/Pawn.h | 4 +++- src/Entities/Player.cpp | 4 ++-- src/Entities/Player.h | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 51ffc46b2..67b6fe4db 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -28,7 +28,7 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk) cEntityEffect &effect_values = iter->second; // Apply entity effect - HandleEntityEffects(effect_type, effect_values); + HandleEntityEffect(effect_type, effect_values); // Reduce the effect's duration effect_values.m_Ticks--; @@ -106,7 +106,7 @@ void cPawn::ClearEntityEffects() -void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) +void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) { switch (a_EffectType) { diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index 47fb691f4..2ffdd9fbb 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -23,6 +23,7 @@ public: virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual void KilledBy(cEntity * a_Killer) override; + // tolua_begin /** Applies an entity effect * @param a_EffectType The entity effect to apply * @param a_Effect The parameters of the effect @@ -36,6 +37,7 @@ public: /** Removes all currently applied entity effects (used when drinking milk) */ void ClearEntityEffects(); + // tolua_end protected: typedef std::map tEffectMap; @@ -45,7 +47,7 @@ protected: * @param a_EffectType The selected entity effect * @param a_Effect The parameters of the selected entity effect */ - virtual void HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect); + virtual void HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect); } ; // tolua_export diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 6bceab26f..5d8c3479b 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1867,7 +1867,7 @@ void cPlayer::TickBurning(cChunk & a_Chunk) -void cPlayer::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) +void cPlayer::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) { switch (a_EffectType) { @@ -1897,7 +1897,7 @@ void cPlayer::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffe } } - super::HandleEntityEffects(a_EffectType, a_Effect); + super::HandleEntityEffect(a_EffectType, a_Effect); } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 3aba3289d..a793d3c30 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -522,7 +522,7 @@ protected: virtual void TickBurning(cChunk & a_Chunk) override; /** Called each tick to handle entity effects*/ - virtual void HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) override; + virtual void HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) override; /** Called in each tick to handle food-related processing */ void HandleFood(void); -- cgit v1.2.3 From 045ae2ef2c0d72b4902fa5151aad095823da9300 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 13 Jun 2014 09:49:42 +0200 Subject: Fixed MSVC compilation. --- src/Entities/Pawn.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 67b6fe4db..186e7df2a 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -114,14 +114,14 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect case cEntityEffect::effInstantHealth: { // Base heal = 6, doubles for every increase in intensity - Heal(6 * std::pow(2, a_Effect.GetIntensity()) * a_Effect.GetDistanceModifier()); + Heal((int)(6 * std::pow(2.0, a_Effect.GetIntensity()) * a_Effect.GetDistanceModifier())); return; } case cEntityEffect::effInstantDamage: { // Base damage = 6, doubles for every increase in intensity - int damage = 6 * std::pow(2, a_Effect.GetIntensity()); - TakeDamage(dtPotionOfHarming, a_Effect.GetUser(), damage * a_Effect.GetDistanceModifier(), 0); + int damage = (int)(6 * std::pow(2.0, a_Effect.GetIntensity()) * a_Effect.GetDistanceModifier()); + TakeDamage(dtPotionOfHarming, a_Effect.GetUser(), damage, 0); return; } case cEntityEffect::effStrength: @@ -132,7 +132,7 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect case cEntityEffect::effWeakness: { // Damage reduction = 0.5 damage, multiplied by potion level (Weakness II = 1 damage) - //double dmg_reduc = 0.5 * (a_Effect.GetIntensity() + 1); + // double dmg_reduc = 0.5 * (a_Effect.GetIntensity() + 1); // TODO: Implement me! // TODO: Weakened villager zombies can be turned back to villagers with the god apple @@ -143,6 +143,7 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect // Regen frequency = 50 ticks, divided by potion level (Regen II = 25 ticks) int frequency = std::floor(50.0 / (double)(a_Effect.GetIntensity() + 1)); + // TODO: The counter needs to be specific to one cPawn, make it a member variable. static short counter = 0; if (++counter >= frequency) { @@ -157,6 +158,7 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect // Poison frequency = 25 ticks, divided by potion level (Poison II = 12 ticks) int frequency = std::floor(25.0 / (double)(a_Effect.GetIntensity() + 1)); + // TODO: The counter needs to be specific to one cPawn, make it a member variable. static short counter = 0; if (++counter >= frequency) { @@ -175,6 +177,7 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect // Poison frequency = 40 ticks, divided by effect level (Wither II = 20 ticks) int frequency = std::floor(25.0 / (double)(a_Effect.GetIntensity() + 1)); + // TODO: The counter needs to be specific to one cPawn, make it a member variable. static short counter = 0; if (++counter >= frequency) { -- cgit v1.2.3 From 22761bb6ad4b121ae3b2319a9a2541a6bb8a982c Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 13 Jun 2014 01:50:09 -0700 Subject: Entity Effect: Separates total duration and ticks of activity Changed HandleEntityEffect to use cEntityEffect's ticks instead of a static counter --- src/Entities/EntityEffects.cpp | 8 +++++--- src/Entities/EntityEffects.h | 13 ++++++++++--- src/Entities/Pawn.cpp | 24 ++++++++---------------- 3 files changed, 23 insertions(+), 22 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffects.cpp b/src/Entities/EntityEffects.cpp index c74463bfa..e8448a6f1 100644 --- a/src/Entities/EntityEffects.cpp +++ b/src/Entities/EntityEffects.cpp @@ -8,6 +8,7 @@ cEntityEffect::cEntityEffect(): m_Ticks(0), + m_Duration(0), m_Intensity(0), m_User(NULL), m_DistanceModifier(1) @@ -19,11 +20,12 @@ cEntityEffect::cEntityEffect(): -cEntityEffect::cEntityEffect(int a_Ticks, short a_Intensity, cPawn *a_User, double a_DistanceModifier): - m_Ticks(a_Ticks), +cEntityEffect::cEntityEffect(int a_Duration, short a_Intensity, cPawn *a_User, double a_DistanceModifier): + m_Ticks(0), + m_Duration(a_Duration), m_Intensity(a_Intensity), m_User(a_User), m_DistanceModifier(a_DistanceModifier) { -} \ No newline at end of file +} diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h index 26d2c92e5..6b2532aae 100644 --- a/src/Entities/EntityEffects.h +++ b/src/Entities/EntityEffects.h @@ -35,9 +35,12 @@ public: effSaturation = 23, } ; - /** The duration of the effect */ + /** How many ticks this effect has been active for */ int m_Ticks; + /** Returns the duration of the effect */ + int GetDuration() { return m_Duration; } + /** Returns how strong the effect will be applied */ short GetIntensity() { return m_Intensity; } @@ -47,6 +50,7 @@ public: /** Returns the distance modifier for affecting potency */ double GetDistanceModifier() { return m_DistanceModifier; } + void SetDuration(int a_Duration) { m_Duration = a_Duration; } void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; } void SetUser(cPawn *a_User) { m_User = a_User; } void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; } @@ -58,14 +62,17 @@ public: /** * An entity effect - * @param a_Ticks The duration of the effect + * @param a_Duration How long this effect will last * @param a_Intensity How strong the effect will be applied * @param a_User The pawn that used this entity effect * @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */ - cEntityEffect(int a_Ticks, short a_Intensity, cPawn *a_User, double a_DistanceModifier = 1); + cEntityEffect(int a_Duration, short a_Intensity, cPawn *a_User, double a_DistanceModifier = 1); private: + /** How long this effect will last */ + int m_Duration; + /** How strong the effect will be applied */ short m_Intensity; diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 186e7df2a..0273981f9 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -30,14 +30,14 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk) // Apply entity effect HandleEntityEffect(effect_type, effect_values); - // Reduce the effect's duration - effect_values.m_Ticks--; + // Increase the effect's tick counter + effect_values.m_Ticks++; // Iterates (must be called before any possible erasure) ++iter; // Remove effect if duration has elapsed - if (effect_values.m_Ticks <= 0) + if (effect_values.GetDuration() - effect_values.m_Ticks <= 0) { RemoveEntityEffect(effect_type); } @@ -68,8 +68,9 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_E return; } + a_Effect.SetDuration(a_Effect.GetDuration() * a_Effect.GetDistanceModifier()); m_EntityEffects[a_EffectType] = a_Effect; - m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), a_Effect.m_Ticks * a_Effect.GetDistanceModifier()); + m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), a_Effect.GetDuration()); } @@ -143,12 +144,9 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect // Regen frequency = 50 ticks, divided by potion level (Regen II = 25 ticks) int frequency = std::floor(50.0 / (double)(a_Effect.GetIntensity() + 1)); - // TODO: The counter needs to be specific to one cPawn, make it a member variable. - static short counter = 0; - if (++counter >= frequency) + if (a_Effect.m_Ticks % frequency == 0) { Heal(1); - counter = 0; } return; @@ -158,16 +156,13 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect // Poison frequency = 25 ticks, divided by potion level (Poison II = 12 ticks) int frequency = std::floor(25.0 / (double)(a_Effect.GetIntensity() + 1)); - // TODO: The counter needs to be specific to one cPawn, make it a member variable. - static short counter = 0; - if (++counter >= frequency) + if (a_Effect.m_Ticks % frequency == 0) { // Cannot take poison damage when health is at 1 if (GetHealth() > 1) { TakeDamage(dtPoisoning, a_Effect.GetUser(), 1, 0); } - counter = 0; } return; @@ -177,12 +172,9 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect // Poison frequency = 40 ticks, divided by effect level (Wither II = 20 ticks) int frequency = std::floor(25.0 / (double)(a_Effect.GetIntensity() + 1)); - // TODO: The counter needs to be specific to one cPawn, make it a member variable. - static short counter = 0; - if (++counter >= frequency) + if (a_Effect.m_Ticks % frequency == 0) { TakeDamage(dtWither, a_Effect.GetUser(), 1, 0); - counter = 0; } //TODO: " withered away> return; -- cgit v1.2.3 From e289fe4dd7372a029ba85722e3ce99991e9d1d6b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 13 Jun 2014 11:04:16 +0200 Subject: Changed the AddEntityEffect() params for easier calls. --- src/Entities/EntityEffects.h | 27 ++++++++++++--------------- src/Entities/Pawn.cpp | 33 ++++++++++++++++----------------- src/Entities/Pawn.h | 16 +++++++++------- src/Entities/Player.cpp | 2 +- src/Entities/SplashPotionEntity.cpp | 19 ++++++++++++------- 5 files changed, 50 insertions(+), 47 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h index 6b2532aae..c0e8abd28 100644 --- a/src/Entities/EntityEffects.h +++ b/src/Entities/EntityEffects.h @@ -3,7 +3,8 @@ class cPawn; // tolua_begin -class cEntityEffect { +class cEntityEffect +{ public: /** All types of entity effects (numbers correspond to IDs) */ @@ -52,25 +53,21 @@ public: void SetDuration(int a_Duration) { m_Duration = a_Duration; } void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; } - void SetUser(cPawn *a_User) { m_User = a_User; } + void SetUser(cPawn * a_User) { m_User = a_User; } void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; } - /** - * An empty entity effect - */ - cEntityEffect(); + /** Creates an empty entity effect */ + cEntityEffect(void); - /** - * An entity effect - * @param a_Duration How long this effect will last - * @param a_Intensity How strong the effect will be applied - * @param a_User The pawn that used this entity effect - * @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 - */ - cEntityEffect(int a_Duration, short a_Intensity, cPawn *a_User, double a_DistanceModifier = 1); + /** Creates an entity effect of the specified type + @param a_Duration How long this effect will last, in ticks + @param a_Intensity How strong the effect will be applied + @param a_User The pawn that used this entity effect + @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */ + cEntityEffect(int a_Duration, short a_Intensity, cPawn * a_User, double a_DistanceModifier = 1); private: - /** How long this effect will last */ + /** How long this effect will last, in ticks */ int m_Duration; /** How strong the effect will be applied */ diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 0273981f9..ec829f6f8 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -8,9 +8,9 @@ -cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) - : cEntity(a_EntityType, 0, 0, 0, a_Width, a_Height) - , m_EntityEffects(tEffectMap()) +cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height): + super(a_EntityType, 0, 0, 0, a_Width, a_Height), + m_EntityEffects(tEffectMap()) { } @@ -24,22 +24,22 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk) for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();) { // Copies values to prevent pesky wrong accesses and erasures - cEntityEffect::eType effect_type = iter->first; - cEntityEffect &effect_values = iter->second; + cEntityEffect::eType EffectType = iter->first; + cEntityEffect & EffectValues = iter->second; // Apply entity effect - HandleEntityEffect(effect_type, effect_values); + HandleEntityEffect(EffectType, EffectValues); - // Increase the effect's tick counter - effect_values.m_Ticks++; + // Reduce the effect's duration + EffectValues.m_Ticks++; // Iterates (must be called before any possible erasure) ++iter; // Remove effect if duration has elapsed - if (effect_values.GetDuration() - effect_values.m_Ticks <= 0) + if (EffectValues.GetDuration() - EffectValues.m_Ticks <= 0) { - RemoveEntityEffect(effect_type); + RemoveEntityEffect(EffectType); } // TODO: Check for discrepancies between client and server effect values @@ -52,7 +52,7 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk) -void cPawn::KilledBy(cEntity *a_Killer) +void cPawn::KilledBy(cEntity * a_Killer) { ClearEntityEffects(); } @@ -61,16 +61,15 @@ void cPawn::KilledBy(cEntity *a_Killer) -void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) +void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier) { if (a_EffectType == cEntityEffect::effNoEffect) { return; } - a_Effect.SetDuration(a_Effect.GetDuration() * a_Effect.GetDistanceModifier()); - m_EntityEffects[a_EffectType] = a_Effect; - m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), a_Effect.GetDuration()); + m_EntityEffects[a_EffectType] = cEntityEffect(a_EffectDurationTicks, a_EffectIntensity, this, a_DistanceModifier); + m_World->BroadcastEntityEffect(*this, a_EffectType, a_EffectIntensity, (short)(a_EffectDurationTicks * a_DistanceModifier)); } @@ -93,13 +92,13 @@ void cPawn::ClearEntityEffects() for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();) { // Copy values to prevent pesky wrong erasures - cEntityEffect::eType effect_type = iter->first; + cEntityEffect::eType EffectType = iter->first; // Iterates (must be called before any possible erasure) ++iter; // Remove effect - RemoveEntityEffect(effect_type); + RemoveEntityEffect(EffectType); } } diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index 2ffdd9fbb..399e02e64 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -24,19 +24,21 @@ public: virtual void KilledBy(cEntity * a_Killer) override; // tolua_begin + /** Applies an entity effect - * @param a_EffectType The entity effect to apply - * @param a_Effect The parameters of the effect - */ - void AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect); + @param a_EffectType The entity effect to apply + @param a_Effect The parameters of the effect + */ + void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier = 1); /** Removes a currently applied entity effect - * @param a_EffectType The entity effect to remove - */ + @param a_EffectType The entity effect to remove + */ void RemoveEntityEffect(cEntityEffect::eType a_EffectType); /** Removes all currently applied entity effects (used when drinking milk) */ - void ClearEntityEffects(); + void ClearEntityEffects(void); + // tolua_end protected: diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 5d8c3479b..f2ec81957 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -570,7 +570,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation) void cPlayer::FoodPoison(int a_NumTicks) { - AddEntityEffect(cEntityEffect::effHunger, cEntityEffect(a_NumTicks, 0, NULL)); + AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0); } diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index 5574ea53c..4035b4794 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -67,20 +67,25 @@ cSplashPotionEntity::cSplashPotionCallback::cSplashPotionCallback(const Vector3d bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity) { - double distance_splash = (a_Entity->GetPosition() - m_HitPos).Length(); - if (distance_splash < 20) + double SplashDistance = (a_Entity->GetPosition() - m_HitPos).Length(); + if (SplashDistance < 20) { // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash. // TODO: better equation - double reduction = -0.25 * distance_splash + 1.0; - if (reduction < 0) reduction = 0; - - m_EntityEffect.SetDistanceModifier(reduction); + double Reduction = -0.25 * SplashDistance + 1.0; + if (Reduction < 0) + { + Reduction = 0; + } if (a_Entity->IsPawn()) { - ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect); + ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.m_Ticks, m_EntityEffect.GetIntensity(), Reduction); } } return false; } + + + + -- cgit v1.2.3 From 9e8361976b6b0dc4c62ef48a4744ba1f59fe4346 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 13 Jun 2014 02:41:43 -0700 Subject: Entity Effects: Clarified user, added it to AddEntityEffect Added second AddEntityEffect with a pass-by-value of the class. --- src/Entities/EntityEffects.h | 6 +++--- src/Entities/Pawn.cpp | 16 +++++++++++++--- src/Entities/Pawn.h | 11 ++++++++++- src/Entities/Player.cpp | 2 +- src/Entities/SplashPotionEntity.cpp | 8 +++----- 5 files changed, 30 insertions(+), 13 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h index c0e8abd28..2a4d0f723 100644 --- a/src/Entities/EntityEffects.h +++ b/src/Entities/EntityEffects.h @@ -45,7 +45,7 @@ public: /** Returns how strong the effect will be applied */ short GetIntensity() { return m_Intensity; } - /** Returns the pawn that used this entity effect */ + /** Returns the pawn that produced this entity effect */ cPawn *GetUser() { return m_User; } /** Returns the distance modifier for affecting potency */ @@ -62,7 +62,7 @@ public: /** Creates an entity effect of the specified type @param a_Duration How long this effect will last, in ticks @param a_Intensity How strong the effect will be applied - @param a_User The pawn that used this entity effect + @param a_User The pawn that produced this entity effect @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */ cEntityEffect(int a_Duration, short a_Intensity, cPawn * a_User, double a_DistanceModifier = 1); @@ -73,7 +73,7 @@ private: /** How strong the effect will be applied */ short m_Intensity; - /** The pawn that used this entity effect */ + /** The pawn that produced this entity effect (threw the potion, etc) */ cPawn *m_User; /** The distance modifier for affecting potency */ diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index ec829f6f8..2986799b7 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -61,15 +61,25 @@ void cPawn::KilledBy(cEntity * a_Killer) -void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier) +void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, cPawn * a_User, double a_DistanceModifier) +{ + AddEntityEffect(a_EffectType, cEntityEffect(a_EffectDurationTicks, a_EffectIntensity, a_User, a_DistanceModifier)); +} + + + + + +void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) { if (a_EffectType == cEntityEffect::effNoEffect) { return; } - m_EntityEffects[a_EffectType] = cEntityEffect(a_EffectDurationTicks, a_EffectIntensity, this, a_DistanceModifier); - m_World->BroadcastEntityEffect(*this, a_EffectType, a_EffectIntensity, (short)(a_EffectDurationTicks * a_DistanceModifier)); + a_Effect.SetDuration(a_Effect.GetDuration() * a_Effect.GetDistanceModifier()); + m_EntityEffects[a_EffectType] = a_Effect; + m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), a_Effect.GetDuration()); } diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index 399e02e64..3b83ec52f 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -25,11 +25,20 @@ public: // tolua_begin + /** Applies an entity effect + @param a_EffectType The entity effect to apply + @param a_EffectDurationTicks The duration of the effect + @param a_EffectIntensity The level of the effect (0 = Potion I, 1 = Potion II, etc) + @param a_User The pawn that produced the effect (e.g. threw the potion) + @param a_DistanceModifier The scalar multiplied to the potion duration, only applies to splash potions) + */ + void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, cPawn * a_User, double a_DistanceModifier = 1); + /** Applies an entity effect @param a_EffectType The entity effect to apply @param a_Effect The parameters of the effect */ - void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier = 1); + void AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect); /** Removes a currently applied entity effect @param a_EffectType The entity effect to remove diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index f2ec81957..b7a315a40 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -570,7 +570,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation) void cPlayer::FoodPoison(int a_NumTicks) { - AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0); + AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0, NULL); } diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index 4035b4794..714e4021d 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -68,7 +68,7 @@ cSplashPotionEntity::cSplashPotionCallback::cSplashPotionCallback(const Vector3d bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity) { double SplashDistance = (a_Entity->GetPosition() - m_HitPos).Length(); - if (SplashDistance < 20) + if (SplashDistance < 20 && a_Entity->IsPawn()) { // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash. // TODO: better equation @@ -78,10 +78,8 @@ bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity) Reduction = 0; } - if (a_Entity->IsPawn()) - { - ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.m_Ticks, m_EntityEffect.GetIntensity(), Reduction); - } + m_EntityEffect.SetDistanceModifier(Reduction); + ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect); } return false; } -- cgit v1.2.3 From fa1d85feca6beee9e07cf92f015a883a190c726a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 13 Jun 2014 12:47:01 +0200 Subject: Added the OnEntityAddEffect hook. --- src/Entities/Pawn.cpp | 9 +++++++++ src/Entities/Pawn.h | 2 ++ 2 files changed, 11 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 2986799b7..41a5b33ff 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -3,6 +3,7 @@ #include "Pawn.h" #include "../World.h" +#include "../Bindings/PluginManager.h" @@ -72,6 +73,14 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurat void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) { + // Check if the plugins allow the addition: + if (cPluginManager::Get()->CallHookEntityAddEffect(*this, a_EffectType, a_Effect.GetDuration(), a_Effect.GetIntensity(), a_Effect.GetUser(), a_Effect.GetDistanceModifier())) + { + // A plugin disallows the addition, bail out. + return; + } + + // No need to add empty effects: if (a_EffectType == cEntityEffect::effNoEffect) { return; diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index 3b83ec52f..c6be6f668 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -26,6 +26,7 @@ public: // tolua_begin /** Applies an entity effect + Checks with plugins if they allow the addition. @param a_EffectType The entity effect to apply @param a_EffectDurationTicks The duration of the effect @param a_EffectIntensity The level of the effect (0 = Potion I, 1 = Potion II, etc) @@ -35,6 +36,7 @@ public: void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, cPawn * a_User, double a_DistanceModifier = 1); /** Applies an entity effect + Checks with plugins if they allow the addition. @param a_EffectType The entity effect to apply @param a_Effect The parameters of the effect */ -- cgit v1.2.3 From 68c30790db17b9d21b2fcda4c7edec679162c577 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 13 Jun 2014 10:59:59 -0700 Subject: Entity effects: changed User to Creator, removed pawn pass-by-value --- src/Entities/EntityEffects.cpp | 6 +++--- src/Entities/EntityEffects.h | 10 +++++----- src/Entities/Pawn.cpp | 25 ++++++++----------------- src/Entities/Pawn.h | 11 ++--------- src/Entities/SplashPotionEntity.cpp | 2 +- 5 files changed, 19 insertions(+), 35 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffects.cpp b/src/Entities/EntityEffects.cpp index e8448a6f1..a9edeee25 100644 --- a/src/Entities/EntityEffects.cpp +++ b/src/Entities/EntityEffects.cpp @@ -10,7 +10,7 @@ cEntityEffect::cEntityEffect(): m_Ticks(0), m_Duration(0), m_Intensity(0), - m_User(NULL), + m_Creator(NULL), m_DistanceModifier(1) { @@ -20,11 +20,11 @@ cEntityEffect::cEntityEffect(): -cEntityEffect::cEntityEffect(int a_Duration, short a_Intensity, cPawn *a_User, double a_DistanceModifier): +cEntityEffect::cEntityEffect(int a_Duration, short a_Intensity, cPawn *a_Creator, double a_DistanceModifier): m_Ticks(0), m_Duration(a_Duration), m_Intensity(a_Intensity), - m_User(a_User), + m_Creator(a_Creator), m_DistanceModifier(a_DistanceModifier) { diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h index 2a4d0f723..9de3fcb86 100644 --- a/src/Entities/EntityEffects.h +++ b/src/Entities/EntityEffects.h @@ -46,14 +46,14 @@ public: short GetIntensity() { return m_Intensity; } /** Returns the pawn that produced this entity effect */ - cPawn *GetUser() { return m_User; } + cPawn *GetCreator() { return m_Creator; } /** Returns the distance modifier for affecting potency */ double GetDistanceModifier() { return m_DistanceModifier; } void SetDuration(int a_Duration) { m_Duration = a_Duration; } void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; } - void SetUser(cPawn * a_User) { m_User = a_User; } + void SetCreator(cPawn * a_Creator) { m_Creator = a_Creator; } void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; } /** Creates an empty entity effect */ @@ -62,9 +62,9 @@ public: /** Creates an entity effect of the specified type @param a_Duration How long this effect will last, in ticks @param a_Intensity How strong the effect will be applied - @param a_User The pawn that produced this entity effect + @param a_Creator The pawn that produced this entity effect @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */ - cEntityEffect(int a_Duration, short a_Intensity, cPawn * a_User, double a_DistanceModifier = 1); + cEntityEffect(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1); private: /** How long this effect will last, in ticks */ @@ -74,7 +74,7 @@ private: short m_Intensity; /** The pawn that produced this entity effect (threw the potion, etc) */ - cPawn *m_User; + cPawn *m_Creator; /** The distance modifier for affecting potency */ double m_DistanceModifier; diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 41a5b33ff..6c70fd2a6 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -62,19 +62,10 @@ void cPawn::KilledBy(cEntity * a_Killer) -void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, cPawn * a_User, double a_DistanceModifier) -{ - AddEntityEffect(a_EffectType, cEntityEffect(a_EffectDurationTicks, a_EffectIntensity, a_User, a_DistanceModifier)); -} - - - - - -void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) +void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, cPawn * a_Creator, double a_DistanceModifier) { // Check if the plugins allow the addition: - if (cPluginManager::Get()->CallHookEntityAddEffect(*this, a_EffectType, a_Effect.GetDuration(), a_Effect.GetIntensity(), a_Effect.GetUser(), a_Effect.GetDistanceModifier())) + if (cPluginManager::Get()->CallHookEntityAddEffect(*this, a_EffectType, a_EffectDurationTicks, a_EffectIntensity, a_Creator, a_DistanceModifier)) { // A plugin disallows the addition, bail out. return; @@ -86,9 +77,9 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_E return; } - a_Effect.SetDuration(a_Effect.GetDuration() * a_Effect.GetDistanceModifier()); - m_EntityEffects[a_EffectType] = a_Effect; - m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), a_Effect.GetDuration()); + int EffectDuration = (int)(a_EffectDurationTicks * a_DistanceModifier); + m_EntityEffects[a_EffectType] = cEntityEffect(EffectDuration, a_EffectIntensity, a_Creator, a_DistanceModifier); + m_World->BroadcastEntityEffect(*this, a_EffectType, a_EffectIntensity, EffectDuration); } @@ -140,7 +131,7 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect { // Base damage = 6, doubles for every increase in intensity int damage = (int)(6 * std::pow(2.0, a_Effect.GetIntensity()) * a_Effect.GetDistanceModifier()); - TakeDamage(dtPotionOfHarming, a_Effect.GetUser(), damage, 0); + TakeDamage(dtPotionOfHarming, a_Effect.GetCreator(), damage, 0); return; } case cEntityEffect::effStrength: @@ -179,7 +170,7 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect // Cannot take poison damage when health is at 1 if (GetHealth() > 1) { - TakeDamage(dtPoisoning, a_Effect.GetUser(), 1, 0); + TakeDamage(dtPoisoning, a_Effect.GetCreator(), 1, 0); } } @@ -192,7 +183,7 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect if (a_Effect.m_Ticks % frequency == 0) { - TakeDamage(dtWither, a_Effect.GetUser(), 1, 0); + TakeDamage(dtWither, a_Effect.GetCreator(), 1, 0); } //TODO: " withered away> return; diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index c6be6f668..9f7771d79 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -30,17 +30,10 @@ public: @param a_EffectType The entity effect to apply @param a_EffectDurationTicks The duration of the effect @param a_EffectIntensity The level of the effect (0 = Potion I, 1 = Potion II, etc) - @param a_User The pawn that produced the effect (e.g. threw the potion) + @param a_Creator The pawn that produced the effect (e.g. threw the potion) @param a_DistanceModifier The scalar multiplied to the potion duration, only applies to splash potions) */ - void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, cPawn * a_User, double a_DistanceModifier = 1); - - /** Applies an entity effect - Checks with plugins if they allow the addition. - @param a_EffectType The entity effect to apply - @param a_Effect The parameters of the effect - */ - void AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect); + void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, cPawn * a_Creator, double a_DistanceModifier = 1); /** Removes a currently applied entity effect @param a_EffectType The entity effect to remove diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index 714e4021d..2a1e9d981 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -79,7 +79,7 @@ bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity) } m_EntityEffect.SetDistanceModifier(Reduction); - ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect); + ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.m_Ticks, m_EntityEffect.GetIntensity(), m_EntityEffect.GetCreator(), Reduction); } return false; } -- cgit v1.2.3 From f5529e544cf8350daf8a20bb8d997f85ee2824f7 Mon Sep 17 00:00:00 2001 From: archshift Date: Mon, 16 Jun 2014 20:22:17 -0700 Subject: EntityEffects.x -> EntityEffect.x, Object-Oriented effects Changed effect map to take a pointer of the effect as a result. --- src/Entities/EntityEffect.cpp | 291 ++++++++++++++++++++++++ src/Entities/EntityEffect.h | 438 ++++++++++++++++++++++++++++++++++++ src/Entities/EntityEffects.cpp | 31 --- src/Entities/EntityEffects.h | 82 ------- src/Entities/Pawn.cpp | 119 +--------- src/Entities/Pawn.h | 10 +- src/Entities/Player.cpp | 37 --- src/Entities/Player.h | 3 - src/Entities/SplashPotionEntity.cpp | 2 +- src/Entities/SplashPotionEntity.h | 2 +- 10 files changed, 745 insertions(+), 270 deletions(-) create mode 100644 src/Entities/EntityEffect.cpp create mode 100644 src/Entities/EntityEffect.h delete mode 100644 src/Entities/EntityEffects.cpp delete mode 100644 src/Entities/EntityEffects.h (limited to 'src/Entities') diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp new file mode 100644 index 000000000..9881785cb --- /dev/null +++ b/src/Entities/EntityEffect.cpp @@ -0,0 +1,291 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "EntityEffect.h" +#include "../Mobs/Monster.h" +#include "Player.h" + + + + +cEntityEffect::cEntityEffect(): + m_Ticks(0), + m_Duration(0), + m_Intensity(0), + m_Creator(NULL), + m_DistanceModifier(1) +{ + +} + + + + + +cEntityEffect::cEntityEffect(int a_Duration, short a_Intensity, cPawn *a_Creator, double a_DistanceModifier): + m_Ticks(0), + m_Duration(a_Duration), + m_Intensity(a_Intensity), + m_Creator(a_Creator), + m_DistanceModifier(a_DistanceModifier) +{ + +} + + + + + +cEntityEffect::~cEntityEffect() +{ + +} + + + + + +cEntityEffect * cEntityEffect::CreateEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier) +{ + switch (a_EffectType) + { + case cEntityEffect::effNoEffect: return new cEntityEffect (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + + case cEntityEffect::effAbsorption: return new cEntityEffectAbsorption (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effBlindness: return new cEntityEffectBlindness (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effFireResistance: return new cEntityEffectFireResistance(a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effHaste: return new cEntityEffectHaste (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effHealthBoost: return new cEntityEffectHealthBoost (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effHunger: return new cEntityEffectHunger (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effInstantDamage: return new cEntityEffectInstantDamage (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effInstantHealth: return new cEntityEffectInstantHealth (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effInvisibility: return new cEntityEffectInvisibility (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effJumpBoost: return new cEntityEffectJumpBoost (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effMiningFatigue: return new cEntityEffectMiningFatigue (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effNausea: return new cEntityEffectNausea (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effNightVision: return new cEntityEffectNightVision (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effPoison: return new cEntityEffectPoison (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effRegeneration: return new cEntityEffectRegeneration (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effResistance: return new cEntityEffectResistance (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effSaturation: return new cEntityEffectSaturation (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effSlowness: return new cEntityEffectSlowness (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effSpeed: return new cEntityEffectSpeed (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effStrength: return new cEntityEffectStrength (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effWaterBreathing: return new cEntityEffectWaterBreathing(a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effWeakness: return new cEntityEffectWeakness (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effWither: return new cEntityEffectWither (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + } + + ASSERT(!"Unhandled entity effect type!"); +} + + + + + +void cEntityEffect::OnTick(cPawn & a_Target) +{ + // Reduce the effect's duration + ++m_Ticks; +} + + + + + +void cEntityEffect::OnActivate(cPawn & a_Target) +{ +} + + + + + +void cEntityEffect::OnDeactivate(cPawn & a_Target) +{ +} + + + + + +/************************************************************************ + **** Instant Health + ************************************************************************/ +void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) +{ + // Base amount = 6, doubles for every increase in intensity + int amount = (int)(6 * std::pow(2.0, m_Intensity) * m_DistanceModifier); + + if (a_Target.IsMob()) + { + if (((cMonster &) a_Target).IsUndead()) + { + a_Target.TakeDamage(dtPotionOfHarming, m_Creator, amount, 0); + return; + } + } + a_Target.Heal(amount); +} + + + + + +/************************************************************************ + **** Instant Damage + ************************************************************************/ +void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target) +{ + // Base amount = 6, doubles for every increase in intensity + int amount = (int)(6 * std::pow(2.0, m_Intensity) * m_DistanceModifier); + + if (a_Target.IsMob()) + { + if (((cMonster &) a_Target).IsUndead()) + { + a_Target.Heal(amount); + return; + } + } + a_Target.TakeDamage(dtPotionOfHarming, m_Creator, amount, 0); +} + + + + + +/************************************************************************ + **** Regeneration + ************************************************************************/ +void cEntityEffectRegeneration::OnTick(cPawn & a_Target) +{ + super::OnTick(a_Target); + + if (a_Target.IsMob()) + { + if (((cMonster &) a_Target).IsUndead()) + { + return; + } + } + + // Regen frequency = 50 ticks, divided by potion level (Regen II = 25 ticks) + int frequency = (int) std::floor(50.0 / (double)(m_Intensity + 1)); + + if (m_Ticks % frequency != 0) + { + return; + } + + a_Target.Heal(1); +} + + + + + +/************************************************************************ + **** Hunger + ************************************************************************/ +void cEntityEffectHunger::OnTick(cPawn & a_Target) +{ + super::OnTick(a_Target); + + if (a_Target.IsPlayer()) + { + cPlayer & Target = (cPlayer &) a_Target; + Target.SetFoodExhaustionLevel(Target.GetFoodExhaustionLevel() + 0.025); // 0.5 per second = 0.025 per tick + } +} + + + + + +/************************************************************************ + **** Weakness + ************************************************************************/ +void cEntityEffectWeakness::OnTick(cPawn & a_Target) +{ + super::OnTick(a_Target); + + // Damage reduction = 0.5 damage, multiplied by potion level (Weakness II = 1 damage) + // double dmg_reduc = 0.5 * (a_Effect.GetIntensity() + 1); + + // TODO: Implement me! + // TODO: Weakened villager zombies can be turned back to villagers with the god apple +} + + + + + +/************************************************************************ + **** Poison + ************************************************************************/ +void cEntityEffectPoison::OnTick(cPawn & a_Target) +{ + super::OnTick(a_Target); + + if (a_Target.IsMob()) + { + cMonster & Target = (cMonster &) a_Target; + + // Doesn't effect undead mobs, spiders + if (Target.IsUndead() + || Target.GetMobType() == cMonster::mtSpider + || Target.GetMobType() == cMonster::mtCaveSpider) + { + return; + } + } + + // Poison frequency = 25 ticks, divided by potion level (Poison II = 12 ticks) + int frequency = (int) std::floor(25.0 / (double)(m_Intensity + 1)); + + if (m_Ticks % frequency == 0) + { + // Cannot take poison damage when health is at 1 + if (a_Target.GetHealth() > 1) + { + a_Target.TakeDamage(dtPoisoning, m_Creator, 1, 0); + } + } +} + + + + + +/************************************************************************ + **** Wither + ************************************************************************/ +void cEntityEffectWither::OnTick(cPawn & a_Target) +{ + super::OnTick(a_Target); + + // Poison frequency = 40 ticks, divided by effect level (Wither II = 20 ticks) + int frequency = (int) std::floor(25.0 / (double)(m_Intensity + 1)); + + if (m_Ticks % frequency == 0) + { + a_Target.TakeDamage(dtWither, m_Creator, 1, 0); + } + //TODO: " withered away> +} + + + + + +/************************************************************************ + **** Saturation + ************************************************************************/ +void cEntityEffectSaturation::OnTick(cPawn & a_Target) +{ + if (a_Target.IsPlayer()) + { + cPlayer & Target = (cPlayer &) a_Target; + Target.SetFoodSaturationLevel(Target.GetFoodSaturationLevel() + (1 + m_Intensity)); // Increase saturation 1 per tick, adds 1 for every increase in level + } +} diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h new file mode 100644 index 000000000..ae7958e11 --- /dev/null +++ b/src/Entities/EntityEffect.h @@ -0,0 +1,438 @@ +#pragma once + +class cPawn; + +// tolua_begin +class cEntityEffect +{ +public: + + /** All types of entity effects (numbers correspond to IDs) */ + enum eType + { + effNoEffect = 0, + effSpeed = 1, + effSlowness = 2, + effHaste = 3, + effMiningFatigue = 4, + effStrength = 5, + effInstantHealth = 6, + effInstantDamage = 7, + effJumpBoost = 8, + effNausea = 9, + effRegeneration = 10, + effResistance = 11, + effFireResistance = 12, + effWaterBreathing = 13, + effInvisibility = 14, + effBlindness = 15, + effNightVision = 16, + effHunger = 17, + effWeakness = 18, + effPoison = 19, + effWither = 20, + effHealthBoost = 21, + effAbsorption = 22, + effSaturation = 23, + } ; + + /** Creates an empty entity effect */ + cEntityEffect(void); + + /** Creates an entity effect of the specified type + @param a_Duration How long this effect will last, in ticks + @param a_Intensity How strong the effect will be applied + @param a_Creator The pawn that produced this entity effect + @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */ + cEntityEffect(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1); + + virtual ~cEntityEffect(void); + + /** Creates a pointer to the proper entity effect from the effect type + @warning This function creates raw pointers that must be manually managed. + @param a_EffectType The effect type to create the effect from + @param a_Duration How long this effect will last, in ticks + @param a_Intensity How strong the effect will be applied + @param a_Creator The pawn that produced this entity effect + @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */ + static cEntityEffect * CreateEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier); + + /** Returns how many ticks this effect has been active for */ + int GetTicks() { return m_Ticks; } + /** Returns the duration of the effect */ + int GetDuration() { return m_Duration; } + /** Returns how strong the effect will be applied */ + short GetIntensity() { return m_Intensity; } + /** Returns the pawn that produced this entity effect */ + cPawn *GetCreator() { return m_Creator; } + /** Returns the distance modifier for affecting potency */ + double GetDistanceModifier() { return m_DistanceModifier; } + + void SetTicks(int a_Ticks) { m_Ticks = a_Ticks; } + void SetDuration(int a_Duration) { m_Duration = a_Duration; } + void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; } + void SetCreator(cPawn * a_Creator) { m_Creator = a_Creator; } + void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; } + + virtual void OnTick(cPawn & a_Target); + virtual void OnActivate(cPawn & a_Target); + virtual void OnDeactivate(cPawn & a_Target); + +protected: + /** How many ticks this effect has been active for */ + int m_Ticks; + + /** How long this effect will last, in ticks */ + int m_Duration; + + /** How strong the effect will be applied */ + short m_Intensity; + + /** The pawn that produced this entity effect (threw the potion, etc) */ + cPawn *m_Creator; + + /** The distance modifier for affecting potency */ + double m_DistanceModifier; +}; + +/************************************************************************ + **** Speed + ************************************************************************/ +class cEntityEffectSpeed: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectSpeed(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Slowness + ************************************************************************/ +class cEntityEffectSlowness: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectSlowness(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Haste + ************************************************************************/ +class cEntityEffectHaste: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectHaste(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Mining Fatigue + ************************************************************************/ +class cEntityEffectMiningFatigue: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectMiningFatigue(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Strength + ************************************************************************/ +class cEntityEffectStrength: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectStrength(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Instant Health + ************************************************************************/ +class cEntityEffectInstantHealth: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectInstantHealth(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } + + virtual void OnActivate(cPawn & a_Target) override; +}; + +/************************************************************************ + **** Instant Damage + ************************************************************************/ +class cEntityEffectInstantDamage: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectInstantDamage(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } + + virtual void OnActivate(cPawn & a_Target) override; +}; + +/************************************************************************ + **** Jump Boost + ************************************************************************/ +class cEntityEffectJumpBoost: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectJumpBoost(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Nausea + ************************************************************************/ +class cEntityEffectNausea: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectNausea(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Regeneration + ************************************************************************/ +class cEntityEffectRegeneration: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectRegeneration(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } + + virtual void OnTick(cPawn & a_Target) override; +}; + +/************************************************************************ + **** Resistance + ************************************************************************/ +class cEntityEffectResistance: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectResistance(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Fire Resistance + ************************************************************************/ +class cEntityEffectFireResistance: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectFireResistance(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Water Breathing + ************************************************************************/ +class cEntityEffectWaterBreathing: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectWaterBreathing(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Invisibility + ************************************************************************/ +class cEntityEffectInvisibility: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectInvisibility(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Blindness + ************************************************************************/ +class cEntityEffectBlindness: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectBlindness(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Night Vision + ************************************************************************/ +class cEntityEffectNightVision: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectNightVision(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Hunger + ************************************************************************/ +class cEntityEffectHunger: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectHunger(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } + + virtual void OnTick(cPawn & a_Target) override; +}; + +/************************************************************************ + **** Weakness + ************************************************************************/ +class cEntityEffectWeakness: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectWeakness(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } + + virtual void OnTick(cPawn & a_Target) override; +}; + +/************************************************************************ + **** Poison + ************************************************************************/ +class cEntityEffectPoison: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectPoison(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } + + virtual void OnTick(cPawn & a_Target) override; +}; + +/************************************************************************ + **** Wither + ************************************************************************/ +class cEntityEffectWither: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectWither(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } + + virtual void OnTick(cPawn & a_Target) override; +}; + +/************************************************************************ + **** Health Boost + ************************************************************************/ +class cEntityEffectHealthBoost: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectHealthBoost(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Absorption + ************************************************************************/ +class cEntityEffectAbsorption: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectAbsorption(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } +}; + +/************************************************************************ + **** Saturation + ************************************************************************/ +class cEntityEffectSaturation: + public cEntityEffect +{ + typedef cEntityEffect super; +public: + cEntityEffectSaturation(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + { + } + + virtual void OnTick(cPawn & a_Target) override; +}; + + + +// tolua_end diff --git a/src/Entities/EntityEffects.cpp b/src/Entities/EntityEffects.cpp deleted file mode 100644 index a9edeee25..000000000 --- a/src/Entities/EntityEffects.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "EntityEffects.h" -#include "Pawn.h" - - - - -cEntityEffect::cEntityEffect(): - m_Ticks(0), - m_Duration(0), - m_Intensity(0), - m_Creator(NULL), - m_DistanceModifier(1) -{ - -} - - - - - -cEntityEffect::cEntityEffect(int a_Duration, short a_Intensity, cPawn *a_Creator, double a_DistanceModifier): - m_Ticks(0), - m_Duration(a_Duration), - m_Intensity(a_Intensity), - m_Creator(a_Creator), - m_DistanceModifier(a_DistanceModifier) -{ - -} diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h deleted file mode 100644 index 9de3fcb86..000000000 --- a/src/Entities/EntityEffects.h +++ /dev/null @@ -1,82 +0,0 @@ -#pragma once - -class cPawn; - -// tolua_begin -class cEntityEffect -{ -public: - - /** All types of entity effects (numbers correspond to IDs) */ - enum eType - { - effNoEffect = 0, - effSpeed = 1, - effSlowness = 2, - effHaste = 3, - effMiningFatigue = 4, - effStrength = 5, - effInstantHealth = 6, - effInstantDamage = 7, - effJumpBoost = 8, - effNausea = 9, - effRegeneration = 10, - effResistance = 11, - effFireResistance = 12, - effWaterBreathing = 13, - effInvisibility = 14, - effBlindness = 15, - effNightVision = 16, - effHunger = 17, - effWeakness = 18, - effPoison = 19, - effWither = 20, - effHealthBoost = 21, - effAbsorption = 22, - effSaturation = 23, - } ; - - /** How many ticks this effect has been active for */ - int m_Ticks; - - /** Returns the duration of the effect */ - int GetDuration() { return m_Duration; } - - /** Returns how strong the effect will be applied */ - short GetIntensity() { return m_Intensity; } - - /** Returns the pawn that produced this entity effect */ - cPawn *GetCreator() { return m_Creator; } - - /** Returns the distance modifier for affecting potency */ - double GetDistanceModifier() { return m_DistanceModifier; } - - void SetDuration(int a_Duration) { m_Duration = a_Duration; } - void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; } - void SetCreator(cPawn * a_Creator) { m_Creator = a_Creator; } - void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; } - - /** Creates an empty entity effect */ - cEntityEffect(void); - - /** Creates an entity effect of the specified type - @param a_Duration How long this effect will last, in ticks - @param a_Intensity How strong the effect will be applied - @param a_Creator The pawn that produced this entity effect - @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */ - cEntityEffect(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1); - -private: - /** How long this effect will last, in ticks */ - int m_Duration; - - /** How strong the effect will be applied */ - short m_Intensity; - - /** The pawn that produced this entity effect (threw the potion, etc) */ - cPawn *m_Creator; - - /** The distance modifier for affecting potency */ - double m_DistanceModifier; -}; -// tolua_end diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 6c70fd2a6..62f71e20f 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -26,19 +26,15 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk) { // Copies values to prevent pesky wrong accesses and erasures cEntityEffect::eType EffectType = iter->first; - cEntityEffect & EffectValues = iter->second; + cEntityEffect * Effect = iter->second; - // Apply entity effect - HandleEntityEffect(EffectType, EffectValues); - - // Reduce the effect's duration - EffectValues.m_Ticks++; + Effect->OnTick(*this); // Iterates (must be called before any possible erasure) ++iter; // Remove effect if duration has elapsed - if (EffectValues.GetDuration() - EffectValues.m_Ticks <= 0) + if (Effect->GetDuration() - Effect->GetTicks() <= 0) { RemoveEntityEffect(EffectType); } @@ -62,10 +58,10 @@ void cPawn::KilledBy(cEntity * a_Killer) -void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, cPawn * a_Creator, double a_DistanceModifier) +void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier) { // Check if the plugins allow the addition: - if (cPluginManager::Get()->CallHookEntityAddEffect(*this, a_EffectType, a_EffectDurationTicks, a_EffectIntensity, a_Creator, a_DistanceModifier)) + if (cPluginManager::Get()->CallHookEntityAddEffect(*this, a_EffectType, a_Duration, a_Intensity, a_Creator, a_DistanceModifier)) { // A plugin disallows the addition, bail out. return; @@ -76,10 +72,11 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurat { return; } + a_Duration = (int)(a_Duration * a_DistanceModifier); - int EffectDuration = (int)(a_EffectDurationTicks * a_DistanceModifier); - m_EntityEffects[a_EffectType] = cEntityEffect(EffectDuration, a_EffectIntensity, a_Creator, a_DistanceModifier); - m_World->BroadcastEntityEffect(*this, a_EffectType, a_EffectIntensity, EffectDuration); + m_EntityEffects[a_EffectType] = cEntityEffect::CreateEntityEffect(a_EffectType, a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + m_World->BroadcastEntityEffect(*this, a_EffectType, a_Intensity, a_Duration); + m_EntityEffects[a_EffectType]->OnActivate(*this); } @@ -88,8 +85,10 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurat void cPawn::RemoveEntityEffect(cEntityEffect::eType a_EffectType) { - m_EntityEffects.erase(a_EffectType); m_World->BroadcastRemoveEntityEffect(*this, a_EffectType); + m_EntityEffects[a_EffectType]->OnDeactivate(*this); + delete m_EntityEffects[a_EffectType]; + m_EntityEffects.erase(a_EffectType); } @@ -111,97 +110,3 @@ void cPawn::ClearEntityEffects() RemoveEntityEffect(EffectType); } } - - - - - -void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) -{ - switch (a_EffectType) - { - // Default effect behaviors - case cEntityEffect::effInstantHealth: - { - // Base heal = 6, doubles for every increase in intensity - Heal((int)(6 * std::pow(2.0, a_Effect.GetIntensity()) * a_Effect.GetDistanceModifier())); - return; - } - case cEntityEffect::effInstantDamage: - { - // Base damage = 6, doubles for every increase in intensity - int damage = (int)(6 * std::pow(2.0, a_Effect.GetIntensity()) * a_Effect.GetDistanceModifier()); - TakeDamage(dtPotionOfHarming, a_Effect.GetCreator(), damage, 0); - return; - } - case cEntityEffect::effStrength: - { - // TODO: Implement me! - return; - } - case cEntityEffect::effWeakness: - { - // Damage reduction = 0.5 damage, multiplied by potion level (Weakness II = 1 damage) - // double dmg_reduc = 0.5 * (a_Effect.GetIntensity() + 1); - - // TODO: Implement me! - // TODO: Weakened villager zombies can be turned back to villagers with the god apple - return; - } - case cEntityEffect::effRegeneration: - { - // Regen frequency = 50 ticks, divided by potion level (Regen II = 25 ticks) - int frequency = std::floor(50.0 / (double)(a_Effect.GetIntensity() + 1)); - - if (a_Effect.m_Ticks % frequency == 0) - { - Heal(1); - } - - return; - } - case cEntityEffect::effPoison: - { - // Poison frequency = 25 ticks, divided by potion level (Poison II = 12 ticks) - int frequency = std::floor(25.0 / (double)(a_Effect.GetIntensity() + 1)); - - if (a_Effect.m_Ticks % frequency == 0) - { - // Cannot take poison damage when health is at 1 - if (GetHealth() > 1) - { - TakeDamage(dtPoisoning, a_Effect.GetCreator(), 1, 0); - } - } - - return; - } - case cEntityEffect::effWither: - { - // Poison frequency = 40 ticks, divided by effect level (Wither II = 20 ticks) - int frequency = std::floor(25.0 / (double)(a_Effect.GetIntensity() + 1)); - - if (a_Effect.m_Ticks % frequency == 0) - { - TakeDamage(dtWither, a_Effect.GetCreator(), 1, 0); - } - //TODO: " withered away> - return; - } - case cEntityEffect::effFireResistance: - { - // TODO: Implement me! - return; - } - case cEntityEffect::effSpeed: - { - // TODO: Implement me! - return; - } - case cEntityEffect::effSlowness: - { - // TODO: Implement me! - return; - } - } -} diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index 9f7771d79..307e5db3d 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -2,7 +2,7 @@ #pragma once #include "Entity.h" -#include "EntityEffects.h" +#include "EntityEffect.h" @@ -46,14 +46,8 @@ public: // tolua_end protected: - typedef std::map tEffectMap; + typedef std::map tEffectMap; tEffectMap m_EntityEffects; - - /** Applies entity effect effects - * @param a_EffectType The selected entity effect - * @param a_Effect The parameters of the selected entity effect - */ - virtual void HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect); } ; // tolua_export diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index b7a315a40..77ab6d309 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1867,43 +1867,6 @@ void cPlayer::TickBurning(cChunk & a_Chunk) -void cPlayer::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) -{ - switch (a_EffectType) - { - // Effects whose behaviors are overridden - case cEntityEffect::effMiningFatigue: - { - // TODO: Implement me! - return; - } - case cEntityEffect::effHunger: - { - m_FoodExhaustionLevel += 0.025; // 0.5 per second = 0.025 per tick - return; - } - case cEntityEffect::effSaturation: - { - // Increase saturation 1 per tick, adds 1 for every increase in level - m_FoodSaturationLevel += (1 + a_Effect.GetIntensity()); - return; - } - - // Client-side-only effects - case cEntityEffect::effNausea: - case cEntityEffect::effNightVision: - { - return; - } - } - - super::HandleEntityEffect(a_EffectType, a_Effect); -} - - - - - void cPlayer::HandleFood(void) { // Ref.: http://www.minecraftwiki.net/wiki/Hunger diff --git a/src/Entities/Player.h b/src/Entities/Player.h index a793d3c30..e80b82901 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -521,9 +521,6 @@ protected: /** Stops players from burning in creative mode */ virtual void TickBurning(cChunk & a_Chunk) override; - /** Called each tick to handle entity effects*/ - virtual void HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) override; - /** Called in each tick to handle food-related processing */ void HandleFood(void); diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index 2a1e9d981..3d2ef279f 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -79,7 +79,7 @@ bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity) } m_EntityEffect.SetDistanceModifier(Reduction); - ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.m_Ticks, m_EntityEffect.GetIntensity(), m_EntityEffect.GetCreator(), Reduction); + ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), m_EntityEffect.GetCreator(), Reduction); } return false; } diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h index 0f84e6387..548ba3a3e 100644 --- a/src/Entities/SplashPotionEntity.h +++ b/src/Entities/SplashPotionEntity.h @@ -5,7 +5,7 @@ #pragma once #include "ProjectileEntity.h" -#include "EntityEffects.h" +#include "EntityEffect.h" #include "../World.h" #include "Entity.h" -- cgit v1.2.3 From 4e6395d6ff9f34edb4dd36dc1f8e845c56b499f4 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 11 Jul 2014 17:27:29 -0700 Subject: For now, removed creator member from Entity Effect for pointer safety --- src/Entities/EntityEffect.cpp | 62 +++++++++++---------- src/Entities/EntityEffect.h | 104 +++++++++++++++++------------------- src/Entities/Pawn.cpp | 7 +-- src/Entities/Pawn.h | 3 +- src/Entities/SplashPotionEntity.cpp | 2 +- 5 files changed, 84 insertions(+), 94 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index 9881785cb..e68ded8b0 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -11,7 +11,6 @@ cEntityEffect::cEntityEffect(): m_Ticks(0), m_Duration(0), m_Intensity(0), - m_Creator(NULL), m_DistanceModifier(1) { @@ -21,11 +20,10 @@ cEntityEffect::cEntityEffect(): -cEntityEffect::cEntityEffect(int a_Duration, short a_Intensity, cPawn *a_Creator, double a_DistanceModifier): +cEntityEffect::cEntityEffect(int a_Duration, short a_Intensity, double a_DistanceModifier): m_Ticks(0), m_Duration(a_Duration), m_Intensity(a_Intensity), - m_Creator(a_Creator), m_DistanceModifier(a_DistanceModifier) { @@ -44,35 +42,35 @@ cEntityEffect::~cEntityEffect() -cEntityEffect * cEntityEffect::CreateEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier) +cEntityEffect * cEntityEffect::CreateEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, double a_DistanceModifier) { switch (a_EffectType) { - case cEntityEffect::effNoEffect: return new cEntityEffect (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effNoEffect: return new cEntityEffect (a_Duration, a_Intensity, a_DistanceModifier); - case cEntityEffect::effAbsorption: return new cEntityEffectAbsorption (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effBlindness: return new cEntityEffectBlindness (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effFireResistance: return new cEntityEffectFireResistance(a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effHaste: return new cEntityEffectHaste (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effHealthBoost: return new cEntityEffectHealthBoost (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effHunger: return new cEntityEffectHunger (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effInstantDamage: return new cEntityEffectInstantDamage (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effInstantHealth: return new cEntityEffectInstantHealth (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effInvisibility: return new cEntityEffectInvisibility (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effJumpBoost: return new cEntityEffectJumpBoost (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effMiningFatigue: return new cEntityEffectMiningFatigue (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effNausea: return new cEntityEffectNausea (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effNightVision: return new cEntityEffectNightVision (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effPoison: return new cEntityEffectPoison (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effRegeneration: return new cEntityEffectRegeneration (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effResistance: return new cEntityEffectResistance (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effSaturation: return new cEntityEffectSaturation (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effSlowness: return new cEntityEffectSlowness (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effSpeed: return new cEntityEffectSpeed (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effStrength: return new cEntityEffectStrength (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effWaterBreathing: return new cEntityEffectWaterBreathing(a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effWeakness: return new cEntityEffectWeakness (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); - case cEntityEffect::effWither: return new cEntityEffectWither (a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + case cEntityEffect::effAbsorption: return new cEntityEffectAbsorption (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effBlindness: return new cEntityEffectBlindness (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effFireResistance: return new cEntityEffectFireResistance(a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effHaste: return new cEntityEffectHaste (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effHealthBoost: return new cEntityEffectHealthBoost (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effHunger: return new cEntityEffectHunger (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effInstantDamage: return new cEntityEffectInstantDamage (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effInstantHealth: return new cEntityEffectInstantHealth (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effInvisibility: return new cEntityEffectInvisibility (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effJumpBoost: return new cEntityEffectJumpBoost (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effMiningFatigue: return new cEntityEffectMiningFatigue (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effNausea: return new cEntityEffectNausea (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effNightVision: return new cEntityEffectNightVision (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effPoison: return new cEntityEffectPoison (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effRegeneration: return new cEntityEffectRegeneration (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effResistance: return new cEntityEffectResistance (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effSaturation: return new cEntityEffectSaturation (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effSlowness: return new cEntityEffectSlowness (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effSpeed: return new cEntityEffectSpeed (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effStrength: return new cEntityEffectStrength (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effWaterBreathing: return new cEntityEffectWaterBreathing(a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effWeakness: return new cEntityEffectWeakness (a_Duration, a_Intensity, a_DistanceModifier); + case cEntityEffect::effWither: return new cEntityEffectWither (a_Duration, a_Intensity, a_DistanceModifier); } ASSERT(!"Unhandled entity effect type!"); @@ -120,7 +118,7 @@ void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) { if (((cMonster &) a_Target).IsUndead()) { - a_Target.TakeDamage(dtPotionOfHarming, m_Creator, amount, 0); + a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage return; } } @@ -147,7 +145,7 @@ void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target) return; } } - a_Target.TakeDamage(dtPotionOfHarming, m_Creator, amount, 0); + a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage } @@ -248,7 +246,7 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target) // Cannot take poison damage when health is at 1 if (a_Target.GetHealth() > 1) { - a_Target.TakeDamage(dtPoisoning, m_Creator, 1, 0); + a_Target.TakeDamage(dtPoisoning, NULL, 1, 0); } } } @@ -269,7 +267,7 @@ void cEntityEffectWither::OnTick(cPawn & a_Target) if (m_Ticks % frequency == 0) { - a_Target.TakeDamage(dtWither, m_Creator, 1, 0); + a_Target.TakeDamage(dtWither, NULL, 1, 0); } //TODO: " withered away> } diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h index ae7958e11..c593fba81 100644 --- a/src/Entities/EntityEffect.h +++ b/src/Entities/EntityEffect.h @@ -42,9 +42,8 @@ public: /** Creates an entity effect of the specified type @param a_Duration How long this effect will last, in ticks @param a_Intensity How strong the effect will be applied - @param a_Creator The pawn that produced this entity effect @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */ - cEntityEffect(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1); + cEntityEffect(int a_Duration, short a_Intensity, double a_DistanceModifier = 1); virtual ~cEntityEffect(void); @@ -53,9 +52,8 @@ public: @param a_EffectType The effect type to create the effect from @param a_Duration How long this effect will last, in ticks @param a_Intensity How strong the effect will be applied - @param a_Creator The pawn that produced this entity effect @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */ - static cEntityEffect * CreateEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier); + static cEntityEffect * CreateEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, double a_DistanceModifier); /** Returns how many ticks this effect has been active for */ int GetTicks() { return m_Ticks; } @@ -63,15 +61,12 @@ public: int GetDuration() { return m_Duration; } /** Returns how strong the effect will be applied */ short GetIntensity() { return m_Intensity; } - /** Returns the pawn that produced this entity effect */ - cPawn *GetCreator() { return m_Creator; } /** Returns the distance modifier for affecting potency */ double GetDistanceModifier() { return m_DistanceModifier; } void SetTicks(int a_Ticks) { m_Ticks = a_Ticks; } void SetDuration(int a_Duration) { m_Duration = a_Duration; } void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; } - void SetCreator(cPawn * a_Creator) { m_Creator = a_Creator; } void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; } virtual void OnTick(cPawn & a_Target); @@ -88,9 +83,6 @@ protected: /** How strong the effect will be applied */ short m_Intensity; - /** The pawn that produced this entity effect (threw the potion, etc) */ - cPawn *m_Creator; - /** The distance modifier for affecting potency */ double m_DistanceModifier; }; @@ -103,8 +95,8 @@ class cEntityEffectSpeed: { typedef cEntityEffect super; public: - cEntityEffectSpeed(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectSpeed(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -117,8 +109,8 @@ class cEntityEffectSlowness: { typedef cEntityEffect super; public: - cEntityEffectSlowness(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectSlowness(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -131,8 +123,8 @@ class cEntityEffectHaste: { typedef cEntityEffect super; public: - cEntityEffectHaste(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectHaste(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -145,8 +137,8 @@ class cEntityEffectMiningFatigue: { typedef cEntityEffect super; public: - cEntityEffectMiningFatigue(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectMiningFatigue(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -159,8 +151,8 @@ class cEntityEffectStrength: { typedef cEntityEffect super; public: - cEntityEffectStrength(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectStrength(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -173,8 +165,8 @@ class cEntityEffectInstantHealth: { typedef cEntityEffect super; public: - cEntityEffectInstantHealth(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectInstantHealth(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } @@ -189,8 +181,8 @@ class cEntityEffectInstantDamage: { typedef cEntityEffect super; public: - cEntityEffectInstantDamage(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectInstantDamage(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } @@ -205,8 +197,8 @@ class cEntityEffectJumpBoost: { typedef cEntityEffect super; public: - cEntityEffectJumpBoost(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectJumpBoost(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -219,8 +211,8 @@ class cEntityEffectNausea: { typedef cEntityEffect super; public: - cEntityEffectNausea(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectNausea(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -233,8 +225,8 @@ class cEntityEffectRegeneration: { typedef cEntityEffect super; public: - cEntityEffectRegeneration(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectRegeneration(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } @@ -249,8 +241,8 @@ class cEntityEffectResistance: { typedef cEntityEffect super; public: - cEntityEffectResistance(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectResistance(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -263,8 +255,8 @@ class cEntityEffectFireResistance: { typedef cEntityEffect super; public: - cEntityEffectFireResistance(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectFireResistance(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -277,8 +269,8 @@ class cEntityEffectWaterBreathing: { typedef cEntityEffect super; public: - cEntityEffectWaterBreathing(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectWaterBreathing(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -291,8 +283,8 @@ class cEntityEffectInvisibility: { typedef cEntityEffect super; public: - cEntityEffectInvisibility(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectInvisibility(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -305,8 +297,8 @@ class cEntityEffectBlindness: { typedef cEntityEffect super; public: - cEntityEffectBlindness(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectBlindness(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -319,8 +311,8 @@ class cEntityEffectNightVision: { typedef cEntityEffect super; public: - cEntityEffectNightVision(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectNightVision(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -333,8 +325,8 @@ class cEntityEffectHunger: { typedef cEntityEffect super; public: - cEntityEffectHunger(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectHunger(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } @@ -349,8 +341,8 @@ class cEntityEffectWeakness: { typedef cEntityEffect super; public: - cEntityEffectWeakness(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectWeakness(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } @@ -365,8 +357,8 @@ class cEntityEffectPoison: { typedef cEntityEffect super; public: - cEntityEffectPoison(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectPoison(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } @@ -381,8 +373,8 @@ class cEntityEffectWither: { typedef cEntityEffect super; public: - cEntityEffectWither(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectWither(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } @@ -397,8 +389,8 @@ class cEntityEffectHealthBoost: { typedef cEntityEffect super; public: - cEntityEffectHealthBoost(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectHealthBoost(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -411,8 +403,8 @@ class cEntityEffectAbsorption: { typedef cEntityEffect super; public: - cEntityEffectAbsorption(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectAbsorption(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; @@ -425,8 +417,8 @@ class cEntityEffectSaturation: { typedef cEntityEffect super; public: - cEntityEffectSaturation(int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_Creator, a_DistanceModifier) + cEntityEffectSaturation(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): + super(a_Duration, a_Intensity, a_DistanceModifier) { } diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 62f71e20f..840736f6a 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -52,16 +52,17 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk) void cPawn::KilledBy(cEntity * a_Killer) { ClearEntityEffects(); + super::KilledBy(a_Killer); } -void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, cPawn * a_Creator, double a_DistanceModifier) +void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, double a_DistanceModifier) { // Check if the plugins allow the addition: - if (cPluginManager::Get()->CallHookEntityAddEffect(*this, a_EffectType, a_Duration, a_Intensity, a_Creator, a_DistanceModifier)) + if (cPluginManager::Get()->CallHookEntityAddEffect(*this, a_EffectType, a_Duration, a_Intensity, a_DistanceModifier)) { // A plugin disallows the addition, bail out. return; @@ -74,7 +75,7 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, s } a_Duration = (int)(a_Duration * a_DistanceModifier); - m_EntityEffects[a_EffectType] = cEntityEffect::CreateEntityEffect(a_EffectType, a_Duration, a_Intensity, a_Creator, a_DistanceModifier); + m_EntityEffects[a_EffectType] = cEntityEffect::CreateEntityEffect(a_EffectType, a_Duration, a_Intensity, a_DistanceModifier); m_World->BroadcastEntityEffect(*this, a_EffectType, a_Intensity, a_Duration); m_EntityEffects[a_EffectType]->OnActivate(*this); } diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index 307e5db3d..252ec5edb 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -30,10 +30,9 @@ public: @param a_EffectType The entity effect to apply @param a_EffectDurationTicks The duration of the effect @param a_EffectIntensity The level of the effect (0 = Potion I, 1 = Potion II, etc) - @param a_Creator The pawn that produced the effect (e.g. threw the potion) @param a_DistanceModifier The scalar multiplied to the potion duration, only applies to splash potions) */ - void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, cPawn * a_Creator, double a_DistanceModifier = 1); + void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier = 1); /** Removes a currently applied entity effect @param a_EffectType The entity effect to remove diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index 3d2ef279f..e84f1c430 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -79,7 +79,7 @@ bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity) } m_EntityEffect.SetDistanceModifier(Reduction); - ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), m_EntityEffect.GetCreator(), Reduction); + ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction); } return false; } -- cgit v1.2.3 From 8cbd43e0434323dcb1ccba6e1b95a3ca16d35d44 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 11 Jul 2014 18:58:11 -0700 Subject: Added splash potions to NBT serialization and retrieval --- src/Entities/ProjectileEntity.cpp | 2 +- src/Entities/SplashPotionEntity.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index c2d97589f..9c1161ac3 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -312,7 +312,7 @@ AString cProjectileEntity::GetMCAClassName(void) const case pkFireCharge: return "SmallFireball"; case pkEnderPearl: return "ThrownEnderpearl"; case pkExpBottle: return "ThrownExpBottle"; - case pkSplashPotion: return "ThrownPotion"; + case pkSplashPotion: return "SplashPotion"; case pkWitherSkull: return "WitherSkull"; case pkFirework: return "Firework"; case pkFishingFloat: return ""; // Unknown, perhaps MC doesn't save this? diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h index 548ba3a3e..ad656d8ab 100644 --- a/src/Entities/SplashPotionEntity.h +++ b/src/Entities/SplashPotionEntity.h @@ -27,6 +27,14 @@ public: cSplashPotionEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed, cEntityEffect::eType a_EntityEffectType, cEntityEffect a_EntityEffect, int a_PotionName); + cEntityEffect::eType GetEntityEffectType() { return m_EntityEffectType; } + cEntityEffect GetEntityEffect() { return m_EntityEffect; } + int GetPotionName() { return m_PotionName; } + + void SetEntityEffectType(cEntityEffect::eType a_EntityEffectType) { m_EntityEffectType = a_EntityEffectType; } + void SetEntityEffect(cEntityEffect a_EntityEffect) { m_EntityEffect = a_EntityEffect; } + void SetPotionName(int a_PotionName) { m_PotionName = a_PotionName; } + protected: // cProjectileEntity overrides: -- cgit v1.2.3 From f77723128c6582e9c184706c7140c8bcf9c390c4 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 13 Jul 2014 15:23:23 -0700 Subject: Changed separating comment style from asterisks to slashes. --- src/Entities/EntityEffect.cpp | 48 +++++++-------- src/Entities/EntityEffect.h | 138 +++++++++++++++++++++--------------------- 2 files changed, 93 insertions(+), 93 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index e68ded8b0..be501297c 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -106,9 +106,9 @@ void cEntityEffect::OnDeactivate(cPawn & a_Target) -/************************************************************************ - **** Instant Health - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Instant Health +///////////////////////////////////////////////////////////////////////// void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) { // Base amount = 6, doubles for every increase in intensity @@ -129,9 +129,9 @@ void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) -/************************************************************************ - **** Instant Damage - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Instant Damage +///////////////////////////////////////////////////////////////////////// void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target) { // Base amount = 6, doubles for every increase in intensity @@ -152,9 +152,9 @@ void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target) -/************************************************************************ - **** Regeneration - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Regeneration +///////////////////////////////////////////////////////////////////////// void cEntityEffectRegeneration::OnTick(cPawn & a_Target) { super::OnTick(a_Target); @@ -182,9 +182,9 @@ void cEntityEffectRegeneration::OnTick(cPawn & a_Target) -/************************************************************************ - **** Hunger - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Hunger +///////////////////////////////////////////////////////////////////////// void cEntityEffectHunger::OnTick(cPawn & a_Target) { super::OnTick(a_Target); @@ -200,9 +200,9 @@ void cEntityEffectHunger::OnTick(cPawn & a_Target) -/************************************************************************ - **** Weakness - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Weakness +///////////////////////////////////////////////////////////////////////// void cEntityEffectWeakness::OnTick(cPawn & a_Target) { super::OnTick(a_Target); @@ -218,9 +218,9 @@ void cEntityEffectWeakness::OnTick(cPawn & a_Target) -/************************************************************************ - **** Poison - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Poison +///////////////////////////////////////////////////////////////////////// void cEntityEffectPoison::OnTick(cPawn & a_Target) { super::OnTick(a_Target); @@ -255,9 +255,9 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target) -/************************************************************************ - **** Wither - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Wither +///////////////////////////////////////////////////////////////////////// void cEntityEffectWither::OnTick(cPawn & a_Target) { super::OnTick(a_Target); @@ -276,9 +276,9 @@ void cEntityEffectWither::OnTick(cPawn & a_Target) -/************************************************************************ - **** Saturation - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Saturation +///////////////////////////////////////////////////////////////////////// void cEntityEffectSaturation::OnTick(cPawn & a_Target) { if (a_Target.IsPlayer()) diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h index c593fba81..6e53d83b8 100644 --- a/src/Entities/EntityEffect.h +++ b/src/Entities/EntityEffect.h @@ -87,9 +87,9 @@ protected: double m_DistanceModifier; }; -/************************************************************************ - **** Speed - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Speed +///////////////////////////////////////////////////////////////////////// class cEntityEffectSpeed: public cEntityEffect { @@ -101,9 +101,9 @@ public: } }; -/************************************************************************ - **** Slowness - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Slowness +///////////////////////////////////////////////////////////////////////// class cEntityEffectSlowness: public cEntityEffect { @@ -115,9 +115,9 @@ public: } }; -/************************************************************************ - **** Haste - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Haste +///////////////////////////////////////////////////////////////////////// class cEntityEffectHaste: public cEntityEffect { @@ -129,9 +129,9 @@ public: } }; -/************************************************************************ - **** Mining Fatigue - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Mining Fatigue +///////////////////////////////////////////////////////////////////////// class cEntityEffectMiningFatigue: public cEntityEffect { @@ -143,9 +143,9 @@ public: } }; -/************************************************************************ - **** Strength - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Strength +///////////////////////////////////////////////////////////////////////// class cEntityEffectStrength: public cEntityEffect { @@ -157,9 +157,9 @@ public: } }; -/************************************************************************ - **** Instant Health - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Instant Health +///////////////////////////////////////////////////////////////////////// class cEntityEffectInstantHealth: public cEntityEffect { @@ -173,9 +173,9 @@ public: virtual void OnActivate(cPawn & a_Target) override; }; -/************************************************************************ - **** Instant Damage - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Instant Damage +///////////////////////////////////////////////////////////////////////// class cEntityEffectInstantDamage: public cEntityEffect { @@ -189,9 +189,9 @@ public: virtual void OnActivate(cPawn & a_Target) override; }; -/************************************************************************ - **** Jump Boost - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Jump Boost +///////////////////////////////////////////////////////////////////////// class cEntityEffectJumpBoost: public cEntityEffect { @@ -203,9 +203,9 @@ public: } }; -/************************************************************************ - **** Nausea - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Nausea +///////////////////////////////////////////////////////////////////////// class cEntityEffectNausea: public cEntityEffect { @@ -217,9 +217,9 @@ public: } }; -/************************************************************************ - **** Regeneration - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Regeneration +///////////////////////////////////////////////////////////////////////// class cEntityEffectRegeneration: public cEntityEffect { @@ -233,9 +233,9 @@ public: virtual void OnTick(cPawn & a_Target) override; }; -/************************************************************************ - **** Resistance - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Resistance +///////////////////////////////////////////////////////////////////////// class cEntityEffectResistance: public cEntityEffect { @@ -247,9 +247,9 @@ public: } }; -/************************************************************************ - **** Fire Resistance - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Fire Resistance +///////////////////////////////////////////////////////////////////////// class cEntityEffectFireResistance: public cEntityEffect { @@ -261,9 +261,9 @@ public: } }; -/************************************************************************ - **** Water Breathing - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Water Breathing +///////////////////////////////////////////////////////////////////////// class cEntityEffectWaterBreathing: public cEntityEffect { @@ -275,9 +275,9 @@ public: } }; -/************************************************************************ - **** Invisibility - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Invisibility +///////////////////////////////////////////////////////////////////////// class cEntityEffectInvisibility: public cEntityEffect { @@ -289,9 +289,9 @@ public: } }; -/************************************************************************ - **** Blindness - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Blindness +///////////////////////////////////////////////////////////////////////// class cEntityEffectBlindness: public cEntityEffect { @@ -303,9 +303,9 @@ public: } }; -/************************************************************************ - **** Night Vision - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Night Vision +///////////////////////////////////////////////////////////////////////// class cEntityEffectNightVision: public cEntityEffect { @@ -317,9 +317,9 @@ public: } }; -/************************************************************************ - **** Hunger - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Hunger +///////////////////////////////////////////////////////////////////////// class cEntityEffectHunger: public cEntityEffect { @@ -333,9 +333,9 @@ public: virtual void OnTick(cPawn & a_Target) override; }; -/************************************************************************ - **** Weakness - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Weakness +///////////////////////////////////////////////////////////////////////// class cEntityEffectWeakness: public cEntityEffect { @@ -349,9 +349,9 @@ public: virtual void OnTick(cPawn & a_Target) override; }; -/************************************************************************ - **** Poison - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Poison +///////////////////////////////////////////////////////////////////////// class cEntityEffectPoison: public cEntityEffect { @@ -365,9 +365,9 @@ public: virtual void OnTick(cPawn & a_Target) override; }; -/************************************************************************ - **** Wither - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Wither +///////////////////////////////////////////////////////////////////////// class cEntityEffectWither: public cEntityEffect { @@ -381,9 +381,9 @@ public: virtual void OnTick(cPawn & a_Target) override; }; -/************************************************************************ - **** Health Boost - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Health Boost +///////////////////////////////////////////////////////////////////////// class cEntityEffectHealthBoost: public cEntityEffect { @@ -395,9 +395,9 @@ public: } }; -/************************************************************************ - **** Absorption - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Absorption +///////////////////////////////////////////////////////////////////////// class cEntityEffectAbsorption: public cEntityEffect { @@ -409,9 +409,9 @@ public: } }; -/************************************************************************ - **** Saturation - ************************************************************************/ +///////////////////////////////////////////////////////////////////////// +// Saturation +///////////////////////////////////////////////////////////////////////// class cEntityEffectSaturation: public cEntityEffect { -- cgit v1.2.3 From 0409daf7360d503e9e2b6258fa2582d7bdd7e5a0 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 13 Jul 2014 15:43:49 -0700 Subject: EntityEffect: Inlined functions, added explicit copy constructor and operator. --- src/Entities/EntityEffect.cpp | 35 ++++++++++++++++++----------------- src/Entities/EntityEffect.h | 14 +++++++++++--- 2 files changed, 29 insertions(+), 20 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index be501297c..852099b79 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -33,7 +33,11 @@ cEntityEffect::cEntityEffect(int a_Duration, short a_Intensity, double a_Distanc -cEntityEffect::~cEntityEffect() +cEntityEffect::cEntityEffect(const cEntityEffect & a_OtherEffect): + m_Ticks(a_OtherEffect.m_Ticks), + m_Duration(a_OtherEffect.m_Duration), + m_Intensity(a_OtherEffect.m_Intensity), + m_DistanceModifier(a_OtherEffect.m_DistanceModifier) { } @@ -42,6 +46,19 @@ cEntityEffect::~cEntityEffect() +cEntityEffect & cEntityEffect::operator=(cEntityEffect a_OtherEffect) +{ + std::swap(m_Ticks, a_OtherEffect.m_Ticks); + std::swap(m_Duration, a_OtherEffect.m_Duration); + std::swap(m_Intensity, a_OtherEffect.m_Intensity); + std::swap(m_DistanceModifier, a_OtherEffect.m_DistanceModifier); + return *this; +} + + + + + cEntityEffect * cEntityEffect::CreateEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, double a_DistanceModifier) { switch (a_EffectType) @@ -90,22 +107,6 @@ void cEntityEffect::OnTick(cPawn & a_Target) -void cEntityEffect::OnActivate(cPawn & a_Target) -{ -} - - - - - -void cEntityEffect::OnDeactivate(cPawn & a_Target) -{ -} - - - - - ///////////////////////////////////////////////////////////////////////// // Instant Health ///////////////////////////////////////////////////////////////////////// diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h index 6e53d83b8..c6532a9bd 100644 --- a/src/Entities/EntityEffect.h +++ b/src/Entities/EntityEffect.h @@ -45,7 +45,15 @@ public: @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */ cEntityEffect(int a_Duration, short a_Intensity, double a_DistanceModifier = 1); - virtual ~cEntityEffect(void); + /** Creates an entity effect by copying another + @param a_OtherEffect The other effect to copy */ + cEntityEffect(const cEntityEffect & a_OtherEffect); + + /** Creates an entity effect by copying another + @param a_OtherEffect The other effect to copy */ + cEntityEffect & operator=(cEntityEffect a_OtherEffect); + + virtual ~cEntityEffect(void) {}; /** Creates a pointer to the proper entity effect from the effect type @warning This function creates raw pointers that must be manually managed. @@ -70,8 +78,8 @@ public: void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; } virtual void OnTick(cPawn & a_Target); - virtual void OnActivate(cPawn & a_Target); - virtual void OnDeactivate(cPawn & a_Target); + virtual void OnActivate(cPawn & a_Target) { } + virtual void OnDeactivate(cPawn & a_Target) { } protected: /** How many ticks this effect has been active for */ -- cgit v1.2.3 From 061010288a99fd11f91bf713ac68068c57f79be7 Mon Sep 17 00:00:00 2001 From: archshift Date: Mon, 14 Jul 2014 13:46:15 -0700 Subject: Readability and clarity changes --- src/Entities/Entity.cpp | 9 ++++++--- src/Entities/EntityEffect.cpp | 41 ++++++++++++++++------------------------- src/Entities/EntityEffect.h | 2 +- 3 files changed, 23 insertions(+), 29 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 042c4b4c3..670e8420a 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -311,10 +311,13 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) // IsOnGround() only is false if the player is moving downwards // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain) - if (!Player->IsOnGround() && (a_TDI.DamageType == dtAttack || a_TDI.DamageType == dtArrowAttack)) + if (!Player->IsOnGround()) { - a_TDI.FinalDamage += 2; - m_World->BroadcastEntityAnimation(*this, 4); // Critical hit + if ((a_TDI.DamageType == dtAttack) || (a_TDI.DamageType == dtArrowAttack)) + { + a_TDI.FinalDamage += 2; + m_World->BroadcastEntityAnimation(*this, 4); // Critical hit + } } Player->GetStatManager().AddValue(statDamageDealt, (StatValue)floor(a_TDI.FinalDamage * 10 + 0.5)); diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index 852099b79..12dd17d72 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -113,15 +113,12 @@ void cEntityEffect::OnTick(cPawn & a_Target) void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) { // Base amount = 6, doubles for every increase in intensity - int amount = (int)(6 * std::pow(2.0, m_Intensity) * m_DistanceModifier); + int amount = (int)(6 * (1 << m_Intensity) * m_DistanceModifier); - if (a_Target.IsMob()) + if (a_Target.IsMob() && ((cMonster &) a_Target).IsUndead()) { - if (((cMonster &) a_Target).IsUndead()) - { - a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage - return; - } + a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage + return; } a_Target.Heal(amount); } @@ -136,15 +133,12 @@ void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target) { // Base amount = 6, doubles for every increase in intensity - int amount = (int)(6 * std::pow(2.0, m_Intensity) * m_DistanceModifier); + int amount = (int)(6 * (1 << m_Intensity) * m_DistanceModifier); - if (a_Target.IsMob()) + if (a_Target.IsMob() && ((cMonster &) a_Target).IsUndead()) { - if (((cMonster &) a_Target).IsUndead()) - { - a_Target.Heal(amount); - return; - } + a_Target.Heal(amount); + return; } a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage } @@ -160,18 +154,15 @@ void cEntityEffectRegeneration::OnTick(cPawn & a_Target) { super::OnTick(a_Target); - if (a_Target.IsMob()) + if (a_Target.IsMob() && ((cMonster &) a_Target).IsUndead()) { - if (((cMonster &) a_Target).IsUndead()) - { - return; - } + return; } // Regen frequency = 50 ticks, divided by potion level (Regen II = 25 ticks) int frequency = (int) std::floor(50.0 / (double)(m_Intensity + 1)); - if (m_Ticks % frequency != 0) + if ((m_Ticks % frequency) != 0) { return; } @@ -231,9 +222,9 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target) cMonster & Target = (cMonster &) a_Target; // Doesn't effect undead mobs, spiders - if (Target.IsUndead() - || Target.GetMobType() == cMonster::mtSpider - || Target.GetMobType() == cMonster::mtCaveSpider) + if ((Target.IsUndead()) + || (Target.GetMobType() == cMonster::mtSpider) + || (Target.GetMobType() == cMonster::mtCaveSpider)) { return; } @@ -242,7 +233,7 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target) // Poison frequency = 25 ticks, divided by potion level (Poison II = 12 ticks) int frequency = (int) std::floor(25.0 / (double)(m_Intensity + 1)); - if (m_Ticks % frequency == 0) + if ((m_Ticks % frequency) == 0) { // Cannot take poison damage when health is at 1 if (a_Target.GetHealth() > 1) @@ -266,7 +257,7 @@ void cEntityEffectWither::OnTick(cPawn & a_Target) // Poison frequency = 40 ticks, divided by effect level (Wither II = 20 ticks) int frequency = (int) std::floor(25.0 / (double)(m_Intensity + 1)); - if (m_Ticks % frequency == 0) + if ((m_Ticks % frequency) == 0) { a_Target.TakeDamage(dtWither, NULL, 1, 0); } diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h index c6532a9bd..ea0716d59 100644 --- a/src/Entities/EntityEffect.h +++ b/src/Entities/EntityEffect.h @@ -220,7 +220,7 @@ class cEntityEffectNausea: typedef cEntityEffect super; public: cEntityEffectNausea(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_DistanceModifier) + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; -- cgit v1.2.3 From d27485157847325c82fb93448f4ad05407abbd58 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 15 Jul 2014 09:43:45 +0200 Subject: Fixed a MSVC warning in cEntityEffect::CreateEntityEffect(). --- src/Entities/EntityEffect.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index 12dd17d72..d1f3e9026 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -91,6 +91,7 @@ cEntityEffect * cEntityEffect::CreateEntityEffect(cEntityEffect::eType a_EffectT } ASSERT(!"Unhandled entity effect type!"); + return NULL; } -- cgit v1.2.3 From 5193335efa1c0da08713715844801ee589dcfdf5 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 15 Jul 2014 09:48:11 +0200 Subject: Reformatted EntityEffect code. --- src/Entities/EntityEffect.cpp | 54 +++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index d1f3e9026..761a4d651 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -109,8 +109,8 @@ void cEntityEffect::OnTick(cPawn & a_Target) ///////////////////////////////////////////////////////////////////////// -// Instant Health -///////////////////////////////////////////////////////////////////////// +// cEntityEffectInstantHealth: + void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) { // Base amount = 6, doubles for every increase in intensity @@ -118,7 +118,7 @@ void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) if (a_Target.IsMob() && ((cMonster &) a_Target).IsUndead()) { - a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage + a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage return; } a_Target.Heal(amount); @@ -129,8 +129,8 @@ void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) ///////////////////////////////////////////////////////////////////////// -// Instant Damage -///////////////////////////////////////////////////////////////////////// +// cEntityEffectInstantDamage: + void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target) { // Base amount = 6, doubles for every increase in intensity @@ -141,7 +141,7 @@ void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target) a_Target.Heal(amount); return; } - a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage + a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage } @@ -149,8 +149,8 @@ void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target) ///////////////////////////////////////////////////////////////////////// -// Regeneration -///////////////////////////////////////////////////////////////////////// +// cEntityEffectRegeneration: + void cEntityEffectRegeneration::OnTick(cPawn & a_Target) { super::OnTick(a_Target); @@ -176,8 +176,8 @@ void cEntityEffectRegeneration::OnTick(cPawn & a_Target) ///////////////////////////////////////////////////////////////////////// -// Hunger -///////////////////////////////////////////////////////////////////////// +// cEntityEffectHunger: + void cEntityEffectHunger::OnTick(cPawn & a_Target) { super::OnTick(a_Target); @@ -185,7 +185,7 @@ void cEntityEffectHunger::OnTick(cPawn & a_Target) if (a_Target.IsPlayer()) { cPlayer & Target = (cPlayer &) a_Target; - Target.SetFoodExhaustionLevel(Target.GetFoodExhaustionLevel() + 0.025); // 0.5 per second = 0.025 per tick + Target.SetFoodExhaustionLevel(Target.GetFoodExhaustionLevel() + 0.025); // 0.5 per second = 0.025 per tick } } @@ -194,8 +194,8 @@ void cEntityEffectHunger::OnTick(cPawn & a_Target) ///////////////////////////////////////////////////////////////////////// -// Weakness -///////////////////////////////////////////////////////////////////////// +// cEntityEffectWeakness: + void cEntityEffectWeakness::OnTick(cPawn & a_Target) { super::OnTick(a_Target); @@ -212,8 +212,8 @@ void cEntityEffectWeakness::OnTick(cPawn & a_Target) ///////////////////////////////////////////////////////////////////////// -// Poison -///////////////////////////////////////////////////////////////////////// +// cEntityEffectPoison: + void cEntityEffectPoison::OnTick(cPawn & a_Target) { super::OnTick(a_Target); @@ -223,9 +223,10 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target) cMonster & Target = (cMonster &) a_Target; // Doesn't effect undead mobs, spiders - if ((Target.IsUndead()) - || (Target.GetMobType() == cMonster::mtSpider) - || (Target.GetMobType() == cMonster::mtCaveSpider)) + if (Target.IsUndead() || + (Target.GetMobType() == cMonster::mtSpider) || + (Target.GetMobType() == cMonster::mtCaveSpider) + ) { return; } @@ -249,20 +250,19 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target) ///////////////////////////////////////////////////////////////////////// -// Wither -///////////////////////////////////////////////////////////////////////// +// cEntityEffectWither: + void cEntityEffectWither::OnTick(cPawn & a_Target) { super::OnTick(a_Target); - // Poison frequency = 40 ticks, divided by effect level (Wither II = 20 ticks) + // Damage frequency = 40 ticks, divided by effect level (Wither II = 20 ticks) int frequency = (int) std::floor(25.0 / (double)(m_Intensity + 1)); if ((m_Ticks % frequency) == 0) { a_Target.TakeDamage(dtWither, NULL, 1, 0); } - //TODO: " withered away> } @@ -270,13 +270,17 @@ void cEntityEffectWither::OnTick(cPawn & a_Target) ///////////////////////////////////////////////////////////////////////// -// Saturation -///////////////////////////////////////////////////////////////////////// +// cEntityEffectSaturation: + void cEntityEffectSaturation::OnTick(cPawn & a_Target) { if (a_Target.IsPlayer()) { cPlayer & Target = (cPlayer &) a_Target; - Target.SetFoodSaturationLevel(Target.GetFoodSaturationLevel() + (1 + m_Intensity)); // Increase saturation 1 per tick, adds 1 for every increase in level + Target.SetFoodSaturationLevel(Target.GetFoodSaturationLevel() + (1 + m_Intensity)); // Increase saturation 1 per tick, adds 1 for every increase in level } } + + + + -- cgit v1.2.3 From f5259d765147cecb44a40ce5308387aba60cef8f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 15 Jul 2014 11:24:48 +0200 Subject: Only the cEntityEffect::effXXX constants are Lua-exported. The rest of the classes don't need exporting, there's no interface using them anyway. --- src/Entities/EntityEffect.cpp | 3 +- src/Entities/EntityEffect.h | 171 ++++++++++++++++++++++++------------------ 2 files changed, 102 insertions(+), 72 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index 761a4d651..4da7cac85 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -223,7 +223,8 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target) cMonster & Target = (cMonster &) a_Target; // Doesn't effect undead mobs, spiders - if (Target.IsUndead() || + if ( + Target.IsUndead() || (Target.GetMobType() == cMonster::mtSpider) || (Target.GetMobType() == cMonster::mtCaveSpider) ) diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h index ea0716d59..a06c1512d 100644 --- a/src/Entities/EntityEffect.h +++ b/src/Entities/EntityEffect.h @@ -36,6 +36,8 @@ public: effSaturation = 23, } ; + // tolua_end + /** Creates an empty entity effect */ cEntityEffect(void); @@ -93,11 +95,12 @@ protected: /** The distance modifier for affecting potency */ double m_DistanceModifier; -}; +}; // tolua_export + + + + -///////////////////////////////////////////////////////////////////////// -// Speed -///////////////////////////////////////////////////////////////////////// class cEntityEffectSpeed: public cEntityEffect { @@ -109,9 +112,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Slowness -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectSlowness: public cEntityEffect { @@ -123,9 +127,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Haste -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectHaste: public cEntityEffect { @@ -137,9 +142,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Mining Fatigue -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectMiningFatigue: public cEntityEffect { @@ -151,9 +157,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Strength -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectStrength: public cEntityEffect { @@ -165,9 +172,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Instant Health -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectInstantHealth: public cEntityEffect { @@ -181,9 +189,10 @@ public: virtual void OnActivate(cPawn & a_Target) override; }; -///////////////////////////////////////////////////////////////////////// -// Instant Damage -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectInstantDamage: public cEntityEffect { @@ -197,9 +206,10 @@ public: virtual void OnActivate(cPawn & a_Target) override; }; -///////////////////////////////////////////////////////////////////////// -// Jump Boost -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectJumpBoost: public cEntityEffect { @@ -211,9 +221,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Nausea -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectNausea: public cEntityEffect { @@ -225,9 +236,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Regeneration -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectRegeneration: public cEntityEffect { @@ -241,9 +253,10 @@ public: virtual void OnTick(cPawn & a_Target) override; }; -///////////////////////////////////////////////////////////////////////// -// Resistance -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectResistance: public cEntityEffect { @@ -255,9 +268,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Fire Resistance -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectFireResistance: public cEntityEffect { @@ -269,9 +283,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Water Breathing -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectWaterBreathing: public cEntityEffect { @@ -283,9 +298,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Invisibility -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectInvisibility: public cEntityEffect { @@ -297,9 +313,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Blindness -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectBlindness: public cEntityEffect { @@ -311,9 +328,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Night Vision -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectNightVision: public cEntityEffect { @@ -325,9 +343,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Hunger -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectHunger: public cEntityEffect { @@ -338,12 +357,14 @@ public: { } + // cEntityEffect overrides: virtual void OnTick(cPawn & a_Target) override; }; -///////////////////////////////////////////////////////////////////////// -// Weakness -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectWeakness: public cEntityEffect { @@ -354,12 +375,14 @@ public: { } + // cEntityEffect overrides: virtual void OnTick(cPawn & a_Target) override; }; -///////////////////////////////////////////////////////////////////////// -// Poison -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectPoison: public cEntityEffect { @@ -370,12 +393,14 @@ public: { } + // cEntityEffect overrides: virtual void OnTick(cPawn & a_Target) override; }; -///////////////////////////////////////////////////////////////////////// -// Wither -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectWither: public cEntityEffect { @@ -386,12 +411,14 @@ public: { } + // cEntityEffect overrides: virtual void OnTick(cPawn & a_Target) override; }; -///////////////////////////////////////////////////////////////////////// -// Health Boost -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectHealthBoost: public cEntityEffect { @@ -403,9 +430,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Absorption -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectAbsorption: public cEntityEffect { @@ -417,9 +445,10 @@ public: } }; -///////////////////////////////////////////////////////////////////////// -// Saturation -///////////////////////////////////////////////////////////////////////// + + + + class cEntityEffectSaturation: public cEntityEffect { @@ -435,4 +464,4 @@ public: -// tolua_end + -- cgit v1.2.3 From cc452f51c8c4e1c886932d2f7965c7b3e4ab42fe Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 15 Jul 2014 22:41:42 +0200 Subject: Restructured cSplashPotionEntity code. The callback doesn't need declaration in the header. Renamed PotionName to PotionParticleType. --- src/Entities/EntityEffect.h | 19 +++++-- src/Entities/SplashPotionEntity.cpp | 107 +++++++++++++++++++++++------------- src/Entities/SplashPotionEntity.h | 46 +++++++--------- 3 files changed, 102 insertions(+), 70 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h index a06c1512d..ebd611ff0 100644 --- a/src/Entities/EntityEffect.h +++ b/src/Entities/EntityEffect.h @@ -7,7 +7,7 @@ class cEntityEffect { public: - /** All types of entity effects (numbers correspond to IDs) */ + /** All types of entity effects (numbers correspond to protocol / storage types) */ enum eType { effNoEffect = 0, @@ -66,21 +66,30 @@ public: static cEntityEffect * CreateEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, double a_DistanceModifier); /** Returns how many ticks this effect has been active for */ - int GetTicks() { return m_Ticks; } + int GetTicks(void) const { return m_Ticks; } + /** Returns the duration of the effect */ - int GetDuration() { return m_Duration; } + int GetDuration(void) const { return m_Duration; } + /** Returns how strong the effect will be applied */ - short GetIntensity() { return m_Intensity; } + short GetIntensity(void) const { return m_Intensity; } + /** Returns the distance modifier for affecting potency */ - double GetDistanceModifier() { return m_DistanceModifier; } + double GetDistanceModifier(void) const { return m_DistanceModifier; } void SetTicks(int a_Ticks) { m_Ticks = a_Ticks; } void SetDuration(int a_Duration) { m_Duration = a_Duration; } void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; } void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; } + /** Called on each tick. + By default increases the m_Ticks, descendants may override to provide additional processing. */ virtual void OnTick(cPawn & a_Target); + + /** Called when the effect is first added to an entity */ virtual void OnActivate(cPawn & a_Target) { } + + /** Called when the effect is removed from an entity */ virtual void OnDeactivate(cPawn & a_Target) { } protected: diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index e84f1c430..804026cc0 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -7,11 +7,77 @@ -cSplashPotionEntity::cSplashPotionEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed, cEntityEffect::eType a_EntityEffectType, cEntityEffect a_EntityEffect, int a_PotionName) : +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cSplashPotionEntityCallback: + +/** Used to distribute the splashed potion effect among nearby entities */ +class cSplashPotionCallback : + public cEntityCallback +{ +public: + /** Creates the callback. + @param a_HitPos The position where the splash potion has splashed + @param a_EntityEffectType The effect type of the potion + @param a_EntityEffect The effect description */ + cSplashPotionCallback(const Vector3d & a_HitPos, cEntityEffect::eType a_EntityEffectType, const cEntityEffect & a_EntityEffect) : + m_HitPos(a_HitPos), + m_EntityEffectType(a_EntityEffectType), + m_EntityEffect(a_EntityEffect) + { + } + + /** Called by cWorld::ForEachEntity(), adds the stored entity effect to the entity, if it is close enough. */ + virtual bool Item(cEntity * a_Entity) override + { + double SplashDistance = (a_Entity->GetPosition() - m_HitPos).Length(); + if (SplashDistance >= 20) + { + // Too far away + return false; + } + if (!a_Entity->IsPawn()) + { + // Not an entity that can take effects + return false; + } + + // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash. + // TODO: better equation + double Reduction = -0.25 * SplashDistance + 1.0; + if (Reduction < 0) + { + Reduction = 0; + } + + ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction); + return false; + } + +private: + const Vector3d & m_HitPos; + cEntityEffect::eType m_EntityEffectType; + const cEntityEffect & m_EntityEffect; +}; + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cSplashPotionEntity: + +cSplashPotionEntity::cSplashPotionEntity( + cEntity * a_Creator, + double a_X, double a_Y, double a_Z, + const Vector3d & a_Speed, + cEntityEffect::eType a_EntityEffectType, + cEntityEffect a_EntityEffect, + int a_PotionParticleType +) : super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), m_EntityEffectType(a_EntityEffectType), m_EntityEffect(a_EntityEffect), - m_PotionName(a_PotionName) + m_PotionParticleType(a_PotionParticleType) { SetSpeed(a_Speed); } @@ -46,42 +112,7 @@ void cSplashPotionEntity::Splash(const Vector3d & a_HitPos) cSplashPotionCallback Callback(a_HitPos, m_EntityEffectType, m_EntityEffect); m_World->ForEachEntity(Callback); - m_World->BroadcastSoundParticleEffect(2002, a_HitPos.x, a_HitPos.y, a_HitPos.z, m_PotionName); -} - - - - - -cSplashPotionEntity::cSplashPotionCallback::cSplashPotionCallback(const Vector3d & a_HitPos, cEntityEffect::eType &a_EntityEffectType, cEntityEffect &a_EntityEffect): - m_HitPos(a_HitPos), - m_EntityEffectType(a_EntityEffectType), - m_EntityEffect(a_EntityEffect) -{ - -} - - - - - -bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity) -{ - double SplashDistance = (a_Entity->GetPosition() - m_HitPos).Length(); - if (SplashDistance < 20 && a_Entity->IsPawn()) - { - // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash. - // TODO: better equation - double Reduction = -0.25 * SplashDistance + 1.0; - if (Reduction < 0) - { - Reduction = 0; - } - - m_EntityEffect.SetDistanceModifier(Reduction); - ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction); - } - return false; + m_World->BroadcastSoundParticleEffect(2002, a_HitPos.x, a_HitPos.y, a_HitPos.z, m_PotionParticleType); } diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h index ad656d8ab..076e477da 100644 --- a/src/Entities/SplashPotionEntity.h +++ b/src/Entities/SplashPotionEntity.h @@ -25,43 +25,35 @@ public: CLASS_PROTODEF(cSplashPotionEntity); - cSplashPotionEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed, cEntityEffect::eType a_EntityEffectType, cEntityEffect a_EntityEffect, int a_PotionName); - - cEntityEffect::eType GetEntityEffectType() { return m_EntityEffectType; } - cEntityEffect GetEntityEffect() { return m_EntityEffect; } - int GetPotionName() { return m_PotionName; } + cSplashPotionEntity( + cEntity * a_Creator, + double a_X, double a_Y, double a_Z, + const Vector3d & a_Speed, + cEntityEffect::eType a_EntityEffectType, + cEntityEffect a_EntityEffect, + int a_PotionParticleType + ); + + cEntityEffect::eType GetEntityEffectType (void) const { return m_EntityEffectType; } + cEntityEffect GetEntityEffect (void) const { return m_EntityEffect; } + int GetPotionParticleType(void) const { return m_PotionParticleType; } void SetEntityEffectType(cEntityEffect::eType a_EntityEffectType) { m_EntityEffectType = a_EntityEffectType; } void SetEntityEffect(cEntityEffect a_EntityEffect) { m_EntityEffect = a_EntityEffect; } - void SetPotionName(int a_PotionName) { m_PotionName = a_PotionName; } + void SetPotionParticleType(int a_PotionParticleType) { m_PotionParticleType = a_PotionParticleType; } protected: + cEntityEffect::eType m_EntityEffectType; + cEntityEffect m_EntityEffect; + int m_PotionParticleType; + + // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; /** Splashes the potion, fires its particle effects and sounds - * @param a_HitPos The position where the potion will splash - */ + @param a_HitPos The position where the potion will splash */ void Splash(const Vector3d & a_HitPos); - - cEntityEffect::eType m_EntityEffectType; - cEntityEffect m_EntityEffect; - int m_PotionName; - - class cSplashPotionCallback : - public cEntityCallback - { - public: - cSplashPotionCallback(const Vector3d & a_HitPos, cEntityEffect::eType &a_EntityEffectType, cEntityEffect &a_EntityEffect); - - virtual bool Item(cEntity *a_Entity) override; - - private: - const Vector3d &m_HitPos; - cEntityEffect::eType &m_EntityEffectType; - cEntityEffect &m_EntityEffect; - }; - } ; // tolua_export -- cgit v1.2.3 From cd1e6f8ef028ea2a24e52190d305a62e6cfa62ab Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 10:24:29 +0200 Subject: Fixed formatting for cWitherSkullEntity --- src/Entities/WitherSkullEntity.cpp | 11 ++++++++++- src/Entities/WitherSkullEntity.h | 5 +++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/WitherSkullEntity.cpp b/src/Entities/WitherSkullEntity.cpp index 03e36a3f4..a7e774bba 100644 --- a/src/Entities/WitherSkullEntity.cpp +++ b/src/Entities/WitherSkullEntity.cpp @@ -1,3 +1,8 @@ + +// WitherSkullEntity.cpp + +// Implements the cWitherSkullEntity class representing the entity used by both blue and black wither skulls + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "WitherSkullEntity.h" @@ -8,7 +13,7 @@ cWitherSkullEntity::cWitherSkullEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkWitherSkull, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) + super(pkWitherSkull, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) { SetSpeed(a_Speed); } @@ -38,3 +43,7 @@ void cWitherSkullEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_H Destroy(true); } + + + + diff --git a/src/Entities/WitherSkullEntity.h b/src/Entities/WitherSkullEntity.h index 85ba55d4d..8b3639802 100644 --- a/src/Entities/WitherSkullEntity.h +++ b/src/Entities/WitherSkullEntity.h @@ -1,6 +1,7 @@ -// + // WitherSkullEntity.h -// + +// Declares the cWitherSkullEntity class representing the entity used by both blue and black wither skulls #pragma once -- cgit v1.2.3 From 430d8b42a5b8889ff3c0bfaea84ede7e543e2b64 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 11:07:10 +0200 Subject: Updated cPawn::KilledBy signature for custom death messages. --- src/Entities/Pawn.cpp | 4 ++-- src/Entities/Pawn.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 840736f6a..fe6c24a7a 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -49,10 +49,10 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk) -void cPawn::KilledBy(cEntity * a_Killer) +void cPawn::KilledBy(TakeDamageInfo & a_TDI) { ClearEntityEffects(); - super::KilledBy(a_Killer); + super::KilledBy(a_TDI); } diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index 252ec5edb..63c7cfbb6 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -21,7 +21,7 @@ public: cPawn(eEntityType a_EntityType, double a_Width, double a_Height); virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - virtual void KilledBy(cEntity * a_Killer) override; + virtual void KilledBy(TakeDamageInfo & a_TDI) override; // tolua_begin -- cgit v1.2.3 From 70f304a96b48de5c31993d9ee87c4b661e3c615c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 11:07:33 +0200 Subject: Fixed 3 MSVC warnings in SplashPotionEntity. --- src/Entities/SplashPotionEntity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index 804026cc0..ed5afaf11 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -112,7 +112,7 @@ void cSplashPotionEntity::Splash(const Vector3d & a_HitPos) cSplashPotionCallback Callback(a_HitPos, m_EntityEffectType, m_EntityEffect); m_World->ForEachEntity(Callback); - m_World->BroadcastSoundParticleEffect(2002, a_HitPos.x, a_HitPos.y, a_HitPos.z, m_PotionParticleType); + m_World->BroadcastSoundParticleEffect(2002, (int)a_HitPos.x, (int)a_HitPos.y, (int)a_HitPos.z, m_PotionParticleType); } -- cgit v1.2.3