bugfix 07/10/26 + evil laugh
This commit is contained in:
parent
eaa87f892a
commit
0159f1e8c4
11 changed files with 417 additions and 8 deletions
|
|
@ -239,6 +239,33 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bat and mist form shut the rest of the human's attack loop as well as StartAttack: crossbow
|
||||
/// reload and draw live in PlayerAttackInput, and the form's Animator fires the held attack
|
||||
/// through OnAttackTrigger. See Fenrir's BlockPlayerAttackInputPatch.
|
||||
/// </summary>
|
||||
public static class AswidFormAttackLoop
|
||||
{
|
||||
public static bool InForm(Humanoid player)
|
||||
{
|
||||
if (player != Player.m_localPlayer) return false;
|
||||
return player.GetComponentInChildren<BatFormBehavior>() != null
|
||||
|| player.GetSEMan().HaveStatusEffect("SE_MistForm".GetStableHashCode());
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "PlayerAttackInput")]
|
||||
public static class Aswid_BlockAttackInput_Patch
|
||||
{
|
||||
public static bool Prefix(Player __instance) => !AswidFormAttackLoop.InForm(__instance);
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Humanoid), nameof(Humanoid.OnAttackTrigger))]
|
||||
public static class Aswid_BlockAttackTrigger_Patch
|
||||
{
|
||||
public static bool Prefix(Humanoid __instance) => !AswidFormAttackLoop.InForm(__instance);
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Character), "SetRun")]
|
||||
public static class Aswid_Run_Patch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -34,6 +34,32 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The rest of the human's attack loop, shut while a form is up. StartAttack is the only door an
|
||||
/// attack starts through and it is blocked above, but a crossbow also lives in the loop around it:
|
||||
/// PlayerAttackInput reloads it and holds its draw, and the form's own Animator carries
|
||||
/// CharacterAnimEvent, whose OnAttackTrigger event resolves to the PLAYER (its Character is the first
|
||||
/// one up the hierarchy) and fires whatever attack the human still has in hand. A tester's crossbow
|
||||
/// shot on all three form attacks, reloaded for free, like a semi-automatic.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Player), "PlayerAttackInput")]
|
||||
public static class BlockPlayerAttackInputPatch
|
||||
{
|
||||
public static bool Prefix(Player __instance)
|
||||
{
|
||||
return !FenrirForms.LocalInForm(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Humanoid), nameof(Humanoid.OnAttackTrigger))]
|
||||
public static class BlockPlayerAttackTriggerPatch
|
||||
{
|
||||
public static bool Prefix(Humanoid __instance)
|
||||
{
|
||||
return !FenrirForms.LocalInForm(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
// --- PATCH 2: BLOCCO ANIMAZIONI ED EFFETTI SONORI NATIVI ---
|
||||
// Every form now, not the Fenring alone: see BlockPlayerLogicAttackPatch.
|
||||
[HarmonyPatch(typeof(ZSyncAnimation), nameof(ZSyncAnimation.SetTrigger))]
|
||||
|
|
|
|||
|
|
@ -402,9 +402,9 @@ namespace RacesOfValheim
|
|||
{
|
||||
if (BossProgressionManager.GetCurrentProgressionState() >= 3) // The Wickerman (Elder)
|
||||
{
|
||||
// Check if it's an arrow (either by skill or by checking if a bow/ammo was used)
|
||||
if ((hitData != null && hitData.m_skill == Skills.SkillType.Bows) ||
|
||||
(ammo != null && ammo.m_shared.m_skillType == Skills.SkillType.Bows))
|
||||
// Check if it's an arrow or a bolt (either by skill or by checking if a bow/crossbow/ammo was used)
|
||||
if ((hitData != null && (hitData.m_skill == Skills.SkillType.Bows || hitData.m_skill == Skills.SkillType.Crossbows)) ||
|
||||
(ammo != null && (ammo.m_shared.m_skillType == Skills.SkillType.Bows || ammo.m_shared.m_skillType == Skills.SkillType.Crossbows)))
|
||||
{
|
||||
// If the arrow doesn't already have significant fire damage, add it
|
||||
if (hitData != null && hitData.m_damage.m_fire < 22f)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "RacesOfValheim",
|
||||
"description": "A Valheim mod that adds ten custom playable races (Aswid, Draugh, Dvergar, Fenrir, Furling, Skadi, Skeleton, Sverm, Trenta, Trol) each with unique abilities, traits, race stations and a deep boss-driven progression system.",
|
||||
"version_number": "1.5.8",
|
||||
"version_number": "1.5.9",
|
||||
"website_url": "",
|
||||
"dependencies": [
|
||||
"denikson-BepInExPack_Valheim-5.4.2333",
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace RacesOfValheim
|
|||
{
|
||||
public const string PluginGUID = "com.nandor.racesofvalheim";
|
||||
public const string PluginName = "Races Of Valheim";
|
||||
public const string PluginVersion = "1.5.8";
|
||||
public const string PluginVersion = "1.5.9";
|
||||
|
||||
private readonly Harmony harmony = new Harmony(PluginGUID);
|
||||
|
||||
|
|
@ -80,6 +80,7 @@ namespace RacesOfValheim
|
|||
CommandManager.Instance.AddConsoleCommand(new DumpPotionsCommand());
|
||||
CommandManager.Instance.AddConsoleCommand(new ListPrefabsCommand());
|
||||
CommandManager.Instance.AddConsoleCommand(new DumpAnimCommand());
|
||||
CommandManager.Instance.AddConsoleCommand(new EvilLaughCommand());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -601,4 +601,30 @@ namespace RacesOfValheim
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The rest of the human's attack loop, shut while a dragon form is up: crossbow reload and draw
|
||||
/// live in PlayerAttackInput, and the form's Animator fires the held attack through
|
||||
/// OnAttackTrigger. Without these a crossbow in hand shot on every form attack. See Fenrir's
|
||||
/// BlockPlayerAttackInputPatch.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Player), "PlayerAttackInput")]
|
||||
public static class SkadiBlockAttackInputPatch
|
||||
{
|
||||
public static bool Prefix(Player __instance)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer) return true;
|
||||
return __instance.GetComponentInChildren<DrakeFormBehavior>() == null;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Humanoid), nameof(Humanoid.OnAttackTrigger))]
|
||||
public static class SkadiBlockAttackTriggerPatch
|
||||
{
|
||||
public static bool Prefix(Humanoid __instance)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer) return true;
|
||||
return __instance.GetComponentInChildren<DrakeFormBehavior>() == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
294
JotunnModStub/Skeleton/SkeletonEvilLaugh.cs
Normal file
294
JotunnModStub/Skeleton/SkeletonEvilLaugh.cs
Normal file
|
|
@ -0,0 +1,294 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Jotunn.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The Skeleton's villain laugh: /evillaugh. Head thrown back, jaw clacking, shoulders
|
||||
/// shaking, both fists punched up into the air.
|
||||
///
|
||||
/// It is not an animation clip and it is not the vanilla 'laugh' emote. It is a pose written
|
||||
/// over the rig in LateUpdate, the way SkeletonJawFix does for the mandible, so it needs no
|
||||
/// asset bundle and no Animator parameter.
|
||||
///
|
||||
/// The start time goes on the player's ZDO, so every client that can see the Skeleton plays
|
||||
/// the same laugh - the command only has to run on the laughing player's own machine.
|
||||
///
|
||||
/// Two kinds of bone, two rules (see SkeletonJawFix for why it matters):
|
||||
/// - Bones the Animator rewrites every frame (head, chest, arms) get the pose multiplied on
|
||||
/// top of whatever the animation left, so it can never accumulate.
|
||||
/// - Bones nothing animates (the jaw, the fingers) are written ABSOLUTELY from the rest
|
||||
/// pose captured once, so the pose is the same however many frames it has been applied.
|
||||
///
|
||||
/// Every direction is worked out in the player's own frame (right / up / forward) rather than
|
||||
/// in a bone's local axes, which the rig does not make guessable. The angles below are first
|
||||
/// guesses to be tuned in game.
|
||||
/// </summary>
|
||||
public class SkeletonEvilLaugh : MonoBehaviour
|
||||
{
|
||||
public const string ZdoKey = "RoV_skelEvilLaughAt";
|
||||
|
||||
private const float DurationSeconds = 4f;
|
||||
private const float BlendSeconds = 0.3f;
|
||||
|
||||
// The laugh itself: how fast the shoulders shake and the jaw clacks, per second.
|
||||
private const float ShakeHz = 8f;
|
||||
|
||||
private const float HeadBackDegrees = 28f;
|
||||
private const float NeckBackDegrees = 8f;
|
||||
private const float ChestBackDegrees = 10f;
|
||||
private const float ChestShakeDegrees = 3.5f;
|
||||
private const float HeadNodDegrees = 4f;
|
||||
private const float JawOpenDegrees = 24f;
|
||||
|
||||
// Fingers curl about the bone's own Z, the usual axis of a humanoid finger. If the fists
|
||||
// open instead of closing in game, flip the sign.
|
||||
private const float FingerCurlDegrees = 70f;
|
||||
|
||||
// Where the fists go, in the player's frame: outward, up, a little forward.
|
||||
private static readonly Vector3 UpperArmAim = new Vector3(0.5f, 0.8f, 0.25f);
|
||||
private static readonly Vector3 ForearmAim = new Vector3(0.15f, 1f, 0.1f);
|
||||
|
||||
private struct Side
|
||||
{
|
||||
public Transform upper, lower, hand;
|
||||
public float sign;
|
||||
public List<Transform> fingers;
|
||||
public List<Quaternion> fingerRest;
|
||||
}
|
||||
|
||||
private Player m_player;
|
||||
private VisEquipment m_vis;
|
||||
private ZNetView m_nview;
|
||||
|
||||
private bool m_resolved;
|
||||
private Transform m_head, m_neck, m_chest, m_jaw;
|
||||
private Quaternion m_jawRest;
|
||||
private Side m_left, m_right;
|
||||
|
||||
private float m_weight;
|
||||
private bool m_wroteHands;
|
||||
|
||||
// ── Starting it ──────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Starts the laugh for the local player; everyone else picks it up from the ZDO.</summary>
|
||||
public static bool Begin(Player player)
|
||||
{
|
||||
if (player == null || ZNet.instance == null) return false;
|
||||
if (!SkeletonVisuals.IsSkeletonPlayer(player)) return false;
|
||||
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview == null || !nview.IsValid()) return false;
|
||||
|
||||
nview.GetZDO().Set(ZdoKey, ZNet.instance.GetTime().Ticks);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_player = GetComponent<Player>();
|
||||
m_vis = GetComponent<VisEquipment>();
|
||||
m_nview = GetComponent<ZNetView>();
|
||||
}
|
||||
|
||||
// ── The pose ─────────────────────────────────────────────────────────
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (m_player == null || m_nview == null || !m_nview.IsValid() || ZNet.instance == null) return;
|
||||
|
||||
float elapsed = ElapsedSinceStart();
|
||||
bool laughing = elapsed >= 0f && elapsed < DurationSeconds
|
||||
&& SkeletonVisuals.IsSkeletonPlayer(m_player)
|
||||
&& !m_player.IsDead();
|
||||
|
||||
// Fade in over the first moments, out over the last, so the pose never pops.
|
||||
float target = 0f;
|
||||
if (laughing) target = Mathf.Clamp01(Mathf.Min(elapsed, DurationSeconds - elapsed) / BlendSeconds);
|
||||
|
||||
m_weight = Mathf.MoveTowards(m_weight, target, Time.deltaTime / BlendSeconds);
|
||||
|
||||
if (m_weight <= 0f)
|
||||
{
|
||||
if (m_wroteHands) RestoreHands();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_resolved) Resolve();
|
||||
|
||||
float t = Time.time;
|
||||
float wave = Mathf.Sin(t * ShakeHz * Mathf.PI * 2f);
|
||||
float open = 0.5f + 0.5f * Mathf.Sin(t * ShakeHz * Mathf.PI * 2f + 0.6f);
|
||||
|
||||
Vector3 right = m_player.transform.right;
|
||||
|
||||
// Back and up, the whole spine in on it: chest first, then neck, then head.
|
||||
Pitch(m_chest, -(ChestBackDegrees + ChestShakeDegrees * wave) * m_weight, right);
|
||||
Pitch(m_neck, -NeckBackDegrees * m_weight, right);
|
||||
Pitch(m_head, -(HeadBackDegrees + HeadNodDegrees * wave) * m_weight, right);
|
||||
|
||||
if (m_jaw != null && m_jaw.parent != null)
|
||||
{
|
||||
m_jaw.localRotation = m_jawRest;
|
||||
m_jaw.rotation = Quaternion.AngleAxis(JawOpenDegrees * open * m_weight, right) * m_jaw.rotation;
|
||||
}
|
||||
|
||||
Fists(m_left, wave);
|
||||
Fists(m_right, wave);
|
||||
m_wroteHands = true;
|
||||
}
|
||||
|
||||
/// <summary>Seconds since the laugh began, by the same clock on every client; -1 if there is none.</summary>
|
||||
private float ElapsedSinceStart()
|
||||
{
|
||||
long ticks = m_nview.GetZDO().GetLong(ZdoKey, 0L);
|
||||
if (ticks == 0L) return -1f;
|
||||
|
||||
double age = (ZNet.instance.GetTime() - new DateTime(ticks)).TotalSeconds;
|
||||
return age < 0 ? -1f : (float)age;
|
||||
}
|
||||
|
||||
private static void Pitch(Transform bone, float degrees, Vector3 axis)
|
||||
{
|
||||
if (bone == null) return;
|
||||
bone.rotation = Quaternion.AngleAxis(degrees, axis) * bone.rotation;
|
||||
}
|
||||
|
||||
private void Fists(Side side, float wave)
|
||||
{
|
||||
if (side.upper == null || side.lower == null || side.hand == null) return;
|
||||
|
||||
Vector3 right = m_player.transform.right;
|
||||
Vector3 up = Vector3.up;
|
||||
Vector3 fwd = m_player.transform.forward;
|
||||
|
||||
// Each fist punches up and down a little with the laugh.
|
||||
Vector3 pump = up * (0.12f * wave);
|
||||
|
||||
Aim(side.upper, side.lower, Frame(UpperArmAim, side.sign, right, up, fwd) + pump);
|
||||
Aim(side.lower, side.hand, Frame(ForearmAim, -side.sign, right, up, fwd) + pump);
|
||||
|
||||
if (side.fingers == null) return;
|
||||
|
||||
for (int i = 0; i < side.fingers.Count; i++)
|
||||
{
|
||||
Transform finger = side.fingers[i];
|
||||
if (finger == null) continue;
|
||||
finger.localRotation = side.fingerRest[i]
|
||||
* Quaternion.Euler(0f, 0f, FingerCurlDegrees * m_weight);
|
||||
}
|
||||
}
|
||||
|
||||
private static Vector3 Frame(Vector3 aim, float sideSign, Vector3 right, Vector3 up, Vector3 fwd)
|
||||
=> (right * (aim.x * sideSign) + up * aim.y + fwd * aim.z).normalized;
|
||||
|
||||
/// <summary>
|
||||
/// Turns a bone so the line from it to its child points along 'desired', by as much as the
|
||||
/// weight allows. The child follows the parent, so the forearm is aimed after the upper arm.
|
||||
/// </summary>
|
||||
private void Aim(Transform bone, Transform child, Vector3 desired)
|
||||
{
|
||||
Vector3 current = child.position - bone.position;
|
||||
if (current.sqrMagnitude < 1e-8f) return;
|
||||
|
||||
Quaternion full = Quaternion.FromToRotation(current.normalized, desired.normalized);
|
||||
bone.rotation = Quaternion.Slerp(Quaternion.identity, full, m_weight) * bone.rotation;
|
||||
}
|
||||
|
||||
private void RestoreHands()
|
||||
{
|
||||
foreach (Side side in new[] { m_left, m_right })
|
||||
{
|
||||
if (side.fingers == null) continue;
|
||||
for (int i = 0; i < side.fingers.Count; i++)
|
||||
if (side.fingers[i] != null) side.fingers[i].localRotation = side.fingerRest[i];
|
||||
}
|
||||
|
||||
if (m_jaw != null) m_jaw.localRotation = m_jawRest;
|
||||
m_wroteHands = false;
|
||||
}
|
||||
|
||||
// ── Finding the bones ────────────────────────────────────────────────
|
||||
|
||||
private void Resolve()
|
||||
{
|
||||
Animator anim = m_player.GetComponentInChildren<Animator>();
|
||||
|
||||
m_head = Find(anim, HumanBodyBones.Head, "head");
|
||||
m_neck = Find(anim, HumanBodyBones.Neck, "neck");
|
||||
m_chest = Find(anim, HumanBodyBones.UpperChest, "spine2") ?? Find(anim, HumanBodyBones.Chest, "spine1");
|
||||
|
||||
m_jaw = FindByName("jaw");
|
||||
if (m_jaw != null) m_jawRest = m_jaw.localRotation;
|
||||
|
||||
m_left = BuildSide(anim, true);
|
||||
m_right = BuildSide(anim, false);
|
||||
|
||||
m_resolved = true;
|
||||
}
|
||||
|
||||
private Side BuildSide(Animator anim, bool left)
|
||||
{
|
||||
string prefix = left ? "left" : "right";
|
||||
Side side = new Side
|
||||
{
|
||||
sign = left ? -1f : 1f,
|
||||
upper = Find(anim, left ? HumanBodyBones.LeftUpperArm : HumanBodyBones.RightUpperArm, prefix + "arm"),
|
||||
lower = Find(anim, left ? HumanBodyBones.LeftLowerArm : HumanBodyBones.RightLowerArm, prefix + "forearm"),
|
||||
hand = Find(anim, left ? HumanBodyBones.LeftHand : HumanBodyBones.RightHand, prefix + "hand"),
|
||||
fingers = new List<Transform>(),
|
||||
fingerRest = new List<Quaternion>()
|
||||
};
|
||||
|
||||
// Every bone below the hand is a finger or a thumb; a hand with none just opens and
|
||||
// closes nothing, and the arms still go up.
|
||||
if (side.hand != null)
|
||||
{
|
||||
foreach (Transform child in side.hand.GetComponentsInChildren<Transform>())
|
||||
{
|
||||
if (child == side.hand) continue;
|
||||
side.fingers.Add(child);
|
||||
side.fingerRest.Add(child.localRotation);
|
||||
}
|
||||
}
|
||||
|
||||
return side;
|
||||
}
|
||||
|
||||
private Transform Find(Animator anim, HumanBodyBones bone, string fallbackName)
|
||||
{
|
||||
Transform t = anim != null ? anim.GetBoneTransform(bone) : null;
|
||||
return t != null ? t : FindByName(fallbackName);
|
||||
}
|
||||
|
||||
private Transform FindByName(string part)
|
||||
{
|
||||
if (m_vis == null || m_vis.m_bodyModel == null || m_vis.m_bodyModel.bones == null) return null;
|
||||
|
||||
foreach (Transform bone in m_vis.m_bodyModel.bones)
|
||||
if (bone != null && bone.name.ToLower().Contains(part)) return bone;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class EvilLaughCommand : ConsoleCommand
|
||||
{
|
||||
public override string Name => "evillaugh";
|
||||
public override string Help => "The Skeleton's villain laugh";
|
||||
|
||||
public override void Run(string[] args)
|
||||
{
|
||||
if (Player.m_localPlayer == null)
|
||||
{
|
||||
Console.instance.Print("You must be in-game to laugh.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SkeletonEvilLaugh.Begin(Player.m_localPlayer))
|
||||
Console.instance.Print("Only a Skeleton laughs like that.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -359,6 +359,12 @@ namespace RacesOfValheim
|
|||
p.gameObject.AddComponent<SkeletonJawFix>();
|
||||
}
|
||||
|
||||
// The /evillaugh pose; same reasoning as the jaw, so remote players laugh too.
|
||||
if (p.GetComponent<SkeletonEvilLaugh>() == null)
|
||||
{
|
||||
p.gameObject.AddComponent<SkeletonEvilLaugh>();
|
||||
}
|
||||
|
||||
// The lights in the eye sockets, cloned out of this tier's own creature so
|
||||
// that each one arrives its own colour. Outside the build block above on
|
||||
// purpose: they hang off the player's rig bones rather than off the body
|
||||
|
|
|
|||
|
|
@ -452,6 +452,30 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The rest of the human's attack loop - crossbow reload and draw, and the animation event that
|
||||
/// fires a held attack - shut for the form too. See Fenrir's BlockPlayerAttackInputPatch.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Player), "PlayerAttackInput")]
|
||||
public static class Sverm_RavagerBlockAttackInput_Patch
|
||||
{
|
||||
public static bool Prefix(Player __instance)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer) return true;
|
||||
return !IsActive;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Humanoid), nameof(Humanoid.OnAttackTrigger))]
|
||||
public static class Sverm_RavagerBlockAttackTrigger_Patch
|
||||
{
|
||||
public static bool Prefix(Humanoid __instance)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer) return true;
|
||||
return !IsActive;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>No food, no mead, no potions. The form is meant to be survived, not sustained.</summary>
|
||||
[HarmonyPatch(typeof(Humanoid), "UseItem")]
|
||||
public static class Sverm_RavagerUseItem_Patch
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue