RacesOfValheim/JotunnModStub/Trenta/TrentaStatusEffects.cs
kanym 9bf144aedc feat(text): status effect names and tooltips come from translation files
Every status effect the mod registers now carries a $rov_se_ token instead
of English, and status_effects.json holds the texts in English and Italian.
Valheim localizes both fields itself when it shows them. The blood
potion's tooltip has numbers in it, so SE_BloodPotion fills its $1 and $2
in GetTooltipString, at display time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 19:51:10 +02:00

136 lines
6.6 KiB
C#

using System.Collections.Generic;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;
namespace RacesOfValheim
{
/// <summary>
/// Passive carrier for the Trenta. Anything Valheim already routes through the status effects
/// - damage modifiers, attack stamina cost, regeneration multipliers - belongs here rather
/// than in a Harmony patch, because there is nothing to intercept.
/// </summary>
public class SE_TrentaStats : SE_Stats
{
public override void Setup(Character character)
{
base.Setup(character);
name = TrentaConfig.StatsSE;
m_name = "$rov_se_trenta_stats_name";
m_tooltip = "$rov_se_trenta_stats_tooltip";
// Resistant/Weak are exactly ±50% damage taken (0.5x / 1.5x) - verified against
// HitData.ApplyModifier's own IL rather than assumed, since the enum names alone
// don't say by how much. Live from the base tier, ungated by boss progression:
// sap and heartwood conduct current and turn away the dead the same on day one as
// on day eight, and kindling and the woodsman's axe never stop being kindling and
// an axe.
m_mods = new List<HitData.DamageModPair>
{
new HitData.DamageModPair { m_type = HitData.DamageType.Lightning, m_modifier = HitData.DamageModifier.Resistant },
new HitData.DamageModPair { m_type = HitData.DamageType.Spirit, m_modifier = HitData.DamageModifier.Resistant },
new HitData.DamageModPair { m_type = HitData.DamageType.Fire, m_modifier = HitData.DamageModifier.Weak },
new HitData.DamageModPair { m_type = HitData.DamageType.Slash, m_modifier = HitData.DamageModifier.Weak }
};
// Bonemass passive. Setup runs once per (re)application of this effect rather than
// continuously, so - same as SkeletonRace's own PoisonImmunity check in
// SE_SkeletonStats - a boss killed mid-life only takes effect from the next
// respawn/re-add onward, not instantly. That already matches how every other
// state-gated m_mods list in this mod behaves.
if (BossProgressionManager.GetCurrentProgressionState() >= TrentaConfig.BonemassDefeatedState)
{
m_mods.Add(new HitData.DamageModPair { m_type = HitData.DamageType.Poison, m_modifier = HitData.DamageModifier.Immune });
}
}
/// <summary>
/// Last Stand (Moder). Unlike the m_mods list above this cannot be computed once at Setup:
/// it has to track current health, which changes every hit, so it is read fresh on every
/// armor calculation instead - already-live boss-progression state included, so this one
/// (unlike the Poison immunity above) does take effect the instant Moder falls, no
/// respawn needed.
/// </summary>
public override void ModifyArmorMods(ref float armor)
{
base.ModifyArmorMods(ref armor);
if (!(m_character is Player player) || player != Player.m_localPlayer) return;
if (!TrentaRace.IsTrenta()) return;
if (BossProgressionManager.GetCurrentProgressionState() < TrentaConfig.ModerDefeatedState) return;
float maxHealth = player.GetMaxHealth();
if (maxHealth <= 0f) return;
float missingFraction = Mathf.Clamp01(1f - player.GetHealth() / maxHealth);
armor *= 1f + TrentaConfig.LastStandMaxArmorBonus * missingFraction;
}
}
/// <summary>
/// Exists only so the HUD has something to count down, the way SE_DvergarAbilityCooldown and
/// SE_SkadiAbilityCooldown do: Valheim prints the remaining time of any effect with a m_ttl.
/// </summary>
public class SE_TrentaAbilityCooldown : StatusEffect
{
}
public static class TrentaStatusEffects
{
public static SE_TrentaStats StatsSE { get; private set; }
public static void RegisterStatusEffects()
{
var stats = ScriptableObject.CreateInstance<SE_TrentaStats>();
stats.name = TrentaConfig.StatsSE;
stats.m_name = "$rov_se_trenta_stats_name";
stats.m_icon = GetItemIcon("Wood"); // TODO: pick the icon the race should carry
CustomStatusEffect customStats = new CustomStatusEffect(stats, fixReference: false);
ItemManager.Instance.AddStatusEffect(customStats);
StatsSE = customStats.StatusEffect as SE_TrentaStats;
var purpleRainCd = ScriptableObject.CreateInstance<SE_TrentaAbilityCooldown>();
purpleRainCd.name = TrentaConfig.PurpleRainCdSE;
purpleRainCd.m_name = "$rov_se_trenta_purpleraincd_name";
purpleRainCd.m_tooltip = "$rov_se_trenta_purpleraincd_tooltip";
purpleRainCd.m_icon = GetItemIcon("TrophyGreydwarfShaman") ?? GetItemIcon("Wood");
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(purpleRainCd, fixReference: false));
var portalCd = ScriptableObject.CreateInstance<SE_TrentaAbilityCooldown>();
portalCd.name = TrentaConfig.PortalCdSE;
portalCd.m_name = "$rov_se_trenta_portalcd_name";
portalCd.m_tooltip = "$rov_se_trenta_portalcd_tooltip";
portalCd.m_icon = GetItemIcon("Wood");
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(portalCd, fixReference: false));
}
/// <summary>
/// Drives the HUD countdown for an ability, mirroring DvergarStatusEffects: the effect
/// only has to exist with a m_ttl for the icon to tick down by itself.
/// </summary>
public static void ApplyCooldownIcon(string effectName, float seconds)
{
if (Player.m_localPlayer == null || seconds <= 0f) return;
int hash = effectName.GetStableHashCode();
SEMan seman = Player.m_localPlayer.GetSEMan();
seman.RemoveStatusEffect(hash, true);
seman.AddStatusEffect(hash, true);
StatusEffect se = seman.GetStatusEffect(hash);
if (se != null) se.m_ttl = seconds;
}
private static Sprite GetItemIcon(string prefabName)
{
GameObject prefab = PrefabManager.Cache.GetPrefab<ItemDrop>(prefabName)?.gameObject;
ItemDrop drop = prefab != null ? prefab.GetComponent<ItemDrop>() : null;
if (drop != null && drop.m_itemData.m_shared.m_icons.Length > 0)
{
return drop.m_itemData.m_shared.m_icons[0];
}
return null;
}
}
}