Merge branch 'fix-sverm-carapace-reset' into main
This commit is contained in:
commit
16ccff0d0b
2 changed files with 65 additions and 2 deletions
|
|
@ -280,7 +280,13 @@ namespace RacesOfValheim
|
||||||
SvermVisuals.ApplyClaws(__instance); // cleanup of the retired cosmetic path
|
SvermVisuals.ApplyClaws(__instance); // cleanup of the retired cosmetic path
|
||||||
SvermVisuals.ApplySpines(__instance);
|
SvermVisuals.ApplySpines(__instance);
|
||||||
SvermVisuals.ApplyGlideMotes(__instance);
|
SvermVisuals.ApplyGlideMotes(__instance);
|
||||||
if (isSverm) SvermVisuals.ApplyCarapace(__instance);
|
|
||||||
|
// Unconditional, like the four above it: ApplyCarapace takes the carapace OFF
|
||||||
|
// whoever is no longer a Sverm, and it cannot do that from behind an
|
||||||
|
// `if (isSverm)`. That gate is why the chitin stayed on after a race change
|
||||||
|
// until the player happened to equip something. For anyone who never wore it
|
||||||
|
// this returns on the first line.
|
||||||
|
SvermVisuals.ApplyCarapace(__instance);
|
||||||
|
|
||||||
// Issues the claws if they are missing and puts them back in hand whenever
|
// Issues the claws if they are missing and puts them back in hand whenever
|
||||||
// both hands are free. On the same throttle rather than every frame: it is a
|
// both hands are free. On the same throttle rather than every frame: it is a
|
||||||
|
|
|
||||||
|
|
@ -643,6 +643,14 @@ namespace RacesOfValheim
|
||||||
/// Called from the UpdateVisuals postfix rather than once at spawn, because Valheim
|
/// Called from the UpdateVisuals postfix rather than once at spawn, because Valheim
|
||||||
/// rebuilds these instances on every equipment change and hands back plain white models.
|
/// rebuilds these instances on every equipment change and hands back plain white models.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <summary>
|
||||||
|
/// Worn by a player whose three armour slots are currently showing carapace rather than
|
||||||
|
/// whatever they actually have equipped. A marker component rather than a static set of
|
||||||
|
/// players: it dies with the GameObject, so a player who logs out or is destroyed cannot
|
||||||
|
/// leave an entry behind.
|
||||||
|
/// </summary>
|
||||||
|
private class CarapaceMark : MonoBehaviour { }
|
||||||
|
|
||||||
public static void ApplyCarapace(Player player)
|
public static void ApplyCarapace(Player player)
|
||||||
{
|
{
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
@ -650,7 +658,29 @@ namespace RacesOfValheim
|
||||||
VisEquipment visEq = player.GetComponent<VisEquipment>();
|
VisEquipment visEq = player.GetComponent<VisEquipment>();
|
||||||
if (visEq == null) return;
|
if (visEq == null) return;
|
||||||
|
|
||||||
if (!IsSvermPlayer(player)) return;
|
if (!IsSvermPlayer(player))
|
||||||
|
{
|
||||||
|
// TAKING IT OFF IS THIS METHOD'S JOB TOO, and for a long time it was nobody's:
|
||||||
|
// this returned here and the only caller was itself behind an `if (isSverm)`, so
|
||||||
|
// the three slots kept showing carapace after the player had stopped being one.
|
||||||
|
// The visuals are a plain override written with SetChestItem and friends, so
|
||||||
|
// nothing in the game corrects them on its own - which is why equipping anything
|
||||||
|
// appeared to "fix" it. That was Valheim's own refresh writing the real gear back
|
||||||
|
// over ours, and until it happened the player wore chitin they no longer had.
|
||||||
|
//
|
||||||
|
// Every other cosmetic in this file already removes itself from whoever is not a
|
||||||
|
// Sverm (ApplyEyes, ApplyClaws, ApplySpines all do); the carapace was the one that
|
||||||
|
// did not.
|
||||||
|
CarapaceMark mark = player.GetComponent<CarapaceMark>();
|
||||||
|
if (mark != null)
|
||||||
|
{
|
||||||
|
Object.Destroy(mark);
|
||||||
|
RestoreEquipmentVisuals(player, visEq);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.GetComponent<CarapaceMark>() == null) player.gameObject.AddComponent<CarapaceMark>();
|
||||||
|
|
||||||
visEq.SetChestItem(SvermConfig.CarapaceChestVisual);
|
visEq.SetChestItem(SvermConfig.CarapaceChestVisual);
|
||||||
visEq.SetLegItem(SvermConfig.CarapaceLegsVisual);
|
visEq.SetLegItem(SvermConfig.CarapaceLegsVisual);
|
||||||
|
|
@ -663,6 +693,33 @@ namespace RacesOfValheim
|
||||||
TintInstances(Traverse.Create(visEq).Field("m_helmetItemInstance").GetValue(), state);
|
TintInstances(Traverse.Create(visEq).Field("m_helmetItemInstance").GetValue(), state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Puts the three slots back to whatever the player actually has equipped.
|
||||||
|
///
|
||||||
|
/// The same three lines vanilla's own Humanoid.SetupVisEquipment writes - the item's drop
|
||||||
|
/// prefab name, or "" for an empty slot - rather than calling that method, because it also
|
||||||
|
/// rewrites the hands, the shoulders and the utility slot, and the Sverm never touched
|
||||||
|
/// those. Restoring only what was overridden cannot disturb another race's visuals or a
|
||||||
|
/// weapon that some other patch is mid-way through swapping.
|
||||||
|
///
|
||||||
|
/// Read through Traverse because the equipment fields are not public in the shipped
|
||||||
|
/// assembly, which is the same reason SvermClawSlot reads m_rightItem that way.
|
||||||
|
/// </summary>
|
||||||
|
private static void RestoreEquipmentVisuals(Player player, VisEquipment visEq)
|
||||||
|
{
|
||||||
|
visEq.SetChestItem(EquippedVisualName(player, "m_chestItem"));
|
||||||
|
visEq.SetLegItem(EquippedVisualName(player, "m_legItem"));
|
||||||
|
visEq.SetHelmetItem(EquippedVisualName(player, "m_helmetItem"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The prefab name VisEquipment wants for an equipped slot, or "" when it is empty.</summary>
|
||||||
|
private static string EquippedVisualName(Player player, string field)
|
||||||
|
{
|
||||||
|
ItemDrop.ItemData item = Traverse.Create((Humanoid)player).Field<ItemDrop.ItemData>(field).Value;
|
||||||
|
if (item == null || item.m_dropPrefab == null) return "";
|
||||||
|
return item.m_dropPrefab.name;
|
||||||
|
}
|
||||||
|
|
||||||
private static void TintInstances(object value, int state)
|
private static void TintInstances(object value, int state)
|
||||||
{
|
{
|
||||||
if (value is GameObject single)
|
if (value is GameObject single)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue