Thrown potions/enderpearls: cleanup
This commit is contained in:
parent
951e6c76a7
commit
3001e23e8c
@ -71,7 +71,7 @@ theophriene
|
|||||||
tigerw (Tiger Wang)
|
tigerw (Tiger Wang)
|
||||||
tonibm19
|
tonibm19
|
||||||
TooAngel
|
TooAngel
|
||||||
tympaniplayer(Nate Palmer)
|
tympaniplayer (Nate Palmer)
|
||||||
UltraCoderRU
|
UltraCoderRU
|
||||||
Warmist
|
Warmist
|
||||||
WebFreak001
|
WebFreak001
|
||||||
|
@ -1410,9 +1410,11 @@ void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
|
|||||||
// ask plugins to allow teleport to the new position.
|
// ask plugins to allow teleport to the new position.
|
||||||
if (!cRoot::Get()->GetPluginManager()->CallHookEntityTeleport(*this, m_LastPosition, Vector3d(a_PosX, a_PosY, a_PosZ)))
|
if (!cRoot::Get()->GetPluginManager()->CallHookEntityTeleport(*this, m_LastPosition, Vector3d(a_PosX, a_PosY, a_PosZ)))
|
||||||
{
|
{
|
||||||
|
m_IsTeleporting = true;
|
||||||
|
|
||||||
|
Detach();
|
||||||
SetPosition({a_PosX, a_PosY, a_PosZ});
|
SetPosition({a_PosX, a_PosY, a_PosZ});
|
||||||
FreezeInternal(GetPosition(), false);
|
FreezeInternal(GetPosition(), false);
|
||||||
m_IsTeleporting = true;
|
|
||||||
|
|
||||||
m_ClientHandle->SendPlayerMoveLook();
|
m_ClientHandle->SendPlayerMoveLook();
|
||||||
}
|
}
|
||||||
@ -2588,15 +2590,6 @@ void cPlayer::AttachTo(cEntity * a_AttachTo)
|
|||||||
|
|
||||||
|
|
||||||
void cPlayer::Detach()
|
void cPlayer::Detach()
|
||||||
{
|
|
||||||
Detach(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cPlayer::Detach(bool a_IsTeleporting)
|
|
||||||
{
|
{
|
||||||
if (m_AttachedTo == nullptr)
|
if (m_AttachedTo == nullptr)
|
||||||
{
|
{
|
||||||
@ -2604,7 +2597,7 @@ void cPlayer::Detach(bool a_IsTeleporting)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Different detach, if this is a spectator
|
// Different detach, if this is a spectator:
|
||||||
if (IsGameModeSpectator())
|
if (IsGameModeSpectator())
|
||||||
{
|
{
|
||||||
GetClientHandle()->SendCameraSetTo(*this);
|
GetClientHandle()->SendCameraSetTo(*this);
|
||||||
@ -2615,8 +2608,8 @@ void cPlayer::Detach(bool a_IsTeleporting)
|
|||||||
|
|
||||||
Super::Detach();
|
Super::Detach();
|
||||||
|
|
||||||
// If they are teleporting, no need to figure out position
|
// If they are teleporting, no need to figure out position:
|
||||||
if (a_IsTeleporting)
|
if (m_IsTeleporting)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -598,7 +598,6 @@ public:
|
|||||||
// cEntity overrides:
|
// cEntity overrides:
|
||||||
virtual void AttachTo(cEntity * a_AttachTo) override;
|
virtual void AttachTo(cEntity * a_AttachTo) override;
|
||||||
virtual void Detach(void) override;
|
virtual void Detach(void) override;
|
||||||
virtual void Detach(bool a_IsTeleporting);
|
|
||||||
virtual cItem GetEquippedWeapon(void) const override { return m_Inventory.GetEquippedItem(); }
|
virtual cItem GetEquippedWeapon(void) const override { return m_Inventory.GetEquippedItem(); }
|
||||||
virtual cItem GetEquippedHelmet(void) const override { return m_Inventory.GetEquippedHelmet(); }
|
virtual cItem GetEquippedHelmet(void) const override { return m_Inventory.GetEquippedHelmet(); }
|
||||||
virtual cItem GetEquippedChestplate(void) const override { return m_Inventory.GetEquippedChestplate(); }
|
virtual cItem GetEquippedChestplate(void) const override { return m_Inventory.GetEquippedChestplate(); }
|
||||||
|
@ -17,11 +17,9 @@ cSplashPotionEntity::cSplashPotionEntity(
|
|||||||
Vector3d a_Speed,
|
Vector3d a_Speed,
|
||||||
const cItem & a_Item
|
const cItem & a_Item
|
||||||
):
|
):
|
||||||
Super(pkSplashPotion, a_Creator, a_Pos, 0.25f, 0.25f),
|
Super(pkSplashPotion, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f),
|
||||||
m_Item(a_Item),
|
m_Item(a_Item)
|
||||||
m_DestroyTimer(-1)
|
|
||||||
{
|
{
|
||||||
SetSpeed(a_Speed);
|
|
||||||
m_EntityEffectType = cEntityEffect::GetPotionEffectType(a_Item.m_ItemDamage);
|
m_EntityEffectType = cEntityEffect::GetPotionEffectType(a_Item.m_ItemDamage);
|
||||||
m_EntityEffect = cEntityEffect(
|
m_EntityEffect = cEntityEffect(
|
||||||
cEntityEffect::GetPotionEffectDuration(a_Item.m_ItemDamage),
|
cEntityEffect::GetPotionEffectDuration(a_Item.m_ItemDamage),
|
||||||
@ -34,10 +32,30 @@ cSplashPotionEntity::cSplashPotionEntity(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cSplashPotionEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace)
|
void cSplashPotionEntity::Splash(Vector3d a_HitPos)
|
||||||
{
|
{
|
||||||
Splash(a_HitPos);
|
// Look for entities in 8.25 (width) x 4.25 (height) cuboid _centred_ on hit position:
|
||||||
m_DestroyTimer = 2;
|
m_World->ForEachEntityInBox({ a_HitPos.addedY(-4.25 / 2), 8.25 / 2, 4.25 }, [this, a_HitPos](cEntity & a_Entity)
|
||||||
|
{
|
||||||
|
if (!a_Entity.IsPawn())
|
||||||
|
{
|
||||||
|
// Not an entity that can take effects
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SplashDistance = (a_Entity.GetPosition() - a_HitPos).Length();
|
||||||
|
double Reduction = -0.25 * SplashDistance + 1.0; // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash.
|
||||||
|
Reduction = std::max(Reduction, 0.0);
|
||||||
|
|
||||||
|
static_cast<cPawn &>(a_Entity).AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
m_World->BroadcastSoundParticleEffect(
|
||||||
|
EffectID::PARTICLE_SPLASH_POTION,
|
||||||
|
a_HitPos.Floor(),
|
||||||
|
m_PotionColor
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -46,42 +64,21 @@ void cSplashPotionEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFac
|
|||||||
|
|
||||||
void cSplashPotionEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos)
|
void cSplashPotionEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos)
|
||||||
{
|
{
|
||||||
|
Super::OnHitEntity(a_EntityHit, a_HitPos);
|
||||||
|
|
||||||
a_EntityHit.TakeDamage(dtRangedAttack, this, 0, 1);
|
a_EntityHit.TakeDamage(dtRangedAttack, this, 0, 1);
|
||||||
Splash(a_HitPos);
|
Splash(a_HitPos);
|
||||||
m_DestroyTimer = 5;
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cSplashPotionEntity::Splash(Vector3d a_HitPos)
|
void cSplashPotionEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace)
|
||||||
{
|
{
|
||||||
double XZCalculation = 8.25/2;
|
Super::OnHitSolidBlock(a_HitPos, a_HitFace);
|
||||||
double YCalculation = 4.25/2;
|
|
||||||
cBoundingBox SplashDistanceBox = cBoundingBox(a_HitPos.x - XZCalculation, a_HitPos.x + XZCalculation, a_HitPos.y - YCalculation, a_HitPos.y + YCalculation, a_HitPos.z - XZCalculation, a_HitPos.z + XZCalculation);
|
|
||||||
|
|
||||||
m_World->ForEachEntityInBox(SplashDistanceBox, [=](cEntity & a_Entity)
|
Splash(a_HitPos);
|
||||||
{
|
Destroy();
|
||||||
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.
|
|
||||||
double SplashDistance = (a_Entity.GetPosition() - a_HitPos).Length();
|
|
||||||
double Reduction = -0.25 * SplashDistance + 1.0;
|
|
||||||
Reduction = std::max(Reduction, 0.0);
|
|
||||||
|
|
||||||
static_cast<cPawn &>(a_Entity).AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
m_World->BroadcastSoundParticleEffect(
|
|
||||||
EffectID::PARTICLE_SPLASH_POTION,
|
|
||||||
a_HitPos.Floor(),
|
|
||||||
m_PotionColor
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -52,43 +52,18 @@ public: // tolua_export
|
|||||||
cEntityEffect GetEntityEffect(void) const { return m_EntityEffect; }
|
cEntityEffect GetEntityEffect(void) const { return m_EntityEffect; }
|
||||||
void SetEntityEffect(cEntityEffect a_EntityEffect) { m_EntityEffect = a_EntityEffect; }
|
void SetEntityEffect(cEntityEffect a_EntityEffect) { m_EntityEffect = a_EntityEffect; }
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
|
|
||||||
cEntityEffect::eType m_EntityEffectType;
|
cEntityEffect::eType m_EntityEffectType;
|
||||||
cEntityEffect m_EntityEffect;
|
cEntityEffect m_EntityEffect;
|
||||||
int m_PotionColor;
|
int m_PotionColor;
|
||||||
cItem m_Item;
|
cItem m_Item;
|
||||||
|
|
||||||
|
|
||||||
// cProjectileEntity overrides:
|
|
||||||
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
|
|
||||||
virtual void OnHitEntity (cEntity & a_EntityHit, Vector3d a_HitPos) override;
|
|
||||||
virtual void Tick (std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override
|
|
||||||
{
|
|
||||||
if (m_DestroyTimer > 0)
|
|
||||||
{
|
|
||||||
m_DestroyTimer--;
|
|
||||||
if (m_DestroyTimer == 0)
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Super::Tick(a_Dt, a_Chunk);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Splashes the potion, fires its particle effects and sounds
|
/** 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(Vector3d a_HitPos);
|
void Splash(Vector3d a_HitPos);
|
||||||
|
|
||||||
private:
|
// cProjectileEntity overrides:
|
||||||
/** Time in ticks to wait for the hit animation to begin before destroying */
|
virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
|
||||||
int m_DestroyTimer;
|
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
|
||||||
} ; // tolua_export
|
} ; // tolua_export
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,22 +9,8 @@
|
|||||||
|
|
||||||
|
|
||||||
cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed):
|
cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed):
|
||||||
Super(pkEnderPearl, a_Creator, a_Pos, 0.25f, 0.25f),
|
Super(pkEnderPearl, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f)
|
||||||
m_DestroyTimer(-1)
|
|
||||||
{
|
{
|
||||||
SetSpeed(a_Speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cThrownEnderPearlEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace)
|
|
||||||
{
|
|
||||||
// TODO: Tweak a_HitPos based on block face.
|
|
||||||
TeleportCreator(a_HitPos);
|
|
||||||
|
|
||||||
m_DestroyTimer = 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -33,51 +19,30 @@ void cThrownEnderPearlEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_Hi
|
|||||||
|
|
||||||
void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos)
|
void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos)
|
||||||
{
|
{
|
||||||
int TotalDamage = 0;
|
Super::OnHitEntity(a_EntityHit, a_HitPos);
|
||||||
|
|
||||||
bool isAttachedEntity = GetWorld()->FindAndDoWithPlayer(m_CreatorData.m_Name, [& a_EntityHit](cPlayer & a_Entity)
|
int Damage = 0;
|
||||||
{
|
if (a_EntityHit.IsEnderCrystal())
|
||||||
const cEntity * attachedEntity = a_Entity.GetAttached();
|
|
||||||
if (attachedEntity == nullptr)
|
|
||||||
{
|
|
||||||
// nothing attached
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return attachedEntity->GetUniqueID() == a_EntityHit.GetUniqueID();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
// TODO: If entity is Ender Crystal, destroy it
|
|
||||||
|
|
||||||
|
|
||||||
if (!isAttachedEntity)
|
|
||||||
{
|
{
|
||||||
TeleportCreator(a_HitPos);
|
// Endercrystals are destroyed:
|
||||||
a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1);
|
Damage = CeilC(a_EntityHit.GetHealth());
|
||||||
m_DestroyTimer = 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1);
|
||||||
|
TeleportCreator(a_HitPos);
|
||||||
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cThrownEnderPearlEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
void cThrownEnderPearlEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace)
|
||||||
{
|
{
|
||||||
if (m_DestroyTimer > 0)
|
Super::OnHitSolidBlock(a_HitPos, a_HitFace);
|
||||||
{
|
|
||||||
m_DestroyTimer--;
|
TeleportCreator(a_HitPos);
|
||||||
if (m_DestroyTimer == 0)
|
Destroy();
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Super::Tick(a_Dt, a_Chunk);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -92,12 +57,10 @@ void cThrownEnderPearlEntity::TeleportCreator(Vector3d a_HitPos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GetWorld()->FindAndDoWithPlayer(m_CreatorData.m_Name, [=](cPlayer & a_Entity)
|
GetWorld()->FindAndDoWithPlayer(m_CreatorData.m_Name, [=](cPlayer & a_Entity)
|
||||||
{
|
{
|
||||||
// Teleport the creator here, make them take 5 damage:
|
// Teleport the creator here, make them take 5 damage:
|
||||||
a_Entity.TeleportToCoords(a_HitPos.x, a_HitPos.y + 0.2, a_HitPos.z);
|
a_Entity.TeleportToCoords(a_HitPos.x, a_HitPos.y + 0.2, a_HitPos.z);
|
||||||
a_Entity.TakeDamage(dtEnderPearl, this, 5, 0);
|
a_Entity.TakeDamage(dtEnderPearl, this, 5, 0);
|
||||||
a_Entity.Detach(true);
|
return false;
|
||||||
return true;
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -30,23 +30,13 @@ public: // tolua_export
|
|||||||
|
|
||||||
cThrownEnderPearlEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed);
|
cThrownEnderPearlEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed);
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
|
|
||||||
// cProjectileEntity overrides:
|
|
||||||
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
|
|
||||||
virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
|
|
||||||
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
|
|
||||||
|
|
||||||
/** Teleports the creator where the ender pearl lands */
|
/** Teleports the creator where the ender pearl lands */
|
||||||
void TeleportCreator(Vector3d a_HitPos);
|
void TeleportCreator(Vector3d a_HitPos);
|
||||||
|
|
||||||
private:
|
// cProjectileEntity overrides:
|
||||||
|
virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
|
||||||
/** Time in ticks to wait for the hit animation to begin before destroying */
|
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
|
||||||
int m_DestroyTimer;
|
|
||||||
|
|
||||||
} ; // tolua_export
|
} ; // tolua_export
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user