diff --git a/ChebsNecromancy/Patches/CharacterPatches.cs b/ChebsNecromancy/Patches/CharacterPatches.cs index edcf93f..cd0b13d 100644 --- a/ChebsNecromancy/Patches/CharacterPatches.cs +++ b/ChebsNecromancy/Patches/CharacterPatches.cs @@ -58,26 +58,47 @@ static void Prefix(ref long sender, ref HitData hit, Character __instance) if (__instance.IsPlayer()) { var player = (Player)__instance; + + var incomingDamage = hit.Clone(); + incomingDamage.ApplyArmor(player.GetBodyArmor()); + incomingDamage.ApplyResistance(player.m_damageModifiers, out _); + + // check if damage would kill player + //Jotunn.Logger.LogInfo($"player health {player.GetHealth()}\ntotal hit damage {incomingDamage.GetTotalDamage()}"); + if (player.GetHealth() > incomingDamage.GetTotalDamage()) + { + //Jotunn.Logger.LogInfo($"player health {player.GetHealth()} > total hit damage {incomingDamage.GetTotalDamage()}"); + return; + } + + var noDamage = new HitData.DamageTypes + { + m_damage = 0, + m_blunt = 0, + m_slash = 0, + m_pierce = 0, + m_chop = 0, + m_pickaxe = 0, + m_fire = 0, + m_frost = 0, + m_lightning = 0, + m_poison = 0, + m_spirit = 0, + }; + + if (player.IsTeleporting()) + { + Jotunn.Logger.LogInfo($"player is teleporting; ignore damage"); + hit.m_damage = noDamage; + return; + } + var playerPhylactery = Phylactery.Phylacteries.Find(phylactery => phylactery.TryGetComponent(out Piece piece) && piece.m_creator == player.GetPlayerID()); if (playerPhylactery != null && playerPhylactery.ConsumeFuel()) { - // save player's life - hit.m_damage = new HitData.DamageTypes - { - m_damage = 0, - m_blunt = 0, - m_slash = 0, - m_pierce = 0, - m_chop = 0, - m_pickaxe = 0, - m_fire = 0, - m_frost = 0, - m_lightning = 0, - m_poison = 0, - m_spirit = 0, - }; + hit.m_damage = noDamage; player.TeleportTo(playerPhylactery.transform.position + Vector3.forward, Quaternion.identity, true); } diff --git a/ChebsNecromancy/Structures/Phylactery.cs b/ChebsNecromancy/Structures/Phylactery.cs index 6346ced..77c6314 100644 --- a/ChebsNecromancy/Structures/Phylactery.cs +++ b/ChebsNecromancy/Structures/Phylactery.cs @@ -1,4 +1,3 @@ -using System; using System.Collections; using System.Collections.Generic; using System.Reflection; @@ -6,6 +5,7 @@ using ChebsValheimLibrary.Common; using ChebsValheimLibrary.Structures; using UnityEngine; +using Logger = Jotunn.Logger; namespace ChebsNecromancy.Structures { @@ -56,13 +56,13 @@ public bool ConsumeFuel() var fuelPrefab = ZNetScene.instance.GetPrefab(FuelPrefab.Value); if (fuelPrefab == null) { - Jotunn.Logger.LogError("Phylactery.ConsumeFuel: fuelPrefab is null"); + Logger.LogError("Phylactery.ConsumeFuel: fuelPrefab is null"); return false; } if (!fuelPrefab.TryGetComponent(out ItemDrop itemDrop)) { - Jotunn.Logger.LogError("Phylactery.ConsumeFuel: fuelPrefab has no ItemDrop"); + Logger.LogError("Phylactery.ConsumeFuel: fuelPrefab has no ItemDrop"); return false; } diff --git a/Translations/English/chebsnecromancy.english.json b/Translations/English/chebsnecromancy.english.json index 4206dd5..dbc279b 100644 --- a/Translations/English/chebsnecromancy.english.json +++ b/Translations/English/chebsnecromancy.english.json @@ -86,5 +86,7 @@ "chebgonaz_miniontype_battleneckro": "Battle Neckro", "chebgonaz_worker_target": "Target", "chebgonaz_worker_cantfindtarget": "Can't find target.", - "chebgonaz_minionstatus_following": "Following" + "chebgonaz_minionstatus_following": "Following", + "chebgonaz_phylactery_name": "Phylactery", + "chebgonaz_phylactery_desc": "For a necromancer, death is easy to escape. All that is required is a different soul to be offered up to the gods rather than your own." }