Skip to content

Commit

Permalink
phylactery improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jpw1991 committed Jul 31, 2023
1 parent 284f53c commit 855c05a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
51 changes: 36 additions & 15 deletions ChebsNecromancy/Patches/CharacterPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions ChebsNecromancy/Structures/Phylactery.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using BepInEx.Configuration;
using ChebsValheimLibrary.Common;
using ChebsValheimLibrary.Structures;
using UnityEngine;
using Logger = Jotunn.Logger;

namespace ChebsNecromancy.Structures
{
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion Translations/English/chebsnecromancy.english.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}

0 comments on commit 855c05a

Please sign in to comment.