1
0

Added some Enchantments

- Bow enchantments: Infinity, Flame and Power
- Sword and tools enchantments: Fire Aspect, Bane of Arthropods, Smite,
Sharpness
This commit is contained in:
Jaume Aloy 2014-08-19 12:38:15 +02:00
parent e045a25e10
commit d3fd63c9eb
4 changed files with 100 additions and 7 deletions

View File

@ -18,6 +18,7 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a
m_HitGroundTimer(0),
m_HasTeleported(false),
m_bIsCollected(false),
m_Creator(a_Creator),
m_HitBlockPos(Vector3i(0, 0, 0))
{
SetSpeed(a_Speed);
@ -43,6 +44,7 @@ cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) :
m_HitGroundTimer(0),
m_HasTeleported(false),
m_bIsCollected(false),
m_Creator(&a_Player),
m_HitBlockPos(0, 0, 0)
{
if (a_Player.IsGameModeCreative())
@ -68,9 +70,6 @@ bool cArrowEntity::CanPickup(const cPlayer & a_Player) const
}
void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace)
{
if (GetSpeed().EqualsEps(Vector3d(0, 0, 0), 0.0000001))
@ -90,6 +89,13 @@ void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFa
// Broadcast arrow hit sound
m_World->BroadcastSoundEffect("random.bowhit", (double)X, (double)Y, (double)Z, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
if ((m_World->GetBlock(Hit) == E_BLOCK_TNT) && (m_TicksLeftBurning > 0))
{
m_World->SetBlock(X, Y, Z, E_BLOCK_AIR, 0);
m_World->SpawnPrimedTNT(X, Y, Z);
}
}
@ -103,8 +109,22 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
{
Damage += m_World->GetTickRandomNumber(Damage / 2 + 2);
}
LOGD("Arrow hit an entity");
int PowerLevel = m_Creator->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchPower);
if (PowerLevel > 0)
{
LOGD("Arrow hit an entity 2");
int ExtraDamage = 0.25 * (PowerLevel + 1);
Damage += ceil(ExtraDamage);
}
a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1);
if (m_TicksLeftBurning > 0)
{
a_EntityHit.StartBurning(100);
}
// Broadcast successful hit sound
GetWorld()->BroadcastSoundEffect("random.successful_hit", GetPosX(), GetPosY(), GetPosZ(), 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));

View File

@ -10,6 +10,7 @@
// tolua_begin
class cArrowEntity :
@ -46,7 +47,7 @@ public:
/// Returns the damage modifier coeff.
double GetDamageCoeff(void) const { return m_DamageCoeff; }
/// Sets the damage modifier coeff
void SetDamageCoeff(double a_DamageCoeff) { m_DamageCoeff = a_DamageCoeff; }
@ -89,7 +90,9 @@ protected:
/// If true, the arrow is in the process of being collected - don't go to anyone else
bool m_bIsCollected;
cEntity * m_Creator;
/// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air
Vector3i m_HitBlockPos;

View File

@ -316,8 +316,68 @@ 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())
cEnchantments Enchantments = Player->GetEquippedItem().m_Enchantments;
int SharpnessLevel = Enchantments.GetLevel(cEnchantments::enchSharpness);
int SmiteLevel = Enchantments.GetLevel(cEnchantments::enchSmite);
int BaneOfArthropodsLevel = Enchantments.GetLevel(cEnchantments::enchBaneOfArthropods);
if (SharpnessLevel > 0)
{
a_TDI.RawDamage += 1.25 * SharpnessLevel;
}
else if (SmiteLevel > 0)
{
if (IsMob())
{
cMonster * Monster = (cMonster *)this;
switch (Monster->GetMobType())
{
case cMonster::mtSkeleton:
case cMonster::mtZombie:
case cMonster::mtWither:
case cMonster::mtZombiePigman:
{
a_TDI.RawDamage += 2.5 * SmiteLevel;
break;
}
}
}
}
else if (BaneOfArthropodsLevel > 0)
{
if (IsMob())
{
cMonster * Monster = (cMonster *)this;
switch (Monster->GetMobType())
{
case cMonster::mtSpider:
case cMonster::mtCaveSpider:
case cMonster::mtSilverfish:
{
a_TDI.RawDamage += 2.5 * BaneOfArthropodsLevel;
break;
}
}
}
}
int FireAspectLevel = Enchantments.GetLevel(cEnchantments::enchFireAspect);
if (FireAspectLevel > 0)
{
int BurnTicks = 3;
if (FireAspectLevel > 1)
{
BurnTicks += 4 * (FireAspectLevel - 1);
}
StartBurning(BurnTicks * 20);
}
if (!Player->IsOnGround())
{
if ((a_TDI.DamageType == dtAttack) || (a_TDI.DamageType == dtArrowAttack))
{
a_TDI.FinalDamage += 2;

View File

@ -75,7 +75,6 @@ public:
Arrow = NULL;
return;
}
a_Player->GetWorld()->BroadcastSoundEffect("random.bow", a_Player->GetPosX(), a_Player->GetPosY(), a_Player->GetPosZ(), 0.5, (float)Force);
if (!a_Player->IsGameModeCreative())
{
@ -83,8 +82,19 @@ public:
{
a_Player->GetInventory().RemoveItem(cItem(E_ITEM_ARROW));
}
else
{
Arrow->SetPickupState(cArrowEntity::ePickupState::psNoPickup);
}
a_Player->UseEquippedItem();
}
if (a_Player->GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchFlame) > 0)
{
Arrow->StartBurning(100);
}
}
} ;