A vegan, tree-born race unlocking new perks per boss defeated: skin/hair tint, blocked non-vegan food, awakened seed foods after Eikthyr, a mob hostility list, Photosynthesis, elemental resistances, Purple Rain after the Elder, swim/poison/wet immunity after Bonemass, Last Stand and Thorns after Moder, a Homecoming Portal after Yagluth, Hornet's Nest after the Queen, and Muspell (a half-size Elder transformation with Stomp/Spike attacks) after Fader. Also fixes RaceScale never listing Trenta as self-sizing, which let a shared Player.Update postfix fight Muspell's own scale changes every frame.
136 lines
6.6 KiB
C#
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 = "Heartwood";
|
|
m_tooltip = "Rooted, patient, and hard to fell.";
|
|
|
|
// 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 = "Heartwood";
|
|
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 = "Purple Rain";
|
|
purpleRainCd.m_tooltip = "The pollen must settle before you may call the rain again.";
|
|
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 = "Homecoming Portal";
|
|
portalCd.m_tooltip = "The way home has not yet settled enough to open again.";
|
|
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;
|
|
}
|
|
}
|
|
}
|