fix(resetrace): drop every form and every mod status effect on reset
ResetRace now undoes each race's form on the spot before it touches status effects: Aswid bat and mist, Fenrir, Skadi drake, Trol True Form, Trenta Muspell and Sverm Ravager. Each race gets a HardResetForReset that stops the form's coroutine, so a transform caught mid-gesture can't finish after the reset and a revert can't hand out its cooldown after the sweep. The hand-written status effect list is gone. The reset now removes everything the mod registers through Jotunn (ModRegistry), which covers the True Form and its cooldowns, Bat and Mist Form, the Skeleton resurrect cooldown and Skadi's ability cooldowns. It also puts the player and the Visual back to scale 1, clears the Sverm's static Ravager cooldown and the Trol's wasTrueFormActive flag, and prints what it removed to the console and the BepInEx log.
This commit is contained in:
parent
65b488b5dc
commit
d5c2d58636
7 changed files with 336 additions and 37 deletions
|
|
@ -4,6 +4,7 @@ using HarmonyLib;
|
|||
using Jotunn.Configs;
|
||||
using Jotunn.Entities;
|
||||
using Jotunn.Managers;
|
||||
using Jotunn.Utils;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI; // Added for UI
|
||||
|
||||
|
|
@ -99,6 +100,20 @@ namespace RacesOfValheim
|
|||
Player player = Player.m_localPlayer;
|
||||
if (player == null) return;
|
||||
|
||||
// What the reset actually took off, printed at the end so it can be read in the console.
|
||||
var removed = new System.Collections.Generic.List<string>();
|
||||
|
||||
// Forms first, before any status effect goes. Taking a form's effect away without
|
||||
// undoing the form leaves the body hidden (bat, mist, drake, wolf, Muspell, Ravager)
|
||||
// or oversized (True Form), and several races only ever look at their form from an
|
||||
// Update that returns early for anyone who is not of that race any more.
|
||||
if (AswidRace.Instance != null && AswidRace.Instance.HardResetForReset()) removed.Add("form: Aswid bat/mist");
|
||||
if (FenrirRace.Instance != null && FenrirRace.Instance.HardResetForReset()) removed.Add("form: Fenrir");
|
||||
if (SkadiRace.Instance != null && SkadiRace.Instance.HardResetForReset()) removed.Add("form: Skadi drake");
|
||||
if (TrolRace.Instance != null && TrolRace.Instance.HardResetForReset()) removed.Add("form: Trol True Form");
|
||||
if (TrentaMuspell.HardResetForReset(player)) removed.Add("form: Trenta Muspell");
|
||||
if (SvermRavagerForm.HardResetForReset(player)) removed.Add("form: Sverm Ravager");
|
||||
|
||||
RemovePermanentRaceEquipment(player);
|
||||
|
||||
player.m_customData.Remove("Race");
|
||||
|
|
@ -120,21 +135,23 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
player.GetSEMan().RemoveStatusEffect("SE_FenrirCurse".GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect("SE_AswidStats".GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect("SE_SkeletonStats".GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect("SE_SkadiStats".GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect("SE_SkadiCooldown".GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect(DvergarConfig.StatsSE.GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect(DvergarConfig.OverchargeSE.GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect(DvergarConfig.OverchargeCdSE.GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect(DvergarConfig.RunicPingCdSE.GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect(TrentaConfig.StatsSE.GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect(TrentaConfig.PurpleRainCdSE.GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect(TrentaConfig.PortalCdSE.GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect(SvermConfig.StatsSE.GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect(SvermConfig.RavagerSE.GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect(SvermConfig.RavagerCdSE.GetStableHashCode());
|
||||
// Every status effect this mod registers, rather than a list kept by hand: the hand
|
||||
// list was missing the True Form and both of its cooldowns, Bat and Mist Form, the
|
||||
// Skeleton's resurrect cooldown and most of Skadi's, and the next effect anyone adds
|
||||
// would have been missing too. The forms were dropped above, so taking their effects
|
||||
// away here no longer leaves a body hidden or blown up.
|
||||
SEMan seman = player.GetSEMan();
|
||||
foreach (CustomStatusEffect custom in ModRegistry.GetStatusEffects(PluginGUID))
|
||||
{
|
||||
StatusEffect se = custom?.StatusEffect;
|
||||
if (se == null) continue;
|
||||
|
||||
int hash = se.name.GetStableHashCode();
|
||||
if (!seman.HaveStatusEffect(hash)) continue;
|
||||
|
||||
seman.RemoveStatusEffect(hash, true);
|
||||
removed.Add(se.name);
|
||||
}
|
||||
|
||||
// COLD, which is not one of ours at all - and that is exactly why it has to go.
|
||||
//
|
||||
|
|
@ -161,9 +178,21 @@ namespace RacesOfValheim
|
|||
// Only after the ZDO above already says "Human" - see the class doc comment.
|
||||
RaceItemCleanup.PurgeForeignRaceItems(player);
|
||||
|
||||
// Normal size. The Trol, the Skeleton past Fader and the self-sizing races all scale
|
||||
// either the player or its Visual, and each puts its own size back only from code that
|
||||
// may not run again now the race has changed. The next race sets its own size anyway.
|
||||
player.transform.localScale = Vector3.one;
|
||||
GameObject visual = Traverse.Create(player).Field("m_visual").GetValue<GameObject>();
|
||||
if (visual != null) visual.transform.localScale = Vector3.one;
|
||||
|
||||
string summary = removed.Count == 0
|
||||
? "[ResetRace] Nothing race-specific was left on the player."
|
||||
: "[ResetRace] Removed: " + string.Join(", ", removed);
|
||||
Jotunn.Logger.LogInfo(summary);
|
||||
if (Console.instance != null) Console.instance.Print(summary);
|
||||
|
||||
if (Instance != null)
|
||||
{
|
||||
if (FenrirRace.Instance != null) FenrirRace.Instance.ForceRevert();
|
||||
Instance.ShowRaceSelectionMenu();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue