1
0

Implemented knockback and critical hit

This commit is contained in:
Tiger Wang 2013-12-22 20:04:17 +00:00
parent 43e8196309
commit b02a81678c

View File

@ -13,6 +13,7 @@
#include "../Bindings/PluginManager.h" #include "../Bindings/PluginManager.h"
#include "../Tracer.h" #include "../Tracer.h"
#include "Minecart.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.Attacker = a_Attacker;
TDI.RawDamage = a_RawDamage; TDI.RawDamage = a_RawDamage;
TDI.FinalDamage = a_FinalDamage; TDI.FinalDamage = a_FinalDamage;
Vector3d Heading;
Heading.x = sin(GetRotation()); Vector3d Heading(0, 0, 0);
Heading.y = 0.4; // TODO: adjust the amount of "up" knockback when testing if (a_Attacker != NULL)
Heading.z = cos(GetRotation()); {
Heading = a_Attacker->GetLookVector() * (a_Attacker->IsSprinting() ? 10 : 8);
}
Heading.y += 3;
TDI.Knockback = Heading * a_KnockbackAmount; TDI.Knockback = Heading * a_KnockbackAmount;
DoTakeDamage(TDI); DoTakeDamage(TDI);
} }
@ -297,6 +302,16 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
return; 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; m_Health -= (short)a_TDI.FinalDamage;
// TODO: Apply damage to armor // TODO: Apply damage to armor
@ -306,6 +321,8 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
m_Health = 0; m_Health = 0;
} }
AddSpeed(a_TDI.Knockback * 3);
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_HURT); m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_HURT);
if (m_Health <= 0) if (m_Health <= 0)