Every message the mod puts in the middle or corner of the screen now reads its text through ModText.Get, and messages.json holds 191 texts in English and Italian. Values computed in code become $1, $2 in the text, so a translator can put them wherever the sentence needs them. Branching messages get one key per branch. A few messages travel through a field before they are shown: thralls' refusals and the building limits now hold a token or key there. Boss and form names inside messages use tokens too, the bosses the game's own, so "The Elder" arrives translated. ModText.Get now localizes each argument before inserting it. A token argument left for a later pass ran into the text after it: "$1's power" became the unknown token "enemy_eikthyr's". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
373 lines
18 KiB
C#
373 lines
18 KiB
C#
using HarmonyLib;
|
|
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
public static class DraughProgressionPatches
|
|
{
|
|
// ========================================
|
|
// STAGE 2: SUNKEN MENACE (State >= 2)
|
|
// ========================================
|
|
|
|
[HarmonyPatch(typeof(SE_Wet), "Setup")]
|
|
public static class SE_Wet_Setup_Patch
|
|
{
|
|
public static void Postfix(SE_Wet __instance, Character character)
|
|
{
|
|
if (character == Player.m_localPlayer && DraughRace.IsDraugh())
|
|
{
|
|
if (BossProgressionManager.GetCurrentProgressionState() >= 2)
|
|
{
|
|
// Invert the Wet debuff to actually heal the Draugh
|
|
__instance.m_healthRegenMultiplier = DraughConfig.WetHealthRegenMultiplier.Value;
|
|
__instance.m_staminaRegenMultiplier = 1f; // No stamina penalty
|
|
__instance.m_tooltip = "$rov_se_draugh_wet_tooltip";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// ========================================
|
|
// STAGE 3: ROTTING EDGE (State >= 3)
|
|
// ========================================
|
|
|
|
[HarmonyPatch(typeof(Character), "Damage")]
|
|
public static class Draugh_DealDamage_Patch
|
|
{
|
|
public static void Prefix(Character __instance, HitData hit)
|
|
{
|
|
if (hit == null || __instance == null || hit.GetAttacker() == null) return;
|
|
|
|
if (hit.GetAttacker() == Player.m_localPlayer && DraughRace.IsDraugh())
|
|
{
|
|
if (BossProgressionManager.GetCurrentProgressionState() >= 3)
|
|
{
|
|
// If it's a physical attack (slash, pierce, blunt, or chop)
|
|
float physDamage = hit.m_damage.m_blunt + hit.m_damage.m_slash + hit.m_damage.m_pierce + hit.m_damage.m_chop;
|
|
if (physDamage > 0f && hit.m_skill != Skills.SkillType.BloodMagic && hit.m_skill != Skills.SkillType.ElementalMagic)
|
|
{
|
|
// Add poison damage based on the physical damage
|
|
hit.m_damage.m_poison += physDamage * DraughConfig.PoisonOnHitPercent.Value;
|
|
}
|
|
}
|
|
|
|
if (BossProgressionManager.GetCurrentProgressionState() >= 4)
|
|
{
|
|
// Stage 4: Undead Fortitude (crit damage on staggered enemies)
|
|
if (__instance.IsStaggering())
|
|
{
|
|
float critMult = DraughConfig.StaggerCritMultiplier.Value;
|
|
hit.m_damage.m_blunt *= critMult;
|
|
hit.m_damage.m_slash *= critMult;
|
|
hit.m_damage.m_pierce *= critMult;
|
|
hit.m_damage.m_chop *= critMult;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Humanoid), "BlockAttack")]
|
|
public static class Draugh_Parry_Patch
|
|
{
|
|
private static float lastNorthWindTime = -100f; // Track cooldown
|
|
|
|
public static void Postfix(Humanoid __instance, HitData hit, Character attacker, ref bool __result)
|
|
{
|
|
if (!__result || __instance != Player.m_localPlayer || attacker == null) return;
|
|
|
|
if (DraughRace.IsDraugh())
|
|
{
|
|
int state = BossProgressionManager.GetCurrentProgressionState();
|
|
|
|
if (state >= 3)
|
|
{
|
|
// Check if it was a parry.
|
|
float blockTimer = Traverse.Create(__instance).Field("m_blockTimer").GetValue<float>();
|
|
float parryTime = DraughConfig.ParryWindow.Value;
|
|
|
|
if (blockTimer != -1f && blockTimer <= parryTime)
|
|
{
|
|
// Stage 3: Poison Splash
|
|
HitData poisonSplash = new HitData();
|
|
poisonSplash.m_damage.m_poison = DraughConfig.PoisonSplashDamage.Value;
|
|
poisonSplash.m_point = attacker.GetCenterPoint();
|
|
poisonSplash.SetAttacker(__instance);
|
|
poisonSplash.m_dir = (attacker.GetCenterPoint() - __instance.GetCenterPoint()).normalized;
|
|
|
|
attacker.ApplyDamage(poisonSplash, true, false);
|
|
|
|
// Visual effect for splash. "vfx_OozeHit" is not a prefab in this game -
|
|
// the blob's hit effect is vfx_blob_hit - and this was the one dead name
|
|
// in the mod that was passed to Instantiate unguarded, so every
|
|
// successful parry threw ArgumentException here and took the North Wind
|
|
// nova below down with it.
|
|
GameObject splashVfx = ZNetScene.instance.GetPrefab("vfx_blob_hit");
|
|
if (splashVfx != null)
|
|
{
|
|
UnityEngine.Object.Instantiate(splashVfx, attacker.GetCenterPoint(), Quaternion.identity);
|
|
}
|
|
|
|
// Said on every parry, which are rare enough not to be noise. A parry has
|
|
// to land inside a quarter-second window while blocking, so "nothing looks
|
|
// different" is as likely to mean the window was missed as it is to mean
|
|
// the splash did not draw - and there was no way to tell the two apart.
|
|
Jotunn.Logger.LogInfo(
|
|
$"[Draugh] Parry on '{attacker.name}': {DraughConfig.PoisonSplashDamage.Value:F0} poison, " +
|
|
$"blockTimer={blockTimer:F3} of {parryTime:F2}, " +
|
|
$"splash vfx={(splashVfx != null ? "vfx_blob_hit" : "NOT RESOLVED")}.");
|
|
|
|
// Stage 5: North Wind (AoE Frost)
|
|
if (state >= 5)
|
|
{
|
|
if (Time.time - lastNorthWindTime >= DraughConfig.NorthWindCooldown.Value)
|
|
{
|
|
lastNorthWindTime = Time.time;
|
|
|
|
// Visual effect for Nova (sledge frost effect)
|
|
GameObject iceHit = ZNetScene.instance.GetPrefab("vfx_sledge_iron_hit"); // Actually, vfx_ice_hit is better, or vfx_sledge_iron_hit which is used by Frostner
|
|
if (iceHit == null) iceHit = ZNetScene.instance.GetPrefab("vfx_ice_hit");
|
|
if (iceHit != null)
|
|
{
|
|
UnityEngine.Object.Instantiate(iceHit, __instance.transform.position, Quaternion.identity);
|
|
}
|
|
|
|
// Find all characters within range
|
|
float northWindRadius = DraughConfig.NorthWindRadius.Value;
|
|
List<Character> allCharacters = Character.GetAllCharacters();
|
|
foreach (Character ch in allCharacters)
|
|
{
|
|
if (ch == null || ch == __instance || ch.IsPlayer() || ch.IsDead()) continue;
|
|
|
|
if (Vector3.Distance(__instance.transform.position, ch.transform.position) <= northWindRadius)
|
|
{
|
|
HitData northWind = new HitData();
|
|
northWind.m_damage.m_frost = DraughConfig.NorthWindFrostDamage.Value;
|
|
northWind.m_point = ch.GetCenterPoint();
|
|
northWind.SetAttacker(__instance);
|
|
northWind.m_dir = (ch.GetCenterPoint() - __instance.GetCenterPoint()).normalized;
|
|
northWind.m_pushForce = DraughConfig.NorthWindPushForce.Value;
|
|
|
|
ch.ApplyDamage(northWind, true, false);
|
|
}
|
|
}
|
|
|
|
Player.m_localPlayer.Message(MessageHud.MessageType.TopLeft, ModText.Get("rov_msg_draugh_northern_wind_blows"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// ========================================
|
|
// STAGE 4: UNDEAD FORTITUDE & DEATH AURA (State >= 4)
|
|
// ========================================
|
|
|
|
[HarmonyPatch(typeof(Skills), "LowerAllSkills")]
|
|
public static class Draugh_NoSkillDrain_Patch
|
|
{
|
|
public static bool Prefix(Skills __instance)
|
|
{
|
|
// Check if this Skills instance belongs to the local player
|
|
Player player = Traverse.Create(__instance).Field("m_player").GetValue<Player>();
|
|
if (player != null && player == Player.m_localPlayer)
|
|
{
|
|
if (DraughRace.IsDraugh() && BossProgressionManager.GetCurrentProgressionState() >= 4)
|
|
{
|
|
return false; // Prevent skill drain
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Player), "OnDeath")]
|
|
public static class Draugh_DeathAura_Patch
|
|
{
|
|
public static void Prefix(Player __instance)
|
|
{
|
|
if (BossProgressionManager.GetCurrentProgressionState() >= 4)
|
|
{
|
|
bool draughNearby = false;
|
|
foreach (Player p in Player.GetAllPlayers())
|
|
{
|
|
if (p.m_customData != null && p.m_customData.TryGetValue("Race", out string race) && race == "Draugh")
|
|
{
|
|
if (Vector3.Distance(__instance.transform.position, p.transform.position) <= DraughConfig.DeathAuraRadius.Value)
|
|
{
|
|
draughNearby = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (draughNearby)
|
|
{
|
|
GameObject meatPrefab = ObjectDB.instance.GetItemPrefab("HumanMeat");
|
|
if (meatPrefab != null)
|
|
{
|
|
Vector3 dropPos = __instance.transform.position + Vector3.up * 1.0f;
|
|
GameObject dropped = UnityEngine.Object.Instantiate(meatPrefab, dropPos, Quaternion.identity);
|
|
|
|
ItemDrop itemDrop = dropped.GetComponent<ItemDrop>();
|
|
if (itemDrop != null)
|
|
{
|
|
itemDrop.m_itemData.m_stack = 1;
|
|
|
|
Rigidbody rb = dropped.GetComponent<Rigidbody>();
|
|
if (rb != null)
|
|
{
|
|
rb.linearVelocity = Vector3.up * 5f + UnityEngine.Random.insideUnitSphere * 2f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// ========================================
|
|
// STAGE 6: UNDYING WILL (State >= 6)
|
|
// ========================================
|
|
|
|
[HarmonyPatch(typeof(Player), "OnDeath")]
|
|
public static class Player_OnDeath_Undying_Patch
|
|
{
|
|
public static bool Prefix(Player __instance)
|
|
{
|
|
if (__instance == Player.m_localPlayer && DraughRace.IsDraugh() && BossProgressionManager.GetCurrentProgressionState() >= 6)
|
|
{
|
|
if (DraughRace.isUndying)
|
|
{
|
|
// If they are already undying and they reach OnDeath again, it means their Eitr ran out.
|
|
// We must let them die for real this time.
|
|
return true;
|
|
}
|
|
|
|
float currentEitr = __instance.GetEitr();
|
|
if (currentEitr > 0f && Time.time - DraughRace.lastUndyingWillTime >= DraughConfig.UndyingWillCooldown.Value)
|
|
{
|
|
// Trigger Undying Will!
|
|
DraughRace.lastUndyingWillTime = Time.time;
|
|
DraughRace.isUndying = true;
|
|
|
|
// Prevent the real death this frame, stay alive at 1 HP
|
|
__instance.SetHealth(1f);
|
|
|
|
DraughRace.Instance.StartCoroutine(DraughRace.Instance.UndyingWillRoutine(__instance));
|
|
|
|
// Return false to skip the original OnDeath method
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Character), "ApplyDamage")]
|
|
public static class Character_ApplyDamage_Undying_Patch
|
|
{
|
|
public static bool Prefix(Character __instance, HitData hit)
|
|
{
|
|
if (__instance == Player.m_localPlayer && DraughRace.IsDraugh())
|
|
{
|
|
if (DraughRace.isUndying)
|
|
{
|
|
// Become immune to all damage
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// ========================================
|
|
// STAGE 7: SWARM OF TERROR (State >= 7)
|
|
// ========================================
|
|
|
|
[HarmonyPatch(typeof(Character), "Damage")]
|
|
public static class Character_Damage_SwarmOfTerror_Patch
|
|
{
|
|
public static void Prefix(Character __instance, HitData hit)
|
|
{
|
|
if (__instance == Player.m_localPlayer && DraughRace.IsDraugh() && BossProgressionManager.GetCurrentProgressionState() >= 7)
|
|
{
|
|
if (hit == null || hit.GetAttacker() == null || hit.m_damage.GetTotalDamage() <= 0f) return;
|
|
|
|
// Melee check via distance
|
|
if (Vector3.Distance(hit.GetAttacker().transform.position, __instance.transform.position) <= DraughConfig.SwarmDetectionRadius.Value)
|
|
{
|
|
if (Time.time - DraughRace.lastSeekerSpawnTime >= DraughConfig.SwarmSpawnCooldown.Value)
|
|
{
|
|
DraughRace.lastSeekerSpawnTime = Time.time;
|
|
|
|
GameObject prefab = ObjectDB.instance.GetItemPrefab("SeekerBrood");
|
|
if (prefab == null)
|
|
{
|
|
prefab = ZNetScene.instance.GetPrefab("SeekerBrood");
|
|
}
|
|
|
|
if (prefab != null)
|
|
{
|
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_draugh_swarm_terror"));
|
|
|
|
for (int i = 0; i < DraughConfig.SwarmSpawnCount.Value; i++)
|
|
{
|
|
Vector3 spawnPos = __instance.transform.position + __instance.transform.forward * 1f + UnityEngine.Random.insideUnitSphere * 1.5f;
|
|
spawnPos.y = __instance.transform.position.y;
|
|
|
|
GameObject brood = UnityEngine.Object.Instantiate(prefab, spawnPos, Quaternion.identity);
|
|
Character c = brood.GetComponent<Character>();
|
|
if (c != null)
|
|
{
|
|
c.m_faction = Character.Faction.Players; // Make it friendly
|
|
|
|
// Remove drops
|
|
CharacterDrop drop = brood.GetComponent<CharacterDrop>();
|
|
if (drop != null)
|
|
{
|
|
UnityEngine.Object.Destroy(drop);
|
|
}
|
|
|
|
DraughRace.Instance.StartCoroutine(DraughRace.Instance.KillBroodAfterTime(c, DraughConfig.SwarmBroodLifetime.Value));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void Postfix(Character __instance, HitData hit)
|
|
{
|
|
// STAGE 8: STEAL THEIR BREATH (State >= 8)
|
|
if (DraughRace.isUndying && __instance != Player.m_localPlayer && __instance.GetHealth() <= 0f)
|
|
{
|
|
if (BossProgressionManager.GetCurrentProgressionState() >= 8)
|
|
{
|
|
if (hit != null && hit.GetAttacker() == Player.m_localPlayer)
|
|
{
|
|
// Steal Their Breath triggered!
|
|
DraughRace.isUndying = false; // Break the routine loop
|
|
|
|
float healAmount = Player.m_localPlayer.GetMaxHealth() * DraughConfig.StealBreathHealPercent.Value;
|
|
Player.m_localPlayer.Heal(healAmount);
|
|
|
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_draugh_steal_their_breath_death_denied"));
|
|
|
|
// Restore visuals immediately
|
|
if (Player.m_localPlayer.GetComponent<VisEquipment>() != null)
|
|
{
|
|
HarmonyLib.Traverse.Create(Player.m_localPlayer.GetComponent<VisEquipment>()).Method("UpdateVisuals").GetValue();
|
|
HarmonyLib.Traverse.Create(Player.m_localPlayer.GetComponent<VisEquipment>()).Method("UpdateColors").GetValue();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|