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>
139 lines
6.1 KiB
C#
139 lines
6.1 KiB
C#
using HarmonyLib;
|
|
using Jotunn.Entities;
|
|
using Jotunn.Managers;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// Passive carrier for the Dvergar. The stamina half of weapon affinity lives here rather than
|
|
/// in a Harmony patch because Valheim already routes attack cost through the status effects
|
|
/// (SEMan.ModifyAttackStaminaUsage), so there is nothing to intercept.
|
|
/// </summary>
|
|
public class SE_DvergarStats : SE_Stats
|
|
{
|
|
public override void Setup(Character character)
|
|
{
|
|
base.Setup(character);
|
|
name = DvergarConfig.StatsSE;
|
|
m_name = "$rov_se_dvergar_stats_name";
|
|
m_tooltip = "$rov_se_dvergar_stats_tooltip";
|
|
}
|
|
|
|
public override void ModifyAttackStaminaUsage(float baseStaminaUse, ref float staminaUse)
|
|
{
|
|
base.ModifyAttackStaminaUsage(baseStaminaUse, ref staminaUse);
|
|
|
|
if (!(m_character is Player player) || player != Player.m_localPlayer) return;
|
|
if (!DvergarRace.IsDvergar()) return;
|
|
|
|
int state = BossProgressionManager.GetCurrentProgressionState();
|
|
|
|
// m_rightItem rather than GetCurrentWeapon(): it is what the rest of the mod reaches
|
|
// for, and it is the item the swing is actually paying for.
|
|
ItemDrop.ItemData weapon = Traverse.Create(player).Field<ItemDrop.ItemData>("m_rightItem").Value;
|
|
if (weapon == null || weapon.m_shared == null) return;
|
|
|
|
Skills.SkillType skill = weapon.m_shared.m_skillType;
|
|
|
|
// Mining is a discount on the pickaxe, not a weapon affinity, so it is checked apart.
|
|
if (skill == Skills.SkillType.Pickaxes)
|
|
{
|
|
if (DvergarProgression.GetRules(state).MiningAffinity)
|
|
{
|
|
staminaUse = Mathf.Max(0f, staminaUse * (1f - DvergarConfig.MiningStaminaPercent));
|
|
}
|
|
return;
|
|
}
|
|
|
|
DvergarConfig.WeaponAffinity? affinity = DvergarProgression.GetAffinity(skill, state);
|
|
if (!affinity.HasValue) return;
|
|
|
|
// Static by design: the discount is the same the day it unlocks as it is after Fader.
|
|
staminaUse = Mathf.Max(0f, staminaUse * (1f - affinity.Value.StaminaPercent) - affinity.Value.StaminaFlat);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Runic Overcharge, held between the cast and the blow that spends it. Purely a marker with a
|
|
/// countdown - DvergarPatches reads it when the next affine hit lands.
|
|
/// </summary>
|
|
public class SE_DvergarOvercharge : StatusEffect
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ability cooldowns. They exist only so the HUD has something to count down, the way
|
|
/// SE_SkadiAbilityCooldown does: Valheim prints the remaining time of any effect with a m_ttl.
|
|
/// </summary>
|
|
public class SE_DvergarAbilityCooldown : StatusEffect
|
|
{
|
|
}
|
|
|
|
public static class DvergarStatusEffects
|
|
{
|
|
public static SE_DvergarStats StatsSE { get; private set; }
|
|
|
|
public static void RegisterStatusEffects()
|
|
{
|
|
Sprite icon = GetItemIcon("HelmetDverger") ?? GetItemIcon("DvergrKeyFragment") ?? GetItemIcon("Copper");
|
|
|
|
var stats = ScriptableObject.CreateInstance<SE_DvergarStats>();
|
|
stats.name = DvergarConfig.StatsSE;
|
|
stats.m_name = "$rov_se_dvergar_stats_name";
|
|
stats.m_icon = icon;
|
|
CustomStatusEffect customStats = new CustomStatusEffect(stats, fixReference: false);
|
|
ItemManager.Instance.AddStatusEffect(customStats);
|
|
StatsSE = customStats.StatusEffect as SE_DvergarStats;
|
|
|
|
var overcharge = ScriptableObject.CreateInstance<SE_DvergarOvercharge>();
|
|
overcharge.name = DvergarConfig.OverchargeSE;
|
|
overcharge.m_name = "$rov_se_dvergar_overcharge_name";
|
|
overcharge.m_tooltip = "$rov_se_dvergar_overcharge_tooltip";
|
|
overcharge.m_icon = GetItemIcon("Eitr") ?? icon;
|
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(overcharge, fixReference: false));
|
|
|
|
var pingCd = ScriptableObject.CreateInstance<SE_DvergarAbilityCooldown>();
|
|
pingCd.name = DvergarConfig.RunicPingCdSE;
|
|
pingCd.m_name = "$rov_se_dvergar_pingcd_name";
|
|
pingCd.m_tooltip = "$rov_se_dvergar_pingcd_tooltip";
|
|
pingCd.m_icon = GetItemIcon("DvergrKeyFragment") ?? icon;
|
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(pingCd, fixReference: false));
|
|
|
|
var overchargeCd = ScriptableObject.CreateInstance<SE_DvergarAbilityCooldown>();
|
|
overchargeCd.name = DvergarConfig.OverchargeCdSE;
|
|
overchargeCd.m_name = "$rov_se_dvergar_overchargecd_name";
|
|
overchargeCd.m_tooltip = "$rov_se_dvergar_overchargecd_tooltip";
|
|
overchargeCd.m_icon = GetItemIcon("Eitr") ?? icon;
|
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(overchargeCd, fixReference: false));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Drives the HUD countdown for an ability, mirroring SkadiRace.ApplyCooldownIcon: 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;
|
|
}
|
|
}
|
|
}
|