diff options
author | Damián Imrich <damian@haze.sk> | 2021-01-22 10:05:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-22 10:05:18 +0100 |
commit | 59e906ec6caac03a705d194705cc2859c5797632 (patch) | |
tree | b7083ea56c65ed27e93f4fa6e897ba8e77bc4c68 /src/Entities/Pawn.cpp | |
parent | MultiVersionProtocol: fix two crashes (diff) | |
download | cuberite-59e906ec6caac03a705d194705cc2859c5797632.tar cuberite-59e906ec6caac03a705d194705cc2859c5797632.tar.gz cuberite-59e906ec6caac03a705d194705cc2859c5797632.tar.bz2 cuberite-59e906ec6caac03a705d194705cc2859c5797632.tar.lz cuberite-59e906ec6caac03a705d194705cc2859c5797632.tar.xz cuberite-59e906ec6caac03a705d194705cc2859c5797632.tar.zst cuberite-59e906ec6caac03a705d194705cc2859c5797632.zip |
Diffstat (limited to 'src/Entities/Pawn.cpp')
-rw-r--r-- | src/Entities/Pawn.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 35efe05ce..6f33a5eca 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -111,6 +111,20 @@ void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) void cPawn::KilledBy(TakeDamageInfo & a_TDI) { ClearEntityEffects(); + + // Is death eligible for totem reanimation? + if (DeductTotem(a_TDI.DamageType)) + { + m_World->BroadcastEntityStatus(*this, esTotemOfUndying); + + AddEntityEffect(cEntityEffect::effAbsorption, 100, 1); + AddEntityEffect(cEntityEffect::effRegeneration, 900, 1); + AddEntityEffect(cEntityEffect::effFireResistance, 800, 0); + + m_Health = 1; + return; + } + Super::KilledBy(a_TDI); } @@ -490,3 +504,38 @@ void cPawn::ResetPosition(Vector3d a_NewPosition) Super::ResetPosition(a_NewPosition); m_LastGroundHeight = GetPosY(); } + + + + + +bool cPawn::DeductTotem(const eDamageType a_DamageType) +{ + if ((a_DamageType == dtAdmin) || (a_DamageType == dtInVoid)) + { + // Beyond saving: + return false; + } + + if (!IsPlayer()) + { + // TODO: implement when mobs will be able to pick up items based on CanPickUpLoot attribute: + return false; + } + + // If the player is holding a totem of undying in their off-hand or + // main-hand slot and receives otherwise fatal damage, the totem saves the player from death. + + auto & inv = static_cast<cPlayer *>(this)->GetInventory(); + if (inv.GetEquippedItem().m_ItemType == E_ITEM_TOTEM_OF_UNDYING) + { + inv.SetEquippedItem({}); + return true; + } + if (inv.GetShieldSlot().m_ItemType == E_ITEM_TOTEM_OF_UNDYING) + { + inv.SetShieldSlot({}); + return true; + } + return false; +} |