From b02a81678c22b00955bc3b2b87ceed55027bb35a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 22 Dec 2013 20:04:17 +0000 Subject: Implemented knockback and critical hit --- src/Entities/Entity.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/Entities/Entity.cpp') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 8fcdcc82f..0f5ed7262 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -13,6 +13,7 @@ #include "../Bindings/PluginManager.h" #include "../Tracer.h" #include "Minecart.h" +#include "Player.h" @@ -239,10 +240,14 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R TDI.Attacker = a_Attacker; TDI.RawDamage = a_RawDamage; TDI.FinalDamage = a_FinalDamage; - Vector3d Heading; - Heading.x = sin(GetRotation()); - Heading.y = 0.4; // TODO: adjust the amount of "up" knockback when testing - Heading.z = cos(GetRotation()); + + Vector3d Heading(0, 0, 0); + if (a_Attacker != NULL) + { + Heading = a_Attacker->GetLookVector() * (a_Attacker->IsSprinting() ? 10 : 8); + } + Heading.y += 3; + TDI.Knockback = Heading * a_KnockbackAmount; DoTakeDamage(TDI); } @@ -297,6 +302,16 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) return; } + if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer())) + { + // IsOnGround() only is true if the player is moving downwards + if (!((cPlayer *)a_TDI.Attacker)->IsOnGround()) // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain) + { + a_TDI.FinalDamage + 2; + m_World->BroadcastEntityAnimation(*this, 4); // Critical hit + } + } + m_Health -= (short)a_TDI.FinalDamage; // TODO: Apply damage to armor @@ -306,6 +321,8 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) m_Health = 0; } + AddSpeed(a_TDI.Knockback * 3); + m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_HURT); if (m_Health <= 0) -- cgit v1.2.3 From d8221854d2f529e8165d5153c767bb29a54646a8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 23 Dec 2013 09:41:45 +0000 Subject: Fixed a comment in Entity.cpp --- src/Entities/Entity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities/Entity.cpp') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 0f5ed7262..d82a89ab2 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -304,7 +304,7 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer())) { - // IsOnGround() only is true if the player is moving downwards + // IsOnGround() only is false if the player is moving downwards if (!((cPlayer *)a_TDI.Attacker)->IsOnGround()) // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain) { a_TDI.FinalDamage + 2; -- cgit v1.2.3 From 89f87f66a5b64619cacf86461c1a0f26563e34c5 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 24 Dec 2013 15:02:35 +0000 Subject: Improved knockback animation * Critical hits now actually increase damage * Looking down at an entity and hitting them still produces upwards motion (as per Vanilla experience) * Reduced force to be more realistic --- src/Entities/Entity.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Entities/Entity.cpp') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index d82a89ab2..8a74c9da4 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -246,7 +246,7 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R { Heading = a_Attacker->GetLookVector() * (a_Attacker->IsSprinting() ? 10 : 8); } - Heading.y += 3; + Heading.y = 2; TDI.Knockback = Heading * a_KnockbackAmount; DoTakeDamage(TDI); @@ -307,7 +307,7 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) // IsOnGround() only is false if the player is moving downwards if (!((cPlayer *)a_TDI.Attacker)->IsOnGround()) // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain) { - a_TDI.FinalDamage + 2; + a_TDI.FinalDamage += 2; m_World->BroadcastEntityAnimation(*this, 4); // Critical hit } } @@ -321,7 +321,7 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) m_Health = 0; } - AddSpeed(a_TDI.Knockback * 3); + AddSpeed(a_TDI.Knockback * 2); m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_HURT); -- cgit v1.2.3