From d3fd63c9eb5f783da0186efcef81a5b0eb9338d6 Mon Sep 17 00:00:00 2001 From: Jaume Aloy Date: Tue, 19 Aug 2014 12:38:15 +0200 Subject: [PATCH 1/9] Added some Enchantments - Bow enchantments: Infinity, Flame and Power - Sword and tools enchantments: Fire Aspect, Bane of Arthropods, Smite, Sharpness --- src/Entities/ArrowEntity.cpp | 26 +++++++++++++-- src/Entities/ArrowEntity.h | 7 ++-- src/Entities/Entity.cpp | 62 +++++++++++++++++++++++++++++++++++- src/Items/ItemBow.h | 12 ++++++- 4 files changed, 100 insertions(+), 7 deletions(-) diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index 913519c4c..c4fd378fb 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -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)); diff --git a/src/Entities/ArrowEntity.h b/src/Entities/ArrowEntity.h index 4bfcb1f6d..2ea6e9fde 100644 --- a/src/Entities/ArrowEntity.h +++ b/src/Entities/ArrowEntity.h @@ -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; diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 32f220897..398f7703b 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -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; diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h index fdc24689c..0fc0f0920 100644 --- a/src/Items/ItemBow.h +++ b/src/Items/ItemBow.h @@ -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); + } } } ; From 1897f678f93bb038fdc4caf1fb2995a28ef8f92e Mon Sep 17 00:00:00 2001 From: Jaume Aloy Date: Tue, 19 Aug 2014 16:08:17 +0200 Subject: [PATCH 2/9] Added more enchantments and some fixes - Removed Debug messages - Added Punch enchantment effect - Added Silk Touch enchantment - Added Unbreaking enchantment effect --- src/Blocks/BlockHandler.cpp | 32 ++++++++++++++++++++++++++++---- src/Blocks/BlockIce.h | 24 ++++++++++++------------ src/Entities/ArrowEntity.cpp | 22 ++++++++++++++++++---- src/Entities/ArrowEntity.h | 1 + src/Entities/Entity.cpp | 25 ++++++++++++++++++++++--- src/Entities/Player.cpp | 20 ++++++++++++++++++++ 6 files changed, 101 insertions(+), 23 deletions(-) diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 52f7dd608..3c85a31e0 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -424,19 +424,43 @@ void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterfac cItems Pickups; NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - if (a_CanDrop) + // Thanks to daniel0916 + cPlayer * Player = (cPlayer *)a_Digger; + cEnchantments Enchantments = Player->GetInventory().GetEquippedItem().m_Enchantments; + if (Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0) { - if (!a_DropVerbatim) + BLOCKTYPE Type = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ); + if (Type == E_BLOCK_CAKE || Type == E_BLOCK_CARROTS || Type == E_BLOCK_COCOA_POD || Type == E_BLOCK_DOUBLE_STONE_SLAB || + Type == E_BLOCK_DOUBLE_WOODEN_SLAB || Type == E_BLOCK_FIRE || Type == E_BLOCK_FARMLAND || Type == E_BLOCK_MELON_STEM || + Type == E_BLOCK_MOB_SPAWNER || Type == E_BLOCK_NETHER_WART || Type == E_BLOCK_POTATOES || Type == E_BLOCK_PUMPKIN_STEM || + Type == E_BLOCK_SNOW || Type == E_BLOCK_SUGARCANE || Type == E_BLOCK_TALL_GRASS || Type == E_BLOCK_CROPS + ) { + // Silktouch can't be used for this blocks ConvertToPickups(Pickups, Meta); } else { - // TODO: Add a proper overridable function for this Pickups.Add(m_BlockType, 1, Meta); } } - + else + { + if (a_CanDrop) + { + if (!a_DropVerbatim) + { + ConvertToPickups(Pickups, Meta); + } + else + { + // TODO: Add a proper overridable function for this + Pickups.Add(m_BlockType, 1, Meta); + } + } + + } + // Allow plugins to modify the pickups: a_BlockPluginInterface.CallHookBlockToPickups(a_Digger, a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta, Pickups); diff --git a/src/Blocks/BlockIce.h b/src/Blocks/BlockIce.h index c38630fe3..cfe1d179f 100644 --- a/src/Blocks/BlockIce.h +++ b/src/Blocks/BlockIce.h @@ -30,18 +30,18 @@ public: { return; } - - BLOCKTYPE BlockBelow = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); - if (!cBlockInfo::FullyOccupiesVoxel(BlockBelow) && !IsBlockLiquid(BlockBelow)) + + cEnchantments Enchantments = a_Player->GetInventory().GetEquippedItem().m_Enchantments; + if (Enchantments.GetLevel(cEnchantments::enchSilkTouch) == 0) { - return; + BLOCKTYPE BlockBelow = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); + if (!cBlockInfo::FullyOccupiesVoxel(BlockBelow) && !IsBlockLiquid(BlockBelow)) + { + return; + } + + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_WATER, 0); + // This is called later than the real destroying of this ice block } - - a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_WATER, 0); - // This is called later than the real destroying of this ice block } -} ; - - - - +} ; \ No newline at end of file diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index c4fd378fb..e71f30a66 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -109,18 +109,32 @@ 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); + + int KnockbackAmount = 1; + int PunchLevel = m_Creator->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchPunch); + if (PunchLevel > 0) + { + Vector3f LookVector = m_Creator->GetLookVector(); + Vector3f FinalSpeed = Vector3f(0, 0, 0); + switch (PunchLevel) + { + case 1: FinalSpeed = LookVector * Vector3d(5, 0.3, 5); + case 2: FinalSpeed = LookVector * Vector3d(8, 0.3, 8); + default: break; + } + a_EntityHit.SetSpeed(FinalSpeed); + } + + a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, KnockbackAmount); - if (m_TicksLeftBurning > 0) + if ((m_TicksLeftBurning > 0 && !a_EntityHit.IsSubmerged() && !a_EntityHit.IsSwimming())) { a_EntityHit.StartBurning(100); } diff --git a/src/Entities/ArrowEntity.h b/src/Entities/ArrowEntity.h index 2ea6e9fde..553bcb6e7 100644 --- a/src/Entities/ArrowEntity.h +++ b/src/Entities/ArrowEntity.h @@ -91,6 +91,7 @@ protected: /// If true, the arrow is in the process of being collected - don't go to anyone else bool m_bIsCollected; + // Stores the creator from that arrow cEntity * m_Creator; /// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 398f7703b..05bad3a78 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -316,7 +316,7 @@ 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) - + // Thanks to daniel0916 cEnchantments Enchantments = Player->GetEquippedItem().m_Enchantments; int SharpnessLevel = Enchantments.GetLevel(cEnchantments::enchSharpness); @@ -372,8 +372,27 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) { BurnTicks += 4 * (FireAspectLevel - 1); } + if (!IsMob() && !IsSubmerged() && !IsSwimming()) + { + StartBurning(BurnTicks * 20); + } + else if (IsMob() && !IsSubmerged() && !IsSwimming()) + { + cMonster * Monster = (cMonster *)this; + switch (Monster->GetMobType()) + { + case cMonster::mtGhast: + case cMonster::mtZombiePigman: + case cMonster::mtMagmaCube: + { + + break; + }; + default:StartBurning(BurnTicks * 20); + } + } - StartBurning(BurnTicks * 20); + } if (!Player->IsOnGround()) @@ -410,7 +429,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) case 2: AdditionalSpeed.Set(8, 0.3, 8); break; default: break; } - AddSpeed(a_TDI.Knockback + AdditionalSpeed); + SetSpeed(a_TDI.Knockback + AdditionalSpeed); } m_World->BroadcastEntityStatus(*this, esGenericHurt); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index ab4ff3161..c1031907d 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -17,6 +17,7 @@ #include "../Chunk.h" #include "../Items/ItemHandler.h" #include "../Vector3.h" +#include "../FastRandom.h" #include "../WorldStorage/StatSerializer.h" #include "../CompositeChat.h" @@ -1962,7 +1963,26 @@ void cPlayer::UseEquippedItem(int a_Amount) { return; } + cItem Item = GetEquippedItem(); + int UnbreakingLevel = Item.m_Enchantments.GetLevel(cEnchantments::enchUnbreaking); + if (UnbreakingLevel > 0) + { + int chance; + if (ItemCategory::IsArmor(Item.m_ItemType)) + { + chance = 60 + (40 / (UnbreakingLevel + 1)); + } + else + { + chance = 100 / (UnbreakingLevel + 1); + } + cFastRandom Random; + if (Random.NextInt(100) <= chance) + { + return; + } + } if (GetInventory().DamageEquippedItem(a_Amount)) { m_World->BroadcastSoundEffect("random.break", GetPosX(), GetPosY(), GetPosZ(), 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); From 07350de514cebd9009f5fbdb5774aa8f1266bdb3 Mon Sep 17 00:00:00 2001 From: Jaume Aloy Date: Tue, 19 Aug 2014 16:47:33 +0200 Subject: [PATCH 3/9] Changed if for switch --- src/Blocks/BlockHandler.cpp | 33 ++++++++++++++++++++++----------- src/Blocks/BlockIce.h | 2 +- src/Entities/Entity.cpp | 5 ++--- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 3c85a31e0..1d537b125 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -430,18 +430,29 @@ void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterfac if (Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0) { BLOCKTYPE Type = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ); - if (Type == E_BLOCK_CAKE || Type == E_BLOCK_CARROTS || Type == E_BLOCK_COCOA_POD || Type == E_BLOCK_DOUBLE_STONE_SLAB || - Type == E_BLOCK_DOUBLE_WOODEN_SLAB || Type == E_BLOCK_FIRE || Type == E_BLOCK_FARMLAND || Type == E_BLOCK_MELON_STEM || - Type == E_BLOCK_MOB_SPAWNER || Type == E_BLOCK_NETHER_WART || Type == E_BLOCK_POTATOES || Type == E_BLOCK_PUMPKIN_STEM || - Type == E_BLOCK_SNOW || Type == E_BLOCK_SUGARCANE || Type == E_BLOCK_TALL_GRASS || Type == E_BLOCK_CROPS - ) + switch (Type) { - // Silktouch can't be used for this blocks - ConvertToPickups(Pickups, Meta); - } - else - { - Pickups.Add(m_BlockType, 1, Meta); + case E_BLOCK_CAKE: + case E_BLOCK_CARROTS: + case E_BLOCK_COCOA_POD: + case E_BLOCK_DOUBLE_STONE_SLAB: + case E_BLOCK_DOUBLE_WOODEN_SLAB: + case E_BLOCK_FIRE: + case E_BLOCK_FARMLAND: + case E_BLOCK_MELON_STEM: + case E_BLOCK_MOB_SPAWNER: + case E_BLOCK_NETHER_WART: + case E_BLOCK_POTATOES: + case E_BLOCK_PUMPKIN_STEM: + case E_BLOCK_SNOW: + case E_BLOCK_SUGARCANE: + case E_BLOCK_TALL_GRASS: + case E_BLOCK_CROPS: + { + // Silktouch can't be used for this blocks + ConvertToPickups(Pickups, Meta); + }; + default: Pickups.Add(m_BlockType, 1, Meta); } } else diff --git a/src/Blocks/BlockIce.h b/src/Blocks/BlockIce.h index cfe1d179f..47a84e5a7 100644 --- a/src/Blocks/BlockIce.h +++ b/src/Blocks/BlockIce.h @@ -44,4 +44,4 @@ public: // This is called later than the real destroying of this ice block } } -} ; \ No newline at end of file +} ; diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 05bad3a78..4316b48e9 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -384,11 +384,10 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) case cMonster::mtGhast: case cMonster::mtZombiePigman: case cMonster::mtMagmaCube: - { - + { break; }; - default:StartBurning(BurnTicks * 20); + default: StartBurning(BurnTicks * 20); } } From 596203e692e6322c7f989b1625cbe03dc1eb6a6c Mon Sep 17 00:00:00 2001 From: Jaume Aloy Date: Tue, 19 Aug 2014 17:57:32 +0200 Subject: [PATCH 4/9] Fixes - Changed m_TicksLeftBurning > 0 for IsOnFire() - Tried to do the changes in BlockHandler.cpp - Removed m_Creator in ArrowEntity - Added m_Enchantments in ProjectileEntity CreatorData - Added blank lines between functions --- src/Blocks/BlockHandler.cpp | 70 +++++++++++++++---------------- src/Entities/ArrowEntity.cpp | 15 +++---- src/Entities/ArrowEntity.h | 3 -- src/Entities/ProjectileEntity.cpp | 5 ++- src/Entities/ProjectileEntity.h | 6 ++- src/Items/ItemBow.h | 2 +- 6 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 1d537b125..d6be99f83 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -427,49 +427,49 @@ void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterfac // Thanks to daniel0916 cPlayer * Player = (cPlayer *)a_Digger; cEnchantments Enchantments = Player->GetInventory().GetEquippedItem().m_Enchantments; - if (Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0) + + if (a_CanDrop) { - BLOCKTYPE Type = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ); - switch (Type) + if (!a_DropVerbatim) { - case E_BLOCK_CAKE: - case E_BLOCK_CARROTS: - case E_BLOCK_COCOA_POD: - case E_BLOCK_DOUBLE_STONE_SLAB: - case E_BLOCK_DOUBLE_WOODEN_SLAB: - case E_BLOCK_FIRE: - case E_BLOCK_FARMLAND: - case E_BLOCK_MELON_STEM: - case E_BLOCK_MOB_SPAWNER: - case E_BLOCK_NETHER_WART: - case E_BLOCK_POTATOES: - case E_BLOCK_PUMPKIN_STEM: - case E_BLOCK_SNOW: - case E_BLOCK_SUGARCANE: - case E_BLOCK_TALL_GRASS: - case E_BLOCK_CROPS: + if (Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0) { - // Silktouch can't be used for this blocks - ConvertToPickups(Pickups, Meta); - }; - default: Pickups.Add(m_BlockType, 1, Meta); - } - } - else - { - if (a_CanDrop) - { - if (!a_DropVerbatim) - { - ConvertToPickups(Pickups, Meta); + switch (m_BlockType) + { + case E_BLOCK_CAKE: + case E_BLOCK_CARROTS: + case E_BLOCK_COCOA_POD: + case E_BLOCK_DOUBLE_STONE_SLAB: + case E_BLOCK_DOUBLE_WOODEN_SLAB: + case E_BLOCK_FIRE: + case E_BLOCK_FARMLAND: + case E_BLOCK_MELON_STEM: + case E_BLOCK_MOB_SPAWNER: + case E_BLOCK_NETHER_WART: + case E_BLOCK_POTATOES: + case E_BLOCK_PUMPKIN_STEM: + case E_BLOCK_SNOW: + case E_BLOCK_SUGARCANE: + case E_BLOCK_TALL_GRASS: + case E_BLOCK_CROPS: + { + // Silktouch can't be used for this blocks + ConvertToPickups(Pickups, Meta); + break; + }; + default: Pickups.Add(m_BlockType, 1, Meta); + } } else { - // TODO: Add a proper overridable function for this - Pickups.Add(m_BlockType, 1, Meta); + ConvertToPickups(Pickups, Meta); } } - + else + { + // TODO: Add a proper overridable function for this + Pickups.Add(m_BlockType, 1, Meta); + } } // Allow plugins to modify the pickups: diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index e71f30a66..12149b297 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -18,7 +18,6 @@ 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); @@ -44,7 +43,6 @@ 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()) @@ -70,6 +68,9 @@ 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,7 +91,7 @@ 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)) + if ((m_World->GetBlock(Hit) == E_BLOCK_TNT) && (IsOnFire())) { m_World->SetBlock(X, Y, Z, E_BLOCK_AIR, 0); m_World->SpawnPrimedTNT(X, Y, Z); @@ -110,7 +111,7 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) Damage += m_World->GetTickRandomNumber(Damage / 2 + 2); } - int PowerLevel = m_Creator->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchPower); + int PowerLevel = m_CreatorData.m_Enchantments.GetLevel(cEnchantments::enchPower); if (PowerLevel > 0) { int ExtraDamage = 0.25 * (PowerLevel + 1); @@ -118,10 +119,10 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) } int KnockbackAmount = 1; - int PunchLevel = m_Creator->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchPunch); + int PunchLevel = m_CreatorData.m_Enchantments.GetLevel(cEnchantments::enchPunch); if (PunchLevel > 0) { - Vector3f LookVector = m_Creator->GetLookVector(); + Vector3f LookVector = Vector3d(0, 0, 0); Vector3f FinalSpeed = Vector3f(0, 0, 0); switch (PunchLevel) { @@ -134,7 +135,7 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, KnockbackAmount); - if ((m_TicksLeftBurning > 0 && !a_EntityHit.IsSubmerged() && !a_EntityHit.IsSwimming())) + if ((IsOnFire() && !a_EntityHit.IsSubmerged() && !a_EntityHit.IsSwimming())) { a_EntityHit.StartBurning(100); } diff --git a/src/Entities/ArrowEntity.h b/src/Entities/ArrowEntity.h index 553bcb6e7..a1e7a17e7 100644 --- a/src/Entities/ArrowEntity.h +++ b/src/Entities/ArrowEntity.h @@ -91,9 +91,6 @@ protected: /// If true, the arrow is in the process of being collected - don't go to anyone else bool m_bIsCollected; - // Stores the creator from that arrow - cEntity * m_Creator; - /// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air Vector3i m_HitBlockPos; diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 43023ec28..acc9bd674 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -222,7 +222,8 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a m_ProjectileKind(a_Kind), m_CreatorData( ((a_Creator != NULL) ? a_Creator->GetUniqueID() : -1), - ((a_Creator != NULL) ? (a_Creator->IsPlayer() ? ((cPlayer *)a_Creator)->GetName() : "") : "") + ((a_Creator != NULL) ? (a_Creator->IsPlayer() ? ((cPlayer *)a_Creator)->GetName() : "") : ""), + ((a_Creator != NULL) ? a_Creator->GetEquippedWeapon().m_Enchantments : cEnchantments()) ), m_IsInGround(false) { @@ -235,7 +236,7 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Vector3d & a_Pos, const Vector3d & a_Speed, double a_Width, double a_Height) : super(etProjectile, a_Pos.x, a_Pos.y, a_Pos.z, a_Width, a_Height), m_ProjectileKind(a_Kind), - m_CreatorData(a_Creator->GetUniqueID(), a_Creator->IsPlayer() ? ((cPlayer *)a_Creator)->GetName() : ""), + m_CreatorData(a_Creator->GetUniqueID(), a_Creator->IsPlayer() ? ((cPlayer *)a_Creator)->GetName() : "", a_Creator->GetEquippedWeapon().m_Enchantments), m_IsInGround(false) { SetSpeed(a_Speed); diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 0ebc32f36..58dc38702 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -94,14 +94,16 @@ protected: */ struct CreatorData { - CreatorData(int a_UniqueID, const AString & a_Name) : + CreatorData(int a_UniqueID, const AString & a_Name, cEnchantments a_Enchantments) : m_UniqueID(a_UniqueID), - m_Name(a_Name) + m_Name(a_Name), + m_Enchantments(a_Enchantments) { } const int m_UniqueID; AString m_Name; + cEnchantments m_Enchantments; }; /** The type of projectile I am */ diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h index 0fc0f0920..f29cc5d59 100644 --- a/src/Items/ItemBow.h +++ b/src/Items/ItemBow.h @@ -84,7 +84,7 @@ public: } else { - Arrow->SetPickupState(cArrowEntity::ePickupState::psNoPickup); + Arrow->SetPickupState(cArrowEntity::psNoPickup); } From 5008eb8c8348ad2664158a8a815ef6851d874367 Mon Sep 17 00:00:00 2001 From: Jaume Aloy Date: Tue, 19 Aug 2014 18:40:42 +0200 Subject: [PATCH 5/9] Changed if in BlockHandler --- src/Blocks/BlockHandler.cpp | 7 ++----- src/Entities/Entity.cpp | 1 - 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index d6be99f83..2238a68a0 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -424,15 +424,12 @@ void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterfac cItems Pickups; NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - // Thanks to daniel0916 - cPlayer * Player = (cPlayer *)a_Digger; - cEnchantments Enchantments = Player->GetInventory().GetEquippedItem().m_Enchantments; - if (a_CanDrop) { if (!a_DropVerbatim) { - if (Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0) + cEnchantments Enchantments = a_Digger->GetEquippedWeapon().m_Enchantments; + if ((Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0) && (a_Digger->IsPlayer())) { switch (m_BlockType) { diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 4316b48e9..54e4cf4f5 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -316,7 +316,6 @@ 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) - // Thanks to daniel0916 cEnchantments Enchantments = Player->GetEquippedItem().m_Enchantments; int SharpnessLevel = Enchantments.GetLevel(cEnchantments::enchSharpness); From 19d1c976e7cd7f6c8a4cb3540d5512a035a4162a Mon Sep 17 00:00:00 2001 From: Jaume Aloy Date: Thu, 21 Aug 2014 12:08:38 +0200 Subject: [PATCH 6/9] Protection Enchantments, some fixes - Protection echantments (fire, blast, feather falling, protection and projectile). It isn't finished, add secondary effects and optimize the code. - Removed some brackets. - Silk touch fixed. --- src/Blocks/BlockHandler.cpp | 15 ++--- src/Entities/ArrowEntity.cpp | 10 ++-- src/Entities/Entity.cpp | 110 ++++++++++++++++++++++++++++++++++- src/Entities/Player.cpp | 2 +- 4 files changed, 122 insertions(+), 15 deletions(-) diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 2238a68a0..0155aa97b 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -428,8 +428,14 @@ void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterfac { if (!a_DropVerbatim) { + ConvertToPickups(Pickups, Meta); + } + else + { + // TODO: Add a proper overridable function for this + // Pickups.Add(m_BlockType, 1, Meta); cEnchantments Enchantments = a_Digger->GetEquippedWeapon().m_Enchantments; - if ((Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0) && (a_Digger->IsPlayer())) + if ((Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0) && a_Digger->IsPlayer()) { switch (m_BlockType) { @@ -459,14 +465,9 @@ void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterfac } else { - ConvertToPickups(Pickups, Meta); + Pickups.Add(m_BlockType, 1, Meta); } } - else - { - // TODO: Add a proper overridable function for this - Pickups.Add(m_BlockType, 1, Meta); - } } // Allow plugins to modify the pickups: diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index 12149b297..c3e7c5d79 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -91,7 +91,7 @@ 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) && (IsOnFire())) + if ((m_World->GetBlock(Hit) == E_BLOCK_TNT) && IsOnFire()) { m_World->SetBlock(X, Y, Z, E_BLOCK_AIR, 0); m_World->SpawnPrimedTNT(X, Y, Z); @@ -122,12 +122,12 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) int PunchLevel = m_CreatorData.m_Enchantments.GetLevel(cEnchantments::enchPunch); if (PunchLevel > 0) { - Vector3f LookVector = Vector3d(0, 0, 0); + Vector3d LookVector = GetLookVector(); Vector3f FinalSpeed = Vector3f(0, 0, 0); switch (PunchLevel) { - case 1: FinalSpeed = LookVector * Vector3d(5, 0.3, 5); - case 2: FinalSpeed = LookVector * Vector3d(8, 0.3, 8); + case 1: FinalSpeed = LookVector * Vector3d(5, 0.3, 5); break; + case 2: FinalSpeed = LookVector * Vector3d(8, 0.3, 8); break; default: break; } a_EntityHit.SetSpeed(FinalSpeed); @@ -135,7 +135,7 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, KnockbackAmount); - if ((IsOnFire() && !a_EntityHit.IsSubmerged() && !a_EntityHit.IsSwimming())) + if (IsOnFire() && !a_EntityHit.IsSubmerged() && !a_EntityHit.IsSwimming()) { a_EntityHit.StartBurning(100); } diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 54e4cf4f5..a4c5c4b2a 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -13,6 +13,7 @@ #include "../Tracer.h" #include "Player.h" #include "Items/ItemHandler.h" +#include "../FastRandom.h" @@ -324,7 +325,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) if (SharpnessLevel > 0) { - a_TDI.RawDamage += 1.25 * SharpnessLevel; + a_TDI.FinalDamage += 1.25 * SharpnessLevel; } else if (SmiteLevel > 0) { @@ -338,7 +339,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) case cMonster::mtWither: case cMonster::mtZombiePigman: { - a_TDI.RawDamage += 2.5 * SmiteLevel; + a_TDI.FinalDamage += 2.5 * SmiteLevel; break; } } @@ -404,6 +405,110 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) Player->GetStatManager().AddValue(statDamageDealt, (StatValue)floor(a_TDI.FinalDamage * 10 + 0.5)); } + if (IsPlayer()){ + double TotalEPF = 0.0; + double EPFProtection = 0.00; + double EPFFireProtection = 0.00; + double EPFBlastProtection = 0.00; + double EPFProjectileProtection = 0.00; + double EPFFeatherFalling = 0.00; + + cEnchantments ChestplateEnchantments = GetEquippedChestplate().m_Enchantments; + cEnchantments LeggingsEnchantments = GetEquippedLeggings().m_Enchantments; + cEnchantments BootsEnchantments = GetEquippedBoots().m_Enchantments; + cEnchantments HelmetEnchantments = GetEquippedHelmet().m_Enchantments; + + if ((ChestplateEnchantments.GetLevel(cEnchantments::enchProtection) > 0) || (LeggingsEnchantments.GetLevel(cEnchantments::enchProtection) > 0) + || (BootsEnchantments.GetLevel(cEnchantments::enchProtection) > 0) || (HelmetEnchantments.GetLevel(cEnchantments::enchProtection) > 0)) + { + EPFProtection += (6 + pow(ChestplateEnchantments.GetLevel(cEnchantments::enchProtection), 2)) * 0.75 / 3; + EPFProtection += (6 + pow(LeggingsEnchantments.GetLevel(cEnchantments::enchProtection), 2)) * 0.75 / 3; + EPFProtection += (6 + pow(BootsEnchantments.GetLevel(cEnchantments::enchProtection), 2)) * 0.75 / 3; + EPFProtection += (6 + pow(HelmetEnchantments.GetLevel(cEnchantments::enchProtection), 2)) * 0.75 / 3; + + TotalEPF += EPFProtection; + } + + if ((ChestplateEnchantments.GetLevel(cEnchantments::enchFireProtection) > 0) || (LeggingsEnchantments.GetLevel(cEnchantments::enchFireProtection) > 0) + || (BootsEnchantments.GetLevel(cEnchantments::enchFireProtection) > 0) || (HelmetEnchantments.GetLevel(cEnchantments::enchFireProtection) > 0)) + { + EPFFireProtection += (6 + pow(ChestplateEnchantments.GetLevel(cEnchantments::enchFireProtection), 2)) * 1.25 / 3; + EPFFireProtection += (6 + pow(LeggingsEnchantments.GetLevel(cEnchantments::enchFireProtection), 2)) * 1.25 / 3; + EPFFireProtection += (6 + pow(BootsEnchantments.GetLevel(cEnchantments::enchFireProtection), 2)) * 1.25 / 3; + EPFFireProtection += (6 + pow(HelmetEnchantments.GetLevel(cEnchantments::enchFireProtection), 2)) * 1.25 / 3; + + TotalEPF += EPFFireProtection; + } + + if ((ChestplateEnchantments.GetLevel(cEnchantments::enchFeatherFalling) > 0) || (LeggingsEnchantments.GetLevel(cEnchantments::enchFeatherFalling) > 0) + || (BootsEnchantments.GetLevel(cEnchantments::enchFeatherFalling) > 0) || (HelmetEnchantments.GetLevel(cEnchantments::enchFeatherFalling) > 0)) + { + EPFFeatherFalling += (6 + pow(ChestplateEnchantments.GetLevel(cEnchantments::enchFeatherFalling), 2)) * 2.5 / 3; + EPFFeatherFalling += (6 + pow(LeggingsEnchantments.GetLevel(cEnchantments::enchFeatherFalling), 2)) * 2.5 / 3; + EPFFeatherFalling += (6 + pow(BootsEnchantments.GetLevel(cEnchantments::enchFeatherFalling), 2)) * 2.5 / 3; + EPFFeatherFalling += (6 + pow(HelmetEnchantments.GetLevel(cEnchantments::enchFeatherFalling), 2)) * 2.5 / 3; + + TotalEPF += EPFFeatherFalling; + } + + if ((ChestplateEnchantments.GetLevel(cEnchantments::enchBlastProtection) > 0) || (LeggingsEnchantments.GetLevel(cEnchantments::enchBlastProtection) > 0) + || (BootsEnchantments.GetLevel(cEnchantments::enchBlastProtection) > 0) || (HelmetEnchantments.GetLevel(cEnchantments::enchBlastProtection) > 0)) + { + EPFBlastProtection += (6 + pow(ChestplateEnchantments.GetLevel(cEnchantments::enchBlastProtection), 2)) * 1.5 / 3; + EPFBlastProtection += (6 + pow(LeggingsEnchantments.GetLevel(cEnchantments::enchBlastProtection), 2)) * 1.5 / 3; + EPFBlastProtection += (6 + pow(BootsEnchantments.GetLevel(cEnchantments::enchBlastProtection), 2)) * 1.5 / 3; + EPFBlastProtection += (6 + pow(HelmetEnchantments.GetLevel(cEnchantments::enchBlastProtection), 2)) * 1.5 / 3; + + TotalEPF += EPFBlastProtection; + } + + if ((ChestplateEnchantments.GetLevel(cEnchantments::enchProjectileProtection) > 0) || (LeggingsEnchantments.GetLevel(cEnchantments::enchProjectileProtection) > 0) + || (BootsEnchantments.GetLevel(cEnchantments::enchProjectileProtection) > 0) || (HelmetEnchantments.GetLevel(cEnchantments::enchProjectileProtection) > 0)) + { + EPFProjectileProtection += (6 + pow(ChestplateEnchantments.GetLevel(cEnchantments::enchProjectileProtection), 2)) * 1.5 / 3; + EPFProjectileProtection += (6 + pow(LeggingsEnchantments.GetLevel(cEnchantments::enchProjectileProtection), 2)) * 1.5 / 3; + EPFProjectileProtection += (6 + pow(BootsEnchantments.GetLevel(cEnchantments::enchProjectileProtection), 2)) * 1.5 / 3; + EPFProjectileProtection += (6 + pow(HelmetEnchantments.GetLevel(cEnchantments::enchProjectileProtection), 2)) * 1.5 / 3; + + TotalEPF += EPFProjectileProtection; + } + + EPFProtection = EPFProtection / TotalEPF; + EPFFireProtection = EPFFireProtection / TotalEPF; + EPFFeatherFalling = EPFFeatherFalling / TotalEPF; + EPFBlastProtection = EPFBlastProtection / TotalEPF; + EPFProjectileProtection = EPFProjectileProtection / TotalEPF; + + if (TotalEPF > 25) TotalEPF = 25; + + cFastRandom Random; + float randomvalue; + randomvalue = Random.GenerateRandomInteger(50, 100) * 0.01; + + TotalEPF = ceil(TotalEPF * randomvalue); + + if (TotalEPF > 20) TotalEPF = 20; + + EPFProtection = TotalEPF * EPFProtection; + EPFFireProtection = TotalEPF * EPFFireProtection; + EPFFeatherFalling = TotalEPF * EPFFeatherFalling; + EPFBlastProtection = TotalEPF * EPFBlastProtection; + EPFProjectileProtection = TotalEPF * EPFProjectileProtection; + + int RemovedDamage = 0; + + if (a_TDI.DamageType != dtInVoid) RemovedDamage += ceil(EPFProtection * 0.04 * a_TDI.FinalDamage); + + if ((a_TDI.DamageType == dtFalling) || (a_TDI.DamageType == dtFall) || (a_TDI.DamageType == dtEnderPearl)) RemovedDamage += ceil(EPFFeatherFalling * 0.04 * a_TDI.FinalDamage); + + if (a_TDI.DamageType == dtBurning) RemovedDamage += ceil(EPFFireProtection * 0.04 * a_TDI.FinalDamage); + + if (a_TDI.DamageType == dtExplosion) RemovedDamage += ceil(EPFBlastProtection * 0.04 * a_TDI.FinalDamage); + + if (a_TDI.DamageType == dtProjectile) RemovedDamage += ceil(EPFBlastProtection * 0.04 * a_TDI.FinalDamage); + + a_TDI.FinalDamage -= RemovedDamage; + } m_Health -= (short)a_TDI.FinalDamage; @@ -411,6 +516,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) m_Health = std::max(m_Health, 0); + if ((IsMob() || IsPlayer()) && (a_TDI.Attacker != NULL)) // Knockback for only players and mobs { int KnockbackLevel = a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchKnockback); // More common enchantment diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index c1031907d..8b829d090 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1978,7 +1978,7 @@ void cPlayer::UseEquippedItem(int a_Amount) } cFastRandom Random; - if (Random.NextInt(100) <= chance) + if (Random.NextInt(101) <= chance) { return; } From 7d771953c0e8275311ca13802e52ccf92a170644 Mon Sep 17 00:00:00 2001 From: Jaume Aloy Date: Fri, 22 Aug 2014 11:49:49 +0200 Subject: [PATCH 7/9] More Enchantments - Added Thorns and Respiration enchantments --- src/Blocks/BlockHandler.cpp | 1 - src/Entities/Entity.cpp | 135 ++++++++++++++++++++---------------- 2 files changed, 74 insertions(+), 62 deletions(-) diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 0155aa97b..c8a57906f 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -433,7 +433,6 @@ void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterfac else { // TODO: Add a proper overridable function for this - // Pickups.Add(m_BlockType, 1, Meta); cEnchantments Enchantments = a_Digger->GetEquippedWeapon().m_Enchantments; if ((Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0) && a_Digger->IsPlayer()) { diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index a4c5c4b2a..760401cc2 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -357,8 +357,11 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) case cMonster::mtSilverfish: { a_TDI.RawDamage += 2.5 * BaneOfArthropodsLevel; + // TODO: Add slowness effect + break; - } + }; + default: break; } } } @@ -390,8 +393,27 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) default: StartBurning(BurnTicks * 20); } } + } - + int ThornsLevel = 0; + cItem ArmorItems[] = { GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots() }; + for (size_t i = 0; i < ARRAYCOUNT(ArmorItems); i++) + { + cItem Item = ArmorItems[i]; + if (Item.m_Enchantments.GetLevel(cEnchantments::enchThorns) > ThornsLevel) ThornsLevel = Item.m_Enchantments.GetLevel(cEnchantments::enchThorns); + } + + if (ThornsLevel > 0) + { + int Chance = ThornsLevel * 15; + + cFastRandom Random; + int RandomValue = Random.GenerateRandomInteger(0, 100); + + if (RandomValue <= Chance) + { + a_TDI.Attacker->TakeDamage(dtAttack, this, 0, Random.GenerateRandomInteger(1, 4), 0); + } } if (!Player->IsOnGround()) @@ -405,6 +427,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) Player->GetStatManager().AddValue(statDamageDealt, (StatValue)floor(a_TDI.FinalDamage * 10 + 0.5)); } + if (IsPlayer()){ double TotalEPF = 0.0; double EPFProtection = 0.00; @@ -413,65 +436,39 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) double EPFProjectileProtection = 0.00; double EPFFeatherFalling = 0.00; - cEnchantments ChestplateEnchantments = GetEquippedChestplate().m_Enchantments; - cEnchantments LeggingsEnchantments = GetEquippedLeggings().m_Enchantments; - cEnchantments BootsEnchantments = GetEquippedBoots().m_Enchantments; - cEnchantments HelmetEnchantments = GetEquippedHelmet().m_Enchantments; - - if ((ChestplateEnchantments.GetLevel(cEnchantments::enchProtection) > 0) || (LeggingsEnchantments.GetLevel(cEnchantments::enchProtection) > 0) - || (BootsEnchantments.GetLevel(cEnchantments::enchProtection) > 0) || (HelmetEnchantments.GetLevel(cEnchantments::enchProtection) > 0)) + cItem ArmorItems[] = { GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots() }; + for (size_t i = 0; i < ARRAYCOUNT(ArmorItems); i++) { - EPFProtection += (6 + pow(ChestplateEnchantments.GetLevel(cEnchantments::enchProtection), 2)) * 0.75 / 3; - EPFProtection += (6 + pow(LeggingsEnchantments.GetLevel(cEnchantments::enchProtection), 2)) * 0.75 / 3; - EPFProtection += (6 + pow(BootsEnchantments.GetLevel(cEnchantments::enchProtection), 2)) * 0.75 / 3; - EPFProtection += (6 + pow(HelmetEnchantments.GetLevel(cEnchantments::enchProtection), 2)) * 0.75 / 3; + cItem Item = ArmorItems[i]; + if (Item.m_Enchantments.GetLevel(cEnchantments::enchProtection) > 0) + { + EPFProtection += (6 + pow(Item.m_Enchantments.GetLevel(cEnchantments::enchProtection), 2)) * 0.75 / 3; + } + + if (Item.m_Enchantments.GetLevel(cEnchantments::enchFireProtection) > 0) + { + EPFFireProtection += (6 + pow(Item.m_Enchantments.GetLevel(cEnchantments::enchFireProtection), 2)) * 1.25 / 3; + } + + if (Item.m_Enchantments.GetLevel(cEnchantments::enchFeatherFalling) > 0) + { + EPFFeatherFalling += (6 + pow(Item.m_Enchantments.GetLevel(cEnchantments::enchFeatherFalling), 2)) * 2.5 / 3; + } + + if (Item.m_Enchantments.GetLevel(cEnchantments::enchBlastProtection) > 0) + { + EPFBlastProtection += (6 + pow(Item.m_Enchantments.GetLevel(cEnchantments::enchBlastProtection), 2)) * 1.5 / 3; + } + + if (Item.m_Enchantments.GetLevel(cEnchantments::enchProjectileProtection) > 0) + { + EPFProjectileProtection += (6 + pow(Item.m_Enchantments.GetLevel(cEnchantments::enchProjectileProtection), 2)) * 1.5 / 3; + } - TotalEPF += EPFProtection; } - if ((ChestplateEnchantments.GetLevel(cEnchantments::enchFireProtection) > 0) || (LeggingsEnchantments.GetLevel(cEnchantments::enchFireProtection) > 0) - || (BootsEnchantments.GetLevel(cEnchantments::enchFireProtection) > 0) || (HelmetEnchantments.GetLevel(cEnchantments::enchFireProtection) > 0)) - { - EPFFireProtection += (6 + pow(ChestplateEnchantments.GetLevel(cEnchantments::enchFireProtection), 2)) * 1.25 / 3; - EPFFireProtection += (6 + pow(LeggingsEnchantments.GetLevel(cEnchantments::enchFireProtection), 2)) * 1.25 / 3; - EPFFireProtection += (6 + pow(BootsEnchantments.GetLevel(cEnchantments::enchFireProtection), 2)) * 1.25 / 3; - EPFFireProtection += (6 + pow(HelmetEnchantments.GetLevel(cEnchantments::enchFireProtection), 2)) * 1.25 / 3; - - TotalEPF += EPFFireProtection; - } - - if ((ChestplateEnchantments.GetLevel(cEnchantments::enchFeatherFalling) > 0) || (LeggingsEnchantments.GetLevel(cEnchantments::enchFeatherFalling) > 0) - || (BootsEnchantments.GetLevel(cEnchantments::enchFeatherFalling) > 0) || (HelmetEnchantments.GetLevel(cEnchantments::enchFeatherFalling) > 0)) - { - EPFFeatherFalling += (6 + pow(ChestplateEnchantments.GetLevel(cEnchantments::enchFeatherFalling), 2)) * 2.5 / 3; - EPFFeatherFalling += (6 + pow(LeggingsEnchantments.GetLevel(cEnchantments::enchFeatherFalling), 2)) * 2.5 / 3; - EPFFeatherFalling += (6 + pow(BootsEnchantments.GetLevel(cEnchantments::enchFeatherFalling), 2)) * 2.5 / 3; - EPFFeatherFalling += (6 + pow(HelmetEnchantments.GetLevel(cEnchantments::enchFeatherFalling), 2)) * 2.5 / 3; - - TotalEPF += EPFFeatherFalling; - } - - if ((ChestplateEnchantments.GetLevel(cEnchantments::enchBlastProtection) > 0) || (LeggingsEnchantments.GetLevel(cEnchantments::enchBlastProtection) > 0) - || (BootsEnchantments.GetLevel(cEnchantments::enchBlastProtection) > 0) || (HelmetEnchantments.GetLevel(cEnchantments::enchBlastProtection) > 0)) - { - EPFBlastProtection += (6 + pow(ChestplateEnchantments.GetLevel(cEnchantments::enchBlastProtection), 2)) * 1.5 / 3; - EPFBlastProtection += (6 + pow(LeggingsEnchantments.GetLevel(cEnchantments::enchBlastProtection), 2)) * 1.5 / 3; - EPFBlastProtection += (6 + pow(BootsEnchantments.GetLevel(cEnchantments::enchBlastProtection), 2)) * 1.5 / 3; - EPFBlastProtection += (6 + pow(HelmetEnchantments.GetLevel(cEnchantments::enchBlastProtection), 2)) * 1.5 / 3; - - TotalEPF += EPFBlastProtection; - } - - if ((ChestplateEnchantments.GetLevel(cEnchantments::enchProjectileProtection) > 0) || (LeggingsEnchantments.GetLevel(cEnchantments::enchProjectileProtection) > 0) - || (BootsEnchantments.GetLevel(cEnchantments::enchProjectileProtection) > 0) || (HelmetEnchantments.GetLevel(cEnchantments::enchProjectileProtection) > 0)) - { - EPFProjectileProtection += (6 + pow(ChestplateEnchantments.GetLevel(cEnchantments::enchProjectileProtection), 2)) * 1.5 / 3; - EPFProjectileProtection += (6 + pow(LeggingsEnchantments.GetLevel(cEnchantments::enchProjectileProtection), 2)) * 1.5 / 3; - EPFProjectileProtection += (6 + pow(BootsEnchantments.GetLevel(cEnchantments::enchProjectileProtection), 2)) * 1.5 / 3; - EPFProjectileProtection += (6 + pow(HelmetEnchantments.GetLevel(cEnchantments::enchProjectileProtection), 2)) * 1.5 / 3; - - TotalEPF += EPFProjectileProtection; - } + TotalEPF = EPFProtection + EPFFireProtection + EPFFeatherFalling + EPFBlastProtection + EPFProjectileProtection; + EPFProtection = EPFProtection / TotalEPF; EPFFireProtection = EPFFireProtection / TotalEPF; @@ -482,10 +479,9 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) if (TotalEPF > 25) TotalEPF = 25; cFastRandom Random; - float randomvalue; - randomvalue = Random.GenerateRandomInteger(50, 100) * 0.01; + float RandomValue = Random.GenerateRandomInteger(50, 100) * 0.01; - TotalEPF = ceil(TotalEPF * randomvalue); + TotalEPF = ceil(TotalEPF * RandomValue); if (TotalEPF > 20) TotalEPF = 20; @@ -507,9 +503,13 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) if (a_TDI.DamageType == dtProjectile) RemovedDamage += ceil(EPFBlastProtection * 0.04 * a_TDI.FinalDamage); + if (a_TDI.FinalDamage < RemovedDamage) RemovedDamage = 0; + a_TDI.FinalDamage -= RemovedDamage; } + + m_Health -= (short)a_TDI.FinalDamage; // TODO: Apply damage to armor @@ -533,7 +533,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) case 2: AdditionalSpeed.Set(8, 0.3, 8); break; default: break; } - SetSpeed(a_TDI.Knockback + AdditionalSpeed); + AddSpeed(a_TDI.Knockback + AdditionalSpeed); } m_World->BroadcastEntityStatus(*this, esGenericHurt); @@ -1435,6 +1435,8 @@ void cEntity::HandleAir(void) // See if the entity is /submerged/ water (block above is water) // Get the type of block the entity is standing in: + int RespirationLevel = GetEquippedHelmet().m_Enchantments.GetLevel(cEnchantments::enchRespiration); + if (IsSubmerged()) { if (!IsPlayer()) // Players control themselves @@ -1442,6 +1444,11 @@ void cEntity::HandleAir(void) SetSpeedY(1); // Float in the water } + if (RespirationLevel > 0) + { + ((cPawn *)this)->AddEntityEffect(cEntityEffect::effNightVision, 200, 5, 0); + } + if (m_AirLevel <= 0) { // Runs the air tick timer to check whether the player should be damaged @@ -1468,6 +1475,12 @@ void cEntity::HandleAir(void) // Set the air back to maximum m_AirLevel = MAX_AIR_LEVEL; m_AirTickTimer = DROWNING_TICKS; + + if (RespirationLevel > 0) + { + m_AirTickTimer = DROWNING_TICKS + (RespirationLevel * 15 * 20); + } + } } From 4900645b2838b8a953fba298c5001b4e2d242931 Mon Sep 17 00:00:00 2001 From: Jaume Aloy Date: Sat, 30 Aug 2014 00:27:33 +0200 Subject: [PATCH 8/9] Added a_Digger check --- src/Blocks/BlockHandler.cpp | 59 +++++++++++++++++++------------------ src/Entities/Entity.cpp | 4 +-- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index c8a57906f..feb024b7f 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -433,38 +433,41 @@ void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterfac else { // TODO: Add a proper overridable function for this - cEnchantments Enchantments = a_Digger->GetEquippedWeapon().m_Enchantments; - if ((Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0) && a_Digger->IsPlayer()) + if (a_Digger != NULL) { - switch (m_BlockType) + cEnchantments Enchantments = a_Digger->GetEquippedWeapon().m_Enchantments; + if ((Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0) && a_Digger->IsPlayer()) { - case E_BLOCK_CAKE: - case E_BLOCK_CARROTS: - case E_BLOCK_COCOA_POD: - case E_BLOCK_DOUBLE_STONE_SLAB: - case E_BLOCK_DOUBLE_WOODEN_SLAB: - case E_BLOCK_FIRE: - case E_BLOCK_FARMLAND: - case E_BLOCK_MELON_STEM: - case E_BLOCK_MOB_SPAWNER: - case E_BLOCK_NETHER_WART: - case E_BLOCK_POTATOES: - case E_BLOCK_PUMPKIN_STEM: - case E_BLOCK_SNOW: - case E_BLOCK_SUGARCANE: - case E_BLOCK_TALL_GRASS: - case E_BLOCK_CROPS: + switch (m_BlockType) { - // Silktouch can't be used for this blocks - ConvertToPickups(Pickups, Meta); - break; - }; - default: Pickups.Add(m_BlockType, 1, Meta); + case E_BLOCK_CAKE: + case E_BLOCK_CARROTS: + case E_BLOCK_COCOA_POD: + case E_BLOCK_DOUBLE_STONE_SLAB: + case E_BLOCK_DOUBLE_WOODEN_SLAB: + case E_BLOCK_FIRE: + case E_BLOCK_FARMLAND: + case E_BLOCK_MELON_STEM: + case E_BLOCK_MOB_SPAWNER: + case E_BLOCK_NETHER_WART: + case E_BLOCK_POTATOES: + case E_BLOCK_PUMPKIN_STEM: + case E_BLOCK_SNOW: + case E_BLOCK_SUGARCANE: + case E_BLOCK_TALL_GRASS: + case E_BLOCK_CROPS: + { + // Silktouch can't be used for this blocks + ConvertToPickups(Pickups, Meta); + break; + }; + default: Pickups.Add(m_BlockType, 1, Meta); + } + } + else + { + Pickups.Add(m_BlockType, 1, Meta); } - } - else - { - Pickups.Add(m_BlockType, 1, Meta); } } } diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 760401cc2..10a0f8920 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -400,9 +400,9 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) for (size_t i = 0; i < ARRAYCOUNT(ArmorItems); i++) { cItem Item = ArmorItems[i]; - if (Item.m_Enchantments.GetLevel(cEnchantments::enchThorns) > ThornsLevel) ThornsLevel = Item.m_Enchantments.GetLevel(cEnchantments::enchThorns); + ThornsLevel = std::max(ThornsLevel, Item.m_Enchantments.GetLevel(cEnchantments::enchThorns)); } - + if (ThornsLevel > 0) { int Chance = ThornsLevel * 15; From 6180f7df095c228530e4c0d2bfaa90fed7b11f49 Mon Sep 17 00:00:00 2001 From: Jaume Aloy Date: Sun, 31 Aug 2014 11:28:42 +0200 Subject: [PATCH 9/9] Fixed style --- src/Entities/Entity.cpp | 12 +++++------- src/Entities/Player.cpp | 3 +++ src/Entities/ProjectileEntity.h | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 10a0f8920..e36ed6c37 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -396,7 +396,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) } int ThornsLevel = 0; - cItem ArmorItems[] = { GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots() }; + const cItem ArmorItems[] = { GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots() }; for (size_t i = 0; i < ARRAYCOUNT(ArmorItems); i++) { cItem Item = ArmorItems[i]; @@ -428,7 +428,8 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) Player->GetStatManager().AddValue(statDamageDealt, (StatValue)floor(a_TDI.FinalDamage * 10 + 0.5)); } - if (IsPlayer()){ + if (IsPlayer()) + { double TotalEPF = 0.0; double EPFProtection = 0.00; double EPFFireProtection = 0.00; @@ -436,7 +437,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) double EPFProjectileProtection = 0.00; double EPFFeatherFalling = 0.00; - cItem ArmorItems[] = { GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots() }; + const cItem ArmorItems[] = { GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots() }; for (size_t i = 0; i < ARRAYCOUNT(ArmorItems); i++) { cItem Item = ArmorItems[i]; @@ -469,7 +470,6 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) TotalEPF = EPFProtection + EPFFireProtection + EPFFeatherFalling + EPFBlastProtection + EPFProjectileProtection; - EPFProtection = EPFProtection / TotalEPF; EPFFireProtection = EPFFireProtection / TotalEPF; EPFFeatherFalling = EPFFeatherFalling / TotalEPF; @@ -507,8 +507,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) a_TDI.FinalDamage -= RemovedDamage; } - - + m_Health -= (short)a_TDI.FinalDamage; @@ -516,7 +515,6 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) m_Health = std::max(m_Health, 0); - if ((IsMob() || IsPlayer()) && (a_TDI.Attacker != NULL)) // Knockback for only players and mobs { int KnockbackLevel = a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchKnockback); // More common enchantment diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 8b829d090..338a87ac1 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1963,6 +1963,8 @@ void cPlayer::UseEquippedItem(int a_Amount) { return; } + + // If the item has an unbreaking enchantment, give it a random chance of not breaking: cItem Item = GetEquippedItem(); int UnbreakingLevel = Item.m_Enchantments.GetLevel(cEnchantments::enchUnbreaking); if (UnbreakingLevel > 0) @@ -1983,6 +1985,7 @@ void cPlayer::UseEquippedItem(int a_Amount) return; } } + if (GetInventory().DamageEquippedItem(a_Amount)) { m_World->BroadcastSoundEffect("random.break", GetPosX(), GetPosY(), GetPosZ(), 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 58dc38702..990136a32 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -94,7 +94,7 @@ protected: */ struct CreatorData { - CreatorData(int a_UniqueID, const AString & a_Name, cEnchantments a_Enchantments) : + CreatorData(int a_UniqueID, const AString & a_Name, const cEnchantments & a_Enchantments) : m_UniqueID(a_UniqueID), m_Name(a_Name), m_Enchantments(a_Enchantments)